From a6f5926aeaf7917cb4bca3d29ffd0e8e6290fb4e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 1 Dec 2009 05:47:25 +0000 Subject: [PATCH] Double->single rewrites and possible fixes for revision data --- inc/classes/cachesystem.class.php | 20 +++++----- inc/config-functions.php | 2 +- inc/filters.php | 4 +- inc/functions.php | 61 ++++++++++++++++--------------- inc/libs/refback_functions.php | 48 ++++++++++++------------ inc/modules/admin/admin-inc.php | 2 +- inc/mysql-manager.php | 34 ++++++++--------- 7 files changed, 87 insertions(+), 84 deletions(-) diff --git a/inc/classes/cachesystem.class.php b/inc/classes/cachesystem.class.php index 4c23235ac2..71bf450d67 100644 --- a/inc/classes/cachesystem.class.php +++ b/inc/classes/cachesystem.class.php @@ -113,7 +113,7 @@ class CacheSystem { fwrite($this->pointer, "".__LINE__."): ".getMessage('CACHE_PROBLEMS_DETECTED')); + addFatalMessage(__METHOD__, __LINE__, '(' . __LINE__ . '): ' . getMessage('CACHE_PROBLEMS_DETECTED')); } } @@ -195,7 +195,7 @@ class CacheSystem { } // END - foreach } else { // Cannot create file - addFatalMessage(__METHOD__, __LINE__, "(".__LINE__."): ".getMessage('CACHE_PROBLEMS_DETECTED')); + addFatalMessage(__METHOD__, __LINE__, '(' . __LINE__ . '): ' . getMessage('CACHE_PROBLEMS_DETECTED')); } } @@ -220,7 +220,7 @@ class CacheSystem { // Remove pointer and status unset($this->status[$this->name]); $this->pointer = false; - //* DEBUG: */ outputHtml(__METHOD__."(".__LINE__."): {$this->name} - FINALIZED!
"); + //* DEBUG: */ outputHtml(__METHOD__ . '(' . __LINE__."): {$this->name} - FINALIZED!
"); } // END - if } @@ -260,7 +260,7 @@ class CacheSystem { } else { // Cache file not found or not readable debug_report_bug($this->name); - addFatalMessage(__METHOD__, __LINE__, "(".__LINE__."): ".getMaskedMessage('CACHE_CANNOT_LOAD', $this->fqfn)); + addFatalMessage(__METHOD__, __LINE__, '(' . __LINE__ . '): ' . getMaskedMessage('CACHE_CANNOT_LOAD', $this->fqfn)); // Try to remove it $this->removeCacheFile(); @@ -315,7 +315,7 @@ class CacheSystem { $this->rebuilt[$this->name] = true; } else { // Not removed! - addFatalMessage(__METHOD__, __LINE__, "(".__LINE__."): ".getMaskedMessage('CACHE_CANNOT_UNLINK', $this->fqfn)); + addFatalMessage(__METHOD__, __LINE__, '(' . __LINE__ . '): ' . getMaskedMessage('CACHE_CANNOT_UNLINK', $this->fqfn)); } } // END - if } @@ -346,7 +346,7 @@ class CacheSystem { } } else { // Cannot write to cache! - addFatalMessage(__METHOD__, __LINE__, "(".__LINE__."): ".getMessage('CACHE_PROBLEMS_DETECTED')); + addFatalMessage(__METHOD__, __LINE__, '(' . __LINE__ . '): ' . getMessage('CACHE_PROBLEMS_DETECTED')); } } @@ -370,7 +370,7 @@ class CacheSystem { } // END - foreach } else { // Cannot write array! - addFatalMessage(__METHOD__, __LINE__, "(".__LINE__."): ".getMessage('CACHE_PROBLEMS_DETECTED')); + addFatalMessage(__METHOD__, __LINE__, '(' . __LINE__ . '): ' . getMessage('CACHE_PROBLEMS_DETECTED')); } } @@ -407,7 +407,7 @@ class CacheSystem { } // END - if } else { // Cannot write to cache! - addFatalMessage(__METHOD__, __LINE__, "(".__LINE__."): ".getMessage('CACHE_PROBLEMS_DETECTED')); + addFatalMessage(__METHOD__, __LINE__, '(' . __LINE__ . '): ' . getMessage('CACHE_PROBLEMS_DETECTED')); } } @@ -426,10 +426,10 @@ class CacheSystem { // Write cache line to file fwrite($this->pointer, $this->rewriteEntry($ext_name, $ext_ver, 'version', true)); } // END - if - //* DEBUG: */ outputHtml(__METHOD__."(".__LINE__."): {$this->name} - {$ext_name}={$ext_ver}
"); + //* DEBUG: */ outputHtml(__METHOD__ . '(' . __LINE__."): {$this->name} - {$ext_name}={$ext_ver}
"); } else { // Cannot create file - addFatalMessage(__METHOD__, __LINE__, "(".__LINE__."): ".getMessage('CACHE_PROBLEMS_DETECTED')); + addFatalMessage(__METHOD__, __LINE__, '(' . __LINE__ . '): ' . getMessage('CACHE_PROBLEMS_DETECTED')); } } diff --git a/inc/config-functions.php b/inc/config-functions.php index cc35fc1cbf..a7897e2abc 100644 --- a/inc/config-functions.php +++ b/inc/config-functions.php @@ -346,7 +346,7 @@ function updateConfiguration ($entries, $values, $updateMode='', $config = '0') //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "entries={$entries}"); SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_config` SET ".$entries." WHERE `config`=%s LIMIT 1", array(bigintval($config)), __FUNCTION__, __LINE__); - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):entries={$entries},affectedRows={$affectedRows}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):entries={$entries},affectedRows={$affectedRows}
"); // Rebuild cache rebuildCacheFile('config', 'config'); diff --git a/inc/filters.php b/inc/filters.php index 4159a10796..b4970d71b8 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -137,7 +137,7 @@ function FILTER_CALL_HANDLER_LOGIN_FAILTURES ($data) { $content = $data; // Handle failed logins here if not in guest - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):type={$data['type']},action={getAction()},what={getWhat()},level={$data['access_level']}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):type={$data['type']},action={getAction()},what={getWhat()},level={$data['access_level']}
"); if ((($data['type'] == 'what') || ($data['type'] == 'action') && ((!isWhatSet()) || (getWhat() == 'overview') || (getWhat() == getConfig('index_home')))) && ($data['access_level'] != 'guest') && ((isExtensionInstalledAndNewer('sql_patches', '0.4.7')) || (isExtensionInstalledAndNewer('admins', '0.7.0')))) { // Handle failure $content['content'] .= handleLoginFailtures($data['access_level']); @@ -167,7 +167,7 @@ function FILTER_AUTO_ACTIVATE_EXTENSION ($data) { // Is this extension always activated? if (getExtensionAlwaysActive() == 'Y') { // Then activate the extension - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."): ext_name={$data['ext_name']}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."): ext_name={$data['ext_name']}
"); doActivateExtension($data['ext_name']); } // END - if diff --git a/inc/functions.php b/inc/functions.php index 35c3a3646a..80bdad0514 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -442,25 +442,25 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0') { } // END - if // Load user's data - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):UID={$userid},template={$template},content[]=".gettype($content).'
'); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):UID={$userid},template={$template},content[]=".gettype($content).'
'); if (($userid > 0) && (is_array($content))) { // If nickname extension is installed, fetch nickname as well if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) { - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):NICKNAME!
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):NICKNAME!
"); // Load by nickname fetchUserData($userid, 'nickname'); } else { - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):NO-NICK!
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):NO-NICK!
"); /// Load by userid fetchUserData($userid); } // Merge data if valid - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):content()=".count($content)." - PRE
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):content()=".count($content)." - PRE
"); if (isUserDataValid()) { $content = merge_array($content, getUserDataArray()); } // END - if - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):content()=".count($content)." - AFTER
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):content()=".count($content)." - AFTER
"); } // END - if // Translate M to male or F to female if present @@ -532,7 +532,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0') { // Send mail out to an email address function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '') { - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):TO={$toEmail},SUBJECT={$subject}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):TO={$toEmail},SUBJECT={$subject}
"); // Compile subject line (for POINTS constant etc.) eval("\$subject = decodeEntities(\"".compileRawCode(escapeQuotes($subject))."\");"); @@ -558,7 +558,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = ' // Is the webmaster! $toEmail = getConfig('WEBMASTER'); } - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):TO={$toEmail}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):TO={$toEmail}
"); // Check for PHPMailer or debug-mode if (!checkPhpMailerUsage()) { @@ -1059,10 +1059,10 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true $test = substr($found, 0, strlen($match)); // Does this entry exist? - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):found={$found},match={$match},set={$set}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):found={$found},match={$match},set={$set}
"); if ($test == $match) { // Match found! - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):fuzzyFound!
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):fuzzyFound!
"); $fuzzyFound = true; break; } // END - if @@ -1074,14 +1074,14 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true // Take all string elements if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key."_" . $matches[4][$key]]))) { // Replace it in the code - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):key={$key},match={$match}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):key={$key},match={$match}
"); $newMatch = str_replace('[', "['", str_replace(']', "']", $match)); $code = str_replace($match, '".' . $newMatch . '."', $code); $matchesFound[$key . '_' . $matches[4][$key]] = 1; $matchesFound[$match] = 1; } elseif (!isset($matchesFound[$match])) { // Not yet replaced! - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):match={$match}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):match={$match}
"); $code = str_replace($match, '".' . $match . '."', $code); $matchesFound[$match] = 1; } @@ -2337,14 +2337,14 @@ function isBooleanConstantAndTrue ($constName) { // : Boolean // In cache? if (isset($GLOBALS['cache_array']['const'][$constName])) { // Use cache - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."): " . $constName."-CACHE!
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__ . '): ' . $constName."-CACHE!
"); $res = ($GLOBALS['cache_array']['const'][$constName] === true); } else { // Check constant - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."): " . $constName."-RESOLVE!
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__ . '): ' . $constName."-RESOLVE!
"); if (defined($constName)) { // Found! - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."): " . $constName."-FOUND!
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__ . '): ' . $constName."-FOUND!
"); $res = (constant($constName) === true); } // END - if @@ -2408,12 +2408,12 @@ function generateErrorCodeFromUserStatus ($status='') { // Function to search for the last modifified file function searchDirsRecursive ($dir, &$last_changed) { // Get dir as array - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):dir=" . $dir.'
'); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):dir=" . $dir.'
'); // Does it match what we are looking for? (We skip a lot files already!) // RegexPattern to exclude ., .., .revision, .svn, debug.log or .cache in the filenames $excludePattern = '@(\.revision|debug\.log|\.cache|config\.php)$@'; $ds = getArrayFromDirectory($dir, '', true, false, array(), '.php', $excludePattern); - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):ds[]=".count($ds).'
'); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):ds[]=".count($ds).'
'); // Walk through all entries foreach ($ds as $d) { @@ -2421,20 +2421,20 @@ function searchDirsRecursive ($dir, &$last_changed) { $FQFN = str_replace('//', '/', getConfig('PATH') . $dir. '/'. $d); // Is it a file and readable? - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):FQFN={$FQFN}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):FQFN={$FQFN}
"); if (isDirectory($FQFN)) { // $FQFN is a directory so also crawl into this directory $newDir = $d; if (!empty($dir)) $newDir = $dir . '/'. $d; - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):DESCENT: " . $newDir.'
'); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):DESCENT: " . $newDir.'
'); searchDirsRecursive($newDir, $last_changed); } elseif (isFileReadable($FQFN)) { // $FQFN is a filename and no directory $time = filemtime($FQFN); - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):File: " . $d." found. (".($last_changed['time'] - $time).")
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):File: " . $d." found. (".($last_changed['time'] - $time).")
"); if ($last_changed['time'] < $time) { // This file is newer as the file before - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__.") - NEWER!
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__.") - NEWER!
"); $last_changed['path_name'] = $FQFN; $last_changed['time'] = $time; } // END - if @@ -2486,7 +2486,7 @@ function getActualVersion ($type = 'Revision') { } // END - foreach // Return found value - return trim($ins_vers[$mapper[$type]]); + return getActualVersion($type); } } } @@ -2506,7 +2506,7 @@ function getActualVersion ($type = 'Revision') { // The returned Array is needed twice (in getArrayFromActualVersion() and in getActualVersion() in the old .revision-fallback) so I puted it in an extra function to not polute the global namespace function getSearchFor () { // Add Revision, Date, Tag and Author - $searchFor = array('Revision', 'Date', 'Tag', 'Author', 'File'); + $searchFor = array('File', 'Revision', 'Date', 'Tag', 'Author'); // Return the created array return $searchFor; @@ -2538,17 +2538,20 @@ function getArrayFromActualVersion () { // Get all the keywords to search for $searchFor = getSearchFor(); + // Save the last-changed filename for debugging + $GLOBALS['cache_array']['revision']['File'] = $last_changed['path_name']; + // This foreach loops the $searchFor-Tags (array('Revision', 'Date', 'Tag', 'Author') --> could easaly extended in the future) foreach ($searchFor as $search) { // Searches for "$search-tag:VALUE$" or "$search-tag::VALUE$"(the stylish keywordversion ;-)) in the lates modified file $res += preg_match('@\$' . $search.'(:|::) (.*) \$@U', $last_file, $t); + // This trimms the search-result and puts it in the $GLOBALS['cache_array']['revision']-return array - if (isset($t[2])) $GLOBALS['cache_array']['revision'][$search] = trim($t[2]); + if (isset($t[2])) { + $GLOBALS['cache_array']['revision'][$search] = trim($t[2]); + } // END - if } // END - foreach - // Save the last-changed filename for debugging - $GLOBALS['cache_array']['revision']['File'] = $last_changed['path_name']; - // at least 3 keyword-Tags are needed for propper values if ($res && $res >= 3 && isset($GLOBALS['cache_array']['revision']['Revision']) && $GLOBALS['cache_array']['revision']['Revision'] != '' @@ -2577,11 +2580,11 @@ function getArrayFromActualVersion () { // Prepare content // Only sets not setted or not proper values to the Online-Server-Fallback-Solution + if (!isset($GLOBALS['cache_array']['revision']['File']) || $GLOBALS['cache_array']['revision']['File'] == '') $GLOBALS['cache_array']['revision']['File'] = trim($version[11]); if (!isset($GLOBALS['cache_array']['revision']['Revision']) || $GLOBALS['cache_array']['revision']['Revision'] == '') $GLOBALS['cache_array']['revision']['Revision'] = trim($version[10]); if (!isset($GLOBALS['cache_array']['revision']['Date']) || $GLOBALS['cache_array']['revision']['Date'] == '') $GLOBALS['cache_array']['revision']['Date'] = trim($version[9]); if (!isset($GLOBALS['cache_array']['revision']['Tag']) || $GLOBALS['cache_array']['revision']['Tag'] == '') $GLOBALS['cache_array']['revision']['Tag'] = trim($version[8]); if (!isset($GLOBALS['cache_array']['revision']['Author']) || $GLOBALS['cache_array']['revision']['Author'] == '') $GLOBALS['cache_array']['revision']['Author'] = 'quix0r'; - if (!isset($GLOBALS['cache_array']['revision']['File']) || $GLOBALS['cache_array']['revision']['File'] == '') $GLOBALS['cache_array']['revision']['File'] = trim($version[11]); } // Return prepared array @@ -3062,7 +3065,7 @@ function handleLoginFailtures ($accessLevel) { // Ignore zero values if (getSession('mxchange_' . $accessLevel.'_failures') > 0) { // Non-guest has login failures found, get both data and prepare it for template - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):accessLevel={$accessLevel}
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):accessLevel={$accessLevel}
"); $content = array( 'login_failures' => getSession('mxchange_' . $accessLevel.'_failures'), 'last_failure' => generateDateTime(getSession('mxchange_' . $accessLevel.'_last_fail'), 2) @@ -3102,7 +3105,7 @@ function rebuildCacheFile ($cache, $inc = '', $force = false) { // Is the include there? if (isIncludeReadable($inc)) { // And rebuild it from scratch - //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."): inc={$inc} - LOADED!
"); + //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."): inc={$inc} - LOADED!
"); loadInclude($inc); } else { // Include not found! diff --git a/inc/libs/refback_functions.php b/inc/libs/refback_functions.php index 5b2feb45ff..78ad023fc7 100644 --- a/inc/libs/refback_functions.php +++ b/inc/libs/refback_functions.php @@ -61,35 +61,35 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) { unset($GLOBALS['ref_level']); // "Walk" through all refids - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},ref={$ref},level={$content['level']},points={$points}
"); + //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},ref={$ref},level={$content['level']},points={$points}
"); foreach (getArrayFromRefbackLevel($userid, $content['level']) as $refid) { // Skip level zero or if both are the same if ($userid == $refid) continue; // Get refback percents $percents = getRefbackPercents($userid, $refid); - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},ref={$ref},refid={$refid},points={$points},percents={$percents}
"); + //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},ref={$ref},refid={$refid},points={$points},percents={$percents}
"); // Some percents given? if ($percents > 0) { - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):points={$points},perc={$content['percents']},percents={$percents},level={$content['level']}
"); + //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):points={$points},perc={$content['percents']},percents={$percents},level={$content['level']}
"); // Calculate points for refback $refback = $points * ($content['percents'] / 100) * ($percents / 100); // Update refback table ('refid' and 'userid' must be exchanged!) SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_refs` SET `points`=`points`+%s WHERE `userid`=%s AND `refid`=%s LIMIT 1", array($refback, $refid, $userid), __FUNCTION__, __LINE__); - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):refback={$refback},userid={$userid},refid={$refid} - UPDATE! (".SQL_AFFECTEDROWS().")
"); + //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):refback={$refback},userid={$userid},refid={$refid} - UPDATE! (".SQL_AFFECTEDROWS().")
"); // Add points again, but only directly - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):refback={$refback}
"); + //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):refback={$refback}
"); addPointsDirectly(sprintf("refback:%s", $refid), $userid, $refback); // Reduce points if refid is found if ($refid == $ref) { // Reduce points here! $return = $points * ($content['percents'] / 100) - $refback; - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):points={$return} - REDUCED
"); + //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):points={$return} - REDUCED
"); } // END - if } // END - if } // END foreach @@ -109,7 +109,7 @@ function addRefbackPoints ($userid, $ref, $points, $ref_points) { // "Getter" for refback percents function getRefbackPercents ($userid, $ref) { //* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ------------------------