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

Last change on this file since 2238 was 2238, checked in by rub, 16 years ago

0000809: Use more php classes implementation

Use class for c13y

Fix problem with call-time pass-by-reference

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