/textpattern/include/txp_prefs.php
PHP | 904 lines | 679 code | 165 blank | 60 comment | 93 complexity | c9044fba8002b86043c6bcc0a3314338 MD5 | raw file
Possible License(s): AGPL-1.0
- <?php
- /*
- This is Textpattern
- Copyright 2005 by Dean Allen
- www.textpattern.com
- All rights reserved
- Use of this software indicates acceptance of the Textpattern license agreement
- $HeadURL: http://textpattern.googlecode.com/svn/development/4.0/textpattern/include/txp_prefs.php $
- $LastChangedRevision: 2812 $
- */
- if (!defined('txpinterface')) die('txpinterface is undefined.');
- //-------------------------------------------------------------
- include_once txpath.'/lib/txplib_update.php';
- if ($event == 'prefs') {
- require_privs('prefs');
- if(!$step or !in_array($step, array('advanced_prefs','prefs_save','advanced_prefs_save','get_language','list_languages','prefs_list','delete_lang','export_lang'))){
- prefs_list();
- } else $step();
- }
- //-------------------------------------------------------------
- function prefs_nav() {
- global $step;
- $out =
- '<ul id="pref-nav">'.
- '<li class="rounded">'.sLink('prefs', 'prefs_list', gTxt('site_prefs'), (($step=='prefs_list') ? 'navlink-active' : 'navlink')).'</li>'.
- '<li class="rounded">'.sLink('prefs', 'advanced_prefs', gTxt('advanced_preferences'), (($step=='prefs_list') ? 'navlink-active' : 'navlink')).'</li>'.
- '<li class="rounded">'.sLink('prefs', 'list_languages', gTxt('manage_languages'), (($step=='prefs_list') ? 'navlink-active' : 'navlink')).'</li>'.
- '</ul>';
-
- return $out;
- }
- // -------------------------------------------------------------
- function prefs_save()
- {
- $prefnames = safe_column("name", "txp_prefs", "prefs_id = 1");
- $post = doSlash(stripPost());
- foreach($prefnames as $prefname) {
- if (isset($post[$prefname])) {
- if ($prefname == 'siteurl')
- {
- $post[$prefname] = str_replace("http://",'',$post[$prefname]);
- $post[$prefname] = rtrim($post[$prefname],"/ ");
- }
- safe_update(
- "txp_prefs",
- "val = '".$post[$prefname]."'",
- "name = '".doSlash($prefname)."' and prefs_id = 1"
- );
- }
- }
- update_lastmod();
- prefs_list(gTxt('preferences_saved'));
- }
- // -------------------------------------------------------------
- function prefs_list($message = '')
- {
- global $prefs;
- extract($prefs);
-
- echo pagetop(gTxt('edit_preferences'), $message).
- n.t.'<div id="content" class="clearfix prefs">'.n.
- t.'<h1>'.gTxt('edit_preferences').'</h1>';
- $locale = setlocale(LC_ALL, $locale);
- echo n.n.'<form method="post" action="index.php">'.
- prefs_nav().
-
- hed(gTxt('site_prefs'), 2);
- $evt_list = safe_column('event', 'txp_prefs', "type = 0 and prefs_id = 1 group by event order by event desc");
- foreach ($evt_list as $event)
- {
- $rs = safe_rows_start('*', 'txp_prefs', "type = 0 and prefs_id = 1 and event = '".doSlash($event)."' order by position");
- $cur_evt = '';
- while ($a = nextRow($rs))
- {
- // do we print the event header?
- if ($a['event'] != $cur_evt)
- {
- $cur_evt = $a['event'];
- if ($cur_evt == 'comments' && !$use_comments)
- {
- continue;
- }
- echo hed(gTxt($a['event']), 3, ' class="pref-heading"');
- }
- // don't print comment settings if comments not allowed
- if ($cur_evt == 'comments' && !$use_comments)
- {
- continue;
- }
- // Skip old settings that don't have an input type
- if (!is_callable($a['html']))
- {
- continue;
- }
- $preflabel = ($a['html'] != 'yesnoradio') ?
- '<label for="'.$a['name'].'">'.gTxt($a['name']).'</label>' :
- gTxt($a['name']);
- if ($a['html'] == 'text_input')
- {
- $prefitem = pref_func('text_input', $a['name'], $a['val'], 20);
- } else {
- $prefitem = pref_func($a['html'], $a['name'], $a['val']);
- }
- echo t2.graf(
- '<span class="left">'.$preflabel.'</span>'.
- '<span class="right">'.$prefitem.'</span>',
- 'class="pref" id="'.$a['name'].'"').n;
- }
- }
-
- echo t2.div(
- fInput('submit', 'Submit', gTxt('save_button'), 'publish','','','','','publish-button').
- n.sInput('prefs_save').
- n.eInput('prefs').
- n.hInput('prefs_id', '1'), 'ctr').
- n.n.'</form>';
- $check_updates = gps('check_updates');
- if ($check_updates)
- {
- $updates = checkUpdates();
- if (is_array($updates))
- {
- $out = graf(join(br, $updates),'class="ctr"');
- }
- else{
- $out = $updates;
- }
- echo graf($out,'class="pref"');
- }
- else
- {
- echo form(
- graf(
- '<strong>'.gTxt('check_for_txp_updates').'</strong>'.sp.
- n.'<input type="submit" name="check_updates" value="'.gTxt('go').'" class="publish" />'.
- n.eInput('prefs').
- n.sInput('prefs_list')
- )
- , 'text-align: center;');
- }
-
- echo '</div>';
- }
- //-------------------------------------------------------------
- function pref_func($func, $name, $val, $size = '')
- {
- $func = (is_callable('pref_'.$func) ? 'pref_'.$func : $func);
- return call_user_func($func, $name, $val, $size);
- }
- //-------------------------------------------------------------
- function text_input($name, $val, $size = '')
- {
- return fInput('text', $name, $val, 'edit', '', '', $size, '', $name);
- }
- // -------------------------------------------------------------
- function hash_picker($name,$val)
- {
- $valkeys = hash_algos();
- $vals = array_combine($valkeys , $valkeys);
- return selectInput($name, $vals, $val, '', '', $name);
- }
-
- // -------------------------------------------------------------
- function get_admin_styles()
- {
- global $txpcfg, $adminstyle;
-
- $css_dir = txpath.DS.'styles'.DS.'cp'.DS;
- if (!is_dir($css_dir))
- {
- trigger_error('Styles directory is not a directory: '.$css_dir, E_USER_WARNING);
- }
- if (chdir($css_dir)) {
- if (function_exists('glob')){
- $css_file_array = glob("*.css");
- }else {
- $dh = opendir($css_dir);
- $css_file_array = array();
- while (false !== ($filename = readdir($dh))) {
- if (strstr($filename, '.css'))
- if(is_file($filename)) {
- $css_file_array[] = $filename;
- }
- }
- closedir($dh);
-
- }
- $styles = array();
- if ($css_file_array) {
- foreach ($css_file_array as $css_name) {
- if (is_file($css_name)) {
- $styles[] = $css_name;
- }
- }
- }
- }
- $stylearray = array_combine($styles, $styles);
- return selectInput('adminstyle', $stylearray, $adminstyle,'','onchange="styleSwitcher(this.value)"');
- }
- //-------------------------------------------------------------
- function gmtoffset_select($name, $val)
- {
- // Standard time zones as compiled by H.M. Nautical Almanac Office, June 2004
- // http://aa.usno.navy.mil/faq/docs/world_tzones.html
- $tz = array(
- -12, -11, -10, -9.5, -9, -8.5, -8, -7, -6, -5, -4, -3.5, -3, -2, -1,
- 0,
- +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,
- );
- $vals = array();
- foreach ($tz as $z)
- {
- $sign = ($z >= 0 ? '+' : '');
- $label = sprintf("GMT %s%02d:%02d", $sign, $z, abs($z - (int)$z) * 60);
- $vals[sprintf("%s%d", $sign, $z * 3600)] = $label;
- }
- return selectInput($name, $vals, $val, '', '', $name);
- }
- //-------------------------------------------------------------
- function logging($name, $val)
- {
- $vals = array(
- 'all' => gTxt('all_hits'),
- 'refer' => gTxt('referrers_only'),
- 'none' => gTxt('none')
- );
- return selectInput($name, $vals, $val, '', '', $name);
- }
- //-------------------------------------------------------------
- function permlinkmodes($name, $val)
- {
- $vals = array(
- 'messy' => gTxt('messy'),
- 'id_title' => gTxt('id_title'),
- 'section_id_title' => gTxt('section_id_title'),
- 'year_month_day_title' => gTxt('year_month_day_title'),
- 'section_title' => gTxt('section_title'),
- 'title_only' => gTxt('title_only'),
- // 'category_subcategory' => gTxt('category_subcategory')
- );
- return selectInput($name, $vals, $val, '', '', $name);
- }
- //-------------------------------------------------------------
- function urlmodes($name, $val)
- {
- $vals = array(
- '0' => gTxt('messy'),
- '1' => gTxt('clean')
- );
- return selectInput($name, $vals, $val, '', '', $name);
- }
- //-------------------------------------------------------------
- function commentmode($name, $val)
- {
- $vals = array(
- '0' => gTxt('nopopup'),
- '1' => gTxt('popup')
- );
- return selectInput($name, $vals, $val, '', '', $name);
- }
- //-------------------------------------------------------------
- function weeks($name, $val)
- {
- $weeks = gTxt('weeks');
- $vals = array(
- '0' => gTxt('never'),
- 7 => '1 '.gTxt('week'),
- 14 => '2 '.$weeks,
- 21 => '3 '.$weeks,
- 28 => '4 '.$weeks,
- 35 => '5 '.$weeks,
- 42 => '6 '.$weeks
- );
- return selectInput($name, $vals, $val, '', '', $name);
- }
- //-------------------------------------------------------------
- function languages($name, $val)
- {
- $installed_langs = safe_column('lang', 'txp_lang', "1 = 1 group by lang");
- $vals = array();
- foreach ($installed_langs as $lang)
- {
- $vals[$lang] = safe_field('data', 'txp_lang', "name = '".doSlash($lang)."' AND lang = '".doSlash($lang)."'");
- if (trim($vals[$lang]) == '')
- {
- $vals[$lang] = $lang;
- }
- }
- asort($vals);
- reset($vals);
- $out = n.'<select id="'.$name.'" name="'.$name.'" class="list">';
- foreach ($vals as $avalue => $alabel)
- {
- $selected = ($avalue == $val || $alabel == $val) ?
- ' selected="selected"' :
- '';
- $out .= n.t.'<option value="'.htmlspecialchars($avalue).'"'.$selected.'>'.htmlspecialchars($alabel).'</option>'.n;
- }
- $out .= n.'</select>';
- return $out;
- }
- // -------------------------------------------------------------
- function dateformats($name, $val)
- {
- $dayname = '%A';
- $dayshort = '%a';
- $daynum = is_numeric(strftime('%e')) ? '%e' : '%d';
- $daynumlead = '%d';
- $daynumord = is_numeric(substr(trim(strftime('%Oe')), 0, 1)) ? '%Oe' : $daynum;
- $monthname = '%B';
- $monthshort = '%b';
- $monthnum = '%m';
- $year = '%Y';
- $yearshort = '%y';
- $time24 = '%H:%M';
- $time12 = strftime('%p') ? '%I:%M %p' : $time24;
- $date = strftime('%x') ? '%x' : '%Y-%m-%d';
- $formats = array(
- "$monthshort $daynumord, $time12",
- "$daynum.$monthnum.$yearshort",
- "$daynumord $monthname, $time12",
- "$yearshort.$monthnum.$daynumlead, $time12",
- "$dayshort $monthshort $daynumord, $time12",
- "$dayname $monthname $daynumord, $year",
- "$monthshort $daynumord",
- "$daynumord $monthname $yearshort",
- "$daynumord $monthnum $year - $time24",
- "$daynumord $monthname $year",
- "$daynumord $monthname $year, $time24",
- "$daynumord. $monthname $year",
- "$daynumord. $monthname $year, $time24",
- "$year-$monthnum-$daynumlead",
- "$year-$daynumlead-$monthnum",
- "$date $time12",
- "$date",
- "$time24",
- "$time12",
- "$year-$monthnum-$daynumlead $time24",
- );
- $ts = time();
- $vals = array();
- foreach ($formats as $f)
- {
- if ($d = safe_strftime($f, $ts))
- {
- $vals[$f] = $d;
- }
- }
- $vals['since'] = gTxt('hours_days_ago');
- return selectInput($name, array_unique($vals), $val, '', '', $name);
- }
- //-------------------------------------------------------------
- function prod_levels($name, $val)
- {
- $vals = array(
- 'debug' => gTxt('production_debug'),
- 'testing' => gTxt('production_test'),
- 'live' => gTxt('production_live'),
- );
- return selectInput($name, $vals, $val, '', '', $name);
- }
- //-------------------------------------------------------------
- function advanced_prefs($message = '')
- {
- echo pagetop(gTxt('edit_preferences'), $message).
- n.t.'<div id="content" class="clearfix prefs">'.n.
- t.'<h1>'.gTxt('edit_preferences').'</h1>';
- echo n.n.'<form method="post" action="index.php">'.
- prefs_nav().
- hed(gTxt('advanced_preferences'), 2);
- $rs = safe_rows_start('*', 'txp_prefs', "type = 1 and prefs_id = 1 order by event, position");
- $cur_evt = '';
- while ($a = nextRow($rs))
- {
- if ($a['event']!= $cur_evt)
- {
- $cur_evt = $a['event'];
- echo hed(gTxt($a['event']), 3, ' class="pref-heading"');
- }
- $preflabel = ($a['html'] != 'yesnoradio') ?
- '<label for="'.$a['name'].'">'.gTxt($a['name']).'</label>' :
- gTxt($a['name']);
- if ($a['html'] == 'text_input')
- {
- $look_for = array('expire_logs_after', 'max_url_len', 'time_offset', 'rss_how_many', 'logs_expire');
- $size = in_array($a['name'], $look_for) ? 3 : 20;
- $prefitem = pref_func('text_input', $a['name'], $a['val'], $size);
- }
- else
- {
- if (is_callable($a['html']))
- {
- $prefitem = pref_func($a['html'], $a['name'], $a['val']);
- }
- else
- {
- $prefitem = $a['val'];
- }
- }
- echo t2.graf(
- '<span class="left">'.$preflabel.'</span>'.
- '<span class="right">'.$prefitem.'</span>',
- 'class="pref" id="'.$a['name'].'"').n;
- }
- echo t2.div(
- fInput('submit', 'Submit', gTxt('save_button'), 'publish','','','','','publish-button').
- sInput('advanced_prefs_save').
- eInput('prefs').
- hInput('prefs_id', '1')
- , 'ctr');
- n.n.'</form>'.
- '</div>';
- }
- //-------------------------------------------------------------
- function real_max_upload_size($user_max)
- {
- // The minimum of the candidates, is the real max. possible size
- $candidates = array($user_max,
- ini_get('post_max_size'),
- ini_get('upload_max_filesize'));
- $real_max = null;
- foreach ($candidates as $item)
- {
- $val = trim($item);
- $modifier = strtolower( substr($val, -1) );
- switch($modifier) {
- // The 'G' modifier is available since PHP 5.1.0
- case 'g': $val *= 1024;
- case 'm': $val *= 1024;
- case 'k': $val *= 1024;
- }
- if ($val > 1) {
- if (is_null($real_max))
- $real_max = $val;
- elseif ($val < $real_max)
- $real_max = $val;
- }
- }
- return $real_max;
- }
- //-------------------------------------------------------------
- function advanced_prefs_save()
- {
- $prefnames = safe_column("name", "txp_prefs", "prefs_id = 1 AND type = 1");
- $post = doSlash(stripPost());
- if (empty($post['tempdir']))
- $post['tempdir'] = doSlash(find_temp_dir());
- if (!empty($post['file_max_upload_size']))
- $post['file_max_upload_size'] = real_max_upload_size($post['file_max_upload_size']);
- foreach($prefnames as $prefname) {
- if (isset($post[$prefname])) {
- safe_update(
- "txp_prefs",
- "val = '".$post[$prefname]."'",
- "name = '".doSlash($prefname)."' and prefs_id = 1"
- );
- }
- }
- update_lastmod();
- advanced_prefs(gTxt('preferences_saved'));
- }
- //-------------------------------------------------------------
- function delete_lang()
- {
- $lang = ps('lang');
- $msg = 'Cannot delete the current admin language ('.$lang.').';
-
- if( $lang != LANG )
- {
- include_once txpath.'/lib/lib_lang.php';
- $langs = get_installation_langs();
- if( in_array( $lang , $langs ) )
- {
- $lang = doSlash($lang);
- safe_delete( 'txp_lang' , "`lang`='$lang'" );
- $msg = 'Deleted all '.gTxt($lang).' '.gTxt('strings');
- }
- else
- {
- $msg = gTxt('lang_file_no_del' , array( '{lang}'=>$lang ) );
- }
- }
- list_languages($msg);
- }
- function export_lang()
- {
- $msg = gTxt('Export failed.');
- $lang = gps('lang');
- if( $lang )
- {
- include_once txpath.'/lib/lib_lang.php';
- $langs = get_installation_langs();
- if( in_array( $lang , $langs ) )
- {
- $file = build_langfile( $lang );
- $title = $lang.'.txt';
- $desc = gTxt('lang_file_desc',array('{lang}'=>$lang) );
- serveFile( $file , $title , $desc , 'text/plain; charset=utf-8' );
- }
- else
- {
- $msg = gTxt('lang_file_no_exp' , array( '{lang}'=>$lang ) );
- }
- }
- list_languages($msg);
- }
-
- //-------------------------------------------------------------
- # RPC install/update languages
- function list_languages($message='')
- {
- global $prefs, $locale, $txpcfg, $textarray;
- require_once txpath.'/lib/IXRClass.php';
- // Select and save active language
- $new_lang = ps('language');
- if (!$message && ps('step')=='list_languages' && $new_lang )
- {
- $locale = doSlash(getlocale($new_lang));
- safe_update("txp_prefs","val='".doSlash($new_lang)."'", "name='language'");
- safe_update("txp_prefs","val='". $locale ."'", "name='locale'");
- $textarray = load_lang(doSlash($new_lang));
- $locale = setlocale(LC_ALL, $locale);
- $message = gTxt('preferences_saved');
- }
- $active_lang = safe_field('val','txp_prefs',"name='language'");
- $lang_form = tda( form(gTxt('active_language').' '.
- languages('language',$active_lang).' '.
- fInput('submit', 'Submit', gTxt('save_button'), 'publish','','','','','publish-button').
- eInput('prefs').sInput('list_languages')
- ,'display:inline;')
- ,' style="text-align:center" colspan="3"');
- $lang_server = !empty($prefs['lang_server']) ? $prefs['lang_server'] : RPC_SERVER;
- $client = new IXR_Client($lang_server);
- #$client->debug = true;
- $available_lang = array();
- $rpc_connect = false;$show_files = false;
- # Get items from RPC
- @set_time_limit(90);
- if (gps('force')!='file' && $client->query('tups.listLanguages',$prefs['blog_uid']))
- {
- $rpc_connect = true;
- $response = $client->getResponse();
- foreach ($response as $language)
- $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);
- } elseif (gps('force')!='file')
- {
- $msg = gTxt('rpc_connect_error')."<!--".$client->getErrorCode().' '.$client->getErrorMessage()."-->";
- }
- # Get items from Filesystem
- $files = get_lang_files();
- if (gps('force')=='file' || !$rpc_connect)
- $show_files = true;
- if ( $show_files && is_array($files) && !empty($files) )
- {
- foreach ($files as $file)
- {
- if ($fp = @fopen(txpath.DS.'lang'.DS.$file,'r'))
- {
- $name = str_replace('.txt','',$file);
- $firstline = fgets($fp, 4069);
- fclose($fp);
- if (strpos($firstline,'#@version') !== false)
- @list($fversion,$ftime) = explode(';',trim(substr($firstline,strpos($firstline,' ',1))));
- else
- $fversion = $ftime = NULL;
- $available_lang[$name]['file_note'] = (isset($fversion)) ? $fversion : 0;
- $available_lang[$name]['file_lastmod'] = (isset($ftime)) ? $ftime : 0;
- }
- }
- }
- # Get installed items from the database
- # I'm affraid we need a value here for the language itself, not for each one of the rows
- $rows = safe_rows('lang, UNIX_TIMESTAMP(MAX(lastmod)) as lastmod','txp_lang',"1 GROUP BY lang ORDER BY lastmod DESC");
- foreach ($rows as $language)
- {
- $available_lang[$language['lang']]['db_lastmod'] = $language['lastmod'];
- }
- $list = '';
- # Show the language table
- foreach ($available_lang as $langname => $langdat)
- {
- $file_updated = ( isset($langdat['db_lastmod']) && @$langdat['file_lastmod'] > $langdat['db_lastmod']);
- $rpc_updated = ( @$langdat['rpc_lastmod'] > @$langdat['db_lastmod']);
- $rpc_install = tda( strong(eLink('prefs','get_language','lang_code',$langname,(isset($langdat['db_lastmod']))
- ? gTxt('update') : gTxt('install'),'updating',isset($langdat['db_lastmod']) )).
- br.safe_strftime('%d %b %Y %X',@$langdat['rpc_lastmod'])
- ,(isset($langdat['db_lastmod']))
- ? ' style="color:red;text-align:center;background-color:#FFFFCC;"'
- : ' style="color:#667;vertical-align:middle;text-align:center"');
- $list.= tr (
- # Lang-Name & Date
- tda(gTxt($langname).
- ((isset($langdat['db_lastmod']) )
- ? br . tag(' '.safe_strftime('%d %b %Y %X',$langdat['db_lastmod']), 'span',' style="color:#aaa;font-style:italic"') .
- form( fInput('submit', '', gTxt('export'), '').eInput('prefs') . sInput('export_lang') . hInput('lang',$langname), '', '', 'post', 'lang_options') .
- ( ($langname != $active_lang) ? form( fInput('submit', '', gTxt('delete'), '').eInput('prefs') . sInput('delete_lang') . hInput('lang',$langname), '',
- "verify('" . doSlash(gTxt('lang_remove_warning' , array('{langcode}'=>$langname, '{lang}'=>gTxt($langname) )) ) .' \\n'.
- doSlash(gTxt('are_you_sure')) . "')", 'post', 'lang_options' ) : '' )
- : '' )
- , (isset($langdat['db_lastmod']) && $rpc_updated) #tda attribute
- ? ' nowrap="nowrap" style="color:red;background-color:#FFFFCC;"'
- : ' nowrap="nowrap" style="vertical-align:middle"' ).n.
- # RPC - Info
- ( ($rpc_updated)
- ? $rpc_install
- : tda( (isset($langdat['rpc_lastmod'])) ? gTxt('updated') : '-'
- ,' style="vertical-align:middle;text-align:center"')
- ).n.
- # File - Info
- ( ($show_files)
- ? tda( tag( ( isset($langdat['file_lastmod']) )
- ? eLink('prefs','get_language','lang_code',$langname,($file_updated) ? gTxt('update') : gTxt('install'),'force','file').
- br.' '.safe_strftime($prefs['archive_dateformat'],$langdat['file_lastmod'])
- : ' ' # No File available
- , 'span', ($file_updated) ? ' style="color:#667;"' : ' style="color:#aaa;font-style:italic"' )
- , ' class="langfile" style="text-align:center;vertical-align:middle"').n
- : '')
- ).n.n;
- }
- // Output Table + Content
- pagetop(gTxt('update_languages'),$message);
- echo n.t.'<div id="content" class="clearfix prefs" >'.n.
- t.'<h1>'.gTxt('edit_preferences').'</h1>'.
-
- prefs_nav().
- hed(gTxt('manage_languages'), 2);
-
- if (isset($msg) && $msg)
- echo tag ($msg,'p',' style="text-align:center;color:red;width:50%;margin: 2em auto"' );
- echo startTable('list'),
- tr(tda(' ',' colspan="3" style="font-size:0.25em"')),
- tr( $lang_form ),
- tr(tda(' ',' colspan="3" style="font-size:0.25em"')),
- tr(tda(gTxt('language')).tda(gTxt('from_server')).( ($show_files) ? tda(gTxt('from_file')) : '' ), ' style="font-weight:bold"');
- echo $list;
- if (!$show_files)
- {
- $linktext = gTxt('from_file').' ('.gTxt('experts_only').')';
- echo tr(tda(' ',' colspan="3" style="font-size:0.25em"')).
- tr(tda(strong(eLink('prefs','list_languages','force','file',$linktext)),' colspan="3" style="text-align:center"') );
- } elseif (gps('force')=='file') {
- echo tr(tda(' ',' colspan="3" style="font-size:0.25em"')).
- tr(tda(sLink('prefs','list_languages',strong(gTxt('from_server'))),' colspan="3" style="text-align:center"') );
- }
- echo endTable();
- $install_langfile = gTxt('install_langfile', array(
- '{url}' => strong('<a href="'.RPC_SERVER.'/lang/">'.RPC_SERVER.'/lang/</a>')
- ));
- if ( $install_langfile == 'install_langfile')
- $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.';
- echo tag( $install_langfile ,'p',' style="text-align:center;width:50%;margin: 2em auto"' );
-
- echo '</div>';
- }
- //-------------------------------------------------------------
- function get_language()
- {
- global $prefs, $txpcfg, $textarray;
- require_once txpath.'/lib/IXRClass.php';
- $lang_code = gps('lang_code');
- $lang_server = !empty($prefs['lang_server']) ? $prefs['lang_server'] : RPC_SERVER;
- $client = new IXR_Client($lang_server);
- // $client->debug = true;
- @set_time_limit(90);
- if (gps('force')=='file' || !$client->query('tups.getLanguage',$prefs['blog_uid'],$lang_code))
- {
- if ( (gps('force')=='file' || gps('updating')!=='1') && install_language_from_file($lang_code) )
- {
- if (defined('LANG'))
- $textarray = load_lang(LANG);
- return list_languages(gTxt($lang_code).sp.gTxt('updated'));
- }else{
- $install_langfile = gTxt('install_langfile', array(
- '{url}' => strong('<a href="'.RPC_SERVER.'/lang/">'.RPC_SERVER.'/lang/</a>')
- ));
- if ( $install_langfile == 'install_langfile')
- $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.';
- pagetop(gTxt('installing_language'));
- echo tag( gTxt('rpc_connect_error')."<!--".$client->getErrorCode().' '.$client->getErrorMessage()."-->"
- ,'p',' style="text-align:center;color:red;width:50%;margin: 2em auto"' );
- echo tag( $install_langfile ,'p',' style="text-align:center;width:50%;margin: 2em auto"' );
- }
- }else {
- $response = $client->getResponse();
- $lang_struct = unserialize($response);
- function install_lang_key(&$value, $key)
- {
- extract(gpsa(array('lang_code','updating')));
- $exists = safe_field('name','txp_lang',"name='".doSlash($value['name'])."' AND lang='".doSlash($lang_code)."'");
- $q = "name='".doSlash($value['name'])."', event='".doSlash($value['event'])."', data='".doSlash($value['data'])."', lastmod='".doSlash(strftime('%Y%m%d%H%M%S',$value['uLastmod']))."'";
- if ($exists)
- {
- $value['ok'] = safe_update('txp_lang',$q,"lang='".doSlash($lang_code)."' AND name='".doSlash($value['name'])."'");
- }else{
- $value['ok'] = safe_insert('txp_lang',$q.", lang='".doSlash($lang_code)."'");
- }
- }
- array_walk($lang_struct,'install_lang_key');
- $size = count($lang_struct);
- $errors = 0;
- for($i=0; $i < $size ; $i++)
- {
- $errors += ( !$lang_struct[$i]['ok'] );
- }
- if (defined('LANG'))
- $textarray = load_lang(LANG);
- $msg = gTxt($lang_code).sp.gTxt('updated');
- if ($errors > 0)
- $msg .= sprintf(" (%s errors, %s ok)",$errors, ($size-$errors));
- return list_languages($msg);
- }
- }
- // ----------------------------------------------------------------------
- function get_lang_files()
- {
- global $txpcfg;
- $dirlist = array();
- $lang_dir = txpath.DS.'lang'.DS;
- if (!is_dir($lang_dir))
- {
- trigger_error('Lang directory is not a directory: '.$lang_dir, E_USER_WARNING);
- return $dirlist;
- }
- if (chdir($lang_dir)) {
- if (function_exists('glob')){
- $g_array = glob("*.txt");
- }else {
- # filter .txt only files here?
- $dh = opendir($lang_dir);
- $g_array = array();
- while (false !== ($filename = readdir($dh))) {
- if (strstr($filename, '.txt'))
- $g_array[] = $filename;
- }
- closedir($dh);
- }
- # build an array of lang-codes => filemtimes
- if ($g_array) {
- foreach ($g_array as $lang_name) {
- if (is_file($lang_name)) {
- $dirlist[substr($lang_name,0,5)] = @filemtime($lang_name);
- }
- }
- }
- }
- return $g_array;
- }
- ?>