1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
// customize appearance of the site for a user
// +-----------------------------------------------------------------------+
// | initialization |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH'))
{//direct script access
define('PHPWG_ROOT_PATH','./');
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
// +-----------------------------------------------------------------------+
// | Check Access and exit when user status is not ok |
// +-----------------------------------------------------------------------+
check_status(ACCESS_CLASSIC);
if (!empty($_POST))
{
check_pwg_token();
}
$userdata = $user;
trigger_action('loc_begin_profile');
// Reset to default (Guest) custom settings
if (isset($_POST['reset_to_default']))
{
$fields = array(
'nb_image_page', 'maxwidth', 'maxheight', 'expand',
'show_nb_comments', 'show_nb_hits', 'recent_period', 'show_nb_hits'
);
// Get the Guest custom settings
$query = '
SELECT '.implode(',', $fields).'
FROM '.USER_INFOS_TABLE.'
WHERE user_id = '.$conf['default_user_id'].'
;';
$result = pwg_query($query);
$default_user = pwg_db_fetch_assoc($result);
$userdata = array_merge($userdata, $default_user);
}
save_profile_from_post($userdata, $errors);
$title= l10n('Your Gallery Customization');
$page['body_id'] = 'theProfilePage';
include(PHPWG_ROOT_PATH.'include/page_header.php');
load_profile_in_template(
get_root_url().'profile.php', // action
make_index_url(), // for redirect
$userdata );
// +-----------------------------------------------------------------------+
// | errors display |
// +-----------------------------------------------------------------------+
if (count($errors) != 0)
{
$template->assign('errors', $errors);
}
$template->set_filename('profile', 'profile.tpl');
trigger_action('loc_end_profile');
$template->pparse('profile');
include(PHPWG_ROOT_PATH.'include/page_tail.php');
}
//------------------------------------------------------ update & customization
function save_profile_from_post($userdata, &$errors)
{
global $conf;
$errors = array();
if (!isset($_POST['validate']))
{
return false;
}
$special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
if ($special_user)
{
unset(
$_POST['mail_address'],
$_POST['password'],
$_POST['use_new_pwd'],
$_POST['passwordConf'],
$_POST['theme'],
$_POST['language']
);
$_POST['theme'] = get_default_theme();
$_POST['language'] = get_default_language();
}
if ($conf['allow_user_customization'] or defined('IN_ADMIN'))
{
$int_pattern = '/^\d+$/';
if (empty($_POST['nb_image_page'])
or (!preg_match($int_pattern, $_POST['nb_image_page'])))
{
$errors[] = l10n('The number of photos per page must be a not null scalar');
}
if ($_POST['maxwidth'] != ''
and (!preg_match($int_pattern, $_POST['maxwidth'])
or $_POST['maxwidth'] < 50))
{
$errors[] = l10n('Maximum width must be a number superior to 50');
}
if ($_POST['maxheight']
and (!preg_match($int_pattern, $_POST['maxheight'])
or $_POST['maxheight'] < 50))
{
$errors[] = l10n('Maximum height must be a number superior to 50');
}
// periods must be integer values, they represents number of days
if (!preg_match($int_pattern, $_POST['recent_period'])
or $_POST['recent_period'] <= 0)
{
$errors[] = l10n('Recent period must be a positive integer value') ;
}
}
if (isset($_POST['mail_address']))
{
// if $_POST and $userdata have are same email
// validate_mail_address allows, however, to check email
$mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']);
if (!empty($mail_error))
{
$errors[] = $mail_error;
}
}
if (!empty($_POST['use_new_pwd']))
{
// password must be the same as its confirmation
if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
{
$errors[] = l10n('New password confirmation does not correspond');
}
if ( !defined('IN_ADMIN') )
{// changing password requires old password
$query = '
SELECT '.$conf['user_fields']['password'].' AS password
FROM '.USERS_TABLE.'
WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
;';
list($current_password) = pwg_db_fetch_row(pwg_query($query));
if ($conf['pass_convert']($_POST['password']) != $current_password)
{
$errors[] = l10n('Current password is wrong');
}
}
}
if (count($errors) == 0)
{
// mass_updates function
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
if (isset($_POST['mail_address']))
{
// update common user informations
$fields = array($conf['user_fields']['email']);
$data = array();
$data{$conf['user_fields']['id']} = $userdata['id'];
$data{$conf['user_fields']['email']} = $_POST['mail_address'];
// password is updated only if filled
if (!empty($_POST['use_new_pwd']))
{
array_push($fields, $conf['user_fields']['password']);
// password is encrpyted with function $conf['pass_convert']
$data{$conf['user_fields']['password']} =
$conf['pass_convert']($_POST['use_new_pwd']);
}
mass_updates(USERS_TABLE,
array('primary' => array($conf['user_fields']['id']),
'update' => $fields),
array($data));
}
if ($conf['allow_user_customization'] or defined('IN_ADMIN'))
{
// update user "additional" informations (specific to Piwigo)
$fields = array(
'nb_image_page', 'language', 'maxwidth', 'maxheight',
'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'theme'
);
$data = array();
$data['user_id'] = $userdata['id'];
foreach ($fields as $field)
{
if (isset($_POST[$field]))
{
$data[$field] = $_POST[$field];
}
}
mass_updates(USER_INFOS_TABLE,
array('primary' => array('user_id'), 'update' => $fields),
array($data));
}
trigger_action( 'save_profile_from_post', $userdata['id'] );
if (!empty($_POST['redirect']))
{
redirect($_POST['redirect']);
}
}
return true;
}
function load_profile_in_template($url_action, $url_redirect, $userdata)
{
global $template, $conf;
$template->set_filename('profile_content', 'profile_content.tpl');
$template->assign('radio_options',
array(
'true' => l10n('Yes'),
'false' => l10n('No')));
$template->assign(
array(
'USERNAME'=>stripslashes($userdata['username']),
'EMAIL'=>get_email_address_as_display_text(@$userdata['email']),
'ALLOW_USER_CUSTOMIZATION'=>$conf['allow_user_customization'],
'NB_IMAGE_PAGE'=>$userdata['nb_image_page'],
'RECENT_PERIOD'=>$userdata['recent_period'],
'MAXWIDTH'=>@$userdata['maxwidth'],
'MAXHEIGHT'=>@$userdata['maxheight'],
'EXPAND' =>$userdata['expand'] ? 'true' : 'false',
'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false',
'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false',
'REDIRECT' => $url_redirect,
'F_ACTION'=>$url_action,
));
$template->assign('template_selection', $userdata['theme']);
$template->assign('template_options', get_pwg_themes());
foreach (get_languages() as $language_code => $language_name)
{
if (isset($_POST['submit']) or $userdata['language'] == $language_code)
{
$template->assign('language_selection', $language_code);
}
$language_options[$language_code] = $language_name;
}
$template->assign('language_options', $language_options);
$special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
$template->assign('SPECIAL_USER', $special_user);
$template->assign('IN_ADMIN', defined('IN_ADMIN'));
// allow plugins to add their own form data to content
trigger_action( 'load_profile_in_template', $userdata );
$template->assign('PWG_TOKEN', get_pwg_token());
$template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
}
?>
|