|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
|
3
|
|
|
|
|
4
|
|
|
define('FOLLOW_REQUEST_SSL', 0); |
|
5
|
|
|
define('ENFORCE_SSL', 1); |
|
6
|
|
|
define('RELEASE_SSL', 2); |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Manages Context such as request arguments/environment variables |
|
10
|
|
|
* It has dual method structure, easy-to use methods which can be called as self::methodname(),and methods called with static object. |
|
11
|
|
|
* |
|
12
|
|
|
* @author NAVER ([email protected]) |
|
13
|
|
|
*/ |
|
14
|
|
|
class Context |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Allow rewrite |
|
19
|
|
|
* @var bool TRUE: using rewrite mod, FALSE: otherwise |
|
20
|
|
|
*/ |
|
21
|
|
|
public $allow_rewrite = FALSE; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Request method |
|
25
|
|
|
* @var string GET|POST|XMLRPC |
|
26
|
|
|
*/ |
|
27
|
|
|
public $request_method = 'GET'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* js callback function name. |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
public $js_callback_func = ''; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Response method.If it's not set, it follows request method. |
|
37
|
|
|
* @var string HTML|XMLRPC |
|
38
|
|
|
*/ |
|
39
|
|
|
public $response_method = ''; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Conatins request parameters and environment variables |
|
43
|
|
|
* @var object |
|
44
|
|
|
*/ |
|
45
|
|
|
public $context = NULL; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* DB info |
|
49
|
|
|
* @var object |
|
50
|
|
|
*/ |
|
51
|
|
|
public $db_info = NULL; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* FTP info |
|
55
|
|
|
* @var object |
|
56
|
|
|
*/ |
|
57
|
|
|
public $ftp_info = NULL; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* ssl action cache file |
|
61
|
|
|
* @var array |
|
62
|
|
|
*/ |
|
63
|
|
|
public $sslActionCacheFile = './files/cache/sslCacheFile.php'; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* List of actions to be sent via ssl (it is used by javascript xml handler for ajax) |
|
67
|
|
|
* @var array |
|
68
|
|
|
*/ |
|
69
|
|
|
public $ssl_actions = array(); |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* obejct oFrontEndFileHandler() |
|
73
|
|
|
* @var object |
|
74
|
|
|
*/ |
|
75
|
|
|
public $oFrontEndFileHandler; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* script codes in <head>..</head> |
|
79
|
|
|
* @var string |
|
80
|
|
|
*/ |
|
81
|
|
|
public $html_header = NULL; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* class names of <body> |
|
85
|
|
|
* @var array |
|
86
|
|
|
*/ |
|
87
|
|
|
public $body_class = array(); |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* codes after <body> |
|
91
|
|
|
* @var string |
|
92
|
|
|
*/ |
|
93
|
|
|
public $body_header = NULL; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* class names before </body> |
|
97
|
|
|
* @var string |
|
98
|
|
|
*/ |
|
99
|
|
|
public $html_footer = NULL; |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* path of Xpress Engine |
|
103
|
|
|
* @var string |
|
104
|
|
|
*/ |
|
105
|
|
|
public $path = ''; |
|
106
|
|
|
// language information - it is changed by HTTP_USER_AGENT or user's cookie |
|
107
|
|
|
/** |
|
108
|
|
|
* language type |
|
109
|
|
|
* @var string |
|
110
|
|
|
*/ |
|
111
|
|
|
public $lang_type = ''; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* contains language-specific data |
|
115
|
|
|
* @var object |
|
116
|
|
|
*/ |
|
117
|
|
|
public $lang = NULL; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* list of loaded languages (to avoid re-loading them) |
|
121
|
|
|
* @var array |
|
122
|
|
|
*/ |
|
123
|
|
|
public $loaded_lang_files = array(); |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* site's browser title |
|
127
|
|
|
* @var string |
|
128
|
|
|
*/ |
|
129
|
|
|
public $site_title = ''; |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* variables from GET or form submit |
|
133
|
|
|
* @var mixed |
|
134
|
|
|
*/ |
|
135
|
|
|
public $get_vars = NULL; |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Checks uploaded |
|
139
|
|
|
* @var bool TRUE if attached file exists |
|
140
|
|
|
*/ |
|
141
|
|
|
public $is_uploaded = FALSE; |
|
142
|
|
|
/** |
|
143
|
|
|
* Pattern for request vars check |
|
144
|
|
|
* @var array |
|
145
|
|
|
*/ |
|
146
|
|
|
public $patterns = array( |
|
147
|
|
|
'/<\?/iUsm', |
|
148
|
|
|
'/<\%/iUsm', |
|
149
|
|
|
'/<script\s*?language\s*?=\s*?("|\')?\s*?php\s*("|\')?/iUsm' |
|
150
|
|
|
); |
|
151
|
|
|
/** |
|
152
|
|
|
* Check init |
|
153
|
|
|
* @var bool FALSE if init fail |
|
154
|
|
|
*/ |
|
155
|
|
|
public $isSuccessInit = TRUE; |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* returns static context object (Singleton). It's to use Context without declaration of an object |
|
159
|
|
|
* |
|
160
|
|
|
* @return object Instance |
|
161
|
|
|
*/ |
|
162
|
|
|
function &getInstance() |
|
163
|
|
|
{ |
|
164
|
|
|
static $theInstance = null; |
|
165
|
|
|
if(!$theInstance) |
|
166
|
|
|
{ |
|
167
|
|
|
$theInstance = new Context(); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
return $theInstance; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Cunstructor |
|
175
|
|
|
* |
|
176
|
|
|
* @return void |
|
177
|
|
|
*/ |
|
178
|
|
|
function Context() |
|
|
|
|
|
|
179
|
|
|
{ |
|
180
|
|
|
$this->oFrontEndFileHandler = new FrontEndFileHandler(); |
|
181
|
|
|
$this->get_vars = new stdClass(); |
|
182
|
|
|
|
|
183
|
|
|
// include ssl action cache file |
|
184
|
|
|
$this->sslActionCacheFile = FileHandler::getRealPath($this->sslActionCacheFile); |
|
|
|
|
|
|
185
|
|
|
if(is_readable($this->sslActionCacheFile)) |
|
186
|
|
|
{ |
|
187
|
|
|
require($this->sslActionCacheFile); |
|
188
|
|
|
if(isset($sslActions)) |
|
|
|
|
|
|
189
|
|
|
{ |
|
190
|
|
|
$this->ssl_actions = $sslActions; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Initialization, it sets DB information, request arguments and so on. |
|
197
|
|
|
* |
|
198
|
|
|
* @see This function should be called only once |
|
199
|
|
|
* @return void |
|
200
|
|
|
*/ |
|
201
|
|
|
function init() |
|
202
|
|
|
{ |
|
203
|
|
|
// fix missing HTTP_RAW_POST_DATA in PHP 5.6 and above |
|
204
|
|
|
if(!isset($GLOBALS['HTTP_RAW_POST_DATA']) && version_compare(PHP_VERSION, '5.6.0', '>=') === TRUE) |
|
205
|
|
|
{ |
|
206
|
|
|
$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("php://input"); |
|
207
|
|
|
|
|
208
|
|
|
// If content is not XML JSON, unset |
|
209
|
|
|
if(!preg_match('/^[\<\{\[]/', $GLOBALS['HTTP_RAW_POST_DATA']) && strpos($_SERVER['CONTENT_TYPE'], 'json') === FALSE && strpos($_SERVER['HTTP_CONTENT_TYPE'], 'json') === FALSE) |
|
210
|
|
|
{ |
|
211
|
|
|
unset($GLOBALS['HTTP_RAW_POST_DATA']); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
// set context variables in $GLOBALS (to use in display handler) |
|
216
|
|
|
$this->context = &$GLOBALS['__Context__']; |
|
217
|
|
|
$this->context->lang = &$GLOBALS['lang']; |
|
218
|
|
|
$this->context->_COOKIE = $_COOKIE; |
|
219
|
|
|
|
|
220
|
|
|
// 20140429 editor/image_link |
|
221
|
|
|
$this->_checkGlobalVars(); |
|
222
|
|
|
|
|
223
|
|
|
$this->setRequestMethod(''); |
|
224
|
|
|
|
|
225
|
|
|
$this->_setXmlRpcArgument(); |
|
226
|
|
|
$this->_setJSONRequestArgument(); |
|
227
|
|
|
$this->_setRequestArgument(); |
|
228
|
|
|
$this->_setUploadedArgument(); |
|
229
|
|
|
|
|
230
|
|
|
$this->loadDBInfo(); |
|
231
|
|
|
if($this->db_info->use_sitelock == 'Y') |
|
232
|
|
|
{ |
|
233
|
|
|
if(is_array($this->db_info->sitelock_whitelist)) $whitelist = $this->db_info->sitelock_whitelist; |
|
234
|
|
|
|
|
235
|
|
|
if(!IpFilter::filter($whitelist)) |
|
|
|
|
|
|
236
|
|
|
{ |
|
237
|
|
|
$title = ($this->db_info->sitelock_title) ? $this->db_info->sitelock_title : 'Maintenance in progress...'; |
|
238
|
|
|
$message = $this->db_info->sitelock_message; |
|
239
|
|
|
|
|
240
|
|
|
define('_XE_SITELOCK_', TRUE); |
|
241
|
|
|
define('_XE_SITELOCK_TITLE_', $title); |
|
242
|
|
|
define('_XE_SITELOCK_MESSAGE_', $message); |
|
243
|
|
|
|
|
244
|
|
|
header("HTTP/1.1 403 Forbidden"); |
|
245
|
|
|
if(FileHandler::exists(_XE_PATH_ . 'common/tpl/sitelock.user.html')) |
|
|
|
|
|
|
246
|
|
|
{ |
|
247
|
|
|
include _XE_PATH_ . 'common/tpl/sitelock.user.html'; |
|
248
|
|
|
} |
|
249
|
|
|
else |
|
250
|
|
|
{ |
|
251
|
|
|
include _XE_PATH_ . 'common/tpl/sitelock.html'; |
|
252
|
|
|
} |
|
253
|
|
|
exit; |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
// If XE is installed, get virtual site information |
|
258
|
|
|
if(self::isInstalled()) |
|
259
|
|
|
{ |
|
260
|
|
|
$oModuleModel = getModel('module'); |
|
261
|
|
|
$site_module_info = $oModuleModel->getDefaultMid(); |
|
262
|
|
|
|
|
263
|
|
|
if(!isset($site_module_info)) |
|
264
|
|
|
{ |
|
265
|
|
|
$site_module_info = new stdClass(); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
// if site_srl of site_module_info is 0 (default site), compare the domain to default_url of db_config |
|
269
|
|
|
if($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url) |
|
270
|
|
|
{ |
|
271
|
|
|
$site_module_info->domain = $this->db_info->default_url; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
$this->set('site_module_info', $site_module_info); |
|
275
|
|
|
if($site_module_info->site_srl && isSiteID($site_module_info->domain)) |
|
276
|
|
|
{ |
|
277
|
|
|
$this->set('vid', $site_module_info->domain, TRUE); |
|
|
|
|
|
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
if(!isset($this->db_info)) |
|
281
|
|
|
{ |
|
282
|
|
|
$this->db_info = new stdClass(); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
$this->db_info->lang_type = $site_module_info->default_language; |
|
286
|
|
|
if(!$this->db_info->lang_type) |
|
287
|
|
|
{ |
|
288
|
|
|
$this->db_info->lang_type = 'en'; |
|
289
|
|
|
} |
|
290
|
|
|
if(!$this->db_info->use_db_session) |
|
291
|
|
|
{ |
|
292
|
|
|
$this->db_info->use_db_session = 'N'; |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
// Load Language File |
|
297
|
|
|
$lang_supported = $this->loadLangSelected(); |
|
298
|
|
|
|
|
299
|
|
|
// Retrieve language type set in user's cookie |
|
300
|
|
|
if($this->lang_type = $this->get('l')) |
|
301
|
|
|
{ |
|
302
|
|
|
if($_COOKIE['lang_type'] != $this->lang_type) |
|
303
|
|
|
{ |
|
304
|
|
|
setcookie('lang_type', $this->lang_type, $_SERVER['REQUEST_TIME'] + 3600 * 24 * 1000, '/'); |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
elseif($_COOKIE['lang_type']) |
|
308
|
|
|
{ |
|
309
|
|
|
$this->lang_type = $_COOKIE['lang_type']; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
// If it's not exists, follow default language type set in db_info |
|
313
|
|
|
if(!$this->lang_type) |
|
314
|
|
|
{ |
|
315
|
|
|
$this->lang_type = $this->db_info->lang_type; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
// if still lang_type has not been set or has not-supported type , set as English. |
|
319
|
|
|
if(!$this->lang_type) |
|
320
|
|
|
{ |
|
321
|
|
|
$this->lang_type = 'en'; |
|
322
|
|
|
} |
|
323
|
|
|
if(is_array($lang_supported) && !isset($lang_supported[$this->lang_type])) |
|
324
|
|
|
{ |
|
325
|
|
|
$this->lang_type = 'en'; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
$this->set('lang_supported', $lang_supported); |
|
|
|
|
|
|
329
|
|
|
$this->setLangType($this->lang_type); |
|
330
|
|
|
|
|
331
|
|
|
// load module module's language file according to language setting |
|
332
|
|
|
$this->loadLang(_XE_PATH_ . 'modules/module/lang'); |
|
333
|
|
|
|
|
334
|
|
|
// set session handler |
|
335
|
|
|
if(self::isInstalled() && $this->db_info->use_db_session == 'Y') |
|
336
|
|
|
{ |
|
337
|
|
|
$oSessionModel = getModel('session'); |
|
338
|
|
|
$oSessionController = getController('session'); |
|
339
|
|
|
session_set_save_handler( |
|
340
|
|
|
array(&$oSessionController, 'open'), array(&$oSessionController, 'close'), array(&$oSessionModel, 'read'), array(&$oSessionController, 'write'), array(&$oSessionController, 'destroy'), array(&$oSessionController, 'gc') |
|
341
|
|
|
); |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
if($sess = $_POST[session_name()]) session_id($sess); |
|
345
|
|
|
session_start(); |
|
346
|
|
|
|
|
347
|
|
|
// set authentication information in Context and session |
|
348
|
|
|
if(self::isInstalled()) |
|
349
|
|
|
{ |
|
350
|
|
|
$oModuleModel = getModel('module'); |
|
351
|
|
|
$oModuleModel->loadModuleExtends(); |
|
352
|
|
|
|
|
353
|
|
|
$oMemberModel = getModel('member'); |
|
354
|
|
|
$oMemberController = getController('member'); |
|
355
|
|
|
|
|
356
|
|
|
if($oMemberController && $oMemberModel) |
|
357
|
|
|
{ |
|
358
|
|
|
// if signed in, validate it. |
|
359
|
|
|
if($oMemberModel->isLogged()) |
|
360
|
|
|
{ |
|
361
|
|
|
$oMemberController->setSessionInfo(); |
|
362
|
|
|
} |
|
363
|
|
|
// check auto sign-in |
|
364
|
|
|
elseif($_COOKIE['xeak']) |
|
365
|
|
|
{ |
|
366
|
|
|
$oMemberController->doAutologin(); |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
$this->set('is_logged', $oMemberModel->isLogged()); |
|
370
|
|
|
$this->set('logged_info', $oMemberModel->getLoggedInfo()); |
|
371
|
|
|
} |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
// load common language file |
|
375
|
|
|
$this->lang = &$GLOBALS['lang']; |
|
376
|
|
|
$this->loadLang(_XE_PATH_ . 'common/lang/'); |
|
377
|
|
|
|
|
378
|
|
|
// check if using rewrite module |
|
379
|
|
|
$this->allow_rewrite = ($this->db_info->use_rewrite == 'Y' ? TRUE : FALSE); |
|
380
|
|
|
|
|
381
|
|
|
// set locations for javascript use |
|
382
|
|
|
$url = array(); |
|
|
|
|
|
|
383
|
|
|
$current_url = self::getRequestUri(); |
|
|
|
|
|
|
384
|
|
|
if($_SERVER['REQUEST_METHOD'] == 'GET') |
|
385
|
|
|
{ |
|
386
|
|
|
if($this->get_vars) |
|
387
|
|
|
{ |
|
388
|
|
|
$url = array(); |
|
389
|
|
View Code Duplication |
foreach($this->get_vars as $key => $val) |
|
390
|
|
|
{ |
|
391
|
|
|
if(is_array($val) && count($val) > 0) |
|
392
|
|
|
{ |
|
393
|
|
|
foreach($val as $k => $v) |
|
394
|
|
|
{ |
|
395
|
|
|
$url[] = $key . '[' . $k . ']=' . urlencode($v); |
|
396
|
|
|
} |
|
397
|
|
|
} |
|
398
|
|
|
elseif($val) |
|
399
|
|
|
{ |
|
400
|
|
|
$url[] = $key . '=' . urlencode($val); |
|
401
|
|
|
} |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
$current_url = self::getRequestUri(); |
|
405
|
|
|
if($url) $current_url .= '?' . join('&', $url); |
|
|
|
|
|
|
406
|
|
|
} |
|
407
|
|
|
else |
|
408
|
|
|
{ |
|
409
|
|
|
$current_url = $this->getUrl(); |
|
410
|
|
|
} |
|
411
|
|
|
} |
|
412
|
|
|
else |
|
413
|
|
|
{ |
|
414
|
|
|
$current_url = self::getRequestUri(); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
$this->set('current_url', $current_url); |
|
418
|
|
|
$this->set('request_uri', self::getRequestUri()); |
|
419
|
|
|
|
|
420
|
|
|
if(strpos($current_url, 'xn--') !== FALSE) |
|
421
|
|
|
{ |
|
422
|
|
|
$this->set('current_url', self::decodeIdna($current_url)); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
if(strpos(self::getRequestUri(), 'xn--') !== FALSE) |
|
426
|
|
|
{ |
|
427
|
|
|
$this->set('request_uri', self::decodeIdna(self::getRequestUri())); |
|
428
|
|
|
} |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* Finalize using resources, such as DB connection |
|
433
|
|
|
* |
|
434
|
|
|
* @return void |
|
435
|
|
|
*/ |
|
436
|
|
|
function close() |
|
437
|
|
|
{ |
|
438
|
|
|
session_write_close(); |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/** |
|
442
|
|
|
* Load the database information |
|
443
|
|
|
* |
|
444
|
|
|
* @return void |
|
445
|
|
|
*/ |
|
446
|
|
|
function loadDBInfo() |
|
447
|
|
|
{ |
|
448
|
|
|
$self = self::getInstance(); |
|
449
|
|
|
|
|
450
|
|
|
if(!$self->isInstalled()) |
|
451
|
|
|
{ |
|
452
|
|
|
return; |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
$config_file = $self->getConfigFile(); |
|
456
|
|
|
if(is_readable($config_file)) |
|
457
|
|
|
{ |
|
458
|
|
|
include($config_file); |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
// If master_db information does not exist, the config file needs to be updated |
|
462
|
|
|
if(!isset($db_info->master_db)) |
|
463
|
|
|
{ |
|
464
|
|
|
$db_info->master_db = array(); |
|
|
|
|
|
|
465
|
|
|
$db_info->master_db["db_type"] = $db_info->db_type; |
|
466
|
|
|
unset($db_info->db_type); |
|
467
|
|
|
$db_info->master_db["db_port"] = $db_info->db_port; |
|
468
|
|
|
unset($db_info->db_port); |
|
469
|
|
|
$db_info->master_db["db_hostname"] = $db_info->db_hostname; |
|
470
|
|
|
unset($db_info->db_hostname); |
|
471
|
|
|
$db_info->master_db["db_password"] = $db_info->db_password; |
|
472
|
|
|
unset($db_info->db_password); |
|
473
|
|
|
$db_info->master_db["db_database"] = $db_info->db_database; |
|
474
|
|
|
unset($db_info->db_database); |
|
475
|
|
|
$db_info->master_db["db_userid"] = $db_info->db_userid; |
|
476
|
|
|
unset($db_info->db_userid); |
|
477
|
|
|
$db_info->master_db["db_table_prefix"] = $db_info->db_table_prefix; |
|
478
|
|
|
unset($db_info->db_table_prefix); |
|
479
|
|
|
|
|
480
|
|
|
if(isset($db_info->master_db["db_table_prefix"]) && substr_compare($db_info->master_db["db_table_prefix"], '_', -1) !== 0) |
|
481
|
|
|
{ |
|
482
|
|
|
$db_info->master_db["db_table_prefix"] .= '_'; |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
$db_info->slave_db = array($db_info->master_db); |
|
486
|
|
|
$self->setDBInfo($db_info); |
|
487
|
|
|
|
|
488
|
|
|
$oInstallController = getController('install'); |
|
489
|
|
|
$oInstallController->makeConfigFile(); |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
if(!$db_info->use_prepared_statements) |
|
493
|
|
|
{ |
|
494
|
|
|
$db_info->use_prepared_statements = 'Y'; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
if(!$db_info->time_zone) |
|
498
|
|
|
$db_info->time_zone = date('O'); |
|
499
|
|
|
$GLOBALS['_time_zone'] = $db_info->time_zone; |
|
500
|
|
|
|
|
501
|
|
|
if($db_info->qmail_compatibility != 'Y') |
|
502
|
|
|
$db_info->qmail_compatibility = 'N'; |
|
503
|
|
|
$GLOBALS['_qmail_compatibility'] = $db_info->qmail_compatibility; |
|
504
|
|
|
|
|
505
|
|
|
if(!$db_info->use_db_session) |
|
506
|
|
|
$db_info->use_db_session = 'N'; |
|
507
|
|
|
if(!$db_info->use_ssl) |
|
508
|
|
|
$db_info->use_ssl = 'none'; |
|
509
|
|
|
$this->set('_use_ssl', $db_info->use_ssl); |
|
510
|
|
|
|
|
511
|
|
|
$self->set('_http_port', ($db_info->http_port) ? $db_info->http_port : NULL); |
|
512
|
|
|
$self->set('_https_port', ($db_info->https_port) ? $db_info->https_port : NULL); |
|
513
|
|
|
|
|
514
|
|
|
if(!$db_info->sitelock_whitelist) { |
|
515
|
|
|
$db_info->sitelock_whitelist = '127.0.0.1'; |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
if(is_string($db_info->sitelock_whitelist)) { |
|
519
|
|
|
$db_info->sitelock_whitelist = explode(',', $db_info->sitelock_whitelist); |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
$self->setDBInfo($db_info); |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
/** |
|
526
|
|
|
* Get DB's db_type |
|
527
|
|
|
* |
|
528
|
|
|
* @return string DB's db_type |
|
529
|
|
|
*/ |
|
530
|
|
|
function getDBType() |
|
531
|
|
|
{ |
|
532
|
|
|
$self = self::getInstance(); |
|
533
|
|
|
return $self->db_info->master_db["db_type"]; |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
/** |
|
537
|
|
|
* Set DB information |
|
538
|
|
|
* |
|
539
|
|
|
* @param object $db_info DB information |
|
540
|
|
|
* @return void |
|
541
|
|
|
*/ |
|
542
|
|
|
function setDBInfo($db_info) |
|
543
|
|
|
{ |
|
544
|
|
|
$self = self::getInstance(); |
|
545
|
|
|
$self->db_info = $db_info; |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
/** |
|
549
|
|
|
* Get DB information |
|
550
|
|
|
* |
|
551
|
|
|
* @return object DB information |
|
552
|
|
|
*/ |
|
553
|
|
|
function getDBInfo() |
|
554
|
|
|
{ |
|
555
|
|
|
$self = self::getInstance(); |
|
556
|
|
|
return $self->db_info; |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
/** |
|
560
|
|
|
* Return ssl status |
|
561
|
|
|
* |
|
562
|
|
|
* @return object SSL status (Optional - none|always|optional) |
|
563
|
|
|
*/ |
|
564
|
|
|
function getSslStatus() |
|
565
|
|
|
{ |
|
566
|
|
|
$dbInfo = self::getDBInfo(); |
|
567
|
|
|
return $dbInfo->use_ssl; |
|
568
|
|
|
} |
|
569
|
|
|
|
|
570
|
|
|
/** |
|
571
|
|
|
* Return default URL |
|
572
|
|
|
* |
|
573
|
|
|
* @return string Default URL |
|
574
|
|
|
*/ |
|
575
|
|
|
function getDefaultUrl() |
|
576
|
|
|
{ |
|
577
|
|
|
$db_info = self::getDBInfo(); |
|
578
|
|
|
return $db_info->default_url; |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
/** |
|
582
|
|
|
* Find supported languages |
|
583
|
|
|
* |
|
584
|
|
|
* @return array Supported languages |
|
585
|
|
|
*/ |
|
586
|
|
|
function loadLangSupported() |
|
587
|
|
|
{ |
|
588
|
|
|
static $lang_supported = null; |
|
589
|
|
View Code Duplication |
if(!$lang_supported) |
|
590
|
|
|
{ |
|
591
|
|
|
$langs = file(_XE_PATH_ . 'common/lang/lang.info'); |
|
592
|
|
|
foreach($langs as $val) |
|
593
|
|
|
{ |
|
594
|
|
|
list($lang_prefix, $lang_text) = explode(',', $val); |
|
595
|
|
|
$lang_text = trim($lang_text); |
|
596
|
|
|
$lang_supported[$lang_prefix] = $lang_text; |
|
597
|
|
|
} |
|
598
|
|
|
} |
|
599
|
|
|
return $lang_supported; |
|
600
|
|
|
} |
|
601
|
|
|
|
|
602
|
|
|
/** |
|
603
|
|
|
* Find selected languages to serve in the site |
|
604
|
|
|
* |
|
605
|
|
|
* @return array Selected languages |
|
606
|
|
|
*/ |
|
607
|
|
|
function loadLangSelected() |
|
608
|
|
|
{ |
|
609
|
|
|
static $lang_selected = null; |
|
610
|
|
|
if(!$lang_selected) |
|
611
|
|
|
{ |
|
612
|
|
|
$orig_lang_file = _XE_PATH_ . 'common/lang/lang.info'; |
|
613
|
|
|
$selected_lang_file = _XE_PATH_ . 'files/config/lang_selected.info'; |
|
614
|
|
|
if(!FileHandler::hasContent($selected_lang_file)) |
|
615
|
|
|
{ |
|
616
|
|
|
$old_selected_lang_file = _XE_PATH_ . 'files/cache/lang_selected.info'; |
|
617
|
|
|
FileHandler::moveFile($old_selected_lang_file, $selected_lang_file); |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
if(!FileHandler::hasContent($selected_lang_file)) |
|
621
|
|
|
{ |
|
622
|
|
|
$buff = FileHandler::readFile($orig_lang_file); |
|
623
|
|
|
FileHandler::writeFile($selected_lang_file, $buff); |
|
624
|
|
|
$lang_selected = self::loadLangSupported(); |
|
625
|
|
|
} |
|
626
|
|
View Code Duplication |
else |
|
627
|
|
|
{ |
|
628
|
|
|
$langs = file($selected_lang_file); |
|
629
|
|
|
foreach($langs as $val) |
|
630
|
|
|
{ |
|
631
|
|
|
list($lang_prefix, $lang_text) = explode(',', $val); |
|
632
|
|
|
$lang_text = trim($lang_text); |
|
633
|
|
|
$lang_selected[$lang_prefix] = $lang_text; |
|
634
|
|
|
} |
|
635
|
|
|
} |
|
636
|
|
|
} |
|
637
|
|
|
return $lang_selected; |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
/** |
|
641
|
|
|
* Single Sign On (SSO) |
|
642
|
|
|
* |
|
643
|
|
|
* @return bool True : Module handling is necessary in the control path of current request , False : Otherwise |
|
644
|
|
|
*/ |
|
645
|
|
|
function checkSSO() |
|
646
|
|
|
{ |
|
647
|
|
|
// pass if it's not GET request or XE is not yet installed |
|
648
|
|
|
if($this->db_info->use_sso != 'Y' || isCrawler()) |
|
649
|
|
|
{ |
|
650
|
|
|
return TRUE; |
|
651
|
|
|
} |
|
652
|
|
|
$checkActList = array('rss' => 1, 'atom' => 1); |
|
653
|
|
|
if(self::getRequestMethod() != 'GET' || !self::isInstalled() || isset($checkActList[self::get('act')])) |
|
654
|
|
|
{ |
|
655
|
|
|
return TRUE; |
|
656
|
|
|
} |
|
657
|
|
|
|
|
658
|
|
|
// pass if default URL is not set |
|
659
|
|
|
$default_url = trim($this->db_info->default_url); |
|
660
|
|
|
if(!$default_url) |
|
661
|
|
|
{ |
|
662
|
|
|
return TRUE; |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
if(substr_compare($default_url, '/', -1) !== 0) |
|
666
|
|
|
{ |
|
667
|
|
|
$default_url .= '/'; |
|
668
|
|
|
} |
|
669
|
|
|
|
|
670
|
|
|
// for sites recieving SSO valdiation |
|
671
|
|
|
if($default_url == self::getRequestUri()) |
|
672
|
|
|
{ |
|
673
|
|
|
if(self::get('url')) |
|
674
|
|
|
{ |
|
675
|
|
|
$url = base64_decode(self::get('url')); |
|
676
|
|
|
$url_info = parse_url($url); |
|
677
|
|
View Code Duplication |
if(!Password::checkSignature($url, self::get('sig'))) |
|
678
|
|
|
{ |
|
679
|
|
|
echo self::get('lang')->msg_invalid_request; |
|
680
|
|
|
return false; |
|
681
|
|
|
} |
|
682
|
|
|
|
|
683
|
|
|
$url_info['query'].= ($url_info['query'] ? '&' : '') . 'SSOID=' . urlencode(session_id()) . '&sig=' . urlencode(Password::createSignature(session_id())); |
|
684
|
|
|
$redirect_url = sprintf('%s://%s%s%s?%s', $url_info['scheme'], $url_info['host'], $url_info['port'] ? ':' . $url_info['port'] : '', $url_info['path'], $url_info['query']); |
|
685
|
|
|
header('location:' . $redirect_url); |
|
686
|
|
|
|
|
687
|
|
|
return FALSE; |
|
688
|
|
|
} |
|
689
|
|
|
// for sites requesting SSO validation |
|
690
|
|
|
} |
|
691
|
|
|
else |
|
692
|
|
|
{ |
|
693
|
|
|
// result handling : set session_name() |
|
694
|
|
|
if($session_name = self::get('SSOID')) |
|
695
|
|
|
{ |
|
696
|
|
View Code Duplication |
if(!Password::checkSignature($session_name, self::get('sig'))) |
|
697
|
|
|
{ |
|
698
|
|
|
echo self::get('lang')->msg_invalid_request; |
|
699
|
|
|
return false; |
|
700
|
|
|
} |
|
701
|
|
|
|
|
702
|
|
|
setcookie(session_name(), $session_name); |
|
703
|
|
|
|
|
704
|
|
|
$url = preg_replace('/[\?\&]SSOID=.+$/', '', self::getRequestUrl()); |
|
705
|
|
|
header('location:' . $url); |
|
706
|
|
|
return FALSE; |
|
707
|
|
|
// send SSO request |
|
708
|
|
|
} |
|
709
|
|
|
else if(!self::get('SSOID') && $_COOKIE['sso'] != md5(self::getRequestUri())) |
|
710
|
|
|
{ |
|
711
|
|
|
setcookie('sso', md5(self::getRequestUri()), 0, '/'); |
|
712
|
|
|
$origin_url = self::getRequestUrl(); |
|
713
|
|
|
$origin_sig = Password::createSignature($origin_url); |
|
714
|
|
|
$url = sprintf("%s?url=%s&sig=%s", $default_url, urlencode(base64_encode($origin_url)), urlencode($origin_sig)); |
|
715
|
|
|
header('location:' . $url); |
|
716
|
|
|
return FALSE; |
|
717
|
|
|
} |
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
|
return TRUE; |
|
721
|
|
|
} |
|
722
|
|
|
|
|
723
|
|
|
/** |
|
724
|
|
|
* Check if FTP info is registered |
|
725
|
|
|
* |
|
726
|
|
|
* @return bool True: FTP information is registered, False: otherwise |
|
727
|
|
|
*/ |
|
728
|
|
|
function isFTPRegisted() |
|
729
|
|
|
{ |
|
730
|
|
|
return file_exists(self::getFTPConfigFile()); |
|
731
|
|
|
} |
|
732
|
|
|
|
|
733
|
|
|
/** |
|
734
|
|
|
* Get FTP information |
|
735
|
|
|
* |
|
736
|
|
|
* @return object FTP information |
|
737
|
|
|
*/ |
|
738
|
|
|
function getFTPInfo() |
|
739
|
|
|
{ |
|
740
|
|
|
$self = self::getInstance(); |
|
741
|
|
|
|
|
742
|
|
|
if(!$self->isFTPRegisted()) |
|
743
|
|
|
{ |
|
744
|
|
|
return null; |
|
745
|
|
|
} |
|
746
|
|
|
|
|
747
|
|
|
include($self->getFTPConfigFile()); |
|
748
|
|
|
|
|
749
|
|
|
return $ftp_info; |
|
|
|
|
|
|
750
|
|
|
} |
|
751
|
|
|
|
|
752
|
|
|
/** |
|
753
|
|
|
* Add string to browser title |
|
754
|
|
|
* |
|
755
|
|
|
* @param string $site_title Browser title to be added |
|
756
|
|
|
* @return void |
|
757
|
|
|
*/ |
|
758
|
|
|
function addBrowserTitle($site_title) |
|
759
|
|
|
{ |
|
760
|
|
|
if(!$site_title) |
|
761
|
|
|
{ |
|
762
|
|
|
return; |
|
763
|
|
|
} |
|
764
|
|
|
$self = self::getInstance(); |
|
765
|
|
|
|
|
766
|
|
|
if($self->site_title) |
|
767
|
|
|
{ |
|
768
|
|
|
$self->site_title .= ' - ' . $site_title; |
|
769
|
|
|
} |
|
770
|
|
|
else |
|
771
|
|
|
{ |
|
772
|
|
|
$self->site_title = $site_title; |
|
773
|
|
|
} |
|
774
|
|
|
} |
|
775
|
|
|
|
|
776
|
|
|
/** |
|
777
|
|
|
* Set string to browser title |
|
778
|
|
|
* |
|
779
|
|
|
* @param string $site_title Browser title to be set |
|
780
|
|
|
* @return void |
|
781
|
|
|
*/ |
|
782
|
|
|
function setBrowserTitle($site_title) |
|
783
|
|
|
{ |
|
784
|
|
|
if(!$site_title) |
|
785
|
|
|
{ |
|
786
|
|
|
return; |
|
787
|
|
|
} |
|
788
|
|
|
$self = self::getInstance(); |
|
789
|
|
|
$self->site_title = $site_title; |
|
790
|
|
|
} |
|
791
|
|
|
|
|
792
|
|
|
/** |
|
793
|
|
|
* Get browser title |
|
794
|
|
|
* |
|
795
|
|
|
* @return string Browser title(htmlspecialchars applied) |
|
796
|
|
|
*/ |
|
797
|
|
|
function getBrowserTitle() |
|
798
|
|
|
{ |
|
799
|
|
|
$self = self::getInstance(); |
|
800
|
|
|
|
|
801
|
|
|
$oModuleController = getController('module'); |
|
802
|
|
|
$oModuleController->replaceDefinedLangCode($self->site_title); |
|
803
|
|
|
|
|
804
|
|
|
return htmlspecialchars($self->site_title, ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE); |
|
805
|
|
|
} |
|
806
|
|
|
|
|
807
|
|
|
/** |
|
808
|
|
|
* Return layout's title |
|
809
|
|
|
* @return string layout's title |
|
810
|
|
|
*/ |
|
811
|
|
|
public function getSiteTitle() |
|
812
|
|
|
{ |
|
813
|
|
|
$oModuleModel = getModel('module'); |
|
814
|
|
|
$moduleConfig = $oModuleModel->getModuleConfig('module'); |
|
815
|
|
|
|
|
816
|
|
|
if(isset($moduleConfig->siteTitle)) |
|
817
|
|
|
{ |
|
818
|
|
|
return $moduleConfig->siteTitle; |
|
819
|
|
|
} |
|
820
|
|
|
return ''; |
|
821
|
|
|
} |
|
822
|
|
|
|
|
823
|
|
|
/** |
|
824
|
|
|
* Get browser title |
|
825
|
|
|
* @deprecated |
|
826
|
|
|
*/ |
|
827
|
|
|
function _getBrowserTitle() |
|
828
|
|
|
{ |
|
829
|
|
|
return $this->getBrowserTitle(); |
|
830
|
|
|
} |
|
831
|
|
|
|
|
832
|
|
|
/** |
|
833
|
|
|
* Load language file according to language type |
|
834
|
|
|
* |
|
835
|
|
|
* @param string $path Path of the language file |
|
836
|
|
|
* @return void |
|
837
|
|
|
*/ |
|
838
|
|
|
function loadLang($path) |
|
839
|
|
|
{ |
|
840
|
|
|
global $lang; |
|
841
|
|
|
|
|
842
|
|
|
$self = self::getInstance(); |
|
843
|
|
|
if(!$self->lang_type) |
|
844
|
|
|
{ |
|
845
|
|
|
return; |
|
846
|
|
|
} |
|
847
|
|
|
if(!is_object($lang)) |
|
848
|
|
|
{ |
|
849
|
|
|
$lang = new stdClass; |
|
850
|
|
|
} |
|
851
|
|
|
|
|
852
|
|
|
if(!($filename = $self->_loadXmlLang($path))) |
|
853
|
|
|
{ |
|
854
|
|
|
$filename = $self->_loadPhpLang($path); |
|
855
|
|
|
} |
|
856
|
|
|
|
|
857
|
|
|
if(!is_array($self->loaded_lang_files)) |
|
858
|
|
|
{ |
|
859
|
|
|
$self->loaded_lang_files = array(); |
|
860
|
|
|
} |
|
861
|
|
|
if(in_array($filename, $self->loaded_lang_files)) |
|
862
|
|
|
{ |
|
863
|
|
|
return; |
|
864
|
|
|
} |
|
865
|
|
|
|
|
866
|
|
|
if($filename && is_readable($filename)) |
|
867
|
|
|
{ |
|
868
|
|
|
$self->loaded_lang_files[] = $filename; |
|
869
|
|
|
include($filename); |
|
870
|
|
|
} |
|
871
|
|
|
else |
|
872
|
|
|
{ |
|
873
|
|
|
$self->_evalxmlLang($path); |
|
874
|
|
|
} |
|
875
|
|
|
} |
|
876
|
|
|
|
|
877
|
|
|
/** |
|
878
|
|
|
* Evaluation of xml language file |
|
879
|
|
|
* |
|
880
|
|
|
* @param string Path of the language file |
|
881
|
|
|
* @return void |
|
882
|
|
|
*/ |
|
883
|
|
|
function _evalxmlLang($path) |
|
884
|
|
|
{ |
|
885
|
|
|
global $lang; |
|
886
|
|
|
|
|
887
|
|
|
if(!$path) return; |
|
888
|
|
|
|
|
889
|
|
|
$_path = 'eval://' . $path; |
|
890
|
|
|
|
|
891
|
|
|
if(in_array($_path, $this->loaded_lang_files)) |
|
892
|
|
|
{ |
|
893
|
|
|
return; |
|
894
|
|
|
} |
|
895
|
|
|
|
|
896
|
|
|
if(substr_compare($path, '/', -1) !== 0) |
|
897
|
|
|
{ |
|
898
|
|
|
$path .= '/'; |
|
899
|
|
|
} |
|
900
|
|
|
|
|
901
|
|
|
$oXmlLangParser = new XmlLangParser($path . 'lang.xml', $this->lang_type); |
|
902
|
|
|
$content = $oXmlLangParser->getCompileContent(); |
|
903
|
|
|
|
|
904
|
|
|
if($content) |
|
|
|
|
|
|
905
|
|
|
{ |
|
906
|
|
|
$this->loaded_lang_files[] = $_path; |
|
907
|
|
|
eval($content); |
|
|
|
|
|
|
908
|
|
|
} |
|
909
|
|
|
} |
|
910
|
|
|
|
|
911
|
|
|
/** |
|
912
|
|
|
* Load language file of xml type |
|
913
|
|
|
* |
|
914
|
|
|
* @param string $path Path of the language file |
|
915
|
|
|
* @return string file name |
|
916
|
|
|
*/ |
|
917
|
|
|
function _loadXmlLang($path) |
|
918
|
|
|
{ |
|
919
|
|
|
if(!$path) return; |
|
920
|
|
|
|
|
921
|
|
|
$oXmlLangParser = new XmlLangParser($path . ((substr_compare($path, '/', -1) !== 0) ? '/' : '') . 'lang.xml', $this->lang_type); |
|
922
|
|
|
return $oXmlLangParser->compile(); |
|
923
|
|
|
} |
|
924
|
|
|
|
|
925
|
|
|
/** |
|
926
|
|
|
* Load language file of php type |
|
927
|
|
|
* |
|
928
|
|
|
* @param string $path Path of the language file |
|
929
|
|
|
* @return string file name |
|
930
|
|
|
*/ |
|
931
|
|
|
function _loadPhpLang($path) |
|
932
|
|
|
{ |
|
933
|
|
|
if(!$path) return; |
|
934
|
|
|
|
|
935
|
|
|
if(substr_compare($path, '/', -1) !== 0) |
|
936
|
|
|
{ |
|
937
|
|
|
$path .= '/'; |
|
938
|
|
|
} |
|
939
|
|
|
$path_tpl = $path . '%s.lang.php'; |
|
940
|
|
|
$file = sprintf($path_tpl, $this->lang_type); |
|
941
|
|
|
|
|
942
|
|
|
$langs = array('ko', 'en'); // this will be configurable. |
|
943
|
|
|
while(!is_readable($file) && $langs[0]) |
|
944
|
|
|
{ |
|
945
|
|
|
$file = sprintf($path_tpl, array_shift($langs)); |
|
946
|
|
|
} |
|
947
|
|
|
|
|
948
|
|
|
if(!is_readable($file)) |
|
949
|
|
|
{ |
|
950
|
|
|
return FALSE; |
|
951
|
|
|
} |
|
952
|
|
|
return $file; |
|
953
|
|
|
} |
|
954
|
|
|
|
|
955
|
|
|
/** |
|
956
|
|
|
* Set lang_type |
|
957
|
|
|
* |
|
958
|
|
|
* @param string $lang_type Language type. |
|
959
|
|
|
* @return void |
|
960
|
|
|
*/ |
|
961
|
|
|
function setLangType($lang_type = 'ko') |
|
962
|
|
|
{ |
|
963
|
|
|
$self = self::getInstance(); |
|
964
|
|
|
|
|
965
|
|
|
$self->lang_type = $lang_type; |
|
966
|
|
|
$self->set('lang_type', $lang_type); |
|
967
|
|
|
|
|
968
|
|
|
$_SESSION['lang_type'] = $lang_type; |
|
969
|
|
|
} |
|
970
|
|
|
|
|
971
|
|
|
/** |
|
972
|
|
|
* Get lang_type |
|
973
|
|
|
* |
|
974
|
|
|
* @return string Language type |
|
975
|
|
|
*/ |
|
976
|
|
|
function getLangType() |
|
977
|
|
|
{ |
|
978
|
|
|
$self = self::getInstance(); |
|
979
|
|
|
return $self->lang_type; |
|
980
|
|
|
} |
|
981
|
|
|
|
|
982
|
|
|
/** |
|
983
|
|
|
* Return string accoring to the inputed code |
|
984
|
|
|
* |
|
985
|
|
|
* @param string $code Language variable name |
|
986
|
|
|
* @return string If string for the code exists returns it, otherwise returns original code |
|
987
|
|
|
*/ |
|
988
|
|
|
function getLang($code) |
|
989
|
|
|
{ |
|
990
|
|
|
if(!$code) |
|
991
|
|
|
{ |
|
992
|
|
|
return; |
|
993
|
|
|
} |
|
994
|
|
|
if($GLOBALS['lang']->{$code}) |
|
995
|
|
|
{ |
|
996
|
|
|
return $GLOBALS['lang']->{$code}; |
|
997
|
|
|
} |
|
998
|
|
|
return $code; |
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
/** |
|
1002
|
|
|
* Set data to lang variable |
|
1003
|
|
|
* |
|
1004
|
|
|
* @param string $code Language variable name |
|
1005
|
|
|
* @param string $val `$code`s value |
|
1006
|
|
|
* @return void |
|
1007
|
|
|
*/ |
|
1008
|
|
|
function setLang($code, $val) |
|
1009
|
|
|
{ |
|
1010
|
|
|
if(!isset($GLOBALS['lang'])) |
|
1011
|
|
|
{ |
|
1012
|
|
|
$GLOBALS['lang'] = new stdClass(); |
|
1013
|
|
|
} |
|
1014
|
|
|
$GLOBALS['lang']->{$code} = $val; |
|
1015
|
|
|
} |
|
1016
|
|
|
|
|
1017
|
|
|
/** |
|
1018
|
|
|
* Convert strings of variables in $source_object into UTF-8 |
|
1019
|
|
|
* |
|
1020
|
|
|
* @param object $source_obj Conatins strings to convert |
|
1021
|
|
|
* @return object converted object |
|
1022
|
|
|
*/ |
|
1023
|
|
|
function convertEncoding($source_obj) |
|
1024
|
|
|
{ |
|
1025
|
|
|
$charset_list = array( |
|
1026
|
|
|
'UTF-8', 'EUC-KR', 'CP949', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS', 'CP932', |
|
1027
|
|
|
'EUC-CN', 'HZ', 'GBK', 'GB18030', 'EUC-TW', 'BIG5', 'CP950', 'BIG5-HKSCS', |
|
1028
|
|
|
'ISO2022-CN', 'ISO2022-CN-EXT', 'ISO2022-JP', 'ISO2022-JP-2', 'ISO2022-JP-1', |
|
1029
|
|
|
'ISO8859-6', 'ISO8859-8', 'JOHAB', 'ISO2022-KR', 'CP1255', 'CP1256', 'CP862', |
|
1030
|
|
|
'ASCII', 'ISO8859-1', 'ISO8850-2', 'ISO8850-3', 'ISO8850-4', 'ISO8850-5', |
|
1031
|
|
|
'ISO8850-7', 'ISO8850-9', 'ISO8850-10', 'ISO8850-13', 'ISO8850-14', |
|
1032
|
|
|
'ISO8850-15', 'ISO8850-16', 'CP1250', 'CP1251', 'CP1252', 'CP1253', 'CP1254', |
|
1033
|
|
|
'CP1257', 'CP850', 'CP866', |
|
1034
|
|
|
); |
|
1035
|
|
|
|
|
1036
|
|
|
$obj = clone $source_obj; |
|
1037
|
|
|
|
|
1038
|
|
|
foreach($charset_list as $charset) |
|
1039
|
|
|
{ |
|
1040
|
|
|
array_walk($obj,'Context::checkConvertFlag',$charset); |
|
1041
|
|
|
$flag = self::checkConvertFlag($flag = TRUE); |
|
|
|
|
|
|
1042
|
|
|
if($flag) |
|
1043
|
|
|
{ |
|
1044
|
|
|
if($charset == 'UTF-8') |
|
1045
|
|
|
{ |
|
1046
|
|
|
return $obj; |
|
1047
|
|
|
} |
|
1048
|
|
|
array_walk($obj,'Context::doConvertEncoding',$charset); |
|
1049
|
|
|
return $obj; |
|
1050
|
|
|
} |
|
1051
|
|
|
} |
|
1052
|
|
|
return $obj; |
|
1053
|
|
|
} |
|
1054
|
|
|
|
|
1055
|
|
|
/** |
|
1056
|
|
|
* Check flag |
|
1057
|
|
|
* |
|
1058
|
|
|
* @param mixed $val |
|
1059
|
|
|
* @param string $key |
|
1060
|
|
|
* @param mixed $charset charset |
|
1061
|
|
|
* @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5 |
|
1062
|
|
|
* @return void |
|
1063
|
|
|
*/ |
|
1064
|
|
|
function checkConvertFlag(&$val, $key = null, $charset = null) |
|
|
|
|
|
|
1065
|
|
|
{ |
|
1066
|
|
|
static $flag = TRUE; |
|
1067
|
|
|
if($charset) |
|
1068
|
|
|
{ |
|
1069
|
|
|
if(is_array($val)) |
|
1070
|
|
|
array_walk($val,'Context::checkConvertFlag',$charset); |
|
1071
|
|
|
else if($val && iconv($charset,$charset,$val)!=$val) $flag = FALSE; |
|
1072
|
|
|
else $flag = FALSE; |
|
1073
|
|
|
} |
|
1074
|
|
|
else |
|
1075
|
|
|
{ |
|
1076
|
|
|
$return = $flag; |
|
1077
|
|
|
$flag = TRUE; |
|
1078
|
|
|
return $return; |
|
1079
|
|
|
} |
|
1080
|
|
|
} |
|
1081
|
|
|
|
|
1082
|
|
|
/** |
|
1083
|
|
|
* Convert array type variables into UTF-8 |
|
1084
|
|
|
* |
|
1085
|
|
|
* @param mixed $val |
|
1086
|
|
|
* @param string $key |
|
1087
|
|
|
* @param string $charset character set |
|
1088
|
|
|
* @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5 |
|
1089
|
|
|
* @return object converted object |
|
1090
|
|
|
*/ |
|
1091
|
|
|
function doConvertEncoding(&$val, $key = null, $charset) |
|
|
|
|
|
|
1092
|
|
|
{ |
|
1093
|
|
|
if (is_array($val)) |
|
1094
|
|
|
{ |
|
1095
|
|
|
array_walk($val,'Context::doConvertEncoding',$charset); |
|
1096
|
|
|
} |
|
1097
|
|
|
else $val = iconv($charset,'UTF-8',$val); |
|
1098
|
|
|
} |
|
1099
|
|
|
|
|
1100
|
|
|
/** |
|
1101
|
|
|
* Convert strings into UTF-8 |
|
1102
|
|
|
* |
|
1103
|
|
|
* @param string $str String to convert |
|
1104
|
|
|
* @return string converted string |
|
1105
|
|
|
*/ |
|
1106
|
|
|
function convertEncodingStr($str) |
|
1107
|
|
|
{ |
|
1108
|
|
|
if(!$str) return null; |
|
1109
|
|
|
$obj = new stdClass(); |
|
1110
|
|
|
$obj->str = $str; |
|
1111
|
|
|
$obj = self::convertEncoding($obj); |
|
1112
|
|
|
return $obj->str; |
|
1113
|
|
|
} |
|
1114
|
|
|
|
|
1115
|
|
|
function decodeIdna($domain) |
|
1116
|
|
|
{ |
|
1117
|
|
|
if(strpos($domain, 'xn--') !== FALSE) |
|
1118
|
|
|
{ |
|
1119
|
|
|
require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php'); |
|
1120
|
|
|
$IDN = new idna_convert(array('idn_version' => 2008)); |
|
1121
|
|
|
$domain = $IDN->decode($domain); |
|
1122
|
|
|
} |
|
1123
|
|
|
|
|
1124
|
|
|
return $domain; |
|
1125
|
|
|
} |
|
1126
|
|
|
|
|
1127
|
|
|
/** |
|
1128
|
|
|
* Force to set response method |
|
1129
|
|
|
* |
|
1130
|
|
|
* @param string $method Response method. [HTML|XMLRPC|JSON] |
|
1131
|
|
|
* @return void |
|
1132
|
|
|
*/ |
|
1133
|
|
|
function setResponseMethod($method = 'HTML') |
|
1134
|
|
|
{ |
|
1135
|
|
|
$self = self::getInstance(); |
|
1136
|
|
|
|
|
1137
|
|
|
$methods = array('HTML' => 1, 'XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
|
1138
|
|
|
$self->response_method = isset($methods[$method]) ? $method : 'HTML'; |
|
1139
|
|
|
} |
|
1140
|
|
|
|
|
1141
|
|
|
/** |
|
1142
|
|
|
* Get reponse method |
|
1143
|
|
|
* |
|
1144
|
|
|
* @return string Response method. If it's not set, returns request method. |
|
1145
|
|
|
*/ |
|
1146
|
|
|
function getResponseMethod() |
|
1147
|
|
|
{ |
|
1148
|
|
|
$self = self::getInstance(); |
|
1149
|
|
|
|
|
1150
|
|
|
if($self->response_method) |
|
1151
|
|
|
{ |
|
1152
|
|
|
return $self->response_method; |
|
1153
|
|
|
} |
|
1154
|
|
|
|
|
1155
|
|
|
$method = $self->getRequestMethod(); |
|
1156
|
|
|
$methods = array('HTML' => 1, 'XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
|
1157
|
|
|
|
|
1158
|
|
|
return isset($methods[$method]) ? $method : 'HTML'; |
|
1159
|
|
|
} |
|
1160
|
|
|
|
|
1161
|
|
|
/** |
|
1162
|
|
|
* Determine request method |
|
1163
|
|
|
* |
|
1164
|
|
|
* @param string $type Request method. (Optional - GET|POST|XMLRPC|JSON) |
|
1165
|
|
|
* @return void |
|
1166
|
|
|
*/ |
|
1167
|
|
|
function setRequestMethod($type = '') |
|
1168
|
|
|
{ |
|
1169
|
|
|
$self = self::getInstance(); |
|
1170
|
|
|
|
|
1171
|
|
|
$self->js_callback_func = $self->getJSCallbackFunc(); |
|
1172
|
|
|
|
|
1173
|
|
|
($type && $self->request_method = $type) or |
|
1174
|
|
|
((strpos($_SERVER['CONTENT_TYPE'], 'json') || strpos($_SERVER['HTTP_CONTENT_TYPE'], 'json')) && $self->request_method = 'JSON') or |
|
1175
|
|
|
($GLOBALS['HTTP_RAW_POST_DATA'] && $self->request_method = 'XMLRPC') or |
|
1176
|
|
|
($self->js_callback_func && $self->request_method = 'JS_CALLBACK') or |
|
1177
|
|
|
($self->request_method = $_SERVER['REQUEST_METHOD']); |
|
1178
|
|
|
} |
|
1179
|
|
|
|
|
1180
|
|
|
/** |
|
1181
|
|
|
* handle global arguments |
|
1182
|
|
|
* |
|
1183
|
|
|
* @return void |
|
1184
|
|
|
*/ |
|
1185
|
|
|
function _checkGlobalVars() |
|
1186
|
|
|
{ |
|
1187
|
|
|
$this->_recursiveCheckVar($_SERVER['HTTP_HOST']); |
|
1188
|
|
|
|
|
1189
|
|
|
$pattern = "/[\,\"\'\{\}\[\]\(\);$]/"; |
|
1190
|
|
|
if(preg_match($pattern, $_SERVER['HTTP_HOST'])) |
|
1191
|
|
|
{ |
|
1192
|
|
|
$this->isSuccessInit = FALSE; |
|
1193
|
|
|
} |
|
1194
|
|
|
} |
|
1195
|
|
|
|
|
1196
|
|
|
/** |
|
1197
|
|
|
* handle request arguments for GET/POST |
|
1198
|
|
|
* |
|
1199
|
|
|
* @return void |
|
1200
|
|
|
*/ |
|
1201
|
|
|
function _setRequestArgument() |
|
1202
|
|
|
{ |
|
1203
|
|
|
if(!count($_REQUEST)) |
|
1204
|
|
|
{ |
|
1205
|
|
|
return; |
|
1206
|
|
|
} |
|
1207
|
|
|
|
|
1208
|
|
|
$requestMethod = $this->getRequestMethod(); |
|
1209
|
|
|
foreach($_REQUEST as $key => $val) |
|
1210
|
|
|
{ |
|
1211
|
|
|
if($val === '' || self::get($key)) |
|
1212
|
|
|
{ |
|
1213
|
|
|
continue; |
|
1214
|
|
|
} |
|
1215
|
|
|
$key = htmlentities($key); |
|
1216
|
|
|
$val = $this->_filterRequestVar($key, $val); |
|
1217
|
|
|
|
|
1218
|
|
|
if($requestMethod == 'GET' && isset($_GET[$key])) |
|
1219
|
|
|
{ |
|
1220
|
|
|
$set_to_vars = TRUE; |
|
1221
|
|
|
} |
|
1222
|
|
|
elseif($requestMethod == 'POST' && isset($_POST[$key])) |
|
1223
|
|
|
{ |
|
1224
|
|
|
$set_to_vars = TRUE; |
|
1225
|
|
|
} |
|
1226
|
|
|
elseif($requestMethod == 'JS_CALLBACK' && (isset($_GET[$key]) || isset($_POST[$key]))) |
|
1227
|
|
|
{ |
|
1228
|
|
|
$set_to_vars = TRUE; |
|
1229
|
|
|
} |
|
1230
|
|
|
else |
|
1231
|
|
|
{ |
|
1232
|
|
|
$set_to_vars = FALSE; |
|
1233
|
|
|
} |
|
1234
|
|
|
|
|
1235
|
|
|
if($set_to_vars) |
|
1236
|
|
|
{ |
|
1237
|
|
|
$this->_recursiveCheckVar($val); |
|
1238
|
|
|
} |
|
1239
|
|
|
|
|
1240
|
|
|
$this->set($key, $val, $set_to_vars); |
|
|
|
|
|
|
1241
|
|
|
} |
|
1242
|
|
|
} |
|
1243
|
|
|
|
|
1244
|
|
|
function _recursiveCheckVar($val) |
|
1245
|
|
|
{ |
|
1246
|
|
|
if(is_string($val)) |
|
1247
|
|
|
{ |
|
1248
|
|
|
foreach($this->patterns as $pattern) |
|
1249
|
|
|
{ |
|
1250
|
|
|
if(preg_match($pattern, $val)) |
|
1251
|
|
|
{ |
|
1252
|
|
|
$this->isSuccessInit = FALSE; |
|
1253
|
|
|
return; |
|
1254
|
|
|
} |
|
1255
|
|
|
} |
|
1256
|
|
|
} |
|
1257
|
|
|
else if(is_array($val)) |
|
1258
|
|
|
{ |
|
1259
|
|
|
foreach($val as $val2) |
|
1260
|
|
|
{ |
|
1261
|
|
|
$this->_recursiveCheckVar($val2); |
|
1262
|
|
|
} |
|
1263
|
|
|
} |
|
1264
|
|
|
} |
|
1265
|
|
|
|
|
1266
|
|
|
/** |
|
1267
|
|
|
* Handle request arguments for JSON |
|
1268
|
|
|
* |
|
1269
|
|
|
* @return void |
|
1270
|
|
|
*/ |
|
1271
|
|
|
function _setJSONRequestArgument() |
|
1272
|
|
|
{ |
|
1273
|
|
|
if($this->getRequestMethod() != 'JSON') |
|
1274
|
|
|
{ |
|
1275
|
|
|
return; |
|
1276
|
|
|
} |
|
1277
|
|
|
|
|
1278
|
|
|
$params = array(); |
|
1279
|
|
|
parse_str($GLOBALS['HTTP_RAW_POST_DATA'], $params); |
|
1280
|
|
|
|
|
1281
|
|
|
foreach($params as $key => $val) |
|
|
|
|
|
|
1282
|
|
|
{ |
|
1283
|
|
|
$this->set($key, $this->_filterRequestVar($key, $val, 1), TRUE); |
|
|
|
|
|
|
1284
|
|
|
} |
|
1285
|
|
|
} |
|
1286
|
|
|
|
|
1287
|
|
|
/** |
|
1288
|
|
|
* Handle request arguments for XML RPC |
|
1289
|
|
|
* |
|
1290
|
|
|
* @return void |
|
1291
|
|
|
*/ |
|
1292
|
|
|
function _setXmlRpcArgument() |
|
1293
|
|
|
{ |
|
1294
|
|
|
if($this->getRequestMethod() != 'XMLRPC') |
|
1295
|
|
|
{ |
|
1296
|
|
|
return; |
|
1297
|
|
|
} |
|
1298
|
|
|
|
|
1299
|
|
|
$xml = $GLOBALS['HTTP_RAW_POST_DATA']; |
|
1300
|
|
|
if(Security::detectingXEE($xml)) |
|
1301
|
|
|
{ |
|
1302
|
|
|
header("HTTP/1.0 400 Bad Request"); |
|
1303
|
|
|
exit; |
|
1304
|
|
|
} |
|
1305
|
|
|
|
|
1306
|
|
|
$oXml = new XmlParser(); |
|
1307
|
|
|
$xml_obj = $oXml->parse($xml); |
|
1308
|
|
|
|
|
1309
|
|
|
$params = $xml_obj->methodcall->params; |
|
1310
|
|
|
unset($params->node_name, $params->attrs, $params->body); |
|
1311
|
|
|
|
|
1312
|
|
|
if(!count(get_object_vars($params))) |
|
1313
|
|
|
{ |
|
1314
|
|
|
return; |
|
1315
|
|
|
} |
|
1316
|
|
|
|
|
1317
|
|
|
foreach($params as $key => $val) |
|
1318
|
|
|
{ |
|
1319
|
|
|
$this->set($key, $this->_filterXmlVars($key, $val), TRUE); |
|
|
|
|
|
|
1320
|
|
|
} |
|
1321
|
|
|
} |
|
1322
|
|
|
|
|
1323
|
|
|
/** |
|
1324
|
|
|
* Filter xml variables |
|
1325
|
|
|
* |
|
1326
|
|
|
* @param string $key Variable key |
|
1327
|
|
|
* @param object $val Variable value |
|
1328
|
|
|
* @return mixed filtered value |
|
1329
|
|
|
*/ |
|
1330
|
|
|
function _filterXmlVars($key, $val) |
|
1331
|
|
|
{ |
|
1332
|
|
|
if(is_array($val)) |
|
1333
|
|
|
{ |
|
1334
|
|
|
$stack = array(); |
|
1335
|
|
|
foreach($val as $k => $v) |
|
1336
|
|
|
{ |
|
1337
|
|
|
$stack[$k] = $this->_filterXmlVars($k, $v); |
|
1338
|
|
|
} |
|
1339
|
|
|
|
|
1340
|
|
|
return $stack; |
|
1341
|
|
|
} |
|
1342
|
|
|
|
|
1343
|
|
|
$body = $val->body; |
|
1344
|
|
|
unset($val->node_name, $val->attrs, $val->body); |
|
1345
|
|
|
if(!count(get_object_vars($val))) |
|
1346
|
|
|
{ |
|
1347
|
|
|
return $this->_filterRequestVar($key, $body, 0); |
|
1348
|
|
|
} |
|
1349
|
|
|
|
|
1350
|
|
|
$stack = new stdClass(); |
|
1351
|
|
|
foreach($val as $k => $v) |
|
1352
|
|
|
{ |
|
1353
|
|
|
$output = $this->_filterXmlVars($k, $v); |
|
1354
|
|
|
if(is_object($v) && $v->attrs->type == 'array') |
|
1355
|
|
|
{ |
|
1356
|
|
|
$output = array($output); |
|
1357
|
|
|
} |
|
1358
|
|
|
if($k == 'value' && (is_array($v) || $v->attrs->type == 'array')) |
|
1359
|
|
|
{ |
|
1360
|
|
|
return $output; |
|
1361
|
|
|
} |
|
1362
|
|
|
|
|
1363
|
|
|
$stack->{$k} = $output; |
|
1364
|
|
|
} |
|
1365
|
|
|
|
|
1366
|
|
|
if(!count(get_object_vars($stack))) |
|
1367
|
|
|
{ |
|
1368
|
|
|
return NULL; |
|
1369
|
|
|
} |
|
1370
|
|
|
|
|
1371
|
|
|
return $stack; |
|
1372
|
|
|
} |
|
1373
|
|
|
|
|
1374
|
|
|
/** |
|
1375
|
|
|
* Filter request variable |
|
1376
|
|
|
* |
|
1377
|
|
|
* @see Cast variables, such as _srl, page, and cpage, into interger |
|
1378
|
|
|
* @param string $key Variable key |
|
1379
|
|
|
* @param string $val Variable value |
|
1380
|
|
|
* @param string $do_stripslashes Whether to strip slashes |
|
1381
|
|
|
* @return mixed filtered value. Type are string or array |
|
1382
|
|
|
*/ |
|
1383
|
|
|
function _filterRequestVar($key, $val, $do_stripslashes = 1) |
|
1384
|
|
|
{ |
|
1385
|
|
|
if(!($isArray = is_array($val))) |
|
1386
|
|
|
{ |
|
1387
|
|
|
$val = array($val); |
|
1388
|
|
|
} |
|
1389
|
|
|
|
|
1390
|
|
|
$result = array(); |
|
1391
|
|
|
foreach($val as $k => $v) |
|
1392
|
|
|
{ |
|
1393
|
|
|
$k = htmlentities($k); |
|
1394
|
|
|
if($key === 'page' || $key === 'cpage' || substr_compare($key, 'srl', -3) === 0) |
|
1395
|
|
|
{ |
|
1396
|
|
|
$result[$k] = !preg_match('/^[0-9,]+$/', $v) ? (int) $v : $v; |
|
1397
|
|
|
} |
|
1398
|
|
|
elseif($key === 'mid' || $key === 'search_keyword') |
|
1399
|
|
|
{ |
|
1400
|
|
|
$result[$k] = htmlspecialchars($v, ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE); |
|
1401
|
|
|
} |
|
1402
|
|
|
elseif($key === 'vid') |
|
1403
|
|
|
{ |
|
1404
|
|
|
$result[$k] = urlencode($v); |
|
1405
|
|
|
} |
|
1406
|
|
|
else |
|
1407
|
|
|
{ |
|
1408
|
|
|
$result[$k] = $v; |
|
1409
|
|
|
|
|
1410
|
|
|
if($do_stripslashes && version_compare(PHP_VERSION, '5.4.0', '<') && get_magic_quotes_gpc()) |
|
1411
|
|
|
{ |
|
1412
|
|
|
$result[$k] = stripslashes($result[$k]); |
|
1413
|
|
|
} |
|
1414
|
|
|
|
|
1415
|
|
|
if(!is_array($result[$k])) |
|
1416
|
|
|
{ |
|
1417
|
|
|
$result[$k] = trim($result[$k]); |
|
1418
|
|
|
} |
|
1419
|
|
|
} |
|
1420
|
|
|
} |
|
1421
|
|
|
|
|
1422
|
|
|
return $isArray ? $result : $result[0]; |
|
1423
|
|
|
} |
|
1424
|
|
|
|
|
1425
|
|
|
/** |
|
1426
|
|
|
* Check if there exists uploaded file |
|
1427
|
|
|
* |
|
1428
|
|
|
* @return bool True: exists, False: otherwise |
|
1429
|
|
|
*/ |
|
1430
|
|
|
function isUploaded() |
|
1431
|
|
|
{ |
|
1432
|
|
|
$self = self::getInstance(); |
|
1433
|
|
|
return $self->is_uploaded; |
|
1434
|
|
|
} |
|
1435
|
|
|
|
|
1436
|
|
|
/** |
|
1437
|
|
|
* Handle uploaded file |
|
1438
|
|
|
* |
|
1439
|
|
|
* @return void |
|
1440
|
|
|
*/ |
|
1441
|
|
|
function _setUploadedArgument() |
|
1442
|
|
|
{ |
|
1443
|
|
|
if($_SERVER['REQUEST_METHOD'] != 'POST' || !$_FILES || (stripos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') === FALSE && stripos($_SERVER['HTTP_CONTENT_TYPE'], 'multipart/form-data') === FALSE)) |
|
1444
|
|
|
{ |
|
1445
|
|
|
return; |
|
1446
|
|
|
} |
|
1447
|
|
|
|
|
1448
|
|
|
foreach($_FILES as $key => $val) |
|
1449
|
|
|
{ |
|
1450
|
|
|
$tmp_name = $val['tmp_name']; |
|
1451
|
|
|
if(!is_array($tmp_name)) |
|
1452
|
|
|
{ |
|
1453
|
|
|
if(!$tmp_name || !is_uploaded_file($tmp_name)) |
|
1454
|
|
|
{ |
|
1455
|
|
|
continue; |
|
1456
|
|
|
} |
|
1457
|
|
|
$val['name'] = htmlspecialchars($val['name'], ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE); |
|
1458
|
|
|
$this->set($key, $val, TRUE); |
|
|
|
|
|
|
1459
|
|
|
$this->is_uploaded = TRUE; |
|
1460
|
|
|
} |
|
1461
|
|
|
else |
|
1462
|
|
|
{ |
|
1463
|
|
|
for($i = 0, $c = count($tmp_name); $i < $c; $i++) |
|
1464
|
|
|
{ |
|
1465
|
|
|
if($val['size'][$i] > 0) |
|
1466
|
|
|
{ |
|
1467
|
|
|
$file['name'] = $val['name'][$i]; |
|
|
|
|
|
|
1468
|
|
|
$file['type'] = $val['type'][$i]; |
|
|
|
|
|
|
1469
|
|
|
$file['tmp_name'] = $val['tmp_name'][$i]; |
|
1470
|
|
|
$file['error'] = $val['error'][$i]; |
|
1471
|
|
|
$file['size'] = $val['size'][$i]; |
|
1472
|
|
|
$files[] = $file; |
|
|
|
|
|
|
1473
|
|
|
} |
|
1474
|
|
|
} |
|
1475
|
|
|
$this->set($key, $files, TRUE); |
|
|
|
|
|
|
1476
|
|
|
} |
|
1477
|
|
|
} |
|
1478
|
|
|
} |
|
1479
|
|
|
|
|
1480
|
|
|
/** |
|
1481
|
|
|
* Return request method |
|
1482
|
|
|
* @return string Request method type. (Optional - GET|POST|XMLRPC|JSON) |
|
1483
|
|
|
*/ |
|
1484
|
|
|
function getRequestMethod() |
|
1485
|
|
|
{ |
|
1486
|
|
|
$self = self::getInstance(); |
|
1487
|
|
|
return $self->request_method; |
|
1488
|
|
|
} |
|
1489
|
|
|
|
|
1490
|
|
|
/** |
|
1491
|
|
|
* Return request URL |
|
1492
|
|
|
* @return string request URL |
|
1493
|
|
|
*/ |
|
1494
|
|
|
function getRequestUrl() |
|
1495
|
|
|
{ |
|
1496
|
|
|
static $url = null; |
|
1497
|
|
|
if(is_null($url)) |
|
1498
|
|
|
{ |
|
1499
|
|
|
$url = self::getRequestUri(); |
|
1500
|
|
|
if(count($_GET) > 0) |
|
1501
|
|
|
{ |
|
1502
|
|
|
foreach($_GET as $key => $val) |
|
1503
|
|
|
{ |
|
1504
|
|
|
$vars[] = $key . '=' . ($val ? urlencode(self::convertEncodingStr($val)) : ''); |
|
|
|
|
|
|
1505
|
|
|
} |
|
1506
|
|
|
$url .= '?' . join('&', $vars); |
|
|
|
|
|
|
1507
|
|
|
} |
|
1508
|
|
|
} |
|
1509
|
|
|
return $url; |
|
1510
|
|
|
} |
|
1511
|
|
|
|
|
1512
|
|
|
/** |
|
1513
|
|
|
* Return js callback func. |
|
1514
|
|
|
* @return string callback func. |
|
1515
|
|
|
*/ |
|
1516
|
|
|
function getJSCallbackFunc() |
|
1517
|
|
|
{ |
|
1518
|
|
|
$self = self::getInstance(); |
|
|
|
|
|
|
1519
|
|
|
$js_callback_func = isset($_GET['xe_js_callback']) ? $_GET['xe_js_callback'] : $_POST['xe_js_callback']; |
|
1520
|
|
|
|
|
1521
|
|
|
if(!preg_match('/^[a-z0-9\.]+$/i', $js_callback_func)) |
|
1522
|
|
|
{ |
|
1523
|
|
|
unset($js_callback_func); |
|
1524
|
|
|
unset($_GET['xe_js_callback']); |
|
1525
|
|
|
unset($_POST['xe_js_callback']); |
|
1526
|
|
|
} |
|
1527
|
|
|
|
|
1528
|
|
|
return $js_callback_func; |
|
1529
|
|
|
} |
|
1530
|
|
|
|
|
1531
|
|
|
/** |
|
1532
|
|
|
* Make URL with args_list upon request URL |
|
1533
|
|
|
* |
|
1534
|
|
|
* @param int $num_args Arguments nums |
|
1535
|
|
|
* @param array $args_list Argument list for set url |
|
1536
|
|
|
* @param string $domain Domain |
|
1537
|
|
|
* @param bool $encode If TRUE, use url encode. |
|
1538
|
|
|
* @param bool $autoEncode If TRUE, url encode automatically, detailed. Use this option, $encode value should be TRUE |
|
1539
|
|
|
* @return string URL |
|
1540
|
|
|
*/ |
|
1541
|
|
|
function getUrl($num_args = 0, $args_list = array(), $domain = null, $encode = TRUE, $autoEncode = FALSE) |
|
|
|
|
|
|
1542
|
|
|
{ |
|
1543
|
|
|
static $site_module_info = null; |
|
1544
|
|
|
static $current_info = null; |
|
1545
|
|
|
|
|
1546
|
|
|
$self = self::getInstance(); |
|
1547
|
|
|
|
|
1548
|
|
|
// retrieve virtual site information |
|
1549
|
|
|
if(is_null($site_module_info)) |
|
1550
|
|
|
{ |
|
1551
|
|
|
$site_module_info = self::get('site_module_info'); |
|
1552
|
|
|
} |
|
1553
|
|
|
|
|
1554
|
|
|
// If $domain is set, handle it (if $domain is vid type, remove $domain and handle with $vid) |
|
1555
|
|
|
if($domain && isSiteID($domain)) |
|
|
|
|
|
|
1556
|
|
|
{ |
|
1557
|
|
|
$vid = $domain; |
|
1558
|
|
|
$domain = ''; |
|
1559
|
|
|
} |
|
1560
|
|
|
|
|
1561
|
|
|
// If $domain, $vid are not set, use current site information |
|
1562
|
|
|
if(!$domain && !$vid) |
|
|
|
|
|
|
1563
|
|
|
{ |
|
1564
|
|
|
if($site_module_info->domain && isSiteID($site_module_info->domain)) |
|
1565
|
|
|
{ |
|
1566
|
|
|
$vid = $site_module_info->domain; |
|
1567
|
|
|
} |
|
1568
|
|
|
else |
|
1569
|
|
|
{ |
|
1570
|
|
|
$domain = $site_module_info->domain; |
|
1571
|
|
|
} |
|
1572
|
|
|
} |
|
1573
|
|
|
|
|
1574
|
|
|
// if $domain is set, compare current URL. If they are same, remove the domain, otherwise link to the domain. |
|
1575
|
|
|
if($domain) |
|
1576
|
|
|
{ |
|
1577
|
|
|
$domain_info = parse_url($domain); |
|
1578
|
|
|
if(is_null($current_info)) |
|
1579
|
|
|
{ |
|
1580
|
|
|
$current_info = parse_url(($_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . getScriptPath()); |
|
1581
|
|
|
} |
|
1582
|
|
|
if($domain_info['host'] . $domain_info['path'] == $current_info['host'] . $current_info['path']) |
|
1583
|
|
|
{ |
|
1584
|
|
|
unset($domain); |
|
1585
|
|
|
} |
|
1586
|
|
|
else |
|
1587
|
|
|
{ |
|
1588
|
|
|
$domain = preg_replace('/^(http|https):\/\//i', '', trim($domain)); |
|
1589
|
|
|
if(substr_compare($domain, '/', -1) !== 0) |
|
1590
|
|
|
{ |
|
1591
|
|
|
$domain .= '/'; |
|
1592
|
|
|
} |
|
1593
|
|
|
} |
|
1594
|
|
|
} |
|
1595
|
|
|
|
|
1596
|
|
|
$get_vars = array(); |
|
1597
|
|
|
|
|
1598
|
|
|
// If there is no GET variables or first argument is '' to reset variables |
|
1599
|
|
|
if(!$self->get_vars || $args_list[0] == '') |
|
1600
|
|
|
{ |
|
1601
|
|
|
// rearrange args_list |
|
1602
|
|
|
if(is_array($args_list) && $args_list[0] == '') |
|
1603
|
|
|
{ |
|
1604
|
|
|
array_shift($args_list); |
|
1605
|
|
|
} |
|
1606
|
|
|
} |
|
1607
|
|
|
else |
|
1608
|
|
|
{ |
|
1609
|
|
|
// Otherwise, make GET variables into array |
|
1610
|
|
|
$get_vars = get_object_vars($self->get_vars); |
|
1611
|
|
|
} |
|
1612
|
|
|
|
|
1613
|
|
|
// arrange args_list |
|
1614
|
|
|
for($i = 0, $c = count($args_list); $i < $c; $i += 2) |
|
1615
|
|
|
{ |
|
1616
|
|
|
$key = $args_list[$i]; |
|
1617
|
|
|
$val = trim($args_list[$i + 1]); |
|
1618
|
|
|
|
|
1619
|
|
|
// If value is not set, remove the key |
|
1620
|
|
|
if(!isset($val) || !strlen($val)) |
|
1621
|
|
|
{ |
|
1622
|
|
|
unset($get_vars[$key]); |
|
1623
|
|
|
continue; |
|
1624
|
|
|
} |
|
1625
|
|
|
// set new variables |
|
1626
|
|
|
$get_vars[$key] = $val; |
|
1627
|
|
|
} |
|
1628
|
|
|
|
|
1629
|
|
|
// remove vid, rnd |
|
1630
|
|
|
unset($get_vars['rnd']); |
|
1631
|
|
|
if($vid) |
|
1632
|
|
|
{ |
|
1633
|
|
|
$get_vars['vid'] = $vid; |
|
1634
|
|
|
} |
|
1635
|
|
|
else |
|
1636
|
|
|
{ |
|
1637
|
|
|
unset($get_vars['vid']); |
|
1638
|
|
|
} |
|
1639
|
|
|
|
|
1640
|
|
|
// for compatibility to lower versions |
|
1641
|
|
|
$act = $get_vars['act']; |
|
1642
|
|
|
$act_alias = array( |
|
1643
|
|
|
'dispMemberFriend' => 'dispCommunicationFriend', |
|
1644
|
|
|
'dispMemberMessages' => 'dispCommunicationMessages', |
|
1645
|
|
|
'dispDocumentAdminManageDocument' => 'dispDocumentManageDocument', |
|
1646
|
|
|
'dispModuleAdminSelectList' => 'dispModuleSelectList' |
|
1647
|
|
|
); |
|
1648
|
|
|
if($act_alias[$act]) |
|
1649
|
|
|
{ |
|
1650
|
|
|
$get_vars['act'] = $act_alias[$act]; |
|
1651
|
|
|
} |
|
1652
|
|
|
|
|
1653
|
|
|
// organize URL |
|
1654
|
|
|
$query = ''; |
|
1655
|
|
|
if(count($get_vars) > 0) |
|
1656
|
|
|
{ |
|
1657
|
|
|
// if using rewrite mod |
|
1658
|
|
|
if($self->allow_rewrite) |
|
1659
|
|
|
{ |
|
1660
|
|
|
$var_keys = array_keys($get_vars); |
|
1661
|
|
|
sort($var_keys); |
|
1662
|
|
|
|
|
1663
|
|
|
$target = join('.', $var_keys); |
|
1664
|
|
|
|
|
1665
|
|
|
$act = $get_vars['act']; |
|
1666
|
|
|
$vid = $get_vars['vid']; |
|
1667
|
|
|
$mid = $get_vars['mid']; |
|
1668
|
|
|
$key = $get_vars['key']; |
|
1669
|
|
|
$srl = $get_vars['document_srl']; |
|
1670
|
|
|
|
|
1671
|
|
|
$tmpArray = array('rss' => 1, 'atom' => 1, 'api' => 1); |
|
1672
|
|
|
$is_feed = isset($tmpArray[$act]); |
|
1673
|
|
|
|
|
1674
|
|
|
$target_map = array( |
|
1675
|
|
|
'vid' => $vid, |
|
1676
|
|
|
'mid' => $mid, |
|
1677
|
|
|
'mid.vid' => "$vid/$mid", |
|
1678
|
|
|
'entry.mid' => "$mid/entry/" . $get_vars['entry'], |
|
1679
|
|
|
'entry.mid.vid' => "$vid/$mid/entry/" . $get_vars['entry'], |
|
1680
|
|
|
'document_srl' => $srl, |
|
1681
|
|
|
'document_srl.mid' => "$mid/$srl", |
|
1682
|
|
|
'document_srl.vid' => "$vid/$srl", |
|
1683
|
|
|
'document_srl.mid.vid' => "$vid/$mid/$srl", |
|
1684
|
|
|
'act' => ($is_feed && $act !== 'api') ? $act : '', |
|
1685
|
|
|
'act.mid' => $is_feed ? "$mid/$act" : '', |
|
1686
|
|
|
'act.mid.vid' => $is_feed ? "$vid/$mid/$act" : '', |
|
1687
|
|
|
'act.document_srl.key' => ($act == 'trackback') ? "$srl/$key/$act" : '', |
|
1688
|
|
|
'act.document_srl.key.mid' => ($act == 'trackback') ? "$mid/$srl/$key/$act" : '', |
|
1689
|
|
|
'act.document_srl.key.vid' => ($act == 'trackback') ? "$vid/$srl/$key/$act" : '', |
|
1690
|
|
|
'act.document_srl.key.mid.vid' => ($act == 'trackback') ? "$vid/$mid/$srl/$key/$act" : '' |
|
1691
|
|
|
); |
|
1692
|
|
|
|
|
1693
|
|
|
$query = $target_map[$target]; |
|
1694
|
|
|
} |
|
1695
|
|
|
|
|
1696
|
|
|
if(!$query) |
|
1697
|
|
|
{ |
|
1698
|
|
|
$queries = array(); |
|
1699
|
|
View Code Duplication |
foreach($get_vars as $key => $val) |
|
1700
|
|
|
{ |
|
1701
|
|
|
if(is_array($val) && count($val) > 0) |
|
1702
|
|
|
{ |
|
1703
|
|
|
foreach($val as $k => $v) |
|
1704
|
|
|
{ |
|
1705
|
|
|
$queries[] = $key . '[' . $k . ']=' . urlencode($v); |
|
1706
|
|
|
} |
|
1707
|
|
|
} |
|
1708
|
|
|
elseif(!is_array($val)) |
|
1709
|
|
|
{ |
|
1710
|
|
|
$queries[] = $key . '=' . urlencode($val); |
|
1711
|
|
|
} |
|
1712
|
|
|
} |
|
1713
|
|
|
if(count($queries) > 0) |
|
1714
|
|
|
{ |
|
1715
|
|
|
$query = 'index.php?' . join('&', $queries); |
|
1716
|
|
|
} |
|
1717
|
|
|
} |
|
1718
|
|
|
} |
|
1719
|
|
|
|
|
1720
|
|
|
// If using SSL always |
|
1721
|
|
|
$_use_ssl = $self->get('_use_ssl'); |
|
1722
|
|
|
if($_use_ssl == 'always') |
|
1723
|
|
|
{ |
|
1724
|
|
|
$query = $self->getRequestUri(ENFORCE_SSL, $domain) . $query; |
|
1725
|
|
|
// optional SSL use |
|
1726
|
|
|
} |
|
1727
|
|
|
elseif($_use_ssl == 'optional') |
|
1728
|
|
|
{ |
|
1729
|
|
|
$ssl_mode = (($self->get('module') === 'admin') || ($get_vars['module'] === 'admin') || (isset($get_vars['act']) && $self->isExistsSSLAction($get_vars['act']))) ? ENFORCE_SSL : RELEASE_SSL; |
|
1730
|
|
|
$query = $self->getRequestUri($ssl_mode, $domain) . $query; |
|
1731
|
|
|
// no SSL |
|
1732
|
|
|
} |
|
1733
|
|
|
else |
|
1734
|
|
|
{ |
|
1735
|
|
|
// currently on SSL but target is not based on SSL |
|
1736
|
|
|
if($_SERVER['HTTPS'] == 'on') |
|
1737
|
|
|
{ |
|
1738
|
|
|
$query = $self->getRequestUri(ENFORCE_SSL, $domain) . $query; |
|
1739
|
|
|
} |
|
1740
|
|
|
else if($domain) // if $domain is set |
|
1741
|
|
|
{ |
|
1742
|
|
|
$query = $self->getRequestUri(FOLLOW_REQUEST_SSL, $domain) . $query; |
|
1743
|
|
|
} |
|
1744
|
|
|
else |
|
1745
|
|
|
{ |
|
1746
|
|
|
$query = getScriptPath() . $query; |
|
1747
|
|
|
} |
|
1748
|
|
|
} |
|
1749
|
|
|
|
|
1750
|
|
|
if(!$encode) |
|
1751
|
|
|
{ |
|
1752
|
|
|
return $query; |
|
1753
|
|
|
} |
|
1754
|
|
|
|
|
1755
|
|
|
if(!$autoEncode) |
|
1756
|
|
|
{ |
|
1757
|
|
|
return htmlspecialchars($query, ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE); |
|
1758
|
|
|
} |
|
1759
|
|
|
|
|
1760
|
|
|
$output = array(); |
|
1761
|
|
|
$encode_queries = array(); |
|
1762
|
|
|
$parsedUrl = parse_url($query); |
|
1763
|
|
|
parse_str($parsedUrl['query'], $output); |
|
1764
|
|
|
foreach($output as $key => $value) |
|
|
|
|
|
|
1765
|
|
|
{ |
|
1766
|
|
|
if(preg_match('/&([a-z]{2,}|#\d+);/', urldecode($value))) |
|
1767
|
|
|
{ |
|
1768
|
|
|
$value = urlencode(htmlspecialchars_decode(urldecode($value))); |
|
1769
|
|
|
} |
|
1770
|
|
|
$encode_queries[] = $key . '=' . $value; |
|
1771
|
|
|
} |
|
1772
|
|
|
|
|
1773
|
|
|
return htmlspecialchars($parsedUrl['path'] . '?' . join('&', $encode_queries), ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE); |
|
1774
|
|
|
} |
|
1775
|
|
|
|
|
1776
|
|
|
/** |
|
1777
|
|
|
* Return after removing an argument on the requested URL |
|
1778
|
|
|
* |
|
1779
|
|
|
* @param string $ssl_mode SSL mode |
|
1780
|
|
|
* @param string $domain Domain |
|
1781
|
|
|
* @retrun string converted URL |
|
1782
|
|
|
*/ |
|
1783
|
|
|
function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null) |
|
1784
|
|
|
{ |
|
1785
|
|
|
static $url = array(); |
|
1786
|
|
|
|
|
1787
|
|
|
// Check HTTP Request |
|
1788
|
|
|
if(!isset($_SERVER['SERVER_PROTOCOL'])) |
|
1789
|
|
|
{ |
|
1790
|
|
|
return; |
|
1791
|
|
|
} |
|
1792
|
|
|
|
|
1793
|
|
|
if(self::get('_use_ssl') == 'always') |
|
1794
|
|
|
{ |
|
1795
|
|
|
$ssl_mode = ENFORCE_SSL; |
|
1796
|
|
|
} |
|
1797
|
|
|
|
|
1798
|
|
|
if($domain) |
|
|
|
|
|
|
1799
|
|
|
{ |
|
1800
|
|
|
$domain_key = md5($domain); |
|
1801
|
|
|
} |
|
1802
|
|
|
else |
|
1803
|
|
|
{ |
|
1804
|
|
|
$domain_key = 'default'; |
|
1805
|
|
|
} |
|
1806
|
|
|
|
|
1807
|
|
|
if(isset($url[$ssl_mode][$domain_key])) |
|
1808
|
|
|
{ |
|
1809
|
|
|
return $url[$ssl_mode][$domain_key]; |
|
1810
|
|
|
} |
|
1811
|
|
|
|
|
1812
|
|
|
$current_use_ssl = ($_SERVER['HTTPS'] == 'on'); |
|
1813
|
|
|
|
|
1814
|
|
|
switch($ssl_mode) |
|
1815
|
|
|
{ |
|
1816
|
|
|
case FOLLOW_REQUEST_SSL: $use_ssl = $current_use_ssl; |
|
1817
|
|
|
break; |
|
1818
|
|
|
case ENFORCE_SSL: $use_ssl = TRUE; |
|
1819
|
|
|
break; |
|
1820
|
|
|
case RELEASE_SSL: $use_ssl = FALSE; |
|
1821
|
|
|
break; |
|
1822
|
|
|
} |
|
1823
|
|
|
|
|
1824
|
|
|
if($domain) |
|
|
|
|
|
|
1825
|
|
|
{ |
|
1826
|
|
|
$target_url = trim($domain); |
|
1827
|
|
|
if(substr_compare($target_url, '/', -1) !== 0) |
|
1828
|
|
|
{ |
|
1829
|
|
|
$target_url.= '/'; |
|
1830
|
|
|
} |
|
1831
|
|
|
} |
|
1832
|
|
|
else |
|
1833
|
|
|
{ |
|
1834
|
|
|
$target_url = $_SERVER['HTTP_HOST'] . getScriptPath(); |
|
1835
|
|
|
} |
|
1836
|
|
|
|
|
1837
|
|
|
$url_info = parse_url('http://' . $target_url); |
|
1838
|
|
|
|
|
1839
|
|
|
if($current_use_ssl != $use_ssl) |
|
|
|
|
|
|
1840
|
|
|
{ |
|
1841
|
|
|
unset($url_info['port']); |
|
1842
|
|
|
} |
|
1843
|
|
|
|
|
1844
|
|
|
if($use_ssl) |
|
1845
|
|
|
{ |
|
1846
|
|
|
$port = self::get('_https_port'); |
|
1847
|
|
View Code Duplication |
if($port && $port != 443) |
|
1848
|
|
|
{ |
|
1849
|
|
|
$url_info['port'] = $port; |
|
1850
|
|
|
} |
|
1851
|
|
|
elseif($url_info['port'] == 443) |
|
1852
|
|
|
{ |
|
1853
|
|
|
unset($url_info['port']); |
|
1854
|
|
|
} |
|
1855
|
|
|
} |
|
1856
|
|
View Code Duplication |
else |
|
1857
|
|
|
{ |
|
1858
|
|
|
$port = self::get('_http_port'); |
|
1859
|
|
|
if($port && $port != 80) |
|
1860
|
|
|
{ |
|
1861
|
|
|
$url_info['port'] = $port; |
|
1862
|
|
|
} |
|
1863
|
|
|
elseif($url_info['port'] == 80) |
|
1864
|
|
|
{ |
|
1865
|
|
|
unset($url_info['port']); |
|
1866
|
|
|
} |
|
1867
|
|
|
} |
|
1868
|
|
|
|
|
1869
|
|
|
$url[$ssl_mode][$domain_key] = sprintf('%s://%s%s%s', $use_ssl ? 'https' : $url_info['scheme'], $url_info['host'], $url_info['port'] && $url_info['port'] != 80 ? ':' . $url_info['port'] : '', $url_info['path']); |
|
1870
|
|
|
|
|
1871
|
|
|
return $url[$ssl_mode][$domain_key]; |
|
1872
|
|
|
} |
|
1873
|
|
|
|
|
1874
|
|
|
/** |
|
1875
|
|
|
* Set a context value with a key |
|
1876
|
|
|
* |
|
1877
|
|
|
* @param string $key Key |
|
1878
|
|
|
* @param string $val Value |
|
1879
|
|
|
* @param mixed $set_to_get_vars If not FALSE, Set to get vars. |
|
1880
|
|
|
* @return void |
|
1881
|
|
|
*/ |
|
1882
|
|
|
function set($key, $val, $set_to_get_vars = 0) |
|
1883
|
|
|
{ |
|
1884
|
|
|
$self = self::getInstance(); |
|
1885
|
|
|
$self->context->{$key} = $val; |
|
1886
|
|
|
if($set_to_get_vars === FALSE) |
|
1887
|
|
|
{ |
|
1888
|
|
|
return; |
|
1889
|
|
|
} |
|
1890
|
|
|
if($val === NULL || $val === '') |
|
1891
|
|
|
{ |
|
1892
|
|
|
unset($self->get_vars->{$key}); |
|
1893
|
|
|
return; |
|
1894
|
|
|
} |
|
1895
|
|
|
if($set_to_get_vars || $self->get_vars->{$key}) |
|
1896
|
|
|
{ |
|
1897
|
|
|
$self->get_vars->{$key} = $val; |
|
1898
|
|
|
} |
|
1899
|
|
|
} |
|
1900
|
|
|
|
|
1901
|
|
|
/** |
|
1902
|
|
|
* Return key's value |
|
1903
|
|
|
* |
|
1904
|
|
|
* @param string $key Key |
|
1905
|
|
|
* @return string Key |
|
1906
|
|
|
*/ |
|
1907
|
|
|
function get($key) |
|
1908
|
|
|
{ |
|
1909
|
|
|
$self = self::getInstance(); |
|
1910
|
|
|
|
|
1911
|
|
|
if(!isset($self->context->{$key})) |
|
1912
|
|
|
{ |
|
1913
|
|
|
return null; |
|
1914
|
|
|
} |
|
1915
|
|
|
return $self->context->{$key}; |
|
1916
|
|
|
} |
|
1917
|
|
|
|
|
1918
|
|
|
/** |
|
1919
|
|
|
* Get one more vars in object vars with given arguments(key1, key2, key3,...) |
|
1920
|
|
|
* |
|
1921
|
|
|
* @return object |
|
1922
|
|
|
*/ |
|
1923
|
|
|
function gets() |
|
1924
|
|
|
{ |
|
1925
|
|
|
$num_args = func_num_args(); |
|
1926
|
|
|
if($num_args < 1) |
|
1927
|
|
|
{ |
|
1928
|
|
|
return; |
|
1929
|
|
|
} |
|
1930
|
|
|
$self = self::getInstance(); |
|
1931
|
|
|
|
|
1932
|
|
|
$args_list = func_get_args(); |
|
1933
|
|
|
$output = new stdClass(); |
|
1934
|
|
|
foreach($args_list as $v) |
|
1935
|
|
|
{ |
|
1936
|
|
|
$output->{$v} = $self->get($v); |
|
1937
|
|
|
} |
|
1938
|
|
|
return $output; |
|
1939
|
|
|
} |
|
1940
|
|
|
|
|
1941
|
|
|
/** |
|
1942
|
|
|
* Return all data |
|
1943
|
|
|
* |
|
1944
|
|
|
* @return object All data |
|
1945
|
|
|
*/ |
|
1946
|
|
|
function getAll() |
|
1947
|
|
|
{ |
|
1948
|
|
|
$self = self::getInstance(); |
|
1949
|
|
|
return $self->context; |
|
1950
|
|
|
} |
|
1951
|
|
|
|
|
1952
|
|
|
/** |
|
1953
|
|
|
* Return values from the GET/POST/XMLRPC |
|
1954
|
|
|
* |
|
1955
|
|
|
* @return Object Request variables. |
|
1956
|
|
|
*/ |
|
1957
|
|
|
function getRequestVars() |
|
1958
|
|
|
{ |
|
1959
|
|
|
$self = self::getInstance(); |
|
1960
|
|
|
if($self->get_vars) |
|
1961
|
|
|
{ |
|
1962
|
|
|
return clone($self->get_vars); |
|
1963
|
|
|
} |
|
1964
|
|
|
return new stdClass; |
|
1965
|
|
|
} |
|
1966
|
|
|
|
|
1967
|
|
|
/** |
|
1968
|
|
|
* Register if an action is to be encrypted by SSL. Those actions are sent to https in common/js/xml_handler.js |
|
1969
|
|
|
* |
|
1970
|
|
|
* @param string $action act name |
|
1971
|
|
|
* @return void |
|
1972
|
|
|
*/ |
|
1973
|
|
|
function addSSLAction($action) |
|
1974
|
|
|
{ |
|
1975
|
|
|
$self = self::getInstance(); |
|
1976
|
|
|
|
|
1977
|
|
|
if(!is_readable($self->sslActionCacheFile)) |
|
1978
|
|
|
{ |
|
1979
|
|
|
$buff = '<?php if(!defined("__XE__"))exit;'; |
|
1980
|
|
|
FileHandler::writeFile($self->sslActionCacheFile, $buff); |
|
|
|
|
|
|
1981
|
|
|
} |
|
1982
|
|
|
|
|
1983
|
|
View Code Duplication |
if(!isset($self->ssl_actions[$action])) |
|
1984
|
|
|
{ |
|
1985
|
|
|
$self->ssl_actions[$action] = 1; |
|
1986
|
|
|
$sslActionCacheString = sprintf('$sslActions[\'%s\'] = 1;', $action); |
|
1987
|
|
|
FileHandler::writeFile($self->sslActionCacheFile, $sslActionCacheString, 'a'); |
|
|
|
|
|
|
1988
|
|
|
} |
|
1989
|
|
|
} |
|
1990
|
|
|
|
|
1991
|
|
|
/** |
|
1992
|
|
|
* Register if actions are to be encrypted by SSL. Those actions are sent to https in common/js/xml_handler.js |
|
1993
|
|
|
* |
|
1994
|
|
|
* @param string $action act name |
|
|
|
|
|
|
1995
|
|
|
* @return void |
|
1996
|
|
|
*/ |
|
1997
|
|
|
function addSSLActions($action_array) |
|
1998
|
|
|
{ |
|
1999
|
|
|
$self = self::getInstance(); |
|
2000
|
|
|
|
|
2001
|
|
|
if(!is_readable($self->sslActionCacheFile)) |
|
2002
|
|
|
{ |
|
2003
|
|
|
unset($self->ssl_actions); |
|
2004
|
|
|
$buff = '<?php if(!defined("__XE__"))exit;'; |
|
2005
|
|
|
FileHandler::writeFile($self->sslActionCacheFile, $buff); |
|
|
|
|
|
|
2006
|
|
|
} |
|
2007
|
|
|
|
|
2008
|
|
|
foreach($action_array as $action) |
|
2009
|
|
|
{ |
|
2010
|
|
View Code Duplication |
if(!isset($self->ssl_actions[$action])) |
|
2011
|
|
|
{ |
|
2012
|
|
|
$self->ssl_actions[$action] = 1; |
|
2013
|
|
|
$sslActionCacheString = sprintf('$sslActions[\'%s\'] = 1;', $action); |
|
2014
|
|
|
FileHandler::writeFile($self->sslActionCacheFile, $sslActionCacheString, 'a'); |
|
|
|
|
|
|
2015
|
|
|
} |
|
2016
|
|
|
} |
|
2017
|
|
|
} |
|
2018
|
|
|
|
|
2019
|
|
|
/** |
|
2020
|
|
|
* Delete if action is registerd to be encrypted by SSL. |
|
2021
|
|
|
* |
|
2022
|
|
|
* @param string $action act name |
|
2023
|
|
|
* @return void |
|
2024
|
|
|
*/ |
|
2025
|
|
|
function subtractSSLAction($action) |
|
2026
|
|
|
{ |
|
2027
|
|
|
$self = self::getInstance(); |
|
2028
|
|
|
|
|
2029
|
|
|
if($self->isExistsSSLAction($action)) |
|
2030
|
|
|
{ |
|
2031
|
|
|
$sslActionCacheString = sprintf('$sslActions[\'%s\'] = 1;', $action); |
|
2032
|
|
|
$buff = FileHandler::readFile($self->sslActionCacheFile); |
|
|
|
|
|
|
2033
|
|
|
$buff = str_replace($sslActionCacheString, '', $buff); |
|
2034
|
|
|
FileHandler::writeFile($self->sslActionCacheFile, $buff); |
|
|
|
|
|
|
2035
|
|
|
} |
|
2036
|
|
|
} |
|
2037
|
|
|
|
|
2038
|
|
|
/** |
|
2039
|
|
|
* Get SSL Action |
|
2040
|
|
|
* |
|
2041
|
|
|
* @return string acts in array |
|
2042
|
|
|
*/ |
|
2043
|
|
|
function getSSLActions() |
|
2044
|
|
|
{ |
|
2045
|
|
|
$self = self::getInstance(); |
|
2046
|
|
|
if($self->getSslStatus() == 'optional') |
|
2047
|
|
|
{ |
|
2048
|
|
|
return $self->ssl_actions; |
|
2049
|
|
|
} |
|
2050
|
|
|
} |
|
2051
|
|
|
|
|
2052
|
|
|
/** |
|
2053
|
|
|
* Check SSL action are existed |
|
2054
|
|
|
* |
|
2055
|
|
|
* @param string $action act name |
|
2056
|
|
|
* @return bool If SSL exists, return TRUE. |
|
2057
|
|
|
*/ |
|
2058
|
|
|
function isExistsSSLAction($action) |
|
2059
|
|
|
{ |
|
2060
|
|
|
$self = self::getInstance(); |
|
2061
|
|
|
return isset($self->ssl_actions[$action]); |
|
2062
|
|
|
} |
|
2063
|
|
|
|
|
2064
|
|
|
/** |
|
2065
|
|
|
* Normalize file path |
|
2066
|
|
|
* |
|
2067
|
|
|
* @deprecated |
|
2068
|
|
|
* @param string $file file path |
|
2069
|
|
|
* @return string normalized file path |
|
2070
|
|
|
*/ |
|
2071
|
|
|
function normalizeFilePath($file) |
|
2072
|
|
|
{ |
|
2073
|
|
|
if($file{0} != '/' && $file{0} != '.' && strpos($file, '://') === FALSE) |
|
2074
|
|
|
{ |
|
2075
|
|
|
$file = './' . $file; |
|
2076
|
|
|
} |
|
2077
|
|
|
$file = preg_replace('@/\./|(?<!:)\/\/@', '/', $file); |
|
2078
|
|
|
while(strpos($file, '/../') !== FALSE) |
|
2079
|
|
|
{ |
|
2080
|
|
|
$file = preg_replace('/\/([^\/]+)\/\.\.\//s', '/', $file, 1); |
|
2081
|
|
|
} |
|
2082
|
|
|
|
|
2083
|
|
|
return $file; |
|
2084
|
|
|
} |
|
2085
|
|
|
|
|
2086
|
|
|
/** |
|
2087
|
|
|
* Get abstract file url |
|
2088
|
|
|
* |
|
2089
|
|
|
* @deprecated |
|
2090
|
|
|
* @param string $file file path |
|
2091
|
|
|
* @return string Converted file path |
|
2092
|
|
|
*/ |
|
2093
|
|
|
function getAbsFileUrl($file) |
|
2094
|
|
|
{ |
|
2095
|
|
|
$file = self::normalizeFilePath($file); |
|
|
|
|
|
|
2096
|
|
|
$script_path = getScriptPath(); |
|
2097
|
|
|
if(strpos($file, './') === 0) |
|
2098
|
|
|
{ |
|
2099
|
|
|
$file = $script_path . substr($file, 2); |
|
2100
|
|
|
} |
|
2101
|
|
|
elseif(strpos($file, '../') === 0) |
|
2102
|
|
|
{ |
|
2103
|
|
|
$file = self::normalizeFilePath($script_path . $file); |
|
|
|
|
|
|
2104
|
|
|
} |
|
2105
|
|
|
|
|
2106
|
|
|
return $file; |
|
2107
|
|
|
} |
|
2108
|
|
|
|
|
2109
|
|
|
/** |
|
2110
|
|
|
* Load front end file |
|
2111
|
|
|
* |
|
2112
|
|
|
* @param array $args array |
|
2113
|
|
|
* case js : |
|
2114
|
|
|
* $args[0]: file name, |
|
2115
|
|
|
* $args[1]: type (head | body), |
|
2116
|
|
|
* $args[2]: target IE, |
|
2117
|
|
|
* $args[3]: index |
|
2118
|
|
|
* case css : |
|
2119
|
|
|
* $args[0]: file name, |
|
2120
|
|
|
* $args[1]: media, |
|
2121
|
|
|
* $args[2]: target IE, |
|
2122
|
|
|
* $args[3]: index |
|
2123
|
|
|
* |
|
2124
|
|
|
*/ |
|
2125
|
|
|
function loadFile($args) |
|
2126
|
|
|
{ |
|
2127
|
|
|
$self = self::getInstance(); |
|
2128
|
|
|
|
|
2129
|
|
|
$self->oFrontEndFileHandler->loadFile($args); |
|
2130
|
|
|
} |
|
2131
|
|
|
|
|
2132
|
|
|
/** |
|
2133
|
|
|
* Unload front end file |
|
2134
|
|
|
* |
|
2135
|
|
|
* @param string $file File name with path |
|
2136
|
|
|
* @param string $targetIe Target IE |
|
2137
|
|
|
* @param string $media Media query |
|
2138
|
|
|
* @return void |
|
2139
|
|
|
*/ |
|
2140
|
|
|
function unloadFile($file, $targetIe = '', $media = 'all') |
|
2141
|
|
|
{ |
|
2142
|
|
|
$self = self::getInstance(); |
|
2143
|
|
|
$self->oFrontEndFileHandler->unloadFile($file, $targetIe, $media); |
|
2144
|
|
|
} |
|
2145
|
|
|
|
|
2146
|
|
|
/** |
|
2147
|
|
|
* Unload front end file all |
|
2148
|
|
|
* |
|
2149
|
|
|
* @param string $type Unload target (optional - all|css|js) |
|
2150
|
|
|
* @return void |
|
2151
|
|
|
*/ |
|
2152
|
|
|
function unloadAllFiles($type = 'all') |
|
2153
|
|
|
{ |
|
2154
|
|
|
$self = self::getInstance(); |
|
2155
|
|
|
$self->oFrontEndFileHandler->unloadAllFiles($type); |
|
2156
|
|
|
} |
|
2157
|
|
|
|
|
2158
|
|
|
/** |
|
2159
|
|
|
* Add the js file |
|
2160
|
|
|
* |
|
2161
|
|
|
* @deprecated |
|
2162
|
|
|
* @param string $file File name with path |
|
2163
|
|
|
* @param string $optimized optimized (That seems to not use) |
|
2164
|
|
|
* @param string $targetie target IE |
|
2165
|
|
|
* @param string $index index |
|
2166
|
|
|
* @param string $type Added position. (head:<head>..</head>, body:<body>..</body>) |
|
2167
|
|
|
* @param bool $isRuleset Use ruleset |
|
2168
|
|
|
* @param string $autoPath If path not readed, set the path automatically. |
|
2169
|
|
|
* @return void |
|
2170
|
|
|
*/ |
|
2171
|
|
|
function addJsFile($file, $optimized = FALSE, $targetie = '', $index = 0, $type = 'head', $isRuleset = FALSE, $autoPath = null) |
|
|
|
|
|
|
2172
|
|
|
{ |
|
2173
|
|
|
if($isRuleset) |
|
2174
|
|
|
{ |
|
2175
|
|
|
if(strpos($file, '#') !== FALSE) |
|
2176
|
|
|
{ |
|
2177
|
|
|
$file = str_replace('#', '', $file); |
|
2178
|
|
|
if(!is_readable($file)) |
|
2179
|
|
|
{ |
|
2180
|
|
|
$file = $autoPath; |
|
2181
|
|
|
} |
|
2182
|
|
|
} |
|
2183
|
|
|
$validator = new Validator($file); |
|
2184
|
|
|
$validator->setCacheDir('files/cache'); |
|
2185
|
|
|
$file = $validator->getJsPath(); |
|
2186
|
|
|
} |
|
2187
|
|
|
|
|
2188
|
|
|
$self = self::getInstance(); |
|
2189
|
|
|
$self->oFrontEndFileHandler->loadFile(array($file, $type, $targetie, $index)); |
|
2190
|
|
|
} |
|
2191
|
|
|
|
|
2192
|
|
|
/** |
|
2193
|
|
|
* Remove the js file |
|
2194
|
|
|
* |
|
2195
|
|
|
* @deprecated |
|
2196
|
|
|
* @param string $file File name with path |
|
2197
|
|
|
* @param string $optimized optimized (That seems to not use) |
|
2198
|
|
|
* @param string $targetie target IE |
|
2199
|
|
|
* @return void |
|
2200
|
|
|
*/ |
|
2201
|
|
|
function unloadJsFile($file, $optimized = FALSE, $targetie = '') |
|
|
|
|
|
|
2202
|
|
|
{ |
|
2203
|
|
|
$self = self::getInstance(); |
|
2204
|
|
|
$self->oFrontEndFileHandler->unloadFile($file, $targetie); |
|
2205
|
|
|
} |
|
2206
|
|
|
|
|
2207
|
|
|
/** |
|
2208
|
|
|
* Unload all javascript files |
|
2209
|
|
|
* |
|
2210
|
|
|
* @return void |
|
2211
|
|
|
*/ |
|
2212
|
|
|
function unloadAllJsFiles() |
|
2213
|
|
|
{ |
|
2214
|
|
|
$self = self::getInstance(); |
|
2215
|
|
|
$self->oFrontEndFileHandler->unloadAllFiles('js'); |
|
2216
|
|
|
} |
|
2217
|
|
|
|
|
2218
|
|
|
/** |
|
2219
|
|
|
* Add javascript filter |
|
2220
|
|
|
* |
|
2221
|
|
|
* @param string $path File path |
|
2222
|
|
|
* @param string $filename File name |
|
2223
|
|
|
* @return void |
|
2224
|
|
|
*/ |
|
2225
|
|
|
function addJsFilter($path, $filename) |
|
2226
|
|
|
{ |
|
2227
|
|
|
$oXmlFilter = new XmlJSFilter($path, $filename); |
|
2228
|
|
|
$oXmlFilter->compile(); |
|
2229
|
|
|
} |
|
2230
|
|
|
|
|
2231
|
|
|
/** |
|
2232
|
|
|
* Same as array_unique but works only for file subscript |
|
2233
|
|
|
* |
|
2234
|
|
|
* @deprecated |
|
2235
|
|
|
* @param array $files File list |
|
2236
|
|
|
* @return array File list |
|
2237
|
|
|
*/ |
|
2238
|
|
|
function _getUniqueFileList($files) |
|
2239
|
|
|
{ |
|
2240
|
|
|
ksort($files); |
|
2241
|
|
|
$files = array_values($files); |
|
2242
|
|
|
$filenames = array(); |
|
2243
|
|
|
for($i = 0, $c = count($files); $i < $c; ++$i) |
|
2244
|
|
|
{ |
|
2245
|
|
|
if(in_array($files[$i]['file'], $filenames)) |
|
2246
|
|
|
{ |
|
2247
|
|
|
unset($files[$i]); |
|
2248
|
|
|
} |
|
2249
|
|
|
$filenames[] = $files[$i]['file']; |
|
2250
|
|
|
} |
|
2251
|
|
|
|
|
2252
|
|
|
return $files; |
|
2253
|
|
|
} |
|
2254
|
|
|
|
|
2255
|
|
|
/** |
|
2256
|
|
|
* Returns the list of javascripts that matches the given type. |
|
2257
|
|
|
* |
|
2258
|
|
|
* @param string $type Added position. (head:<head>..</head>, body:<body>..</body>) |
|
2259
|
|
|
* @return array Returns javascript file list. Array contains file, targetie. |
|
2260
|
|
|
*/ |
|
2261
|
|
|
function getJsFile($type = 'head') |
|
2262
|
|
|
{ |
|
2263
|
|
|
$self = self::getInstance(); |
|
2264
|
|
|
return $self->oFrontEndFileHandler->getJsFileList($type); |
|
2265
|
|
|
} |
|
2266
|
|
|
|
|
2267
|
|
|
/** |
|
2268
|
|
|
* Add CSS file |
|
2269
|
|
|
* |
|
2270
|
|
|
* @deprecated |
|
2271
|
|
|
* @param string $file File name with path |
|
2272
|
|
|
* @param string $optimized optimized (That seems to not use) |
|
2273
|
|
|
* @param string $media Media query |
|
2274
|
|
|
* @param string $targetie target IE |
|
2275
|
|
|
* @param string $index index |
|
2276
|
|
|
* @return void |
|
2277
|
|
|
* |
|
2278
|
|
|
*/ |
|
2279
|
|
|
function addCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '', $index = 0) |
|
|
|
|
|
|
2280
|
|
|
{ |
|
2281
|
|
|
$self = self::getInstance(); |
|
2282
|
|
|
$self->oFrontEndFileHandler->loadFile(array($file, $media, $targetie, $index)); |
|
2283
|
|
|
} |
|
2284
|
|
|
|
|
2285
|
|
|
/** |
|
2286
|
|
|
* Remove css file |
|
2287
|
|
|
* |
|
2288
|
|
|
* @deprecated |
|
2289
|
|
|
* @param string $file File name with path |
|
2290
|
|
|
* @param string $optimized optimized (That seems to not use) |
|
2291
|
|
|
* @param string $media Media query |
|
2292
|
|
|
* @param string $targetie target IE |
|
2293
|
|
|
* @return void |
|
2294
|
|
|
*/ |
|
2295
|
|
|
function unloadCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '') |
|
|
|
|
|
|
2296
|
|
|
{ |
|
2297
|
|
|
$self = self::getInstance(); |
|
2298
|
|
|
$self->oFrontEndFileHandler->unloadFile($file, $targetie, $media); |
|
2299
|
|
|
} |
|
2300
|
|
|
|
|
2301
|
|
|
/** |
|
2302
|
|
|
* Unload all css files |
|
2303
|
|
|
* |
|
2304
|
|
|
* @return void |
|
2305
|
|
|
*/ |
|
2306
|
|
|
function unloadAllCSSFiles() |
|
2307
|
|
|
{ |
|
2308
|
|
|
$self = self::getInstance(); |
|
2309
|
|
|
$self->oFrontEndFileHandler->unloadAllFiles('css'); |
|
2310
|
|
|
} |
|
2311
|
|
|
|
|
2312
|
|
|
/** |
|
2313
|
|
|
* Return a list of css files |
|
2314
|
|
|
* |
|
2315
|
|
|
* @return array Returns css file list. Array contains file, media, targetie. |
|
2316
|
|
|
*/ |
|
2317
|
|
|
function getCSSFile() |
|
2318
|
|
|
{ |
|
2319
|
|
|
$self = self::getInstance(); |
|
2320
|
|
|
return $self->oFrontEndFileHandler->getCssFileList(); |
|
2321
|
|
|
} |
|
2322
|
|
|
|
|
2323
|
|
|
/** |
|
2324
|
|
|
* Returns javascript plugin file info |
|
2325
|
|
|
* @param string $pluginName |
|
2326
|
|
|
* @return stdClass |
|
2327
|
|
|
*/ |
|
2328
|
|
|
function getJavascriptPluginInfo($pluginName) |
|
2329
|
|
|
{ |
|
2330
|
|
|
if($plugin_name == 'ui.datepicker') |
|
|
|
|
|
|
2331
|
|
|
{ |
|
2332
|
|
|
$plugin_name = 'ui'; |
|
|
|
|
|
|
2333
|
|
|
} |
|
2334
|
|
|
|
|
2335
|
|
|
$plugin_path = './common/js/plugins/' . $pluginName . '/'; |
|
2336
|
|
|
$info_file = $plugin_path . 'plugin.load'; |
|
2337
|
|
|
if(!is_readable($info_file)) |
|
2338
|
|
|
{ |
|
2339
|
|
|
return; |
|
2340
|
|
|
} |
|
2341
|
|
|
|
|
2342
|
|
|
$list = file($info_file); |
|
2343
|
|
|
$result = new stdClass(); |
|
2344
|
|
|
$result->jsList = array(); |
|
2345
|
|
|
$result->cssList = array(); |
|
2346
|
|
|
|
|
2347
|
|
|
foreach($list as $filename) |
|
2348
|
|
|
{ |
|
2349
|
|
|
$filename = trim($filename); |
|
2350
|
|
|
if(!$filename) |
|
2351
|
|
|
{ |
|
2352
|
|
|
continue; |
|
2353
|
|
|
} |
|
2354
|
|
|
|
|
2355
|
|
|
if(strncasecmp('./', $filename, 2) === 0) |
|
2356
|
|
|
{ |
|
2357
|
|
|
$filename = substr($filename, 2); |
|
2358
|
|
|
} |
|
2359
|
|
|
|
|
2360
|
|
|
if(substr_compare($filename, '.js', -3) === 0) |
|
2361
|
|
|
{ |
|
2362
|
|
|
$result->jsList[] = $plugin_path . $filename; |
|
2363
|
|
|
} |
|
2364
|
|
|
elseif(substr_compare($filename, '.css', -4) === 0) |
|
2365
|
|
|
{ |
|
2366
|
|
|
$result->cssList[] = $plugin_path . $filename; |
|
2367
|
|
|
} |
|
2368
|
|
|
} |
|
2369
|
|
|
|
|
2370
|
|
|
if(is_dir($plugin_path . 'lang')) |
|
2371
|
|
|
{ |
|
2372
|
|
|
$result->langPath = $plugin_path . 'lang'; |
|
2373
|
|
|
} |
|
2374
|
|
|
|
|
2375
|
|
|
return $result; |
|
2376
|
|
|
} |
|
2377
|
|
|
/** |
|
2378
|
|
|
* Load javascript plugin |
|
2379
|
|
|
* |
|
2380
|
|
|
* @param string $plugin_name plugin name |
|
2381
|
|
|
* @return void |
|
2382
|
|
|
*/ |
|
2383
|
|
|
function loadJavascriptPlugin($plugin_name) |
|
2384
|
|
|
{ |
|
2385
|
|
|
static $loaded_plugins = array(); |
|
2386
|
|
|
|
|
2387
|
|
|
$self = self::getInstance(); |
|
2388
|
|
|
if($plugin_name == 'ui.datepicker') |
|
2389
|
|
|
{ |
|
2390
|
|
|
$plugin_name = 'ui'; |
|
2391
|
|
|
} |
|
2392
|
|
|
|
|
2393
|
|
|
if($loaded_plugins[$plugin_name]) |
|
2394
|
|
|
{ |
|
2395
|
|
|
return; |
|
2396
|
|
|
} |
|
2397
|
|
|
$loaded_plugins[$plugin_name] = TRUE; |
|
2398
|
|
|
|
|
2399
|
|
|
$plugin_path = './common/js/plugins/' . $plugin_name . '/'; |
|
2400
|
|
|
$info_file = $plugin_path . 'plugin.load'; |
|
2401
|
|
|
if(!is_readable($info_file)) |
|
2402
|
|
|
{ |
|
2403
|
|
|
return; |
|
2404
|
|
|
} |
|
2405
|
|
|
|
|
2406
|
|
|
$list = file($info_file); |
|
2407
|
|
|
foreach($list as $filename) |
|
2408
|
|
|
{ |
|
2409
|
|
|
$filename = trim($filename); |
|
2410
|
|
|
if(!$filename) |
|
2411
|
|
|
{ |
|
2412
|
|
|
continue; |
|
2413
|
|
|
} |
|
2414
|
|
|
|
|
2415
|
|
|
if(strncasecmp('./', $filename, 2) === 0) |
|
2416
|
|
|
{ |
|
2417
|
|
|
$filename = substr($filename, 2); |
|
2418
|
|
|
} |
|
2419
|
|
View Code Duplication |
if(substr_compare($filename, '.js', -3) === 0) |
|
2420
|
|
|
{ |
|
2421
|
|
|
$self->loadFile(array($plugin_path . $filename, 'body', '', 0), TRUE); |
|
|
|
|
|
|
2422
|
|
|
} |
|
2423
|
|
View Code Duplication |
if(substr_compare($filename, '.css', -4) === 0) |
|
2424
|
|
|
{ |
|
2425
|
|
|
$self->loadFile(array($plugin_path . $filename, 'all', '', 0), TRUE); |
|
|
|
|
|
|
2426
|
|
|
} |
|
2427
|
|
|
} |
|
2428
|
|
|
|
|
2429
|
|
|
if(is_dir($plugin_path . 'lang')) |
|
2430
|
|
|
{ |
|
2431
|
|
|
$self->loadLang($plugin_path . 'lang'); |
|
2432
|
|
|
} |
|
2433
|
|
|
} |
|
2434
|
|
|
|
|
2435
|
|
|
/** |
|
2436
|
|
|
* Add html code before </head> |
|
2437
|
|
|
* |
|
2438
|
|
|
* @param string $header add html code before </head>. |
|
2439
|
|
|
* @return void |
|
2440
|
|
|
*/ |
|
2441
|
|
|
function addHtmlHeader($header) |
|
2442
|
|
|
{ |
|
2443
|
|
|
$self = self::getInstance(); |
|
2444
|
|
|
$self->html_header .= "\n" . $header; |
|
2445
|
|
|
} |
|
2446
|
|
|
|
|
2447
|
|
|
function clearHtmlHeader() |
|
2448
|
|
|
{ |
|
2449
|
|
|
$self = self::getInstance(); |
|
2450
|
|
|
$self->html_header = ''; |
|
2451
|
|
|
} |
|
2452
|
|
|
|
|
2453
|
|
|
/** |
|
2454
|
|
|
* Returns added html code by addHtmlHeader() |
|
2455
|
|
|
* |
|
2456
|
|
|
* @return string Added html code before </head> |
|
2457
|
|
|
*/ |
|
2458
|
|
|
function getHtmlHeader() |
|
2459
|
|
|
{ |
|
2460
|
|
|
$self = self::getInstance(); |
|
2461
|
|
|
return $self->html_header; |
|
2462
|
|
|
} |
|
2463
|
|
|
|
|
2464
|
|
|
/** |
|
2465
|
|
|
* Add css class to Html Body |
|
2466
|
|
|
* |
|
2467
|
|
|
* @param string $class_name class name |
|
2468
|
|
|
*/ |
|
2469
|
|
|
function addBodyClass($class_name) |
|
2470
|
|
|
{ |
|
2471
|
|
|
$self = self::getInstance(); |
|
2472
|
|
|
$self->body_class[] = $class_name; |
|
2473
|
|
|
} |
|
2474
|
|
|
|
|
2475
|
|
|
/** |
|
2476
|
|
|
* Return css class to Html Body |
|
2477
|
|
|
* |
|
2478
|
|
|
* @return string Return class to html body |
|
2479
|
|
|
*/ |
|
2480
|
|
|
function getBodyClass() |
|
2481
|
|
|
{ |
|
2482
|
|
|
$self = self::getInstance(); |
|
2483
|
|
|
$self->body_class = array_unique($self->body_class); |
|
2484
|
|
|
|
|
2485
|
|
|
return (count($self->body_class) > 0) ? sprintf(' class="%s"', join(' ', $self->body_class)) : ''; |
|
2486
|
|
|
} |
|
2487
|
|
|
|
|
2488
|
|
|
/** |
|
2489
|
|
|
* Add html code after <body> |
|
2490
|
|
|
* |
|
2491
|
|
|
* @param string $header Add html code after <body> |
|
2492
|
|
|
*/ |
|
2493
|
|
|
function addBodyHeader($header) |
|
2494
|
|
|
{ |
|
2495
|
|
|
$self = self::getInstance(); |
|
2496
|
|
|
$self->body_header .= "\n" . $header; |
|
2497
|
|
|
} |
|
2498
|
|
|
|
|
2499
|
|
|
/** |
|
2500
|
|
|
* Returns added html code by addBodyHeader() |
|
2501
|
|
|
* |
|
2502
|
|
|
* @return string Added html code after <body> |
|
2503
|
|
|
*/ |
|
2504
|
|
|
function getBodyHeader() |
|
2505
|
|
|
{ |
|
2506
|
|
|
$self = self::getInstance(); |
|
2507
|
|
|
return $self->body_header; |
|
2508
|
|
|
} |
|
2509
|
|
|
|
|
2510
|
|
|
/** |
|
2511
|
|
|
* Add html code before </body> |
|
2512
|
|
|
* |
|
2513
|
|
|
* @param string $footer Add html code before </body> |
|
2514
|
|
|
*/ |
|
2515
|
|
|
function addHtmlFooter($footer) |
|
2516
|
|
|
{ |
|
2517
|
|
|
$self = self::getInstance(); |
|
2518
|
|
|
$self->html_footer .= ($self->Htmlfooter ? "\n" : '') . $footer; |
|
|
|
|
|
|
2519
|
|
|
} |
|
2520
|
|
|
|
|
2521
|
|
|
/** |
|
2522
|
|
|
* Returns added html code by addHtmlHeader() |
|
2523
|
|
|
* |
|
2524
|
|
|
* @return string Added html code before </body> |
|
2525
|
|
|
*/ |
|
2526
|
|
|
function getHtmlFooter() |
|
2527
|
|
|
{ |
|
2528
|
|
|
$self = self::getInstance(); |
|
2529
|
|
|
return $self->html_footer; |
|
2530
|
|
|
} |
|
2531
|
|
|
|
|
2532
|
|
|
/** |
|
2533
|
|
|
* Get config file |
|
2534
|
|
|
* |
|
2535
|
|
|
* @retrun string The path of the config file that contains database settings |
|
2536
|
|
|
*/ |
|
2537
|
|
|
function getConfigFile() |
|
2538
|
|
|
{ |
|
2539
|
|
|
return _XE_PATH_ . 'files/config/db.config.php'; |
|
2540
|
|
|
} |
|
2541
|
|
|
|
|
2542
|
|
|
/** |
|
2543
|
|
|
* Get FTP config file |
|
2544
|
|
|
* |
|
2545
|
|
|
* @return string The path of the config file that contains FTP settings |
|
2546
|
|
|
*/ |
|
2547
|
|
|
function getFTPConfigFile() |
|
2548
|
|
|
{ |
|
2549
|
|
|
return _XE_PATH_ . 'files/config/ftp.config.php'; |
|
2550
|
|
|
} |
|
2551
|
|
|
|
|
2552
|
|
|
/** |
|
2553
|
|
|
* Checks whether XE is installed |
|
2554
|
|
|
* |
|
2555
|
|
|
* @return bool True if the config file exists, otherwise FALSE. |
|
2556
|
|
|
*/ |
|
2557
|
|
|
function isInstalled() |
|
2558
|
|
|
{ |
|
2559
|
|
|
return FileHandler::hasContent(self::getConfigFile()); |
|
2560
|
|
|
} |
|
2561
|
|
|
|
|
2562
|
|
|
/** |
|
2563
|
|
|
* Transforms codes about widget or other features into the actual code, deprecatred |
|
2564
|
|
|
* |
|
2565
|
|
|
* @param string Transforms codes |
|
2566
|
|
|
* @return string Transforms codes |
|
2567
|
|
|
*/ |
|
2568
|
|
|
function transContent($content) |
|
2569
|
|
|
{ |
|
2570
|
|
|
return $content; |
|
2571
|
|
|
} |
|
2572
|
|
|
|
|
2573
|
|
|
/** |
|
2574
|
|
|
* Check whether it is allowed to use rewrite mod |
|
2575
|
|
|
* |
|
2576
|
|
|
* @return bool True if it is allowed to use rewrite mod, otherwise FALSE |
|
2577
|
|
|
*/ |
|
2578
|
|
|
function isAllowRewrite() |
|
2579
|
|
|
{ |
|
2580
|
|
|
$oContext = self::getInstance(); |
|
2581
|
|
|
return $oContext->allow_rewrite; |
|
2582
|
|
|
} |
|
2583
|
|
|
|
|
2584
|
|
|
/** |
|
2585
|
|
|
* Converts a local path into an URL |
|
2586
|
|
|
* |
|
2587
|
|
|
* @param string $path URL path |
|
2588
|
|
|
* @return string Converted path |
|
2589
|
|
|
*/ |
|
2590
|
|
|
function pathToUrl($path) |
|
2591
|
|
|
{ |
|
2592
|
|
|
$xe = _XE_PATH_; |
|
2593
|
|
|
$path = strtr($path, "\\", "/"); |
|
2594
|
|
|
|
|
2595
|
|
|
$base_url = preg_replace('@^https?://[^/]+/?@', '', self::getRequestUri()); |
|
2596
|
|
|
|
|
2597
|
|
|
$_xe = explode('/', $xe); |
|
2598
|
|
|
$_path = explode('/', $path); |
|
2599
|
|
|
$_base = explode('/', $base_url); |
|
2600
|
|
|
|
|
2601
|
|
|
if(!$_base[count($_base) - 1]) |
|
2602
|
|
|
{ |
|
2603
|
|
|
array_pop($_base); |
|
2604
|
|
|
} |
|
2605
|
|
|
|
|
2606
|
|
|
foreach($_xe as $idx => $dir) |
|
2607
|
|
|
{ |
|
2608
|
|
|
if($_path[0] != $dir) |
|
2609
|
|
|
{ |
|
2610
|
|
|
break; |
|
2611
|
|
|
} |
|
2612
|
|
|
array_shift($_path); |
|
2613
|
|
|
} |
|
2614
|
|
|
|
|
2615
|
|
|
$idx = count($_xe) - $idx - 1; |
|
|
|
|
|
|
2616
|
|
|
while($idx--) |
|
2617
|
|
|
{ |
|
2618
|
|
|
if(count($_base) > 0) |
|
2619
|
|
|
{ |
|
2620
|
|
|
array_shift($_base); |
|
2621
|
|
|
} |
|
2622
|
|
|
else |
|
2623
|
|
|
{ |
|
2624
|
|
|
array_unshift($_base, '..'); |
|
2625
|
|
|
} |
|
2626
|
|
|
} |
|
2627
|
|
|
|
|
2628
|
|
|
if(count($_base) > 0) |
|
2629
|
|
|
{ |
|
2630
|
|
|
array_unshift($_path, join('/', $_base)); |
|
2631
|
|
|
} |
|
2632
|
|
|
|
|
2633
|
|
|
$path = '/' . join('/', $_path); |
|
2634
|
|
|
if(substr_compare($path, '/', -1) !== 0) |
|
2635
|
|
|
{ |
|
2636
|
|
|
$path .= '/'; |
|
2637
|
|
|
} |
|
2638
|
|
|
return $path; |
|
2639
|
|
|
} |
|
2640
|
|
|
|
|
2641
|
|
|
/** |
|
2642
|
|
|
* Get meta tag |
|
2643
|
|
|
* @return array The list of meta tags |
|
2644
|
|
|
*/ |
|
2645
|
|
|
function getMetaTag() |
|
2646
|
|
|
{ |
|
2647
|
|
|
$self = self::getInstance(); |
|
2648
|
|
|
|
|
2649
|
|
|
if(!is_array($self->meta_tags)) |
|
2650
|
|
|
{ |
|
2651
|
|
|
$self->meta_tags = array(); |
|
|
|
|
|
|
2652
|
|
|
} |
|
2653
|
|
|
|
|
2654
|
|
|
$ret = array(); |
|
2655
|
|
|
foreach($self->meta_tags as $key => $val) |
|
2656
|
|
|
{ |
|
2657
|
|
|
list($name, $is_http_equiv) = explode("\t", $key); |
|
2658
|
|
|
$ret[] = array('name' => $name, 'is_http_equiv' => $is_http_equiv, 'content' => $val); |
|
2659
|
|
|
} |
|
2660
|
|
|
|
|
2661
|
|
|
return $ret; |
|
2662
|
|
|
} |
|
2663
|
|
|
|
|
2664
|
|
|
/** |
|
2665
|
|
|
* Add the meta tag |
|
2666
|
|
|
* |
|
2667
|
|
|
* @param string $name name of meta tag |
|
2668
|
|
|
* @param string $content content of meta tag |
|
2669
|
|
|
* @param mixed $is_http_equiv value of http_equiv |
|
2670
|
|
|
* @return void |
|
2671
|
|
|
*/ |
|
2672
|
|
|
function addMetaTag($name, $content, $is_http_equiv = FALSE) |
|
2673
|
|
|
{ |
|
2674
|
|
|
$self = self::getInstance(); |
|
2675
|
|
|
$self->meta_tags[$name . "\t" . ($is_http_equiv ? '1' : '0')] = $content; |
|
2676
|
|
|
} |
|
2677
|
|
|
|
|
2678
|
|
|
} |
|
2679
|
|
|
/* End of file Context.class.php */ |
|
2680
|
|
|
/* Location: ./classes/context/Context.class.php */ |
|
2681
|
|
|
|