1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Module;
13: /**
14: * @copyright XOOPS Project (http://xoops.org)
15: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16: * @author trabis <lusopoemas@gmail.com>
17: * @version $Id$
18: */
19:
20: class Helper
21: {
22: /**
23: * @param string $dirname
24: *
25: * @return bool|Xoops\Module\Helper\HelperAbstract
26: */
27: public static function getHelper($dirname = 'system')
28: {
29: static $modules = array();
30:
31: $dirname = strtolower($dirname);
32: if (!isset($modules[$dirname])) {
33: $modules[$dirname] = false;
34: $xoops = \Xoops::getInstance();
35: if ($xoops->isActiveModule($dirname)) {
36: //Load Module helper if available
37: if (\XoopsLoad::loadFile($xoops->path("modules/{$dirname}/class/helper.php"))) {
38: $className = '\\' . ucfirst($dirname);
39: if (class_exists($className)) {
40: $class = new $className();
41: if ($class instanceof \Xoops\Module\Helper\HelperAbstract) {
42: $modules[$dirname] = $class::getInstance();
43: }
44: }
45: } else {
46: //Create Module Helper
47: $xoops->registry()->set('module_helper_id', $dirname);
48: $class = \Xoops\Module\Helper\Dummy::getInstance();
49: $class->setDirname($dirname);
50: $modules[$dirname] = $class;
51: }
52: }
53: }
54: return $modules[$dirname];
55: }
56: }
57: