Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 450 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ucp_profile | |
0.00% |
0 / 448 |
|
0.00% |
0 / 1 |
17030 | |
0.00% |
0 / 1 |
| main | |
0.00% |
0 / 448 |
|
0.00% |
0 / 1 |
17030 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | use phpbb\messenger\method\messenger_interface; |
| 15 | |
| 16 | /** |
| 17 | * @ignore |
| 18 | */ |
| 19 | if (!defined('IN_PHPBB')) |
| 20 | { |
| 21 | exit; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * ucp_profile |
| 26 | * Changing profile settings |
| 27 | * |
| 28 | * @todo what about pertaining user_sig_options? |
| 29 | */ |
| 30 | class ucp_profile |
| 31 | { |
| 32 | var $u_action; |
| 33 | |
| 34 | function main($id, $mode) |
| 35 | { |
| 36 | global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; |
| 37 | global $request, $phpbb_container, $phpbb_log, $phpbb_dispatcher, $language; |
| 38 | |
| 39 | $user->add_lang('posting'); |
| 40 | |
| 41 | $submit = $request->variable('submit', false, false, \phpbb\request\request_interface::POST); |
| 42 | $error = array(); |
| 43 | $s_hidden_fields = ''; |
| 44 | |
| 45 | switch ($mode) |
| 46 | { |
| 47 | case 'reg_details': |
| 48 | |
| 49 | $data = array( |
| 50 | 'username' => $request->variable('username', $user->data['username'], true), |
| 51 | 'email' => strtolower($request->variable('email', $user->data['user_email'])), |
| 52 | 'new_password' => $request->variable('new_password', '', true), |
| 53 | 'cur_password' => $request->variable('cur_password', '', true), |
| 54 | 'password_confirm' => $request->variable('password_confirm', '', true), |
| 55 | ); |
| 56 | |
| 57 | /** |
| 58 | * Modify user registration data on editing account settings in UCP |
| 59 | * |
| 60 | * @event core.ucp_profile_reg_details_data |
| 61 | * @var array data Array with current or updated user registration data |
| 62 | * @var bool submit Flag indicating if submit button has been pressed |
| 63 | * @since 3.1.4-RC1 |
| 64 | */ |
| 65 | $vars = array('data', 'submit'); |
| 66 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_reg_details_data', compact($vars))); |
| 67 | |
| 68 | add_form_key('ucp_reg_details'); |
| 69 | |
| 70 | if ($submit) |
| 71 | { |
| 72 | // Do not check cur_password, it is the old one. |
| 73 | $check_ary = array( |
| 74 | 'new_password' => array( |
| 75 | array('string', true, $config['min_pass_chars'], 0), |
| 76 | array('password')), |
| 77 | 'password_confirm' => array('string', true, $config['min_pass_chars'], 0), |
| 78 | 'email' => array( |
| 79 | array('string', false, 6, 60), |
| 80 | array('user_email')), |
| 81 | ); |
| 82 | |
| 83 | if ($auth->acl_get('u_chgname') && $config['allow_namechange']) |
| 84 | { |
| 85 | $check_ary['username'] = array( |
| 86 | array('string', false, $config['min_name_chars'], $config['max_name_chars']), |
| 87 | array('username'), |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | $error = validate_data($data, $check_ary); |
| 92 | |
| 93 | if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && $data['password_confirm'] != $data['new_password']) |
| 94 | { |
| 95 | $error[] = ($data['password_confirm']) ? 'NEW_PASSWORD_ERROR' : 'NEW_PASSWORD_CONFIRM_EMPTY'; |
| 96 | } |
| 97 | |
| 98 | // Instantiate passwords manager |
| 99 | /* @var $passwords_manager \phpbb\passwords\manager */ |
| 100 | $passwords_manager = $phpbb_container->get('passwords.manager'); |
| 101 | |
| 102 | // Only check the new password against the previous password if there have been no errors |
| 103 | if (!count($error) && $auth->acl_get('u_chgpasswd') && $data['new_password'] && $passwords_manager->check($data['new_password'], $user->data['user_password'])) |
| 104 | { |
| 105 | $error[] = 'SAME_PASSWORD_ERROR'; |
| 106 | } |
| 107 | |
| 108 | if (!$passwords_manager->check($data['cur_password'], $user->data['user_password'])) |
| 109 | { |
| 110 | $error[] = ($data['cur_password']) ? 'CUR_PASSWORD_ERROR' : 'CUR_PASSWORD_EMPTY'; |
| 111 | } |
| 112 | |
| 113 | if (!check_form_key('ucp_reg_details')) |
| 114 | { |
| 115 | $error[] = 'FORM_INVALID'; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Validate user data on editing registration data in UCP |
| 120 | * |
| 121 | * @event core.ucp_profile_reg_details_validate |
| 122 | * @var array data Array with user profile data |
| 123 | * @var bool submit Flag indicating if submit button has been pressed |
| 124 | * @var array error Array of any generated errors |
| 125 | * @since 3.1.4-RC1 |
| 126 | */ |
| 127 | $vars = array('data', 'submit', 'error'); |
| 128 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_reg_details_validate', compact($vars))); |
| 129 | |
| 130 | if (!count($error)) |
| 131 | { |
| 132 | $sql_ary = array( |
| 133 | 'username' => ($auth->acl_get('u_chgname') && $config['allow_namechange']) ? $data['username'] : $user->data['username'], |
| 134 | 'username_clean' => ($auth->acl_get('u_chgname') && $config['allow_namechange']) ? utf8_clean_string($data['username']) : $user->data['username_clean'], |
| 135 | 'user_email' => ($auth->acl_get('u_chgemail')) ? $data['email'] : $user->data['user_email'], |
| 136 | 'user_password' => ($auth->acl_get('u_chgpasswd') && $data['new_password']) ? $passwords_manager->hash($data['new_password']) : $user->data['user_password'], |
| 137 | ); |
| 138 | |
| 139 | if ($auth->acl_get('u_chgname') && $config['allow_namechange'] && $data['username'] != $user->data['username']) |
| 140 | { |
| 141 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_NAME', false, array( |
| 142 | 'reportee_id' => $user->data['user_id'], |
| 143 | $user->data['username'], |
| 144 | $data['username'] |
| 145 | )); |
| 146 | } |
| 147 | |
| 148 | if ($auth->acl_get('u_chgpasswd') && $data['new_password']) |
| 149 | { |
| 150 | $sql_ary['user_passchg'] = time(); |
| 151 | |
| 152 | $user->reset_login_keys(); |
| 153 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_NEW_PASSWORD', false, array( |
| 154 | 'reportee_id' => $user->data['user_id'], |
| 155 | $user->data['username'] |
| 156 | )); |
| 157 | } |
| 158 | |
| 159 | if ($auth->acl_get('u_chgemail') && $data['email'] != $user->data['user_email']) |
| 160 | { |
| 161 | $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_EMAIL', false, array( |
| 162 | 'reportee_id' => $user->data['user_id'], |
| 163 | $user->data['username'], |
| 164 | $user->data['user_email'], |
| 165 | $data['email'] |
| 166 | )); |
| 167 | } |
| 168 | |
| 169 | $message = 'PROFILE_UPDATED'; |
| 170 | |
| 171 | if ($auth->acl_get('u_chgemail') && $config['email_enable'] && $data['email'] != $user->data['user_email'] && $user->data['user_type'] != USER_FOUNDER && ($config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN)) |
| 172 | { |
| 173 | $message = ($config['require_activation'] == USER_ACTIVATION_SELF) ? 'ACCOUNT_EMAIL_CHANGED' : 'ACCOUNT_EMAIL_CHANGED_ADMIN'; |
| 174 | |
| 175 | $server_url = generate_board_url(); |
| 176 | |
| 177 | $user_actkey = gen_rand_string(mt_rand(6, 10)); |
| 178 | |
| 179 | $email_method = $phpbb_container->get('messenger.method.email'); |
| 180 | $template_file = ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? 'user_activate_inactive' : 'user_activate'; |
| 181 | $email_method->template($template_file, $user->data['user_lang']); |
| 182 | $email_method->to($data['email'], $data['username']); |
| 183 | $email_method->anti_abuse_headers($config, $user); |
| 184 | $email_method->assign_vars([ |
| 185 | 'USERNAME' => html_entity_decode($data['username'], ENT_COMPAT), |
| 186 | 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user->data['user_id']}&k=$user_actkey", |
| 187 | ]); |
| 188 | $email_method->send(); |
| 189 | |
| 190 | if ($config['require_activation'] == USER_ACTIVATION_ADMIN) |
| 191 | { |
| 192 | $notifications_manager = $phpbb_container->get('notification_manager'); |
| 193 | $notifications_manager->add_notifications('notification.type.admin_activate_user', array( |
| 194 | 'user_id' => $user->data['user_id'], |
| 195 | 'user_actkey' => $user_actkey, |
| 196 | 'user_actkey_expiration' => $user::get_token_expiration(), |
| 197 | 'user_regdate' => time(), // Notification time |
| 198 | )); |
| 199 | } |
| 200 | |
| 201 | user_active_flip('deactivate', $user->data['user_id'], INACTIVE_PROFILE); |
| 202 | |
| 203 | // Because we want the profile to be reactivated we set user_newpasswd to empty (else the reactivation will fail) |
| 204 | $sql_ary['user_actkey'] = $user_actkey; |
| 205 | $sql_ary['user_newpasswd'] = ''; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Modify user registration data before submitting it to the database |
| 210 | * |
| 211 | * @event core.ucp_profile_reg_details_sql_ary |
| 212 | * @var array data Array with current or updated user registration data |
| 213 | * @var array sql_ary Array with user registration data to submit to the database |
| 214 | * @since 3.1.4-RC1 |
| 215 | */ |
| 216 | $vars = array('data', 'sql_ary'); |
| 217 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_reg_details_sql_ary', compact($vars))); |
| 218 | |
| 219 | if (count($sql_ary)) |
| 220 | { |
| 221 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 222 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 223 | WHERE user_id = ' . $user->data['user_id']; |
| 224 | $db->sql_query($sql); |
| 225 | } |
| 226 | |
| 227 | // Need to update config, forum, topic, posting, messages, etc. |
| 228 | if ($data['username'] != $user->data['username'] && $auth->acl_get('u_chgname') && $config['allow_namechange']) |
| 229 | { |
| 230 | user_update_name($user->data['username'], $data['username']); |
| 231 | } |
| 232 | |
| 233 | // Now, we can remove the user completely (kill the session) - NOT BEFORE!!! |
| 234 | if (!empty($sql_ary['user_actkey'])) |
| 235 | { |
| 236 | meta_refresh(5, append_sid($phpbb_root_path . 'index.' . $phpEx)); |
| 237 | $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($phpbb_root_path . 'index.' . $phpEx) . '">', '</a>'); |
| 238 | |
| 239 | // Because the user gets deactivated we log him out too, killing his session |
| 240 | $user->session_kill(); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | meta_refresh(3, $this->u_action); |
| 245 | $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
| 246 | } |
| 247 | |
| 248 | trigger_error($message); |
| 249 | } |
| 250 | |
| 251 | // Replace "error" strings with their real, localised form |
| 252 | $error = array_map(array($user, 'lang'), $error); |
| 253 | } |
| 254 | |
| 255 | $template->assign_vars(array( |
| 256 | 'ERROR' => (count($error)) ? implode('<br />', $error) : '', |
| 257 | |
| 258 | 'USERNAME' => $data['username'], |
| 259 | 'EMAIL' => $data['email'], |
| 260 | 'PASSWORD_CONFIRM' => $data['password_confirm'], |
| 261 | 'NEW_PASSWORD' => $data['new_password'], |
| 262 | 'CUR_PASSWORD' => '', |
| 263 | |
| 264 | 'L_USERNAME_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS_XY', (int) $config['min_name_chars']), $user->lang('CHARACTERS_XY', (int) $config['max_name_chars'])), |
| 265 | 'L_CHANGE_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars'])), |
| 266 | |
| 267 | 'S_FORCE_PASSWORD' => ($auth->acl_get('u_chgpasswd') && $config['chg_passforce'] && $user->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400)) ? true : false, |
| 268 | 'S_CHANGE_USERNAME' => ($config['allow_namechange'] && $auth->acl_get('u_chgname')) ? true : false, |
| 269 | 'S_CHANGE_EMAIL' => ($auth->acl_get('u_chgemail')) ? true : false, |
| 270 | 'S_CHANGE_PASSWORD' => ($auth->acl_get('u_chgpasswd')) ? true : false) |
| 271 | ); |
| 272 | break; |
| 273 | |
| 274 | case 'profile_info': |
| 275 | // Do not display profile information panel if not authed to do so |
| 276 | if (!$auth->acl_get('u_chgprofileinfo')) |
| 277 | { |
| 278 | send_status_line(403, 'Forbidden'); |
| 279 | trigger_error('NO_AUTH_PROFILEINFO'); |
| 280 | } |
| 281 | |
| 282 | /* @var $cp \phpbb\profilefields\manager */ |
| 283 | $cp = $phpbb_container->get('profilefields.manager'); |
| 284 | |
| 285 | $cp_data = $cp_error = array(); |
| 286 | |
| 287 | $data = []; |
| 288 | |
| 289 | if ($config['allow_birthdays']) |
| 290 | { |
| 291 | $data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0; |
| 292 | |
| 293 | if ($user->data['user_birthday']) |
| 294 | { |
| 295 | list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user->data['user_birthday']); |
| 296 | } |
| 297 | |
| 298 | $data['bday_day'] = $request->variable('bday_day', $data['bday_day']); |
| 299 | $data['bday_month'] = $request->variable('bday_month', $data['bday_month']); |
| 300 | $data['bday_year'] = $request->variable('bday_year', $data['bday_year']); |
| 301 | $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Modify user data on editing profile in UCP |
| 306 | * |
| 307 | * @event core.ucp_profile_modify_profile_info |
| 308 | * @var array data Array with user profile data |
| 309 | * @var bool submit Flag indicating if submit button has been pressed |
| 310 | * @since 3.1.4-RC1 |
| 311 | */ |
| 312 | $vars = array('data', 'submit'); |
| 313 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_modify_profile_info', compact($vars))); |
| 314 | |
| 315 | add_form_key('ucp_profile_info'); |
| 316 | |
| 317 | if ($submit) |
| 318 | { |
| 319 | $validate_array = []; |
| 320 | |
| 321 | if ($config['allow_birthdays']) |
| 322 | { |
| 323 | $validate_array = array_merge($validate_array, array( |
| 324 | 'bday_day' => array('num', true, 1, 31), |
| 325 | 'bday_month' => array('num', true, 1, 12), |
| 326 | 'bday_year' => array('num', true, 1901, gmdate('Y', time()) + 50), |
| 327 | 'user_birthday' => array('date', true), |
| 328 | )); |
| 329 | } |
| 330 | |
| 331 | $error = validate_data($data, $validate_array); |
| 332 | |
| 333 | // validate custom profile fields |
| 334 | $cp->submit_cp_field('profile', $user->get_iso_lang_id(), $cp_data, $cp_error); |
| 335 | |
| 336 | if (count($cp_error)) |
| 337 | { |
| 338 | $error = array_merge($error, $cp_error); |
| 339 | } |
| 340 | |
| 341 | if (!check_form_key('ucp_profile_info')) |
| 342 | { |
| 343 | $error[] = 'FORM_INVALID'; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Validate user data on editing profile in UCP |
| 348 | * |
| 349 | * @event core.ucp_profile_validate_profile_info |
| 350 | * @var array data Array with user profile data |
| 351 | * @var bool submit Flag indicating if submit button has been pressed |
| 352 | * @var array error Array of any generated errors |
| 353 | * @since 3.1.4-RC1 |
| 354 | */ |
| 355 | $vars = array('data', 'submit', 'error'); |
| 356 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_validate_profile_info', compact($vars))); |
| 357 | |
| 358 | if (!count($error)) |
| 359 | { |
| 360 | $sql_ary = []; |
| 361 | |
| 362 | if ($config['allow_birthdays']) |
| 363 | { |
| 364 | $sql_ary['user_birthday'] = $data['user_birthday']; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Modify profile data in UCP before submitting to the database |
| 369 | * |
| 370 | * @event core.ucp_profile_info_modify_sql_ary |
| 371 | * @var array cp_data Array with the user custom profile fields data |
| 372 | * @var array data Array with user profile data |
| 373 | * @var array sql_ary user options data we update |
| 374 | * @since 3.1.4-RC1 |
| 375 | */ |
| 376 | $vars = array('cp_data', 'data', 'sql_ary'); |
| 377 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_info_modify_sql_ary', compact($vars))); |
| 378 | |
| 379 | // Skip query if no data to update |
| 380 | if (count($sql_ary)) |
| 381 | { |
| 382 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 383 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 384 | WHERE user_id = ' . $user->data['user_id']; |
| 385 | $db->sql_query($sql); |
| 386 | } |
| 387 | |
| 388 | // Always update custom fields |
| 389 | $cp->update_profile_field_data($user->data['user_id'], $cp_data); |
| 390 | |
| 391 | meta_refresh(3, $this->u_action); |
| 392 | $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
| 393 | trigger_error($message); |
| 394 | } |
| 395 | |
| 396 | // Replace "error" strings with their real, localised form |
| 397 | $error = array_map(array($user, 'lang'), $error); |
| 398 | } |
| 399 | |
| 400 | if ($config['allow_birthdays']) |
| 401 | { |
| 402 | $s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>'; |
| 403 | for ($i = 1; $i < 32; $i++) |
| 404 | { |
| 405 | $selected = ($i == $data['bday_day']) ? ' selected="selected"' : ''; |
| 406 | $s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>"; |
| 407 | } |
| 408 | |
| 409 | $s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>'; |
| 410 | for ($i = 1; $i < 13; $i++) |
| 411 | { |
| 412 | $selected = ($i == $data['bday_month']) ? ' selected="selected"' : ''; |
| 413 | $s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>"; |
| 414 | } |
| 415 | |
| 416 | $now = getdate(); |
| 417 | $s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>'; |
| 418 | for ($i = $now['year'] - 100; $i <= $now['year']; $i++) |
| 419 | { |
| 420 | $selected = ($i == $data['bday_year']) ? ' selected="selected"' : ''; |
| 421 | $s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>"; |
| 422 | } |
| 423 | unset($now); |
| 424 | |
| 425 | $template->assign_vars(array( |
| 426 | 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, |
| 427 | 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, |
| 428 | 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, |
| 429 | 'S_BIRTHDAYS_ENABLED' => true, |
| 430 | )); |
| 431 | } |
| 432 | |
| 433 | $template->assign_vars(array( |
| 434 | 'ERROR' => (count($error)) ? implode('<br />', $error) : '', |
| 435 | )); |
| 436 | |
| 437 | // Get additional profile fields and assign them to the template block var 'profile_fields' |
| 438 | $user->get_profile_fields($user->data['user_id']); |
| 439 | |
| 440 | $cp->generate_profile_fields('profile', $user->get_iso_lang_id()); |
| 441 | |
| 442 | break; |
| 443 | |
| 444 | case 'signature': |
| 445 | |
| 446 | if (!$auth->acl_get('u_sig')) |
| 447 | { |
| 448 | send_status_line(403, 'Forbidden'); |
| 449 | trigger_error('NO_AUTH_SIGNATURE'); |
| 450 | } |
| 451 | |
| 452 | if (!function_exists('generate_smilies')) |
| 453 | { |
| 454 | include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); |
| 455 | } |
| 456 | |
| 457 | if (!function_exists('display_custom_bbcodes')) |
| 458 | { |
| 459 | include($phpbb_root_path . 'includes/functions_display.' . $phpEx); |
| 460 | } |
| 461 | |
| 462 | $preview = $request->is_set_post('preview'); |
| 463 | |
| 464 | $enable_bbcode = ($config['allow_sig_bbcode']) ? $user->optionget('sig_bbcode') : false; |
| 465 | $enable_smilies = ($config['allow_sig_smilies']) ? $user->optionget('sig_smilies') : false; |
| 466 | $enable_urls = ($config['allow_sig_links']) ? $user->optionget('sig_links') : false; |
| 467 | |
| 468 | $bbcode_flags = ($enable_bbcode ? OPTION_FLAG_BBCODE : 0) + ($enable_smilies ? OPTION_FLAG_SMILIES : 0) + ($enable_urls ? OPTION_FLAG_LINKS : 0); |
| 469 | |
| 470 | $decoded_message = generate_text_for_edit($user->data['user_sig'], $user->data['user_sig_bbcode_uid'], $bbcode_flags); |
| 471 | $signature = $request->variable('signature', $decoded_message['text'], true); |
| 472 | $signature_preview = ''; |
| 473 | |
| 474 | if ($submit || $preview) |
| 475 | { |
| 476 | $enable_bbcode = ($config['allow_sig_bbcode']) ? !$request->variable('disable_bbcode', false) : false; |
| 477 | $enable_smilies = ($config['allow_sig_smilies']) ? !$request->variable('disable_smilies', false) : false; |
| 478 | $enable_urls = ($config['allow_sig_links']) ? !$request->variable('disable_magic_url', false) : false; |
| 479 | |
| 480 | if (!check_form_key('ucp_sig')) |
| 481 | { |
| 482 | $error[] = 'FORM_INVALID'; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Modify user signature on editing profile in UCP |
| 488 | * |
| 489 | * @event core.ucp_profile_modify_signature |
| 490 | * @var bool enable_bbcode Whether or not bbcode is enabled |
| 491 | * @var bool enable_smilies Whether or not smilies are enabled |
| 492 | * @var bool enable_urls Whether or not urls are enabled |
| 493 | * @var string signature Users signature text |
| 494 | * @var array error Any error strings |
| 495 | * @var bool submit Whether or not the form has been sumitted |
| 496 | * @var bool preview Whether or not the signature is being previewed |
| 497 | * @since 3.1.10-RC1 |
| 498 | * @changed 3.2.0-RC2 Removed message parser |
| 499 | */ |
| 500 | $vars = array( |
| 501 | 'enable_bbcode', |
| 502 | 'enable_smilies', |
| 503 | 'enable_urls', |
| 504 | 'signature', |
| 505 | 'error', |
| 506 | 'submit', |
| 507 | 'preview', |
| 508 | ); |
| 509 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_modify_signature', compact($vars))); |
| 510 | |
| 511 | $bbcode_uid = $bbcode_bitfield = $bbcode_flags = ''; |
| 512 | $warn_msg = generate_text_for_storage( |
| 513 | $signature, |
| 514 | $bbcode_uid, |
| 515 | $bbcode_bitfield, |
| 516 | $bbcode_flags, |
| 517 | $enable_bbcode, |
| 518 | $enable_urls, |
| 519 | $enable_smilies, |
| 520 | $config['allow_sig_img'], |
| 521 | true, |
| 522 | $config['allow_sig_links'], |
| 523 | 'sig' |
| 524 | ); |
| 525 | |
| 526 | if (count($warn_msg)) |
| 527 | { |
| 528 | $error += $warn_msg; |
| 529 | } |
| 530 | |
| 531 | if (!$submit) |
| 532 | { |
| 533 | // Parse it for displaying |
| 534 | $signature_preview = generate_text_for_display($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags); |
| 535 | } |
| 536 | else |
| 537 | { |
| 538 | if (!count($error)) |
| 539 | { |
| 540 | $user->optionset('sig_bbcode', $enable_bbcode); |
| 541 | $user->optionset('sig_smilies', $enable_smilies); |
| 542 | $user->optionset('sig_links', $enable_urls); |
| 543 | |
| 544 | $sql_ary = array( |
| 545 | 'user_sig' => $signature, |
| 546 | 'user_options' => $user->data['user_options'], |
| 547 | 'user_sig_bbcode_uid' => $bbcode_uid, |
| 548 | 'user_sig_bbcode_bitfield' => $bbcode_bitfield |
| 549 | ); |
| 550 | |
| 551 | /** |
| 552 | * Modify user registration data before submitting it to the database |
| 553 | * |
| 554 | * @event core.ucp_profile_modify_signature_sql_ary |
| 555 | * @var array sql_ary Array with user signature data to submit to the database |
| 556 | * @since 3.1.10-RC1 |
| 557 | */ |
| 558 | $vars = array('sql_ary'); |
| 559 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_modify_signature_sql_ary', compact($vars))); |
| 560 | |
| 561 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 562 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 563 | WHERE user_id = ' . $user->data['user_id']; |
| 564 | $db->sql_query($sql); |
| 565 | |
| 566 | $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
| 567 | trigger_error($message); |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | // Replace "error" strings with their real, localised form |
| 572 | $error = array_map(array($user, 'lang'), $error); |
| 573 | |
| 574 | if ($request->is_set_post('preview')) |
| 575 | { |
| 576 | $decoded_message = generate_text_for_edit($signature, $bbcode_uid, $bbcode_flags); |
| 577 | } |
| 578 | |
| 579 | /** @var \phpbb\controller\helper $controller_helper */ |
| 580 | $controller_helper = $phpbb_container->get('controller.helper'); |
| 581 | |
| 582 | $template->assign_vars(array( |
| 583 | 'ERROR' => (count($error)) ? implode('<br />', $error) : '', |
| 584 | 'SIGNATURE' => $decoded_message['text'], |
| 585 | 'SIGNATURE_PREVIEW' => $signature_preview, |
| 586 | |
| 587 | 'S_BBCODE_CHECKED' => (!$enable_bbcode) ? ' checked="checked"' : '', |
| 588 | 'S_SMILIES_CHECKED' => (!$enable_smilies) ? ' checked="checked"' : '', |
| 589 | 'S_MAGIC_URL_CHECKED' => (!$enable_urls) ? ' checked="checked"' : '', |
| 590 | |
| 591 | 'BBCODE_STATUS' => $user->lang(($config['allow_sig_bbcode'] ? 'BBCODE_IS_ON' : 'BBCODE_IS_OFF'), '<a href="' . $controller_helper->route('phpbb_help_bbcode_controller') . '">', '</a>'), |
| 592 | 'SMILIES_STATUS' => ($config['allow_sig_smilies']) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], |
| 593 | 'IMG_STATUS' => ($config['allow_sig_img']) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], |
| 594 | 'URL_STATUS' => ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], |
| 595 | 'MAX_FONT_SIZE' => (int) $config['max_sig_font_size'], |
| 596 | |
| 597 | 'L_SIGNATURE_EXPLAIN' => $user->lang('SIGNATURE_EXPLAIN', (int) $config['max_sig_chars']), |
| 598 | |
| 599 | 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], |
| 600 | 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'], |
| 601 | 'S_BBCODE_IMG' => ($config['allow_sig_img']) ? true : false, |
| 602 | 'S_LINKS_ALLOWED' => ($config['allow_sig_links']) ? true : false) |
| 603 | ); |
| 604 | |
| 605 | add_form_key('ucp_sig'); |
| 606 | |
| 607 | // Build custom bbcodes array |
| 608 | display_custom_bbcodes(); |
| 609 | |
| 610 | // Generate smiley listing |
| 611 | generate_smilies('inline', 0); |
| 612 | |
| 613 | break; |
| 614 | |
| 615 | case 'avatar': |
| 616 | |
| 617 | add_form_key('ucp_avatar'); |
| 618 | |
| 619 | $avatars_enabled = false; |
| 620 | |
| 621 | if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) |
| 622 | { |
| 623 | /* @var $phpbb_avatar_manager \phpbb\avatar\manager */ |
| 624 | $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); |
| 625 | $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); |
| 626 | |
| 627 | // This is normalised data, without the user_ prefix |
| 628 | $avatar_data = \phpbb\avatar\manager::clean_row($user->data, 'user'); |
| 629 | |
| 630 | if ($submit) |
| 631 | { |
| 632 | if (check_form_key('ucp_avatar')) |
| 633 | { |
| 634 | $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', '')); |
| 635 | |
| 636 | if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) |
| 637 | { |
| 638 | $driver = $phpbb_avatar_manager->get_driver($driver_name); |
| 639 | $result = $driver->process_form($request, $template, $user, $avatar_data, $error); |
| 640 | |
| 641 | if ($result && empty($error)) |
| 642 | { |
| 643 | // Success! Lets save the result in the database |
| 644 | $result = array( |
| 645 | 'user_avatar_type' => $driver_name, |
| 646 | 'user_avatar' => $result['avatar'], |
| 647 | 'user_avatar_width' => $result['avatar_width'], |
| 648 | 'user_avatar_height' => $result['avatar_height'], |
| 649 | ); |
| 650 | |
| 651 | /** |
| 652 | * Trigger events on successful avatar change |
| 653 | * |
| 654 | * @event core.ucp_profile_avatar_sql |
| 655 | * @var array result Array with data to be stored in DB |
| 656 | * @since 3.1.11-RC1 |
| 657 | */ |
| 658 | $vars = array('result'); |
| 659 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_avatar_sql', compact($vars))); |
| 660 | |
| 661 | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 662 | SET ' . $db->sql_build_array('UPDATE', $result) . ' |
| 663 | WHERE user_id = ' . (int) $user->data['user_id']; |
| 664 | $db->sql_query($sql); |
| 665 | |
| 666 | if ($request->is_ajax()) |
| 667 | { |
| 668 | $json_response = new \phpbb\json_response; |
| 669 | $json_response->send(array( |
| 670 | 'success' => true, |
| 671 | |
| 672 | 'MESSAGE_TITLE' => $language->lang('INFORMATION'), |
| 673 | 'MESSAGE_TEXT' => $language->lang('PROFILE_UPDATED'), |
| 674 | 'REFRESH_DATA' => [ |
| 675 | 'time' => 3, |
| 676 | 'url' => $this->u_action, |
| 677 | 'text' => $language->lang('RETURN_TO_UCP'), |
| 678 | ] |
| 679 | )); |
| 680 | } |
| 681 | else |
| 682 | { |
| 683 | meta_refresh(3, $this->u_action); |
| 684 | $message = $language->lang('PROFILE_UPDATED') . '<br><br>' . $language->lang('RETURN_UCP', '<a href="' . $this->u_action . '">', '</a>'); |
| 685 | trigger_error($message); |
| 686 | } |
| 687 | } |
| 688 | else if ($request->is_ajax()) |
| 689 | { |
| 690 | $error = $phpbb_avatar_manager->localize_errors($user, $error); |
| 691 | |
| 692 | $json_response = new \phpbb\json_response; |
| 693 | $json_response->send([ |
| 694 | 'success' => false, |
| 695 | 'error' => [ |
| 696 | 'title' => $language->lang('INFORMATION'), |
| 697 | 'messages' => $error, |
| 698 | ], |
| 699 | ]); |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | else |
| 704 | { |
| 705 | $error[] = 'FORM_INVALID'; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | // Handle deletion of avatars |
| 710 | if ($request->is_set_post('avatar_delete')) |
| 711 | { |
| 712 | if (!confirm_box(true)) |
| 713 | { |
| 714 | confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array( |
| 715 | 'avatar_delete' => true, |
| 716 | 'i' => $id, |
| 717 | 'mode' => $mode)) |
| 718 | ); |
| 719 | } |
| 720 | else |
| 721 | { |
| 722 | $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, USERS_TABLE, 'user_'); |
| 723 | |
| 724 | meta_refresh(3, $this->u_action); |
| 725 | $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
| 726 | trigger_error($message); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type'])); |
| 731 | |
| 732 | $template->assign_vars(array( |
| 733 | 'AVATAR_MIN_WIDTH' => $config['avatar_min_width'], |
| 734 | 'AVATAR_MAX_WIDTH' => $config['avatar_max_width'], |
| 735 | 'AVATAR_MIN_HEIGHT' => $config['avatar_min_height'], |
| 736 | 'AVATAR_MAX_HEIGHT' => $config['avatar_max_height'], |
| 737 | )); |
| 738 | |
| 739 | foreach ($avatar_drivers as $current_driver) |
| 740 | { |
| 741 | $driver = $phpbb_avatar_manager->get_driver($current_driver); |
| 742 | |
| 743 | $avatars_enabled = true; |
| 744 | $template->set_filenames(array( |
| 745 | 'avatar' => $driver->get_template_name(), |
| 746 | )); |
| 747 | |
| 748 | if ($driver->prepare_form($request, $template, $user, $avatar_data, $error)) |
| 749 | { |
| 750 | $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver); |
| 751 | $driver_upper = strtoupper($driver_name); |
| 752 | |
| 753 | $template->assign_block_vars('avatar_drivers', array( |
| 754 | 'L_TITLE' => $user->lang($driver_upper . '_TITLE'), |
| 755 | 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), |
| 756 | |
| 757 | 'DRIVER' => $driver_name, |
| 758 | 'SELECTED' => $current_driver == $selected_driver, |
| 759 | 'OUTPUT' => $template->assign_display('avatar'), |
| 760 | )); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | // Replace "error" strings with their real, localised form |
| 765 | $error = $phpbb_avatar_manager->localize_errors($user, $error); |
| 766 | } |
| 767 | |
| 768 | /** @var \phpbb\avatar\helper $avatar_helper */ |
| 769 | $avatar_helper = $phpbb_container->get('avatar.helper'); |
| 770 | |
| 771 | $avatar = $avatar_helper->get_user_avatar($user->data, 'USER_AVATAR', true); |
| 772 | $template->assign_vars($avatar_helper->get_template_vars($avatar)); |
| 773 | |
| 774 | $template->assign_vars(array( |
| 775 | 'ERROR' => !empty($error) ? implode('<br />', $error) : '', |
| 776 | |
| 777 | 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', |
| 778 | |
| 779 | 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), |
| 780 | |
| 781 | 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), |
| 782 | )); |
| 783 | |
| 784 | break; |
| 785 | |
| 786 | case 'autologin_keys': |
| 787 | |
| 788 | add_form_key('ucp_autologin_keys'); |
| 789 | |
| 790 | if ($submit) |
| 791 | { |
| 792 | $keys = $request->variable('keys', array('')); |
| 793 | |
| 794 | if (!check_form_key('ucp_autologin_keys')) |
| 795 | { |
| 796 | $error[] = 'FORM_INVALID'; |
| 797 | } |
| 798 | |
| 799 | if (!count($error)) |
| 800 | { |
| 801 | if (!empty($keys)) |
| 802 | { |
| 803 | foreach ($keys as $key => $id) |
| 804 | { |
| 805 | $keys[$key] = $db->sql_like_expression($id . $db->get_any_char()); |
| 806 | } |
| 807 | $sql_where = '(key_id ' . implode(' OR key_id ', $keys) . ')'; |
| 808 | $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' |
| 809 | WHERE user_id = ' . (int) $user->data['user_id'] . ' |
| 810 | AND ' . $sql_where ; |
| 811 | |
| 812 | $db->sql_query($sql); |
| 813 | |
| 814 | meta_refresh(3, $this->u_action); |
| 815 | $message = $user->lang['AUTOLOGIN_SESSION_KEYS_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); |
| 816 | trigger_error($message); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | // Replace "error" strings with their real, localised form |
| 821 | $error = array_map(array($user, 'lang'), $error); |
| 822 | } |
| 823 | |
| 824 | $sql_ary = [ |
| 825 | 'SELECT' => 'sk.key_id, sk.last_ip, sk.last_login', |
| 826 | 'FROM' => [SESSIONS_KEYS_TABLE => 'sk'], |
| 827 | 'WHERE' => 'sk.user_id = ' . (int) $user->data['user_id'], |
| 828 | 'ORDER_BY' => 'sk.last_login ASC', |
| 829 | ]; |
| 830 | |
| 831 | /** |
| 832 | * Event allows changing SQL query for autologin keys |
| 833 | * |
| 834 | * @event core.ucp_profile_autologin_keys_sql |
| 835 | * @var array sql_ary Array with autologin keys SQL query |
| 836 | * @since 3.3.2-RC1 |
| 837 | */ |
| 838 | $vars = ['sql_ary']; |
| 839 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_autologin_keys_sql', compact($vars))); |
| 840 | |
| 841 | $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); |
| 842 | $sessions = (array) $db->sql_fetchrowset($result); |
| 843 | $db->sql_freeresult($result); |
| 844 | |
| 845 | $template_vars = []; |
| 846 | foreach ($sessions as $row) |
| 847 | { |
| 848 | $key = substr($row['key_id'], 0, 8); |
| 849 | $template_vars[$key] = [ |
| 850 | 'KEY' => $key, |
| 851 | 'IP' => $row['last_ip'], |
| 852 | 'LOGIN_TIME' => $user->format_date($row['last_login']), |
| 853 | ]; |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * Event allows changing template variables |
| 858 | * |
| 859 | * @event core.ucp_profile_autologin_keys_template_vars |
| 860 | * @var array sessions Array with session keys data |
| 861 | * @var array template_vars Array with template variables |
| 862 | * @since 3.3.2-RC1 |
| 863 | */ |
| 864 | $vars = ['sessions', 'template_vars']; |
| 865 | extract($phpbb_dispatcher->trigger_event('core.ucp_profile_autologin_keys_template_vars', compact($vars))); |
| 866 | |
| 867 | $template->assign_block_vars_array('sessions', $template_vars); |
| 868 | |
| 869 | break; |
| 870 | } |
| 871 | |
| 872 | $template->assign_vars(array( |
| 873 | 'ERROR' => (count($error)) ? implode('<br />', $error) : '', |
| 874 | |
| 875 | 'L_TITLE' => $user->lang['UCP_PROFILE_' . strtoupper($mode)], |
| 876 | |
| 877 | 'S_HIDDEN_FIELDS' => $s_hidden_fields, |
| 878 | 'S_UCP_ACTION' => $this->u_action) |
| 879 | ); |
| 880 | |
| 881 | // Set desired template |
| 882 | $this->tpl_name = 'ucp_profile_' . $mode; |
| 883 | $this->page_title = 'UCP_PROFILE_' . strtoupper($mode); |
| 884 | } |
| 885 | } |