【发布时间】:2011-09-08 07:41:16
【问题描述】:
我想限制组件在 Joomla 1.5 中由经理角色访问。
如果仅通过几行代码而不是使用任何组件/扩展来实现,那就太好了。
任何帮助将不胜感激。
谢谢
【问题讨论】:
标签: php joomla components joomla1.5
我想限制组件在 Joomla 1.5 中由经理角色访问。
如果仅通过几行代码而不是使用任何组件/扩展来实现,那就太好了。
任何帮助将不胜感激。
谢谢
【问题讨论】:
标签: php joomla components joomla1.5
非常感谢,拉克什。效果很好。
请注意:就我而言,上面的代码: if($login_user->gid == '23') 必须改为 if($user->gid == '23') 因为 $login_user 未定义。
另外,您在末尾添加了 1 个额外的 } 以匹配 {}。
【讨论】:
因为您想使用自定义编码来限制仅管理器的组件。 所以打开文件管理员/模块/mod_menu/helper.php
在第 167 行。有一个用于组件的 foreach。
$login_user = JFactory::getUser(); // <--------------object for login user------------------------->
foreach ($comps as $row)
{
if ($editAllComponents | $user->authorize('administration', 'edit', 'components', $row->option))
{
if ($row->parent == 0 && (trim($row->admin_menu_link) || array_key_exists($row->id, $subs)))
{
if($login_user->gid == '23') // <--------------check for manager------------------------->
{
$text = $lang->hasKey($row->option) ? JText::_($row->option) : $row->name;
if($text == 'Banner' or $text == 'Polls' ) // <--------------write component name which is visibal to manager only------------------------->
{
$link = $row->admin_menu_link ? "index.php?$row->admin_menu_link" : "index.php?option=$row->option";
if (array_key_exists($row->id, $subs)) {
$menu->addChild(new JMenuNode($text, $link, $row->admin_menu_img), true);
foreach ($subs[$row->id] as $sub) {
$key = $row->option.'.'.$sub->name;
$text = $lang->hasKey($key) ? JText::_($key) : $sub->name;
$link = $sub->admin_menu_link ? "index.php?$sub->admin_menu_link" : null;
$menu->addChild(new JMenuNode($text, $link, $sub->admin_menu_img));
}
$menu->getParent();
} else {
$menu->addChild(new JMenuNode($text, $link, $row->admin_menu_img));
}
}
}else // <--------------else for other group------------------------->
{
// no change in it
$text = $lang->hasKey($row->option) ? JText::_($row->option) : $row->name;
$link = $row->admin_menu_link ? "index.php?$row->admin_menu_link" : "index.php?option=$row->option";
if (array_key_exists($row->id, $subs)) {
$menu->addChild(new JMenuNode($text, $link, $row->admin_menu_img), true);
foreach ($subs[$row->id] as $sub) {
$key = $row->option.'.'.$sub->name;
$text = $lang->hasKey($key) ? JText::_($key) : $sub->name;
$link = $sub->admin_menu_link ? "index.php?$sub->admin_menu_link" : null;
$menu->addChild(new JMenuNode($text, $link, $sub->admin_menu_img));
}
$menu->getParent();
} else {
$menu->addChild(new JMenuNode($text, $link, $row->admin_menu_img));
}
}
}
}
}
【讨论】:
您将无法仅通过几行代码来实现访问控制级别。如果就这么简单,ACL 就没什么大不了了。
您需要一个允许您管理管理员访问级别的扩展程序。看看这些 -
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control/13524
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control/2587
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control/9040 - 还有更高级的专业版
每一个都应该为您提供所需的控制。
【讨论】: