Hi there,
I have read a lot of posts from people wanting a way to redirect users to a configurable URL upon logging out of the EE system.
I thought I would give a go at writing an extension to handle this.
I now admit that I have absolutely no idea of what I am doing at all. I tried the code below for an extension but every time I go to the Extensions Manager I just get a completely blank page and there is no source to the page.
<?php
//------------------------------------
// Logout Redirect Extension
// using 'member_member_logout' hook
// author: Mark Bowen
//------------------------------------
if ( ! defined('EXT'))
{
exit('Invalid file request');
}
class Logout_redirect
{
var $settings = array();
var $name = 'Logout Redirect';
var $classname = 'Logout_redirect';
var $version = '1.0';
var $description = 'Provide a simple setting to redirect the user to a URL upon logging out of the system.';
var $settings_exist = 'y';
var $docs_url = '';
//------------------------------------
// Constructor - Settings
//------------------------------------
function Logout_redirect($settings='')
{
$this->settings = $settings;
}
// END
//------------------------------------
// Activate Extension
//------------------------------------
function activate_extension()
{
global $DB;
$DB->query($DB->insert_string('exp_extensions',
array(
'extension_id' => '',
'class' => $this->classname,
'method' => "logout_redirect",
'hook' => "member_member_logout",
'settings' => $default_settings,
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
}
// END
//------------------------------------
// Update Extension
//------------------------------------
function update_extension($current='')
{
global $DB;
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
if ($current > '1.0')
{
// Update to next version
}
$DB->query("UPDATE exp_extensions
SET version = '".$DB->escape_str($this->version)."'
WHERE class = '$this->classname'");
}
// END
//------------------------------------
// Extension Settings
//------------------------------------
function settings()
{
$settings = array();
$settings['redirect_url'] = "/contact/";
return $settings;
}
// END
//------------------------------------
// Logout Redirect Function
//------------------------------------
function logout_redirect()
{
$FNS->redirect("http://www.yahoo.com");
}
// END
}
?>
I tried commenting out the last part of the extension where it has my function :
//------------------------------------
// Logout Redirect Function
//------------------------------------
// function logout_redirect()
// {
// $FNS->redirect("http://www.yahoo.com");
// }
// END
and this allows the extension to be enabled and the setting to be set but if the function is un-commented then it all goes hay-wire!!
I was just wondering if anyone could possibly give me a push in the right direction to get this working?
Also how would I go about using a language file to hold the redirect_url setting instead of having it directly inside the extension file?
One last question. I was also wondering if it is possible to have a plug-in that somehow references this so that when the {path=LOGOUT} link is used in a template it could perhaps send the redirect_url setting to it instead of using the setting in the extension so that if you want you can have different redirects depending upon which logout link on which page you click.
If anyone has any idea as to what I am babbling on about and could possibly lend me a push or shove in the right direction to get this all up and working then I would really appreciate it. I would rather not have the answer given to me as I would love to say that I managed to make this myself but any help would be massively appreciated.
Thanks in advance for any ideas.
Best wishes,
Mark
