| Conditions | 46 |
| Paths | 256 |
| Total Lines | 273 |
| Lines | 59 |
| Ratio | 21.61 % |
| Changes | 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 |
||
| 82 | function template_registration_form() |
||
| 83 | { |
||
| 84 | global $context, $scripturl, $txt, $modSettings; |
||
| 85 | |||
| 86 | echo ' |
||
| 87 | <script> |
||
| 88 | function verifyAgree() |
||
| 89 | { |
||
| 90 | if (currentAuthMethod == \'passwd\' && document.forms.registration.smf_autov_pwmain.value != document.forms.registration.smf_autov_pwverify.value) |
||
| 91 | { |
||
| 92 | alert("', $txt['register_passwords_differ_js'], '"); |
||
| 93 | return false; |
||
| 94 | } |
||
| 95 | |||
| 96 | return true; |
||
| 97 | } |
||
| 98 | |||
| 99 | var currentAuthMethod = \'passwd\'; |
||
| 100 | </script>'; |
||
| 101 | |||
| 102 | // Any errors? |
||
| 103 | if (!empty($context['registration_errors'])) |
||
| 104 | { |
||
| 105 | echo ' |
||
| 106 | <div class="errorbox"> |
||
| 107 | <span>', $txt['registration_errors_occurred'], '</span> |
||
| 108 | <ul>'; |
||
| 109 | |||
| 110 | // Cycle through each error and display an error message. |
||
| 111 | foreach ($context['registration_errors'] as $error) |
||
| 112 | echo ' |
||
| 113 | <li>', $error, '</li>'; |
||
| 114 | |||
| 115 | echo ' |
||
| 116 | </ul> |
||
| 117 | </div>'; |
||
| 118 | } |
||
| 119 | |||
| 120 | echo ' |
||
| 121 | <form action="', !empty($modSettings['force_ssl']) ? strtr($scripturl, array('http://' => 'https://')) : $scripturl, '?action=signup2" method="post" accept-charset="', $context['character_set'], '" name="registration" id="registration" onsubmit="return verifyAgree();"> |
||
| 122 | <div class="cat_bar"> |
||
| 123 | <h3 class="catbg">', $txt['registration_form'], '</h3> |
||
| 124 | </div> |
||
| 125 | <div class="title_bar"> |
||
| 126 | <h3 class="titlebg">', $txt['required_info'], '</h3> |
||
| 127 | </div> |
||
| 128 | <div class="roundframe noup"> |
||
| 129 | <fieldset> |
||
| 130 | <dl class="register_form"> |
||
| 131 | <dt> |
||
| 132 | <strong><label for="smf_autov_username">', $txt['username'], ':</label></strong> |
||
| 133 | </dt> |
||
| 134 | <dd> |
||
| 135 | <input type="text" name="user" id="smf_autov_username" size="50" tabindex="', $context['tabindex']++, '" maxlength="25" value="', isset($context['username']) ? $context['username'] : '', '"> |
||
| 136 | <span id="smf_autov_username_div" style="display: none;"> |
||
| 137 | <a id="smf_autov_username_link" href="#"> |
||
| 138 | <span id="smf_autov_username_img" class="generic_icons check"></span> |
||
| 139 | </a> |
||
| 140 | </span> |
||
| 141 | </dd> |
||
| 142 | <dt><strong><label for="smf_autov_reserve1">', $txt['user_email_address'], ':</label></strong></dt> |
||
| 143 | <dd> |
||
| 144 | <input type="text" name="email" id="smf_autov_reserve1" size="50" tabindex="', $context['tabindex']++, '" value="', isset($context['email']) ? $context['email'] : '', '"> |
||
| 145 | </dd> |
||
| 146 | </dl> |
||
| 147 | <dl class="register_form" id="password1_group"> |
||
| 148 | <dt><strong><label for="smf_autov_pwmain">', ucwords($txt['choose_pass']), ':</label></strong></dt> |
||
| 149 | <dd> |
||
| 150 | <input type="password" name="passwrd1" id="smf_autov_pwmain" size="50" tabindex="', $context['tabindex']++, '"> |
||
| 151 | <span id="smf_autov_pwmain_div" style="display: none;"> |
||
| 152 | <span id="smf_autov_pwmain_img" class="generic_icons invalid"></span> |
||
| 153 | </span> |
||
| 154 | </dd> |
||
| 155 | </dl> |
||
| 156 | <dl class="register_form" id="password2_group"> |
||
| 157 | <dt> |
||
| 158 | <strong><label for="smf_autov_pwverify">', ucwords($txt['verify_pass']), ':</label></strong> |
||
| 159 | </dt> |
||
| 160 | <dd> |
||
| 161 | <input type="password" name="passwrd2" id="smf_autov_pwverify" size="50" tabindex="', $context['tabindex']++, '"> |
||
| 162 | <span id="smf_autov_pwverify_div" style="display: none;"> |
||
| 163 | <span id="smf_autov_pwverify_img" class="generic_icons valid"></span> |
||
| 164 | </span> |
||
| 165 | </dd> |
||
| 166 | </dl> |
||
| 167 | <dl class="register_form" id="notify_announcements"> |
||
| 168 | <dt> |
||
| 169 | <strong><label for="notify_announcements">', $txt['notify_announcements'], ':</label></strong> |
||
| 170 | </dt> |
||
| 171 | <dd> |
||
| 172 | <input type="checkbox" name="notify_announcements" id="notify_announcements" tabindex="', $context['tabindex']++, '"', $context['notify_announcements'] ? ' checked="checked"' : '', '> |
||
| 173 | </dd> |
||
| 174 | </dl>'; |
||
| 175 | |||
| 176 | // If there is any field marked as required, show it here! |
||
| 177 | View Code Duplication | if (!empty($context['custom_fields_required']) && !empty($context['custom_fields'])) |
|
| 178 | { |
||
| 179 | echo ' |
||
| 180 | <dl class="register_form">'; |
||
| 181 | |||
| 182 | foreach ($context['custom_fields'] as $field) |
||
| 183 | if ($field['show_reg'] > 1) |
||
| 184 | echo ' |
||
| 185 | <dt> |
||
| 186 | <strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['name'], ':</strong> |
||
| 187 | <span class="smalltext">', $field['desc'], '</span> |
||
| 188 | </dt> |
||
| 189 | <dd>', str_replace('name="', 'tabindex="' . $context['tabindex']++ . '" name="', $field['input_html']), '</dd>'; |
||
| 190 | |||
| 191 | echo ' |
||
| 192 | </dl>'; |
||
| 193 | } |
||
| 194 | |||
| 195 | echo ' |
||
| 196 | </fieldset> |
||
| 197 | </div><!-- .roundframe -->'; |
||
| 198 | |||
| 199 | // If we have either of these, show the extra group. |
||
| 200 | if (!empty($context['profile_fields']) || !empty($context['custom_fields'])) |
||
| 201 | echo ' |
||
| 202 | <div class="title_bar"> |
||
| 203 | <h3 class="titlebg">', $txt['additional_information'], '</h3> |
||
| 204 | </div> |
||
| 205 | <div class="roundframe noup"> |
||
| 206 | <fieldset> |
||
| 207 | <dl class="register_form" id="custom_group">'; |
||
| 208 | |||
| 209 | if (!empty($context['profile_fields'])) |
||
| 210 | { |
||
| 211 | // Any fields we particularly want? |
||
| 212 | foreach ($context['profile_fields'] as $key => $field) |
||
| 213 | { |
||
| 214 | if ($field['type'] == 'callback') |
||
| 215 | { |
||
| 216 | View Code Duplication | if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func'])) |
|
| 217 | { |
||
| 218 | $callback_func = 'template_profile_' . $field['callback_func']; |
||
| 219 | $callback_func(); |
||
| 220 | } |
||
| 221 | } |
||
| 222 | else |
||
| 223 | { |
||
| 224 | echo ' |
||
| 225 | <dt> |
||
| 226 | <strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['label'], ':</strong>'; |
||
| 227 | |||
| 228 | // Does it have any subtext to show? |
||
| 229 | if (!empty($field['subtext'])) |
||
| 230 | echo ' |
||
| 231 | <span class="smalltext">', $field['subtext'], '</span>'; |
||
| 232 | |||
| 233 | echo ' |
||
| 234 | </dt> |
||
| 235 | <dd>'; |
||
| 236 | |||
| 237 | // Want to put something infront of the box? |
||
| 238 | if (!empty($field['preinput'])) |
||
| 239 | echo ' |
||
| 240 | ', $field['preinput']; |
||
| 241 | |||
| 242 | // What type of data are we showing? |
||
| 243 | if ($field['type'] == 'label') |
||
| 244 | echo ' |
||
| 245 | ', $field['value']; |
||
| 246 | |||
| 247 | // Maybe it's a text box - very likely! |
||
| 248 | elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'url'))) |
||
| 249 | echo ' |
||
| 250 | <input type="', $field['type'] == 'password' ? 'password' : 'text', '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], '>'; |
||
| 251 | |||
| 252 | // You "checking" me out? ;) |
||
| 253 | View Code Duplication | elseif ($field['type'] == 'check') |
|
| 254 | echo ' |
||
| 255 | <input type="hidden" name="', $key, '" value="0"><input type="checkbox" name="', $key, '" id="', $key, '"', !empty($field['value']) ? ' checked' : '', ' value="1" tabindex="', $context['tabindex']++, '" ', $field['input_attr'], '>'; |
||
| 256 | |||
| 257 | // Always fun - select boxes! |
||
| 258 | View Code Duplication | elseif ($field['type'] == 'select') |
|
| 259 | { |
||
| 260 | echo ' |
||
| 261 | <select name="', $key, '" id="', $key, '" tabindex="', $context['tabindex']++, '">'; |
||
| 262 | |||
| 263 | if (isset($field['options'])) |
||
| 264 | { |
||
| 265 | // Is this some code to generate the options? |
||
| 266 | if (!is_array($field['options'])) |
||
| 267 | $field['options'] = eval($field['options']); |
||
| 268 | |||
| 269 | // Assuming we now have some! |
||
| 270 | if (is_array($field['options'])) |
||
| 271 | foreach ($field['options'] as $value => $name) |
||
| 272 | echo ' |
||
| 273 | <option', is_numeric($value) ? ' value="" disabled' : ' value="' . $value . '"', $value === $field['value'] ? ' selected' : '', '>', $name, '</option>'; |
||
| 274 | } |
||
| 275 | |||
| 276 | echo ' |
||
| 277 | </select>'; |
||
| 278 | } |
||
| 279 | |||
| 280 | // Something to end with? |
||
| 281 | if (!empty($field['postinput'])) |
||
| 282 | echo ' |
||
| 283 | ', $field['postinput']; |
||
| 284 | |||
| 285 | echo ' |
||
| 286 | </dd>'; |
||
| 287 | } |
||
| 288 | } |
||
| 289 | } |
||
| 290 | |||
| 291 | // Are there any custom fields? |
||
| 292 | if (!empty($context['custom_fields'])) |
||
| 293 | { |
||
| 294 | foreach ($context['custom_fields'] as $field) |
||
| 295 | if ($field['show_reg'] < 2) |
||
| 296 | echo ' |
||
| 297 | <dt> |
||
| 298 | <strong', !empty($field['is_error']) ? ' class="red"' : '', '>', $field['name'], ':</strong> |
||
| 299 | <span class="smalltext">', $field['desc'], '</span> |
||
| 300 | </dt> |
||
| 301 | <dd>', $field['input_html'], '</dd>'; |
||
| 302 | } |
||
| 303 | |||
| 304 | // If we have either of these, close the list like a proper gent. |
||
| 305 | if (!empty($context['profile_fields']) || !empty($context['custom_fields'])) |
||
| 306 | echo ' |
||
| 307 | </dl> |
||
| 308 | </fieldset> |
||
| 309 | </div><!-- .roundframe -->'; |
||
| 310 | |||
| 311 | View Code Duplication | if ($context['visual_verification']) |
|
| 312 | echo ' |
||
| 313 | <div class="title_bar"> |
||
| 314 | <h3 class="titlebg">', $txt['verification'], '</h3> |
||
| 315 | </div> |
||
| 316 | <div class="roundframe noup"> |
||
| 317 | <fieldset class="centertext"> |
||
| 318 | ', template_control_verification($context['visual_verification_id'], 'all'), ' |
||
| 319 | </fieldset> |
||
| 320 | </div>'; |
||
| 321 | |||
| 322 | echo ' |
||
| 323 | <div id="confirm_buttons" class="flow_auto">'; |
||
| 324 | |||
| 325 | // Age restriction in effect? |
||
| 326 | if (!$context['require_agreement'] && $context['show_coppa']) |
||
| 327 | echo ' |
||
| 328 | <input type="submit" name="accept_agreement" value="', $context['coppa_agree_above'], '" class="button"><br> |
||
| 329 | <br> |
||
| 330 | <input type="submit" name="accept_agreement_coppa" value="', $context['coppa_agree_below'], '" class="button">'; |
||
| 331 | else |
||
| 332 | echo ' |
||
| 333 | <input type="submit" name="regSubmit" value="', $txt['register'], '" tabindex="', $context['tabindex']++, '" class="button">'; |
||
| 334 | |||
| 335 | echo ' |
||
| 336 | </div> |
||
| 337 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
||
| 338 | <input type="hidden" name="', $context['register_token_var'], '" value="', $context['register_token'], '"> |
||
| 339 | <input type="hidden" name="step" value="3"> |
||
| 340 | </form> |
||
| 341 | <script> |
||
| 342 | var regTextStrings = { |
||
| 343 | "username_valid": "', $txt['registration_username_available'], '", |
||
| 344 | "username_invalid": "', $txt['registration_username_unavailable'], '", |
||
| 345 | "username_check": "', $txt['registration_username_check'], '", |
||
| 346 | "password_short": "', $txt['registration_password_short'], '", |
||
| 347 | "password_reserved": "', $txt['registration_password_reserved'], '", |
||
| 348 | "password_numbercase": "', $txt['registration_password_numbercase'], '", |
||
| 349 | "password_no_match": "', $txt['registration_password_no_match'], '", |
||
| 350 | "password_valid": "', $txt['registration_password_valid'], '" |
||
| 351 | }; |
||
| 352 | var verificationHandle = new smfRegister("registration", ', empty($modSettings['password_strength']) ? 0 : $modSettings['password_strength'], ', regTextStrings); |
||
| 353 | </script>'; |
||
| 354 | } |
||
| 355 | |||
| 738 | ?> |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state