From 91c0cbb273af4b6657513537495dbd81f2a3be9b Mon Sep 17 00:00:00 2001 From: marj Date: Wed, 28 Oct 2009 20:26:04 +0000 Subject: [PATCH] review some comments --- e107_admin/ugflag.php | 6 +- e107_handlers/redirection_class.php | 329 ++++++++++++++-------------- 2 files changed, 167 insertions(+), 168 deletions(-) diff --git a/e107_admin/ugflag.php b/e107_admin/ugflag.php index 94728d29d..deb0c5367 100644 --- a/e107_admin/ugflag.php +++ b/e107_admin/ugflag.php @@ -9,8 +9,8 @@ * Administration - Site Maintenance * * $Source: /cvs_backup/e107_0.8/e107_admin/ugflag.php,v $ - * $Revision: 1.6 $ - * $Date: 2009-10-28 16:57:51 $ + * $Revision: 1.7 $ + * $Date: 2009-10-28 20:26:04 $ * $Author: marj_nl_fr $ * */ @@ -94,7 +94,7 @@ $text .= " "; - +//TODO multilanguage pref $text .= " ".UGFLAN_5." diff --git a/e107_handlers/redirection_class.php b/e107_handlers/redirection_class.php index dbc72f141..912e9cefb 100644 --- a/e107_handlers/redirection_class.php +++ b/e107_handlers/redirection_class.php @@ -1,21 +1,21 @@ -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'); + } + + /** + * Perform re-direction when Maintenance Mode is active. + * + * @return void + */ + public function checkMaintenance() + { + // prevent looping. + if(strpos(e_SELF, 'admin.php') !== FALSE || strpos(e_SELF, 'sitedown.php') !== FALSE) { - $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'); - } + return; + } - /** - * Perform re-direction when Maintenance Mode is active. - * - * @return void - */ - public function checkMaintenance() - { - // prevent looping. - if(strpos(e_SELF, 'admin.php') !== FALSE || strpos(e_SELF, 'sitedown.php') !== FALSE) + if(e107::getPref('maintainance_flag')) + { + // if not admin + if(!ADMIN + // or if not mainadmin - ie e_UC_MAINADMIN + || (e_UC_MAINADMIN == e107::getPref('maintainance_flag') && !getperms('0'))) + { + // 307 Temporary Redirect + $this->redirect(SITEURL.'sitedown.php', TRUE, 307); + } + } + else + { + return; + } + } + + + /** + * Check if user is logged in. + * + * @return void + */ + 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'); + } - if(e107::getPref('maintainance_flag')) - { - if(!ADMIN - || (e_UC_MAINADMIN == e107::getPref('maintainance_flag') - && !getperms('0') - ) - ) - { - // 307 Temporary Redirect - $this->redirect(SITEURL.'sitedown.php', TRUE, 307); - } - } - else - { - return; - } - } - - - /** - * Check if user is logged in. - * - * @return void - */ - 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. + * + * @return void + */ + 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); + } - - /** - * Store the current URL so that it can retrieved after login. - * - * @return void - */ - private function saveMembersOnlyUrl() + + /** + * Restore the previously saved URL, and redirect the User to it after login. + * + * @return void + */ + private function restoreMembersOnlyUrl() + { + if(USER && ($_SESSION[e_COOKIE.'_afterlogin'] || $_COOKIE[e_COOKIE.'_afterlogin'])) { - // 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. - * - * @return void - */ - 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); - } - } - + $url = ($_SESSION[e_COOKIE.'_afterlogin']) ? $_SESSION[e_COOKIE.'_afterlogin'] : $_COOKIE[e_COOKIE.'_afterlogin']; + session_set(e_COOKIE.'_afterlogin', FALSE, -1000); + $this->redirect($url); + } + } - /** - * Redirect to the given URI - * - * @param string $url - * @param boolean $replace - default TRUE - * @param integer|null $http_response_code - default NULL - * @return void - */ - public function redirect($url, $replace = TRUE, $http_response_code = NULL) + + /** + * Redirect to the given URI + * + * @param string $url + * @param boolean $replace - default TRUE + * @param integer|null $http_response_code - default NULL + * @return void + */ + public function redirect($url, $replace = TRUE, $http_response_code = NULL) + { + if(NULL == $http_response_code) { - if(NULL == $http_response_code) - { - header('Location: '.$url, $replace); - } - else - { - header('Location: '.$url, $replace, $http_response_code); - } - - // Safari endless loop fix. - header('Content-Length: 0'); - exit(); - } + header('Location: '.$url, $replace); + } + else + { + header('Location: '.$url, $replace, $http_response_code); + } + + // Safari endless loop fix. + header('Content-Length: 0'); + exit(); + } }