| Conditions | 16 |
| Paths | 768 |
| Total Lines | 122 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 62 | public function action_signatureSettings_display(): void |
||
| 63 | { |
||
| 64 | global $context, $txt, $modSettings; |
||
| 65 | |||
| 66 | // Initialize the form |
||
| 67 | $settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER); |
||
| 68 | |||
| 69 | // Initialize it with our settings |
||
| 70 | $settingsForm->setConfigVars($this->_signatureSettings()); |
||
| 71 | |||
| 72 | // Set up the template. |
||
| 73 | $context['page_title'] = $txt['signature_settings']; |
||
| 74 | $context['sub_template'] = 'show_settings'; |
||
| 75 | |||
| 76 | // Disable the max smileys option if we don't allow smileys at all! |
||
| 77 | theme()->addInlineJavascript(' |
||
| 78 | document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;', true); |
||
| 79 | |||
| 80 | // Load all the signature settings. |
||
| 81 | [$sig_limits, $sig_bbc] = explode(':', $modSettings['signature_settings']); |
||
| 82 | $sig_limits = explode(',', $sig_limits); |
||
| 83 | $disabledTags = empty($sig_bbc) ? [] : explode(',', $sig_bbc); |
||
| 84 | |||
| 85 | // It does not work in signatures, and seriously, why would you do this? |
||
| 86 | $disabledTags[] = 'footnote'; |
||
| 87 | |||
| 88 | // Applying to ALL signatures?!! |
||
| 89 | if ($this->_req->hasQuery('apply')) |
||
| 90 | { |
||
| 91 | // Security! |
||
| 92 | checkSession('get'); |
||
| 93 | |||
| 94 | // This is horrid - but I suppose some people will want the option to do it. |
||
| 95 | $applied_sigs = $this->_req->getQuery('step', 'intval', 0); |
||
| 96 | updateAllSignatures($applied_sigs); |
||
| 97 | |||
| 98 | $settings_applied = true; |
||
| 99 | } |
||
| 100 | |||
| 101 | $context['signature_settings'] = [ |
||
| 102 | 'enable' => $sig_limits[0] ?? 0, |
||
| 103 | 'max_length' => $sig_limits[1] ?? 0, |
||
| 104 | 'max_lines' => $sig_limits[2] ?? 0, |
||
| 105 | 'max_images' => $sig_limits[3] ?? 0, |
||
| 106 | 'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1, |
||
| 107 | 'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0, |
||
| 108 | 'max_image_width' => $sig_limits[5] ?? 0, |
||
| 109 | 'max_image_height' => $sig_limits[6] ?? 0, |
||
| 110 | 'max_font_size' => $sig_limits[7] ?? 0, |
||
| 111 | 'repetition_guests' => $sig_limits[8] ?? 0, |
||
| 112 | 'repetition_members' => $sig_limits[9] ?? 0, |
||
| 113 | ]; |
||
| 114 | |||
| 115 | // Temporarily make each setting a modSetting! |
||
| 116 | foreach ($context['signature_settings'] as $key => $value) |
||
| 117 | { |
||
| 118 | $modSettings['signature_' . $key] = $value; |
||
| 119 | } |
||
| 120 | |||
| 121 | // Make sure we check the right tags! |
||
| 122 | $modSettings['bbc_disabled_signature_bbc'] = $disabledTags; |
||
| 123 | |||
| 124 | // Saving? |
||
| 125 | if ($this->_req->hasQuery('save')) |
||
| 126 | { |
||
| 127 | checkSession(); |
||
| 128 | |||
| 129 | // Clean up the tag stuff! |
||
| 130 | $codes = ParserWrapper::instance()->getCodes(); |
||
| 131 | $bbcTags = $codes->getTags(); |
||
| 132 | |||
| 133 | $signature_bbc_enabledTags = $this->_req->getPost('signature_bbc_enabledTags', null, []); |
||
| 134 | if (!is_array($signature_bbc_enabledTags)) |
||
| 135 | { |
||
| 136 | $signature_bbc_enabledTags = [$signature_bbc_enabledTags]; |
||
| 137 | } |
||
| 138 | |||
| 139 | // Do not mutate the request; keep a local copy for settings persistence |
||
| 140 | $signature_bbc_enabledTags_local = $signature_bbc_enabledTags; |
||
| 141 | |||
| 142 | $sig_limits = []; |
||
| 143 | foreach (array_keys($context['signature_settings']) as $key) |
||
| 144 | { |
||
| 145 | if ($key === 'allow_smileys') |
||
| 146 | { |
||
| 147 | continue; |
||
| 148 | } |
||
| 149 | if ($key === 'max_smileys' && empty($this->_req->post->signature_allow_smileys)) |
||
| 150 | { |
||
| 151 | $sig_limits[] = -1; |
||
| 152 | } |
||
| 153 | else |
||
| 154 | { |
||
| 155 | $current_key = $this->_req->getPost('signature_' . $key, 'intval'); |
||
| 156 | $sig_limits[] = empty($current_key) ? 0 : max(1, $current_key); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | call_integration_hook('integrate_save_signature_settings', [&$sig_limits, &$bbcTags]); |
||
| 161 | |||
| 162 | // Build the combined signature settings string using locals (do not write back to request) |
||
| 163 | $signature_settings_local = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $signature_bbc_enabledTags_local)); |
||
| 164 | |||
| 165 | // Even though we have practically no settings, let's keep the convention going! |
||
| 166 | $save_vars = []; |
||
| 167 | $save_vars[] = ['text', 'signature_settings']; |
||
| 168 | |||
| 169 | $settingsForm->setConfigVars($save_vars); |
||
| 170 | // Start from posted values but override with our local computed values |
||
| 171 | $config_values = (array) $this->_req->post; |
||
| 172 | $config_values['signature_bbc_enabledTags'] = $signature_bbc_enabledTags_local; |
||
| 173 | $config_values['signature_settings'] = $signature_settings_local; |
||
| 174 | $settingsForm->setConfigValues($config_values); |
||
| 175 | $settingsForm->save(); |
||
| 176 | redirectexit('action=admin;area=featuresettings;sa=sig'); |
||
| 177 | } |
||
| 178 | |||
| 179 | $context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'save']); |
||
| 180 | $context['settings_title'] = $txt['signature_settings']; |
||
| 181 | $context['settings_message'] = empty($settings_applied) ? sprintf($txt['signature_settings_warning'], getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'sig', 'apply', '{session_data}'])) : $txt['signature_settings_applied']; |
||
| 182 | |||
| 183 | $settingsForm->prepare(); |
||
| 184 | } |
||
| 243 |