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:
Complex classes like Xoops often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Xoops, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
34 | class Xoops |
||
35 | { |
||
36 | const VERSION = 'XOOPS 2.6.0-Alpha 3'; |
||
37 | |||
38 | /** |
||
39 | * @var null|Xoops\Core\Session\Manager |
||
40 | */ |
||
41 | public $sessionManager = null; |
||
42 | |||
43 | /** |
||
44 | * @var null|XoopsModule |
||
45 | */ |
||
46 | public $module = null; |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | */ |
||
51 | public $config = array(); |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | public $moduleConfig = array(); |
||
57 | |||
58 | /** |
||
59 | * @var array |
||
60 | */ |
||
61 | public $moduleDirname = ''; |
||
62 | |||
63 | /** |
||
64 | * @var XoopsUser|string |
||
65 | */ |
||
66 | public $user = ''; |
||
67 | |||
68 | /** |
||
69 | * @var bool |
||
70 | */ |
||
71 | public $userIsAdmin = false; |
||
72 | |||
73 | /** |
||
74 | * @var array |
||
75 | */ |
||
76 | public $option = array(); |
||
77 | |||
78 | /** |
||
79 | * @var XoopsTpl|null |
||
80 | */ |
||
81 | private $tpl = null; |
||
82 | |||
83 | /** |
||
84 | * @var XoopsTheme|null |
||
85 | */ |
||
86 | private $theme = null; |
||
87 | |||
88 | /** |
||
89 | * @var array |
||
90 | */ |
||
91 | public $paths = array( |
||
92 | 'XOOPS' => array(), 'www' => array(), 'var' => array(), 'lib' => array(), 'modules' => array(), |
||
93 | 'themes' => array(), 'media' => array() |
||
94 | ); |
||
95 | |||
96 | /** |
||
97 | * @var string |
||
98 | */ |
||
99 | public $tpl_name = ''; |
||
100 | |||
101 | /** |
||
102 | * @var HandlerFactory |
||
103 | */ |
||
104 | private $handlerFactory; |
||
105 | |||
106 | /** |
||
107 | * @var array |
||
108 | */ |
||
109 | private $kernelHandlers = array(); |
||
110 | |||
111 | /** |
||
112 | * @var array |
||
113 | */ |
||
114 | private $moduleHandlers = array(); |
||
115 | |||
116 | /** |
||
117 | * @var null|array |
||
118 | */ |
||
119 | private $activeModules = null; |
||
120 | |||
121 | /** |
||
122 | * @var array |
||
123 | */ |
||
124 | private $moduleConfigs = array(); |
||
125 | |||
126 | /** |
||
127 | * @var bool |
||
128 | */ |
||
129 | public $isAdminSide = false; |
||
130 | |||
131 | /** |
||
132 | * Actual Xoops OS |
||
133 | */ |
||
134 | private function __construct() |
||
157 | |||
158 | /** |
||
159 | * Access the only instance of this class |
||
160 | * |
||
161 | * @return Xoops |
||
162 | */ |
||
163 | 386 | public static function getInstance() |
|
164 | { |
||
165 | 386 | static $instance; |
|
166 | 386 | if (!isset($instance)) { |
|
167 | $class = __CLASS__; |
||
168 | $instance = new $class(); |
||
169 | } |
||
170 | 386 | return $instance; |
|
171 | } |
||
172 | |||
173 | /** |
||
174 | * get database connection instance |
||
175 | * |
||
176 | * @return Xoops\Core\Database\Connection |
||
177 | */ |
||
178 | 138 | public function db() |
|
182 | |||
183 | /** |
||
184 | * get a \Xoops\Core\Cache\Access object for a named cache |
||
185 | * |
||
186 | * @param string $cacheName a named cached pool |
||
187 | * |
||
188 | * @return \Xoops\Core\Cache\Access |
||
189 | */ |
||
190 | 25 | public function cache($cacheName = 'default') |
|
191 | { |
||
192 | 25 | static $cacheManager; |
|
193 | |||
194 | 25 | if (!isset($cacheManager)) { |
|
195 | $cacheManager = new \Xoops\Core\Cache\CacheManager(); |
||
196 | } |
||
197 | |||
198 | 25 | return $cacheManager->getCache($cacheName); |
|
199 | } |
||
200 | |||
201 | /** |
||
202 | * get the system logger instance |
||
203 | * |
||
204 | * @return \Xoops\Core\Logger |
||
205 | */ |
||
206 | 17 | public function logger() |
|
210 | |||
211 | |||
212 | /** |
||
213 | * get the event processor |
||
214 | * |
||
215 | * @return \Xoops\Core\Events instance |
||
216 | */ |
||
217 | 130 | public function events() |
|
221 | |||
222 | /** |
||
223 | * get the asset utility |
||
224 | * |
||
225 | * @return Xoops\Core\Assets instance |
||
226 | */ |
||
227 | 4 | public function assets() |
|
235 | |||
236 | /** |
||
237 | * get the service manager |
||
238 | * |
||
239 | * @param string $service - service name |
||
240 | * |
||
241 | * @return Xoops\Core\Service\Provider instance |
||
242 | */ |
||
243 | 4 | public function service($service) |
|
251 | |||
252 | /** |
||
253 | * provide a common registry instance |
||
254 | * |
||
255 | * @return Xoops\Core\Registry |
||
256 | */ |
||
257 | 3 | public function registry() |
|
265 | |||
266 | /** |
||
267 | * get security instance |
||
268 | * |
||
269 | * @return XoopsSecurity |
||
270 | */ |
||
271 | 4 | public function security() |
|
279 | |||
280 | /** |
||
281 | * get current template engine |
||
282 | * |
||
283 | * @return null|XoopsTpl |
||
284 | */ |
||
285 | 9 | public function tpl() |
|
289 | |||
290 | /** |
||
291 | * set current template engine |
||
292 | * |
||
293 | * @param XoopsTpl $tpl template engine |
||
294 | * |
||
295 | * @return XoopsTpl |
||
296 | */ |
||
297 | 6 | public function setTpl(XoopsTpl $tpl) |
|
301 | |||
302 | /** |
||
303 | * establish the theme |
||
304 | * |
||
305 | * @param null|string $tpl_name base template |
||
306 | * |
||
307 | * @return null|XoopsTheme |
||
308 | */ |
||
309 | 6 | public function theme($tpl_name = null) |
|
351 | |||
352 | /** |
||
353 | * set theme |
||
354 | * |
||
355 | * @param XoopsTheme $theme theme |
||
356 | * |
||
357 | * @return XoopsTheme |
||
358 | */ |
||
359 | 4 | public function setTheme(XoopsTheme $theme) |
|
363 | |||
364 | /** |
||
365 | * Convert a XOOPS path to a physical one |
||
366 | * |
||
367 | * @param string $url url to derive path from |
||
368 | * @param bool $virtual virtual |
||
369 | * |
||
370 | * @return string |
||
371 | */ |
||
372 | 32 | public function path($url, $virtual = false) |
|
393 | |||
394 | /** |
||
395 | * Convert path separators to unix style |
||
396 | * |
||
397 | * @param string $path path to normalize |
||
398 | * |
||
399 | * @return string normalized path |
||
400 | */ |
||
401 | 32 | public function normalizePath($path) |
|
405 | |||
406 | /** |
||
407 | * Convert a XOOPS path to an URL |
||
408 | * |
||
409 | * @param string $url path (or url) |
||
410 | * |
||
411 | * @return string |
||
412 | */ |
||
413 | 5 | public function url($url) |
|
417 | |||
418 | /** |
||
419 | * Build an URL with the specified request params |
||
420 | * |
||
421 | * @param string $url base url |
||
422 | * @param array $params parameters to add to the url |
||
423 | * |
||
424 | * @return string |
||
425 | */ |
||
426 | 1 | public function buildUrl($url, $params = array()) |
|
445 | |||
446 | /** |
||
447 | * Check if a path exists |
||
448 | * |
||
449 | * @param string $path filesystem path |
||
450 | * @param string $error_type error level i.e. Psr\Log\LogLevel |
||
451 | * |
||
452 | * @return string|false |
||
453 | */ |
||
454 | 2 | public function pathExists($path, $error_type) |
|
469 | |||
470 | /** |
||
471 | * Start gzipCompression output buffer |
||
472 | * |
||
473 | * @return void |
||
474 | */ |
||
475 | 1 | public function gzipCompression() |
|
494 | |||
495 | /** |
||
496 | * Translate a path |
||
497 | * |
||
498 | * @return void |
||
499 | */ |
||
500 | 1 | public function pathTranslation() |
|
526 | |||
527 | /** |
||
528 | * Select Theme |
||
529 | * |
||
530 | * @return void |
||
531 | */ |
||
532 | 1 | public function themeSelect() |
|
546 | |||
547 | /** |
||
548 | * Gets module, type and file from a tpl name |
||
549 | * |
||
550 | * @param string $tpl_name in form type:module/filename.tpl |
||
551 | * |
||
552 | * @return array|false associative array of 'tpl_name', 'type', 'module', 'file' |
||
553 | * or false on error |
||
554 | */ |
||
555 | 9 | public function getTplInfo($tpl_name) |
|
597 | |||
598 | /** |
||
599 | * Render Header |
||
600 | * |
||
601 | * @param string|null $tpl_name template name |
||
602 | * |
||
603 | * @return null|boolean |
||
604 | */ |
||
605 | public function header($tpl_name = null) |
||
668 | |||
669 | /** |
||
670 | * Render Footer |
||
671 | * |
||
672 | * @return false|null |
||
673 | */ |
||
674 | public function footer() |
||
701 | |||
702 | /** |
||
703 | * Check if a module is set |
||
704 | * |
||
705 | * @return bool |
||
706 | */ |
||
707 | 12 | public function isModule() |
|
711 | |||
712 | /** |
||
713 | * Check if a user is set |
||
714 | * |
||
715 | * @return bool |
||
716 | */ |
||
717 | 7 | public function isUser() |
|
721 | |||
722 | /** |
||
723 | * Check if user is admin |
||
724 | * |
||
725 | * @return bool |
||
726 | */ |
||
727 | 1 | public function isAdmin() |
|
731 | |||
732 | /** |
||
733 | * Get handler of Block |
||
734 | * |
||
735 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
736 | * |
||
737 | * @return \Xoops\Core\Kernel\Handlers\XoopsBlockHandler |
||
738 | */ |
||
739 | 4 | public function getHandlerBlock($optional = false) |
|
743 | |||
744 | /** |
||
745 | * Get handler of Block Module Link |
||
746 | * |
||
747 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
748 | * |
||
749 | * @return \Xoops\Core\Kernel\Handlers\XoopsBlockModuleLinkHandler |
||
750 | */ |
||
751 | 1 | public function getHandlerBlockModuleLink($optional = false) |
|
755 | |||
756 | /** |
||
757 | * Get handler of Config |
||
758 | * |
||
759 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
760 | * |
||
761 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigHandler |
||
762 | */ |
||
763 | 1 | public function getHandlerConfig($optional = false) |
|
767 | |||
768 | /** |
||
769 | * Get handler of Config Item |
||
770 | * |
||
771 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
772 | * |
||
773 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigItemHandler |
||
774 | */ |
||
775 | 18 | public function getHandlerConfigItem($optional = false) |
|
779 | |||
780 | /** |
||
781 | * Get handler of Config Option |
||
782 | * |
||
783 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
784 | * |
||
785 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigOptionHandler |
||
786 | */ |
||
787 | 18 | public function getHandlerConfigOption($optional = false) |
|
791 | |||
792 | /** |
||
793 | * Get handler of Group |
||
794 | * |
||
795 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
796 | * |
||
797 | * @return \Xoops\Core\Kernel\Handlers\XoopsGroupHandler |
||
798 | */ |
||
799 | 2 | public function getHandlerGroup($optional = false) |
|
803 | |||
804 | /** |
||
805 | * Get handler of Group Permission |
||
806 | * |
||
807 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
808 | * |
||
809 | * @return \Xoops\Core\Kernel\Handlers\XoopsGroupPermHandler |
||
810 | */ |
||
811 | 4 | public function getHandlerGroupPermission($optional = false) |
|
815 | |||
816 | /** |
||
817 | * Get handler of Member |
||
818 | * |
||
819 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
820 | * |
||
821 | * @return \Xoops\Core\Kernel\Handlers\XoopsMemberHandler |
||
822 | */ |
||
823 | 15 | public function getHandlerMember($optional = false) |
|
827 | |||
828 | /** |
||
829 | * Get handler of Membership |
||
830 | * |
||
831 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
832 | * |
||
833 | * @return \Xoops\Core\Kernel\Handlers\XoopsMembershipHandler |
||
834 | */ |
||
835 | 2 | public function getHandlerMembership($optional = false) |
|
839 | |||
840 | /** |
||
841 | * Get handler of Module |
||
842 | * |
||
843 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
844 | * |
||
845 | * @return \Xoops\Core\Kernel\Handlers\XoopsModuleHandler |
||
846 | */ |
||
847 | 10 | public function getHandlerModule($optional = false) |
|
851 | |||
852 | /** |
||
853 | * Get handler of Online |
||
854 | * |
||
855 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
856 | * |
||
857 | * @return \Xoops\Core\Kernel\Handlers\XoopsOnlineHandler |
||
858 | */ |
||
859 | 2 | public function getHandlerOnline($optional = false) |
|
863 | |||
864 | /** |
||
865 | * Get handler of Private Message |
||
866 | * |
||
867 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
868 | * |
||
869 | * @return \Xoops\Core\Kernel\Handlers\XoopsPrivateMessageHandler |
||
870 | */ |
||
871 | 1 | public function getHandlerPrivateMessage($optional = false) |
|
875 | |||
876 | /** |
||
877 | * Get the session manager |
||
878 | * |
||
879 | * @return Xoops\Core\Session\Manager |
||
880 | */ |
||
881 | 1 | public function session() |
|
888 | |||
889 | /** |
||
890 | * Get handler of Template File |
||
891 | * |
||
892 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
893 | * |
||
894 | * @return \Xoops\Core\Kernel\Handlers\XoopsTplFileHandler |
||
895 | */ |
||
896 | 2 | public function getHandlerTplFile($optional = false) |
|
900 | |||
901 | /** |
||
902 | * Get handler of Template Set |
||
903 | * |
||
904 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
905 | * |
||
906 | * @return \Xoops\Core\Kernel\Handlers\XoopsTplSetHandler |
||
907 | */ |
||
908 | 1 | public function getHandlerTplSet($optional = false) |
|
912 | |||
913 | /** |
||
914 | * Get handler of User |
||
915 | * |
||
916 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
917 | * |
||
918 | * @return \Xoops\Core\Kernel\Handlers\XoopsUserHandler |
||
919 | */ |
||
920 | 2 | public function getHandlerUser($optional = false) |
|
924 | |||
925 | /** |
||
926 | * Get handler |
||
927 | * |
||
928 | * @param string $name name of handler |
||
929 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
930 | * |
||
931 | * @return XoopsObjectHandler|XoopsPersistableObjectHandler|null |
||
932 | */ |
||
933 | 59 | protected function getHandler($name, $optional = false) |
|
951 | |||
952 | /** |
||
953 | * Get Module Handler |
||
954 | * |
||
955 | * @param string|null $name name of handler |
||
956 | * @param string|null $module_dir dirname of module |
||
957 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
958 | * |
||
959 | * @return XoopsObjectHandler|XoopsPersistableObjectHandler|bool |
||
960 | */ |
||
961 | 2 | public function getModuleHandler($name = null, $module_dir = null, $optional = false) |
|
990 | |||
991 | /** |
||
992 | * Get Module Form |
||
993 | * |
||
994 | * @param XoopsObject $obj object to populate form |
||
995 | * @param string $name name of form |
||
996 | * @param string $module_dir dirname of associated module |
||
997 | * |
||
998 | * @return Xoops\Form\Form|bool |
||
999 | */ |
||
1000 | 1 | public function getModuleForm($obj, $name, $module_dir = null) |
|
1026 | |||
1027 | /** |
||
1028 | * Get Module Helper |
||
1029 | * |
||
1030 | * @param string $dirname dirname of module |
||
1031 | * |
||
1032 | * @return bool|Xoops\Module\Helper\HelperAbstract |
||
1033 | */ |
||
1034 | 1 | public static function getModuleHelper($dirname) |
|
1038 | |||
1039 | /** |
||
1040 | * XOOPS language loader wrapper |
||
1041 | * Temporary solution, not encouraged to use |
||
1042 | * |
||
1043 | * @param string $name Name of language file to be loaded, without extension |
||
1044 | * @param mixed $domain string: Module dirname; global language file will be loaded if |
||
1045 | * $domain is set to 'global' or not specified |
||
1046 | * array: example; array('Frameworks/moduleclasses/moduleadmin') |
||
1047 | * @param string $language Language to be loaded, current language content will be loaded if not specified |
||
1048 | * |
||
1049 | * @return boolean |
||
1050 | */ |
||
1051 | 7 | public function loadLanguage($name, $domain = '', $language = null) |
|
1074 | |||
1075 | /** |
||
1076 | * loadLocale |
||
1077 | * |
||
1078 | * @param string $domain Module dirname; global language file will be loaded if set to 'global' or not specified |
||
1079 | * @param string $locale Locale to be loaded, current language content will be loaded if not specified |
||
1080 | * |
||
1081 | * @return boolean |
||
1082 | */ |
||
1083 | 4 | public static function loadLocale($domain = null, $locale = null) |
|
1087 | |||
1088 | /** |
||
1089 | * Translate a key value |
||
1090 | * |
||
1091 | * @param string $key constant name |
||
1092 | * @param string $dirname dirname of module (domain) |
||
1093 | * |
||
1094 | * @return string |
||
1095 | */ |
||
1096 | 1 | public function translate($key, $dirname = 'xoops') |
|
1100 | |||
1101 | /** |
||
1102 | * Get active modules from cache file |
||
1103 | * |
||
1104 | * @return array |
||
1105 | */ |
||
1106 | 10 | public function getActiveModules() |
|
1121 | |||
1122 | /** |
||
1123 | * Write active modules to cache file |
||
1124 | * |
||
1125 | * @return array |
||
1126 | */ |
||
1127 | 1 | public function setActiveModules() |
|
1139 | |||
1140 | /** |
||
1141 | * Checks is module is installed and active |
||
1142 | * |
||
1143 | * @param string $dirname module directory |
||
1144 | * |
||
1145 | * @return bool |
||
1146 | */ |
||
1147 | 8 | public function isActiveModule($dirname) |
|
1154 | |||
1155 | /** |
||
1156 | * get module object from module name (dirname) |
||
1157 | * |
||
1158 | * @param string $dirname dirname of the module |
||
1159 | * |
||
1160 | * @return bool|XoopsModule |
||
1161 | */ |
||
1162 | 4 | View Code Duplication | public function getModuleByDirname($dirname) |
1171 | |||
1172 | /** |
||
1173 | * Get Module By Id |
||
1174 | * |
||
1175 | * @param int $id Id of the module |
||
1176 | * |
||
1177 | * @return bool|XoopsModule |
||
1178 | */ |
||
1179 | 1 | View Code Duplication | public function getModuleById($id) |
1188 | |||
1189 | /** |
||
1190 | * Render Simple Header |
||
1191 | * |
||
1192 | * @param bool $closehead true to close the HTML head element |
||
1193 | * |
||
1194 | * @return void |
||
1195 | */ |
||
1196 | 1 | public function simpleHeader($closehead = true) |
|
1244 | |||
1245 | /** |
||
1246 | * Render simpleFooter |
||
1247 | * |
||
1248 | * @return void |
||
1249 | */ |
||
1250 | 2 | public function simpleFooter() |
|
1256 | /** |
||
1257 | * render an alert message to a string |
||
1258 | * |
||
1259 | * @param string $type alert type, one of 'info', 'error', 'success' or 'warning' |
||
1260 | * @param mixed $msg string or array of strings |
||
1261 | * @param string $title title for alert |
||
1262 | * |
||
1263 | * @return string |
||
1264 | */ |
||
1265 | 1 | public function alert($type, $msg, $title = '/') |
|
1319 | |||
1320 | /** |
||
1321 | * Render a confirmation form to a string |
||
1322 | * |
||
1323 | * @param array $hiddens associative array of values used to complete confirmed action |
||
1324 | * @param string $action form action (URL) |
||
1325 | * @param string $msg message to display |
||
1326 | * @param string $submit submit button message |
||
1327 | * @param boolean $addtoken true to add CSRF token |
||
1328 | * |
||
1329 | * @return string rendered confirm message |
||
1330 | */ |
||
1331 | 1 | public function confirm($hiddens, $action, $msg, $submit = '', $addtoken = true) |
|
1357 | |||
1358 | /** |
||
1359 | * Get User Timestamp (kind of pointless, since timestamps are UTC?) |
||
1360 | * |
||
1361 | * @param \DateTime|int $time DateTime object or unix timestamp |
||
1362 | * |
||
1363 | * @return int unix timestamp |
||
1364 | */ |
||
1365 | 1 | public function getUserTimestamp($time) |
|
1370 | |||
1371 | /** |
||
1372 | * Function to calculate server timestamp from user entered time (timestamp) |
||
1373 | * |
||
1374 | * @param int $timestamp time stamp |
||
1375 | * @param null $userTZ timezone |
||
1376 | * |
||
1377 | * @return int |
||
1378 | */ |
||
1379 | 1 | public function userTimeToServerTime($timestamp, $userTZ = null) |
|
1387 | |||
1388 | /** |
||
1389 | * get the groups associated with the current user |
||
1390 | * |
||
1391 | * @return int[] |
||
1392 | */ |
||
1393 | 3 | public function getUserGroups() |
|
1399 | |||
1400 | /** |
||
1401 | * generate a temporary password |
||
1402 | * |
||
1403 | * @return string |
||
1404 | * |
||
1405 | * @todo make better passwords |
||
1406 | */ |
||
1407 | 1 | public function makePass() |
|
1427 | |||
1428 | /** |
||
1429 | * Check Email |
||
1430 | * |
||
1431 | * @param string $email check email |
||
1432 | * @param bool $antispam true if returned email should be have anti-SPAM measures applied |
||
1433 | * |
||
1434 | * @return false|string email address if valid, otherwise false |
||
1435 | */ |
||
1436 | 2 | public function checkEmail($email, $antispam = false) |
|
1447 | |||
1448 | /** |
||
1449 | * formatURL - add default http:// if no valid protocol specified |
||
1450 | * |
||
1451 | * @param string $url full or partial url |
||
1452 | * |
||
1453 | * @return string |
||
1454 | */ |
||
1455 | 1 | public function formatURL($url) |
|
1465 | |||
1466 | /** |
||
1467 | * Function to get banner html tags for use in templates |
||
1468 | * |
||
1469 | * @return string |
||
1470 | */ |
||
1471 | 3 | public function getBanner() |
|
1477 | |||
1478 | /** |
||
1479 | * Function to redirect a user to certain pages |
||
1480 | * |
||
1481 | * @param string $url URL to redirect to |
||
1482 | * @param int $time time to wait (to allow reading message display) |
||
1483 | * @param string $message message to display |
||
1484 | * @param bool $addredirect add xoops_redirect parameter with current URL to the redirect |
||
1485 | * URL - used for return from login redirect |
||
1486 | * @param bool $allowExternalLink allow redirect to external URL |
||
1487 | * |
||
1488 | * @return void |
||
1489 | */ |
||
1490 | public function redirect($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false) |
||
1554 | |||
1555 | /** |
||
1556 | * Do an immediate redirect to the specified url. Use this instead of using PHP's header() |
||
1557 | * directly so that a core.redirect.start event is triggered. An example is debugbar, that |
||
1558 | * stacks data so the details for both original and redirected scripts data are available. |
||
1559 | * |
||
1560 | * @param string $url URL to redirect to |
||
1561 | * |
||
1562 | * @return void |
||
1563 | */ |
||
1564 | public static function simpleRedirect($url) |
||
1571 | |||
1572 | /** |
||
1573 | * Get Environment Value |
||
1574 | * |
||
1575 | * @param string $key key (name) in the environment |
||
1576 | * |
||
1577 | * @return string |
||
1578 | */ |
||
1579 | 8 | public function getEnv($key) |
|
1583 | |||
1584 | /** |
||
1585 | * Function to get css file for a certain themeset |
||
1586 | * |
||
1587 | * @param string $theme theme name |
||
1588 | * |
||
1589 | * @return string |
||
1590 | */ |
||
1591 | 6 | public function getCss($theme = '') |
|
1622 | |||
1623 | /** |
||
1624 | * Get Mailer |
||
1625 | * |
||
1626 | * @return XoopsMailer|XoopsMailerLocale |
||
1627 | */ |
||
1628 | 1 | public function getMailer() |
|
1642 | |||
1643 | /** |
||
1644 | * Get Option |
||
1645 | * |
||
1646 | * @param string $key key (name) of option |
||
1647 | * |
||
1648 | * @return string |
||
1649 | */ |
||
1650 | 4 | public function getOption($key) |
|
1658 | |||
1659 | /** |
||
1660 | * Set Option |
||
1661 | * |
||
1662 | * @param string $key key (name) of option |
||
1663 | * @param null $value value for option |
||
1664 | * |
||
1665 | * @return void |
||
1666 | */ |
||
1667 | 1 | public function setOption($key, $value = null) |
|
1673 | |||
1674 | /** |
||
1675 | * Get Config value |
||
1676 | * |
||
1677 | * @param string $key key (name) of configuration |
||
1678 | * |
||
1679 | * @return mixed |
||
1680 | */ |
||
1681 | 60 | public function getConfig($key) |
|
1685 | |||
1686 | /** |
||
1687 | * Get all Config Values |
||
1688 | * |
||
1689 | * @return array |
||
1690 | */ |
||
1691 | 13 | public function getConfigs() |
|
1695 | |||
1696 | /** |
||
1697 | * Add Config Values |
||
1698 | * |
||
1699 | * @param array $configs array of configs |
||
1700 | * @param string $dirname module name |
||
1701 | * |
||
1702 | * @return void |
||
1703 | */ |
||
1704 | 1 | View Code Duplication | public function addConfigs($configs, $dirname = 'system') |
1714 | |||
1715 | /** |
||
1716 | * Set Config Value |
||
1717 | * |
||
1718 | * @param string $key key (name) of the configuration item |
||
1719 | * @param mixed $value configuration value |
||
1720 | * @param string $dirname dirname of module |
||
1721 | * |
||
1722 | * @return void |
||
1723 | */ |
||
1724 | 9 | View Code Duplication | public function setConfig($key, $value = null, $dirname = 'system') |
1734 | |||
1735 | /** |
||
1736 | * Unset Config Value |
||
1737 | * |
||
1738 | * @param string $key key (name) of the configuration item |
||
1739 | * @param string $dirname dirname of module |
||
1740 | * |
||
1741 | * @return void |
||
1742 | */ |
||
1743 | 3 | public function unsetConfig($key, $dirname = 'system') |
|
1754 | |||
1755 | /** |
||
1756 | * Unset all module configs |
||
1757 | * |
||
1758 | * @return void |
||
1759 | */ |
||
1760 | public function clearModuleConfigsCache() |
||
1764 | |||
1765 | /** |
||
1766 | * getModuleConfig |
||
1767 | * |
||
1768 | * @param string $key config name |
||
1769 | * @param string $dirname module directory |
||
1770 | * |
||
1771 | * @return mixed the value for the named config |
||
1772 | */ |
||
1773 | 63 | public function getModuleConfig($key, $dirname = '') |
|
1791 | |||
1792 | /** |
||
1793 | * Get Module Configs |
||
1794 | * |
||
1795 | * @param string $dirname dirname of module |
||
1796 | * |
||
1797 | * @return array |
||
1798 | */ |
||
1799 | 20 | public function getModuleConfigs($dirname = '') |
|
1830 | |||
1831 | /** |
||
1832 | * Append Config Value |
||
1833 | * |
||
1834 | * @param string $key key (name) of the configuration item |
||
1835 | * @param array $values array of configuration value |
||
1836 | * @param bool $appendWithKey true to add each $value element with associative value |
||
1837 | * false to add $values as a single index element |
||
1838 | * @param string $dirname dirname of module |
||
1839 | * |
||
1840 | * @return void |
||
1841 | */ |
||
1842 | 3 | public function appendConfig($key, array $values, $appendWithKey = false, $dirname = 'system') |
|
1859 | |||
1860 | /** |
||
1861 | * Disables page cache by overriding module cache settings |
||
1862 | * |
||
1863 | * @return void |
||
1864 | */ |
||
1865 | 1 | public function disableModuleCache() |
|
1871 | |||
1872 | /** |
||
1873 | * getBaseDomain |
||
1874 | * |
||
1875 | * Get domain name from a URL. This will check that the domain is valid for registering, |
||
1876 | * preventing return of constructs like 'co.uk' as the domain. See https://publicsuffix.org/ |
||
1877 | * |
||
1878 | * @param string $url URL |
||
1879 | * @param boolean $includeSubdomain true to include include subdomains, |
||
1880 | * default is false registerable domain only |
||
1881 | * @param boolean $returnObject true to return Pdp\Uri\Url\Host object |
||
1882 | * false returns domain as string |
||
1883 | * |
||
1884 | * @return Pdp\Uri\Url\Host|string|null domain, or null if domain is invalid |
||
1885 | */ |
||
1886 | 1 | public function getBaseDomain($url, $includeSubdomain = false, $returnObject = false) |
|
1924 | |||
1925 | /** |
||
1926 | * function to update compiled template file in cache folder |
||
1927 | * |
||
1928 | * @param string $tpl_id template id |
||
1929 | * |
||
1930 | * @return boolean |
||
1931 | */ |
||
1932 | 1 | public function templateTouch($tpl_id) |
|
1945 | |||
1946 | /** |
||
1947 | * Clear the module cache |
||
1948 | * |
||
1949 | * @param int $mid Module ID |
||
1950 | * |
||
1951 | * @return void |
||
1952 | */ |
||
1953 | public function templateClearModuleCache($mid) |
||
1959 | |||
1960 | /** |
||
1961 | * Support for deprecated messages events |
||
1962 | * |
||
1963 | * @param string $message message |
||
1964 | * |
||
1965 | * @return void |
||
1966 | */ |
||
1967 | 15 | public function deprecated($message) |
|
1972 | |||
1973 | /** |
||
1974 | * Support for disabling error reporting |
||
1975 | * |
||
1976 | * @return void |
||
1977 | */ |
||
1978 | 3 | public function disableErrorReporting() |
|
1983 | } |
||
1984 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: