| Conditions | 24 |
| Paths | 24 |
| Total Lines | 94 |
| Code Lines | 39 |
| 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 |
||
| 201 | function template_create_list_menu($list_menu, $direction = 'top') |
||
| 202 | { |
||
| 203 | global $context; |
||
| 204 | |||
| 205 | /** |
||
| 206 | // This is used if you want your generic lists to have tabs. |
||
| 207 | $cur_list['list_menu'] = array( |
||
| 208 | // This is the style to use. Tabs or Buttons (Text 1 | Text 2). |
||
| 209 | // By default tabs are selected if not set. |
||
| 210 | // The main difference between tabs and buttons is that tabs get highlighted if selected. |
||
| 211 | // If style is set to buttons and use tabs is disabled then we change the style to old styled tabs. |
||
| 212 | 'style' => 'tabs', |
||
| 213 | // The position of the tabs/buttons. Left or Right. By default is set to left. |
||
| 214 | 'position' => 'left', |
||
| 215 | // This is used by the old styled menu. We *need* to know the total number of columns to span. |
||
| 216 | 'columns' => 0, |
||
| 217 | // This gives you the option to show tabs only at the top, bottom or both. |
||
| 218 | // By default they are just shown at the top. |
||
| 219 | 'show_on' => 'top', |
||
| 220 | // Links. This is the core of the array. It has all the info that we need. |
||
| 221 | 'links' => array( |
||
| 222 | 'name' => array( |
||
| 223 | // This will tell use were to go when they click it. |
||
| 224 | 'href' => $scripturl . '?action=theaction', |
||
| 225 | // The name that you want to appear for the link. |
||
| 226 | 'label' => $txt['name'], |
||
| 227 | // If we use tabs instead of buttons we highlight the current tab. |
||
| 228 | // Must use conditions to determine if its selected or not. |
||
| 229 | 'is_selected' => isset($_REQUEST['name']), |
||
| 230 | ), |
||
| 231 | ), |
||
| 232 | ); |
||
| 233 | */ |
||
| 234 | |||
| 235 | // Are we using right-to-left orientation? |
||
| 236 | $first = $context['right_to_left'] ? 'last' : 'first'; |
||
| 237 | $last = $context['right_to_left'] ? 'first' : 'last'; |
||
| 238 | |||
| 239 | if (!isset($list_menu['style']) || isset($list_menu['style']) && $list_menu['style'] == 'tabs') |
||
| 240 | { |
||
| 241 | echo ' |
||
| 242 | <table style="margin-', $list_menu['position'], ': 10px; width: 100%;"> |
||
| 243 | <tr>', $list_menu['position'] == 'right' ? ' |
||
| 244 | <td></td>' : '', ' |
||
| 245 | <td class="', $list_menu['position'], 'text"> |
||
| 246 | <table> |
||
| 247 | <tr> |
||
| 248 | <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $first, '"></td>'; |
||
| 249 | |||
| 250 | foreach ($list_menu['links'] as $link) |
||
| 251 | { |
||
| 252 | if ($link['is_selected']) |
||
| 253 | echo ' |
||
| 254 | <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_active_', $first, '"></td> |
||
| 255 | <td class="', $direction == 'top' ? 'mirrortab' : 'maintab', '_active_back"> |
||
| 256 | <a href="', $link['href'], '">', $link['label'], '</a> |
||
| 257 | </td> |
||
| 258 | <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_active_', $last, '"></td>'; |
||
| 259 | else |
||
| 260 | echo ' |
||
| 261 | <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_back"> |
||
| 262 | <a href="', $link['href'], '">', $link['label'], '</a> |
||
| 263 | </td>'; |
||
| 264 | } |
||
| 265 | |||
| 266 | echo ' |
||
| 267 | <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $last, '"></td> |
||
| 268 | </tr> |
||
| 269 | </table> |
||
| 270 | </td>', $list_menu['position'] == 'left' ? ' |
||
| 271 | <td></td>' : '', ' |
||
| 272 | </tr> |
||
| 273 | </table>'; |
||
| 274 | } |
||
| 275 | elseif (isset($list_menu['style']) && $list_menu['style'] == 'buttons') |
||
| 276 | { |
||
| 277 | $links = array(); |
||
| 278 | foreach ($list_menu['links'] as $link) |
||
| 279 | $links[] = '<a href="' . $link['href'] . '">' . $link['label'] . '</a>'; |
||
| 280 | |||
| 281 | echo ' |
||
| 282 | <table style="margin-', $list_menu['position'], ': 10px; width: 100%;"> |
||
| 283 | <tr>', $list_menu['position'] == 'right' ? ' |
||
| 284 | <td></td>' : '', ' |
||
| 285 | <td class="', $list_menu['position'], 'text"> |
||
| 286 | <table> |
||
| 287 | <tr> |
||
| 288 | <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $first, '"></td> |
||
| 289 | <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_back">', implode(' | ', $links), '</td> |
||
| 290 | <td class="', $direction == 'top' ? 'mirror' : 'main', 'tab_', $last, '"></td> |
||
| 291 | </tr> |
||
| 292 | </table> |
||
| 293 | </td>', $list_menu['position'] == 'left' ? ' |
||
| 294 | <td></td>' : '', ' |
||
| 295 | </tr> |
||
| 300 | ?> |