[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/include/ -> updateLangFiles.php (source)

   1  <?php
   2  /* 
   3   * phpMyVisites : website statistics and audience measurements
   4   * Copyright (C) 2002 - 2006
   5   * http://www.phpmyvisites.net/ 
   6   * phpMyVisites is free software (license GNU/GPL)
   7   * Authors : phpMyVisites team
   8  */
   9  
  10  // $Id: updateLangFiles.php 87 2006-09-15 19:05:30Z matthieu_ $
  11  
  12  
  13  //=========
  14  // HOW TO
  15  //=========
  16  // - backup /langs/ directory
  17  // - copy paste new languages files version
  18  // - run the script directly 
  19  // - look at the result in the output dir
  20  // - copy paste from the output dir in the /langs/ dir if OK
  21  
  22  
  23  error_reporting(E_ALL);
  24  
  25  define('LANGS_PATH', '../../langs/');
  26  define('ORIGINAL_FILE', 'en-utf-8.php');
  27  define('ORIGINAL_FILE_PATH', LANGS_PATH . 'en-utf-8.php');
  28  define('PATH_DESTINATION', LANGS_PATH . 'afterUpdate/');
  29  
  30  if(!function_exists('file_put_contents')) {
  31   function file_put_contents($filename, $data, $file_append = false) {
  32    $fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
  33    if(!$fp) {
  34     trigger_error('file_put_contents ne peut pas écrire dans le fichier.', E_USER_ERROR);
  35     return;
  36    }
  37    fputs($fp, $data);
  38    fclose($fp);
  39   }
  40  }
  41  
  42  function copyArrayInFile( $file, &$a)
  43  {
  44      $contenu = '';
  45      foreach($a as $l) $contenu.=$l;
  46      file_put_contents($file, $contenu);
  47  }
  48  
  49  function getFileInArray( $file)
  50  {
  51      $f = fopen( $file, 'r');
  52      if(!$f) { print("Error loading $file..."); return;}
  53      while (!feof($f))
  54          $return[] = fgets($f, 4096);
  55      return $return;
  56  }
  57  
  58  function getLangFiles()
  59  {
  60      $handle = opendir( LANGS_PATH );
  61      while ($file = readdir($handle)) 
  62      {
  63          print("<br>To analyse : ". $file);
  64          if (strpos($file, '-utf-8.php') && $file != ORIGINAL_FILE)
  65          {
  66              print(" YES ");
  67              $return[] = LANGS_PATH . $file;
  68          }
  69      }
  70      if(sizeof($return) == 0)
  71          print("No lang file detected.");
  72      return $return;
  73  }
  74  
  75  // Tests
  76  //======
  77  //var_dump( getFileInArray('./en-utf-8.php') );
  78  // $a = array('toto' => 'titi', 'tata' => 1 );
  79  // copyArrayInFile( 'test.php', $a );
  80  
  81  function searchForStringInArray( $stringToSearch, $old)
  82  {
  83      // go throught new from currentLine
  84      $stop = sizeof($old);
  85      //print("search for $stringToSearch...");
  86      for($i = 0;$i < $stop; $i++)
  87      {
  88          if(substr_count($old[$i], $stringToSearch) == 1)
  89          {
  90          //    print("found!<br>");
  91              return $old[$i];
  92          }
  93      }
  94      //print("not found!<br>");
  95      return false;
  96      // if ereg string
  97      // return whole line
  98      // else false
  99  }
 100  
 101  // opens original files and save in array
 102  $english = getFileInArray( ORIGINAL_FILE_PATH );
 103  
 104  $all = getLangFiles();
 105  
 106  //$all = array('../../langs/cz-utf-8.php'); //, '../../langs/si-utf-8.php');
 107  
 108  foreach($all as $file)
 109  {
 110      print($file."<br><br>");
 111      $fileDestination = PATH_DESTINATION. substr($file, strrpos( $file, '/') + 1) ;
 112      print("<br>".$fileDestination);
 113  
 114      $new = $english;
 115      $old = getFileInArray( $file );
 116      
 117      // algo
 118      // go througt $new file
 119      $currentLine = 0;
 120      foreach($new as $newLine)
 121      {
 122          $stringToSearch = '';
 123          if(ereg("] =", $newLine))
 124          {
 125              $stringToSearch = substr( $newLine, 0, strpos( $newLine, '='));
 126          //    print($stringToSearch . "<br>");
 127          }
 128          elseif(ereg("=>", $newLine))
 129          {
 130              $stringToSearch = substr( $newLine, 1, strpos( $newLine, '=>'));
 131          //    print($stringToSearch . "<br>");
 132          }    
 133  
 134          if( !empty($stringToSearch) 
 135                  && $oldLineWhichIsOk = searchForStringInArray( $stringToSearch, $old))
 136          {
 137              $new[$currentLine] = $oldLineWhichIsOk;
 138          }
 139          $currentLine++;
 140      }
 141      flush();
 142      // foreach '] =
 143      // search the string before = in the $old file
 144      // if found, copy the old string in the new one
 145  
 146      // TODO: Countries copy
 147      // saves new file in $fileDestination
 148      copyArrayInFile( $fileDestination, $new );
 149  }
 150  
 151  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics