XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AdminBlockMenu.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16define('LEGACY_ADMIN_BLOCK_MENU_CACHEPREFIX', XOOPS_CACHE_PATH.'/'.urlencode(XOOPS_URL).'_admin_block_menu_');
17
29{
30 public $mModules = [];
31
38
39 public function getName()
40 {
41 return 'block_menu';
42 }
43
44 public function getTitle()
45 {
46 return _AD_BLOCK_MENU;
47 }
48
49 public function getEntryIndex()
50 {
51 return 0;
52 }
53
54 public function isEnableCache()
55 {
56 return false;
57 }
58
59 public function execute()
60 {
61 $root =& XCube_Root::getSingleton();
62
63 // load admin message catalog of legacy for _AD_LEGACY_LANG_NO_SETTING, even if the current module is not Legacy.
64 $langMgr =& $root->mLanguageManager;
65 $langMgr->loadModuleAdminMessageCatalog('legacy');
66 // load info 'modinfo' message catalog
67 $langMgr->loadModinfoMessageCatalog('legacy');
68
69 // User Group
70 $controller =& $root->mController;
71 $user =& $root->mContext->mXoopsUser;
72 $groups = implode(',', $user->getGroups());
73 $cachePath = LEGACY_ADMIN_BLOCK_MENU_CACHEPREFIX . md5(XOOPS_SALT . "($groups)". $langMgr->mLanguageName).'.html';
74 // Render target & cache
75 $render =& $this->getRenderTarget();
76 if (file_exists($cachePath)) {
77 $render->mRenderBuffer = file_get_contents($cachePath);
78 return;
79 }
80 $render->setAttribute('legacy_module', 'legacy');
81
82 $this->mCurrentModule =& $controller->mRoot->mContext->mXoopsModule;
83
84 if (($this->mCurrentModule->get('dirname') === 'legacy') && xoops_getrequest('action') === 'help') {
85 $moduleHandler =& xoops_gethandler('module');
86 $t_module =& $moduleHandler->getByDirname(xoops_gethandler('legacy'));
87 if (is_object($t_module)) {
88 $this->mCurrentModule =& $t_module;
89 }
90 }
91
92 // DB & Permissions
93 $db=&$controller->getDB();
94
95 $mod = $db->prefix('modules');
96 $perm = $db->prefix('group_permission');
97
98 //
99 // Users who belong to the ADMIN group have full permissions, so we need to prepare two types of SQL.
100 //
101 if ($root->mContext->mUser->isInRole('Site.Owner')) {
102 $sql = "SELECT DISTINCT weight, mid FROM {$mod} WHERE isactive=1 AND hasadmin=1 ORDER BY weight, mid";
103 } else {
104 $sql = "SELECT DISTINCT {$mod}.weight, {$mod}.mid FROM {$mod},{$perm} " .
105 "WHERE {$mod}.isactive=1 AND {$mod}.mid={$perm}.gperm_itemid AND {$perm}.gperm_name='module_admin' AND {$perm}.gperm_groupid IN ({$groups}) " .
106 "AND {$mod}.hasadmin=1 " .
107 "ORDER BY {$mod}.weight, {$mod}.mid";
108 }
109
110
111 $result=$db->query($sql);
112
113 $handler =& xoops_gethandler('module');
114
115 while ([$weight, $mid] = $db->fetchRow($result)) {
116 $xoopsModule = & $handler->get($mid);
117 $module =& Legacy_Utils::createModule($xoopsModule, false);
118
119 $this->mModules[] =& $module;
120 unset($module);
121 }
122 // Template
123 $tpl = $db->prefix('tplfile');
124 $tpl_modules = [];
125 $sql = "SELECT DISTINCT tpl_module FROM {$tpl}";
126 $result = $db->query($sql);
127 while ($row = $db->fetchArray($result)) {
128 $tpl_modules[] = $row['tpl_module'];
129 }
130 $render->setAttribute('tplmodules', $tpl_modules);
131
132 // Set Template & attributes
133 $render->setTemplateName('legacy_admin_block_menu.html');
134 $render->setAttribute('modules', $this->mModules);
135 $render->setAttribute('currentModule', $this->mCurrentModule);
136
137 // Render System
138 $renderSystem =& $root->getRenderSystem($this->getRenderSystemName());
139 // Render as Block
140 $renderSystem->renderBlock($render);
141 file_put_contents($cachePath, $render->mRenderBuffer);
142 }
143
144 public static function clearCache()
145 {
146 $adminDashboardMenucache = glob(LEGACY_ADMIN_BLOCK_MENU_CACHEPREFIX . '*.html');
147 if ($adminDashboardMenucache) {
148 foreach ($adminDashboardMenucache as $file) {
149 unlink($file);
150 }
151 }
152 }
153}