1 |
2
|
Manuela
|
<?php
|
2 |
|
|
/* -------------------------------------------------------- */
|
3 |
|
|
// Must include code to stop this file being accessed directly
|
4 |
|
|
//if(defined('WB_PATH') == false) { die('Illegale file access /'.basename(__DIR__).'/'.basename(__FILE__).''); }
|
5 |
|
|
/* -------------------------------------------------------- */
|
6 |
|
|
|
7 |
|
|
if (!isset( $oReg ) && !class_exists('WbAdaptor')) {
|
8 |
|
|
$oThis = new stdClass;
|
9 |
|
|
// first reinitialize arrays
|
10 |
|
|
$oThis->aObjects = array('Db' => null, 'Trans' => null, 'App' => null);
|
11 |
|
|
$oApp = $oThis->aObjects['App'] = ( isset($GLOBALS['wb']) ?$GLOBALS['wb']: null );
|
12 |
|
|
$oApp = $oThis->aObjects['App'] = ( isset($GLOBALS['admin']) ?$GLOBALS['admin']: $oApp );
|
13 |
|
|
$oDb = $oThis->aObjects['Db'] = ( isset($GLOBALS['database']) ?$GLOBALS['database']: null );
|
14 |
|
|
$oTrans = $oThis->aObjects['Trans'] = (class_exists('Translate') ?Translate::getInstance (): null );
|
15 |
|
|
$oThis->aReservedVars = array('Db', 'Trans', 'App');
|
16 |
|
|
$oThis->aProperties = array(
|
17 |
|
|
'System' => array(),
|
18 |
|
|
'Request' => array()
|
19 |
|
|
);
|
20 |
|
|
// get all defined constants
|
21 |
|
|
$aConsts = get_defined_constants(true);
|
22 |
|
|
// iterate all user defined constants
|
23 |
|
|
foreach ($aConsts['user'] as $sKey=>$sVal) {
|
24 |
|
|
if (in_array($sKey, $oThis->aReservedVars)) { continue; }
|
25 |
|
|
// skip possible existing database constants
|
26 |
|
|
if (preg_match('/^db_/i', $sKey)) { continue; }
|
27 |
|
|
// change all path items to trailing slash scheme and assign the new naming syntax
|
28 |
|
|
switch($sKey):
|
29 |
|
|
case 'DEBUG':
|
30 |
|
|
$oThis->aProperties['System']['Debug'] = intval($sVal);
|
31 |
|
|
$oThis->aProperties['System']['DebugLevel'] = intval($sVal);
|
32 |
|
|
break;
|
33 |
|
|
case 'WB_URL':
|
34 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
35 |
|
|
$sKey = 'AppUrl';
|
36 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
37 |
|
|
break;
|
38 |
|
|
case 'WB_REL':
|
39 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
40 |
|
|
$sKey = 'AppRel';
|
41 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
42 |
|
|
break;
|
43 |
|
|
case 'WB_PATH':
|
44 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
45 |
|
|
$sKey = 'AppPath';
|
46 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
47 |
|
|
break;
|
48 |
|
|
case 'ADMIN_URL':
|
49 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
50 |
|
|
$sKey = 'AcpUrl';
|
51 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
52 |
|
|
break;
|
53 |
|
|
case 'ADMIN_REL':
|
54 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
55 |
|
|
$sKey = 'AcpRel';
|
56 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
57 |
|
|
break;
|
58 |
|
|
case 'ADMIN_PATH':
|
59 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
60 |
|
|
$sKey = 'AcpPath';
|
61 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
62 |
|
|
break;
|
63 |
|
|
case 'THEME_URL':
|
64 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
65 |
|
|
$sKey = 'ThemeUrl';
|
66 |
|
|
$oThis->aProperties['Request'][$sKey] = $sVal;
|
67 |
|
|
break;
|
68 |
|
|
case 'THEME_REL':
|
69 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
70 |
|
|
$sKey = 'ThemeRel';
|
71 |
|
|
$oThis->aProperties['Request'][$sKey] = $sVal;
|
72 |
|
|
break;
|
73 |
|
|
case 'THEME_PATH':
|
74 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
75 |
|
|
$sKey = 'ThemePath';
|
76 |
|
|
$oThis->aProperties['Request'][$sKey] = $sVal;
|
77 |
|
|
break;
|
78 |
|
|
case 'TMP_PATH':
|
79 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
80 |
|
|
$sKey = 'TempPath';
|
81 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
82 |
|
|
break;
|
83 |
|
|
case 'ADMIN_DIRECTORY':
|
84 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
|
85 |
|
|
$sKey = 'AcpDir';
|
86 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
87 |
|
|
break;
|
88 |
|
|
case 'DOCUMENT_ROOT':
|
89 |
|
|
$sVal = rtrim(str_replace('\\', '/', $sVal), '/').'/';
|
90 |
|
|
$sKey = 'DocumentRoot';
|
91 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
92 |
|
|
break;
|
93 |
|
|
case 'PAGES_DIRECTORY':
|
94 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
|
95 |
|
|
$sVal = $sVal=='/' ? '' : $sVal;
|
96 |
|
|
$sKey = 'PagesDir';
|
97 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
98 |
|
|
break;
|
99 |
|
|
case 'MEDIA_DIRECTORY':
|
100 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
|
101 |
|
|
$sKey = 'MediaDir';
|
102 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
103 |
|
|
break;
|
104 |
|
|
case 'DEFAULT_TEMPLATE':
|
105 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/');
|
106 |
|
|
$sKey = 'DefaultTemplate';
|
107 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
108 |
|
|
break;
|
109 |
|
|
case 'TEMPLATE':
|
110 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/');
|
111 |
|
|
$sKey = 'Template';
|
112 |
|
|
$oThis->aProperties['Request'][$sKey] = $sVal;
|
113 |
|
|
break;
|
114 |
|
|
case 'DEFAULT_THEME':
|
115 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/');
|
116 |
|
|
$sKey = 'DefaultTheme';
|
117 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
118 |
|
|
$oThis->aProperties['Request']['Theme'] = trim($sVal, '/');
|
119 |
|
|
break;
|
120 |
|
|
case 'OCTAL_FILE_MODE':
|
121 |
|
|
$sVal = ((intval($sVal) & ~0111)|0600); // o-x/g-x/u-x/o+rw
|
122 |
|
|
$sKey = 'OctalFileMode';
|
123 |
|
|
$oThis->aProperties['System']['OctalFileMode'] = $sVal;
|
124 |
|
|
$oThis->aProperties['System']['FileModeOctal'] = $sVal;
|
125 |
|
|
break;
|
126 |
|
|
case 'OCTAL_DIR_MODE':
|
127 |
|
|
$sVal = (intval($sVal) |0711); // o+rwx/g+x/u+x
|
128 |
|
|
$sKey = 'OctalDirMode';
|
129 |
|
|
$oThis->aProperties['System']['OctalDirMode'] = $sVal;
|
130 |
|
|
$oThis->aProperties['System']['DirModeOctal'] = $sVal;
|
131 |
|
|
break;
|
132 |
|
|
case 'WB_VERSION':
|
133 |
|
|
$sKey = 'AppVersion';
|
134 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
135 |
|
|
break;
|
136 |
|
|
case 'WB_REVISION':
|
137 |
|
|
$sKey = 'AppRevision';
|
138 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
139 |
|
|
break;
|
140 |
|
|
case 'WB_SP':
|
141 |
|
|
$sKey = 'AppServicePack';
|
142 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
143 |
|
|
break;
|
144 |
|
|
case 'PAGE_ICON_DIR':
|
145 |
|
|
$sKey = 'PageIconDir';
|
146 |
|
|
$sVal = trim(str_replace('\\', '/', $sVal), '/').'/';
|
147 |
|
|
$oThis->aProperties['Request'][$sKey] = $sVal;
|
148 |
|
|
break;
|
149 |
|
|
case 'TEMPLATE_DIR':
|
150 |
|
|
break;
|
151 |
|
|
case 'TEMPLATE_DIR':
|
152 |
|
|
break;
|
153 |
|
|
default:
|
154 |
|
|
$aSysList = array(
|
155 |
|
|
// list of values which should be placed in ['System']
|
156 |
|
|
'DefaultCharset','DefaultDateFormat','DefaultLanguage','DefaultTimeFormat',
|
157 |
|
|
'DefaultTimezone','DevInfos','Timezone'
|
158 |
|
|
);
|
159 |
|
|
// convert 'true' or 'false' strings into boolean
|
160 |
|
|
$sVal = ($sVal == 'true' ? true : ($sVal == 'false' ? false : $sVal));
|
161 |
|
|
// reformatting constant names
|
162 |
|
|
$sKey = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($sKey))));
|
163 |
|
|
if (in_array($sKey, $aSysList)) {
|
164 |
|
|
$oThis->aProperties['System'][$sKey] = $sVal;
|
165 |
|
|
} else {
|
166 |
|
|
$oThis->aProperties['Request'][$sKey] = $sVal;
|
167 |
|
|
}
|
168 |
|
|
break;
|
169 |
|
|
endswitch;
|
170 |
|
|
}
|
171 |
|
|
/* now set values which needs dependencies */
|
172 |
|
|
if (!isset($oThis->aProperties['Request']['Template']) || $oThis->aProperties['Request']['Template'] == '') {
|
173 |
|
|
$oThis->aProperties['Request']['Template'] = $oThis->aProperties['System']['DefaultTemplate'];
|
174 |
|
|
}
|
175 |
|
|
$oThis->aProperties['System']['AppName'] = 'WebsiteBaker';
|
176 |
|
|
if (isset($oThis->aProperties['Request']['Template'])) {
|
177 |
|
|
$oThis->aProperties['Request']['TemplateDir'] = 'templates/'.$oThis->aProperties['Request']['Template'].'/';
|
178 |
|
|
$oThis->aProperties['Request']['TemplateUrl'] = $oThis->aProperties['System']['AppUrl'].'templates/'.$oThis->aProperties['Request']['Template'].'/';
|
179 |
|
|
$oThis->aProperties['Request']['TemplatePath'] = $oThis->aProperties['System']['AppPath'].'templates/'.$oThis->aProperties['Request']['Template'].'/';
|
180 |
|
|
}
|
181 |
|
|
/* correct PageIconDir if necessary */
|
182 |
|
|
// $oThis->aProperties['Request']['PageIconDir'] = str_replace('/*/', '/'.$oThis->aProperties['Request']['Template'], $oReg->aProperties['Request']['PageIconDir']);
|
183 |
|
|
$oThis->aProperties['System']['VarPath'] = $oThis->aProperties['System']['AppPath'].'var/';
|
184 |
|
|
$oThis->aProperties['System']['VarUrl'] = $oThis->aProperties['System']['AppUrl'].'var/';
|
185 |
|
|
// $oThis->aProperties['System']['VarRel'] = $oThis->aProperties['System']['AppRel'].'var/';
|
186 |
|
|
/* cleanup arrays */
|
187 |
|
|
$oThis->aProperties['Request'] = array_diff_key(
|
188 |
|
|
$oThis->aProperties['Request'],
|
189 |
|
|
$oThis->aProperties['System']
|
190 |
|
|
);
|
191 |
|
|
ksort($oThis->aProperties['System']);
|
192 |
|
|
ksort($oThis->aProperties['Request']);
|
193 |
|
|
$aReg = array_merge( $oThis->aProperties['System'], $oThis->aProperties['Request'], $oThis->aObjects );
|
194 |
|
|
$oReg = new ArrayObject( $aReg, ArrayObject::ARRAY_AS_PROPS );
|
195 |
|
|
}
|