mirror of
https://github.com/e107inc/e107.git
synced 2025-07-29 10:50:25 +02:00
redirection class added.
This commit is contained in:
41
class2.php
41
class2.php
@@ -9,9 +9,9 @@
|
||||
* General purpose file
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/class2.php,v $
|
||||
* $Revision: 1.131 $
|
||||
* $Date: 2009-08-19 14:39:57 $
|
||||
* $Author: secretr $
|
||||
* $Revision: 1.132 $
|
||||
* $Date: 2009-08-20 13:54:40 $
|
||||
* $Author: e107coders $
|
||||
*
|
||||
*/
|
||||
//
|
||||
@@ -957,32 +957,15 @@ $sql->db_Mark_Time('Start: Signup/splash/admin');
|
||||
define('e_SIGNUP', e_BASE.(file_exists(e_BASE.'customsignup.php') ? 'customsignup.php' : 'signup.php'));
|
||||
define('e_LOGIN', e_BASE.(file_exists(e_BASE.'customlogin.php') ? 'customlogin.php' : 'login.php'));
|
||||
|
||||
// --------- Send user to Membersonly-page when not logged in ---------------.
|
||||
if ($pref['membersonly_enabled'] && !USER && e_SELF != SITEURL.e_SIGNUP && e_SELF != SITEURL.'index.php' && e_SELF != SITEURL.'fpw.php' && e_SELF != SITEURL.e_LOGIN && strpos(e_PAGE, 'admin') === FALSE && e_SELF != SITEURL.'membersonly.php' && e_SELF != SITEURL.'sitedown.php')
|
||||
if(($pref['membersonly_enabled'] && !isset($_E107['allow_guest'])) || $pref['maintainance_flag'])
|
||||
{
|
||||
if(!isset($_E107['allow_guest']))
|
||||
{
|
||||
if(e_AJAX_REQUEST || e_PAGE == 'e_ajax.php' || e_PAGE == 'e_js.php' || e_PAGE == 'e_jslib.php')
|
||||
{
|
||||
exit;
|
||||
}
|
||||
// remember the url for after-login.
|
||||
$afterlogin = e_COOKIE.'_afterlogin';
|
||||
$url = (e_QUERY ? e_SELF.'?'.e_QUERY : e_SELF);
|
||||
session_set($afterlogin,$url,time()+300);
|
||||
header('Location: '.e_HTTP.'membersonly.php');
|
||||
exit();
|
||||
}
|
||||
//XXX move force_userupdate() also?
|
||||
require_once(e_HANDLER."redirection_class.php");
|
||||
$red = new redirection;
|
||||
$red->checkMaintenance();
|
||||
$red->checkMembersOnly();
|
||||
}
|
||||
|
||||
// ----- Redirect to previously logged-in page ---------------------------.
|
||||
if(USER && $pref['membersonly_enabled'] && ($_SESSION[e_COOKIE.'_afterlogin'] || $_COOKIE[e_COOKIE.'_afterlogin']))
|
||||
{
|
||||
$url = ($_SESSION[e_COOKIE.'_afterlogin']) ? $_SESSION[e_COOKIE.'_afterlogin'] : $_COOKIE[e_COOKIE.'_afterlogin'];
|
||||
session_set(e_COOKIE.'_afterlogin',FALSE,-1000);
|
||||
header('Location: '.$url);
|
||||
exit();
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if(!isset($_E107['no_prunetmp']))
|
||||
@@ -990,12 +973,6 @@ if(!isset($_E107['no_prunetmp']))
|
||||
$sql->db_Delete('tmp', 'tmp_time < '.(time() - 300)." AND tmp_ip!='data' AND tmp_ip!='submitted_link'");
|
||||
}
|
||||
|
||||
if ($pref['maintainance_flag'] && ADMIN == FALSE && strpos(e_SELF, 'admin.php') === FALSE && strpos(e_SELF, 'sitedown.php') === false)
|
||||
{
|
||||
header('Location: '.SITEURL.'sitedown.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$sql->db_Mark_Time('(Start: Login/logout/ban/tz)');
|
||||
|
||||
|
130
e107_handlers/redirection_class.php
Normal file
130
e107_handlers/redirection_class.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/*
|
||||
+ ----------------------------------------------------------------------------+
|
||||
| e107 website system
|
||||
|
|
||||
| <20>Steve Dunstan 2001-2002
|
||||
| http://e107.org
|
||||
| jalist@e107.org
|
||||
|
|
||||
| Released under the terms and conditions of the
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/redirection_class.php,v $
|
||||
| $Revision: 1.1 $
|
||||
| $Date: 2009-08-20 13:54:42 $
|
||||
| $Author: e107coders $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
class redirection
|
||||
{
|
||||
|
||||
var $self_exceptions = array();
|
||||
|
||||
var $page_exceptions = array();
|
||||
/**
|
||||
* Manage Member-Only Mode.
|
||||
*/
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->self_exceptions = array(SITEURL.e_SIGNUP, SITEURL.'index.php', SITEURL.'fpw.php', SITEURL.e_LOGIN, SITEURL.'membersonly.php');
|
||||
$this->page_exceptions = array('e_ajax.php', 'e_js.php', 'e_jslib.php', 'sitedown.php');
|
||||
}
|
||||
|
||||
public function checkMaintenance()
|
||||
{
|
||||
if(ADMIN == TRUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!e107::getPref('maintainance_flag') || (strpos(e_SELF, 'admin.php') !== FALSE) || (strpos(e_SELF, 'sitedown.php') !== FALSE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->redirect(SITEURL.'sitedown.php');
|
||||
}
|
||||
/** check if user is logged in.
|
||||
*
|
||||
*/
|
||||
|
||||
public function checkMembersOnly()
|
||||
{
|
||||
|
||||
if(!e107::getPref('membersonly_enabled'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (USER && !e_AJAX_REQUEST)
|
||||
{
|
||||
$this->restoreMembersOnlyUrl();
|
||||
return;
|
||||
}
|
||||
if (e_AJAX_REQUEST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (strpos(e_PAGE, 'admin') !== FALSE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (in_array(e_SELF, $this->self_exceptions))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (in_array(e_PAGE, $this->page_exceptions))
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (e107::getPref('membersonly_exceptions') as $val)
|
||||
{
|
||||
$srch = trim($val);
|
||||
if (strpos(e_SELF, $srch) !== FALSE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->saveMembersOnlyUrl();
|
||||
$this->redirect(e_HTTP.'membersonly.php');
|
||||
}
|
||||
|
||||
/** Store the current URL so that it can retrieved after login.
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
private function saveMembersOnlyUrl()
|
||||
{
|
||||
// remember the url for after-login.
|
||||
$afterlogin = e_COOKIE.'_afterlogin';
|
||||
$url = (e_QUERY ? e_SELF.'?'.e_QUERY : e_SELF);
|
||||
session_set($afterlogin, $url, time() + 300);
|
||||
}
|
||||
|
||||
|
||||
/** Restore the previously saved URL, and redirect the User to it after login.
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
private function restoreMembersOnlyUrl()
|
||||
{
|
||||
if (USER && ($_SESSION[e_COOKIE.'_afterlogin'] || $_COOKIE[e_COOKIE.'_afterlogin']))
|
||||
{
|
||||
$url = ($_SESSION[e_COOKIE.'_afterlogin']) ? $_SESSION[e_COOKIE.'_afterlogin'] : $_COOKIE[e_COOKIE.'_afterlogin'];
|
||||
session_set(e_COOKIE.'_afterlogin', FALSE, -1000);
|
||||
$this->redirect($url);
|
||||
}
|
||||
}
|
||||
|
||||
function redirect($url)
|
||||
{
|
||||
header('Location: '.$url);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user