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 | 385 | public static function getInstance() |
|
| 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') |
|
| 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 | 129 | public function events() |
|
| 221 | |||
| 222 | /** |
||
| 223 | * Deprecated - use events() instead |
||
| 224 | * |
||
| 225 | * @return XoopsPreload |
||
| 226 | */ |
||
| 227 | 16 | public function preload() |
|
| 231 | |||
| 232 | /** |
||
| 233 | * get the asset utility |
||
| 234 | * |
||
| 235 | * @return Xoops\Core\Assets instance |
||
| 236 | */ |
||
| 237 | 4 | public function assets() |
|
| 245 | |||
| 246 | /** |
||
| 247 | * get the service manager |
||
| 248 | * |
||
| 249 | * @param string $service - service name |
||
| 250 | * |
||
| 251 | * @return Xoops\Core\Service\Provider instance |
||
| 252 | */ |
||
| 253 | 4 | public function service($service) |
|
| 261 | |||
| 262 | /** |
||
| 263 | * provide a common registry instance |
||
| 264 | * |
||
| 265 | * @return Xoops\Core\Registry |
||
| 266 | */ |
||
| 267 | 3 | public function registry() |
|
| 275 | |||
| 276 | /** |
||
| 277 | * get security instance |
||
| 278 | * |
||
| 279 | * @return XoopsSecurity |
||
| 280 | */ |
||
| 281 | 4 | public function security() |
|
| 289 | |||
| 290 | /** |
||
| 291 | * get current template engine |
||
| 292 | * |
||
| 293 | * @return null|XoopsTpl |
||
| 294 | */ |
||
| 295 | 9 | public function tpl() |
|
| 299 | |||
| 300 | /** |
||
| 301 | * set current template engine |
||
| 302 | * |
||
| 303 | * @param XoopsTpl $tpl template engine |
||
| 304 | * |
||
| 305 | * @return XoopsTpl |
||
| 306 | */ |
||
| 307 | 6 | public function setTpl(XoopsTpl $tpl) |
|
| 311 | |||
| 312 | /** |
||
| 313 | * establish the theme |
||
| 314 | * |
||
| 315 | * @param null|string $tpl_name base template |
||
| 316 | * |
||
| 317 | * @return null|XoopsTheme |
||
| 318 | */ |
||
| 319 | 6 | public function theme($tpl_name = null) |
|
| 361 | |||
| 362 | /** |
||
| 363 | * set theme |
||
| 364 | * |
||
| 365 | * @param XoopsTheme $theme theme |
||
| 366 | * |
||
| 367 | * @return XoopsTheme |
||
| 368 | */ |
||
| 369 | 4 | public function setTheme(XoopsTheme $theme) |
|
| 373 | |||
| 374 | /** |
||
| 375 | * Convert a XOOPS path to a physical one |
||
| 376 | * |
||
| 377 | * @param string $url url to derive path from |
||
| 378 | * @param bool $virtual virtual |
||
| 379 | * |
||
| 380 | * @return string |
||
| 381 | */ |
||
| 382 | 32 | public function path($url, $virtual = false) |
|
| 403 | |||
| 404 | /** |
||
| 405 | * Convert path separators to unix style |
||
| 406 | * |
||
| 407 | * @param string $path path to normalize |
||
| 408 | * |
||
| 409 | * @return string normalized path |
||
| 410 | */ |
||
| 411 | 32 | public function normalizePath($path) |
|
| 415 | |||
| 416 | /** |
||
| 417 | * Convert a XOOPS path to an URL |
||
| 418 | * |
||
| 419 | * @param string $url path (or url) |
||
| 420 | * |
||
| 421 | * @return string |
||
| 422 | */ |
||
| 423 | 5 | public function url($url) |
|
| 427 | |||
| 428 | /** |
||
| 429 | * Build an URL with the specified request params |
||
| 430 | * |
||
| 431 | * @param string $url base url |
||
| 432 | * @param array $params parameters to add to the url |
||
| 433 | * |
||
| 434 | * @return string |
||
| 435 | */ |
||
| 436 | 1 | public function buildUrl($url, $params = array()) |
|
| 455 | |||
| 456 | /** |
||
| 457 | * Check if a path exists |
||
| 458 | * |
||
| 459 | * @param string $path filesystem path |
||
| 460 | * @param string $error_type error level i.e. Psr\Log\LogLevel |
||
| 461 | * |
||
| 462 | * @return string|false |
||
| 463 | */ |
||
| 464 | 2 | public function pathExists($path, $error_type) |
|
| 479 | |||
| 480 | /** |
||
| 481 | * Start gzipCompression output buffer |
||
| 482 | * |
||
| 483 | * @return void |
||
| 484 | */ |
||
| 485 | 1 | public function gzipCompression() |
|
| 504 | |||
| 505 | /** |
||
| 506 | * Translate a path |
||
| 507 | * |
||
| 508 | * @return void |
||
| 509 | */ |
||
| 510 | 1 | public function pathTranslation() |
|
| 536 | |||
| 537 | /** |
||
| 538 | * Select Theme |
||
| 539 | * |
||
| 540 | * @return void |
||
| 541 | */ |
||
| 542 | 1 | public function themeSelect() |
|
| 556 | |||
| 557 | /** |
||
| 558 | * Gets module, type and file from a tpl name |
||
| 559 | * |
||
| 560 | * @param string $tpl_name in form type:module/filename.tpl |
||
| 561 | * |
||
| 562 | * @return array|false associative array of 'tpl_name', 'type', 'module', 'file' |
||
| 563 | * or false on error |
||
| 564 | */ |
||
| 565 | 9 | public function getTplInfo($tpl_name) |
|
| 607 | |||
| 608 | /** |
||
| 609 | * Render Header |
||
| 610 | * |
||
| 611 | * @param string|null $tpl_name template name |
||
| 612 | * |
||
| 613 | * @return null|boolean |
||
| 614 | */ |
||
| 615 | public function header($tpl_name = null) |
||
| 678 | |||
| 679 | /** |
||
| 680 | * Render Footer |
||
| 681 | * |
||
| 682 | * @return false|null |
||
| 683 | */ |
||
| 684 | public function footer() |
||
| 711 | |||
| 712 | /** |
||
| 713 | * Check if a module is set |
||
| 714 | * |
||
| 715 | * @return bool |
||
| 716 | */ |
||
| 717 | 12 | public function isModule() |
|
| 721 | |||
| 722 | /** |
||
| 723 | * Check if a user is set |
||
| 724 | * |
||
| 725 | * @return bool |
||
| 726 | */ |
||
| 727 | 7 | public function isUser() |
|
| 731 | |||
| 732 | /** |
||
| 733 | * Check if user is admin |
||
| 734 | * |
||
| 735 | * @return bool |
||
| 736 | */ |
||
| 737 | 1 | public function isAdmin() |
|
| 741 | |||
| 742 | /** |
||
| 743 | * Get handler of Block |
||
| 744 | * |
||
| 745 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 746 | * |
||
| 747 | * @return \Xoops\Core\Kernel\Handlers\XoopsBlockHandler |
||
| 748 | */ |
||
| 749 | 4 | public function getHandlerBlock($optional = false) |
|
| 753 | |||
| 754 | /** |
||
| 755 | * Get handler of Block Module Link |
||
| 756 | * |
||
| 757 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 758 | * |
||
| 759 | * @return \Xoops\Core\Kernel\Handlers\XoopsBlockModuleLinkHandler |
||
| 760 | */ |
||
| 761 | 1 | public function getHandlerBlockModuleLink($optional = false) |
|
| 765 | |||
| 766 | /** |
||
| 767 | * Get handler of Config |
||
| 768 | * |
||
| 769 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 770 | * |
||
| 771 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigHandler |
||
| 772 | */ |
||
| 773 | 1 | public function getHandlerConfig($optional = false) |
|
| 777 | |||
| 778 | /** |
||
| 779 | * Get handler of Config Item |
||
| 780 | * |
||
| 781 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 782 | * |
||
| 783 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigItemHandler |
||
| 784 | */ |
||
| 785 | 18 | public function getHandlerConfigItem($optional = false) |
|
| 789 | |||
| 790 | /** |
||
| 791 | * Get handler of Config Option |
||
| 792 | * |
||
| 793 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 794 | * |
||
| 795 | * @return \Xoops\Core\Kernel\Handlers\XoopsConfigOptionHandler |
||
| 796 | */ |
||
| 797 | 18 | public function getHandlerConfigOption($optional = false) |
|
| 801 | |||
| 802 | /** |
||
| 803 | * Get handler of Group |
||
| 804 | * |
||
| 805 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 806 | * |
||
| 807 | * @return \Xoops\Core\Kernel\Handlers\XoopsGroupHandler |
||
| 808 | */ |
||
| 809 | 2 | public function getHandlerGroup($optional = false) |
|
| 813 | |||
| 814 | /** |
||
| 815 | * Get handler of Group Permission |
||
| 816 | * |
||
| 817 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 818 | * |
||
| 819 | * @return \Xoops\Core\Kernel\Handlers\XoopsGroupPermHandler |
||
| 820 | */ |
||
| 821 | 4 | public function getHandlerGroupPermission($optional = false) |
|
| 825 | |||
| 826 | /** |
||
| 827 | * Get handler of Member |
||
| 828 | * |
||
| 829 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 830 | * |
||
| 831 | * @return \Xoops\Core\Kernel\Handlers\XoopsMemberHandler |
||
| 832 | */ |
||
| 833 | 15 | public function getHandlerMember($optional = false) |
|
| 837 | |||
| 838 | /** |
||
| 839 | * Get handler of Membership |
||
| 840 | * |
||
| 841 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 842 | * |
||
| 843 | * @return \Xoops\Core\Kernel\Handlers\XoopsMembershipHandler |
||
| 844 | */ |
||
| 845 | 2 | public function getHandlerMembership($optional = false) |
|
| 849 | |||
| 850 | /** |
||
| 851 | * Get handler of Module |
||
| 852 | * |
||
| 853 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 854 | * |
||
| 855 | * @return \Xoops\Core\Kernel\Handlers\XoopsModuleHandler |
||
| 856 | */ |
||
| 857 | 10 | public function getHandlerModule($optional = false) |
|
| 861 | |||
| 862 | /** |
||
| 863 | * Get handler of Online |
||
| 864 | * |
||
| 865 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 866 | * |
||
| 867 | * @return \Xoops\Core\Kernel\Handlers\XoopsOnlineHandler |
||
| 868 | */ |
||
| 869 | 2 | public function getHandlerOnline($optional = false) |
|
| 873 | |||
| 874 | /** |
||
| 875 | * Get handler of Private Message |
||
| 876 | * |
||
| 877 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 878 | * |
||
| 879 | * @return \Xoops\Core\Kernel\Handlers\XoopsPrivateMessageHandler |
||
| 880 | */ |
||
| 881 | 1 | public function getHandlerPrivateMessage($optional = false) |
|
| 885 | |||
| 886 | /** |
||
| 887 | * Get the session manager |
||
| 888 | * |
||
| 889 | * @return Xoops\Core\Session\Manager |
||
| 890 | */ |
||
| 891 | 1 | public function session() |
|
| 898 | |||
| 899 | /** |
||
| 900 | * Get handler of Template File |
||
| 901 | * |
||
| 902 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 903 | * |
||
| 904 | * @return \Xoops\Core\Kernel\Handlers\XoopsTplFileHandler |
||
| 905 | */ |
||
| 906 | 2 | public function getHandlerTplFile($optional = false) |
|
| 910 | |||
| 911 | /** |
||
| 912 | * Get handler of Template Set |
||
| 913 | * |
||
| 914 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 915 | * |
||
| 916 | * @return \Xoops\Core\Kernel\Handlers\XoopsTplSetHandler |
||
| 917 | */ |
||
| 918 | 1 | public function getHandlerTplSet($optional = false) |
|
| 922 | |||
| 923 | /** |
||
| 924 | * Get handler of User |
||
| 925 | * |
||
| 926 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 927 | * |
||
| 928 | * @return \Xoops\Core\Kernel\Handlers\XoopsUserHandler |
||
| 929 | */ |
||
| 930 | 2 | public function getHandlerUser($optional = false) |
|
| 934 | |||
| 935 | /** |
||
| 936 | * Get handler |
||
| 937 | * |
||
| 938 | * @param string $name name of handler |
||
| 939 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 940 | * |
||
| 941 | * @return XoopsObjectHandler|XoopsPersistableObjectHandler|null |
||
| 942 | */ |
||
| 943 | 59 | protected function getHandler($name, $optional = false) |
|
| 961 | |||
| 962 | /** |
||
| 963 | * Get Module Handler |
||
| 964 | * |
||
| 965 | * @param string|null $name name of handler |
||
| 966 | * @param string|null $module_dir dirname of module |
||
| 967 | * @param boolean $optional true if failure to load handler should be considered a warning, not an error |
||
| 968 | * |
||
| 969 | * @return XoopsObjectHandler|XoopsPersistableObjectHandler|bool |
||
| 970 | */ |
||
| 971 | 2 | public function getModuleHandler($name = null, $module_dir = null, $optional = false) |
|
| 1000 | |||
| 1001 | /** |
||
| 1002 | * Get Module Form |
||
| 1003 | * |
||
| 1004 | * @param XoopsObject $obj object to populate form |
||
| 1005 | * @param string $name name of form |
||
| 1006 | * @param string $module_dir dirname of associated module |
||
| 1007 | * |
||
| 1008 | * @return Xoops\Form\Form|bool |
||
| 1009 | */ |
||
| 1010 | 1 | public function getModuleForm($obj, $name, $module_dir = null) |
|
| 1036 | |||
| 1037 | /** |
||
| 1038 | * Get Module Helper |
||
| 1039 | * |
||
| 1040 | * @param string $dirname dirname of module |
||
| 1041 | * |
||
| 1042 | * @return bool|Xoops\Module\Helper\HelperAbstract |
||
| 1043 | */ |
||
| 1044 | 1 | public static function getModuleHelper($dirname) |
|
| 1048 | |||
| 1049 | /** |
||
| 1050 | * XOOPS language loader wrapper |
||
| 1051 | * Temporary solution, not encouraged to use |
||
| 1052 | * |
||
| 1053 | * @param string $name Name of language file to be loaded, without extension |
||
| 1054 | * @param mixed $domain string: Module dirname; global language file will be loaded if |
||
| 1055 | * $domain is set to 'global' or not specified |
||
| 1056 | * array: example; array('Frameworks/moduleclasses/moduleadmin') |
||
| 1057 | * @param string $language Language to be loaded, current language content will be loaded if not specified |
||
| 1058 | * |
||
| 1059 | * @return boolean |
||
| 1060 | */ |
||
| 1061 | 7 | public function loadLanguage($name, $domain = '', $language = null) |
|
| 1084 | |||
| 1085 | /** |
||
| 1086 | * loadLocale |
||
| 1087 | * |
||
| 1088 | * @param string $domain Module dirname; global language file will be loaded if set to 'global' or not specified |
||
| 1089 | * @param string $locale Locale to be loaded, current language content will be loaded if not specified |
||
| 1090 | * |
||
| 1091 | * @return boolean |
||
| 1092 | */ |
||
| 1093 | 4 | public static function loadLocale($domain = null, $locale = null) |
|
| 1097 | |||
| 1098 | /** |
||
| 1099 | * Translate a key value |
||
| 1100 | * |
||
| 1101 | * @param string $key constant name |
||
| 1102 | * @param string $dirname dirname of module (domain) |
||
| 1103 | * |
||
| 1104 | * @return string |
||
| 1105 | */ |
||
| 1106 | 1 | public function translate($key, $dirname = 'xoops') |
|
| 1110 | |||
| 1111 | /** |
||
| 1112 | * Get active modules from cache file |
||
| 1113 | * |
||
| 1114 | * @return array |
||
| 1115 | */ |
||
| 1116 | 10 | public function getActiveModules() |
|
| 1131 | |||
| 1132 | /** |
||
| 1133 | * Write active modules to cache file |
||
| 1134 | * |
||
| 1135 | * @return array |
||
| 1136 | */ |
||
| 1137 | 1 | public function setActiveModules() |
|
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Checks is module is installed and active |
||
| 1151 | * |
||
| 1152 | * @param string $dirname module directory |
||
| 1153 | * |
||
| 1154 | * @return bool |
||
| 1155 | */ |
||
| 1156 | 8 | public function isActiveModule($dirname) |
|
| 1163 | |||
| 1164 | /** |
||
| 1165 | * get module object from module name (dirname) |
||
| 1166 | * |
||
| 1167 | * @param string $dirname dirname of the module |
||
| 1168 | * |
||
| 1169 | * @return bool|XoopsModule |
||
| 1170 | */ |
||
| 1171 | 4 | View Code Duplication | public function getModuleByDirname($dirname) |
| 1180 | |||
| 1181 | /** |
||
| 1182 | * Get Module By Id |
||
| 1183 | * |
||
| 1184 | * @param int $id Id of the module |
||
| 1185 | * |
||
| 1186 | * @return bool|XoopsModule |
||
| 1187 | */ |
||
| 1188 | 1 | View Code Duplication | public function getModuleById($id) |
| 1197 | |||
| 1198 | /** |
||
| 1199 | * Render Simple Header |
||
| 1200 | * |
||
| 1201 | * @param bool $closehead true to close the HTML head element |
||
| 1202 | * |
||
| 1203 | * @return void |
||
| 1204 | */ |
||
| 1205 | 1 | public function simpleHeader($closehead = true) |
|
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Render simpleFooter |
||
| 1256 | * |
||
| 1257 | * @return void |
||
| 1258 | */ |
||
| 1259 | 2 | public function simpleFooter() |
|
| 1265 | /** |
||
| 1266 | * render an alert message to a string |
||
| 1267 | * |
||
| 1268 | * @param string $type alert type, one of 'info', 'error', 'success' or 'warning' |
||
| 1269 | * @param mixed $msg string or array of strings |
||
| 1270 | * @param string $title title for alert |
||
| 1271 | * |
||
| 1272 | * @return string |
||
| 1273 | */ |
||
| 1274 | 1 | public function alert($type, $msg, $title = '/') |
|
| 1328 | |||
| 1329 | /** |
||
| 1330 | * Render a confirmation form to a string |
||
| 1331 | * |
||
| 1332 | * @param array $hiddens associative array of values used to complete confirmed action |
||
| 1333 | * @param string $action form action (URL) |
||
| 1334 | * @param string $msg message to display |
||
| 1335 | * @param string $submit submit button message |
||
| 1336 | * @param boolean $addtoken true to add CSRF token |
||
| 1337 | * |
||
| 1338 | * @return string rendered confirm message |
||
| 1339 | */ |
||
| 1340 | 1 | public function confirm($hiddens, $action, $msg, $submit = '', $addtoken = true) |
|
| 1366 | |||
| 1367 | /** |
||
| 1368 | * Get User Timestamp (kind of pointless, since timestamps are UTC?) |
||
| 1369 | * |
||
| 1370 | * @param \DateTime|int $time DateTime object or unix timestamp |
||
| 1371 | * |
||
| 1372 | * @return int unix timestamp |
||
| 1373 | */ |
||
| 1374 | 1 | public function getUserTimestamp($time) |
|
| 1379 | |||
| 1380 | /** |
||
| 1381 | * Function to calculate server timestamp from user entered time (timestamp) |
||
| 1382 | * |
||
| 1383 | * @param int $timestamp time stamp |
||
| 1384 | * @param null $userTZ timezone |
||
| 1385 | * |
||
| 1386 | * @return int |
||
| 1387 | */ |
||
| 1388 | 1 | public function userTimeToServerTime($timestamp, $userTZ = null) |
|
| 1396 | |||
| 1397 | /** |
||
| 1398 | * get the groups associated with the current user |
||
| 1399 | * |
||
| 1400 | * @return int[] |
||
| 1401 | */ |
||
| 1402 | 3 | public function getUserGroups() |
|
| 1408 | |||
| 1409 | /** |
||
| 1410 | * generate a temporary password |
||
| 1411 | * |
||
| 1412 | * @return string |
||
| 1413 | * |
||
| 1414 | * @todo make better passwords |
||
| 1415 | */ |
||
| 1416 | 1 | public function makePass() |
|
| 1436 | |||
| 1437 | /** |
||
| 1438 | * Check Email |
||
| 1439 | * |
||
| 1440 | * @param string $email check email |
||
| 1441 | * @param bool $antispam true if returned email should be have anti-SPAM measures applied |
||
| 1442 | * |
||
| 1443 | * @return false|string email address if valid, otherwise false |
||
| 1444 | */ |
||
| 1445 | 2 | public function checkEmail($email, $antispam = false) |
|
| 1456 | |||
| 1457 | /** |
||
| 1458 | * formatURL - add default http:// if no valid protocol specified |
||
| 1459 | * |
||
| 1460 | * @param string $url full or partial url |
||
| 1461 | * |
||
| 1462 | * @return string |
||
| 1463 | */ |
||
| 1464 | 1 | public function formatURL($url) |
|
| 1474 | |||
| 1475 | /** |
||
| 1476 | * Function to get banner html tags for use in templates |
||
| 1477 | * |
||
| 1478 | * @return string |
||
| 1479 | */ |
||
| 1480 | 3 | public function getBanner() |
|
| 1486 | |||
| 1487 | /** |
||
| 1488 | * Function to redirect a user to certain pages |
||
| 1489 | * |
||
| 1490 | * @param string $url URL to redirect to |
||
| 1491 | * @param int $time time to wait (to allow reading message display) |
||
| 1492 | * @param string $message message to display |
||
| 1493 | * @param bool $addredirect add xoops_redirect parameter with current URL to the redirect |
||
| 1494 | * URL - used for return from login redirect |
||
| 1495 | * @param bool $allowExternalLink allow redirect to external URL |
||
| 1496 | * |
||
| 1497 | * @return void |
||
| 1498 | */ |
||
| 1499 | public function redirect($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false) |
||
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Do an immediate redirect to the specified url. Use this instead of using PHP's header() |
||
| 1566 | * directly so that a core.redirect.start event is triggered. An example is debugbar, that |
||
| 1567 | * stacks data so the details for both original and redirected scripts data are available. |
||
| 1568 | * |
||
| 1569 | * @param string $url URL to redirect to |
||
| 1570 | * |
||
| 1571 | * @return void |
||
| 1572 | */ |
||
| 1573 | public static function simpleRedirect($url) |
||
| 1580 | |||
| 1581 | /** |
||
| 1582 | * Get Environment Value |
||
| 1583 | * |
||
| 1584 | * @param string $key key (name) in the environment |
||
| 1585 | * |
||
| 1586 | * @return string |
||
| 1587 | */ |
||
| 1588 | 8 | public function getEnv($key) |
|
| 1592 | |||
| 1593 | /** |
||
| 1594 | * Function to get css file for a certain themeset |
||
| 1595 | * |
||
| 1596 | * @param string $theme theme name |
||
| 1597 | * |
||
| 1598 | * @return string |
||
| 1599 | */ |
||
| 1600 | 6 | public function getCss($theme = '') |
|
| 1631 | |||
| 1632 | /** |
||
| 1633 | * Get Mailer |
||
| 1634 | * |
||
| 1635 | * @return XoopsMailer|XoopsMailerLocale |
||
| 1636 | */ |
||
| 1637 | 1 | public function getMailer() |
|
| 1651 | |||
| 1652 | /** |
||
| 1653 | * Get Option |
||
| 1654 | * |
||
| 1655 | * @param string $key key (name) of option |
||
| 1656 | * |
||
| 1657 | * @return string |
||
| 1658 | */ |
||
| 1659 | 4 | public function getOption($key) |
|
| 1667 | |||
| 1668 | /** |
||
| 1669 | * Set Option |
||
| 1670 | * |
||
| 1671 | * @param string $key key (name) of option |
||
| 1672 | * @param null $value value for option |
||
| 1673 | * |
||
| 1674 | * @return void |
||
| 1675 | */ |
||
| 1676 | 1 | public function setOption($key, $value = null) |
|
| 1682 | |||
| 1683 | /** |
||
| 1684 | * Get Config value |
||
| 1685 | * |
||
| 1686 | * @param string $key key (name) of configuration |
||
| 1687 | * |
||
| 1688 | * @return mixed |
||
| 1689 | */ |
||
| 1690 | 60 | public function getConfig($key) |
|
| 1694 | |||
| 1695 | /** |
||
| 1696 | * Get all Config Values |
||
| 1697 | * |
||
| 1698 | * @return array |
||
| 1699 | */ |
||
| 1700 | 13 | public function getConfigs() |
|
| 1704 | |||
| 1705 | /** |
||
| 1706 | * Add Config Values |
||
| 1707 | * |
||
| 1708 | * @param array $configs array of configs |
||
| 1709 | * @param string $dirname module name |
||
| 1710 | * |
||
| 1711 | * @return void |
||
| 1712 | */ |
||
| 1713 | 1 | View Code Duplication | public function addConfigs($configs, $dirname = 'system') |
| 1723 | |||
| 1724 | /** |
||
| 1725 | * Set Config Value |
||
| 1726 | * |
||
| 1727 | * @param string $key key (name) of the configuration item |
||
| 1728 | * @param mixed $value configuration value |
||
| 1729 | * @param string $dirname dirname of module |
||
| 1730 | * |
||
| 1731 | * @return void |
||
| 1732 | */ |
||
| 1733 | 9 | View Code Duplication | public function setConfig($key, $value = null, $dirname = 'system') |
| 1743 | |||
| 1744 | /** |
||
| 1745 | * Unset Config Value |
||
| 1746 | * |
||
| 1747 | * @param string $key key (name) of the configuration item |
||
| 1748 | * @param string $dirname dirname of module |
||
| 1749 | * |
||
| 1750 | * @return void |
||
| 1751 | */ |
||
| 1752 | 3 | public function unsetConfig($key, $dirname = 'system') |
|
| 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 | 63 | 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 | 20 | 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 | 3 | 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 | 1 | 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 | 1 | 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 | 1 | 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 | 15 | public function deprecated($message) |
|
| 1971 | |||
| 1972 | /** |
||
| 1973 | * Support for disabling error reporting |
||
| 1974 | * |
||
| 1975 | * @return void |
||
| 1976 | */ |
||
| 1977 | 3 | 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: