[23421] | 1 | <?php |
---|
| 2 | defined('PLA_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | global $template, $page; |
---|
| 5 | |
---|
| 6 | $page['active_menu'] = get_active_menu('updates'); |
---|
| 7 | |
---|
| 8 | include_once(PLA_PATH . 'include/functions.inc.php'); |
---|
[23472] | 9 | include_once(PHPWG_ROOT_PATH . 'admin/include/plugins.class.php'); |
---|
[23467] | 10 | $plugins = new plugins(); |
---|
[23421] | 11 | |
---|
[23472] | 12 | /* SELECT */ |
---|
[23421] | 13 | if (!isset($_GET['plugin_id'])) |
---|
| 14 | { |
---|
| 15 | $template->assign(array( |
---|
| 16 | 'PLA_STEP' => 'select', |
---|
[23467] | 17 | 'PLA_PLUGINS' => $plugins->fs_plugins, |
---|
[23421] | 18 | 'F_ACTION' => PLA_ADMIN, |
---|
| 19 | )); |
---|
| 20 | } |
---|
| 21 | |
---|
[23472] | 22 | /* CONFIG */ |
---|
[23421] | 23 | else if (!isset($_GET['analyze'])) |
---|
| 24 | { |
---|
| 25 | $files = list_plugin_files($_GET['plugin_id']); |
---|
[23467] | 26 | $language_files = list_plugin_languages_files($_GET['plugin_id']); |
---|
[23421] | 27 | |
---|
[23467] | 28 | $default_lang_files = get_loaded_in_main($_GET['plugin_id']); |
---|
| 29 | if (empty($default_lang_files)) |
---|
| 30 | { |
---|
| 31 | $default_lang_files = count($language_files)==1 ? array_keys($language_files) : ( |
---|
| 32 | array_key_exists('plugin.lang', $language_files) ? array('plugin.lang') : array() |
---|
| 33 | ); |
---|
| 34 | } |
---|
| 35 | |
---|
[23473] | 36 | if (file_exists(PLA_DATA.$_GET['plugin_id'].'.php')) |
---|
[23421] | 37 | { |
---|
[23473] | 38 | $saved_files = include(PLA_DATA.$_GET['plugin_id'].'.php'); |
---|
[23421] | 39 | } |
---|
| 40 | else |
---|
| 41 | { |
---|
| 42 | $saved_files = array(); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | foreach ($files as &$file) |
---|
| 46 | { |
---|
[23472] | 47 | if (isset($saved_files[ $file ])) |
---|
[23421] | 48 | { |
---|
[23472] | 49 | $file = $saved_files[ $file ]; |
---|
[23467] | 50 | $file['lang_files'] = array_intersect($file['lang_files'], array_keys($language_files)); |
---|
[23421] | 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | $file = array( |
---|
| 55 | 'path' => $file, |
---|
| 56 | 'is_admin' => strpos($file, '/admin') === 0, |
---|
[23467] | 57 | 'lang_files' => $default_lang_files |
---|
[23421] | 58 | ); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | unset($file); |
---|
| 62 | |
---|
| 63 | $template->assign(array( |
---|
| 64 | 'PLA_STEP' => 'config', |
---|
[23467] | 65 | 'PLA_PLUGIN' => $plugins->fs_plugins[ $_GET['plugin_id'] ], |
---|
[23421] | 66 | 'PLA_FILES' => $files, |
---|
[23472] | 67 | 'PLA_LANG_FILES' => array_keys($language_files), |
---|
[23421] | 68 | 'F_ACTION' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'].'&analyze', |
---|
| 69 | 'U_BACK' => PLA_ADMIN, |
---|
| 70 | )); |
---|
| 71 | } |
---|
[23472] | 72 | |
---|
| 73 | /* ANALYSIS */ |
---|
[23421] | 74 | else |
---|
| 75 | { |
---|
| 76 | // save |
---|
| 77 | if (isset($_POST['files'])) |
---|
| 78 | { |
---|
| 79 | $files = array(); |
---|
[23467] | 80 | foreach ($_POST['files'] as $file => $data) |
---|
[23421] | 81 | { |
---|
[23472] | 82 | $files[ $file ] = array( |
---|
[23421] | 83 | 'path' => $file, |
---|
[23467] | 84 | 'is_admin' => $data['is_admin']=='true', |
---|
| 85 | 'lang_files' => array(), |
---|
[23421] | 86 | ); |
---|
[23467] | 87 | if (!empty($data['lang_files'])) |
---|
| 88 | { |
---|
[23472] | 89 | $files[ $file ]['lang_files'] = array_keys(array_filter($data['lang_files'], create_function('$f', 'return $f=="true";'))); |
---|
[23467] | 90 | } |
---|
[23421] | 91 | } |
---|
| 92 | |
---|
| 93 | $content = "<?php\nreturn "; |
---|
[23467] | 94 | $content.= var_export($files, true); |
---|
[23421] | 95 | $content.= ";\n?>"; |
---|
| 96 | |
---|
[23473] | 97 | @mkdir(PLA_DATA, true, 0755); |
---|
| 98 | file_put_contents(PLA_DATA.$_GET['plugin_id'].'.php', $content); |
---|
[23421] | 99 | } |
---|
| 100 | else |
---|
| 101 | { |
---|
[23473] | 102 | $files = include(PLA_DATA.$_GET['plugin_id'].'.php'); |
---|
[23421] | 103 | } |
---|
| 104 | |
---|
| 105 | $strings = array(); |
---|
| 106 | $counts = array('ok'=>0,'missing'=>0,'useless'=>0); |
---|
| 107 | |
---|
| 108 | // get strings list |
---|
| 109 | foreach ($files as $file => $file_data) |
---|
| 110 | { |
---|
| 111 | $file_strings = analyze_file($_GET['plugin_id'].$file); |
---|
| 112 | |
---|
| 113 | foreach ($file_strings as $string => $lines) |
---|
| 114 | { |
---|
[23467] | 115 | $strings[ $string ]['files'][ $file ] = $file_data + array('lines' => $lines); |
---|
[23421] | 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | // load language files |
---|
| 120 | $lang_common = load_language_file(PHPWG_ROOT_PATH.'language/en_UK/common.lang.php'); |
---|
| 121 | $lang_admin = load_language_file(PHPWG_ROOT_PATH.'language/en_UK/admin.lang.php'); |
---|
| 122 | |
---|
[23467] | 123 | $language_files = list_plugin_languages_files($_GET['plugin_id']); |
---|
| 124 | foreach ($language_files as $name => $path) |
---|
| 125 | { |
---|
| 126 | $lang_plugin[ $name ] = load_language_file(PHPWG_PLUGINS_PATH.$_GET['plugin_id'].$path); |
---|
| 127 | } |
---|
| 128 | |
---|
[23472] | 129 | // analyse |
---|
[23421] | 130 | foreach ($strings as $string => &$string_data) |
---|
| 131 | { |
---|
[23472] | 132 | // find where the string is defined |
---|
[23421] | 133 | $string_data['in_common'] = array_key_exists($string, $lang_common); |
---|
| 134 | $string_data['in_admin'] = array_key_exists($string, $lang_admin); |
---|
[23467] | 135 | $string_data['in_plugin'] = array(); |
---|
| 136 | foreach ($language_files as $name => $path) |
---|
| 137 | { |
---|
| 138 | if (array_key_exists($string, $lang_plugin[$name])) $string_data['in_plugin'][] = $name; |
---|
| 139 | } |
---|
[23421] | 140 | |
---|
[23472] | 141 | // very rare case |
---|
| 142 | if (count($string_data['in_plugin'])>1) |
---|
| 143 | { |
---|
| 144 | $string_data['warnings'][] = l10n('This string is translated in multiple files'); |
---|
| 145 | } |
---|
| 146 | |
---|
[23467] | 147 | $missing = $useless = $ok = false; |
---|
| 148 | $string_data['is_admin'] = true; |
---|
| 149 | |
---|
[23472] | 150 | // analyse for each file where the string exists |
---|
[23467] | 151 | foreach ($string_data['files'] as $file => &$file_data) |
---|
[23421] | 152 | { |
---|
[23467] | 153 | // the string is "admin" if all files are "admin" |
---|
| 154 | $string_data['is_admin'] &= $file_data['is_admin']; |
---|
| 155 | |
---|
| 156 | // find if the string is translated in one of the language files included in this file |
---|
[23472] | 157 | $exists = count(array_intersect($file_data['lang_files'], $string_data['in_plugin'])) > 0; |
---|
[23467] | 158 | |
---|
| 159 | // useless if translated in the plugin AND in common or admin |
---|
| 160 | if ($exists && ($string_data['in_common'] || ($file_data['is_admin'] && $string_data['in_admin']))) |
---|
| 161 | { |
---|
| 162 | $file_data['stat'] = 'useless'; |
---|
| 163 | $useless = true; |
---|
| 164 | } |
---|
| 165 | // missing if not translated in the plugin NOR in common or admin |
---|
| 166 | else if (!$exists && !$string_data['in_common'] && (!$file_data['is_admin'] || !$string_data['in_admin'])) |
---|
| 167 | { |
---|
| 168 | $file_data['stat'] = 'missing'; |
---|
| 169 | $missing = true; |
---|
| 170 | } |
---|
| 171 | // else ok |
---|
| 172 | else |
---|
| 173 | { |
---|
| 174 | $file_data['stat'] = 'ok'; |
---|
| 175 | $ok = true; |
---|
| 176 | } |
---|
[23421] | 177 | } |
---|
[23467] | 178 | unset($file_data); |
---|
| 179 | |
---|
| 180 | // string is missing if at least missing in one file |
---|
| 181 | if ($missing) |
---|
[23421] | 182 | { |
---|
| 183 | $string_data['stat'] = 'missing'; |
---|
| 184 | $counts['missing']++; |
---|
| 185 | } |
---|
[23467] | 186 | // string is useless if useless in all files |
---|
| 187 | else if ($useless && !$ok) |
---|
| 188 | { |
---|
| 189 | $string_data['stat'] = 'useless'; |
---|
| 190 | $counts['useless']++; |
---|
| 191 | } |
---|
| 192 | // else ok |
---|
[23421] | 193 | else |
---|
| 194 | { |
---|
[23472] | 195 | // another very rare case |
---|
| 196 | if ($useless) |
---|
| 197 | { |
---|
| 198 | $string_data['warnings'][] = l10n('This string is useless in some files'); |
---|
| 199 | } |
---|
| 200 | |
---|
[23421] | 201 | $string_data['stat'] = 'ok'; |
---|
| 202 | $counts['ok']++; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | unset($string_data); |
---|
| 206 | |
---|
[23488] | 207 | // unused strings |
---|
| 208 | $unused = array(); |
---|
| 209 | foreach ($language_files as $name => $path) |
---|
| 210 | { |
---|
| 211 | $unused = array_merge($unused, array_diff_key($lang_plugin[ $name ], $strings)); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | foreach ($unused as $string => $translation) |
---|
| 215 | { |
---|
| 216 | $string_data = array( |
---|
| 217 | 'files' => array(), |
---|
| 218 | 'in_common' => array_key_exists($string, $lang_common), |
---|
| 219 | 'in_admin' => array_key_exists($string, $lang_admin), |
---|
| 220 | 'in_plugin' => array(), |
---|
| 221 | 'stat' => 'useless', |
---|
| 222 | 'is_admin' => false, |
---|
| 223 | 'warning' => array(l10n('This string is not used anywhere in the plugin')), |
---|
| 224 | ); |
---|
| 225 | |
---|
| 226 | foreach ($language_files as $name => $path) |
---|
| 227 | { |
---|
| 228 | if (array_key_exists($string, $lang_plugin[$name])) $string_data['in_plugin'][] = $name; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | $strings[ $string ] = $string_data; |
---|
[23584] | 232 | $counts['useless']++; |
---|
[23488] | 233 | } |
---|
| 234 | |
---|
[23472] | 235 | uksort($strings, 'strnatcasecmp'); // natural sort |
---|
[23421] | 236 | $counts['total'] = array_sum($counts); |
---|
| 237 | |
---|
| 238 | $template->assign(array( |
---|
| 239 | 'PLA_STEP' => 'analysis', |
---|
[23467] | 240 | 'PLA_PLUGIN' => $plugins->fs_plugins[ $_GET['plugin_id'] ], |
---|
[23421] | 241 | 'PLA_STRINGS' => $strings, |
---|
[23472] | 242 | 'PLA_LANG_FILES' => array_keys($language_files), |
---|
[23421] | 243 | 'PLA_COUNTS' => $counts, |
---|
| 244 | 'U_BACK' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'], |
---|
| 245 | )); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | // template vars |
---|
| 249 | $template->assign(array( |
---|
| 250 | 'PLA_PATH'=> PLA_PATH, |
---|
[23472] | 251 | 'PLA_ABS_PATH'=> realpath(PLA_PATH).'/', |
---|
[23421] | 252 | 'PLA_ADMIN' => PLA_ADMIN, |
---|
| 253 | )); |
---|
| 254 | |
---|
| 255 | $template->set_filename('pla_content', realpath(PLA_PATH.'template/main.tpl')); |
---|
| 256 | $template->assign_var_from_handle('ADMIN_CONTENT', 'pla_content'); |
---|
| 257 | |
---|
| 258 | ?> |
---|