Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/lib/txplib_update.php - 91 lines - 3179 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4  $HeadURL: https://textpattern.googlecode.com/svn/releases/4.5.4/source/textpattern/lib/txplib_update.php $
   5  $LastChangedRevision: 4020 $
   6  */
   7  
   8  //-------------------------------------------------------------
   9  function install_language_from_file($lang)
  10  {
  11      $lang_file = txpath.'/lang/'.$lang.'.txt';
  12  
  13      if (is_file($lang_file) && is_readable($lang_file))
  14      {
  15          $lang_file = txpath.'/lang/'.$lang.'.txt';
  16          if (!is_file($lang_file) || !is_readable($lang_file)) return;
  17          $file = @fopen($lang_file, "r");
  18          if ($file) {
  19              $lastmod = @filemtime($lang_file);
  20              $lastmod = date('YmdHis',$lastmod);
  21              $data = $core_events = array();
  22              $event = '';
  23  
  24              while (!feof($file)) {
  25                  $line = fgets($file, 4096);
  26                  # ignore empty lines and simple comments (any line starting with #, not followed by @)
  27                  if(trim($line) === '' || ($line[0] == '#' && $line[1] != '@' && $line[1] != '#')) continue;
  28                  # if available use the lastmod time from the file
  29                  if (strpos($line,'#@version') === 0)
  30                  {    # Looks like: "#@version id;unixtimestamp"
  31                      @list($fversion,$ftime) = explode(';',trim(substr($line,strpos($line,' ',1))));
  32                      $lastmod = date("YmdHis",min($ftime, time()));
  33                  }
  34                  # each language section should be prefixed by #@
  35                  if($line[0] == '#' && $line[1] == '@')
  36                  {
  37                      if (!empty($data))
  38                      {
  39                          foreach ($data as $name => $value)
  40                          {
  41                              $value = addslashes($value);
  42                              $exists = mysql_query('SELECT name, lastmod FROM `'.PFX."txp_lang` WHERE `lang`='".$lang."' AND `name`='$name' AND `event`='$event'");
  43                              if ($exists) $exists = mysql_fetch_row($exists);
  44                              if ($exists[1])
  45                              {
  46                                  mysql_query("UPDATE `".PFX."txp_lang` SET `lastmod`='$lastmod', `data`='$value' WHERE `lang`='".$lang."' AND `name`='$name' AND `event`='$event'");
  47                                  echo mysql_error();
  48                              } else
  49                                  mysql_query("INSERT DELAYED INTO `".PFX."txp_lang`  SET    `lang`='".$lang."', `name`='$name', `lastmod`='$lastmod', `event`='$event', `data`='$value'");
  50                                  echo mysql_error();
  51                          }
  52                      }
  53                      # reset
  54                      $data = array();
  55                      $event = substr($line,2, (strlen($line)-2));
  56                      $event = rtrim($event);
  57                      if (strpos($event, 'version') === false) {
  58                          $core_events[] = $event;
  59                      }
  60                      continue;
  61                  }
  62  
  63                  # Guard against setup strings being loaded.
  64                  # TODO: Setup strings will be removed from the .txt files at some point; this check can then be removed
  65                  if ($event !== 'setup')
  66                  {
  67                      @list($name,$val) = explode(' => ',trim($line));
  68                      $data[$name] = $val;
  69                  }
  70              }
  71              # remember to add the last one
  72              if (!empty($data))
  73              {
  74                  foreach ($data as $name => $value)
  75                  {
  76                       mysql_query("INSERT DELAYED INTO `".PFX."txp_lang`  SET `lang`='".$lang."', `name`='$name', `lastmod`='$lastmod', `event`='$event', `data`='$value'");
  77                  }
  78              }
  79              mysql_query("DELETE FROM `".PFX."txp_lang`  WHERE `lang`='".$lang."' AND `event` IN ('".join("','", array_unique($core_events))."') AND `lastmod`>$lastmod");
  80              @fclose($filename);
  81              #delete empty fields if any
  82              mysql_query("DELETE FROM `".PFX."txp_lang` WHERE `data`=''");
  83              mysql_query("FLUSH TABLE `".PFX."txp_lang`");
  84  
  85              return true;
  86          }
  87      }
  88      return false;
  89  }
  90  
  91  ?>

title

Description

title

Description

title

Description

title

title

Body