问题
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:
- User gets an activation link: http://example.com/index.php?option=com_users&task=edit&emailactivation=1&u=63&d077b8106=1 and clicks it.
- Of course the component will omit emailactivation and other params simply displying "Edit Profile Form" (or login form for guests).
- 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:
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
}
}
}
}
}
来源:https://stackoverflow.com/questions/7236928/joomla-1-5-com-user-and-importing-user-plugins-like-joomla-1-6-and-above