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() |
||
437 | { |
||
438 | session_write_close(); |
||
439 | } |
||
440 | |||
441 | /** |
||
442 | * Load the database information |
||
443 | * |
||
444 | * @return void |
||
445 | */ |
||
446 | function loadDBInfo() |
||
447 | { |
||
448 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
449 | |||
450 | if(!$self->isInstalled()) |
||
451 | { |
||
452 | return; |
||
453 | } |
||
454 | |||
455 | $config_file = $self->getConfigFile(); |
||
456 | if(is_readable($config_file)) |
||
457 | { |
||
458 | include($config_file); |
||
459 | } |
||
460 | |||
461 | // If master_db information does not exist, the config file needs to be updated |
||
462 | if(!isset($db_info->master_db)) |
||
463 | { |
||
464 | $db_info->master_db = array(); |
||
465 | $db_info->master_db["db_type"] = $db_info->db_type; |
||
466 | unset($db_info->db_type); |
||
467 | $db_info->master_db["db_port"] = $db_info->db_port; |
||
468 | unset($db_info->db_port); |
||
469 | $db_info->master_db["db_hostname"] = $db_info->db_hostname; |
||
470 | unset($db_info->db_hostname); |
||
471 | $db_info->master_db["db_password"] = $db_info->db_password; |
||
472 | unset($db_info->db_password); |
||
473 | $db_info->master_db["db_database"] = $db_info->db_database; |
||
474 | unset($db_info->db_database); |
||
475 | $db_info->master_db["db_userid"] = $db_info->db_userid; |
||
476 | unset($db_info->db_userid); |
||
477 | $db_info->master_db["db_table_prefix"] = $db_info->db_table_prefix; |
||
478 | unset($db_info->db_table_prefix); |
||
479 | |||
480 | if(isset($db_info->master_db["db_table_prefix"]) && substr_compare($db_info->master_db["db_table_prefix"], '_', -1) !== 0) |
||
481 | { |
||
482 | $db_info->master_db["db_table_prefix"] .= '_'; |
||
483 | } |
||
484 | |||
485 | $db_info->slave_db = array($db_info->master_db); |
||
486 | $self->setDBInfo($db_info); |
||
487 | |||
488 | $oInstallController = getController('install'); |
||
489 | $oInstallController->makeConfigFile(); |
||
490 | } |
||
491 | |||
492 | if(!$db_info->use_prepared_statements) |
||
493 | { |
||
494 | $db_info->use_prepared_statements = 'Y'; |
||
495 | } |
||
496 | |||
497 | if(!$db_info->time_zone) |
||
498 | $db_info->time_zone = date('O'); |
||
499 | $GLOBALS['_time_zone'] = $db_info->time_zone; |
||
500 | |||
501 | if($db_info->qmail_compatibility != 'Y') |
||
502 | $db_info->qmail_compatibility = 'N'; |
||
503 | $GLOBALS['_qmail_compatibility'] = $db_info->qmail_compatibility; |
||
504 | |||
505 | if(!$db_info->use_db_session) |
||
506 | $db_info->use_db_session = 'N'; |
||
507 | if(!$db_info->use_ssl) |
||
508 | $db_info->use_ssl = 'none'; |
||
509 | $this->set('_use_ssl', $db_info->use_ssl); |
||
510 | |||
511 | $self->set('_http_port', ($db_info->http_port) ? $db_info->http_port : NULL); |
||
512 | $self->set('_https_port', ($db_info->https_port) ? $db_info->https_port : NULL); |
||
513 | |||
514 | if(!$db_info->sitelock_whitelist) { |
||
515 | $db_info->sitelock_whitelist = '127.0.0.1'; |
||
516 | } |
||
517 | |||
518 | if(is_string($db_info->sitelock_whitelist)) { |
||
519 | $db_info->sitelock_whitelist = explode(',', $db_info->sitelock_whitelist); |
||
520 | } |
||
521 | |||
522 | $self->setDBInfo($db_info); |
||
523 | } |
||
524 | |||
525 | /** |
||
526 | * Get DB's db_type |
||
527 | * |
||
528 | * @return string DB's db_type |
||
529 | */ |
||
530 | function getDBType() |
||
531 | { |
||
532 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
533 | return $self->db_info->master_db["db_type"]; |
||
534 | } |
||
535 | |||
536 | /** |
||
537 | * Set DB information |
||
538 | * |
||
539 | * @param object $db_info DB information |
||
540 | * @return void |
||
541 | */ |
||
542 | function setDBInfo($db_info) |
||
543 | { |
||
544 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
545 | $self->db_info = $db_info; |
||
546 | } |
||
547 | |||
548 | /** |
||
549 | * Get DB information |
||
550 | * |
||
551 | * @return object DB information |
||
552 | */ |
||
553 | function getDBInfo() |
||
554 | { |
||
555 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
556 | return $self->db_info; |
||
557 | } |
||
558 | |||
559 | /** |
||
560 | * Return ssl status |
||
561 | * |
||
562 | * @return object SSL status (Optional - none|always|optional) |
||
563 | */ |
||
564 | function getSslStatus() |
||
565 | { |
||
566 | $dbInfo = self::getDBInfo(); |
||
567 | return $dbInfo->use_ssl; |
||
568 | } |
||
569 | |||
570 | /** |
||
571 | * Return default URL |
||
572 | * |
||
573 | * @return string Default URL |
||
574 | */ |
||
575 | function getDefaultUrl() |
||
576 | { |
||
577 | $db_info = self::getDBInfo(); |
||
578 | return $db_info->default_url; |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * Find supported languages |
||
583 | * |
||
584 | * @return array Supported languages |
||
585 | */ |
||
586 | function loadLangSupported() |
||
587 | { |
||
588 | static $lang_supported = null; |
||
589 | View Code Duplication | if(!$lang_supported) |
|
590 | { |
||
591 | $langs = file(_XE_PATH_ . 'common/lang/lang.info'); |
||
592 | foreach($langs as $val) |
||
593 | { |
||
594 | list($lang_prefix, $lang_text) = explode(',', $val); |
||
595 | $lang_text = trim($lang_text); |
||
596 | $lang_supported[$lang_prefix] = $lang_text; |
||
597 | } |
||
598 | } |
||
599 | return $lang_supported; |
||
600 | } |
||
601 | |||
602 | /** |
||
603 | * Find selected languages to serve in the site |
||
604 | * |
||
605 | * @return array Selected languages |
||
606 | */ |
||
607 | function loadLangSelected() |
||
608 | { |
||
609 | static $lang_selected = null; |
||
610 | if(!$lang_selected) |
||
611 | { |
||
612 | $orig_lang_file = _XE_PATH_ . 'common/lang/lang.info'; |
||
613 | $selected_lang_file = _XE_PATH_ . 'files/config/lang_selected.info'; |
||
614 | if(!FileHandler::hasContent($selected_lang_file)) |
||
615 | { |
||
616 | $old_selected_lang_file = _XE_PATH_ . 'files/cache/lang_selected.info'; |
||
617 | FileHandler::moveFile($old_selected_lang_file, $selected_lang_file); |
||
618 | } |
||
619 | |||
620 | if(!FileHandler::hasContent($selected_lang_file)) |
||
621 | { |
||
622 | $buff = FileHandler::readFile($orig_lang_file); |
||
623 | FileHandler::writeFile($selected_lang_file, $buff); |
||
624 | $lang_selected = self::loadLangSupported(); |
||
625 | } |
||
626 | View Code Duplication | else |
|
627 | { |
||
628 | $langs = file($selected_lang_file); |
||
629 | foreach($langs as $val) |
||
630 | { |
||
631 | list($lang_prefix, $lang_text) = explode(',', $val); |
||
632 | $lang_text = trim($lang_text); |
||
633 | $lang_selected[$lang_prefix] = $lang_text; |
||
634 | } |
||
635 | } |
||
636 | } |
||
637 | return $lang_selected; |
||
638 | } |
||
639 | |||
640 | /** |
||
641 | * Single Sign On (SSO) |
||
642 | * |
||
643 | * @return bool True : Module handling is necessary in the control path of current request , False : Otherwise |
||
644 | */ |
||
645 | function checkSSO() |
||
719 | |||
720 | /** |
||
721 | * Check if FTP info is registered |
||
722 | * |
||
723 | * @return bool True: FTP information is registered, False: otherwise |
||
724 | */ |
||
725 | function isFTPRegisted() |
||
726 | { |
||
727 | return file_exists(self::getFTPConfigFile()); |
||
728 | } |
||
729 | |||
730 | /** |
||
731 | * Get FTP information |
||
732 | * |
||
733 | * @return object FTP information |
||
734 | */ |
||
735 | function getFTPInfo() |
||
736 | { |
||
737 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
738 | |||
739 | if(!$self->isFTPRegisted()) |
||
740 | { |
||
741 | return null; |
||
742 | } |
||
743 | |||
744 | include($self->getFTPConfigFile()); |
||
745 | |||
746 | return $ftp_info; |
||
747 | } |
||
748 | |||
749 | /** |
||
750 | * Add string to browser title |
||
751 | * |
||
752 | * @param string $site_title Browser title to be added |
||
753 | * @return void |
||
754 | */ |
||
755 | function addBrowserTitle($site_title) |
||
756 | { |
||
757 | if(!$site_title) |
||
758 | { |
||
759 | return; |
||
760 | } |
||
761 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
762 | |||
763 | if($self->site_title) |
||
764 | { |
||
765 | $self->site_title .= ' - ' . $site_title; |
||
766 | } |
||
767 | else |
||
768 | { |
||
769 | $self->site_title = $site_title; |
||
770 | } |
||
771 | } |
||
772 | |||
773 | /** |
||
774 | * Set string to browser title |
||
775 | * |
||
776 | * @param string $site_title Browser title to be set |
||
777 | * @return void |
||
778 | */ |
||
779 | function setBrowserTitle($site_title) |
||
780 | { |
||
781 | if(!$site_title) |
||
782 | { |
||
783 | return; |
||
784 | } |
||
785 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
786 | $self->site_title = $site_title; |
||
787 | } |
||
788 | |||
789 | /** |
||
790 | * Get browser title |
||
791 | * |
||
792 | * @return string Browser title(htmlspecialchars applied) |
||
793 | */ |
||
794 | function getBrowserTitle() |
||
795 | { |
||
796 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
797 | |||
798 | $oModuleController = getController('module'); |
||
799 | $oModuleController->replaceDefinedLangCode($self->site_title); |
||
800 | |||
801 | return htmlspecialchars($self->site_title, ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE); |
||
802 | } |
||
803 | |||
804 | /** |
||
805 | * Return layout's title |
||
806 | * @return string layout's title |
||
807 | */ |
||
808 | public function getSiteTitle() |
||
809 | { |
||
810 | $oModuleModel = getModel('module'); |
||
811 | $moduleConfig = $oModuleModel->getModuleConfig('module'); |
||
812 | |||
813 | if(isset($moduleConfig->siteTitle)) |
||
814 | { |
||
815 | return $moduleConfig->siteTitle; |
||
816 | } |
||
817 | return ''; |
||
818 | } |
||
819 | |||
820 | /** |
||
821 | * Get browser title |
||
822 | * @deprecated |
||
823 | */ |
||
824 | function _getBrowserTitle() |
||
825 | { |
||
826 | return $this->getBrowserTitle(); |
||
827 | } |
||
828 | |||
829 | /** |
||
830 | * Load language file according to language type |
||
831 | * |
||
832 | * @param string $path Path of the language file |
||
833 | * @return void |
||
834 | */ |
||
835 | function loadLang($path) |
||
836 | { |
||
837 | global $lang; |
||
838 | |||
839 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
840 | if(!$self->lang_type) |
||
841 | { |
||
842 | return; |
||
843 | } |
||
844 | if(!is_object($lang)) |
||
845 | { |
||
846 | $lang = new stdClass; |
||
847 | } |
||
848 | |||
849 | if(!($filename = $self->_loadXmlLang($path))) |
||
850 | { |
||
851 | $filename = $self->_loadPhpLang($path); |
||
852 | } |
||
853 | |||
854 | if(!is_array($self->loaded_lang_files)) |
||
855 | { |
||
856 | $self->loaded_lang_files = array(); |
||
857 | } |
||
858 | if(in_array($filename, $self->loaded_lang_files)) |
||
859 | { |
||
860 | return; |
||
861 | } |
||
862 | |||
863 | if($filename && is_readable($filename)) |
||
864 | { |
||
865 | $self->loaded_lang_files[] = $filename; |
||
866 | include($filename); |
||
867 | } |
||
868 | else |
||
869 | { |
||
870 | $self->_evalxmlLang($path); |
||
871 | } |
||
872 | } |
||
873 | |||
874 | /** |
||
875 | * Evaluation of xml language file |
||
876 | * |
||
877 | * @param string Path of the language file |
||
878 | * @return void |
||
879 | */ |
||
880 | function _evalxmlLang($path) |
||
881 | { |
||
882 | global $lang; |
||
883 | |||
884 | if(!$path) return; |
||
885 | |||
886 | $_path = 'eval://' . $path; |
||
887 | |||
888 | if(in_array($_path, $this->loaded_lang_files)) |
||
889 | { |
||
890 | return; |
||
891 | } |
||
892 | |||
893 | if(substr_compare($path, '/', -1) !== 0) |
||
894 | { |
||
895 | $path .= '/'; |
||
896 | } |
||
897 | |||
898 | $oXmlLangParser = new XmlLangParser($path . 'lang.xml', $this->lang_type); |
||
899 | $content = $oXmlLangParser->getCompileContent(); |
||
900 | |||
901 | if($content) |
||
902 | { |
||
903 | $this->loaded_lang_files[] = $_path; |
||
904 | eval($content); |
||
905 | } |
||
906 | } |
||
907 | |||
908 | /** |
||
909 | * Load language file of xml type |
||
910 | * |
||
911 | * @param string $path Path of the language file |
||
912 | * @return string file name |
||
913 | */ |
||
914 | function _loadXmlLang($path) |
||
915 | { |
||
916 | if(!$path) return; |
||
917 | |||
918 | $oXmlLangParser = new XmlLangParser($path . ((substr_compare($path, '/', -1) !== 0) ? '/' : '') . 'lang.xml', $this->lang_type); |
||
919 | return $oXmlLangParser->compile(); |
||
920 | } |
||
921 | |||
922 | /** |
||
923 | * Load language file of php type |
||
924 | * |
||
925 | * @param string $path Path of the language file |
||
926 | * @return string file name |
||
927 | */ |
||
928 | function _loadPhpLang($path) |
||
929 | { |
||
930 | if(!$path) return; |
||
931 | |||
932 | if(substr_compare($path, '/', -1) !== 0) |
||
933 | { |
||
934 | $path .= '/'; |
||
935 | } |
||
936 | $path_tpl = $path . '%s.lang.php'; |
||
937 | $file = sprintf($path_tpl, $this->lang_type); |
||
938 | |||
939 | $langs = array('ko', 'en'); // this will be configurable. |
||
940 | while(!is_readable($file) && $langs[0]) |
||
941 | { |
||
942 | $file = sprintf($path_tpl, array_shift($langs)); |
||
943 | } |
||
944 | |||
945 | if(!is_readable($file)) |
||
946 | { |
||
947 | return FALSE; |
||
948 | } |
||
949 | return $file; |
||
950 | } |
||
951 | |||
952 | /** |
||
953 | * Set lang_type |
||
954 | * |
||
955 | * @param string $lang_type Language type. |
||
956 | * @return void |
||
957 | */ |
||
958 | function setLangType($lang_type = 'ko') |
||
959 | { |
||
960 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
961 | |||
962 | $self->lang_type = $lang_type; |
||
963 | $self->set('lang_type', $lang_type); |
||
964 | |||
965 | $_SESSION['lang_type'] = $lang_type; |
||
966 | } |
||
967 | |||
968 | /** |
||
969 | * Get lang_type |
||
970 | * |
||
971 | * @return string Language type |
||
972 | */ |
||
973 | function getLangType() |
||
974 | { |
||
975 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
976 | return $self->lang_type; |
||
977 | } |
||
978 | |||
979 | /** |
||
980 | * Return string accoring to the inputed code |
||
981 | * |
||
982 | * @param string $code Language variable name |
||
983 | * @return string If string for the code exists returns it, otherwise returns original code |
||
984 | */ |
||
985 | function getLang($code) |
||
986 | { |
||
987 | if(!$code) |
||
988 | { |
||
989 | return; |
||
990 | } |
||
991 | if($GLOBALS['lang']->{$code}) |
||
992 | { |
||
993 | return $GLOBALS['lang']->{$code}; |
||
994 | } |
||
995 | return $code; |
||
996 | } |
||
997 | |||
998 | /** |
||
999 | * Set data to lang variable |
||
1000 | * |
||
1001 | * @param string $code Language variable name |
||
1002 | * @param string $val `$code`s value |
||
1003 | * @return void |
||
1004 | */ |
||
1005 | function setLang($code, $val) |
||
1006 | { |
||
1007 | if(!isset($GLOBALS['lang'])) |
||
1008 | { |
||
1009 | $GLOBALS['lang'] = new stdClass(); |
||
1010 | } |
||
1011 | $GLOBALS['lang']->{$code} = $val; |
||
1012 | } |
||
1013 | |||
1014 | /** |
||
1015 | * Convert strings of variables in $source_object into UTF-8 |
||
1016 | * |
||
1017 | * @param object $source_obj Conatins strings to convert |
||
1018 | * @return object converted object |
||
1019 | */ |
||
1020 | function convertEncoding($source_obj) |
||
1021 | { |
||
1022 | $charset_list = array( |
||
1023 | 'UTF-8', 'EUC-KR', 'CP949', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS', 'CP932', |
||
1024 | 'EUC-CN', 'HZ', 'GBK', 'GB18030', 'EUC-TW', 'BIG5', 'CP950', 'BIG5-HKSCS', |
||
1025 | 'ISO2022-CN', 'ISO2022-CN-EXT', 'ISO2022-JP', 'ISO2022-JP-2', 'ISO2022-JP-1', |
||
1026 | 'ISO8859-6', 'ISO8859-8', 'JOHAB', 'ISO2022-KR', 'CP1255', 'CP1256', 'CP862', |
||
1027 | 'ASCII', 'ISO8859-1', 'ISO8850-2', 'ISO8850-3', 'ISO8850-4', 'ISO8850-5', |
||
1028 | 'ISO8850-7', 'ISO8850-9', 'ISO8850-10', 'ISO8850-13', 'ISO8850-14', |
||
1029 | 'ISO8850-15', 'ISO8850-16', 'CP1250', 'CP1251', 'CP1252', 'CP1253', 'CP1254', |
||
1030 | 'CP1257', 'CP850', 'CP866', |
||
1031 | ); |
||
1032 | |||
1033 | $obj = clone $source_obj; |
||
1034 | |||
1035 | foreach($charset_list as $charset) |
||
1036 | { |
||
1037 | array_walk($obj,'Context::checkConvertFlag',$charset); |
||
1038 | $flag = self::checkConvertFlag($flag = TRUE); |
||
1039 | if($flag) |
||
1040 | { |
||
1041 | if($charset == 'UTF-8') |
||
1042 | { |
||
1043 | return $obj; |
||
1044 | } |
||
1045 | array_walk($obj,'Context::doConvertEncoding',$charset); |
||
1046 | return $obj; |
||
1047 | } |
||
1048 | } |
||
1049 | return $obj; |
||
1050 | } |
||
1051 | |||
1052 | /** |
||
1053 | * Check flag |
||
1054 | * |
||
1055 | * @param mixed $val |
||
1056 | * @param string $key |
||
1057 | * @param mixed $charset charset |
||
1058 | * @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5 |
||
1059 | * @return void |
||
1060 | */ |
||
1061 | function checkConvertFlag(&$val, $key = null, $charset = null) |
||
1062 | { |
||
1063 | static $flag = TRUE; |
||
1064 | if($charset) |
||
1065 | { |
||
1066 | if(is_array($val)) |
||
1067 | array_walk($val,'Context::checkConvertFlag',$charset); |
||
1068 | else if($val && iconv($charset,$charset,$val)!=$val) $flag = FALSE; |
||
1069 | else $flag = FALSE; |
||
1070 | } |
||
1071 | else |
||
1072 | { |
||
1073 | $return = $flag; |
||
1074 | $flag = TRUE; |
||
1075 | return $return; |
||
1076 | } |
||
1077 | } |
||
1078 | |||
1079 | /** |
||
1080 | * Convert array type variables into UTF-8 |
||
1081 | * |
||
1082 | * @param mixed $val |
||
1083 | * @param string $key |
||
1084 | * @param string $charset character set |
||
1085 | * @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5 |
||
1086 | * @return object converted object |
||
1087 | */ |
||
1088 | function doConvertEncoding(&$val, $key = null, $charset) |
||
1089 | { |
||
1090 | if (is_array($val)) |
||
1091 | { |
||
1092 | array_walk($val,'Context::doConvertEncoding',$charset); |
||
1093 | } |
||
1094 | else $val = iconv($charset,'UTF-8',$val); |
||
1095 | } |
||
1096 | |||
1097 | /** |
||
1098 | * Convert strings into UTF-8 |
||
1099 | * |
||
1100 | * @param string $str String to convert |
||
1101 | * @return string converted string |
||
1102 | */ |
||
1103 | function convertEncodingStr($str) |
||
1104 | { |
||
1105 | if(!$str) return null; |
||
1106 | $obj = new stdClass(); |
||
1107 | $obj->str = $str; |
||
1108 | $obj = self::convertEncoding($obj); |
||
1109 | return $obj->str; |
||
1110 | } |
||
1111 | |||
1112 | function decodeIdna($domain) |
||
1113 | { |
||
1114 | if(strpos($domain, 'xn--') !== FALSE) |
||
1115 | { |
||
1116 | require_once(_XE_PATH_ . 'libs/idna_convert/idna_convert.class.php'); |
||
1117 | $IDN = new idna_convert(array('idn_version' => 2008)); |
||
1118 | $domain = $IDN->decode($domain); |
||
1119 | } |
||
1120 | |||
1121 | return $domain; |
||
1122 | } |
||
1123 | |||
1124 | /** |
||
1125 | * Force to set response method |
||
1126 | * |
||
1127 | * @param string $method Response method. [HTML|XMLRPC|JSON] |
||
1128 | * @return void |
||
1129 | */ |
||
1130 | function setResponseMethod($method = 'HTML') |
||
1131 | { |
||
1132 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
1133 | |||
1134 | $methods = array('HTML' => 1, 'XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
||
1135 | $self->response_method = isset($methods[$method]) ? $method : 'HTML'; |
||
1136 | } |
||
1137 | |||
1138 | /** |
||
1139 | * Get reponse method |
||
1140 | * |
||
1141 | * @return string Response method. If it's not set, returns request method. |
||
1142 | */ |
||
1143 | function getResponseMethod() |
||
1144 | { |
||
1145 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
1146 | |||
1147 | if($self->response_method) |
||
1148 | { |
||
1149 | return $self->response_method; |
||
1150 | } |
||
1151 | |||
1152 | $method = $self->getRequestMethod(); |
||
1153 | $methods = array('HTML' => 1, 'XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); |
||
1154 | |||
1155 | return isset($methods[$method]) ? $method : 'HTML'; |
||
1156 | } |
||
1157 | |||
1158 | /** |
||
1159 | * Determine request method |
||
1160 | * |
||
1161 | * @param string $type Request method. (Optional - GET|POST|XMLRPC|JSON) |
||
1162 | * @return void |
||
1163 | */ |
||
1164 | function setRequestMethod($type = '') |
||
1165 | { |
||
1166 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
1167 | |||
1168 | $self->js_callback_func = $self->getJSCallbackFunc(); |
||
1169 | |||
1170 | ($type && $self->request_method = $type) or |
||
1171 | ((strpos($_SERVER['CONTENT_TYPE'], 'json') || strpos($_SERVER['HTTP_CONTENT_TYPE'], 'json')) && $self->request_method = 'JSON') or |
||
1172 | ($GLOBALS['HTTP_RAW_POST_DATA'] && $self->request_method = 'XMLRPC') or |
||
1173 | ($self->js_callback_func && $self->request_method = 'JS_CALLBACK') or |
||
1174 | ($self->request_method = $_SERVER['REQUEST_METHOD']); |
||
1175 | } |
||
1176 | |||
1177 | /** |
||
1178 | * handle global arguments |
||
1179 | * |
||
1180 | * @return void |
||
1181 | */ |
||
1182 | function _checkGlobalVars() |
||
1183 | { |
||
1184 | $this->_recursiveCheckVar($_SERVER['HTTP_HOST']); |
||
1185 | |||
1186 | $pattern = "/[\,\"\'\{\}\[\]\(\);$]/"; |
||
1187 | if(preg_match($pattern, $_SERVER['HTTP_HOST'])) |
||
1188 | { |
||
1189 | $this->isSuccessInit = FALSE; |
||
1190 | } |
||
1191 | } |
||
1192 | |||
1193 | /** |
||
1194 | * handle request arguments for GET/POST |
||
1195 | * |
||
1196 | * @return void |
||
1197 | */ |
||
1198 | function _setRequestArgument() |
||
1199 | { |
||
1200 | if(!count($_REQUEST)) |
||
1201 | { |
||
1202 | return; |
||
1203 | } |
||
1204 | |||
1205 | $requestMethod = $this->getRequestMethod(); |
||
1206 | foreach($_REQUEST as $key => $val) |
||
1207 | { |
||
1208 | if($val === '' || self::get($key)) |
||
1209 | { |
||
1210 | continue; |
||
1211 | } |
||
1212 | $key = htmlentities($key); |
||
1213 | $val = $this->_filterRequestVar($key, $val); |
||
1214 | |||
1215 | if($requestMethod == 'GET' && isset($_GET[$key])) |
||
1216 | { |
||
1217 | $set_to_vars = TRUE; |
||
1218 | } |
||
1219 | elseif($requestMethod == 'POST' && isset($_POST[$key])) |
||
1220 | { |
||
1221 | $set_to_vars = TRUE; |
||
1222 | } |
||
1223 | elseif($requestMethod == 'JS_CALLBACK' && (isset($_GET[$key]) || isset($_POST[$key]))) |
||
1224 | { |
||
1225 | $set_to_vars = TRUE; |
||
1226 | } |
||
1227 | else |
||
1228 | { |
||
1229 | $set_to_vars = FALSE; |
||
1230 | } |
||
1231 | |||
1232 | if($set_to_vars) |
||
1233 | { |
||
1234 | $this->_recursiveCheckVar($val); |
||
1235 | } |
||
1236 | |||
1237 | $this->set($key, $val, $set_to_vars); |
||
1238 | } |
||
1239 | } |
||
1240 | |||
1241 | function _recursiveCheckVar($val) |
||
1242 | { |
||
1243 | if(is_string($val)) |
||
1244 | { |
||
1245 | foreach($this->patterns as $pattern) |
||
1246 | { |
||
1247 | if(preg_match($pattern, $val)) |
||
1248 | { |
||
1249 | $this->isSuccessInit = FALSE; |
||
1250 | return; |
||
1251 | } |
||
1252 | } |
||
1253 | } |
||
1254 | else if(is_array($val)) |
||
1255 | { |
||
1256 | foreach($val as $val2) |
||
1257 | { |
||
1258 | $this->_recursiveCheckVar($val2); |
||
1259 | } |
||
1260 | } |
||
1261 | } |
||
1262 | |||
1263 | /** |
||
1264 | * Handle request arguments for JSON |
||
1265 | * |
||
1266 | * @return void |
||
1267 | */ |
||
1268 | function _setJSONRequestArgument() |
||
1269 | { |
||
1270 | if($this->getRequestMethod() != 'JSON') |
||
1271 | { |
||
1272 | return; |
||
1273 | } |
||
1274 | |||
1275 | $params = array(); |
||
1276 | parse_str($GLOBALS['HTTP_RAW_POST_DATA'], $params); |
||
1277 | |||
1278 | foreach($params as $key => $val) |
||
1279 | { |
||
1280 | $this->set($key, $this->_filterRequestVar($key, $val, 1), TRUE); |
||
1281 | } |
||
1282 | } |
||
1283 | |||
1284 | /** |
||
1285 | * Handle request arguments for XML RPC |
||
1286 | * |
||
1287 | * @return void |
||
1288 | */ |
||
1289 | function _setXmlRpcArgument() |
||
1290 | { |
||
1291 | if($this->getRequestMethod() != 'XMLRPC') |
||
1292 | { |
||
1293 | return; |
||
1294 | } |
||
1295 | |||
1296 | $xml = $GLOBALS['HTTP_RAW_POST_DATA']; |
||
1297 | if(Security::detectingXEE($xml)) |
||
1298 | { |
||
1299 | header("HTTP/1.0 400 Bad Request"); |
||
1300 | exit; |
||
1301 | } |
||
1302 | |||
1303 | $oXml = new XmlParser(); |
||
1304 | $xml_obj = $oXml->parse($xml); |
||
1305 | |||
1306 | $params = $xml_obj->methodcall->params; |
||
1307 | unset($params->node_name, $params->attrs, $params->body); |
||
1308 | |||
1309 | if(!count(get_object_vars($params))) |
||
1310 | { |
||
1311 | return; |
||
1312 | } |
||
1313 | |||
1314 | foreach($params as $key => $val) |
||
1315 | { |
||
1316 | $this->set($key, $this->_filterXmlVars($key, $val), TRUE); |
||
1317 | } |
||
1318 | } |
||
1319 | |||
1320 | /** |
||
1321 | * Filter xml variables |
||
1322 | * |
||
1323 | * @param string $key Variable key |
||
1324 | * @param object $val Variable value |
||
1325 | * @return mixed filtered value |
||
1326 | */ |
||
1327 | function _filterXmlVars($key, $val) |
||
1328 | { |
||
1329 | if(is_array($val)) |
||
1330 | { |
||
1331 | $stack = array(); |
||
1332 | foreach($val as $k => $v) |
||
1333 | { |
||
1334 | $stack[$k] = $this->_filterXmlVars($k, $v); |
||
1335 | } |
||
1336 | |||
1337 | return $stack; |
||
1338 | } |
||
1339 | |||
1340 | $body = $val->body; |
||
1341 | unset($val->node_name, $val->attrs, $val->body); |
||
1342 | if(!count(get_object_vars($val))) |
||
1343 | { |
||
1344 | return $this->_filterRequestVar($key, $body, 0); |
||
1345 | } |
||
1346 | |||
1347 | $stack = new stdClass(); |
||
1348 | foreach($val as $k => $v) |
||
1349 | { |
||
1350 | $output = $this->_filterXmlVars($k, $v); |
||
1351 | if(is_object($v) && $v->attrs->type == 'array') |
||
1352 | { |
||
1353 | $output = array($output); |
||
1354 | } |
||
1355 | if($k == 'value' && (is_array($v) || $v->attrs->type == 'array')) |
||
1356 | { |
||
1357 | return $output; |
||
1358 | } |
||
1359 | |||
1360 | $stack->{$k} = $output; |
||
1361 | } |
||
1362 | |||
1363 | if(!count(get_object_vars($stack))) |
||
1364 | { |
||
1365 | return NULL; |
||
1366 | } |
||
1367 | |||
1368 | return $stack; |
||
1369 | } |
||
1370 | |||
1371 | /** |
||
1372 | * Filter request variable |
||
1373 | * |
||
1374 | * @see Cast variables, such as _srl, page, and cpage, into interger |
||
1375 | * @param string $key Variable key |
||
1376 | * @param string $val Variable value |
||
1377 | * @param string $do_stripslashes Whether to strip slashes |
||
1378 | * @return mixed filtered value. Type are string or array |
||
1379 | */ |
||
1380 | function _filterRequestVar($key, $val, $do_stripslashes = 1) |
||
1381 | { |
||
1382 | if(!($isArray = is_array($val))) |
||
1383 | { |
||
1384 | $val = array($val); |
||
1385 | } |
||
1386 | |||
1387 | $result = array(); |
||
1388 | foreach($val as $k => $v) |
||
1389 | { |
||
1390 | $k = htmlentities($k); |
||
1391 | if($key === 'page' || $key === 'cpage' || substr_compare($key, 'srl', -3) === 0) |
||
1392 | { |
||
1393 | $result[$k] = !preg_match('/^[0-9,]+$/', $v) ? (int) $v : $v; |
||
1394 | } |
||
1395 | elseif($key === 'mid' || $key === 'search_keyword') |
||
1396 | { |
||
1397 | $result[$k] = htmlspecialchars($v, ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE); |
||
1398 | } |
||
1399 | elseif($key === 'vid') |
||
1400 | { |
||
1401 | $result[$k] = urlencode($v); |
||
1402 | } |
||
1403 | else |
||
1404 | { |
||
1405 | $result[$k] = $v; |
||
1406 | |||
1407 | if($do_stripslashes && version_compare(PHP_VERSION, '5.4.0', '<') && get_magic_quotes_gpc()) |
||
1408 | { |
||
1409 | $result[$k] = stripslashes($result[$k]); |
||
1410 | } |
||
1411 | |||
1412 | if(!is_array($result[$k])) |
||
1413 | { |
||
1414 | $result[$k] = trim($result[$k]); |
||
1415 | } |
||
1416 | } |
||
1417 | } |
||
1418 | |||
1419 | return $isArray ? $result : $result[0]; |
||
1420 | } |
||
1421 | |||
1422 | /** |
||
1423 | * Check if there exists uploaded file |
||
1424 | * |
||
1425 | * @return bool True: exists, False: otherwise |
||
1426 | */ |
||
1427 | function isUploaded() |
||
1428 | { |
||
1429 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
1430 | return $self->is_uploaded; |
||
1431 | } |
||
1432 | |||
1433 | /** |
||
1434 | * Handle uploaded file |
||
1435 | * |
||
1436 | * @return void |
||
1437 | */ |
||
1438 | function _setUploadedArgument() |
||
1439 | { |
||
1440 | if($_SERVER['REQUEST_METHOD'] != 'POST' || !$_FILES || (stripos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') === FALSE && stripos($_SERVER['HTTP_CONTENT_TYPE'], 'multipart/form-data') === FALSE)) |
||
1441 | { |
||
1442 | return; |
||
1443 | } |
||
1444 | |||
1445 | foreach($_FILES as $key => $val) |
||
1446 | { |
||
1447 | $tmp_name = $val['tmp_name']; |
||
1448 | if(!is_array($tmp_name)) |
||
1449 | { |
||
1450 | if(!$tmp_name || !is_uploaded_file($tmp_name)) |
||
1451 | { |
||
1452 | continue; |
||
1453 | } |
||
1454 | $val['name'] = htmlspecialchars($val['name'], ENT_COMPAT | ENT_HTML401, 'UTF-8', FALSE); |
||
1455 | $this->set($key, $val, TRUE); |
||
1456 | $this->is_uploaded = TRUE; |
||
1457 | } |
||
1458 | else |
||
1459 | { |
||
1460 | for($i = 0, $c = count($tmp_name); $i < $c; $i++) |
||
1461 | { |
||
1462 | if($val['size'][$i] > 0) |
||
1463 | { |
||
1464 | $file['name'] = $val['name'][$i]; |
||
1465 | $file['type'] = $val['type'][$i]; |
||
1466 | $file['tmp_name'] = $val['tmp_name'][$i]; |
||
1467 | $file['error'] = $val['error'][$i]; |
||
1468 | $file['size'] = $val['size'][$i]; |
||
1469 | $files[] = $file; |
||
1470 | } |
||
1471 | } |
||
1472 | $this->set($key, $files, TRUE); |
||
1473 | } |
||
1474 | } |
||
1475 | } |
||
1476 | |||
1477 | /** |
||
1478 | * Return request method |
||
1479 | * @return string Request method type. (Optional - GET|POST|XMLRPC|JSON) |
||
1480 | */ |
||
1481 | function getRequestMethod() |
||
1482 | { |
||
1483 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
1484 | return $self->request_method; |
||
1485 | } |
||
1486 | |||
1487 | /** |
||
1488 | * Return request URL |
||
1489 | * @return string request URL |
||
1490 | */ |
||
1491 | function getRequestUrl() |
||
1492 | { |
||
1493 | static $url = null; |
||
1494 | if(is_null($url)) |
||
1495 | { |
||
1496 | $url = self::getRequestUri(); |
||
1497 | if(count($_GET) > 0) |
||
1498 | { |
||
1499 | foreach($_GET as $key => $val) |
||
1500 | { |
||
1501 | $vars[] = $key . '=' . ($val ? urlencode(self::convertEncodingStr($val)) : ''); |
||
1502 | } |
||
1503 | $url .= '?' . join('&', $vars); |
||
1504 | } |
||
1505 | } |
||
1506 | return $url; |
||
1507 | } |
||
1508 | |||
1509 | /** |
||
1510 | * Return js callback func. |
||
1511 | * @return string callback func. |
||
1512 | */ |
||
1513 | function getJSCallbackFunc() |
||
1514 | { |
||
1515 | is_a($this, 'Context') ? $self = $this : $self = self::getInstance(); |
||
1516 | $js_callback_func = isset($_GET['xe_js_callback']) ? $_GET['xe_js_callback'] : $_POST['xe_js_callback']; |
||
1517 | |||
1518 | if(!preg_match('/^[a-z0-9\.]+$/i', $js_callback_func)) |
||
1519 | { |
||
1520 | unset($js_callback_func); |
||
1521 | unset($_GET['xe_js_callback']); |
||
1522 | unset($_POST['xe_js_callback']); |
||
1523 | } |
||
1524 | |||
1525 | return $js_callback_func; |
||
1526 | } |
||
1527 | |||
1528 | /** |
||
1529 | * Make URL with args_list upon request URL |
||
1530 | * |
||
1531 | * @param int $num_args Arguments nums |
||
1532 | * @param array $args_list Argument list for set url |
||
1533 | * @param string $domain Domain |
||
1534 | * @param bool $encode If TRUE, use url encode. |
||
1535 | * @param bool $autoEncode If TRUE, url encode automatically, detailed. Use this option, $encode value should be TRUE |
||
1536 | * @return string URL |
||
1537 | */ |
||
1538 | function getUrl($num_args = 0, $args_list = array(), $domain = null, $encode = TRUE, $autoEncode = FALSE) |
||
1772 | |||
1773 | /** |
||
1774 | * Return after removing an argument on the requested URL |
||
1775 | * |
||
1776 | * @param string $ssl_mode SSL mode |
||
1777 | * @param string $domain Domain |
||
1778 | * @retrun string converted URL |
||
1779 | */ |
||
1780 | function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null) |
||
1781 | { |
||
1782 | static $url = array(); |
||
1783 | |||
1784 | // Check HTTP Request |
||
1785 | if(!isset($_SERVER['SERVER_PROTOCOL'])) |
||
1786 | { |
||
1787 | return; |
||
1788 | } |
||
1789 | |||
1790 | if(self::get('_use_ssl') == 'always') |
||
1791 | { |
||
1792 | $ssl_mode = ENFORCE_SSL; |
||
1793 | } |
||
1794 | |||
1795 | if($domain) |
||
1796 | { |
||
1797 | $domain_key = md5($domain); |
||
1798 | } |
||
1799 | else |
||
1800 | { |
||
1801 | $domain_key = 'default'; |
||
1802 | } |
||
1803 | |||
1804 | if(isset($url[$ssl_mode][$domain_key])) |
||
1805 | { |
||
1806 | return $url[$ssl_mode][$domain_key]; |
||
1807 | } |
||
1808 | |||
1809 | $current_use_ssl = ($_SERVER['HTTPS'] == 'on'); |
||
1810 | |||
1811 | switch($ssl_mode) |
||
1812 | { |
||
1813 | case FOLLOW_REQUEST_SSL: $use_ssl = $current_use_ssl; |
||
1814 | break; |
||
1815 | case ENFORCE_SSL: $use_ssl = TRUE; |
||
1816 | break; |
||
1817 | case RELEASE_SSL: $use_ssl = FALSE; |
||
1818 | break; |
||
1870 | |||
1871 | /** |
||
1872 | * Set a context value with a key |
||
1873 | * |
||
1874 | * @param string $key Key |
||
1875 | * @param string $val Value |
||
1876 | * @param mixed $set_to_get_vars If not FALSE, Set to get vars. |
||
1877 | * @return void |
||
1878 | */ |
||
1879 | function set($key, $val, $set_to_get_vars = 0) |
||
1897 | |||
1898 | /** |
||
1899 | * Return key's value |
||
1900 | * |
||
1901 | * @param string $key Key |
||
1902 | * @return string Key |
||
1903 | */ |
||
1904 | function get($key) |
||
1914 | |||
1915 | /** |
||
1916 | * Get one more vars in object vars with given arguments(key1, key2, key3,...) |
||
1917 | * |
||
1918 | * @return object |
||
1919 | */ |
||
1920 | function gets() |
||
1937 | |||
1938 | /** |
||
1939 | * Return all data |
||
1940 | * |
||
1941 | * @return object All data |
||
1942 | */ |
||
1943 | function getAll() |
||
1948 | |||
1949 | /** |
||
1950 | * Return values from the GET/POST/XMLRPC |
||
1951 | * |
||
1952 | * @return Object Request variables. |
||
1953 | */ |
||
1954 | function getRequestVars() |
||
1963 | |||
1964 | /** |
||
1965 | * Register if an action is to be encrypted by SSL. Those actions are sent to https in common/js/xml_handler.js |
||
1966 | * |
||
1967 | * @param string $action act name |
||
1968 | * @return void |
||
1969 | */ |
||
1970 | function addSSLAction($action) |
||
1987 | |||
1988 | /** |
||
1989 | * Register if actions are to be encrypted by SSL. Those actions are sent to https in common/js/xml_handler.js |
||
1990 | * |
||
1991 | * @param string $action act name |
||
1992 | * @return void |
||
1993 | */ |
||
1994 | function addSSLActions($action_array) |
||
2015 | |||
2016 | /** |
||
2017 | * Delete if action is registerd to be encrypted by SSL. |
||
2018 | * |
||
2019 | * @param string $action act name |
||
2020 | * @return void |
||
2021 | */ |
||
2022 | function subtractSSLAction($action) |
||
2034 | |||
2035 | /** |
||
2036 | * Get SSL Action |
||
2037 | * |
||
2038 | * @return string acts in array |
||
2039 | */ |
||
2040 | function getSSLActions() |
||
2048 | |||
2049 | /** |
||
2050 | * Check SSL action are existed |
||
2051 | * |
||
2052 | * @param string $action act name |
||
2053 | * @return bool If SSL exists, return TRUE. |
||
2054 | */ |
||
2055 | function isExistsSSLAction($action) |
||
2060 | |||
2061 | /** |
||
2062 | * Normalize file path |
||
2063 | * |
||
2064 | * @deprecated |
||
2065 | * @param string $file file path |
||
2066 | * @return string normalized file path |
||
2067 | */ |
||
2068 | function normalizeFilePath($file) |
||
2082 | |||
2083 | /** |
||
2084 | * Get abstract file url |
||
2085 | * |
||
2086 | * @deprecated |
||
2087 | * @param string $file file path |
||
2088 | * @return string Converted file path |
||
2089 | */ |
||
2090 | function getAbsFileUrl($file) |
||
2104 | |||
2105 | /** |
||
2106 | * Load front end file |
||
2107 | * |
||
2108 | * @param array $args array |
||
2109 | * case js : |
||
2110 | * $args[0]: file name, |
||
2111 | * $args[1]: type (head | body), |
||
2112 | * $args[2]: target IE, |
||
2113 | * $args[3]: index |
||
2114 | * case css : |
||
2115 | * $args[0]: file name, |
||
2116 | * $args[1]: media, |
||
2117 | * $args[2]: target IE, |
||
2118 | * $args[3]: index |
||
2119 | * |
||
2120 | */ |
||
2121 | function loadFile($args) |
||
2127 | |||
2128 | /** |
||
2129 | * Unload front end file |
||
2130 | * |
||
2131 | * @param string $file File name with path |
||
2132 | * @param string $targetIe Target IE |
||
2133 | * @param string $media Media query |
||
2134 | * @return void |
||
2135 | */ |
||
2136 | function unloadFile($file, $targetIe = '', $media = 'all') |
||
2141 | |||
2142 | /** |
||
2143 | * Unload front end file all |
||
2144 | * |
||
2145 | * @param string $type Unload target (optional - all|css|js) |
||
2146 | * @return void |
||
2147 | */ |
||
2148 | function unloadAllFiles($type = 'all') |
||
2153 | |||
2154 | /** |
||
2155 | * Add the js file |
||
2156 | * |
||
2157 | * @deprecated |
||
2158 | * @param string $file File name with path |
||
2159 | * @param string $optimized optimized (That seems to not use) |
||
2160 | * @param string $targetie target IE |
||
2161 | * @param string $index index |
||
2162 | * @param string $type Added position. (head:<head>..</head>, body:<body>..</body>) |
||
2163 | * @param bool $isRuleset Use ruleset |
||
2164 | * @param string $autoPath If path not readed, set the path automatically. |
||
2165 | * @return void |
||
2166 | */ |
||
2167 | function addJsFile($file, $optimized = FALSE, $targetie = '', $index = 0, $type = 'head', $isRuleset = FALSE, $autoPath = null) |
||
2187 | |||
2188 | /** |
||
2189 | * Remove the js file |
||
2190 | * |
||
2191 | * @deprecated |
||
2192 | * @param string $file File name with path |
||
2193 | * @param string $optimized optimized (That seems to not use) |
||
2194 | * @param string $targetie target IE |
||
2195 | * @return void |
||
2196 | */ |
||
2197 | function unloadJsFile($file, $optimized = FALSE, $targetie = '') |
||
2202 | |||
2203 | /** |
||
2204 | * Unload all javascript files |
||
2205 | * |
||
2206 | * @return void |
||
2207 | */ |
||
2208 | function unloadAllJsFiles() |
||
2213 | |||
2214 | /** |
||
2215 | * Add javascript filter |
||
2216 | * |
||
2217 | * @param string $path File path |
||
2218 | * @param string $filename File name |
||
2219 | * @return void |
||
2220 | */ |
||
2221 | function addJsFilter($path, $filename) |
||
2226 | |||
2227 | /** |
||
2228 | * Same as array_unique but works only for file subscript |
||
2229 | * |
||
2230 | * @deprecated |
||
2231 | * @param array $files File list |
||
2232 | * @return array File list |
||
2233 | */ |
||
2234 | function _getUniqueFileList($files) |
||
2250 | |||
2251 | /** |
||
2252 | * Returns the list of javascripts that matches the given type. |
||
2253 | * |
||
2254 | * @param string $type Added position. (head:<head>..</head>, body:<body>..</body>) |
||
2255 | * @return array Returns javascript file list. Array contains file, targetie. |
||
2256 | */ |
||
2257 | function getJsFile($type = 'head') |
||
2262 | |||
2263 | /** |
||
2264 | * Add CSS file |
||
2265 | * |
||
2266 | * @deprecated |
||
2267 | * @param string $file File name with path |
||
2268 | * @param string $optimized optimized (That seems to not use) |
||
2269 | * @param string $media Media query |
||
2270 | * @param string $targetie target IE |
||
2271 | * @param string $index index |
||
2272 | * @return void |
||
2273 | * |
||
2274 | */ |
||
2275 | function addCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '', $index = 0) |
||
2280 | |||
2281 | /** |
||
2282 | * Remove css file |
||
2283 | * |
||
2284 | * @deprecated |
||
2285 | * @param string $file File name with path |
||
2286 | * @param string $optimized optimized (That seems to not use) |
||
2287 | * @param string $media Media query |
||
2288 | * @param string $targetie target IE |
||
2289 | * @return void |
||
2290 | */ |
||
2291 | function unloadCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '') |
||
2296 | |||
2297 | /** |
||
2298 | * Unload all css files |
||
2299 | * |
||
2300 | * @return void |
||
2301 | */ |
||
2302 | function unloadAllCSSFiles() |
||
2307 | |||
2308 | /** |
||
2309 | * Return a list of css files |
||
2310 | * |
||
2311 | * @return array Returns css file list. Array contains file, media, targetie. |
||
2312 | */ |
||
2313 | function getCSSFile() |
||
2318 | |||
2319 | /** |
||
2320 | * Returns javascript plugin file info |
||
2321 | * @param string $pluginName |
||
2322 | * @return stdClass |
||
2323 | */ |
||
2324 | function getJavascriptPluginInfo($pluginName) |
||
2373 | /** |
||
2374 | * Load javascript plugin |
||
2375 | * |
||
2376 | * @param string $plugin_name plugin name |
||
2377 | * @return void |
||
2378 | */ |
||
2379 | function loadJavascriptPlugin($plugin_name) |
||
2430 | |||
2431 | /** |
||
2432 | * Add html code before </head> |
||
2433 | * |
||
2434 | * @param string $header add html code before </head>. |
||
2435 | * @return void |
||
2436 | */ |
||
2437 | function addHtmlHeader($header) |
||
2442 | |||
2443 | function clearHtmlHeader() |
||
2448 | |||
2449 | /** |
||
2450 | * Returns added html code by addHtmlHeader() |
||
2451 | * |
||
2452 | * @return string Added html code before </head> |
||
2453 | */ |
||
2454 | function getHtmlHeader() |
||
2459 | |||
2460 | /** |
||
2461 | * Add css class to Html Body |
||
2462 | * |
||
2463 | * @param string $class_name class name |
||
2464 | */ |
||
2465 | function addBodyClass($class_name) |
||
2470 | |||
2471 | /** |
||
2472 | * Return css class to Html Body |
||
2473 | * |
||
2474 | * @return string Return class to html body |
||
2475 | */ |
||
2476 | function getBodyClass() |
||
2483 | |||
2484 | /** |
||
2485 | * Add html code after <body> |
||
2486 | * |
||
2487 | * @param string $header Add html code after <body> |
||
2488 | */ |
||
2489 | function addBodyHeader($header) |
||
2494 | |||
2495 | /** |
||
2496 | * Returns added html code by addBodyHeader() |
||
2497 | * |
||
2498 | * @return string Added html code after <body> |
||
2499 | */ |
||
2500 | function getBodyHeader() |
||
2505 | |||
2506 | /** |
||
2507 | * Add html code before </body> |
||
2508 | * |
||
2509 | * @param string $footer Add html code before </body> |
||
2510 | */ |
||
2511 | function addHtmlFooter($footer) |
||
2516 | |||
2517 | /** |
||
2518 | * Returns added html code by addHtmlHeader() |
||
2519 | * |
||
2520 | * @return string Added html code before </body> |
||
2521 | */ |
||
2522 | function getHtmlFooter() |
||
2527 | |||
2528 | /** |
||
2529 | * Get config file |
||
2530 | * |
||
2531 | * @retrun string The path of the config file that contains database settings |
||
2532 | */ |
||
2533 | function getConfigFile() |
||
2537 | |||
2538 | /** |
||
2539 | * Get FTP config file |
||
2540 | * |
||
2541 | * @return string The path of the config file that contains FTP settings |
||
2542 | */ |
||
2543 | function getFTPConfigFile() |
||
2547 | |||
2548 | /** |
||
2549 | * Checks whether XE is installed |
||
2550 | * |
||
2551 | * @return bool True if the config file exists, otherwise FALSE. |
||
2552 | */ |
||
2553 | function isInstalled() |
||
2557 | |||
2558 | /** |
||
2559 | * Transforms codes about widget or other features into the actual code, deprecatred |
||
2560 | * |
||
2561 | * @param string Transforms codes |
||
2562 | * @return string Transforms codes |
||
2563 | */ |
||
2564 | function transContent($content) |
||
2568 | |||
2569 | /** |
||
2570 | * Check whether it is allowed to use rewrite mod |
||
2571 | * |
||
2572 | * @return bool True if it is allowed to use rewrite mod, otherwise FALSE |
||
2573 | */ |
||
2574 | function isAllowRewrite() |
||
2579 | |||
2580 | /** |
||
2581 | * Converts a local path into an URL |
||
2582 | * |
||
2583 | * @param string $path URL path |
||
2584 | * @return string Converted path |
||
2585 | */ |
||
2586 | function pathToUrl($path) |
||
2636 | |||
2637 | /** |
||
2638 | * Get meta tag |
||
2639 | * @return array The list of meta tags |
||
2640 | */ |
||
2641 | function getMetaTag() |
||
2659 | |||
2660 | /** |
||
2661 | * Add the meta tag |
||
2662 | * |
||
2663 | * @param string $name name of meta tag |
||
2664 | * @param string $content content of meta tag |
||
2665 | * @param mixed $is_http_equiv value of http_equiv |
||
2666 | * @return void |
||
2667 | */ |
||
2668 | function addMetaTag($name, $content, $is_http_equiv = FALSE) |
||
2673 | |||
2674 | } |
||
2675 | /* End of file Context.class.php */ |
||
2677 |