Hi there,
I am starting to get into the dark world of writing plug-ins and extensions. I have my first one (extension) up and running now in this post.
I am now thinking though that this would be better handled with a plug-in instead so that people could use it in this way below :
{exp:logout_redirect url="http://www.yahoo.com"}
Logout Of The System
{/exp:logout_redirect}
Currently I have this code in my plug-in :
<?php
$plugin_info = array(
'pi_name' => 'Logout Redirect',
'pi_version' =>'1.0',
'pi_author' =>'Mark Bowen',
'pi_author_url' => 'http://www.markbowendesign.com/',
'pi_description' => 'Configurable User Logout Redirection Paths',
'pi_usage' => Logout_redirect::usage()
);
class Logout_redirect
{
var $return_data = "";
function Logout_redirect()
{
global $TMPL, $FNS, $EXT;
$parameter = $TMPL->fetch_param('url');
//---------------------------------------------
// Taken from system/core/core.functions.php
//---------------------------------------------
// $qs = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
// $logout_link = $this->fetch_site_index(0, 0).$qs.'ACT='.$this->fetch_action_id('Member', 'member_logout');
$this->return_data = "<a href="http://$parameter" title='Logout'>".$TMPL->tagdata."</a>";
// $FNS->redirect($redirect_url);
// $EXT->end_script = TRUE;
// END
}
// ----------------------------------------
// Plugin Usage
// ----------------------------------------
// This function describes how the plugin is used.
// Make sure and use output buffering
function usage()
{
ob_start();
?>
The Logout Redirect Plugin allows you to redirect a user
to a page of your choosing upon logging out of the EE system.
{exp:logout_redirect url="http://www.yahoo.com"}
Logout
{/exp:logout_redirect}
This will convert the 'Logout' text that is inside the plug-in
tags to be a link that logs the user out of the EE system and will
redirect them to the url specified at the top of the tag.
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
// END
}
?>
This works so far as it returns the text that is wrapped between the tag-pair and adds in the url so that it directs you to the page you want. What I want it to do however is slightly more complex. The extension that I created over at the previously mentioned post allows you to set a redirect url in the extensions settings and when a person logs out it hooks into the member_member_logout hook and first of all logs them out and then redirects them to the page in the settings.
I would like to do that (without the use of an extension) here in this plug-in so that whatever is wrapped inside the plug-in tag pair is turned into a link that first of all logs the user out of the system and then re-directs them to the url specified in the plug-in tag parameter.
Any help with this would be greatly appreciated.
Best wishes,
Mark
Hiya,
Just thinking about this some more and was thinking that in order for this to work then the link is obviously going to need to do two things :
1 - Log the user out and then, 2 - Redirect them.
I could be wrong but I don’t think that I will be able to do this with a static link so I was wondering if there would be anyway of tying this into the extension that I have created so that the plugin would look like this :
{exp:logout_redirect url="http://www.yahoo.com"}
Log Me Out
{/exp:logout_redirect}
This would then create a link that would somehow tie in with the Logout Redirect extension that I have created and would use the url=”http://www.yahoo.com” part in the plugin tag to somehow activate the logout and redirect extension in some way?
Also I would like to extend the plugin so that there would be extra parameters for extra html markup code such as class etc but I can probably do that easily enough once I have it spitting out a link that can actually take care of this.
Any thoughts on this would be massively appreciated.
Best wishes,
Mark
Does anyone have any ideas how I could achieve this at all?
I’m sure that this must be possible as ExpressionEngine can do anything 😊 but I just can’t figure out how I can use a plug-in that allows a link to do these things as a plug-in mainly changes something after it has processed but I need to create a link that is going to do two things when clicked?
Any help with this would be very gratefully received.
Best wishes,
Mark
Hey Mark,
I don’t think this is really something for the realm of a plugin on it’s own.
Hooks are specifically to do the sort of thing you want to do, which is to change the behavior of EE functionality that is not template based. Plugins are by their nature unable to do what you want on the logout front. But I get what you are going for.
Now here is what you could do.
You could have a plugin that wraps around the logout link that EE generates by default. The plugin could add to the query string generated.
So a default logout url:
http://expressionengine.com/?ACT=10
Would end up looking like this once the plugin has done it’s thing:
http://expressionengine.com/?ACT=10?&url=http://www.yahoo.com
Then you have an extension that works in tandem with that to interpret the url info and redirect based off of that.
This is all very high level. I’ve not even looked at the code to make sure that its workable. But on the face of it, I think it should work.
Jamie
Hi Jamie,
Thanks for the info. Pretty sure I can get something working with an idea I have that is based around the same thing that you have mentioned there. I was hoping for some clever EE way of handling this but there wouldn’t be because a link can’t really do two things and I secretly knew that in my head but I definitely have a way around this one!! 😊
Will keep you all informed.
Best wishes,
Mark
Hi Jamie,
Just to keep you up to where I am on this to see if you can throw any other ideas my way. I tried an exceptionally easy test on a local DEV server which has the logout link without me doing anything as this :
http://localhost:8888/ee161/index.php?ACT=10
That is just the normal logout link code shown above. I tried simply pasting this :
http://localhost:8888/ee161/index.php?ACT=10&url=www.yahoo.com
into the browser hoping that it would log me out but I just get :
Invalid URI
I guess that it isn’t possible to tack anything on the end of the link then? Saying that I did try this :
http://localhost:8888/ee161/index.php?ACT=10&url1=www&url2=yahoo&url3=com
This logged me out of the system and it doesn’t seem that the extra bits tacked on the end did any harm at all.
Perhaps this is the way to go. I am thinking that I can get the url1, url2 and url3 segments (or however many there are, out of the URL and then re-constitute them to make the re-direction link although I do think that this is quite messy and there must be a better way?
I do have one other way in my head that would definitely work but it would involve creating a template which I would really like not to have to do.
Any more ideas on this would be great. Thanks.
Best wishes,
Mark
Mark,
The periods were probably causing the problem. Query strings can be a security problem so EE is pretty picky about what it allows through.
Your solution is certainly workable. You could also work out your own replacements for the http:// and . parts and slash parts of the url and then replace those with the real ones in the extension.
So a link to:
http://www.yahoo.com
Could become something like this:
HTTPwwwDOTyahooDOTcom
I haven’t had my morning tea yet though so its entirely possible my brain is just spewing garbage.
Jamie
Hi Jamie,
Yup my thoughts exactly. I think that I would have to re-constitute the parts afterwards which should do what I want although there may be more than 3 parts for URLs such as myarea.mysite.co.uk where that would have four url parts as opposed to www.yahoo.com which would just have 3.
I will look into this some more. Thanks for the info.
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.