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

Last change on this file since 2269 was 2269, checked in by rub, 17 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
RevLine 
[2065]1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[2208]5// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
[2065]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
[2232]27class check_integrity
[2065]28{
[2232]29  var $ignore_list;
30  var $retrieve_list;
31  var $build_ignore_list;
[2065]32
[2232]33  function check_integrity()
[2208]34  {
[2232]35    $this->ignore_list = array();
36    $this->retrieve_list = array();
37    $this->build_ignore_list = array();
[2208]38  }
[2232]39
40  /**
41   * Check integrities
42   *
43   * @param void
44   * @return void
45   */
46  function check()
[2208]47  {
[2232]48    global $page, $header_notes, $conf;
[2065]49
[2232]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    }
[2065]67
[2232]68    // Retrieve list
69    $this->retrieve_list = array();
70    $this->build_ignore_list = array();
[2208]71
[2238]72    trigger_action('list_check_integrity', $this);
[2065]73
[2232]74    // Information
75    if (count($this->retrieve_list) > 0)
[2065]76    {
[2232]77      $header_notes[] =
78        l10n_dec('c13y_anomaly_count', 'c13y_anomalies_count',
79          count($this->retrieve_list));
80    }
[2065]81
[2232]82    // Treatments
83    if (!is_adviser())
84    {
85      if (isset($_POST['c13y_submit_correction']) and isset($_POST['c13y_selection']))
[2065]86      {
[2232]87        $corrected_count = 0;
88        $not_corrected_count = 0;
89
90        foreach ($this->retrieve_list as $i => $c13y)
[2065]91        {
[2232]92          if (!empty($c13y['correction_fct']) and
93              $c13y['is_callable'] and
94              in_array($c13y['id'], $_POST['c13y_selection']))
[2065]95          {
[2232]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);
[2217]110
[2232]111            if ($this->retrieve_list[$i]['corrected'])
112            {
113              $corrected_count += 1;
114            }
115            else
116            {
117              $not_corrected_count += 1;
118            }
[2065]119          }
120        }
121
[2232]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        }
[2065]134      }
[2232]135      else
[2065]136      {
[2232]137        if (isset($_POST['c13y_submit_ignore']) and isset($_POST['c13y_selection']))
138        {
139          $ignored_count = 0;
[2208]140
[2232]141          foreach ($this->retrieve_list as $i => $c13y)
[2208]142          {
[2232]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            }
[2208]149          }
150
[2232]151          if ($ignored_count > 0)
152          {
153            $page['infos'][] =
154              l10n_dec('c13y_anomaly_ignored_count', 'c13y_anomalies_ignored_count',
155                $ignored_count);
156          }
[2208]157        }
158      }
159    }
160
[2232]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        );
[2208]167
[2232]168    if ($ignore_list_changed)
169    {
170      $this->update_conf($this->build_ignore_list);
171    }
[2208]172  }
[2065]173
[2232]174  /**
175   * Display anomalies list
176   *
177   * @param void
178   * @return void
179   */
180  function display()
181  {
182    global $template;
[2065]183
[2232]184    $check_automatic_correction = false;
185    $submit_automatic_correction = false;
186    $submit_ignore = false;
[2065]187
[2232]188    if (isset($this->retrieve_list) and count($this->retrieve_list) > 0)
[2065]189    {
[2232]190      $template->set_filenames(array('check_integrity' => 'admin/check_integrity.tpl'));
[2208]191
[2232]192      foreach ($this->retrieve_list as $i => $c13y)
193      {
194        $can_select = false;
[2241]195        $c13y_display = array(
[2269]196           'id' => $c13y['id'],
197           'anomaly' => $c13y['anomaly'],
[2241]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          );
[2208]206
[2232]207        if (isset($c13y['ignored']))
[2065]208        {
[2232]209          if ($c13y['ignored'])
210          {
[2241]211            $c13y_display['show_ignore_msg'] = true;
[2232]212          }
213          else
214          {
215            die('$c13y[\'ignored\'] cannot be false');
216          }
[2208]217        }
218        else
219        {
[2232]220          if (!empty($c13y['correction_fct']))
[2065]221          {
[2232]222            if (isset($c13y['corrected']))
[2208]223            {
[2232]224              if ($c13y['corrected'])
225              {
[2241]226                $c13y_display['show_correction_success_fct'] = true;
[2232]227              }
228              else
229              {
[2241]230                $c13y_display['correction_error_fct'] = $this->get_htlm_links_more_info();
[2232]231              }
[2208]232            }
[2232]233            else if ($c13y['is_callable'])
234            {
[2241]235              $c13y_display['show_correction_fct'] = true;
236              $template->append('c13y_do_check', $c13y['id']);
[2232]237              $submit_automatic_correction = true;
238              $can_select = true;
239            }
[2208]240            else
241            {
[2241]242              $c13y_display['show_correction_bad_fct'] = true;
[2232]243              $can_select = true;
[2208]244            }
[2065]245          }
[2232]246          else
[2208]247          {
248            $can_select = true;
249          }
[2232]250
251          if (!empty($c13y['correction_msg']) and !isset($c13y['corrected']))
252          {
[2241]253            $c13y_display['correction_msg'] = $c13y['correction_msg'];
[2232]254          }
[2065]255        }
256
[2241]257        $c13y_display['can_select'] = $can_select;
[2232]258        if ($can_select)
[2208]259        {
[2232]260          $submit_ignore = true;
[2208]261        }
[2241]262       
263        $template->append('c13y_list', $c13y_display);
[2065]264      }
265
[2241]266      $template->assign('c13y_show_submit_automatic_correction', $submit_automatic_correction);
267      $template->assign('c13y_show_submit_ignore', $submit_ignore);
[2065]268
[2269]269      $template->concat_var('ADMIN_CONTENT', $template->parse('check_integrity', true));
270
[2208]271    }
[2065]272  }
273
[2232]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)
[2208]281  {
[2232]282    $id = md5($anomaly.$correction_fct.serialize($correction_fct_args).$correction_msg);
[2065]283
[2232]284    if (in_array($id, $this->ignore_list))
[2065]285    {
[2232]286      $this->build_ignore_list[] = $id;
[2065]287    }
[2232]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    }
[2065]299  }
300
[2232]301  /**
302   * Update table config
303   *
304   * @param ignore list array
305   * @return void
306   */
307  function update_conf($conf_ignore_list = array())
[2065]308  {
[2232]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);
[2065]314  }
[2217]315
[2232]316  /**
317   * Apply maintenance
318   *
319   * @param void
320   * @return void
321   */
322  function maintenance()
[2065]323  {
[2232]324    $this->update_conf();
[2065]325  }
326
[2232]327  /**
328   * Returns links more informations
329   *
330   * @param void
331   * @return html links
332   */
333  function get_htlm_links_more_info()
[2065]334  {
[2232]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      );
[2065]344  }
345
346}
347
348?>
Note: See TracBrowser for help on using the repository browser.