From ef8bdde1d3b805a341e64cb29c89e562e1ca963f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 27 Jan 2011 21:23:19 +0000 Subject: [PATCH] Speed improvement, TODOs.txt updated: - Several different hacks added to improve script execution time - TODOs.txt updated --- DOCS/TODOs.txt | 7 ++--- inc/db/lib-mysql3.php | 9 +++---- inc/filters.php | 6 +++-- inc/functions.php | 28 ++++++++++++++----- inc/language-functions.php | 55 +++++++++++++++++++++----------------- inc/template-functions.php | 2 +- inc/wrapper-functions.php | 24 ++++++++++------- 7 files changed, 79 insertions(+), 52 deletions(-) diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index 1a024da49f..7531723847 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -48,14 +48,15 @@ ./inc/functions.php:1596: // @TODO Are these convertions still required? ./inc/functions.php:1614:// @TODO Rewrite this function to use readFromFile() and writeToFile() ./inc/functions.php:181:// @TODO Rewrite this to an extension 'smtp' -./inc/functions.php:2277: // @TODO This is still very static, rewrite it somehow -./inc/functions.php:2454: // @TODO Rename column data_type to e.g. mail_status +./inc/functions.php:2187: // @TODO Find a way to cache this +./inc/functions.php:2288: // @TODO This is still very static, rewrite it somehow +./inc/functions.php:2468: // @TODO Rename column data_type to e.g. mail_status ./inc/gen_sql_patches.php:95:// @TODO Rewrite this to a filter ./inc/install-functions.php:57: // @TODO DEACTIVATED: changeDataInInclude(getCachePath() . 'config-local.php', 'OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestParameter('omode'), 0); ./inc/language/de.php:1082: // @TODO Rewrite these two constants ./inc/language/de.php:1103: // @TODO Rewrite these three constants ./inc/language/de.php:779:// @TODO Are these constants longer used? -./inc/language-functions.php:243: // @TODO These are all valid languages, again hard-coded +./inc/language-functions.php:250: // @TODO These are all valid languages, again hard-coded ./inc/language-functions.php:44:// @TODO Rewrite all language constants to this function. ./inc/language/newsletter_de.php:13: * @TODO This language file is completely out-dated, please do no * ./inc/language/rallye_de.php:13: * @TODO Naming convention not applied for language strings * diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 80e3a1d509..9db8e65bea 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -220,9 +220,6 @@ function SQL_CONNECT ($host, $login, $password, $F, $L) { // Set the link resource SQL_SET_LINK($linkResource); - - // Destroy cache - unset($GLOBALS['is_sql_link_up']); } // SQL select database @@ -248,9 +245,6 @@ function SQL_CLOSE ($F, $L) { // Close link SQL_SET_LINK(null); - // Destroy cache - unset($GLOBALS['is_sql_link_up']); - // Return the result return $close; } @@ -503,6 +497,9 @@ function SQL_SET_LINK ($link) { // Set it $GLOBALS['sql_link'] = $link; + + // Re-init cache + $GLOBALS['is_sql_link_up'] = is_resource($link); } // Checks if the link is up diff --git a/inc/filters.php b/inc/filters.php index 538efa1f03..9985adf03d 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -508,7 +508,7 @@ function FILTER_COMPILE_EXPRESSION_CODE ($code) { $data = array( 'matches' => $matches, 'key' => $key, - 'mode' => $outputMode, + 'mode' => getScriptOutputMode(), 'code' => $code, 'callback' => $callback, 'extra_func' => $extraFunction, @@ -527,7 +527,9 @@ function FILTER_COMPILE_EXPRESSION_CODE ($code) { } // END - if // Do we have non-HTML mode? - if ((!isHtmlOutputMode()) || ($outputMode != '0')) $code = decodeEntities($code); + if (!isHtmlOutputMode()) { + $code = decodeEntities($code); + } // END - if // Return compiled code //* DEBUG: */ debugOutput(__FUNCTION__.'['.__LINE__.']:
'.($code).'
'); diff --git a/inc/functions.php b/inc/functions.php index 4b25ba9777..f4c11ee73f 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1931,7 +1931,9 @@ function addNewBonusMail ($data, $mode = '', $output = true) { // Determines referal id and sets it function determineReferalId () { // Skip this in non-html-mode and outside ref.php - if ((!isHtmlOutputMode()) && (basename($_SERVER['PHP_SELF']) != 'ref.php')) return false; + if ((!isHtmlOutputMode()) && (basename($_SERVER['PHP_SELF']) != 'ref.php')) { + return false; + } // END - if // Check if refid is set if ((isset($GLOBALS['refid'])) && ($GLOBALS['refid'] > 0)) { @@ -2126,7 +2128,7 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad // And skip further processing continue; - } elseif (substr($baseFile, 0, strlen($prefix)) != $prefix) { + } elseif (!isFilePrefixFound($baseFile, $prefix)) { // Skip this file //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Invalid prefix in file ' . $baseFile . ', prefix=' . $prefix); continue; @@ -2140,9 +2142,12 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad continue; } + // Get file' extension (last 4 chars) + $fileExtension = substr($baseFile, -4, 4); + // Is the file a PHP script or other? //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'baseDir=' . $baseDir . ',prefix=' . $prefix . ',baseFile=' . $baseFile); - if ((substr($baseFile, -4, 4) == '.php') || (($fileIncludeDirs === true) && (isDirectory($FQFN)))) { + if (($fileExtension == '.php') || (($fileIncludeDirs === true) && (isDirectory($FQFN)))) { // Is this a valid include file? if ($extension == '.php') { // Remove both for extension name @@ -2158,9 +2163,9 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad } } else { // We found .php file but should not search for them, why? - debug_report_bug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script.'); + debug_report_bug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script. (baseFile=' . $baseFile . ')'); } - } elseif (substr($baseFile, -4, 4) == $extension) { + } elseif ($fileExtension == $extension) { // Other, generic file found $files[] = $fileName; } @@ -2177,6 +2182,12 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad return $files; } +// Checks wether $prefix is found in $fileName +function isFilePrefixFound ($fileName, $prefix) { + // @TODO Find a way to cache this + return (substr($fileName, 0, strlen($prefix)) == $prefix); +} + // Maps a module name into a database table name function mapModuleToTable ($moduleName) { // Map only these, still lame code... @@ -2298,7 +2309,10 @@ function getModuleFromFileName ($file, $accessLevel) { // Encodes an URL for adding session id, etc. function encodeUrl ($url, $outputMode = '0') { // Do we have already have a PHPSESSID inside or view.php is called? Then abort here - if ((strpos($url, session_name()) !== false) || (isRawOutputMode())) return $url; + if ((strpos($url, session_name()) !== false) || (isRawOutputMode())) { + // Raw output mode detected or session_name() found in URL + return $url; + } // END - if // Do we have a valid session? if (((!isset($GLOBALS['valid_session'])) || ($GLOBALS['valid_session'] === false) || (!isset($_COOKIE[session_name()]))) && (isSpider() === false)) { @@ -2309,7 +2323,7 @@ function encodeUrl ($url, $outputMode = '0') { // No question mark $seperator = '?'; } elseif ((!isHtmlOutputMode()) || ($outputMode != '0')) { - // Non-HTML mode + // Non-HTML mode (or forced non-HTML mode $seperator = '&'; } diff --git a/inc/language-functions.php b/inc/language-functions.php index 93999f1f92..dad887e92c 100644 --- a/inc/language-functions.php +++ b/inc/language-functions.php @@ -113,32 +113,39 @@ function setCurrentLanguage ($language) { // "Getter" for language function getLanguage () { - // Default is 'de'. DO NOT CHANGE THIS!!! - $ret = 'de'; - - // Set default return value to default language from config - if (isConfigEntrySet('DEFAULT_LANG')) $ret = getDefaultLanguage(); - - // Is the variable set - if (isGetRequestParameterSet('mx_lang')) { - // Accept only first 2 chars - $ret = substr(getRequestParameter('mx_lang'), 0, 2); - } elseif (isset($GLOBALS['language'])) { - // Use cached - $ret = getCurrentLanguage(); - } elseif (isSessionVariableSet('mx_lang')) { - // Return stored value from cookie - $ret = getSession('mx_lang'); - - // Fixes a warning before the session has the mx_lang constant - if (empty($ret)) $ret = getDefaultLanguage(); - } + // Do we have cache? + if (!isset($GLOBALS['language'])) { + // Default is 'de'. DO NOT CHANGE THIS!!! + $ret = 'de'; + + // Set default return value to default language from config + if (isConfigEntrySet('DEFAULT_LANG')) { + $ret = getDefaultLanguage(); + } // END - if + + // Is the variable set + if (isGetRequestParameterSet('mx_lang')) { + // Accept only first 2 chars + $ret = substr(getRequestParameter('mx_lang'), 0, 2); + } elseif (isset($GLOBALS['language'])) { + // Use cached + $ret = getCurrentLanguage(); + } elseif (isSessionVariableSet('mx_lang')) { + // Return stored value from cookie + $ret = getSession('mx_lang'); + + // Fixes a warning before the session has the mx_lang constant + if (empty($ret)) { + $ret = getDefaultLanguage(); + } // END - if + } - // Cache entry - setCurrentLanguage($ret); + // Cache entry + setCurrentLanguage($ret); + } // END - if - // Return value - return $ret; + // Return cached value + return getCurrentLanguage(); } // "Setter" for language diff --git a/inc/template-functions.php b/inc/template-functions.php index bdb505d8fb..b2f6b1fa00 100644 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -1462,7 +1462,7 @@ function escapeQuotes ($str, $single = false) { $str = addslashes($str); } else { // Remove escaping of single quotes - $str = str_replace("\'", "'", $str); + $str = str_replace("\\'", "'", $str); // Escape only double-quotes but prevent double-quoting $str = str_replace("\\\\", "\\", str_replace('"', "\\\"", $str)); diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index 8758f853d6..7df4d8f710 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -660,17 +660,23 @@ function isModuleSet ($strict = false) { // Getter for 'output_mode' value function getScriptOutputMode () { - // Default is null - $output_mode = null; + // Do we have cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Default is null + $output_mode = null; - // Is the value set? - if (isOutputModeSet(true)) { - // Then use it - $output_mode = $GLOBALS['output_mode']; + // Is the value set? + if (isOutputModeSet(true)) { + // Then use it + $output_mode = $GLOBALS['output_mode']; + } // END - if + + // Store it in cache + $GLOBALS[__FUNCTION__] = $output_mode; } // END - if - // Return it - return $output_mode; + // Return cache + return $GLOBALS[__FUNCTION__]; } // Setter for 'output_mode' value @@ -686,7 +692,7 @@ function isOutputModeSet ($strict = false) { // Should we abort here? if (($strict === true) && ($isset === false)) { // Output backtrace - debug_report_bug(__FUNCTION__, __LINE__, 'Output_mode is empty.'); + debug_report_bug(__FUNCTION__, __LINE__, 'Output mode is not set.'); } // END - if // Return it -- 2.39.2