=')) { $str = htmlspecialchars($str, ENT_QUOTES, 'UTF-8', FALSE); } else { $str = preg_replace('/&(?!(?:#\d++|[a-z]++);)/ui', '&', $str); $str = str_replace(array('<', '>', '\'', '"'), array('<', '>', ''', '"'), $str); } } return $str; } public static function specialurlencode($str, $double_encode = TRUE) { return str_replace(' ', '%20', html::specialchars($str, $double_encode)); } public static function anchor($uri, $title = NULL, $attributes = NULL, $protocol = NULL, $escape_title = FALSE) { if ($uri === '') { $site_url = url::base(FALSE); } elseif (strpos($uri, '#') === 0) { $site_url = $uri; } elseif (strpos($uri, '://') === FALSE) { $site_url = url::site($uri, $protocol); } else { if (html::$windowed_urls === TRUE AND empty($attributes['target'])) { $attributes['target'] = '_blank'; } $site_url = $uri; } return '' .($escape_title ? html::specialchars((($title === NULL) ? $site_url : $title), FALSE) : (($title === NULL) ? $site_url : $title)).''; } public static function file_anchor($file, $title = NULL, $attributes = NULL, $protocol = NULL) { return '' .(($title === NULL) ? end(explode('/', $file)) : $title) .''; } public static function panchor($protocol, $uri, $title = NULL, $attributes = FALSE) { return html::anchor($uri, $title, $attributes, $protocol); } public static function anchor_array(array $array) { $anchors = array(); foreach ($array as $link => $title) { $anchors[] = html::anchor($link, $title); } return $anchors; } public static function email($email) { $safe = ''; foreach (str_split($email) as $letter) { switch (($letter === '@') ? rand(1, 2) : rand(1, 3)) { case 1: $safe .= ''.ord($letter).';'; break; case 2: $safe .= ''.dechex(ord($letter)).';'; break; case 3: $safe .= $letter; } } return $safe; } public static function mailto($email, $title = NULL, $attributes = NULL) { if (empty($email)) return $title; if (strpos($email, '?') !== FALSE) { list ($email, $params) = explode('?', $email, 2); $params = '?'.str_replace(' ', '%20', $params); } else { $params = ''; } $safe = html::email($email); empty($title) and $title = $safe; empty($attributes) or $attributes = html::attributes($attributes); return ''.$title.''; } public static function breadcrumb($segments = NULL) { empty($segments) and $segments = Router::$segments; $array = array(); while ($segment = array_pop($segments)) { $array[] = html::anchor ( implode('/', $segments).'/'.$segment, ucwords(inflector::humanize($segment)) ); } return array_reverse($array); } public static function meta($tag, $value = NULL) { if (is_array($tag)) { $tags = array(); foreach ($tag as $t => $v) { $tags[] = html::meta($t, $v); } return implode("\n", $tags); } $attr = in_array(strtolower($tag), Kohana::config('http.meta_equiv')) ? 'http-equiv' : 'name'; return ''; } public static function stylesheet($style, $media = FALSE, $index = FALSE) { return html::link($style, 'stylesheet', 'text/css', '.css', $media, $index); } public static function link($href, $rel, $type, $suffix = FALSE, $media = FALSE, $index = FALSE) { $compiled = ''; if (is_array($href)) { foreach ($href as $_href) { $_rel = is_array($rel) ? array_shift($rel) : $rel; $_type = is_array($type) ? array_shift($type) : $type; $_media = is_array($media) ? array_shift($media) : $media; $compiled .= html::link($_href, $_rel, $_type, $suffix, $_media, $index); } } else { if (strpos($href, '://') === FALSE) { $href = url::base($index).$href; } $length = strlen($suffix); if ( $length > 0 AND substr_compare($href, $suffix, -$length, $length, FALSE) !== 0) { $href .= $suffix; } $attr = array ( 'rel' => $rel, 'type' => $type, 'href' => $href, ); if ( ! empty($media)) { $attr['media'] = $media; } $compiled = ''; } return $compiled."\n"; } public static function script($script, $index = FALSE) { $compiled = ''; if (is_array($script)) { foreach ($script as $name) { $compiled .= html::script($name, $index); } } else { if (strpos($script, '://') === FALSE) { $script = url::base((bool) $index).$script; } if (substr_compare($script, '.js', -3, 3, FALSE) !== 0) { $script .= '.js'; } $compiled = ''; } return $compiled."\n"; } public static function image($src = NULL, $alt = NULL, $index = FALSE) { $attributes = is_array($src) ? $src : array('src' => $src); if (is_array($alt)) { $attributes += $alt; } elseif ( ! empty($alt)) { $attributes['alt'] = $alt; } if (strpos($attributes['src'], '://') === FALSE) { $attributes['src'] = url::base($index).$attributes['src']; } return '
'; } public static function attributes($attrs) { if (empty($attrs)) return ''; if (is_string($attrs)) return ' '.$attrs; $compiled = ''; foreach ($attrs as $key => $val) { $compiled .= ' '.$key.'="'.html::specialchars($val).'"'; } return $compiled; } }