1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18:
19: namespace Xoops\Core\Kernel\Handlers;
20:
21: use Xoops\Core\Kernel\Dtype;
22: use Xoops\Core\Kernel\XoopsObject;
23:
24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
35: class XoopsModule extends XoopsObject
36: {
37: 38: 39:
40: public $modinfo;
41:
42: 43: 44:
45: public $adminmenu;
46: 47: 48: 49:
50: private $internalMessages = array();
51:
52: protected $xoops_url;
53: protected $xoops_root_path;
54:
55: 56: 57:
58: public function __construct()
59: {
60: $this->initVar('mid', Dtype::TYPE_INTEGER, null, false);
61: $this->initVar('name', Dtype::TYPE_TEXT_BOX, null, true, 150);
62: $this->initVar('version', Dtype::TYPE_INTEGER, 100, false);
63: $this->initVar('last_update', Dtype::TYPE_INTEGER, null, false);
64: $this->initVar('weight', Dtype::TYPE_INTEGER, 0, false);
65: $this->initVar('isactive', Dtype::TYPE_INTEGER, 1, false);
66: $this->initVar('dirname', Dtype::TYPE_OTHER, null, true);
67: $this->initVar('hasmain', Dtype::TYPE_INTEGER, 0, false);
68: $this->initVar('hasadmin', Dtype::TYPE_INTEGER, 0, false);
69: $this->initVar('hassearch', Dtype::TYPE_INTEGER, 0, false);
70: $this->initVar('hasconfig', Dtype::TYPE_INTEGER, 0, false);
71: $this->initVar('hascomments', Dtype::TYPE_INTEGER, 0, false);
72:
73: $this->initVar('hasnotification', Dtype::TYPE_INTEGER, 0, false);
74:
75: $this->xoops_url = \XoopsBaseConfig::get('url');
76: $this->xoops_root_path = \XoopsBaseConfig::get('root-path');
77: }
78:
79: 80: 81: 82: 83: 84: 85: 86:
87: public function loadInfoAsVar($dirname, $verbose = true)
88: {
89: $dirname = basename($dirname);
90: if (!isset($this->modinfo)) {
91: $this->loadInfo($dirname, $verbose);
92: }
93: $this->setVar('name', $this->modinfo['name']);
94: $this->setVar('version', (int)(100 * ($this->modinfo['version'] + 0.001)));
95: $this->setVar('dirname', $this->modinfo['dirname']);
96: $hasmain = (isset($this->modinfo['hasMain']) && $this->modinfo['hasMain'] == 1) ? 1 : 0;
97: $hasadmin = (isset($this->modinfo['hasAdmin']) && $this->modinfo['hasAdmin'] == 1) ? 1 : 0;
98: $hassearch = (isset($this->modinfo['hasSearch']) && $this->modinfo['hasSearch'] == 1) ? 1 : 0;
99: $hasconfig = ((isset($this->modinfo['config']) && is_array($this->modinfo['config']))
100: || !empty($this->modinfo['hasComments'])) ? 1 : 0;
101: $hascomments = (isset($this->modinfo['hasComments']) && $this->modinfo['hasComments'] == 1) ? 1 : 0;
102:
103: $hasnotification = (isset($this->modinfo['hasNotification']) && $this->modinfo['hasNotification'] == 1) ? 1 : 0;
104: $this->setVar('hasmain', $hasmain);
105: $this->setVar('hasadmin', $hasadmin);
106: $this->setVar('hassearch', $hassearch);
107: $this->setVar('hasconfig', $hasconfig);
108: $this->setVar('hascomments', $hascomments);
109:
110: $this->setVar('hasnotification', $hasnotification);
111: }
112:
113: 114: 115: 116: 117: 118: 119:
120: public function setMessage($str)
121: {
122: $this->internalMessages[] = trim($str);
123: }
124:
125: 126: 127: 128: 129:
130: public function getMessages()
131: {
132: return $this->internalMessages;
133: }
134:
135: 136: 137: 138: 139: 140: 141: 142:
143: public function setInfo($name, $value)
144: {
145: if (empty($name)) {
146: $this->modinfo = $value;
147: } else {
148: $this->modinfo[$name] = $value;
149: }
150: return true;
151: }
152:
153: 154: 155: 156: 157: 158: 159:
160: public function getInfo($name = null)
161: {
162: if (!isset($this->modinfo)) {
163: $this->loadInfo($this->getVar('dirname'));
164: }
165: if (isset($name)) {
166: if (isset($this->modinfo[$name])) {
167: return $this->modinfo[$name];
168: }
169: $return = false;
170: return $return;
171: }
172: return $this->modinfo;
173: }
174:
175: 176: 177: 178: 179:
180: public function mainLink()
181: {
182: if ($this->getVar('hasmain') == 1) {
183: $ret = '<a href="' . $this->xoops_url . '/modules/' . $this->getVar('dirname') . '/">'
184: . $this->getVar('name') . '</a>';
185: return $ret;
186: }
187: return false;
188: }
189:
190: 191: 192: 193: 194:
195: public function subLink()
196: {
197: $ret = array();
198: if ($this->getInfo('sub') && is_array($this->getInfo('sub'))) {
199: foreach ($this->getInfo('sub') as $submenu) {
200: $ret[] = array(
201: 'name' => $submenu['name'] ,
202: 'url' => $submenu['url']);
203: }
204: }
205: return $ret;
206: }
207:
208: 209: 210: 211: 212:
213: public function loadAdminMenu()
214: {
215: $file = $this->xoops_root_path . '/modules/' . $this->getInfo('dirname') . '/' . $this->getInfo('adminmenu');
216: if ($this->getInfo('adminmenu') && $this->getInfo('adminmenu') != '' && \XoopsLoad::fileExists($file)) {
217: $adminmenu = array();
218: include $file;
219: $this->adminmenu = $adminmenu;
220: }
221: }
222:
223: 224: 225: 226: 227:
228: public function getAdminMenu()
229: {
230: if (!isset($this->adminmenu)) {
231: $this->loadAdminMenu();
232: }
233: return $this->adminmenu;
234: }
235:
236: 237: 238: 239: 240: 241: 242: 243: 244: 245:
246: public function loadInfo($dirname, $verbose = true)
247: {
248: static $modVersions;
249: if (empty($dirname)) {
250: return false;
251: }
252: $dirname = basename($dirname);
253: if (isset($modVersions[$dirname])) {
254: $this->modinfo = $modVersions[$dirname];
255: return true;
256: }
257: $xoops = \Xoops::getInstance();
258: $dirname = basename($dirname);
259: $xoops->loadLanguage('modinfo', $dirname);
260: $xoops->loadLocale($dirname);
261:
262: if (!\XoopsLoad::fileExists($file = $xoops->path('modules/' . $dirname . '/xoops_version.php'))) {
263: if (false != $verbose) {
264: echo "Module File for $dirname Not Found!";
265: }
266: return false;
267: }
268: $modversion = array();
269: include $file;
270: $modVersions[$dirname] = $modversion;
271: $this->modinfo = $modVersions[$dirname];
272: return true;
273: }
274:
275: 276: 277: 278: 279: 280: 281:
282: public function id($format = 'n')
283: {
284: return $this->getVar('mid', $format);
285: }
286:
287: 288: 289: 290: 291: 292: 293:
294: public function mid($format = '')
295: {
296: return $this->getVar('mid', $format);
297: }
298:
299: 300: 301: 302: 303: 304: 305:
306: public function name($format = '')
307: {
308: return $this->getVar('name', $format);
309: }
310:
311: 312: 313: 314: 315: 316: 317:
318: public function version($format = '')
319: {
320: return $this->getVar('version', $format);
321: }
322:
323: 324: 325: 326: 327: 328: 329:
330: public function last_update($format = '')
331: {
332: return $this->getVar('last_update', $format);
333: }
334:
335: 336: 337: 338: 339: 340: 341:
342: public function weight($format = '')
343: {
344: return $this->getVar('weight', $format);
345: }
346:
347: 348: 349: 350: 351: 352: 353:
354: public function isactive($format = '')
355: {
356: return $this->getVar('isactive', $format);
357: }
358:
359: 360: 361: 362: 363: 364: 365:
366: public function dirname($format = '')
367: {
368: return $this->getVar('dirname', $format);
369: }
370:
371: 372: 373: 374: 375: 376: 377:
378: public function hasmain($format = '')
379: {
380: return $this->getVar('hasmain', $format);
381: }
382:
383: 384: 385: 386: 387: 388: 389:
390: public function hasadmin($format = '')
391: {
392: return $this->getVar('hasadmin', $format);
393: }
394:
395: 396: 397: 398: 399: 400: 401:
402: public function hassearch($format = '')
403: {
404: return $this->getVar('hassearch', $format);
405: }
406:
407: 408: 409: 410: 411: 412: 413:
414: public function hasconfig($format = '')
415: {
416: return $this->getVar('hasconfig', $format);
417: }
418:
419: 420: 421: 422: 423: 424: 425:
426: public function hascomments($format = '')
427: {
428: return $this->getVar('hascomments', $format);
429: }
430:
431: 432: 433: 434: 435: 436: 437:
438: public function hasnotification($format = '')
439: {
440: return $this->getVar('hasnotification', $format);
441: }
442:
443: 444: 445: 446: 447: 448: 449:
450: public function getByDirname($dirname)
451: {
452: return \Xoops::getInstance()->getModuleByDirname($dirname);
453: }
454: }
455: