Complex classes like ManageFeatures often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ManageFeatures, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class ManageFeatures extends \ElkArte\AbstractController |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * Pre Dispatch, called before other methods. |
||
| 29 | */ |
||
| 30 | 2 | public function pre_dispatch() |
|
| 35 | |||
| 36 | /** |
||
| 37 | * This function passes control through to the relevant tab. |
||
| 38 | * |
||
| 39 | * @event integrate_sa_modify_features Use to add new Configuration tabs |
||
| 40 | * @see \ElkArte\AbstractController::action_index() |
||
| 41 | * @uses Help, ManageSettings languages |
||
| 42 | * @uses sub_template show_settings |
||
| 43 | */ |
||
| 44 | public function action_index() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Config array for changing the basic forum settings |
||
| 150 | * |
||
| 151 | * - Accessed from ?action=admin;area=featuresettings;sa=basic; |
||
| 152 | * |
||
| 153 | * @event integrate_save_basic_settings |
||
| 154 | */ |
||
| 155 | public function action_basicSettings_display() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Allows modifying the global layout settings in the forum |
||
| 208 | * |
||
| 209 | * - Accessed through ?action=admin;area=featuresettings;sa=layout; |
||
| 210 | * |
||
| 211 | * @event integrate_save_layout_settings |
||
| 212 | */ |
||
| 213 | public function action_layoutSettings_display() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Display configuration settings page for karma settings. |
||
| 257 | * |
||
| 258 | * - Accessed from ?action=admin;area=featuresettings;sa=karma; |
||
| 259 | * |
||
| 260 | * @event integrate_save_karma_settings |
||
| 261 | */ |
||
| 262 | public function action_karmaSettings_display() |
||
|
|
|||
| 263 | { |
||
| 264 | global $txt, $context; |
||
| 265 | |||
| 266 | // Initialize the form |
||
| 267 | $settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER); |
||
| 268 | |||
| 269 | // Initialize it with our settings |
||
| 270 | $settingsForm->setConfigVars($this->_karmaSettings()); |
||
| 271 | |||
| 272 | // Saving? |
||
| 273 | if (isset($this->_req->query->save)) |
||
| 274 | { |
||
| 275 | checkSession(); |
||
| 276 | |||
| 277 | call_integration_hook('integrate_save_karma_settings'); |
||
| 278 | |||
| 279 | $settingsForm->setConfigValues((array) $this->_req->post); |
||
| 280 | $settingsForm->save(); |
||
| 281 | redirectexit('action=admin;area=featuresettings;sa=karma'); |
||
| 282 | } |
||
| 283 | |||
| 284 | $context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'karm', 'save']); |
||
| 285 | $context['settings_title'] = $txt['karma']; |
||
| 286 | |||
| 287 | $settingsForm->prepare(); |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Display configuration settings page for likes settings. |
||
| 292 | * |
||
| 293 | * - Accessed from ?action=admin;area=featuresettings;sa=likes; |
||
| 294 | * |
||
| 295 | * @event integrate_save_likes_settings |
||
| 296 | */ |
||
| 297 | public function action_likesSettings_display() |
||
| 298 | { |
||
| 299 | global $txt, $context; |
||
| 300 | |||
| 301 | // Initialize the form |
||
| 302 | $settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER); |
||
| 303 | |||
| 304 | // Initialize it with our settings |
||
| 305 | $settingsForm->setConfigVars($this->_likesSettings()); |
||
| 306 | |||
| 307 | // Saving? |
||
| 308 | if (isset($this->_req->query->save)) |
||
| 309 | { |
||
| 310 | checkSession(); |
||
| 311 | |||
| 312 | call_integration_hook('integrate_save_likes_settings'); |
||
| 313 | |||
| 314 | $settingsForm->setConfigValues((array) $this->_req->post); |
||
| 315 | $settingsForm->save(); |
||
| 316 | redirectexit('action=admin;area=featuresettings;sa=likes'); |
||
| 317 | } |
||
| 318 | |||
| 319 | $context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'likes', 'save']); |
||
| 320 | $context['settings_title'] = $txt['likes']; |
||
| 321 | |||
| 322 | $settingsForm->prepare(); |
||
| 323 | } |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Initializes the mentions settings admin page. |
||
| 327 | * |
||
| 328 | * - Accessed from ?action=admin;area=featuresettings;sa=mention; |
||
| 329 | * |
||
| 330 | * @event integrate_save_modify_mention_settings |
||
| 331 | */ |
||
| 332 | public function action_notificationsSettings_display() |
||
| 333 | { |
||
| 334 | global $txt, $context, $modSettings; |
||
| 335 | |||
| 336 | theme()->getTemplates()->loadLanguageFile('Mentions'); |
||
| 337 | |||
| 338 | // Instantiate the form |
||
| 339 | $settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER); |
||
| 340 | |||
| 341 | // Initialize it with our settings |
||
| 342 | $settingsForm->setConfigVars($this->_notificationsSettings()); |
||
| 343 | |||
| 344 | // Some context stuff |
||
| 345 | $context['page_title'] = $txt['mentions_settings']; |
||
| 346 | $context['sub_template'] = 'show_settings'; |
||
| 347 | |||
| 348 | // Saving the settings? |
||
| 349 | if (isset($this->_req->query->save)) |
||
| 350 | { |
||
| 351 | checkSession(); |
||
| 352 | |||
| 353 | call_integration_hook('integrate_save_modify_mention_settings'); |
||
| 354 | |||
| 355 | if (!empty($this->_req->post->mentions_enabled)) |
||
| 356 | { |
||
| 357 | enableModules('mentions', array('post', 'display')); |
||
| 358 | } |
||
| 359 | else |
||
| 360 | { |
||
| 361 | disableModules('mentions', array('post', 'display')); |
||
| 362 | } |
||
| 363 | |||
| 364 | if (empty($this->_req->post->notifications)) |
||
| 365 | { |
||
| 366 | $notification_methods = serialize(array()); |
||
| 367 | } |
||
| 368 | else |
||
| 369 | { |
||
| 370 | $notification_methods = serialize($this->_req->post->notifications); |
||
| 371 | } |
||
| 372 | |||
| 373 | require_once(SUBSDIR . '/Mentions.subs.php'); |
||
| 374 | $enabled_mentions = array(); |
||
| 375 | $current_settings = unserialize($modSettings['notification_methods']); |
||
| 376 | |||
| 377 | // Fist hide what was visible |
||
| 378 | $modules_toggle = array('enable' => array(), 'disable' => array()); |
||
| 379 | foreach ($current_settings as $type => $val) |
||
| 380 | { |
||
| 381 | if (!isset($this->_req->post->notifications[$type])) |
||
| 382 | { |
||
| 383 | toggleMentionsVisibility($type, false); |
||
| 384 | $modules_toggle['disable'][] = $type; |
||
| 385 | } |
||
| 386 | } |
||
| 387 | |||
| 388 | // Then make visible what was hidden, but only if there is anything |
||
| 389 | if (!empty($this->_req->post->notifications)) |
||
| 390 | { |
||
| 391 | foreach ($this->_req->post->notifications as $type => $val) |
||
| 392 | { |
||
| 393 | if (!isset($current_settings[$type])) |
||
| 394 | { |
||
| 395 | toggleMentionsVisibility($type, true); |
||
| 396 | $modules_toggle['enable'][] = $type; |
||
| 397 | } |
||
| 398 | } |
||
| 399 | |||
| 400 | $enabled_mentions = array_keys($this->_req->post->notifications); |
||
| 401 | } |
||
| 402 | |||
| 403 | // Let's just keep it active, there are too many reasons it should be. |
||
| 404 | require_once(SUBSDIR . '/ScheduledTasks.subs.php'); |
||
| 405 | toggleTaskStatusByName('user_access_mentions', true); |
||
| 406 | |||
| 407 | // Disable or enable modules as needed |
||
| 408 | foreach ($modules_toggle as $action => $toggles) |
||
| 409 | { |
||
| 410 | if (!empty($toggles)) |
||
| 411 | { |
||
| 412 | // The modules associated with the notification (mentionmem, likes, etc) area |
||
| 413 | $modules = getMentionsModules($toggles); |
||
| 414 | |||
| 415 | // The action will either be enable to disable |
||
| 416 | $function = $action . 'Modules'; |
||
| 417 | |||
| 418 | // Something like enableModule('mentions', array('post', 'display'); |
||
| 419 | foreach ($modules as $key => $val) |
||
| 420 | $function($key, $val); |
||
| 421 | } |
||
| 422 | } |
||
| 423 | |||
| 424 | updateSettings(array('enabled_mentions' => implode(',', array_unique($enabled_mentions)), 'notification_methods' => $notification_methods)); |
||
| 425 | $settingsForm->setConfigValues((array) $this->_req->post); |
||
| 426 | $settingsForm->save(); |
||
| 427 | redirectexit('action=admin;area=featuresettings;sa=mention'); |
||
| 428 | } |
||
| 429 | |||
| 430 | // Prepare the settings for display |
||
| 431 | $context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'mention', 'save']); |
||
| 432 | $settingsForm->prepare(); |
||
| 433 | } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Display configuration settings for signatures on forum. |
||
| 437 | * |
||
| 438 | * - Accessed from ?action=admin;area=featuresettings;sa=sig; |
||
| 439 | * |
||
| 440 | * @event integrate_save_signature_settings |
||
| 441 | */ |
||
| 442 | public function action_signatureSettings_display() |
||
| 443 | { |
||
| 444 | global $context, $txt, $modSettings; |
||
| 445 | |||
| 446 | // Initialize the form |
||
| 447 | $settingsForm = new \ElkArte\SettingsForm\SettingsForm(\ElkArte\SettingsForm\SettingsForm::DB_ADAPTER); |
||
| 448 | |||
| 449 | // Initialize it with our settings |
||
| 450 | $settingsForm->setConfigVars($this->_signatureSettings()); |
||
| 451 | |||
| 452 | // Setup the template. |
||
| 453 | $context['page_title'] = $txt['signature_settings']; |
||
| 454 | $context['sub_template'] = 'show_settings'; |
||
| 455 | |||
| 456 | // Disable the max smileys option if we don't allow smileys at all! |
||
| 457 | theme()->addInlineJavascript(' |
||
| 458 | document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;', true); |
||
| 459 | |||
| 460 | // Load all the signature settings. |
||
| 461 | list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']); |
||
| 462 | $sig_limits = explode(',', $sig_limits); |
||
| 463 | $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array(); |
||
| 464 | |||
| 465 | // @todo temporary since it does not work, and seriously why would you do this? |
||
| 466 | $disabledTags[] = 'footnote'; |
||
| 467 | |||
| 468 | // Applying to ALL signatures?!! |
||
| 469 | if (isset($this->_req->query->apply)) |
||
| 470 | { |
||
| 471 | // Security! |
||
| 472 | checkSession('get'); |
||
| 473 | |||
| 474 | // This is horrid - but I suppose some people will want the option to do it. |
||
| 475 | $applied_sigs = $this->_req->getQuery('step', 'intval', 0); |
||
| 476 | updateAllSignatures($applied_sigs); |
||
| 477 | |||
| 478 | $settings_applied = true; |
||
| 479 | } |
||
| 480 | |||
| 481 | $context['signature_settings'] = array( |
||
| 482 | 'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0, |
||
| 483 | 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0, |
||
| 484 | 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0, |
||
| 485 | 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0, |
||
| 486 | 'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1, |
||
| 487 | 'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0, |
||
| 488 | 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0, |
||
| 489 | 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0, |
||
| 490 | 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0, |
||
| 491 | 'repetition_guests' => isset($sig_limits[8]) ? $sig_limits[8] : 0, |
||
| 492 | 'repetition_members' => isset($sig_limits[9]) ? $sig_limits[9] : 0, |
||
| 493 | ); |
||
| 494 | |||
| 495 | // Temporarily make each setting a modSetting! |
||
| 496 | foreach ($context['signature_settings'] as $key => $value) |
||
| 497 | $modSettings['signature_' . $key] = $value; |
||
| 498 | |||
| 499 | // Make sure we check the right tags! |
||
| 500 | $modSettings['bbc_disabled_signature_bbc'] = $disabledTags; |
||
| 501 | |||
| 502 | // Saving? |
||
| 503 | if (isset($this->_req->query->save)) |
||
| 504 | { |
||
| 505 | checkSession(); |
||
| 506 | |||
| 507 | // Clean up the tag stuff! |
||
| 508 | $codes = \BBC\ParserWrapper::instance()->getCodes(); |
||
| 509 | $bbcTags = $codes->getTags(); |
||
| 510 | |||
| 511 | if (!isset($this->_req->post->signature_bbc_enabledTags)) |
||
| 512 | $this->_req->post->signature_bbc_enabledTags = array(); |
||
| 513 | elseif (!is_array($this->_req->post->signature_bbc_enabledTags)) |
||
| 514 | $this->_req->post->signature_bbc_enabledTags = array($this->_req->post->signature_bbc_enabledTags); |
||
| 515 | |||
| 516 | $sig_limits = array(); |
||
| 517 | foreach ($context['signature_settings'] as $key => $value) |
||
| 518 | { |
||
| 519 | if ($key == 'allow_smileys') |
||
| 520 | continue; |
||
| 521 | elseif ($key == 'max_smileys' && empty($this->_req->post->signature_allow_smileys)) |
||
| 522 | $sig_limits[] = -1; |
||
| 523 | else |
||
| 524 | { |
||
| 525 | $current_key = $this->_req->getPost('signature_' . $key, 'intval'); |
||
| 526 | $sig_limits[] = !empty($current_key) ? max(1, $current_key) : 0; |
||
| 527 | } |
||
| 528 | } |
||
| 529 | |||
| 530 | call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags)); |
||
| 531 | |||
| 532 | $this->_req->post->signature_settings = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $this->_req->post->signature_bbc_enabledTags)); |
||
| 533 | |||
| 534 | // Even though we have practically no settings let's keep the convention going! |
||
| 535 | $save_vars = array(); |
||
| 536 | $save_vars[] = array('text', 'signature_settings'); |
||
| 537 | |||
| 538 | $settingsForm->setConfigVars($save_vars); |
||
| 539 | $settingsForm->setConfigValues((array) $this->_req->post); |
||
| 540 | $settingsForm->save(); |
||
| 541 | redirectexit('action=admin;area=featuresettings;sa=sig'); |
||
| 542 | } |
||
| 543 | |||
| 544 | $context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'save']); |
||
| 545 | $context['settings_title'] = $txt['signature_settings']; |
||
| 546 | $context['settings_message'] = !empty($settings_applied) ? $txt['signature_settings_applied'] : sprintf($txt['signature_settings_warning'], getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'apply', '{session_data}'])); |
||
| 547 | |||
| 548 | $settingsForm->prepare(); |
||
| 549 | } |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Show all the custom profile fields available to the user. |
||
| 553 | * |
||
| 554 | * - Allows for drag/drop sorting of custom profile fields |
||
| 555 | * - Accessed with ?action=admin;area=featuresettings;sa=profile |
||
| 556 | * |
||
| 557 | * @uses sub template show_custom_profile |
||
| 558 | */ |
||
| 559 | public function action_profile() |
||
| 560 | { |
||
| 561 | global $txt, $scripturl, $context; |
||
| 562 | |||
| 563 | theme()->getTemplates()->load('ManageFeatures'); |
||
| 564 | $context['page_title'] = $txt['custom_profile_title']; |
||
| 565 | $context['sub_template'] = 'show_custom_profile'; |
||
| 566 | |||
| 567 | // What about standard fields they can tweak? |
||
| 568 | $standard_fields = array('website', 'posts', 'warning_status', 'date_registered'); |
||
| 569 | |||
| 570 | // What fields can't you put on the registration page? |
||
| 571 | $context['fields_no_registration'] = array('posts', 'warning_status', 'date_registered'); |
||
| 572 | |||
| 573 | // Are we saving any standard field changes? |
||
| 574 | if (isset($this->_req->post->save)) |
||
| 575 | { |
||
| 576 | checkSession(); |
||
| 577 | validateToken('admin-scp'); |
||
| 578 | |||
| 579 | $changes = array(); |
||
| 580 | |||
| 581 | // Do the active ones first. |
||
| 582 | $disable_fields = array_flip($standard_fields); |
||
| 583 | if (!empty($this->_req->post->active)) |
||
| 584 | { |
||
| 585 | foreach ($this->_req->post->active as $value) |
||
| 586 | { |
||
| 587 | if (isset($disable_fields[$value])) |
||
| 588 | { |
||
| 589 | unset($disable_fields[$value]); |
||
| 590 | } |
||
| 591 | } |
||
| 592 | } |
||
| 593 | |||
| 594 | // What we have left! |
||
| 595 | $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields)); |
||
| 596 | |||
| 597 | // Things we want to show on registration? |
||
| 598 | $reg_fields = array(); |
||
| 599 | if (!empty($this->_req->post->reg)) |
||
| 600 | { |
||
| 601 | foreach ($this->_req->post->reg as $value) |
||
| 602 | { |
||
| 603 | if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) |
||
| 604 | $reg_fields[] = $value; |
||
| 605 | } |
||
| 606 | } |
||
| 607 | |||
| 608 | // What we have left! |
||
| 609 | $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields); |
||
| 610 | |||
| 611 | if (!empty($changes)) |
||
| 612 | updateSettings($changes); |
||
| 613 | } |
||
| 614 | |||
| 615 | createToken('admin-scp'); |
||
| 616 | |||
| 617 | // Create a listing for all our standard fields |
||
| 618 | $listOptions = array( |
||
| 619 | 'id' => 'standard_profile_fields', |
||
| 620 | 'title' => $txt['standard_profile_title'], |
||
| 621 | 'base_href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']), |
||
| 622 | 'get_items' => array( |
||
| 623 | 'function' => 'list_getProfileFields', |
||
| 624 | 'params' => array( |
||
| 625 | true, |
||
| 626 | ), |
||
| 627 | ), |
||
| 628 | 'columns' => array( |
||
| 629 | 'field' => array( |
||
| 630 | 'header' => array( |
||
| 631 | 'value' => $txt['standard_profile_field'], |
||
| 632 | ), |
||
| 633 | 'data' => array( |
||
| 634 | 'db' => 'label', |
||
| 635 | 'style' => 'width: 60%;', |
||
| 636 | ), |
||
| 637 | ), |
||
| 638 | 'active' => array( |
||
| 639 | 'header' => array( |
||
| 640 | 'value' => $txt['custom_edit_active'], |
||
| 641 | 'class' => 'centertext', |
||
| 642 | ), |
||
| 643 | 'data' => array( |
||
| 644 | 'function' => function ($rowData) { |
||
| 645 | $isChecked = $rowData['disabled'] ? '' : ' checked="checked"'; |
||
| 646 | $onClickHandler = $rowData['can_show_register'] ? sprintf('onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : ''; |
||
| 647 | return sprintf('<input type="checkbox" name="active[]" id="active_%1$s" value="%1$s" class="input_check" %2$s %3$s />', $rowData['id'], $isChecked, $onClickHandler); |
||
| 648 | }, |
||
| 649 | 'style' => 'width: 20%;', |
||
| 650 | 'class' => 'centertext', |
||
| 651 | ), |
||
| 652 | ), |
||
| 653 | 'show_on_registration' => array( |
||
| 654 | 'header' => array( |
||
| 655 | 'value' => $txt['custom_edit_registration'], |
||
| 656 | 'class' => 'centertext', |
||
| 657 | ), |
||
| 658 | 'data' => array( |
||
| 659 | 'function' => function ($rowData) { |
||
| 660 | $isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked="checked"' : ''; |
||
| 661 | $isDisabled = $rowData['can_show_register'] ? '' : ' disabled="disabled"'; |
||
| 662 | return sprintf('<input type="checkbox" name="reg[]" id="reg_%1$s" value="%1$s" class="input_check" %2$s %3$s />', $rowData['id'], $isChecked, $isDisabled); |
||
| 663 | }, |
||
| 664 | 'style' => 'width: 20%;', |
||
| 665 | 'class' => 'centertext', |
||
| 666 | ), |
||
| 667 | ), |
||
| 668 | ), |
||
| 669 | 'form' => array( |
||
| 670 | 'href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']), |
||
| 671 | 'name' => 'standardProfileFields', |
||
| 672 | 'token' => 'admin-scp', |
||
| 673 | ), |
||
| 674 | 'additional_rows' => array( |
||
| 675 | array( |
||
| 676 | 'position' => 'below_table_data', |
||
| 677 | 'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="right_submit" />', |
||
| 678 | ), |
||
| 679 | ), |
||
| 680 | ); |
||
| 681 | createList($listOptions); |
||
| 682 | |||
| 683 | // And now we do the same for all of our custom ones |
||
| 684 | $token = createToken('admin-sort'); |
||
| 685 | $listOptions = array( |
||
| 686 | 'id' => 'custom_profile_fields', |
||
| 687 | 'title' => $txt['custom_profile_title'], |
||
| 688 | 'base_href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profile']), |
||
| 689 | 'default_sort_col' => 'vieworder', |
||
| 690 | 'no_items_label' => $txt['custom_profile_none'], |
||
| 691 | 'items_per_page' => 25, |
||
| 692 | 'sortable' => true, |
||
| 693 | 'get_items' => array( |
||
| 694 | 'function' => 'list_getProfileFields', |
||
| 695 | 'params' => array( |
||
| 696 | false, |
||
| 697 | ), |
||
| 698 | ), |
||
| 699 | 'get_count' => array( |
||
| 700 | 'function' => 'list_getProfileFieldSize', |
||
| 701 | ), |
||
| 702 | 'columns' => array( |
||
| 703 | 'vieworder' => array( |
||
| 704 | 'header' => array( |
||
| 705 | 'value' => '', |
||
| 706 | 'class' => 'hide', |
||
| 707 | ), |
||
| 708 | 'data' => array( |
||
| 709 | 'db' => 'vieworder', |
||
| 710 | 'class' => 'hide', |
||
| 711 | ), |
||
| 712 | 'sort' => array( |
||
| 713 | 'default' => 'vieworder', |
||
| 714 | ), |
||
| 715 | ), |
||
| 716 | 'field_name' => array( |
||
| 717 | 'header' => array( |
||
| 718 | 'value' => $txt['custom_profile_fieldname'], |
||
| 719 | ), |
||
| 720 | 'data' => array( |
||
| 721 | 'function' => function ($rowData) { |
||
| 722 | return sprintf('<a href="%1$s">%2$s</a><div class="smalltext">%3$s</div>', getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profileedit', 'fid' => (int) $rowData['id_field']]), $rowData['field_name'], $rowData['field_desc']); |
||
| 723 | }, |
||
| 724 | 'style' => 'width: 65%;', |
||
| 725 | ), |
||
| 726 | 'sort' => array( |
||
| 727 | 'default' => 'field_name', |
||
| 728 | 'reverse' => 'field_name DESC', |
||
| 729 | ), |
||
| 730 | ), |
||
| 731 | 'field_type' => array( |
||
| 732 | 'header' => array( |
||
| 733 | 'value' => $txt['custom_profile_fieldtype'], |
||
| 734 | ), |
||
| 735 | 'data' => array( |
||
| 736 | 'function' => function ($rowData) { |
||
| 737 | global $txt; |
||
| 738 | |||
| 739 | $textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']); |
||
| 740 | return isset($txt[$textKey]) ? $txt[$textKey] : $textKey; |
||
| 741 | }, |
||
| 742 | 'style' => 'width: 10%;', |
||
| 743 | ), |
||
| 744 | 'sort' => array( |
||
| 745 | 'default' => 'field_type', |
||
| 746 | 'reverse' => 'field_type DESC', |
||
| 747 | ), |
||
| 748 | ), |
||
| 749 | 'cust' => array( |
||
| 750 | 'header' => array( |
||
| 751 | 'value' => $txt['custom_profile_active'], |
||
| 752 | 'class' => 'centertext', |
||
| 753 | ), |
||
| 754 | 'data' => array( |
||
| 755 | 'function' => function ($rowData) { |
||
| 756 | $isChecked = $rowData['active'] ? ' checked="checked"' : ''; |
||
| 757 | return sprintf('<input type="checkbox" name="cust[]" id="cust_%1$s" value="%1$s" class="input_check"%2$s />', $rowData['id_field'], $isChecked); |
||
| 758 | }, |
||
| 759 | 'style' => 'width: 8%;', |
||
| 760 | 'class' => 'centertext', |
||
| 761 | ), |
||
| 762 | 'sort' => array( |
||
| 763 | 'default' => 'active DESC', |
||
| 764 | 'reverse' => 'active', |
||
| 765 | ), |
||
| 766 | ), |
||
| 767 | 'placement' => array( |
||
| 768 | 'header' => array( |
||
| 769 | 'value' => $txt['custom_profile_placement'], |
||
| 770 | ), |
||
| 771 | 'data' => array( |
||
| 772 | 'function' => function ($rowData) { |
||
| 773 | global $txt; |
||
| 774 | $placement = 'custom_profile_placement_'; |
||
| 775 | |||
| 776 | switch ((int) $rowData['placement']) |
||
| 777 | { |
||
| 778 | case 0: |
||
| 779 | $placement .= 'standard'; |
||
| 780 | break; |
||
| 781 | case 1: |
||
| 782 | $placement .= 'withicons'; |
||
| 783 | break; |
||
| 784 | case 2: |
||
| 785 | $placement .= 'abovesignature'; |
||
| 786 | break; |
||
| 787 | case 3: |
||
| 788 | $placement .= 'aboveicons'; |
||
| 789 | break; |
||
| 790 | } |
||
| 791 | |||
| 792 | return $txt[$placement]; |
||
| 793 | }, |
||
| 794 | 'style' => 'width: 5%;', |
||
| 795 | ), |
||
| 796 | 'sort' => array( |
||
| 797 | 'default' => 'placement DESC', |
||
| 798 | 'reverse' => 'placement', |
||
| 799 | ), |
||
| 800 | ), |
||
| 801 | 'show_on_registration' => array( |
||
| 802 | 'data' => array( |
||
| 803 | 'sprintf' => array( |
||
| 804 | 'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>', |
||
| 805 | 'params' => array( |
||
| 806 | 'id_field' => false, |
||
| 807 | ), |
||
| 808 | ), |
||
| 809 | 'style' => 'width: 5%;', |
||
| 810 | ), |
||
| 811 | ), |
||
| 812 | ), |
||
| 813 | 'form' => array( |
||
| 814 | 'href' => getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'profileedit']), |
||
| 815 | 'name' => 'customProfileFields', |
||
| 816 | 'token' => 'admin-scp', |
||
| 817 | ), |
||
| 818 | 'additional_rows' => array( |
||
| 819 | array( |
||
| 820 | 'class' => 'submitbutton', |
||
| 821 | 'position' => 'below_table_data', |
||
| 822 | 'value' => '<input type="submit" name="onoff" value="' . $txt['save'] . '" class="right_submit" /> |
||
| 823 | <input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="right_submit" />', |
||
| 824 | ), |
||
| 825 | array( |
||
| 826 | 'position' => 'top_of_list', |
||
| 827 | 'value' => '<p class="infobox">' . $txt['custom_profile_sort'] . '</p>', |
||
| 828 | ), |
||
| 829 | ), |
||
| 830 | 'javascript' => ' |
||
| 831 | $().elkSortable({ |
||
| 832 | sa: "profileorder", |
||
| 833 | error: "' . $txt['admin_order_error'] . '", |
||
| 834 | title: "' . $txt['admin_order_title'] . '", |
||
| 835 | placeholder: "ui-state-highlight", |
||
| 836 | href: "?action=admin;area=featuresettings;sa=profile", |
||
| 837 | token: {token_var: "' . $token['admin-sort_token_var'] . '", token_id: "' . $token['admin-sort_token'] . '"} |
||
| 838 | }); |
||
| 839 | ', |
||
| 840 | ); |
||
| 841 | |||
| 842 | createList($listOptions); |
||
| 843 | } |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Edit some profile fields? |
||
| 847 | * |
||
| 848 | * - Accessed with ?action=admin;area=featuresettings;sa=profileedit |
||
| 849 | * |
||
| 850 | * @uses sub template edit_profile_field |
||
| 851 | */ |
||
| 852 | public function action_profileedit() |
||
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Editing personal messages settings |
||
| 1164 | * |
||
| 1165 | * - Accessed with ?action=admin;area=featuresettings;sa=pmsettings |
||
| 1166 | * |
||
| 1167 | * @event integrate_save_pmsettings_settings |
||
| 1168 | */ |
||
| 1169 | public function action_pmsettings() |
||
| 1208 | |||
| 1209 | /** |
||
| 1210 | * Return basic feature settings. |
||
| 1211 | * |
||
| 1212 | * @event integrate_modify_basic_settings Adds to General features and Options |
||
| 1213 | */ |
||
| 1214 | 2 | private function _basicSettings() |
|
| 1268 | |||
| 1269 | /** |
||
| 1270 | * Public method to return the basic settings, used for admin search |
||
| 1271 | */ |
||
| 1272 | 2 | public function basicSettings_search() |
|
| 1276 | |||
| 1277 | /** |
||
| 1278 | * Return layout settings. |
||
| 1279 | * |
||
| 1280 | * @event integrate_modify_layout_settings Adds options to Configuration->Layout |
||
| 1281 | */ |
||
| 1282 | 2 | private function _layoutSettings() |
|
| 1311 | |||
| 1312 | /** |
||
| 1313 | * Public method to return the layout settings, used for admin search |
||
| 1314 | */ |
||
| 1315 | 2 | public function layoutSettings_search() |
|
| 1319 | |||
| 1320 | /** |
||
| 1321 | * Return karma settings. |
||
| 1322 | * |
||
| 1323 | * @event integrate_modify_karma_settings Adds to Configuration->Karma |
||
| 1324 | */ |
||
| 1325 | 2 | private function _karmaSettings() |
|
| 1349 | |||
| 1350 | /** |
||
| 1351 | * Public method to return the karma settings, used for admin search |
||
| 1352 | */ |
||
| 1353 | 2 | public function karmaSettings_search() |
|
| 1357 | |||
| 1358 | /** |
||
| 1359 | * Return likes settings. |
||
| 1360 | * |
||
| 1361 | * @event integrate_modify_likes_settings Adds to Configuration->Likes |
||
| 1362 | */ |
||
| 1363 | 2 | private function _likesSettings() |
|
| 1385 | |||
| 1386 | /** |
||
| 1387 | * Public method to return the likes settings, used for admin search |
||
| 1388 | */ |
||
| 1389 | 2 | public function likesSettings_search() |
|
| 1393 | |||
| 1394 | /** |
||
| 1395 | * Return mentions settings. |
||
| 1396 | * |
||
| 1397 | * @event integrate_modify_mention_settings Adds to Configuration->Mentions |
||
| 1398 | */ |
||
| 1399 | 2 | private function _notificationsSettings() |
|
| 1436 | |||
| 1437 | /** |
||
| 1438 | * Public method to return the mention settings, used for admin search |
||
| 1439 | */ |
||
| 1440 | 2 | public function mentionSettings_search() |
|
| 1444 | |||
| 1445 | /** |
||
| 1446 | * Return signature settings. |
||
| 1447 | * |
||
| 1448 | * - Used in admin center search and settings form |
||
| 1449 | * |
||
| 1450 | * @event integrate_modify_signature_settings Adds options to Signature Settings |
||
| 1451 | */ |
||
| 1452 | 2 | private function _signatureSettings() |
|
| 1493 | |||
| 1494 | /** |
||
| 1495 | * Public method to return the signature settings, used for admin search |
||
| 1496 | */ |
||
| 1497 | 2 | public function signatureSettings_search() |
|
| 1501 | |||
| 1502 | /** |
||
| 1503 | * Return pm settings. |
||
| 1504 | * |
||
| 1505 | * - Used in admin center search and settings form |
||
| 1506 | * |
||
| 1507 | * @event integrate_modify_pmsettings_settings Adds / Modifies PM Settings |
||
| 1508 | */ |
||
| 1509 | private function _pmSettings() |
||
| 1532 | } |
||
| 1533 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.