XOOPS  2.6.0
HelperAbstract.php
Go to the documentation of this file.
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\Helper;
13 
21 abstract class HelperAbstract
22 {
26  protected $_dirname = '';
27 
31  protected $_module = null;
32 
36  protected $_debug = false;
37 
38  public function init()
39  {
40  }
41 
45  protected function setDirname($dirname)
46  {
47  $this->_dirname = strtolower($dirname);
48  }
49 
53  protected function setDebug($debug)
54  {
55  $this->_debug = (bool)$debug;
56  }
57 
61  static function getInstance()
62  {
63  static $instance = false;
64  $id = $className = get_called_class();
65  if ($className == 'Xoops\Module\Helper\Dummy') {
66  $id = @\Xoops::getInstance()->registry()->get('module_helper_id');
67  }
68  if (!isset($instance[$id])) {
69  /* @var $class Xoops\Module\Helper\HelperAbstract */
70  $class = new $className();
71  $class->init();
72  $instance[$id] = $class;
73  }
74  return $instance[$id];
75  }
76 
80  public function getModule()
81  {
82  if ($this->_module == null) {
83  $this->_initModule();
84  }
85  return $this->_module;
86  }
87 
88  public function xoops()
89  {
90  return \Xoops::getInstance();
91  }
92 
98  public function getConfig($name)
99  {
100  $name = strtolower($name);
101  $result = $this->xoops()->getModuleConfig($name, $this->_dirname);
102  $this->_addLog("Getting config '{$name}' : " . $result);
103  return $result;
104  }
105 
111  public function getConfigs()
112  {
113  $result = $this->xoops()->getModuleConfigs($this->_dirname);
114  $this->_addLog("Getting configs for {$this->_dirname} module");
115  return $result;
116  }
117 
123  public function getHandler($name)
124  {
125  $name = strtolower($name);
126  $this->_addLog("Getting handler '{$name}'");
127  return $this->xoops()->getModuleHandler($name, $this->_dirname);
128  }
129 
130  public function disableCache()
131  {
132  $this->xoops()->appendConfig('module_cache', array($this->getModule()->getVar('mid') => 0), true, $this->_dirname);
133  $this->_addLog("Disabling module cache");
134  }
135 
141  public function isCurrentModule()
142  {
143  if ($this->xoops()->moduleDirname == $this->_dirname) {
144  return true;
145  }
146  return false;
147  }
148 
154  public function isUserAdmin()
155  {
156  if ($this->xoops()->isUser()) {
157  return $this->xoops()->user->isAdmin($this->getModule()->getVar('mid'));
158  }
159  return false;
160  }
161 
169  public function url($url = '')
170  {
171  return $this->xoops()->url('modules/' . $this->_dirname . '/' . $url);
172  }
173 
181  public function path($path = '')
182  {
183  return $this->xoops()->path('modules/' . $this->_dirname . '/' . $path);
184  }
185 
200  public function redirect($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false)
201  {
202  $this->xoops()->redirect($this->url($url), $time, $message, $addredirect, $allowExternalLink);
203  }
204 
210  public function loadLanguage($language)
211  {
212  $this->xoops()->loadLanguage($language, $this->_dirname);
213  $this->_addLog("Loading language '{$language}'");
214  }
215 
216  public function loadLocale()
217  {
218  $this->xoops()->loadLocale($this->_dirname);
219  $this->_addLog("Loading locale");
220  }
221 
228  public function getForm($obj, $name)
229  {
230  $name = strtolower($name);
231  $this->_addLog("Loading form '{$name}'");
232  return $this->xoops()->getModuleForm($obj, $name, $this->_dirname);
233  }
234 
238  private function _initModule()
239  {
240  if ($this->isCurrentModule()) {
241  $this->_module = $this->xoops()->module;
242  } else {
243  $this->_module = $this->xoops()->getModuleByDirname($this->_dirname);
244  }
245  if (!$this->_module instanceof \XoopsModule) {
246  $this->_module = $this->xoops()->getHandlerModule()->create();
247  }
248  $this->_addLog('Loading module');
249  }
250 
254  protected function _addLog($log)
255  {
256  if ($this->_debug) {
257  $this->xoops()->preload()->triggerEvent('core.module.addlog', array(
258  $this->getModule()->getVar('name'),
259  $log
260  ));
261  }
262  }
263 }
$path
Definition: execute.php:31
static getInstance()
Definition: Xoops.php:160
isUser()
Definition: Xoops.php:722
$result
Definition: pda.php:33
redirect($url, $time=3, $message= '', $addredirect=true, $allowExternalLink=false)
$id
Definition: admin_menu.php:36
$xoops moduleDirname
Definition: common.php:216
$url
Definition: register.php:72
$dirname
Definition: backend.php:38
$language