PageRenderTime 47ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/textpattern/include/txp_prefs.php

https://bitbucket.org/Manfre/xpattern
PHP | 904 lines | 679 code | 165 blank | 60 comment | 93 complexity | c9044fba8002b86043c6bcc0a3314338 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /*
  3. This is Textpattern
  4. Copyright 2005 by Dean Allen
  5. www.textpattern.com
  6. All rights reserved
  7. Use of this software indicates acceptance of the Textpattern license agreement
  8. $HeadURL: http://textpattern.googlecode.com/svn/development/4.0/textpattern/include/txp_prefs.php $
  9. $LastChangedRevision: 2812 $
  10. */
  11. if (!defined('txpinterface')) die('txpinterface is undefined.');
  12. //-------------------------------------------------------------
  13. include_once txpath.'/lib/txplib_update.php';
  14. if ($event == 'prefs') {
  15. require_privs('prefs');
  16. if(!$step or !in_array($step, array('advanced_prefs','prefs_save','advanced_prefs_save','get_language','list_languages','prefs_list','delete_lang','export_lang'))){
  17. prefs_list();
  18. } else $step();
  19. }
  20. //-------------------------------------------------------------
  21. function prefs_nav() {
  22. global $step;
  23. $out =
  24. '<ul id="pref-nav">'.
  25. '<li class="rounded">'.sLink('prefs', 'prefs_list', gTxt('site_prefs'), (($step=='prefs_list') ? 'navlink-active' : 'navlink')).'</li>'.
  26. '<li class="rounded">'.sLink('prefs', 'advanced_prefs', gTxt('advanced_preferences'), (($step=='prefs_list') ? 'navlink-active' : 'navlink')).'</li>'.
  27. '<li class="rounded">'.sLink('prefs', 'list_languages', gTxt('manage_languages'), (($step=='prefs_list') ? 'navlink-active' : 'navlink')).'</li>'.
  28. '</ul>';
  29. return $out;
  30. }
  31. // -------------------------------------------------------------
  32. function prefs_save()
  33. {
  34. $prefnames = safe_column("name", "txp_prefs", "prefs_id = 1");
  35. $post = doSlash(stripPost());
  36. foreach($prefnames as $prefname) {
  37. if (isset($post[$prefname])) {
  38. if ($prefname == 'siteurl')
  39. {
  40. $post[$prefname] = str_replace("http://",'',$post[$prefname]);
  41. $post[$prefname] = rtrim($post[$prefname],"/ ");
  42. }
  43. safe_update(
  44. "txp_prefs",
  45. "val = '".$post[$prefname]."'",
  46. "name = '".doSlash($prefname)."' and prefs_id = 1"
  47. );
  48. }
  49. }
  50. update_lastmod();
  51. prefs_list(gTxt('preferences_saved'));
  52. }
  53. // -------------------------------------------------------------
  54. function prefs_list($message = '')
  55. {
  56. global $prefs;
  57. extract($prefs);
  58. echo pagetop(gTxt('edit_preferences'), $message).
  59. n.t.'<div id="content" class="clearfix prefs">'.n.
  60. t.'<h1>'.gTxt('edit_preferences').'</h1>';
  61. $locale = setlocale(LC_ALL, $locale);
  62. echo n.n.'<form method="post" action="index.php">'.
  63. prefs_nav().
  64. hed(gTxt('site_prefs'), 2);
  65. $evt_list = safe_column('event', 'txp_prefs', "type = 0 and prefs_id = 1 group by event order by event desc");
  66. foreach ($evt_list as $event)
  67. {
  68. $rs = safe_rows_start('*', 'txp_prefs', "type = 0 and prefs_id = 1 and event = '".doSlash($event)."' order by position");
  69. $cur_evt = '';
  70. while ($a = nextRow($rs))
  71. {
  72. // do we print the event header?
  73. if ($a['event'] != $cur_evt)
  74. {
  75. $cur_evt = $a['event'];
  76. if ($cur_evt == 'comments' && !$use_comments)
  77. {
  78. continue;
  79. }
  80. echo hed(gTxt($a['event']), 3, ' class="pref-heading"');
  81. }
  82. // don't print comment settings if comments not allowed
  83. if ($cur_evt == 'comments' && !$use_comments)
  84. {
  85. continue;
  86. }
  87. // Skip old settings that don't have an input type
  88. if (!is_callable($a['html']))
  89. {
  90. continue;
  91. }
  92. $preflabel = ($a['html'] != 'yesnoradio') ?
  93. '<label for="'.$a['name'].'">'.gTxt($a['name']).'</label>' :
  94. gTxt($a['name']);
  95. if ($a['html'] == 'text_input')
  96. {
  97. $prefitem = pref_func('text_input', $a['name'], $a['val'], 20);
  98. } else {
  99. $prefitem = pref_func($a['html'], $a['name'], $a['val']);
  100. }
  101. echo t2.graf(
  102. '<span class="left">'.$preflabel.'</span>'.
  103. '<span class="right">'.$prefitem.'</span>',
  104. 'class="pref" id="'.$a['name'].'"').n;
  105. }
  106. }
  107. echo t2.div(
  108. fInput('submit', 'Submit', gTxt('save_button'), 'publish','','','','','publish-button').
  109. n.sInput('prefs_save').
  110. n.eInput('prefs').
  111. n.hInput('prefs_id', '1'), 'ctr').
  112. n.n.'</form>';
  113. $check_updates = gps('check_updates');
  114. if ($check_updates)
  115. {
  116. $updates = checkUpdates();
  117. if (is_array($updates))
  118. {
  119. $out = graf(join(br, $updates),'class="ctr"');
  120. }
  121. else{
  122. $out = $updates;
  123. }
  124. echo graf($out,'class="pref"');
  125. }
  126. else
  127. {
  128. echo form(
  129. graf(
  130. '<strong>'.gTxt('check_for_txp_updates').'</strong>'.sp.
  131. n.'<input type="submit" name="check_updates" value="'.gTxt('go').'" class="publish" />'.
  132. n.eInput('prefs').
  133. n.sInput('prefs_list')
  134. )
  135. , 'text-align: center;');
  136. }
  137. echo '</div>';
  138. }
  139. //-------------------------------------------------------------
  140. function pref_func($func, $name, $val, $size = '')
  141. {
  142. $func = (is_callable('pref_'.$func) ? 'pref_'.$func : $func);
  143. return call_user_func($func, $name, $val, $size);
  144. }
  145. //-------------------------------------------------------------
  146. function text_input($name, $val, $size = '')
  147. {
  148. return fInput('text', $name, $val, 'edit', '', '', $size, '', $name);
  149. }
  150. // -------------------------------------------------------------
  151. function hash_picker($name,$val)
  152. {
  153. $valkeys = hash_algos();
  154. $vals = array_combine($valkeys , $valkeys);
  155. return selectInput($name, $vals, $val, '', '', $name);
  156. }
  157. // -------------------------------------------------------------
  158. function get_admin_styles()
  159. {
  160. global $txpcfg, $adminstyle;
  161. $css_dir = txpath.DS.'styles'.DS.'cp'.DS;
  162. if (!is_dir($css_dir))
  163. {
  164. trigger_error('Styles directory is not a directory: '.$css_dir, E_USER_WARNING);
  165. }
  166. if (chdir($css_dir)) {
  167. if (function_exists('glob')){
  168. $css_file_array = glob("*.css");
  169. }else {
  170. $dh = opendir($css_dir);
  171. $css_file_array = array();
  172. while (false !== ($filename = readdir($dh))) {
  173. if (strstr($filename, '.css'))
  174. if(is_file($filename)) {
  175. $css_file_array[] = $filename;
  176. }
  177. }
  178. closedir($dh);
  179. }
  180. $styles = array();
  181. if ($css_file_array) {
  182. foreach ($css_file_array as $css_name) {
  183. if (is_file($css_name)) {
  184. $styles[] = $css_name;
  185. }
  186. }
  187. }
  188. }
  189. $stylearray = array_combine($styles, $styles);
  190. return selectInput('adminstyle', $stylearray, $adminstyle,'','onchange="styleSwitcher(this.value)"');
  191. }
  192. //-------------------------------------------------------------
  193. function gmtoffset_select($name, $val)
  194. {
  195. // Standard time zones as compiled by H.M. Nautical Almanac Office, June 2004
  196. // http://aa.usno.navy.mil/faq/docs/world_tzones.html
  197. $tz = array(
  198. -12, -11, -10, -9.5, -9, -8.5, -8, -7, -6, -5, -4, -3.5, -3, -2, -1,
  199. 0,
  200. +1, +2, +3, +3.5, +4, +4.5, +5, +5.5, +6, +6.5, +7, +8, +9, +9.5, +10, +10.5, +11, +11.5, +12, +13, +14,
  201. );
  202. $vals = array();
  203. foreach ($tz as $z)
  204. {
  205. $sign = ($z >= 0 ? '+' : '');
  206. $label = sprintf("GMT %s%02d:%02d", $sign, $z, abs($z - (int)$z) * 60);
  207. $vals[sprintf("%s%d", $sign, $z * 3600)] = $label;
  208. }
  209. return selectInput($name, $vals, $val, '', '', $name);
  210. }
  211. //-------------------------------------------------------------
  212. function logging($name, $val)
  213. {
  214. $vals = array(
  215. 'all' => gTxt('all_hits'),
  216. 'refer' => gTxt('referrers_only'),
  217. 'none' => gTxt('none')
  218. );
  219. return selectInput($name, $vals, $val, '', '', $name);
  220. }
  221. //-------------------------------------------------------------
  222. function permlinkmodes($name, $val)
  223. {
  224. $vals = array(
  225. 'messy' => gTxt('messy'),
  226. 'id_title' => gTxt('id_title'),
  227. 'section_id_title' => gTxt('section_id_title'),
  228. 'year_month_day_title' => gTxt('year_month_day_title'),
  229. 'section_title' => gTxt('section_title'),
  230. 'title_only' => gTxt('title_only'),
  231. // 'category_subcategory' => gTxt('category_subcategory')
  232. );
  233. return selectInput($name, $vals, $val, '', '', $name);
  234. }
  235. //-------------------------------------------------------------
  236. function urlmodes($name, $val)
  237. {
  238. $vals = array(
  239. '0' => gTxt('messy'),
  240. '1' => gTxt('clean')
  241. );
  242. return selectInput($name, $vals, $val, '', '', $name);
  243. }
  244. //-------------------------------------------------------------
  245. function commentmode($name, $val)
  246. {
  247. $vals = array(
  248. '0' => gTxt('nopopup'),
  249. '1' => gTxt('popup')
  250. );
  251. return selectInput($name, $vals, $val, '', '', $name);
  252. }
  253. //-------------------------------------------------------------
  254. function weeks($name, $val)
  255. {
  256. $weeks = gTxt('weeks');
  257. $vals = array(
  258. '0' => gTxt('never'),
  259. 7 => '1 '.gTxt('week'),
  260. 14 => '2 '.$weeks,
  261. 21 => '3 '.$weeks,
  262. 28 => '4 '.$weeks,
  263. 35 => '5 '.$weeks,
  264. 42 => '6 '.$weeks
  265. );
  266. return selectInput($name, $vals, $val, '', '', $name);
  267. }
  268. //-------------------------------------------------------------
  269. function languages($name, $val)
  270. {
  271. $installed_langs = safe_column('lang', 'txp_lang', "1 = 1 group by lang");
  272. $vals = array();
  273. foreach ($installed_langs as $lang)
  274. {
  275. $vals[$lang] = safe_field('data', 'txp_lang', "name = '".doSlash($lang)."' AND lang = '".doSlash($lang)."'");
  276. if (trim($vals[$lang]) == '')
  277. {
  278. $vals[$lang] = $lang;
  279. }
  280. }
  281. asort($vals);
  282. reset($vals);
  283. $out = n.'<select id="'.$name.'" name="'.$name.'" class="list">';
  284. foreach ($vals as $avalue => $alabel)
  285. {
  286. $selected = ($avalue == $val || $alabel == $val) ?
  287. ' selected="selected"' :
  288. '';
  289. $out .= n.t.'<option value="'.htmlspecialchars($avalue).'"'.$selected.'>'.htmlspecialchars($alabel).'</option>'.n;
  290. }
  291. $out .= n.'</select>';
  292. return $out;
  293. }
  294. // -------------------------------------------------------------
  295. function dateformats($name, $val)
  296. {
  297. $dayname = '%A';
  298. $dayshort = '%a';
  299. $daynum = is_numeric(strftime('%e')) ? '%e' : '%d';
  300. $daynumlead = '%d';
  301. $daynumord = is_numeric(substr(trim(strftime('%Oe')), 0, 1)) ? '%Oe' : $daynum;
  302. $monthname = '%B';
  303. $monthshort = '%b';
  304. $monthnum = '%m';
  305. $year = '%Y';
  306. $yearshort = '%y';
  307. $time24 = '%H:%M';
  308. $time12 = strftime('%p') ? '%I:%M %p' : $time24;
  309. $date = strftime('%x') ? '%x' : '%Y-%m-%d';
  310. $formats = array(
  311. "$monthshort $daynumord, $time12",
  312. "$daynum.$monthnum.$yearshort",
  313. "$daynumord $monthname, $time12",
  314. "$yearshort.$monthnum.$daynumlead, $time12",
  315. "$dayshort $monthshort $daynumord, $time12",
  316. "$dayname $monthname $daynumord, $year",
  317. "$monthshort $daynumord",
  318. "$daynumord $monthname $yearshort",
  319. "$daynumord $monthnum $year - $time24",
  320. "$daynumord $monthname $year",
  321. "$daynumord $monthname $year, $time24",
  322. "$daynumord. $monthname $year",
  323. "$daynumord. $monthname $year, $time24",
  324. "$year-$monthnum-$daynumlead",
  325. "$year-$daynumlead-$monthnum",
  326. "$date $time12",
  327. "$date",
  328. "$time24",
  329. "$time12",
  330. "$year-$monthnum-$daynumlead $time24",
  331. );
  332. $ts = time();
  333. $vals = array();
  334. foreach ($formats as $f)
  335. {
  336. if ($d = safe_strftime($f, $ts))
  337. {
  338. $vals[$f] = $d;
  339. }
  340. }
  341. $vals['since'] = gTxt('hours_days_ago');
  342. return selectInput($name, array_unique($vals), $val, '', '', $name);
  343. }
  344. //-------------------------------------------------------------
  345. function prod_levels($name, $val)
  346. {
  347. $vals = array(
  348. 'debug' => gTxt('production_debug'),
  349. 'testing' => gTxt('production_test'),
  350. 'live' => gTxt('production_live'),
  351. );
  352. return selectInput($name, $vals, $val, '', '', $name);
  353. }
  354. //-------------------------------------------------------------
  355. function advanced_prefs($message = '')
  356. {
  357. echo pagetop(gTxt('edit_preferences'), $message).
  358. n.t.'<div id="content" class="clearfix prefs">'.n.
  359. t.'<h1>'.gTxt('edit_preferences').'</h1>';
  360. echo n.n.'<form method="post" action="index.php">'.
  361. prefs_nav().
  362. hed(gTxt('advanced_preferences'), 2);
  363. $rs = safe_rows_start('*', 'txp_prefs', "type = 1 and prefs_id = 1 order by event, position");
  364. $cur_evt = '';
  365. while ($a = nextRow($rs))
  366. {
  367. if ($a['event']!= $cur_evt)
  368. {
  369. $cur_evt = $a['event'];
  370. echo hed(gTxt($a['event']), 3, ' class="pref-heading"');
  371. }
  372. $preflabel = ($a['html'] != 'yesnoradio') ?
  373. '<label for="'.$a['name'].'">'.gTxt($a['name']).'</label>' :
  374. gTxt($a['name']);
  375. if ($a['html'] == 'text_input')
  376. {
  377. $look_for = array('expire_logs_after', 'max_url_len', 'time_offset', 'rss_how_many', 'logs_expire');
  378. $size = in_array($a['name'], $look_for) ? 3 : 20;
  379. $prefitem = pref_func('text_input', $a['name'], $a['val'], $size);
  380. }
  381. else
  382. {
  383. if (is_callable($a['html']))
  384. {
  385. $prefitem = pref_func($a['html'], $a['name'], $a['val']);
  386. }
  387. else
  388. {
  389. $prefitem = $a['val'];
  390. }
  391. }
  392. echo t2.graf(
  393. '<span class="left">'.$preflabel.'</span>'.
  394. '<span class="right">'.$prefitem.'</span>',
  395. 'class="pref" id="'.$a['name'].'"').n;
  396. }
  397. echo t2.div(
  398. fInput('submit', 'Submit', gTxt('save_button'), 'publish','','','','','publish-button').
  399. sInput('advanced_prefs_save').
  400. eInput('prefs').
  401. hInput('prefs_id', '1')
  402. , 'ctr');
  403. n.n.'</form>'.
  404. '</div>';
  405. }
  406. //-------------------------------------------------------------
  407. function real_max_upload_size($user_max)
  408. {
  409. // The minimum of the candidates, is the real max. possible size
  410. $candidates = array($user_max,
  411. ini_get('post_max_size'),
  412. ini_get('upload_max_filesize'));
  413. $real_max = null;
  414. foreach ($candidates as $item)
  415. {
  416. $val = trim($item);
  417. $modifier = strtolower( substr($val, -1) );
  418. switch($modifier) {
  419. // The 'G' modifier is available since PHP 5.1.0
  420. case 'g': $val *= 1024;
  421. case 'm': $val *= 1024;
  422. case 'k': $val *= 1024;
  423. }
  424. if ($val > 1) {
  425. if (is_null($real_max))
  426. $real_max = $val;
  427. elseif ($val < $real_max)
  428. $real_max = $val;
  429. }
  430. }
  431. return $real_max;
  432. }
  433. //-------------------------------------------------------------
  434. function advanced_prefs_save()
  435. {
  436. $prefnames = safe_column("name", "txp_prefs", "prefs_id = 1 AND type = 1");
  437. $post = doSlash(stripPost());
  438. if (empty($post['tempdir']))
  439. $post['tempdir'] = doSlash(find_temp_dir());
  440. if (!empty($post['file_max_upload_size']))
  441. $post['file_max_upload_size'] = real_max_upload_size($post['file_max_upload_size']);
  442. foreach($prefnames as $prefname) {
  443. if (isset($post[$prefname])) {
  444. safe_update(
  445. "txp_prefs",
  446. "val = '".$post[$prefname]."'",
  447. "name = '".doSlash($prefname)."' and prefs_id = 1"
  448. );
  449. }
  450. }
  451. update_lastmod();
  452. advanced_prefs(gTxt('preferences_saved'));
  453. }
  454. //-------------------------------------------------------------
  455. function delete_lang()
  456. {
  457. $lang = ps('lang');
  458. $msg = 'Cannot delete the current admin language ('.$lang.').';
  459. if( $lang != LANG )
  460. {
  461. include_once txpath.'/lib/lib_lang.php';
  462. $langs = get_installation_langs();
  463. if( in_array( $lang , $langs ) )
  464. {
  465. $lang = doSlash($lang);
  466. safe_delete( 'txp_lang' , "`lang`='$lang'" );
  467. $msg = 'Deleted all '.gTxt($lang).' '.gTxt('strings');
  468. }
  469. else
  470. {
  471. $msg = gTxt('lang_file_no_del' , array( '{lang}'=>$lang ) );
  472. }
  473. }
  474. list_languages($msg);
  475. }
  476. function export_lang()
  477. {
  478. $msg = gTxt('Export failed.');
  479. $lang = gps('lang');
  480. if( $lang )
  481. {
  482. include_once txpath.'/lib/lib_lang.php';
  483. $langs = get_installation_langs();
  484. if( in_array( $lang , $langs ) )
  485. {
  486. $file = build_langfile( $lang );
  487. $title = $lang.'.txt';
  488. $desc = gTxt('lang_file_desc',array('{lang}'=>$lang) );
  489. serveFile( $file , $title , $desc , 'text/plain; charset=utf-8' );
  490. }
  491. else
  492. {
  493. $msg = gTxt('lang_file_no_exp' , array( '{lang}'=>$lang ) );
  494. }
  495. }
  496. list_languages($msg);
  497. }
  498. //-------------------------------------------------------------
  499. # RPC install/update languages
  500. function list_languages($message='')
  501. {
  502. global $prefs, $locale, $txpcfg, $textarray;
  503. require_once txpath.'/lib/IXRClass.php';
  504. // Select and save active language
  505. $new_lang = ps('language');
  506. if (!$message && ps('step')=='list_languages' && $new_lang )
  507. {
  508. $locale = doSlash(getlocale($new_lang));
  509. safe_update("txp_prefs","val='".doSlash($new_lang)."'", "name='language'");
  510. safe_update("txp_prefs","val='". $locale ."'", "name='locale'");
  511. $textarray = load_lang(doSlash($new_lang));
  512. $locale = setlocale(LC_ALL, $locale);
  513. $message = gTxt('preferences_saved');
  514. }
  515. $active_lang = safe_field('val','txp_prefs',"name='language'");
  516. $lang_form = tda( form(gTxt('active_language').'&nbsp;&nbsp;'.
  517. languages('language',$active_lang).'&nbsp;&nbsp;'.
  518. fInput('submit', 'Submit', gTxt('save_button'), 'publish','','','','','publish-button').
  519. eInput('prefs').sInput('list_languages')
  520. ,'display:inline;')
  521. ,' style="text-align:center" colspan="3"');
  522. $lang_server = !empty($prefs['lang_server']) ? $prefs['lang_server'] : RPC_SERVER;
  523. $client = new IXR_Client($lang_server);
  524. #$client->debug = true;
  525. $available_lang = array();
  526. $rpc_connect = false;$show_files = false;
  527. # Get items from RPC
  528. @set_time_limit(90);
  529. if (gps('force')!='file' && $client->query('tups.listLanguages',$prefs['blog_uid']))
  530. {
  531. $rpc_connect = true;
  532. $response = $client->getResponse();
  533. foreach ($response as $language)
  534. $available_lang[$language['language']]['rpc_lastmod'] = gmmktime($language['lastmodified']->hour,$language['lastmodified']->minute,$language['lastmodified']->second,$language['lastmodified']->month,$language['lastmodified']->day,$language['lastmodified']->year);
  535. } elseif (gps('force')!='file')
  536. {
  537. $msg = gTxt('rpc_connect_error')."<!--".$client->getErrorCode().' '.$client->getErrorMessage()."-->";
  538. }
  539. # Get items from Filesystem
  540. $files = get_lang_files();
  541. if (gps('force')=='file' || !$rpc_connect)
  542. $show_files = true;
  543. if ( $show_files && is_array($files) && !empty($files) )
  544. {
  545. foreach ($files as $file)
  546. {
  547. if ($fp = @fopen(txpath.DS.'lang'.DS.$file,'r'))
  548. {
  549. $name = str_replace('.txt','',$file);
  550. $firstline = fgets($fp, 4069);
  551. fclose($fp);
  552. if (strpos($firstline,'#@version') !== false)
  553. @list($fversion,$ftime) = explode(';',trim(substr($firstline,strpos($firstline,' ',1))));
  554. else
  555. $fversion = $ftime = NULL;
  556. $available_lang[$name]['file_note'] = (isset($fversion)) ? $fversion : 0;
  557. $available_lang[$name]['file_lastmod'] = (isset($ftime)) ? $ftime : 0;
  558. }
  559. }
  560. }
  561. # Get installed items from the database
  562. # I'm affraid we need a value here for the language itself, not for each one of the rows
  563. $rows = safe_rows('lang, UNIX_TIMESTAMP(MAX(lastmod)) as lastmod','txp_lang',"1 GROUP BY lang ORDER BY lastmod DESC");
  564. foreach ($rows as $language)
  565. {
  566. $available_lang[$language['lang']]['db_lastmod'] = $language['lastmod'];
  567. }
  568. $list = '';
  569. # Show the language table
  570. foreach ($available_lang as $langname => $langdat)
  571. {
  572. $file_updated = ( isset($langdat['db_lastmod']) && @$langdat['file_lastmod'] > $langdat['db_lastmod']);
  573. $rpc_updated = ( @$langdat['rpc_lastmod'] > @$langdat['db_lastmod']);
  574. $rpc_install = tda( strong(eLink('prefs','get_language','lang_code',$langname,(isset($langdat['db_lastmod']))
  575. ? gTxt('update') : gTxt('install'),'updating',isset($langdat['db_lastmod']) )).
  576. br.safe_strftime('%d %b %Y %X',@$langdat['rpc_lastmod'])
  577. ,(isset($langdat['db_lastmod']))
  578. ? ' style="color:red;text-align:center;background-color:#FFFFCC;"'
  579. : ' style="color:#667;vertical-align:middle;text-align:center"');
  580. $list.= tr (
  581. # Lang-Name & Date
  582. tda(gTxt($langname).
  583. ((isset($langdat['db_lastmod']) )
  584. ? br . tag('&nbsp;'.safe_strftime('%d %b %Y %X',$langdat['db_lastmod']), 'span',' style="color:#aaa;font-style:italic"') .
  585. form( fInput('submit', '', gTxt('export'), '').eInput('prefs') . sInput('export_lang') . hInput('lang',$langname), '', '', 'post', 'lang_options') .
  586. ( ($langname != $active_lang) ? form( fInput('submit', '', gTxt('delete'), '').eInput('prefs') . sInput('delete_lang') . hInput('lang',$langname), '',
  587. "verify('" . doSlash(gTxt('lang_remove_warning' , array('{langcode}'=>$langname, '{lang}'=>gTxt($langname) )) ) .' \\n'.
  588. doSlash(gTxt('are_you_sure')) . "')", 'post', 'lang_options' ) : '' )
  589. : '' )
  590. , (isset($langdat['db_lastmod']) && $rpc_updated) #tda attribute
  591. ? ' nowrap="nowrap" style="color:red;background-color:#FFFFCC;"'
  592. : ' nowrap="nowrap" style="vertical-align:middle"' ).n.
  593. # RPC - Info
  594. ( ($rpc_updated)
  595. ? $rpc_install
  596. : tda( (isset($langdat['rpc_lastmod'])) ? gTxt('updated') : '-'
  597. ,' style="vertical-align:middle;text-align:center"')
  598. ).n.
  599. # File - Info
  600. ( ($show_files)
  601. ? tda( tag( ( isset($langdat['file_lastmod']) )
  602. ? eLink('prefs','get_language','lang_code',$langname,($file_updated) ? gTxt('update') : gTxt('install'),'force','file').
  603. br.'&nbsp;'.safe_strftime($prefs['archive_dateformat'],$langdat['file_lastmod'])
  604. : ' &nbsp; ' # No File available
  605. , 'span', ($file_updated) ? ' style="color:#667;"' : ' style="color:#aaa;font-style:italic"' )
  606. , ' class="langfile" style="text-align:center;vertical-align:middle"').n
  607. : '')
  608. ).n.n;
  609. }
  610. // Output Table + Content
  611. pagetop(gTxt('update_languages'),$message);
  612. echo n.t.'<div id="content" class="clearfix prefs" >'.n.
  613. t.'<h1>'.gTxt('edit_preferences').'</h1>'.
  614. prefs_nav().
  615. hed(gTxt('manage_languages'), 2);
  616. if (isset($msg) && $msg)
  617. echo tag ($msg,'p',' style="text-align:center;color:red;width:50%;margin: 2em auto"' );
  618. echo startTable('list'),
  619. tr(tda('&nbsp;',' colspan="3" style="font-size:0.25em"')),
  620. tr( $lang_form ),
  621. tr(tda('&nbsp;',' colspan="3" style="font-size:0.25em"')),
  622. tr(tda(gTxt('language')).tda(gTxt('from_server')).( ($show_files) ? tda(gTxt('from_file')) : '' ), ' style="font-weight:bold"');
  623. echo $list;
  624. if (!$show_files)
  625. {
  626. $linktext = gTxt('from_file').' ('.gTxt('experts_only').')';
  627. echo tr(tda('&nbsp;',' colspan="3" style="font-size:0.25em"')).
  628. tr(tda(strong(eLink('prefs','list_languages','force','file',$linktext)),' colspan="3" style="text-align:center"') );
  629. } elseif (gps('force')=='file') {
  630. echo tr(tda('&nbsp;',' colspan="3" style="font-size:0.25em"')).
  631. tr(tda(sLink('prefs','list_languages',strong(gTxt('from_server'))),' colspan="3" style="text-align:center"') );
  632. }
  633. echo endTable();
  634. $install_langfile = gTxt('install_langfile', array(
  635. '{url}' => strong('<a href="'.RPC_SERVER.'/lang/">'.RPC_SERVER.'/lang/</a>')
  636. ));
  637. if ( $install_langfile == 'install_langfile')
  638. $install_langfile = 'To install new languages from file you can download them from <b><a href="'.RPC_SERVER.'/lang/">'.RPC_SERVER.'/lang/</a></b> and place them inside your ./textpattern/lang/ directory.';
  639. echo tag( $install_langfile ,'p',' style="text-align:center;width:50%;margin: 2em auto"' );
  640. echo '</div>';
  641. }
  642. //-------------------------------------------------------------
  643. function get_language()
  644. {
  645. global $prefs, $txpcfg, $textarray;
  646. require_once txpath.'/lib/IXRClass.php';
  647. $lang_code = gps('lang_code');
  648. $lang_server = !empty($prefs['lang_server']) ? $prefs['lang_server'] : RPC_SERVER;
  649. $client = new IXR_Client($lang_server);
  650. // $client->debug = true;
  651. @set_time_limit(90);
  652. if (gps('force')=='file' || !$client->query('tups.getLanguage',$prefs['blog_uid'],$lang_code))
  653. {
  654. if ( (gps('force')=='file' || gps('updating')!=='1') && install_language_from_file($lang_code) )
  655. {
  656. if (defined('LANG'))
  657. $textarray = load_lang(LANG);
  658. return list_languages(gTxt($lang_code).sp.gTxt('updated'));
  659. }else{
  660. $install_langfile = gTxt('install_langfile', array(
  661. '{url}' => strong('<a href="'.RPC_SERVER.'/lang/">'.RPC_SERVER.'/lang/</a>')
  662. ));
  663. if ( $install_langfile == 'install_langfile')
  664. $install_langfile = 'To install new languages from file you can download them from <b><a href="'.RPC_SERVER.'/lang/">'.RPC_SERVER.'/lang/</a></b> and place them inside your ./textpattern/lang/ directory.';
  665. pagetop(gTxt('installing_language'));
  666. echo tag( gTxt('rpc_connect_error')."<!--".$client->getErrorCode().' '.$client->getErrorMessage()."-->"
  667. ,'p',' style="text-align:center;color:red;width:50%;margin: 2em auto"' );
  668. echo tag( $install_langfile ,'p',' style="text-align:center;width:50%;margin: 2em auto"' );
  669. }
  670. }else {
  671. $response = $client->getResponse();
  672. $lang_struct = unserialize($response);
  673. function install_lang_key(&$value, $key)
  674. {
  675. extract(gpsa(array('lang_code','updating')));
  676. $exists = safe_field('name','txp_lang',"name='".doSlash($value['name'])."' AND lang='".doSlash($lang_code)."'");
  677. $q = "name='".doSlash($value['name'])."', event='".doSlash($value['event'])."', data='".doSlash($value['data'])."', lastmod='".doSlash(strftime('%Y%m%d%H%M%S',$value['uLastmod']))."'";
  678. if ($exists)
  679. {
  680. $value['ok'] = safe_update('txp_lang',$q,"lang='".doSlash($lang_code)."' AND name='".doSlash($value['name'])."'");
  681. }else{
  682. $value['ok'] = safe_insert('txp_lang',$q.", lang='".doSlash($lang_code)."'");
  683. }
  684. }
  685. array_walk($lang_struct,'install_lang_key');
  686. $size = count($lang_struct);
  687. $errors = 0;
  688. for($i=0; $i < $size ; $i++)
  689. {
  690. $errors += ( !$lang_struct[$i]['ok'] );
  691. }
  692. if (defined('LANG'))
  693. $textarray = load_lang(LANG);
  694. $msg = gTxt($lang_code).sp.gTxt('updated');
  695. if ($errors > 0)
  696. $msg .= sprintf(" (%s errors, %s ok)",$errors, ($size-$errors));
  697. return list_languages($msg);
  698. }
  699. }
  700. // ----------------------------------------------------------------------
  701. function get_lang_files()
  702. {
  703. global $txpcfg;
  704. $dirlist = array();
  705. $lang_dir = txpath.DS.'lang'.DS;
  706. if (!is_dir($lang_dir))
  707. {
  708. trigger_error('Lang directory is not a directory: '.$lang_dir, E_USER_WARNING);
  709. return $dirlist;
  710. }
  711. if (chdir($lang_dir)) {
  712. if (function_exists('glob')){
  713. $g_array = glob("*.txt");
  714. }else {
  715. # filter .txt only files here?
  716. $dh = opendir($lang_dir);
  717. $g_array = array();
  718. while (false !== ($filename = readdir($dh))) {
  719. if (strstr($filename, '.txt'))
  720. $g_array[] = $filename;
  721. }
  722. closedir($dh);
  723. }
  724. # build an array of lang-codes => filemtimes
  725. if ($g_array) {
  726. foreach ($g_array as $lang_name) {
  727. if (is_file($lang_name)) {
  728. $dirlist[substr($lang_name,0,5)] = @filemtime($lang_name);
  729. }
  730. }
  731. }
  732. }
  733. return $g_array;
  734. }
  735. ?>