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() |
||
163 | { |
||
164 | static $theInstance = null; |
||
165 | if(!$theInstance) |
||
166 | { |
||
167 | $theInstance = new Context(); |
||
168 | } |
||
169 | |||
170 | return $theInstance; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Cunstructor |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | function Context() |
||
|
|||
179 | { |
||
180 | $this->oFrontEndFileHandler = new FrontEndFileHandler(); |
||
181 | $this->get_vars = new stdClass(); |
||
182 | |||
183 | // include ssl action cache file |
||
184 | $this->sslActionCacheFile = FileHandler::getRealPath($this->sslActionCacheFile); |
||
185 | if(is_readable($this->sslActionCacheFile)) |
||
186 | { |
||
187 | require($this->sslActionCacheFile); |
||
188 | if(isset($sslActions)) |
||
189 | { |
||
190 | $this->ssl_actions = $sslActions; |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * Initialization, it sets DB information, request arguments and so on. |
||
197 | * |
||
198 | * @see This function should be called only once |
||
199 | * @return void |
||
200 | */ |
||
201 | function init() |
||
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() |
||
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) |
||
2107 | |||
2108 | /** |
||
2109 | * Load front end file |
||
2110 | * |
||
2111 | * @param array $args array |
||
2112 | * case js : |
||
2113 | * $args[0]: file name, |
||
2114 | * $args[1]: type (head | body), |
||
2115 | * $args[2]: target IE, |
||
2116 | * $args[3]: index |
||
2117 | * case css : |
||
2118 | * $args[0]: file name, |
||
2119 | * $args[1]: media, |
||
2120 | * $args[2]: target IE, |
||
2121 | * $args[3]: index |
||
2122 | * |
||
2123 | */ |
||
2124 | function loadFile($args) |
||
2125 | { |
||
2126 | $self = self::getInstance(); |
||
2127 | |||
2128 | $self->oFrontEndFileHandler->loadFile($args); |
||
2129 | } |
||
2130 | |||
2131 | /** |
||
2132 | * Unload front end file |
||
2133 | * |
||
2134 | * @param string $file File name with path |
||
2135 | * @param string $targetIe Target IE |
||
2136 | * @param string $media Media query |
||
2137 | * @return void |
||
2138 | */ |
||
2139 | function unloadFile($file, $targetIe = '', $media = 'all') |
||
2140 | { |
||
2141 | $self = self::getInstance(); |
||
2142 | $self->oFrontEndFileHandler->unloadFile($file, $targetIe, $media); |
||
2143 | } |
||
2144 | |||
2145 | /** |
||
2146 | * Unload front end file all |
||
2147 | * |
||
2148 | * @param string $type Unload target (optional - all|css|js) |
||
2149 | * @return void |
||
2150 | */ |
||
2151 | function unloadAllFiles($type = 'all') |
||
2152 | { |
||
2153 | $self = self::getInstance(); |
||
2154 | $self->oFrontEndFileHandler->unloadAllFiles($type); |
||
2155 | } |
||
2156 | |||
2157 | /** |
||
2158 | * Add the js file |
||
2159 | * |
||
2160 | * @deprecated |
||
2161 | * @param string $file File name with path |
||
2162 | * @param string $optimized optimized (That seems to not use) |
||
2163 | * @param string $targetie target IE |
||
2164 | * @param string $index index |
||
2165 | * @param string $type Added position. (head:<head>..</head>, body:<body>..</body>) |
||
2166 | * @param bool $isRuleset Use ruleset |
||
2167 | * @param string $autoPath If path not readed, set the path automatically. |
||
2168 | * @return void |
||
2169 | */ |
||
2170 | function addJsFile($file, $optimized = FALSE, $targetie = '', $index = 0, $type = 'head', $isRuleset = FALSE, $autoPath = null) |
||
2171 | { |
||
2172 | if($isRuleset) |
||
2173 | { |
||
2174 | if(strpos($file, '#') !== FALSE) |
||
2175 | { |
||
2176 | $file = str_replace('#', '', $file); |
||
2177 | if(!is_readable($file)) |
||
2178 | { |
||
2179 | $file = $autoPath; |
||
2180 | } |
||
2181 | } |
||
2182 | $validator = new Validator($file); |
||
2183 | $validator->setCacheDir('files/cache'); |
||
2184 | $file = $validator->getJsPath(); |
||
2185 | } |
||
2186 | |||
2187 | $self = self::getInstance(); |
||
2188 | $self->oFrontEndFileHandler->loadFile(array($file, $type, $targetie, $index)); |
||
2189 | } |
||
2190 | |||
2191 | /** |
||
2192 | * Remove the js file |
||
2193 | * |
||
2194 | * @deprecated |
||
2195 | * @param string $file File name with path |
||
2196 | * @param string $optimized optimized (That seems to not use) |
||
2197 | * @param string $targetie target IE |
||
2198 | * @return void |
||
2199 | */ |
||
2200 | function unloadJsFile($file, $optimized = FALSE, $targetie = '') |
||
2201 | { |
||
2202 | $self = self::getInstance(); |
||
2203 | $self->oFrontEndFileHandler->unloadFile($file, $targetie); |
||
2204 | } |
||
2205 | |||
2206 | /** |
||
2207 | * Unload all javascript files |
||
2208 | * |
||
2209 | * @return void |
||
2210 | */ |
||
2211 | function unloadAllJsFiles() |
||
2212 | { |
||
2213 | $self = self::getInstance(); |
||
2214 | $self->oFrontEndFileHandler->unloadAllFiles('js'); |
||
2215 | } |
||
2216 | |||
2217 | /** |
||
2218 | * Add javascript filter |
||
2219 | * |
||
2220 | * @param string $path File path |
||
2221 | * @param string $filename File name |
||
2222 | * @return void |
||
2223 | */ |
||
2224 | function addJsFilter($path, $filename) |
||
2229 | |||
2230 | /** |
||
2231 | * Same as array_unique but works only for file subscript |
||
2232 | * |
||
2233 | * @deprecated |
||
2234 | * @param array $files File list |
||
2235 | * @return array File list |
||
2236 | */ |
||
2237 | function _getUniqueFileList($files) |
||
2253 | |||
2254 | /** |
||
2255 | * Returns the list of javascripts that matches the given type. |
||
2256 | * |
||
2257 | * @param string $type Added position. (head:<head>..</head>, body:<body>..</body>) |
||
2258 | * @return array Returns javascript file list. Array contains file, targetie. |
||
2259 | */ |
||
2260 | function getJsFile($type = 'head') |
||
2261 | { |
||
2262 | $self = self::getInstance(); |
||
2263 | return $self->oFrontEndFileHandler->getJsFileList($type); |
||
2264 | } |
||
2265 | |||
2266 | /** |
||
2267 | * Add CSS file |
||
2268 | * |
||
2269 | * @deprecated |
||
2270 | * @param string $file File name with path |
||
2271 | * @param string $optimized optimized (That seems to not use) |
||
2272 | * @param string $media Media query |
||
2273 | * @param string $targetie target IE |
||
2274 | * @param string $index index |
||
2275 | * @return void |
||
2276 | * |
||
2277 | */ |
||
2278 | function addCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '', $index = 0) |
||
2279 | { |
||
2280 | $self = self::getInstance(); |
||
2281 | $self->oFrontEndFileHandler->loadFile(array($file, $media, $targetie, $index)); |
||
2282 | } |
||
2283 | |||
2284 | /** |
||
2285 | * Remove css file |
||
2286 | * |
||
2287 | * @deprecated |
||
2288 | * @param string $file File name with path |
||
2289 | * @param string $optimized optimized (That seems to not use) |
||
2290 | * @param string $media Media query |
||
2291 | * @param string $targetie target IE |
||
2292 | * @return void |
||
2293 | */ |
||
2294 | function unloadCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '') |
||
2295 | { |
||
2296 | $self = self::getInstance(); |
||
2297 | $self->oFrontEndFileHandler->unloadFile($file, $targetie, $media); |
||
2298 | } |
||
2299 | |||
2300 | /** |
||
2301 | * Unload all css files |
||
2302 | * |
||
2303 | * @return void |
||
2304 | */ |
||
2305 | function unloadAllCSSFiles() |
||
2306 | { |
||
2307 | $self = self::getInstance(); |
||
2308 | $self->oFrontEndFileHandler->unloadAllFiles('css'); |
||
2309 | } |
||
2310 | |||
2311 | /** |
||
2312 | * Return a list of css files |
||
2313 | * |
||
2314 | * @return array Returns css file list. Array contains file, media, targetie. |
||
2315 | */ |
||
2316 | function getCSSFile() |
||
2317 | { |
||
2318 | $self = self::getInstance(); |
||
2319 | return $self->oFrontEndFileHandler->getCssFileList(); |
||
2320 | } |
||
2321 | |||
2322 | /** |
||
2323 | * Returns javascript plugin file info |
||
2324 | * @param string $pluginName |
||
2325 | * @return stdClass |
||
2326 | */ |
||
2327 | function getJavascriptPluginInfo($pluginName) |
||
2376 | /** |
||
2377 | * Load javascript plugin |
||
2378 | * |
||
2379 | * @param string $plugin_name plugin name |
||
2380 | * @return void |
||
2381 | */ |
||
2382 | function loadJavascriptPlugin($plugin_name) |
||
2383 | { |
||
2384 | static $loaded_plugins = array(); |
||
2385 | |||
2386 | $self = self::getInstance(); |
||
2387 | if($plugin_name == 'ui.datepicker') |
||
2388 | { |
||
2389 | $plugin_name = 'ui'; |
||
2390 | } |
||
2391 | |||
2392 | if($loaded_plugins[$plugin_name]) |
||
2393 | { |
||
2394 | return; |
||
2395 | } |
||
2396 | $loaded_plugins[$plugin_name] = TRUE; |
||
2397 | |||
2398 | $plugin_path = './common/js/plugins/' . $plugin_name . '/'; |
||
2399 | $info_file = $plugin_path . 'plugin.load'; |
||
2400 | if(!is_readable($info_file)) |
||
2401 | { |
||
2402 | return; |
||
2403 | } |
||
2404 | |||
2405 | $list = file($info_file); |
||
2406 | foreach($list as $filename) |
||
2407 | { |
||
2408 | $filename = trim($filename); |
||
2409 | if(!$filename) |
||
2410 | { |
||
2411 | continue; |
||
2412 | } |
||
2413 | |||
2414 | if(strncasecmp('./', $filename, 2) === 0) |
||
2415 | { |
||
2416 | $filename = substr($filename, 2); |
||
2417 | } |
||
2418 | View Code Duplication | if(substr_compare($filename, '.js', -3) === 0) |
|
2419 | { |
||
2420 | $self->loadFile(array($plugin_path . $filename, 'body', '', 0), TRUE); |
||
2421 | } |
||
2422 | View Code Duplication | if(substr_compare($filename, '.css', -4) === 0) |
|
2423 | { |
||
2424 | $self->loadFile(array($plugin_path . $filename, 'all', '', 0), TRUE); |
||
2425 | } |
||
2426 | } |
||
2427 | |||
2428 | if(is_dir($plugin_path . 'lang')) |
||
2429 | { |
||
2430 | $self->loadLang($plugin_path . 'lang'); |
||
2431 | } |
||
2432 | } |
||
2433 | |||
2434 | /** |
||
2435 | * Add html code before </head> |
||
2436 | * |
||
2437 | * @param string $header add html code before </head>. |
||
2438 | * @return void |
||
2439 | */ |
||
2440 | function addHtmlHeader($header) |
||
2441 | { |
||
2442 | $self = self::getInstance(); |
||
2443 | $self->html_header .= "\n" . $header; |
||
2444 | } |
||
2445 | |||
2446 | function clearHtmlHeader() |
||
2447 | { |
||
2448 | $self = self::getInstance(); |
||
2449 | $self->html_header = ''; |
||
2450 | } |
||
2451 | |||
2452 | /** |
||
2453 | * Returns added html code by addHtmlHeader() |
||
2454 | * |
||
2455 | * @return string Added html code before </head> |
||
2456 | */ |
||
2457 | function getHtmlHeader() |
||
2458 | { |
||
2459 | $self = self::getInstance(); |
||
2460 | return $self->html_header; |
||
2461 | } |
||
2462 | |||
2463 | /** |
||
2464 | * Add css class to Html Body |
||
2465 | * |
||
2466 | * @param string $class_name class name |
||
2467 | */ |
||
2468 | function addBodyClass($class_name) |
||
2469 | { |
||
2470 | $self = self::getInstance(); |
||
2471 | $self->body_class[] = $class_name; |
||
2472 | } |
||
2473 | |||
2474 | /** |
||
2475 | * Return css class to Html Body |
||
2476 | * |
||
2477 | * @return string Return class to html body |
||
2478 | */ |
||
2479 | function getBodyClass() |
||
2480 | { |
||
2481 | $self = self::getInstance(); |
||
2482 | $self->body_class = array_unique($self->body_class); |
||
2483 | |||
2484 | return (count($self->body_class) > 0) ? sprintf(' class="%s"', join(' ', $self->body_class)) : ''; |
||
2485 | } |
||
2486 | |||
2487 | /** |
||
2488 | * Add html code after <body> |
||
2489 | * |
||
2490 | * @param string $header Add html code after <body> |
||
2491 | */ |
||
2492 | function addBodyHeader($header) |
||
2493 | { |
||
2494 | $self = self::getInstance(); |
||
2495 | $self->body_header .= "\n" . $header; |
||
2496 | } |
||
2497 | |||
2498 | /** |
||
2499 | * Returns added html code by addBodyHeader() |
||
2500 | * |
||
2501 | * @return string Added html code after <body> |
||
2502 | */ |
||
2503 | function getBodyHeader() |
||
2504 | { |
||
2505 | $self = self::getInstance(); |
||
2506 | return $self->body_header; |
||
2507 | } |
||
2508 | |||
2509 | /** |
||
2510 | * Add html code before </body> |
||
2511 | * |
||
2512 | * @param string $footer Add html code before </body> |
||
2513 | */ |
||
2514 | function addHtmlFooter($footer) |
||
2515 | { |
||
2516 | $self = self::getInstance(); |
||
2517 | $self->html_footer .= ($self->Htmlfooter ? "\n" : '') . $footer; |
||
2518 | } |
||
2519 | |||
2520 | /** |
||
2521 | * Returns added html code by addHtmlHeader() |
||
2522 | * |
||
2523 | * @return string Added html code before </body> |
||
2524 | */ |
||
2525 | function getHtmlFooter() |
||
2526 | { |
||
2527 | $self = self::getInstance(); |
||
2528 | return $self->html_footer; |
||
2529 | } |
||
2530 | |||
2531 | /** |
||
2532 | * Get config file |
||
2533 | * |
||
2534 | * @retrun string The path of the config file that contains database settings |
||
2535 | */ |
||
2536 | function getConfigFile() |
||
2540 | |||
2541 | /** |
||
2542 | * Get FTP config file |
||
2543 | * |
||
2544 | * @return string The path of the config file that contains FTP settings |
||
2545 | */ |
||
2546 | function getFTPConfigFile() |
||
2550 | |||
2551 | /** |
||
2552 | * Checks whether XE is installed |
||
2553 | * |
||
2554 | * @return bool True if the config file exists, otherwise FALSE. |
||
2555 | */ |
||
2556 | function isInstalled() |
||
2560 | |||
2561 | /** |
||
2562 | * Transforms codes about widget or other features into the actual code, deprecatred |
||
2563 | * |
||
2564 | * @param string Transforms codes |
||
2565 | * @return string Transforms codes |
||
2566 | */ |
||
2567 | function transContent($content) |
||
2571 | |||
2572 | /** |
||
2573 | * Check whether it is allowed to use rewrite mod |
||
2574 | * |
||
2575 | * @return bool True if it is allowed to use rewrite mod, otherwise FALSE |
||
2576 | */ |
||
2577 | function isAllowRewrite() |
||
2582 | |||
2583 | /** |
||
2584 | * Converts a local path into an URL |
||
2585 | * |
||
2586 | * @param string $path URL path |
||
2587 | * @return string Converted path |
||
2588 | */ |
||
2589 | function pathToUrl($path) |
||
2639 | |||
2640 | /** |
||
2641 | * Get meta tag |
||
2642 | * @return array The list of meta tags |
||
2643 | */ |
||
2644 | function getMetaTag() |
||
2645 | { |
||
2646 | $self = self::getInstance(); |
||
2647 | |||
2648 | if(!is_array($self->meta_tags)) |
||
2649 | { |
||
2650 | $self->meta_tags = array(); |
||
2651 | } |
||
2652 | |||
2653 | $ret = array(); |
||
2654 | foreach($self->meta_tags as $key => $val) |
||
2655 | { |
||
2656 | list($name, $is_http_equiv) = explode("\t", $key); |
||
2657 | $ret[] = array('name' => $name, 'is_http_equiv' => $is_http_equiv, 'content' => $val); |
||
2658 | } |
||
2659 | |||
2660 | return $ret; |
||
2661 | } |
||
2662 | |||
2663 | /** |
||
2664 | * Add the meta tag |
||
2665 | * |
||
2666 | * @param string $name name of meta tag |
||
2667 | * @param string $content content of meta tag |
||
2668 | * @param mixed $is_http_equiv value of http_equiv |
||
2669 | * @return void |
||
2670 | */ |
||
2671 | function addMetaTag($name, $content, $is_http_equiv = FALSE) |
||
2672 | { |
||
2673 | $self = self::getInstance(); |
||
2674 | $self->meta_tags[$name . "\t" . ($is_http_equiv ? '1' : '0')] = $content; |
||
2675 | } |
||
2676 | |||
2677 | } |
||
2678 | /* End of file Context.class.php */ |
||
2679 | /* Location: ./classes/context/Context.class.php */ |
||
2680 |