|
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 <[email protected]> |
|
17
|
|
|
* @version $Id$ |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
class Helper |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $dirname |
|
24
|
|
|
* |
|
25
|
|
|
* @return bool|Xoops\Module\Helper\HelperAbstract |
|
26
|
|
|
*/ |
|
27
|
5 |
|
public static function getHelper($dirname = 'system') |
|
28
|
|
|
{ |
|
29
|
5 |
|
static $modules = array(); |
|
30
|
|
|
|
|
31
|
5 |
|
$dirname = strtolower($dirname); |
|
32
|
5 |
|
if (!isset($modules[$dirname])) { |
|
33
|
4 |
|
$modules[$dirname] = false; |
|
34
|
4 |
|
$xoops = \Xoops::getInstance(); |
|
35
|
4 |
|
if ($xoops->isActiveModule($dirname)) { |
|
36
|
|
|
//Load Module helper if available |
|
37
|
1 |
|
if (\XoopsLoad::loadFile($xoops->path("modules/{$dirname}/class/helper.php"))) { |
|
38
|
1 |
|
$className = '\\' . ucfirst($dirname); |
|
39
|
1 |
|
if (class_exists($className)) { |
|
40
|
1 |
|
$class = new $className(); |
|
41
|
1 |
|
if ($class instanceof \Xoops\Module\Helper\HelperAbstract) { |
|
42
|
1 |
|
$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
|
5 |
|
return $modules[$dirname]; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.