1 |
1861
|
darkviper
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
5 |
|
|
*
|
6 |
|
|
* This program is free software: you can redistribute it and/or modify
|
7 |
|
|
* it under the terms of the GNU General Public License as published by
|
8 |
|
|
* the Free Software Foundation, either version 3 of the License, or
|
9 |
|
|
* (at your option) any later version.
|
10 |
|
|
*
|
11 |
|
|
* This program is distributed in the hope that it will be useful,
|
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
* GNU General Public License for more details.
|
15 |
|
|
*
|
16 |
|
|
* You should have received a copy of the GNU General Public License
|
17 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* WbAdaptor.php
|
22 |
|
|
*
|
23 |
|
|
* @category Core
|
24 |
|
|
* @package Core_package
|
25 |
2120
|
darkviper
|
* @author Manuela v.d.Decken <manuela@isteam.de>
|
26 |
|
|
* @copyright Manuela v.d.Decken <manuela@isteam.de>
|
27 |
1861
|
darkviper
|
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
28 |
|
|
* @version 0.0.1
|
29 |
|
|
* @revision $Revision$
|
30 |
|
|
* @lastmodified $Date$
|
31 |
|
|
* @since File available since 18.01.2013
|
32 |
|
|
* @deprecated This class will be removed if Registry comes activated
|
33 |
|
|
* @description This adaptor is a temporary replacement for the future registry class
|
34 |
|
|
*/
|
35 |
|
|
class WbAdaptor {
|
36 |
|
|
|
37 |
|
|
/** active instance */
|
38 |
2120
|
darkviper
|
protected static $oInstance = null;
|
39 |
1861
|
darkviper
|
/** array hold settings */
|
40 |
2120
|
darkviper
|
protected $aProperties = array();
|
41 |
|
|
/** */
|
42 |
|
|
protected $aObjects = array('Db' => null, 'Trans' => null, 'App' => null);
|
43 |
|
|
/** vars which */
|
44 |
|
|
protected $aReservedVars = array('Db', 'Trans', 'App');
|
45 |
1861
|
darkviper
|
/** constructor */
|
46 |
|
|
protected function __construct()
|
47 |
|
|
{
|
48 |
2120
|
darkviper
|
$this->aProperties = array('System' => array(), 'Request' => array());
|
49 |
1861
|
darkviper
|
}
|
50 |
|
|
/**
|
51 |
|
|
* Get active instance
|
52 |
|
|
* @return WbAdaptor
|
53 |
|
|
*/
|
54 |
|
|
public static function getInstance()
|
55 |
|
|
{
|
56 |
2120
|
darkviper
|
if(self::$oInstance == null) {
|
57 |
1861
|
darkviper
|
$c = __CLASS__;
|
58 |
2120
|
darkviper
|
self::$oInstance = new $c();
|
59 |
1861
|
darkviper
|
|
60 |
|
|
}
|
61 |
2120
|
darkviper
|
return self::$oInstance;
|
62 |
1861
|
darkviper
|
}
|
63 |
|
|
/**
|
64 |
2120
|
darkviper
|
* set the global database object
|
65 |
|
|
* @param WbDatabase $oDb
|
66 |
|
|
*/
|
67 |
|
|
public function setDatabase(WbDatabase $oDb)
|
68 |
|
|
{
|
69 |
|
|
$this->aObjects['Db'] = $oDb;
|
70 |
|
|
return true;
|
71 |
|
|
}
|
72 |
|
|
/**
|
73 |
|
|
* set the global translation object
|
74 |
|
|
* @param Translate $oTrans
|
75 |
|
|
*/
|
76 |
|
|
public function setTranslate(Translate $oTrans)
|
77 |
|
|
{
|
78 |
|
|
$this->aObjects['Trans'] = $oTrans;
|
79 |
|
|
return true;
|
80 |
|
|
}
|
81 |
|
|
/**
|
82 |
|
|
* set the global application object
|
83 |
|
|
* @param wb $oApp
|
84 |
|
|
*/
|
85 |
|
|
public function setApplication(wb $oApp)
|
86 |
|
|
{
|
87 |
|
|
$this->aObjects['App'] = $oApp;
|
88 |
|
|
}
|
89 |
|
|
/**
|
90 |
1879
|
darkviper
|
* handle unknown properties
|
91 |
|
|
* @param string name of the property
|
92 |
|
|
* @param mixed value to set
|
93 |
|
|
* @throws InvalidArgumentException
|
94 |
|
|
*/
|
95 |
|
|
public function __set($name, $value)
|
96 |
|
|
{
|
97 |
2120
|
darkviper
|
if (array_key_exists($name, $this->aProperties['System'])) {
|
98 |
|
|
throw new InvalidArgumentException('tried to set readonly or nonexisting property [ '.$name.' }!! ');
|
99 |
|
|
} else {
|
100 |
|
|
$this->aProperties['Request'][$name] = $value;
|
101 |
|
|
}
|
102 |
1879
|
darkviper
|
}
|
103 |
|
|
/**
|
104 |
1861
|
darkviper
|
* Get value of a variable
|
105 |
|
|
* @param string name of the variable
|
106 |
|
|
* @return mixed
|
107 |
|
|
*/
|
108 |
|
|
public function __get($sVarname)
|
109 |
|
|
{
|
110 |
2120
|
darkviper
|
if (isset($this->aObjects[$sVarname]) && !is_null($this->aObjects[$sVarname])) {
|
111 |
|
|
return $this->aObjects[$sVarname];
|
112 |
|
|
}
|
113 |
|
|
if (isset($this->aProperties['System'][$sVarname])) {
|
114 |
|
|
return $this->aProperties['System'][$sVarname];
|
115 |
|
|
} elseif ( isset($this->aProperties['Request'][$sVarname])) {
|
116 |
|
|
return $this->aProperties['Request'][$sVarname];
|
117 |
|
|
} else {
|
118 |
|
|
return null;
|
119 |
1861
|
darkviper
|
}
|
120 |
|
|
}
|
121 |
|
|
/**
|
122 |
|
|
* Check if var is set
|
123 |
|
|
* @param string name of the variable
|
124 |
|
|
* @return bool
|
125 |
|
|
*/
|
126 |
|
|
public function __isset($sVarname)
|
127 |
|
|
{
|
128 |
2120
|
darkviper
|
if (isset($this->aObjects[$sVarname]) && !is_null($this->aObjects[$sVarname])) {
|
129 |
|
|
return true;
|
130 |
|
|
}
|
131 |
|
|
$bRetval = (isset($this->aProperties['System'][$sVarname]) ||
|
132 |
|
|
isset($this->aProperties['Request'][$sVarname]));
|
133 |
1861
|
darkviper
|
return $bRetval;
|
134 |
|
|
}
|
135 |
|
|
/**
|
136 |
|
|
* Import WB-Constants
|
137 |
|
|
*/
|
138 |
|
|
public function getWbConstants()
|
139 |
|
|
{
|
140 |
2120
|
darkviper
|
// first reinitialize arrays
|
141 |
|
|
$this->aProperties = array(
|
142 |
|
|
'System' => array(),
|
143 |
|
|
'Request' => array()
|
144 |
|
|
);
|
145 |
|
|
// get all defined constants
|
146 |
1861
|
darkviper
|
$aConsts = get_defined_constants(true);
|
147 |
2120
|
darkviper
|
// iterate all user defined constants
|
148 |
|
|
foreach ($aConsts['user'] as $sKey=>$sVal) {
|
149 |
|
|
if (in_array($sKey, $this->aReservedVars)) { continue; }
|
150 |
2000
|
darkviper
|
// skip possible existing database constants
|
151 |
|
|
if (preg_match('/^db_|^TABLE_PREFIX$/i', $sKey)) { continue; }
|
152 |
2120
|
darkviper
|
// change all path items to trailing slash scheme and assign the new naming syntax
|
153 |
1861
|
darkviper
|
switch($sKey):
|
154 |
2120
|
darkviper
|
case 'DEBUG':
|
155 |
|
|
$this->aProperties['System']['Debug'] = intval($sVal);
|
156 |
|
|
$this->aProperties['System']['DebugLevel'] = intval($sVal);
|
157 |
|
|
break;
|
158 |
1861
|
darkviper
|
case 'WB_URL':
|
159 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
160 |
|
|
$sKey = 'AppUrl';
|
161 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
162 |
1861
|
darkviper
|
break;
|
163 |
|
|
case 'WB_REL':
|
164 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
165 |
|
|
$sKey = 'AppRel';
|
166 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
167 |
1861
|
darkviper
|
break;
|
168 |
|
|
case 'WB_PATH':
|
169 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
170 |
|
|
$sKey = 'AppPath';
|
171 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
172 |
1861
|
darkviper
|
break;
|
173 |
|
|
case 'ADMIN_URL':
|
174 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
175 |
|
|
$sKey = 'AcpUrl';
|
176 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
177 |
1861
|
darkviper
|
break;
|
178 |
|
|
case 'ADMIN_REL':
|
179 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
180 |
|
|
$sKey = 'AcpRel';
|
181 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
182 |
1861
|
darkviper
|
break;
|
183 |
|
|
case 'ADMIN_PATH':
|
184 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
185 |
|
|
$sKey = 'AcpPath';
|
186 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
187 |
1861
|
darkviper
|
break;
|
188 |
|
|
case 'THEME_URL':
|
189 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
190 |
|
|
$sKey = 'ThemeUrl';
|
191 |
2120
|
darkviper
|
$this->aProperties['Request'][$sKey] = $sVal;
|
192 |
1861
|
darkviper
|
break;
|
193 |
|
|
case 'THEME_REL':
|
194 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
195 |
|
|
$sKey = 'ThemeRel';
|
196 |
2120
|
darkviper
|
$this->aProperties['Request'][$sKey] = $sVal;
|
197 |
1861
|
darkviper
|
break;
|
198 |
|
|
case 'THEME_PATH':
|
199 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
200 |
|
|
$sKey = 'ThemePath';
|
201 |
2120
|
darkviper
|
$this->aProperties['Request'][$sKey] = $sVal;
|
202 |
1861
|
darkviper
|
break;
|
203 |
|
|
case 'TMP_PATH':
|
204 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
205 |
|
|
$sKey = 'TempPath';
|
206 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
207 |
1861
|
darkviper
|
break;
|
208 |
|
|
case 'ADMIN_DIRECTORY':
|
209 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
|
210 |
|
|
$sKey = 'AcpDir';
|
211 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
212 |
1861
|
darkviper
|
break;
|
213 |
|
|
case 'DOCUMENT_ROOT':
|
214 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
215 |
|
|
$sKey = 'DocumentRoot';
|
216 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
217 |
1861
|
darkviper
|
break;
|
218 |
|
|
case 'PAGES_DIRECTORY':
|
219 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
|
220 |
1878
|
darkviper
|
$sVal = $sVal=='/' ? '' : $sVal;
|
221 |
1861
|
darkviper
|
$sKey = 'PagesDir';
|
222 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
223 |
1861
|
darkviper
|
break;
|
224 |
|
|
case 'MEDIA_DIRECTORY':
|
225 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
|
226 |
|
|
$sKey = 'MediaDir';
|
227 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
228 |
1861
|
darkviper
|
break;
|
229 |
|
|
case 'DEFAULT_TEMPLATE':
|
230 |
2120
|
darkviper
|
$sVal = trim(str_replace('\\', '/', $sVal), '/');
|
231 |
1861
|
darkviper
|
$sKey = 'DefaultTemplate';
|
232 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
233 |
1861
|
darkviper
|
break;
|
234 |
2097
|
darkviper
|
case 'TEMPLATE':
|
235 |
2120
|
darkviper
|
$sVal = trim(str_replace('\\', '/', $sVal), '/');
|
236 |
2097
|
darkviper
|
$sKey = 'Template';
|
237 |
2120
|
darkviper
|
$this->aProperties['Request'][$sKey] = $sVal;
|
238 |
2097
|
darkviper
|
break;
|
239 |
1861
|
darkviper
|
case 'DEFAULT_THEME':
|
240 |
2120
|
darkviper
|
$sVal = trim(str_replace('\\', '/', $sVal), '/');
|
241 |
1861
|
darkviper
|
$sKey = 'DefaultTheme';
|
242 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
243 |
|
|
$this->aProperties['Request']['Theme'] = trim($sVal, '/');
|
244 |
1861
|
darkviper
|
break;
|
245 |
|
|
case 'OCTAL_FILE_MODE':
|
246 |
|
|
$sVal = ((intval($sVal) & ~0111)|0600); // o-x/g-x/u-x/o+rw
|
247 |
|
|
$sKey = 'OctalFileMode';
|
248 |
2120
|
darkviper
|
$this->aProperties['System']['OctalFileMode'] = $sVal;
|
249 |
|
|
$this->aProperties['System']['FileModeOctal'] = $sVal;
|
250 |
1861
|
darkviper
|
break;
|
251 |
|
|
case 'OCTAL_DIR_MODE':
|
252 |
|
|
$sVal = (intval($sVal) |0711); // o+rwx/g+x/u+x
|
253 |
|
|
$sKey = 'OctalDirMode';
|
254 |
2120
|
darkviper
|
$this->aProperties['System']['OctalDirMode'] = $sVal;
|
255 |
|
|
$this->aProperties['System']['DirModeOctal'] = $sVal;
|
256 |
1861
|
darkviper
|
break;
|
257 |
|
|
case 'WB_VERSION':
|
258 |
|
|
$sKey = 'AppVersion';
|
259 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
260 |
1861
|
darkviper
|
break;
|
261 |
|
|
case 'WB_REVISION':
|
262 |
|
|
$sKey = 'AppRevision';
|
263 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
264 |
1861
|
darkviper
|
break;
|
265 |
|
|
case 'WB_SP':
|
266 |
|
|
$sKey = 'AppServicePack';
|
267 |
2120
|
darkviper
|
$this->aProperties['System'][$sKey] = $sVal;
|
268 |
1861
|
darkviper
|
break;
|
269 |
2097
|
darkviper
|
case 'PAGE_ICON_DIR':
|
270 |
|
|
$sKey = 'PageIconDir';
|
271 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
|
272 |
2120
|
darkviper
|
$this->aProperties['Request'][$sKey] = $sVal;
|
273 |
2097
|
darkviper
|
break;
|
274 |
2120
|
darkviper
|
case 'TEMPLATE_DIR':
|
275 |
|
|
break;
|
276 |
1861
|
darkviper
|
default:
|
277 |
2120
|
darkviper
|
$aSysList = array(
|
278 |
|
|
// list of values which should be placed in ['System']
|
279 |
|
|
'DefaultCharset','DefaultDateFormat','DefaultLanguage','DefaultTimeFormat',
|
280 |
|
|
'DefaultTimezone','DevInfos'
|
281 |
|
|
);
|
282 |
|
|
// convert 'true' or 'false' strings into boolean
|
283 |
1861
|
darkviper
|
$sVal = ($sVal == 'true' ? true : ($sVal == 'false' ? false : $sVal));
|
284 |
2120
|
darkviper
|
// reformatting constant names
|
285 |
1861
|
darkviper
|
$sKey = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($sKey))));
|
286 |
2120
|
darkviper
|
if (in_array($sKey, $aSysList)) {
|
287 |
|
|
$this->aProperties['System'][$sKey] = $sVal;
|
288 |
|
|
} else {
|
289 |
|
|
$this->aProperties['Request'][$sKey] = $sVal;
|
290 |
|
|
}
|
291 |
1861
|
darkviper
|
break;
|
292 |
|
|
endswitch;
|
293 |
|
|
}
|
294 |
2120
|
darkviper
|
/* now set values which needs dependencies */
|
295 |
|
|
if (!isset($this->aProperties['Request']['Template']) || $this->aProperties['Request']['Template'] == '') {
|
296 |
|
|
$this->aProperties['Request']['Template'] = $this->DefaultTemplate;
|
297 |
|
|
}
|
298 |
|
|
$this->aProperties['System']['AppName'] = 'WebsiteBaker';
|
299 |
|
|
if (isset($this->Template)) {
|
300 |
|
|
$this->aProperties['Request']['TemplateDir'] = 'templates/'.$this->Template.'/';
|
301 |
|
|
$this->aProperties['Request']['TemplateUrl'] = $this->AppUrl.'templates/'.$this->Template.'/';
|
302 |
|
|
$this->aProperties['Request']['TemplatePath'] = $this->AppPath.'templates/'.$this->Template.'/';
|
303 |
|
|
}
|
304 |
|
|
/* correct PageIconDir if necessary */
|
305 |
|
|
$this->aProperties['Request']['PageIconDir'] = str_replace('/*/', '/'.$this->Template, $this->PageIconDir);
|
306 |
|
|
|
307 |
|
|
/* cleanup arrays */
|
308 |
|
|
$this->aProperties['Request'] = array_diff_key(
|
309 |
|
|
$this->aProperties['Request'],
|
310 |
|
|
$this->aProperties['System']
|
311 |
|
|
);
|
312 |
|
|
|
313 |
1861
|
darkviper
|
}
|
314 |
2120
|
darkviper
|
// temporary method for testing purposes only
|
315 |
|
|
public function showAll()
|
316 |
|
|
{
|
317 |
|
|
ksort($this->_aSys['System']);
|
318 |
|
|
ksort($this->_aSys['Request']);
|
319 |
|
|
return $this->_aSys;
|
320 |
|
|
}
|
321 |
1861
|
darkviper
|
|
322 |
|
|
} // end of class WbAdaptor
|