elkarte /
Elkarte
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * @package ElkArte Forum |
||
| 5 | * @copyright ElkArte Forum contributors |
||
| 6 | * @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
||
| 7 | * |
||
| 8 | * @version 2.0 dev |
||
| 9 | * |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Renders a collapsible list of groups |
||
| 14 | * |
||
| 15 | * @param string $group defaults to default_groups_list |
||
| 16 | */ |
||
| 17 | function template_list_groups_collapsible($group = 'default_groups_list') |
||
| 18 | { |
||
| 19 | global $context, $txt; |
||
| 20 | |||
| 21 | $current_group_list = $context[$group]; |
||
| 22 | $all_selected = true; |
||
| 23 | |||
| 24 | if (!isset($current_group_list['id'])) |
||
| 25 | { |
||
| 26 | $current_group_list['id'] = $group; |
||
| 27 | } |
||
| 28 | |||
| 29 | echo ' |
||
| 30 | <fieldset id="', $current_group_list['id'], '"> |
||
| 31 | <legend>', $current_group_list['select_group'], '</legend>'; |
||
| 32 | |||
| 33 | echo ' |
||
| 34 | <ul class="permission_groups">'; |
||
| 35 | |||
| 36 | foreach ($current_group_list['member_groups'] as $group) |
||
| 37 | { |
||
| 38 | $all_selected &= $group['status'] === 'on'; |
||
| 39 | echo ' |
||
| 40 | <li> |
||
| 41 | <input type="checkbox" id="', $current_group_list['id'], '_', $group['id'], '" name="', $current_group_list['id'], '[', $group['id'], ']" value="on"', $group['status'] == 'on' ? ' checked="checked"' : '', ' /> |
||
| 42 | <label for="', $current_group_list['id'], '_', $group['id'], '"', $group['is_postgroup'] ? ' class="em"' : '', '>', $group['name'], '</label> <em>(', $group['member_count'], ')</em> |
||
| 43 | </li>'; |
||
| 44 | } |
||
| 45 | |||
| 46 | echo ' |
||
| 47 | <li class="check_all"> |
||
| 48 | <input type="checkbox" id="check_all" ', $all_selected ? 'checked="checked" ' : '', 'onclick="invertAll(this, this.form, \'', $current_group_list['id'], '\');" class="input_check" /> |
||
| 49 | <label for="check_all">', $txt['check_all'], '</label> |
||
| 50 | </li> |
||
| 51 | </ul> |
||
| 52 | </fieldset>'; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Dropdown usable to select a board |
||
| 57 | * |
||
| 58 | * @param string $name |
||
| 59 | * @param string $label |
||
| 60 | * @param string $extra |
||
| 61 | * @param bool $all |
||
| 62 | * |
||
| 63 | * @return string as echoed output |
||
| 64 | */ |
||
| 65 | function template_select_boards($name, $label = '', $extra = '', $all = false) |
||
| 66 | { |
||
| 67 | global $context, $txt; |
||
| 68 | |||
| 69 | if (!empty($label)) |
||
| 70 | { |
||
| 71 | echo ' |
||
| 72 | <label for="', $name, '">', $label, ' </label>'; |
||
| 73 | } |
||
| 74 | |||
| 75 | echo ' |
||
| 76 | <select name="', $name, '" id="', $name, '" ', $extra, ' >'; |
||
| 77 | |||
| 78 | if ($all) |
||
| 79 | { |
||
| 80 | echo ' |
||
| 81 | <option value="">', $txt['icons_edit_icons_all_boards'], '</option>'; |
||
| 82 | } |
||
| 83 | |||
| 84 | foreach ($context['categories'] as $category) |
||
| 85 | { |
||
| 86 | echo ' |
||
| 87 | <optgroup label="', $category['name'], '">'; |
||
| 88 | |||
| 89 | foreach ($category['boards'] as $board) |
||
| 90 | { |
||
| 91 | echo ' |
||
| 92 | <option value="', $board['id'], '"', empty($board['selected']) ? '' : ' selected="selected"', !empty($context['current_board']) && $board['id'] == $context['current_board'] && $context['boards_current_disabled'] ? ' disabled="disabled"' : '', '>', $board['child_level'] > 0 ? str_repeat(' ', $board['child_level'] - 1) . ' ➤' : '', $board['name'], '</option>'; |
||
| 93 | } |
||
| 94 | |||
| 95 | echo ' |
||
| 96 | </optgroup>'; |
||
| 97 | } |
||
| 98 | |||
| 99 | echo ' |
||
| 100 | </select>'; |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Generate a strip of buttons (like those present at the top of the message display) |
||
| 105 | * |
||
| 106 | * What it does: |
||
| 107 | * |
||
| 108 | * - Create a button list area, passed an array of the button name with parameter values to use on each <li> |
||
| 109 | * ['buttonName' => [ |
||
| 110 | * 'url' => link to call when button is pressed |
||
| 111 | * 'text' => txt key to use as $txt[key] to display in the button |
||
| 112 | * 'icon' => (optional) svg icon name to be applied as <i class="icon i-{icon}"></i> in front of the text |
||
| 113 | * 'custom' => (optional) action to perform, generally used to add 'onclick' events |
||
| 114 | * 'test' => (optional) permission to check for in $context[key] before showing the button |
||
| 115 | * 'submenu' => (optional) if the button should be placed in a "more" dropdown button |
||
| 116 | * 'class' => (optional) *additional* className to apply to the <li> element |
||
| 117 | * 'linkclass' => (optional) *additional* className to use on <a>, if not supplied defaults to button_strip_{buttonName} |
||
| 118 | * 'active' => (optional) adds active to the the list of classes on the <a> link |
||
| 119 | * 'id' => (optional) id to apply to the <a> link as button_strip_{id} |
||
| 120 | * 'checkbox' => (optional) 'always' will wrap an input element, otherwise an empty <li> placeholder, suitable for JS |
||
| 121 | * 'counter' => (optional) if set, will add a count indicator span in front of the link text |
||
| 122 | * ]] |
||
| 123 | * |
||
| 124 | * @param array $button_strip the above definition array |
||
| 125 | * @param string $class overall class to append to "buttonlist no_js" on the list UL |
||
| 126 | * @param array $strip_options = [] of options applied to the outer <UL> |
||
| 127 | * 'id' => id to use on the UL |
||
| 128 | * 'no-class' => do not apply the default "buttonlist no_js" to the ul (will still use passed $class) |
||
| 129 | * 'above' => turn dropdown sub-menu into a dropup sub-menu |
||
| 130 | * @return void string as echoed content as buttons | submenu | checkbox |
||
| 131 | */ |
||
| 132 | function template_button_strip($button_strip, $class = '', $strip_options = []) |
||
| 133 | { |
||
| 134 | global $context, $txt, $options; |
||
| 135 | |||
| 136 | // Not sure if this can happen, but people can misuse functions very efficiently |
||
| 137 | if (empty($button_strip)) |
||
| 138 | { |
||
| 139 | return; |
||
| 140 | } |
||
| 141 | |||
| 142 | if (!is_array($strip_options)) |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 143 | { |
||
| 144 | $strip_options = []; |
||
| 145 | } |
||
| 146 | |||
| 147 | // Create the buttons... now with cleaner markup (yay!). |
||
| 148 | $buttons = []; |
||
| 149 | $subMenu = []; |
||
| 150 | $checkbox = []; |
||
| 151 | |||
| 152 | foreach ($button_strip as $buttonName => $buttonParameters) |
||
| 153 | { |
||
| 154 | // Don't have the right permission, or it has been disabled, no button for you! |
||
| 155 | if ((isset($buttonParameters['enabled']) && $buttonParameters['enabled'] === false) |
||
| 156 | || (isset($buttonParameters['test']) && empty($context[$buttonParameters['test']]))) |
||
| 157 | { |
||
| 158 | continue; |
||
| 159 | } |
||
| 160 | |||
| 161 | // Start with this button markup details |
||
| 162 | $id = (isset($buttonParameters['id']) ? 'id="button_strip_' . $buttonParameters['id'] . '"' : ''); |
||
| 163 | $liClass = 'class="listlevel1 ' . ($buttonParameters['class'] ?? $buttonName) . '"'; |
||
| 164 | $linkClass = 'class="linklevel1 ' . (empty($buttonParameters['active']) ? '' : 'active ') . (empty($buttonParameters['linkclass']) ? 'button_strip_' . $buttonName : $buttonParameters['linkclass']) . '"'; |
||
| 165 | $icon = empty($buttonParameters['icon']) ? '' : '<i class="icon icon-small i-' . preg_replace('/^i-/', '',$buttonParameters['icon']) . '"></i>'; |
||
| 166 | $counter = empty($buttonParameters['counter']) ? '' : '<span class="button_indicator">' . $buttonParameters['counter'] . '</span>'; |
||
| 167 | $url = $buttonParameters['url'] ?? 'javascript:void(0);'; |
||
| 168 | |||
| 169 | // Special case, the button checkbox. |
||
| 170 | if (!empty($buttonParameters['checkbox']) && (!empty($options['display_quick_mod']) || $buttonParameters['checkbox'] === 'always')) |
||
| 171 | { |
||
| 172 | // if not always, just reserve a checkbox location (e.g. for quick moderation) |
||
| 173 | $checkbox[] = ' |
||
| 174 | <li ' . (isset($buttonParameters['id']) ? 'id="' . $buttonParameters['id'] . '"' : '') . ' ' . $liClass . ' role="none">' . |
||
| 175 | ($buttonParameters['checkbox'] === 'always' ? '<input role="menuitemcheckbox" class="input_check ' . $buttonName . '_check" type="checkbox" name="' . $buttonParameters['name'] . '[]" value="' . $buttonParameters['value'] . '" />' : '') . ' |
||
| 176 | </li>'; |
||
| 177 | |||
| 178 | continue; |
||
| 179 | } |
||
| 180 | |||
| 181 | // This little button goes in a dropdown |
||
| 182 | if (!empty($buttonParameters['submenu'])) |
||
| 183 | { |
||
| 184 | $subMenu[] = ' |
||
| 185 | <li ' . $liClass . ' role="none"> |
||
| 186 | <a href="' . $url . '" class="linklevel2 button_strip_' . $buttonName . '" ' . ($buttonParameters['custom'] ?? '') . '> |
||
| 187 | ' . $icon . $txt[$buttonParameters['text']] . ' |
||
| 188 | </a> |
||
| 189 | </li>'; |
||
| 190 | continue; |
||
| 191 | } |
||
| 192 | |||
| 193 | // This little button goes in a row |
||
| 194 | $buttons[] = ' |
||
| 195 | <li ' . $liClass . ' role="none"> |
||
| 196 | <a ' . $id . ' ' . $linkClass . ' role="menuitem" href="' . $url . '" ' . ($buttonParameters['custom'] ?? '') . '> |
||
| 197 | ' . $counter . $icon . $txt[$buttonParameters['text']] . ' |
||
| 198 | </a> |
||
| 199 | </li>'; |
||
| 200 | } |
||
| 201 | |||
| 202 | // If a "more" button was needed, we place it as the last button (but before a checkbox) |
||
| 203 | if (!empty($subMenu)) |
||
| 204 | { |
||
| 205 | $buttons[] = ' |
||
| 206 | <li class="listlevel1 subsections' . (!empty($strip_options['above']) ? ' above"' : '"') . ' role="none"> |
||
| 207 | <a aria-haspopup="true" role="menuitem" href="#" ' . (empty($options['use_click_menu']) ? 'onclick="event.stopPropagation();return false;"' : '') . ' class="linklevel1 post_options">' . |
||
| 208 | $txt['post_options'] . ' |
||
| 209 | </a> |
||
| 210 | <ul role="menu" class="menulevel2' . (!empty($strip_options['above']) ? ' above"' : '"') . '>' . implode('', $subMenu) . '</ul> |
||
| 211 | </li>'; |
||
| 212 | } |
||
| 213 | |||
| 214 | // No buttons? No button strip either. |
||
| 215 | if (!empty($buttons)) |
||
| 216 | { |
||
| 217 | // The markup details for the entire strip |
||
| 218 | $id = empty($strip_options['id']) ? '' : 'id="' . $strip_options['id'] . '" '; |
||
| 219 | $defaultClass = empty($strip_options['no-class']) ? 'buttonlist no_js' : ''; |
||
| 220 | $class .= $context['right_to_left'] ? ' rtl' : ''; |
||
| 221 | $class = trim($defaultClass . (empty($class) ? '' : ' ' . $class)); |
||
| 222 | |||
| 223 | echo ' |
||
| 224 | <ul ', $id, 'role="menubar" class="', $class, '"> |
||
| 225 | ', implode('', $buttons), implode('', $checkbox), ' |
||
| 226 | </ul>'; |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Another used and abused piece of template that can be found everywhere |
||
| 232 | * |
||
| 233 | * @param string|bool $button_strip index of $context to create the button strip |
||
| 234 | * @param string $strip_direction direction of the button strip (see template_button_strip for details) |
||
| 235 | * @param array $options array of optional values, possible values: |
||
| 236 | * - 'page_index' (string) index of $context where is located the pages index generated by constructPageIndex |
||
| 237 | * - 'page_index_markup' (string) markup for the page index, overrides 'page_index' and can be used if |
||
| 238 | * the page index code is not in the first level of $context |
||
| 239 | * - 'extra' (string) used to add html markup at the end of the template |
||
| 240 | * |
||
| 241 | * @return string as echoed content |
||
| 242 | */ |
||
| 243 | function template_pagesection($button_strip = false, $strip_direction = '', $options = []) |
||
| 244 | { |
||
| 245 | global $context; |
||
| 246 | |||
| 247 | if (!empty($options['page_index_markup'])) |
||
| 248 | { |
||
| 249 | $pages = '<ul ' . (isset($options['page_index_id']) ? 'id="' . $options['page_index_id'] . '" ' : '') . 'class="pagelinks">' . $options['page_index_markup'] . '</ul>'; |
||
| 250 | } |
||
| 251 | else |
||
| 252 | { |
||
| 253 | if (!isset($options['page_index'])) |
||
| 254 | { |
||
| 255 | $options['page_index'] = 'page_index'; |
||
| 256 | } |
||
| 257 | |||
| 258 | $pages = empty($context[$options['page_index']]) ? '' : '<ul ' . (isset($options['page_index_id']) ? 'id="' . $options['page_index_id'] . '" ' : '') . 'class="pagelinks">' . $context[$options['page_index']] . '</ul>'; |
||
| 259 | } |
||
| 260 | |||
| 261 | if (!isset($options['extra'])) |
||
| 262 | { |
||
| 263 | $options['extra'] = ''; |
||
| 264 | } |
||
| 265 | |||
| 266 | if (!empty($strip_direction) && $strip_direction === 'left') |
||
| 267 | { |
||
| 268 | $strip_direction = 'rtl'; |
||
| 269 | } |
||
| 270 | |||
| 271 | echo ' |
||
| 272 | <nav class="pagesection"> |
||
| 273 | ', $pages, ' |
||
| 274 | ', !empty($button_strip) && !empty($context[$button_strip]) ? template_button_strip($context[$button_strip], $strip_direction) : '', |
||
|
0 ignored issues
–
show
Are you sure the usage of
template_button_strip($c...rip], $strip_direction) is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 275 | $options['extra'], ' |
||
| 276 | </nav>'; |
||
| 277 | } |
||
| 278 | |||
| 279 | /** |
||
| 280 | * DEPRECIATED since 2.0 |
||
| 281 | * |
||
| 282 | * Generate a strip of "quick" buttons (those present next to each message) |
||
| 283 | * |
||
| 284 | * What it does: |
||
| 285 | * |
||
| 286 | * - Create a quick button, pass an array of the button name with key values |
||
| 287 | * - array('somename' => array(href => '' text => '' custom => '' test => '')) |
||
| 288 | * - href => link to call when button is pressed |
||
| 289 | * - text => text to display in the button |
||
| 290 | * - custom => custom action to perform, generally used to add 'onclick' events (optional) |
||
| 291 | * - test => key to check in the $tests array before showing the button (optional) |
||
| 292 | * - override => full and complete <li></li> to use for the button |
||
| 293 | * - checkboxes can be shown as well as buttons, |
||
| 294 | * - use array('check' => array(checkbox => (true | always), name => value =>) |
||
| 295 | * - if true follows show moderation as checkbox setting, always will always show |
||
| 296 | * - name => name of the checkbox array, like delete, will have [] added for the form |
||
| 297 | * - value => value for the checkbox to return in the post |
||
| 298 | * |
||
| 299 | * @param array $strip - the $context index where the strip is stored |
||
| 300 | * @param bool[] $tests - an array of tests to determine if the button should be displayed or not |
||
| 301 | * @depreciated since 2.0, use improved template_button_strip |
||
| 302 | * @return void echos a string of buttons |
||
| 303 | */ |
||
| 304 | function template_quickbutton_strip($strip, $tests = array()) |
||
| 305 | { |
||
| 306 | global $options; |
||
| 307 | |||
| 308 | // Annoy devs so they stop using this function |
||
| 309 | \ElkArte\Errors\Errors::instance()->log_error('Depreciated: template_quickbutton_strip usage', 'depreciated'); |
||
|
0 ignored issues
–
show
The type
ElkArte\Errors\Errors was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 310 | |||
| 311 | $buttons = []; |
||
| 312 | |||
| 313 | foreach ($strip as $key => $value) |
||
| 314 | { |
||
| 315 | if (!empty($value['checkbox']) && (!empty($options['display_quick_mod']) || $value['checkbox'] === 'always')) |
||
| 316 | { |
||
| 317 | $buttons[] = ' |
||
| 318 | <li class="listlevel1 ' . $key . '"> |
||
| 319 | <input class="input_check ' . $key . '_check" type="checkbox" name="' . $value['name'] . '[]" value="' . $value['value'] . '" /> |
||
| 320 | </li>'; |
||
| 321 | |||
| 322 | continue; |
||
| 323 | } |
||
| 324 | |||
| 325 | // No special permission needed, or you have valid permission, then get a button! |
||
| 326 | if (!isset($value['test']) || !empty($tests[$value['test']])) |
||
| 327 | { |
||
| 328 | if (!empty($value['override'])) |
||
| 329 | { |
||
| 330 | $buttons[] = $value['override']; |
||
| 331 | continue; |
||
| 332 | } |
||
| 333 | |||
| 334 | $buttons[] = ' |
||
| 335 | <li class="listlevel1"> |
||
| 336 | <a href="' . $value['href'] . '" class="linklevel1 ' . $key . '_button"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '>' . $value['text'] . '</a> |
||
| 337 | </li>'; |
||
| 338 | } |
||
| 339 | } |
||
| 340 | |||
| 341 | // No buttons? No button strip either. |
||
| 342 | if (!empty($buttons)) |
||
| 343 | { |
||
| 344 | echo ' |
||
| 345 | <ul class="quickbuttons">', implode(' |
||
| 346 | ', $buttons), ' |
||
| 347 | </ul>'; |
||
| 348 | } |
||
| 349 | } |
||
| 350 |