/helpers/TbHtml.php
PHP | 4045 lines | 2135 code | 299 blank | 1611 comment | 170 complexity | 7a768193a813c7bfa641c9e22a52ab50 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * TbHtml class file.
- * @author Antonio Ramirez <ramirez.cobos@gmail.com>
- * @author Christoffer Niska <christoffer.niska@gmail.com>
- * @copyright Copyright © Christoffer Niska 2013-
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @package bootstrap.helpers
- */
-
- /**
- * Bootstrap HTML helper.
- */
- class TbHtml extends CHtml // required in order to access protected methods
- {
- // Floats.
- const PULL_LEFT = 'left';
- const PULL_RIGHT = 'right';
-
- // Text alignments.
- const ALIGN_LEFT = 'left';
- const ALIGN_CENTER = 'center';
- const ALIGN_RIGHT = 'right';
-
- // Element colors.
- const COLOR_DEFAULT = '';
- const COLOR_PRIMARY = 'primary';
- const COLOR_INFO = 'info';
- const COLOR_SUCCESS = 'success';
- const COLOR_WARNING = 'warning';
- const COLOR_ERROR = 'error';
- const COLOR_DANGER = 'danger';
- const COLOR_IMPORTANT = 'important';
- const COLOR_INVERSE = 'inverse';
- const COLOR_LINK = 'link';
-
- // Element sizes.
- const SIZE_MINI = 'mini';
- const SIZE_SMALL = 'small';
- const SIZE_DEFAULT = '';
- const SIZE_MEDIUM = 'medium';
- const SIZE_LARGE = 'large';
- const SIZE_XLARGE = 'xlarge';
- const SIZE_XXLARGE = 'xxlarge';
-
- const BUTTON_LINK = 'link';
- const BUTTON_HTML = 'htmlButton';
- const BUTTON_SUBMIT = 'submitButton';
- const BUTTON_RESET = 'resetButton';
- const BUTTON_IMAGE = 'imageButton';
- const BUTTON_LINKBUTTON = 'linkButton';
- const BUTTON_AJAXLINK = 'ajaxLink';
- const BUTTON_AJAXBUTTON = 'ajaxButton';
- const BUTTON_INPUTBUTTON = 'inputButton';
- const BUTTON_INPUTSUBMIT = 'inputSubmit';
-
- // Menu types.
- const NAV_TABS = 'tabs';
- const NAV_PILLS = 'pills';
- const NAV_LIST = 'list';
-
- // Navbar positions.
- const NAVBAR_INLINE = '';
- const NAVBAR_FIXED_TOP = 'fixed-top';
- const NAVBAR_FIXED_BOTTOM = 'fixed-bottom';
- const NAVBAR_STATIC_TOP = 'static-top';
-
- // Image types.
- const IMAGE_ROUNDED = 'rounded';
- const IMAGE_CIRCLE = 'circle';
- const IMAGE_POLAROID = 'polaroid';
-
- // Progress bar types.
- const PROGRESS_LEFT = 'left';
- const PROGRESS_CENTER = 'centered';
- const PROGRESS_RIGHT = 'right';
- const PROGRESS_STRIPED = 'striped';
- const PROGRESS_ACTIVE = 'active';
-
- // Tooltip placements.
- const TOOLTIP_TOP = 'top';
- const TOOLTIP_BOTTOM = 'bottom';
- const TOOLTIP_LEFT = 'left';
- const TOOLTIP_RIGHT = 'right';
-
- // Tab placements.
- const TABS_ABOVE = '';
- const TABS_BELOW = 'below';
- const TABS_LEFT = 'left';
- const TABS_RIGHT = 'right';
-
- // Affix offset types.
- const AFFIX_TOP = 'top';
- const AFFIX_BOTTOM = 'bottom';
-
- // Tooltip triggers.
- const TRIGGER_CLICK = 'click';
- const TRIGGER_HOVER = 'hover';
- const TRIGGER_FOCUS = 'focus';
- const TRIGGER_MANUAL = 'manual';
-
- // Addon types.
- const ADDON_PREPEND = 'prepend';
- const ADDON_APPEND = 'append';
-
- // Help types.
- const HELP_INLINE = 'inline';
- const HELP_BLOCK = 'block';
-
- // Form layouts.
- const FORM_VERTICAL = 'vertical';
- const FORM_HORIZONTAL = 'horizontal';
- const FORM_INLINE = 'inline';
- const FORM_SEARCH = 'search';
-
- // Input types.
- const INPUT_URL = 'urlField';
- const INPUT_EMAIL = 'emailField';
- const INPUT_NUMBER = 'numberField';
- const INPUT_RANGE = 'rangeField';
- const INPUT_DATE = 'dateField';
- const INPUT_TEXT = 'textField';
- const INPUT_PASSWORD = 'passwordField';
- const INPUT_TEXTAREA = 'textArea';
- const INPUT_FILE = 'fileField';
- const INPUT_RADIOBUTTON = 'radioButton';
- const INPUT_CHECKBOX = 'checkBox';
- const INPUT_DROPDOWN = 'dropDownList';
- const INPUT_LISTBOX = 'listBox';
- const INPUT_CHECKBOXLIST = 'checkBoxList';
- const INPUT_INLINECHECKBOXLIST = 'inlineCheckBoxList';
- const INPUT_RADIOBUTTONLIST = 'radioButtonList';
- const INPUT_INLINERADIOBUTTONLIST = 'inlineRadioButtonList';
- const INPUT_UNEDITABLE = 'uneditableField';
- const INPUT_SEARCH = 'searchQuery';
-
- // grid types.
- const GRID_STRIPED = 'striped';
- const GRID_BORDERED = 'bordered';
- const GRID_CONDENSED = 'condensed';
- const GRID_HOVER = 'hover';
-
- // Icon types.
- const ICON_GLASS = 'icon-glass';
- const ICON_MUSIC = 'icon-music';
- const ICON_SEARCH = 'icon-search';
- const ICON_ENVELOPE = 'icon-envelope';
- const ICON_HEART = 'icon-heart';
- const ICON_STAR = 'icon-star';
- const ICON_STAR_EMPTY = 'icon-star-empty';
- const ICON_USER = 'icon-user';
- const ICON_FILM = 'icon-film';
- const ICON_TH_LARGE = 'icon-th-large';
- const ICON_TH = 'icon-th';
- const ICON_TH_LIST = 'icon-th-list';
- const ICON_OK = 'icon-ok';
- const ICON_REMOVE = 'icon-remove';
- const ICON_ZOOM_IN = 'icon-zoom-in';
- const ICON_ZOOM_OUT = 'icon-zoom-out';
- const ICON_OFF = 'icon-off';
- const ICON_SIGNAL = 'icon-signal';
- const ICON_COG = 'icon-cog';
- const ICON_TRASH = 'icon-trash';
- const ICON_HOME = 'icon-home';
- const ICON_FILE = 'icon-file';
- const ICON_TIME = 'icon-time';
- const ICON_ROAD = 'icon-road';
- const ICON_DOWNLOAD_ALT = 'icon-download-alt';
- const ICON_DOWNLOAD = 'icon-download';
- const ICON_UPLOAD = 'icon-upload';
- const ICON_INBOX = 'icon-inbox';
- const ICON_PLAY_CIRCLE = 'icon-play-circle';
- const ICON_REPEAT = 'icon-repeat';
- const ICON_REFRESH = 'icon-refresh';
- const ICON_LIST_ALT = 'icon-list-alt';
- const ICON_LOCK = 'icon-lock';
- const ICON_FLAG = 'icon-flag';
- const ICON_HEADPHONES = 'icon-headphones';
- const ICON_VOLUME_OFF = 'icon-volume-off';
- const ICON_VOLUME_DOWN = 'icon-volume-down';
- const ICON_VOLUME_UP = 'icon-volume-up';
- const ICON_QRCODE = 'icon-qrcode';
- const ICON_BARCODE = 'icon-barcode';
- const ICON_TAG = 'icon-tag';
- const ICON_TAGS = 'icon-tags';
- const ICON_BOOK = 'icon-book';
- const ICON_BOOKMARK = 'icon-bookmark';
- const ICON_PRINT = 'icon-print';
- const ICON_CAMERA = 'icon-camera';
- const ICON_FONT = 'icon-font';
- const ICON_BOLD = 'icon-bold';
- const ICON_ITALIC = 'icon-italic';
- const ICON_TEXT_HEIGHT = 'icon-text-height';
- const ICON_TEXT_WIDTH = 'icon-text-width';
- const ICON_ALIGN_LEFT = 'icon-align-left';
- const ICON_ALIGN_CENTER = 'icon-align-center';
- const ICON_ALIGN_RIGHT = 'icon-align-right';
- const ICON_ALIGN_JUSTIFY = 'icon-align-justify';
- const ICON_LIST = 'icon-list';
- const ICON_INDENT_LEFT = 'icon-indent-left';
- const ICON_INDENT_RIGHT = 'icon-indent-right';
- const ICON_FACETIME_VIDEO = 'icon-facetime-video';
- const ICON_PICTURE = 'icon-picture';
- const ICON_PENCIL = 'icon-pencil';
- const ICON_MAP_MARKER = 'icon-map-marker';
- const ICON_ADJUST = 'icon-adjust';
- const ICON_TINT = 'icon-tint';
- const ICON_EDIT = 'icon-edit';
- const ICON_SHARE = 'icon-share';
- const ICON_CHECK = 'icon-check';
- const ICON_MOVE = 'icon-move';
- const ICON_STEP_BACKWARD = 'icon-step-backward';
- const ICON_FAST_BACKWARD = 'icon-fast-backward';
- const ICON_BACKWARD = 'icon-backward';
- const ICON_PLAY = 'icon-play';
- const ICON_PAUSE = 'icon-pause';
- const ICON_STOP = 'icon-pause';
- const ICON_FORWARD = 'icon-forward';
- const ICON_FAST_FORWARD = 'icon-fast-forward';
- const ICON_STEP_FORWARD = 'icon-step-forward';
- const ICON_EJECT = 'icon-eject';
- const ICON_CHEVRON_LEFT = 'icon-chevron-left';
- const ICON_CHEVRON_RIGHT = 'icon-chevron-right';
- const ICON_PLUS_SIGN = 'icon-plus-sign';
- const ICON_MINUS_SIGN = 'icon-minus-sign';
- const ICON_REMOVE_SIGN = 'icon-remove-sign';
- const ICON_OK_SIGN = 'icon-ok-sign';
- const ICON_QUESTION_SIGN = 'icon-question-sign';
- const ICON_INFO_SIGN = 'icon-info-sign';
- const ICON_SCREENSHOT = 'icon-screenshot';
- const ICON_REMOVE_CIRCLE = 'icon-remove-circle';
- const ICON_OK_CIRCLE = 'icon-ok-circle';
- const ICON_BAN_CIRCLE = 'icon-ban-circle';
- const ICON_ARROW_LEFT = 'icon-arrow-left';
- const ICON_ARROW_RIGHT = 'icon-arrow-right';
- const ICON_ARROW_UP = 'icon-arrow-up';
- const ICON_ARROW_DOWN = 'icon-arrow-down';
- const ICON_SHARE_ALT = 'icon-share-alt';
- const ICON_RESIZE_FULL = 'icon-resize-full';
- const ICON_RESIZE_SMALL = 'icon-resize-small';
- const ICON_PLUS = 'icon-plus';
- const ICON_MINUS = 'icon-minus';
- const ICON_ASTERISK = 'icon-asterisk';
- const ICON_EXCLAMATION_SIGN = 'icon-exclamation-sign';
- const ICON_GIFT = 'icon-gift';
- const ICON_LEAF = 'icon-leaf';
- const ICON_FIRE = 'icon-fire';
- const ICON_EYE_OPEN = 'icon-eye-open';
- const ICON_EYE_CLOSE = 'icon-eye-close';
- const ICON_WARNING_SIGN = 'icon-warning-sign';
- const ICON_PLANE = 'icon-plane';
- const ICON_CALENDAR = 'icon-calendar';
- const ICON_RANDOM = 'icon-random';
- const ICON_COMMENT = 'icon-comment';
- const ICON_MAGNET = 'icon-magnet';
- const ICON_CHEVRON_UP = 'icon-chevron-up';
- const ICON_CHEVRON_DOWN = 'icon-chevron-down';
- const ICON_RETWEET = 'icon-retweet';
- const ICON_SHOPPING_CART = 'icon-shopping-cart';
- const ICON_FOLDER_CLOSE = 'icon-folder-close';
- const ICON_FOLDER_OPEN = 'icon-folder-open';
- const ICON_RESIZE_VERTICAL = 'icon-resize-vertical';
- const ICON_RESIZE_HORIZONTAL = 'icon-resize-horizontal';
- const ICON_HDD = 'icon-hdd';
- const ICON_BULLHORN = 'icon-bullhorn';
- const ICON_BELL = 'icon-bell';
- const ICON_CERTFICATE = 'icon-certificate';
- const ICON_THUMBS_UP = 'icon-thumbs-up';
- const ICON_THUMBS_DOWN = 'icon-thumbs-down';
- const ICON_HAND_RIGHT = 'icon-hand-right';
- const ICON_HAND_LEFT = 'icon-hand-left';
- const ICON_HAND_UP = 'icon-hand-up';
- const ICON_HAND_DOWN = 'icon-hand-down';
- const ICON_CIRCLE_ARROW_RIGHT = 'icon-circle-arrow-right';
- const ICON_CIRCLE_ARROW_LEFT = 'icon-circle-arrow-left';
- const ICON_CIRCLE_ARROW_UP = 'icon-circle-arrow-up';
- const ICON_CIRCLE_ARROW_DOWN = 'icon-circle-arrow-down';
- const ICON_GLOBE = 'icon-globe';
- const ICON_WRENCH = 'icon-wrench';
- const ICON_TASKS = 'icon-tasks';
- const ICON_FILTER = 'icon-filter';
- const ICON_BRIEFCASE = 'icon-briefcase';
- const ICON_FULLSCREEN = 'icon-fullscreen';
-
- // Default close text.
- const CLOSE_TEXT = '×';
-
- //
- // BASE CSS
- // --------------------------------------------------
-
- // Typography
- // http://twitter.github.com/bootstrap/base-css.html#typography
- // --------------------------------------------------
-
- /**
- * Generates a paragraph that stands out.
- * @param string $text the lead text.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated paragraph.
- */
- public static function lead($text, $htmlOptions = array())
- {
- $htmlOptions = self::addClassName('lead', $htmlOptions);
- return self::tag('p', $htmlOptions, $text);
- }
-
- /**
- * Generates small text.
- * @param string $text the text to style.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated text.
- */
- public static function small($text, $htmlOptions = array())
- {
- return self::tag('small', $htmlOptions, $text);
- }
-
- /**
- * Generates bold text.
- * @param string $text the text to style.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated text.
- */
- public static function b($text, $htmlOptions = array())
- {
- return self::tag('strong', $htmlOptions, $text);
- }
-
- /**
- * Generates italic text.
- * @param string $text the text to style.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated text.
- */
- public static function i($text, $htmlOptions = array())
- {
- return self::tag('em', $htmlOptions, $text);
- }
-
- /**
- * Generates an emphasized text.
- * @param string $style the text style.
- * @param string $text the text to emphasize.
- * @param array $htmlOptions additional HTML attributes.
- * @param string $tag the HTML tag.
- * @return string the generated text.
- */
- public static function em($style, $text, $htmlOptions = array(), $tag = 'p')
- {
- $htmlOptions = self::addClassName('text-' . $style, $htmlOptions);
- return self::tag($tag, $htmlOptions, $text);
- }
-
- /**
- * Generates a muted text block.
- * @param string $text the text.
- * @param array $htmlOptions additional HTML attributes.
- * @param string $tag the HTML tag.
- * @return string the generated text block.
- */
- public static function muted($text, $htmlOptions = array(), $tag = 'p')
- {
- if (self::popOption('muted', $htmlOptions, false))
- $htmlOptions = self::addClassName('muted', $htmlOptions);
- return self::tag($tag, $htmlOptions, $text);
- }
-
- /**
- * Generates a muted span.
- * @param string $text the text.
- * @param array $htmlOptions additional HTML attributes.
- * @param string $tag the HTML tag.
- * @return string the generated span.
- */
- public static function mutedSpan($text, $htmlOptions = array())
- {
- return self::muted($text, $htmlOptions, 'span');
- }
-
- /**
- * Generates an abbreviation with a help text.
- * @param string $text the abbreviation.
- * @param string $word the word the abbreviation is for.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated abbreviation.
- */
- public static function abbr($text, $word, $htmlOptions = array())
- {
- if (self::popOption('small', $htmlOptions, false))
- $htmlOptions = self::addClassName('initialism', $htmlOptions);
- $htmlOptions['title'] = $word;
- return self::tag('abbr', $htmlOptions, $text);
- }
-
- /**
- * Generates a small abbreviation with a help text.
- * @param string $text the abbreviation.
- * @param string $word the word the abbreviation is for.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated abbreviation.
- */
- public static function smallAbbr($text, $word, $htmlOptions = array())
- {
- $htmlOptions['small'] = true;
- return self::abbr($text, $word, $htmlOptions);
- }
-
- /**
- * Generates an address block.
- * @param string $quote the address text.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated block.
- */
- public static function address($text, $htmlOptions = array())
- {
- return self::tag('address', $htmlOptions, $text);
- }
-
- /**
- * Generates a quote.
- * @param string $text the quoted text.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated quote.
- */
- public static function quote($text, $htmlOptions = array())
- {
- $paragraphOptions = self::popOption('paragraphOptions', $htmlOptions, array());
- $source = self::popOption('source', $htmlOptions);
- $sourceOptions = self::popOption('sourceOptions', $htmlOptions, array());
- $cite = self::popOption('cite', $htmlOptions);
- $citeOptions = self::popOption('citeOptions', $htmlOptions, array());
- $cite = isset($cite) ? self::tag('cite', $citeOptions, $cite) : '';
- $source = isset($source) ? self::tag('small', $sourceOptions, $source . ' ' . $cite) : '';
- $text = self::tag('p', $paragraphOptions, $text) . $source;
- return self::tag('blockquote', $htmlOptions, $text);
- }
-
- /**
- * Generates a help text.
- * @param string $text the help text.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated text.
- */
- public static function help($text, $htmlOptions = array())
- {
- $htmlOptions = self::addClassName('help-inline', $htmlOptions);
- return self::tag('span', $htmlOptions, $text);
- }
-
- /**
- * Generates a help block.
- * @param string $text the help text.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated block.
- */
- public static function helpBlock($text, $htmlOptions = array())
- {
- $htmlOptions = self::addClassName('help-block', $htmlOptions);
- return self::tag('p', $htmlOptions, $text);
- }
-
- // Code
- // http://twitter.github.com/bootstrap/base-css.html#code
- // --------------------------------------------------
-
- /**
- * Generates inline code.
- * @param string $code the code.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated code.
- */
- public static function code($code, $htmlOptions = array())
- {
- return self::tag('code', $htmlOptions, $code);
- }
-
- /**
- * Generates a code block.
- * @param string $code the code.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated block.
- */
- public static function codeBlock($code, $htmlOptions = array())
- {
- return self::tag('pre', $htmlOptions, $code);
- }
-
- /**
- * Generates an HTML element.
- * @param string $tag the tag name.
- * @param array $htmlOptions the element attributes.
- * @param mixed $content the content to be enclosed between open and close element tags.
- * @param boolean $closeTag whether to generate the close tag.
- * @return string the generated HTML element tag.
- */
- public static function tag($tag, $htmlOptions = array(), $content = false, $closeTag = true)
- {
- self::addSpanClass($htmlOptions);
- $align = self::popOption('align', $htmlOptions);
- if (isset($align))
- $htmlOptions = self::addClassName('text-' . $align, $htmlOptions);
- $pull = self::popOption('pull', $htmlOptions);
- if (isset($pull))
- $htmlOptions = self::addClassName('pull-' . $pull, $htmlOptions);
- return CHtml::tag($tag, $htmlOptions, $content, $closeTag);
- }
-
- /**
- * Generates an open HTML element.
- * @param string $tag the tag name.
- * @param array $htmlOptions the element attributes.
- * @return string the generated HTML element tag.
- */
- public static function openTag($tag, $htmlOptions = array())
- {
- return self::tag($tag, $htmlOptions);
- }
-
- // Tables
- // http://twitter.github.com/bootstrap/base-css.html#forms
- // --------------------------------------------------
-
- // todo: create table methods here.
-
- // Forms
- // http://twitter.github.com/bootstrap/base-css.html#tables
- // --------------------------------------------------
-
- /**
- * Generates a form tag.
- * @param string $layout the form layout.
- * @param string $action the form action URL.
- * @param string $method form method (e.g. post, get).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated tag.
- */
- public static function formTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
- {
- return self::beginFormTb($layout, $action, $method, $htmlOptions);
- }
-
- /**
- * Generates an open form tag.
- * @param string $layout the form layout.
- * @param string $action the form action URL.
- * @param string $method form method (e.g. post, get).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated tag.
- */
- public static function beginFormTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
- {
- $htmlOptions = self::addClassName('form-' . $layout, $htmlOptions);
- return CHtml::beginForm($action, $method, $htmlOptions);
- }
-
- /**
- * Generates a stateful form tag.
- * @param mixed $action the form action URL.
- * @param string $method form method (e.g. post, get).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated form tag.
- */
- public static function statefulFormTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
- {
- return self::formTb($layout, $action, $method, $htmlOptions)
- . CHtml::tag('div', array('style' => 'display:none'), CHtml::pageStateField(''));
- }
-
- /**
- * Generates a text field input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input field.
- * @see TbHtml::textInputField
- */
- public static function textField($name, $value = '', $htmlOptions = array())
- {
- return self::textInputField('text', $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a password field input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input field.
- * @see TbHtml::textInputField
- */
- public static function passwordField($name, $value = '', $htmlOptions = array())
- {
- CHtml::clientChange('change', $htmlOptions);
- return self::textInputField('password', $name, $value, $htmlOptions);
- }
-
- /**
- * Generates an url field input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input field.
- * @see TbHtml::textInputField
- */
- public static function urlField($name, $value = '', $htmlOptions = array())
- {
- return self::textInputField('url', $name, $value, $htmlOptions);
- }
-
- /**
- * Generates an email field input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input field.
- * @see TbHtml::textInputField
- */
- public static function emailField($name, $value = '', $htmlOptions = array())
- {
- return self::textInputField('email', $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a number field input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input field.
- * @see TbHtml::textInputField
- */
- public static function numberField($name, $value = '', $htmlOptions = array())
- {
- return self::textInputField('number', $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a range field input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input field.
- * @see TbHtml::textInputField
- */
- public static function rangeField($name, $value = '', $htmlOptions = array())
- {
- return self::textInputField('range', $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a date field input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input field.
- * @see TbHtml::textInputField
- */
- public static function dateField($name, $value = '', $htmlOptions = array())
- {
- return self::textInputField('date', $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a text area input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated text area.
- */
- public static function textArea($name, $value = '', $htmlOptions = array())
- {
- $htmlOptions = self::normalizeInputOptions($htmlOptions);
- return CHtml::textArea($name, $value, $htmlOptions);
- }
-
- /**
- * Generates a radio button.
- * @param string $name the input name.
- * @param boolean $checked whether the radio button is checked.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated radio button.
- */
- public static function radioButton($name, $checked = false, $htmlOptions = array())
- {
- $label = self::popOption('label', $htmlOptions, false);
- $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
- $radioButton = CHtml::radioButton($name, $checked, $htmlOptions);
- if ($label !== false)
- {
- $labelOptions = self::addClassName('radio', $labelOptions);
- ob_start();
- echo self::tag('label', $labelOptions, $radioButton . $label);
- return ob_get_clean();
- }
- else
- return $radioButton;
- }
-
- /**
- * Generates a check box.
- * @param string $name the input name.
- * @param boolean $checked whether the check box is checked.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated check box.
- */
- public static function checkBox($name, $checked = false, $htmlOptions = array())
- {
- $label = self::popOption('label', $htmlOptions, false);
- $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
- $checkBox = CHtml::checkBox($name, $checked, $htmlOptions);
- if ($label !== false)
- {
- $labelOptions = self::addClassName('checkbox', $labelOptions);
- ob_start();
- echo self::tag('label', $labelOptions, $checkBox . $label);
- return ob_get_clean();
- }
- else
- return $checkBox;
- }
-
- /**
- * Generates a drop down list.
- * @param string $name the input name.
- * @param string $select the selected value.
- * @param array $data data for generating the list options (value=>display).
- * @return string the generated drop down list.
- */
- public static function dropDownList($name, $select, $data, $htmlOptions = array())
- {
- $htmlOptions = self::normalizeInputOptions($htmlOptions);
- return CHtml::dropDownList($name, $select, $data, $htmlOptions);
- }
-
- /**
- * Generates a list box.
- * @param string $name the input name.
- * @param mixed $select the selected value(s).
- * @param array $data data for generating the list options (value=>display).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated list box
- */
- public static function listBox($name, $select, $data, $htmlOptions = array())
- {
- $htmlOptions = self::defaultOption('size', 4, $htmlOptions);
- if (isset($htmlOptions['multiple']))
- {
- if (substr($name, -2) !== '[]')
- $name .= '[]';
- }
- return self::dropDownList($name, $select, $data, $htmlOptions);
- }
-
- /**
- * Generates a radio button list.
- * @param string $name name of the radio button list.
- * @param mixed $select selection of the radio buttons.
- * @param array $data $data value-label pairs used to generate the radio button list.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated list.
- */
- public static function radioButtonList($name, $select, $data, $htmlOptions = array())
- {
- $inline = self::popOption('inline', $htmlOptions, false);
- $separator = self::popOption('separator', $htmlOptions, ' ');
- $container = self::popOption('container', $htmlOptions);
- $containerOptions = self::popOption('containerOptions', $htmlOptions, array());
-
- $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
- if ($inline)
- $labelOptions = self::addClassName('inline', $labelOptions);
-
- $items = array();
- $baseID = $containerOptions['id'] = self::popOption('baseID', $htmlOptions, CHtml::getIdByName($name));
-
- $id = 0;
- foreach ($data as $value => $label)
- {
- $checked = !strcmp($value, $select);
- $htmlOptions['value'] = $value;
- $htmlOptions['id'] = $baseID . '_' . $id++;
- if ($inline)
- {
- $htmlOptions['label'] = $label;
- $htmlOptions['labelOptions'] = $labelOptions;
- $items[] = self::radioButton($name, $checked, $htmlOptions);
- }
- else
- {
- $option = self::radioButton($name, $checked, $htmlOptions);
- $items[] = self::label($option . ' ' . $label, false, $labelOptions);
- }
- }
-
- $inputs = implode($separator, $items);
- return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs;
- }
-
- /**
- * Generates an inline radio button list.
- * @param string $name name of the radio button list.
- * @param mixed $select selection of the radio buttons.
- * @param array $data $data value-label pairs used to generate the radio button list.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated list.
- */
- public static function inlineRadioButtonList($name, $select, $data, $htmlOptions = array())
- {
- $htmlOptions['inline'] = true;
- return self::radioButtonList($name, $select, $data, $htmlOptions);
- }
-
- /**
- * Generates a check box list.
- * @param string $name name of the check box list.
- * @param mixed $select selection of the check boxes.
- * @param array $data $data value-label pairs used to generate the check box list.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated list.
- */
- public static function checkBoxList($name, $select, $data, $htmlOptions = array())
- {
- $inline = self::popOption('inline', $htmlOptions, false);
- $separator = self::popOption('separator', $htmlOptions, ' ');
- $container = self::popOption('container', $htmlOptions);
- $containerOptions = self::popOption('containerOptions', $htmlOptions, array());
-
- if (substr($name, -2) !== '[]')
- $name .= '[]';
-
- $checkAllLabel = self::popOption('checkAll', $htmlOptions);
- $checkAllLast = self::popOption('checkAllLast', $htmlOptions);
-
- $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
- if ($inline)
- $labelOptions = self::addClassName('inline', $labelOptions);
-
- $items = array();
- $baseID = $containerOptions['id'] = self::popOption('baseID', $htmlOptions, CHtml::getIdByName($name));
- $id = 0;
- $checkAll = true;
-
- foreach ($data as $value => $label)
- {
- $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select);
- $checkAll = $checkAll && $checked;
- $htmlOptions['value'] = $value;
- $htmlOptions['id'] = $baseID . '_' . $id++;
- if ($inline)
- {
- $htmlOptions['label'] = $label;
- $htmlOptions['labelOptions'] = $labelOptions;
- $items[] = self::checkBox($name, $checked, $htmlOptions);
- }
- else
- {
- $option = self::checkBox($name, $checked, $htmlOptions);
- $items[] = self::label($option . ' ' . $label, false, $labelOptions);
- }
- }
-
- if (isset($checkAllLabel))
- {
- $htmlOptions['value'] = 1;
- $htmlOptions['id'] = $id = $baseID . '_all';
- $option = self::checkBox($id, $checkAll, $htmlOptions);
- $label = self::label($checkAllLabel, '', $labelOptions);
- $item = self::label($option . ' ' . $label, '', $labelOptions);
- if ($checkAllLast)
- $items[] = $item;
- else
- array_unshift($items, $item);
- $name = strtr($name, array('[' => '\\[', ']' => '\\]'));
- $js = <<<EOD
- jQuery('#$id').click(function() {
- jQuery("input[name='$name']").prop('checked', this.checked);
- });
- jQuery("input[name='$name']").click(function() {
- jQuery('#$id').prop('checked', !jQuery("input[name='$name']:not(:checked)").length);
- });
- jQuery('#$id').prop('checked', !jQuery("input[name='$name']:not(:checked)").length);
- EOD;
- $cs = Yii::app()->getClientScript();
- $cs->registerCoreScript('jquery');
- $cs->registerScript($id, $js);
- }
-
- $inputs = implode($separator, $items);
- return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs;
- }
-
- /**
- * Generates an inline check box list.
- * @param string $name name of the check box list.
- * @param mixed $select selection of the check boxes.
- * @param array $data $data value-label pairs used to generate the check box list.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated list.
- */
- public static function inlineCheckBoxList($name, $select, $data, $htmlOptions = array())
- {
- $htmlOptions['inline'] = true;
- return self::checkBoxList($name, $select, $data, $htmlOptions);
- }
-
- /**
- * Generates an uneditable input.
- * @param string $value the value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input.
- */
- public static function uneditableField($value = '', $htmlOptions = array())
- {
- $size = self::popOption('size', $htmlOptions);
- if (!self::addSpanClass($htmlOptions))
- {
- if (isset($size))
- $htmlOptions = self::addClassName('input-' . $size, $htmlOptions);
- else if (isset($htmlOptions['block']))
- $htmlOptions = self::addClassName('input-block-level', $htmlOptions);
- }
- $htmlOptions = self::addClassName('uneditable-input', $htmlOptions);
- return self::tag('span', $htmlOptions, $value);
- }
-
- /**
- * Generates a search query input.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated input.
- */
- public static function searchQuery($name, $value = '', $htmlOptions = array())
- {
- $htmlOptions = self::addClassName('search-query', $htmlOptions);
- return self::textField($name, $value, $htmlOptions);
- }
-
- /**
- * Generates a text field input row.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function textFieldRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_TEXT, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a password field input row.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::textInputField
- */
- public static function passwordFieldRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_PASSWORD, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates an url field input row.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function urlFieldRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_URL, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates an email field input row.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function emailFieldRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_EMAIL, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a number field input row.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::textInputField
- */
- public static function numberFieldRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_NUMBER, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a range field input row.
- * @param string $name the input name
- * @param string $value the input value
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function rangeFieldRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_RANGE, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a date field input row.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function dateFieldRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_DATE, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a text area input row.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function textAreaRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_TEXTAREA, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a file input row.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function fileFieldRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_FILE, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a radio button row.
- * @param string $name the input name.
- * @param string $checked whether the radio button is checked.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function radioButtonRow($name, $checked = false, $htmlOptions = array())
- {
- return self::row(self::INPUT_RADIOBUTTON, $name, $checked, $htmlOptions);
- }
-
- /**
- * Generates a check box row.
- * @param string $name the input name.
- * @param string $checked whether the check box is checked.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function checkBoxRow($name, $checked = false, $htmlOptions = array())
- {
- return self::row(self::INPUT_CHECKBOX, $name, $checked, $htmlOptions);
- }
-
- /**
- * Generates a drop down list row.
- * @param string $name the input name.
- * @param string $select the selected value.
- * @param array $data data for generating the list options (value=>display).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function dropDownListRow($name, $select = '', $data = array(), $htmlOptions = array())
- {
- return self::row(self::INPUT_DROPDOWN, $name, $select, $htmlOptions, $data);
- }
-
- /**
- * Generates a list box row.
- * @param string $name the input name.
- * @param string $select the selected value.
- * @param array $data data for generating the list options (value=>display).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function listBoxRow($name, $select = '', $data = array(), $htmlOptions = array())
- {
- return self::row(self::INPUT_LISTBOX, $name, $select, $htmlOptions, $data);
- }
-
- /**
- * Generates a radio button list row.
- * @param string $name the input name.
- * @param string $select the selected value.
- * @param array $data data for generating the list options (value=>display).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function radioButtonListRow($name, $select = '', $data = array(), $htmlOptions = array())
- {
- return self::row(self::INPUT_RADIOBUTTONLIST, $name, $select, $htmlOptions, $data);
- }
-
- /**
- * Generates an inline radio button list row.
- * @param string $name the input name.
- * @param string $select the selected value.
- * @param array $data data for generating the list options (value=>display).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function inlineRadioButtonListRow($name, $select = '', $data = array(), $htmlOptions = array())
- {
- return self::row(self::INPUT_INLINERADIOBUTTONLIST, $name, $select, $htmlOptions, $data);
- }
-
- /**
- * Generates a check box list row.
- * @param string $name the input name.
- * @param string $select the selected value.
- * @param array $data data for generating the list options (value=>display).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function checkBoxListRow($name, $select = '', $data = array(), $htmlOptions = array())
- {
- return self::row(self::INPUT_CHECKBOXLIST, $name, $select, $htmlOptions, $data);
- }
-
- /**
- * Generates an inline check box list row.
- * @param string $name the input name.
- * @param string $select the selected value.
- * @param array $data data for generating the list options (value=>display).
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function inlineCheckBoxListRow($name, $select = '', $data = array(), $htmlOptions = array())
- {
- return self::row(self::INPUT_INLINECHECKBOXLIST, $name, $select, $htmlOptions, $data);
- }
-
- /**
- * Generates a uneditable field row.
- * @param string $select the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function unediableFieldRow($value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_UNEDITABLE, '', $value, $htmlOptions);
- }
-
- /**
- * Generates search query row.
- * @param string $name the input name.
- * @param string $select the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @return string the generated row.
- * @see TbHtml::row
- */
- public static function searchQueryRow($name, $value = '', $htmlOptions = array())
- {
- return self::row(self::INPUT_SEARCH, $name, $value, $htmlOptions);
- }
-
- /**
- * Generates a form row.
- * @param string $type the input type.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @param array $data data for multiple select inputs.
- * @return string the generated row.
- */
- public static function row($type, $name, $value, $htmlOptions = array(), $data = array())
- {
- $wrap = self::popOption('wrap', $htmlOptions, false);
- $label = self::popOption('label', $htmlOptions, false);
- $color = self::popOption('color', $htmlOptions);
- $groupOptions = self::popOption('groupOptions', $htmlOptions, array());
- $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
- $controlOptions = self::popOption('controlOptions', $htmlOptions, array());
-
- if (in_array($type, array(self::INPUT_CHECKBOX, self::INPUT_RADIOBUTTON)))
- {
- $htmlOptions['label'] = $label;
- $htmlOptions['labelOptions'] = $labelOptions;
- $label = false;
- }
-
- $help = self::popOption('help', $htmlOptions, '');
- $helpOptions = self::popOption('helpOptions', $htmlOptions, array());
- if (!empty($help))
- $help = self::inputHelp($help, $helpOptions);
- $input = self::createInput($type, $name, $value, $htmlOptions, $data);
-
- if ($wrap)
- {
- $groupOptions = self::addClassName('control-group', $groupOptions);
- if (isset($color))
- $groupOptions = self::addClassName($color, $groupOptions);
- $labelOptions = self::addClassName('control-label', $labelOptions);
- ob_start();
- echo self::openTag('div', $groupOptions);
- if ($label !== false)
- echo CHtml::label($label, $name, $labelOptions);
- echo self::formControls($input . $help, $controlOptions);
- echo '</div>';
- return ob_get_clean();
- }
- else
- {
- ob_start();
- if ($label !== false)
- echo CHtml::label($label, $name, $labelOptions);
- echo $input . $help;
- return ob_get_clean();
- }
- }
-
- /**
- * Generates a wrapped form row.
- * @param string $type the input type.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @param array $data data for multiple select inputs.
- * @return string the generated row.
- */
- public static function wrappedRow($type, $name, $value, $htmlOptions = array(), $data = array())
- {
- $htmlOptions['wrap'] = true;
- return self::row($type, $name, $value, $htmlOptions, $data);
- }
-
- /**
- * Creates a form input of the given type.
- * @param string $type the input type.
- * @param string $name the input name.
- * @param string $value the input value.
- * @param array $htmlOptions additional HTML attributes.
- * @param array $data data for multiple select inputs.
- * @return string the input.
- * @throws CException if the input type is invalid.
- */
- protected static function createInput($type, $name, $value, $htmlOptions = array(), $data = array())
- {
- switch ($type)
- {
- case self::INPUT_URL: return self::urlField($name, $value, $htmlOptions);
- case self::INPUT_EMAIL: return self::emailField($name, $value, $htmlOptions);
- case self::INPUT_NUMBER: return self::numberField($name, $value, $htmlOptions);
- case self::INPUT_RANGE: return self::rangeField($name, $value, $htmlOptions);
- case self::INPUT_DATE: return self::dateField($name, $value, $htmlOptions);
- case self::INPUT_TEXT: return self::textField($name, $value, $htmlOptions);
- case self::INPUT_PASSWORD: return self::passwordField($name, $value, $htmlOptions);
- case self::INPUT_TEXTAREA: return self::textArea($name, $value, $htmlOptions);
- case self::INPUT_FILE: return self::fileField($name, $value, $htmlOptions);
- case self::INPUT_RADIOBUTTON: return self::radioButton($name, $value, $htmlOptions);
- case self::INPUT_CHECKBOX: return self::checkBox($name, $value, $htmlOptions);
- case self::INPUT_DROPDOWN: return self::dropDownList($name, $value, $data, $htmlOptions);
- case self::INPUT_LISTBOX: return self::listBox($name, $value, $data, $htmlOptions);
- case self::INPUT_CHECKBOXLIST: return self::checkBoxList($name, $value, $data, $htmlOptions);
- case self::INPUT_INLINECHECKBOXLIST: return self::inlineCheckBoxList($n…
Large files files are truncated, but you can click here to view the full file