source: trunk/plugins/c13y_upgrade/initialize.inc.php @ 2243

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

0000809: Use more php classes implementation

Use class for c13y

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 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: initialize.inc.php 2232 2008-03-01 13:23:51Z rub $
8// | last update   : $Date: 2008-03-01 13:23:51 +0000 (Sat, 01 Mar 2008) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 2232 $
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
27if (!defined('PHPWG_ROOT_PATH'))
28{
29  die('Hacking attempt!');
30}
31
32add_event_handler('list_check_integrity', 'c13y_upgrade');
33
34function c13y_upgrade($c13y)
35{
36  global $conf;
37
38  load_language('plugin.lang', dirname(__FILE__).'/');
39
40  $can_be_deactivate = true;
41
42  /* Check user with same e-mail */
43  $query = '
44select
45  count(*)
46from
47  '.USERS_TABLE.'
48where
49  '.$conf['user_fields']['email'].' is not null
50group by
51  upper('.$conf['user_fields']['email'].')
52having count(*) > 1
53limit 0,1
54;';
55
56  if (mysql_fetch_array(pwg_query($query)))
57  {
58    $can_be_deactivate = false;
59    $c13y->add_anomaly(
60      l10n('c13y_dbl_email_user'),
61      null,
62      null,
63      l10n('c13y_correction_dbl_email_user'));
64  }
65
66  /* Check plugin included in Piwigo sources */
67  $included_plugins = array('dew');
68  $query = '
69select
70  id
71from
72  '.PLUGINS_TABLE.'
73where
74  id in ('.
75    implode(
76      ',',
77      array_map(
78        create_function('$s', 'return "\'".$s."\'";'),
79        $included_plugins
80        )
81      )
82      .')
83;';
84
85  $result = pwg_query($query);
86  while ($row = mysql_fetch_assoc($result))
87  {
88    $can_be_deactivate = false;
89
90    $uninstall_msg_link =
91      '<a href="'.
92      PHPWG_ROOT_PATH.
93      'admin.php?page=plugins&amp;plugin='.$row['id'].'&amp;action=uninstall'.
94      '" onclick="window.open(this.href, \'\'); return false;">'.
95      sprintf(l10n('c13y_correction_obsolete_plugin'), $row['id']).'</a>';
96
97    $c13y->add_anomaly(
98      l10n('c13y_obsolete_plugin'),
99      null,
100      null,
101      $uninstall_msg_link);
102  }
103
104  /* Check if this plugin must deactivate */
105  if ($can_be_deactivate)
106  {
107    $deactivate_msg_link =
108      '<a href="'.
109      PHPWG_ROOT_PATH.
110      'admin.php?page=plugins&amp;plugin=c13y_upgrade&amp;action=deactivate'.
111      '" onclick="window.open(this.href, \'\'); return false;">'.
112      l10n('c13y_upgrade_deactivate').'</a>';
113
114    $c13y->add_anomaly(
115      l10n('c13y_upgrade_no_anomaly'),
116      'c13y_upgrade_correction',
117      'deactivate_plugin',
118      $deactivate_msg_link
119      );
120  }
121}
122
123function c13y_upgrade_correction($action)
124{
125  $result = false;
126
127  switch ($action)
128  {
129    case 'deactivate_plugin':
130      {
131        $query = '
132REPLACE INTO '.PLUGINS_TABLE.'
133(id, state)
134VALUES (\'c13y_upgrade\', \'inactive\')
135;';
136        pwg_query($query);
137        $result = true;
138      }
139      break;
140  }
141
142  return $result;
143}
144
145?>
Note: See TracBrowser for help on using the repository browser.