mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
cleaning up some deprecated code. renderElement is deprecated, but a the notice was removed for this release. Notice will be thrown in next release and method will be removed in the following release. Refactor of View Caching, along with addition of enabling beforeFilter and component initialize/startup callbacks. Use {{{
//set for the individual action var $cacheAction = array('view' => array('duration' => '+1 hour', 'callbacks' => false)); //globally disable callbacks for all actions var $cacheAction = array(callbacks' => false, 'view' => '+1 hour'); //per method $this->cacheAction = array('duration' => '+1 hour', 'callbacks' => true); }}} git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7031 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
9c722b6999
commit
f7d07012dd
3 changed files with 180 additions and 195 deletions
191
cake/basics.php
191
cake/basics.php
|
@ -48,57 +48,6 @@ if (!function_exists('clone')) {
|
|||
}');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get CakePHP basic paths as an indexed array.
|
||||
* Resulting array will contain array of paths
|
||||
* indexed by: Models, Behaviors, Controllers,
|
||||
* Components, and Helpers.
|
||||
*
|
||||
* @return array Array of paths indexed by type
|
||||
* @deprecated See Configure::corePaths
|
||||
*/
|
||||
function paths() {
|
||||
$directories = Configure::getInstance();
|
||||
$paths = array();
|
||||
|
||||
foreach ($directories->modelPaths as $path) {
|
||||
$paths['Models'][] = $path;
|
||||
}
|
||||
foreach ($directories->behaviorPaths as $path) {
|
||||
$paths['Behaviors'][] = $path;
|
||||
}
|
||||
foreach ($directories->controllerPaths as $path) {
|
||||
$paths['Controllers'][] = $path;
|
||||
}
|
||||
foreach ($directories->componentPaths as $path) {
|
||||
$paths['Components'][] = $path;
|
||||
}
|
||||
foreach ($directories->helperPaths as $path) {
|
||||
$paths['Helpers'][] = $path;
|
||||
}
|
||||
|
||||
if (!class_exists('Folder')) {
|
||||
App::import('Core', 'Folder');
|
||||
}
|
||||
|
||||
$folder =& new Folder(APP.'plugins'.DS);
|
||||
$plugins = $folder->ls();
|
||||
$classPaths = array('models', 'models'.DS.'behaviors', 'controllers', 'controllers'.DS.'components', 'views'.DS.'helpers');
|
||||
|
||||
foreach ($plugins[0] as $plugin) {
|
||||
foreach ($classPaths as $path) {
|
||||
if (strpos($path, DS) !== false) {
|
||||
$key = explode(DS, $path);
|
||||
$key = $key[1];
|
||||
} else {
|
||||
$key = $path;
|
||||
}
|
||||
$folder->path = APP.'plugins'.DS.$plugin.DS.$path;
|
||||
$paths[Inflector::camelize($plugin)][Inflector::camelize($key)][] = $folder->path;
|
||||
}
|
||||
}
|
||||
return $paths;
|
||||
}
|
||||
/**
|
||||
* Loads configuration files. Receives a set of configuration files
|
||||
* to load.
|
||||
|
@ -144,38 +93,6 @@ if (!function_exists('clone')) {
|
|||
require_once(LIBS . strtolower($file) . '.php');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
function vendor() {
|
||||
trigger_error('(vendor) Deprecated, see App::import(\'Vendor\', \'...\');', E_USER_WARNING);
|
||||
$args = func_get_args();
|
||||
$c = func_num_args();
|
||||
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
$arg = $args[$i];
|
||||
|
||||
if (strpos($arg, '.') !== false) {
|
||||
$file = explode('.', $arg);
|
||||
$plugin = Inflector::underscore($file[0]);
|
||||
unset($file[0]);
|
||||
$file = implode('.', $file);
|
||||
if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'vendors' . DS . $file . '.php')) {
|
||||
require_once(APP . 'plugins' . DS . $plugin . DS . 'vendors' . DS . $file . '.php');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists(APP . 'vendors' . DS . $arg . '.php')) {
|
||||
require_once(APP . 'vendors' . DS . $arg . '.php');
|
||||
} elseif (file_exists(VENDORS . $arg . '.php')) {
|
||||
require_once(VENDORS . $arg . '.php');
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Prints out debug information about given variable.
|
||||
*
|
||||
|
@ -424,22 +341,6 @@ if (!function_exists('clone')) {
|
|||
}
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* see Dispatcher::uri();
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function setUri() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* see Dispatcher::getUrl();
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function setUrl() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Gets an environment variable from available sources, and provides emulation
|
||||
* for unsupported or inconsisten environment variables (i.e. DOCUMENT_ROOT on
|
||||
|
@ -1169,4 +1070,96 @@ if (!function_exists('clone')) {
|
|||
trigger_error('listClasses is deprecated see Configure::listObjects(\'file\', $path);', E_USER_WARNING);
|
||||
return Configure::listObjects('file', $path);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see Configure::corePaths();
|
||||
*/
|
||||
function paths() {
|
||||
$directories = Configure::getInstance();
|
||||
$paths = array();
|
||||
|
||||
foreach ($directories->modelPaths as $path) {
|
||||
$paths['Models'][] = $path;
|
||||
}
|
||||
foreach ($directories->behaviorPaths as $path) {
|
||||
$paths['Behaviors'][] = $path;
|
||||
}
|
||||
foreach ($directories->controllerPaths as $path) {
|
||||
$paths['Controllers'][] = $path;
|
||||
}
|
||||
foreach ($directories->componentPaths as $path) {
|
||||
$paths['Components'][] = $path;
|
||||
}
|
||||
foreach ($directories->helperPaths as $path) {
|
||||
$paths['Helpers'][] = $path;
|
||||
}
|
||||
|
||||
if (!class_exists('Folder')) {
|
||||
App::import('Core', 'Folder');
|
||||
}
|
||||
|
||||
$folder =& new Folder(APP.'plugins'.DS);
|
||||
$plugins = $folder->ls();
|
||||
$classPaths = array('models', 'models'.DS.'behaviors', 'controllers', 'controllers'.DS.'components', 'views'.DS.'helpers');
|
||||
|
||||
foreach ($plugins[0] as $plugin) {
|
||||
foreach ($classPaths as $path) {
|
||||
if (strpos($path, DS) !== false) {
|
||||
$key = explode(DS, $path);
|
||||
$key = $key[1];
|
||||
} else {
|
||||
$key = $path;
|
||||
}
|
||||
$folder->path = APP.'plugins'.DS.$plugin.DS.$path;
|
||||
$paths[Inflector::camelize($plugin)][Inflector::camelize($key)][] = $folder->path;
|
||||
}
|
||||
}
|
||||
return $paths;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
function vendor() {
|
||||
trigger_error('(vendor) Deprecated, see App::import(\'Vendor\', \'...\');', E_USER_WARNING);
|
||||
$args = func_get_args();
|
||||
$c = func_num_args();
|
||||
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
$arg = $args[$i];
|
||||
|
||||
if (strpos($arg, '.') !== false) {
|
||||
$file = explode('.', $arg);
|
||||
$plugin = Inflector::underscore($file[0]);
|
||||
unset($file[0]);
|
||||
$file = implode('.', $file);
|
||||
if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'vendors' . DS . $file . '.php')) {
|
||||
require_once(APP . 'plugins' . DS . $plugin . DS . 'vendors' . DS . $file . '.php');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists(APP . 'vendors' . DS . $arg . '.php')) {
|
||||
require_once(APP . 'vendors' . DS . $arg . '.php');
|
||||
} elseif (file_exists(VENDORS . $arg . '.php')) {
|
||||
require_once(VENDORS . $arg . '.php');
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see Dispatcher::uri();
|
||||
*/
|
||||
function setUri() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see Dispatcher::getUrl();
|
||||
*/
|
||||
function setUrl() {
|
||||
return null;
|
||||
}
|
||||
?>
|
|
@ -65,7 +65,6 @@ class CacheHelper extends AppHelper {
|
|||
* @access public
|
||||
*/
|
||||
var $cacheAction;
|
||||
|
||||
/**
|
||||
* Main method used to cache a view
|
||||
*
|
||||
|
@ -75,6 +74,8 @@ class CacheHelper extends AppHelper {
|
|||
* @return view ouput
|
||||
*/
|
||||
function cache($file, $out, $cache = false) {
|
||||
$cacheTime = 0;
|
||||
$useCallbacks = true;
|
||||
if (is_array($this->cacheAction)) {
|
||||
$check = str_replace('/', '_', $this->here);
|
||||
$replace = str_replace('/', '_', $this->base);
|
||||
|
@ -110,11 +111,23 @@ class CacheHelper extends AppHelper {
|
|||
} elseif ($this->action == 'index') {
|
||||
$index = 'index';
|
||||
}
|
||||
|
||||
$options = $this->cacheAction;
|
||||
if (isset($this->cacheAction[$index])) {
|
||||
$cacheTime = $this->cacheAction[$index];
|
||||
} else {
|
||||
$cacheTime = 0;
|
||||
if (is_array($this->cacheAction[$index])) {
|
||||
$options = array_merge(array('duration'=> 0, 'callbacks' => true), $this->cacheAction[$index]);
|
||||
} else {
|
||||
$cacheTime = $this->cacheAction[$index];
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('duration', $options)) {
|
||||
$cacheTime = $options['duration'];
|
||||
}
|
||||
if (array_key_exists('callbacks', $options)) {
|
||||
$useCallbacks = $options['callbacks'];
|
||||
}
|
||||
|
||||
} else {
|
||||
$cacheTime = $this->cacheAction;
|
||||
}
|
||||
|
@ -124,7 +137,7 @@ class CacheHelper extends AppHelper {
|
|||
|
||||
if ($cache === true) {
|
||||
$cached = $this->__parseOutput($out);
|
||||
$this->__writeFile($cached, $cacheTime);
|
||||
$this->__writeFile($cached, $cacheTime, $useCallbacks);
|
||||
}
|
||||
return $out;
|
||||
} else {
|
||||
|
@ -201,7 +214,7 @@ class CacheHelper extends AppHelper {
|
|||
* @return cached view
|
||||
* @access private
|
||||
*/
|
||||
function __writeFile($content, $timestamp) {
|
||||
function __writeFile($content, $timestamp, $useCallbacks = true) {
|
||||
$now = time();
|
||||
|
||||
if (is_numeric($timestamp)) {
|
||||
|
@ -209,66 +222,62 @@ class CacheHelper extends AppHelper {
|
|||
} else {
|
||||
$cacheTime = strtotime($timestamp, $now);
|
||||
}
|
||||
|
||||
$cache = Inflector::slug($this->here);
|
||||
|
||||
if (empty($cache)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cache = $cache . '.php';
|
||||
$file = '<!--cachetime:' . $cacheTime . '--><?php';
|
||||
|
||||
if (empty($this->plugin)) {
|
||||
$file .= '
|
||||
App::import(\'Controller\', \'' . $this->controllerName. '\');
|
||||
App::import(\'Model\');
|
||||
';
|
||||
} else {
|
||||
$file .= '
|
||||
if (!class_exists(\'AppController\')) {
|
||||
if (file_exists(\'' . APP . 'app_controller.php\')) {
|
||||
require(\''. APP . 'app_controller.php\');
|
||||
} else {
|
||||
require(\''.CAKE . 'app_controller.php\');
|
||||
}
|
||||
}
|
||||
App::import(\'Controller\', \'' . $this->plugin . '.' . $this->controllerName. '\');
|
||||
App::import(\'Model\', \''.$this->plugin.'\');
|
||||
';
|
||||
}
|
||||
$file .= '$this->controller = new ' . $this->controllerName . 'Controller();
|
||||
$this->controller->plugin = \''.$this->plugin.'\';
|
||||
$this->controller->_initComponents();
|
||||
$this->helpers = unserialize(\'' . serialize($this->helpers) . '\');
|
||||
$this->base = \'' . $this->base . '\';
|
||||
$this->layout = \'' . $this->layout. '\';
|
||||
$this->webroot = \'' . $this->webroot . '\';
|
||||
$this->here = \'' . $this->here . '\';
|
||||
$this->namedArgs = \'' . $this->namedArgs . '\';
|
||||
$this->argSeparator = \'' . $this->argSeparator . '\';
|
||||
$this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\'));
|
||||
$this->action = unserialize(\'' . serialize($this->action) . '\');
|
||||
$this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\'));
|
||||
$this->themeWeb = \'' . $this->themeWeb . '\';
|
||||
$this->plugin = \'' . $this->plugin . '\';
|
||||
Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));
|
||||
$loadedHelpers = array();
|
||||
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
|
||||
foreach (array_keys($loadedHelpers) as $helper)
|
||||
{
|
||||
$replace = strtolower(substr($helper, 0, 1));
|
||||
$camelBackedHelper = preg_replace(\'/\\w/\', $replace, $helper, 1);
|
||||
${$camelBackedHelper} =& $loadedHelpers[$helper];
|
||||
|
||||
if (isset(${$camelBackedHelper}->helpers) && is_array(${$camelBackedHelper}->helpers))
|
||||
{
|
||||
foreach (${$camelBackedHelper}->helpers as $subHelper)
|
||||
{
|
||||
${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper];
|
||||
}
|
||||
$file .= '$controller = new ' . $this->controllerName . 'Controller();
|
||||
$controller->plugin = $this->plugin = \''.$this->plugin.'\';
|
||||
$controller->helpers = $this->helpers = unserialize(\'' . serialize($this->helpers) . '\');
|
||||
$controller->base = $this->base = \'' . $this->base . '\';
|
||||
$controller->layout = $this->layout = \'' . $this->layout. '\';
|
||||
$controller->webroot = $this->webroot = \'' . $this->webroot . '\';
|
||||
$controller->here = $this->here = \'' . $this->here . '\';
|
||||
$controller->namedArgs = $this->namedArgs = \'' . $this->namedArgs . '\';
|
||||
$controller->argSeparator = $this->argSeparator = \'' . $this->argSeparator . '\';
|
||||
$controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\'));
|
||||
$controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\');
|
||||
$controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\'));
|
||||
$controller->themeWeb = $this->themeWeb = \'' . $this->themeWeb . '\';';
|
||||
|
||||
if ($useCallbacks == true) {
|
||||
$file .= '$controller->constructClasses();
|
||||
$controller->beforeFilter();
|
||||
foreach ($controller->components as $c) {
|
||||
$path = preg_split(\'/\/|\./\', $c);
|
||||
$c = $path[count($path) - 1];
|
||||
|
||||
if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, \'startup\'))) {
|
||||
if (!array_key_exists(\'enabled\', get_object_vars($controller->{$c})) || $controller->{$c}->enabled == true) {
|
||||
$controller->{$c}->startup($controller);
|
||||
}
|
||||
$this->loaded[$camelBackedHelper] = (${$camelBackedHelper});
|
||||
}
|
||||
?>';
|
||||
}';
|
||||
}
|
||||
|
||||
$file .= '
|
||||
$loadedHelpers = array();
|
||||
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
|
||||
foreach (array_keys($loadedHelpers) as $helper) {
|
||||
$camelBackedHelper = Inflector::variable($helper);
|
||||
${$camelBackedHelper} =& $loadedHelpers[$helper];
|
||||
$this->loaded[$camelBackedHelper] =& ${$camelBackedHelper};
|
||||
}
|
||||
?>';
|
||||
$content = preg_replace("/(<\\?xml)/", "<?php echo '$1';?>",$content);
|
||||
$file .= $content;
|
||||
return cache('views' . DS . $cache, $file, $timestamp);
|
||||
|
|
|
@ -25,12 +25,10 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Included libraries.
|
||||
*/
|
||||
App::import('Core', array('Helper', 'ClassRegistry'));
|
||||
|
||||
/**
|
||||
* View, the V in the MVC triad.
|
||||
*
|
||||
|
@ -271,13 +269,12 @@ class View extends Object {
|
|||
$this->{$var} = $controller->{$var};
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
|
||||
if ($register) {
|
||||
ClassRegistry::addObject('view', $this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
|
||||
*
|
||||
|
@ -292,17 +289,18 @@ class View extends Object {
|
|||
*/
|
||||
function element($name, $params = array(), $loadHelpers = false) {
|
||||
$file = $plugin = $key = null;
|
||||
|
||||
|
||||
if (isset($params['plugin'])) {
|
||||
$plugin = $params['plugin'];
|
||||
}
|
||||
|
||||
|
||||
if (isset($this->plugin) && !$plugin) {
|
||||
$plugin = $this->plugin;
|
||||
}
|
||||
|
||||
|
||||
if (isset($params['cache'])) {
|
||||
$expires = '+1 day';
|
||||
|
||||
if (is_array($params['cache'])) {
|
||||
$expires = $params['cache']['time'];
|
||||
$key = Inflector::slug($params['cache']['key']);
|
||||
|
@ -310,13 +308,14 @@ class View extends Object {
|
|||
$expires = $params['cache'];
|
||||
$key = implode('_', array_keys($params));
|
||||
}
|
||||
|
||||
if ($expires) {
|
||||
$cacheFile = 'element_' . $key . '_' . $plugin . Inflector::slug($name);
|
||||
$cache = cache('views' . DS . $cacheFile, null, $expires);
|
||||
|
||||
if (is_string($cache)) {
|
||||
return $cache;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$paths = $this->_paths($plugin);
|
||||
|
@ -330,6 +329,7 @@ class View extends Object {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_file($file)) {
|
||||
$params = array_merge_recursive($params, $this->loaded);
|
||||
$element = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
||||
|
@ -338,13 +338,11 @@ class View extends Object {
|
|||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
$file = $paths[0] . 'elements' . DS . $name . $this->ext;
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
return "Not Found: " . $file;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Renders view for given action and layout. If $file is given, that is used
|
||||
|
@ -356,11 +354,9 @@ class View extends Object {
|
|||
* @return string Rendered Element
|
||||
*/
|
||||
function render($action = null, $layout = null, $file = null) {
|
||||
|
||||
if ($this->hasRendered) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$out = null;
|
||||
|
||||
if ($file != null) {
|
||||
|
@ -388,21 +384,12 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
$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);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see View::element
|
||||
*/
|
||||
function renderElement($name, $params = array(), $loadHelpers = false) {
|
||||
trigger_error(__("View::renderElement is deprecated see View::element('name', 'params');", true), E_USER_NOTICE);
|
||||
return $this->element($name, $params, $loadHelpers);
|
||||
}
|
||||
/**
|
||||
* Renders a layout. Returns output from _render(). Returns false on error.
|
||||
*
|
||||
|
@ -411,7 +398,6 @@ class View extends Object {
|
|||
*/
|
||||
function renderLayout($content_for_layout, $layout = null) {
|
||||
$layout_fn = $this->_getLayoutFileName($layout);
|
||||
|
||||
$debug = '';
|
||||
|
||||
if (isset($this->viewVars['cakeDebug']) && Configure::read() > 2) {
|
||||
|
@ -424,7 +410,6 @@ class View extends Object {
|
|||
} else {
|
||||
$pageTitle = Inflector::humanize($this->viewPath);
|
||||
}
|
||||
|
||||
$data_for_layout = array_merge($this->viewVars,
|
||||
array(
|
||||
'title_for_layout' => $pageTitle,
|
||||
|
@ -449,20 +434,20 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (substr($layout_fn, -3) === 'ctp' || substr($layout_fn, -5) === 'thtml') {
|
||||
$this->output = View::_render($layout_fn, $data_for_layout, $loadHelpers, true);
|
||||
} else {
|
||||
$this->output = $this->_render($layout_fn, $data_for_layout, $loadHelpers);
|
||||
}
|
||||
|
||||
|
||||
if ($this->output === false) {
|
||||
$this->output = $this->_render($layout_fn, $data_for_layout);
|
||||
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>", true), $layout_fn, $this->output), E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($this->loaded)) {
|
||||
foreach ($this->loaded as $helper) {
|
||||
if (is_object($helper)) {
|
||||
|
@ -472,8 +457,6 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
$this->TEST = 'TESTS';
|
||||
|
||||
return $this->output;
|
||||
}
|
||||
/**
|
||||
|
@ -489,7 +472,6 @@ class View extends Object {
|
|||
if (Configure::read() > 0 && $this->layout != 'xml') {
|
||||
echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->";
|
||||
}
|
||||
|
||||
$out = ob_get_clean();
|
||||
|
||||
if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match)) {
|
||||
|
@ -556,9 +538,10 @@ class View extends Object {
|
|||
*/
|
||||
function uuid($object, $url) {
|
||||
$c = 1;
|
||||
$hash = $object . substr(md5($object . Router::url($url)), 0, 10);
|
||||
$url = Router::url($url);
|
||||
$hash = $object . substr(md5($object . $url), 0, 10);
|
||||
while (in_array($hash, $this->uuids)) {
|
||||
$hash = $object . substr(md5($object . Router::url($url) . $c), 0, 10);
|
||||
$hash = $object . substr(md5($object . $url . $c), 0, 10);
|
||||
$c++;
|
||||
}
|
||||
$this->uuids[] = $hash;
|
||||
|
@ -608,7 +591,6 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error page to the user. Uses layouts/error.ctp to render the page.
|
||||
*
|
||||
|
@ -619,9 +601,10 @@ class View extends Object {
|
|||
function error($code, $name, $message) {
|
||||
header ("HTTP/1.1 {$code} {$name}");
|
||||
print ($this->_render(
|
||||
$this->_getLayoutFileName('error'), array('code' => $code, 'name' => $name, 'message' => $message)));
|
||||
$this->_getLayoutFileName('error'),
|
||||
array('code' => $code, 'name' => $name, 'message' => $message)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders and returns output for given view filename with its
|
||||
* array of data.
|
||||
|
@ -651,9 +634,7 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extract($___dataForView, EXTR_SKIP);
|
||||
|
||||
ob_start();
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
|
@ -671,7 +652,6 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$out = ob_get_clean();
|
||||
|
||||
if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) {
|
||||
|
@ -681,7 +661,6 @@ class View extends Object {
|
|||
if ($cached === true) {
|
||||
$cache->view = &$this;
|
||||
}
|
||||
|
||||
$cache->base = $this->base;
|
||||
$cache->here = $this->here;
|
||||
$cache->helpers = $this->helpers;
|
||||
|
@ -692,7 +671,6 @@ class View extends Object {
|
|||
$cache->cache($___viewFn, $out, $cached);
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
|
@ -747,9 +725,9 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
$loaded[$helper] =& new $helperCn($options);
|
||||
|
||||
$vars = array('base', 'webroot', 'here', 'params', 'action', 'data', 'themeWeb', 'plugin');
|
||||
$c = count($vars);
|
||||
|
||||
for ($j = 0; $j < $c; $j++) {
|
||||
$loaded[$helper]->{$vars[$j]} = $this->{$vars[$j]};
|
||||
}
|
||||
|
@ -778,6 +756,7 @@ class View extends Object {
|
|||
*/
|
||||
function _getViewFileName($name = null) {
|
||||
$subDir = null;
|
||||
|
||||
if (!is_null($this->subDir)) {
|
||||
$subDir = $this->subDir . DS;
|
||||
}
|
||||
|
@ -785,8 +764,8 @@ class View extends Object {
|
|||
if ($name === null) {
|
||||
$name = $this->action;
|
||||
}
|
||||
|
||||
$name = str_replace('/', DS, $name);
|
||||
|
||||
if (strpos($name, DS) === false && strpos($name, '..') === false) {
|
||||
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
|
||||
} elseif (strpos($name, DS) !== false) {
|
||||
|
@ -805,8 +784,8 @@ class View extends Object {
|
|||
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;
|
||||
|
@ -816,8 +795,8 @@ class View extends Object {
|
|||
return $path . $name . '.thtml';
|
||||
}
|
||||
}
|
||||
|
||||
$defaultPath = $paths[0];
|
||||
|
||||
if ($this->plugin) {
|
||||
$pluginPaths = Configure::read('pluginPaths');
|
||||
foreach ($paths as $path) {
|
||||
|
@ -845,7 +824,6 @@ class View extends Object {
|
|||
if (!is_null($this->layoutPath)) {
|
||||
$subDir = $this->layoutPath . DS;
|
||||
}
|
||||
|
||||
$paths = $this->_paths($this->plugin);
|
||||
$file = 'layouts' . DS . $subDir . $name;
|
||||
|
||||
|
@ -858,7 +836,6 @@ class View extends Object {
|
|||
return $path . $file . '.thtml';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout');
|
||||
}
|
||||
/**
|
||||
|
@ -900,26 +877,32 @@ class View extends Object {
|
|||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
if (empty($this->__paths)) {
|
||||
$this->__paths = $paths;
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see View::element
|
||||
*/
|
||||
function renderElement($name, $params = array(), $loadHelpers = false) {
|
||||
return $this->element($name, $params, $loadHelpers);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue