| Conditions | 41 |
| Paths | 2304 |
| Total Lines | 272 |
| Code Lines | 100 |
| 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 |
||
| 162 | function template_edit_group() |
||
| 163 | { |
||
| 164 | global $context, $scripturl, $txt, $modSettings; |
||
| 165 | |||
| 166 | echo ' |
||
| 167 | <form action="', $scripturl, '?action=admin;area=membergroups;sa=edit;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '" name="groupForm" id="groupForm"> |
||
| 168 | <div class="cat_bar"> |
||
| 169 | <h3 class="catbg">', $txt['membergroups_edit_group'], ' - ', $context['group']['name'], ' |
||
| 170 | </h3> |
||
| 171 | </div> |
||
| 172 | <div class="windowbg"> |
||
| 173 | <dl class="settings"> |
||
| 174 | <dt> |
||
| 175 | <label for="group_name_input"><strong>', $txt['membergroups_edit_name'], ':</strong></label> |
||
| 176 | </dt> |
||
| 177 | <dd> |
||
| 178 | <input type="text" name="group_name" id="group_name_input" value="', $context['group']['editable_name'], '" size="30"> |
||
| 179 | </dd>'; |
||
| 180 | |||
| 181 | if ($context['group']['id'] != 3 && $context['group']['id'] != 4) |
||
| 182 | echo ' |
||
| 183 | <dt id="group_desc_text"> |
||
| 184 | <label for="group_desc_input"><strong>', $txt['membergroups_edit_desc'], ':</strong></label> |
||
| 185 | </dt> |
||
| 186 | <dd> |
||
| 187 | <textarea name="group_desc" id="group_desc_input" rows="4" cols="40">', $context['group']['description'], '</textarea> |
||
| 188 | </dd>'; |
||
| 189 | |||
| 190 | // Group type... |
||
| 191 | if ($context['group']['allow_post_group']) |
||
| 192 | { |
||
| 193 | echo ' |
||
| 194 | <dt> |
||
| 195 | <label for="group_type"><strong>', $txt['membergroups_edit_group_type'], ':</strong></label> |
||
| 196 | </dt> |
||
| 197 | <dd> |
||
| 198 | <fieldset id="group_type"> |
||
| 199 | <legend>', $txt['membergroups_edit_select_group_type'], '</legend> |
||
| 200 | <label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0"', !$context['group']['is_post_group'] && $context['group']['type'] == 0 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_private'], '</label><br>'; |
||
| 201 | |||
| 202 | if ($context['group']['allow_protected']) |
||
| 203 | echo ' |
||
| 204 | <label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1"', $context['group']['type'] == 1 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_protected'], '</label><br>'; |
||
| 205 | |||
| 206 | echo ' |
||
| 207 | <label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2"', $context['group']['type'] == 2 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_request'], '</label><br> |
||
| 208 | <label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3"', $context['group']['type'] == 3 ? ' checked' : '', ' onclick="swapPostGroup(0);">', $txt['membergroups_group_type_free'], '</label><br> |
||
| 209 | <label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1"', $context['group']['is_post_group'] ? ' checked' : '', ' onclick="swapPostGroup(1);">', $txt['membergroups_group_type_post'], '</label><br> |
||
| 210 | </fieldset> |
||
| 211 | </dd>'; |
||
| 212 | } |
||
| 213 | |||
| 214 | if ($context['group']['id'] != 3 && $context['group']['id'] != 4) |
||
| 215 | echo ' |
||
| 216 | <dt id="group_moderators_text"> |
||
| 217 | <label for="group_moderators"><strong>', $txt['moderators'], ':</strong></label> |
||
| 218 | </dt> |
||
| 219 | <dd> |
||
| 220 | <input type="text" name="group_moderators" id="group_moderators" value="', $context['group']['moderator_list'], '" size="30"> |
||
| 221 | <div id="moderator_container"></div> |
||
| 222 | </dd> |
||
| 223 | <dt id="group_hidden_text"> |
||
| 224 | <label for="group_hidden_input"><strong>', $txt['membergroups_edit_hidden'], ':</strong></label> |
||
| 225 | </dt> |
||
| 226 | <dd> |
||
| 227 | <select name="group_hidden" id="group_hidden_input" onchange="if (this.value == 2 && !confirm(\'', $txt['membergroups_edit_hidden_warning'], '\')) this.value = 0;"> |
||
| 228 | <option value="0"', $context['group']['hidden'] ? '' : ' selected', '>', $txt['membergroups_edit_hidden_no'], '</option> |
||
| 229 | <option value="1"', $context['group']['hidden'] == 1 ? ' selected' : '', '>', $txt['membergroups_edit_hidden_boardindex'], '</option> |
||
| 230 | <option value="2"', $context['group']['hidden'] == 2 ? ' selected' : '', '>', $txt['membergroups_edit_hidden_all'], '</option> |
||
| 231 | </select> |
||
| 232 | </dd>'; |
||
| 233 | |||
| 234 | // Can they inherit permissions? |
||
| 235 | if ($context['group']['id'] > 1 && $context['group']['id'] != 3) |
||
| 236 | { |
||
| 237 | echo ' |
||
| 238 | <dt id="group_inherit_text"> |
||
| 239 | <label for="group_inherit_input"><strong>', $txt['membergroups_edit_inherit_permissions'], '</strong></label>:<br> |
||
| 240 | <span class="smalltext">', $txt['membergroups_edit_inherit_permissions_desc'], '</span> |
||
| 241 | </dt> |
||
| 242 | <dd> |
||
| 243 | <select name="group_inherit" id="group_inherit_input"> |
||
| 244 | <option value="-2">', $txt['membergroups_edit_inherit_permissions_no'], '</option> |
||
| 245 | <option value="-1"', $context['group']['inherited_from'] == -1 ? ' selected' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_guests'], '</option> |
||
| 246 | <option value="0"', $context['group']['inherited_from'] == 0 ? ' selected' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_members'], '</option>'; |
||
| 247 | |||
| 248 | // For all the inheritable groups show an option. |
||
| 249 | foreach ($context['inheritable_groups'] as $id => $group) |
||
| 250 | echo ' |
||
| 251 | <option value="', $id, '"', $context['group']['inherited_from'] == $id ? ' selected' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $group, '</option>'; |
||
| 252 | |||
| 253 | echo ' |
||
| 254 | </select> |
||
| 255 | <input type="hidden" name="old_inherit" value="', $context['group']['inherited_from'], '"> |
||
| 256 | </dd>'; |
||
| 257 | } |
||
| 258 | |||
| 259 | if ($context['group']['allow_post_group']) |
||
| 260 | echo ' |
||
| 261 | |||
| 262 | <dt id="min_posts_text"> |
||
| 263 | <label for="min_posts_input"><strong>', $txt['membergroups_min_posts'], ':</strong></label> |
||
| 264 | </dt> |
||
| 265 | <dd> |
||
| 266 | <input type="number" name="min_posts" id="min_posts_input"', $context['group']['is_post_group'] ? ' value="' . $context['group']['min_posts'] . '"' : '', ' size="6"> |
||
| 267 | </dd>'; |
||
| 268 | |||
| 269 | echo ' |
||
| 270 | <dt> |
||
| 271 | <label for="online_color_input"><strong>', $txt['membergroups_online_color'], ':</strong></label> |
||
| 272 | </dt> |
||
| 273 | <dd> |
||
| 274 | <input type="text" name="online_color" id="online_color_input" value="', $context['group']['color'], '" size="20"> |
||
| 275 | </dd> |
||
| 276 | <dt> |
||
| 277 | <label for="icon_count_input"><strong>', $txt['membergroups_icon_count'], ':</strong></label> |
||
| 278 | </dt> |
||
| 279 | <dd> |
||
| 280 | <input type="number" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4"> |
||
| 281 | </dd>'; |
||
| 282 | |||
| 283 | // Do we have any possible icons to select from? |
||
| 284 | if (!empty($context['possible_icons'])) |
||
| 285 | { |
||
| 286 | echo ' |
||
| 287 | <dt> |
||
| 288 | <label for="icon_image_input"><strong>', $txt['membergroups_icon_image'], ':</strong></label><br> |
||
| 289 | <span class="smalltext">', $txt['membergroups_icon_image_note'], '</span> |
||
| 290 | <span class="smalltext">', $txt['membergroups_icon_image_size'], '</span> |
||
| 291 | </dt> |
||
| 292 | <dd> |
||
| 293 | ', $txt['membergroups_images_url'], ' |
||
| 294 | <select name="icon_image" id="icon_image_input">'; |
||
| 295 | |||
| 296 | // For every possible icon, create an option. |
||
| 297 | foreach ($context['possible_icons'] as $icon) |
||
| 298 | echo ' |
||
| 299 | <option value="', $icon, '"', $context['group']['icon_image'] == $icon ? ' selected' : '', '>', $icon, '</option>'; |
||
| 300 | |||
| 301 | echo ' |
||
| 302 | </select> |
||
| 303 | <img id="icon_preview" src="" alt="*"> |
||
| 304 | </dd>'; |
||
| 305 | } |
||
| 306 | |||
| 307 | // No? Hide the entire control. |
||
| 308 | else |
||
| 309 | echo ' |
||
| 310 | <input type="hidden" name="icon_image" value="">'; |
||
| 311 | |||
| 312 | echo ' |
||
| 313 | <dt> |
||
| 314 | <label for="max_messages_input"><strong>', $txt['membergroups_max_messages'], ':</strong></label><br> |
||
| 315 | <span class="smalltext">', $txt['membergroups_max_messages_note'], '</span> |
||
| 316 | </dt> |
||
| 317 | <dd> |
||
| 318 | <input type="text" name="max_messages" id="max_messages_input" value="', $context['group']['id'] == 1 ? 0 : $context['group']['max_messages'], '" size="6"', $context['group']['id'] == 1 ? ' disabled' : '', '> |
||
| 319 | </dd>'; |
||
| 320 | |||
| 321 | // Force 2FA for this membergroup? |
||
| 322 | if (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] == 2) |
||
| 323 | echo ' |
||
| 324 | <dt> |
||
| 325 | <label for="group_tfa_force_input"><strong>', $txt['membergroups_tfa_force'], ':</strong></label><br> |
||
| 326 | <span class="smalltext">', $txt['membergroups_tfa_force_note'], '</span> |
||
| 327 | </dt> |
||
| 328 | <dd> |
||
| 329 | <input type="checkbox" name="group_tfa_force"', $context['group']['tfa_required'] ? ' checked' : '', '> |
||
| 330 | </dd>'; |
||
| 331 | |||
| 332 | if (!empty($context['categories'])) |
||
| 333 | { |
||
| 334 | echo ' |
||
| 335 | <dt> |
||
| 336 | <strong>', $txt['membergroups_new_board'], ':</strong>', $context['group']['is_post_group'] ? '<br> |
||
| 337 | <span class="smalltext">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', ' |
||
| 338 | </dt> |
||
| 339 | <dd>'; |
||
| 340 | |||
| 341 | if (!empty($context['can_manage_boards'])) |
||
| 342 | echo $txt['membergroups_can_manage_access']; |
||
| 343 | |||
| 344 | else |
||
| 345 | template_add_edit_group_boards_list(); |
||
| 346 | |||
| 347 | echo ' |
||
| 348 | </dd>'; |
||
| 349 | } |
||
| 350 | |||
| 351 | echo ' |
||
| 352 | </dl> |
||
| 353 | <input type="submit" name="save" value="', $txt['membergroups_edit_save'], '" class="button">', $context['group']['allow_delete'] ? ' |
||
| 354 | <input type="submit" name="delete" value="'. $txt['membergroups_delete'] . '" data-confirm="' . ($context['is_moderator_group'] ? $txt['membergroups_confirm_delete_mod'] : $txt['membergroups_confirm_delete']) . '" class="button you_sure">' : '', ' |
||
| 355 | </div><!-- .windowbg --> |
||
| 356 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
||
| 357 | <input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '"> |
||
| 358 | </form> |
||
| 359 | <script> |
||
| 360 | var oModeratorSuggest = new smc_AutoSuggest({ |
||
| 361 | sSelf: \'oModeratorSuggest\', |
||
| 362 | sSessionId: smf_session_id, |
||
| 363 | sSessionVar: smf_session_var, |
||
| 364 | sSuggestId: \'group_moderators\', |
||
| 365 | sControlId: \'group_moderators\', |
||
| 366 | sSearchType: \'member\', |
||
| 367 | bItemList: true, |
||
| 368 | sPostName: \'moderator_list\', |
||
| 369 | sURLMask: \'action=profile;u=%item_id%\', |
||
| 370 | sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\', |
||
| 371 | sItemListContainerId: \'moderator_container\', |
||
| 372 | aListItems: ['; |
||
| 373 | |||
| 374 | foreach ($context['group']['moderators'] as $id_member => $member_name) |
||
| 375 | echo ' |
||
| 376 | { |
||
| 377 | sItemId: ', JavaScriptEscape($id_member), ', |
||
| 378 | sItemName: ', JavaScriptEscape($member_name), ' |
||
| 379 | }', $id_member == $context['group']['last_moderator_id'] ? '' : ','; |
||
| 380 | |||
| 381 | echo ' |
||
| 382 | ] |
||
| 383 | }); |
||
| 384 | </script>'; |
||
| 385 | |||
| 386 | if ($context['group']['allow_post_group']) |
||
| 387 | echo ' |
||
| 388 | <script> |
||
| 389 | function swapPostGroup(isChecked) |
||
| 390 | { |
||
| 391 | var is_moderator_group = ', $context['is_moderator_group'], '; |
||
| 392 | var group_type = ', $context['group']['type'], '; |
||
| 393 | var min_posts_text = document.getElementById(\'min_posts_text\'); |
||
| 394 | var group_desc_text = document.getElementById(\'group_desc_text\'); |
||
| 395 | var group_hidden_text = document.getElementById(\'group_hidden_text\'); |
||
| 396 | var group_moderators_text = document.getElementById(\'group_moderators_text\'); |
||
| 397 | |||
| 398 | // If it\'s a moderator group, warn of possible problems... and remember the group type |
||
| 399 | if (isChecked && is_moderator_group && !confirm(\'', $txt['membergroups_swap_mod'], '\')) |
||
| 400 | { |
||
| 401 | isChecked = false; |
||
| 402 | |||
| 403 | switch(group_type) |
||
| 404 | { |
||
| 405 | case 0: |
||
| 406 | document.getElementById(\'group_type_private\').checked = true; |
||
| 407 | break; |
||
| 408 | case 1: |
||
| 409 | document.getElementById(\'group_type_protected\').checked = true; |
||
| 410 | break; |
||
| 411 | case 2: |
||
| 412 | document.getElementById(\'group_type_request\').checked = true; |
||
| 413 | break; |
||
| 414 | case 3: |
||
| 415 | document.getElementById(\'group_type_free\').checked = true; |
||
| 416 | break; |
||
| 417 | default: |
||
| 418 | document.getElementById(\'group_type_private\').checked = true; |
||
| 419 | break; |
||
| 420 | } |
||
| 421 | } |
||
| 422 | |||
| 423 | document.forms.groupForm.min_posts.disabled = !isChecked; |
||
| 424 | min_posts_text.style.color = isChecked ? "" : "#888888"; |
||
| 425 | document.forms.groupForm.group_desc_input.disabled = isChecked; |
||
| 426 | group_desc_text.style.color = !isChecked ? "" : "#888888"; |
||
| 427 | document.forms.groupForm.group_hidden_input.disabled = isChecked; |
||
| 428 | group_hidden_text.style.color = !isChecked ? "" : "#888888"; |
||
| 429 | document.forms.groupForm.group_moderators.disabled = isChecked; |
||
| 430 | group_moderators_text.style.color = !isChecked ? "" : "#888888"; |
||
| 431 | } |
||
| 432 | |||
| 433 | swapPostGroup(', $context['group']['is_post_group'] ? 'true' : 'false', '); |
||
| 434 | </script>'; |
||
| 750 | ?> |