2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Backend for helpers.
|
|
|
|
*
|
|
|
|
* Internal methods for the Helpers.
|
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, 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.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.libs.view
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
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
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-12-11 05:47:55 +00:00
|
|
|
App::uses('Router', 'Routing');
|
2010-07-12 00:01:24 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 22:59:05 +00:00
|
|
|
* Abstract base class for all other Helpers in CakePHP.
|
|
|
|
* Provides common methods and features.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.libs.view
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-24 01:21:31 +00:00
|
|
|
class Helper extends Object {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* List of helpers used by this helper
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-07-03 15:36:53 +00:00
|
|
|
public $helpers = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper lookup table used to lazy load helper objects.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $_helperMap = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 22:59:05 +00:00
|
|
|
* The current theme name if any.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $theme = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-14 04:05:45 +00:00
|
|
|
/**
|
|
|
|
* Request object
|
|
|
|
*
|
|
|
|
* @var CakeRequest
|
|
|
|
*/
|
|
|
|
public $request = null;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Plugin path
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $plugin = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Contains model validation errors of form post-backs
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $validationErrors = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds tag templates.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $tags = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds the content to be cleaned.
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @var mixed
|
|
|
|
*/
|
2010-04-04 06:33:39 +00:00
|
|
|
private $__tainted = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds the cleaned content.
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @var mixed
|
|
|
|
*/
|
2010-04-04 06:33:39 +00:00
|
|
|
private $__cleaned = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-03 05:15:00 +00:00
|
|
|
/**
|
2010-07-03 15:36:53 +00:00
|
|
|
* The View instance this helper is attached to
|
2010-07-03 05:15:00 +00:00
|
|
|
*
|
2010-07-03 15:36:53 +00:00
|
|
|
* @var View
|
2010-07-03 05:15:00 +00:00
|
|
|
*/
|
2010-07-03 15:36:53 +00:00
|
|
|
protected $_View;
|
2010-07-03 05:15:00 +00:00
|
|
|
|
2010-04-05 07:30:24 +00:00
|
|
|
/**
|
|
|
|
* Default Constructor
|
|
|
|
*
|
2010-07-03 05:07:50 +00:00
|
|
|
* @param View $View The View this helper is being attached to.
|
|
|
|
* @param array $settings Configuration settings for the helper.
|
2010-04-05 07:30:24 +00:00
|
|
|
*/
|
2010-07-03 05:07:50 +00:00
|
|
|
public function __construct(View $View, $settings = array()) {
|
2010-07-03 15:36:53 +00:00
|
|
|
$this->_View = $View;
|
2010-08-28 04:40:12 +00:00
|
|
|
$this->request = $View->request;
|
2010-07-03 15:36:53 +00:00
|
|
|
if (!empty($this->helpers)) {
|
|
|
|
$this->_helperMap = ObjectCollection::normalizeObjectArray($this->helpers);
|
|
|
|
}
|
2010-04-05 07:30:24 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-07-03 15:41:49 +00:00
|
|
|
* Provide non fatal errors on missing method calls.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-07-03 15:41:49 +00:00
|
|
|
* @param string $method Method to invoke
|
|
|
|
* @param array $params Array of params for the method.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-14 03:54:21 +00:00
|
|
|
public function __call($method, $params) {
|
2010-12-05 01:37:13 +00:00
|
|
|
trigger_error(__('Method %1$s::%2$s does not exist', get_class($this), $method), E_USER_WARNING);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 05:15:00 +00:00
|
|
|
/**
|
2010-09-12 04:24:37 +00:00
|
|
|
* Lazy loads helpers. Provides access to deprecated request properties as well.
|
2010-07-03 05:15:00 +00:00
|
|
|
*
|
2010-07-03 15:41:49 +00:00
|
|
|
* @param string $name Name of the property being accessed.
|
|
|
|
* @return mixed Helper or property found at $name
|
2010-07-03 05:15:00 +00:00
|
|
|
*/
|
|
|
|
public function __get($name) {
|
2010-07-03 15:36:53 +00:00
|
|
|
if (isset($this->_helperMap[$name]) && !isset($this->{$name})) {
|
2010-11-07 04:07:27 +00:00
|
|
|
$settings = array_merge((array)$this->_helperMap[$name]['settings'], array('enabled' => false));
|
|
|
|
$this->{$name} = $this->_View->loadHelper($this->_helperMap[$name]['class'], $settings);
|
2010-07-03 15:36:53 +00:00
|
|
|
}
|
|
|
|
if (isset($this->{$name})) {
|
2010-07-03 05:15:00 +00:00
|
|
|
return $this->{$name};
|
|
|
|
}
|
2010-09-12 04:24:37 +00:00
|
|
|
switch ($name) {
|
|
|
|
case 'base':
|
|
|
|
case 'here':
|
|
|
|
case 'webroot':
|
|
|
|
case 'data':
|
|
|
|
return $this->request->{$name};
|
|
|
|
case 'action':
|
|
|
|
return isset($this->request->params['action']) ? $this->request->params['action'] : '';
|
|
|
|
case 'params':
|
|
|
|
return $this->request;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides backwards compatiblity access for setting values to the request object.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __set($name, $value) {
|
|
|
|
switch ($name) {
|
|
|
|
case 'base':
|
|
|
|
case 'here':
|
|
|
|
case 'webroot':
|
|
|
|
case 'data':
|
|
|
|
return $this->request->{$name} = $value;
|
|
|
|
case 'action':
|
|
|
|
return $this->request->params['action'] = $value;
|
|
|
|
}
|
|
|
|
return $this->{$name} = $value;
|
2010-07-03 05:15:00 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Finds URL for specified action.
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* Returns a URL pointing at the provided parameters.
|
|
|
|
*
|
|
|
|
* @param mixed $url Either a relative string url like `/products/view/23` or
|
|
|
|
* an array of url parameters. Using an array for urls will allow you to leverage
|
|
|
|
* the reverse routing features of CakePHP.
|
|
|
|
* @param boolean $full If true, the full base URL will be prepended to the result
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Full translated URL with base path.
|
2010-04-05 01:12:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1448/url
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function url($url = null, $full = false) {
|
2009-02-25 19:51:41 +00:00
|
|
|
return h(Router::url($url, $full));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Checks if a file exists when theme is used, if no file is found default location is returned
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param string $file The file to create a webroot path to.
|
2010-03-28 16:53:57 +00:00
|
|
|
* @return string Web accessible path to file.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function webroot($file) {
|
2009-11-25 07:51:25 +00:00
|
|
|
$asset = explode('?', $file);
|
|
|
|
$asset[1] = isset($asset[1]) ? '?' . $asset[1] : null;
|
2010-05-14 04:05:45 +00:00
|
|
|
$webPath = "{$this->request->webroot}" . $asset[0];
|
2009-11-26 20:52:38 +00:00
|
|
|
$file = $asset[0];
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-11-25 07:51:25 +00:00
|
|
|
if (!empty($this->theme)) {
|
2009-11-26 20:52:38 +00:00
|
|
|
$file = trim($file, '/');
|
|
|
|
$theme = $this->theme . '/';
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
if (DS === '\\') {
|
|
|
|
$file = str_replace('/', '\\', $file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists(Configure::read('App.www_root') . 'theme' . DS . $this->theme . DS . $file)) {
|
2010-05-14 04:05:45 +00:00
|
|
|
$webPath = "{$this->request->webroot}theme/" . $theme . $asset[0];
|
2009-11-26 20:52:38 +00:00
|
|
|
} else {
|
|
|
|
$viewPaths = App::path('views');
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-11-26 20:52:38 +00:00
|
|
|
foreach ($viewPaths as $viewPath) {
|
|
|
|
$path = $viewPath . 'themed'. DS . $this->theme . DS . 'webroot' . DS . $file;
|
|
|
|
|
|
|
|
if (file_exists($path)) {
|
2010-05-14 04:05:45 +00:00
|
|
|
$webPath = "{$this->request->webroot}theme/" . $theme . $asset[0];
|
2009-11-26 20:52:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-09-12 05:11:34 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-12 05:11:34 +00:00
|
|
|
if (strpos($webPath, '//') !== false) {
|
2010-02-14 01:43:02 +00:00
|
|
|
return str_replace('//', '/', $webPath . $asset[1]);
|
2008-09-12 05:11:34 +00:00
|
|
|
}
|
2009-11-25 07:51:25 +00:00
|
|
|
return $webPath . $asset[1];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-24 03:45:11 +00:00
|
|
|
/**
|
2010-01-25 22:59:05 +00:00
|
|
|
* Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in
|
2009-09-24 03:45:11 +00:00
|
|
|
* Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force'
|
|
|
|
* a timestamp will be added.
|
|
|
|
*
|
|
|
|
* @param string $path The file path to timestamp, the path must be inside WWW_ROOT
|
|
|
|
* @return string Path with a timestamp added, or not.
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function assetTimestamp($path) {
|
2010-12-07 03:19:15 +00:00
|
|
|
$stamp = Configure::read('Asset.timestamp');
|
|
|
|
$timestampEnabled = $stamp === 'force' || ($stamp === true && Configure::read('debug') > 0);
|
|
|
|
if ($timestampEnabled && strpos($path, '?') === false) {
|
2010-05-14 04:05:45 +00:00
|
|
|
$filepath = preg_replace('/^' . preg_quote($this->request->webroot, '/') . '/', '', $path);
|
2010-07-01 00:47:54 +00:00
|
|
|
$webrootPath = WWW_ROOT . str_replace('/', DS, $filepath);
|
|
|
|
if (file_exists($webrootPath)) {
|
|
|
|
return $path . '?' . @filemtime($webrootPath);
|
|
|
|
}
|
|
|
|
$segments = explode('/', ltrim($filepath, '/'));
|
|
|
|
if ($segments[0] === 'theme') {
|
|
|
|
$theme = $segments[1];
|
|
|
|
unset($segments[0], $segments[1]);
|
|
|
|
$themePath = App::themePath($theme) . 'webroot' . DS . implode(DS, $segments);
|
|
|
|
return $path . '?' . @filemtime($themePath);
|
|
|
|
} else {
|
|
|
|
$plugin = $segments[0];
|
|
|
|
unset($segments[0]);
|
|
|
|
$pluginPath = App::pluginPath($plugin) . 'webroot' . DS . implode(DS, $segments);
|
|
|
|
return $path . '?' . @filemtime($pluginPath);
|
|
|
|
}
|
2009-09-24 03:45:11 +00:00
|
|
|
}
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-03-28 16:53:57 +00:00
|
|
|
* Used to remove harmful tags from content. Removes a number of well known XSS attacks
|
|
|
|
* from content. However, is not guaranteed to remove all possiblities. Escaping
|
|
|
|
* content is the best way to prevent all possible attacks.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-03-28 16:53:57 +00:00
|
|
|
* @param mixed $output Either an array of strings to clean or a single string to clean.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return cleaned content for output
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function clean($output) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->__reset();
|
|
|
|
if (empty($output)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (is_array($output)) {
|
|
|
|
foreach ($output as $key => $value) {
|
|
|
|
$return[$key] = $this->clean($value);
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
$this->__tainted = $output;
|
|
|
|
$this->__clean();
|
|
|
|
return $this->__cleaned;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2011-01-28 05:44:59 +00:00
|
|
|
<<<<<<< HEAD:lib/Cake/View/Helper.php
|
2008-05-30 11:40:08 +00:00
|
|
|
* Returns a space-delimited string with items of the $options array. If a
|
|
|
|
* key of $options array happens to be one of:
|
2009-10-17 02:53:38 +00:00
|
|
|
*
|
|
|
|
* - 'compact'
|
|
|
|
* - 'checked'
|
|
|
|
* - 'declare'
|
|
|
|
* - 'readonly'
|
|
|
|
* - 'disabled'
|
|
|
|
* - 'selected'
|
|
|
|
* - 'defer'
|
|
|
|
* - 'ismap'
|
|
|
|
* - 'nohref'
|
|
|
|
* - 'noshade'
|
|
|
|
* - 'nowrap'
|
|
|
|
* - 'multiple'
|
|
|
|
* - 'noresize'
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* And its value is one of:
|
2009-10-17 02:53:38 +00:00
|
|
|
*
|
2010-06-10 23:11:26 +00:00
|
|
|
* - '1' (string)
|
|
|
|
* - 1 (integer)
|
|
|
|
* - true (boolean)
|
|
|
|
* - 'true' (string)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2009-10-17 02:53:38 +00:00
|
|
|
* '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.
|
|
|
|
*
|
2010-02-07 21:30:43 +00:00
|
|
|
* If value for any option key is set to `null` or `false`, that option will be excluded from output.
|
|
|
|
*
|
2009-10-17 02:53:38 +00:00
|
|
|
* @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.
|
2010-02-07 21:30:43 +00:00
|
|
|
* @param string $insertAfter String to be inserted after options.
|
2009-10-17 02:53:38 +00:00
|
|
|
* @return string Composed attributes.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
|
2010-12-07 03:19:15 +00:00
|
|
|
if (!is_string($options)) {
|
2010-12-22 02:35:36 +00:00
|
|
|
$options = (array) $options + array('escape' => true);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (!is_array($exclude)) {
|
|
|
|
$exclude = array();
|
|
|
|
}
|
2010-12-07 03:19:15 +00:00
|
|
|
|
|
|
|
$exclude = array('escape' => true) + array_flip($exclude);
|
2008-05-30 11:40:08 +00:00
|
|
|
$escape = $options['escape'];
|
|
|
|
$attributes = array();
|
|
|
|
|
2010-12-07 03:19:15 +00:00
|
|
|
foreach ($options as $key => $value) {
|
|
|
|
if (!isset($exclude[$key]) && $value !== false && $value !== null) {
|
2010-12-10 04:42:38 +00:00
|
|
|
$attributes[] = $this->_formatAttribute($key, $value, $escape);
|
2010-02-07 21:30:43 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
$out = implode(' ', $attributes);
|
|
|
|
} else {
|
|
|
|
$out = $options;
|
|
|
|
}
|
|
|
|
return $out ? $insertBefore . $out . $insertAfter : '';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-10-17 02:53:38 +00:00
|
|
|
* Formats an individual attribute, and returns the string value of the composed attribute.
|
2010-01-25 22:59:05 +00:00
|
|
|
* Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
|
2009-10-17 02:53:38 +00:00
|
|
|
*
|
|
|
|
* @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.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 04:42:38 +00:00
|
|
|
protected function _formatAttribute($key, $value, $escape = true) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$attribute = '';
|
|
|
|
if (is_array($value)) {
|
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
|
2010-12-10 04:42:38 +00:00
|
|
|
if (is_numeric($key)) {
|
|
|
|
$attribute = sprintf($this->_minimizedAttributeFormat, $value, $value);
|
|
|
|
} elseif (in_array($key, $this->_minimizedAttributes)) {
|
2010-06-10 23:11:26 +00:00
|
|
|
if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
|
2010-12-10 04:42:38 +00:00
|
|
|
$attribute = sprintf($this->_minimizedAttributeFormat, $key, $key);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-12-10 04:42:38 +00:00
|
|
|
$attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return $attribute;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Sets this helper's model and field properties to the dot-separated value-pair in $entity.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function setEntity($entity, $setScope = false) {
|
2011-01-28 05:44:59 +00:00
|
|
|
$view = $this->_View;
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($setScope) {
|
|
|
|
$view->modelScope = false;
|
2009-10-21 13:08:20 +00:00
|
|
|
} elseif (!empty($view->entityPath) && $view->entityPath == $entity) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($entity === null) {
|
|
|
|
$view->model = null;
|
|
|
|
$view->association = null;
|
|
|
|
$view->modelId = null;
|
|
|
|
$view->modelScope = false;
|
2009-10-21 13:08:20 +00:00
|
|
|
$view->entityPath = null;
|
2008-05-30 11:40:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-10-21 13:08:20 +00:00
|
|
|
$view->entityPath = $entity;
|
2008-05-30 11:40:08 +00:00
|
|
|
$model = $view->model;
|
|
|
|
$sameScope = $hasField = false;
|
2008-09-18 03:09:19 +00:00
|
|
|
$parts = array_values(Set::filter(explode('.', $entity), true));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (empty($parts)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-10-21 03:49:23 +00:00
|
|
|
$count = count($parts);
|
|
|
|
if ($count === 1) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$sameScope = true;
|
|
|
|
} else {
|
2009-10-21 03:49:23 +00:00
|
|
|
if (is_numeric($parts[0])) {
|
|
|
|
$sameScope = true;
|
|
|
|
}
|
|
|
|
$reverse = array_reverse($parts);
|
|
|
|
$field = array_shift($reverse);
|
|
|
|
while(!empty($reverse)) {
|
|
|
|
$subject = array_shift($reverse);
|
|
|
|
if (is_numeric($subject)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ClassRegistry::isKeySet($subject)) {
|
|
|
|
$model = $subject;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
if (ClassRegistry::isKeySet($model)) {
|
2011-01-28 05:44:59 +00:00
|
|
|
$ModelObj = ClassRegistry::getObject($model);
|
2009-10-21 03:49:23 +00:00
|
|
|
for ($i = 0; $i < $count; $i++) {
|
2010-08-24 01:39:23 +00:00
|
|
|
if (
|
|
|
|
is_a($ModelObj, 'Model') &&
|
|
|
|
($ModelObj->hasField($parts[$i]) ||
|
|
|
|
array_key_exists($parts[$i], $ModelObj->validate))
|
|
|
|
) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$hasField = $i;
|
|
|
|
if ($hasField === 0 || ($hasField === 1 && is_numeric($parts[0]))) {
|
|
|
|
$sameScope = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sameScope === true && in_array($parts[0], array_keys($ModelObj->hasAndBelongsToMany))) {
|
|
|
|
$sameScope = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$view->association && $parts[0] == $view->field && $view->field != $view->model) {
|
|
|
|
array_unshift($parts, $model);
|
|
|
|
$hasField = true;
|
|
|
|
}
|
|
|
|
$view->field = $view->modelId = $view->fieldSuffix = $view->association = null;
|
|
|
|
|
|
|
|
switch (count($parts)) {
|
|
|
|
case 1:
|
2008-10-23 00:10:44 +00:00
|
|
|
if ($view->modelScope === false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$view->model = $parts[0];
|
|
|
|
} else {
|
|
|
|
$view->field = $parts[0];
|
2008-10-23 00:10:44 +00:00
|
|
|
if ($sameScope === false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$view->association = $parts[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-06-20 11:57:56 +00:00
|
|
|
case 2:
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($view->modelScope === false) {
|
|
|
|
list($view->model, $view->field) = $parts;
|
|
|
|
} elseif ($sameScope === true && $hasField === 0) {
|
|
|
|
list($view->field, $view->fieldSuffix) = $parts;
|
|
|
|
} 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;
|
|
|
|
case 4:
|
|
|
|
if ($parts[0] === $view->model) {
|
|
|
|
list($view->model, $view->modelId, $view->field, $view->fieldSuffix) = $parts;
|
|
|
|
} else {
|
|
|
|
list($view->association, $view->modelId, $view->field, $view->fieldSuffix) = $parts;
|
|
|
|
}
|
|
|
|
break;
|
2009-10-21 03:49:23 +00:00
|
|
|
default:
|
|
|
|
$reverse = array_reverse($parts);
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-10-21 03:49:23 +00:00
|
|
|
if ($hasField) {
|
|
|
|
$view->field = $field;
|
|
|
|
if (!is_numeric($reverse[1]) && $reverse[1] != $model) {
|
|
|
|
$view->field = $reverse[1];
|
|
|
|
$view->fieldSuffix = $field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_numeric($parts[0])) {
|
|
|
|
$view->modelId = $parts[0];
|
|
|
|
} elseif ($view->model == $parts[0] && is_numeric($parts[1])) {
|
|
|
|
$view->modelId = $parts[1];
|
|
|
|
}
|
|
|
|
$view->association = $model;
|
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($view->model) || empty($view->model)) {
|
|
|
|
$view->model = $view->association;
|
|
|
|
$view->association = null;
|
|
|
|
} elseif ($view->model === $view->association) {
|
|
|
|
$view->association = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($setScope) {
|
|
|
|
$view->modelScope = true;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets the currently-used model of the rendering context.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function model() {
|
2010-07-15 02:35:36 +00:00
|
|
|
if (!empty($this->_View->association)) {
|
|
|
|
return $this->_View->association;
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
2010-07-15 02:35:36 +00:00
|
|
|
return $this->_View->model;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets the ID of the currently-used model of the rendering context.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function modelID() {
|
2010-07-15 02:35:36 +00:00
|
|
|
return $this->_View->modelId;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets the currently-used model field of the rendering context.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function field() {
|
2010-07-15 02:35:36 +00:00
|
|
|
return $this->_View->field;
|
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 false if given FORM field has no errors. Otherwise it returns the constant set in
|
|
|
|
* the array Model->validationErrors.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param string $model Model name as a string
|
|
|
|
* @param string $field Fieldname as a string
|
|
|
|
* @param integer $modelID Unique index identifying this record within the form
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return boolean True on errors.
|
|
|
|
*/
|
2010-04-05 06:39:29 +00:00
|
|
|
public function tagIsInvalid($model = null, $field = null, $modelID = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$errors = $this->validationErrors;
|
2010-07-15 02:35:36 +00:00
|
|
|
$entity = $this->_View->entity();
|
2009-10-21 21:09:16 +00:00
|
|
|
if (!empty($entity)) {
|
2009-11-04 19:05:12 +00:00
|
|
|
return Set::extract($errors, join('.', $entity));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Generates a DOM ID for the selected element, if one is not set.
|
2010-01-25 22:59:05 +00:00
|
|
|
* Uses the current View::entity() settings to generate a CamelCased id attribute.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param mixed $options Either an array of html attributes to add $id into, or a string
|
|
|
|
* with a view entity path to get a domId for.
|
|
|
|
* @param string $id The name of the 'id' attribute.
|
|
|
|
* @return mixed If $options was an array, an array will be returned with $id set. If a string
|
|
|
|
* was supplied, a string will be returned.
|
|
|
|
* @todo Refactor this method to not have as many input/output options.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 06:39:29 +00:00
|
|
|
public function domId($options = null, $id = 'id') {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_array($options) && array_key_exists($id, $options) && $options[$id] === null) {
|
|
|
|
unset($options[$id]);
|
|
|
|
return $options;
|
|
|
|
} elseif (!is_array($options) && $options !== null) {
|
|
|
|
$this->setEntity($options);
|
|
|
|
return $this->domId();
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2010-07-15 02:35:36 +00:00
|
|
|
$entity = $this->_View->entity();
|
2009-10-21 21:09:16 +00:00
|
|
|
$model = array_shift($entity);
|
2010-01-25 22:59:05 +00:00
|
|
|
$dom = $model . join('', array_map(array('Inflector', 'camelize'), $entity));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (is_array($options) && !array_key_exists($id, $options)) {
|
|
|
|
$options[$id] = $dom;
|
|
|
|
} elseif ($options === null) {
|
|
|
|
return $dom;
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 22:59:05 +00:00
|
|
|
* Gets the input field name for the current tag. Creates input name attributes
|
|
|
|
* using CakePHP's data[Model][field] formatting.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param mixed $options If an array, should be an array of attributes that $key needs to be added to.
|
|
|
|
* If a string or null, will be used as the View entity.
|
|
|
|
* @param string $field
|
|
|
|
* @param string $key The name of the attribute to be set, defaults to 'name'
|
|
|
|
* @return mixed If an array was given for $options, an array with $key set will be returned.
|
|
|
|
* If a string was supplied a string will be returned.
|
2009-11-15 10:18:46 +00:00
|
|
|
* @access protected
|
2010-01-25 22:59:05 +00:00
|
|
|
* @todo Refactor this method to not have as many input/output options.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 06:39:29 +00:00
|
|
|
protected function _name($options = array(), $field = null, $key = 'name') {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($options === null) {
|
|
|
|
$options = array();
|
|
|
|
} elseif (is_string($options)) {
|
|
|
|
$field = $options;
|
|
|
|
$options = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($field)) {
|
|
|
|
$this->setEntity($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($options) && array_key_exists($key, $options)) {
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($field) {
|
|
|
|
case '_method':
|
|
|
|
$name = $field;
|
|
|
|
break;
|
|
|
|
default:
|
2010-07-15 02:35:36 +00:00
|
|
|
$name = 'data[' . implode('][', $this->_View->entity()) . ']';
|
2008-05-30 11:40:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($options)) {
|
|
|
|
$options[$key] = $name;
|
|
|
|
return $options;
|
|
|
|
} else {
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets the data for the current tag
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param mixed $options If an array, should be an array of attributes that $key needs to be added to.
|
|
|
|
* If a string or null, will be used as the View entity.
|
|
|
|
* @param string $field
|
|
|
|
* @param string $key The name of the attribute to be set, defaults to 'value'
|
|
|
|
* @return mixed If an array was given for $options, an array with $key set will be returned.
|
|
|
|
* If a string was supplied a string will be returned.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access public
|
2010-01-25 22:59:05 +00:00
|
|
|
* @todo Refactor this method to not have as many input/output options.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 06:39:29 +00:00
|
|
|
public function value($options = array(), $field = null, $key = 'value') {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($options === null) {
|
|
|
|
$options = array();
|
|
|
|
} elseif (is_string($options)) {
|
|
|
|
$field = $options;
|
|
|
|
$options = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($options) && isset($options[$key])) {
|
|
|
|
return $options;
|
|
|
|
}
|
2010-01-25 22:59:05 +00:00
|
|
|
|
2009-10-21 13:08:20 +00:00
|
|
|
if (!empty($field)) {
|
|
|
|
$this->setEntity($field);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = null;
|
2010-05-14 04:05:45 +00:00
|
|
|
$data = $this->request->data;
|
2009-11-04 19:05:12 +00:00
|
|
|
|
2010-07-15 02:35:36 +00:00
|
|
|
$entity = $this->_View->entity();
|
2010-08-28 04:40:12 +00:00
|
|
|
if (!empty($data) && !empty($entity)) {
|
|
|
|
$result = Set::extract($data, join('.', $entity));
|
2009-11-04 19:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$habtmKey = $this->field();
|
2010-05-14 04:05:45 +00:00
|
|
|
if (empty($result) && isset($data[$habtmKey][$habtmKey])) {
|
2010-08-28 04:40:12 +00:00
|
|
|
$result = $data[$habtmKey][$habtmKey];
|
2010-05-14 04:05:45 +00:00
|
|
|
} elseif (empty($result) && isset($data[$habtmKey]) && is_array($data[$habtmKey])) {
|
2009-11-04 19:05:12 +00:00
|
|
|
if (ClassRegistry::isKeySet($habtmKey)) {
|
|
|
|
$model =& ClassRegistry::getObject($habtmKey);
|
2010-05-14 04:05:45 +00:00
|
|
|
$result = $this->__selectedArray($data[$habtmKey], $model->primaryKey);
|
2009-11-04 19:05:12 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($result)) {
|
2010-07-15 02:35:36 +00:00
|
|
|
if (array_key_exists($this->_View->fieldSuffix, $result)) {
|
|
|
|
$result = $result[$this->_View->fieldSuffix];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($options)) {
|
2010-03-10 19:46:02 +00:00
|
|
|
if ($result === null && isset($options['default'])) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $options['default'];
|
|
|
|
}
|
|
|
|
unset($options['default']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($options)) {
|
|
|
|
$options[$key] = $result;
|
|
|
|
return $options;
|
|
|
|
} else {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-02-07 21:30:43 +00:00
|
|
|
* Sets the defaults for an input tag. Will set the
|
2010-01-25 22:59:05 +00:00
|
|
|
* name, value, and id attributes for an array of html attributes. Will also
|
|
|
|
* add a 'form-error' class if the field contains validation errors.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param string $field The field name to initialize.
|
|
|
|
* @param array $options Array of options to use while initializing an input field.
|
|
|
|
* @return array Array options for the form input.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _initInputField($field, $options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($field !== null) {
|
|
|
|
$this->setEntity($field);
|
|
|
|
}
|
|
|
|
$options = (array)$options;
|
2009-11-15 10:18:46 +00:00
|
|
|
$options = $this->_name($options);
|
2008-05-30 11:40:08 +00:00
|
|
|
$options = $this->value($options);
|
|
|
|
$options = $this->domId($options);
|
|
|
|
if ($this->tagIsInvalid()) {
|
|
|
|
$options = $this->addClass($options, 'form-error');
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Adds the given class to the element options
|
|
|
|
*
|
2010-02-07 21:30:43 +00:00
|
|
|
* @param array $options Array options/attributes to add a class to
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param string $class The classname being added.
|
|
|
|
* @param string $key the key to use for class.
|
|
|
|
* @return array Array of options with $key set.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function addClass($options = array(), $class = null, $key = 'class') {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (isset($options[$key]) && trim($options[$key]) != '') {
|
|
|
|
$options[$key] .= ' ' . $class;
|
|
|
|
} else {
|
|
|
|
$options[$key] = $class;
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a string generated by a helper method
|
|
|
|
*
|
|
|
|
* This method can be overridden in subclasses to do generalized output post-processing
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param string $str String to be output.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string
|
2010-01-25 22:59:05 +00:00
|
|
|
* @deprecated This method will be removed in future versions.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 06:39:29 +00:00
|
|
|
public function output($str) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $str;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 22:59:05 +00:00
|
|
|
* Before render callback. beforeRender is called before the view file is rendered.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* Overridden in subclasses.
|
|
|
|
*
|
2010-11-05 02:53:00 +00:00
|
|
|
* @param string $viewFile The view file that is going to be rendered
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-11-05 02:53:00 +00:00
|
|
|
public function beforeRender($viewFile) {
|
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
|
|
|
* After render callback. afterRender is called after the view file is rendered
|
|
|
|
* but before the layout has been rendered.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* Overridden in subclasses.
|
|
|
|
*
|
2010-11-05 02:53:00 +00:00
|
|
|
* @param string $viewFile The view file that was rendered.
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-11-05 03:55:50 +00:00
|
|
|
public function afterRender($viewFile) {
|
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
|
|
|
* Before layout callback. beforeLayout is called before the layout is rendered.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* Overridden in subclasses.
|
|
|
|
*
|
2010-11-05 02:53:00 +00:00
|
|
|
* @param string $layoutFile The layout about to be rendered.
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-11-05 02:53:00 +00:00
|
|
|
public function beforeLayout($layoutFile) {
|
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
|
|
|
* After layout callback. afterLayout is called after the layout has rendered.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* Overridden in subclasses.
|
|
|
|
*
|
2010-11-05 02:53:00 +00:00
|
|
|
* @param string $layoutFile The layout file that was rendered.
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-11-05 03:55:50 +00:00
|
|
|
public function afterLayout($layoutFile) {
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Transforms a recordset from a hasAndBelongsToMany association to a list of selected
|
|
|
|
* options for a multiple select element
|
|
|
|
*
|
|
|
|
* @param mixed $data
|
|
|
|
* @param string $key
|
|
|
|
* @return array
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function __selectedArray($data, $key = 'id') {
|
|
|
|
if (!is_array($data)) {
|
|
|
|
$model = $data;
|
2010-05-14 04:05:45 +00:00
|
|
|
if (!empty($this->request->data[$model][$model])) {
|
|
|
|
return $this->request->data[$model][$model];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-05-14 04:05:45 +00:00
|
|
|
if (!empty($this->request->data[$model])) {
|
|
|
|
$data = $this->request->data[$model];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$array = array();
|
|
|
|
if (!empty($data)) {
|
|
|
|
foreach ($data as $var) {
|
|
|
|
$array[$var[$key]] = $var[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $array;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Resets the vars used by Helper::clean() to null
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function __reset() {
|
|
|
|
$this->__tainted = null;
|
|
|
|
$this->__cleaned = null;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Removes harmful content from output
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function __clean() {
|
|
|
|
if (get_magic_quotes_gpc()) {
|
|
|
|
$this->__cleaned = stripslashes($this->__tainted);
|
|
|
|
} else {
|
|
|
|
$this->__cleaned = $this->__tainted;
|
|
|
|
}
|
|
|
|
|
2008-08-27 03:42:17 +00:00
|
|
|
$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);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->__cleaned = html_entity_decode($this->__cleaned, ENT_COMPAT, "UTF-8");
|
2008-08-27 03:42:17 +00:00
|
|
|
$this->__cleaned = preg_replace('#(<[^>]+[\x00-\x20\"\'\/])(on|xmlns)[^>]*>#iUu', "$1>", $this->__cleaned);
|
|
|
|
$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);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=*([\'\"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#iUu','$1=$2nomozbinding...', $this->__cleaned);
|
2008-08-27 03:42:17 +00:00
|
|
|
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=([\'\"]*)[\x00-\x20]*data[\x00-\x20]*:#Uu', '$1=$2nodata...', $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);
|
|
|
|
$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);
|
|
|
|
$this->__cleaned = preg_replace('#</*\w+:\w[^>]*>#i', "", $this->__cleaned);
|
2008-05-30 11:40:08 +00:00
|
|
|
do {
|
|
|
|
$oldstring = $this->__cleaned;
|
2008-08-27 03:42:17 +00:00
|
|
|
$this->__cleaned = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $this->__cleaned);
|
2008-05-30 11:40:08 +00:00
|
|
|
} while ($oldstring != $this->__cleaned);
|
2008-08-27 03:42:17 +00:00
|
|
|
$this->__cleaned = str_replace(array("&", "<", ">"), array("&amp;", "&lt;", "&gt;"), $this->__cleaned);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|