diff --git a/LICENSE b/LICENSE deleted file mode 100644 index d2857bf..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013-2016, Mikaël Capelle. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index 7952134..0000000 --- a/README.md +++ /dev/null @@ -1,61 +0,0 @@ -CakePHP 2.x Helpers for Bootstrap 3 -=================================== - -CakePHP Helpers to generate HTML with @Twitter Boostrap 3 style. - -**Warning:** Works only with CakePHP 2.x! - -Looking for CakePHP 3.0 helpers? Check it out! https://github.com/Holt59/cakephp3-bootstrap3-helpers - -Do not hesitate to... - - **Post a github issue** if you find a bug or want a new feature. - - **Send me a message** if you have troubles installing or using the plugin. - -Installation -============ - -Simply Clone the repository in your `app/Plugin/Bootstrap3` folder and add the following to your `app/Config/bootstrap.php`: - -```php -CakePlugin::load('Bootstrap3') ; -``` - -How to use? -=========== - -Just load the helpers in you controller: -```php -public $helpers = array( - 'Html' => array( - 'className' => 'Bootstrap3.BootstrapHtml' - ), - 'Form' => array( - 'className' => 'Bootstrap3.BootstrapForm' - ), - 'Modal' => array( - 'className' => 'Bootstrap3.BootstrapModal' - ) -); -``` - -Documentation -============= - -Current documentation available on the CakePHP 3.0 helpers repository: https://github.com/Holt59/cakephp3-bootstrap3-helpers - -**Note:** If you are using an old PHP version, you must change `[]` to `array()`. - -**Warning:** The `BootstrapFormHelper` configuration is not available for the CakePHP 2.x helpers. - -Copyright and license -===================== - -The MIT License (MIT) - -Copyright (c) 2013-2017, Mikaël Capelle. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -See LICENSE. diff --git a/View/Helper/BootstrapFormHelper.php b/View/Helper/BootstrapFormHelper.php deleted file mode 100644 index b2f8265..0000000 --- a/View/Helper/BootstrapFormHelper.php +++ /dev/null @@ -1,495 +0,0 @@ -addClass($options, 'btn btn-default') ; - - if (isset($options['bootstrap-type']) && in_array($options['bootstrap-type'], $this->buttonTypes)){ - $options = $this->addClass($options, 'btn-'.$options['bootstrap-type']) ; - } - - if (isset($options['bootstrap-size']) && in_array($options['bootstrap-size'], $this->buttonSizes)){ - $options = $this->addClass($options, 'btn-'.$options['bootstrap-size']) ; - } - - unset($options['bootstrap-size']) ; - unset($options['bootstrap-type']) ; - return $options ; - } - - /** - * - * Try to match the specified HTML code with a button or a input with submit type. - * - * @param $html The HTML code to check - * - * @return true if the HTML code contains a button - * - **/ - protected function _matchButton ($html) { - return strpos($html, 'colSize = array( - 'label' => 2, - 'input' => 6, - 'error' => 4 - ) ; - if (isset($options['cols'])) { - $this->colSize = $options['cols'] ; - unset($options['cols']); - } - $this->horizontal = $this->_extractOption('horizontal', $options, false); - unset($options['horizontal']); - $this->search = $this->_extractOption('search', $options, false) ; - unset($options['search']) ; - $this->inline = $this->_extractOption('inline', $options, false) ; - unset($options['inline']) ; - if ($this->horizontal) { - $options = $this->addClass($options, 'form-horizontal') ; - } - else if ($this->inline) { - $options = $this->addClass($options, 'form-inline') ; - } - if ($this->search) { - $options = $this->addClass($options, 'form-search') ; - } - $options['role'] = 'form' ; - if (!isset($options['inputDefaults']) || !is_array($options['inputDefaults'])) { - $options['inputDefaults'] = array(); - } - $options['inputDefaults'] += array( - 'div' => array( - 'class' => 'form-group' - ) - ) ; - return parent::create($model, $options) ; - } - - /** - * - * Return the col size class for the specified column (label, input or error). - * - **/ - protected function _getColClass($what, $offset = false) { - if ($what == 'offset') { - $what = 'label' ; - $offset = TRUE ; - } - $size = $this->colSize[$what] ; - if ($size) { - return 'col-md-'.($offset ? 'offset-' : '').$size ; - } - return '' ; - } - - /** - * - * Create & return a error message (Twitter Bootstrap like). - * - * The error is wrapped in a tag, with a class - * according to the form type (help-inline or help-block). - * - **/ - public function error($field, $text = null, $options = array()) { - $this->setEntity($field); - $optField = $this->_magicOptions(array()) ; - $options['wrap'] = $this->_extractOption('wrap', $options, 'span') ; - $errorClass = 'help-block' ; - if ($this->horizontal && $optField['type'] != 'checkbox' && $optField['type'] != 'radio') { - $errorClass .= ' '.$this->_getColClass('error') ; - } - $options = $this->addClass($options, $errorClass) ; - return parent::error($field, $text, $options) ; - } - - /** - * - * Create & return a label message (Twitter Boostrap like). - * - **/ - public function label($fieldName = null, $text = null, $options = array()) { - if ($this->currentInputType == 'checkbox') { - if ($text === null) { - if (strpos($fieldName, '.') !== false) { - $fieldElements = explode('.', $fieldName); - $text = array_pop($fieldElements); - } - else { - $text = $fieldName; - } - if (substr($text, -3) === '_id') { - $text = substr($text, 0, -3); - } - $text = __(Inflector::humanize(Inflector::underscore($text))); - } - return $text ; - } - if (!$this->inline) { - $options = $this->addClass($options, 'control-label') ; - } - if ($this->horizontal) { - $options = $this->addClass($options, $this->_getColClass('label')) ; - } - if ($this->inline) { - $options = $this->addClass($options, 'sr-only') ; - } - return parent::label($fieldName, $text, $options) ; - } - - /** - * - * Create & return an input block (Twitter Boostrap Like). - * - * New options: - * - prepend: - * -> string: Add before the input - * -> array: Add elements in array before inputs - * - append: Same as prepend except it add elements after input - * - **/ - public function input($fieldName, $options = array()) { - - $prepend = $this->_extractOption('prepend', $options, null) ; - unset ($options['prepend']) ; - $append = $this->_extractOption('append', $options, null) ; - unset ($options['append']) ; - $before = $this->_extractOption('before', $options, '') ; - $after = $this->_extractOption('after', $options, '') ; - $between = $this->_extractOption('between', $options, '') ; - $label = $this->_extractOption('label', $options, false) ; - $inline = $this->_extractOption('inline', $options, false) ; - unset ($options['inline']) ; - - $this->setEntity($fieldName); - $options = $this->_parseOptions($options) ; - $options['format'] = array('label', 'before', 'input', 'between', 'error', 'after') ; - $this->currentInputType = $options['type'] ; - - $beforeClass = array() ; - $oneLessDiv = FALSE; - - if ($options['type'] == 'checkbox' || $options['type'] == 'radio') { - $before = ''.$before ; - $between = $between.'' ; - $options['format'] = array('before', 'input', 'label', 'between', 'error', 'after') ; - if ($this->horizontal) { - $before = '
' - .($inline ? '' : '
').$before ; - $after = $after.($inline ? '' : '
').'
' ; - } - else if (!$inline && ($options['type'] == 'checkbox' || !$label)) { - $options['div'] = array( - 'class' => $options['type'] - ); - } - if ($options['type'] == 'radio') { - if ($label) { - $before = $this->label($fieldName, $label).($this->horizontal ? '' : '
').$before ; - $after .= $this->horizontal ? '' : '
' ; - } - $options['label'] = FALSE ; - $options['separator'] = ''.($inline ? '' : '
'; - } - - if (!empty($beforeClass)) { - foreach($beforeClass as $bc) { - $before .= '
' ; - if (!$oneLessDiv) { - $after = '
'.$after ; - } - $oneLessDiv = FALSE ; - } - } - $before .= $beforePrepend ; - - $type = $options['type']; - $error = $this->_extractOption('error', $options, null); - if ($type !== 'hidden' - && $error !== false - && $this->error($fieldName, $error)) { - $options['div'] = $this->addClass($this->_inputDefaults['div'], 'has-error'); - } - - $options['before'] = $before ; - $options['after'] = $after ; - $options['between'] = $between ; - - if (!in_array($options['type'], array('checkbox', 'radio', 'file'))) { - $options = $this->addClass($options, 'form-control') ; - } - - return parent::input($fieldName, $options) ; - } - - /** - * - * Create & return a Twitter Like button. - * - * New options: - * - bootstrap-type: Twitter bootstrap button type (primary, danger, info, etc.) - * - bootstrap-size: Twitter bootstrap button size (mini, small, large) - * - **/ - public function button($title, $options = array()) { - $options = $this->_addButtonClasses($options) ; - $options['type'] = FALSE ; - return parent::button($title, $options) ; - } - - /** - * - * Create & return a Twitter Like button group. - * - * @param $buttons The buttons in the group - * @param $options Options for div method - * - * Extra options: - * - vertical true/false - * - **/ - public function buttonGroup ($buttons, $options = array()) { - $vertical = $this->_extractOption('vertical', $options, false) ; - unset($options['vertical']) ; - $options = $this->addClass($options, 'btn-group') ; - if ($vertical) { - $options = $this->addClass($options, 'btn-group-vertical') ; - } - return $this->Html->tag('div', implode('', $buttons), $options) ; - } - - /** - * - * Create & return a Twitter Like button toolbar. - * - * @param $buttons The groups in the toolbar - * @param $options Options for div method - * - **/ - public function buttonToolbar ($buttonGroups, $options = array()) { - $options = $this->addClass($options, 'btn-toolbar') ; - return $this->Html->tag('div', implode('', $buttonGroups), $options) ; - } - - /** - * - * Create & return a twitter bootstrap dropdown button. - * - * @param $title The text in the button - * @param $menu HTML tags corresponding to menu options (which will be wrapped - * into
  • tag). To add separator, pass 'divider'. - * @param $options Options for button - * - **/ - public function dropdownButton ($title, $menu = array(), $options = array()) { - - $options['type'] = false ; - $options['data-toggle'] = 'dropdown' ; - $options = $this->addClass($options, "dropdown-toggle") ; - - $outPut = '
    ' ; - $outPut .= $this->button($title.'', $options) ; - $outPut .= '
    ' ; - return $outPut ; - } - - /** - * - * Create & return a Twitter Like submit input. - * - * New options: - * - bootstrap-type: Twitter bootstrap button type (primary, danger, info, etc.) - * - bootstrap-size: Twitter bootstrap button size (mini, small, large) - * - * Unusable options: div - * - **/ - public function submit($caption = null, $options = array()) { - $options = $this->_addButtonClasses($options) ; - if (!isset($options['div'])) { - $options['div'] = false ; - } - if (!$this->horizontal) { - return parent::submit($caption, $options) ; - } - return '
    '.parent::submit($caption, $options).'
    '; - } - - /** - * - * End a form, Twitter Bootstrap like. - * - * New options: - * - bootstrap-type: Twitter bootstrap button type (primary, danger, info, etc.) - * - bootstrap-size: Twitter bootstrap button size (mini, small, large) - * - **/ - public function end ($options = null,$secureAttributes = array()) { - if ($options == null) { - return parent::end($options, $secureAttributes) ; - } - if (is_string($options)) { - $options = array('label' => $options) ; - } - if (!$this->inline) { - if (!array_key_exists('div', $options)) { - $options['div'] = array() ; - } - - if (!isset($options['div']['class'])){ - $options['div']['class'] = ''; - } - - $options['div']['class'] .= ' form-actions' ; - } - return parent::end($options, $secureAttributes) ; - } - - /** SPECIAL FORM **/ - - /** - * - * Create a basic bootstrap search form. - * - * @param $model The model of the form - * @param $options The options that will be pass to the BootstrapForm::create method - * - * Extra options: - * - label: The input label (default false) - * - placeholder: The input placeholder (default "Search... ") - * - button: The search button text (default: "Search") - * - **/ - public function searchForm ($model = null, $options = array()) { - - $label = $this->_extractOption('label', $options, false) ; - unset($options['label']) ; - $placeholder = $this->_extractOption('placeholder', $options, 'Search... ') ; - unset($options['placeholder']) ; - $button = $this->_extractOption('button', $options, 'Search') ; - unset($options['button']) ; - - $output = '' ; - - $output .= $this->create($model, array_merge(array('search' => true, 'inline' => (bool)$label), $options)) ; - $output .= $this->input('search', array( - 'label' => $label, - 'placeholder' => $placeholder, - 'append' => array( - $this->button($button, array('style' => 'vertical-align: middle')) - ) - )) ; - $output .= $this->end() ; - - return $output ; - } - -} - -?> diff --git a/View/Helper/BootstrapHtmlHelper.php b/View/Helper/BootstrapHtmlHelper.php deleted file mode 100644 index a5d3cf5..0000000 --- a/View/Helper/BootstrapHtmlHelper.php +++ /dev/null @@ -1,262 +0,0 @@ -_extractOption($key, $options, $default) ; - if ($default !== false && $type == $default) { - return $default ; - } - if (!in_array($type, $avail)) { - return null ; - } - return $type ; - } - - /** - * - * Create a Twitter Bootstrap icon. - * - * @param $icon The type of the icon (search, pencil, etc.) - * @param $opcions Options for icon - * @param $opcions['tag'] Tag use for the icon, "i" for default - * @param $opcions['font'] Font of the icon: - * "glyphicon" for default Twitter Bootstrap icon. - * "fa" for Font Awesome icon. - * - **/ - public function icon ($icon, array $options = []) { - $tag = empty($options['tag']) ? 'i' : $options['tag']; - $font = 'glyphicon glyphicon-'; - if (!empty($options['font']) and $options['font'] == 'fa') { - $font = 'fa fa-'; - } - unset($options['tag']); - unset($options['font']); - $options['class'] = empty($options['class']) ? ($font . $icon) : ($font . $icon . ' ' . $options['class']); - return $this->tag($tag, '', $options); - } - - /** - * - * Create a Font Awesome icon. - * - * @param $icon The type of the icon (search, pencil, etc.) - * @param $opcions Options for icon - * @param $opcions['tag'] Tag use for the icon, "i" for default - * - **/ - public function faIcon($icon, array $options = []) { - $options['font'] = 'fa'; - return $this->icon($icon, $options); - } - - /** - * - * Create a Twitter Bootstrap span label. - * - * @param text The label text - * @param type The label type (default, primary, success, warning, info, danger) - * @param options Options for span - * - * The second parameter may either be $type or $options (in this case, the third parameter - * is useless, and the label type can be specified in the $options array). - * - * Extra options - * - type The type of the label (useless if $type specified) - * - **/ - public function label ($text, $type = 'default', $options = array()) { - if (is_string($type)) { - $options['type'] = $type ; - } - else if (is_array($type)) { - $options = $type ; - } - $type = $this->_extractType($options, 'type', $default = 'default', - array('default', 'primary', 'success', 'warning', 'info', 'danger')) ; - unset ($options['type']) ; - $options = $this->addClass($options, 'label') ; - $options = $this->addClass($options, 'label-'.$type) ; - return $this->tag('span', $text, $options) ; - } - - /** - * - * Create a Twitter Bootstrap span badge. - * - * @param text The badge text - * @param options Options for span - * - * - **/ - public function badge ($text, $options = array()) { - $options = $this->addClass($options, 'badge') ; - return $this->tag('span', $text, $options) ; - } - - /** - * - * Get crumb lists in a HTML list, with bootstrap like style. - * - * @param $options Options for list - * @param $startText Text to insert before list - * - * Unusable options: - * - Separator - **/ - public function getCrumbList($options = array(), $startText = null) { - $options['separator'] = '' ; - $options = $this->addClass($options, 'breadcrumb') ; - return parent::getCrumbList ($options, $startText) ; - } - - /** - * - * Create a Twitter Bootstrap style alert block, containing text. - * - * @param $text The alert text - * @param $type The type of the alert - * @param $options Options that will be passed to Html::div method - * - * The second parameter may either be $type or $options (in this case, the third parameter - * is useless, and the label type can be specified in the $options array). - * - * Available BootstrapHtml options: - * - type: string, type of alert (default, error, info, success ; useless if - * $type is specified) - * - **/ - public function alert ($text, $type = 'warning', $options = array()) { - if (is_string($type)) { - $options['type'] = $type ; - } - else if (is_array($type)) { - $options = $type ; - } - $button = '' ; - $type = $this->_extractType($options, 'type', 'warning', array('info', 'warning', 'success', 'danger')) ; - unset($options['type']) ; - $options = $this->addClass($options, 'alert') ; - if ($type) { - $options = $this->addClass($options, 'alert-'.$type) ; - } - $class = $options['class'] ; - unset($options['class']) ; - return $this->div($class, $button.$text, $options) ; - } - - /** - * - * Create a Twitter Bootstrap style progress bar. - * - * @param $widths - * - The width (in %) of the bar (style primary, without display) - * - An array of bar, with (for each bar) : - * - width (only field required) - * - type (primary, info, danger, success, warning, default is primary) - * - min (integer, default 0) - * - max (integer, default 100) - * - display (boolean, default false, for text display) - * @param $options Options that will be passed to Html::div method (only for main div) - * - * If $widths is only a integer (first case), $options may contains value for the fields - * specified above. - * - * Available BootstrapHtml options: - * - striped: boolean, specify if progress bar should be striped - * - active: boolean, specify if progress bar should be active - * - **/ - public function progress ($widths, $options = array()) { - $striped = $this->_extractOption('striped', $options, false) ; - unset($options['striped']) ; - $active = $this->_extractOption('active', $options, false) ; - unset($options['active']) ; - $bars = '' ; - if (is_array($widths)) { - foreach ($widths as $w) { - $type = $this->_extractType($w, 'type', 'primary', array('info', 'primary', 'success', 'warning', 'danger')) ; - $class = 'progress-bar progress-bar-'.$type ; - $min = $this->_extractOption('min', $w, 0); - $max = $this->_extractOption('max', $w, 100); - $display = $this->_extractOption('display', $w, false); - $bars .= $this->div($class, $display ? $w['width'].'%' : '', array( - 'aria-valuenow' => $w['width'], - 'aria-valuemin' => $min, - 'aria-valuemax' => $max, - 'role' => 'progressbar', - 'style' => 'width: '.$w['width'].'%;' - )) ; - } - } - else { - $type = $this->_extractType($options, 'type', 'primary', array('info', 'primary', 'success', 'warning', 'danger')) ; - unset($options['type']) ; - $class = 'progress-bar progress-bar-'.$type ; - $min = $this->_extractOption('min', $options, 0); - unset ($options['min']) ; - $max = $this->_extractOption('max', $options, 100); - unset ($options['max']) ; - $display = $this->_extractOption('display', $options, false); - unset ($options['display']) ; - $bars = $this->div($class, $display ? $widths.'%' : '', array( - 'aria-valuenow' => $widths, - 'aria-valuemin' => $min, - 'aria-valuemax' => $max, - 'role' => 'progressbar', - 'style' => 'width: '.$widths.'%;' - )) ; - } - $options = $this->addClass($options, 'progress') ; - if ($active) { - $options = $this->addClass($options, 'active') ; - } - if ($striped) { - $options = $this->addClass($options, 'progress-striped') ; - } - $classes = $options['class']; - unset($options['class']) ; - return $this->div($classes, $bars, $options) ; - } - -} - -?> diff --git a/View/Helper/BootstrapModalHelper.php b/View/Helper/BootstrapModalHelper.php deleted file mode 100644 index 845a4b5..0000000 --- a/View/Helper/BootstrapModalHelper.php +++ /dev/null @@ -1,219 +0,0 @@ -_extractOption('close', $options, true); - unset ($options['close']) ; - $nobody = $this->_extractOption('no-body', $options, false); - unset ($options['no-body']) ; - $options['tabindex'] = $this->_extractOption('tabindex', $options, -1); - $options['role'] = $this->_extractOption('role', $options, 'dialog'); - $options['aria-hidden'] = $this->_extractOption('aria-hidden', $options, 'true'); - if (isset($options['id'])) { - $this->currentId = $options['id'] ; - $options['aria-labbeledby'] = $this->currentId.'Label' ; - } - if (isset($options['size'])) { - if($options['size'] == 'large'){$size = ' modal-lg';} - if($options['size'] == 'small'){$size = ' modal-sm';} - } else { - $size = null; //default size modal - } - unset($options['size']); - - $res = $this->Html->div('modal fade', NULL, $options).$this->Html->div('modal-dialog' . $size).$this->Html->div('modal-content'); - if (is_string($title) && $title) { - $res .= $this->_createheader($title, array('close' => $close)) ; - if (!$nobody) { - $res .= $this->_startpart('body'); - } - } - return $res ; - } - - /** - * - * End a modal. If $buttons is not null, the ModalHelper::footer functions is called with $buttons and $options arguments. - * - * @param array|null $buttons - * @param array $options - * - **/ - public function end ($buttons = NULL, $options = array()) { - $res = '' ; - if ($this->current != NULL) { - $this->current = NULL ; - $res .= $this->_endpart(); - } - if ($buttons !== NULL) { - $res .= $this->footer($buttons, $options) ; - } - $res .= '' ; - return $res ; - } - - private function _cleancurrent () { - if ($this->current) { - $this->current = NULL ; - return $this->_endpart(); - } - return '' ; - } - - protected function _createheader ($title, $options = array()) { - $close = $this->_extractOption('close', $options, true); - unset($options['close']) ; - if ($close) { - $button = '' ; - } - else { - $button = '' ; - } - return $this->_cleancurrent().$this->Html->div('modal-header', $button.$this->Html->tag('h4', $title, array('class' => 'modal-title', 'id' => $this->currentId ? $this->currentId.'Label' : false)), $options) ; - } - - protected function _createbody ($text, $options = array()) { - return $this->_cleancurrent().$this->Html->div('modal-body', $text, $options) ; - } - - protected function _createfooter ($buttons = NULL, $options = array()) { - if ($buttons == NULL) { - $close = $this->_extractOption('close', $options, true); - unset($options['close']) ; - if ($close) { - $buttons = '' ; - } - else { - $buttons = '' ; - } - } - return $this->_cleancurrent().$this->Html->div('modal-footer', $buttons, $options) ; - } - - protected function _startpart ($part, $options = array()) { - $res = '' ; - if ($this->current != NULL) { - $res = $this->_endpart () ; - } - $this->current = $part ; - return $res.$this->Html->div('modal-'.$part, NULL, $options) ; - } - - protected function _endpart () { - return '' ; - } - - /** - * - * Create / Start the header. If $info is specified as a string, create and return the whole header, otherwize only open the header. - * - * @param array|string $info If string, use as the modal title, otherwize works as $options. - * @param array $options Options for the header div. - * - * Special option (if $info is string): - * - close: Add the 'close' button in the header (default true). - * - **/ - public function header ($info = NULL, $options = array()) { - if (is_string($info)) { - return $this->_createheader($info, $options) ; - } - return $this->_startpart('header', is_array($info) ? $info : $options) ; - } - - /** - * - * Create / Start the body. If $info is not null, it is used as the body content, otherwize start the body div. - * - * @param array|string $info If string, use as the body content, otherwize works as $options. - * @param array $options Options for the footer div. - * - * - **/ - public function body ($info = NULL, $options = array()) { - if (is_string($info)) { - if ($this->current != NULL) { - $this->_endpart() ; - } - return $this->_createbody($info, $options) ; - } - return $this->_startpart('body', is_array($info) ? $info : $options) ; - } - - protected function _isAssociativeArray ($array) { - return array_keys($array) !== range(0, count($array) - 1); - } - - /** - * - * Create / Start the footer. If $buttons is specified as an associative arrays or as null, start the footer, otherwize create the footer with the specified buttons. - * - * @param array|string $buttons If string, use as the footer content, if list, concatenate values in the list as content (use for buttons purpose), otherwize works as $options. - * @param array $options Options for the footer div. - * - * Special option (if $buttons is NOT NULL but empty): - * - close: Add the 'close' button to the footer (default true). - * - **/ - public function footer ($buttons = array(), $options = array()) { - if ($buttons === NULL || (!empty($buttons) && $this->_isAssociativeArray($buttons))) { - return $this->_startpart('footer', $buttons === NULL ? $options : $buttons) ; - } - if (empty($buttons)) { - return $this->_createfooter(NULL, $options) ; - } - return $this->_createfooter(is_string($buttons) ? $buttons : implode('', $buttons), $options) ; - } - -} - -?> diff --git a/View/Helper/BootstrapNavbarHelper.php b/View/Helper/BootstrapNavbarHelper.php deleted file mode 100644 index c0082b3..0000000 --- a/View/Helper/BootstrapNavbarHelper.php +++ /dev/null @@ -1,515 +0,0 @@ - '', 'url' => '', 'menu' => array()). **/ - private $currentMenu = null ; - /** Same but for hover menu. **/ - private $currentSubMenu = null ; - - private $brand = null ; - private $navs = array () ; - - /** - * - * Create a new navbar. - * - * @param options Options passed to tag method for outer navbar div - * - * Extra options: - * - fixed: false, 'top', 'bottom' - * - static: false, true (useless if fixed != false) - * - responsive: false, true - * - inverse: false, true - * - fluid: false, true - * - **/ - public function create ($options = array()) { - $this->fixed = $this->_extractOption('fixed', $options, false) ; - unset($options['fixed']) ; - $this->responsive = $this->_extractOption('responsive', $options, false) ; - unset($options['responsive']) ; - $this->static = $this->_extractOption('static', $options, false) ; - unset($options['static']) ; - $this->inverse = $this->_extractOption('inverse', $options, false) ; - unset($options['inverse']) ; - $this->fluid = $this->_extractOption('fluid', $options, false); - unset($options['fluid']); - $this->options = $options ; - } - - /** - * - * Create the brand link of the navbar. - * - * @param name The brand link text - * @param url The brand link URL (default '/') - * @param collapse true if you want the brand to be collapsed - * with responsive design (default false) - * @param options Options passed to link method - * - **/ - public function brand ($name, $url = '/', $collapse = false, $options = array()) { - $this->brand = array( - 'text' => $name, - 'url' => $url, - 'collapse' => $collapse, - 'options' => $options - ) ; - } - - /** - * - * Functions below accept following options: - * - * - disabled (default false) - * - active (default auto) - * - pull (default auto) - * - **/ - - /** - * - * Add a link to the navbar or to a menu. - * - * @param name The link text - * @param url The link URL - * @param options Options passed to link method (+ extra options, see above) - * - **/ - public function link ($name, $url, $options = array()) { - $value = array( - 'text' => $name, - 'url' => $url - ) ; - $this->_addToCurrent('link', $value, $options) ; - } - - /** - * - * Add a divider to the navbar or to a menu. - * - **/ - public function divider () { - $this->_addToCurrent('divider', array(), array()) ; - } - - /** - * - * Add a text to the navbar or to a menu. - * - * @param text The text message - * @param options Options passed to the tag method (+ extra options, see above) - * - * Extra options: - * - wrap The HTML tag to use (default p) - * - **/ - public function text ($text, $options = array()) { - $tag = $this->_extractOption('wrap', $options, 'p') ; - unset($options['wrap']) ; - $value = array( - 'wrap' => $tag, - 'text' => $text, - ) ; - $this->_addToCurrent('text', $value, $options) ; - } - - /** - * - * Add a HTML block to the navbar. - * - * @param block The HTML block to add - * - * Extra options: - * - list true/false (default true), specify if block should be wrap in a "li" tag, only - * work on main nav (in submenu, block are always wrapped in a li tag) - * - **/ - public function block ($block, $options = array()) { - $list = $this->_extractOption('list', $options, true) ; - unset ($options['list']) ; - $value = array( - 'text' => $block, - 'list' => $list - ) ; - $this->_addToCurrent('block', $value, $options) ; - } - - /** - * - * Add a serach form to the navbar. - * - * @param block The HTML block to add - * @param options - * - * Extra options: - * - form Extra options for BootstrapFormHelper::searchForm options - * - pull left/right (default left) - * - model Model for BootstrapFormHelper::searchForm method - * - **/ - public function searchForm ($options = array()) { - App::import('Helper', 'BootstrapForm') ; - $bootFormHelper = new BootstrapFormHelper($this->_View); - $formOptions = $this->_extractOption('form', $options, array()) ; - unset($formOptions['form']) ; - $pull = $this->_extractOption('pull', $options, 'left') ; - unset($options['pull']) ; - $model = $this->_extractOption('model', $options, null) ; - unset($options['model']) ; - $formOptions = $this->addClass($formOptions, 'navbar-form pull-'.$pull) ; - $this->block($bootFormHelper->searchForm($model, $formOptions), array('list' => false)) ; - } - - /** - * - * Start a new menu, 2 levels: If not in submenu, create a dropdown menu, - * oterwize create hover menu. - * - * @param name The name of the menu - * @param url A URL for the menu (default null) - * @param options Options passed to the tag method (+ extra options, see above) - * - **/ - public function beginMenu ($name, $url = null, $options = array()) { - $default = array( - 'type' => 'menu', - 'text' => $name, - 'url' => $url, - 'menu' => array() - ) ; - $value = array_merge($this->_extractValue($options), $default) ; - if ($this->currentMenu === null) { - $this->currentMenu = $value ; - } - else if ($this->currentSubMenu === null) { - $value['type'] = 'smenu' ; - $this->currentSubMenu = $value ; - } - } - - /** - * - * End a menu. - * - **/ - public function endMenu () { - if ($this->currentSubMenu !== null) { - $this->currentMenu['menu'][] = $this->currentSubMenu ; - $this->currentSubMenu = null ; - } - else if ($this->currentMenu !== null) { - $this->navs[] = $this->currentMenu ; - $this->currentMenu = null ; - } - } - - /** - * - * End a navbar. - * - * @param compile If true, compile the navbar and return - * - **/ - public function end ($compile = false) { - - if ($compile) { - return $this->compile () ; - } - } - - /** - * - * Compile a navigation block. - * - * @param nav Array (type, active, pull, disabled, options, ...) - * - * @return array( - * inner => Inner HTML for li tag - * class => Extra class for li tag - * active => Active element - * disabled => disabled element - * ) - * - **/ - private function __compileNavBlock ($nav) { - $inner = '' ; - $class = '' ; - switch ($nav['type']) { - case 'text': - $nav['options'] = $this->addClass($nav['options'], 'navbar-text') ; - $inner = $this->Html->tag($nav['wrap'], $nav['text'], $nav['options']) ; - break ; - case 'link': - $active = $nav['active'] === 'auto' ? - Router::url() === Router::normalize($nav['url']) : $nav['active'] ; - $disabled = $nav['disabled'] ; - $inner = $this->Html->link($nav['text'], $nav['url'], $nav['options']) ; - break ; - case 'menu': - case 'smenu': - $res = $this->compileMenu($nav) ; - $inner = $res['inner'] ; - $active = $nav['active'] === 'auto' ? $res['active'] : $nav['active'] ; - $disabled = $nav['disabled'] ; - $class = $res['class']; - break ; - case 'block': - $inner = $nav['text'] ; - break ; - case 'divider': - $class = 'divider' ; - break ; - } - return array( - 'inner' => $inner, - 'class' => $class, - 'active' => isset($active) && $active, - 'disabled' => isset($disabled) && $disabled - ) ; - } - - /** - * - * Compile a menu. - * - * @param menu array(type, pull, url, text, menu) - * - * @return array( - * inner => Inner HTML for li tag - * class => Extra class for li tag - * active => Active element - * disabled => disabled element - * ) - * - **/ - private function compileMenu ($menu) { - if ($menu['type'] === 'menu') { - $button = $this->Html->link($menu['text'].'', $menu['url'] ? $menu['url'] : '#', array( - 'class' => 'dropdown-toggle', - 'data-toggle' => 'dropdown', - 'escape' => false - )) ; - } - else { - $button = $this->Html->link($menu['text'], $menu['url'] ? $menu['url'] : '#', array( - 'tabindex' => -1 - )) ; - } - $active = false ; - $link = array() ; - foreach ($menu['menu'] as $m) { - $res = $this->__compileNavBlock($m) ; - if ($res['active']) { - $active = true ; - $res = $this->addClass($res, 'active') ; - } - $link[] = $this->Html->tag('li', $res['inner'], $res['class'] ? array('class' => $res['class']) : array()) ; - } - $list = $this->Html->tag('ul', implode('', $link), array( - 'class' => 'dropdown-menu' - )) ; - $class = ($menu['type'] === 'menu') ? 'dropdown' : 'dropdown-submenu' ; - if ($menu['pull'] !== 'auto') { - $class .= ' pull-'.$menu['pull'] ; - } - return array( - 'active' => $active, - 'inner' => $button.$list, - 'class' => $class, - 'disabled' => $menu['disabled'] - ) ; - } - - /** - * - * Compile and returns the current navbar. - * - * @return The navbar (HTML string) - * - **/ - public function compile () { - $htmls = array() ; - $ul = false ; - foreach ($this->navs as $nav) { - /* Extra check for block... */ - if ($nav['type'] === 'block' && $nav['list'] === false) { - if ($ul) { - $htmls[] = '' ; - $ul = false ; - } - $htmls[] = $nav['text'] ; - continue ; - } - if ($ul && $nav['pull'] != 'auto' && $nav['pull'] != $ul) { - $htmls[] = '' ; - $ul = false ; - } - if (!$ul && $nav['pull'] === 'auto') { - $ul = 'left' ; - $htmls[] = '