yf_html5fw_bs3 class

Twitter bootstrap v3 html5 abstraction driver.

Fileplugins/html/classes/html5fw/yf_html5fw_bs3.class.php
Use_class('html5fw_bs3', 'classes/html5fw/')
Extendsyf_html5fw_empty

Public properties

A site sets them in its config with $PROJECT_CONF['html5fw_bs3']['NAME'] = ...;

PropertyDefaultDescription
$CLASS_ADDON 'add-on input-group-addon'
$CLASS_CONTROLS 'controls col-md-offset-3'
$CLASS_CONTROLS_BUTTONS 'controls col-md-offset-3'
$CLASS_DESC ''
$CLASS_EDIT_ICON 'icon-edit fa fa-edit'
$CLASS_ERROR 'error has-error'
$CLASS_FEEDBACK 'form-control-feedback'
$CLASS_FORM_GROUP 'control-group form-group'
$CLASS_HELP 'help-block pull-left'
$CLASS_INFO 'info has-info'
$CLASS_INPUT_APPEND 'input-append'
$CLASS_INPUT_GROUP 'input-group'
$CLASS_INPUT_GROUP_BTN
string
'input-group-btn' wrapper of the `prepend_html` / `append_html` buttons of an input group ('' puts them in the group as they are)
$CLASS_INPUT_GROUP_SIZE
string
'input-group-%size' `input_group_size` class (sm, lg)
$CLASS_INPUT_PREPEND 'input-prepend'
$CLASS_LABEL 'control-label col-md-3'
$CLASS_NO_LABEL ' col-md-offset-3'
$CLASS_NO_LABEL_BUTTONS ' col-md-offset-3'
$CLASS_STACKED_ITEM 'stacked-item'
$CLASS_SUCCESS 'success has-success'
$CLASS_WARNING 'warning has-warning'

Public methods 3

form_dd_row

public function form_dd_row($content, $extra = [], $replace = [], $form = [])

Generate form row using dl>dt,dd html tags. Useful for user profle and other simple table-like content.

    public function form_dd_row($content, $extra = [], $replace = [], $form = [])
    {
        $extra = (array) $extra + array_fill_keys(['class_wrapper', 'class_add_wrapper', 'class_dd', 'class_add_dd', 'wide', 'desc', 'edit_link', 'link_url', 'link_name', 'tip', 'only_row_start', 'only_row_end', 'stacked'], null);
        $dd_class = ($form->_params['dd_class'] ?? null) ?: 'span6';

        $class_wrapper = ($extra['class_wrapper'] ?? null) ?: 'dl-horizontal';
        if ($extra['class_add_wrapper']) {
            $class_wrapper .= ' ' . $extra['class_add_wrapper'];
        }
        $class_dd = ($extra['class_dd'] ?? null) ?: '';
        if ($extra['class_add_dd']) {
            $class_dd .= ' ' . $extra['class_add_dd'];
        }
        $row_start = ! $extra['wide'] ? '<dl class="' . $class_wrapper . '">' . PHP_EOL . '<dt>' . t($extra['desc']) . '</dt>' . PHP_EOL : '';
        $before_content_html = '<dd' . ($class_dd ? ' class="' . $class_dd . '"' : '') . '>';
        $after_content_html = '</dd>';
        $row_end = '</dl>' . PHP_EOL;

        if ($extra['edit_link']) {
            if (MAIN_TYPE_ADMIN && main()->ADMIN_GROUP != 1 && ! _class('admin_methods')->_admin_link_is_allowed($extra['edit_link'])) {
                $extra['edit_link'] = '';
            }
        }
        $edit_link_html = $extra['edit_link'] ? ' <a href="' . _escape_tpl_braces(_htmlchars($extra['edit_link'])) . '" class="' . $this->CLASS_EDIT_LINK . '"><i class="' . $this->CLASS_EDIT_ICON . '"></i> ' . t('Edit') . '</a>' . PHP_EOL : '';
        $link_name_html = ($extra['link_url'] && $extra['link_name']) ? ' <a href="' . $extra['link_url'] . '" class="' . $this->CLASS_LINK_URL . '">' . t($extra['link_name']) . '</a>' . PHP_EOL : '';

        $inline_tip_html = ($extra['tip'] ? ' ' . tip($extra['tip'], $replace) : '');
        $inline_help_before = '';
        $inline_help_after = '';

        if ($extra['only_row_start']) {
            return $row_start . $before_content_html;
        } elseif ($extra['only_row_end']) {
            return $after_content_html . $row_end;
        } elseif ($extra['stacked']) {
            return $inline_help_before . $content . PHP_EOL
                . $edit_link_html . $link_name_html . $inline_tip_html . $inline_help_after;
        }
        // Full variant
        return $row_start
                    . $before_content_html . $inline_help_before . $content . PHP_EOL
                    . $edit_link_html . $link_name_html . $inline_tip_html . $inline_help_after . $after_content_html
                    . $this->_add_rich_editor($extra, $replace, $form)
                . $row_end;
    }

