dtl4521 2011-08-29 22:52
浏览 70
已采纳

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

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.

Ok. let's make it simplier:

  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

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.

But hold on a minute...

  • In the link change index.php?option=com_users to index.php?option=com_user
  • And let's try on Joomla 1.5...

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

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.

Edit: 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

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条回答 默认 最新

  • dpdhnd3577 2011-08-30 12:18
    关注

    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.

    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                        
                }
            }       
        }       
     }      
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题