XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
Legacy_Module.class.php
1<?php
11
32{
39 public $mAttributes = [];
40
45 public $mXoopsModule = null;
46
51 public $mModuleConfig = [];
52
58 public $mCacheInfo = null;
59
65 public $mRender = null;
66
76 public function __construct(&$module, $loadConfig=true)
77 {
78 $this->setXoopsModule($module);
79
80 if ($loadConfig && (1 == $module->get('hasconfig') || 1 == $module->get('hascomments') || 1 == $module->get('hasnotification'))) {
81 $handler =& xoops_gethandler('config');
82 $this->setModuleConfig($handler->getConfigsByCat(0, $module->get('mid')));
83 }
84 }
85
96 public function setAttribute($key, $value)
97 {
98 $this->mAttributes[$key] = $value;
99 }
100
107 public function hasAttribute($key)
108 {
109 return isset($this->mAttributes[$key]);
110 }
111
118 public function getAttribute($key)
119 {
120 return $this->mAttributes[$key] ?? null;
121 }
122
129 public function setXoopsModule(&$xoopsModule)
130 {
131 $this->mXoopsModule =& $xoopsModule;
132 }
133
139 public function &getXoopsModule()
140 {
141 return $this->mXoopsModule;
142 }
143
150 public function setModuleConfig($config)
151 {
152 $this->mModuleConfig = $config;
153 }
154
161 public function getModuleConfig(string $key = null)
162 {
163 if (null == $key) {
165 }
166
167 return $this->mModuleConfig[$key] ?? null;
168 }
169
176 public function &getCacheInfo()
177 {
178 if (!is_object($this->mCacheInfo)) {
179 $this->_createCacheInfo();
180 }
181
182 return $this->mCacheInfo;
183 }
184
194 public function _createCacheInfo()
195 {
196 $this->mCacheInfo = new Legacy_ModuleCacheInformation();
197 $this->mCacheInfo->mURL = xoops_getenv('REQUEST_URI');
198 $this->mCacheInfo->setModule($this->mXoopsModule);
199 }
200
207 public function &getRenderTarget()
208 {
209 if (null == $this->mRender) {
210 $this->_createRenderTarget();
211 }
212
213 return $this->mRender;
214 }
215
225 public function _createRenderTarget()
226 {
227 $renderSystem =& $this->getRenderSystem();
228
229 $this->mRender =& $renderSystem->createRenderTarget('main');
230 if (null !== $this->mXoopsModule) {
231 $this->mRender->setAttribute('legacy_module', $this->mXoopsModule->get('dirname'));
232 }
233 }
234
244 public function getRenderSystemName()
245 {
246 $root =& XCube_Root::getSingleton();
247 return $root->mContext->mBaseRenderSystemName;
248 }
249
257 public function &getRenderSystem()
258 {
259 $root =& XCube_Root::getSingleton();
260 $renderSystem =& $root->getRenderSystem($this->getRenderSystemName());
261
262 return $renderSystem;
263 }
264
270 public function isActive()
271 {
272 if (!is_object($this->mXoopsModule)) { //< FIXME
273 return false;
274 }
275
276 //return $this->mXoopsModule->get('isactive') ? true : false;
277 return (bool)$this->mXoopsModule->get('isactive');
278 }
279
286 public function isEnableCache()
287 {
288 if ('POST' == xoops_getenv('REQUEST_METHOD')) {
289 return false;
290 }
291
292 $root =& XCube_Root::getSingleton();
293
294 return is_object($this->mXoopsModule) && !empty($root->mContext->mXoopsConfig['module_cache'][$this->mXoopsModule->get('mid')]);
295 }
296
302 public function &createCacheInfo()
303 {
304 $this->mCacheInfo = new Legacy_ModuleCacheInformation();
305 $this->mCacheInfo->mURL = xoops_getenv('REQUEST_URI');
306 $this->mCacheInfo->setModule($this->mXoopsModule);
307
308 return $this->mCacheInfo;
309 }
310
317 public function startup()
318 {
319 }
320
329 public function doActionSearch(&$searchArgs)
330 {
331 }
332
342 public function doLegacyGlobalSearch($queries, $andor, $max_hit, $start, $uid)
343 {
344 }
345
358 public function hasAdminIndex()
359 {
360 return false;
361 }
362
372 public function getAdminIndex()
373 {
374 return null;
375 }
376
383 public function getAdminMenu()
384 {
385 }
386}
387
397{
403
408 public $mAdminMenu = null;
409
410 public function __construct($module, $loadConfig=true)
411 {
412 parent::__construct($module, $loadConfig);
413 }
414
423 public function doActionSearch(&$searchArgs)
424 {
425 if (!is_object($searchArgs)) {
426 return;
427 }
428
429 $this->mXoopsModule->loadAdminMenu();
430
431 /*
432 * Polyfill if not PHP >= 7.3.0 // XCL 2.3.0 Bug fix #163 @gigamaster
433 */
434 if (!function_exists('is_countable')) {
435
436 function is_countable($searchArgs) {
437
438 if (0 == (is_countable($this->mXoopsModule->adminmenu) ? count($this->mXoopsModule->adminmenu) : 0) && !isset($this->mXoopsModule->modinfo['config'])) {
439
440 return (is_countable($searchArgs));
441 }
442 }
443 }
444
445
446 //
447 // Search preference
448 //
449 if (isset($this->mXoopsModule->modinfo['config']) && (is_countable($this->mXoopsModule->modinfo['config']) ? count($this->mXoopsModule->modinfo['config']) : 0)>0) {
450 $findFlag = false;
451 foreach ($searchArgs->getKeywords() as $word) {
452 if (stripos(_PREFERENCES, (string) $word) !== false) {
453 $root =& XCube_Root::getSingleton();
454 $searchArgs->addRecord($this->mXoopsModule->getVar('name'), $root->mController->getPreferenceEditUrl($this->mXoopsModule), _PREFERENCES);
455 $findFlag = true;
456 break;
457 }
458 }
459 // Since XCL 2.3.x PHP8 Check if constant is defined
460 if (!$findFlag) {
461 $configInfos= [];
462 foreach ($this->mXoopsModule->modinfo['config'] as $config) {
463 if (isset($config['title'])) {
464 if (defined($config['title'])) {
465 $configInfos[]= @constant($config['title']);
466 }
467 }
468 if (isset($config['description'])) {
469 if (defined($config['description'])) {
470 $configInfos[]= @constant($config['description']);
471 }
472 }
473 if (isset($config['options']) && (is_countable($config['options']) ? count($config['options']) : 0) > 0 ) {
474 foreach ($config['options'] as $key=>$val) {
475 if (defined($key)) {
476 $configInfos[]= ( constant($key) ?? $key ?? '' );
477 }
478 }
479 }
480 }
481
482 $findFlag=true;
483 foreach ($searchArgs->getKeywords() as $word) {
484 $findFlag&=(stripos(implode(' ', $configInfos), (string) $word) !== false);
485 }
486
487 if ($findFlag) {
488 $searchArgs->addRecord($this->mXoopsModule->getVar('name'),
489 XOOPS_URL.'/modules/legacy/admin/index.php?action=PreferenceEdit&amp;confmod_id='.$this->mXoopsModule->getVar('mid'),
490 _PREFERENCES);
491 }
492 }
493 }
494
495 /*
496 * Search AdminMenu
497 * Polyfill if not PHP 7.3.0 // XCLBug #163 @Gigamaster
498 */
499 if (!function_exists('is_countable')) {
500
501 function is_countable($searchArgs) {
502
503 if ((is_countable($this->mXoopsModule->adminmenu) ? count($this->mXoopsModule->adminmenu) : 0) > 0 ) {
504 foreach ($this->mXoopsModule->adminmenu as $menu) {
505 $findFlag = true;
506 foreach ($searchArgs->getKeywords() as $word) {
507 $tmpFlag=false;
508 $tmpFlag|=(stripos($menu['title'], (string) $word) !== false);
509
510 // Search keyword
511 if (isset($menu['keywords'])) {
512 $keyword=is_array($menu['keywords']) ? implode(' ', $menu['keywords']) : $menu['keywords'];
513 $tmpFlag|=(stripos($keyword, (string) $word) !== false);
514 }
515
516 $findFlag&=$tmpFlag;
517 }
518
519 if ($findFlag) {
520 //
521 // Create url string with absolute information.
522 //
523 $url= '';
524 if (isset($menu['absolute'])&&$menu['absolute']) {
525 $url=$menu['link'];
526 } else {
527 $url= XOOPS_URL . '/modules/' . $this->mXoopsModule->getVar('dirname') . '/' . $menu['link'];
528 }
529
530 //
531 // Add record
532 //
533 $searchArgs->addRecord($this->mXoopsModule->getVar('name'), $url, $menu['title']);
534 }
535 }
536 }
537
538 return (is_countable($searchArgs));
539
540 }
541
542 }
543
544 //
545 // Search help
546 //
547 if ($this->mXoopsModule->hasHelp()) {
548 $findFlag = false;
549
550 foreach ($searchArgs->getKeywords() as $word) {
551 if (stripos(_HELP, (string) $word) !== false) {
552 $root =& XCube_Root::getSingleton();
553 $searchArgs->addRecord($this->mXoopsModule->getVar('name'), $root->mController->getHelpViewUrl($this->mXoopsModule), _HELP);
554 $findFlag = true;
555 break;
556 }
557 }
558
559 if (!$findFlag) {
560 $root =& XCube_Root::getSingleton();
561 $language = $root->mContext->getXoopsConfig('language');
562 $helpfile = $this->mXoopsModule->getHelp();
563 $dir = XOOPS_MODULE_PATH . '/' . $this->mXoopsModule->getVar('dirname') . '/language/' . $language . '/help';
564
565/* if (!file_exists($dir . '/' . $helpfile)) {
566 $dir = XOOPS_MODULE_PATH . '/' . $this->mXoopsModule->getVar('dirname') . '/language/english/help';
567 if (!file_exists($dir . '/' . $helpfile)) {
568 return;
569 }
570 } */
571 if (!file_exists($dir . '/' . $helpfile)) {
572 $dir = XOOPS_MODULE_PATH . '/' . $this->mXoopsModule->getVar('dirname') . '/language/english/help';
573 if (!file_exists($dir . '/' . $helpfile)) {
574 // Try XOOPS_TRUST_PATH for D3 modules
575 $trustDir = XOOPS_TRUST_PATH . '/modules/' . $this->mXoopsModule->getVar('dirname') . '/language/' . $language . '/help';
576 if (!file_exists($trustDir . '/' . $helpfile)) {
577 $trustDir = XOOPS_TRUST_PATH . '/modules/' . $this->mXoopsModule->getVar('dirname') . '/language/english/help';
578 if (!file_exists($trustDir . '/' . $helpfile)) {
579 return;
580 }
581 }
582 $dir = $trustDir;
583 }
584 }
585
586 $lines = file($dir . '/' . $helpfile);
587 foreach ($lines as $line) {
588 foreach ($searchArgs->getKeywords() as $word) {
589 if (stripos($line, (string) $word) !== false) {
590 $url = XOOPS_MODULE_URL . '/legacy/admin/index.php?action=Help&amp;dirname=' . $this->mXoopsModule->getVar('dirname');
591 $searchArgs->addRecord($this->mXoopsModule->getVar('name'), $url, _HELP);
592 return;
593 }
594 }
595 }
596 }
597 }
598 }
599
600 public function doLegacyGlobalSearch($queries, $andor, $max_hit, $start, $uid)
601 {
602 $ret = [];
603 $results = $this->mXoopsModule->search($queries, $andor, $max_hit, $start, $uid);
604
605 if (is_array($results) && count($results) > 0) {
606 foreach ($results as $result) {
607 $item = [];
608 if (isset($result['image']) && $result['image'] !== '') {
609 if (file_exists(XOOPS_ROOT_PATH . '/uploads/' . $result['image'])) {
610 $item['image'] = XOOPS_URL . '/uploads/' . $result['image'];
611 } else {
612 // TODO @gigamaster change module dirname to images/icons
613 // $item['image'] = XOOPS_URL . '/modules/' . $this->mXoopsModule->get('dirname') . '/' . $result['image'];
614 $item['image'] = XOOPS_URL . '/images/icons/' . $result['image'];
615 }
616 } else {
617 $item['image'] = XOOPS_URL . '/images/icons/file.svg';
618 }
619
620 $item['link'] = XOOPS_URL . '/modules/' . $this->mXoopsModule->get('dirname') . '/' . $result['link'];
621 $item['title'] = $result['title'];
622 $item['uid'] = $result['uid'];
623
624 //
625 // TODO If this service will come to web service, we should
626 // change format from unixtime to string by timeoffset.
627 //
628 $item['time'] = $result['time'] ?? 0;
629
630 $ret[] = $item;
631 }
632 }
633
634 return $ret;
635 }
636
643 public function hasAdminIndex()
644 {
645 $dmy =& $this->mXoopsModule->getInfo();
646 return isset($this->mXoopsModule->modinfo['adminindex']) && null !== $this->mXoopsModule->modinfo['adminindex'];
647 }
648
655 public function getAdminIndex()
656 {
657 $dmy =& $this->mXoopsModule->getInfo();
658 return XOOPS_MODULE_URL . '/' . $this->mXoopsModule->get('dirname') . '/' . $this->mXoopsModule->modinfo['adminindex'];
659 }
660
661 public function getAdminMenu()
662 {
663 if ($this->_mAdminMenuLoadedFlag) {
664 return $this->mAdminMenu;
665 }
666
667 $info =& $this->mXoopsModule->getInfo();
668 $root =& XCube_Root::getSingleton();
669
670 //
671 // Load admin menu, and add preference menu by own judge.
672 //
673 $this->mXoopsModule->loadAdminMenu();
674 if ($this->mXoopsModule->get('hasnotification')
675 || (isset($info['config']) && is_array($info['config']))
676 || (isset($info['comments']) && is_array($info['comments']))) {
677 $this->mXoopsModule->adminmenu[] = [
678 'link' => $root->mController->getPreferenceEditUrl($this->mXoopsModule),
679 'title' => _PREFERENCES,
680 'absolute' => true
681 ];
682 }
683
684 if ($this->mXoopsModule->hasHelp()) {
685 $this->mXoopsModule->adminmenu[] = [
686 'link' => $root->mController->getHelpViewUrl($this->mXoopsModule),
687 'title' => _HELP,
688 'absolute' => true
689 ];
690 }
691
692 $this->_mAdminMenuLoadedFlag = true;
693
694 if ($this->mXoopsModule->adminmenu) {
695 $dirname = $this->mXoopsModule->get('dirname');
696 foreach ($this->mXoopsModule->adminmenu as $menu) {
697 if (!isset($menu['absolute']) || (isset($menu['absolute']) && true !== $menu['absolute'])) {
698 $menu['link'] = XOOPS_MODULE_URL . '/' . $dirname . '/' . $menu['link'];
699 }
700 $this->mAdminMenu[] = $menu;
701 }
702 }
703
704 return $this->mAdminMenu;
705 }
706}
[Abstract] Represents modules and used for Legacy_Controller
doActionSearch(&$searchArgs)
[Abstract] This method is called back by the action search feature in the control panel.
& createCacheInfo()
Initializes a cache information object, and returns it.
setAttribute($key, $value)
Sets $value with $key to attributes.
getAdminMenu()
Gets an array having menus for the side menu of the control panel.
hasAdminIndex()
Gets a value indicating whether this module has the page controller in the control panel side.
$mCacheInfo
Legacy_AbstractCacheInformation - The cached instance.
$mModuleConfig
[READ ONLY] Map Array - std::map<string, string>
$mRender
XCube_RenderTarget - The render target instance for this module.
setModuleConfig($config)
Binds array of xoops module config to the property.
getModuleConfig(string $key=null)
Gets a value form xoops module config with $key.
& getXoopsModule()
Gets the binded XoopsModule instance.
& getCacheInfo()
Gets the cache information instance.
hasAttribute($key)
Gets a value indicating whether the value specified by $key exists.
isEnableCache()
Gets a value indicating whether the current module has a option of configurations to use the cache sy...
getRenderSystemName()
Gets a name of the dependency render system.
& getRenderSystem()
Gets the dependency render system.
setXoopsModule(&$xoopsModule)
Binds an instance of XoopsModule to the property.
$mAttributes
[READ ONLY] Map Array - std::map<string, mixed> - used freely for this module.
__construct(&$module, $loadConfig=true)
constructor
isActive()
Gets a value indicating whether this modules is an active.
getAttribute($key)
Gets a value of attributes with $key.
startup()
[Abstract] This method is called by the controller strategy, if this module is the current module.
getAdminIndex()
[Abstract] Gets an absolute URL indicating the top page of this module for the control panel side.
& getRenderTarget()
Gets the render target instance.
_createCacheInfo()
Creates a cache information instance and returns it.
_createRenderTarget()
Creates a render target instance and returns it.
$mXoopsModule
[READ ONLY] XoopsModule
doLegacyGlobalSearch($queries, $andor, $max_hit, $start, $uid)
This method is called back by the xoops global search feature.
Used for adapting $xoopsModule to imitate XOOPS2 responses.
doActionSearch(&$searchArgs)
This method is called back by the action search feature in the control panel.
getAdminMenu()
Gets an array having menus for the side menu of the control panel.
hasAdminIndex()
[Final] Gets a value indicating whether this module has the page controller in the control panel side...
$mAdminMenu
Complex Array - cached.
getAdminIndex()
Gets an absolute URL indicating the top page of this module for the control panel side.
doLegacyGlobalSearch($queries, $andor, $max_hit, $start, $uid)
This method is called back by the xoops global search feature.