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-02-08 05:15:04 +00:00
|
|
|
if(!empty($this->theme)) {
|
2007-02-08 05:21:28 +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;
|
2006-07-29 04:16:54 +00:00
|
|
|
if(!file_exists($file)) {
|
|
|
|
$file = LAYOUTS.'error'.$this->ext;
|
|
|
|
}
|
|
|
|
header ("HTTP/1.0 {$code} {$name}");
|
|
|
|
print ($this->_render($file, array('code' => $code,
|
|
|
|
'name' => $name,
|
|
|
|
'message' => $message)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $name
|
|
|
|
* @param unknown_type $params
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function renderElement($name, $params = array()) {
|
2007-03-05 09:38:31 +00:00
|
|
|
if(isset($params['plugin'])) {
|
|
|
|
$this->plugin = $params['plugin'];
|
|
|
|
$this->pluginPath = 'plugins' . DS . $this->plugin . DS;
|
2007-03-16 20:36:24 +00:00
|
|
|
$this->pluginPaths = array(
|
|
|
|
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-03-05 09:38:31 +00:00
|
|
|
$viewPaths = am($this->pluginPaths, $paths->viewPaths);
|
|
|
|
|
|
|
|
$file = null;
|
|
|
|
foreach($viewPaths as $path) {
|
|
|
|
if(file_exists($path . $this->themeElement . $name . $this->ext)) {
|
|
|
|
$file = $path . $this->themeElement . $name . $this->ext;
|
2007-04-29 17:51:38 +00:00
|
|
|
break;
|
2007-03-05 09:38:31 +00:00
|
|
|
} else if(file_exists($path . $this->themeElement . $name . '.thtml')) {
|
|
|
|
$file = $path . $this->themeElement . $name . '.thtml';
|
2007-04-29 17:51:38 +00:00
|
|
|
break;
|
2007-03-05 09:38:31 +00:00
|
|
|
} else if(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-03-05 09:38:31 +00:00
|
|
|
} else if(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
|
|
|
|
|
|
|
if(!is_null($file)) {
|
|
|
|
$params = array_merge_recursive($params, $this->loaded);
|
|
|
|
return $this->_render($file, array_merge($this->viewVars, $params), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
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();
|
|
|
|
$viewPaths = am($this->pluginPaths, $paths->viewPaths);
|
|
|
|
|
|
|
|
$name = $this->viewPath . DS . $this->subDir . $type . $action;
|
|
|
|
foreach($viewPaths as $path) {
|
|
|
|
if(file_exists($path . $this->themePath . $name . $this->ext)) {
|
|
|
|
return $path . $this->themePath . $name . $this->ext;
|
|
|
|
} else if(file_exists($path . $this->themePath . $name . '.thtml')) {
|
|
|
|
return $path . $this->themePath . $name . '.thtml';
|
|
|
|
} else if(file_exists($path . $name . $this->ext)) {
|
|
|
|
return $path . $name . $this->ext;
|
|
|
|
} else if(file_exists($path . $name . '.thtml')) {
|
|
|
|
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;
|
2006-11-25 22:04:43 +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-03-05 09:38:31 +00:00
|
|
|
if(!is_null($this->pluginPath)) {
|
|
|
|
$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-03-05 09:38:31 +00:00
|
|
|
if(!is_null($this->layoutPath)) {
|
|
|
|
$type = $this->layoutPath . DS;
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths = Configure::getInstance();
|
|
|
|
$viewPaths = am($this->pluginPaths, $paths->viewPaths);
|
|
|
|
|
|
|
|
$name = $this->subDir . $type . $this->layout;
|
|
|
|
foreach($viewPaths as $path) {
|
|
|
|
if(file_exists($path . $this->themeLayout . $name . $this->ext)) {
|
|
|
|
return $path . $this->themeLayout . $name . $this->ext;
|
|
|
|
} else if(file_exists($path . $this->themeLayout . $name . '.thtml')) {
|
|
|
|
return $path . $this->themeLayout . $name . '.thtml';
|
|
|
|
} else if(file_exists($path . 'layouts' . DS . $name . $this->ext)) {
|
|
|
|
return $path . 'layouts' . DS . $name . $this->ext;
|
|
|
|
} else if(file_exists($path . 'layouts' . DS . $name . '.thtml')) {
|
|
|
|
return $path . 'layouts' . DS . $name . '.thtml';
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-05 09:38:31 +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');
|
|
|
|
}
|
|
|
|
if(empty($default)) {
|
|
|
|
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $this->layout . '.ctp');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($default)) {
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
return $layoutFileName;
|
2006-07-29 04:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-03 04:35:25 +00:00
|
|
|
?>
|