Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
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
00133
00134 }
00135
00136 $analyzer = new ilLangVarAnalyzer();
00137 $analyzer->setDirectories(array(".", "./classes", "./include"));
00138 $analyzer->setFileTypes(array(".php"));
00139
00140 $analyzer->parseFiles();
00141 $analyzer->catVars();
00142
00143 $analyzer->printOthers();
00144
00145 ?>