[ Index ]

PHP Cross Reference of Textpattern 4.0.8

title

Body

[close]

/textpattern/include/ -> txp_prefs.php (source)

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


Generated: Thu May 21 23:03:01 2009 Cross-referenced by PHPXref 0.7