* Copyright (c) 2006, Cake Software Foundation, Inc. * 1785 E. Sahara Avenue, Suite 490-204 * Las Vegas, Nevada 89104 * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright (c) 2006, Cake Software Foundation, Inc. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project * @package cake * @subpackage cake.cake.libs.view.helpers * @since CakePHP v 0.9.1 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ /** * Html Helper class for easy use of HTML widgets. * * HtmlHelper encloses all methods needed while working with HTML pages. * * @package cake * @subpackage cake.cake.libs.view.helpers */ class HtmlHelper extends Helper { /************************************************************************* * Public variables *************************************************************************/ /**#@+ * @access public */ /** * Base URL * * @var string */ var $base = null; /** * URL to current action. * * @var string */ var $here = null; /** * Parameter array. * * @var array */ var $params = array(); /** * Current action. * * @var string */ var $action = null; /** * Enter description here... * * @var array */ var $data = null; /** * Name of model this helper is attached to. * * @var string */ var $model = null; /** * Enter description here... * * @var string */ var $field = null; /**#@-*/ /************************************************************************* * Private variables *************************************************************************/ /**#@+ * @access private */ /** * Breadcrumbs. * * @var array * @access private */ var $_crumbs = array(); /** * Document type definitions * * @var array * @access private */ var $__docTypes = array( 'html4-strict' => '', 'html4-trans' => '', 'html4-frame' => '', 'xhtml-strict' => '', 'xhtml-trans' => '', 'xhtml-frame' => '', 'xhtml11' => '' ); /** * Adds a link to the breadcrumbs array. * * @param string $name Text for link * @param string $link URL for link */ function addCrumb($name, $link) { $this->_crumbs[] = array($name, $link); } /** * Returns a doctype string. * * Possible doctypes: * + html4-strict: HTML4 Strict. * + html4-trans: HTML4 Transitional. * + html4-frame: HTML4 Frameset. * + xhtml-strict: XHTML1 Strict. * + xhtml-trans: XHTML1 Transitional. * + xhtml-frame: XHTML1 Frameset. * + xhtml11: XHTML1.1. * * @param string $type Doctype to use. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return string Doctype. */ function docType($type = 'xhtml-strict', $return = false) { if (isset($this->__docTypes[$type])) { return $this->output($this->__docTypes[$type], $return); } } /** * Returns a charset META-tag. * * @param string $charset * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or boolean value, depends on AUTO_OUTPUT and $return. */ function charset($charset, $return = false) { return $this->output(sprintf($this->tags['charset'], $charset), $return); } /** * Finds URL for specified action. * * Returns an URL pointing to a combination of controller and action. Param * $url can be: * + Empty - the method will find adress to actuall controller/action. * + '/' - the method will find base URL of application. * + A combination of controller/action - the method will find url for it. * * @param string $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4" * @return string Full translated URL with base path. */ function url($url = null) { $base = strip_plugin($this->base, $this->plugin); if (is_array($url) && !empty($url)) { if (!isset($url['controller'])) { $url['controller'] = $this->params['controller']; } if (!isset($url['plugin'])) { $url['plugin'] = $this->plugin; } } else { if (empty($url)) { return $this->here; } elseif($url{0} == '/') { $output = $base . $url; } else { $output = $base . '/' . strtolower($this->params['controller']) . '/' . $url; } } return $this->output($output); } /** * 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. * * @param string $title The content of the A tag. * @param string $url Cake-relative URL, or external URL (starts with http://) * @param array $htmlAttributes Array of HTML attributes. * @param string $confirmMessage Confirmation message. * @param boolean $escapeTitle Whether or not the text in the $title variable should be HTML escaped. * @param boolean $return Whether this method should return a value or output it. This overrides AUTO_OUTPUT. * @return string An element. */ function link($title, $url = null, $htmlAttributes = null, $confirmMessage = false, $escapeTitle = true, $return = false) { if ($escapeTitle) { $title = htmlspecialchars($title, ENT_QUOTES); } $url = $url ? $url : $title; if ($confirmMessage) { $confirmMessage = htmlspecialchars($confirmMessage, ENT_NOQUOTES); $confirmMessage = str_replace("'", "\'", $confirmMessage); $confirmMessage = str_replace('"', '"', $confirmMessage); $htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');"; } if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0) || (strpos($url, 'mailto:') === 0))) { $output = sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title); } else { $output = sprintf($this->tags['link'], $this->url($url, true), $this->_parseAttributes($htmlAttributes), $title); } return $this->output($output, $return); } /** * Creates a link element for CSS stylesheets. * * @param string $path Path to CSS file * @param string $rel Rel attribute. Defaults to "stylesheet". * @param array $htmlAttributes Array of HTML attributes. * @return string CSS or