[2065] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[19703] | 5 | // | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[2065] | 23 | |
---|
[2232] | 24 | class check_integrity |
---|
[2065] | 25 | { |
---|
[2232] | 26 | var $ignore_list; |
---|
| 27 | var $retrieve_list; |
---|
| 28 | var $build_ignore_list; |
---|
[2065] | 29 | |
---|
[2232] | 30 | function check_integrity() |
---|
[2208] | 31 | { |
---|
[2232] | 32 | $this->ignore_list = array(); |
---|
| 33 | $this->retrieve_list = array(); |
---|
| 34 | $this->build_ignore_list = array(); |
---|
[2208] | 35 | } |
---|
[2232] | 36 | |
---|
| 37 | /** |
---|
| 38 | * Check integrities |
---|
| 39 | * |
---|
| 40 | * @param void |
---|
| 41 | * @return void |
---|
| 42 | */ |
---|
| 43 | function check() |
---|
[2208] | 44 | { |
---|
[2232] | 45 | global $page, $header_notes, $conf; |
---|
[2065] | 46 | |
---|
[2232] | 47 | // Ignore list |
---|
| 48 | $conf_c13y_ignore = unserialize($conf['c13y_ignore']); |
---|
| 49 | if ( |
---|
| 50 | is_array($conf_c13y_ignore) and |
---|
| 51 | isset($conf_c13y_ignore['version']) and |
---|
| 52 | ($conf_c13y_ignore['version'] == PHPWG_VERSION) and |
---|
| 53 | is_array($conf_c13y_ignore['list']) |
---|
| 54 | ) |
---|
| 55 | { |
---|
| 56 | $ignore_list_changed = false; |
---|
| 57 | $this->ignore_list = $conf_c13y_ignore['list']; |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
| 61 | $ignore_list_changed = true; |
---|
| 62 | $this->ignore_list = array(); |
---|
| 63 | } |
---|
[2065] | 64 | |
---|
[2232] | 65 | // Retrieve list |
---|
| 66 | $this->retrieve_list = array(); |
---|
| 67 | $this->build_ignore_list = array(); |
---|
[2208] | 68 | |
---|
[2238] | 69 | trigger_action('list_check_integrity', $this); |
---|
[2065] | 70 | |
---|
[2232] | 71 | // Information |
---|
| 72 | if (count($this->retrieve_list) > 0) |
---|
[2065] | 73 | { |
---|
[2232] | 74 | $header_notes[] = |
---|
[5287] | 75 | l10n_dec('%d anomaly has been detected.', '%d anomalies have been detected.', |
---|
[2232] | 76 | count($this->retrieve_list)); |
---|
| 77 | } |
---|
[2065] | 78 | |
---|
[2232] | 79 | // Treatments |
---|
[8126] | 80 | if (isset($_POST['c13y_submit_correction']) and isset($_POST['c13y_selection'])) |
---|
[2232] | 81 | { |
---|
[8126] | 82 | $corrected_count = 0; |
---|
| 83 | $not_corrected_count = 0; |
---|
| 84 | |
---|
| 85 | foreach ($this->retrieve_list as $i => $c13y) |
---|
[2065] | 86 | { |
---|
[8126] | 87 | if (!empty($c13y['correction_fct']) and |
---|
| 88 | $c13y['is_callable'] and |
---|
| 89 | in_array($c13y['id'], $_POST['c13y_selection'])) |
---|
[2065] | 90 | { |
---|
[8126] | 91 | if (is_array($c13y['correction_fct_args'])) |
---|
[2065] | 92 | { |
---|
[8126] | 93 | $args = $c13y['correction_fct_args']; |
---|
| 94 | } |
---|
| 95 | else |
---|
| 96 | if (!is_null($c13y['correction_fct_args'])) |
---|
| 97 | { |
---|
| 98 | $args = array($c13y['correction_fct_args']); |
---|
| 99 | } |
---|
| 100 | else |
---|
| 101 | { |
---|
| 102 | $args = array(); |
---|
| 103 | } |
---|
| 104 | $this->retrieve_list[$i]['corrected'] = call_user_func_array($c13y['correction_fct'], $args); |
---|
[2217] | 105 | |
---|
[8126] | 106 | if ($this->retrieve_list[$i]['corrected']) |
---|
| 107 | { |
---|
| 108 | $corrected_count += 1; |
---|
[2065] | 109 | } |
---|
[8126] | 110 | else |
---|
| 111 | { |
---|
| 112 | $not_corrected_count += 1; |
---|
| 113 | } |
---|
[2065] | 114 | } |
---|
[8126] | 115 | } |
---|
[2065] | 116 | |
---|
[8126] | 117 | if ($corrected_count > 0) |
---|
| 118 | { |
---|
| 119 | $page['infos'][] = |
---|
| 120 | l10n_dec('%d anomaly has been corrected.', '%d anomalies have been detected corrected.', |
---|
| 121 | $corrected_count); |
---|
[2065] | 122 | } |
---|
[8126] | 123 | if ($not_corrected_count > 0) |
---|
[2065] | 124 | { |
---|
[8126] | 125 | $page['errors'][] = |
---|
| 126 | l10n_dec('%d anomaly has not been corrected.', '%d anomalies have not been corrected.', |
---|
| 127 | $not_corrected_count); |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | else |
---|
| 131 | { |
---|
| 132 | if (isset($_POST['c13y_submit_ignore']) and isset($_POST['c13y_selection'])) |
---|
| 133 | { |
---|
| 134 | $ignored_count = 0; |
---|
| 135 | |
---|
| 136 | foreach ($this->retrieve_list as $i => $c13y) |
---|
[2232] | 137 | { |
---|
[8126] | 138 | if (in_array($c13y['id'], $_POST['c13y_selection'])) |
---|
[2208] | 139 | { |
---|
[8126] | 140 | $this->build_ignore_list[] = $c13y['id']; |
---|
| 141 | $this->retrieve_list[$i]['ignored'] = true; |
---|
| 142 | $ignored_count += 1; |
---|
[2208] | 143 | } |
---|
[8126] | 144 | } |
---|
[2208] | 145 | |
---|
[8126] | 146 | if ($ignored_count > 0) |
---|
| 147 | { |
---|
| 148 | $page['infos'][] = |
---|
| 149 | l10n_dec('%d anomaly has been ignored.', '%d anomalies have been ignored.', |
---|
| 150 | $ignored_count); |
---|
[2208] | 151 | } |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
[2232] | 155 | $ignore_list_changed = |
---|
| 156 | ( |
---|
| 157 | ($ignore_list_changed) or |
---|
| 158 | (count(array_diff($this->ignore_list, $this->build_ignore_list)) > 0) or |
---|
| 159 | (count(array_diff($this->build_ignore_list, $this->ignore_list)) > 0) |
---|
| 160 | ); |
---|
[2208] | 161 | |
---|
[2232] | 162 | if ($ignore_list_changed) |
---|
| 163 | { |
---|
| 164 | $this->update_conf($this->build_ignore_list); |
---|
| 165 | } |
---|
[2208] | 166 | } |
---|
[2065] | 167 | |
---|
[2232] | 168 | /** |
---|
| 169 | * Display anomalies list |
---|
| 170 | * |
---|
| 171 | * @param void |
---|
| 172 | * @return void |
---|
| 173 | */ |
---|
| 174 | function display() |
---|
| 175 | { |
---|
| 176 | global $template; |
---|
[2065] | 177 | |
---|
[2232] | 178 | $check_automatic_correction = false; |
---|
| 179 | $submit_automatic_correction = false; |
---|
| 180 | $submit_ignore = false; |
---|
[2065] | 181 | |
---|
[2232] | 182 | if (isset($this->retrieve_list) and count($this->retrieve_list) > 0) |
---|
[2065] | 183 | { |
---|
[2530] | 184 | $template->set_filenames(array('check_integrity' => 'check_integrity.tpl')); |
---|
[2208] | 185 | |
---|
[2232] | 186 | foreach ($this->retrieve_list as $i => $c13y) |
---|
| 187 | { |
---|
| 188 | $can_select = false; |
---|
[2241] | 189 | $c13y_display = array( |
---|
[2269] | 190 | 'id' => $c13y['id'], |
---|
| 191 | 'anomaly' => $c13y['anomaly'], |
---|
[2241] | 192 | 'show_ignore_msg' => false, |
---|
| 193 | 'show_correction_success_fct' => false, |
---|
| 194 | 'correction_error_fct' => '', |
---|
| 195 | 'show_correction_fct' => false, |
---|
| 196 | 'correction_error_fct' => '', |
---|
| 197 | 'show_correction_bad_fct' => false, |
---|
| 198 | 'correction_msg' => '' |
---|
| 199 | ); |
---|
[2208] | 200 | |
---|
[2232] | 201 | if (isset($c13y['ignored'])) |
---|
[2065] | 202 | { |
---|
[2232] | 203 | if ($c13y['ignored']) |
---|
| 204 | { |
---|
[2241] | 205 | $c13y_display['show_ignore_msg'] = true; |
---|
[2232] | 206 | } |
---|
| 207 | else |
---|
| 208 | { |
---|
| 209 | die('$c13y[\'ignored\'] cannot be false'); |
---|
| 210 | } |
---|
[2208] | 211 | } |
---|
| 212 | else |
---|
| 213 | { |
---|
[2232] | 214 | if (!empty($c13y['correction_fct'])) |
---|
[2065] | 215 | { |
---|
[2232] | 216 | if (isset($c13y['corrected'])) |
---|
[2208] | 217 | { |
---|
[2232] | 218 | if ($c13y['corrected']) |
---|
| 219 | { |
---|
[2241] | 220 | $c13y_display['show_correction_success_fct'] = true; |
---|
[2232] | 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
[2241] | 224 | $c13y_display['correction_error_fct'] = $this->get_htlm_links_more_info(); |
---|
[2232] | 225 | } |
---|
[2208] | 226 | } |
---|
[2232] | 227 | else if ($c13y['is_callable']) |
---|
| 228 | { |
---|
[2241] | 229 | $c13y_display['show_correction_fct'] = true; |
---|
| 230 | $template->append('c13y_do_check', $c13y['id']); |
---|
[2232] | 231 | $submit_automatic_correction = true; |
---|
| 232 | $can_select = true; |
---|
| 233 | } |
---|
[2208] | 234 | else |
---|
| 235 | { |
---|
[2241] | 236 | $c13y_display['show_correction_bad_fct'] = true; |
---|
[2232] | 237 | $can_select = true; |
---|
[2208] | 238 | } |
---|
[2065] | 239 | } |
---|
[2232] | 240 | else |
---|
[2208] | 241 | { |
---|
| 242 | $can_select = true; |
---|
| 243 | } |
---|
[2232] | 244 | |
---|
| 245 | if (!empty($c13y['correction_msg']) and !isset($c13y['corrected'])) |
---|
| 246 | { |
---|
[2241] | 247 | $c13y_display['correction_msg'] = $c13y['correction_msg']; |
---|
[2232] | 248 | } |
---|
[2065] | 249 | } |
---|
| 250 | |
---|
[2241] | 251 | $c13y_display['can_select'] = $can_select; |
---|
[2232] | 252 | if ($can_select) |
---|
[2208] | 253 | { |
---|
[2232] | 254 | $submit_ignore = true; |
---|
[2208] | 255 | } |
---|
[2286] | 256 | |
---|
[2241] | 257 | $template->append('c13y_list', $c13y_display); |
---|
[2065] | 258 | } |
---|
| 259 | |
---|
[2241] | 260 | $template->assign('c13y_show_submit_automatic_correction', $submit_automatic_correction); |
---|
| 261 | $template->assign('c13y_show_submit_ignore', $submit_ignore); |
---|
[2065] | 262 | |
---|
[2286] | 263 | $template->concat('ADMIN_CONTENT', $template->parse('check_integrity', true)); |
---|
[2269] | 264 | |
---|
[2208] | 265 | } |
---|
[2065] | 266 | } |
---|
| 267 | |
---|
[2232] | 268 | /** |
---|
| 269 | * Add anomaly data |
---|
| 270 | * |
---|
| 271 | * @param anomaly arguments |
---|
| 272 | * @return void |
---|
| 273 | */ |
---|
| 274 | function add_anomaly($anomaly, $correction_fct = null, $correction_fct_args = null, $correction_msg = null) |
---|
[2208] | 275 | { |
---|
[2232] | 276 | $id = md5($anomaly.$correction_fct.serialize($correction_fct_args).$correction_msg); |
---|
[2065] | 277 | |
---|
[2232] | 278 | if (in_array($id, $this->ignore_list)) |
---|
[2065] | 279 | { |
---|
[2232] | 280 | $this->build_ignore_list[] = $id; |
---|
[2065] | 281 | } |
---|
[2232] | 282 | else |
---|
| 283 | { |
---|
| 284 | $this->retrieve_list[] = |
---|
| 285 | array( |
---|
| 286 | 'id' => $id, |
---|
| 287 | 'anomaly' => $anomaly, |
---|
| 288 | 'correction_fct' => $correction_fct, |
---|
| 289 | 'correction_fct_args' => $correction_fct_args, |
---|
| 290 | 'correction_msg' => $correction_msg, |
---|
| 291 | 'is_callable' => is_callable($correction_fct)); |
---|
| 292 | } |
---|
[2065] | 293 | } |
---|
| 294 | |
---|
[2232] | 295 | /** |
---|
| 296 | * Update table config |
---|
| 297 | * |
---|
| 298 | * @param ignore list array |
---|
| 299 | * @return void |
---|
| 300 | */ |
---|
| 301 | function update_conf($conf_ignore_list = array()) |
---|
[2065] | 302 | { |
---|
[2232] | 303 | $conf_c13y_ignore = array(); |
---|
| 304 | $conf_c13y_ignore['version'] = PHPWG_VERSION; |
---|
| 305 | $conf_c13y_ignore['list'] = $conf_ignore_list; |
---|
| 306 | $query = 'update '.CONFIG_TABLE.' set value =\''.serialize($conf_c13y_ignore).'\'where param = \'c13y_ignore\';'; |
---|
| 307 | pwg_query($query); |
---|
[2065] | 308 | } |
---|
[2217] | 309 | |
---|
[2232] | 310 | /** |
---|
| 311 | * Apply maintenance |
---|
| 312 | * |
---|
| 313 | * @param void |
---|
| 314 | * @return void |
---|
| 315 | */ |
---|
| 316 | function maintenance() |
---|
[2065] | 317 | { |
---|
[2232] | 318 | $this->update_conf(); |
---|
[2065] | 319 | } |
---|
| 320 | |
---|
[2232] | 321 | /** |
---|
| 322 | * Returns links more informations |
---|
| 323 | * |
---|
| 324 | * @param void |
---|
| 325 | * @return html links |
---|
| 326 | */ |
---|
| 327 | function get_htlm_links_more_info() |
---|
[2065] | 328 | { |
---|
[2232] | 329 | $pwg_links = pwg_URL(); |
---|
| 330 | $link_fmt = '<a href="%s" onclick="window.open(this.href, \'\'); return false;">%s</a>'; |
---|
| 331 | return |
---|
| 332 | sprintf |
---|
| 333 | ( |
---|
[5021] | 334 | l10n('Go to %s or %s for more informations'), |
---|
| 335 | sprintf($link_fmt, $pwg_links['FORUM'], l10n('the forum')), |
---|
| 336 | sprintf($link_fmt, $pwg_links['WIKI'], l10n('the wiki')) |
---|
[2232] | 337 | ); |
---|
[2065] | 338 | } |
---|
| 339 | |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | ?> |
---|