1 | <?php |
||
31 | abstract class GenericHelper |
||
32 | { |
||
33 | /** |
||
34 | * @var string module directory name |
||
35 | */ |
||
36 | protected $dirname; |
||
37 | |||
38 | /** |
||
39 | * @var \XoopsModule |
||
40 | */ |
||
41 | protected $object; |
||
42 | |||
43 | /** |
||
44 | * @var array of XoopsObjectHandler|XoopsPersistableObjectHandler |
||
45 | */ |
||
46 | protected $handlers; |
||
47 | |||
48 | /** |
||
49 | * @var array config items |
||
50 | */ |
||
51 | protected $configs; |
||
52 | |||
53 | /** |
||
54 | * @var bool true if debug is enabled |
||
55 | */ |
||
56 | protected $debug; |
||
57 | |||
58 | /** |
||
59 | * class constructor |
||
60 | * |
||
61 | * @param string $dirname a module directory name |
||
62 | */ |
||
63 | protected function __construct($dirname) |
||
67 | |||
68 | /** |
||
69 | * get the module object |
||
70 | * |
||
71 | * @return XoopsModule |
||
72 | */ |
||
73 | public function getModule() |
||
84 | |||
85 | /** |
||
86 | * get a module config item |
||
87 | * |
||
88 | * @param string $name name of config item, or blank for all items |
||
89 | * @param mixed $default default value to return if config $name is not set |
||
90 | * |
||
91 | * @return mixed string config item, array of config items, |
||
92 | * or null if config not found |
||
93 | */ |
||
94 | public function getConfig($name = null, $default = null) |
||
114 | |||
115 | /** |
||
116 | * Get an Object Handler |
||
117 | * |
||
118 | * @param string $name name of handler to load |
||
119 | * |
||
120 | * @return bool|XoopsObjectHandler|XoopsPersistableObjectHandler |
||
121 | */ |
||
122 | public function getHandler($name) |
||
139 | |||
140 | /** |
||
141 | * get a module object |
||
142 | * |
||
143 | * @return void |
||
144 | */ |
||
145 | protected function initObject() |
||
159 | |||
160 | /** |
||
161 | * get module configs |
||
162 | * |
||
163 | * @return void |
||
164 | */ |
||
165 | protected function initConfig() |
||
180 | |||
181 | /** |
||
182 | * get a handler instance and store in $this->_handlers |
||
183 | * |
||
184 | * @param string $name name of handler to load |
||
185 | * |
||
186 | * @return void |
||
187 | */ |
||
188 | protected function initHandler($name) |
||
208 | |||
209 | /** |
||
210 | * load a language file for this module |
||
211 | * |
||
212 | * @param string $name basename of language file (i.e. 'admin') |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function loadLanguage($name) |
||
226 | |||
227 | /** |
||
228 | * Set debug option on or off |
||
229 | * |
||
230 | * @param bool $bool true to turn on debug logging, false for off |
||
231 | * |
||
232 | * @return void |
||
233 | */ |
||
234 | public function setDebug($bool = true) |
||
238 | |||
239 | /** |
||
240 | * Add a message to the module log |
||
241 | * |
||
242 | * @param string $log log message |
||
243 | * |
||
244 | * @return void |
||
245 | */ |
||
246 | public function addLog($log) |
||
260 | |||
261 | /** |
||
262 | * Is this the currently active module? |
||
263 | * |
||
264 | * @return bool |
||
265 | */ |
||
266 | public function isCurrentModule() |
||
274 | |||
275 | /** |
||
276 | * Does user have admin rights to this module? |
||
277 | * |
||
278 | * @return bool true is user has admin right, else false |
||
279 | */ |
||
280 | 1 | public function isUserAdmin() |
|
285 | |||
286 | /** |
||
287 | * Return absolute URL for a module relative URL |
||
288 | * |
||
289 | * @param string $url module relative URL |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function url($url = '') |
||
297 | |||
298 | /** |
||
299 | * Return absolute filesystem path for a module relative path |
||
300 | * |
||
301 | * @param string $path module relative file system path |
||
302 | * |
||
303 | * @return string |
||
304 | */ |
||
305 | public function path($path = '') |
||
309 | |||
310 | /** |
||
311 | * Redirect the user to a page within this module |
||
312 | * |
||
313 | * @param string $url module relative url (i.e. index.php) |
||
314 | * @param int $time time in seconds to show redirect message |
||
315 | * @param string $message redirect message |
||
316 | * |
||
317 | * @return void |
||
318 | */ |
||
319 | public function redirect($url, $time = 3, $message = '') |
||
323 | } |
||
324 |
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