source: trunk/admin/include/check_integrity.class.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

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