|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Contains some tools to check themes with |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Core |
|
9
|
|
|
* @package Themes |
|
10
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
11
|
|
|
* @copyright 2013 cSphere Team |
|
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
13
|
|
|
* @link http://www.csphere.eu |
|
14
|
|
|
**/ |
|
15
|
|
|
|
|
16
|
|
|
namespace csphere\core\themes; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Contains some tools to check themes with |
|
20
|
|
|
* |
|
21
|
|
|
* @category Core |
|
22
|
|
|
* @package Themes |
|
23
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
24
|
|
|
* @copyright 2013 cSphere Team |
|
25
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
26
|
|
|
* @link http://www.csphere.eu |
|
27
|
|
|
**/ |
|
28
|
|
|
|
|
29
|
|
|
class Checks |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Theme that will be used |
|
33
|
|
|
**/ |
|
34
|
|
|
private $_theme = ''; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Local path |
|
38
|
|
|
**/ |
|
39
|
|
|
private $_path = ''; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* File that will be used |
|
43
|
|
|
**/ |
|
44
|
|
|
private $_file = ''; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Remember positive existance checks |
|
48
|
|
|
**/ |
|
49
|
|
|
private $_existance = false; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get theme to see if it exists |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $theme Name of theme |
|
55
|
|
|
* |
|
56
|
|
|
* @return \csphere\core\themes\Checks |
|
57
|
|
|
**/ |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function __construct($theme) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->_path = \csphere\core\init\path(); |
|
62
|
|
|
|
|
63
|
|
|
$this->_theme = $theme; |
|
64
|
|
|
|
|
65
|
|
|
// Check theme details |
|
66
|
|
|
$this->_validate(); |
|
67
|
|
|
|
|
68
|
|
|
$this->_file = 'csphere/themes/' . $this->_theme . '/index.htm'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Check if plugin is valid |
|
73
|
|
|
* |
|
74
|
|
|
* @throws \Exception |
|
75
|
|
|
* |
|
76
|
|
|
* @return void |
|
77
|
|
|
**/ |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
private function _validate() |
|
80
|
|
|
{ |
|
81
|
|
|
$meta = new \csphere\core\themes\Metadata(); |
|
82
|
|
|
|
|
83
|
|
|
$exists = $meta->exists($this->_theme); |
|
84
|
|
|
|
|
85
|
|
|
if ($exists == false) { |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
$msg = 'Theme not found: "' . $this->_theme . '"'; |
|
88
|
|
|
|
|
89
|
|
|
throw new \Exception($msg); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Set target for template files |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $target Name of target |
|
97
|
|
|
* @param string $plugin Name of plugin |
|
98
|
|
|
* |
|
99
|
|
|
* @return void |
|
100
|
|
|
**/ |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
public function setTemplate($target, $plugin) |
|
103
|
|
|
{ |
|
104
|
|
|
|
|
105
|
|
|
$metadata=new \csphere\core\plugins\metadata(); |
|
106
|
|
|
$type=$metadata->templateType($plugin, $target); |
|
107
|
|
|
|
|
108
|
|
|
$this->_file = 'csphere/themes/' . $this->_theme |
|
109
|
|
|
. '/templates/' . $plugin . '/' . $type. '/' . $target . '.tpl'; |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Checks if the target file exists |
|
115
|
|
|
* |
|
116
|
|
|
* @return boolean |
|
117
|
|
|
**/ |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
public function existance() |
|
120
|
|
|
{ |
|
121
|
|
|
$result = false; |
|
122
|
|
|
|
|
123
|
|
|
// Check for file existance if not done already |
|
124
|
|
|
if ($this->_existance == true) { |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
$result = true; |
|
127
|
|
|
} else { |
|
128
|
|
|
|
|
129
|
|
|
$target = $this->_path . $this->_file; |
|
130
|
|
|
|
|
131
|
|
|
// File must set before |
|
132
|
|
|
if (file_exists($target)) { |
|
133
|
|
|
|
|
134
|
|
|
$this->_existance = true; |
|
135
|
|
|
$result = true; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return $result; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Dirname for external theme path |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
**/ |
|
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
public function dirname() |
|
149
|
|
|
{ |
|
150
|
|
|
$target = \csphere\core\http\Request::get('dirname') |
|
151
|
|
|
. 'csphere/themes/' . $this->_theme . '/'; |
|
152
|
|
|
|
|
153
|
|
|
return $target; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Replies with the target file |
|
158
|
|
|
* |
|
159
|
|
|
* @param boolean $path Append local path which defaults to true |
|
160
|
|
|
* |
|
161
|
|
|
* @throws \Exception |
|
162
|
|
|
* |
|
163
|
|
|
* @return string |
|
164
|
|
|
**/ |
|
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
public function result($path = true) |
|
167
|
|
|
{ |
|
168
|
|
|
$exists = $this->existance(); |
|
169
|
|
|
|
|
170
|
|
|
// File must be there to return its origin |
|
171
|
|
|
if ($exists == false) { |
|
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
throw new \Exception('Theme target not found: "' . $this->_file . '"'); |
|
174
|
|
|
|
|
175
|
|
|
} else { |
|
176
|
|
|
|
|
177
|
|
|
$place = ($path == true) ? $this->_path . $this->_file : $this->_file; |
|
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
return isset($place) ? $place : ''; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.