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

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

Bug fixed: as rvelices notified me by email, my header replacement script was
bugged (r2297 was repeating new and old header).

By the way, I've also removed the replacement keywords. We were using them
because it was a common usage with CVS but it is advised not to use them with
Subversion. Personnaly, it is a problem when I search differences between 2
Piwigo installations outside Subversion.

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