diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-26 11:24:50 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-26 11:24:50 -0800 |
commit | 3060a6f662da66008d57a461bf1c9b5b4aa2b002 (patch) | |
tree | 442fd290505817efc0324f2af6e01805cb7396aa /system/helpers/html.php | |
parent | 1cd6a615bb47a33794e4a4f690c87a348ab752d7 (diff) | |
parent | 32d25dafd5b033338b6a9bb8c7c53edab462543a (diff) |
Merge branch 'master' into talmdal_dev
Conflicts:
modules/gallery/controllers/albums.php
modules/gallery/controllers/movies.php
modules/gallery/controllers/photos.php
Diffstat (limited to 'system/helpers/html.php')
-rw-r--r-- | system/helpers/html.php | 106 |
1 files changed, 13 insertions, 93 deletions
diff --git a/system/helpers/html.php b/system/helpers/html.php index 2c609567..2d759ac0 100644 --- a/system/helpers/html.php +++ b/system/helpers/html.php @@ -2,12 +2,12 @@ /** * HTML helper class. * - * $Id: html.php 4376 2009-06-01 11:40:39Z samsoir $ + * $Id: html.php 4679 2009-11-10 01:45:52Z isaiah $ * * @package Core * @author Kohana Team - * @copyright (c) 2007-2008 Kohana Team - * @license http://kohanaphp.com/license.html + * @copyright (c) 2007-2009 Kohana Team + * @license http://kohanaphp.com/license */ class html_Core { @@ -21,47 +21,13 @@ class html_Core { * @param boolean encode existing entities * @return string */ - public static function specialchars($str, $double_encode = TRUE) + public static function chars($str, $double_encode = TRUE) { - // Force the string to be a string - $str = (string) $str; - - // Do encode existing HTML entities (default) - if ($double_encode === TRUE) - { - $str = htmlspecialchars($str, ENT_QUOTES, 'UTF-8'); - } - else - { - // Do not encode existing HTML entities - // From PHP 5.2.3 this functionality is built-in, otherwise use a regex - if (version_compare(PHP_VERSION, '5.2.3', '>=')) - { - $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; + // Return HTML entities using the Kohana charset + return htmlspecialchars($str, ENT_QUOTES, Kohana::CHARSET, $double_encode); } /** - * Perform a html::specialchars() with additional URL specific encoding. - * - * @param string string to convert - * @param boolean encode existing entities - * @return string - */ - public static function specialurlencode($str, $double_encode = TRUE) - { - return str_replace(' ', '%20', html::specialchars($str, $double_encode)); - } - - /** * Create HTML link anchors. * * @param string URL or URI string @@ -98,11 +64,11 @@ class html_Core { return // Parsed URL - '<a href="'.html::specialurlencode($site_url, FALSE).'"' + '<a href="'.htmlspecialchars($site_url, ENT_QUOTES, Kohana::CHARSET, FALSE).'"' // Attributes empty? Use an empty string .(is_array($attributes) ? html::attributes($attributes) : '').'>' // Title empty? Use the parsed URL - .($escape_title ? html::specialchars((($title === NULL) ? $site_url : $title), FALSE) : (($title === NULL) ? $site_url : $title)).'</a>'; + .($escape_title ? htmlspecialchars((($title === NULL) ? $site_url : $title), ENT_QUOTES, Kohana::CHARSET, FALSE) : (($title === NULL) ? $site_url : $title)).'</a>'; } /** @@ -118,7 +84,7 @@ class html_Core { { return // Base URL + URI = full URL - '<a href="'.html::specialurlencode(url::base(FALSE, $protocol).$file, FALSE).'"' + '<a href="'.htmlspecialchars(url::base(FALSE, $protocol).$file, ENT_QUOTES, Kohana::CHARSET, FALSE).'"' // Attributes empty? Use an empty string .(is_array($attributes) ? html::attributes($attributes) : '').'>' // Title empty? Use the filename part of the URI @@ -126,37 +92,6 @@ class html_Core { } /** - * Similar to anchor, but with the protocol parameter first. - * - * @param string link protocol - * @param string URI or URL to link to - * @param string link text - * @param array HTML anchor attributes - * @return string - */ - public static function panchor($protocol, $uri, $title = NULL, $attributes = FALSE) - { - return html::anchor($uri, $title, $attributes, $protocol); - } - - /** - * Create an array of anchors from an array of link/title pairs. - * - * @param array link/title pairs - * @return array - */ - public static function anchor_array(array $array) - { - $anchors = array(); - foreach ($array as $link => $title) - { - // Create list of anchors - $anchors[] = html::anchor($link, $title); - } - return $anchors; - } - - /** * Generates an obfuscated version of an email address. * * @param string email address @@ -286,7 +221,7 @@ class html_Core { */ public static function stylesheet($style, $media = FALSE, $index = FALSE) { - return html::link($style, 'stylesheet', 'text/css', '.css', $media, $index); + return html::link($style, 'stylesheet', 'text/css', $media, $index); } /** @@ -295,12 +230,11 @@ class html_Core { * @param string|array filename * @param string|array relationship * @param string|array mimetype - * @param string specifies suffix of the file * @param string|array specifies on what device the document will be displayed * @param boolean include the index_page in the link * @return string */ - public static function link($href, $rel, $type, $suffix = FALSE, $media = FALSE, $index = FALSE) + public static function link($href, $rel, $type, $media = FALSE, $index = FALSE) { $compiled = ''; @@ -312,7 +246,7 @@ class html_Core { $_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); + $compiled .= html::link($_href, $_rel, $_type, $_media, $index); } } else @@ -323,14 +257,6 @@ class html_Core { $href = url::base($index).$href; } - $length = strlen($suffix); - - if ( $length > 0 AND substr_compare($href, $suffix, -$length, $length, FALSE) !== 0) - { - // Add the defined suffix - $href .= $suffix; - } - $attr = array ( 'rel' => $rel, @@ -376,12 +302,6 @@ class html_Core { $script = url::base((bool) $index).$script; } - if (substr_compare($script, '.js', -3, 3, FALSE) !== 0) - { - // Add the javascript suffix - $script .= '.js'; - } - $compiled = '<script type="text/javascript" src="'.$script.'"></script>'; } @@ -437,7 +357,7 @@ class html_Core { $compiled = ''; foreach ($attrs as $key => $val) { - $compiled .= ' '.$key.'="'.html::specialchars($val).'"'; + $compiled .= ' '.$key.'="'.htmlspecialchars($val, ENT_QUOTES, Kohana::CHARSET).'"'; } return $compiled; |