1: <?php
2: /**
3: * A custom view class that is used for themeing
4: *
5: * PHP 5
6: *
7: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8: * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
9: *
10: * Licensed under The MIT License
11: * Redistributions of files must retain the above copyright notice.
12: *
13: * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
14: * @link http://cakephp.org CakePHP(tm) Project
15: * @package Cake.View
16: * @since CakePHP(tm) v 0.10.0.1076
17: * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
18: */
19:
20: App::uses('View', 'View');
21:
22: /**
23: * Theme view class
24: *
25: * Allows the creation of multiple themes to be used in an app. Theme views are regular view files
26: * that can provide unique HTML and static assets. If theme views are not found for the current view
27: * the default app view files will be used. You can set `$this->theme` and `$this->viewClass = 'Theme'`
28: * in your Controller to use the ThemeView.
29: *
30: * Example of theme path with `$this->theme = 'SuperHot';` Would be `app/View/Themed/SuperHot/Posts`
31: *
32: * @package Cake.View
33: */
34: class ThemeView extends View {
35: /**
36: * Constructor for ThemeView sets $this->theme.
37: *
38: * @param Controller $controller Controller object to be rendered.
39: */
40: public function __construct($controller) {
41: parent::__construct($controller);
42: if ($controller) {
43: $this->theme = $controller->theme;
44: }
45: }
46:
47: /**
48: * Return all possible paths to find view files in order
49: *
50: * @param string $plugin The name of the plugin views are being found for.
51: * @param boolean $cached Set to true to force dir scan.
52: * @return array paths
53: * @todo Make theme path building respect $cached parameter.
54: */
55: protected function _paths($plugin = null, $cached = true) {
56: $paths = parent::_paths($plugin, $cached);
57: $themePaths = array();
58:
59: if (!empty($this->theme)) {
60: foreach ($paths as $path) {
61: if (strpos($path, DS . 'Plugin' . DS) === false
62: && strpos($path, DS . 'Cake' . DS . 'View') === false) {
63: if ($plugin) {
64: $themePaths[] = $path . 'Themed'. DS . $this->theme . DS . 'Plugin' . DS . $plugin . DS;
65: }
66: $themePaths[] = $path . 'Themed'. DS . $this->theme . DS;
67: }
68: }
69: $paths = array_merge($themePaths, $paths);
70: }
71: return $paths;
72: }
73: }
74: