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'); |
---|
9 | |
---|
10 | |
---|
11 | /* PLUGINS LIST */ |
---|
12 | if (!isset($_GET['plugin_id'])) |
---|
13 | { |
---|
14 | $query = ' |
---|
15 | SELECT * |
---|
16 | FROM '.PLUGINS_TABLE.' |
---|
17 | ORDER BY LOWER(id) |
---|
18 | ;'; |
---|
19 | |
---|
20 | $plugins = hash_from_query($query, 'id'); |
---|
21 | |
---|
22 | $template->assign(array( |
---|
23 | 'PLA_STEP' => 'select', |
---|
24 | 'PLA_PLUGINS' => $plugins, |
---|
25 | 'F_ACTION' => PLA_ADMIN, |
---|
26 | )); |
---|
27 | } |
---|
28 | |
---|
29 | /* FILES LIST */ |
---|
30 | else if (!isset($_GET['analyze'])) |
---|
31 | { |
---|
32 | $files = list_plugin_files($_GET['plugin_id']); |
---|
33 | |
---|
34 | if (file_exists(PLA_PATH.'_data/'.$_GET['plugin_id'].'.php')) |
---|
35 | { |
---|
36 | list($filename, $saved_files) = @include(PLA_PATH.'_data/'.$_GET['plugin_id'].'.php'); |
---|
37 | } |
---|
38 | else |
---|
39 | { |
---|
40 | $saved_files = array(); |
---|
41 | $filename = 'plugin.lang.php'; |
---|
42 | } |
---|
43 | |
---|
44 | foreach ($files as &$file) |
---|
45 | { |
---|
46 | if (isset($saved_files[$file])) |
---|
47 | { |
---|
48 | $file = $saved_files[$file]; |
---|
49 | } |
---|
50 | else |
---|
51 | { |
---|
52 | $file = array( |
---|
53 | 'path' => $file, |
---|
54 | 'is_admin' => strpos($file, '/admin') === 0, |
---|
55 | ); |
---|
56 | } |
---|
57 | } |
---|
58 | unset($file); |
---|
59 | |
---|
60 | $template->assign(array( |
---|
61 | 'PLA_STEP' => 'config', |
---|
62 | 'PLA_PLUGIN' => $_GET['plugin_id'], |
---|
63 | 'PLA_FILES' => $files, |
---|
64 | 'PLA_FILENAME' => $filename, |
---|
65 | 'F_ACTION' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'].'&analyze', |
---|
66 | 'U_BACK' => PLA_ADMIN, |
---|
67 | )); |
---|
68 | } |
---|
69 | else |
---|
70 | { |
---|
71 | // save |
---|
72 | if (isset($_POST['files'])) |
---|
73 | { |
---|
74 | $filename = $_POST['filename']; |
---|
75 | |
---|
76 | $files = array(); |
---|
77 | foreach ($_POST['files'] as $file => $is_admin) |
---|
78 | { |
---|
79 | $files[$file] = array( |
---|
80 | 'path' => $file, |
---|
81 | 'is_admin' => $is_admin=='true', |
---|
82 | ); |
---|
83 | } |
---|
84 | |
---|
85 | $content = "<?php\nreturn "; |
---|
86 | $content.= var_export(array($filename, $files), true); |
---|
87 | $content.= ";\n?>"; |
---|
88 | |
---|
89 | @mkdir(PLA_PATH.'_data/', true, 0755); |
---|
90 | file_put_contents(PLA_PATH.'_data/'.$_GET['plugin_id'].'.php', $content); |
---|
91 | } |
---|
92 | else |
---|
93 | { |
---|
94 | list($filename, $files) = include(PLA_PATH.'_data/'.$_GET['plugin_id'].'.php'); |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | $strings = array(); |
---|
99 | $counts = array('ok'=>0,'missing'=>0,'useless'=>0); |
---|
100 | |
---|
101 | // get strings list |
---|
102 | foreach ($files as $file => $file_data) |
---|
103 | { |
---|
104 | $file_strings = analyze_file($_GET['plugin_id'].$file); |
---|
105 | |
---|
106 | foreach ($file_strings as $string => $lines) |
---|
107 | { |
---|
108 | if (empty($strings[ $string ])) |
---|
109 | $strings[ $string ]['is_admin'] = $file_data['is_admin']; |
---|
110 | else |
---|
111 | $strings[ $string ]['is_admin'] = $strings[ $string ]['is_admin'] && $file_data['is_admin']; |
---|
112 | |
---|
113 | $strings[ $string ]['files'][ $file ] = $lines; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | // load language files |
---|
118 | $lang_common = load_language_file(PHPWG_ROOT_PATH.'language/en_UK/common.lang.php'); |
---|
119 | $lang_admin = load_language_file(PHPWG_ROOT_PATH.'language/en_UK/admin.lang.php'); |
---|
120 | $lang_plugin = load_language_file(PHPWG_PLUGINS_PATH.$_GET['plugin_id'].'/language/en_UK/'.$filename); |
---|
121 | |
---|
122 | // analyze |
---|
123 | foreach ($strings as $string => &$string_data) |
---|
124 | { |
---|
125 | $string_data['in_common'] = array_key_exists($string, $lang_common); |
---|
126 | $string_data['in_admin'] = array_key_exists($string, $lang_admin); |
---|
127 | $string_data['in_plugin'] = array_key_exists($string, $lang_plugin); |
---|
128 | |
---|
129 | if ($string_data['in_plugin'] && ($string_data['in_common'] || ($string_data['is_admin'] && $string_data['in_admin']))) |
---|
130 | { |
---|
131 | $string_data['stat'] = 'useless'; |
---|
132 | $counts['useless']++; |
---|
133 | } |
---|
134 | else if (!$string_data['in_plugin'] && !$string_data['in_common'] && (!$string_data['is_admin'] || !$string_data['in_admin'])) |
---|
135 | { |
---|
136 | $string_data['stat'] = 'missing'; |
---|
137 | $counts['missing']++; |
---|
138 | } |
---|
139 | else |
---|
140 | { |
---|
141 | $string_data['stat'] = 'ok'; |
---|
142 | $counts['ok']++; |
---|
143 | } |
---|
144 | } |
---|
145 | unset($string_data); |
---|
146 | |
---|
147 | uksort($strings, 'strnatcasecmp'); |
---|
148 | $counts['total'] = array_sum($counts); |
---|
149 | |
---|
150 | $template->assign(array( |
---|
151 | 'PLA_STEP' => 'analysis', |
---|
152 | 'PLA_PLUGIN' => $_GET['plugin_id'], |
---|
153 | 'PLA_FILES' => $files, |
---|
154 | 'PLA_STRINGS' => $strings, |
---|
155 | 'PLA_COUNTS' => $counts, |
---|
156 | 'U_BACK' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'], |
---|
157 | )); |
---|
158 | } |
---|
159 | |
---|
160 | // template vars |
---|
161 | $template->assign(array( |
---|
162 | 'PLA_PATH'=> PLA_PATH, |
---|
163 | 'PLA_ABS_PATH'=> realpath(PLA_PATH), |
---|
164 | 'PLA_ADMIN' => PLA_ADMIN, |
---|
165 | )); |
---|
166 | |
---|
167 | $template->set_filename('pla_content', realpath(PLA_PATH.'template/main.tpl')); |
---|
168 | $template->assign_var_from_handle('ADMIN_CONTENT', 'pla_content'); |
---|
169 | |
---|
170 | ?> |
---|