2005-07-02 22:49:04 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-06-21 23:44:49 +00:00
|
|
|
|
|
|
|
/**
|
2006-02-07 02:19:53 +00:00
|
|
|
* Methods for displaying presentation data in the view.
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
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/>
|
2008-01-01 22:18:17 +00:00
|
|
|
* Copyright 2005-2008, 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-27 03:33:44 +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-27 03:33:44 +00:00
|
|
|
* @filesource
|
2008-01-01 22:18:17 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
2007-02-02 10:39:45 +00:00
|
|
|
* @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.10.0.1076
|
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
|
|
|
*/
|
2005-06-21 23:44:49 +00:00
|
|
|
|
2005-08-21 06:49:02 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Included libraries.
|
|
|
|
*/
|
2006-11-25 09:27:13 +00:00
|
|
|
uses ('view' . DS . 'helper', 'class_registry');
|
2005-07-02 22:49:04 +00:00
|
|
|
|
|
|
|
/**
|
2005-12-22 01:07:28 +00:00
|
|
|
* View, the V in the MVC triad.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-08-25 16:40:50 +00:00
|
|
|
* Class holding methods for displaying presentation data.
|
2005-07-02 22:49:04 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view
|
2005-07-02 22:49:04 +00:00
|
|
|
*/
|
2006-10-16 20:02:34 +00:00
|
|
|
class View extends Object {
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Path parts for creating links in views.
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var string Base URL
|
2005-07-10 05:08:19 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $base = null;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Stores the current URL (for links etc.)
|
|
|
|
*
|
|
|
|
* @var string Current URL
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $here = null;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Name of the plugin.
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @link http://manual.cakephp.org/chapter/plugins
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $plugin = null;
|
|
|
|
/**
|
|
|
|
* Name of the controller.
|
|
|
|
*
|
|
|
|
* @var string Name of controller
|
2005-07-10 05:08:19 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $name = null;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Action to be performed.
|
|
|
|
*
|
2005-08-25 16:40:50 +00:00
|
|
|
* @var string Name of action
|
2005-07-10 05:08:19 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $action = null;
|
2007-11-04 18:07:59 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Array of parameter data
|
2007-04-18 16:39:11 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var array Parameter data
|
2007-04-18 16:39:11 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $params = array();
|
2007-02-06 17:18:23 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Current passed params
|
2007-02-06 17:18:23 +00:00
|
|
|
*
|
2007-11-04 18:07:59 +00:00
|
|
|
* @var mixed
|
2007-02-06 17:18:23 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $passedArgs = array();
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Array of data
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var array Parameter data
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $data = array();
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* An array of names of built-in helpers to include.
|
|
|
|
*
|
|
|
|
* @var mixed A single name as a string or a list of names as an array.
|
2007-12-14 22:20:44 +00:00
|
|
|
* @access public
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $helpers = array('Html');
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2005-08-25 16:40:50 +00:00
|
|
|
* Path to View.
|
2005-07-21 04:02:32 +00:00
|
|
|
*
|
2005-08-25 16:40:50 +00:00
|
|
|
* @var string Path to View
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $viewPath = null;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Variables for the view
|
|
|
|
*
|
|
|
|
* @var array
|
2007-10-13 15:38:07 +00:00
|
|
|
* @access public
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2006-11-28 11:18:05 +00:00
|
|
|
var $viewVars = array();
|
2006-08-28 20:41:08 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Name of layout to use with this View.
|
2006-08-28 20:41:08 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var string
|
|
|
|
* @access public
|
2006-08-28 20:41:08 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $layout = 'default';
|
|
|
|
/**
|
|
|
|
* Path to Layout.
|
|
|
|
*
|
|
|
|
* @var string Path to Layout
|
|
|
|
*/
|
|
|
|
var $layoutPath = null;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2005-08-25 16:40:50 +00:00
|
|
|
* Title HTML element of this View.
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-10-13 15:38:07 +00:00
|
|
|
* @var string
|
|
|
|
* @access public
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $pageTitle = false;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Turns on or off Cake's conventional mode of rendering views. On by default.
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var boolean
|
2005-07-10 05:08:19 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $autoRender = true;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Turns on or off Cake's conventional mode of finding layout files. On by default.
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var boolean
|
2005-07-10 05:08:19 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $autoLayout = true;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* File extension. Defaults to Cake's template ".ctp".
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $ext = '.ctp';
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Sub-directory for this view file.
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var string
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $subDir = null;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Theme name.
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var string
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $themeWeb = null;
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Used to define methods a controller that will be cached.
|
2005-07-21 04:02:32 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @see Controller::$cacheAction
|
|
|
|
* @var mixed
|
|
|
|
* @access public
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $cacheAction = false;
|
2007-12-20 01:19:19 +00:00
|
|
|
/**
|
|
|
|
* holds current errors for the model validation
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $validationErrors = array();
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* True when the view has been rendered.
|
2005-07-21 04:02:32 +00:00
|
|
|
*
|
2005-08-25 16:40:50 +00:00
|
|
|
* @var boolean
|
2005-07-21 04:02:32 +00:00
|
|
|
*/
|
2007-12-20 01:19:19 +00:00
|
|
|
var $hasRendered = false;
|
2005-12-28 17:23:12 +00:00
|
|
|
/**
|
2006-02-07 02:19:53 +00:00
|
|
|
* Array of loaded view helpers.
|
2005-12-28 17:23:12 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $loaded = array();
|
2006-01-01 02:05:01 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* True if in scope of model-specific region
|
2006-01-01 02:05:01 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var boolean
|
2006-01-01 02:05:01 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $modelScope = false;
|
2006-01-01 02:05:01 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Name of current model this view context is attached to
|
2006-01-01 02:05:01 +00:00
|
|
|
*
|
2006-02-07 02:19:53 +00:00
|
|
|
* @var string
|
2006-01-01 02:05:01 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $model = null;
|
2006-02-01 13:26:23 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Name of association model this view context is attached to
|
2006-02-01 13:26:23 +00:00
|
|
|
*
|
2007-10-13 15:38:07 +00:00
|
|
|
* @var string
|
2006-02-01 13:26:23 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $association = null;
|
2006-02-01 13:26:23 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Name of current model field this view context is attached to
|
2006-02-01 13:26:23 +00:00
|
|
|
*
|
2006-02-07 02:19:53 +00:00
|
|
|
* @var string
|
2006-02-01 13:26:23 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $field = null;
|
2007-03-05 09:38:31 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Suffix of current field this view context is attached to
|
2007-03-05 09:38:31 +00:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $fieldSuffix = null;
|
2007-03-05 09:38:31 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* The current model ID this view context is attached to
|
2007-03-05 09:38:31 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var mixed
|
2007-03-05 09:38:31 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $modelId = null;
|
2007-06-08 01:18:00 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* List of generated DOM UUIDs
|
2007-06-08 01:18:00 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @var array
|
2007-06-08 01:18:00 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $uuids = array();
|
2006-08-18 08:05:00 +00:00
|
|
|
/**
|
|
|
|
* List of variables to collect from the associated controller
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access protected
|
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $__passedVars = array('viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot', 'helpers', 'here', 'layout', 'name', 'pageTitle', 'layoutPath', 'viewPath', 'params', 'data', 'webservices', 'plugin', 'passedArgs', 'cacheAction');
|
2007-03-14 18:28:36 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Scripts (and/or other <head /> tags) for the layout
|
2007-03-14 18:28:36 +00:00
|
|
|
*
|
|
|
|
* @var array
|
2007-12-14 22:20:44 +00:00
|
|
|
* @access private
|
2007-03-14 18:28:36 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
var $__scripts = array();
|
|
|
|
/**
|
|
|
|
* Holds an array of paths.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $__paths = array();
|
2005-07-21 04:02:32 +00:00
|
|
|
/**
|
2005-08-25 16:40:50 +00:00
|
|
|
* Constructor
|
2005-07-21 04:02:32 +00:00
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
2007-10-22 23:52:12 +00:00
|
|
|
function __construct(&$controller, $register = true) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_object($controller)) {
|
2006-11-25 08:55:16 +00:00
|
|
|
$count = count($this->__passedVars);
|
|
|
|
for ($j = 0; $j < $count; $j++) {
|
2006-07-31 23:55:29 +00:00
|
|
|
$var = $this->__passedVars[$j];
|
|
|
|
$this->{$var} = $controller->{$var};
|
|
|
|
}
|
2006-07-27 17:13:02 +00:00
|
|
|
}
|
2007-12-14 22:20:44 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
parent::__construct();
|
2007-12-22 19:24:56 +00:00
|
|
|
if ($register) {
|
2007-10-22 23:52:12 +00:00
|
|
|
ClassRegistry::addObject('view', $this);
|
|
|
|
}
|
2006-07-06 13:45:13 +00:00
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
/**
|
|
|
|
* Wrapper for View::renderElement();
|
|
|
|
*
|
|
|
|
* @param string $name Name of template file in the/app/views/elements/ folder
|
|
|
|
* @param array $params Array of data to be made available to the for rendered view (i.e. the Element)
|
|
|
|
* @return string View::renderElement()
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function element($name, $params = array()) {
|
|
|
|
if (isset($params['cache'])) {
|
|
|
|
$expires = '+1 day';
|
|
|
|
$key = null;
|
|
|
|
if (is_array($params['cache'])) {
|
|
|
|
$expires = $params['cache']['time'];
|
2007-12-17 07:28:53 +00:00
|
|
|
$key = Inflector::slug($params['cache']['key']);
|
2007-12-14 22:20:44 +00:00
|
|
|
} elseif ($params['cache'] !== true) {
|
|
|
|
$expires = $params['cache'];
|
|
|
|
$key = implode('_', array_keys($params));
|
|
|
|
}
|
|
|
|
if ($expires) {
|
|
|
|
$plugin = null;
|
|
|
|
if (isset($params['plugin'])) {
|
|
|
|
$plugin = $params['plugin'].'_';
|
|
|
|
}
|
2007-12-17 07:28:53 +00:00
|
|
|
$cacheFile = 'element_' . $key . '_' . $plugin . Inflector::slug($name);
|
2007-12-14 22:20:44 +00:00
|
|
|
$cache = cache('views' . DS . $cacheFile, null, $expires);
|
|
|
|
|
|
|
|
if (is_string($cache)) {
|
|
|
|
return $cache;
|
|
|
|
} else {
|
|
|
|
$element = $this->renderElement($name, $params);
|
|
|
|
cache('views' . DS . $cacheFile, $element, $expires);
|
|
|
|
return $element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->renderElement($name, $params);
|
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2005-12-22 01:07:28 +00:00
|
|
|
* Renders view for given action and layout. If $file is given, that is used
|
2006-11-25 21:27:34 +00:00
|
|
|
* for a view filename (e.g. customFunkyView.ctp).
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $action Name of action to render for
|
|
|
|
* @param string $layout Layout to use
|
|
|
|
* @param string $file Custom filename for view
|
|
|
|
*/
|
|
|
|
function render($action = null, $layout = null, $file = null) {
|
|
|
|
|
2007-12-20 01:19:19 +00:00
|
|
|
if ($this->hasRendered) {
|
2006-05-26 05:29:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-12-20 01:19:19 +00:00
|
|
|
$out = null;
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
if ($file != null) {
|
|
|
|
$action = $file;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-11-28 11:18:05 +00:00
|
|
|
|
2007-12-20 01:19:19 +00:00
|
|
|
if ($action !== false) {
|
|
|
|
$viewFileName = $this->_getViewFileName($action);
|
2006-11-26 03:22:02 +00:00
|
|
|
if (substr($viewFileName, -3) === 'ctp' || substr($viewFileName, -5) === 'thtml') {
|
2006-11-28 11:18:05 +00:00
|
|
|
$out = View::_render($viewFileName, $this->viewVars);
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
2006-11-28 11:18:05 +00:00
|
|
|
$out = $this->_render($viewFileName, $this->viewVars);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-12-20 01:19:19 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-12-22 02:04:26 +00:00
|
|
|
if ($layout === null) {
|
|
|
|
$layout = $this->layout;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-12-20 01:19:19 +00:00
|
|
|
if ($out !== false) {
|
|
|
|
if ($layout && $this->autoLayout) {
|
|
|
|
$out = $this->renderLayout($out, $layout);
|
|
|
|
if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) {
|
|
|
|
$replace = array('<cake:nocache>', '</cake:nocache>');
|
|
|
|
$out = str_replace($replace, '', $out);
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-12-20 01:19:19 +00:00
|
|
|
|
|
|
|
print $out;
|
|
|
|
$this->hasRendered = true;
|
|
|
|
} else {
|
|
|
|
$out = $this->_render($viewFileName, $this->viewVars);
|
|
|
|
trigger_error(sprintf(__("Error in view %s, got: <blockquote>%s</blockquote>", true), $viewFileName, $out), E_USER_ERROR);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-12-20 01:19:19 +00:00
|
|
|
return true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
|
|
|
|
*
|
2005-08-25 16:40:50 +00:00
|
|
|
* This realizes the concept of Elements, (or "partial layouts")
|
2005-12-22 01:07:28 +00:00
|
|
|
* and the $params array is used to send data to be used in the
|
2005-08-25 16:40:50 +00:00
|
|
|
* Element.
|
|
|
|
*
|
2006-10-31 03:20:57 +00:00
|
|
|
* @link
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $name Name of template file in the/app/views/elements/ folder
|
|
|
|
* @param array $params Array of data to be made available to the for rendered view (i.e. the Element)
|
|
|
|
* @return string Rendered output
|
|
|
|
*/
|
2007-02-02 02:47:53 +00:00
|
|
|
function renderElement($name, $params = array(), $loadHelpers = false) {
|
2007-12-17 07:28:53 +00:00
|
|
|
$file = $plugin = null;
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (isset($params['plugin'])) {
|
2007-12-14 22:20:44 +00:00
|
|
|
$plugin = $params['plugin'];
|
2006-10-20 21:48:35 +00:00
|
|
|
}
|
2006-11-01 06:51:57 +00:00
|
|
|
|
2007-12-17 07:28:53 +00:00
|
|
|
if (isset($this->plugin) && !$plugin) {
|
|
|
|
$plugin = $this->plugin;
|
|
|
|
}
|
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
$paths = $this->_paths($plugin);
|
2007-12-17 07:28:53 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
foreach ($paths as $path) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$file = $path . 'elements' . DS . $name . $this->ext;
|
2007-04-29 03:33:37 +00:00
|
|
|
break;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . 'elements' . DS . $name . '.thtml')) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$file = $path . 'elements' . DS . $name . '.thtml';
|
2007-04-29 03:33:37 +00:00
|
|
|
break;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
if (is_file($file)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$params = array_merge_recursive($params, $this->loaded);
|
2007-03-23 00:25:27 +00:00
|
|
|
return $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
2007-03-05 09:38:31 +00:00
|
|
|
}
|
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
$file = $paths[0] . 'views' . DS . 'elements' . DS . $name . $this->ext;
|
2007-12-17 07:28:53 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (Configure::read() > 0) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return "Not Found: " . $file;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Renders a layout. Returns output from _render(). Returns false on error.
|
|
|
|
*
|
2005-08-25 16:40:50 +00:00
|
|
|
* @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
|
2005-10-18 22:27:39 +00:00
|
|
|
* @return mixed Rendered output, or false on error
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
function renderLayout($content_for_layout, $layout = null) {
|
|
|
|
$layout_fn = $this->_getLayoutFileName($layout);
|
2006-11-26 03:22:02 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
$debug = '';
|
2007-12-17 07:28:53 +00:00
|
|
|
|
2007-12-22 19:24:56 +00:00
|
|
|
if (isset($this->viewVars['cakeDebug']) && Configure::read() > 2) {
|
2007-12-17 07:28:53 +00:00
|
|
|
$debug = View::renderElement('dump', array('controller' => $this->viewVars['cakeDebug']), false);
|
2007-08-16 16:31:50 +00:00
|
|
|
unset($this->viewVars['cakeDebug']);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->pageTitle !== false) {
|
2006-06-14 18:02:37 +00:00
|
|
|
$pageTitle = $this->pageTitle;
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
2006-06-14 18:02:37 +00:00
|
|
|
$pageTitle = Inflector::humanize($this->viewPath);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2006-11-28 11:18:05 +00:00
|
|
|
$data_for_layout = array_merge($this->viewVars,
|
2006-08-18 08:05:00 +00:00
|
|
|
array(
|
|
|
|
'title_for_layout' => $pageTitle,
|
|
|
|
'content_for_layout' => $content_for_layout,
|
2006-08-28 20:41:08 +00:00
|
|
|
'scripts_for_layout' => join("\n\t", $this->__scripts),
|
2006-08-18 08:05:00 +00:00
|
|
|
'cakeDebug' => $debug
|
|
|
|
)
|
2006-06-14 18:02:37 +00:00
|
|
|
);
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
if (empty($this->loaded) && !empty($this->helpers)) {
|
|
|
|
$loadHelpers = true;
|
|
|
|
} else {
|
|
|
|
$loadHelpers = false;
|
|
|
|
$data_for_layout = array_merge($data_for_layout, $this->loaded);
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
if (substr($layout_fn, -3) === 'ctp' || substr($layout_fn, -5) === 'thtml') {
|
|
|
|
$out = View::_render($layout_fn, $data_for_layout, $loadHelpers, true);
|
|
|
|
} else {
|
|
|
|
$out = $this->_render($layout_fn, $data_for_layout, $loadHelpers);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($out === false) {
|
|
|
|
$out = $this->_render($layout_fn, $data_for_layout);
|
|
|
|
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>", true), $layout_fn, $out), E_USER_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Render cached view
|
|
|
|
*
|
|
|
|
* @param string $filename the cache file to include
|
|
|
|
* @param string $timeStart the page render start time
|
|
|
|
*/
|
|
|
|
function renderCache($filename, $timeStart) {
|
|
|
|
ob_start();
|
|
|
|
include ($filename);
|
|
|
|
|
|
|
|
if (Configure::read() > 0 && $this->layout != 'xml') {
|
|
|
|
echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->";
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match)) {
|
|
|
|
if (time() >= $match['1']) {
|
|
|
|
@unlink($filename);
|
|
|
|
unset ($out);
|
2007-12-29 19:05:22 +00:00
|
|
|
return false;
|
2006-06-14 18:02:37 +00:00
|
|
|
} else {
|
2007-12-14 22:20:44 +00:00
|
|
|
if ($this->layout === 'xml') {
|
|
|
|
header('Content-type: text/xml');
|
|
|
|
}
|
|
|
|
$out = str_replace('<!--cachetime:'.$match['1'].'-->', '', $out);
|
2007-12-17 07:28:53 +00:00
|
|
|
echo $out;
|
2007-12-29 19:05:22 +00:00
|
|
|
return true;
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-22 07:32:59 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of variables available in the current View context
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function getVars() {
|
2006-11-28 11:18:05 +00:00
|
|
|
return array_keys($this->viewVars);
|
2006-08-22 07:32:59 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns the contents of the given View variable(s)
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function getVar($var) {
|
2006-11-28 11:18:05 +00:00
|
|
|
if (!isset($this->viewVars[$var])) {
|
2006-08-22 07:32:59 +00:00
|
|
|
return null;
|
|
|
|
} else {
|
2006-11-28 11:18:05 +00:00
|
|
|
return $this->viewVars[$var];
|
2006-08-22 07:32:59 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-28 20:41:08 +00:00
|
|
|
/**
|
|
|
|
* Adds a script block or other element to be inserted in $scripts_for_layout in
|
|
|
|
* the <head /> of a document layout
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $content
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function addScript($name, $content = null) {
|
2007-03-22 00:37:45 +00:00
|
|
|
if (empty($content)) {
|
|
|
|
if (!in_array($name, array_values($this->__scripts))) {
|
2006-08-28 20:41:08 +00:00
|
|
|
$this->__scripts[] = $name;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->__scripts[$name] = $content;
|
|
|
|
}
|
|
|
|
}
|
2007-03-14 18:28:36 +00:00
|
|
|
/**
|
|
|
|
* Generates a unique, non-random DOM ID for an object, based on the object type and the target URL.
|
|
|
|
*
|
|
|
|
* @param string $object Type of object, i.e. 'form' or 'link'
|
|
|
|
* @param string $url The object's target URL
|
|
|
|
* @return string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function uuid($object, $url) {
|
|
|
|
$c = 1;
|
|
|
|
$hash = $object . substr(md5($object . Router::url($url)), 0, 10);
|
|
|
|
while (in_array($hash, $this->uuids)) {
|
|
|
|
$hash = $object . substr(md5($object . Router::url($url) . $c), 0, 10);
|
|
|
|
$c++;
|
|
|
|
}
|
|
|
|
$this->uuids[] = $hash;
|
|
|
|
return $hash;
|
|
|
|
}
|
2007-11-04 18:07:59 +00:00
|
|
|
/**
|
|
|
|
* Returns the entity reference of the current context as an array of identity parts
|
|
|
|
*
|
|
|
|
* @return array An array containing the identity elements of an entity
|
|
|
|
*/
|
|
|
|
function entity() {
|
2007-11-19 14:08:37 +00:00
|
|
|
return Set::filter(array(
|
2007-11-04 18:07:59 +00:00
|
|
|
ife($this->association, $this->association, $this->model),
|
|
|
|
$this->modelId, $this->field, $this->fieldSuffix
|
|
|
|
));
|
|
|
|
}
|
2006-08-12 01:18:28 +00:00
|
|
|
/**
|
|
|
|
* Allows a template or element to set a variable that will be available in
|
|
|
|
* a layout or other element. Analagous to Controller::set.
|
|
|
|
*
|
|
|
|
* @param mixed $one A string or an array of data.
|
|
|
|
* @param mixed $two Value in case $one is a string (which then works as the key).
|
|
|
|
* Unused if $one is an associative array, otherwise serves as the values to $one's keys.
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function set($one, $two = null) {
|
|
|
|
$data = null;
|
|
|
|
if (is_array($one)) {
|
|
|
|
if (is_array($two)) {
|
|
|
|
$data = array_combine($one, $two);
|
|
|
|
} else {
|
|
|
|
$data = $one;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$data = array($one => $two);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($data == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($data as $name => $value) {
|
2006-08-12 01:18:28 +00:00
|
|
|
if ($name == 'title') {
|
|
|
|
$this->pageTitle = $value;
|
|
|
|
} else {
|
2006-11-28 11:18:05 +00:00
|
|
|
$this->viewVars[$name] = $value;
|
2006-08-12 01:18:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-03-16 20:36:24 +00:00
|
|
|
* Displays an error page to the user. Uses layouts/error.ctp to render the page.
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2007-10-22 16:11:12 +00:00
|
|
|
* @param integer $code HTTP Error code (for instance: 404)
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $name Name of the error (for instance: Not Found)
|
|
|
|
* @param string $message Error message as a web page
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function error($code, $name, $message) {
|
2007-03-14 18:28:36 +00:00
|
|
|
header ("HTTP/1.1 {$code} {$name}");
|
|
|
|
print ($this->_render(
|
2007-12-14 22:20:44 +00:00
|
|
|
$this->_getLayoutFileName('error'),
|
2007-03-14 18:28:36 +00:00
|
|
|
array(
|
|
|
|
'code' => $code,
|
|
|
|
'name' => $name,
|
|
|
|
'message' => $message
|
|
|
|
)
|
|
|
|
));
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
|
|
|
|
/**
|
2005-12-22 01:07:28 +00:00
|
|
|
* Renders and returns output for given view filename with its
|
2005-07-10 05:08:19 +00:00
|
|
|
* array of data.
|
|
|
|
*
|
|
|
|
* @param string $___viewFn Filename of the view
|
2006-02-18 23:42:21 +00:00
|
|
|
* @param array $___dataForView Data to include in rendered view
|
2005-07-10 05:08:19 +00:00
|
|
|
* @return string Rendered output
|
2007-12-14 22:20:44 +00:00
|
|
|
* @access protected
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) {
|
2007-12-17 07:28:53 +00:00
|
|
|
$loadedHelpers = array();
|
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($this->helpers != false && $loadHelpers === true) {
|
|
|
|
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach (array_keys($loadedHelpers) as $helper) {
|
2007-12-17 07:28:53 +00:00
|
|
|
$camelBackedHelper = Inflector::variable($helper);
|
2006-05-26 05:29:17 +00:00
|
|
|
${$camelBackedHelper} =& $loadedHelpers[$helper];
|
2007-07-06 04:31:45 +00:00
|
|
|
$this->loaded[$camelBackedHelper] =& ${$camelBackedHelper};
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-03-04 09:12:09 +00:00
|
|
|
foreach ($loadedHelpers as $helper) {
|
|
|
|
if (is_object($helper)) {
|
|
|
|
if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) {
|
|
|
|
$helper->beforeRender();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
extract($___dataForView, EXTR_SKIP);
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
|
2006-12-05 09:49:59 +00:00
|
|
|
if (Configure::read() > 0) {
|
2006-05-26 05:29:17 +00:00
|
|
|
include ($___viewFn);
|
|
|
|
} else {
|
|
|
|
@include ($___viewFn);
|
|
|
|
}
|
|
|
|
|
2007-12-17 07:28:53 +00:00
|
|
|
if (!empty($loadedHelpers)) {
|
2006-06-14 18:02:37 +00:00
|
|
|
foreach ($loadedHelpers as $helper) {
|
|
|
|
if (is_object($helper)) {
|
|
|
|
if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) {
|
|
|
|
$helper->afterRender();
|
|
|
|
}
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
2007-10-01 16:49:37 +00:00
|
|
|
if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if (is_a($this->loaded['cache'], 'CacheHelper')) {
|
|
|
|
$cache =& $this->loaded['cache'];
|
|
|
|
|
|
|
|
if ($cached === true) {
|
|
|
|
$cache->view = &$this;
|
|
|
|
}
|
|
|
|
|
2007-10-26 08:40:10 +00:00
|
|
|
$cache->base = $this->base;
|
|
|
|
$cache->here = $this->here;
|
|
|
|
$cache->helpers = $this->helpers;
|
|
|
|
$cache->action = $this->action;
|
|
|
|
$cache->controllerName = $this->name;
|
2006-11-25 09:27:13 +00:00
|
|
|
$cache->layout = $this->layout;
|
2007-10-26 08:40:10 +00:00
|
|
|
$cache->cacheAction = $this->cacheAction;
|
2006-05-26 05:29:17 +00:00
|
|
|
$cache->cache($___viewFn, $out, $cached);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Loads helpers, with their dependencies.
|
|
|
|
*
|
|
|
|
* @param array $loaded List of helpers that are already loaded.
|
|
|
|
* @param array $helpers List of helpers to load.
|
2007-12-17 07:28:53 +00:00
|
|
|
* @param string $parent holds name of helper, if loaded helper has helpers
|
2006-02-18 23:42:21 +00:00
|
|
|
* @return array
|
2005-10-09 01:56:21 +00:00
|
|
|
*/
|
2007-12-17 07:28:53 +00:00
|
|
|
function &_loadHelpers(&$loaded, $helpers, $parent = null) {
|
|
|
|
if (empty($loaded)) {
|
|
|
|
$helpers[] = 'Session';
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($helpers as $helper) {
|
2007-03-23 10:34:21 +00:00
|
|
|
$parts = preg_split('/\/|\./', $helper);
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (count($parts) === 1) {
|
2006-07-29 17:08:23 +00:00
|
|
|
$plugin = $this->plugin;
|
|
|
|
} else {
|
|
|
|
$plugin = Inflector::underscore($parts['0']);
|
2007-03-23 10:34:21 +00:00
|
|
|
$helper = $parts[count($parts) - 1];
|
2006-07-29 17:08:23 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
$helperCn = $helper . 'Helper';
|
|
|
|
|
|
|
|
if (in_array($helper, array_keys($loaded)) !== true) {
|
|
|
|
if (!class_exists($helperCn)) {
|
2007-11-23 08:16:23 +00:00
|
|
|
if (is_null($plugin) || !App::import('Helper', $plugin . '.' . $helper)) {
|
|
|
|
if (!App::import('Helper', $helper)) {
|
2006-11-23 10:06:49 +00:00
|
|
|
$this->cakeError('missingHelperFile', array(array(
|
2007-03-22 00:37:45 +00:00
|
|
|
'helper' => $helper,
|
|
|
|
'file' => Inflector::underscore($helper) . '.php',
|
|
|
|
'base' => $this->base
|
|
|
|
)));
|
2006-11-23 10:06:49 +00:00
|
|
|
exit();
|
2006-08-20 22:21:22 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
|
|
|
if (!class_exists($helperCn)) {
|
2006-11-23 10:06:49 +00:00
|
|
|
$this->cakeError('missingHelperClass', array(array(
|
2007-03-14 18:28:36 +00:00
|
|
|
'helper' => $helper,
|
|
|
|
'file' => Inflector::underscore($helper) . '.php',
|
|
|
|
'base' => $this->base
|
|
|
|
)));
|
2006-11-23 10:06:49 +00:00
|
|
|
exit();
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-17 07:28:53 +00:00
|
|
|
$loaded[$helper] =& new $helperCn();
|
2006-07-31 23:55:29 +00:00
|
|
|
|
2007-08-16 17:54:02 +00:00
|
|
|
$vars = array('base', 'webroot', 'here', 'params', 'action', 'data', 'themeWeb', 'plugin');
|
2006-07-31 23:55:29 +00:00
|
|
|
$c = count($vars);
|
|
|
|
for ($j = 0; $j < $c; $j++) {
|
2007-12-17 07:28:53 +00:00
|
|
|
$loaded[$helper]->{$vars[$j]} = $this->{$vars[$j]};
|
2006-07-31 23:55:29 +00:00
|
|
|
}
|
2006-06-14 18:02:37 +00:00
|
|
|
|
|
|
|
if (!empty($this->validationErrors)) {
|
2007-12-17 07:28:53 +00:00
|
|
|
$loaded[$helper]->validationErrors = $this->validationErrors;
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-12-17 07:28:53 +00:00
|
|
|
if (is_array($loaded[$helper]->helpers) && !empty($loaded[$helper]->helpers)) {
|
|
|
|
$loaded =& $this->_loadHelpers($loaded, $loaded[$helper]->helpers, $helper);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-17 07:28:53 +00:00
|
|
|
|
|
|
|
if (isset($loaded[$parent])) {
|
|
|
|
$loaded[$parent]->{$helper} =& $loaded[$helper];
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
return $loaded;
|
|
|
|
}
|
2006-11-27 01:04:19 +00:00
|
|
|
/**
|
2007-12-14 22:20:44 +00:00
|
|
|
* Returns filename of given action's template file (.ctp) as a string.
|
|
|
|
* CamelCased action names will be under_scored! This means that you can have
|
|
|
|
* LongActionNames that refer to long_action_names.ctp views.
|
2006-11-27 01:04:19 +00:00
|
|
|
*
|
2007-12-14 22:20:44 +00:00
|
|
|
* @param string $action Controller action to find template filename for
|
|
|
|
* @return string Template filename
|
|
|
|
* @access protected
|
2006-11-27 01:04:19 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
function _getViewFileName($name = null) {
|
|
|
|
$subDir = null;
|
2007-12-20 01:19:19 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
if (!is_null($this->webservices)) {
|
|
|
|
$subDir = strtolower($this->webservices) . DS;
|
|
|
|
}
|
|
|
|
if (!is_null($this->subDir)) {
|
|
|
|
$subDir = $this->subDir . DS;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-12-22 19:24:56 +00:00
|
|
|
if ($name === null) {
|
2007-12-14 22:20:44 +00:00
|
|
|
$name = $this->action;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-12-29 21:20:48 +00:00
|
|
|
if (strpos($name, '/') === false && strpos($name, '..') === false) {
|
2007-12-14 22:20:44 +00:00
|
|
|
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
|
2007-12-29 21:20:48 +00:00
|
|
|
} elseif (strpos($name, '/') !== false) {
|
|
|
|
if ($name{0} === '/') {
|
|
|
|
if (is_file($name)) {
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
$name = trim($name, '/');
|
|
|
|
} else {
|
|
|
|
$name = $this->viewPath . DS . $subDir . $name;
|
2007-12-29 21:10:41 +00:00
|
|
|
}
|
2007-12-29 21:03:36 +00:00
|
|
|
if (DS !== '/') {
|
|
|
|
$name = implode(DS, explode('/', $name));
|
|
|
|
}
|
2007-12-14 22:20:44 +00:00
|
|
|
} elseif (strpos($name, '..') !== false) {
|
|
|
|
$name = explode('/', $name);
|
|
|
|
$i = array_search('..', $name);
|
|
|
|
unset($name[$i - 1]);
|
|
|
|
unset($name[$i]);
|
|
|
|
$name = '..' . DS . implode(DS, $name);
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths = $this->_paths($this->plugin);
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
if (file_exists($path . $name . $this->ext)) {
|
|
|
|
return $path . $name . $this->ext;
|
|
|
|
} elseif (file_exists($path . $name . '.thtml')) {
|
|
|
|
return $path . $name . '.thtml';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_missingView($paths[0] . $name . $this->ext, 'missingView');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns layout filename for this template as a string.
|
|
|
|
*
|
|
|
|
* @return string Filename for layout file (.ctp).
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
function _getLayoutFileName($name = null) {
|
2007-12-22 19:24:56 +00:00
|
|
|
if ($name === null) {
|
2007-12-14 22:20:44 +00:00
|
|
|
$name = $this->layout;
|
|
|
|
}
|
|
|
|
$subDir = null;
|
2007-12-17 07:28:53 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
if (!is_null($this->layoutPath)) {
|
|
|
|
$subDir = $this->layoutPath . DS;
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths = $this->_paths($this->plugin);
|
|
|
|
$file = 'layouts' . DS . $subDir . $name;
|
2007-12-17 07:28:53 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
foreach ($paths as $path) {
|
|
|
|
if (file_exists($path . $file . $this->ext)) {
|
|
|
|
return $path . $file . $this->ext;
|
|
|
|
} elseif (file_exists($path . $file . '.thtml')) {
|
|
|
|
return $path . $file . '.thtml';
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-14 22:20:44 +00:00
|
|
|
|
|
|
|
return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout');
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-11-27 01:04:19 +00:00
|
|
|
/**
|
|
|
|
* Return a misssing view error message
|
|
|
|
*
|
|
|
|
* @param string $viewFileName the filename that should exist
|
|
|
|
* @return cakeError
|
2006-11-28 11:18:05 +00:00
|
|
|
*/
|
2007-12-14 22:20:44 +00:00
|
|
|
function _missingView($file, $error = 'missingView') {
|
|
|
|
$paths = $this->_paths($this->plugin);
|
|
|
|
$name = 'errors' . DS . Inflector::underscore($error);
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
if (file_exists($path . $name . $this->ext)) {
|
|
|
|
$name = $path . $name . $this->ext;
|
|
|
|
break;
|
|
|
|
} elseif (file_exists($path . $name . '.thtml')) {
|
|
|
|
$name = $path . $name . '.thtml';
|
|
|
|
break;
|
2006-11-27 01:04:19 +00:00
|
|
|
}
|
2007-12-14 22:20:44 +00:00
|
|
|
}
|
2006-11-27 01:04:19 +00:00
|
|
|
|
2007-12-14 22:20:44 +00:00
|
|
|
if ($error === 'missingView') {
|
|
|
|
return $this->cakeError('missingView', array(array(
|
2007-10-13 15:38:07 +00:00
|
|
|
'className' => $this->name,
|
|
|
|
'action' => $this->action,
|
2007-12-14 22:20:44 +00:00
|
|
|
'file' => $file,
|
|
|
|
'base' => $this->base
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
if ($error === 'missingLayout') {
|
|
|
|
return $this->cakeError('missingLayout', array(array(
|
|
|
|
'layout' => $this->layout,
|
|
|
|
'file' => $file,
|
2007-10-13 15:38:07 +00:00
|
|
|
'base' => $this->base
|
|
|
|
)));
|
2007-12-14 22:20:44 +00:00
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return all possible paths to find view files in order
|
|
|
|
*
|
|
|
|
* @param string $plugin
|
|
|
|
* @return array paths
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
function _paths($plugin = null, $cached = true) {
|
2007-12-22 19:24:56 +00:00
|
|
|
if ($plugin === null && $cached === true && !empty($this->__paths)) {
|
2007-12-14 22:20:44 +00:00
|
|
|
return $this->__paths;
|
|
|
|
}
|
|
|
|
$paths = array();
|
|
|
|
$viewPaths = Configure::read('viewPaths');
|
|
|
|
if ($plugin !== null) {
|
|
|
|
$count = count($viewPaths);
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
|
|
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
|
2006-11-27 01:04:19 +00:00
|
|
|
}
|
2007-12-14 22:20:44 +00:00
|
|
|
|
|
|
|
$pluginPaths = Configure::read('pluginPaths');
|
|
|
|
$count = count($pluginPaths);
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
|
|
$paths[] = $pluginPaths[$i] . $plugin . DS . 'views' . DS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths = array_merge($paths, $viewPaths);
|
|
|
|
|
2007-12-22 19:24:56 +00:00
|
|
|
if (empty($this->__paths)) {
|
2007-12-14 22:20:44 +00:00
|
|
|
$this->__paths = $paths;
|
2006-11-27 01:04:19 +00:00
|
|
|
}
|
2007-12-14 22:20:44 +00:00
|
|
|
|
|
|
|
return $paths;
|
2006-11-27 01:04:19 +00:00
|
|
|
}
|
2006-02-01 13:26:23 +00:00
|
|
|
}
|
2007-05-03 04:35:25 +00:00
|
|
|
?>
|