source: trunk/profile.php @ 12877

Last change on this file since 12877 was 12877, checked in by rvelices, 12 years ago

remove max photo width/height from user profile because not used anymore

  • Property svn:eol-style set to LF
File size: 9.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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
24// customize appearance of the site for a user
25// +-----------------------------------------------------------------------+
26// |                           initialization                              |
27// +-----------------------------------------------------------------------+
28
29if (!defined('PHPWG_ROOT_PATH'))
30{//direct script access
31  define('PHPWG_ROOT_PATH','./');
32  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
33
34  // +-----------------------------------------------------------------------+
35  // | Check Access and exit when user status is not ok                      |
36  // +-----------------------------------------------------------------------+
37  check_status(ACCESS_CLASSIC);
38
39  if (!empty($_POST))
40  {
41    check_pwg_token();
42  }
43
44  $userdata = $user;
45
46  trigger_action('loc_begin_profile');
47
48// Reset to default (Guest) custom settings
49  if (isset($_POST['reset_to_default']))
50  {
51    $fields = array(
52      'nb_image_page', 'expand',
53      'show_nb_comments', 'show_nb_hits', 'recent_period', 'show_nb_hits'
54      );
55
56    // Get the Guest custom settings
57    $query = '
58SELECT '.implode(',', $fields).'
59  FROM '.USER_INFOS_TABLE.'
60  WHERE user_id = '.$conf['default_user_id'].'
61;';
62    $result = pwg_query($query);
63    $default_user = pwg_db_fetch_assoc($result);
64    $userdata = array_merge($userdata, $default_user);
65  }
66
67  save_profile_from_post($userdata, $page['errors']);
68
69  $title= l10n('Your Gallery Customization');
70  $page['body_id'] = 'theProfilePage';
71  $template->set_filename('profile', 'profile.tpl');
72
73  load_profile_in_template(
74    get_root_url().'profile.php', // action
75    make_index_url(), // for redirect
76    $userdata );
77
78 
79  // include menubar
80  $themeconf = $template->get_template_vars('themeconf');
81  if (!isset($themeconf['hide_menu_on']) OR !in_array('theProfilePage', $themeconf['hide_menu_on']))
82  {
83    include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
84  }
85 
86  include(PHPWG_ROOT_PATH.'include/page_header.php');
87  trigger_action('loc_end_profile');
88  $template->pparse('profile');
89  include(PHPWG_ROOT_PATH.'include/page_tail.php');
90}
91
92//------------------------------------------------------ update & customization
93function save_profile_from_post($userdata, &$errors)
94{
95  global $conf;
96  $errors = array();
97
98  if (!isset($_POST['validate']))
99  {
100    return false;
101  }
102
103  $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
104  if ($special_user)
105  {
106    unset(
107      $_POST['mail_address'],
108      $_POST['password'],
109      $_POST['use_new_pwd'],
110      $_POST['passwordConf'],
111      $_POST['theme'],
112      $_POST['language']
113      );
114    $_POST['theme'] = get_default_theme();
115    $_POST['language'] = get_default_language();
116  }
117
118  if ($conf['allow_user_customization'] or defined('IN_ADMIN'))
119  {
120    $int_pattern = '/^\d+$/';
121    if (empty($_POST['nb_image_page'])
122        or (!preg_match($int_pattern, $_POST['nb_image_page'])))
123    {
124      $errors[] = l10n('The number of photos per page must be a not null scalar');
125    }
126
127    // periods must be integer values, they represents number of days
128    if (!preg_match($int_pattern, $_POST['recent_period'])
129        or $_POST['recent_period'] <= 0)
130    {
131      $errors[] = l10n('Recent period must be a positive integer value') ;
132    }
133
134    if (!in_array($_POST['language'], array_keys(get_languages())))
135    {
136      die('Hacking attempt, incorrect language value');
137    }
138
139    if (!in_array($_POST['theme'], array_keys(get_pwg_themes())))
140    {
141      die('Hacking attempt, incorrect theme value');
142    }
143  }
144
145  if (isset($_POST['mail_address']))
146  {
147    // if $_POST and $userdata have are same email
148    // validate_mail_address allows, however, to check email
149    $mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']);
150    if (!empty($mail_error))
151    {
152      $errors[] = $mail_error;
153    }
154  }
155
156  if (!empty($_POST['use_new_pwd']))
157  {
158    // password must be the same as its confirmation
159    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
160    {
161      $errors[] = l10n('The passwords do not match');
162    }
163
164    if ( !defined('IN_ADMIN') )
165    {// changing password requires old password
166      $query = '
167  SELECT '.$conf['user_fields']['password'].' AS password
168    FROM '.USERS_TABLE.'
169    WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
170  ;';
171      list($current_password) = pwg_db_fetch_row(pwg_query($query));
172
173      if ($conf['pass_convert']($_POST['password']) != $current_password)
174      {
175        $errors[] = l10n('Current password is wrong');
176      }
177    }
178  }
179
180  if (count($errors) == 0)
181  {
182    // mass_updates function
183    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
184
185    if (isset($_POST['mail_address']))
186    {
187      // update common user informations
188      $fields = array($conf['user_fields']['email']);
189
190      $data = array();
191      $data{$conf['user_fields']['id']} = $userdata['id'];
192      $data{$conf['user_fields']['email']} = $_POST['mail_address'];
193
194      // password is updated only if filled
195      if (!empty($_POST['use_new_pwd']))
196      {
197        array_push($fields, $conf['user_fields']['password']);
198        // password is encrpyted with function $conf['pass_convert']
199        $data{$conf['user_fields']['password']} =
200          $conf['pass_convert']($_POST['use_new_pwd']);
201      }
202      mass_updates(USERS_TABLE,
203                   array('primary' => array($conf['user_fields']['id']),
204                         'update' => $fields),
205                   array($data));
206    }
207
208    if ($conf['allow_user_customization'] or defined('IN_ADMIN'))
209    {
210      // update user "additional" informations (specific to Piwigo)
211      $fields = array(
212        'nb_image_page', 'language',
213        'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'theme'
214        );
215
216      $data = array();
217      $data['user_id'] = $userdata['id'];
218
219      foreach ($fields as $field)
220      {
221        if (isset($_POST[$field]))
222        {
223          $data[$field] = $_POST[$field];
224        }
225      }
226      mass_updates(USER_INFOS_TABLE,
227                   array('primary' => array('user_id'), 'update' => $fields),
228                   array($data));
229    }
230    trigger_action( 'save_profile_from_post', $userdata['id'] );
231
232    if (!empty($_POST['redirect']))
233    {
234      redirect($_POST['redirect']);
235    }
236  }
237  return true;
238}
239
240
241function load_profile_in_template($url_action, $url_redirect, $userdata)
242{
243  global $template, $conf;
244
245  $template->set_filename('profile_content', 'profile_content.tpl');
246
247  $template->assign('radio_options',
248    array(
249      'true' => l10n('Yes'),
250      'false' => l10n('No')));
251
252  $template->assign(
253    array(
254      'USERNAME'=>stripslashes($userdata['username']),
255      'EMAIL'=>get_email_address_as_display_text(@$userdata['email']),
256      'ALLOW_USER_CUSTOMIZATION'=>$conf['allow_user_customization'],
257      'NB_IMAGE_PAGE'=>$userdata['nb_image_page'],
258      'RECENT_PERIOD'=>$userdata['recent_period'],
259      'EXPAND' =>$userdata['expand'] ? 'true' : 'false',
260      'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false',
261      'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false',
262      'REDIRECT' => $url_redirect,
263      'F_ACTION'=>$url_action,
264      ));
265
266  $template->assign('template_selection', $userdata['theme']);
267  $template->assign('template_options', get_pwg_themes());
268
269  foreach (get_languages() as $language_code => $language_name)
270  {
271    if (isset($_POST['submit']) or $userdata['language'] == $language_code)
272    {
273      $template->assign('language_selection', $language_code);
274    }
275    $language_options[$language_code] = $language_name;
276  }
277
278  $template->assign('language_options', $language_options);
279
280  $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
281  $template->assign('SPECIAL_USER', $special_user);
282  $template->assign('IN_ADMIN', defined('IN_ADMIN'));
283
284  // allow plugins to add their own form data to content
285  trigger_action( 'load_profile_in_template', $userdata );
286
287  $template->assign('PWG_TOKEN', get_pwg_token());
288  $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
289}
290?>
Note: See TracBrowser for help on using the repository browser.