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 | public static function getInstance() |
||
| 172 | |||
| 173 | /** |
||
| 174 | * get database connection instance |
||
| 175 | * |
||
| 176 | * @return Xoops\Core\Database\Connection |
||
| 177 | */ |
||
| 178 | 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 | public function cache($cacheName = 'default') |
||
| 200 | |||
| 201 | /** |
||
| 202 | * get the system logger instance |
||
| 203 | * |
||
| 204 | * @return \Xoops\Core\Logger |
||
| 205 | */ |
||
| 206 | public function logger() |
||
| 210 | |||
| 211 | |||
| 212 | /** |
||
| 213 | * get the event processor |
||
| 214 | * |
||
| 215 | * @return \Xoops\Core\Events instance |
||
| 216 | */ |
||
| 217 | public function events() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * get the asset utility |
||
| 224 | * |
||
| 225 | * @return Xoops\Core\Assets instance |
||
| 226 | */ |
||
| 227 | 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 | public function service($service) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * provide a common registry instance |
||
| 254 | * |
||
| 255 | * @return Xoops\Core\Registry |
||
| 256 | */ |
||
| 257 | public function registry() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * get security instance |
||
| 268 | * |
||
| 269 | * @return XoopsSecurity |
||
| 270 | */ |
||
| 271 | public function security() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * get current template engine |
||
| 282 | * |
||
| 283 | * @return null|XoopsTpl |
||
| 284 | */ |
||
| 285 | public function tpl() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * set current template engine |
||
| 292 | * |
||
| 293 | * @param XoopsTpl $tpl template engine |
||
| 294 | * |
||
| 295 | * @return XoopsTpl |
||
| 296 | */ |
||
| 297 | 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 | public function theme($tpl_name = null) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * set theme |
||
| 353 | * |
||
| 354 | * @param XoopsTheme $theme theme |
||
| 355 | * |
||
| 356 | * @return XoopsTheme |
||
| 357 | */ |
||
| 358 | public function setTheme(XoopsTheme $theme) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Convert a XOOPS path to a physical one |
||
| 365 | * |
||
| 366 | * @param string $url url to derive path from |
||
| 367 | * @param bool $virtual virtual |
||
| 368 | * |
||
| 369 | * @return string |
||
| 370 | */ |
||
| 371 | public function path($url, $virtual = false) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Convert path separators to unix style |
||
| 395 | * |
||
| 396 | * @param string $path path to normalize |
||
| 397 | * |
||
| 398 | * @return string normalized path |
||
| 399 | */ |
||
| 400 | public function normalizePath($path) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Convert a XOOPS path to an URL |
||
| 407 | * |
||
| 408 | * @param string $url path (or url) |
||
| 409 | * |
||
| 410 | * @return string |
||
| 411 | */ |
||
| 412 | public function url($url) |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Build an URL with the specified request params |
||
| 419 | * |
||
| 420 | * @param string $url base url |
||
| 421 | * @param array $params parameters to add to the url |
||
| 422 | * |
||
| 423 | * @return string |
||
| 424 | */ |
||
| 425 | public function buildUrl($url, $params = array()) |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Check if a path exists |
||
| 447 | * |
||
| 448 | * @param string $path filesystem path |
||
| 449 | * @param string $error_type error level i.e. Psr\Log\LogLevel |
||
| 450 | * |
||
| 451 | * @return string|false |
||
| 452 | */ |
||
| 453 | public function pathExists($path, $error_type) |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Start gzipCompression output buffer |
||
| 471 | * |
||
| 472 | * @return void |
||
| 473 | */ |
||
| 474 | public function gzipCompression() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Translate a path |
||
| 496 | * |
||
| 497 | * @return void |
||
| 498 | */ |
||
| 499 | public function pathTranslation() |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Select Theme |
||
| 528 | * |
||
| 529 | * @return void |
||
| 530 | */ |
||
| 531 | public function themeSelect() |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Gets module, type and file from a tpl name |
||
| 548 | * |
||
| 549 | * @param string $tpl_name in form type:module/filename.tpl |
||
| 550 | * |
||
| 551 | * @return array|false associative array of 'tpl_name', 'type', 'module', 'file' |
||
| 552 | * or false on error |
||
| 553 | */ |
||
| 554 | public function getTplInfo($tpl_name) |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Render Header |
||
| 599 | * |
||
| 600 | * @param string|null $tpl_name template name |
||
| 601 | * |
||
| 602 | * @return null|boolean |
||
| 603 | */ |
||
| 604 | public function header($tpl_name = null) |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Render Footer |
||
| 670 | * |
||
| 671 | * @return false|null |
||
| 672 | */ |
||
| 673 | public function footer() |
||
| 700 | |||
| 701 | /** |
||
| 702 | * Check if a module is set |
||
| 703 | * |
||
| 704 | * @return bool |
||
| 705 | */ |
||
| 706 | public function isModule() |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Check if a user is set |
||
| 713 | * |
||
| 714 | * @return bool |
||
| 715 | */ |
||
| 716 | public function isUser() |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Check if user is admin |
||
| 723 | * |
||
| 724 | * @return bool |
||
| 725 | */ |
||
| 726 | public function isAdmin() |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Get handler of Block |
||
| 733 | * |
||
| 734 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 735 | * |
||
| 736 | * @return \Xoops\Core\Kernel\Handlers\XoopsBlockHandler |
||
| 737 | */ |
||
| 738 | public function getHandlerBlock($optional = false) |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Get handler of Block Module Link |
||
| 745 | * |
||
| 746 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 747 | * |
||
| 748 | * @return \Xoops\Core\Kernel\Handlers\XoopsBlockModuleLinkHandler |
||
| 749 | */ |
||
| 750 | public function getHandlerBlockModuleLink($optional = false) |
||
| 754 | |||
| 755 | /** |
||
| 756 | * Get handler of Config |
||
| 757 | * |
||
| 758 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 759 | * |
||
| 760 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigHandler |
||
| 761 | */ |
||
| 762 | public function getHandlerConfig($optional = false) |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Get handler of Config Item |
||
| 769 | * |
||
| 770 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 771 | * |
||
| 772 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigItemHandler |
||
| 773 | */ |
||
| 774 | public function getHandlerConfigItem($optional = false) |
||
| 778 | |||
| 779 | /** |
||
| 780 | * Get handler of Config Option |
||
| 781 | * |
||
| 782 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 783 | * |
||
| 784 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigOptionHandler |
||
| 785 | */ |
||
| 786 | public function getHandlerConfigOption($optional = false) |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Get handler of Group |
||
| 793 | * |
||
| 794 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 795 | * |
||
| 796 | * @return \Xoops\Core\Kernel\Handlers\XoopsGroupHandler |
||
| 797 | */ |
||
| 798 | public function getHandlerGroup($optional = false) |
||
| 802 | |||
| 803 | /** |
||
| 804 | * Get handler of Group Permission |
||
| 805 | * |
||
| 806 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 807 | * |
||
| 808 | * @return \Xoops\Core\Kernel\Handlers\XoopsGroupPermHandler |
||
| 809 | */ |
||
| 810 | public function getHandlerGroupPermission($optional = false) |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Get handler of Member |
||
| 817 | * |
||
| 818 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 819 | * |
||
| 820 | * @return \Xoops\Core\Kernel\Handlers\XoopsMemberHandler |
||
| 821 | */ |
||
| 822 | public function getHandlerMember($optional = false) |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Get handler of Membership |
||
| 829 | * |
||
| 830 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 831 | * |
||
| 832 | * @return \Xoops\Core\Kernel\Handlers\XoopsMembershipHandler |
||
| 833 | */ |
||
| 834 | public function getHandlerMembership($optional = false) |
||
| 838 | |||
| 839 | /** |
||
| 840 | * Get handler of Module |
||
| 841 | * |
||
| 842 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 843 | * |
||
| 844 | * @return \Xoops\Core\Kernel\Handlers\XoopsModuleHandler |
||
| 845 | */ |
||
| 846 | public function getHandlerModule($optional = false) |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Get handler of Online |
||
| 853 | * |
||
| 854 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 855 | * |
||
| 856 | * @return \Xoops\Core\Kernel\Handlers\XoopsOnlineHandler |
||
| 857 | */ |
||
| 858 | public function getHandlerOnline($optional = false) |
||
| 862 | |||
| 863 | /** |
||
| 864 | * Get handler of Private Message |
||
| 865 | * |
||
| 866 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 867 | * |
||
| 868 | * @return \Xoops\Core\Kernel\Handlers\XoopsPrivateMessageHandler |
||
| 869 | */ |
||
| 870 | public function getHandlerPrivateMessage($optional = false) |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Get the session manager |
||
| 877 | * |
||
| 878 | * @return Xoops\Core\Session\Manager |
||
| 879 | */ |
||
| 880 | public function session() |
||
| 887 | |||
| 888 | /** |
||
| 889 | * Get handler of Template File |
||
| 890 | * |
||
| 891 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 892 | * |
||
| 893 | * @return \Xoops\Core\Kernel\Handlers\XoopsTplFileHandler |
||
| 894 | */ |
||
| 895 | public function getHandlerTplFile($optional = false) |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Get handler of Template Set |
||
| 902 | * |
||
| 903 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 904 | * |
||
| 905 | * @return \Xoops\Core\Kernel\Handlers\XoopsTplSetHandler |
||
| 906 | */ |
||
| 907 | public function getHandlerTplSet($optional = false) |
||
| 911 | |||
| 912 | /** |
||
| 913 | * Get handler of User |
||
| 914 | * |
||
| 915 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 916 | * |
||
| 917 | * @return \Xoops\Core\Kernel\Handlers\XoopsUserHandler |
||
| 918 | */ |
||
| 919 | public function getHandlerUser($optional = false) |
||
| 923 | |||
| 924 | /** |
||
| 925 | * Get handler |
||
| 926 | * |
||
| 927 | * @param string $name name of handler |
||
| 928 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 929 | * |
||
| 930 | * @return XoopsObjectHandler|XoopsPersistableObjectHandler|null |
||
| 931 | */ |
||
| 932 | protected function getHandler($name, $optional = false) |
||
| 950 | |||
| 951 | /** |
||
| 952 | * Get Module Handler |
||
| 953 | * |
||
| 954 | * @param string|null $name name of handler |
||
| 955 | * @param string|null $module_dir dirname of module |
||
| 956 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 957 | * |
||
| 958 | * @return XoopsObjectHandler|XoopsPersistableObjectHandler|bool |
||
| 959 | */ |
||
| 960 | public function getModuleHandler($name = null, $module_dir = null, $optional = false) |
||
| 989 | |||
| 990 | /** |
||
| 991 | * Get Module Form |
||
| 992 | * |
||
| 993 | * @param XoopsObject $obj object to populate form |
||
| 994 | * @param string $name name of form |
||
| 995 | * @param string $module_dir dirname of associated module |
||
| 996 | * |
||
| 997 | * @return Xoops\Form\Form|bool |
||
| 998 | */ |
||
| 999 | public function getModuleForm($obj, $name, $module_dir = null) |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Get Module Helper |
||
| 1028 | * |
||
| 1029 | * @param string $dirname dirname of module |
||
| 1030 | * |
||
| 1031 | * @return bool|Xoops\Module\Helper\HelperAbstract |
||
| 1032 | */ |
||
| 1033 | public static function getModuleHelper($dirname) |
||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * XOOPS language loader wrapper |
||
| 1040 | * Temporary solution, not encouraged to use |
||
| 1041 | * |
||
| 1042 | * @param string $name Name of language file to be loaded, without extension |
||
| 1043 | * @param mixed $domain string: Module dirname; global language file will be loaded if |
||
| 1044 | * $domain is set to 'global' or not specified |
||
| 1045 | * array: example; array('Frameworks/moduleclasses/moduleadmin') |
||
| 1046 | * @param string $language Language to be loaded, current language content will be loaded if not specified |
||
| 1047 | * |
||
| 1048 | * @return boolean |
||
| 1049 | */ |
||
| 1050 | public function loadLanguage($name, $domain = '', $language = null) |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * loadLocale |
||
| 1076 | * |
||
| 1077 | * @param string $domain Module dirname; global language file will be loaded if set to 'global' or not specified |
||
| 1078 | * @param string $locale Locale to be loaded, current language content will be loaded if not specified |
||
| 1079 | * |
||
| 1080 | * @return boolean |
||
| 1081 | */ |
||
| 1082 | public static function loadLocale($domain = null, $locale = null) |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Translate a key value |
||
| 1089 | * |
||
| 1090 | * @param string $key constant name |
||
| 1091 | * @param string $dirname dirname of module (domain) |
||
| 1092 | * |
||
| 1093 | * @return string |
||
| 1094 | */ |
||
| 1095 | public function translate($key, $dirname = 'xoops') |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * Get active modules from cache file |
||
| 1102 | * |
||
| 1103 | * @return array |
||
| 1104 | */ |
||
| 1105 | public function getActiveModules() |
||
| 1120 | |||
| 1121 | /** |
||
| 1122 | * Write active modules to cache file |
||
| 1123 | * |
||
| 1124 | * @return array |
||
| 1125 | */ |
||
| 1126 | public function setActiveModules() |
||
| 1138 | |||
| 1139 | /** |
||
| 1140 | * Checks is module is installed and active |
||
| 1141 | * |
||
| 1142 | * @param string $dirname module directory |
||
| 1143 | * |
||
| 1144 | * @return bool |
||
| 1145 | */ |
||
| 1146 | public function isActiveModule($dirname) |
||
| 1153 | |||
| 1154 | /** |
||
| 1155 | * get module object from module name (dirname) |
||
| 1156 | * |
||
| 1157 | * @param string $dirname dirname of the module |
||
| 1158 | * |
||
| 1159 | * @return bool|XoopsModule |
||
| 1160 | */ |
||
| 1161 | View Code Duplication | public function getModuleByDirname($dirname) |
|
| 1170 | |||
| 1171 | /** |
||
| 1172 | * Get Module By Id |
||
| 1173 | * |
||
| 1174 | * @param int $id Id of the module |
||
| 1175 | * |
||
| 1176 | * @return bool|XoopsModule |
||
| 1177 | */ |
||
| 1178 | View Code Duplication | public function getModuleById($id) |
|
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Render Simple Header |
||
| 1190 | * |
||
| 1191 | * @param bool $closehead true to close the HTML head element |
||
| 1192 | * |
||
| 1193 | * @return void |
||
| 1194 | */ |
||
| 1195 | public function simpleHeader($closehead = true) |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Render simpleFooter |
||
| 1243 | * |
||
| 1244 | * @return void |
||
| 1245 | */ |
||
| 1246 | public function simpleFooter() |
||
| 1252 | /** |
||
| 1253 | * render an alert message to a string |
||
| 1254 | * |
||
| 1255 | * @param string $type alert type, one of 'info', 'error', 'success' or 'warning' |
||
| 1256 | * @param mixed $msg string or array of strings |
||
| 1257 | * @param string $title title for alert |
||
| 1258 | * |
||
| 1259 | * @return string |
||
| 1260 | */ |
||
| 1261 | public function alert($type, $msg, $title = '/') |
||
| 1311 | |||
| 1312 | /** |
||
| 1313 | * Render a confirmation form to a string |
||
| 1314 | * |
||
| 1315 | * @param array $hiddens associative array of values used to complete confirmed action |
||
| 1316 | * @param string $action form action (URL) |
||
| 1317 | * @param string $msg message to display |
||
| 1318 | * @param string $submit submit button message |
||
| 1319 | * @param boolean $addtoken true to add CSRF token |
||
| 1320 | * |
||
| 1321 | * @return string rendered confirm message |
||
| 1322 | */ |
||
| 1323 | public function confirm($hiddens, $action, $msg, $submit = '', $addtoken = true) |
||
| 1349 | |||
| 1350 | /** |
||
| 1351 | * Get User Timestamp (kind of pointless, since timestamps are UTC?) |
||
| 1352 | * |
||
| 1353 | * @param \DateTime|int $time DateTime object or unix timestamp |
||
| 1354 | * |
||
| 1355 | * @return int unix timestamp |
||
| 1356 | */ |
||
| 1357 | public function getUserTimestamp($time) |
||
| 1362 | |||
| 1363 | /** |
||
| 1364 | * Function to calculate server timestamp from user entered time (timestamp) |
||
| 1365 | * |
||
| 1366 | * @param int $timestamp time stamp |
||
| 1367 | * @param null $userTZ timezone |
||
| 1368 | * |
||
| 1369 | * @return int |
||
| 1370 | */ |
||
| 1371 | public function userTimeToServerTime($timestamp, $userTZ = null) |
||
| 1379 | |||
| 1380 | /** |
||
| 1381 | * get the groups associated with the current user |
||
| 1382 | * |
||
| 1383 | * @return int[] |
||
| 1384 | */ |
||
| 1385 | public function getUserGroups() |
||
| 1391 | |||
| 1392 | /** |
||
| 1393 | * generate a temporary password |
||
| 1394 | * |
||
| 1395 | * @return string |
||
| 1396 | * |
||
| 1397 | * @todo make better passwords |
||
| 1398 | */ |
||
| 1399 | public function makePass() |
||
| 1419 | |||
| 1420 | /** |
||
| 1421 | * Check Email |
||
| 1422 | * |
||
| 1423 | * @param string $email check email |
||
| 1424 | * @param bool $antispam true if returned email should be have anti-SPAM measures applied |
||
| 1425 | * |
||
| 1426 | * @return false|string email address if valid, otherwise false |
||
| 1427 | */ |
||
| 1428 | public function checkEmail($email, $antispam = false) |
||
| 1439 | |||
| 1440 | /** |
||
| 1441 | * formatURL - add default http:// if no valid protocol specified |
||
| 1442 | * |
||
| 1443 | * @param string $url full or partial url |
||
| 1444 | * |
||
| 1445 | * @return string |
||
| 1446 | */ |
||
| 1447 | public function formatURL($url) |
||
| 1457 | |||
| 1458 | /** |
||
| 1459 | * Function to get banner html tags for use in templates |
||
| 1460 | * |
||
| 1461 | * @return string |
||
| 1462 | */ |
||
| 1463 | public function getBanner() |
||
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Function to redirect a user to certain pages |
||
| 1472 | * |
||
| 1473 | * @param string $url URL to redirect to |
||
| 1474 | * @param int $time time to wait (to allow reading message display) |
||
| 1475 | * @param string $message message to display |
||
| 1476 | * @param bool $addredirect add xoops_redirect parameter with current URL to the redirect |
||
| 1477 | * URL - used for return from login redirect |
||
| 1478 | * @param bool $allowExternalLink allow redirect to external URL |
||
| 1479 | * |
||
| 1480 | * @return void |
||
| 1481 | */ |
||
| 1482 | public function redirect($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false) |
||
| 1546 | |||
| 1547 | /** |
||
| 1548 | * Do an immediate redirect to the specified url. Use this instead of using PHP's header() |
||
| 1549 | * directly so that a core.redirect.start event is triggered. An example is debugbar, that |
||
| 1550 | * stacks data so the details for both original and redirected scripts data are available. |
||
| 1551 | * |
||
| 1552 | * @param string $url URL to redirect to |
||
| 1553 | * |
||
| 1554 | * @return void |
||
| 1555 | */ |
||
| 1556 | public static function simpleRedirect($url) |
||
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Get Environment Value |
||
| 1566 | * |
||
| 1567 | * @param string $key key (name) in the environment |
||
| 1568 | * |
||
| 1569 | * @return string |
||
| 1570 | */ |
||
| 1571 | public function getEnv($key) |
||
| 1575 | |||
| 1576 | /** |
||
| 1577 | * Function to get css file for a certain themeset |
||
| 1578 | * |
||
| 1579 | * @param string $theme theme name |
||
| 1580 | * |
||
| 1581 | * @return string |
||
| 1582 | */ |
||
| 1583 | public function getCss($theme = '') |
||
| 1621 | |||
| 1622 | /** |
||
| 1623 | * Get Mailer |
||
| 1624 | * |
||
| 1625 | * @return XoopsMailer|XoopsMailerLocale |
||
| 1626 | */ |
||
| 1627 | public function getMailer() |
||
| 1641 | |||
| 1642 | /** |
||
| 1643 | * Get Option |
||
| 1644 | * |
||
| 1645 | * @param string $key key (name) of option |
||
| 1646 | * |
||
| 1647 | * @return string |
||
| 1648 | */ |
||
| 1649 | public function getOption($key) |
||
| 1657 | |||
| 1658 | /** |
||
| 1659 | * Set Option |
||
| 1660 | * |
||
| 1661 | * @param string $key key (name) of option |
||
| 1662 | * @param null $value value for option |
||
| 1663 | * |
||
| 1664 | * @return void |
||
| 1665 | */ |
||
| 1666 | public function setOption($key, $value = null) |
||
| 1672 | |||
| 1673 | /** |
||
| 1674 | * Get Config value |
||
| 1675 | * |
||
| 1676 | * @param string $key key (name) of configuration |
||
| 1677 | * |
||
| 1678 | * @return mixed |
||
| 1679 | */ |
||
| 1680 | public function getConfig($key) |
||
| 1684 | |||
| 1685 | /** |
||
| 1686 | * Get all Config Values |
||
| 1687 | * |
||
| 1688 | * @return array |
||
| 1689 | */ |
||
| 1690 | public function getConfigs() |
||
| 1694 | |||
| 1695 | /** |
||
| 1696 | * Add Config Values |
||
| 1697 | * |
||
| 1698 | * @param array $configs array of configs |
||
| 1699 | * @param string $dirname module name |
||
| 1700 | * |
||
| 1701 | * @return void |
||
| 1702 | */ |
||
| 1703 | View Code Duplication | public function addConfigs($configs, $dirname = 'system') |
|
| 1713 | |||
| 1714 | /** |
||
| 1715 | * Set Config Value |
||
| 1716 | * |
||
| 1717 | * @param string $key key (name) of the configuration item |
||
| 1718 | * @param mixed $value configuration value |
||
| 1719 | * @param string $dirname dirname of module |
||
| 1720 | * |
||
| 1721 | * @return void |
||
| 1722 | */ |
||
| 1723 | View Code Duplication | public function setConfig($key, $value = null, $dirname = 'system') |
|
| 1733 | |||
| 1734 | /** |
||
| 1735 | * Unset Config Value |
||
| 1736 | * |
||
| 1737 | * @param string $key key (name) of the configuration item |
||
| 1738 | * @param string $dirname dirname of module |
||
| 1739 | * |
||
| 1740 | * @return void |
||
| 1741 | */ |
||
| 1742 | public function unsetConfig($key, $dirname = 'system') |
||
| 1753 | |||
| 1754 | /** |
||
| 1755 | * Unset all module configs |
||
| 1756 | * |
||
| 1757 | * @return void |
||
| 1758 | */ |
||
| 1759 | public function clearModuleConfigsCache() |
||
| 1763 | |||
| 1764 | /** |
||
| 1765 | * getModuleConfig |
||
| 1766 | * |
||
| 1767 | * @param string $key config name |
||
| 1768 | * @param string $dirname module directory |
||
| 1769 | * |
||
| 1770 | * @return mixed the value for the named config |
||
| 1771 | */ |
||
| 1772 | public function getModuleConfig($key, $dirname = '') |
||
| 1790 | |||
| 1791 | /** |
||
| 1792 | * Get Module Configs |
||
| 1793 | * |
||
| 1794 | * @param string $dirname dirname of module |
||
| 1795 | * |
||
| 1796 | * @return array |
||
| 1797 | */ |
||
| 1798 | public function getModuleConfigs($dirname = '') |
||
| 1829 | |||
| 1830 | /** |
||
| 1831 | * Append Config Value |
||
| 1832 | * |
||
| 1833 | * @param string $key key (name) of the configuration item |
||
| 1834 | * @param array $values array of configuration value |
||
| 1835 | * @param bool $appendWithKey true to add each $value element with associative value |
||
| 1836 | * false to add $values as a single index element |
||
| 1837 | * @param string $dirname dirname of module |
||
| 1838 | * |
||
| 1839 | * @return void |
||
| 1840 | */ |
||
| 1841 | public function appendConfig($key, array $values, $appendWithKey = false, $dirname = 'system') |
||
| 1858 | |||
| 1859 | /** |
||
| 1860 | * Disables page cache by overriding module cache settings |
||
| 1861 | * |
||
| 1862 | * @return void |
||
| 1863 | */ |
||
| 1864 | public function disableModuleCache() |
||
| 1870 | |||
| 1871 | /** |
||
| 1872 | * getBaseDomain |
||
| 1873 | * |
||
| 1874 | * Get domain name from a URL. This will check that the domain is valid for registering, |
||
| 1875 | * preventing return of constructs like 'co.uk' as the domain. See https://publicsuffix.org/ |
||
| 1876 | * |
||
| 1877 | * @param string $url URL |
||
| 1878 | * @param boolean $includeSubdomain true to include include subdomains, |
||
| 1879 | * default is false registerable domain only |
||
| 1880 | * @param boolean $returnObject true to return Pdp\Uri\Url\Host object |
||
| 1881 | * false returns domain as string |
||
| 1882 | * |
||
| 1883 | * @return Pdp\Uri\Url\Host|string|null domain, or null if domain is invalid |
||
| 1884 | */ |
||
| 1885 | public function getBaseDomain($url, $includeSubdomain = false, $returnObject = false) |
||
| 1923 | |||
| 1924 | /** |
||
| 1925 | * function to update compiled template file in cache folder |
||
| 1926 | * |
||
| 1927 | * @param string $tpl_id template id |
||
| 1928 | * |
||
| 1929 | * @return boolean |
||
| 1930 | */ |
||
| 1931 | public function templateTouch($tpl_id) |
||
| 1944 | |||
| 1945 | /** |
||
| 1946 | * Clear the module cache |
||
| 1947 | * |
||
| 1948 | * @param int $mid Module ID |
||
| 1949 | * |
||
| 1950 | * @return void |
||
| 1951 | */ |
||
| 1952 | public function templateClearModuleCache($mid) |
||
| 1958 | |||
| 1959 | /** |
||
| 1960 | * Support for deprecated messages events |
||
| 1961 | * |
||
| 1962 | * @param string $message message |
||
| 1963 | * |
||
| 1964 | * @return void |
||
| 1965 | */ |
||
| 1966 | public function deprecated($message) |
||
| 1971 | |||
| 1972 | /** |
||
| 1973 | * Support for disabling error reporting |
||
| 1974 | * |
||
| 1975 | * @return void |
||
| 1976 | */ |
||
| 1977 | public function disableErrorReporting() |
||
| 1982 | } |
||
| 1983 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: