From f5ebd83b36f343022977241bd9b570051ece4b0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 3 Dec 2009 22:36:06 +0000 Subject: [PATCH] Endless redirect fixed and needless action/what sets removed --- inc/extensions-functions.php | 13 ++++++++----- inc/filters.php | 6 +++--- inc/functions.php | 2 +- inc/libs/admins_functions.php | 2 +- inc/modules/admin.php | 2 +- inc/modules/admin/admin-inc.php | 2 +- inc/modules/admin/what-config_admins.php | 2 +- inc/modules/index.php | 9 --------- inc/modules/login.php | 2 +- inc/mysql-manager.php | 22 +++++++++++----------- inc/wrapper-functions.php | 4 ++-- 11 files changed, 30 insertions(+), 36 deletions(-) diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php index 001aee7e1d..a9c6fd9239 100644 --- a/inc/extensions-functions.php +++ b/inc/extensions-functions.php @@ -960,9 +960,9 @@ function ifModuleHasMenu ($mod, $forceDb = false) { // Check cache and count hit $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y'); incrementStatsEntry('cache_hits'); - } elseif ($mod == 'admin') { - // Admin module has always a menu! - $ret = true; + } else { + // Admin/guest/member/sponsor modules have always a menu! + $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); } } elseif ((isExtensionInstalled('sql_patches')) && (getExtensionVersion('sql_patches') >= '0.3.6') && ((!isExtensionActive('cache')) || ($forceDb === true))) { // Check database for entry @@ -984,8 +984,11 @@ function ifModuleHasMenu ($mod, $forceDb = false) { // Free memory SQL_FREERESULT($result); } elseif (!isExtensionInstalled('sql_patches')) { - // No sql_patches installed, so maybe in admin area or no admin registered? - $ret = (((isAdmin()) || (!isAdminRegistered())) && ($mod == 'admin')); // Then there is a menu! + // No sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered? + $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu! + } else { + // Unsupported state! + debug_report_bug('This should never be reached.'); } // Return status diff --git a/inc/filters.php b/inc/filters.php index b4970d71b8..35ff120eb7 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -705,7 +705,7 @@ function FILTER_DETERMINE_WHAT_ACTION () { if (!isWhatSet()) setWhat(getWhatFromModule(getModule())); // Fix 'action' if not yet set - if (!isActionSet()) setAction(getModeAction(getModule(), getWhat())); + if (!isActionSet()) setAction(getActionFromModuleWhat(getModule(), getWhat())); } else { // Set action/what to empty setAction(''); @@ -717,7 +717,7 @@ function FILTER_DETERMINE_WHAT_ACTION () { if ((!isWhatSet()) && (!isActionSet()) && (getOutputMode() != 1) && (getOutputMode() != -1)) { if (getModule() == 'admin') { // Set 'action' value to 'login' in admin menu - setAction(getModeAction(getModule(), getWhat())); + setAction(getActionFromModuleWhat(getModule(), getWhat())); } elseif ((getModule() == 'index') || (getModule() == 'login')) { // Set 'what' value to 'welcome' in guest and member menu setWhatFromConfig('index_home'); @@ -803,7 +803,7 @@ function FILTER_CHECK_ADMIN_ACL () { $action = getAction(); if (isWhatSet()) { // Get action value by what-value - $action = getModeAction('admin', getWhat()); + $action = getActionFromModuleWhat('admin', getWhat()); } // END - if // Check for access control line of current menu entry diff --git a/inc/functions.php b/inc/functions.php index f9bdf90e02..a8870527a7 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -936,7 +936,7 @@ function redirectToUrl ($URL) { } // END - if // Three different ways to debug... - //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL)); + /* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL)); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL); //* DEBUG: */ die($URL); diff --git a/inc/libs/admins_functions.php b/inc/libs/admins_functions.php index 4b3aa1bedf..b3336935e2 100644 --- a/inc/libs/admins_functions.php +++ b/inc/libs/admins_functions.php @@ -59,7 +59,7 @@ function adminsCheckAdminAcl ($action, $what) { if (!empty($what)) { // Check for parent menu: // First get it's action value - $parent_action = getModeAction('admin', $what); + $parent_action = getActionFromModuleWhat('admin', $what); // Check with this function... $parent = adminsCheckAdminAcl($parent_action, ''); diff --git a/inc/modules/admin.php b/inc/modules/admin.php index 3455022bc7..51fa7f9e1e 100644 --- a/inc/modules/admin.php +++ b/inc/modules/admin.php @@ -215,7 +215,7 @@ if (!isAdminRegistered()) { // Rewrite overview module if (getWhat() == 'overview') { - setAction(getModeAction(getModule(), getWhat())); + setAction(getActionFromModuleWhat(getModule(), getWhat())); } // END - if // Add data to URL diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index 28dc8a33f1..cd753943fb 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -255,7 +255,7 @@ function doAdminAction () { } // Get action value - $action = getModeAction(getModule(), $what); + $action = getActionFromModuleWhat(getModule(), $what); // Define admin login name and id number $content['login'] = getSession('admin_login'); diff --git a/inc/modules/admin/what-config_admins.php b/inc/modules/admin/what-config_admins.php index 0391c25e6a..6040a1f3ad 100644 --- a/inc/modules/admin/what-config_admins.php +++ b/inc/modules/admin/what-config_admins.php @@ -163,7 +163,7 @@ if ((isPostRequestParameterSet('edit')) && (countPostSelection() > 0)) { $ACL = false; if (isPostRequestParameterSet('what_menu')) { // Check parent ACL - $ACL = adminsCheckAdminAcl(getModeAction('admin', postRequestParameter('what_menu')), ''); + $ACL = adminsCheckAdminAcl(getActionFromModuleWhat('admin', postRequestParameter('what_menu')), ''); } // END - if if (($mode != postRequestParameter('mode')) || ($ACL)) { diff --git a/inc/modules/index.php b/inc/modules/index.php index 79141ef944..3f4fb3da07 100644 --- a/inc/modules/index.php +++ b/inc/modules/index.php @@ -50,15 +50,6 @@ handleCodeMessage(); // Some of you needs this to be extracted into a template... ??? loadTemplate('guest_menu_td'); -// When no what value is provided take the "home" value -if (!isWhatSet()) setWhatFromConfig('index_home'); - -// Adding the main content module here -if (!isActionSet()) { - // Get action value from what value - setAction(getModeAction('guest', getWhat())); -} // END - if - // Add the guest's menu here... if ((getConfig('guest_menu') == 'Y') || (!isExtensionActive('sql_patches', true))) { // Show only when guest menu is active diff --git a/inc/modules/login.php b/inc/modules/login.php index 0e04a299d8..f06beeb852 100644 --- a/inc/modules/login.php +++ b/inc/modules/login.php @@ -66,7 +66,7 @@ if (!isActionSet()) { // Add the member's menu here... if ((getConfig('member_menu') == 'Y') || (!isExtensionActive('sql_patches', true))) { - addMenu('member', getModeAction('member', getWhat()), getWhat()); + addMenu('member', getActionFromModuleWhat('member', getWhat()), getWhat()); } // END - if // Disable block-mode again diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 95fc006a84..bd453fac30 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -326,7 +326,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) { if (isAdmin()) $ADD = ''; $dummy = substr($search, 0, -4); - $ADD .= " AND `action`='".getModeAction($accessLevel, $dummy)."'"; + $ADD .= " AND `action`='".getActionFromModuleWhat($accessLevel, $dummy)."'"; } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) { // Sponsor / engine menu $type = 'what'; @@ -870,29 +870,29 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) { } // Get action value from mode (admin/guest/member) and what-value -function getModeAction ($mode, $what) { +function getActionFromModuleWhat ($module, $what) { // Init status $data['action'] = ''; - //* DEBUG: */ print(__LINE__.'='.$mode.'/'.$what.'/'.getAction()."=
"); + //* DEBUG: */ print(__LINE__.'='.$module.'/'.$what.'/'.getAction()."=
"); if (!isExtensionInstalledAndNewer('sql_patches', '0.0.5')) { // sql_patches is missing so choose depending on mode if (isWhatSet()) { // Use setted what $what = getWhat(); - } elseif ($mode == 'admin') { + } elseif ($module == 'admin') { // Admin area $what = 'overview'; } else { // Everywhere else $what = 'welcome'; } - } elseif ((empty($what)) && ($mode != 'admin')) { + } elseif ((empty($what)) && ($module != 'admin')) { // Use configured 'home' $what = getConfig('index_home'); } // END - if - if ($mode == 'admin') { + if ($module == 'admin') { // Action value for admin area if (isGetRequestParameterSet('action')) { // Use from request! @@ -908,19 +908,19 @@ function getModeAction ($mode, $what) { // Get it directly from URL return getAction(); } - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."): ret=".$data['action'].'
'); + //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__ . '): ret=' . $data['action'] . '
'); // Does the module have a menu? - if (ifModuleHasMenu($mode)) { + if (ifModuleHasMenu($module)) { // Rewriting modules to menu - $mode = mapModuleToTable($mode); + $module = mapModuleToTable($module); // Guest and member menu is 'main' as the default if (empty($data['action'])) $data['action'] = 'main'; // Load from database $result = SQL_QUERY_ESC("SELECT `action` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `what`='%s' LIMIT 1", - array($mode, $what), __FUNCTION__, __LINE__); + array($module, $what), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Load action value and pray that this one is the right you want... ;-) $data = SQL_FETCHARRAY($result); @@ -928,7 +928,7 @@ function getModeAction ($mode, $what) { // Free memory SQL_FREERESULT($result); - } elseif ((!isExtensionInstalled('sql_patches')) && (($mode != 'admin') && ($mode != 'unknown'))) { + } elseif ((!isExtensionInstalled('sql_patches')) && ($module != 'admin') && ($module != 'unknown')) { // No sql_patches installed, but maybe we need to register an admin? if (isAdminRegistered()) { // Redirect to admin area diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index ca8ef7430b..cd0b929be7 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -504,7 +504,7 @@ function setWhatFromConfig ($configEntry) { // Checks wether what is set and optionally aborts on miss function isWhatSet ($strict = false) { // Check for it - $isset = (isset($GLOBALS['what'])); + $isset = ((isset($GLOBALS['what'])) && (!empty($GLOBALS['what']))); // Should we abort here? if (($strict === true) && ($isset === false)) { @@ -539,7 +539,7 @@ function setAction ($newAction) { // Checks wether action is set and optionally aborts on miss function isActionSet ($strict = false) { // Check for it - $isset = (isset($GLOBALS['action'])); + $isset = ((isset($GLOBALS['action'])) && (!empty($GLOBALS['action']))); // Should we abort here? if (($strict === true) && ($isset === false)) { -- 2.39.5