Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 142 lines (130 sloc) 3.705 kb
55bdd95 removed carriage returns from files.
qiang.xue authored
1 <?php
2 /**
3 * CTheme class file.
4 *
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.yiiframework.com/
4be0af6 changed copyright year.
qiang.xue authored
7 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
55bdd95 removed carriage returns from files.
qiang.xue authored
8 * @license http://www.yiiframework.com/license/
9 */
10
11 /**
12 * CTheme represents an application theme.
13 *
646cbb2 Documented component accessors with @property for significantly better I...
alexander.makarow authored
14 * @property string $name Theme name.
15 * @property string $baseUrl The relative URL to the theme folder (without ending slash).
16 * @property string $basePath The file path to the theme folder.
17 * @property string $viewPath The path for controller views. Defaults to 'ThemeRoot/views'.
18 * @property string $systemViewPath The path for system views. Defaults to 'ThemeRoot/views/system'.
19 * @property string $skinPath The path for widget skins. Defaults to 'ThemeRoot/views/skins'.
20 *
55bdd95 removed carriage returns from files.
qiang.xue authored
21 * @author Qiang Xue <qiang.xue@gmail.com>
22 * @version $Id$
23 * @package system.web
24 * @since 1.0
25 */
26 class CTheme extends CComponent
27 {
28 private $_name;
29 private $_basePath;
30 private $_baseUrl;
31
32 /**
33 * Constructor.
72b9745 Updated PHPDoc @param parameter names
mdomba authored
34 * @param string $name name of the theme
35 * @param string $basePath base theme path
36 * @param string $baseUrl base theme URL
55bdd95 removed carriage returns from files.
qiang.xue authored
37 */
38 public function __construct($name,$basePath,$baseUrl)
39 {
40 $this->_name=$name;
41 $this->_baseUrl=$baseUrl;
42 $this->_basePath=$basePath;
43 }
44
45 /**
46 * @return string theme name
47 */
48 public function getName()
49 {
50 return $this->_name;
51 }
52
53 /**
54 * @return string the relative URL to the theme folder (without ending slash)
55 */
56 public function getBaseUrl()
57 {
58 return $this->_baseUrl;
59 }
60
61 /**
62 * @return string the file path to the theme folder
63 */
64 public function getBasePath()
65 {
66 return $this->_basePath;
67 }
68
69 /**
70 * @return string the path for controller views. Defaults to 'ThemeRoot/views'.
71 */
72 public function getViewPath()
73 {
74 return $this->_basePath.DIRECTORY_SEPARATOR.'views';
75 }
76
77 /**
78 * @return string the path for system views. Defaults to 'ThemeRoot/views/system'.
79 */
80 public function getSystemViewPath()
81 {
82 return $this->getViewPath().DIRECTORY_SEPARATOR.'system';
83 }
84
85 /**
768d676 initial implementation of skin feature.
qiang.xue authored
86 * @return string the path for widget skins. Defaults to 'ThemeRoot/views/skins'.
87 * @since 1.1
88 */
89 public function getSkinPath()
90 {
91 return $this->getViewPath().DIRECTORY_SEPARATOR.'skins';
92 }
93
94 /**
55bdd95 removed carriage returns from files.
qiang.xue authored
95 * Finds the view file for the specified controller's view.
72b9745 Updated PHPDoc @param parameter names
mdomba authored
96 * @param CController $controller the controller
97 * @param string $viewName the view name
55bdd95 removed carriage returns from files.
qiang.xue authored
98 * @return string the view file path. False if the file does not exist.
99 */
100 public function getViewFile($controller,$viewName)
101 {
7273b56 * (Fixes issue 1043) Improved view resolution to support using themeable...
qiang.xue authored
102 $moduleViewPath=$this->getViewPath();
103 if(($module=$controller->getModule())!==null)
104 $moduleViewPath.='/'.$module->getId();
105 return $controller->resolveViewFile($viewName,$this->getViewPath().'/'.$controller->getUniqueId(),$this->getViewPath(),$moduleViewPath);
55bdd95 removed carriage returns from files.
qiang.xue authored
106 }
107
108 /**
109 * Finds the layout file for the specified controller's layout.
72b9745 Updated PHPDoc @param parameter names
mdomba authored
110 * @param CController $controller the controller
111 * @param string $layoutName the layout name
55bdd95 removed carriage returns from files.
qiang.xue authored
112 * @return string the layout file path. False if the file does not exist.
113 */
114 public function getLayoutFile($controller,$layoutName)
115 {
7273b56 * (Fixes issue 1043) Improved view resolution to support using themeable...
qiang.xue authored
116 $moduleViewPath=$basePath=$this->getViewPath();
117 $module=$controller->getModule();
c26672a merge from 1.0
qiang.xue authored
118 if(empty($layoutName))
119 {
120 while($module!==null)
121 {
122 if($module->layout===false)
123 return false;
124 if(!empty($module->layout))
125 break;
126 $module=$module->getParentModule();
127 }
128 if($module===null)
7273b56 * (Fixes issue 1043) Improved view resolution to support using themeable...
qiang.xue authored
129 $layoutName=Yii::app()->layout;
c26672a merge from 1.0
qiang.xue authored
130 else
f7bb922 merge from 1.0
qiang.xue authored
131 {
7273b56 * (Fixes issue 1043) Improved view resolution to support using themeable...
qiang.xue authored
132 $layoutName=$module->layout;
133 $moduleViewPath.='/'.$module->getId();
f7bb922 merge from 1.0
qiang.xue authored
134 }
c26672a merge from 1.0
qiang.xue authored
135 }
7273b56 * (Fixes issue 1043) Improved view resolution to support using themeable...
qiang.xue authored
136 else if($module!==null)
137 $moduleViewPath.='/'.$module->getId();
138
d674aeb
qiang.xue authored
139 return $controller->resolveViewFile($layoutName,$moduleViewPath.'/layouts',$basePath,$moduleViewPath);
55bdd95 removed carriage returns from files.
qiang.xue authored
140 }
141 }
Something went wrong with that request. Please try again.