[23421] | 1 | <?php |
---|
| 2 | defined('PLA_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | /** |
---|
| 5 | * list files of a plugin |
---|
[23467] | 6 | * @param: string $id, plugin id |
---|
| 7 | * @return: array of paths relative to plugin root |
---|
[23421] | 8 | */ |
---|
| 9 | function list_plugin_files($id, $path=null) |
---|
| 10 | { |
---|
| 11 | if (empty($path)) |
---|
| 12 | { |
---|
| 13 | $path = '/'; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | if ($path == '/language/') |
---|
| 17 | { |
---|
| 18 | return array(); |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | if (strlen($path)-strrpos($path, '_data/') == 6) |
---|
| 22 | { |
---|
| 23 | return array(); |
---|
| 24 | } |
---|
| 25 | |
---|
[23467] | 26 | if (($handle = @opendir(PHPWG_PLUGINS_PATH.$id.$path)) === false) |
---|
[23421] | 27 | { |
---|
| 28 | return array(); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | $data = array(); |
---|
| 32 | |
---|
| 33 | while ($entry = readdir($handle)) |
---|
| 34 | { |
---|
| 35 | if ($entry=='.' || $entry=='..' || $entry=='.svn' || $entry=='index.php') continue; |
---|
| 36 | |
---|
| 37 | if (is_dir(PHPWG_PLUGINS_PATH.$id.$path.$entry)) |
---|
| 38 | { |
---|
| 39 | $data = array_merge($data, list_plugin_files($id, $path.$entry.'/')); |
---|
| 40 | } |
---|
| 41 | else |
---|
| 42 | { |
---|
| 43 | $ext = strtolower(get_extension($entry)); |
---|
| 44 | if (in_array($ext, array('php', 'tpl'))) |
---|
| 45 | { |
---|
| 46 | $data[] = $path.$entry; |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | closedir($handle); |
---|
| 52 | |
---|
| 53 | return $data; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | /** |
---|
[23467] | 57 | * list language files of a plugin |
---|
| 58 | * @param: string $id, plugin id |
---|
| 59 | * @return: array, keys are basenames, values are paths relative to plugin root |
---|
| 60 | */ |
---|
| 61 | function list_plugin_languages_files($id) |
---|
| 62 | { |
---|
| 63 | $path = '/language/en_UK/'; |
---|
| 64 | |
---|
| 65 | if (($handle = @opendir(PHPWG_PLUGINS_PATH.$id.$path)) === false) |
---|
| 66 | { |
---|
| 67 | return array(); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | $data = array(); |
---|
| 71 | |
---|
| 72 | while ($entry = readdir($handle)) |
---|
| 73 | { |
---|
| 74 | if ($entry=='.' || $entry=='..' || $entry=='.svn' || $entry=='index.php') continue; |
---|
| 75 | |
---|
| 76 | if (!is_dir(PHPWG_PLUGINS_PATH.$id.$path.$entry)) |
---|
| 77 | { |
---|
| 78 | $ext = strtolower(get_extension($entry)); |
---|
| 79 | if ($ext == 'php') |
---|
| 80 | { |
---|
| 81 | $data[ basename($entry, '.php') ] = $path.$entry; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | closedir($handle); |
---|
| 87 | |
---|
| 88 | return $data; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | /** |
---|
[23421] | 92 | * list translated strings of a file |
---|
[23467] | 93 | * @param: string $path, file $path relative to main plugins folder |
---|
| 94 | * @return: array, keys are language strings, values are arrays of lines |
---|
[23421] | 95 | */ |
---|
| 96 | function analyze_file($path) |
---|
| 97 | { |
---|
| 98 | $lines = file(PHPWG_PLUGINS_PATH.$path, FILE_IGNORE_NEW_LINES); |
---|
| 99 | |
---|
| 100 | $strings = array(); |
---|
| 101 | |
---|
| 102 | foreach ($lines as $i => $line) |
---|
| 103 | { |
---|
| 104 | // l10n |
---|
[23449] | 105 | if (preg_match_all('#l10n\((?:\s*)(?:["\']{1})(.*?)(?:["\']{1})(?:\s*)\)#', $line, $matches)) |
---|
[23421] | 106 | { |
---|
| 107 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
| 108 | { |
---|
| 109 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | // translate |
---|
[23584] | 113 | if (preg_match_all('#\{(?:\\\\{0,1})(?:["\']{1})(.*?)(?:\\\\{0,1})(?:["\']{1})\|(?:@{0,1})translate#', $line, $matches)) |
---|
[23421] | 114 | { |
---|
| 115 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
| 116 | { |
---|
| 117 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
| 118 | } |
---|
| 119 | } |
---|
[23584] | 120 | // translate_dec |
---|
| 121 | if (preg_match_all('#translate_dec:(?:\\\\{0,1})(?:["\']{1})(.*?)(?:\\\\{0,1})(?:["\']{1}):(?:\\\\{0,1})(?:["\']{1})(.*?)(?:\\\\{0,1})(?:["\']{1})}#', $line, $matches)) |
---|
| 122 | { |
---|
| 123 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
| 124 | { |
---|
| 125 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
| 126 | $strings[ stripslashes($matches[2][$j]) ][] = $i+1; |
---|
| 127 | } |
---|
| 128 | } |
---|
[23421] | 129 | // l10n_dec on one line |
---|
[23449] | 130 | if (preg_match_all('#l10n_dec\((?:\s*)(?:["\']{1})(.*?)(?:["\']{1})(?:\s*),(?:\s*)(?:["\']{1})(.*?)(?:["\']{1})#', $line, $matches)) |
---|
[23421] | 131 | { |
---|
| 132 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
| 133 | { |
---|
| 134 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
| 135 | $strings[ stripslashes($matches[2][$j]) ][] = $i+1; |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | // l10n_dec on two or three lines |
---|
| 139 | else if (strpos($line, 'l10n_dec')!==false) |
---|
| 140 | { |
---|
| 141 | $three_lines = $lines[$i]; |
---|
| 142 | if (isset($lines[$i+1])) |
---|
| 143 | { |
---|
| 144 | $three_lines.= ' '.$lines[$i+1]; |
---|
| 145 | if (isset($lines[$i+2])) $three_lines.= ' '.$lines[$i+2]; |
---|
| 146 | } |
---|
| 147 | |
---|
[23449] | 148 | if (preg_match_all('#l10n_dec\((?:\s*)(?:["\']{1})(.*?)(?:["\']{1})(?:\s*),(?:\s*)(?:["\']{1})(.*?)(?:["\']{1})#', $three_lines, $matches)) |
---|
[23421] | 149 | { |
---|
| 150 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
| 151 | { |
---|
| 152 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
| 153 | $strings[ stripslashes($matches[2][$j]) ][] = $i+1; |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | return $strings; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | /** |
---|
[23467] | 163 | * get language files loaded in main.inc.php |
---|
| 164 | * @param: string $id, plugin id |
---|
| 165 | * @return: array of file basenames |
---|
| 166 | */ |
---|
| 167 | function get_loaded_in_main($id) |
---|
| 168 | { |
---|
| 169 | $content = file_get_contents(PHPWG_PLUGINS_PATH.$id.'/main.inc.php'); |
---|
| 170 | |
---|
| 171 | $files = array(); |
---|
| 172 | |
---|
| 173 | if (preg_match_all('#load_language\((?:\s*)(?:["\']{1})(.*?)(?:["\']{1})#', $content, $matches)) |
---|
| 174 | { |
---|
| 175 | $files = $matches[1]; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | return $files; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | /** |
---|
[23421] | 182 | * load a language file |
---|
| 183 | */ |
---|
| 184 | function load_language_file($path) |
---|
| 185 | { |
---|
| 186 | @include($path); |
---|
| 187 | if (!isset($lang)) return array(); |
---|
| 188 | return $lang; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | ?> |
---|