• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

LangVarAnalyzer.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00025 
00026 // language variables analyzer
00027 // a.killing, ilias opensource
00028 
00029 
00030 class ilLangVarAnalyzer
00031 {
00032         var $dirs;
00033         var $ftypes;
00034         var $langvar;
00035         var $common;
00036         var $others;
00037 
00038         function setDirectories($a_dirs)
00039         {
00040                 $this->dirs = $a_dirs;
00041         }
00042 
00043         function setFileTypes($a_ftypes)
00044         {
00045                 $this->ftypes = $a_ftypes;
00046         }
00047 
00048         function getSuffix($a_file)
00049         {
00050                 $dotpos = strrpos($a_file, ".");
00051                 return substr($a_file, $dotpos, strlen($a_file) - $dotpos);
00052         }
00053 
00054         function parseFiles()
00055         {
00056                 foreach ($this->dirs as $dir)
00057                 {
00058                         if (is_dir($dir))
00059                         {
00060                                 $dirh = opendir($dir);
00061                                 while (false !== ($file = readdir($dirh)))
00062                                 {
00063                                         if (in_array($this->getSuffix($file), $this->ftypes))
00064                                         {
00065                                                 $fullname = $dir."/".$file;
00066                                                 //if($fullname == "./login.php")
00067                                                 $this->parseCode($fullname);
00068                                         }
00069                                 }
00070                         }
00071                 }
00072         }
00073 
00074         function parseCode($a_file)
00075         {
00076                 $fileh = fopen($a_file, "r");
00077                 $code = fread($fileh, filesize($a_file));
00078                 //if (eregi("lng->txt/(\"(([0-9]|_|[a-z]|[A-Z])*)\"/)", $code, $found))
00079                 while (eregi("lng->txt\(\"([^\)]*)\"\)", $code, $found))
00080                 {
00081                         $this->langvar[$found[1]][] = $a_file;
00082                         $code = str_replace($found[0], "", $code);
00083                 }
00084 
00085                 fclose($fileh);
00086         }
00087 
00088         function printVars()
00089         {
00090                 ksort($this->langvar);
00091                 reset($this->langvar);
00092                 foreach ($this->langvar as $langvar => $files)
00093                 {
00094                         echo $langvar." <b>".count($files)."</b> ".implode(", ", $files)."<br>";
00095                 }
00096         }
00097 
00098         function catVars()
00099         {
00100                 reset($this->langvar);
00101                 foreach ($this->langvar as $langvar => $files)
00102                 {
00103                         $cnt = count($files);
00104                         if ($cnt == 1)
00105                                 $this->others[$files[0]][] = $langvar;
00106                         else
00107                                 $this->common[$langvar] = $cnt;
00108                 }
00109                 arsort($this->common);
00110                 ksort($this->others);
00111         }
00112 
00113         function printCommons()
00114         {
00115                 reset($this->common);
00116                 foreach ($this->common as $langvar => $cnt)
00117                 {
00118                         echo $langvar." <b>".$cnt."</b> ".implode(", ", $this->langvar[$langvar])."<br>";
00119                 }
00120         }
00121 
00122 
00123         function printOthers()
00124         {
00125                 reset($this->others);
00126                 foreach ($this->others as $file => $langvars)
00127                 {
00128                         echo $langvar." <b>".$file." (".count($langvars).")</b>: ".implode(", ", $langvars)."<br>";
00129                 }
00130         }
00131 
00132         //function get
00133 
00134 }
00135 
00136 $analyzer = new ilLangVarAnalyzer();
00137 $analyzer->setDirectories(array(".", "./classes", "./include"));
00138 $analyzer->setFileTypes(array(".php"));
00139 //$analyzer->setLangFile("./lang/ilias_en.lang");
00140 $analyzer->parseFiles();
00141 $analyzer->catVars();
00142 //$analyzer->printCommons();
00143 $analyzer->printOthers();
00144 
00145 ?>

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1