【问题标题】:Joomla 1.5 com_user and importing user plugins like Joomla 1.6 and aboveJoomla 1.5 com_user 和导入用户插件,如 Joomla 1.6 及更高版本
【发布时间】:2011-08-30 20:42:32
【问题描述】:

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

好的。让我们让它更简单:

  1. 用户获得激活链接:http://example.com/index.php?option=com_users&task=edit&emailactivation=1&u=63&d077b8106=1 并点击它。
  2. 当然,该组件将省略 emailactivation 和其他参数,仅显示“编辑个人资料表单”(或访客登录表单)。
  3. 然后 JApplication 从 'user' 组导入所有插件,这会触发 __constructors

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

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
        }
    }
}

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

但是等一下……

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

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

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

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

编辑: 我通过以下形式发送链接解决了我的问题:

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

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

【问题讨论】:

    标签: php model-view-controller joomla joomla1.5 joomla-extensions


    【解决方案1】:

    1.5 的问题是,事件受到更多限制。您有以下可用事件:Joomla 1.5 Plugin Events - User。我想因此您的插件没有启动。

    如何将此作为系统插件并在 URL/请求属性中检查激活?比如:

    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                        
                }
            }       
        }       
     }      
    }
    

    【讨论】:

    • 我需要它作为用户插件,除了你的代码将在所有子页面上执行,即使在“com_content”中
    • 实际上我已经暂时解决了我的问题,请参阅更新后的问题
    • 是的,插件总是被执行的。但是计算工作量并不大,因为它会检查它是否在正确的位置,例如在“com_content”中立即从执行中返回。
    猜你喜欢
    • 2011-07-02
    • 2011-08-12
    • 2011-12-24
    • 1970-01-01
    • 2011-08-14
    • 2012-08-18
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    相关资源
    最近更新 更多