Completed
Push — master ( 692213...d4ec0d )
by Goffy
03:18 queued 01:37
created

class/xnewsletter.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
 *  xnewsletterxnewsletter class
13
 *
14
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
15
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package         xnewsletter
17
 * @since           1.3
18
 * @author          Xoops Development Team
19
 * @version         svn:$id$
20
 */
21
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined");
22
23
class xnewsletterxnewsletter
24
{
25
    var $dirname;
26
    var $module;
27
    var $handler;
28
    var $config;
29
    var $debug;
30
    var $debugArray = array();
31
32
    /**
33
     * @param $debug
34
     */
35
    protected function __construct($debug)
36
    {
37
        $this->debug   = $debug;
38
        $this->dirname =  basename(dirname(__DIR__));
39
    }
40
41
    /**
42
     * @param bool $debug
43
     *
44
     * @return xnewsletterxnewsletter
45
     */
46
    public static function &getInstance($debug = false)
47
    {
48
        static $instance = false;
49
        if (!$instance) {
50
            $instance = new self($debug);
51
        }
52
        return $instance;
53
    }
54
55
    public function &getModule()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
56
    {
57
        if ($this->module == null) {
58
            $this->initModule();
59
        }
60
61
        return $this->module;
62
    }
63
64
    /**
65
     * @param null $name
66
     *
67
     * @return null
68
     */
69
    public function getConfig($name = null)
70
    {
71
        if ($this->config == null) {
72
            $this->initConfig();
73
        }
74
        if (!$name) {
75
            $this->addLog("Getting all config");
76
77
            return $this->config;
78
        }
79
        if (!isset($this->config[$name])) {
80
            $this->addLog("ERROR :: CONFIG '{$name}' does not exist");
81
82
            return null;
83
        }
84
        $this->addLog("Getting config '{$name}' : " . print_r($this->config[$name], true));
85
86
        return $this->config[$name];
87
    }
88
89
    /**
90
     * @param null $name
91
     * @param null $value
92
     *
93
     * @return mixed
94
     */
95
    public function setConfig($name = null, $value = null)
96
    {
97
        if ($this->config == null) {
98
            $this->initConfig();
99
        }
100
        $this->config[$name] = $value;
101
        $this->addLog("Setting config '{$name}' : " . $this->config[$name]);
102
103
        return $this->config[$name];
104
    }
105
106
    /**
107
     * @param $name
108
     *
109
     * @return mixed
110
     */
111
    public function &getHandler($name)
112
    {
113
        if (!isset($this->handler[$name . '_handler'])) {
114
            $this->initHandler($name);
115
        }
116
        $this->addLog("Getting handler '{$name}'");
117
118
        return $this->handler[$name . '_handler'];
119
    }
120
121
    public function initModule()
122
    {
123
        global $xoopsModule;
124
        if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $this->dirname) {
125
            $this->module = $xoopsModule;
126
        } else {
127
            $hModule = xoops_gethandler('module');
128
            $this->module = $hModule->getByDirname($this->dirname);
129
        }
130
        $this->addLog('INIT MODULE');
131
    }
132
133
    public function initConfig()
134
    {
135
        $this->addLog('INIT CONFIG');
136
        $hModConfig = xoops_gethandler('config');
137
        $this->config = $hModConfig->getConfigsByCat(0, $this->getModule()->getVar('mid'));
138
    }
139
140
    /**
141
     * @param $name
142
     */
143
    public function initHandler($name)
144
    {
145
        $this->addLog('INIT ' . $name . ' HANDLER');
146
        $this->handler[$name . '_handler'] = xoops_getModuleHandler($name, $this->dirname);
147
    }
148
149
    /**
150
     * @param $log
151
     */
152
    public function addLog($log)
153
    {
154
        if ($this->debug) {
155
            if (is_object($GLOBALS['xoopsLogger'])) {
156
                $GLOBALS['xoopsLogger']->addExtra($this->module->name(), $log);
157
            }
158
        }
159
    }
160
}
161