cakephp2-php8/lib/Cake/View/ThemeView.php

74 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* A custom view class that is used for themeing
*
2010-10-03 16:38:58 +00:00
* PHP 5
*
2009-11-06 06:46:59 +00:00
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
2011-05-29 21:31:39 +00:00
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
2011-05-29 21:31:39 +00:00
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
2009-11-06 06:00:11 +00:00
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.View
* @since CakePHP(tm) v 0.10.0.1076
2009-11-06 06:51:51 +00:00
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
/**
* Theme view class
*
2009-08-25 02:57:01 +00:00
* Allows the creation of multiple themes to be used in an app. Theme views are regular view files
* that can provide unique HTML and static assets. If theme views are not found for the current view
* the default app view files will be used. You can set `$this->theme` and `$this->viewClass = 'Theme'`
2009-08-25 02:57:01 +00:00
* in your Controller to use the ThemeView.
*
2011-06-20 00:28:40 +00:00
* Example of theme path with `$this->theme = 'super_hot';` Would be `app/View/Themed/SuperHot/Posts`
2009-08-25 02:57:01 +00:00
*
* @package Cake.View
*/
class ThemeView extends View {
/**
2009-08-25 02:53:09 +00:00
* Constructor for ThemeView sets $this->theme.
*
* @param Controller $controller Controller object to be rendered.
*/
public function __construct($controller) {
parent::__construct($controller);
if ($controller) {
$this->theme = $controller->theme;
}
}
/**
* Return all possible paths to find view files in order
*
* @param string $plugin The name of the plugin views are being found for.
* @param boolean $cached Set to true to force dir scan.
* @return array paths
* @todo Make theme path building respect $cached parameter.
*/
protected function _paths($plugin = null, $cached = true) {
$paths = parent::_paths($plugin, $cached);
2009-11-26 22:50:33 +00:00
$themePaths = array();
if (!empty($this->theme)) {
$count = count($paths);
for ($i = 0; $i < $count; $i++) {
if (strpos($paths[$i], DS . 'Plugins' . DS) === false
2010-12-20 04:19:20 +00:00
&& strpos($paths[$i], DS . 'Cake' . DS . 'View') === false) {
if ($plugin) {
$themePaths[] = $paths[$i] . 'Themed'. DS . $this->theme . DS . 'Plugins' . DS . $plugin . DS;
}
$themePaths[] = $paths[$i] . 'Themed'. DS . $this->theme . DS;
}
}
$paths = array_merge($themePaths, $paths);
}
return $paths;
}
}