public static function ul($data) { // echo "<pre>"; var_dump($data); exit; $output = "<ul " . array_to_attr($data['attr']) . ">"; foreach ($data['links'] as $link) { $output .= "<li " . array_to_attr($link['attr']) . ">"; if (array_key_exists('href', $link)) { $output .= Html::anchor($link['href'], $link['text']); } else { $output .= "<span>" . $link['text'] . "</span>"; } if (array_key_exists('children', $link)) { // if ($link['attr']['class'] == 'leaf last') { $output .= "<ul>"; foreach ($link['children'] as $ch => $child) { if (array_key_exists('href', $child)) { $output .= "<li>"; $output .= Html::anchor($child['href'], $child['text']); $output .= "</li>"; } else { $output .= "<li" . array_to_attr($link['attr']) . ">"; $output .= "<span>" . $child['text'] . "</span>"; $output .= "</li>"; } } $output .= "</ul>"; // } } $output .= "</li>"; } //$output .= "</ul>"; //closed in navigation.php return $output; }
/** inheritdoc */ public static function displayForm($value, &$settings, $model) { $class = get_called_class(); $settings = static::settings($settings); $include_label = isset($settings['label']) ? $settings['label'] : true; $required = isset($settings['required']) ? $settings['required'] : false; $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge form-control'); if (!isset($input_attributes['id'])) { $input_attributes['id'] = 'form_' . $settings['mapping']['fieldName']; } $attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings)); $label_text = $settings['title'] . ($required ? ' *' : ''); // Build the input $input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />'; // Build the label $label = !$include_label ? '' : \Form::label($label_text . ($has_errors ? ' - ' . $errors[0] : ''), $settings['mapping']['fieldName'], array('class' => 'item-label')); // Wrap it in an input group $input = html_tag('div', array('class' => 'input-append'), $input . html_tag('span', array('class' => 'add-on'), ' ')); // Don't wrap the input if wrap is set to false if (isset($settings['wrap']) && $settings['wrap'] === false) { return $label . $input; } return html_tag('div', $attributes, $label . $input); }
/** * Renders the field's form element for editing in the admin site */ public static function displayForm($value, &$settings, $model) { $class = get_called_class(); $settings = static::settings($settings); $include_label = isset($settings['label']) ? $settings['label'] : true; $required = isset($settings['required']) ? $settings['required'] : false; $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge'); if (!isset($input_attributes['id'])) { $input_attributes['id'] = 'form_' . $settings['mapping']['fieldName']; } $attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings)); $label_text = $settings['title'] . ($required ? ' *' : ''); if (empty($value)) { $value = substr(\Security::generate_token(), 0, 16); } // Description? $description = isset($settings['description']) ? '<span class="help-block">' . $settings['description'] . '</span>' : ''; // Build the input $input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />'; // Build the label $label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $settings['mapping']['fieldName']), $label_text . ($has_errors ? ' - ' . $errors[0] : '')); // Don't wrap the input if wrap is set to false if (isset($settings['wrap']) && $settings['wrap'] === false) { return $label . $input; } return html_tag('div', $attributes, $label . $description . $input); }
/** * Create a XHTML tag * * @param string The tag name * @param array|string The tag attributes * @param string|bool The content to place in the tag, or false for no closing tag * @return string */ function html_tag($tag, $attr = array(), $content = false) { $has_content = (bool) ($content !== false and $content !== null); $html = '<' . $tag; $html .= !empty($attr) ? ' ' . (is_array($attr) ? array_to_attr($attr) : $attr) : ''; $html .= $has_content ? '>' : ' />'; $html .= $has_content ? $content . '</' . $tag . '>' : ''; return $html; }
/** * Renders the field's form element for editing in the admin site * @see \Admin::getFieldSettings() * @param mixed $value The current value of the property, if there is one * @param array $settings Field settings, created through \Admin::getFieldSettings() * @param object $model The model, if it is being edited. * @return string The form control */ public static function displayForm($value, &$settings, $model) { $class = get_called_class(); $settings = static::settings($settings); $include_label = isset($settings['label']) ? $settings['label'] : true; $required = isset($settings['required']) ? $settings['required'] : false; $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge'); if (!isset($input_attributes['id'])) { $input_attributes['id'] = 'form_' . $settings['mapping']['fieldName']; } $attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings)); $label_text = $settings['title'] . ($required ? ' *' : ''); // Translation? if (\CMF::$lang_enabled && !\CMF::langIsDefault() && isset($settings['mapping']['columnName']) && $model->isTranslatable($settings['mapping']['columnName'])) { // If there is no translation if (!$model->hasTranslation($settings['mapping']['columnName'])) { $attributes['class'] .= ' no-translation'; $input_attributes['class'] .= ' no-translation'; $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" /> ' . $label_text; } else { $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" /> ' . $label_text; } } // Description? $description = isset($settings['description']) ? '<span class="help-block">' . $settings['description'] . '</span>' : ''; // Build the input $input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />'; // Build the label $label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $settings['mapping']['fieldName']), $label_text . ($has_errors ? ' - ' . $errors[0] : '')); // Prepend or append things... if (isset($settings['prepend'])) { $input = html_tag('div', array('class' => 'input-prepend'), html_tag('span', array('class' => 'add-on'), $settings['prepend']) . $input); } if (isset($settings['append'])) { $input = html_tag('div', array('class' => 'input-append'), $input . html_tag('span', array('class' => 'add-on'), $settings['append'])); } // Don't wrap the input if wrap is set to false if (isset($settings['wrap']) && $settings['wrap'] === false) { return $label . $input; } // Add the 'keep updated' control if the field has a template if (isset($settings['template']) && !empty($settings['template'])) { $attributes['class'] .= ' field-with-controls field-with-template'; $auto_update_setting = 'settings[' . $settings['mapping']['fieldName'] . '][auto_update]'; $auto_update_content = \Form::hidden($auto_update_setting, '0', array()) . html_tag('label', array('class' => 'checkbox auto-update-label'), \Form::checkbox($auto_update_setting, '1', \Arr::get($settings, 'auto_update', true), array('class' => 'auto-update')) . strtolower(\Lang::get('admin.common.auto_update'))); $auto_update = html_tag('div', array('class' => 'controls-top'), $auto_update_content); $label .= $auto_update; return array('content' => html_tag('div', $attributes, $label . $description . $input) . '<div class="clear"><!-- --></div>', 'widget' => false, 'assets' => array('js' => array('/admin/assets/js/twig.min.js', '/admin/assets/js/fields/template.js')), 'js_data' => $settings); } return html_tag('div', $attributes, $label . $description . $input); }
/** * Creates a mailto link with Javascript to prevent bots from picking up the * email address. * * @param string the email address * @param string the text value * @param string the subject * @param array attributes for the tag * @return string the javascript code containg email */ public static function mail_to_safe($email, $text, $subject = null, $attr = array()) { $text or $text = str_replace('@', '[at]', $email); $email = explode("@", $email); $subject and $subject = '?subject=' . $subject; $attr = array_to_attr($attr); $attr = ($attr == '' ? '' : ' ') . $attr; $output = '<script type="text/javascript">'; $output .= 'var user = "******";'; $output .= 'var at = "@";'; $output .= 'var server = "' . $email[1] . '";'; $output .= "document.write('<a href=\"' + 'mail' + 'to:' + user + at + server + '{$subject}\"{$attr}>{$text}</a>');"; $output .= '</script>'; return $output; }
/** * Attr to String * * Wraps the global attributes function and does some form specific work * * @param array $attr * @return string */ protected function attr_to_string($attr) { unset($attr['label']); return array_to_attr($attr); }
/** * Attr to String * * Wraps the global attributes function and does some form specific work * * @access private * @param array $attr * @return string */ private static function attr_to_string($attr) { unset($attr['label']); return array_to_attr($attr); }
/** * renders the navigation * * @param array array with tag attribute settings * @access public * @return void */ public static function render($type = 'default', array $attributes = array(), $header = false) { if (empty($type)) { return; } $links = \Config::get('navigation.' . $type, false); if (empty($links)) { throw new BootstrapException('Missing navigation links in config'); return; } $callback = \Config::get('bootstrap.navigation_links_callback', null); if ($callback != null) { $links = $callback($links); } foreach ($links as $key => &$link) { if (empty($link['url'])) { $link['url'] = \Inflector::friendly_title($link['title'], '-', true); } // Set link to active if it matches the current page URI. if (!isset($link['active'])) { $link['active'] = $link['url'] == ltrim(\Input::uri(), '/'); } if (empty($link['attributes'])) { $link['attributes'] = array(); } $anchor_classs = \Config::get('bootstrap.navigation.anchor_class', true); if ($anchor_classs) { if (!isset($link['attributes']['class'])) { $link['class'] = \Inflector::friendly_title($link['title'], '-', true); } $anchor_prefix = \Config::get('bootstrap.navigation.anchor_prefix', 'nav-'); if (!empty($anchor_prefix)) { $link['class'] = $anchor_prefix . $link['class']; } } if (!empty($link['class'])) { $link['attributes']['class'] = $link['class']; } } if (isset($attributes['class'])) { $attributes['class'] = 'nav ' . $attributes['class']; } else { $attributes['class'] = 'nav'; } echo \View::forge('navigation', array('header' => $header, 'links' => $links, 'attributes' => array_to_attr($attributes)))->render(); }
$btn_group_attrs = array(); } $default_btn_group_attrs = array('class' => 'btn-group'); $btn_group_attrs = Util_toolkit::convert_to_attr($btn_group_attrs, $default_btn_group_attrs); if (!isset($btn_attrs)) { $btn_attrs = array(); } $default_btn_attrs = array('data-toggle' => 'dropdown'); $btn_attrs = Util_toolkit::convert_to_attr($btn_attrs, $default_btn_attrs); $menu_id = !empty($btn_attrs['data-menu']) ? str_replace('#', '', $btn_attrs['data-menu']) : ''; if (empty($btn_with_text)) { $btn_with_text = false; } ?> <div <?php echo array_to_attr($btn_group_attrs); ?> > <?php echo btn($type, null, 'dropdown-toggle', $btn_with_text, $btn_size, $btn_type, $btn_attrs, null, 'button', null, null, $with_caret); ?> <ul class="dropdown-menu<?php if ($is_popover_align_right) { ?> pull-right<?php } ?> " role="menu"<?php if ($menu_id) { ?> id="<?php
function html_tag($tag, $attr = array(), $content = false) { $self_close = array('link', 'meta'); $has_content = (bool) ($content !== false && $content !== null); if (isset($attr['cddata'])) { $has_content = true; $content = $attr['cddata']; unset($attr['cddata']); } $html = '<' . $tag; $html .= !empty($attr) ? ' ' . (is_array($attr) ? array_to_attr($attr) : $attr) : ''; $html .= ($has_content or !in_array($tag, $self_close)) ? '>' : ' />'; $html .= ($has_content or !in_array($tag, $self_close)) ? $content . '</' . $tag . '>' : ''; return $html; }
/** * Open an action wrapper. * * @access public * @return void */ public function action_open($attrs = array()) { static::$helper->add_template($attrs); $class = array('form-actions'); static::$helper->merge_classes($attrs, $class); return '<div ' . array_to_attr($attrs) . '>'; }
/** * renders the breadcrumbs * * @param array array with tag attribute settings * @access public * @return void */ public static function render(array $attributes = array()) { if (empty(self::$breadcrumbs)) { return; } if (isset($attributes['class'])) { $attributes['class'] = 'breadcrumb ' . $attributes['class']; } else { $attributes['class'] = 'breadcrumb'; } echo \View::forge('breadcrumbs.php', array('links' => self::$breadcrumbs, 'attributes' => array_to_attr($attributes)))->render(); }
function html_tag($tag, $attr = array(), $content = false) { // list of void elements (tags that can not have content) static $void_elements = array("area", "base", "br", "col", "hr", "img", "input", "link", "meta", "param", "command", "embed", "keygen", "source", "track", "wbr", "menuitem"); // construct the HTML $html = '<' . $tag; $html .= !empty($attr) ? ' ' . (is_array($attr) ? array_to_attr($attr) : $attr) : ''; // a void element? if (in_array(strtolower($tag), $void_elements)) { // these can not have content $html .= ' />'; } else { // add the content and close the tag $html .= '>' . $content . '</' . $tag . '>'; } return $html; }
public static function label($text, $attr = array(), $error = '') { $error_icon = empty($error) ? \Config::get('petro.form.error_icon') : ''; return static::template('label', array('{label_attr}', '{label}', '{error_icon}'), array(array_to_attr($attr), $text, $error_icon)); }
/** * renders the alerts * * @param array array with tag attribute settings * @access public * @return void */ public static function render(array $attributes = array()) { self::load(); if (empty(self::$alerts)) { return; } foreach (self::$alerts as $type => $alert) { $alert_attributes = $attributes; $class = 'alert'; if (count($alert) > 1) { $class .= ' alert-block'; } $class .= ' alert-' . $type; if (isset($alert_attributes['class'])) { $alert_attributes['class'] = $class . ' ' . $alert_attributes['class']; } else { $alert_attributes['class'] = $class; } echo \View::forge('alerts', array('type' => $type, 'alert' => $alert, 'attributes' => array_to_attr($alert_attributes)))->render(); } }