| Conditions | 87 |
| Paths | > 20000 |
| Total Lines | 683 |
| Code Lines | 388 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 215 | public function loadProfileFields($force_reload = false): void |
||
| 216 | { |
||
| 217 | global $context, $profile_fields, $txt, $scripturl, $modSettings, $cur_profile, $language, $settings; |
||
| 218 | |||
| 219 | // Don't load this twice! |
||
| 220 | if (!empty($profile_fields) && !$force_reload) |
||
| 221 | { |
||
| 222 | return; |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * This horrific array defines all the profile fields in the whole world! |
||
| 227 | * In general each "field" has one array - the key of which is the database |
||
| 228 | * column name associated with said field. |
||
| 229 | * |
||
| 230 | * Each item can have the following attributes: |
||
| 231 | * |
||
| 232 | * string $type: The type of field this is - valid types are: |
||
| 233 | * - callback: This is a field which has its own callback mechanism for templating. |
||
| 234 | * - check: A simple checkbox. |
||
| 235 | * - hidden: This doesn't have any visual aspects but may have some validity. |
||
| 236 | * - password: A password box. |
||
| 237 | * - select: A select box. |
||
| 238 | * - text: A string of some description. |
||
| 239 | * |
||
| 240 | * string $label: The label for this item - default will be $txt[$key] if this isn't set. |
||
| 241 | * string $subtext: The subtext (Small label) for this item. |
||
| 242 | * int $size: Optional size for a text area. |
||
| 243 | * array $input_attr: An array of text strings to be added to the input box for this item. |
||
| 244 | * string $value: The value of the item. If not set $cur_profile[$key] is assumed. |
||
| 245 | * string $permission: Permission required for this item (Excluded _any/_own suffix which is applied automatically). |
||
| 246 | * func $input_validate: A runtime function which validates the element before going to the database. It is passed |
||
| 247 | * the relevant $_POST element if it exists and should be treated like a reference. |
||
| 248 | * |
||
| 249 | * Return types: |
||
| 250 | * - true: Element can be stored. |
||
| 251 | * - false: Skip this element. |
||
| 252 | * - a text string: An error occurred - this is the error message. |
||
| 253 | * |
||
| 254 | * function $preload: A function that is used to load data required for this element to be displayed. Must return |
||
| 255 | * true to be displayed at all. |
||
| 256 | * |
||
| 257 | * string $cast_type: If set casts the element to a certain type. Valid types (bool, int, float). |
||
| 258 | * string $save_key: If the index of this element isn't the database column name it can be overridden with this string. |
||
| 259 | * bool $is_dummy: If set then nothing is acted upon for this element. |
||
| 260 | * bool $enabled: A test to determine whether this is even available - if not is unset. |
||
| 261 | * string $link_with: Key which links this field to an overall set. |
||
| 262 | * |
||
| 263 | * string $js_submit: javascript to add inside the function checkProfileSubmit() in the template |
||
| 264 | * string $js: javascript to add to the page in general |
||
| 265 | * string $js_load: filename of js to be loaded with loadJavasciptFile |
||
| 266 | * |
||
| 267 | * Note that all elements that have a custom input_validate must ensure they set the value of $cur_profile correct to enable |
||
| 268 | * the changes to be displayed correctly on submit of the form. |
||
| 269 | */ |
||
| 270 | |||
| 271 | $profile_fields = [ |
||
| 272 | 'avatar_choice' => [ |
||
| 273 | 'type' => 'callback', |
||
| 274 | 'callback_func' => 'avatar_select', |
||
| 275 | // This handles the permissions too. |
||
| 276 | 'preload' => 'profileLoadAvatarData', |
||
| 277 | 'input_validate' => 'profileSaveAvatarData', |
||
| 278 | 'save_key' => 'avatar', |
||
| 279 | ], |
||
| 280 | 'bday1' => [ |
||
| 281 | 'type' => 'callback', |
||
| 282 | 'callback_func' => 'birthdate', |
||
| 283 | 'permission' => 'profile_extra', |
||
| 284 | 'preload' => static function () { |
||
| 285 | global $cur_profile, $context; |
||
| 286 | |||
| 287 | // Split up the birth date.... |
||
| 288 | [$uyear, $umonth, $uday] = explode('-', empty($cur_profile['birthdate']) || $cur_profile['birthdate'] === '0001-01-01' ? '0000-00-00' : $cur_profile['birthdate']); |
||
| 289 | $context['member']['birth_date'] = [ |
||
| 290 | 'year' => $uyear === '0004' ? '0000' : $uyear, |
||
| 291 | 'month' => $umonth, |
||
| 292 | 'day' => $uday, |
||
| 293 | ]; |
||
| 294 | |||
| 295 | return true; |
||
| 296 | }, |
||
| 297 | 'input_validate' => static function (&$value) { |
||
| 298 | global $profile_vars, $cur_profile; |
||
| 299 | |||
| 300 | if (isset($_POST['bday1'])) |
||
| 301 | { |
||
| 302 | $date_parts = explode('-', $_POST['bday1']); |
||
| 303 | $bday3 = isset($date_parts[0]) ? (int) $date_parts[0] : 1; // Year |
||
| 304 | $bday1 = isset($date_parts[1]) ? (int) $date_parts[1] : 1; // Month |
||
| 305 | $bday2 = isset($date_parts[2]) ? (int) $date_parts[2] : 1; // Day |
||
| 306 | |||
| 307 | // Set to blank? |
||
| 308 | if ($bday3 === 1 && $bday2 === 1 && $bday1 === 1) |
||
| 309 | { |
||
| 310 | $value = '0001-01-01'; |
||
| 311 | } |
||
| 312 | else |
||
| 313 | { |
||
| 314 | $value = checkdate($bday1, $bday2, max($bday3, 4)) ? sprintf('%04d-%02d-%02d', max($bday3, 4), $bday1, $bday2) : '0001-01-01'; |
||
| 315 | } |
||
| 316 | } |
||
| 317 | else |
||
| 318 | { |
||
| 319 | $value = '0001-01-01'; |
||
| 320 | } |
||
| 321 | $profile_vars['birthdate'] = $value; |
||
| 322 | $cur_profile['birthdate'] = $value; |
||
| 323 | |||
| 324 | return false; |
||
| 325 | }, |
||
| 326 | ], |
||
| 327 | 'date_registered' => [ |
||
| 328 | 'type' => 'date', |
||
| 329 | 'value' => empty($cur_profile['date_registered']) ? $txt['not_applicable'] : Util::strftime('%Y-%m-%d', $cur_profile['date_registered'] + (User::$info->time_offset + $modSettings['time_offset']) * 3600), |
||
| 330 | 'label' => $txt['date_registered'], |
||
| 331 | 'log_change' => true, |
||
| 332 | 'permission' => 'moderate_forum', |
||
| 333 | 'input_validate' => static function (&$value) { |
||
| 334 | global $txt, $modSettings, $cur_profile; |
||
| 335 | |||
| 336 | // Bad date! Go try again - please? |
||
| 337 | if (($value = strtotime($value)) === -1) |
||
| 338 | { |
||
| 339 | $value = $cur_profile['date_registered']; |
||
| 340 | |||
| 341 | return $txt['invalid_registration'] . ' ' . Util::strftime('%d %b %Y ' . (strpos(User::$info->time_format, '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false)); |
||
| 342 | } |
||
| 343 | |||
| 344 | // As long as it doesn't equal "N/A"... |
||
| 345 | if ($value !== $txt['not_applicable'] && $value !== strtotime(Util::strftime('%Y-%m-%d', $cur_profile['date_registered'] + (User::$info->time_offset + $modSettings['time_offset']) * 3600))) |
||
| 346 | { |
||
| 347 | $value -= (User::$info->time_offset + $modSettings['time_offset']) * 3600; |
||
| 348 | } |
||
| 349 | else |
||
| 350 | { |
||
| 351 | $value = $cur_profile['date_registered']; |
||
| 352 | } |
||
| 353 | |||
| 354 | return true; |
||
| 355 | }, |
||
| 356 | ], |
||
| 357 | 'email_address' => [ |
||
| 358 | 'type' => 'email', |
||
| 359 | 'label' => $txt['user_email_address'], |
||
| 360 | 'subtext' => $txt['valid_email'], |
||
| 361 | 'log_change' => true, |
||
| 362 | 'permission' => 'profile_identity', |
||
| 363 | 'input_validate' => function ($value) { |
||
| 364 | global $context, $old_profile, $profile_vars, $modSettings; |
||
| 365 | |||
| 366 | if (strtolower($value) === strtolower($old_profile['email_address'])) |
||
| 367 | { |
||
| 368 | return false; |
||
| 369 | } |
||
| 370 | |||
| 371 | $isValid = ProfileFields::profileValidateEmail($value, $context['id_member']); |
||
| 372 | |||
| 373 | // Do they need to re-validate? If so schedule the function! |
||
| 374 | if ($isValid === true && !empty($modSettings['send_validation_onChange']) && !allowedTo('moderate_forum')) |
||
| 375 | { |
||
| 376 | require_once(SUBSDIR . '/Auth.subs.php'); |
||
| 377 | $old_profile['validation_code'] = generateValidationCode(14); |
||
| 378 | $profile_vars['validation_code'] = substr(hash('sha256', $old_profile['validation_code']), 0, 10); |
||
| 379 | $profile_vars['is_activated'] = 2; |
||
| 380 | $context['profile_execute_on_save'][] = 'profileSendActivation'; |
||
| 381 | unset($context['profile_execute_on_save']['reload_user']); |
||
| 382 | } |
||
| 383 | |||
| 384 | return $isValid; |
||
| 385 | }, |
||
| 386 | ], |
||
| 387 | // Selecting group membership is a complicated one, so we treat it separate! |
||
| 388 | 'id_group' => [ |
||
| 389 | 'type' => 'callback', |
||
| 390 | 'callback_func' => 'group_manage', |
||
| 391 | 'permission' => 'manage_membergroups', |
||
| 392 | 'preload' => 'profileLoadGroups', |
||
| 393 | 'log_change' => true, |
||
| 394 | 'input_validate' => 'profileSaveGroups', |
||
| 395 | ], |
||
| 396 | 'id_theme' => [ |
||
| 397 | 'type' => 'callback', |
||
| 398 | 'callback_func' => 'theme_pick', |
||
| 399 | 'permission' => 'profile_extra', |
||
| 400 | 'enabled' => empty($settings['disable_user_variant']) || !empty($modSettings['theme_allow']) || allowedTo('admin_forum'), |
||
| 401 | 'preload' => static function () { |
||
| 402 | global $context, $cur_profile, $txt; |
||
| 403 | |||
| 404 | $db = database(); |
||
| 405 | $request = $db->query('', ' |
||
| 406 | SELECT value |
||
| 407 | FROM {db_prefix}themes |
||
| 408 | WHERE id_theme = {int:id_theme} |
||
| 409 | AND variable = {string:variable} |
||
| 410 | LIMIT 1', [ |
||
| 411 | 'id_theme' => $cur_profile['id_theme'], |
||
| 412 | 'variable' => 'name', |
||
| 413 | ] |
||
| 414 | ); |
||
| 415 | [$name] = $request->fetch_row(); |
||
| 416 | $request->free_result(); |
||
| 417 | $context['member']['theme'] = [ |
||
| 418 | 'id' => $cur_profile['id_theme'], |
||
| 419 | 'name' => empty($cur_profile['id_theme']) ? $txt['theme_forum_default'] : $name |
||
| 420 | ]; |
||
| 421 | |||
| 422 | return true; |
||
| 423 | }, |
||
| 424 | 'input_validate' => static function (&$value) { |
||
| 425 | $value = (int) $value; |
||
| 426 | return true; |
||
| 427 | }, |
||
| 428 | ], |
||
| 429 | 'karma_good' => [ |
||
| 430 | 'type' => 'callback', |
||
| 431 | 'callback_func' => 'karma_modify', |
||
| 432 | 'permission' => 'admin_forum', |
||
| 433 | // Set karma_bad too! |
||
| 434 | 'input_validate' => static function (&$value) { |
||
| 435 | global $profile_vars, $cur_profile; |
||
| 436 | |||
| 437 | $value = (int) $value; |
||
| 438 | if (isset($_POST['karma_bad'])) |
||
| 439 | { |
||
| 440 | $profile_vars['karma_bad'] = $_POST['karma_bad'] !== '' ? (int) $_POST['karma_bad'] : 0; |
||
| 441 | $cur_profile['karma_bad'] = $_POST['karma_bad'] !== '' ? (int) $_POST['karma_bad'] : 0; |
||
| 442 | } |
||
| 443 | |||
| 444 | return true; |
||
| 445 | }, |
||
| 446 | 'preload' => static function () { |
||
| 447 | global $context, $cur_profile; |
||
| 448 | |||
| 449 | $context['member']['karma'] = [ |
||
| 450 | 'good' => (int) $cur_profile['karma_good'], |
||
| 451 | 'bad' => (int) $cur_profile['karma_bad'] |
||
| 452 | ]; |
||
| 453 | |||
| 454 | return true; |
||
| 455 | }, |
||
| 456 | 'enabled' => !empty($modSettings['karmaMode']), |
||
| 457 | ], |
||
| 458 | 'lngfile' => [ |
||
| 459 | 'type' => 'select', |
||
| 460 | 'options' => 'return $context[\'profile_languages\'];', |
||
| 461 | 'label' => $txt['preferred_language'], |
||
| 462 | 'permission' => 'profile_identity', |
||
| 463 | 'preload' => 'profileLoadLanguages', |
||
| 464 | 'enabled' => !empty($modSettings['userLanguage']), |
||
| 465 | 'value' => empty($cur_profile['lngfile']) ? $language : $cur_profile['lngfile'], |
||
| 466 | 'input_validate' => static function (&$value) { |
||
| 467 | global $context, $cur_profile; |
||
| 468 | |||
| 469 | // Load the languages. |
||
| 470 | profileLoadLanguages(); |
||
| 471 | if (isset($context['profile_languages'][$value])) |
||
| 472 | { |
||
| 473 | if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) |
||
| 474 | { |
||
| 475 | $_SESSION['language'] = $value; |
||
| 476 | } |
||
| 477 | |||
| 478 | return true; |
||
| 479 | } |
||
| 480 | |||
| 481 | $value = $cur_profile['lngfile']; |
||
| 482 | |||
| 483 | return false; |
||
| 484 | }, |
||
| 485 | ], |
||
| 486 | // The username is not always editable - so adjust it as such. |
||
| 487 | 'member_name' => [ |
||
| 488 | 'type' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? 'text' : 'label', |
||
| 489 | 'label' => $txt['username'], |
||
| 490 | 'subtext' => allowedTo('admin_forum') && !isset($_GET['changeusername']) ? '[<a href="' . $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=account;changeusername" class="em">' . $txt['username_change'] . '</a>]' : '', |
||
| 491 | 'log_change' => true, |
||
| 492 | 'permission' => 'profile_identity', |
||
| 493 | 'prehtml' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? '<div class="warningbox">' . $txt['username_warning'] . '</div>' : '', |
||
| 494 | 'input_validate' => static function (&$value) { |
||
| 495 | global $context, $cur_profile; |
||
| 496 | |||
| 497 | if (allowedTo('admin_forum')) |
||
| 498 | { |
||
| 499 | // We'll need this... |
||
| 500 | require_once(SUBSDIR . '/Auth.subs.php'); |
||
| 501 | |||
| 502 | // Maybe they are trying to change their password as well? |
||
| 503 | $resetPassword = true; |
||
| 504 | if (isset($_POST['passwrd1'], $_POST['passwrd2']) && $_POST['passwrd1'] !== '' && $_POST['passwrd1'] === $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, [$cur_profile['real_name'], User::$info->username, User::$info->name, User::$info->email]) === null) |
||
| 505 | { |
||
| 506 | $resetPassword = false; |
||
| 507 | } |
||
| 508 | |||
| 509 | // Do the reset... this will email them too. |
||
| 510 | if ($resetPassword) |
||
| 511 | { |
||
| 512 | resetPassword($context['id_member'], $value); |
||
| 513 | } |
||
| 514 | elseif ($value !== null) |
||
| 515 | { |
||
| 516 | $errors = ErrorContext::context('change_username', 0); |
||
| 517 | |||
| 518 | validateUsername($context['id_member'], $value, 'change_username'); |
||
| 519 | |||
| 520 | // No errors we can proceed normally |
||
| 521 | if (!$errors->hasErrors()) |
||
| 522 | { |
||
| 523 | updateMemberData($context['id_member'], ['member_name' => $value]); |
||
| 524 | } |
||
| 525 | else |
||
| 526 | { |
||
| 527 | // If there are "important" errors, and you are not an admin: log the first error |
||
| 528 | // Otherwise grab all of them and do not log anything |
||
| 529 | $error_severity = $errors->hasErrors(1) && User::$info->is_admin === false ? 1 : null; |
||
| 530 | foreach ($errors->prepareErrors($error_severity) as $error) |
||
| 531 | { |
||
| 532 | throw new Exception($error, $error_severity === null ? false : 'general'); |
||
| 533 | } |
||
| 534 | } |
||
| 535 | } |
||
| 536 | } |
||
| 537 | |||
| 538 | return false; |
||
| 539 | }, |
||
| 540 | ], |
||
| 541 | 'passwrd1' => [ |
||
| 542 | 'type' => 'password', |
||
| 543 | 'label' => ucwords($txt['choose_pass']), |
||
| 544 | 'subtext' => $txt['password_strength'], |
||
| 545 | 'size' => 20, |
||
| 546 | 'value' => '', |
||
| 547 | 'enabled' => true, |
||
| 548 | 'permission' => 'profile_identity', |
||
| 549 | 'save_key' => 'passwd', |
||
| 550 | // Note this will only work if passwrd2 also exists! |
||
| 551 | 'input_validate' => static function (&$value) { |
||
| 552 | global $cur_profile; |
||
| 553 | |||
| 554 | // If we didn't try it then ignore it! |
||
| 555 | if ($value === '') |
||
| 556 | { |
||
| 557 | return false; |
||
| 558 | } |
||
| 559 | |||
| 560 | // Do the two entries for the password even match? |
||
| 561 | if (!isset($_POST['passwrd2']) || $value !== $_POST['passwrd2']) |
||
| 562 | { |
||
| 563 | return 'bad_new_password'; |
||
| 564 | } |
||
| 565 | |||
| 566 | // Let's get the validation function into play... |
||
| 567 | require_once(SUBSDIR . '/Auth.subs.php'); |
||
| 568 | $passwordErrors = validatePassword($value, $cur_profile['member_name'], [$cur_profile['real_name'], User::$info->username, User::$info->name, User::$info->email]); |
||
| 569 | |||
| 570 | // Were there errors? |
||
| 571 | if ($passwordErrors !== null) |
||
| 572 | { |
||
| 573 | return 'password_' . $passwordErrors; |
||
| 574 | } |
||
| 575 | |||
| 576 | // Set up the new password variable... ready for storage. |
||
| 577 | require_once(SUBSDIR . '/Auth.subs.php'); |
||
| 578 | $value = validateLoginPassword($value, '', $cur_profile['member_name'], true); |
||
| 579 | |||
| 580 | return true; |
||
| 581 | }, |
||
| 582 | ], |
||
| 583 | 'passwrd2' => [ |
||
| 584 | 'type' => 'password', |
||
| 585 | 'label' => ucwords($txt['verify_pass']), |
||
| 586 | 'enabled' => true, |
||
| 587 | 'size' => 20, |
||
| 588 | 'value' => '', |
||
| 589 | 'permission' => 'profile_identity', |
||
| 590 | 'is_dummy' => true, |
||
| 591 | ], |
||
| 592 | 'enable_otp' => [ |
||
| 593 | 'type' => 'check', |
||
| 594 | 'value' => !empty($cur_profile['enable_otp']), |
||
| 595 | 'subtext' => $txt['otp_enabled_help'], |
||
| 596 | 'label' => $txt['otp_enabled'], |
||
| 597 | 'permission' => 'profile_identity', |
||
| 598 | ], |
||
| 599 | 'otp_secret' => [ |
||
| 600 | 'type' => 'text', |
||
| 601 | 'label' => ucwords($txt['otp_token']), |
||
| 602 | 'subtext' => $txt['otp_token_help'], |
||
| 603 | 'enabled' => true, |
||
| 604 | 'size' => 20, |
||
| 605 | 'value' => empty($cur_profile['otp_secret']) ? '' : $cur_profile['otp_secret'], |
||
| 606 | 'postinput' => '<div style="display: inline-block;"><input type="button" value="' . $txt['otp_generate'] . '" onclick="generateSecret();"></div><div id="qrcode"></div>', |
||
| 607 | 'permission' => 'profile_identity', |
||
| 608 | ], |
||
| 609 | // This does contact-related settings |
||
| 610 | 'receive_from' => [ |
||
| 611 | 'type' => 'select', |
||
| 612 | 'options' => [ |
||
| 613 | $txt['receive_from_everyone'], |
||
| 614 | $txt['receive_from_ignore'], |
||
| 615 | $txt['receive_from_buddies'], |
||
| 616 | $txt['receive_from_admins'], |
||
| 617 | ], |
||
| 618 | 'subtext' => $txt['receive_from_description'], |
||
| 619 | 'value' => empty($cur_profile['receive_from']) ? 0 : $cur_profile['receive_from'], |
||
| 620 | 'input_validate' => static function (&$value) { |
||
| 621 | global $cur_profile, $profile_vars; |
||
| 622 | |||
| 623 | // Simple validate and apply the two "sub settings" |
||
| 624 | $value = max(min($value, 3), 0); |
||
| 625 | $cur_profile['receive_from'] = $profile_vars['receive_from'] = max(min((int) $_POST['receive_from'], 4), 0); |
||
| 626 | |||
| 627 | return true; |
||
| 628 | }, |
||
| 629 | ], |
||
| 630 | // This does ALL the pm settings |
||
| 631 | 'pm_settings' => [ |
||
| 632 | 'type' => 'callback', |
||
| 633 | 'callback_func' => 'pm_settings', |
||
| 634 | 'permission' => 'pm_read', |
||
| 635 | 'save_key' => 'pm_prefs', |
||
| 636 | 'preload' => static function () { |
||
| 637 | global $context, $cur_profile; |
||
| 638 | |||
| 639 | $context['display_mode'] = $cur_profile['pm_prefs'] & 3; |
||
| 640 | $context['send_email'] = $cur_profile['pm_email_notify']; |
||
| 641 | |||
| 642 | return true; |
||
| 643 | }, |
||
| 644 | 'input_validate' => static function (&$value) { |
||
| 645 | global $cur_profile, $profile_vars; |
||
| 646 | |||
| 647 | // Simple validate and apply the two "sub settings" |
||
| 648 | $value = max(min($value, 2), 0); |
||
| 649 | $cur_profile['pm_email_notify'] = $profile_vars['pm_email_notify'] = max(min((int) $_POST['pm_email_notify'], 2), 0); |
||
| 650 | |||
| 651 | return true; |
||
| 652 | }, |
||
| 653 | ], |
||
| 654 | 'posts' => [ |
||
| 655 | 'type' => 'int', |
||
| 656 | 'label' => $txt['profile_posts'], |
||
| 657 | 'log_change' => true, |
||
| 658 | 'size' => 7, |
||
| 659 | 'permission' => 'moderate_forum', |
||
| 660 | 'input_validate' => static function (&$value) { |
||
| 661 | // Account for comma_format presentation up front |
||
| 662 | $check = strtr($value, [',' => '', '.' => '', ' ' => '']); |
||
| 663 | if (!is_numeric($check)) |
||
| 664 | { |
||
| 665 | return 'digits_only'; |
||
| 666 | } |
||
| 667 | $value = $check !== '' ? $check : 0; |
||
| 668 | |||
| 669 | return true; |
||
| 670 | }, |
||
| 671 | ], |
||
| 672 | 'real_name' => [ |
||
| 673 | 'type' => !empty($modSettings['allow_editDisplayName']) || allowedTo('moderate_forum') ? 'text' : 'label', |
||
| 674 | 'label' => $txt['name'], |
||
| 675 | 'subtext' => $txt['display_name_desc'], |
||
| 676 | 'log_change' => true, |
||
| 677 | 'input_attr' => ['maxlength="60"'], |
||
| 678 | 'permission' => 'profile_identity', |
||
| 679 | 'enabled' => !empty($modSettings['allow_editDisplayName']) || allowedTo('moderate_forum'), |
||
| 680 | 'input_validate' => static function (&$value) { |
||
| 681 | global $context, $cur_profile; |
||
| 682 | |||
| 683 | $value = trim(preg_replace('~\s~u', ' ', $value)); |
||
| 684 | if (trim($value) === '') |
||
| 685 | { |
||
| 686 | return 'no_name'; |
||
| 687 | } |
||
| 688 | |||
| 689 | if (Util::strlen($value) > 60) |
||
| 690 | { |
||
| 691 | return 'name_too_long'; |
||
| 692 | } |
||
| 693 | |||
| 694 | if ($cur_profile['real_name'] !== $value) |
||
| 695 | { |
||
| 696 | require_once(SUBSDIR . '/Members.subs.php'); |
||
| 697 | if (isReservedName($value, $context['id_member'])) |
||
| 698 | { |
||
| 699 | return 'name_taken'; |
||
| 700 | } |
||
| 701 | } |
||
| 702 | |||
| 703 | return true; |
||
| 704 | }, |
||
| 705 | ], |
||
| 706 | 'secret_question' => [ |
||
| 707 | 'type' => 'text', |
||
| 708 | 'label' => $txt['secret_question'], |
||
| 709 | 'subtext' => $txt['secret_desc'], |
||
| 710 | 'size' => 50, |
||
| 711 | 'permission' => 'profile_identity', |
||
| 712 | ], |
||
| 713 | 'secret_answer' => [ |
||
| 714 | 'type' => 'text', |
||
| 715 | 'label' => $txt['secret_answer'], |
||
| 716 | 'subtext' => $txt['secret_desc2'], |
||
| 717 | 'size' => 20, |
||
| 718 | 'postinput' => '<span class="smalltext" style="margin-left: 4ex;">[<a href="' . $scripturl . '?action=quickhelp;help=secret_why_blank" onclick="return reqOverlayDiv(this.href);">' . $txt['secret_why_blank'] . '</a>]</span>', |
||
| 719 | 'value' => '', |
||
| 720 | 'permission' => 'profile_identity', |
||
| 721 | 'input_validate' => static function (&$value) { |
||
| 722 | global $cur_profile; |
||
| 723 | |||
| 724 | if (empty($value)) |
||
| 725 | { |
||
| 726 | require_once(SUBSDIR . '/Members.subs.php'); |
||
| 727 | $member = getBasicMemberData($cur_profile['id_member'], ['authentication' => true]); |
||
| 728 | |||
| 729 | // No previous answer was saved, so that\'s all good |
||
| 730 | if (empty($member['secret_answer'])) |
||
| 731 | { |
||
| 732 | return true; |
||
| 733 | } |
||
| 734 | |||
| 735 | // There is a previous secret answer to the secret question, so let\'s put it back in the db... |
||
| 736 | $value = $member['secret_answer']; |
||
| 737 | |||
| 738 | // We have to tell the code is an error otherwise an empty value will go into the db |
||
| 739 | return false; |
||
| 740 | } |
||
| 741 | |||
| 742 | $value = $value !== '' ? md5($value) : ''; |
||
| 743 | |||
| 744 | return true; |
||
| 745 | }, |
||
| 746 | ], |
||
| 747 | 'signature' => [ |
||
| 748 | 'type' => 'callback', |
||
| 749 | 'callback_func' => 'signature_modify', |
||
| 750 | 'permission' => 'profile_extra', |
||
| 751 | 'enabled' => strpos($modSettings['signature_settings'], (string) 1) === 0, |
||
| 752 | 'preload' => 'profileLoadSignatureData', |
||
| 753 | 'input_validate' => 'profileValidateSignature', |
||
| 754 | ], |
||
| 755 | 'show_online' => [ |
||
| 756 | 'type' => 'check', |
||
| 757 | 'label' => $txt['show_online'], |
||
| 758 | 'permission' => 'profile_identity', |
||
| 759 | 'enabled' => !empty($modSettings['allow_hideOnline']) || allowedTo('moderate_forum'), |
||
| 760 | ], |
||
| 761 | // Pretty much a dummy entry - it populates all the theme settings. |
||
| 762 | 'theme_settings' => [ |
||
| 763 | 'type' => 'callback', |
||
| 764 | 'callback_func' => 'theme_settings', |
||
| 765 | 'permission' => 'profile_extra', |
||
| 766 | 'is_dummy' => true, |
||
| 767 | 'preload' => static function () { |
||
| 768 | global $context; |
||
| 769 | |||
| 770 | Txt::load('Settings'); |
||
| 771 | |||
| 772 | // Can they disable censoring? |
||
| 773 | $context['allow_no_censored'] = false; |
||
| 774 | if (User::$info->is_admin || $context['user']['is_owner']) |
||
| 775 | { |
||
| 776 | $context['allow_no_censored'] = allowedTo('disable_censor'); |
||
| 777 | } |
||
| 778 | |||
| 779 | return true; |
||
| 780 | }, |
||
| 781 | ], |
||
| 782 | 'time_format' => [ |
||
| 783 | 'type' => 'callback', |
||
| 784 | 'callback_func' => 'timeformat_modify', |
||
| 785 | 'permission' => 'profile_extra', |
||
| 786 | 'preload' => static function () { |
||
| 787 | global $context, $txt, $cur_profile, $modSettings; |
||
| 788 | |||
| 789 | $context['easy_timeformats'] = [ |
||
| 790 | ['format' => '', 'title' => $txt['timeformat_default']], |
||
| 791 | ['format' => '%B %d, %Y, %I:%M:%S %p', 'title' => $txt['timeformat_easy1']], |
||
| 792 | ['format' => '%B %d, %Y, %H:%M:%S', 'title' => $txt['timeformat_easy2']], |
||
| 793 | ['format' => '%Y-%m-%d, %H:%M:%S', 'title' => $txt['timeformat_easy3']], |
||
| 794 | ['format' => '%d %B %Y, %H:%M:%S', 'title' => $txt['timeformat_easy4']], |
||
| 795 | ['format' => '%d-%m-%Y, %H:%M:%S', 'title' => $txt['timeformat_easy5']] |
||
| 796 | ]; |
||
| 797 | $context['member']['time_format'] = $cur_profile['time_format']; |
||
| 798 | $context['current_forum_time'] = standardTime(time() - User::$info->time_offset * 3600, false); |
||
| 799 | $context['current_forum_time_js'] = Util::strftime('%Y,' . ((int) Util::strftime('%m', time() + $modSettings['time_offset'] * 3600) - 1) . ',%d,%H,%M,%S', time() + $modSettings['time_offset'] * 3600); |
||
| 800 | $context['current_forum_time_hour'] = (int) Util::strftime('%H', forum_time(false)); |
||
| 801 | |||
| 802 | return true; |
||
| 803 | }, |
||
| 804 | ], |
||
| 805 | 'time_offset' => [ |
||
| 806 | 'type' => 'callback', |
||
| 807 | 'callback_func' => 'timeoffset_modify', |
||
| 808 | 'permission' => 'profile_extra', |
||
| 809 | 'preload' => static function () { |
||
| 810 | global $context, $cur_profile; |
||
| 811 | |||
| 812 | $context['member']['time_offset'] = $cur_profile['time_offset']; |
||
| 813 | |||
| 814 | return true; |
||
| 815 | }, |
||
| 816 | 'input_validate' => static function (&$value) { |
||
| 817 | // Validate the time_offset... |
||
| 818 | $value = (float) str_replace(',', '.', $value); |
||
| 819 | if ($value < -23.5 || $value > 23.5) |
||
| 820 | { |
||
| 821 | return 'bad_offset'; |
||
| 822 | } |
||
| 823 | |||
| 824 | return true; |
||
| 825 | }, |
||
| 826 | ], |
||
| 827 | 'usertitle' => [ |
||
| 828 | 'type' => 'text', |
||
| 829 | 'label' => $txt['custom_title'], |
||
| 830 | 'log_change' => true, |
||
| 831 | 'input_attr' => ['maxlength="50"'], |
||
| 832 | 'size' => 50, |
||
| 833 | 'permission' => 'profile_title', |
||
| 834 | 'enabled' => !empty($modSettings['titlesEnable']), |
||
| 835 | 'input_validate' => static function ($value) { |
||
| 836 | if (Util::strlen($value) > 50) |
||
| 837 | { |
||
| 838 | return 'user_title_too_long'; |
||
| 839 | } |
||
| 840 | |||
| 841 | return true; |
||
| 842 | }, |
||
| 843 | ], |
||
| 844 | 'website_title' => [ |
||
| 845 | 'type' => 'text', |
||
| 846 | 'label' => $txt['website_title'], |
||
| 847 | 'subtext' => $txt['include_website_url'], |
||
| 848 | 'size' => 50, |
||
| 849 | 'permission' => 'profile_extra', |
||
| 850 | 'link_with' => 'website', |
||
| 851 | ], |
||
| 852 | 'website_url' => [ |
||
| 853 | 'type' => 'url', |
||
| 854 | 'label' => $txt['website_url'], |
||
| 855 | 'subtext' => $txt['complete_url'], |
||
| 856 | 'size' => 50, |
||
| 857 | 'permission' => 'profile_extra', |
||
| 858 | // Fix the URL... |
||
| 859 | 'input_validate' => static function (&$value) { |
||
| 860 | $value = addProtocol($value, ['http://', 'https://', 'ftp://', 'ftps://']); |
||
| 861 | if (strlen($value) < 8) |
||
| 862 | { |
||
| 863 | $value = ''; |
||
| 864 | } |
||
| 865 | |||
| 866 | return true; |
||
| 867 | }, |
||
| 868 | 'link_with' => 'website', |
||
| 869 | ], |
||
| 870 | ]; |
||
| 871 | |||
| 872 | call_integration_hook('integrate_load_profile_fields', [&$profile_fields]); |
||
| 873 | |||
| 874 | $disabled_fields = empty($modSettings['disabled_profile_fields']) ? [] : explode(',', $modSettings['disabled_profile_fields']); |
||
| 875 | |||
| 876 | // Hard to imagine this won't be necessary |
||
| 877 | require_once(SUBSDIR . '/Members.subs.php'); |
||
| 878 | |||
| 879 | // For each of the above let's take out the bits which don't apply - to save memory and security! |
||
| 880 | foreach ($profile_fields as $key => $field) |
||
| 881 | { |
||
| 882 | // Do we have permission to do this? |
||
| 883 | if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? [$field['permission'] . '_own', $field['permission'] . '_any'] : $field['permission'] . '_any')) && !allowedTo($field['permission'])) |
||
| 884 | { |
||
| 885 | unset($profile_fields[$key]); |
||
| 886 | } |
||
| 887 | |||
| 888 | // Is it enabled? |
||
| 889 | if (isset($field['enabled']) && !$field['enabled']) |
||
| 890 | { |
||
| 891 | unset($profile_fields[$key]); |
||
| 892 | } |
||
| 893 | |||
| 894 | // Is it specifically disabled? |
||
| 895 | if (in_array($key, $disabled_fields, true) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields, true))) |
||
| 896 | { |
||
| 897 | unset($profile_fields[$key]); |
||
| 898 | } |
||
| 1192 |