2006-07-29 04:16:54 +00:00
|
|
|
<?php
|
2006-07-29 05:59:42 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2006-07-29 04:16:54 +00:00
|
|
|
/**
|
|
|
|
* A custom view class that is used for themeing
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-07-29 04:16:54 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-07-29 04:16:54 +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-07-29 04:16:54 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Theme view class
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view
|
|
|
|
*/
|
|
|
|
class ThemeView extends View {
|
|
|
|
/**
|
2007-03-05 09:38:31 +00:00
|
|
|
* System path to themed element: themed . DS . theme . DS . elements . DS
|
2006-07-29 04:16:54 +00:00
|
|
|
*
|
2007-03-05 09:38:31 +00:00
|
|
|
* @var string
|
2006-07-29 04:16:54 +00:00
|
|
|
*/
|
2007-03-05 09:38:31 +00:00
|
|
|
var $themeElement = null;
|
2006-07-29 04:16:54 +00:00
|
|
|
/**
|
2007-03-05 09:38:31 +00:00
|
|
|
* System path to themed layout: themed . DS . theme . DS . layouts . DS
|
2006-07-29 04:16:54 +00:00
|
|
|
*
|
2007-03-05 09:38:31 +00:00
|
|
|
* @var string
|
2006-07-29 04:16:54 +00:00
|
|
|
*/
|
2007-03-05 09:38:31 +00:00
|
|
|
var $themeLayout = null;
|
2006-07-29 04:16:54 +00:00
|
|
|
/**
|
2007-03-05 09:38:31 +00:00
|
|
|
* System path to themed: themed . DS . theme . DS
|
2006-07-29 04:16:54 +00:00
|
|
|
*
|
2007-03-05 09:38:31 +00:00
|
|
|
* @var string
|
2006-07-29 04:16:54 +00:00
|
|
|
*/
|
2007-03-05 09:38:31 +00:00
|
|
|
var $themePath = null;
|
2006-07-29 04:16:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $controller
|
|
|
|
*/
|
|
|
|
function __construct (&$controller) {
|
|
|
|
parent::__construct($controller);
|
2007-03-05 09:38:31 +00:00
|
|
|
|
2006-07-29 04:16:54 +00:00
|
|
|
$this->theme =& $controller->theme;
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($this->theme)) {
|
2007-06-20 07:51:52 +00:00
|
|
|
if (is_dir(WWW_ROOT . 'themed' . DS . $this->theme)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$this->themeWeb = 'themed/'. $this->theme .'/';
|
2007-02-08 05:21:28 +00:00
|
|
|
}
|
2007-03-05 09:38:31 +00:00
|
|
|
$this->themeElement = 'themed'. DS . $this->theme . DS .'elements'. DS;
|
|
|
|
$this->themeLayout = 'themed'. DS . $this->theme . DS .'layouts'. DS;
|
|
|
|
$this->themePath = 'themed'. DS . $this->theme . DS;
|
2007-02-08 04:38:10 +00:00
|
|
|
}
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $code
|
|
|
|
* @param unknown_type $name
|
|
|
|
* @param unknown_type $message
|
|
|
|
*/
|
|
|
|
function error($code, $name, $message) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$file = VIEWS . $this->themeLayout.'error'.$this->ext;
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!file_exists($file)) {
|
2006-07-29 04:16:54 +00:00
|
|
|
$file = LAYOUTS.'error'.$this->ext;
|
|
|
|
}
|
|
|
|
header ("HTTP/1.0 {$code} {$name}");
|
|
|
|
print ($this->_render($file, array('code' => $code,
|
|
|
|
'name' => $name,
|
|
|
|
'message' => $message)));
|
|
|
|
}
|
|
|
|
/**
|
2007-10-19 02:31:25 +00:00
|
|
|
* Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
|
2006-07-29 04:16:54 +00:00
|
|
|
*
|
2007-10-19 02:31:25 +00:00
|
|
|
* This realizes the concept of Elements, (or "partial layouts")
|
|
|
|
* and the $params array is used to send data to be used in the
|
|
|
|
* Element.
|
|
|
|
*
|
|
|
|
* @link
|
|
|
|
* @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
|
2006-07-29 04:16:54 +00:00
|
|
|
*/
|
2007-10-19 02:31:25 +00:00
|
|
|
function renderElement($name, $params = array(), $loadHelpers = false) {
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (isset($params['plugin'])) {
|
2007-12-03 00:27:50 +00:00
|
|
|
$reset = array('plugin' => $this->plugin,
|
|
|
|
'pluginPath' => $this->pluginPath,
|
|
|
|
'pluginPaths' => $this->pluginPaths);
|
2007-03-05 09:38:31 +00:00
|
|
|
$this->plugin = $params['plugin'];
|
|
|
|
$this->pluginPath = 'plugins' . DS . $this->plugin . DS;
|
2007-03-16 20:36:24 +00:00
|
|
|
$this->pluginPaths = array(
|
2007-10-19 02:31:25 +00:00
|
|
|
VIEWS . $this->pluginPath,
|
|
|
|
APP . $this->pluginPath . 'views' . DS,
|
|
|
|
);
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
2006-11-29 07:32:14 +00:00
|
|
|
|
2006-11-25 22:04:43 +00:00
|
|
|
$paths = Configure::getInstance();
|
2007-12-08 06:08:03 +00:00
|
|
|
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
2007-03-05 09:38:31 +00:00
|
|
|
|
|
|
|
$file = null;
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($viewPaths as $path) {
|
|
|
|
if (file_exists($path . $this->themeElement . $name . $this->ext)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$file = $path . $this->themeElement . $name . $this->ext;
|
2007-04-29 17:51:38 +00:00
|
|
|
break;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . $this->themeElement . $name . '.thtml')) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$file = $path . $this->themeElement . $name . '.thtml';
|
2007-04-29 17:51:38 +00:00
|
|
|
break;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . 'elements' . DS . $name . $this->ext)) {
|
2006-11-25 22:04:43 +00:00
|
|
|
$file = $path . 'elements' . DS . $name . $this->ext;
|
2007-04-29 17:51:38 +00:00
|
|
|
break;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . 'elements' . DS . $name . '.thtml')) {
|
2006-11-25 22:04:43 +00:00
|
|
|
$file = $path . 'elements' . DS . $name . '.thtml';
|
2007-04-29 17:51:38 +00:00
|
|
|
break;
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-05 09:38:31 +00:00
|
|
|
|
2007-10-19 02:31:25 +00:00
|
|
|
if (is_null($file)) {
|
|
|
|
$file = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . $name. '.ctp');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($file) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$params = array_merge_recursive($params, $this->loaded);
|
2007-12-03 00:27:50 +00:00
|
|
|
$return = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
2007-03-05 09:38:31 +00:00
|
|
|
} else {
|
2007-12-03 00:27:50 +00:00
|
|
|
if (!is_null($this->pluginPath)) {
|
|
|
|
$file = APP . $this->pluginPath . $this->themeElement . $name . $this->ext;
|
|
|
|
} else {
|
|
|
|
$file = VIEWS . $this->themeElement . $name . $this->ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Configure::read() > 0) {
|
|
|
|
$return = 'Not Found: ' . $file;
|
|
|
|
}
|
2007-03-05 09:38:31 +00:00
|
|
|
}
|
|
|
|
|
2007-12-03 00:27:50 +00:00
|
|
|
if (isset($params['plugin'])) {
|
|
|
|
$this->plugin = $reset['plugin'];
|
|
|
|
$this->pluginPath = $reset['pluginPath'];
|
|
|
|
$this->pluginPaths = $reset['pluginPaths'];
|
2007-03-05 09:38:31 +00:00
|
|
|
}
|
2007-12-03 00:27:50 +00:00
|
|
|
|
|
|
|
return $return;
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $action
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function _getViewFileName($action) {
|
|
|
|
$action = Inflector::underscore($action);
|
|
|
|
|
|
|
|
if (!is_null($this->webservices)) {
|
|
|
|
$type = strtolower($this->webservices) . DS;
|
|
|
|
} else {
|
|
|
|
$type = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$position = strpos($action, '..');
|
2007-03-05 09:38:31 +00:00
|
|
|
if ($position !== false) {
|
2006-07-29 04:16:54 +00:00
|
|
|
$action = explode('/', $action);
|
|
|
|
$i = array_search('..', $action);
|
|
|
|
unset($action[$i - 1]);
|
|
|
|
unset($action[$i]);
|
2007-03-05 09:38:31 +00:00
|
|
|
$action = '..' . DS . implode(DS, $action);
|
2006-11-29 07:32:14 +00:00
|
|
|
}
|
2006-07-29 04:16:54 +00:00
|
|
|
|
2007-03-05 09:38:31 +00:00
|
|
|
$paths = Configure::getInstance();
|
2007-12-08 06:08:03 +00:00
|
|
|
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
2007-03-05 09:38:31 +00:00
|
|
|
|
|
|
|
$name = $this->viewPath . DS . $this->subDir . $type . $action;
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($viewPaths as $path) {
|
|
|
|
if (file_exists($path . $this->themePath . $name . $this->ext)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $path . $this->themePath . $name . $this->ext;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . $this->themePath . $name . '.thtml')) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $path . $this->themePath . $name . '.thtml';
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . $name . $this->ext)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $path . $name . $this->ext;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . $name . '.thtml')) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $path . $name . '.thtml';
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-25 22:04:43 +00:00
|
|
|
if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $viewFileName;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $viewFileName;
|
2006-07-29 04:16:54 +00:00
|
|
|
} else {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!is_null($this->pluginPath)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$viewFileName = APP . $this->pluginPath . $this->themePath . $name . $this->ext;
|
|
|
|
} else {
|
|
|
|
$viewFileName = VIEWS . $this->themePath . $name . $this->ext;
|
|
|
|
}
|
|
|
|
$this->_missingView($viewFileName, $action);
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
2007-03-05 09:38:31 +00:00
|
|
|
return false;
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function _getLayoutFileName() {
|
|
|
|
if (isset($this->webservices) && !is_null($this->webservices)) {
|
|
|
|
$type = strtolower($this->webservices) . DS;
|
|
|
|
} else {
|
|
|
|
$type = null;
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!is_null($this->layoutPath)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
$type = $this->layoutPath . DS;
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths = Configure::getInstance();
|
2007-12-08 06:08:03 +00:00
|
|
|
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
2007-03-05 09:38:31 +00:00
|
|
|
|
|
|
|
$name = $this->subDir . $type . $this->layout;
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($viewPaths as $path) {
|
|
|
|
if (file_exists($path . $this->themeLayout . $name . $this->ext)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $path . $this->themeLayout . $name . $this->ext;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . $this->themeLayout . $name . '.thtml')) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $path . $this->themeLayout . $name . '.thtml';
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . 'layouts' . DS . $name . $this->ext)) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $path . 'layouts' . DS . $name . $this->ext;
|
2007-06-20 06:15:35 +00:00
|
|
|
} elseif (file_exists($path . 'layouts' . DS . $name . '.thtml')) {
|
2007-03-05 09:38:31 +00:00
|
|
|
return $path . 'layouts' . DS . $name . '.thtml';
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!is_null($this->pluginPath)) {
|
2007-04-29 17:51:38 +00:00
|
|
|
$layoutFileName = APP . $this->pluginPath . 'views' . DS . $this->themeLayout . $name . $this->ext;
|
2006-07-29 04:16:54 +00:00
|
|
|
} else {
|
2007-04-29 17:51:38 +00:00
|
|
|
$layoutFileName = VIEWS . $this->themeLayout . $name . $this->ext;
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
2007-04-29 17:51:38 +00:00
|
|
|
|
|
|
|
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . $this->layout . '.ctp');
|
|
|
|
if (empty($default) && !empty($type)) {
|
|
|
|
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . 'default.ctp');
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
if (empty($default)) {
|
2007-04-29 17:51:38 +00:00
|
|
|
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $this->layout . '.ctp');
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!empty($default)) {
|
2007-04-29 17:51:38 +00:00
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
return $layoutFileName;
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-03 04:35:25 +00:00
|
|
|
?>
|