form_row

public function form_row($content, $extra = [], $replace = [], $form = [])
    public function form_row($content, $extra = [], $replace = [], $form = [])
    {
        $name = $extra['name'] ?? '';
        $is_html_array = (false !== strpos($name, '['));
        if ($is_html_array) {
            $name_dotted = str_replace(['[', ']'], ['.', ''], trim($name, ']['));
        }
        $no_label = false;
        if (isset($form->_params['no_label'])) {
            $no_label = $form->_params['no_label'];
        }
        if (isset($extra['no_label'])) {
            $no_label = $extra['no_label'];
        }
        $_css_group_map = [
            'errors' => $this->CLASS_ERROR,
            'success' => $this->CLASS_SUCCESS,
            'warnings' => $this->CLASS_WARNING,
            'infos' => $this->CLASS_INFO,
        ];
        foreach ($_css_group_map as $_a => $_css_class) {
            if (isset($extra[$_a][$name]) || ($is_html_array && isset($extra[$_a][$name_dotted]))) {
                if ($extra['stacked'] ?? null) {
                    $extra['class_add_stacked'] = ($extra['class_add_stacked'] ?? '') . ' ' . $_css_class;
                } else {
                    $extra['class_add_form_group'] = ($extra['class_add_form_group'] ?? '') . ' ' . $_css_class;
                }
                break;
            }
        }
        $class_form_group = ($extra['class_form_group'] ?? null) ?: $this->CLASS_FORM_GROUP . (($extra['class_add_form_group'] ?? null) ? ' ' . $extra['class_add_form_group'] : '');
        if ($extra['class_add_wrapper'] ?? null) {
            $class_form_group .= ' ' . ($extra['class_add_wrapper'] ?? null);
        }
        $class_label = ($extra['class_label'] ?? null) ?: $this->CLASS_LABEL
            . (($extra['class_add_label'] ?? null) ? ' ' . $extra['class_add_label'] : '');

        $def_class_controls = ($extra['buttons_controls'] ?? null) ? $this->CLASS_CONTROLS_BUTTONS : $this->CLASS_CONTROLS;
        $def_class_no_label = ($extra['buttons_controls'] ?? null) ? $this->CLASS_NO_LABEL_BUTTONS : $this->CLASS_NO_LABEL;
        $class_controls = ($extra['class_controls'] ?? null) ?: $def_class_controls
            . (($extra['desc'] ?? null) && ! $no_label ? ' ' . $this->CLASS_DESC : $def_class_no_label)
            . (($extra['class_add_controls'] ?? null) ? ' ' . $extra['class_add_controls'] : '');

        $form_group_extra = ($extra['form_group'] ?? null);
        $form_group_extra['class'] = $class_form_group;

        if (($form->_params['form_group_auto_id'] ?? null) && ! ($form_group_extra['id'] ?? null) && ($extra['id'] ?? null)) {
            $form_group_extra['class'] .= ' form-group-id-' . $extra['id'];
        }

        $controls_extra = ($extra['controls'] ?? null);
        $controls_extra['class'] = $class_controls;

        $label_extra = ($extra['control_label'] ?? null);
        $label_extra['class'] = $class_label;
        $label_extra['for'] = $extra['id'] ?? null;

        $label_tip_html = ($extra['label_tip'] ?? null) ? trim(' ' . tip($extra['label_tip'], $replace)) : '';

        $label = (($extra['desc'] ?? null) && ! $no_label ? '<label' . _attrs($label_extra, ['id', 'class', 'style', 'for']) . '>' . t($extra['desc']) . $label_tip_html . '</label>' . PHP_EOL : '');

        $row_start = '<div' . _attrs($form_group_extra, ['id', 'class', 'style']) . '>' . PHP_EOL
            . $label
            . ( ! ($extra['wide'] ?? null) ? '<div' . _attrs($controls_extra, ['id', 'class', 'style']) . '>' . PHP_EOL : '');

        $row_end =
                ( ! ($extra['wide'] ?? null) ? '</div>' . PHP_EOL : '')
            . '</div>';

        $has_prepend = ($extra['prepend'] ?? null) || ($extra['prepend_html'] ?? null);
        $has_append = ($extra['append'] ?? null) || ($extra['append_html'] ?? null);
        $input_group_extra = ($extra['input_group'] ?? null);
        if ( ! isset($input_group_extra['class'])) {
            $input_group_extra['class'] =  $this->CLASS_INPUT_GROUP . ' ' . ($has_prepend ? $this->CLASS_INPUT_PREPEND : '') . ($has_append ? ' ' . $this->CLASS_INPUT_APPEND : '');
        }
        if ($extra['input_group_size'] ?? null) {
            $input_group_extra['class'] .= ' ' . str_replace('%size', $extra['input_group_size'], $this->CLASS_INPUT_GROUP_SIZE);
        }
        $input_group_extra['class'] .= ' ' . ($input_group_extra['class_add'] ?? null);

        $show_input_group = $has_append || $has_prepend;

        $before_content_html = $show_input_group ? '<div' . _attrs($input_group_extra, ['id', 'class', 'style']) . '>' . PHP_EOL : '';
        $before_content_html .= $this->_input_group_items($extra, 'prepend');

        $after_content_html = $this->_input_group_items($extra, 'append');
        $after_content_html .= $show_input_group ? '</div>' . PHP_EOL : '';


        if ($extra['edit_link'] ?? null) {
            if (MAIN_TYPE_ADMIN && main()->ADMIN_GROUP != 1 && ! _class('admin_methods')->_admin_link_is_allowed($extra['edit_link'])) {
                $extra['edit_link'] = '';
            }
        }
        $edit_link_html = ($extra['edit_link'] ?? null) ? ' <a href="' . _escape_tpl_braces(_htmlchars($extra['edit_link'])) . '" class="' . $this->CLASS_EDIT_LINK . '"><i class="' . $this->CLASS_EDIT_ICON . '"></i> ' . t('Edit') . '</a>' . PHP_EOL : '';
        $link_name_html = (($extra['link_url'] ?? null) && ($extra['link_name'] ?? null)) ? ' <a href="' . $extra['link_url'] . '" class="' . $this->CLASS_LINK_URL . ($extra['link_class'] ?? null) . '">' . t($extra['link_name']) . '</a>' . PHP_EOL : '';

        $inline_help_before = ($extra['help_before'] ?? null) ? '<span class="' . $this->CLASS_HELP . '">' . nl2br($extra['help_before']) . '</span>' . PHP_EOL : '';
        $inline_help_after = ($extra['inline_help'] ?? null) ? '<span class="' . $this->CLASS_HELP . '">' . nl2br($extra['inline_help']) . '</span>' . PHP_EOL : '';
        $inline_tip_html = ($extra['tip'] ?? null) ? ' ' . tip($extra['tip'], $replace) : '';

        if ($extra['only_row_start'] ?? null) {
            return $row_start;
        } elseif ($extra['only_row_end'] ?? null) {
            return $row_end;
        } elseif ($extra['stacked'] ?? null) {
            $extra_stacked = is_array($extra['stacked']) ? $extra['stacked'] : [];
            if (($extra['class_stacked'] ?? null) && ! isset($extra_stacked['class'])) {
                $extra_stacked['class'] = $extra['class_stacked'];
            }
            $extra_stacked['class'] = (($extra_stacked['class'] ?? null) ?: $this->CLASS_STACKED_ITEM) . ' ' . (($extra_stacked['class_add'] ?? null) ?: ($extra['class_add_stacked'] ?? null));
            return
                '<span' . _attrs($extra_stacked, ['id', 'class', 'style']) . '>'
                . (($extra['show_label'] ?? null) ? $label : '')
                . $inline_help_before . $before_content_html . $content . PHP_EOL . $after_content_html
                . $edit_link_html . $link_name_html . $inline_tip_html . $inline_help_after
                . '</span>';
        }
        // Full variant
        return
                $row_start
                . $inline_help_before . $before_content_html . $content . PHP_EOL . $after_content_html
                . $edit_link_html . $link_name_html . $inline_tip_html . $inline_help_after
                . $this->_add_rich_editor($extra, $replace, $form)
                . $row_end;
    }

