/** * Render Buttons * * @param $buttons array * @param $options Array * @return String */ static function renderButtons($buttons, $options = array()) { $renderedButtons = ''; $groupclass = array(); if (isset($options['class'])) { if (!is_array($options['class'])) { $options['class'] = explode(' ', $options['class']); } $groupclass = $options['class']; } $currentwrapperclass = ''; // set wrapper $wrapper = 'div'; if (isset($options['wrapper'])) { $wrapper = $options['wrapper']; } foreach ($buttons as $button) { $btnoptions = array(); // set classes for specific button // explicit classes for the specific line? if (isset($button['class'])) { $button['class'] = explode(' ', $button['class']); } else { $button['class'] = $groupclass; } foreach ($button['class'] as $btnclass) { if (strpos($btnclass, 'btn') === 0) { $button['class'][] = 'btn'; break; } } // set wrapper class if (isset($options['wrapperclass'])) { $wrapperclass = $options['wrapperclass']; } else { if (in_array('btn', $button['class']) === false) { $wrapperclass = 'dropdown'; } else { $wrapperclass = 'btn-group'; } } $button['class'] = implode(' ', array_unique($button['class'])); // if aria-attributes are set, add them if (isset($options['aria-controls'])) { $button['aria-controls'] = $options['aria-controls']; } if (isset($options['aria-expanded'])) { $button['aria-expanded'] = $options['aria-expanded']; } // if data-target attribute is set, add it if (isset($options['data-target'])) { $button['data-target'] = $options['data-target']; } // if data-dismiss attribute is set, add it if (isset($options['data-dismiss'])) { $button['data-dismiss'] = $options['data-dismiss']; } // if data-placement attribute is set, add it if (isset($options['data-placement'])) { $button['data-placement'] = $options['data-placement']; } // if title attribute is set, add it if (isset($options['title'])) { $button['title'] = $options['title']; } // if data-toggle attribute is set, unset wrapper and add attribute and toggle-class if (isset($options['data-toggle'])) { $wrapper = ''; $button['data-toggle'] = $options['data-toggle']; $button['class'] .= ' ' . $options['data-toggle'] . '-toggle'; } // if html is not set, use text and sanitize it if (!isset($button['html'])) { $button['html'] = htmlspecialchars($button['text']); } // if fa attribute is set, add fa-icon to buttons if (isset($options['fa'])) { $button['html'] = '<span class="fa fa-' . $options['fa'] . '"></span> ' . $button['html']; } // if glyphicon or icon attribute is set, add icon to buttons if (isset($options['icon'])) { $options['glyphicon'] = $options['icon']; } if (isset($options['glyphicon'])) { $button['html'] = '<span class="glyphicon glyphicon-' . $options['glyphicon'] . '"></span> ' . $button['html']; } // render wrapper if (($currentwrapperclass != $wrapperclass || isset($button['items'])) && $wrapper != '' || $wrapper == 'li') { if ($currentwrapperclass != '') { $renderedButtons .= '</' . $wrapper . '>'; } $renderedButtons .= '<' . $wrapper . ' class="' . $wrapperclass; if (isset($button['active']) && $button['active'] === true) { $renderedButtons .= ' active'; } if (isset($options['wrapperid'])) { $renderedButtons .= '" id="' . $options['wrapperid']; } $renderedButtons .= '">'; $currentwrapperclass = $wrapperclass; } // dropdown if (isset($button['items'])) { if (isset($options['dropdownclass'])) { $renderedButtons .= TweekiHooks::buildDropdown($button, $options['dropdownclass']); } else { $renderedButtons .= TweekiHooks::buildDropdown($button); } } else { $renderedButtons .= TweekiHooks::makeLink($button, $btnoptions); } } // close wrapper if ($wrapper != '') { $renderedButtons .= '</' . $wrapper . '>'; } return $renderedButtons; }