source: trunk/admin/include/c13y_internal.class.php @ 2299

Last change on this file since 2299 was 2299, checked in by plg, 16 years ago

Bug fixed: as rvelices notified me by email, my header replacement script was
bugged (r2297 was repeating new and old header).

By the way, I've also removed the replacement keywords. We were using them
because it was a common usage with CVS but it is advised not to use them with
Subversion. Personnaly, it is a problem when I search differences between 2
Piwigo installations outside Subversion.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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 c13y_internal
25{
26  function c13y_internal()
27  {
28    add_event_handler('list_check_integrity', array(&$this, 'c13y_exif'));
29    add_event_handler('list_check_integrity', array(&$this, 'c13y_user'));
30  }
31
32  /**
33   * Check exif
34   *
35   * @param void
36   * @return void
37   */
38  function c13y_exif($c13y)
39  {
40    global $conf;
41
42    foreach (array('show_exif', 'use_exif') as $value)
43    {
44      if (($conf[$value]) and (!function_exists('read_exif_data')))
45      {
46        $c13y->add_anomaly(
47          sprintf(l10n('c13y_exif_anomaly'), '$conf[\''.$value.'\']'),
48          null,
49          null,
50          sprintf(l10n('c13y_exif_correction'), '$conf[\''.$value.'\']')
51          .'<BR />'.
52          $c13y->get_htlm_links_more_info());
53      }
54    }
55  }
56
57  /**
58   * Check user
59   *
60   * @param void
61   * @return void
62   */
63  function c13y_user($c13y)
64  {
65    global $conf;
66
67    $c13y_users = array();
68    $c13y_users[$conf['guest_id']] = array(
69      'status' => 'guest',
70      'l10n_non_existent' => 'c13y_guest_non_existent',
71      'l10n_bad_status' => 'c13y_bad_guest_status');
72
73    if ($conf['guest_id'] != $conf['default_user_id'])
74    {
75      $c13y_users[$conf['default_user_id']] = array(
76        'password' => null,
77        'l10n_non_existent' => 'c13y_default_non_existent');
78    }
79
80    $c13y_users[$conf['webmaster_id']] = array(
81      'status' => 'webmaster',
82      'l10n_non_existent' => 'c13y_webmaster_non_existent',
83      'l10n_bad_status' => 'c13y_bad_webmaster_status');
84
85      $query = '
86  select u.'.$conf['user_fields']['id'].' as id, ui.status
87  from '.USERS_TABLE.' as u
88    left join '.USER_INFOS_TABLE.' as ui
89        on u.'.$conf['user_fields']['id'].' = ui.user_id
90  where
91    u.'.$conf['user_fields']['id'].' in ('.implode(',', array_keys($c13y_users)).')
92  ;';
93
94
95    $status = array();
96
97    $result = pwg_query($query);
98    while ($row = mysql_fetch_array($result))
99    {
100      $status[$row['id']] = $row['status'];
101    }
102
103    foreach ($c13y_users as $id => $data)
104    {
105      if (!array_key_exists($id, $status))
106      {
107        $c13y->add_anomaly(l10n($data['l10n_non_existent']), 'c13y_correction_user',
108          array('id' => $id, 'action' => 'creation'));
109      }
110      else
111      if (!empty($data['status']) and $status[$id] != $data['status'])
112      {
113        $c13y->add_anomaly(l10n($data['l10n_bad_status']), 'c13y_correction_user',
114          array('id' => $id, 'action' => 'status'));
115      }
116    }
117  }
118
119  /**
120   * Do correction user
121   *
122   * @param user_id, action
123   * @return boolean true if ok else false
124   */
125  function c13y_correction_user($id, $action)
126  {
127    global $conf, $page;
128
129    $result = false;
130
131    if (!empty($id))
132    {
133      switch ($action)
134      {
135        case 'creation':
136          if ($id == $conf['guest_id'])
137          {
138            $name = 'guest';
139            $password = null;
140          }
141          else if  ($id == $conf['default_user_id'])
142          {
143            $name = 'guest';
144            $password = null;
145          }
146          else if  ($id == $conf['webmaster_id'])
147          {
148            $name = 'webmaster';
149            $password = generate_key(6);
150          }
151
152          if (isset($name))
153          {
154            $name_ok = false;
155            while (!$name_ok)
156            {
157              $name_ok = (get_userid($name) === false);
158              if (!$name_ok)
159              {
160                $name .= generate_key(1);
161              }
162            }
163
164            $inserts = array(
165              array(
166                'id'       => $id,
167                'username' => $name,
168                'password' => $password
169                ),
170              );
171            mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts);
172
173            create_user_infos($id);
174
175            $page['infos'][] = sprintf(l10n('c13y_user_created'), $name, $password);
176
177            $result = true;
178          }
179          break;
180        case 'status':
181          if ($id == $conf['guest_id'])
182          {
183            $status = 'guest';
184          }
185          else if  ($id == $conf['default_user_id'])
186          {
187            $status = 'guest';
188          }
189          else if  ($id == $conf['webmaster_id'])
190          {
191            $status = 'webmaster';
192          }
193
194          if (isset($status))
195          {
196            $updates = array(
197              array(
198                'user_id' => $id,
199                'status'  => $status
200                ),
201              );
202            mass_updates(USER_INFOS_TABLE,
203              array('primary' => array('user_id'),'update' => array('status')),
204              $updates);
205
206            $page['infos'][] = sprintf(l10n('c13y_user_status_updated'), get_username($id));
207
208            $result = true;
209          }
210          break;
211      }
212    }
213
214    return $result;
215  }
216}
217
218?>
Note: See TracBrowser for help on using the repository browser.