Methods starting with _ hooks and helpers; not routable as page actions

public function _input_group_items($extra, $side)

One side of an input group: the `prepend` / `append` addons (a string, or an array for several) and the `prepend_html` / `append_html` buttons (HTML, a string or an array), the buttons outermost. SECURITY: `prepend` / `append` (scalar or array) and `prepend_html` / `append_html` are HTML, developer-supplied, NOT escaped: never put request or DB data in them.

  • $extra array
  • $side string prepend or append
    public function _input_group_items($extra, $side)
    {
        $addon_class = $this->CLASS_ADDON . (($extra['class_' . $side] ?? null) ? ' ' . $extra['class_' . $side] : '');
        $addons = '';
        foreach (is_array($extra[$side] ?? null) ? $extra[$side] : [$extra[$side] ?? null] as $addon) {
            $addons .= $addon ? '<span class="' . $addon_class . '">' . $addon . '</span>' . PHP_EOL : '';
        }
        $buttons = array_filter(array_map('strval', (array) ($extra[$side . '_html'] ?? [])), 'strlen');
        $buttons_html = '';
        if ($buttons) {
            $buttons_html = $this->CLASS_INPUT_GROUP_BTN !== ''
                ? '<span class="' . $this->CLASS_INPUT_GROUP_BTN . '">' . implode('', $buttons) . '</span>' . PHP_EOL
                : implode(PHP_EOL, $buttons) . PHP_EOL;
        }
        return $side === 'prepend' ? $buttons_html . $addons : $addons . $buttons_html;
    }

Inherited methods

from yf_html5fw_empty: _add_rich_editor(), form_render_out()