Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
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() |
||
172 | |||
173 | /** |
||
174 | * Cunstructor |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | function Context() |
||
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() |
||
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() |
||
535 | |||
536 | /** |
||
537 | * Set DB information |
||
538 | * |
||
539 | * @param object $db_info DB information |
||
540 | * @return void |
||
541 | */ |
||
542 | function setDBInfo($db_info) |
||
547 | |||
548 | /** |
||
549 | * Get DB information |
||
550 | * |
||
551 | * @return object DB information |
||
552 | */ |
||
553 | function getDBInfo() |
||
558 | |||
559 | /** |
||
560 | * Return ssl status |
||
561 | * |
||
562 | * @return object SSL status (Optional - none|always|optional) |
||
563 | */ |
||
564 | function getSslStatus() |
||
569 | |||
570 | /** |
||
571 | * Return default URL |
||
572 | * |
||
573 | * @return string Default URL |
||
574 | */ |
||
575 | function getDefaultUrl() |
||
580 | |||
581 | /** |
||
582 | * Find supported languages |
||
583 | * |
||
584 | * @return array Supported languages |
||
585 | */ |
||
586 | function loadLangSupported() |
||
601 | |||
602 | /** |
||
603 | * Find selected languages to serve in the site |
||
604 | * |
||
605 | * @return array Selected languages |
||
606 | */ |
||
607 | function loadLangSelected() |
||
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() |
||
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() |
||
822 | |||
823 | /** |
||
824 | * Get browser title |
||
825 | * @deprecated |
||
826 | */ |
||
827 | function _getBrowserTitle() |
||
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) |
||
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) |
||
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) |
||
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() |
||
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) |
||
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) |
||
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) |
||
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) |
||
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) |
||
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) |
||
1114 | |||
1115 | function decodeIdna($domain) |
||
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() |
||
1195 | |||
1196 | /** |
||
1197 | * handle request arguments for GET/POST |
||
1198 | * |
||
1199 | * @return void |
||
1200 | */ |
||
1201 | function _setRequestArgument() |
||
1243 | |||
1244 | function _recursiveCheckVar($val) |
||
1265 | |||
1266 | /** |
||
1267 | * Handle request arguments for JSON |
||
1268 | * |
||
1269 | * @return void |
||
1270 | */ |
||
1271 | function _setJSONRequestArgument() |
||
1286 | |||
1287 | /** |
||
1288 | * Handle request arguments for XML RPC |
||
1289 | * |
||
1290 | * @return void |
||
1291 | */ |
||
1292 | function _setXmlRpcArgument() |
||
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) |
||
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) |
||
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() |
||
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() |
||
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) |
||
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) |
||
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) |
||
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') |
||
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') |
||
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) |
||
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 = '') |
||
2206 | |||
2207 | /** |
||
2208 | * Unload all javascript files |
||
2209 | * |
||
2210 | * @return void |
||
2211 | */ |
||
2212 | function unloadAllJsFiles() |
||
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) |
||
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) |
||
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') |
||
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) |
||
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 = '') |
||
2300 | |||
2301 | /** |
||
2302 | * Unload all css files |
||
2303 | * |
||
2304 | * @return void |
||
2305 | */ |
||
2306 | function unloadAllCSSFiles() |
||
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() |
||
2322 | |||
2323 | /** |
||
2324 | * Returns javascript plugin file info |
||
2325 | * @param string $pluginName |
||
2326 | * @return stdClass |
||
2327 | */ |
||
2328 | function getJavascriptPluginInfo($pluginName) |
||
2377 | /** |
||
2378 | * Load javascript plugin |
||
2379 | * |
||
2380 | * @param string $plugin_name plugin name |
||
2381 | * @return void |
||
2382 | */ |
||
2383 | function loadJavascriptPlugin($plugin_name) |
||
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) |
||
2446 | |||
2447 | function clearHtmlHeader() |
||
2452 | |||
2453 | /** |
||
2454 | * Returns added html code by addHtmlHeader() |
||
2455 | * |
||
2456 | * @return string Added html code before </head> |
||
2457 | */ |
||
2458 | function getHtmlHeader() |
||
2463 | |||
2464 | /** |
||
2465 | * Add css class to Html Body |
||
2466 | * |
||
2467 | * @param string $class_name class name |
||
2468 | */ |
||
2469 | function addBodyClass($class_name) |
||
2474 | |||
2475 | /** |
||
2476 | * Return css class to Html Body |
||
2477 | * |
||
2478 | * @return string Return class to html body |
||
2479 | */ |
||
2480 | function getBodyClass() |
||
2487 | |||
2488 | /** |
||
2489 | * Add html code after <body> |
||
2490 | * |
||
2491 | * @param string $header Add html code after <body> |
||
2492 | */ |
||
2493 | function addBodyHeader($header) |
||
2498 | |||
2499 | /** |
||
2500 | * Returns added html code by addBodyHeader() |
||
2501 | * |
||
2502 | * @return string Added html code after <body> |
||
2503 | */ |
||
2504 | function getBodyHeader() |
||
2509 | |||
2510 | /** |
||
2511 | * Add html code before </body> |
||
2512 | * |
||
2513 | * @param string $footer Add html code before </body> |
||
2514 | */ |
||
2515 | function addHtmlFooter($footer) |
||
2520 | |||
2521 | /** |
||
2522 | * Returns added html code by addHtmlHeader() |
||
2523 | * |
||
2524 | * @return string Added html code before </body> |
||
2525 | */ |
||
2526 | function getHtmlFooter() |
||
2531 | |||
2532 | /** |
||
2533 | * Get config file |
||
2534 | * |
||
2535 | * @retrun string The path of the config file that contains database settings |
||
2536 | */ |
||
2537 | function getConfigFile() |
||
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() |
||
2551 | |||
2552 | /** |
||
2553 | * Checks whether XE is installed |
||
2554 | * |
||
2555 | * @return bool True if the config file exists, otherwise FALSE. |
||
2556 | */ |
||
2557 | function isInstalled() |
||
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) |
||
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() |
||
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) |
||
2640 | |||
2641 | /** |
||
2642 | * Get meta tag |
||
2643 | * @return array The list of meta tags |
||
2644 | */ |
||
2645 | function getMetaTag() |
||
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) |
||
2677 | |||
2678 | } |
||
2679 | /* End of file Context.class.php */ |
||
2681 |