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       Werner v.d.Decken <wkl@isteam.de>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28
 * @version      0.0.1
29
 * @revision     $Revision: 1878 $
30
 * @lastmodified $Date: 2013-03-05 08:18:56 +0100 (Tue, 05 Mar 2013) $
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
	private static $_oInstance = null;
39
/** array hold settings */	
40
	private $_aSys = array();
41
/** constructor */
42
	protected function __construct() 
43
	{
44
		$this->_aSys = array('System' => array(), 'Request' => array());
45
	}
46
/**
47
 * Get active instance 
48
 * @return WbAdaptor
49
 */
50
	public static function getInstance()
51
	{
52
		if(self::$_oInstance == null) {
53
			$c = __CLASS__;
54
			self::$_oInstance = new $c();
55
			
56
		}
57
		return self::$_oInstance;
58
	}
59
/**
60
 * Get value of a variable
61
 * @param string name of the variable
62
 * @return mixed
63
 */	
64
	public function __get($sVarname)
65
	{
66
		if( isset($this->_aSys['Request'][$sVarname])) {
67
			return $this->_aSys['Request'][$sVarname];
68
		}elseif( isset($this->_aSys['System'][$sVarname])) {
69
			return $this->_aSys['System'][$sVarname];
70
		}elseif( isset($this->_aSys[$sVarname])) {
71
			return $this->_aSys[$sVarname];
72
		}else {
73
			return null;
74
		}
75
	}
76
/**
77
 * Check if var is set
78
 * @param string name of the variable
79
 * @return bool
80
 */	
81
	public function __isset($sVarname)
82
	{
83
		$bRetval = (isset($this->_aSys['Request'][$sVarname]) ||
84
		            isset($this->_aSys['System'][$sVarname]) ||
85
		            isset($this->_aSys[$sVarname]));
86
		return $bRetval;
87
	}
88
/**
89
 * Import WB-Constants
90
 */	
91
	public function getWbConstants()
92
	{
93
		$this->_aSys = array('System' => array(), 'Request' => array());
94
		$aConsts = get_defined_constants(true);
95
		foreach($aConsts['user'] as $sKey=>$sVal)
96
		{
97
			// change all path items to trailing slash scheme
98
			switch($sKey):
99
				case 'WB_URL': 
100
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
101
					$sKey = 'AppUrl';
102
					$this->_aSys['System'][$sKey] = $sVal; 
103
					break;
104
				case 'WB_REL':
105
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
106
					$sKey = 'AppRel';
107
					$this->_aSys['System'][$sKey] = $sVal; 
108
					break;
109
				case 'WB_PATH':
110
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
111
					$sKey = 'AppPath';
112
					$this->_aSys['System'][$sKey] = $sVal; 
113
					break;
114
				case 'ADMIN_URL':
115
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
116
					$sKey = 'AcpUrl';
117
					$this->_aSys['System'][$sKey] = $sVal; 
118
					break;
119
				case 'ADMIN_REL':
120
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
121
					$sKey = 'AcpRel';
122
					$this->_aSys['System'][$sKey] = $sVal; 
123
					break;
124
				case 'ADMIN_PATH':
125
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
126
					$sKey = 'AcpPath';
127
					$this->_aSys['System'][$sKey] = $sVal; 
128
					break;
129
				case 'THEME_URL':
130
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
131
					$sKey = 'ThemeUrl';
132
					$this->_aSys['Request'][$sKey] = $sVal; 
133
					break;
134
				case 'THEME_REL':
135
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
136
					$sKey = 'ThemeRel';
137
					$this->_aSys['Request'][$sKey] = $sVal; 
138
					break;
139
				case 'THEME_PATH':
140
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
141
					$sKey = 'ThemePath';
142
					$this->_aSys['Request'][$sKey] = $sVal; 
143
					break;
144
				case 'TMP_PATH':
145
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
146
					$sKey = 'TempPath';
147
					$this->_aSys['System'][$sKey] = $sVal; 
148
					break;
149
				case 'ADMIN_DIRECTORY':
150
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
151
					$sKey = 'AcpDir';
152
					$this->_aSys['System'][$sKey] = $sVal; 
153
					break;
154
				case 'DOCUMENT_ROOT':
155
					$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
156
					$sKey = 'DocumentRoot';
157
					$this->_aSys['System'][$sKey] = $sVal; 
158
					break;
159
				case 'PAGES_DIRECTORY':
160
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
161
					$sVal = $sVal=='/' ? '' : $sVal;
162
					$sKey = 'PagesDir';
163
					$this->_aSys['System'][$sKey] = $sVal; 
164
					break;
165
				case 'MEDIA_DIRECTORY':
166
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
167
					$sKey = 'MediaDir';
168
					$this->_aSys['System'][$sKey] = $sVal; 
169
					break;
170
				case 'DEFAULT_TEMPLATE':
171
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
172
					$sKey = 'DefaultTemplate';
173
					$this->_aSys['Request'][$sKey] = $sVal; 
174
					break;
175
				case 'DEFAULT_THEME':
176
					$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
177
					$sKey = 'DefaultTheme';
178
					$this->_aSys['Request'][$sKey] = $sVal; 
179
					break;
180
				case 'TABLE_PREFIX':
181
					$sKey = 'TablePrefix';
182
					$this->_aSys['System'][$sKey] = $sVal; 
183
					break;
184
				case 'OCTAL_FILE_MODE':
185
					$sVal = ((intval($sVal) & ~0111)|0600); // o-x/g-x/u-x/o+rw
186
					$sKey = 'OctalFileMode';
187
					$this->_aSys['Request'][$sKey] = $sVal; 
188
					break;
189
				case 'OCTAL_DIR_MODE':
190
					$sVal = (intval($sVal) |0711); // o+rwx/g+x/u+x
191
					$sKey = 'OctalDirMode';
192
					$this->_aSys['Request'][$sKey] = $sVal; 
193
					break;
194
				case 'WB_VERSION':
195
					$sKey = 'AppVersion';
196
					$this->_aSys['System'][$sKey] = $sVal; 
197
					break;
198
				case 'WB_REVISION':
199
					$sKey = 'AppRevision';
200
					$this->_aSys['System'][$sKey] = $sVal; 
201
					break;
202
				case 'WB_SP':
203
					$sKey = 'AppServicePack';
204
					$this->_aSys['System'][$sKey] = $sVal; 
205
					break;
206
				default:
207
					$sVal = ($sVal == 'true' ? true : ($sVal == 'false' ? false : $sVal));
208
					$sKey = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($sKey))));
209
					$this->_aSys['Request'][$sKey] = $sVal; 
210
					break;
211
			endswitch;
212
			$this->_aSys[$sKey] = $sVal;
213
		}
214
		$this->_aSys['AppName'] = 'WebsiteBaker';
215
		$this->_aSys['System']['AppName'] = 'WebsiteBaker';
216
	}
217

    
218
} // end of class WbAdaptor
219

    
(11-11/30)