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

Last change on this file since 26998 was 26461, checked in by mistic100, 10 years ago

Update headers to 2014. Happy new year!!

  • Property svn:eol-style set to LF
File size: 9.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 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[] = l10n_dec(
75        '%d anomaly has been detected.', '%d anomalies have been detected.',
76        count($this->retrieve_list)
77        );
78    }
79
80    // Treatments
81    if (isset($_POST['c13y_submit_correction']) and isset($_POST['c13y_selection']))
82    {
83      $corrected_count = 0;
84      $not_corrected_count = 0;
85
86      foreach ($this->retrieve_list as $i => $c13y)
87      {
88        if (!empty($c13y['correction_fct']) and
89            $c13y['is_callable'] and
90            in_array($c13y['id'], $_POST['c13y_selection']))
91        {
92          if (is_array($c13y['correction_fct_args']))
93          {
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);
106
107          if ($this->retrieve_list[$i]['corrected'])
108          {
109            $corrected_count += 1;
110          }
111          else
112          {
113            $not_corrected_count += 1;
114          }
115        }
116      }
117
118      if ($corrected_count > 0)
119      {
120        $page['infos'][] = l10n_dec(
121          '%d anomaly has been corrected.', '%d anomalies have been detected corrected.',
122          $corrected_count
123          );
124      }
125      if ($not_corrected_count > 0)
126      {
127        $page['errors'][] = l10n_dec(
128          '%d anomaly has not been corrected.', '%d anomalies have not been corrected.',
129          $not_corrected_count
130          );
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)
140        {
141          if (in_array($c13y['id'], $_POST['c13y_selection']))
142          {
143            $this->build_ignore_list[] = $c13y['id'];
144            $this->retrieve_list[$i]['ignored'] = true;
145            $ignored_count += 1;
146          }
147        }
148
149        if ($ignored_count > 0)
150        {
151          $page['infos'][] = l10n_dec(
152            '%d anomaly has been ignored.', '%d anomalies have been ignored.',
153            $ignored_count
154            );
155        }
156      }
157    }
158
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        );
165
166    if ($ignore_list_changed)
167    {
168      $this->update_conf($this->build_ignore_list);
169    }
170  }
171
172  /**
173   * Display anomalies list
174   *
175   * @param void
176   * @return void
177   */
178  function display()
179  {
180    global $template;
181
182    $check_automatic_correction = false;
183    $submit_automatic_correction = false;
184    $submit_ignore = false;
185
186    if (isset($this->retrieve_list) and count($this->retrieve_list) > 0)
187    {
188      $template->set_filenames(array('check_integrity' => 'check_integrity.tpl'));
189
190      foreach ($this->retrieve_list as $i => $c13y)
191      {
192        $can_select = false;
193        $c13y_display = array(
194           'id' => $c13y['id'],
195           'anomaly' => $c13y['anomaly'],
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          );
204
205        if (isset($c13y['ignored']))
206        {
207          if ($c13y['ignored'])
208          {
209            $c13y_display['show_ignore_msg'] = true;
210          }
211          else
212          {
213            die('$c13y[\'ignored\'] cannot be false');
214          }
215        }
216        else
217        {
218          if (!empty($c13y['correction_fct']))
219          {
220            if (isset($c13y['corrected']))
221            {
222              if ($c13y['corrected'])
223              {
224                $c13y_display['show_correction_success_fct'] = true;
225              }
226              else
227              {
228                $c13y_display['correction_error_fct'] = $this->get_htlm_links_more_info();
229              }
230            }
231            else if ($c13y['is_callable'])
232            {
233              $c13y_display['show_correction_fct'] = true;
234              $template->append('c13y_do_check', $c13y['id']);
235              $submit_automatic_correction = true;
236              $can_select = true;
237            }
238            else
239            {
240              $c13y_display['show_correction_bad_fct'] = true;
241              $can_select = true;
242            }
243          }
244          else
245          {
246            $can_select = true;
247          }
248
249          if (!empty($c13y['correction_msg']) and !isset($c13y['corrected']))
250          {
251            $c13y_display['correction_msg'] = $c13y['correction_msg'];
252          }
253        }
254
255        $c13y_display['can_select'] = $can_select;
256        if ($can_select)
257        {
258          $submit_ignore = true;
259        }
260
261        $template->append('c13y_list', $c13y_display);
262      }
263
264      $template->assign('c13y_show_submit_automatic_correction', $submit_automatic_correction);
265      $template->assign('c13y_show_submit_ignore', $submit_ignore);
266
267      $template->concat('ADMIN_CONTENT', $template->parse('check_integrity', true));
268
269    }
270  }
271
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)
279  {
280    $id = md5($anomaly.$correction_fct.serialize($correction_fct_args).$correction_msg);
281
282    if (in_array($id, $this->ignore_list))
283    {
284      $this->build_ignore_list[] = $id;
285    }
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    }
297  }
298
299  /**
300   * Update table config
301   *
302   * @param ignore list array
303   * @return void
304   */
305  function update_conf($conf_ignore_list = array())
306  {
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);
312  }
313
314  /**
315   * Apply maintenance
316   *
317   * @param void
318   * @return void
319   */
320  function maintenance()
321  {
322    $this->update_conf();
323  }
324
325  /**
326   * Returns links more informations
327   *
328   * @param void
329   * @return html links
330   */
331  function get_htlm_links_more_info()
332  {
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      (
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'))
341      );
342  }
343
344}
345
346?>
Note: See TracBrowser for help on using the repository browser.