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