1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
/** |
15
|
|
|
* NewBB module for xoops |
16
|
|
|
* |
17
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
18
|
|
|
* @license GPL 2.0 or later |
19
|
|
|
* @package newbb |
20
|
|
|
* @since 5.0.0 |
21
|
|
|
* @author XOOPS Development Team <https://xoops.org> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class Helper |
26
|
|
|
*/ |
27
|
|
|
class Helper extends \Xmf\Module\Helper |
28
|
|
|
{ |
29
|
|
|
public $debug; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param bool $debug |
33
|
|
|
*/ |
34
|
|
|
public function __construct($debug = false) |
35
|
|
|
{ |
36
|
|
|
$this->debug = $debug; |
37
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
38
|
|
|
parent::__construct($moduleDirName); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param bool $debug |
43
|
|
|
* |
44
|
|
|
* @return \XoopsModules\Newbb\Helper |
45
|
|
|
*/ |
46
|
|
|
public static function getInstance($debug = false) |
47
|
|
|
{ |
48
|
|
|
static $instance; |
49
|
|
|
if (null === $instance) { |
50
|
|
|
$instance = new static($debug); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $instance; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param null|string $name |
58
|
|
|
* @param null|string $value |
59
|
|
|
* |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function setConfig($name = null, $value = null) |
63
|
|
|
{ |
64
|
|
|
if (null === $this->configs) { |
65
|
|
|
$this->initConfig(); |
66
|
|
|
} |
67
|
|
|
$this->configs[$name] = $value; |
68
|
|
|
$this->addLog("Setting config '{$name}' : " . $this->configs[$name]); |
69
|
|
|
|
70
|
|
|
return $this->configs[$name]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getDirname() |
77
|
|
|
{ |
78
|
|
|
return $this->dirname; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get an Object Handler |
83
|
|
|
* |
84
|
|
|
* @param string $name name of handler to load |
85
|
|
|
* |
86
|
|
|
* @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler |
87
|
|
|
*/ |
88
|
|
|
public function getHandler($name) |
89
|
|
|
{ |
90
|
|
|
$ret = false; |
|
|
|
|
91
|
|
|
|
92
|
|
|
$class = __NAMESPACE__ . '\\' . \ucfirst($name) . 'Handler'; |
93
|
|
|
if (!\class_exists($class)) { |
94
|
|
|
throw new \RuntimeException("Class '$class' not found"); |
95
|
|
|
} |
96
|
|
|
/** @var \XoopsMySQLDatabase $db */ |
97
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
98
|
|
|
$helper = self::getInstance(); |
99
|
|
|
$ret = new $class($db, $helper); |
100
|
|
|
$this->addLog("Getting handler '{$name}'"); |
101
|
|
|
return $ret; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|