From 2763c536e15b838a5df284bca71b7430870edc47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 7 Oct 2010 00:46:26 +0000 Subject: [PATCH] Variable renamed, function refactured/moved: - Variable $check renamed to $moduleState which is more clear what the variable is for - Function isMember() refactured - Function translatePoolType() moved to template-functions.php and added strtoupper() call for the $type variable - TODOs.txt updated --- DOCS/TODOs.txt | 18 ++++++------ inc/functions.php | 8 +----- inc/mysql-manager.php | 57 +++++++++++++++++--------------------- inc/template-functions.php | 8 +++++- modules.php | 14 ++++++---- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index 436f5d35b6..c19f51b8df 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -42,11 +42,11 @@ ./inc/extensions-functions.php:434:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) ) ./inc/extensions-functions.php:564: // @TODO Extension is loaded, what next? ./inc/functions.php:110: // @TODO Extension 'msg' does not exist -./inc/functions.php:1509: // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ? -./inc/functions.php:1597: // @TODO Are these convertions still required? -./inc/functions.php:1615:// @TODO Rewrite this function to use readFromFile() and writeToFile() +./inc/functions.php:1503: // @TODO Move this SQL code into a function, let's say 'getTimestampFromPoolId($id) ? +./inc/functions.php:1591: // @TODO Are these convertions still required? +./inc/functions.php:1609:// @TODO Rewrite this function to use readFromFile() and writeToFile() ./inc/functions.php:179:// @TODO Rewrite this to an extension 'smtp' -./inc/functions.php:2273: // @TODO This is still very static, rewrite it somehow +./inc/functions.php:2267: // @TODO This is still very static, rewrite it somehow ./inc/gen_sql_patches.php:94:// @TODO Rewrite this to a filter ./inc/install-functions.php:57: // @TODO DEACTIVATED: changeDataInFile(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0); ./inc/language/de.php:1091:// @TODO Rewrite these two constants @@ -175,11 +175,11 @@ ./inc/modules/member/what-unconfirmed.php:206: // @TODO This 'userid' cannot be saved because of encapsulated EL code ./inc/modules/order.php:74: // @TODO Unused: 2,4 ./inc/monthly/monthly_bonus.php:67: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1188: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1443: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() -./inc/mysql-manager.php:1551: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1922: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1966:// @TODO Fix inconsistency between last_module and getWhat() +./inc/mysql-manager.php:1183: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1438: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() +./inc/mysql-manager.php:1546: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1917: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1961:// @TODO Fix inconsistency between last_module and getWhat() ./inc/mysql-manager.php:368: // @TODO Try to rewrite this to one or more functions ./inc/mysql-manager.php:44:// @TODO Can we cache this? ./inc/reset/reset_beg.php:49:// @TODO This should be converted in a daily beg rallye diff --git a/inc/functions.php b/inc/functions.php index 4a8296e18a..0241262964 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -357,12 +357,6 @@ function translateYesNo ($yn) { return $GLOBALS[__FUNCTION__][$yn]; } -// Translates the "pool type" into human-readable -function translatePoolType ($type) { - // Return "translation" - return sprintf("{--POOL_TYPE_%s--}", $type); -} - // Translates the american decimal dot into a german comma function translateComma ($dotted, $cut = true, $max = '0') { // First, cast all to double, due to PHP changes @@ -652,7 +646,7 @@ function array_pk_sort (&$array, $a_sort, $primary_key = '0', $order = -1, $nums // -// Deprecated : $length +// Deprecated : $length (still has one reference in this function) // Optional : $DATA // function generateRandomCode ($length, $code, $userid, $DATA = '') { diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index f6bc8baaec..91a16286fe 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -368,58 +368,53 @@ function isMember () { // @TODO Try to rewrite this to one or more functions if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) $GLOBALS['last_online'] = array(); - // is the cache entry there? + // Is the cache entry there? if (isset($GLOBALS[__FUNCTION__])) { // Then return it //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS[__FUNCTION__]) . ')'); return $GLOBALS[__FUNCTION__]; } elseif ((!isSessionVariableSet('userid')) || (!isSessionVariableSet('u_hash'))) { - // No member + // Destroy any existing user session data + destroyMemberSession(); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No member set in cookie/session.'); + + // Abort further processing return false; - } else { - // Get it secured from session - setMemberId(getSession('userid')); - setCurrentUserId(getMemberId()); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . getSession('userid') . ' used from cookie/session.'); } + // Get userid secured from session + setMemberId(getSession('userid')); + + // ... and set it as currently handled user id + setCurrentUserId(getMemberId()); + // Init user data array initUserData(); // Fix "deleted" cookies first fixDeletedCookies(array('userid', 'u_hash')); - // Are cookies set? - if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) { - // Cookies are set with values, but are they valid? - if (fetchUserData(getMemberId()) === true) { - // Validate password by created the difference of it and the secret key - $valPass = encodeHashForCookie(getUserData('password')); + // Are cookies set and can the member data be loaded? + if ((isMemberIdSet()) && (isSessionVariableSet('u_hash')) && (fetchUserData(getMemberId()) === true)) { + // Validate password by created the difference of it and the secret key + $valPass = encodeHashForCookie(getUserData('password')); + // So did we now have valid data and an unlocked user? + if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) { // Transfer last module and online time $GLOBALS['last_online']['module'] = getUserData('last_module'); $GLOBALS['last_online']['online'] = getUserData('last_online'); - // So did we now have valid data and an unlocked user? - if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) { - // Account is confirmed and all cookie data is valid so he is definely logged in! :-) - $ret = true; - } else { - // Maybe got locked etc. - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'status=' . getUserData('status') . ',' . $valPass . '(' . strlen($valPass) . ')/' . getSession('u_hash') . '(' . strlen(getSession('u_hash')) . ')/' . getUserData('password') . '(' . strlen(getUserData('password')) . ')'); - destroyMemberSession(); - } - } else { - // Cookie data is invalid! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cookie data invalid or user not found.'); - destroyMemberSession(); - } - } else { - // Cookie data is invalid! - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cookie data not complete.'); + // Account is confirmed and all cookie data is valid so he is definely logged in! :-) + $ret = true; + } // END - if + } // END - if + + // Is $ret still false? + if ($ret === false) { + // Yes, so destroy the session destroyMemberSession(); - } + } // END - if // Cache status $GLOBALS[__FUNCTION__] = $ret; diff --git a/inc/template-functions.php b/inc/template-functions.php index f8e5da36b7..d46d83e458 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -1676,8 +1676,14 @@ function fixNullEmptyToDashes ($str, $num) { return $return; } +// Translates the "pool type" into human-readable +function translatePoolType ($type) { + // Return "translation" + return sprintf("{--POOL_TYPE_%s--}", strtoupper($type)); +} + //----------------------------------------------------------------------------- -// Template Helper Functions +// Template helper functions for EL //----------------------------------------------------------------------------- // Color-switch helper function diff --git a/modules.php b/modules.php index 4f49e79ec1..3b6905a4ec 100644 --- a/modules.php +++ b/modules.php @@ -60,7 +60,9 @@ loadIncludeOnce('inc/header.php'); // Modules are by default not valid! $isModuleValid = false; $URL = ''; -$check = 'failed'; + +// Init module state as 'failed' (always failed first) +$moduleState = 'failed'; // Is the maintenance mode active or goes all well? if ((isExtensionActive('maintenance')) && (getConfig('maintenance') == 'Y') && (!isAdmin()) && (getModule() != 'admin')) { @@ -71,8 +73,10 @@ if ((isExtensionActive('maintenance')) && (getConfig('maintenance') == 'Y') && ( $GLOBALS['module_inc'] = sprintf("inc/modules/%s.php", getModule()); // Check module permission (again) - $check = checkModulePermissions(); - switch ($check) { + $moduleState = checkModulePermissions(); + + // Which permission/error state do we have? + switch ($moduleState) { case 'cache_miss': // The cache is gone case 'admin_only': // Admin-only access case 'mem_only': // Member-only access @@ -119,8 +123,8 @@ if ((isExtensionActive('maintenance')) && (getConfig('maintenance') == 'Y') && ( default: // Unknown module status - logDebugMessage(__FILE__, __LINE__, sprintf("Unknown status %s return from module check. Module=%s", $check, getModule())); - addFatalMessage(__FILE__, __LINE__, getMaskedMessage('UNKNOWN_MODULE_STATUS', $check)); + logDebugMessage(__FILE__, __LINE__, sprintf("Unknown status %s return from module check. Module=%s", $moduleState, getModule())); + addFatalMessage(__FILE__, __LINE__, getMaskedMessage('UNKNOWN_MODULE_STATUS', $moduleState)); break; } // END - switch } elseif (!ifFatalErrorsDetected()) { -- 2.39.2