html.php.svn-base
来自「j2me is based on j2mepolish, client & se」· SVN-BASE 代码 · 共 1,235 行 · 第 1/3 页
SVN-BASE
1,235 行
<?php/* SVN FILE: $Id: html.php 4205 2006-12-25 12:36:03Z phpnut $ *//** * Html Helper class file. * * Simplifies the construction of HTML elements. * * CakePHP : Rapid Development Framework <http://www.cakephp.org/> * 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: 4205 $ * @modifiedby $LastChangedBy: phpnut $ * @lastmodified $Date: 2006-12-25 06:36:03 -0600 (Mon, 25 Dec 2006) $ * @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 {/** * Base URL * * @var string * @access public */ var $base = null;/** * URL to current action. * * @var string * @access public */ var $here = null;/** * Parameter array. * * @var array * @access public */ var $params = array();/** * Current action. * * @var string * @access public */ var $action = null;/** * Controller::data; * * @var array * @access public */ var $data = null;/** * Name of model this helper is attached to. * * @var string * @access public */ var $model = null;/** * * @var string * @access public */ var $field = null;/** * Breadcrumbs. * * @var array * @access protected */ var $_crumbs = array();/** * Adds a link to the breadcrumbs array. * * @param string $name Text for link * @param string $link URL for link * @return void * @access public */ function addCrumb($name, $link) { $this->_crumbs[] = array($name, $link); }/** * 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 echos the value, depends on AUTO_OUTPUT and $return. * @access public */ 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" * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function url($url = null, $return = false) { if (isset($this->plugin)) { $base = strip_plugin($this->base, $this->plugin); } else { $base = $this->base; } if (empty($url)) { return $this->here; } elseif($url{0} == '/') { $output = $base . $url; } else { $output = $base . '/' . Inflector::underscore($this->params['controller']) . '/' . $url; } return $this->output($output, $return); }/** * 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 Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $return = false) { if ($escapeTitle === true) { $title = htmlspecialchars($title, ENT_QUOTES); } elseif (is_string($escapeTitle)) { $title = htmlentities($title, ENT_QUOTES); } $url = $url ? $url : $title; if ($confirmMessage) { if ($escapeTitle === true || is_string($escapeTitle)) { $confirmMessage = htmlspecialchars($confirmMessage, ENT_NOQUOTES); } else { $confirmMessage = htmlentities($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) || $url{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 submit widget. * * @param string $caption Text on submit button * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function submit($caption = 'Submit', $htmlAttributes = array(), $return = false) { $htmlAttributes['value'] = $caption; return $this->output(sprintf($this->tags['submit'], $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return); }/** * Creates a password input widget. * * @param string $fieldName Name of a field, like this "Modelname/fieldname" * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function password($fieldName, $htmlAttributes = array(), $return = false) { $this->setFormTag($fieldName); if (!isset($htmlAttributes['value'])) { $htmlAttributes['value'] = $this->tagValue($fieldName); } if (!isset($htmlAttributes['id'])) { $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field); } if ($this->tagIsInvalid($this->model, $this->field)) { if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") { $htmlAttributes['class'] .= ' form_error'; } else { $htmlAttributes['class'] = 'form_error'; } } return $this->output(sprintf($this->tags['password'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return); }/** * Creates a textarea widget. * * @param string $fieldName Name of a field, like this "Modelname/fieldname" * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function textarea($fieldName, $htmlAttributes = array(), $return = false) { $this->setFormTag($fieldName); $value = $this->tagValue($fieldName); if (!empty($htmlAttributes['value'])) { $value = $htmlAttributes['value']; unset($htmlAttributes['value']); } if (!isset($htmlAttributes['id'])) { $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field); } if ($this->tagIsInvalid($this->model, $this->field)) { if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") { $htmlAttributes['class'] .= ' form_error'; } else { $htmlAttributes['class'] = 'form_error'; } } return $this->output(sprintf($this->tags['textarea'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' '), $value), $return); }/** * Creates a checkbox widget. * * @param string $fieldName Name of a field, like this "Modelname/fieldname" * @deprecated string $title * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function checkbox($fieldName, $title = null, $htmlAttributes = array(), $return = false) { $value = $this->tagValue($fieldName); $notCheckedValue = 0; if (!isset($htmlAttributes['id'])) { $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field); } if (isset($htmlAttributes['checked'])) { if ($htmlAttributes['checked'] == 'checked' || intval($htmlAttributes['checked']) === 1 || $htmlAttributes['checked'] === true) { $htmlAttributes['checked'] = 'checked'; } else { $htmlAttributes['checked'] = null; $notCheckedValue = -1; } } else { if (isset($htmlAttributes['value'])) { $htmlAttributes['checked'] = ($htmlAttributes['value'] == $value) ? 'checked' : null; if ($htmlAttributes['value'] == '0') { $notCheckedValue = -1; } } else { $model = new $this->model; $db =& ConnectionManager::getDataSource($model->useDbConfig); $value = $db->boolean($value); $htmlAttributes['checked'] = $value ? 'checked' : null; $htmlAttributes['value'] = 1; } } $output = $this->hidden($fieldName, array('value' => $notCheckedValue, 'id' => $htmlAttributes['id'] . '_'), true); $output .= sprintf($this->tags['checkbox'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' ')); 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. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function css($path, $rel = 'stylesheet', $htmlAttributes = array(), $return = false) { $url = "{$this->webroot}" . (COMPRESS_CSS ? 'c' : '') . $this->themeWeb . CSS_URL . $path . ".css"; if ($rel == 'import') { return $this->output(sprintf($this->tags['style'], $this->parseHtmlOptions($htmlAttributes, null, '', ' '), '@import url(' . $url . ');'), $return); } else { return $this->output(sprintf($this->tags['css'], $rel, $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return); } }/** * Creates file input widget. * * @param string $fieldName Name of a field, like this "Modelname/fieldname" * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a valueor output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function file($fieldName, $htmlAttributes = array(), $return = false) { if (strpos($fieldName, '/')) { $this->setFormTag($fieldName); if (!isset($htmlAttributes['id'])) { $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field); } return $this->output(sprintf($this->tags['file'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return); } return $this->output(sprintf($this->tags['file_no_model'], $fieldName, $this->_parseAttributes($htmlAttributes, null, '', ' ')), $return); }/** * Returns the breadcrumb trail as a sequence of »-separated links. * * @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 * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. If $this->_crumbs is empty, return null. * @access public */ function getCrumbs($separator = '»', $startText = false, $return = false) { if (count($this->_crumbs)) { $out = array(); if ($startText) { $out[] = $this->link($startText, '/'); } foreach($this->_crumbs as $crumb) { $out[] = $this->link($crumb[0], $crumb[1]); } return $this->output(join($separator, $out), $return); } else { return null; } }/** * Creates a hidden input field. * * @param string $fieldName Name of a field, like this "Modelname/fieldname" * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function hidden($fieldName, $htmlAttributes = array(), $return = false) { $this->setFormTag($fieldName); if (!isset($htmlAttributes['value'])) { $htmlAttributes['value'] = $this->tagValue($fieldName); } if (!isset($htmlAttributes['id'])) { $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field); } return $this->output(sprintf($this->tags['hidden'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return); }/** * Creates a formatted IMG element. * * @param string $path Path to the image file, relative to the webroot/img/ directory. * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function image($path, $htmlAttributes = array(), $return = false) { if (strpos($path, '://')) { $url = $path; } else { $url = $this->webroot . $this->themeWeb . IMAGES_URL . $path; } return $this->output(sprintf($this->tags['image'], $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')), $return); }/** * Creates a text input widget. * * @param string $fieldNamem Name of a field, like this "Modelname/fieldname" * @param array $htmlAttributes Array of HTML attributes. * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */ function input($fieldName, $htmlAttributes = array(), $return = false) { $this->setFormTag($fieldName); if (!isset($htmlAttributes['value'])) { $htmlAttributes['value'] = $this->tagValue($fieldName);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?