[ 'meta' => '', 'metalink' => '', 'link' => '{{content}}', 'mailto' => '{{content}}', 'image' => '', 'tableheader' => '{{content}}', 'tableheaderrow' => '{{content}}', 'tablecell' => '{{content}}', 'tablerow' => '{{content}}', 'block' => '{{content}}', 'blockstart' => '', 'blockend' => '', 'tag' => '<{{tag}}{{attrs}}>{{content}}', 'tagstart' => '<{{tag}}{{attrs}}>', 'tagend' => '', 'tagselfclosing' => '<{{tag}}{{attrs}}/>', 'para' => '{{content}}

', 'parastart' => '', 'css' => '', 'style' => '{{content}}', 'charset' => '', 'ul' => '{{content}}', 'ol' => '{{content}}', 'li' => '{{content}}', 'javascriptblock' => '{{content}}', 'javascriptstart' => '', 'javascriptend' => '' ] ]; /** * Breadcrumbs. * * @var array */ protected $_crumbs = array(); /** * Names of script & css files that have been included once * * @var array */ protected $_includedAssets = 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 * * - `templates` Either a filename to a config containing templates. * Or an array of templates to load. See Cake\View\StringTemplate for * template formatting. * * ### Customizing tag sets * * Using the `templates` option you can redefine the tag HtmlHelper will use. * * @param View $View The View this helper is being attached to. * @param array $config Configuration settings for the helper. */ public function __construct(View $View, array $config = array()) { parent::__construct($View, $config); $this->response = $this->_View->response ?: new Response(); } /** * 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, array $options = array()) { $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 custom view block "meta": * * `$this->Html->meta('description', 'A great page', array('block' => true));` * * Append the meta tag to custom view block: * * `$this->Html->meta('description', 'A great page', array('block' => 'metaTags'));` * * ### Options * * - `block` - Set to true to append output to view block "meta" or provide * custom block name. * * @param string $type The title of the external resource * @param string|array $content 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, $content = null, array $options = array()) { $options += array('block' => null); $types = array( 'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $content), 'atom' => array('type' => 'application/atom+xml', 'title' => $type, 'link' => $content), 'icon' => array('type' => 'image/x-icon', 'rel' => 'icon', 'link' => $content), 'keywords' => array('name' => 'keywords', 'content' => $content), 'description' => array('name' => 'description', 'content' => $content), 'robots' => array('name' => 'robots', 'content' => $content), 'viewport' => array('name' => 'viewport', 'content' => $content), ); if ($type === 'icon' && $content === null) { $types['icon']['link'] = 'favicon.ico'; } if (isset($types[$type])) { $type = $types[$type]; } elseif (!isset($options['type']) && $content !== null) { if (is_array($content) && isset($content['ext'])) { $type = $types[$content['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 = $this->formatTemplate('metalink', [ 'url' => $options['link'], 'attrs' => $this->templater()->formatAttributes($options, ['block', 'link']) ]); $options['rel'] = 'shortcut icon'; } $out .= $this->formatTemplate('metalink', [ 'url' => $options['link'], 'attrs' => $this->templater()->formatAttributes($options, ['block', 'link']) ]); } else { $out = $this->formatTemplate('meta', [ 'attrs' => $this->templater()->formatAttributes($options, ['block', 'type']) ]); } if (empty($options['block'])) { return $out; } if ($options['block'] === true) { $options['block'] = __FUNCTION__; } $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 $this->formatTemplate('charset', [ '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, array $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 $this->formatTemplate('link', [ 'url' => $url, 'attrs' => $this->templater()->formatAttributes($options), 'content' => $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 view block "css": * * `$this->Html->css('styles.css', array('block' => true));` * * Add the stylesheet to a custom block: * * `$this->Html->css('styles.css', array('block' => 'layoutCss'));` * * ### Options * * - `block` Set to true to append output to view block "css" or provide * custom block name. * - `once` Whether or not the css file should be checked for uniqueness. If true css * files will only be included once, use false to allow the same * css to be included more than once per request. * - `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