2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Html Helper class file.
|
|
|
|
*
|
|
|
|
* Simplifies the construction of HTML elements.
|
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.View.Helper
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 0.9.1
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-04 18:10:24 +00:00
|
|
|
|
|
|
|
App::uses('AppHelper', 'View/Helper');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Html Helper class for easy use of HTML widgets.
|
|
|
|
*
|
|
|
|
* HtmlHelper encloses all methods needed while working with HTML pages.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.View.Helper
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1434/HTML
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class HtmlHelper extends AppHelper {
|
|
|
|
/**
|
|
|
|
* html tags used by this helper.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2011-01-23 14:38:36 +00:00
|
|
|
protected $_tags = array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'meta' => '<meta%s/>',
|
|
|
|
'metalink' => '<link href="%s"%s/>',
|
|
|
|
'link' => '<a href="%s"%s>%s</a>',
|
|
|
|
'mailto' => '<a href="mailto:%s" %s>%s</a>',
|
2011-06-23 21:06:35 +00:00
|
|
|
'form' => '<form action="%s"%s>',
|
2008-05-30 11:40:08 +00:00
|
|
|
'formend' => '</form>',
|
2011-02-05 06:48:52 +00:00
|
|
|
'input' => '<input name="%s"%s/>',
|
|
|
|
'textarea' => '<textarea name="%s"%s>%s</textarea>',
|
|
|
|
'hidden' => '<input type="hidden" name="%s"%s/>',
|
2008-05-30 11:40:08 +00:00
|
|
|
'checkbox' => '<input type="checkbox" name="%s" %s/>',
|
|
|
|
'checkboxmultiple' => '<input type="checkbox" name="%s[]"%s />',
|
|
|
|
'radio' => '<input type="radio" name="%s" id="%s" %s />%s',
|
|
|
|
'selectstart' => '<select name="%s"%s>',
|
|
|
|
'selectmultiplestart' => '<select name="%s[]"%s>',
|
|
|
|
'selectempty' => '<option value=""%s> </option>',
|
|
|
|
'selectoption' => '<option value="%s"%s>%s</option>',
|
|
|
|
'selectend' => '</select>',
|
|
|
|
'optiongroup' => '<optgroup label="%s"%s>',
|
|
|
|
'optiongroupend' => '</optgroup>',
|
2008-12-25 22:13:06 +00:00
|
|
|
'checkboxmultiplestart' => '',
|
2008-05-30 11:40:08 +00:00
|
|
|
'checkboxmultipleend' => '',
|
|
|
|
'password' => '<input type="password" name="%s" %s/>',
|
|
|
|
'file' => '<input type="file" name="%s" %s/>',
|
|
|
|
'file_no_model' => '<input type="file" name="%s" %s/>',
|
2009-10-20 03:44:50 +00:00
|
|
|
'submit' => '<input %s/>',
|
2008-05-30 11:40:08 +00:00
|
|
|
'submitimage' => '<input type="image" src="%s" %s/>',
|
2009-10-20 03:57:23 +00:00
|
|
|
'button' => '<button type="%s"%s>%s</button>',
|
2008-05-30 11:40:08 +00:00
|
|
|
'image' => '<img src="%s" %s/>',
|
|
|
|
'tableheader' => '<th%s>%s</th>',
|
|
|
|
'tableheaderrow' => '<tr%s>%s</tr>',
|
|
|
|
'tablecell' => '<td%s>%s</td>',
|
|
|
|
'tablerow' => '<tr%s>%s</tr>',
|
|
|
|
'block' => '<div%s>%s</div>',
|
|
|
|
'blockstart' => '<div%s>',
|
|
|
|
'blockend' => '</div>',
|
|
|
|
'tag' => '<%s%s>%s</%s>',
|
|
|
|
'tagstart' => '<%s%s>',
|
|
|
|
'tagend' => '</%s>',
|
|
|
|
'para' => '<p%s>%s</p>',
|
|
|
|
'parastart' => '<p%s>',
|
|
|
|
'label' => '<label for="%s"%s>%s</label>',
|
|
|
|
'fieldset' => '<fieldset%s>%s</fieldset>',
|
|
|
|
'fieldsetstart' => '<fieldset><legend>%s</legend>',
|
|
|
|
'fieldsetend' => '</fieldset>',
|
|
|
|
'legend' => '<legend>%s</legend>',
|
|
|
|
'css' => '<link rel="%s" type="text/css" href="%s" %s/>',
|
|
|
|
'style' => '<style type="text/css"%s>%s</style>',
|
|
|
|
'charset' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
|
|
|
|
'ul' => '<ul%s>%s</ul>',
|
|
|
|
'ol' => '<ol%s>%s</ol>',
|
|
|
|
'li' => '<li%s>%s</li>',
|
2009-03-12 23:51:30 +00:00
|
|
|
'error' => '<div%s>%s</div>',
|
2009-09-03 17:50:53 +00:00
|
|
|
'javascriptblock' => '<script type="text/javascript"%s>%s</script>',
|
2009-03-12 23:51:30 +00:00
|
|
|
'javascriptstart' => '<script type="text/javascript">',
|
2009-09-03 17:45:39 +00:00
|
|
|
'javascriptlink' => '<script type="text/javascript" src="%s"%s></script>',
|
2009-03-12 23:51:30 +00:00
|
|
|
'javascriptend' => '</script>'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-23 14:36:14 +00:00
|
|
|
/**
|
|
|
|
* Minimized attributes
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $_minimizedAttributes = array(
|
|
|
|
'compact', 'checked', 'declare', 'readonly', 'disabled', 'selected',
|
|
|
|
'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format to attribute
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_attributeFormat = '%s="%s"';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format to attribute
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_minimizedAttributeFormat = '%s="%s"';
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Breadcrumbs.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @var array
|
2009-07-25 19:43:26 +00:00
|
|
|
* @access protected
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_crumbs = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-12 23:51:30 +00:00
|
|
|
/**
|
|
|
|
* Names of script files that have been included once
|
|
|
|
*
|
|
|
|
* @var array
|
2009-07-25 19:43:26 +00:00
|
|
|
* @access private
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-04 06:33:39 +00:00
|
|
|
private $__includedScripts = array();
|
2009-07-25 19:43:26 +00:00
|
|
|
/**
|
|
|
|
* Options for the currently opened script block buffer if any.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access protected
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_scriptBlockOptions = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Document type definitions
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @var array
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
2010-04-04 06:33:39 +00:00
|
|
|
private $__docTypes = array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
|
|
|
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
|
|
|
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
2011-01-23 13:05:51 +00:00
|
|
|
'html5' => '<!DOCTYPE html>',
|
2008-05-30 11:40:08 +00:00
|
|
|
'xhtml-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
|
|
|
'xhtml-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
|
|
|
'xhtml-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
|
|
|
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-23 21:27:50 +00:00
|
|
|
/**
|
|
|
|
* Default Constructor
|
|
|
|
*
|
|
|
|
* @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 (!empty($settings['configFile'])) {
|
|
|
|
$this->loadConfig($settings['configFile']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* 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 mixed $options Link attributes e.g. array('id'=>'selected')
|
2009-10-17 02:15:57 +00:00
|
|
|
* @return void
|
2009-10-17 02:10:01 +00:00
|
|
|
* @see HtmlHelper::link() for details on $options that can be used.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function addCrumb($name, $link = null, $options = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_crumbs[] = array($name, $link, $options);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a doctype string.
|
|
|
|
*
|
|
|
|
* Possible doctypes:
|
2009-10-17 03:11:13 +00:00
|
|
|
*
|
|
|
|
* - html4-strict: HTML4 Strict.
|
|
|
|
* - html4-trans: HTML4 Transitional.
|
|
|
|
* - html4-frame: HTML4 Frameset.
|
2011-01-23 13:05:51 +00:00
|
|
|
* - html5: HTML5.
|
2009-10-17 03:11:13 +00:00
|
|
|
* - xhtml-strict: XHTML1 Strict.
|
|
|
|
* - xhtml-trans: XHTML1 Transitional.
|
|
|
|
* - xhtml-frame: XHTML1 Frameset.
|
|
|
|
* - xhtml11: XHTML1.1.
|
|
|
|
*
|
|
|
|
* @param string $type Doctype to use.
|
2009-03-12 23:34:04 +00:00
|
|
|
* @return string Doctype string
|
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1439/docType
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function docType($type = 'xhtml-strict') {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (isset($this->__docTypes[$type])) {
|
2009-11-21 21:43:54 +00:00
|
|
|
return $this->__docTypes[$type];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Creates a link to an external resource and handles basic meta tags
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-10-17 02:31:56 +00:00
|
|
|
*
|
|
|
|
* - `inline` Whether or not the link element should be output inline, or in scripts_for_layout.
|
|
|
|
*
|
2009-10-17 02:10:01 +00:00
|
|
|
* @param string $type The title of the external resource
|
|
|
|
* @param mixed $url The address of the external resource or string for content attribute
|
2009-10-17 02:31:56 +00:00
|
|
|
* @param array $options Other attributes for the generated tag. If the type attribute is html,
|
2009-10-17 02:10:01 +00:00
|
|
|
* rss, atom, or icon, the mime-type is returned.
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return string A completed `<link />` element.
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1438/meta
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function meta($type, $url = null, $options = array()) {
|
2009-10-17 02:31:56 +00:00
|
|
|
$inline = isset($options['inline']) ? $options['inline'] : true;
|
|
|
|
unset($options['inline']);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
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'] = $this->webroot('favicon.ico');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($types[$type])) {
|
|
|
|
$type = $types[$type];
|
2009-10-17 02:31:56 +00:00
|
|
|
} elseif (!isset($options['type']) && $url !== null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_array($url) && isset($url['ext'])) {
|
|
|
|
$type = $types[$url['ext']];
|
|
|
|
} else {
|
|
|
|
$type = $types['rss'];
|
|
|
|
}
|
2009-10-17 02:31:56 +00:00
|
|
|
} elseif (isset($options['type']) && isset($types[$options['type']])) {
|
|
|
|
$type = $types[$options['type']];
|
|
|
|
unset($options['type']);
|
2008-06-19 14:31:00 +00:00
|
|
|
} else {
|
|
|
|
$type = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
} elseif ($url !== null) {
|
|
|
|
$inline = $url;
|
|
|
|
}
|
2009-10-17 02:31:56 +00:00
|
|
|
$options = array_merge($type, $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
$out = null;
|
|
|
|
|
2009-10-17 02:31:56 +00:00
|
|
|
if (isset($options['link'])) {
|
|
|
|
if (isset($options['rel']) && $options['rel'] === 'icon') {
|
2011-01-23 14:38:36 +00:00
|
|
|
$out = sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('link'), ' ', ' '));
|
2009-10-17 02:31:56 +00:00
|
|
|
$options['rel'] = 'shortcut icon';
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
2009-10-17 02:31:56 +00:00
|
|
|
$options['link'] = $this->url($options['link'], true);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
$out .= sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('link'), ' ', ' '));
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
2011-01-23 14:38:36 +00:00
|
|
|
$out = sprintf($this->_tags['meta'], $this->_parseAttributes($options, array('type'), ' ', ' '));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($inline) {
|
2009-11-21 21:43:54 +00:00
|
|
|
return $out;
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
2010-07-15 03:03:30 +00:00
|
|
|
$this->_View->addScript($out);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a charset META-tag.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @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".
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string A meta tag containing the specified character set.
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1436/charset
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function charset($charset = null) {
|
2008-09-04 13:35:04 +00:00
|
|
|
if (empty($charset)) {
|
|
|
|
$charset = strtolower(Configure::read('App.encoding'));
|
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
return sprintf($this->_tags['charset'], (!empty($charset) ? $charset : 'utf-8'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-10-17 02:49:44 +00:00
|
|
|
*
|
|
|
|
* - `escape` Set to false to disable escaping of title and attributes.
|
|
|
|
*
|
2009-10-17 02:10:01 +00:00
|
|
|
* @param string $title The content to be wrapped by <a> tags.
|
|
|
|
* @param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
|
2009-10-17 02:49:44 +00:00
|
|
|
* @param array $options Array of HTML attributes.
|
2009-10-17 02:10:01 +00:00
|
|
|
* @param string $confirmMessage JavaScript confirmation message.
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return string An `<a />` element.
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1442/link
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function link($title, $url = null, $options = array(), $confirmMessage = false) {
|
2009-10-17 02:49:44 +00:00
|
|
|
$escapeTitle = true;
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($url !== null) {
|
|
|
|
$url = $this->url($url);
|
|
|
|
} else {
|
|
|
|
$url = $this->url($title);
|
|
|
|
$title = $url;
|
|
|
|
$escapeTitle = false;
|
|
|
|
}
|
|
|
|
|
2009-10-17 02:49:44 +00:00
|
|
|
if (isset($options['escape'])) {
|
|
|
|
$escapeTitle = $options['escape'];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-08-01 04:53:16 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($escapeTitle === true) {
|
2008-08-01 04:53:16 +00:00
|
|
|
$title = h($title);
|
2008-05-30 11:40:08 +00:00
|
|
|
} elseif (is_string($escapeTitle)) {
|
|
|
|
$title = htmlentities($title, ENT_QUOTES, $escapeTitle);
|
|
|
|
}
|
|
|
|
|
2009-10-17 02:49:44 +00:00
|
|
|
if (!empty($options['confirm'])) {
|
|
|
|
$confirmMessage = $options['confirm'];
|
|
|
|
unset($options['confirm']);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if ($confirmMessage) {
|
|
|
|
$confirmMessage = str_replace("'", "\'", $confirmMessage);
|
|
|
|
$confirmMessage = str_replace('"', '\"', $confirmMessage);
|
2009-10-17 02:49:44 +00:00
|
|
|
$options['onclick'] = "return confirm('{$confirmMessage}');";
|
|
|
|
} elseif (isset($options['default']) && $options['default'] == false) {
|
|
|
|
if (isset($options['onclick'])) {
|
|
|
|
$options['onclick'] .= ' event.returnValue = false; return false;';
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
2009-10-17 02:49:44 +00:00
|
|
|
$options['onclick'] = 'event.returnValue = false; return false;';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-10-17 02:49:44 +00:00
|
|
|
unset($options['default']);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
return sprintf($this->_tags['link'], $url, $this->_parseAttributes($options), $title);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Creates a link element for CSS stylesheets.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-10-17 03:00:31 +00:00
|
|
|
*
|
2009-11-06 14:31:57 +00:00
|
|
|
* - `inline` If set to false, the generated tag appears in the head tag of the layout. Defaults to true
|
2009-10-17 03:00:31 +00:00
|
|
|
*
|
2009-07-04 22:04:40 +00:00
|
|
|
* @param mixed $path The name of a CSS style sheet or an array containing names of
|
2009-05-22 01:25:13 +00:00
|
|
|
* 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 string $rel Rel attribute. Defaults to "stylesheet". If equal to 'import' the stylesheet will be imported.
|
2009-10-17 03:11:13 +00:00
|
|
|
* @param array $options Array of HTML attributes.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string CSS <link /> or <style /> tag, depending on the type of link.
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1437/css
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function css($path, $rel = null, $options = array()) {
|
2009-11-06 14:31:57 +00:00
|
|
|
$options += array('inline' => true);
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_array($path)) {
|
|
|
|
$out = '';
|
|
|
|
foreach ($path as $i) {
|
2009-11-06 14:31:57 +00:00
|
|
|
$out .= "\n\t" . $this->css($i, $rel, $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-11-06 14:31:57 +00:00
|
|
|
if ($options['inline']) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $out . "\n";
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($path, '://') !== false) {
|
|
|
|
$url = $path;
|
|
|
|
} else {
|
2008-11-08 12:34:51 +00:00
|
|
|
if ($path[0] !== '/') {
|
2008-05-30 11:40:08 +00:00
|
|
|
$path = CSS_URL . $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($path, '?') === false) {
|
2009-10-02 16:53:20 +00:00
|
|
|
if (substr($path, -4) !== '.css') {
|
2008-06-20 11:57:56 +00:00
|
|
|
$path .= '.css';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-09 03:36:04 +00:00
|
|
|
$url = $this->assetTimestamp($this->webroot($path));
|
2009-01-14 22:19:11 +00:00
|
|
|
|
|
|
|
if (Configure::read('Asset.filter.css')) {
|
2009-09-26 18:22:12 +00:00
|
|
|
$pos = strpos($url, CSS_URL);
|
|
|
|
if ($pos !== false) {
|
|
|
|
$url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(CSS_URL));
|
|
|
|
}
|
2009-01-14 22:19:11 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($rel == 'import') {
|
2011-01-23 14:38:36 +00:00
|
|
|
$out = sprintf($this->_tags['style'], $this->_parseAttributes($options, array('inline'), '', ' '), '@import url(' . $url . ');');
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
|
|
|
if ($rel == null) {
|
|
|
|
$rel = 'stylesheet';
|
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
$out = sprintf($this->_tags['css'], $rel, $url, $this->_parseAttributes($options, array('inline'), '', ' '));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-06 14:31:57 +00:00
|
|
|
if ($options['inline']) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $out;
|
|
|
|
} else {
|
2010-07-15 02:26:42 +00:00
|
|
|
$this->_View->addScript($out);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 22:59:05 +00:00
|
|
|
* Returns one or many `<script>` tags depending on the number of scripts given.
|
2009-03-12 23:51:30 +00:00
|
|
|
*
|
|
|
|
* If the filename is prefixed with "/", the path will be relative to the base path of your
|
|
|
|
* application. Otherwise, the path will be relative to your JavaScript path, usually webroot/js.
|
|
|
|
*
|
|
|
|
* Can include one or many Javascript files.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-09-03 17:45:39 +00:00
|
|
|
*
|
|
|
|
* - `inline` - Whether script should be output inline or into scripts_for_layout.
|
|
|
|
* - `once` - Whether or not the script should be checked for uniqueness. If true scripts will only be
|
2009-03-12 23:51:30 +00:00
|
|
|
* included once, use false to allow the same script to be included more than once per request.
|
2009-09-03 17:45:39 +00:00
|
|
|
*
|
|
|
|
* @param mixed $url String or array of javascript files to include
|
|
|
|
* @param mixed $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return mixed String of `<script />` tags or null if $inline is false or if $once is true and the file has been
|
2009-03-12 23:51:30 +00:00
|
|
|
* included before.
|
2010-01-25 22:59:05 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1589/script
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function script($url, $options = array()) {
|
2009-09-03 17:45:39 +00:00
|
|
|
if (is_bool($options)) {
|
|
|
|
list($inline, $options) = array($options, array());
|
|
|
|
$options['inline'] = $inline;
|
|
|
|
}
|
|
|
|
$options = array_merge(array('inline' => true, 'once' => true), $options);
|
2009-03-12 23:51:30 +00:00
|
|
|
if (is_array($url)) {
|
|
|
|
$out = '';
|
|
|
|
foreach ($url as $i) {
|
2009-09-03 17:45:39 +00:00
|
|
|
$out .= "\n\t" . $this->script($i, $options);
|
2009-03-12 23:51:30 +00:00
|
|
|
}
|
2009-09-03 17:45:39 +00:00
|
|
|
if ($options['inline']) {
|
2009-03-12 23:51:30 +00:00
|
|
|
return $out . "\n";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2009-09-03 17:45:39 +00:00
|
|
|
if ($options['once'] && isset($this->__includedScripts[$url])) {
|
2009-07-25 19:43:26 +00:00
|
|
|
return null;
|
2009-03-12 23:51:30 +00:00
|
|
|
}
|
|
|
|
$this->__includedScripts[$url] = true;
|
|
|
|
|
|
|
|
if (strpos($url, '://') === false) {
|
|
|
|
if ($url[0] !== '/') {
|
|
|
|
$url = JS_URL . $url;
|
|
|
|
}
|
2010-07-28 20:41:00 +00:00
|
|
|
if (strpos($url, '?') === false && substr($url, -3) !== '.js') {
|
2009-09-24 04:16:19 +00:00
|
|
|
$url .= '.js';
|
2009-03-12 23:51:30 +00:00
|
|
|
}
|
2010-04-09 03:36:04 +00:00
|
|
|
$url = $this->assetTimestamp($this->webroot($url));
|
2009-03-12 23:51:30 +00:00
|
|
|
|
|
|
|
if (Configure::read('Asset.filter.js')) {
|
|
|
|
$url = str_replace(JS_URL, 'cjs/', $url);
|
|
|
|
}
|
|
|
|
}
|
2009-11-06 14:31:57 +00:00
|
|
|
$attributes = $this->_parseAttributes($options, array('inline', 'once'), ' ');
|
2011-01-23 14:38:36 +00:00
|
|
|
$out = sprintf($this->_tags['javascriptlink'], $url, $attributes);
|
2009-03-12 23:51:30 +00:00
|
|
|
|
2009-11-06 14:31:57 +00:00
|
|
|
if ($options['inline']) {
|
2009-03-12 23:51:30 +00:00
|
|
|
return $out;
|
|
|
|
} else {
|
2010-07-15 02:26:42 +00:00
|
|
|
$this->_View->addScript($out);
|
2009-03-12 23:51:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-03-13 02:59:55 +00:00
|
|
|
/**
|
|
|
|
* Wrap $script in a script tag.
|
|
|
|
*
|
2009-07-30 02:48:40 +00:00
|
|
|
* ### Options
|
|
|
|
*
|
|
|
|
* - `safe` (boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
|
|
|
|
* - `inline` (boolean) Whether or not the $script should be added to $scripts_for_layout or output inline
|
|
|
|
*
|
2009-03-13 02:59:55 +00:00
|
|
|
* @param string $script The script to wrap
|
|
|
|
* @param array $options The options to use.
|
2009-10-17 02:15:57 +00:00
|
|
|
* @return mixed string or null depending on the value of `$options['inline']`
|
2010-01-25 22:59:05 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1604/scriptBlock
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function scriptBlock($script, $options = array()) {
|
2009-11-06 14:31:57 +00:00
|
|
|
$options += array('safe' => true, 'inline' => true);
|
2009-03-13 02:59:55 +00:00
|
|
|
if ($options['safe']) {
|
|
|
|
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
|
|
|
|
}
|
2009-09-03 17:50:53 +00:00
|
|
|
$inline = $options['inline'];
|
|
|
|
unset($options['inline'], $options['safe']);
|
|
|
|
$attributes = $this->_parseAttributes($options, ' ', ' ');
|
|
|
|
if ($inline) {
|
2011-01-23 14:38:36 +00:00
|
|
|
return sprintf($this->_tags['javascriptblock'], $attributes, $script);
|
2009-03-13 02:59:55 +00:00
|
|
|
} else {
|
2011-01-23 14:38:36 +00:00
|
|
|
$this->_View->addScript(sprintf($this->_tags['javascriptblock'], $attributes, $script));
|
2009-03-13 02:59:55 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-07-25 19:43:26 +00:00
|
|
|
/**
|
|
|
|
* Begin a script block that captures output until HtmlHelper::scriptEnd()
|
|
|
|
* is called. This capturing block will capture all output between the methods
|
|
|
|
* and create a scriptBlock from it.
|
|
|
|
*
|
|
|
|
* ### Options
|
|
|
|
*
|
|
|
|
* - `safe` Whether the code block should contain a CDATA
|
|
|
|
* - `inline` Should the generated script tag be output inline or in `$scripts_for_layout`
|
|
|
|
*
|
|
|
|
* @param array $options Options for the code block.
|
|
|
|
* @return void
|
2010-01-25 22:59:05 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1605/scriptStart
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function scriptStart($options = array()) {
|
2009-11-06 14:31:57 +00:00
|
|
|
$options += array('safe' => true, 'inline' => true);
|
2009-07-25 19:43:26 +00:00
|
|
|
$this->_scriptBlockOptions = $options;
|
|
|
|
ob_start();
|
|
|
|
return null;
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-07-25 19:43:26 +00:00
|
|
|
/**
|
|
|
|
* End a Buffered section of Javascript capturing.
|
|
|
|
* Generates a script tag inline or in `$scripts_for_layout` depending on the settings
|
2009-07-30 02:48:40 +00:00
|
|
|
* used when the scriptBlock was started
|
2009-07-25 19:43:26 +00:00
|
|
|
*
|
|
|
|
* @return mixed depending on the settings of scriptStart() either a script tag or null
|
2010-01-25 22:59:05 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1606/scriptEnd
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function scriptEnd() {
|
2009-07-25 19:43:26 +00:00
|
|
|
$buffer = ob_get_clean();
|
|
|
|
$options = $this->_scriptBlockOptions;
|
|
|
|
$this->_scriptBlockOptions = array();
|
|
|
|
return $this->scriptBlock($buffer, $options);
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-03-12 23:51:30 +00:00
|
|
|
/**
|
2008-05-30 11:40:08 +00:00
|
|
|
* Builds CSS style data from an array of CSS properties
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Usage:
|
|
|
|
*
|
|
|
|
* {{{
|
|
|
|
* echo $html->style(array('margin' => '10px', 'padding' => '10px'), true);
|
2010-07-28 20:41:00 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* // creates
|
|
|
|
* 'margin:10px;padding:10px;'
|
|
|
|
* }}}
|
|
|
|
*
|
|
|
|
* @param array $data Style data array, keys will be used as property names, values as property values.
|
2009-10-17 03:19:46 +00:00
|
|
|
* @param boolean $oneline Whether or not the style block should be displayed on one line.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string CSS styling data
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1440/style
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function style($data, $oneline = true) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!is_array($data)) {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
$out = array();
|
|
|
|
foreach ($data as $key=> $value) {
|
|
|
|
$out[] = $key.':'.$value.';';
|
|
|
|
}
|
2009-10-17 03:11:13 +00:00
|
|
|
if ($oneline) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return join(' ', $out);
|
|
|
|
}
|
2009-11-19 22:13:35 +00:00
|
|
|
return implode("\n", $out);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the breadcrumb trail as a sequence of »-separated links.
|
|
|
|
*
|
2009-10-17 02:10:01 +00:00
|
|
|
* @param string $separator Text to separate crumbs.
|
|
|
|
* @param string $startText This will be the first crumb, if false it defaults to first crumb in array
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return string Composed bread crumbs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function getCrumbs($separator = '»', $startText = false) {
|
2009-11-21 20:14:21 +00:00
|
|
|
if (!empty($this->_crumbs)) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$out = array();
|
|
|
|
if ($startText) {
|
|
|
|
$out[] = $this->link($startText, '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->_crumbs as $crumb) {
|
|
|
|
if (!empty($crumb[1])) {
|
|
|
|
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
|
|
|
} else {
|
|
|
|
$out[] = $crumb[0];
|
|
|
|
}
|
|
|
|
}
|
2009-11-21 21:43:54 +00:00
|
|
|
return join($separator, $out);
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-27 16:07:19 +00:00
|
|
|
/**
|
|
|
|
* Returns breadcrumbs as a (x)html list
|
2010-06-29 02:53:33 +00:00
|
|
|
*
|
2010-06-27 16:07:19 +00:00
|
|
|
* This method uses HtmlHelper::tag() to generate list and its elements. Works
|
|
|
|
* similiary to HtmlHelper::getCrumbs(), so it uses options which every
|
|
|
|
* crumb was added with.
|
2010-06-29 02:53:33 +00:00
|
|
|
*
|
|
|
|
* @param array $options Array of html attributes to apply to the generated list elements.
|
2010-06-27 16:07:19 +00:00
|
|
|
* @return string breadcrumbs html list
|
|
|
|
* @access public
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function getCrumbList($options = array()) {
|
2010-06-29 02:53:33 +00:00
|
|
|
if (!empty($this->_crumbs)) {
|
|
|
|
$result = '';
|
|
|
|
$crumbCount = count($this->_crumbs);
|
2010-06-29 03:45:36 +00:00
|
|
|
$ulOptions = $options;
|
2010-06-29 02:53:33 +00:00
|
|
|
foreach ($this->_crumbs as $which => $crumb) {
|
|
|
|
$options = array();
|
|
|
|
if (empty($crumb[1])) {
|
|
|
|
$elementContent = $crumb[0];
|
|
|
|
} else {
|
|
|
|
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
|
|
|
}
|
|
|
|
if ($which == 0) {
|
|
|
|
$options['class'] = 'first';
|
|
|
|
} elseif ($which == $crumbCount - 1) {
|
|
|
|
$options['class'] = 'last';
|
|
|
|
}
|
|
|
|
$result .= $this->tag('li', $elementContent, $options);
|
|
|
|
}
|
2010-06-29 03:45:36 +00:00
|
|
|
return $this->tag('ul', $result, $ulOptions);
|
2010-06-29 02:53:33 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2011-04-17 11:13:02 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 22:59:05 +00:00
|
|
|
* Creates a formatted IMG element. If `$options['url']` is provided, an image link will be
|
2009-10-17 03:11:13 +00:00
|
|
|
* generated with the link pointed at `$options['url']`. This method will set an empty
|
|
|
|
* alt attribute if one is not supplied.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Usage
|
|
|
|
*
|
|
|
|
* Create a regular image:
|
|
|
|
*
|
|
|
|
* `echo $html->image('cake_icon.png', array('alt' => 'CakePHP'));`
|
|
|
|
*
|
|
|
|
* Create an image link:
|
|
|
|
*
|
|
|
|
* `echo $html->image('cake_icon.png', array('alt' => 'CakePHP', 'url' => 'http://cakephp.org'));`
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $path Path to the image file, relative to the app/webroot/img/ directory.
|
2009-10-17 02:10:01 +00:00
|
|
|
* @param array $options Array of HTML attributes.
|
2009-03-12 23:34:04 +00:00
|
|
|
* @return string completed img tag
|
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1441/image
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function image($path, $options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_array($path)) {
|
2008-06-11 02:10:32 +00:00
|
|
|
$path = $this->url($path);
|
2009-01-14 22:19:11 +00:00
|
|
|
} elseif (strpos($path, '://') === false) {
|
2009-09-21 21:00:52 +00:00
|
|
|
if ($path[0] !== '/') {
|
|
|
|
$path = IMAGES_URL . $path;
|
|
|
|
}
|
2010-04-09 03:36:04 +00:00
|
|
|
$path = $this->assetTimestamp($this->webroot($path));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($options['alt'])) {
|
|
|
|
$options['alt'] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$url = false;
|
|
|
|
if (!empty($options['url'])) {
|
|
|
|
$url = $options['url'];
|
|
|
|
unset($options['url']);
|
|
|
|
}
|
|
|
|
|
2011-01-23 14:38:36 +00:00
|
|
|
$image = sprintf($this->_tags['image'], $path, $this->_parseAttributes($options, null, '', ' '));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if ($url) {
|
2011-01-23 14:38:36 +00:00
|
|
|
return sprintf($this->_tags['link'], $this->url($url), null, $image);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-11-21 21:43:54 +00:00
|
|
|
return $image;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a row of formatted and named TABLE headers.
|
|
|
|
*
|
2009-03-12 23:34:04 +00:00
|
|
|
* @param array $names Array of tablenames.
|
|
|
|
* @param array $trOptions HTML options for TR elements.
|
|
|
|
* @param array $thOptions HTML options for TH elements.
|
|
|
|
* @return string Completed table headers
|
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1446/tableHeaders
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function tableHeaders($names, $trOptions = null, $thOptions = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$out = array();
|
|
|
|
foreach ($names as $arg) {
|
2011-01-23 14:38:36 +00:00
|
|
|
$out[] = sprintf($this->_tags['tableheader'], $this->_parseAttributes($thOptions), $arg);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a formatted string of table rows (TR's with TD's in them).
|
|
|
|
*
|
2009-10-17 02:10:01 +00:00
|
|
|
* @param array $data Array of table data
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param array $oddTrOptions HTML options for odd TR elements if true useCount is used
|
|
|
|
* @param array $evenTrOptions HTML options for even TR elements
|
|
|
|
* @param bool $useCount adds class "column-$i"
|
2009-10-17 02:15:57 +00:00
|
|
|
* @param bool $continueOddEven If false, will use a non-static $count variable,
|
|
|
|
* so that the odd/even count is reset to zero just for that call.
|
|
|
|
* @return string Formatted HTML
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1447/tableCells
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (empty($data[0]) || !is_array($data[0])) {
|
|
|
|
$data = array($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oddTrOptions === true) {
|
|
|
|
$useCount = true;
|
|
|
|
$oddTrOptions = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($evenTrOptions === false) {
|
|
|
|
$continueOddEven = false;
|
|
|
|
$evenTrOptions = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($continueOddEven) {
|
|
|
|
static $count = 0;
|
|
|
|
} else {
|
|
|
|
$count = 0;
|
2008-06-20 11:57:56 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
foreach ($data as $line) {
|
|
|
|
$count++;
|
|
|
|
$cellsOut = array();
|
|
|
|
$i = 0;
|
|
|
|
foreach ($line as $cell) {
|
|
|
|
$cellOptions = array();
|
|
|
|
|
|
|
|
if (is_array($cell)) {
|
|
|
|
$cellOptions = $cell[1];
|
|
|
|
$cell = $cell[0];
|
|
|
|
} elseif ($useCount) {
|
|
|
|
$cellOptions['class'] = 'column-' . ++$i;
|
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
$cellsOut[] = sprintf($this->_tags['tablecell'], $this->_parseAttributes($cellOptions), $cell);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
$options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions);
|
2011-01-23 14:38:36 +00:00
|
|
|
$out[] = sprintf($this->_tags['tablerow'], $options, implode(' ', $cellsOut));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-11-21 21:43:54 +00:00
|
|
|
return implode("\n", $out);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a formatted block tag, i.e DIV, SPAN, P.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-08-27 02:54:23 +00:00
|
|
|
*
|
|
|
|
* - `escape` Whether or not the contents should be html_entity escaped.
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $name Tag name.
|
|
|
|
* @param string $text String content that will appear inside the div element.
|
2009-02-03 18:48:28 +00:00
|
|
|
* If null, only a start tag will be printed
|
2009-10-17 03:11:13 +00:00
|
|
|
* @param array $options Additional HTML attributes of the DIV tag, see above.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string The formatted tag element
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1443/tag
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function tag($name, $text = null, $options = array()) {
|
2009-10-17 03:11:13 +00:00
|
|
|
if (is_array($options) && isset($options['escape']) && $options['escape']) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$text = h($text);
|
2009-10-17 03:11:13 +00:00
|
|
|
unset($options['escape']);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-10-17 03:11:13 +00:00
|
|
|
if (!is_array($options)) {
|
|
|
|
$options = array('class' => $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if ($text === null) {
|
|
|
|
$tag = 'tagstart';
|
|
|
|
} else {
|
|
|
|
$tag = 'tag';
|
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
return sprintf($this->_tags[$tag], $name, $this->_parseAttributes($options, null, ' ', ''), $text, $name);
|
2008-06-20 11:57:56 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-23 14:25:52 +00:00
|
|
|
/**
|
|
|
|
* Returns a formatted existent block of $tags
|
|
|
|
*
|
|
|
|
* @param string $tag Tag name
|
|
|
|
* @return string Formatted block
|
|
|
|
*/
|
|
|
|
public function useTag($tag) {
|
2011-01-23 14:38:36 +00:00
|
|
|
if (!isset($this->_tags[$tag])) {
|
2011-01-23 14:25:52 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$args = func_get_args();
|
|
|
|
array_shift($args);
|
|
|
|
foreach ($args as &$arg) {
|
|
|
|
if (is_array($arg)) {
|
|
|
|
$arg = $this->_parseAttributes($arg, null, ' ', '');
|
|
|
|
}
|
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
return vsprintf($this->_tags[$tag], $args);
|
2008-06-20 11:57:56 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a formatted DIV tag for HTML FORMs.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-10-17 03:11:13 +00:00
|
|
|
*
|
|
|
|
* - `escape` Whether or not the contents should be html_entity escaped.
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $class CSS class name of the div element.
|
|
|
|
* @param string $text String content that will appear inside the div element.
|
2009-02-03 18:48:28 +00:00
|
|
|
* If null, only a start tag will be printed
|
2009-10-17 03:19:46 +00:00
|
|
|
* @param array $options Additional HTML attributes of the DIV tag
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string The formatted DIV element
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1444/div
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function div($class = null, $text = null, $options = array()) {
|
2009-10-17 03:11:13 +00:00
|
|
|
if (!empty($class)) {
|
|
|
|
$options['class'] = $class;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-10-17 03:11:13 +00:00
|
|
|
return $this->tag('div', $text, $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a formatted P tag.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-10-17 03:14:42 +00:00
|
|
|
*
|
|
|
|
* - `escape` Whether or not the contents should be html_entity escaped.
|
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $class CSS class name of the p element.
|
|
|
|
* @param string $text String content that will appear inside the p element.
|
2009-10-17 03:19:46 +00:00
|
|
|
* @param array $options Additional HTML attributes of the P tag
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string The formatted P element
|
2009-03-12 23:34:04 +00:00
|
|
|
* @access public
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1445/para
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function para($class, $text, $options = array()) {
|
2009-10-17 03:14:42 +00:00
|
|
|
if (isset($options['escape'])) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$text = h($text);
|
|
|
|
}
|
|
|
|
if ($class != null && !empty($class)) {
|
2009-10-17 03:14:42 +00:00
|
|
|
$options['class'] = $class;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if ($text === null) {
|
|
|
|
$tag = 'parastart';
|
|
|
|
} else {
|
|
|
|
$tag = 'para';
|
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Build a nested list (UL/OL) out of an associative array.
|
|
|
|
*
|
|
|
|
* @param array $list Set of elements to list
|
2009-10-17 03:14:42 +00:00
|
|
|
* @param array $options Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
|
|
|
|
* @param array $itemOptions Additional HTML attributes of the list item (LI) tag
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $tag Type of list tag to use (ol/ul)
|
|
|
|
* @return string The nested list
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function nestedList($list, $options = array(), $itemOptions = array(), $tag = 'ul') {
|
2009-10-17 03:14:42 +00:00
|
|
|
if (is_string($options)) {
|
|
|
|
$tag = $options;
|
|
|
|
$options = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-10-17 03:14:42 +00:00
|
|
|
$items = $this->__nestedListItem($list, $options, $itemOptions, $tag);
|
2011-01-23 14:38:36 +00:00
|
|
|
return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $items);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Internal function to build a nested list (UL/OL) out of an associative array.
|
|
|
|
*
|
2010-12-08 17:41:28 +00:00
|
|
|
* @param array $items Set of elements to list
|
2009-10-17 03:14:42 +00:00
|
|
|
* @param array $options Additional HTML attributes of the list (ol/ul) tag
|
|
|
|
* @param array $itemOptions Additional HTML attributes of the list item (LI) tag
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $tag Type of list tag to use (ol/ul)
|
|
|
|
* @return string The nested list element
|
|
|
|
* @access private
|
2009-10-17 02:15:57 +00:00
|
|
|
* @see HtmlHelper::nestedList()
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-10-17 03:14:42 +00:00
|
|
|
function __nestedListItem($items, $options, $itemOptions, $tag) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$out = '';
|
|
|
|
|
|
|
|
$index = 1;
|
2008-10-23 00:10:44 +00:00
|
|
|
foreach ($items as $key => $item) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_array($item)) {
|
2009-10-17 03:14:42 +00:00
|
|
|
$item = $key . $this->nestedList($item, $options, $itemOptions, $tag);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-10-17 03:14:42 +00:00
|
|
|
if (isset($itemOptions['even']) && $index % 2 == 0) {
|
|
|
|
$itemOptions['class'] = $itemOptions['even'];
|
|
|
|
} else if (isset($itemOptions['odd']) && $index % 2 != 0) {
|
|
|
|
$itemOptions['class'] = $itemOptions['odd'];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-01-23 14:38:36 +00:00
|
|
|
$out .= sprintf($this->_tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd'), ' ', ''), $item);
|
2008-05-30 11:40:08 +00:00
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2011-01-23 14:36:14 +00:00
|
|
|
|
2011-01-23 18:21:17 +00:00
|
|
|
/**
|
2011-01-23 21:27:50 +00:00
|
|
|
* Load Html configs
|
2011-01-23 18:21:17 +00:00
|
|
|
*
|
2011-01-23 21:27:50 +00:00
|
|
|
* @param mixed $configFile String with the config file (load using PhpReader) or an array with file and reader name
|
|
|
|
* @param string $path Path with config file
|
|
|
|
* @return mixed False to error or loaded configs
|
2011-01-23 18:21:17 +00:00
|
|
|
*/
|
2011-04-17 11:32:08 +00:00
|
|
|
public function loadConfig($configFile, $path = null) {
|
|
|
|
if (!$path) {
|
|
|
|
$path = APP . 'Config' . DS;
|
|
|
|
}
|
2011-01-23 21:27:50 +00:00
|
|
|
$file = null;
|
|
|
|
$reader = 'php';
|
|
|
|
|
|
|
|
if (!is_array($configFile)) {
|
|
|
|
$file = $configFile;
|
|
|
|
} elseif (isset($configFile[0])) {
|
|
|
|
$file = $configFile[0];
|
|
|
|
if (isset($configFile[1])) {
|
|
|
|
$reader = $configFile[1];
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-20 15:35:43 +00:00
|
|
|
throw new ConfigureException(__d('cake_dev', 'Cannot load the configuration file. Wrong "configFile" configuration.'));
|
2011-01-23 21:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$readerClass = Inflector::camelize($reader) . 'Reader';
|
2011-02-14 04:48:10 +00:00
|
|
|
App::uses($readerClass, 'Configure');
|
|
|
|
if (!class_exists($readerClass)) {
|
2011-03-20 15:35:43 +00:00
|
|
|
throw new ConfigureException(__d('cake_dev', 'Cannot load the configuration file. Unknown reader.'));
|
2011-01-23 21:27:50 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 22:00:06 +00:00
|
|
|
$readerObj = new $readerClass($path);
|
|
|
|
$configs = $readerObj->read($file);
|
|
|
|
if (isset($configs['tags']) && is_array($configs['tags'])) {
|
|
|
|
$this->_tags = array_merge($this->_tags, $configs['tags']);
|
|
|
|
}
|
|
|
|
if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) {
|
|
|
|
$this->_minimizedAttributes = array_merge($this->_minimizedAttributes, $configs['minimizedAttributes']);
|
|
|
|
}
|
|
|
|
if (isset($configs['docTypes']) && is_array($configs['docTypes'])) {
|
|
|
|
$this->__docTypes = array_merge($this->__docTypes, $configs['docTypes']);
|
|
|
|
}
|
|
|
|
if (isset($configs['attributeFormat'])) {
|
|
|
|
$this->_attributeFormat = $configs['attributeFormat'];
|
|
|
|
}
|
|
|
|
if (isset($configs['minimizedAttributeFormat'])) {
|
|
|
|
$this->_minimizedAttributeFormat = $configs['minimizedAttributeFormat'];
|
2011-01-23 18:21:17 +00:00
|
|
|
}
|
2011-01-23 21:27:50 +00:00
|
|
|
return $configs;
|
2011-01-23 18:21:17 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 14:36:14 +00:00
|
|
|
/**
|
|
|
|
* Returns a space-delimited string with items of the $options array. If a
|
|
|
|
* key of $options array happens to be one of:
|
|
|
|
*
|
|
|
|
* - 'compact'
|
|
|
|
* - 'checked'
|
|
|
|
* - 'declare'
|
|
|
|
* - 'readonly'
|
|
|
|
* - 'disabled'
|
|
|
|
* - 'selected'
|
|
|
|
* - 'defer'
|
|
|
|
* - 'ismap'
|
|
|
|
* - 'nohref'
|
|
|
|
* - 'noshade'
|
|
|
|
* - 'nowrap'
|
|
|
|
* - 'multiple'
|
|
|
|
* - 'noresize'
|
|
|
|
*
|
|
|
|
* And its value is one of:
|
|
|
|
*
|
|
|
|
* - '1' (string)
|
|
|
|
* - 1 (integer)
|
|
|
|
* - true (boolean)
|
|
|
|
* - 'true' (string)
|
|
|
|
*
|
|
|
|
* Then the value will be reset to be identical with key's name.
|
|
|
|
* If the value is not one of these 3, the parameter is not output.
|
|
|
|
*
|
|
|
|
* 'escape' is a special option in that it controls the conversion of
|
|
|
|
* attributes to their html-entity encoded equivalents. Set to false to disable html-encoding.
|
|
|
|
*
|
|
|
|
* If value for any option key is set to `null` or `false`, that option will be excluded from output.
|
|
|
|
*
|
|
|
|
* @param array $options Array of options.
|
|
|
|
* @param array $exclude Array of options to be excluded, the options here will not be part of the return.
|
|
|
|
* @param string $insertBefore String to be inserted before options.
|
|
|
|
* @param string $insertAfter String to be inserted after options.
|
|
|
|
* @return string Composed attributes.
|
|
|
|
*/
|
2011-05-30 20:26:42 +00:00
|
|
|
protected function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
|
2011-01-23 14:36:14 +00:00
|
|
|
if (is_array($options)) {
|
|
|
|
$options = array_merge(array('escape' => true), $options);
|
|
|
|
|
|
|
|
if (!is_array($exclude)) {
|
|
|
|
$exclude = array();
|
|
|
|
}
|
|
|
|
$filtered = array_diff_key($options, array_merge(array_flip($exclude), array('escape' => true)));
|
|
|
|
$escape = $options['escape'];
|
|
|
|
$attributes = array();
|
|
|
|
|
|
|
|
foreach ($filtered as $key => $value) {
|
|
|
|
if ($value !== false && $value !== null) {
|
|
|
|
$attributes[] = $this->_formatAttribute($key, $value, $escape);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$out = implode(' ', $attributes);
|
|
|
|
} else {
|
|
|
|
$out = $options;
|
|
|
|
}
|
|
|
|
return $out ? $insertBefore . $out . $insertAfter : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats an individual attribute, and returns the string value of the composed attribute.
|
|
|
|
* Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
|
|
|
|
*
|
|
|
|
* @param string $key The name of the attribute to create
|
|
|
|
* @param string $value The value of the attribute to create.
|
|
|
|
* @return string The composed attribute.
|
|
|
|
*/
|
|
|
|
protected function _formatAttribute($key, $value, $escape = true) {
|
|
|
|
$attribute = '';
|
|
|
|
if (is_array($value)) {
|
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_numeric($key)) {
|
|
|
|
$attribute = sprintf($this->_minimizedAttributeFormat, $value, $value);
|
|
|
|
} elseif (in_array($key, $this->_minimizedAttributes)) {
|
|
|
|
if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
|
|
|
|
$attribute = sprintf($this->_minimizedAttributeFormat, $key, $key);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
|
|
|
|
}
|
|
|
|
return $attribute;
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|