| Conditions | 8 |
| Paths | 32 |
| Total Lines | 179 |
| Code Lines | 80 |
| 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 |
||
| 18 | function template_maintenance() |
||
| 19 | { |
||
| 20 | global $context, $txt, $modSettings; |
||
| 21 | |||
| 22 | echo ' |
||
| 23 | <div id="manage_attachments"> |
||
| 24 | <h2 class="category_header hdicon i-pie-chart">', $txt['attachment_stats'], '</h2> |
||
| 25 | <div class="content"> |
||
| 26 | <dl class="settings"> |
||
| 27 | <dt><label>', $txt['attachment_total'], ':</label></dt> |
||
| 28 | <dd>', $context['num_attachments'], '</dd> |
||
| 29 | <dt><label>', $txt['attachment_manager_total_avatars'], ':</label></dt> |
||
| 30 | <dd>', $context['num_avatars'], '</dd> |
||
| 31 | <dt><label>', $txt['attachmentdir_size'], ':</label></dt> |
||
| 32 | <dd>', $context['attachment_total_size'], '</dd> |
||
| 33 | <dt><label>', $txt['attach_current_dir'], ':</label></dt> |
||
| 34 | <dd>', $context['attach_dirs'][$modSettings['currentAttachmentUploadDir']], '</dd> |
||
| 35 | <dt><label>', $txt['attachmentdir_size_current'], ':</label></dt> |
||
| 36 | <dd>', $context['attachment_current_size'], '</dd> |
||
| 37 | <dt><label>', $txt['attachment_space'], ':</label></dt> |
||
| 38 | <dd>', $context['attachment_space'] ?? $txt['attachmentdir_size_not_set'], '</dd> |
||
| 39 | <dt><label>', $txt['attachmentdir_files_current'], ':</label></dt> |
||
| 40 | <dd>', $context['attachment_current_files'], '</dd> |
||
| 41 | <dt><label>', $txt['attachment_files'], ':</label></dt> |
||
| 42 | <dd>', $context['attachment_files'] ?? $txt['attachmentdir_files_not_set'], '</dd> |
||
| 43 | </dl> |
||
| 44 | </div> |
||
| 45 | <div class="separator"></div> |
||
| 46 | <h2 class="category_header">', $txt['attachment_integrity_check'], '</h2> |
||
| 47 | <div class="content"> |
||
| 48 | <form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments', 'sa' => 'repair', '{session_data}']), '" method="post" accept-charset="UTF-8"> |
||
| 49 | <p>', $txt['attachment_integrity_check_desc'], '</p> |
||
| 50 | <div class="submitbutton"> |
||
| 51 | <input type="submit" name="repair" value="', $txt['attachment_check_now'], '" /> |
||
| 52 | </div> |
||
| 53 | </form> |
||
| 54 | </div> |
||
| 55 | <div class="separator"></div> |
||
| 56 | <h2 class="category_header">', $txt['attachment_pruning'], '</h2> |
||
| 57 | <div class="content"> |
||
| 58 | <form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments']), '" method="post" accept-charset="UTF-8" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');"> |
||
| 59 | <label for="age">', sprintf($txt['attachment_remove_old'], ' <input type="text" id="age" name="age" value="25" size="4" class="input_text" /> '), '</label><br /> |
||
| 60 | <label for="age_notice">', $txt['attachment_pruning_message'], '</label>: <input type="text" id="age_notice" name="notice" value="', $txt['attachment_delete_admin'], '" size="40" class="input_text" /><br /> |
||
| 61 | <div class="submitbutton"> |
||
| 62 | <input type="submit" name="remove" value="', $txt['remove'], '" /> |
||
| 63 | <input type="hidden" name="type" value="attachments" /> |
||
| 64 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" /> |
||
| 65 | <input type="hidden" name="sa" value="byAge" /> |
||
| 66 | </div> |
||
| 67 | </form> |
||
| 68 | <hr /> |
||
| 69 | <form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments']), '" method="post" accept-charset="UTF-8" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');"> |
||
| 70 | <label for="size">', sprintf($txt['attachment_remove_size'], ' <input type="text" name="size" id="size" value="1000" size="5" class="input_text" /> '), '</label><br /> |
||
| 71 | <label for="size_notice">', $txt['attachment_pruning_message'], '</label>: <input type="text" id="size_notice" name="notice" value="', $txt['attachment_delete_admin'], '" size="40" class="input_text" /><br /> |
||
| 72 | <div class="submitbutton"> |
||
| 73 | <input type="submit" name="remove" value="', $txt['remove'], '" /> |
||
| 74 | <input type="hidden" name="type" value="attachments" /> |
||
| 75 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" /> |
||
| 76 | <input type="hidden" name="sa" value="bySize" /> |
||
| 77 | </div> |
||
| 78 | </form> |
||
| 79 | <hr /> |
||
| 80 | <form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments']), '" method="post" accept-charset="UTF-8" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');"> |
||
| 81 | <label for="avatar_age">', sprintf($txt['attachment_manager_avatars_older'], ' |
||
| 82 | <input type="text" id="avatar_age" name="age" value="45" size="4" class="input_text" /> '), ' |
||
| 83 | </label> |
||
| 84 | <div class="submitbutton"> |
||
| 85 | <input type="submit" name="remove" value="', $txt['remove'], '" /> |
||
| 86 | <input type="hidden" name="type" value="avatars" /> |
||
| 87 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" /> |
||
| 88 | <input type="hidden" name="sa" value="byAge" /> |
||
| 89 | </div> |
||
| 90 | </form> |
||
| 91 | </div> |
||
| 92 | <div class="separator"></div>'; |
||
| 93 | |||
| 94 | // Transfer Attachments section |
||
| 95 | echo ' |
||
| 96 | <h2 id="transfer" class="category_header">', $txt['attachment_transfer'], '</h2>'; |
||
| 97 | |||
| 98 | // Any results to show |
||
| 99 | if (!empty($context['results'])) |
||
| 100 | { |
||
| 101 | echo ' |
||
| 102 | <div class="successbox">', $context['results'], '</div>'; |
||
| 103 | } |
||
| 104 | |||
| 105 | // Lots-o-options |
||
| 106 | echo ' |
||
| 107 | <div class="content"> |
||
| 108 | <form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments', 'sa' => 'transfer']), '" method="post" accept-charset="UTF-8"> |
||
| 109 | <p class="infobox">', $txt['attachment_transfer_desc'], '</p> |
||
| 110 | <dl class="settings"> |
||
| 111 | <dt> |
||
| 112 | <label for="from">', $txt['attachment_transfer_from'], '</label> |
||
| 113 | </dt> |
||
| 114 | <dd> |
||
| 115 | <select id="from" name="from"> |
||
| 116 | <option value="0">', $txt['attachment_transfer_select'], '</option>'; |
||
| 117 | |||
| 118 | foreach ($context['attach_dirs'] as $id => $dir) |
||
| 119 | { |
||
| 120 | echo ' |
||
| 121 | <option value="', $id, '">', $dir, '</option>'; |
||
| 122 | } |
||
| 123 | |||
| 124 | echo ' |
||
| 125 | </select> |
||
| 126 | </dd> |
||
| 127 | <dt> |
||
| 128 | <label for="auto">', $txt['attachment_transfer_auto'], '</label> |
||
| 129 | </dt> |
||
| 130 | <dd> |
||
| 131 | <select id="auto" name="auto" onchange="transferAttachOptions();"> |
||
| 132 | <option value="0">', $txt['attachment_transfer_auto_select'], '</option> |
||
| 133 | <option value="-1">', $txt['attachment_transfer_forum_root'], '</option>'; |
||
| 134 | |||
| 135 | if (!empty($context['base_dirs'])) |
||
| 136 | { |
||
| 137 | foreach ($context['base_dirs'] as $id => $dir) |
||
| 138 | { |
||
| 139 | echo ' |
||
| 140 | <option value="', $id, '">', $dir, '</option>'; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | else |
||
| 144 | { |
||
| 145 | echo ' |
||
| 146 | <option value="0" disabled="disabled">', $txt['attachment_transfer_no_base'], '</option>'; |
||
| 147 | } |
||
| 148 | |||
| 149 | echo ' |
||
| 150 | </select> |
||
| 151 | </dd> |
||
| 152 | <dt> |
||
| 153 | <label for="to">', $txt['attachment_transfer_to'], '</label> |
||
| 154 | </dt> |
||
| 155 | <dd> |
||
| 156 | <select id="to" name="to" onchange="transferAttachOptions();" > |
||
| 157 | <option value="0">', $txt['attachment_transfer_select'], '</option>'; |
||
| 158 | |||
| 159 | foreach ($context['attach_dirs'] as $id => $dir) |
||
| 160 | { |
||
| 161 | echo ' |
||
| 162 | <option value="', $id, '">', $dir, '</option>'; |
||
| 163 | } |
||
| 164 | |||
| 165 | echo ' |
||
| 166 | </select> |
||
| 167 | </dd>'; |
||
| 168 | |||
| 169 | // If there are directory limits to impose, give the option to enforce it |
||
| 170 | if (!empty($modSettings['attachmentDirFileLimit'])) |
||
| 171 | { |
||
| 172 | echo ' |
||
| 173 | <dt> |
||
| 174 | <a href="' . getUrl('action', ['action' => 'quickhelp', 'help' => 'attachment_transfer_empty']), '" onclick="return reqOverlayDiv(this.href);" class="helpicon i-help"><s>' . $txt['help'] . '</s></a>', $txt['attachment_transfer_empty'], ' |
||
| 175 | </dt> |
||
| 176 | <dd> |
||
| 177 | <input type="checkbox" name="empty_it"', $context['checked'] ? ' checked="checked"' : '', ' /> |
||
| 178 | </dd>'; |
||
| 179 | } |
||
| 180 | |||
| 181 | echo ' |
||
| 182 | </dl> |
||
| 183 | <div class="submitbutton"> |
||
| 184 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" /> |
||
| 185 | <input type="submit" onclick="start_progress()" name="transfer" value="', $txt['attachment_transfer_now'], '" /> |
||
| 186 | </div> |
||
| 187 | <div id="progress_msg"></div> |
||
| 188 | <div id="show_progress"></div> |
||
| 189 | </form> |
||
| 190 | <script> |
||
| 191 | function start_progress() { |
||
| 192 | setTimeout(function() {show_msg();}, 1000); |
||
| 193 | } |
||
| 194 | |||
| 195 | function show_msg() { |
||
| 196 | $(\'#progress_msg\').html(\'<div><i class="icon i-oval"></i> ', $txt['attachment_transfer_progress'], '<\/div>\'); |
||
| 197 | show_progress(); |
||
| 283 |