XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
Context.class.php
Go to the documentation of this file.
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 
14 class Context
15 {
16 
21  public $allow_rewrite = FALSE;
22 
27  public $request_method = 'GET';
28 
33  public $js_callback_func = '';
34 
39  public $response_method = '';
40 
45  public $context = NULL;
46 
51  public $db_info = NULL;
52 
57  public $ftp_info = NULL;
58 
63  public $sslActionCacheFile = './files/cache/sslCacheFile.php';
64 
69  public $ssl_actions = array();
70 
76 
81  public $html_header = NULL;
82 
87  public $body_class = array();
88 
93  public $body_header = NULL;
94 
99  public $html_footer = NULL;
100 
105  public $path = '';
106  // language information - it is changed by HTTP_USER_AGENT or user's cookie
111  public $lang_type = '';
112 
117  public $lang = NULL;
118 
123  public $loaded_lang_files = array();
124 
129  public $site_title = '';
130 
135  public $get_vars = NULL;
136 
141  public $is_uploaded = FALSE;
146  public $patterns = array(
147  '/<\?/iUsm',
148  '/<\%/iUsm',
149  '/<script\s*?language\s*?=\s*?("|\')?\s*?php\s*("|\')?/iUsm'
150  );
155  public $isSuccessInit = TRUE;
156 
162  function &getInstance()
163  {
164  static $theInstance = null;
165  if(!$theInstance)
166  {
167  $theInstance = new Context();
168  }
169 
170  return $theInstance;
171  }
172 
178  function __construct()
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 
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  ini_set('session.serialize_handler', 'php');
340  session_set_save_handler(
341  array(&$oSessionController, 'open'), array(&$oSessionController, 'close'), array(&$oSessionModel, 'read'), array(&$oSessionController, 'write'), array(&$oSessionController, 'destroy'), array(&$oSessionController, 'gc')
342  );
343  }
344 
345  if($sess = $_POST[session_name()]) session_id($sess);
346  session_start();
347 
348  // set authentication information in Context and session
349  if(self::isInstalled())
350  {
351  $oModuleModel = getModel('module');
352  $oModuleModel->loadModuleExtends();
353 
354  $oMemberModel = getModel('member');
355  $oMemberController = getController('member');
356 
357  if($oMemberController && $oMemberModel)
358  {
359  // if signed in, validate it.
360  if($oMemberModel->isLogged())
361  {
362  $oMemberController->setSessionInfo();
363  }
364  // check auto sign-in
365  elseif($_COOKIE['xeak'])
366  {
367  $oMemberController->doAutologin();
368  }
369 
370  $this->set('is_logged', $oMemberModel->isLogged());
371  $this->set('logged_info', $oMemberModel->getLoggedInfo());
372  }
373  }
374 
375  // load common language file
376  $this->lang = &$GLOBALS['lang'];
377  $this->loadLang(_XE_PATH_ . 'common/lang/');
378 
379  // check if using rewrite module
380  $this->allow_rewrite = ($this->db_info->use_rewrite == 'Y' ? TRUE : FALSE);
381 
382  // set locations for javascript use
383  $url = array();
384  $current_url = self::getRequestUri();
385  if($_SERVER['REQUEST_METHOD'] == 'GET')
386  {
387  if($this->get_vars)
388  {
389  $url = array();
390  foreach($this->get_vars as $key => $val)
391  {
392  if(is_array($val) && count($val) > 0)
393  {
394  foreach($val as $k => $v)
395  {
396  $url[] = $key . '[' . $k . ']=' . urlencode($v);
397  }
398  }
399  elseif($val)
400  {
401  $url[] = $key . '=' . urlencode($val);
402  }
403  }
404 
405  $current_url = self::getRequestUri();
406  if($url) $current_url .= '?' . join('&', $url);
407  }
408  else
409  {
410  $current_url = $this->getUrl();
411  }
412  }
413  else
414  {
415  $current_url = self::getRequestUri();
416  }
417 
418  $this->set('current_url', $current_url);
419  $this->set('request_uri', self::getRequestUri());
420 
421  if(strpos($current_url, 'xn--') !== FALSE)
422  {
423  $this->set('current_url', self::decodeIdna($current_url));
424  }
425 
426  if(strpos(self::getRequestUri(), 'xn--') !== FALSE)
427  {
428  $this->set('request_uri', self::decodeIdna(self::getRequestUri()));
429  }
430  }
431 
437  function close()
438  {
439  session_write_close();
440  }
441 
447  function loadDBInfo()
448  {
449  $self = self::getInstance();
450 
451  if(!$self->isInstalled())
452  {
453  return;
454  }
455 
456  ob_start(); // trash BOM
457  include($self::getConfigFile());
458  ob_end_clean();
459 
460  // If master_db information does not exist, the config file needs to be updated
461  if(!isset($db_info->master_db))
462  {
463  $db_info->master_db = array();
464  $db_info->master_db["db_type"] = $db_info->db_type;
465  unset($db_info->db_type);
466  $db_info->master_db["db_port"] = $db_info->db_port;
467  unset($db_info->db_port);
468  $db_info->master_db["db_hostname"] = $db_info->db_hostname;
469  unset($db_info->db_hostname);
470  $db_info->master_db["db_password"] = $db_info->db_password;
471  unset($db_info->db_password);
472  $db_info->master_db["db_database"] = $db_info->db_database;
473  unset($db_info->db_database);
474  $db_info->master_db["db_userid"] = $db_info->db_userid;
475  unset($db_info->db_userid);
476  $db_info->master_db["db_table_prefix"] = $db_info->db_table_prefix;
477  unset($db_info->db_table_prefix);
478 
479  if(isset($db_info->master_db["db_table_prefix"]) && substr_compare($db_info->master_db["db_table_prefix"], '_', -1) !== 0)
480  {
481  $db_info->master_db["db_table_prefix"] .= '_';
482  }
483 
484  $db_info->slave_db = array($db_info->master_db);
485  $self->setDBInfo($db_info);
486 
487  $oInstallController = getController('install');
488  $oInstallController->makeConfigFile();
489  }
490 
491  if(version_compare(PHP_VERSION, '7.0', '>='))
492  {
493  $db_info->master_db["db_type"] = preg_replace('/^mysql(_.+)?$/', 'mysqli$1', $db_info->master_db["db_type"]);
494  foreach($db_info->slave_db as &$slave_db_info)
495  {
496  $slave_db_info["db_type"] = preg_replace('/^mysql(_.+)?$/', 'mysqli$1', $slave_db_info["db_type"]);
497  }
498  }
499 
500  if(!$db_info->use_prepared_statements)
501  {
502  $db_info->use_prepared_statements = 'Y';
503  }
504 
505  if(!$db_info->time_zone)
506  $db_info->time_zone = date('O');
507  $GLOBALS['_time_zone'] = $db_info->time_zone;
508 
509  if($db_info->qmail_compatibility != 'Y')
510  $db_info->qmail_compatibility = 'N';
511  $GLOBALS['_qmail_compatibility'] = $db_info->qmail_compatibility;
512 
513  if(!$db_info->use_db_session)
514  $db_info->use_db_session = 'N';
515  if(!$db_info->use_ssl)
516  $db_info->use_ssl = 'none';
517  $this->set('_use_ssl', $db_info->use_ssl);
518 
519  $self->set('_http_port', ($db_info->http_port) ? $db_info->http_port : NULL);
520  $self->set('_https_port', ($db_info->https_port) ? $db_info->https_port : NULL);
521 
522  if(!$db_info->sitelock_whitelist) {
523  $db_info->sitelock_whitelist = '127.0.0.1';
524  }
525 
526  if(is_string($db_info->sitelock_whitelist)) {
527  $db_info->sitelock_whitelist = explode(',', $db_info->sitelock_whitelist);
528  }
529 
530  $self->setDBInfo($db_info);
531  }
532 
538  function getDBType()
539  {
540  $self = self::getInstance();
541  return $self->db_info->master_db["db_type"];
542  }
543 
550  function setDBInfo($db_info)
551  {
552  $self = self::getInstance();
553  $self->db_info = $db_info;
554  }
555 
561  function getDBInfo()
562  {
563  $self = self::getInstance();
564  return $self->db_info;
565  }
566 
572  function getSslStatus()
573  {
574  $dbInfo = self::getDBInfo();
575  return $dbInfo->use_ssl;
576  }
577 
583  function getDefaultUrl()
584  {
585  $db_info = self::getDBInfo();
586  return $db_info->default_url;
587  }
588 
594  function loadLangSupported()
595  {
596  static $lang_supported = null;
597  if(!$lang_supported)
598  {
599  $langs = file(_XE_PATH_ . 'common/lang/lang.info');
600  foreach($langs as $val)
601  {
602  list($lang_prefix, $lang_text) = explode(',', $val);
603  $lang_text = trim($lang_text);
604  $lang_supported[$lang_prefix] = $lang_text;
605  }
606  }
607  return $lang_supported;
608  }
609 
615  function loadLangSelected()
616  {
617  static $lang_selected = null;
618  if(!$lang_selected)
619  {
620  $orig_lang_file = _XE_PATH_ . 'common/lang/lang.info';
621  $selected_lang_file = _XE_PATH_ . 'files/config/lang_selected.info';
622  if(!FileHandler::hasContent($selected_lang_file))
623  {
624  $old_selected_lang_file = _XE_PATH_ . 'files/cache/lang_selected.info';
625  FileHandler::moveFile($old_selected_lang_file, $selected_lang_file);
626  }
627 
628  if(!FileHandler::hasContent($selected_lang_file))
629  {
630  $buff = FileHandler::readFile($orig_lang_file);
631  FileHandler::writeFile($selected_lang_file, $buff);
632  $lang_selected = self::loadLangSupported();
633  }
634  else
635  {
636  $langs = file($selected_lang_file);
637  foreach($langs as $val)
638  {
639  list($lang_prefix, $lang_text) = explode(',', $val);
640  $lang_text = trim($lang_text);
641  $lang_selected[$lang_prefix] = $lang_text;
642  }
643  }
644  }
645  return $lang_selected;
646  }
647 
653  function checkSSO()
654  {
655  // pass if it's not GET request or XE is not yet installed
656  if($this->db_info->use_sso != 'Y' || isCrawler())
657  {
658  return TRUE;
659  }
660  $checkActList = array('rss' => 1, 'atom' => 1);
661  if(self::getRequestMethod() != 'GET' || !self::isInstalled() || isset($checkActList[self::get('act')]))
662  {
663  return TRUE;
664  }
665 
666  // pass if default URL is not set
667  $default_url = trim($this->db_info->default_url);
668  if(!$default_url)
669  {
670  return TRUE;
671  }
672 
673  if(substr_compare($default_url, '/', -1) !== 0)
674  {
675  $default_url .= '/';
676  }
677 
678  // for sites recieving SSO valdiation
679  if($default_url == self::getRequestUri())
680  {
681  if(self::get('url'))
682  {
683  $url = base64_decode(self::get('url'));
684  $url_info = parse_url($url);
685  if(!Password::checkSignature($url, self::get('sig')))
686  {
687  echo self::get('lang')->msg_invalid_request;
688  return false;
689  }
690 
691  $oModuleModel = getModel('module');
692  $domain = $url_info['host'] . $url_info['path'];
693  if(substr_compare($domain, '/', -1) === 0) $domain = substr($domain, 0, -1);
694  $site_info = $oModuleModel->getSiteInfoByDomain($domain);
695 
696  if($site_info->site_srl)
697  {
698  $url_info['query'].= ($url_info['query'] ? '&' : '') . 'SSOID=' . urlencode(session_id()) . '&sig=' . urlencode(Password::createSignature(session_id()));
699  $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']);
700  }
701  else
702  {
703  $redirect_url = $url;
704  }
705  header('location:' . $redirect_url);
706 
707  return FALSE;
708  }
709  // for sites requesting SSO validation
710  }
711  else
712  {
713  // result handling : set session_name()
714  if($session_name = self::get('SSOID'))
715  {
716  if(!Password::checkSignature($session_name, self::get('sig')))
717  {
718  echo self::get('lang')->msg_invalid_request;
719  return false;
720  }
721 
722  setcookie(session_name(), $session_name);
723 
724  $url = preg_replace('/[\?\&]SSOID=.+$/', '', self::getRequestUrl());
725  header('location:' . $url);
726  return FALSE;
727  // send SSO request
728  }
729  else if(!self::get('SSOID') && $_COOKIE['sso'] != md5(self::getRequestUri()))
730  {
731  setcookie('sso', md5(self::getRequestUri()));
732  $origin_url = self::getRequestUrl();
733  $origin_sig = Password::createSignature($origin_url);
734  $url = sprintf("%s?url=%s&sig=%s", $default_url, urlencode(base64_encode($origin_url)), urlencode($origin_sig));
735  header('location:' . $url);
736  return FALSE;
737  }
738  }
739 
740  return TRUE;
741  }
742 
748  function isFTPRegisted()
749  {
750  return file_exists(self::getFTPConfigFile());
751  }
752 
758  function getFTPInfo()
759  {
760  $self = self::getInstance();
761 
762  if(!$self->isFTPRegisted())
763  {
764  return null;
765  }
766 
767  include($self->getFTPConfigFile());
768 
769  return $ftp_info;
770  }
771 
779  {
780  if(!$site_title)
781  {
782  return;
783  }
784  $self = self::getInstance();
785 
786  if($self->site_title)
787  {
788  $self->site_title .= ' - ' . $site_title;
789  }
790  else
791  {
792  $self->site_title = $site_title;
793  }
794  }
795 
803  {
804  if(!$site_title)
805  {
806  return;
807  }
808  $self = self::getInstance();
809  $self->site_title = $site_title;
810  }
811 
817  function getBrowserTitle()
818  {
819  $self = self::getInstance();
820 
821  $oModuleController = getController('module');
822  $oModuleController->replaceDefinedLangCode($self->site_title);
823 
824  return htmlspecialchars($self->site_title, ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE);
825  }
826 
831  public function getSiteTitle()
832  {
833  $oModuleModel = getModel('module');
834  $moduleConfig = $oModuleModel->getModuleConfig('module');
835 
836  if(isset($moduleConfig->siteTitle))
837  {
838  return $moduleConfig->siteTitle;
839  }
840  return '';
841  }
842 
847  function _getBrowserTitle()
848  {
849  return $this->getBrowserTitle();
850  }
851 
858  function loadLang($path)
859  {
860  global $lang;
861 
862  $self = self::getInstance();
863  if(!$self->lang_type)
864  {
865  return;
866  }
867  if(!is_object($lang))
868  {
869  $lang = new stdClass;
870  }
871 
872  if(!($filename = $self->_loadXmlLang($path)))
873  {
874  $filename = $self->_loadPhpLang($path);
875  }
876 
877  if(!is_array($self->loaded_lang_files))
878  {
879  $self->loaded_lang_files = array();
880  }
881  if(in_array($filename, $self->loaded_lang_files))
882  {
883  return;
884  }
885 
886  if($filename && is_readable($filename))
887  {
888  $self->loaded_lang_files[] = $filename;
889  include($filename);
890  }
891  else
892  {
893  $self->_evalxmlLang($path);
894  }
895  }
896 
903  function _evalxmlLang($path)
904  {
905  global $lang;
906 
907  if(!$path) return;
908 
909  $_path = 'eval://' . $path;
910 
911  if(in_array($_path, $this->loaded_lang_files))
912  {
913  return;
914  }
915 
916  if(substr_compare($path, '/', -1) !== 0)
917  {
918  $path .= '/';
919  }
920 
921  $oXmlLangParser = new XmlLangParser($path . 'lang.xml', $this->lang_type);
922  $content = $oXmlLangParser->getCompileContent();
923 
924  if($content)
925  {
926  $this->loaded_lang_files[] = $_path;
927  eval($content);
928  }
929  }
930 
937  function _loadXmlLang($path)
938  {
939  if(!$path) return;
940 
941  $oXmlLangParser = new XmlLangParser($path . ((substr_compare($path, '/', -1) !== 0) ? '/' : '') . 'lang.xml', $this->lang_type);
942  return $oXmlLangParser->compile();
943  }
944 
951  function _loadPhpLang($path)
952  {
953  if(!$path) return;
954 
955  if(substr_compare($path, '/', -1) !== 0)
956  {
957  $path .= '/';
958  }
959  $path_tpl = $path . '%s.lang.php';
960  $file = sprintf($path_tpl, $this->lang_type);
961 
962  $langs = array('ko', 'en'); // this will be configurable.
963  while(!is_readable($file) && $langs[0])
964  {
965  $file = sprintf($path_tpl, array_shift($langs));
966  }
967 
968  if(!is_readable($file))
969  {
970  return FALSE;
971  }
972  return $file;
973  }
974 
981  function setLangType($lang_type = 'ko')
982  {
983  $self = self::getInstance();
984 
985  $self->lang_type = $lang_type;
986  $self->set('lang_type', $lang_type);
987 
988  $_SESSION['lang_type'] = $lang_type;
989  }
990 
996  function getLangType()
997  {
998  $self = self::getInstance();
999  return $self->lang_type;
1000  }
1001 
1008  function getLang($code)
1009  {
1010  if(!$code)
1011  {
1012  return;
1013  }
1014  if($GLOBALS['lang']->{$code})
1015  {
1016  return $GLOBALS['lang']->{$code};
1017  }
1018  return $code;
1019  }
1020 
1028  function setLang($code, $val)
1029  {
1030  if(!isset($GLOBALS['lang']))
1031  {
1032  $GLOBALS['lang'] = new stdClass();
1033  }
1034  $GLOBALS['lang']->{$code} = $val;
1035  }
1036 
1043  function convertEncoding($source_obj)
1044  {
1045  $charset_list = array(
1046  'UTF-8', 'EUC-KR', 'CP949', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS',
1047  'CP932', 'EUC-CN', 'HZ', 'GBK', 'GB18030', 'EUC-TW', 'BIG5',
1048  'CP950', 'BIG5-HKSCS', 'ISO8859-6', 'ISO8859-8', 'JOHAB', 'CP1255',
1049  'CP1256', 'CP862', 'ASCII', 'ISO8859-1', 'CP1250', 'CP1251',
1050  'CP1252', 'CP1253', 'CP1254', 'CP1257', 'CP850', 'CP866'
1051  );
1052 
1053  $obj = clone $source_obj;
1054 
1055  foreach($charset_list as $charset)
1056  {
1057  array_walk($obj,'Context::checkConvertFlag',$charset);
1058  $flag = self::checkConvertFlag($flag = TRUE);
1059  if($flag)
1060  {
1061  if($charset == 'UTF-8')
1062  {
1063  return $obj;
1064  }
1065  array_walk($obj,'Context::doConvertEncoding',$charset);
1066  return $obj;
1067  }
1068  }
1069  return $obj;
1070  }
1071 
1081  function checkConvertFlag(&$val, $key = null, $charset = null)
1082  {
1083  static $flag = TRUE;
1084  if($charset)
1085  {
1086  if(is_array($val))
1087  array_walk($val,'Context::checkConvertFlag',$charset);
1088  else if($val && iconv($charset,$charset,$val)!=$val) $flag = FALSE;
1089  else $flag = FALSE;
1090  }
1091  else
1092  {
1093  $return = $flag;
1094  $flag = TRUE;
1095  return $return;
1096  }
1097  }
1098 
1108  function doConvertEncoding(&$val, $key = null, $charset)
1109  {
1110  if (is_array($val))
1111  {
1112  array_walk($val,'Context::doConvertEncoding',$charset);
1113  }
1114  else $val = iconv($charset,'UTF-8',$val);
1115  }
1116 
1123  function convertEncodingStr($str)
1124  {
1125  if(!$str) return null;
1126  $obj = new stdClass();
1127  $obj->str = $str;
1128  $obj = self::convertEncoding($obj);
1129  return $obj->str;
1130  }
1131 
1132  function decodeIdna($domain)
1133  {
1134  if(strpos($domain, 'xn--') !== FALSE)
1135  {
1136  require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php');
1137  $IDN = new idna_convert(array('idn_version' => 2008));
1138  $domain = $IDN->decode($domain);
1139  }
1140 
1141  return $domain;
1142  }
1143 
1150  function setResponseMethod($method = 'HTML')
1151  {
1152  $self = self::getInstance();
1153 
1154  $methods = array('HTML' => 1, 'XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1);
1155  $self->response_method = isset($methods[$method]) ? $method : 'HTML';
1156  }
1157 
1164  {
1165  $self = self::getInstance();
1166 
1167  if($self->response_method)
1168  {
1169  return $self->response_method;
1170  }
1171 
1172  $method = $self->getRequestMethod();
1173  $methods = array('HTML' => 1, 'XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1);
1174 
1175  return isset($methods[$method]) ? $method : 'HTML';
1176  }
1177 
1184  function setRequestMethod($type = '')
1185  {
1186  $self = self::getInstance();
1187 
1188  $self->js_callback_func = $self->getJSCallbackFunc();
1189 
1190  ($type && $self->request_method = $type) or
1191  ((strpos($_SERVER['CONTENT_TYPE'], 'json') || strpos($_SERVER['HTTP_CONTENT_TYPE'], 'json')) && $self->request_method = 'JSON') or
1192  ($GLOBALS['HTTP_RAW_POST_DATA'] && $self->request_method = 'XMLRPC') or
1193  ($self->js_callback_func && $self->request_method = 'JS_CALLBACK') or
1194  ($self->request_method = $_SERVER['REQUEST_METHOD']);
1195  }
1196 
1202  function _checkGlobalVars()
1203  {
1204  $this->_recursiveCheckVar($_SERVER['HTTP_HOST']);
1205 
1206  $pattern = "/[\,\"\'\{\}\[\]\(\);$]/";
1207  if(preg_match($pattern, $_SERVER['HTTP_HOST']))
1208  {
1209  $this->isSuccessInit = FALSE;
1210  }
1211  }
1212 
1219  {
1220  if(!count($_REQUEST))
1221  {
1222  return;
1223  }
1224 
1225  $requestMethod = $this->getRequestMethod();
1226  foreach($_REQUEST as $key => $val)
1227  {
1228  if($val === '' || self::get($key))
1229  {
1230  continue;
1231  }
1232  $key = htmlentities($key);
1233  $val = $this->_filterRequestVar($key, $val, false, ($requestMethod == 'GET'));
1234 
1235  if($requestMethod == 'GET' && isset($_GET[$key]))
1236  {
1237  $set_to_vars = TRUE;
1238  }
1239  elseif($requestMethod == 'POST' && isset($_POST[$key]))
1240  {
1241  $set_to_vars = TRUE;
1242  }
1243  elseif($requestMethod == 'JS_CALLBACK' && (isset($_GET[$key]) || isset($_POST[$key])))
1244  {
1245  $set_to_vars = TRUE;
1246  }
1247  else
1248  {
1249  $set_to_vars = FALSE;
1250  }
1251 
1252  if($set_to_vars)
1253  {
1254  $this->_recursiveCheckVar($val);
1255  }
1256 
1257  $this->set($key, $val, $set_to_vars);
1258  }
1259  }
1260 
1261  function _recursiveCheckVar($val)
1262  {
1263  if(is_string($val))
1264  {
1265  foreach($this->patterns as $pattern)
1266  {
1267  if(preg_match($pattern, $val))
1268  {
1269  $this->isSuccessInit = FALSE;
1270  return;
1271  }
1272  }
1273  }
1274  else if(is_array($val))
1275  {
1276  foreach($val as $val2)
1277  {
1278  $this->_recursiveCheckVar($val2);
1279  }
1280  }
1281  }
1282 
1289  {
1290  if($this->getRequestMethod() != 'JSON')
1291  {
1292  return;
1293  }
1294 
1295  $params = array();
1296  parse_str($GLOBALS['HTTP_RAW_POST_DATA'], $params);
1297 
1298  foreach($params as $key => $val)
1299  {
1300  $key = htmlentities($key);
1301  $this->set($key, $this->_filterRequestVar($key, $val, 1), TRUE);
1302  }
1303  }
1304 
1311  {
1312  if($this->getRequestMethod() != 'XMLRPC')
1313  {
1314  return;
1315  }
1316 
1317  $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
1318  if(Security::detectingXEE($xml))
1319  {
1320  header("HTTP/1.0 400 Bad Request");
1321  exit;
1322  }
1323 
1324  $oXml = new XmlParser();
1325  $xml_obj = $oXml->parse($xml);
1326 
1327  $params = $xml_obj->methodcall->params;
1328  unset($params->node_name, $params->attrs, $params->body);
1329 
1330  if(!count(get_object_vars($params)))
1331  {
1332  return;
1333  }
1334 
1335  foreach($params as $key => $val)
1336  {
1337  $this->set($key, $this->_filterXmlVars($key, $val), TRUE);
1338  }
1339  }
1340 
1348  function _filterXmlVars($key, $val)
1349  {
1350  if(is_array($val))
1351  {
1352  $stack = array();
1353  foreach($val as $k => $v)
1354  {
1355  $stack[$k] = $this->_filterXmlVars($k, $v);
1356  }
1357 
1358  return $stack;
1359  }
1360 
1361  $body = $val->body;
1362  unset($val->node_name, $val->attrs, $val->body);
1363  if(!count(get_object_vars($val)))
1364  {
1365  return $this->_filterRequestVar($key, $body, 0);
1366  }
1367 
1368  $stack = new stdClass();
1369  foreach($val as $k => $v)
1370  {
1371  $output = $this->_filterXmlVars($k, $v);
1372  if(is_object($v) && $v->attrs->type == 'array')
1373  {
1374  $output = array($output);
1375  }
1376  if($k == 'value' && (is_array($v) || $v->attrs->type == 'array'))
1377  {
1378  return $output;
1379  }
1380 
1381  $stack->{$k} = $output;
1382  }
1383 
1384  if(!count(get_object_vars($stack)))
1385  {
1386  return NULL;
1387  }
1388 
1389  return $stack;
1390  }
1391 
1401  function _filterRequestVar($key, $val, $do_stripslashes = true, $remove_hack = false)
1402  {
1403  if(!($isArray = is_array($val)))
1404  {
1405  $val = array($val);
1406  }
1407 
1408  $result = array();
1409  foreach($val as $k => $v)
1410  {
1411  if($remove_hack && !is_array($v)) {
1412  if(stripos($v, '<script') || stripos($v, 'lt;script') || stripos($v, '%3Cscript'))
1413  {
1414  $result[$k] = escape($v);
1415  continue;
1416  }
1417  }
1418 
1419  $k = htmlentities($k);
1420  if($key === 'page' || $key === 'cpage' || substr_compare($key, 'srl', -3) === 0)
1421  {
1422  $result[$k] = !preg_match('/^[0-9,]+$/', $v) ? (int) $v : $v;
1423  }
1424  elseif(in_array($key, array('mid','search_keyword','search_target','xe_validator_id'))) {
1425  $result[$k] = escape($v, false);
1426  }
1427  elseif($key === 'vid')
1428  {
1429  $result[$k] = urlencode($v);
1430  }
1431  elseif(stripos($key, 'XE_VALIDATOR', 0) === 0)
1432  {
1433  unset($result[$k]);
1434  }
1435  else
1436  {
1437  $result[$k] = $v;
1438 
1439  if($do_stripslashes && version_compare(PHP_VERSION, '5.4.0', '<') && get_magic_quotes_gpc())
1440  {
1441  if (is_array($result[$k]))
1442  {
1443  array_walk_recursive($result[$k], function(&$val) { $val = stripslashes($val); });
1444  }
1445  else
1446  {
1447  $result[$k] = stripslashes($result[$k]);
1448  }
1449  }
1450 
1451  if(is_array($result[$k]))
1452  {
1453  array_walk_recursive($result[$k], function(&$val) { $val = trim($val); });
1454  }
1455  else
1456  {
1457  $result[$k] = trim($result[$k]);
1458  }
1459 
1460  if($remove_hack)
1461  {
1462  $result[$k] = escape($result[$k], false);
1463  }
1464  }
1465  }
1466 
1467  return $isArray ? $result : $result[0];
1468  }
1469 
1475  function isUploaded()
1476  {
1477  $self = self::getInstance();
1478  return $self->is_uploaded;
1479  }
1480 
1487  {
1488  if($_SERVER['REQUEST_METHOD'] != 'POST' || !$_FILES || (stripos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') === FALSE && stripos($_SERVER['HTTP_CONTENT_TYPE'], 'multipart/form-data') === FALSE))
1489  {
1490  return;
1491  }
1492 
1493  foreach($_FILES as $key => $val)
1494  {
1495  $tmp_name = $val['tmp_name'];
1496  if(!is_array($tmp_name))
1497  {
1498  if(!UploadFileFilter::check($tmp_name, $val['name']))
1499  {
1500  continue;
1501  }
1502  $val['name'] = htmlspecialchars($val['name'], ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE);
1503  $this->set($key, $val, TRUE);
1504  $this->is_uploaded = TRUE;
1505  }
1506  else
1507  {
1508  $files = array();
1509  foreach ($tmp_name as $i => $j)
1510  {
1511  if(!UploadFileFilter::check($val['tmp_name'][$i], $val['name'][$i]))
1512  {
1513  $files = array();
1514  unset($_FILES[$key]);
1515  break;
1516  }
1517  $file = array();
1518  $file['name'] = $val['name'][$i];
1519  $file['type'] = $val['type'][$i];
1520  $file['tmp_name'] = $val['tmp_name'][$i];
1521  $file['error'] = $val['error'][$i];
1522  $file['size'] = $val['size'][$i];
1523  $files[] = $file;
1524  }
1525  if(count($files))
1526  {
1527  self::set($key, $files, true);
1528  }
1529  }
1530  }
1531  }
1532 
1537  function getRequestMethod()
1538  {
1539  $self = self::getInstance();
1540  return $self->request_method;
1541  }
1542 
1547  function getRequestUrl()
1548  {
1549  static $url = null;
1550  if(is_null($url))
1551  {
1552  $url = self::getRequestUri();
1553  if(count($_GET) > 0)
1554  {
1555  foreach($_GET as $key => $val)
1556  {
1557  $vars[] = $key . '=' . ($val ? urlencode(self::convertEncodingStr($val)) : '');
1558  }
1559  $url .= '?' . join('&', $vars);
1560  }
1561  }
1562  return $url;
1563  }
1564 
1570  {
1571  $self = self::getInstance();
1572  $js_callback_func = isset($_GET['xe_js_callback']) ? $_GET['xe_js_callback'] : $_POST['xe_js_callback'];
1573 
1574  if(!preg_match('/^[a-z0-9\.]+$/i', $js_callback_func))
1575  {
1576  unset($js_callback_func);
1577  unset($_GET['xe_js_callback']);
1578  unset($_POST['xe_js_callback']);
1579  }
1580 
1581  return $js_callback_func;
1582  }
1583 
1594  function getUrl($num_args = 0, $args_list = array(), $domain = null, $encode = TRUE, $autoEncode = FALSE)
1595  {
1596  static $site_module_info = null;
1597  static $current_info = null;
1598 
1599  $self = self::getInstance();
1600 
1601  // retrieve virtual site information
1602  if(is_null($site_module_info))
1603  {
1604  $site_module_info = self::get('site_module_info');
1605  }
1606 
1607  // If $domain is set, handle it (if $domain is vid type, remove $domain and handle with $vid)
1608  if($domain && isSiteID($domain))
1609  {
1610  $vid = $domain;
1611  $domain = '';
1612  }
1613 
1614  // If $domain, $vid are not set, use current site information
1615  if(!$domain && !$vid)
1616  {
1617  if($site_module_info->domain && isSiteID($site_module_info->domain))
1618  {
1619  $vid = $site_module_info->domain;
1620  }
1621  else
1622  {
1623  $domain = $site_module_info->domain;
1624  }
1625  }
1626 
1627  // if $domain is set, compare current URL. If they are same, remove the domain, otherwise link to the domain.
1628  if($domain)
1629  {
1630  $domain_info = parse_url($domain);
1631  if(is_null($current_info))
1632  {
1633  $current_info = parse_url(($_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . getScriptPath());
1634  }
1635  if($domain_info['host'] . $domain_info['path'] == $current_info['host'] . $current_info['path'])
1636  {
1637  unset($domain);
1638  }
1639  else
1640  {
1641  $domain = preg_replace('/^(http|https):\/\//i', '', trim($domain));
1642  if(substr_compare($domain, '/', -1) !== 0)
1643  {
1644  $domain .= '/';
1645  }
1646  }
1647  }
1648 
1649  $get_vars = array();
1650 
1651  // If there is no GET variables or first argument is '' to reset variables
1652  if(!$self->get_vars || $args_list[0] == '')
1653  {
1654  // rearrange args_list
1655  if(is_array($args_list) && $args_list[0] == '')
1656  {
1657  array_shift($args_list);
1658  }
1659  }
1660  elseif($_SERVER['REQUEST_METHOD'] == 'GET')
1661  {
1662  // Otherwise, make GET variables into array
1663  $get_vars = get_object_vars($self->get_vars);
1664  }
1665  else
1666  {
1667  if(!!$self->get_vars->module) $get_vars['module'] = $self->get_vars->module;
1668  if(!!$self->get_vars->mid) $get_vars['mid'] = $self->get_vars->mid;
1669  if(!!$self->get_vars->act) $get_vars['act'] = $self->get_vars->act;
1670  if(!!$self->get_vars->page) $get_vars['page'] = $self->get_vars->page;
1671  if(!!$self->get_vars->search_target) $get_vars['search_target'] = $self->get_vars->search_target;
1672  if(!!$self->get_vars->search_keyword) $get_vars['search_keyword'] = $self->get_vars->search_keyword;
1673  if($get_vars['act'] == 'IS')
1674  {
1675  if(!!$self->get_vars->is_keyword) $get_vars['is_keyword'] = $self->get_vars->is_keyword;
1676  }
1677  }
1678 
1679  // arrange args_list
1680  for($i = 0, $c = count($args_list); $i < $c; $i += 2)
1681  {
1682  $key = $args_list[$i];
1683  $val = trim($args_list[$i + 1]);
1684 
1685  // If value is not set, remove the key
1686  if(!isset($val) || !strlen($val))
1687  {
1688  unset($get_vars[$key]);
1689  continue;
1690  }
1691  // set new variables
1692  $get_vars[$key] = $val;
1693  }
1694 
1695  // remove vid, rnd
1696  unset($get_vars['rnd']);
1697  if($vid)
1698  {
1699  $get_vars['vid'] = $vid;
1700  }
1701  else
1702  {
1703  unset($get_vars['vid']);
1704  }
1705 
1706  // for compatibility to lower versions
1707  $act = $get_vars['act'];
1708  $act_alias = array(
1709  'dispMemberFriend' => 'dispCommunicationFriend',
1710  'dispMemberMessages' => 'dispCommunicationMessages',
1711  'dispDocumentAdminManageDocument' => 'dispDocumentManageDocument',
1712  'dispModuleAdminSelectList' => 'dispModuleSelectList'
1713  );
1714  if($act_alias[$act])
1715  {
1716  $get_vars['act'] = $act_alias[$act];
1717  }
1718 
1719  // organize URL
1720  $query = '';
1721  if(count($get_vars) > 0)
1722  {
1723  // if using rewrite mod
1724  if($self->allow_rewrite)
1725  {
1726  $var_keys = array_keys($get_vars);
1727  sort($var_keys);
1728 
1729  $target = join('.', $var_keys);
1730 
1731  $act = $get_vars['act'];
1732  $vid = $get_vars['vid'];
1733  $mid = $get_vars['mid'];
1734  $key = $get_vars['key'];
1735  $srl = $get_vars['document_srl'];
1736 
1737  $tmpArray = array('rss' => 1, 'atom' => 1, 'api' => 1);
1738  $is_feed = isset($tmpArray[$act]);
1739 
1740  $target_map = array(
1741  'vid' => $vid,
1742  'mid' => $mid,
1743  'mid.vid' => "$vid/$mid",
1744  'entry.mid' => "$mid/entry/" . $get_vars['entry'],
1745  'entry.mid.vid' => "$vid/$mid/entry/" . $get_vars['entry'],
1746  'document_srl' => $srl,
1747  'document_srl.mid' => "$mid/$srl",
1748  'document_srl.vid' => "$vid/$srl",
1749  'document_srl.mid.vid' => "$vid/$mid/$srl",
1750  'act' => ($is_feed && $act !== 'api') ? $act : '',
1751  'act.mid' => $is_feed ? "$mid/$act" : '',
1752  'act.mid.vid' => $is_feed ? "$vid/$mid/$act" : '',
1753  'act.document_srl.key' => ($act == 'trackback') ? "$srl/$key/$act" : '',
1754  'act.document_srl.key.mid' => ($act == 'trackback') ? "$mid/$srl/$key/$act" : '',
1755  'act.document_srl.key.vid' => ($act == 'trackback') ? "$vid/$srl/$key/$act" : '',
1756  'act.document_srl.key.mid.vid' => ($act == 'trackback') ? "$vid/$mid/$srl/$key/$act" : ''
1757  );
1758 
1759  $query = $target_map[$target];
1760  }
1761 
1762  if(!$query)
1763  {
1764  $queries = array();
1765  foreach($get_vars as $key => $val)
1766  {
1767  if(is_array($val) && count($val) > 0)
1768  {
1769  foreach($val as $k => $v)
1770  {
1771  $queries[] = $key . '[' . $k . ']=' . urlencode($v);
1772  }
1773  }
1774  elseif(!is_array($val))
1775  {
1776  $queries[] = $key . '=' . urlencode($val);
1777  }
1778  }
1779  if(count($queries) > 0)
1780  {
1781  $query = 'index.php?' . join('&', $queries);
1782  }
1783  }
1784  }
1785 
1786  // If using SSL always
1787  $_use_ssl = $self->get('_use_ssl');
1788  if($_use_ssl == 'always')
1789  {
1790  $query = $self->getRequestUri(ENFORCE_SSL, $domain) . $query;
1791  // optional SSL use
1792  }
1793  elseif($_use_ssl == 'optional')
1794  {
1795  $ssl_mode = (($self->get('module') === 'admin') || ($get_vars['module'] === 'admin') || (isset($get_vars['act']) && $self->isExistsSSLAction($get_vars['act']))) ? ENFORCE_SSL : RELEASE_SSL;
1796  $query = $self->getRequestUri($ssl_mode, $domain) . $query;
1797  // no SSL
1798  }
1799  else
1800  {
1801  // currently on SSL but target is not based on SSL
1802  if($_SERVER['HTTPS'] == 'on')
1803  {
1804  $query = $self->getRequestUri(ENFORCE_SSL, $domain) . $query;
1805  }
1806  else if($domain) // if $domain is set
1807  {
1808  $query = $self->getRequestUri(FOLLOW_REQUEST_SSL, $domain) . $query;
1809  }
1810  else
1811  {
1812  $query = getScriptPath() . $query;
1813  }
1814  }
1815 
1816  if(!$encode)
1817  {
1818  return $query;
1819  }
1820 
1821  if(!$autoEncode)
1822  {
1823  return htmlspecialchars($query, ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE);
1824  }
1825 
1826  $output = array();
1827  $encode_queries = array();
1828  $parsedUrl = parse_url($query);
1829  parse_str($parsedUrl['query'], $output);
1830  foreach($output as $key => $value)
1831  {
1832  if(preg_match('/&([a-z]{2,}|#\d+);/', urldecode($value)))
1833  {
1834  $value = urlencode(htmlspecialchars_decode(urldecode($value)));
1835  }
1836  $encode_queries[] = $key . '=' . $value;
1837  }
1838 
1839  return htmlspecialchars($parsedUrl['path'] . '?' . join('&', $encode_queries), ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE);
1840  }
1841 
1849  function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null)
1850  {
1851  static $url = array();
1852 
1853  // Check HTTP Request
1854  if(!isset($_SERVER['SERVER_PROTOCOL']))
1855  {
1856  return;
1857  }
1858 
1859  if(self::get('_use_ssl') == 'always')
1860  {
1861  $ssl_mode = ENFORCE_SSL;
1862  }
1863 
1864  if($domain)
1865  {
1866  $domain_key = md5($domain);
1867  }
1868  else
1869  {
1870  $domain_key = 'default';
1871  }
1872 
1873  if(isset($url[$ssl_mode][$domain_key]))
1874  {
1875  return $url[$ssl_mode][$domain_key];
1876  }
1877 
1878  $current_use_ssl = ($_SERVER['HTTPS'] == 'on');
1879 
1880  switch($ssl_mode)
1881  {
1882  case FOLLOW_REQUEST_SSL: $use_ssl = $current_use_ssl;
1883  break;
1884  case ENFORCE_SSL: $use_ssl = TRUE;
1885  break;
1886  case RELEASE_SSL: $use_ssl = FALSE;
1887  break;
1888  }
1889 
1890  if($domain)
1891  {
1892  $target_url = trim($domain);
1893  if(substr_compare($target_url, '/', -1) !== 0)
1894  {
1895  $target_url.= '/';
1896  }
1897  }
1898  else
1899  {
1900  $target_url = $_SERVER['HTTP_HOST'] . getScriptPath();
1901  }
1902 
1903  $url_info = parse_url('http://' . $target_url);
1904 
1905  if($current_use_ssl != $use_ssl)
1906  {
1907  unset($url_info['port']);
1908  }
1909 
1910  if($use_ssl)
1911  {
1912  $port = self::get('_https_port');
1913  if($port && $port != 443)
1914  {
1915  $url_info['port'] = $port;
1916  }
1917  elseif($url_info['port'] == 443)
1918  {
1919  unset($url_info['port']);
1920  }
1921  }
1922  else
1923  {
1924  $port = self::get('_http_port');
1925  if($port && $port != 80)
1926  {
1927  $url_info['port'] = $port;
1928  }
1929  elseif($url_info['port'] == 80)
1930  {
1931  unset($url_info['port']);
1932  }
1933  }
1934 
1935  $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']);
1936 
1937  return $url[$ssl_mode][$domain_key];
1938  }
1939 
1948  function set($key, $val, $set_to_get_vars = 0)
1949  {
1950  $self = self::getInstance();
1951  $self->context->{$key} = $val;
1952  if($set_to_get_vars === FALSE)
1953  {
1954  return;
1955  }
1956  if($val === NULL || $val === '')
1957  {
1958  unset($self->get_vars->{$key});
1959  return;
1960  }
1961  if($set_to_get_vars || $self->get_vars->{$key})
1962  {
1963  $self->get_vars->{$key} = $val;
1964  }
1965  }
1966 
1973  function get($key)
1974  {
1975  $self = self::getInstance();
1976 
1977  if(!isset($self->context->{$key}))
1978  {
1979  return null;
1980  }
1981  return $self->context->{$key};
1982  }
1983 
1989  function gets()
1990  {
1991  $num_args = func_num_args();
1992  if($num_args < 1)
1993  {
1994  return;
1995  }
1996  $self = self::getInstance();
1997 
1998  $args_list = func_get_args();
1999  $output = new stdClass();
2000  foreach($args_list as $v)
2001  {
2002  $output->{$v} = $self->get($v);
2003  }
2004  return $output;
2005  }
2006 
2012  function getAll()
2013  {
2014  $self = self::getInstance();
2015  return $self->context;
2016  }
2017 
2023  function getRequestVars()
2024  {
2025  $self = self::getInstance();
2026  if($self->get_vars)
2027  {
2028  return clone($self->get_vars);
2029  }
2030  return new stdClass;
2031  }
2032 
2039  function addSSLAction($action)
2040  {
2041  $self = self::getInstance();
2042 
2043  if(!is_readable($self->sslActionCacheFile))
2044  {
2045  $buff = '<?php if(!defined("__XE__"))exit;';
2046  FileHandler::writeFile($self->sslActionCacheFile, $buff);
2047  }
2048 
2049  if(!isset($self->ssl_actions[$action]))
2050  {
2051  $self->ssl_actions[$action] = 1;
2052  $sslActionCacheString = sprintf('$sslActions[\'%s\'] = 1;', $action);
2053  FileHandler::writeFile($self->sslActionCacheFile, $sslActionCacheString, 'a');
2054  }
2055  }
2056 
2063  function addSSLActions($action_array)
2064  {
2065  $self = self::getInstance();
2066 
2067  if(!is_readable($self->sslActionCacheFile))
2068  {
2069  unset($self->ssl_actions);
2070  $buff = '<?php if(!defined("__XE__"))exit;';
2071  FileHandler::writeFile($self->sslActionCacheFile, $buff);
2072  }
2073 
2074  foreach($action_array as $action)
2075  {
2076  if(!isset($self->ssl_actions[$action]))
2077  {
2078  $self->ssl_actions[$action] = 1;
2079  $sslActionCacheString = sprintf('$sslActions[\'%s\'] = 1;', $action);
2080  FileHandler::writeFile($self->sslActionCacheFile, $sslActionCacheString, 'a');
2081  }
2082  }
2083  }
2084 
2091  function subtractSSLAction($action)
2092  {
2093  $self = self::getInstance();
2094 
2095  if($self->isExistsSSLAction($action))
2096  {
2097  $sslActionCacheString = sprintf('$sslActions[\'%s\'] = 1;', $action);
2098  $buff = FileHandler::readFile($self->sslActionCacheFile);
2099  $buff = str_replace($sslActionCacheString, '', $buff);
2100  FileHandler::writeFile($self->sslActionCacheFile, $buff);
2101  }
2102  }
2103 
2109  function getSSLActions()
2110  {
2111  $self = self::getInstance();
2112  if($self->getSslStatus() == 'optional')
2113  {
2114  return $self->ssl_actions;
2115  }
2116  }
2117 
2124  function isExistsSSLAction($action)
2125  {
2126  $self = self::getInstance();
2127  return isset($self->ssl_actions[$action]);
2128  }
2129 
2137  function normalizeFilePath($file)
2138  {
2139  if($file{0} != '/' && $file{0} != '.' && strpos($file, '://') === FALSE)
2140  {
2141  $file = './' . $file;
2142  }
2143  $file = preg_replace('@/\./|(?<!:)\/\/@', '/', $file);
2144  while(strpos($file, '/../') !== FALSE)
2145  {
2146  $file = preg_replace('/\/([^\/]+)\/\.\.\//s', '/', $file, 1);
2147  }
2148 
2149  return $file;
2150  }
2151 
2159  function getAbsFileUrl($file)
2160  {
2161  $file = self::normalizeFilePath($file);
2162  $script_path = getScriptPath();
2163  if(strpos($file, './') === 0)
2164  {
2165  $file = $script_path . substr($file, 2);
2166  }
2167  elseif(strpos($file, '../') === 0)
2168  {
2169  $file = self::normalizeFilePath($script_path . $file);
2170  }
2171 
2172  return $file;
2173  }
2174 
2191  function loadFile($args)
2192  {
2193  $self = self::getInstance();
2194 
2195  $self->oFrontEndFileHandler->loadFile($args);
2196  }
2197 
2206  function unloadFile($file, $targetIe = '', $media = 'all')
2207  {
2208  $self = self::getInstance();
2209  $self->oFrontEndFileHandler->unloadFile($file, $targetIe, $media);
2210  }
2211 
2218  function unloadAllFiles($type = 'all')
2219  {
2220  $self = self::getInstance();
2221  $self->oFrontEndFileHandler->unloadAllFiles($type);
2222  }
2223 
2237  function addJsFile($file, $optimized = FALSE, $targetie = '', $index = 0, $type = 'head', $isRuleset = FALSE, $autoPath = null)
2238  {
2239  if($isRuleset)
2240  {
2241  if(strpos($file, '#') !== FALSE)
2242  {
2243  $file = str_replace('#', '', $file);
2244  if(!is_readable($file))
2245  {
2246  $file = $autoPath;
2247  }
2248  }
2249  $validator = new Validator($file);
2250  $validator->setCacheDir('files/cache');
2251  $file = $validator->getJsPath();
2252  }
2253 
2254  $self = self::getInstance();
2255  $self->oFrontEndFileHandler->loadFile(array($file, $type, $targetie, $index));
2256  }
2257 
2267  function unloadJsFile($file, $optimized = FALSE, $targetie = '')
2268  {
2269  $self = self::getInstance();
2270  $self->oFrontEndFileHandler->unloadFile($file, $targetie);
2271  }
2272 
2278  function unloadAllJsFiles()
2279  {
2280  $self = self::getInstance();
2281  $self->oFrontEndFileHandler->unloadAllFiles('js');
2282  }
2283 
2291  function addJsFilter($path, $filename)
2292  {
2293  $oXmlFilter = new XmlJSFilter($path, $filename);
2294  $oXmlFilter->compile();
2295  }
2296 
2304  function _getUniqueFileList($files)
2305  {
2306  ksort($files);
2307  $files = array_values($files);
2308  $filenames = array();
2309  for($i = 0, $c = count($files); $i < $c; ++$i)
2310  {
2311  if(in_array($files[$i]['file'], $filenames))
2312  {
2313  unset($files[$i]);
2314  }
2315  $filenames[] = $files[$i]['file'];
2316  }
2317 
2318  return $files;
2319  }
2320 
2327  function getJsFile($type = 'head')
2328  {
2329  $self = self::getInstance();
2330  return $self->oFrontEndFileHandler->getJsFileList($type);
2331  }
2332 
2345  function addCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '', $index = 0)
2346  {
2347  $self = self::getInstance();
2348  $self->oFrontEndFileHandler->loadFile(array($file, $media, $targetie, $index));
2349  }
2350 
2361  function unloadCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '')
2362  {
2363  $self = self::getInstance();
2364  $self->oFrontEndFileHandler->unloadFile($file, $targetie, $media);
2365  }
2366 
2373  {
2374  $self = self::getInstance();
2375  $self->oFrontEndFileHandler->unloadAllFiles('css');
2376  }
2377 
2383  function getCSSFile()
2384  {
2385  $self = self::getInstance();
2386  return $self->oFrontEndFileHandler->getCssFileList();
2387  }
2388 
2394  function getJavascriptPluginInfo($pluginName)
2395  {
2396  if($plugin_name == 'ui.datepicker')
2397  {
2398  $plugin_name = 'ui';
2399  }
2400 
2401  $plugin_path = './common/js/plugins/' . $pluginName . '/';
2402  $info_file = $plugin_path . 'plugin.load';
2403  if(!is_readable($info_file))
2404  {
2405  return;
2406  }
2407 
2408  $list = file($info_file);
2409  $result = new stdClass();
2410  $result->jsList = array();
2411  $result->cssList = array();
2412 
2413  foreach($list as $filename)
2414  {
2415  $filename = trim($filename);
2416  if(!$filename)
2417  {
2418  continue;
2419  }
2420 
2421  if(strncasecmp('./', $filename, 2) === 0)
2422  {
2423  $filename = substr($filename, 2);
2424  }
2425 
2426  if(substr_compare($filename, '.js', -3) === 0)
2427  {
2428  $result->jsList[] = $plugin_path . $filename;
2429  }
2430  elseif(substr_compare($filename, '.css', -4) === 0)
2431  {
2432  $result->cssList[] = $plugin_path . $filename;
2433  }
2434  }
2435 
2436  if(is_dir($plugin_path . 'lang'))
2437  {
2438  $result->langPath = $plugin_path . 'lang';
2439  }
2440 
2441  return $result;
2442  }
2449  function loadJavascriptPlugin($plugin_name)
2450  {
2451  static $loaded_plugins = array();
2452 
2453  $self = self::getInstance();
2454  if($plugin_name == 'ui.datepicker')
2455  {
2456  $plugin_name = 'ui';
2457  }
2458 
2459  if($loaded_plugins[$plugin_name])
2460  {
2461  return;
2462  }
2463  $loaded_plugins[$plugin_name] = TRUE;
2464 
2465  $plugin_path = './common/js/plugins/' . $plugin_name . '/';
2466  $info_file = $plugin_path . 'plugin.load';
2467  if(!is_readable($info_file))
2468  {
2469  return;
2470  }
2471 
2472  $list = file($info_file);
2473  foreach($list as $filename)
2474  {
2475  $filename = trim($filename);
2476  if(!$filename)
2477  {
2478  continue;
2479  }
2480 
2481  if(strncasecmp('./', $filename, 2) === 0)
2482  {
2483  $filename = substr($filename, 2);
2484  }
2485  if(substr_compare($filename, '.js', -3) === 0)
2486  {
2487  $self->loadFile(array($plugin_path . $filename, 'body', '', 0), TRUE);
2488  }
2489  if(substr_compare($filename, '.css', -4) === 0)
2490  {
2491  $self->loadFile(array($plugin_path . $filename, 'all', '', 0), TRUE);
2492  }
2493  }
2494 
2495  if(is_dir($plugin_path . 'lang'))
2496  {
2497  $self->loadLang($plugin_path . 'lang');
2498  }
2499  }
2500 
2507  function addHtmlHeader($header)
2508  {
2509  $self = self::getInstance();
2510  $self->html_header .= "\n" . $header;
2511  }
2512 
2513  function clearHtmlHeader()
2514  {
2515  $self = self::getInstance();
2516  $self->html_header = '';
2517  }
2518 
2524  function getHtmlHeader()
2525  {
2526  $self = self::getInstance();
2527  return $self->html_header;
2528  }
2529 
2535  function addBodyClass($class_name)
2536  {
2537  $self = self::getInstance();
2538  $self->body_class[] = $class_name;
2539  }
2540 
2546  function getBodyClass()
2547  {
2548  $self = self::getInstance();
2549  $self->body_class = array_unique($self->body_class);
2550 
2551  return (count($self->body_class) > 0) ? sprintf(' class="%s"', join(' ', $self->body_class)) : '';
2552  }
2553 
2559  function addBodyHeader($header)
2560  {
2561  $self = self::getInstance();
2562  $self->body_header .= "\n" . $header;
2563  }
2564 
2570  function getBodyHeader()
2571  {
2572  $self = self::getInstance();
2573  return $self->body_header;
2574  }
2575 
2581  function addHtmlFooter($footer)
2582  {
2583  $self = self::getInstance();
2584  $self->html_footer .= ($self->Htmlfooter ? "\n" : '') . $footer;
2585  }
2586 
2592  function getHtmlFooter()
2593  {
2594  $self = self::getInstance();
2595  return $self->html_footer;
2596  }
2597 
2603  function getConfigFile()
2604  {
2605  return _XE_PATH_ . 'files/config/db.config.php';
2606  }
2607 
2613  function getFTPConfigFile()
2614  {
2615  return _XE_PATH_ . 'files/config/ftp.config.php';
2616  }
2617 
2623  function isInstalled()
2624  {
2625  return FileHandler::hasContent(self::getConfigFile());
2626  }
2627 
2634  function transContent($content)
2635  {
2636  return $content;
2637  }
2638 
2644  function isAllowRewrite()
2645  {
2646  $oContext = self::getInstance();
2647  return $oContext->allow_rewrite;
2648  }
2649 
2656  function pathToUrl($path)
2657  {
2658  $xe = _XE_PATH_;
2659  $path = strtr($path, "\\", "/");
2660 
2661  $base_url = preg_replace('@^https?://[^/]+/?@', '', self::getRequestUri());
2662 
2663  $_xe = explode('/', $xe);
2664  $_path = explode('/', $path);
2665  $_base = explode('/', $base_url);
2666 
2667  if(!$_base[count($_base) - 1])
2668  {
2669  array_pop($_base);
2670  }
2671 
2672  foreach($_xe as $idx => $dir)
2673  {
2674  if($_path[0] != $dir)
2675  {
2676  break;
2677  }
2678  array_shift($_path);
2679  }
2680 
2681  $idx = count($_xe) - $idx - 1;
2682  while($idx--)
2683  {
2684  if(count($_base) > 0)
2685  {
2686  array_shift($_base);
2687  }
2688  else
2689  {
2690  array_unshift($_base, '..');
2691  }
2692  }
2693 
2694  if(count($_base) > 0)
2695  {
2696  array_unshift($_path, join('/', $_base));
2697  }
2698 
2699  $path = '/' . join('/', $_path);
2700  if(substr_compare($path, '/', -1) !== 0)
2701  {
2702  $path .= '/';
2703  }
2704  return $path;
2705  }
2706 
2711  function getMetaTag()
2712  {
2713  $self = self::getInstance();
2714 
2715  if(!is_array($self->meta_tags))
2716  {
2717  $self->meta_tags = array();
2718  }
2719 
2720  $ret = array();
2721  foreach($self->meta_tags as $key => $val)
2722  {
2723  list($name, $is_http_equiv) = explode("\t", $key);
2724  $ret[] = array('name' => $name, 'is_http_equiv' => $is_http_equiv, 'content' => $val);
2725  }
2726 
2727  return $ret;
2728  }
2729 
2738  function addMetaTag($name, $content, $is_http_equiv = FALSE)
2739  {
2740  $self = self::getInstance();
2741  $self->meta_tags[$name . "\t" . ($is_http_equiv ? '1' : '0')] = $content;
2742  }
2743 
2744 }
2745 /* End of file Context.class.php */
2746 /* Location: ./classes/context/Context.class.php */
getUrl($num_args=0, $args_list=array(), $domain=null, $encode=TRUE, $autoEncode=FALSE)
$oModuleModel
Definition: ko.install.php:236
$IDN
Definition: example.php:7
_setXmlRpcArgument()
getController($module_name)
Definition: func.inc.php:90
unloadFile($file, $targetIe= '', $media= 'all')
loadFile($args)
$obj
Definition: ko.install.php:262
setRequestMethod($type= '')
loadLang($path)
getJsFile($type= 'head')
if(file_exists(_XE_PATH_. 'config/config.user.inc.php')) if(!defined('__DEBUG__')) if(!defined('__DEBUG_OUTPUT__')) if(!defined('__DEBUG_PROTECT__')) if(!defined('__DEBUG_PROTECT_IP__')) if(!defined('__DEBUG_DB_OUTPUT__')) if(!defined('__LOG_SLOW_QUERY__')) if(!defined('__LOG_SLOW_TRIGGER__')) if(!defined('__LOG_SLOW_ADDON__')) if(!defined('__LOG_SLOW_WIDGET__')) if(!defined('__DEBUG_QUERY__')) if(!defined('__OB_GZHANDLER_ENABLE__')) if(!defined('__ENABLE_PHPUNIT_TEST__')) if(!defined('__PROXY_SERVER__')) if(!defined('__ERROR_LOG__')) if(!defined('__DISABLE_DEFAULT_CSS__')) if(!defined('__AUTO_OPCACHE_INVALIDATE__')) if((__DEBUG_OUTPUT__==2)&&version_compare(PHP_VERSION, '6.0.0')===-1) if(version_compare(PHP_VERSION, '5.3.0') >=0) $GLOBALS['__xe_autoload_file_map']
Definition: config.inc.php:324
addHtmlHeader($header)
$output
Definition: ko.install.php:193
_evalxmlLang($path)
set($key, $val, $set_to_get_vars=0)
unloadCSSFile($file, $optimized=FALSE, $media= 'all', $targetie= '')
_recursiveCheckVar($val)
static checkSignature($string, $signature)
Check whether a signature is valid.
writeFile($filename, $buff, $mode="w")
_filterRequestVar($key, $val, $do_stripslashes=true, $remove_hack=false)
setBrowserTitle($site_title)
$oFrontEndFileHandler
_loadPhpLang($path)
_getBrowserTitle()
$oContext
Include the necessary configuration files.
Definition: index.php:45
_loadXmlLang($path)
transContent($content)
filter($ip_list, $ip=NULL)
addSSLActions($action_array)
setLang($code, $val)
loadJavascriptPlugin($plugin_name)
checkConvertFlag(&$val, $key=null, $charset=null)
moveFile($source, $target)
pathToUrl($path)
subtractSSLAction($action)
const ENFORCE_SSL
const FOLLOW_REQUEST_SSL
addBodyHeader($header)
const RELEASE_SSL
$args
Definition: ko.install.php:185
setLangType($lang_type= 'ko')
decodeIdna($domain)
isSiteID($domain)
Definition: func.inc.php:495
getScriptPath()
Definition: func.inc.php:1364
addJsFile($file, $optimized=FALSE, $targetie= '', $index=0, $type= 'head', $isRuleset=FALSE, $autoPath=null)
addCSSFile($file, $optimized=FALSE, $media= 'all', $targetie= '', $index=0)
addBrowserTitle($site_title)
getRealPath($source)
loadLangSupported()
getLang($code)
const _XE_PATH_
Definition: config.inc.php:49
readFile($filename)
addSSLAction($action)
convertEncoding($source_obj)
getRequestUri($ssl_mode=FOLLOW_REQUEST_SSL, $domain=null)
& getInstance()
getJavascriptPluginInfo($pluginName)
getModel($module_name)
Definition: func.inc.php:145
addBodyClass($class_name)
loadLangSelected()
doConvertEncoding(&$val, $key=null, $charset)
convertEncodingStr($str)
setDBInfo($db_info)
_getUniqueFileList($files)
getAbsFileUrl($file)
normalizeFilePath($file)
setResponseMethod($method= 'HTML')
addJsFilter($path, $filename)
_setRequestArgument()
_setJSONRequestArgument()
static createSignature($string)
Create a digital signature to verify the authenticity of a string.
$oModuleController
Definition: ko.install.php:287
_filterXmlVars($key, $val)
escape($str, $double_escape=true, $escape_defined_lang_code=false)
Definition: func.inc.php:1799
isCrawler($agent=NULL)
Definition: func.inc.php:1538
addMetaTag($name, $content, $is_http_equiv=FALSE)
unloadJsFile($file, $optimized=FALSE, $targetie= '')
_setUploadedArgument()
addHtmlFooter($footer)
static detectingXEE($xml)
check XML External Entity
static check($file, $filename=null)
isExistsSSLAction($action)
unloadAllFiles($type= 'all')
hasContent($filename)