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

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

Fix some c13y/smarty bugs

  • 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// | 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 2269 2008-03-09 07:28:04Z rub $
8// | last update   : $Date: 2008-03-09 07:28:04 +0000 (Sun, 09 Mar 2008) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 2269 $
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        $c13y_display = array(
196           'id' => $c13y['id'],
197           'anomaly' => $c13y['anomaly'],
198           'show_ignore_msg' => false,
199           'show_correction_success_fct' => false,
200           'correction_error_fct' => '',
201           'show_correction_fct' => false,
202           'correction_error_fct' => '',
203           'show_correction_bad_fct' => false,
204           'correction_msg' => ''
205          );
206
207        if (isset($c13y['ignored']))
208        {
209          if ($c13y['ignored'])
210          {
211            $c13y_display['show_ignore_msg'] = true;
212          }
213          else
214          {
215            die('$c13y[\'ignored\'] cannot be false');
216          }
217        }
218        else
219        {
220          if (!empty($c13y['correction_fct']))
221          {
222            if (isset($c13y['corrected']))
223            {
224              if ($c13y['corrected'])
225              {
226                $c13y_display['show_correction_success_fct'] = true;
227              }
228              else
229              {
230                $c13y_display['correction_error_fct'] = $this->get_htlm_links_more_info();
231              }
232            }
233            else if ($c13y['is_callable'])
234            {
235              $c13y_display['show_correction_fct'] = true;
236              $template->append('c13y_do_check', $c13y['id']);
237              $submit_automatic_correction = true;
238              $can_select = true;
239            }
240            else
241            {
242              $c13y_display['show_correction_bad_fct'] = true;
243              $can_select = true;
244            }
245          }
246          else
247          {
248            $can_select = true;
249          }
250
251          if (!empty($c13y['correction_msg']) and !isset($c13y['corrected']))
252          {
253            $c13y_display['correction_msg'] = $c13y['correction_msg'];
254          }
255        }
256
257        $c13y_display['can_select'] = $can_select;
258        if ($can_select)
259        {
260          $submit_ignore = true;
261        }
262       
263        $template->append('c13y_list', $c13y_display);
264      }
265
266      $template->assign('c13y_show_submit_automatic_correction', $submit_automatic_correction);
267      $template->assign('c13y_show_submit_ignore', $submit_ignore);
268
269      $template->concat_var('ADMIN_CONTENT', $template->parse('check_integrity', true));
270
271    }
272  }
273
274  /**
275   * Add anomaly data
276   *
277   * @param anomaly arguments
278   * @return void
279   */
280  function add_anomaly($anomaly, $correction_fct = null, $correction_fct_args = null, $correction_msg = null)
281  {
282    $id = md5($anomaly.$correction_fct.serialize($correction_fct_args).$correction_msg);
283
284    if (in_array($id, $this->ignore_list))
285    {
286      $this->build_ignore_list[] = $id;
287    }
288    else
289    {
290      $this->retrieve_list[] =
291        array(
292          'id' => $id,
293          'anomaly' => $anomaly,
294          'correction_fct' => $correction_fct,
295          'correction_fct_args' => $correction_fct_args,
296          'correction_msg' => $correction_msg,
297          'is_callable' => is_callable($correction_fct));
298    }
299  }
300
301  /**
302   * Update table config
303   *
304   * @param ignore list array
305   * @return void
306   */
307  function update_conf($conf_ignore_list = array())
308  {
309    $conf_c13y_ignore =  array();
310    $conf_c13y_ignore['version'] = PHPWG_VERSION;
311    $conf_c13y_ignore['list'] = $conf_ignore_list;
312    $query = 'update '.CONFIG_TABLE.' set value =\''.serialize($conf_c13y_ignore).'\'where param = \'c13y_ignore\';';
313    pwg_query($query);
314  }
315
316  /**
317   * Apply maintenance
318   *
319   * @param void
320   * @return void
321   */
322  function maintenance()
323  {
324    $this->update_conf();
325  }
326
327  /**
328   * Returns links more informations
329   *
330   * @param void
331   * @return html links
332   */
333  function get_htlm_links_more_info()
334  {
335    $pwg_links = pwg_URL();
336    $link_fmt = '<a href="%s" onclick="window.open(this.href, \'\'); return false;">%s</a>';
337    return
338      sprintf
339      (
340        l10n('c13y_more_info'),
341        sprintf($link_fmt, $pwg_links['FORUM'], l10n('c13y_more_info_forum')),
342        sprintf($link_fmt, $pwg_links['WIKI'], l10n('c13y_more_info_wiki'))
343      );
344  }
345
346}
347
348?>
Note: See TracBrowser for help on using the repository browser.