443
by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0 |
1 |
<?php
|
2 |
/**
|
|
3 |
*
|
|
4 |
* @package ucp
|
|
5 |
* @version $Id: ucp_prefs.php,v 1.54 2007/10/05 14:36:34 acydburn Exp $
|
|
6 |
* @copyright (c) 2005 phpBB Group
|
|
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
8 |
*
|
|
9 |
*/
|
|
10 |
||
11 |
/**
|
|
12 |
* @ignore
|
|
13 |
*/
|
|
14 |
if (!defined('IN_PHPBB')) |
|
15 |
{
|
|
16 |
exit; |
|
17 |
}
|
|
18 |
||
19 |
/**
|
|
20 |
* ucp_prefs
|
|
21 |
* Changing user preferences
|
|
22 |
* @package ucp
|
|
23 |
*/
|
|
24 |
class ucp_prefs |
|
25 |
{
|
|
26 |
var $u_action; |
|
27 |
||
28 |
function main($id, $mode) |
|
29 |
{
|
|
30 |
global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; |
|
31 |
||
32 |
$submit = (isset($_POST['submit'])) ? true : false; |
|
33 |
$error = $data = array(); |
|
34 |
$s_hidden_fields = ''; |
|
35 |
||
36 |
switch ($mode) |
|
37 |
{
|
|
38 |
case 'personal': |
|
39 |
add_form_key('ucp_prefs_personal'); |
|
40 |
$data = array( |
|
41 |
'notifymethod' => request_var('notifymethod', $user->data['user_notify_type']), |
|
42 |
'dateformat' => request_var('dateformat', $user->data['user_dateformat'], true), |
|
43 |
'lang' => basename(request_var('lang', $user->data['user_lang'])), |
|
44 |
'style' => request_var('style', (int) $user->data['user_style']), |
|
45 |
'tz' => request_var('tz', (float) $user->data['user_timezone']), |
|
46 |
||
47 |
'dst' => request_var('dst', (bool) $user->data['user_dst']), |
|
48 |
'viewemail' => request_var('viewemail', (bool) $user->data['user_allow_viewemail']), |
|
49 |
'massemail' => request_var('massemail', (bool) $user->data['user_allow_massemail']), |
|
50 |
'hideonline' => request_var('hideonline', (bool) !$user->data['user_allow_viewonline']), |
|
51 |
'notifypm' => request_var('notifypm', (bool) $user->data['user_notify_pm']), |
|
52 |
'popuppm' => request_var('popuppm', (bool) $user->optionget('popuppm')), |
|
53 |
'allowpm' => request_var('allowpm', (bool) $user->data['user_allow_pm']), |
|
54 |
);
|
|
55 |
||
56 |
if ($submit) |
|
57 |
{
|
|
58 |
$data['style'] = ($config['override_user_style']) ? $config['default_style'] : $data['style']; |
|
59 |
||
60 |
$error = validate_data($data, array( |
|
61 |
'dateformat' => array('string', false, 1, 30), |
|
62 |
'lang' => array('match', false, '#^[a-z0-9_\-]{2,}$#i'), |
|
63 |
'tz' => array('num', false, -14, 14), |
|
64 |
));
|
|
65 |
||
66 |
if (!check_form_key('ucp_prefs_personal')) |
|
67 |
{
|
|
68 |
$error[] = 'FORM_INVALID'; |
|
69 |
}
|
|
70 |
||
71 |
if (!sizeof($error)) |
|
72 |
{
|
|
73 |
$user->optionset('popuppm', $data['popuppm']); |
|
74 |
||
75 |
$sql_ary = array( |
|
76 |
'user_allow_pm' => $data['allowpm'], |
|
77 |
'user_allow_viewemail' => $data['viewemail'], |
|
78 |
'user_allow_massemail' => $data['massemail'], |
|
79 |
'user_allow_viewonline' => ($auth->acl_get('u_hideonline')) ? !$data['hideonline'] : $user->data['user_allow_viewonline'], |
|
80 |
'user_notify_type' => $data['notifymethod'], |
|
81 |
'user_notify_pm' => $data['notifypm'], |
|
82 |
'user_options' => $user->data['user_options'], |
|
83 |
||
84 |
'user_dst' => $data['dst'], |
|
85 |
'user_dateformat' => $data['dateformat'], |
|
86 |
'user_lang' => $data['lang'], |
|
87 |
'user_timezone' => $data['tz'], |
|
88 |
'user_style' => $data['style'], |
|
89 |
);
|
|
90 |
||
91 |
$sql = 'UPDATE ' . USERS_TABLE . ' |
|
92 |
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
|
93 |
WHERE user_id = ' . $user->data['user_id']; |
|
94 |
$db->sql_query($sql); |
|
95 |
||
96 |
meta_refresh(3, $this->u_action); |
|
97 |
$message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
|
98 |
trigger_error($message); |
|
99 |
}
|
|
100 |
||
101 |
// Replace "error" strings with their real, localised form
|
|
102 |
$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); |
|
103 |
}
|
|
104 |
||
105 |
$dateformat_options = ''; |
|
106 |
||
107 |
foreach ($user->lang['dateformats'] as $format => $null) |
|
108 |
{
|
|
109 |
$dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>'; |
|
110 |
$dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : ''); |
|
111 |
$dateformat_options .= '</option>'; |
|
112 |
}
|
|
113 |
||
114 |
$s_custom = false; |
|
115 |
||
116 |
$dateformat_options .= '<option value="custom"'; |
|
117 |
if (!in_array($data['dateformat'], array_keys($user->lang['dateformats']))) |
|
118 |
{
|
|
119 |
$dateformat_options .= ' selected="selected"'; |
|
120 |
$s_custom = true; |
|
121 |
}
|
|
122 |
$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>'; |
|
123 |
||
124 |
$template->assign_vars(array( |
|
125 |
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', |
|
126 |
||
127 |
'S_NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false, |
|
128 |
'S_NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false, |
|
129 |
'S_NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false, |
|
130 |
'S_VIEW_EMAIL' => $data['viewemail'], |
|
131 |
'S_MASS_EMAIL' => $data['massemail'], |
|
132 |
'S_ALLOW_PM' => $data['allowpm'], |
|
133 |
'S_HIDE_ONLINE' => $data['hideonline'], |
|
134 |
'S_NOTIFY_PM' => $data['notifypm'], |
|
135 |
'S_POPUP_PM' => $data['popuppm'], |
|
136 |
'S_DST' => $data['dst'], |
|
137 |
||
138 |
'DATE_FORMAT' => $data['dateformat'], |
|
139 |
'A_DATE_FORMAT' => addslashes($data['dateformat']), |
|
140 |
'S_DATEFORMAT_OPTIONS' => $dateformat_options, |
|
141 |
'S_CUSTOM_DATEFORMAT' => $s_custom, |
|
142 |
'DEFAULT_DATEFORMAT' => $config['default_dateformat'], |
|
143 |
'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), |
|
144 |
||
145 |
'S_LANG_OPTIONS' => language_select($data['lang']), |
|
146 |
'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['style']), |
|
147 |
'S_TZ_OPTIONS' => tz_select($data['tz'], true), |
|
148 |
'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false, |
|
149 |
'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false) |
|
150 |
);
|
|
151 |
||
152 |
break; |
|
153 |
||
154 |
case 'view': |
|
155 |
||
156 |
add_form_key('ucp_prefs_view'); |
|
157 |
||
158 |
$data = array( |
|
159 |
'topic_sk' => request_var('topic_sk', (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't'), |
|
160 |
'topic_sd' => request_var('topic_sd', (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd'), |
|
161 |
'topic_st' => request_var('topic_st', (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0), |
|
162 |
||
163 |
'post_sk' => request_var('post_sk', (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't'), |
|
164 |
'post_sd' => request_var('post_sd', (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a'), |
|
165 |
'post_st' => request_var('post_st', (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0), |
|
166 |
||
167 |
'images' => request_var('images', (bool) $user->optionget('viewimg')), |
|
168 |
'flash' => request_var('flash', (bool) $user->optionget('viewflash')), |
|
169 |
'smilies' => request_var('smilies', (bool) $user->optionget('viewsmilies')), |
|
170 |
'sigs' => request_var('sigs', (bool) $user->optionget('viewsigs')), |
|
171 |
'avatars' => request_var('avatars', (bool) $user->optionget('viewavatars')), |
|
172 |
'wordcensor' => request_var('wordcensor', (bool) $user->optionget('viewcensors')), |
|
173 |
);
|
|
174 |
||
175 |
if ($submit) |
|
176 |
{
|
|
177 |
$error = validate_data($data, array( |
|
178 |
'topic_sk' => array('string', false, 1, 1), |
|
179 |
'topic_sd' => array('string', false, 1, 1), |
|
180 |
'post_sk' => array('string', false, 1, 1), |
|
181 |
'post_sd' => array('string', false, 1, 1), |
|
182 |
));
|
|
183 |
||
184 |
if (!check_form_key('ucp_prefs_view')) |
|
185 |
{
|
|
186 |
$error[] = 'FORM_INVALID'; |
|
187 |
}
|
|
188 |
||
189 |
if (!sizeof($error)) |
|
190 |
{
|
|
191 |
$user->optionset('viewimg', $data['images']); |
|
192 |
$user->optionset('viewflash', $data['flash']); |
|
193 |
$user->optionset('viewsmilies', $data['smilies']); |
|
194 |
$user->optionset('viewsigs', $data['sigs']); |
|
195 |
$user->optionset('viewavatars', $data['avatars']); |
|
196 |
||
197 |
if ($auth->acl_get('u_chgcensors')) |
|
198 |
{
|
|
199 |
$user->optionset('viewcensors', $data['wordcensor']); |
|
200 |
}
|
|
201 |
||
202 |
$sql_ary = array( |
|
203 |
'user_options' => $user->data['user_options'], |
|
204 |
'user_topic_sortby_type' => $data['topic_sk'], |
|
205 |
'user_post_sortby_type' => $data['post_sk'], |
|
206 |
'user_topic_sortby_dir' => $data['topic_sd'], |
|
207 |
'user_post_sortby_dir' => $data['post_sd'], |
|
208 |
||
209 |
'user_topic_show_days' => $data['topic_st'], |
|
210 |
'user_post_show_days' => $data['post_st'], |
|
211 |
);
|
|
212 |
||
213 |
$sql = 'UPDATE ' . USERS_TABLE . ' |
|
214 |
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
|
215 |
WHERE user_id = ' . $user->data['user_id']; |
|
216 |
$db->sql_query($sql); |
|
217 |
||
218 |
meta_refresh(3, $this->u_action); |
|
219 |
$message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
|
220 |
trigger_error($message); |
|
221 |
}
|
|
222 |
||
223 |
// Replace "error" strings with their real, localised form
|
|
224 |
$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); |
|
225 |
}
|
|
226 |
||
227 |
$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); |
|
228 |
||
229 |
// Topic ordering options
|
|
230 |
$limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
|
231 |
||
232 |
$sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); |
|
233 |
$sort_by_topic_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views'); |
|
234 |
||
235 |
// Post ordering options
|
|
236 |
$limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); |
|
237 |
||
238 |
$sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); |
|
239 |
$sort_by_post_sql = array('a' => 'u.username_clean', 't' => 'p.post_id', 's' => 'p.post_subject'); |
|
240 |
||
241 |
$_options = array('topic', 'post'); |
|
242 |
foreach ($_options as $sort_option) |
|
243 |
{
|
|
244 |
${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">'; |
|
245 |
foreach (${'limit_' . $sort_option . '_days'} as $day => $text) |
|
246 |
{
|
|
247 |
$selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : ''; |
|
248 |
${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>'; |
|
249 |
}
|
|
250 |
${'s_limit_' . $sort_option . '_days'} .= '</select>'; |
|
251 |
||
252 |
${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">'; |
|
253 |
foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text) |
|
254 |
{
|
|
255 |
$selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : ''; |
|
256 |
${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>'; |
|
257 |
}
|
|
258 |
${'s_sort_' . $sort_option . '_key'} .= '</select>'; |
|
259 |
||
260 |
${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">'; |
|
261 |
foreach ($sort_dir_text as $key => $value) |
|
262 |
{
|
|
263 |
$selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : ''; |
|
264 |
${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; |
|
265 |
}
|
|
266 |
${'s_sort_' . $sort_option . '_dir'} .= '</select>'; |
|
267 |
}
|
|
268 |
||
269 |
$template->assign_vars(array( |
|
270 |
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', |
|
271 |
||
272 |
'S_IMAGES' => $data['images'], |
|
273 |
'S_FLASH' => $data['flash'], |
|
274 |
'S_SMILIES' => $data['smilies'], |
|
275 |
'S_SIGS' => $data['sigs'], |
|
276 |
'S_AVATARS' => $data['avatars'], |
|
277 |
'S_DISABLE_CENSORS' => $data['wordcensor'], |
|
278 |
||
279 |
'S_CHANGE_CENSORS' => ($auth->acl_get('u_chgcensors')) ? true : false, |
|
280 |
||
281 |
'S_TOPIC_SORT_DAYS' => $s_limit_topic_days, |
|
282 |
'S_TOPIC_SORT_KEY' => $s_sort_topic_key, |
|
283 |
'S_TOPIC_SORT_DIR' => $s_sort_topic_dir, |
|
284 |
'S_POST_SORT_DAYS' => $s_limit_post_days, |
|
285 |
'S_POST_SORT_KEY' => $s_sort_post_key, |
|
286 |
'S_POST_SORT_DIR' => $s_sort_post_dir) |
|
287 |
);
|
|
288 |
||
289 |
break; |
|
290 |
||
291 |
case 'post': |
|
292 |
||
293 |
$data = array( |
|
294 |
'bbcode' => request_var('bbcode', $user->optionget('bbcode')), |
|
295 |
'smilies' => request_var('smilies', $user->optionget('smilies')), |
|
296 |
'sig' => request_var('sig', $user->optionget('attachsig')), |
|
297 |
'notify' => request_var('notify', $user->data['user_notify']), |
|
298 |
);
|
|
299 |
add_form_key('ucp_prefs_post'); |
|
300 |
||
301 |
if ($submit) |
|
302 |
{
|
|
303 |
if (check_form_key('ucp_prefs_post')) |
|
304 |
{
|
|
305 |
$user->optionset('bbcode', $data['bbcode']); |
|
306 |
$user->optionset('smilies', $data['smilies']); |
|
307 |
$user->optionset('attachsig', $data['sig']); |
|
308 |
||
309 |
$sql_ary = array( |
|
310 |
'user_options' => $user->data['user_options'], |
|
311 |
'user_notify' => $data['notify'], |
|
312 |
);
|
|
313 |
||
314 |
$sql = 'UPDATE ' . USERS_TABLE . ' |
|
315 |
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
|
316 |
WHERE user_id = ' . $user->data['user_id']; |
|
317 |
$db->sql_query($sql); |
|
318 |
||
319 |
$msg = $user->lang['PREFERENCES_UPDATED']; |
|
320 |
}
|
|
321 |
else
|
|
322 |
{
|
|
323 |
$msg = $user->lang['FORM_INVALID']; |
|
324 |
}
|
|
325 |
meta_refresh(3, $this->u_action); |
|
326 |
$message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
|
327 |
trigger_error($message); |
|
328 |
}
|
|
329 |
||
330 |
$template->assign_vars(array( |
|
331 |
'S_BBCODE' => $data['bbcode'], |
|
332 |
'S_SMILIES' => $data['smilies'], |
|
333 |
'S_SIG' => $data['sig'], |
|
334 |
'S_NOTIFY' => $data['notify']) |
|
335 |
);
|
|
336 |
break; |
|
337 |
}
|
|
338 |
||
339 |
$template->assign_vars(array( |
|
340 |
'L_TITLE' => $user->lang['UCP_PREFS_' . strtoupper($mode)], |
|
341 |
||
342 |
'S_HIDDEN_FIELDS' => $s_hidden_fields, |
|
343 |
'S_UCP_ACTION' => $this->u_action) |
|
344 |
);
|
|
345 |
||
346 |
$this->tpl_name = 'ucp_prefs_' . $mode; |
|
347 |
$this->page_title = 'UCP_PREFS_' . strtoupper($mode); |
|
348 |
}
|
|
349 |
}
|
|
350 |
||
351 |
?>
|