Joomla 1.5 com_user 和导入用户插件,如 Joomla 1.6 及更高版本

在前端访问 Joomla 1.6 和 1.7 中的 com_users 组件时,应用程序会自动从用户"组导入所有插件.显然,如果不想创建一个组件来简单地将一些变量传递给插件,这是非常有用的.

When accessing com_users component in Joomla 1.6 and 1.7 on front-end the application automatically imports all plugins from 'user' group. Obviously it is very useful if one doesn't want to create a component to simply pass some variables to a plugin.

好的.让我们简单点:

  1. 用户获得激活链接:http://example.com/index.php?option=com_users&task=edit&emailactivation=1&u=63&d077b8106=1 并点击它.
  2. 当然,该组件将省略电子邮件激活和其他参数,只需显示编辑个人资料表单"(或访客登录表单).
  3. 然后JAp​​plication从'user'组导入所有插件,这会触发__constructors
  1. User gets an activation link: http://example.com/index.php?option=com_users&task=edit&emailactivation=1&u=63&d077b8106=1 and clicks it.
  2. Of course the component will omit emailactivation and other params simply displying "Edit Profile Form" (or login form for guests).
  3. Then JApplication imports all plugins from 'user' group, which triggers __constructors

基本上,使用插件的 __constructor 可以设置像下面这样的简单操作:

Basically, with plugin's __constructor one can set up simple action like this one below:

class plgUserAccountactivation extends JPlugin
{
    public function __construct(& $subject, $config)
    {
        parent::__construct($subject, $config);

        if(isset($_GET['emailactivation'])) {
            // check token
            // activate account, email or whatever
            // redirect with message
        }
    }
}

哇!它有效,不需要创建一个完整的控制器来处理一个简单的任务.

Wow! It works, it is not necessary to create a whole controller to handle one simple task.

请稍等...

  • 在链接中将 index.php?option=com_users 更改为 index.php?option=com_user
  • 让我们试试 Joomla 1.5...

嘿,嘿,什么都没有发生 com_user 根本没有导入任何东西,也没有调用 __constructor.

Hey, hey, nothing happens com_user didn't import anything at all and __constructor wan't called.

我在 Joomla 1.5 中对此感到非常困扰,我不想编写整个组件.

I am very troubled by this in Joomla 1.5 and I don't feel like writing whole component.

如果有人有什么好主意,请告诉我.

Should anybody have some bright idea, please let me know.

我已通过以下格式发送链接解决了我的问题:

I've solved my problem by sending the link in the following form:

http:/example.com/index.php?option=com_user&task=logout&emailactivation=1&u=63&d077b8106=1

http:/example.com/index.php?option=com_user&task=logout&emailactivation=1&u=63&d077b8106=1

通过这种方式包含用户插件并执行 __constructors.但这太无聊了,因为 task=logout 并没有真正鼓励点击链接.

This way user plugins are included and __constructors are executed. But this is so frivolous as task=logout doesn't really encourage to click in the link.

推荐答案

1.5 的问题是,事件更加有限.您有以下可用事件:Joomla 1.5 插件事件 - 用户.我猜因此你的插件没有启动.

The problem with 1.5 is, that events are more limited. You have the following events available: Joomla 1.5 Plugin Events - User. I guess therefore your plugin is not initiated.

如何将其设为系统插件并检查 URL/请求属性中的激活情况?类似的东西:

How about making this a system plugin and checking for the activation in the URL/request properties? Something like:

class plgSystemUseractiavation extends JPlugin {

  function onAfterInitialise(){

    $u = &JURI::getInstance(); 
    $option = trim(strtolower($u->getVar('option')));
    $emailactivation = trim(strtolower($u->getVar('emailactivation')));

    if( strlen($option  < 1) ){ // for SEF...
        $option = trim(strtolower(JRequest::getString('option')));
    }

    $app =& JFactory::getApplication(); 
    $appName = trim(strtolower($app->getName()));
    if( $appName === 'site' ){
        if( ( $option === 'com_users' ) || ( $option === 'com_user' ) ){
            if( $emailactivation === '1' ){
                // check token
                // activate account, email or whatever
                // redirect with message                        
            }
        }       
    }       
 }      
}

相关文章