Project

General

Profile

1
<?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
 * @author       Manuela v.d.Decken <manuela@isteam.de>
26
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28
 * @version      0.0.1
29
 * @revision     $Revision: 2120 $
30
 * @lastmodified $Date: 2015-03-10 18:16:46 +0100 (Tue, 10 Mar 2015) $
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
	protected static $oInstance = null;
39
/** array hold settings */	
40
	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
/** constructor */
46
	protected function __construct() 
47
	{
48
		$this->aProperties = array('System' => array(), 'Request' => array());
49
	}
50
/**
51
 * Get active instance 
52
 * @return WbAdaptor
53
 */
54
	public static function getInstance()
55
	{
56
		if(self::$oInstance == null) {
57
			$c = __CLASS__;
58
			self::$oInstance = new $c();
59
			
60
		}
61
		return self::$oInstance;
62
	}
63
/**
64
 * 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
 * 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
        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
	}
103
/**
104
 * Get value of a variable
105
 * @param string name of the variable
106
 * @return mixed
107
 */	
108
	public function __get($sVarname)
109
	{
110
        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
		}
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
        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
		return $bRetval;
134
	}
135
/**
136
 * Import WB-Constants
137
 */	
138
	public function getWbConstants()
139
	{
140
    // first reinitialize arrays
141
		$this->aProperties = array(
142
            'System' => array(),
143
            'Request' => array()
144
        );
145
    // get all defined constants
146
		$aConsts = get_defined_constants(true);
147
    // iterate all user defined constants
148
		foreach ($aConsts['user'] as $sKey=>$sVal) {
149
            if (in_array($sKey, $this->aReservedVars)) { continue; }
150
		// skip possible existing database constants
151
			if (preg_match('/^db_|^TABLE_PREFIX$/i', $sKey)) { continue; }
152
		// change all path items to trailing slash scheme and assign the new naming syntax
153
			switch($sKey):
154
                case 'DEBUG':
155
                    $this->aProperties['System']['Debug'] = intval($sVal);
156
                    $this->aProperties['System']['DebugLevel'] = intval($sVal);
157
                    break;
158
				case 'WB_URL': 
159
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
160
					$sKey = 'AppUrl';
161
					$this->aProperties['System'][$sKey] = $sVal;
162
					break;
163
				case 'WB_REL':
164
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
165
					$sKey = 'AppRel';
166
					$this->aProperties['System'][$sKey] = $sVal;
167
					break;
168
				case 'WB_PATH':
169
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
170
					$sKey = 'AppPath';
171
					$this->aProperties['System'][$sKey] = $sVal;
172
					break;
173
				case 'ADMIN_URL':
174
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
175
					$sKey = 'AcpUrl';
176
					$this->aProperties['System'][$sKey] = $sVal;
177
					break;
178
				case 'ADMIN_REL':
179
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
180
					$sKey = 'AcpRel';
181
					$this->aProperties['System'][$sKey] = $sVal;
182
					break;
183
				case 'ADMIN_PATH':
184
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
185
					$sKey = 'AcpPath';
186
					$this->aProperties['System'][$sKey] = $sVal;
187
					break;
188
				case 'THEME_URL':
189
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
190
					$sKey = 'ThemeUrl';
191
					$this->aProperties['Request'][$sKey] = $sVal;
192
					break;
193
				case 'THEME_REL':
194
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
195
					$sKey = 'ThemeRel';
196
					$this->aProperties['Request'][$sKey] = $sVal;
197
					break;
198
				case 'THEME_PATH':
199
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
200
					$sKey = 'ThemePath';
201
					$this->aProperties['Request'][$sKey] = $sVal;
202
					break;
203
				case 'TMP_PATH':
204
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
205
					$sKey = 'TempPath';
206
					$this->aProperties['System'][$sKey] = $sVal;
207
					break;
208
				case 'ADMIN_DIRECTORY':
209
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
210
					$sKey = 'AcpDir';
211
					$this->aProperties['System'][$sKey] = $sVal;
212
					break;
213
				case 'DOCUMENT_ROOT':
214
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
215
					$sKey = 'DocumentRoot';
216
					$this->aProperties['System'][$sKey] = $sVal;
217
					break;
218
				case 'PAGES_DIRECTORY':
219
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
220
					$sVal = $sVal=='/' ? '' : $sVal;
221
					$sKey = 'PagesDir';
222
					$this->aProperties['System'][$sKey] = $sVal;
223
					break;
224
				case 'MEDIA_DIRECTORY':
225
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
226
					$sKey = 'MediaDir';
227
					$this->aProperties['System'][$sKey] = $sVal;
228
					break;
229
				case 'DEFAULT_TEMPLATE':
230
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
231
					$sKey = 'DefaultTemplate';
232
					$this->aProperties['System'][$sKey] = $sVal;
233
					break;
234
				case 'TEMPLATE':
235
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
236
					$sKey = 'Template';
237
					$this->aProperties['Request'][$sKey] = $sVal;
238
					break;
239
				case 'DEFAULT_THEME':
240
					$sVal = trim(str_replace('\\', '/', $sVal), '/');
241
					$sKey = 'DefaultTheme';
242
					$this->aProperties['System'][$sKey] = $sVal;
243
					$this->aProperties['Request']['Theme'] = trim($sVal, '/');
244
					break;
245
				case 'OCTAL_FILE_MODE':
246
					$sVal = ((intval($sVal) & ~0111)|0600); // o-x/g-x/u-x/o+rw
247
					$sKey = 'OctalFileMode';
248
					$this->aProperties['System']['OctalFileMode'] = $sVal;
249
					$this->aProperties['System']['FileModeOctal'] = $sVal;
250
					break;
251
				case 'OCTAL_DIR_MODE':
252
					$sVal = (intval($sVal) |0711); // o+rwx/g+x/u+x
253
					$sKey = 'OctalDirMode';
254
					$this->aProperties['System']['OctalDirMode'] = $sVal;
255
					$this->aProperties['System']['DirModeOctal'] = $sVal;
256
					break;
257
				case 'WB_VERSION':
258
					$sKey = 'AppVersion';
259
					$this->aProperties['System'][$sKey] = $sVal;
260
					break;
261
				case 'WB_REVISION':
262
					$sKey = 'AppRevision';
263
					$this->aProperties['System'][$sKey] = $sVal;
264
					break;
265
				case 'WB_SP':
266
					$sKey = 'AppServicePack';
267
					$this->aProperties['System'][$sKey] = $sVal;
268
					break;
269
                case 'PAGE_ICON_DIR':
270
                    $sKey = 'PageIconDir';
271
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
272
					$this->aProperties['Request'][$sKey] = $sVal;
273
                    break;
274
                case 'TEMPLATE_DIR':
275
                    break;
276
				default:
277
                    $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
					$sVal = ($sVal == 'true' ? true : ($sVal == 'false' ? false : $sVal));
284
                    // reformatting constant names
285
					$sKey = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($sKey))));
286
                    if (in_array($sKey, $aSysList)) {
287
    					$this->aProperties['System'][$sKey] = $sVal;
288
                    } else {
289
                        $this->aProperties['Request'][$sKey] = $sVal;
290
                    }
291
					break;
292
			endswitch;
293
		}
294
/* 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
	}
314
// 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

    
322
} // end of class WbAdaptor
323

    
(17-17/38)