[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, |
---|
[25677] | 18 | 'F_ACTION' => PLA_ADMIN.'&config', |
---|
[23421] | 19 | )); |
---|
| 20 | } |
---|
| 21 | |
---|
[23472] | 22 | /* CONFIG */ |
---|
[25677] | 23 | else if (isset($_GET['config'])) |
---|
[23421] | 24 | { |
---|
| 25 | $files = list_plugin_files($_GET['plugin_id']); |
---|
[23467] | 26 | $language_files = list_plugin_languages_files($_GET['plugin_id']); |
---|
[28876] | 27 | $default_lang_files = get_loaded_in_main($_GET['plugin_id']); |
---|
[23421] | 28 | |
---|
[23467] | 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 | |
---|
[28876] | 45 | global $language_files, $default_lang_files; |
---|
| 46 | populate_plugin_files($files, $saved_files); |
---|
| 47 | |
---|
[23421] | 48 | $template->assign(array( |
---|
| 49 | 'PLA_STEP' => 'config', |
---|
[23467] | 50 | 'PLA_PLUGIN' => $plugins->fs_plugins[ $_GET['plugin_id'] ], |
---|
[23421] | 51 | 'PLA_FILES' => $files, |
---|
[23472] | 52 | 'PLA_LANG_FILES' => array_keys($language_files), |
---|
[23421] | 53 | 'F_ACTION' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'].'&analyze', |
---|
| 54 | 'U_BACK' => PLA_ADMIN, |
---|
| 55 | )); |
---|
| 56 | } |
---|
[23472] | 57 | |
---|
| 58 | /* ANALYSIS */ |
---|
[25677] | 59 | else if (isset($_GET['analyze'])) |
---|
[23421] | 60 | { |
---|
| 61 | // save |
---|
| 62 | if (isset($_POST['files'])) |
---|
| 63 | { |
---|
[28876] | 64 | $files = $_POST['files']; |
---|
| 65 | clean_files_from_config($files); |
---|
[23421] | 66 | |
---|
| 67 | $content = "<?php\nreturn "; |
---|
[23467] | 68 | $content.= var_export($files, true); |
---|
[28876] | 69 | $content.= ";\n"; |
---|
[23421] | 70 | |
---|
[23473] | 71 | @mkdir(PLA_DATA, true, 0755); |
---|
| 72 | file_put_contents(PLA_DATA.$_GET['plugin_id'].'.php', $content); |
---|
[23421] | 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
[23473] | 76 | $files = include(PLA_DATA.$_GET['plugin_id'].'.php'); |
---|
[23421] | 77 | } |
---|
| 78 | |
---|
| 79 | $counts = array('ok'=>0,'missing'=>0,'useless'=>0); |
---|
| 80 | |
---|
| 81 | // get strings list |
---|
[28876] | 82 | $strings = analyze_files($_GET['plugin_id'], $files); |
---|
[23421] | 83 | |
---|
| 84 | // load language files |
---|
| 85 | $lang_common = load_language_file(PHPWG_ROOT_PATH.'language/en_UK/common.lang.php'); |
---|
| 86 | $lang_admin = load_language_file(PHPWG_ROOT_PATH.'language/en_UK/admin.lang.php'); |
---|
| 87 | |
---|
[23467] | 88 | $language_files = list_plugin_languages_files($_GET['plugin_id']); |
---|
| 89 | foreach ($language_files as $name => $path) |
---|
| 90 | { |
---|
| 91 | $lang_plugin[ $name ] = load_language_file(PHPWG_PLUGINS_PATH.$_GET['plugin_id'].$path); |
---|
| 92 | } |
---|
| 93 | |
---|
[23472] | 94 | // analyse |
---|
[23421] | 95 | foreach ($strings as $string => &$string_data) |
---|
| 96 | { |
---|
[23472] | 97 | // find where the string is defined |
---|
[23421] | 98 | $string_data['in_common'] = array_key_exists($string, $lang_common); |
---|
| 99 | $string_data['in_admin'] = array_key_exists($string, $lang_admin); |
---|
[23467] | 100 | $string_data['in_plugin'] = array(); |
---|
| 101 | foreach ($language_files as $name => $path) |
---|
| 102 | { |
---|
| 103 | if (array_key_exists($string, $lang_plugin[$name])) $string_data['in_plugin'][] = $name; |
---|
| 104 | } |
---|
[23421] | 105 | |
---|
[23472] | 106 | // very rare case |
---|
| 107 | if (count($string_data['in_plugin'])>1) |
---|
| 108 | { |
---|
| 109 | $string_data['warnings'][] = l10n('This string is translated in multiple files'); |
---|
| 110 | } |
---|
| 111 | |
---|
[23467] | 112 | $missing = $useless = $ok = false; |
---|
| 113 | $string_data['is_admin'] = true; |
---|
| 114 | |
---|
[23472] | 115 | // analyse for each file where the string exists |
---|
[23467] | 116 | foreach ($string_data['files'] as $file => &$file_data) |
---|
[23421] | 117 | { |
---|
[23467] | 118 | // the string is "admin" if all files are "admin" |
---|
| 119 | $string_data['is_admin'] &= $file_data['is_admin']; |
---|
| 120 | |
---|
| 121 | // find if the string is translated in one of the language files included in this file |
---|
[23472] | 122 | $exists = count(array_intersect($file_data['lang_files'], $string_data['in_plugin'])) > 0; |
---|
[23467] | 123 | |
---|
| 124 | // useless if translated in the plugin AND in common or admin |
---|
| 125 | if ($exists && ($string_data['in_common'] || ($file_data['is_admin'] && $string_data['in_admin']))) |
---|
| 126 | { |
---|
| 127 | $file_data['stat'] = 'useless'; |
---|
| 128 | $useless = true; |
---|
| 129 | } |
---|
| 130 | // missing if not translated in the plugin NOR in common or admin |
---|
| 131 | else if (!$exists && !$string_data['in_common'] && (!$file_data['is_admin'] || !$string_data['in_admin'])) |
---|
| 132 | { |
---|
| 133 | $file_data['stat'] = 'missing'; |
---|
| 134 | $missing = true; |
---|
| 135 | } |
---|
| 136 | // else ok |
---|
| 137 | else |
---|
| 138 | { |
---|
| 139 | $file_data['stat'] = 'ok'; |
---|
| 140 | $ok = true; |
---|
| 141 | } |
---|
[23421] | 142 | } |
---|
[23467] | 143 | unset($file_data); |
---|
| 144 | |
---|
| 145 | // string is missing if at least missing in one file |
---|
| 146 | if ($missing) |
---|
[23421] | 147 | { |
---|
| 148 | $string_data['stat'] = 'missing'; |
---|
| 149 | $counts['missing']++; |
---|
| 150 | } |
---|
[23467] | 151 | // string is useless if useless in all files |
---|
| 152 | else if ($useless && !$ok) |
---|
| 153 | { |
---|
| 154 | $string_data['stat'] = 'useless'; |
---|
| 155 | $counts['useless']++; |
---|
| 156 | } |
---|
| 157 | // else ok |
---|
[23421] | 158 | else |
---|
| 159 | { |
---|
[23472] | 160 | // another very rare case |
---|
| 161 | if ($useless) |
---|
| 162 | { |
---|
| 163 | $string_data['warnings'][] = l10n('This string is useless in some files'); |
---|
| 164 | } |
---|
| 165 | |
---|
[23421] | 166 | $string_data['stat'] = 'ok'; |
---|
| 167 | $counts['ok']++; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | unset($string_data); |
---|
| 171 | |
---|
[23488] | 172 | // unused strings |
---|
| 173 | $unused = array(); |
---|
| 174 | foreach ($language_files as $name => $path) |
---|
| 175 | { |
---|
| 176 | $unused = array_merge($unused, array_diff_key($lang_plugin[ $name ], $strings)); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | foreach ($unused as $string => $translation) |
---|
| 180 | { |
---|
| 181 | $string_data = array( |
---|
| 182 | 'files' => array(), |
---|
| 183 | 'in_common' => array_key_exists($string, $lang_common), |
---|
| 184 | 'in_admin' => array_key_exists($string, $lang_admin), |
---|
| 185 | 'in_plugin' => array(), |
---|
| 186 | 'stat' => 'useless', |
---|
| 187 | 'is_admin' => false, |
---|
| 188 | 'warning' => array(l10n('This string is not used anywhere in the plugin')), |
---|
| 189 | ); |
---|
| 190 | |
---|
| 191 | foreach ($language_files as $name => $path) |
---|
| 192 | { |
---|
| 193 | if (array_key_exists($string, $lang_plugin[$name])) $string_data['in_plugin'][] = $name; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | $strings[ $string ] = $string_data; |
---|
[23584] | 197 | $counts['useless']++; |
---|
[23488] | 198 | } |
---|
| 199 | |
---|
[23472] | 200 | uksort($strings, 'strnatcasecmp'); // natural sort |
---|
[23421] | 201 | $counts['total'] = array_sum($counts); |
---|
| 202 | |
---|
| 203 | $template->assign(array( |
---|
| 204 | 'PLA_STEP' => 'analysis', |
---|
[23467] | 205 | 'PLA_PLUGIN' => $plugins->fs_plugins[ $_GET['plugin_id'] ], |
---|
[23421] | 206 | 'PLA_STRINGS' => $strings, |
---|
[23472] | 207 | 'PLA_LANG_FILES' => array_keys($language_files), |
---|
[23421] | 208 | 'PLA_COUNTS' => $counts, |
---|
[25677] | 209 | 'U_BACK' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'].'&config', |
---|
[26059] | 210 | 'U_REFRESH' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'].'&analyze', |
---|
[23421] | 211 | )); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | // template vars |
---|
| 215 | $template->assign(array( |
---|
| 216 | 'PLA_PATH'=> PLA_PATH, |
---|
[23472] | 217 | 'PLA_ABS_PATH'=> realpath(PLA_PATH).'/', |
---|
[23421] | 218 | 'PLA_ADMIN' => PLA_ADMIN, |
---|
| 219 | )); |
---|
| 220 | |
---|
| 221 | $template->set_filename('pla_content', realpath(PLA_PATH.'template/main.tpl')); |
---|
| 222 | $template->assign_var_from_handle('ADMIN_CONTENT', 'pla_content'); |
---|