2005-08-21 06:49:02 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
|
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Backend for helpers.
|
2005-12-28 17:23:12 +00:00
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* Internal methods for the Helpers.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-12-28 17:23:12 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-28 17:23:12 +00:00
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
|
|
|
|
2006-10-27 21:40:34 +00:00
|
|
|
/**
|
|
|
|
* Included libs
|
|
|
|
*/
|
|
|
|
uses('overloadable');
|
|
|
|
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
|
|
|
* Backend for helpers.
|
|
|
|
*
|
|
|
|
* Long description for class
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view
|
2005-08-21 06:49:02 +00:00
|
|
|
*/
|
2006-10-27 21:40:34 +00:00
|
|
|
class Helper extends Overloadable {
|
2005-08-21 06:49:02 +00:00
|
|
|
|
2006-11-25 08:55:16 +00:00
|
|
|
/**
|
|
|
|
* List of helpers used by this helper
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $helpers = null;
|
2006-09-28 22:27:31 +00:00
|
|
|
/**
|
|
|
|
* Base URL
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $base = null;
|
2006-11-25 08:55:16 +00:00
|
|
|
/**
|
|
|
|
* Webroot path
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $webroot = null;
|
|
|
|
/**
|
|
|
|
* Theme name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $themeWeb = null;
|
2006-09-28 22:27:31 +00:00
|
|
|
/**
|
|
|
|
* URL to current action.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $here = null;
|
|
|
|
/**
|
|
|
|
* Parameter array.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $params = array();
|
|
|
|
/**
|
|
|
|
* Current action.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $action = null;
|
|
|
|
/**
|
2006-11-25 08:55:16 +00:00
|
|
|
* Plugin path
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $plugin = null;
|
|
|
|
/**
|
|
|
|
* POST data for models
|
2006-09-28 22:27:31 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $data = null;
|
2006-11-25 08:55:16 +00:00
|
|
|
/**
|
|
|
|
* List of named arguments
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $namedArgs = null;
|
|
|
|
/**
|
|
|
|
* URL argument separator character
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $argSeparator = null;
|
|
|
|
/**
|
|
|
|
* Contains model validation errors of form post-backs
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $validationErrors = null;
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2005-12-27 03:33:44 +00:00
|
|
|
* Holds tag templates.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
2006-11-22 03:51:21 +00:00
|
|
|
var $tags = array();
|
2007-03-05 12:13:37 +00:00
|
|
|
/**
|
|
|
|
* Holds the content to be cleaned.
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
var $__tainted = null;
|
|
|
|
/**
|
|
|
|
* Holds the cleaned content.
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
var $__cleaned = null;
|
2006-11-23 22:48:47 +00:00
|
|
|
/**
|
|
|
|
* Default overload methods
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
*/
|
2006-11-25 08:55:16 +00:00
|
|
|
function get__($name) {}
|
|
|
|
function set__($name, $value) {}
|
2006-12-26 16:17:37 +00:00
|
|
|
function call__($method, $params) {
|
2007-03-06 20:56:45 +00:00
|
|
|
trigger_error(sprintf(__('Method %1$s::%2$s does not exist', true), get_class($this), $method), E_USER_WARNING);
|
2006-11-23 22:48:47 +00:00
|
|
|
}
|
2006-11-22 03:16:34 +00:00
|
|
|
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2005-12-27 03:33:44 +00:00
|
|
|
* Parses tag templates into $this->tags.
|
|
|
|
*
|
2007-03-05 13:48:21 +00:00
|
|
|
* @param $name file name
|
|
|
|
* @return array merged tags from config/$name.php
|
|
|
|
*/
|
|
|
|
function loadConfig($name = 'tags') {
|
|
|
|
if (file_exists(APP . 'config' . DS . $name .'.php')) {
|
|
|
|
require(APP . 'config' . DS . $name .'.php');
|
2007-06-20 06:15:35 +00:00
|
|
|
if (isset($tags)) {
|
2007-12-08 06:08:03 +00:00
|
|
|
$this->tags = array_merge($this->tags, $tags);
|
2007-03-05 13:48:21 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2006-11-22 03:16:34 +00:00
|
|
|
return $this->tags;
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
/**
|
|
|
|
* 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 mixed $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4"
|
|
|
|
* or an array specifying any of the following: 'controller', 'action',
|
|
|
|
* and/or 'plugin', in addition to named arguments (keyed array elements),
|
|
|
|
* and standard URL arguments (indexed array elements)
|
2007-10-22 16:54:36 +00:00
|
|
|
* @param boolean $full If true, the full base URL will be prepended to the result
|
2006-08-30 16:23:24 +00:00
|
|
|
* @return string Full translated URL with base path.
|
|
|
|
*/
|
|
|
|
function url($url = null, $full = false) {
|
2006-10-18 18:07:55 +00:00
|
|
|
return Router::url($url, $full);
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
2007-02-08 07:42:23 +00:00
|
|
|
/**
|
|
|
|
* Checks if a file exists when theme is used, if no file is found default location is returned
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return string $webPath web path to file.
|
|
|
|
*/
|
|
|
|
function webroot($file) {
|
|
|
|
$webPath = "{$this->webroot}" . $file;
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($this->themeWeb)) {
|
2007-02-08 07:42:23 +00:00
|
|
|
$os = env('OS');
|
|
|
|
if (!empty($os) && strpos($os, 'Windows') !== false) {
|
|
|
|
$path = str_replace('/', '\\', WWW_ROOT . $this->themeWeb . $file);
|
|
|
|
} else {
|
|
|
|
$path = WWW_ROOT . $this->themeWeb . $file;
|
|
|
|
}
|
2007-06-20 07:51:52 +00:00
|
|
|
if (file_exists($path)) {
|
2007-02-08 07:42:23 +00:00
|
|
|
$webPath = "{$this->webroot}" . $this->themeWeb . $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $webPath;
|
|
|
|
}
|
|
|
|
|
2007-03-05 12:13:37 +00:00
|
|
|
/**
|
|
|
|
* Used to remove harmful tags from content
|
|
|
|
*
|
|
|
|
* @param mixed $output
|
|
|
|
* @return cleaned content for output
|
|
|
|
* @access public
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function clean($output) {
|
2007-03-05 12:13:37 +00:00
|
|
|
$this->__reset();
|
|
|
|
if (is_array($output)) {
|
|
|
|
foreach ($output as $key => $value) {
|
|
|
|
$return[$key] = $this->clean($value);
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
$this->__tainted = $output;
|
|
|
|
$this->__clean();
|
|
|
|
return $this->__cleaned;
|
|
|
|
}
|
2006-08-30 16:23:24 +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
|
|
|
|
* + true
|
|
|
|
* + 'true'
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param array $options Array of options.
|
|
|
|
* @param array $exclude Array of options to be excluded.
|
|
|
|
* @param string $insertBefore String to be inserted before options.
|
|
|
|
* @param string $insertAfter String to be inserted ater options.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
|
|
|
|
if (is_array($options)) {
|
2007-12-14 15:07:25 +00:00
|
|
|
$options = array_merge(array('escape' => true), $options);
|
|
|
|
|
2007-03-23 06:36:24 +00:00
|
|
|
if (!is_array($exclude)) {
|
|
|
|
$exclude = array();
|
|
|
|
}
|
2007-12-14 15:07:25 +00:00
|
|
|
$keys = array_diff(array_keys($options), array_merge((array)$exclude, array('escape')));
|
2007-03-23 06:36:24 +00:00
|
|
|
$values = array_intersect_key(array_values($options), $keys);
|
2007-04-28 23:52:19 +00:00
|
|
|
$escape = $options['escape'];
|
|
|
|
$attributes = array();
|
2007-12-14 15:07:25 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($keys as $index => $key) {
|
2007-04-28 23:52:19 +00:00
|
|
|
$attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
|
|
|
|
}
|
|
|
|
$out = implode(' ', $attributes);
|
2007-03-23 06:36:24 +00:00
|
|
|
} else {
|
|
|
|
$out = $options;
|
|
|
|
}
|
|
|
|
return $out ? $insertBefore . $out . $insertAfter : '';
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
* @param string $value
|
|
|
|
* @return string
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-04-28 23:52:19 +00:00
|
|
|
function __formatAttribute($key, $value, $escape = true) {
|
2007-03-23 06:36:24 +00:00
|
|
|
$attribute = '';
|
|
|
|
$attributeFormat = '%s="%s"';
|
|
|
|
$minimizedAttributes = array('compact', 'checked', 'declare', 'readonly', 'disabled', 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
|
2007-12-15 23:00:42 +00:00
|
|
|
if (is_array($value)) {
|
|
|
|
$value = '';
|
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
|
2007-03-23 06:36:24 +00:00
|
|
|
if (in_array($key, $minimizedAttributes)) {
|
|
|
|
if ($value === 1 || $value === true || $value === 'true' || $value == $key) {
|
|
|
|
$attribute = sprintf($attributeFormat, $key, $key);
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-04-28 23:52:19 +00:00
|
|
|
$attribute = sprintf($attributeFormat, $key, ife($escape, h($value), $value));
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
2007-03-23 06:36:24 +00:00
|
|
|
return $attribute;
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
/**
|
2007-11-04 18:07:59 +00:00
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
function setFormTag($tagValue, $setScope = false) {
|
|
|
|
return $this->setEntity($tagValue, $setScope);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Sets this helper's model and field properties to the dot-separated value-pair in $entity.
|
2006-08-30 16:23:24 +00:00
|
|
|
*
|
2007-11-04 18:07:59 +00:00
|
|
|
* @param mixed $entity A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName"
|
|
|
|
* @param boolean $setScope Sets the view scope to the model specified in $tagValue
|
|
|
|
* @return void
|
2006-08-30 16:23:24 +00:00
|
|
|
*/
|
2007-11-04 18:07:59 +00:00
|
|
|
function setEntity($entity, $setScope = false) {
|
2006-11-27 04:45:03 +00:00
|
|
|
$view =& ClassRegistry::getObject('view');
|
2007-06-21 06:47:57 +00:00
|
|
|
|
2007-11-04 18:07:59 +00:00
|
|
|
if ($setScope) {
|
|
|
|
$view->modelScope = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($entity === null) {
|
2007-06-08 01:17:40 +00:00
|
|
|
$view->model = null;
|
|
|
|
$view->association = null;
|
|
|
|
$view->modelId = null;
|
2007-11-04 18:07:59 +00:00
|
|
|
$view->modelScope = false;
|
2007-06-08 01:17:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-06-21 06:47:57 +00:00
|
|
|
|
2007-11-09 00:17:44 +00:00
|
|
|
$sameScope = $hasField = false;
|
2007-11-04 18:07:59 +00:00
|
|
|
$parts = preg_split('/\/|\./', $entity);
|
2007-11-08 00:05:12 +00:00
|
|
|
|
2007-12-12 04:08:19 +00:00
|
|
|
$model = $view->model;
|
2007-12-07 10:55:42 +00:00
|
|
|
if(count($parts) === 1 || is_numeric($parts[0])) {
|
2007-11-12 00:57:38 +00:00
|
|
|
$sameScope = true;
|
2007-12-07 10:55:42 +00:00
|
|
|
} else {
|
2007-12-12 04:08:19 +00:00
|
|
|
if (ClassRegistry::isKeySet($parts[0])) {
|
|
|
|
$model = $parts[0];
|
|
|
|
}
|
2007-11-08 00:05:12 +00:00
|
|
|
}
|
2007-11-04 18:07:59 +00:00
|
|
|
|
2007-12-07 10:55:42 +00:00
|
|
|
if (ClassRegistry::isKeySet($model)) {
|
|
|
|
$ModelObj =& ClassRegistry::getObject($model);
|
2007-12-12 04:08:19 +00:00
|
|
|
for ($i = 0; $i < count($parts); $i++) {
|
2007-12-07 10:55:42 +00:00
|
|
|
if ($ModelObj->hasField($parts[$i]) || array_key_exists($parts[$i], $ModelObj->validate)) {
|
2007-11-04 18:07:59 +00:00
|
|
|
$hasField = $i;
|
2007-12-12 04:08:19 +00:00
|
|
|
if ($hasField === 0) {
|
|
|
|
$sameScope = true;
|
|
|
|
}
|
2007-11-04 18:07:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-07 10:55:42 +00:00
|
|
|
|
|
|
|
if($sameScope === true && in_array($parts[0], array_keys($ModelObj->hasAndBelongsToMany))) {
|
|
|
|
$sameScope = false;
|
|
|
|
}
|
2007-11-04 18:07:59 +00:00
|
|
|
}
|
2007-10-09 20:44:28 +00:00
|
|
|
|
2007-11-09 00:17:44 +00:00
|
|
|
$view->field = $view->modelId = $view->fieldSuffix = $view->association = null;
|
|
|
|
|
|
|
|
switch (count($parts)) {
|
|
|
|
case 1:
|
|
|
|
if($view->modelScope === false) {
|
|
|
|
$view->model = $parts[0];
|
|
|
|
} else {
|
2007-11-04 18:07:59 +00:00
|
|
|
$view->field = $parts[0];
|
2007-11-09 00:17:44 +00:00
|
|
|
if($sameScope === false) {
|
|
|
|
$view->association = $parts[0];
|
2007-11-04 18:07:59 +00:00
|
|
|
}
|
2007-11-09 00:17:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if ($view->modelScope === false) {
|
|
|
|
list($view->model, $view->field) = $parts;
|
|
|
|
} elseif ($sameScope === true && $hasField === 0) {
|
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
|
|
|
list($view->field, $view->fieldSuffix) = $parts;
|
2007-11-09 00:17:44 +00:00
|
|
|
} elseif ($sameScope === true && $hasField === 1) {
|
|
|
|
list($view->modelId, $view->field) = $parts;
|
|
|
|
} else {
|
|
|
|
list($view->association, $view->field) = $parts;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if ($sameScope === true && $hasField === 1) {
|
|
|
|
list($view->modelId, $view->field, $view->fieldSuffix) = $parts;
|
|
|
|
} elseif ($hasField === 2) {
|
|
|
|
list($view->association, $view->modelId, $view->field) = $parts;
|
|
|
|
} else {
|
|
|
|
list($view->association, $view->field, $view->fieldSuffix) = $parts;
|
|
|
|
}
|
|
|
|
break;
|
2007-11-04 18:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($view->model) || empty($view->model)) {
|
2007-06-08 01:17:40 +00:00
|
|
|
$view->model = $view->association;
|
|
|
|
$view->association = null;
|
2007-11-09 00:17:44 +00:00
|
|
|
} elseif ($view->model === $view->association) {
|
2007-11-04 18:07:59 +00:00
|
|
|
$view->association = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($setScope) {
|
|
|
|
$view->modelScope = true;
|
2007-06-08 01:17:40 +00:00
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* Gets the currently-used model of the rendering context.
|
2006-08-30 16:23:24 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function model() {
|
2006-11-27 04:45:03 +00:00
|
|
|
$view =& ClassRegistry::getObject('view');
|
2007-11-04 18:07:59 +00:00
|
|
|
if (!empty($view->association)) {
|
2007-06-08 01:17:40 +00:00
|
|
|
return $view->association;
|
2007-11-04 18:07:59 +00:00
|
|
|
} else {
|
|
|
|
return $view->model;
|
2007-06-08 01:17:40 +00:00
|
|
|
}
|
2007-06-21 06:47:57 +00:00
|
|
|
}
|
2007-04-01 04:55:56 +00:00
|
|
|
/**
|
|
|
|
* Gets the ID of the currently-used model of the rendering context.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function modelID() {
|
|
|
|
$view =& ClassRegistry::getObject('view');
|
|
|
|
return $view->modelId;
|
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
/**
|
2006-11-26 20:43:54 +00:00
|
|
|
* Gets the currently-used model field of the rendering context.
|
2006-08-30 16:23:24 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function field() {
|
2006-11-27 04:45:03 +00:00
|
|
|
$view =& ClassRegistry::getObject('view');
|
2006-11-25 08:55:16 +00:00
|
|
|
return $view->field;
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns false if given FORM field has no errors. Otherwise it returns the constant set in the array Model->validationErrors.
|
|
|
|
*
|
|
|
|
* @param string $model Model name as string
|
|
|
|
* @param string $field Fieldname as string
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True on errors.
|
2006-08-30 16:23:24 +00:00
|
|
|
*/
|
|
|
|
function tagIsInvalid($model = null, $field = null) {
|
|
|
|
if ($model == null) {
|
|
|
|
$model = $this->model();
|
|
|
|
}
|
|
|
|
if ($field == null) {
|
|
|
|
$field = $this->field();
|
|
|
|
}
|
|
|
|
return empty($this->validationErrors[$model][$field]) ? 0 : $this->validationErrors[$model][$field];
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Generates a DOM ID for the selected element, if one is not set.
|
|
|
|
*
|
2007-03-16 23:54:24 +00:00
|
|
|
* @param mixed $options
|
2006-08-30 16:23:24 +00:00
|
|
|
* @param string $id
|
2007-03-16 23:54:24 +00:00
|
|
|
* @return mixed
|
2006-08-30 16:23:24 +00:00
|
|
|
*/
|
2007-03-16 23:54:24 +00:00
|
|
|
function domId($options = null, $id = 'id') {
|
2007-11-04 18:07:59 +00:00
|
|
|
$view =& ClassRegistry::getObject('view');
|
|
|
|
|
2007-11-08 00:05:12 +00:00
|
|
|
if (is_array($options) && array_key_exists($id, $options) && $options[$id] === null) {
|
2007-10-28 05:28:45 +00:00
|
|
|
unset($options[$id]);
|
|
|
|
return $options;
|
2007-11-08 00:05:12 +00:00
|
|
|
} elseif (!is_array($options) && $options !== null) {
|
2007-11-04 18:07:59 +00:00
|
|
|
$this->setEntity($options);
|
2007-11-08 00:05:12 +00:00
|
|
|
return $this->domId();
|
|
|
|
}
|
2007-11-08 01:44:47 +00:00
|
|
|
|
2007-11-08 00:05:12 +00:00
|
|
|
$dom = $this->model() . Inflector::camelize($view->field) . Inflector::camelize($view->fieldSuffix);
|
|
|
|
|
|
|
|
if (is_array($options) && !array_key_exists($id, $options)) {
|
|
|
|
$options[$id] = $dom;
|
|
|
|
} elseif ($options === null) {
|
|
|
|
return $dom;
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
2007-02-26 18:58:18 +00:00
|
|
|
/**
|
|
|
|
* Gets the input field name for the current tag
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param string $key
|
2007-05-01 15:17:27 +00:00
|
|
|
* @return array
|
2007-02-26 18:58:18 +00:00
|
|
|
*/
|
|
|
|
function __name($options = array(), $field = null, $key = 'name') {
|
2007-11-04 18:07:59 +00:00
|
|
|
$view =& ClassRegistry::getObject('view');
|
|
|
|
|
2007-02-26 18:58:18 +00:00
|
|
|
if ($options === null) {
|
|
|
|
$options = array();
|
|
|
|
} elseif (is_string($options)) {
|
|
|
|
$field = $options;
|
|
|
|
$options = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($field)) {
|
2007-11-04 18:07:59 +00:00
|
|
|
$this->setEntity($field);
|
2007-02-26 18:58:18 +00:00
|
|
|
}
|
|
|
|
|
2007-10-28 05:28:45 +00:00
|
|
|
if (is_array($options) && array_key_exists($key, $options)) {
|
2007-02-26 18:58:18 +00:00
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
2007-11-04 18:07:59 +00:00
|
|
|
switch ($field) {
|
2007-02-26 18:58:18 +00:00
|
|
|
case '_method':
|
|
|
|
$name = $field;
|
|
|
|
break;
|
|
|
|
default:
|
2007-11-04 18:07:59 +00:00
|
|
|
$name = 'data[' . join('][', $view->entity()) . ']';
|
2007-02-26 18:58:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($options)) {
|
|
|
|
$options[$key] = $name;
|
|
|
|
return $options;
|
|
|
|
} else {
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
/**
|
|
|
|
* Gets the data for the current tag
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param string $key
|
|
|
|
* @return array
|
2007-05-27 19:54:36 +00:00
|
|
|
* @access public
|
2006-08-30 16:23:24 +00:00
|
|
|
*/
|
2007-05-27 19:54:36 +00:00
|
|
|
function value($options = array(), $field = null, $key = 'value') {
|
2006-10-18 18:07:55 +00:00
|
|
|
if ($options === null) {
|
|
|
|
$options = array();
|
|
|
|
} elseif (is_string($options)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$field = $options;
|
|
|
|
$options = 0;
|
|
|
|
}
|
|
|
|
|
2007-02-26 18:58:18 +00:00
|
|
|
if (!empty($field)) {
|
2007-11-04 18:07:59 +00:00
|
|
|
$this->setEntity($field);
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($options) && isset($options[$key])) {
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = null;
|
2007-10-11 19:55:24 +00:00
|
|
|
|
2006-11-12 00:12:34 +00:00
|
|
|
if (isset($this->data[$this->model()][$this->field()])) {
|
2007-03-25 01:16:29 +00:00
|
|
|
$result = $this->data[$this->model()][$this->field()];
|
2007-02-05 04:53:31 +00:00
|
|
|
} elseif (isset($this->data[$this->field()]) && is_array($this->data[$this->field()])) {
|
|
|
|
if (ClassRegistry::isKeySet($this->field())) {
|
2007-10-11 19:55:24 +00:00
|
|
|
$model =& ClassRegistry::getObject($this->field());
|
|
|
|
$result = $this->__selectedArray($this->data[$this->field()], $model->primaryKey);
|
2007-02-05 04:53:31 +00:00
|
|
|
}
|
2007-11-19 09:05:20 +00:00
|
|
|
} elseif (isset($this->data[$this->model()][$this->modelID()][$this->field()])) {
|
|
|
|
$result = $this->data[$this->model()][$this->modelID()][$this->field()];
|
2006-08-30 16:23:24 +00:00
|
|
|
}
|
|
|
|
|
2007-12-06 01:16:14 +00:00
|
|
|
if (is_array($result)) {
|
|
|
|
$view =& ClassRegistry::getObject('view');
|
|
|
|
if(isset($result[$view->fieldSuffix])) {
|
|
|
|
$result = $result[$view->fieldSuffix];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-23 17:32:02 +00:00
|
|
|
if (is_array($options)) {
|
|
|
|
if (empty($result) && isset($options['default'])) {
|
|
|
|
$result = $options['default'];
|
|
|
|
}
|
|
|
|
unset($options['default']);
|
|
|
|
}
|
|
|
|
|
2006-10-18 18:07:55 +00:00
|
|
|
if (is_array($options)) {
|
2006-08-30 16:23:24 +00:00
|
|
|
$options[$key] = $result;
|
|
|
|
return $options;
|
|
|
|
} else {
|
|
|
|
return $result;
|
|
|
|
}
|
2007-02-26 18:58:18 +00:00
|
|
|
}
|
2007-05-01 15:17:27 +00:00
|
|
|
/**
|
|
|
|
* Sets the defaults for an input tag
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param string $key
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function __initInputField($field, $options = array()) {
|
2007-12-22 04:20:35 +00:00
|
|
|
if ($field !== null) {
|
|
|
|
$this->setEntity($field);
|
|
|
|
}
|
2007-05-01 15:17:27 +00:00
|
|
|
$options = (array)$options;
|
|
|
|
$options = $this->__name($options);
|
2007-05-27 19:54:36 +00:00
|
|
|
$options = $this->value($options);
|
2007-05-01 15:17:27 +00:00
|
|
|
$options = $this->domId($options);
|
|
|
|
if ($this->tagIsInvalid()) {
|
|
|
|
$options = $this->addClass($options, 'form-error');
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
2006-08-30 16:23:24 +00:00
|
|
|
/**
|
|
|
|
* Adds the given class to the element options
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param string $class
|
|
|
|
* @param string $key
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function addClass($options = array(), $class = null, $key = 'class') {
|
|
|
|
if (isset($options[$key]) && trim($options[$key]) != '') {
|
|
|
|
$options[$key] .= ' ' . $class;
|
|
|
|
} else {
|
|
|
|
$options[$key] = $class;
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2006-08-20 21:54:50 +00:00
|
|
|
* Returns a string generated by a helper method
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2006-08-20 21:54:50 +00:00
|
|
|
* This method can be overridden in subclasses to do generalized output post-processing
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2006-08-20 21:54:50 +00:00
|
|
|
* @param string $str String to be output.
|
|
|
|
* @return string
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2006-08-20 21:54:50 +00:00
|
|
|
function output($str) {
|
|
|
|
return $str;
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2005-12-27 03:33:44 +00:00
|
|
|
* Assigns values to tag templates.
|
|
|
|
*
|
|
|
|
* Finds a tag template by $keyName, and replaces $values's keys with
|
|
|
|
* $values's keys.
|
|
|
|
*
|
|
|
|
* @param string $keyName Name of the key in the tag array.
|
|
|
|
* @param array $values Values to be inserted into tag.
|
|
|
|
* @return string Tag with inserted values.
|
|
|
|
*/
|
2006-06-14 18:02:37 +00:00
|
|
|
function assign($keyName, $values) {
|
2007-04-01 04:55:56 +00:00
|
|
|
$out = $keyName;
|
|
|
|
if (isset($this->tags) && isset($this->tags[$keyName])) {
|
|
|
|
$out = $this->tags[$keyName];
|
|
|
|
}
|
2007-05-02 08:07:19 +00:00
|
|
|
|
|
|
|
//$out =
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2006-08-18 08:03:32 +00:00
|
|
|
/**
|
|
|
|
* Before render callback. Overridden in subclasses.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function beforeRender() {
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
/**
|
|
|
|
* After render callback. Overridden in subclasses.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function afterRender() {
|
|
|
|
}
|
2006-08-18 08:03:32 +00:00
|
|
|
/**
|
|
|
|
* Before layout callback. Overridden in subclasses.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function beforeLayout() {
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* After layout callback. Overridden in subclasses.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function afterLayout() {
|
|
|
|
}
|
2007-02-05 04:53:31 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param mixed $data
|
|
|
|
* @param string $key
|
|
|
|
* @return array
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function __selectedArray($data, $key = 'id') {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!is_array($data)) {
|
2007-02-05 04:53:31 +00:00
|
|
|
$model = $data;
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($this->data[$model][$model])) {
|
2007-02-05 04:53:31 +00:00
|
|
|
return $this->data[$model][$model];
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($this->data[$model])) {
|
2007-02-05 04:53:31 +00:00
|
|
|
$data = $this->data[$model];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$array = array();
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($data)) {
|
|
|
|
foreach ($data as $var) {
|
2007-02-05 04:53:31 +00:00
|
|
|
$array[$var[$key]] = $var[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $array;
|
|
|
|
}
|
2007-03-05 12:13:37 +00:00
|
|
|
/**
|
|
|
|
* Resets the vars used by Helper::clean() to null
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __reset() {
|
2007-03-05 12:13:37 +00:00
|
|
|
$this->__tainted = null;
|
|
|
|
$this->__cleaned = null;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Removes harmful content from output
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2007-06-20 07:51:52 +00:00
|
|
|
function __clean() {
|
2007-03-05 12:13:37 +00:00
|
|
|
if (get_magic_quotes_gpc()) {
|
|
|
|
$this->__cleaned = stripslashes($this->__tainted);
|
|
|
|
} else {
|
|
|
|
$this->__cleaned = $this->__tainted;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->__cleaned = str_replace(array("&","<",">"),array("&amp;","&lt;","&gt;"), $this->__cleaned);
|
|
|
|
$this->__cleaned = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"$1;", $this->__cleaned);
|
|
|
|
$this->__cleaned = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"$1$2;", $this->__cleaned);
|
2007-12-09 06:43:44 +00:00
|
|
|
$this->__cleaned = html_entity_decode($this->__cleaned, ENT_COMPAT, "UTF-8");
|
|
|
|
$this->__cleaned = preg_replace('#(<*[^>]*[\x00-\x20\"\'])(on|xmlns)[^>]*>#iUu',"$1>", $this->__cleaned);
|
2007-03-05 12:13:37 +00:00
|
|
|
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*)[\\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu','$1=$2nojavascript...', $this->__cleaned);
|
|
|
|
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=([\'\"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu','$1=$2novbscript...', $this->__cleaned);
|
2007-12-09 06:43:44 +00:00
|
|
|
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=*([\'\"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#iUu','$1=$2nomozbinding...', $this->__cleaned);
|
|
|
|
$this->__cleaned = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*expression[\x00-\x20]*\([^>]*>#iU',"$1>", $this->__cleaned);
|
|
|
|
$this->__cleaned = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*behaviour[\x00-\x20]*\([^>]*>#iU',"$1>", $this->__cleaned);
|
2007-03-05 12:13:37 +00:00
|
|
|
$this->__cleaned = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*>#iUu',"$1>",$this->__cleaned);
|
2007-12-09 06:43:44 +00:00
|
|
|
$this->__cleaned = preg_replace('#</*\w+:\w[^>]*>#i',"", $this->__cleaned);
|
2007-03-05 12:13:37 +00:00
|
|
|
do {
|
|
|
|
$oldstring = $this->__cleaned;
|
|
|
|
$this->__cleaned = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i',"",$this->__cleaned);
|
|
|
|
} while ($oldstring != $this->__cleaned);
|
|
|
|
}
|
2005-08-21 06:49:02 +00:00
|
|
|
}
|
2007-05-03 04:35:25 +00:00
|
|
|
?>
|