Variable renamed, function refactured/moved:
authorRoland Häder <roland@mxchange.org>
Thu, 7 Oct 2010 00:46:26 +0000 (00:46 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 7 Oct 2010 00:46:26 +0000 (00:46 +0000)
- 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
inc/functions.php
inc/mysql-manager.php
inc/template-functions.php
modules.php

index 436f5d35b6e09183ec1afc04f4829b328a779843..c19f51b8df0d12d2fbedcc079e47ebfcd3a48758 100644 (file)
 ./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
 ./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
index 4a8296e18a6172ef7d54d4f9158979f6d860b498..0241262964b9ba4fe80edfbb67b1ed29949183c9 100644 (file)
@@ -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 = '') {
index f6bc8baaeca843f8454a8a61ddd702ffc50030a0..91a16286fef6f3f40c91ba36c4fdb724377f4bc1 100644 (file)
@@ -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;
index f8e5da36b78e16e5e12412884112e8800c7b22cf..d46d83e45886189f7aa3efc8f679f0feabb58ddf 100644 (file)
@@ -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
index 4f49e79ec114c42059ce86e62b3af469907b5483..3b6905a4ec08233841ebb512d81c966289cdd97f 100644 (file)
@@ -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()) {