简体   繁体   English

Joomla 2.5-可见的菜单项-但需要登录才能访问

[英]Joomla 2.5 - Visible Menu Item - but need login to access

I followed this tutorial about ACL - http://community.joomla.org/blogs/community/1252-16-acl.html 我遵循了有关ACL的本教程-http: //community.joomla.org/blogs/community/1252-16-acl.html

To make everything clear: this is what I need: 明确说明:这就是我需要的:

  1. having a menu item that is linking to an article 有一个链接到文章的菜单项
  2. a user enters (not logged yet) the web site (it does not matter if the user is already registered or not) 用户进入(尚未登录)网站(用户是否已经注册都没有关系)
  3. this user should see the menu item 该用户应该看到菜单项
  4. the user clicks on the menu item 用户单击菜单项
    • if the user is NOT logged in - the user is asked to enter the username/pass 如果用户未登录-要求用户输入用户名/密码
    • if the user is logged in -> goto 6 如果用户已登录-> goto 6
  5. after login is ok, the user can see the content of the article where the menu item was linked. 登录确定后,用户可以看到链接菜单项的文章内容。

My aim is to have a menu item that would be visible for all users: logged in and not logged in. But when clicked - only logged in users can view the content where the menu item is pointing. 我的目标是拥有一个对所有用户可见的菜单项:已登录但未登录。但是单击时-只有已登录的用户才能查看菜单项所指向的内容。 In case the user is not logged in -> log in form should be displayed. 如果用户未登录-应该显示登录表单。

After following the above tutorial I got a menu item that is completely invisible for users that are NOT logged in. 遵循上述教程之后,我得到了一个菜单项,该菜单项对于未登录的用户完全不可见。

How can I make the menu item to be visible for all, but need login to see content? 如何使菜单项对所有人可见,但需要登录才能看到内容?

Thank you. 谢谢。

EDIT 1: 编辑1:

I just found this solution http://docs.joomla.org/Auto_redirect_guests_to_login Is it the only solution? 我刚刚找到了此解决方案http://docs.joomla.org/Auto_redirect_guests_to_login这是唯一的解决方案吗? I have a huge tree menu structure. 我有一个巨大的树菜单结构。 That means I need to have a clone of my huge menu... And everytime I change a menu item name - I should do it twice (in visible menu and in invisible menu). 这意味着我需要克隆一个巨大的菜单...每次更改菜单项名称时,我都应该进行两次(在可见菜单和不可见菜单中)。 Are there any other solutions without having 2 menus? 没有2个菜单,还有其他解决方案吗?

EDIT 2: 编辑2:

Found another solution (hacking core files). 找到了另一个解决方案(破解核心文件)。 This is when menu item is set to "public" but the article ACL is set to "registered" 这是菜单项设置为“公共”但文章ACL设置为“已注册”的情况

components/com_content/views/article/view.html.php 组件/com_content/views/article/view.html.php

from

// Check the view access to the article (the model has already computed the values).
if ($item->params->get('access-view') != true && (($item->params->get('show_noauth') != true &&  $user->get('guest') ))) {
  JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
  return;
}

to

// Check the view access to the article (the model has already computed the values).
if ($item->params->get('access-view') != true && (($item->params->get('show_noauth') != true &&  $user->get('guest') ))) {
  // Redirect to login
  $uri = JFactory::getURI();
  $app->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), JText::_('Members please login to view this page. If you are not a member please <a href="/component/users/?view=registration">register here<a>'));
  return;
}

How can I override that code and avoid hacking core files? 如何覆盖该代码并避免对核心文件进行黑客攻击?

Or maybe there is a more elegant solution? 也许还有更优雅的解决方案?

Thanks. 谢谢。

What you can do is a template override and add the login form to the page that provides the message. 您可以做的是覆盖模板,并将登录表单添加到提供消息的页面上。 A template override will allow you to add extras to pages without hacking the core files, therefore when updating Joomla, it will still be there. 模板替代功能可让您在不破坏核心文件的情况下向页面添加其他功能,因此在更新Joomla时,它仍将存在。

For more information on how to override, please see the link below: 有关如何覆盖的更多信息,请参见以下链接:

http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM