1 | <?php |
||
33 | abstract class GenericHelper |
||
34 | { |
||
35 | /** |
||
36 | * @var string module directory name |
||
37 | */ |
||
38 | protected $dirname; |
||
39 | |||
40 | /** |
||
41 | * @var \XoopsModule |
||
42 | */ |
||
43 | protected $object; |
||
44 | |||
45 | /** |
||
46 | * @var array of XoopsObjectHandler|XoopsPersistableObjectHandler |
||
47 | */ |
||
48 | protected $handlers; |
||
49 | |||
50 | /** |
||
51 | * @var array config items |
||
52 | */ |
||
53 | protected $configs; |
||
54 | |||
55 | /** |
||
56 | * @var bool true if debug is enabled |
||
57 | */ |
||
58 | protected $debug; |
||
59 | |||
60 | /** |
||
61 | * class constructor |
||
62 | * |
||
63 | * @param string $dirname a module directory name |
||
64 | */ |
||
65 | protected function __construct($dirname) |
||
69 | |||
70 | /** |
||
71 | * get the module object |
||
72 | * |
||
73 | * @return XoopsModule |
||
74 | */ |
||
75 | public function getModule() |
||
86 | |||
87 | /** |
||
88 | * get a module config item |
||
89 | * |
||
90 | * @param string $name name of config item, or blank for all items |
||
91 | * @param mixed $default default value to return if config $name is not set |
||
92 | * |
||
93 | * @return mixed string config item, array of config items, |
||
94 | * or null if config not found |
||
95 | */ |
||
96 | public function getConfig($name = null, $default = null) |
||
116 | |||
117 | /** |
||
118 | * Get an Object Handler |
||
119 | * |
||
120 | * @param string $name name of handler to load |
||
121 | * |
||
122 | * @return bool|XoopsObjectHandler|XoopsPersistableObjectHandler |
||
123 | */ |
||
124 | public function getHandler($name) |
||
141 | |||
142 | /** |
||
143 | * get a module object |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | protected function initObject() |
||
161 | |||
162 | /** |
||
163 | * get module configs |
||
164 | * |
||
165 | * @return void |
||
166 | */ |
||
167 | protected function initConfig() |
||
182 | |||
183 | /** |
||
184 | * get a handler instance and store in $this->_handlers |
||
185 | * |
||
186 | * @param string $name name of handler to load |
||
187 | * |
||
188 | * @return void |
||
189 | */ |
||
190 | protected function initHandler($name) |
||
210 | |||
211 | /** |
||
212 | * load a language file for this module |
||
213 | * |
||
214 | * @param string $name basename of language file (i.e. 'admin') |
||
215 | * |
||
216 | * @return bool |
||
217 | */ |
||
218 | public function loadLanguage($name) |
||
228 | |||
229 | /** |
||
230 | * Set debug option on or off |
||
231 | * |
||
232 | * @param bool $bool true to turn on debug logging, false for off |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | public function setDebug($bool = true) |
||
240 | |||
241 | /** |
||
242 | * Add a message to the module log |
||
243 | * |
||
244 | * @param string $log log message |
||
245 | * |
||
246 | * @return void |
||
247 | */ |
||
248 | public function addLog($log) |
||
262 | |||
263 | /** |
||
264 | * Is this the currently active module? |
||
265 | * |
||
266 | * @return bool |
||
267 | */ |
||
268 | public function isCurrentModule() |
||
276 | |||
277 | /** |
||
278 | * Does user have admin rights to this module? |
||
279 | * |
||
280 | * @return bool true is user has admin right, else false |
||
281 | */ |
||
282 | public function isUserAdmin() |
||
286 | |||
287 | /** |
||
288 | * Return absolute URL for a module relative URL |
||
289 | * |
||
290 | * @param string $url module relative URL |
||
291 | * |
||
292 | * @return string |
||
293 | */ |
||
294 | public function url($url = '') |
||
298 | |||
299 | /** |
||
300 | * Return absolute filesystem path for a module relative path |
||
301 | * |
||
302 | * @param string $path module relative file system path |
||
303 | * |
||
304 | * @return string |
||
305 | */ |
||
306 | public function path($path = '') |
||
310 | |||
311 | /** |
||
312 | * Redirect the user to a page within this module |
||
313 | * |
||
314 | * @param string $url module relative url (i.e. index.php) |
||
315 | * @param int $time time in seconds to show redirect message |
||
316 | * @param string $message redirect message |
||
317 | * |
||
318 | * @return void |
||
319 | */ |
||
320 | public function redirect($url, $time = 3, $message = '') |
||
324 | } |
||
325 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state