'', 'metalink' => '', 'link' => '%s', 'mailto' => '%s', 'form' => '
', 'formend' => '
', 'input' => '', 'textarea' => '', 'hidden' => '', 'checkbox' => '', 'checkboxmultiple' => '', 'radio' => '%s', 'selectstart' => '', 'selectempty' => '', 'selectoption' => '', 'selectend' => '', 'optiongroup' => '', 'optiongroupend' => '', 'checkboxmultiplestart' => '', 'checkboxmultipleend' => '', 'password' => '', 'file' => '', 'file_no_model' => '', 'submit' => '', 'submitimage' => '', 'button' => '%s', 'image' => '', 'tableheader' => '%s', 'tableheaderrow' => '%s', 'tablecell' => '%s', 'tablerow' => '%s', 'block' => '%s', 'blockstart' => '', 'blockend' => '', 'hiddenblock' => '
%s
', 'tag' => '<%s%s>%s', 'tagstart' => '<%s%s>', 'tagend' => '', 'tagselfclosing' => '<%s%s/>', 'para' => '%s

', 'parastart' => '', 'label' => '', 'fieldset' => '%s', 'fieldsetstart' => '
%s', 'fieldsetend' => '
', 'legend' => '%s', 'css' => '', 'style' => '', 'charset' => '', 'ul' => '%s', 'ol' => '%s', 'li' => '%s', 'error' => '%s', 'javascriptblock' => '%s', 'javascriptstart' => '', 'javascriptend' => '' ); /** * Breadcrumbs. * * @var array */ protected $_crumbs = array(); /** * Names of script files that have been included once * * @var array */ protected $_includedScripts = array(); /** * Options for the currently opened script block buffer if any. * * @var array */ protected $_scriptBlockOptions = array(); /** * Document type definitions * * @var array */ protected $_docTypes = array( 'html4-strict' => '', 'html4-trans' => '', 'html4-frame' => '', 'html5' => '', 'xhtml-strict' => '', 'xhtml-trans' => '', 'xhtml-frame' => '', 'xhtml11' => '' ); /** * Constructor * * ### Settings * * - `configFile` A file containing an array of tags you wish to redefine. * * ### Customizing tag sets * * Using the `configFile` option you can redefine the tag HtmlHelper will use. * The file named should be compatible with HtmlHelper::loadConfig(). * * @param View $View The View this helper is being attached to. * @param array $settings Configuration settings for the helper. */ public function __construct(View $View, $settings = array()) { parent::__construct($View, $settings); if (is_object($this->_View->response)) { $this->response = $this->_View->response; } else { $this->response = new CakeResponse(); } if (!empty($settings['configFile'])) { $this->loadConfig($settings['configFile']); } } /** * Adds a link to the breadcrumbs array. * * @param string $name Text for link * @param string $link URL for link (if empty it won't be a link) * @param string|array $options Link attributes e.g. array('id' => 'selected') * @return this HtmlHelper * @see HtmlHelper::link() for details on $options that can be used. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper */ public function addCrumb($name, $link = null, $options = null) { $this->_crumbs[] = array($name, $link, $options); return $this; } /** * Returns a doctype string. * * Possible doctypes: * * - html4-strict: HTML4 Strict. * - html4-trans: HTML4 Transitional. * - html4-frame: HTML4 Frameset. * - html5: HTML5. Default value. * - xhtml-strict: XHTML1 Strict. * - xhtml-trans: XHTML1 Transitional. * - xhtml-frame: XHTML1 Frameset. * - xhtml11: XHTML1.1. * * @param string $type Doctype to use. * @return string Doctype string * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::docType */ public function docType($type = 'html5') { if (isset($this->_docTypes[$type])) { return $this->_docTypes[$type]; } return null; } /** * Creates a link to an external resource and handles basic meta tags * * Create a meta tag that is output inline: * * `$this->Html->meta('icon', 'favicon.ico'); * * Append the meta tag to `$scripts_for_layout`: * * `$this->Html->meta('description', 'A great page', array('inline' => false));` * * Append the meta tag to custom view block: * * `$this->Html->meta('description', 'A great page', array('block' => 'metaTags'));` * * ### Options * * - `inline` Whether or not the link element should be output inline. Set to false to * have the meta tag included in `$scripts_for_layout`, and appended to the 'meta' view block. * - `block` Choose a custom block to append the meta tag to. Using this option * will override the inline option. * * @param string $type The title of the external resource * @param string|array $url The address of the external resource or string for content attribute * @param array $options Other attributes for the generated tag. If the type attribute is html, * rss, atom, or icon, the mime-type is returned. * @return string A completed `` element. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::meta */ public function meta($type, $url = null, $options = array()) { $options += array('inline' => true, 'block' => null); if (!$options['inline'] && empty($options['block'])) { $options['block'] = __FUNCTION__; } unset($options['inline']); if (!is_array($type)) { $types = array( 'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $url), 'atom' => array('type' => 'application/atom+xml', 'title' => $type, 'link' => $url), 'icon' => array('type' => 'image/x-icon', 'rel' => 'icon', 'link' => $url), 'keywords' => array('name' => 'keywords', 'content' => $url), 'description' => array('name' => 'description', 'content' => $url), ); if ($type === 'icon' && $url === null) { $types['icon']['link'] = 'favicon.ico'; } if (isset($types[$type])) { $type = $types[$type]; } elseif (!isset($options['type']) && $url !== null) { if (is_array($url) && isset($url['ext'])) { $type = $types[$url['ext']]; } else { $type = $types['rss']; } } elseif (isset($options['type']) && isset($types[$options['type']])) { $type = $types[$options['type']]; unset($options['type']); } else { $type = array(); } } $options += $type; $out = null; if (isset($options['link'])) { $options['link'] = $this->assetUrl($options['link']); if (isset($options['rel']) && $options['rel'] === 'icon') { $out = sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link'), ' ', ' ')); $options['rel'] = 'shortcut icon'; } $out .= sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link'), ' ', ' ')); } else { $out = sprintf($this->_tags['meta'], $this->_parseAttributes($options, array('block', 'type'), ' ', ' ')); } if (empty($options['block'])) { return $out; } $this->_View->append($options['block'], $out); } /** * Returns a charset META-tag. * * @param string $charset The character set to be used in the meta tag. If empty, * The App.encoding value will be used. Example: "utf-8". * @return string A meta tag containing the specified character set. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::charset */ public function charset($charset = null) { if (empty($charset)) { $charset = strtolower(Configure::read('App.encoding')); } return sprintf($this->_tags['charset'], (!empty($charset) ? $charset : 'utf-8')); } /** * Creates an HTML link. * * If $url starts with "http://" this is treated as an external link. Else, * it is treated as a path to controller/action and parsed with the * HtmlHelper::url() method. * * If the $url is empty, $title is used instead. * * ### Options * * - `escape` Set to false to disable escaping of title and attributes. * - `escapeTitle` Set to false to disable escaping of title. (Takes precedence over value of `escape`) * - `confirm` JavaScript confirmation message. * * @param string $title The content to be wrapped by tags. * @param string|array $url Cake-relative URL or array of URL parameters, or external URL (starts with http://) * @param array $options Array of options and HTML attributes. * @param string $confirmMessage JavaScript confirmation message. * @return string An `` element. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link */ public function link($title, $url = null, $options = array(), $confirmMessage = false) { $escapeTitle = true; if ($url !== null) { $url = $this->url($url); } else { $url = $this->url($title); $title = htmlspecialchars_decode($url, ENT_QUOTES); $title = h(urldecode($title)); $escapeTitle = false; } if (isset($options['escapeTitle'])) { $escapeTitle = $options['escapeTitle']; unset($options['escapeTitle']); } elseif (isset($options['escape'])) { $escapeTitle = $options['escape']; } if ($escapeTitle === true) { $title = h($title); } elseif (is_string($escapeTitle)) { $title = htmlentities($title, ENT_QUOTES, $escapeTitle); } if (!empty($options['confirm'])) { $confirmMessage = $options['confirm']; unset($options['confirm']); } if ($confirmMessage) { $options['onclick'] = $this->_confirm($confirmMessage, 'return true;', 'return false;', $options); } elseif (isset($options['default']) && !$options['default']) { if (isset($options['onclick'])) { $options['onclick'] .= ' '; } else { $options['onclick'] = ''; } $options['onclick'] .= 'event.returnValue = false; return false;'; unset($options['default']); } return sprintf($this->_tags['link'], $url, $this->_parseAttributes($options), $title); } /** * Creates a link element for CSS stylesheets. * * ### Usage * * Include one CSS file: * * `echo $this->Html->css('styles.css');` * * Include multiple CSS files: * * `echo $this->Html->css(array('one.css', 'two.css'));` * * Add the stylesheet to the `$scripts_for_layout` layout var: * * `$this->Html->css('styles.css', array('inline' => false));` * * Add the stylesheet to a custom block: * * `$this->Html->css('styles.css', array('block' => 'layoutCss'));` * * ### Options * * - `inline` If set to false, the generated tag will be appended to the 'css' block, * and included in the `$scripts_for_layout` layout variable. Defaults to true. * - `block` Set the name of the block link/style tag will be appended to. * This overrides the `inline` option. * - `plugin` False value will prevent parsing path as a plugin * - `rel` Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be imported. * - `fullBase` If true the URL will get a full address for the css file. * * @param string|array $path The name of a CSS style sheet or an array containing names of * CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot * of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css. * @param array $options Array of options and HTML arguments. * @return string CSS or