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