/** * Render alert. * * @return string */ public function render() { ob_start(); // Section attributes $attributes = array('class' => 'alert alert-block ' . $this->class); ?> <div <?php echo HTML::attributes($attributes); ?> > <?php if ($this->header) { ?> <h4 class="alert-heading"><?php echo HTML::chars($this->header); ?> </h4><?php } ?> <?php echo $this->content; ?> </div> <?php return ob_get_clean(); }
/** * Render a sortable <th> tag based on current request * * @param string $column * @param string $name * @param string|array $attributes * @return string */ public static function th($column, $name, $attributes = null) { static $_query; // Only get one per request if ($_query === null) { $_query = Request::current()->query(); // Default $_query['sort'] = isset($_query['sort']) ? strtolower($_query['sort']) : 'id'; $_query['order'] = isset($_query['order']) ? strtolower($_query['order']) : 'desc'; } // Attributes if (!is_array($attributes)) { $attributes = array('class' => $attributes); } // Init $class = 'sorting'; $order = 'asc'; // This column is selected if ($column == $_query['sort']) { $class .= '_' . $_query['order']; $order = $_query['order'] == 'asc' ? 'desc' : 'asc'; } // Add class to element $attributes['class'] = trim($class . ' ' . $attributes['class'], ' '); // Build URL query $url = URL::query(array('sort' => $column, 'order' => $order)); // Return HTML return strtr('<th:attrs><a href=":url">:name</a></th>', array(':attrs' => HTML::attributes($attributes), ':url' => $url, ':name' => $name)); }
public static function error($message = '', $class = 'field_error', array $attributes = NULL) { if (empty($attributes['class'])) { $attributes['class'] = $class; } return '<span' . HTML::attributes($attributes) . '>' . $message . '</span>'; }
/** * Create HTML link anchors. Note that the title is not escaped, to allow * HTML elements within links (images, etc). * * @param string URL or URI string * @param string link text * @param array HTML anchor attributes * @param string use a specific protocol * @return string */ public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL) { if ($title === NULL) { // Use the URI as the title $title = $uri; } // Translate the title $title = __($title); if ($uri === '') { // Only use the base URL $uri = URL::base(FALSE, $protocol); } else { if (strpos($uri, '://') !== FALSE) { if (HTML::$windowed_urls === TRUE and empty($attributes['target'])) { // Make the link open in a new window $attributes['target'] = '_blank'; } } elseif ($uri[0] !== '#') { // Make the URI absolute for non-id anchors $uri = URL::site($uri, $protocol); } } // Add the sanitized link to the attributes $attributes['href'] = $uri; return '<a' . HTML::attributes($attributes) . '>' . $title . '</a>'; }
/** * Generates an opening HTML form tag. * * // Form will submit back to the current page using POST * echo Form::open(); * * // Form will submit to 'search' using GET * echo Form::open('search', array('method' => 'get')); * * // When "file" inputs are present, you must include the "enctype" * echo Form::open(NULL, array('enctype' => 'multipart/form-data')); * * @param mixed form action, defaults to the current request URI, or [Request] class to use * @param array html attributes * @return string * @uses Request::instance * @uses URL::site * @uses HTML::attributes */ public static function open($action = NULL, array $attributes = NULL) { if ($action instanceof Request) { // Use the current URI $action = $action->uri(); } if (!$action) { // Allow empty form actions (submits back to the current url). $action = ''; } elseif (strpos($action, '://') === FALSE) { // Make the URI absolute $action = URL::site($action); } // Add the form action to the attributes $attributes['action'] = $action; // Only accept the default character set $attributes['accept-charset'] = Kohana::$charset; if (!isset($attributes['method'])) { // Use POST method $attributes['method'] = 'post'; } // Only render the CSRF field when the POST method is used $hidden_csrf_field = $attributes['method'] == 'post' ? self::hidden('form_auth_id', CSRF::token()) : ''; return '<form' . HTML::attributes($attributes) . '>' . $hidden_csrf_field; }
/** * Tests HTML::attributes() * * @test * @dataProvider provider_attributes * @param array $attributes Attributes to use * @param string $expected Expected output */ public function test_attributes($attributes, $expected) { $this->assertSame( $expected, HTML::attributes($attributes) ); }
public static function counter($num = 0) { if ($num == 0) { return ''; } return '<span' . HTML::attributes(array('class' => 'counter')) . '>' . (int) $num . '</span>'; }
/** * Render alert. * * @return string */ public function render() { ob_start(); // Section attributes $attributes = array('class' => 'alert alert-block ' . $this->class); if ($this->header === true) { $this->header = self::generate_header(); } ?> <div <?php echo HTML::attributes($attributes); ?> > <?php if ($this->header) { ?> <strong><?php echo HTML::chars($this->header); ?> </strong><?php } ?> <?php echo $this->content; ?> </div> <?php return ob_get_clean(); }
public function __toString() { $regular_browser = " <!--[if !IE]>< --><link " . HTML::attributes($this->attributes) . " /><!-- ><![endif]-->"; $this->attributes['rel'] = 'shortcut icon'; $ie = "<!--[if IE]><link " . HTML::attributes($this->attributes) . " /><![endif]-->"; return $regular_browser . "\n" . $ie; }
public static function favicon($file, array $attributes = array('rel' => 'icon', 'type' => 'image/x-icon'), $protocol = NULL, $index = FALSE) { if (strpos($file, '://') === FALSE) { $file = URL::base($protocol, $index) . $file; } $attributes['href'] = $file; return '<link' . HTML::attributes($attributes) . ' />'; }
protected static function style($file, $media = 'all') { if (!Asset::valid_url($file)) { // Add base url $file = URL::site($file); } return '<link' . HTML::attributes(array('type' => 'text/css', 'rel' => 'stylesheet', 'href' => $file, 'media' => $media)) . '>'; }
/** * * @param string $title * @param array $types * @return string */ public static function hidden($title, array $types = ['xs', 'sm']) { $attributes = ['class' => '']; foreach ($types as $type) { $attributes['class'] .= ' hidden-' . e($type); } return '<span' . \HTML::attributes($attributes) . '>' . $title . '</span>'; }
public static function image($file, array $attributes = NULL, $index = FALSE) { if (strpos($file, '://') === FALSE) { $file = URL::site($file); } $attributes['src'] = $file; return '<img' . HTML::attributes($attributes) . '>'; }
/** * Generate a HTML link to a named route. * * @param string $name * @param string $title * @param array $parameters * @param array $attributes * @return string */ function link_to_route($name, $title = null, $parameters = array(), $attributes = array()) { if (Route::getRoutes()->hasNamedRoute($name)) { return app('html')->linkRoute($name, $title, $parameters, $attributes); } else { return '<a href="javascript:void(0)"' . HTML::attributes($attributes) . '>' . $name . '</a>'; } }
public static function link_icon($action, $icon, $title = null, $parameters = array(), $attributes = array()) { $url = URL::to_action($action, $parameters); if (is_null($title)) { $title = $url; } $icon_tag = '<i class="icon-' . $icon . '"></i>'; return '<a href="' . $url . '"' . HTML::attributes($attributes) . ' title="' . $title . '">' . $icon_tag . '</a>'; }
function link_to_by_custom($url, $body, $parameters = null) { // slime // return "<a href='http://:/dogs/1'>Show Dog</a>"; // generalize $url = url($url); $attributes = $parameters ? HTML::attributes($parameters) : ''; return "<a href='{$url}'{$attributes}>{$body}</a>"; }
/** * Get the computed attributes for given row data * Returns html attribute string */ public function get_attributes($rowdata) { // Static attributes $attr = $this->attributes_array(); // Dynamic attributes? if (is_callable($this->attr_callback)) { $attr = array_merge($attr, call_user_func($this->attr_callback, $rowdata)); } return \HTML::attributes($attr); }
/** * Creates a link element. * * echo HTML::link('media/img/favicon.ico', array('rel'=>'ico', 'type'=>'image/x-icon')); * * @param string file name * @param array default attributes * @param mixed protocol to pass to URL::base() * @param boolean include the index page * @return string * @uses URL::base * @uses HTML::attributes */ public static function link($file, array $attributes = NULL, $protocol = NULL, $index = FALSE) { if (strpos($file, '://') === FALSE) { // Add the base URL $file = URL::base($protocol, $index) . $file; } // Set the stylesheet link $attributes['href'] = $file; return '<link' . HTML::attributes($attributes) . ' >'; }
/** * @return mixed */ public function formgroup() { $hidden = $this->isHide() ? 'display:none;' : ''; $hasError = $this->hasError() ? 'has-error' : ''; $options = array('class' => 'form-group', 'style' => ''); $options['class'] .= ' ' . $hasError; $options['class'] .= ' ' . $this->getColClass(); $options['style'] .= ' ' . $hidden; return \HTML::attributes($options); }
/** * Get or set an array of attributes * The returned attributes are in HTML string format */ public function attributes($attributes = null) { if (is_array($attributes)) { foreach ($attributes as $attr => $value) { $this->attr($attr, $value); } return $this; } return \HTML::attributes($this->attributes_array()); }
/** * @param $field - field name to chance * @param $id - id * @param $value - value of field * @param $params - route url parameters * * @return string */ public static function change($field, $id, $value, $params) { // Добавляем inlineJS один раз для каждого столбца в таблице if (!isset(self::$is_running_change[$field])) { $url = Route::url('ajax', ['module' => str_replace('cms_', '', $params['module']), 'controller' => Request::get('controller'), 'action' => 'change', 'param' => $field]); Assets::instance()->add_inlineJS("\n\t\t \$('.ch-{$field}').click(function() {\n\t\t APP.chEnabled(\$(this), '{$url}', '{$field}');\n\t\t });\n\t\t "); self::$is_running_change[$field] = true; } $attributes = ['class' => 'ch-' . $field . ' fa fa-check-circle fa-lg fa-fw text-' . ($value ? 'success' : 'danger'), 'data-toggle' => 'tooltip', 'data-id' => $id, 'title' => __('settings.status_change')]; return '<i' . HTML::attributes($attributes) . '></i>'; }
/** * Creates a form label. * * @param string target input * @param string label text * @param array html attributes * @return string */ public static function label($input, $text = NULL, array $attributes = NULL) { if ($text === NULL) { // Use the input name as the text $text = ucwords(str_replace('_', ' ', $input)); } // Translate the string $text = __($text); // Set the label target $attributes['for'] = $input; return '<label' . HTML::attributes($attributes) . '>' . $text . '</label>'; }
private function cb($name = 'foo', $label = null, $value = 1, $inline = false, $checked = false) { $checkAttr = array('id' => $name, 'checked' => 'checked', 'type' => 'checkbox', 'name' => $name, 'value' => $value); $labelAttr = array('for' => $name, 'class' => 'checkbox'); if ($inline) { $labelAttr['class'] .= ' inline'; } if (!$checked) { unset($checkAttr['checked']); } $radio = '<input' . HTML::attributes($checkAttr) . '>'; return $label ? '<label' . HTML::attributes($labelAttr) . '>' . $radio . $label . '</label>' : $radio; }
/** * Creates a <picture> tag with <source> elements and final <img> element. * * echo HTML::picture('media/img/logo.png', array('w' => 179, 'h' => 179), array('1200px' => array('w' => '169', 'h' => '169'), '992px' => array('w' => '132', 'h' => '132'), '768px' => array('w' => '138', 'h' => '138'), '480px' => array('w' => '324', 'h' => '324'), '320px' => array('w' => '180', 'h' => '180')), array('alt' => 'My Company')) * * @param string $file file name * @param array $size resize image with Core::imagefly * @param array $sources image sources with size and media braking point * @param array $attributes default attributes * @return string * @uses Core::imagefly * @uses HTML::image * @uses HTML::attributes */ public static function picture($file, array $size = NULL, array $sources = NULL, array $attributes = NULL) { if (empty($sources)) { return ''; } $ret = ''; foreach ($sources as $key => $value) { $media = '(min-width: ' . $key . ')'; $srcset = Core::imagefly($file, isset($value['w']) ? $value['w'] : NULL, isset($value['h']) ? $value['h'] : NULL); $ret .= '<source' . HTML::attributes(compact('media', 'srcset')) . '>'; } $image = HTML::image(Core::imagefly($file, isset($size['w']) ? $size['w'] : NULL, isset($size['h']) ? $size['h'] : NULL), $attributes); return '<picture>' . $ret . $image . '</picture>'; }
/** * Creates a select form input. * * @param string input name * @param array available options * @param string selected option * @param array html attributes * @return string */ public static function select_improved($name, array $options = NULL, $selected = NULL, array $attributes = NULL) { // Set the input name $attributes['name'] = $name; $attributes['class'] = 'form-control'; if (empty($options)) { // There are no options $options = ''; } else { foreach ($options as $value => $name) { if (is_array($name)) { // Create a new optgroup $group = array('label' => $value); // Create a new list of options $_options = array(); foreach ($name as $_value => $_name) { // Create a new attribute set for this option $option = array('value' => $_value); if ((string) $_value == (string) $selected) { // This option is selected $option['selected'] = 'selected'; } // Sanitize the option title $title = htmlspecialchars($_name, ENT_NOQUOTES, Kohana::$charset, FALSE); // Change the option to the HTML string $_options[] = '<option' . HTML::attributes($option) . '>' . $title . '</option>'; } // Compile the options into a string $_options = "\n" . implode("\n", $_options) . "\n"; $options[$value] = '<optgroup' . HTML::attributes($group) . '>' . $_options . '</optgroup>'; } else { // Create a new attribute set for this option $option = array('value' => $value); if ((string) $value == (string) $selected) { // This option is selected $option['selected'] = 'selected'; } // Sanitize the option title $title = htmlspecialchars($name, ENT_NOQUOTES, Kohana::$charset, FALSE); // Change the option to the HTML string $options[$value] = '<option' . HTML::attributes($option) . '>' . $title . '</option>'; } } // Compile the options into a single string $options = "\n" . implode("\n", $options) . "\n"; } return '<select' . HTML::attributes($attributes) . '>' . $options . '</select>'; }
public function image($name, $size = NULL, $attributes = NULL) { // TODO: also work with full URLs if (isset($this->_params["image_url"])) { if (is_numeric($size)) { // TODO: make size work properly with $name that contains subfolders $attributes["src"] = $this->_params["image_url"] . $size . "/" . $name; echo "<img" . HTML::attributes($attributes) . "></img>"; } else { $attributes["src"] = $this->_params["image_url"] . $name; echo "<img" . HTML::attributes($attributes) . "></img>"; } } else { echo "Image could not be found."; } }
public function render($indent = 0) { if (!$this->_name) { return $this->render_content(); } $attributes = HTML::attributes($this->_attributes); $indent_string = Builder_Xml::indent_string($indent); if ($this->has_content()) { $content = $this->render_content($this->preserve() ? -1 : $indent + 1); if (!$this->preserve()) { $content = strlen($content) > 30 ? "\n{$content}\n{$indent_string}" : trim($content); } return $indent_string . "<{$this->_name}{$attributes}>{$content}</{$this->_name}>"; } else { return $indent_string . "<{$this->_name}{$attributes}/>"; } }
public static function button($name, $value, array $attributes = NULL) { $id = 'send_sms_btn_' . mt_rand(1000, 9999); $url = URL::site('sms/send'); $js = <<<EOF <script> \$(function() { var timer = null; var countdown = 60; \$('#{$id}').click(function() { var t = \$(this); t.attr('disabled', true); var url = '{$url}'; var params = {}; params.type = 'reg'; params.phone = \$('input[name={$name}]').val(); \$.get(url, params, function(res) { alert(res.info); if (res.status=='n') { t.attr('disabled', false); } else { if(typeof(res.timeleft)!='undefined') { countdown = res.timeleft; } t.val(countdown+"秒后重发"); clearTimeout(timer); timer = setInterval(function() { if (countdown == 1) { clearTimeout(timer); t.attr('disabled', false); t.val("获取验证码"); countdown = 60; } else { countdown--; t.val(countdown+"秒后重发"); } },1000); } }); }); }); </script> EOF; $attributes['type'] = 'button'; return "<input id=\"{$id}\" value=\"{$value}\" " . HTML::attributes($attributes) . ">\n{$js}"; }
/** * Create a listing HTML element. * * @param string $type * @param array $list * @param array $attributes * @return string */ protected static function _listing($type, array $list, array $attributes = NULL) { $html = ''; if (count($list) == 0) { return $html; } // Essentially we will just spin through the list and build the list of the HTML // elements from the array. We will also handled nested lists in case that is // present in the array. Then we will build out the final listing elements. foreach ($list as $key => $value) { if (is_array($value)) { $html .= self::_nested_listing($key, $type, $value); } else { $html .= '<li>' . $value . '</li>'; } } return "<{$type}" . HTML::attributes($attributes) . ">{$html}</{$type}>"; }
/** * Render content. * * @return string */ public function render() { $attributes = array(); // Custom URL $url = $this->url ? $this->url : Anqh::page_meta('url'); if ($url) { $attributes['addthis:url'] = $url; } // Custom title $title = $this->title ? $this->title : Anqh::page_meta('title'); if ($title) { $attributes['addthis:title'] = $title; } ob_start(); ?> <div class="addthis_toolbox addthis_floating_style addthis_32x32_style"<?php echo HTML::attributes($attributes); ?> > <a class="addthis_button_facebook"></a> <a class="addthis_button_twitter"></a> <a class="addthis_button_google_plusone_share"></a> <a class="addthis_button_email"></a> </div> <script> var addthis_config = { data_track_clickback: true, pubid: '<?php echo Kohana::$config->load('site.share'); ?> ' } , addthis_share = { templates: { twitter: '{{title}}: {{url}} (via @<?php echo Kohana::$config->load('site.share'); ?> )' } }; </script> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=<?php echo Kohana::$config->load('site.share'); ?> "></script> <?php return ob_get_clean(); }