[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 | { |
---|
[25018] | 74 | $header_notes[] = l10n_dec( |
---|
| 75 | '%d anomaly has been detected.', '%d anomalies have been detected.', |
---|
| 76 | count($this->retrieve_list) |
---|
| 77 | ); |
---|
[2232] | 78 | } |
---|
[2065] | 79 | |
---|
[2232] | 80 | // Treatments |
---|
[8126] | 81 | if (isset($_POST['c13y_submit_correction']) and isset($_POST['c13y_selection'])) |
---|
[2232] | 82 | { |
---|
[8126] | 83 | $corrected_count = 0; |
---|
| 84 | $not_corrected_count = 0; |
---|
| 85 | |
---|
| 86 | foreach ($this->retrieve_list as $i => $c13y) |
---|
[2065] | 87 | { |
---|
[8126] | 88 | if (!empty($c13y['correction_fct']) and |
---|
| 89 | $c13y['is_callable'] and |
---|
| 90 | in_array($c13y['id'], $_POST['c13y_selection'])) |
---|
[2065] | 91 | { |
---|
[8126] | 92 | if (is_array($c13y['correction_fct_args'])) |
---|
[2065] | 93 | { |
---|
[8126] | 94 | $args = $c13y['correction_fct_args']; |
---|
| 95 | } |
---|
| 96 | else |
---|
| 97 | if (!is_null($c13y['correction_fct_args'])) |
---|
| 98 | { |
---|
| 99 | $args = array($c13y['correction_fct_args']); |
---|
| 100 | } |
---|
| 101 | else |
---|
| 102 | { |
---|
| 103 | $args = array(); |
---|
| 104 | } |
---|
| 105 | $this->retrieve_list[$i]['corrected'] = call_user_func_array($c13y['correction_fct'], $args); |
---|
[2217] | 106 | |
---|
[8126] | 107 | if ($this->retrieve_list[$i]['corrected']) |
---|
| 108 | { |
---|
| 109 | $corrected_count += 1; |
---|
[2065] | 110 | } |
---|
[8126] | 111 | else |
---|
| 112 | { |
---|
| 113 | $not_corrected_count += 1; |
---|
| 114 | } |
---|
[2065] | 115 | } |
---|
[8126] | 116 | } |
---|
[2065] | 117 | |
---|
[8126] | 118 | if ($corrected_count > 0) |
---|
| 119 | { |
---|
[25018] | 120 | $page['infos'][] = l10n_dec( |
---|
| 121 | '%d anomaly has been corrected.', '%d anomalies have been detected corrected.', |
---|
| 122 | $corrected_count |
---|
| 123 | ); |
---|
[2065] | 124 | } |
---|
[8126] | 125 | if ($not_corrected_count > 0) |
---|
[2065] | 126 | { |
---|
[25018] | 127 | $page['errors'][] = l10n_dec( |
---|
| 128 | '%d anomaly has not been corrected.', '%d anomalies have not been corrected.', |
---|
| 129 | $not_corrected_count |
---|
| 130 | ); |
---|
[8126] | 131 | } |
---|
| 132 | } |
---|
| 133 | else |
---|
| 134 | { |
---|
| 135 | if (isset($_POST['c13y_submit_ignore']) and isset($_POST['c13y_selection'])) |
---|
| 136 | { |
---|
| 137 | $ignored_count = 0; |
---|
| 138 | |
---|
| 139 | foreach ($this->retrieve_list as $i => $c13y) |
---|
[2232] | 140 | { |
---|
[8126] | 141 | if (in_array($c13y['id'], $_POST['c13y_selection'])) |
---|
[2208] | 142 | { |
---|
[8126] | 143 | $this->build_ignore_list[] = $c13y['id']; |
---|
| 144 | $this->retrieve_list[$i]['ignored'] = true; |
---|
| 145 | $ignored_count += 1; |
---|
[2208] | 146 | } |
---|
[8126] | 147 | } |
---|
[2208] | 148 | |
---|
[8126] | 149 | if ($ignored_count > 0) |
---|
| 150 | { |
---|
[25018] | 151 | $page['infos'][] = l10n_dec( |
---|
| 152 | '%d anomaly has been ignored.', '%d anomalies have been ignored.', |
---|
| 153 | $ignored_count |
---|
| 154 | ); |
---|
[2208] | 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
[2232] | 159 | $ignore_list_changed = |
---|
| 160 | ( |
---|
| 161 | ($ignore_list_changed) or |
---|
| 162 | (count(array_diff($this->ignore_list, $this->build_ignore_list)) > 0) or |
---|
| 163 | (count(array_diff($this->build_ignore_list, $this->ignore_list)) > 0) |
---|
| 164 | ); |
---|
[2208] | 165 | |
---|
[2232] | 166 | if ($ignore_list_changed) |
---|
| 167 | { |
---|
| 168 | $this->update_conf($this->build_ignore_list); |
---|
| 169 | } |
---|
[2208] | 170 | } |
---|
[2065] | 171 | |
---|
[2232] | 172 | /** |
---|
| 173 | * Display anomalies list |
---|
| 174 | * |
---|
| 175 | * @param void |
---|
| 176 | * @return void |
---|
| 177 | */ |
---|
| 178 | function display() |
---|
| 179 | { |
---|
| 180 | global $template; |
---|
[2065] | 181 | |
---|
[2232] | 182 | $check_automatic_correction = false; |
---|
| 183 | $submit_automatic_correction = false; |
---|
| 184 | $submit_ignore = false; |
---|
[2065] | 185 | |
---|
[2232] | 186 | if (isset($this->retrieve_list) and count($this->retrieve_list) > 0) |
---|
[2065] | 187 | { |
---|
[2530] | 188 | $template->set_filenames(array('check_integrity' => 'check_integrity.tpl')); |
---|
[2208] | 189 | |
---|
[2232] | 190 | foreach ($this->retrieve_list as $i => $c13y) |
---|
| 191 | { |
---|
| 192 | $can_select = false; |
---|
[2241] | 193 | $c13y_display = array( |
---|
[2269] | 194 | 'id' => $c13y['id'], |
---|
| 195 | 'anomaly' => $c13y['anomaly'], |
---|
[2241] | 196 | 'show_ignore_msg' => false, |
---|
| 197 | 'show_correction_success_fct' => false, |
---|
| 198 | 'correction_error_fct' => '', |
---|
| 199 | 'show_correction_fct' => false, |
---|
| 200 | 'correction_error_fct' => '', |
---|
| 201 | 'show_correction_bad_fct' => false, |
---|
| 202 | 'correction_msg' => '' |
---|
| 203 | ); |
---|
[2208] | 204 | |
---|
[2232] | 205 | if (isset($c13y['ignored'])) |
---|
[2065] | 206 | { |
---|
[2232] | 207 | if ($c13y['ignored']) |
---|
| 208 | { |
---|
[2241] | 209 | $c13y_display['show_ignore_msg'] = true; |
---|
[2232] | 210 | } |
---|
| 211 | else |
---|
| 212 | { |
---|
| 213 | die('$c13y[\'ignored\'] cannot be false'); |
---|
| 214 | } |
---|
[2208] | 215 | } |
---|
| 216 | else |
---|
| 217 | { |
---|
[2232] | 218 | if (!empty($c13y['correction_fct'])) |
---|
[2065] | 219 | { |
---|
[2232] | 220 | if (isset($c13y['corrected'])) |
---|
[2208] | 221 | { |
---|
[2232] | 222 | if ($c13y['corrected']) |
---|
| 223 | { |
---|
[2241] | 224 | $c13y_display['show_correction_success_fct'] = true; |
---|
[2232] | 225 | } |
---|
| 226 | else |
---|
| 227 | { |
---|
[2241] | 228 | $c13y_display['correction_error_fct'] = $this->get_htlm_links_more_info(); |
---|
[2232] | 229 | } |
---|
[2208] | 230 | } |
---|
[2232] | 231 | else if ($c13y['is_callable']) |
---|
| 232 | { |
---|
[2241] | 233 | $c13y_display['show_correction_fct'] = true; |
---|
| 234 | $template->append('c13y_do_check', $c13y['id']); |
---|
[2232] | 235 | $submit_automatic_correction = true; |
---|
| 236 | $can_select = true; |
---|
| 237 | } |
---|
[2208] | 238 | else |
---|
| 239 | { |
---|
[2241] | 240 | $c13y_display['show_correction_bad_fct'] = true; |
---|
[2232] | 241 | $can_select = true; |
---|
[2208] | 242 | } |
---|
[2065] | 243 | } |
---|
[2232] | 244 | else |
---|
[2208] | 245 | { |
---|
| 246 | $can_select = true; |
---|
| 247 | } |
---|
[2232] | 248 | |
---|
| 249 | if (!empty($c13y['correction_msg']) and !isset($c13y['corrected'])) |
---|
| 250 | { |
---|
[2241] | 251 | $c13y_display['correction_msg'] = $c13y['correction_msg']; |
---|
[2232] | 252 | } |
---|
[2065] | 253 | } |
---|
| 254 | |
---|
[2241] | 255 | $c13y_display['can_select'] = $can_select; |
---|
[2232] | 256 | if ($can_select) |
---|
[2208] | 257 | { |
---|
[2232] | 258 | $submit_ignore = true; |
---|
[2208] | 259 | } |
---|
[2286] | 260 | |
---|
[2241] | 261 | $template->append('c13y_list', $c13y_display); |
---|
[2065] | 262 | } |
---|
| 263 | |
---|
[2241] | 264 | $template->assign('c13y_show_submit_automatic_correction', $submit_automatic_correction); |
---|
| 265 | $template->assign('c13y_show_submit_ignore', $submit_ignore); |
---|
[2065] | 266 | |
---|
[2286] | 267 | $template->concat('ADMIN_CONTENT', $template->parse('check_integrity', true)); |
---|
[2269] | 268 | |
---|
[2208] | 269 | } |
---|
[2065] | 270 | } |
---|
| 271 | |
---|
[2232] | 272 | /** |
---|
| 273 | * Add anomaly data |
---|
| 274 | * |
---|
| 275 | * @param anomaly arguments |
---|
| 276 | * @return void |
---|
| 277 | */ |
---|
| 278 | function add_anomaly($anomaly, $correction_fct = null, $correction_fct_args = null, $correction_msg = null) |
---|
[2208] | 279 | { |
---|
[2232] | 280 | $id = md5($anomaly.$correction_fct.serialize($correction_fct_args).$correction_msg); |
---|
[2065] | 281 | |
---|
[2232] | 282 | if (in_array($id, $this->ignore_list)) |
---|
[2065] | 283 | { |
---|
[2232] | 284 | $this->build_ignore_list[] = $id; |
---|
[2065] | 285 | } |
---|
[2232] | 286 | else |
---|
| 287 | { |
---|
| 288 | $this->retrieve_list[] = |
---|
| 289 | array( |
---|
| 290 | 'id' => $id, |
---|
| 291 | 'anomaly' => $anomaly, |
---|
| 292 | 'correction_fct' => $correction_fct, |
---|
| 293 | 'correction_fct_args' => $correction_fct_args, |
---|
| 294 | 'correction_msg' => $correction_msg, |
---|
| 295 | 'is_callable' => is_callable($correction_fct)); |
---|
| 296 | } |
---|
[2065] | 297 | } |
---|
| 298 | |
---|
[2232] | 299 | /** |
---|
| 300 | * Update table config |
---|
| 301 | * |
---|
| 302 | * @param ignore list array |
---|
| 303 | * @return void |
---|
| 304 | */ |
---|
| 305 | function update_conf($conf_ignore_list = array()) |
---|
[2065] | 306 | { |
---|
[2232] | 307 | $conf_c13y_ignore = array(); |
---|
| 308 | $conf_c13y_ignore['version'] = PHPWG_VERSION; |
---|
| 309 | $conf_c13y_ignore['list'] = $conf_ignore_list; |
---|
| 310 | $query = 'update '.CONFIG_TABLE.' set value =\''.serialize($conf_c13y_ignore).'\'where param = \'c13y_ignore\';'; |
---|
| 311 | pwg_query($query); |
---|
[2065] | 312 | } |
---|
[2217] | 313 | |
---|
[2232] | 314 | /** |
---|
| 315 | * Apply maintenance |
---|
| 316 | * |
---|
| 317 | * @param void |
---|
| 318 | * @return void |
---|
| 319 | */ |
---|
| 320 | function maintenance() |
---|
[2065] | 321 | { |
---|
[2232] | 322 | $this->update_conf(); |
---|
[2065] | 323 | } |
---|
| 324 | |
---|
[2232] | 325 | /** |
---|
| 326 | * Returns links more informations |
---|
| 327 | * |
---|
| 328 | * @param void |
---|
| 329 | * @return html links |
---|
| 330 | */ |
---|
| 331 | function get_htlm_links_more_info() |
---|
[2065] | 332 | { |
---|
[2232] | 333 | $pwg_links = pwg_URL(); |
---|
| 334 | $link_fmt = '<a href="%s" onclick="window.open(this.href, \'\'); return false;">%s</a>'; |
---|
| 335 | return |
---|
| 336 | sprintf |
---|
| 337 | ( |
---|
[5021] | 338 | l10n('Go to %s or %s for more informations'), |
---|
| 339 | sprintf($link_fmt, $pwg_links['FORUM'], l10n('the forum')), |
---|
| 340 | sprintf($link_fmt, $pwg_links['WIKI'], l10n('the wiki')) |
---|
[2232] | 341 | ); |
---|
[2065] | 342 | } |
---|
| 343 | |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | ?> |
---|