| Conditions | 13 |
| Paths | 16 |
| Total Lines | 205 |
| Code Lines | 123 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 45 | function ManageUltimateMenu() |
||
| 46 | { |
||
| 47 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc; |
||
| 48 | |||
| 49 | // Get rid of all of em! |
||
| 50 | if (!empty($_POST['removeAll'])) |
||
| 51 | { |
||
| 52 | checkSession(); |
||
| 53 | |||
| 54 | $smcFunc['db_query']('', ' |
||
| 55 | TRUNCATE {db_prefix}um_menu'); |
||
| 56 | |||
| 57 | $this->rebuildMenu(); |
||
| 58 | redirectexit('action=admin;area=umen'); |
||
| 59 | } |
||
| 60 | |||
| 61 | // User pressed the 'remove selection button'. |
||
| 62 | if (!empty($_POST['removeButtons']) && !empty($_POST['remove']) && is_array($_POST['remove'])) |
||
| 63 | { |
||
| 64 | checkSession(); |
||
| 65 | |||
| 66 | // Make sure every entry is a proper integer. |
||
| 67 | foreach ($_POST['remove'] as $index => $page_id) |
||
| 68 | $_POST['remove'][(int) $index] = (int) $page_id; |
||
| 69 | |||
| 70 | // Delete the page! |
||
| 71 | $smcFunc['db_query']('', ' |
||
| 72 | DELETE FROM {db_prefix}um_menu |
||
| 73 | WHERE id_button IN ({array_int:button_list})', |
||
| 74 | array( |
||
| 75 | 'button_list' => $_POST['remove'], |
||
| 76 | ) |
||
| 77 | ); |
||
| 78 | $this->rebuildMenu(); |
||
| 79 | redirectexit('action=admin;area=umen'); |
||
| 80 | } |
||
| 81 | |||
| 82 | // Changing the status? |
||
| 83 | if (isset($_POST['save'])) |
||
| 84 | { |
||
| 85 | checkSession(); |
||
| 86 | foreach ($this->total_getMenu() as $item) |
||
| 87 | { |
||
| 88 | $status = !empty($_POST['status'][$item['id_button']]) ? 'active' : 'inactive'; |
||
| 89 | if ($status != $item['status']) |
||
| 90 | $smcFunc['db_query']('', ' |
||
| 91 | UPDATE {db_prefix}um_menu |
||
| 92 | SET status = {string:status} |
||
| 93 | WHERE id_button = {int:item}', |
||
| 94 | array( |
||
| 95 | 'status' => $status, |
||
| 96 | 'item' => $item['id_button'], |
||
| 97 | ) |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | $this->rebuildMenu(); |
||
| 101 | redirectexit('action=admin;area=umen'); |
||
| 102 | } |
||
| 103 | |||
| 104 | // New item? |
||
| 105 | if (isset($_POST['new'])) |
||
| 106 | redirectexit('action=admin;area=umen;sa=addbutton'); |
||
| 107 | |||
| 108 | loadLanguage('ManageBoards'); |
||
| 109 | $button_names = $this->getButtonNames(); |
||
| 110 | |||
| 111 | // Our options for our list. |
||
| 112 | $listOptions = array( |
||
| 113 | 'id' => 'menu_list', |
||
| 114 | 'items_per_page' => 20, |
||
| 115 | 'base_href' => $scripturl . '?action=admin;area=umen;sa=manmenu', |
||
| 116 | 'default_sort_col' => 'name', |
||
| 117 | 'default_sort_dir' => 'desc', |
||
| 118 | 'get_items' => array( |
||
| 119 | 'function' => 'list_getMenu', |
||
| 120 | ), |
||
| 121 | 'get_count' => array( |
||
| 122 | 'function' => 'list_getNumButtons', |
||
| 123 | ), |
||
| 124 | 'no_items_label' => $txt['um_menu_no_buttons'], |
||
| 125 | 'columns' => array( |
||
| 126 | 'name' => array( |
||
| 127 | 'header' => array( |
||
| 128 | 'value' => $txt['um_menu_button_name'], |
||
| 129 | ), |
||
| 130 | 'data' => array( |
||
| 131 | 'db_htmlsafe' => 'name', |
||
| 132 | 'class' => 'centertext', |
||
| 133 | ), |
||
| 134 | 'sort' => array( |
||
| 135 | 'default' => 'name', |
||
| 136 | 'reverse' => 'name DESC', |
||
| 137 | ), |
||
| 138 | ), |
||
| 139 | 'type' => array( |
||
| 140 | 'header' => array( |
||
| 141 | 'value' => $txt['um_menu_button_type'], |
||
| 142 | ), |
||
| 143 | 'data' => array( |
||
| 144 | 'function' => function($rowData) use ($txt) |
||
| 145 | { |
||
| 146 | return $txt[$rowData['type'] . '_link']; |
||
| 147 | }, |
||
| 148 | 'class' => 'centertext', |
||
| 149 | ), |
||
| 150 | 'sort' => array( |
||
| 151 | 'default' => 'type', |
||
| 152 | 'reverse' => 'type DESC', |
||
| 153 | ), |
||
| 154 | ), |
||
| 155 | 'poition' => array( |
||
| 156 | 'header' => array( |
||
| 157 | 'value' => $txt['um_menu_button_position'], |
||
| 158 | ), |
||
| 159 | 'data' => array( |
||
| 160 | 'function' => function($rowData) use ($txt, $button_names) |
||
| 161 | { |
||
| 162 | return $txt['mboards_order_' . $rowData['position']] . ' ' . (isset($button_names[$rowData['parent']]) ? $button_names[$rowData['parent']] : ucwords($rowData['parent'])); |
||
| 163 | }, |
||
| 164 | 'class' => 'centertext', |
||
| 165 | ), |
||
| 166 | 'sort' => array( |
||
| 167 | 'default' => 'position', |
||
| 168 | 'reverse' => 'position DESC', |
||
| 169 | ), |
||
| 170 | ), |
||
| 171 | 'link' => array( |
||
| 172 | 'header' => array( |
||
| 173 | 'value' => $txt['um_menu_button_link'], |
||
| 174 | ), |
||
| 175 | 'data' => array( |
||
| 176 | 'db_htmlsafe' => 'link', |
||
| 177 | 'class' => 'centertext', |
||
| 178 | ), |
||
| 179 | 'sort' => array( |
||
| 180 | 'default' => 'link', |
||
| 181 | 'reverse' => 'link DESC', |
||
| 182 | ), |
||
| 183 | ), |
||
| 184 | 'status' => array( |
||
| 185 | 'header' => array( |
||
| 186 | 'value' => $txt['um_menu_button_active'], |
||
| 187 | ), |
||
| 188 | 'data' => array( |
||
| 189 | 'function' => function($rowData) use ($txt) |
||
| 190 | { |
||
| 191 | return sprintf('<input type="checkbox" name="status[%1$s]" id="status_%1$s" value="%1$s"%2$s />', $rowData['id_button'], $rowData['status'] == 'inactive' ? '' : ' checked="checked"'); |
||
| 192 | }, |
||
| 193 | 'class' => 'centertext', |
||
| 194 | ), |
||
| 195 | 'sort' => array( |
||
| 196 | 'default' => 'status', |
||
| 197 | 'reverse' => 'status DESC', |
||
| 198 | ), |
||
| 199 | ), |
||
| 200 | 'actions' => array( |
||
| 201 | 'header' => array( |
||
| 202 | 'value' => $txt['um_menu_actions'], |
||
| 203 | ), |
||
| 204 | 'data' => array( |
||
| 205 | 'sprintf' => array( |
||
| 206 | 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=admin;area=umen;sa=addbutton;edit;in=%1$d">' . $txt['modify'] . '</a>', |
||
| 207 | 'params' => array( |
||
| 208 | 'id_button' => false, |
||
| 209 | ), |
||
| 210 | ), |
||
| 211 | 'class' => 'centertext', |
||
| 212 | ), |
||
| 213 | ), |
||
| 214 | 'check' => array( |
||
| 215 | 'header' => array( |
||
| 216 | 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />', |
||
| 217 | ), |
||
| 218 | 'data' => array( |
||
| 219 | 'sprintf' => array( |
||
| 220 | 'format' => '<input type="checkbox" name="remove[]" value="%1$d" class="input_check" />', |
||
| 221 | 'params' => array( |
||
| 222 | 'id_button' => false, |
||
| 223 | ), |
||
| 224 | ), |
||
| 225 | 'class' => 'centertext', |
||
| 226 | ), |
||
| 227 | ), |
||
| 228 | ), |
||
| 229 | 'form' => array( |
||
| 230 | 'href' => $scripturl . '?action=admin;area=umen;sa=manmenu', |
||
| 231 | ), |
||
| 232 | 'additional_rows' => array( |
||
| 233 | array( |
||
| 234 | 'position' => 'below_table_data', |
||
| 235 | 'value' => ' |
||
| 236 | <input type="submit" name="removeButtons" value="' . $txt['um_menu_remove_selected'] . '" onclick="return confirm(\'' . $txt['um_menu_remove_confirm'] . '\');" class="button_submit" /> |
||
| 237 | <input type="submit" name="removeAll" value="' . $txt['um_menu_remove_all'] . '" onclick="return confirm(\'' . $txt['um_menu_remove_all_confirm'] . '\');" class="button_submit" /> |
||
| 238 | <input type="submit" name="new" value="' . $txt['um_admin_add_button'] . '" class="button_submit" /> |
||
| 239 | <input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />', |
||
| 240 | 'class' => 'righttext', |
||
| 241 | ), |
||
| 242 | ), |
||
| 243 | ); |
||
| 244 | |||
| 245 | require_once($sourcedir . '/Subs-List.php'); |
||
| 246 | createList($listOptions); |
||
| 247 | |||
| 248 | $context['sub_template'] = 'show_list'; |
||
| 249 | $context['default_list'] = 'menu_list'; |
||
| 250 | } |
||
| 522 | } |