]> git.mxchange.org Git - mailer.git/commitdiff
Cache path changed and compileRawCode() introduced
authorRoland Häder <roland@mxchange.org>
Wed, 4 Nov 2009 07:32:13 +0000 (07:32 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 4 Nov 2009 07:32:13 +0000 (07:32 +0000)
12 files changed:
.gitattributes
.gitignore
inc/cache/_compiled/.htaccess [new file with mode: 0644]
inc/cache/_compiled/templates/.htaccess [new file with mode: 0644]
inc/cache/templates/.htaccess [deleted file]
inc/config-functions.php
inc/db/lib-mysql3.php
inc/filters.php
inc/functions.php
inc/libs/primera_functions.php
inc/libs/wernis_functions.php
modules.php

index 8891988c5f303aeb1e98607dfcaaa8399001709c..ca82c559f5c73cdfe7e976e323503942a74c9e20 100644 (file)
@@ -95,7 +95,8 @@ inc/autopurge/purge-mails.php -text
 inc/autopurge/purge-tsks.php -text
 inc/autopurge/purge-unconfirmed.php -text
 inc/cache/.htaccess -text
-inc/cache/templates/.htaccess -text
+inc/cache/_compiled/.htaccess -text
+inc/cache/_compiled/templates/.htaccess -text
 inc/classes/.htaccess -text
 inc/classes/cachesystem.class.php -text
 inc/classes/rdf.class.php -text
index 36fda3f619c91180ebf6652bc113b5bb272dc872..2307ae3c6627e72acd6845f8a2e6183bb5d3a7b8 100644 (file)
@@ -9,7 +9,7 @@ inc/.secret/.*
 inc/.secret/dummy.php
 inc/cache/*.cache
 inc/cache/.revision
+inc/cache/_compiled/templates/*.cache
 inc/cache/config-local.php
 inc/cache/debug.log
 inc/cache/sess_*
-inc/cache/templates/*.cache
diff --git a/inc/cache/_compiled/.htaccess b/inc/cache/_compiled/.htaccess
new file mode 100644 (file)
index 0000000..14249c5
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
\ No newline at end of file
diff --git a/inc/cache/_compiled/templates/.htaccess b/inc/cache/_compiled/templates/.htaccess
new file mode 100644 (file)
index 0000000..14249c5
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
\ No newline at end of file
diff --git a/inc/cache/templates/.htaccess b/inc/cache/templates/.htaccess
deleted file mode 100644 (file)
index 14249c5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Deny from all
\ No newline at end of file
index 3b9b1759ffbf2fb99484f5e452536454a697a10f..cda835e7752a9f1ae7ca72392600dc3e5a721e6f 100644 (file)
@@ -109,7 +109,7 @@ function mergeConfig ($newConfig) {
 // Increment or init with given value or 1 as default the given config entry
 function incrementConfigEntry ($configEntry, $value=1) {
        // Increment it if set or init it with 1
-       if (getConfig($configEntry) > 0) {
+       if (isConfigEntrySet($configEntry)) {
                $GLOBALS['config'][$configEntry] += $value;
        } else {
                $GLOBALS['config'][$configEntry] = $value;
index 625125b39d6e6f3f5b9ad5f98c0439bef2c0947d..b4e386ce8ea20a1835d8a4bea4be04d445c05938 100644 (file)
@@ -72,7 +72,7 @@ function SQL_QUERY ($sqlString, $F, $L) {
        $sqlString = str_replace("\t", ' ', str_replace("\n", ' ', str_replace("\r", ' ', $sqlString)));
 
        // Compile config out
-       $sqlString = FILTER_COMPILE_CONFIG($sqlString);
+       $sqlString = FILTER_COMPILE_CONFIG($sqlString, true);
 
        // Starting time
        $querytimeBefore = array_sum(explode(' ', microtime()));
index fab11f202f6bb03bcebe0187de8b31dfba784e04..431b5ac367a4b21f71e9f67f895416827fb3aa3a 100644 (file)
@@ -398,40 +398,55 @@ function FILTER_DETERMINE_USERNAME () {
 }
 
 // Filter for compiling config entries
-function FILTER_COMPILE_CONFIG ($code) {
-       // Compile {?some_var?} to getConfig('some_var')
-       preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches);
+function FILTER_COMPILE_CONFIG ($code, $compiled = false) {
+       // Save the uncompiled code
+       $uncompiled = $code;
+
+       // Do we have cache?
+       if (!isset($GLOBALS['compiled_config'][$code])) {
+               // Compile {?some_var?} to getConfig('some_var')
+               preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches);
+
+               // Some entries found?
+               if ((count($matches) > 0) && (count($matches[0]) > 0)) {
+                       // Replace all matches
+                       foreach ($matches[0] as $key => $match) {
+                               // Do we have cache?
+                               if (!isset($GLOBALS['compile_config'][$matches[1][$key]])) {
+                                       // Is the config valid?
+                                       if (isConfigEntrySet($matches[1][$key])) {
+                                               // Set it for caching
+                                               $GLOBALS['compile_config'][$matches[1][$key]] = "\".getConfig('" . $matches[1][$key] . "').\"";
+                                       } elseif (isConfigEntrySet('default_' . strtoupper($matches[1][$key]))) {
+                                               // Use default value
+                                               $GLOBALS['compile_config'][$matches[1][$key]] = "\".getConfig('" . 'DEFAULT_' . strtoupper($matches[1][$key]) . "').\"";
+                                       } elseif (isMessageIdValid('DEFAULT_' . strtoupper($matches[1][$key]))) {
+                                               // No config, try the language system
+                                               $GLOBALS['compile_config'][$matches[1][$key]] = "\".getMessage('". 'DEFAULT_' . strtoupper($matches[1][$key]) . "').\"";
+                                       } else {
+                                               // Unhandled!
+                                               $GLOBALS['compile_config'][$matches[1][$key]] = '!' . $matches[1][$key] . '!';
+                                       }
+                               } // END - if
 
-       // Some entries found?
-       if ((count($matches) > 0) && (count($matches[0]) > 0)) {
-               // Replace all matches
-               foreach ($matches[0] as $key => $match) {
-                       // Do we have cache?
-                       if (!isset($GLOBALS['compile_config'][$matches[1][$key]])) {
-                               // Is the config valid?
-                               if (isConfigEntrySet($matches[1][$key])) {
-                                       // Set it for caching
-                                       $GLOBALS['compile_config'][$matches[1][$key]] = getConfig($matches[1][$key]);
-                               } elseif (isConfigEntrySet('default_' . strtoupper($matches[1][$key]))) {
-                                       // Use default value
-                                       $GLOBALS['compile_config'][$matches[1][$key]] = getConfig('DEFAULT_' . strtoupper($matches[1][$key]));
-                               } elseif (isMessageIdValid('DEFAULT_' . strtoupper($matches[1][$key]))) {
-                                       // No config, try the language system
-                                       $GLOBALS['compile_config'][$matches[1][$key]] = getMessage('DEFAULT_' . strtoupper($matches[1][$key]));
-                               } else {
-                                       // Unhandled!
-                                       $GLOBALS['compile_config'][$matches[1][$key]] = '!' . $matches[1][$key] . '!';
-                               }
-                       } // END - if
+                               // Use this for replacing
+                               $code = str_replace($match, $GLOBALS['compile_config'][$matches[1][$key]], $code);
+                               //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die('<pre>'.htmlentities($code).'</pre>');
+                       } // END - foreach
+               } // END - if
 
-                       // Use this for replacing
-                       $code = str_replace($match, $GLOBALS['compile_config'][$matches[1][$key]], $code);
-                       //* DEBUG: */ if (($match == '{?URL?}') && (strlen($code) > 10000)) die('<pre>'.htmlentities($code).'</pre>');
-               } // END - foreach
+               // Add it to cache
+               $GLOBALS['compiled_config'][$uncompiled] = $code;
+       } // END - if
+
+       // Should we compile it?
+       if ($compiled === true) {
+               // Run the code
+               eval("\$GLOBALS['compiled_config'][\$uncompiled] = \"" . $GLOBALS['compiled_config'][$uncompiled] . "\";");
        } // END - if
 
        // Return compiled code
-       return $code;
+       return $GLOBALS['compiled_config'][$uncompiled];
 }
 
 // Filter for compiling extension data
index c9d530034735a1d88b48db113107bd8082ac0f42..90e2bc50580fd7d076333d0cd2834421576a32d5 100644 (file)
@@ -382,9 +382,6 @@ function loadTemplate ($template, $return=false, $content=array()) {
 function loadEmailTemplate ($template, $content = array(), $UID = 0) {
        global $DATA;
 
-       // Our configuration is kept non-global here
-       $_CONFIG = getConfigArray();
-
        // Make sure all template names are lowercase!
        $template = strtolower($template);
 
@@ -526,7 +523,7 @@ function loadEmailTemplate ($template, $content = array(), $UID = 0) {
        unset($DATA);
 
        // Compile the code and eval it
-       $eval = '$newContent = "' . compileCode(smartAddSlashes($newContent)) . '";';
+       $eval = '$newContent = "' . compileRawCode(smartAddSlashes($newContent)) . '";';
        eval($eval);
 
        // Return content
@@ -538,7 +535,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
        //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):TO={$toEmail},SUBJECT={$subject}<br />");
 
        // Compile subject line (for POINTS constant etc.)
-       eval("\$subject = decodeEntities(\"".compileCode(smartAddSlashes($subject))."\");");
+       eval("\$subject = decodeEntities(\"".compileRawCode(smartAddSlashes($subject))."\");");
 
        // Set from header
        if ((!eregi('@', $toEmail)) && ($toEmail > 0)) {
@@ -584,10 +581,10 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
        }
 
        // Compile "TO"
-       eval("\$toEmail = \"".compileCode(smartAddSlashes($toEmail))."\";");
+       eval("\$toEmail = \"".compileRawCode(smartAddSlashes($toEmail))."\";");
 
        // Compile "MSG"
-       eval("\$message = \"".compileCode(smartAddSlashes($message))."\";");
+       eval("\$message = \"".compileRawCode(smartAddSlashes($message))."\";");
 
        // Fix HTML parameter (default is no!)
        if (empty($isHtml)) $isHtml = 'N';
@@ -921,7 +918,7 @@ function makeTime ($hours, $minutes, $seconds, $stamp) {
 // Redirects to an URL and if neccessarry extends it with own base URL
 function redirectToUrl ($URL) {
        // Compile out codes
-       eval('$URL = "' . compileCode($URL) . '";');
+       eval('$URL = "' . compileRawCode($URL) . '";');
 
        // Check if http(s):// is there
        if ((substr($URL, 0, 7) != 'http://') && (substr($URL, 0, 8) != 'https://')) {
@@ -999,6 +996,27 @@ function compileCode ($code, $simple = false, $constants = true, $full = true) {
        // Start couting
        $startCompile = explode(' ', microtime());
 
+       // Comile the code
+       $code = compileRawCode($code, $simple, $constants, $full);
+
+       // Get timing
+       $compiled = explode(' ', microtime());
+
+       // Add timing
+       $code .= '<!-- Compilation time: ' . ((($compiled[1] + $compiled[0]) - ($startCompile[1] + $startCompile[0])) * 1000). 'ms //-->';
+
+       // Return compiled code
+       return $code;
+}
+
+// Compiles the code (use compileCode() only for HTML because of the comments)
+function compileRawCode ($code, $simple = false, $constants = true, $full = true) {
+       // Is the code a string?
+       if (!is_string($code)) {
+               // Silently return it
+               return $code;
+       } // END - if
+
        // Init replacement-array with full security characters
        $secChars = $GLOBALS['security_chars'];
 
@@ -1074,13 +1092,7 @@ function compileCode ($code, $simple = false, $constants = true, $full = true) {
                } // END - foreach
        } // END - if
 
-       // Get timing
-       $compiled = explode(' ', microtime());
-
-       // Add timing
-       $code .= '<!-- Compilation time: ' . ((($compiled[1] + $compiled[0]) - ($startCompile[1] + $startCompile[0])) * 1000). 'ms //-->';
-
-       // Return compiled code
+       // Return it
        return $code;
 }
 
@@ -1806,7 +1818,7 @@ function sendRawRequest ($host, $request) {
        //* DEBUG: */ die("SCRIPT=" . $script.'<br />');
        if ($useProxy === true) {
                // Connect to host through proxy connection
-               $fp = @fsockopen(compileCode(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
+               $fp = @fsockopen(compileRawCode(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
        } else {
                // Connect to host directly
                $fp = @fsockopen($host, 80, $errno, $errdesc, 30);
@@ -1827,7 +1839,7 @@ function sendRawRequest ($host, $request) {
                // Use login data to proxy? (username at least!)
                if (getConfig('proxy_username') != '') {
                        // Add it as well
-                       $encodedAuth = base64_encode(compileCode(getConfig('proxy_username')) . getConfig('ENCRYPT_SEPERATOR') . compileCode(getConfig('proxy_password')));
+                       $encodedAuth = base64_encode(compileRawCode(getConfig('proxy_username')) . getConfig('ENCRYPT_SEPERATOR') . compileRawCode(getConfig('proxy_password')));
                        $proxyTunnel .= "Proxy-Authorization: Basic " . $encodedAuth . getConfig('HTTP_EOL');
                } // END - if
 
@@ -2780,7 +2792,7 @@ function compileUriCode ($code, $simple = true) {
 // Function taken from user comments on www.php.net / function eregi()
 function isUrlValidSimple ($url) {
        // Prepare URL
-       $url = secureString(str_replace("\\", '', compileCode(urldecode($url))));
+       $url = secureString(str_replace("\\", '', compileRawCode(urldecode($url))));
 
        // Allows http and https
        $http      = "(http|https)+(:\/\/)";
@@ -3647,7 +3659,7 @@ function isTemplateCached ($template) {
        // Do we have cached this result?
        if (!isset($GLOBALS['template_cache'][$template])) {
                // Generate FQFN
-               $FQFN = sprintf("%stemplates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
+               $FQFN = sprintf("%s_compiled/templates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
 
                // Is it there?
                $GLOBALS['template_cache'][$template] = isFileReadable($FQFN);
@@ -3662,7 +3674,7 @@ function flushTemplateCache ($template, $eval) {
        // Is this cache flushed?
        if (!isTemplateCached($template)) {
                // Generate FQFN
-               $FQFN = sprintf("%stemplates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
+               $FQFN = sprintf("%s_compiled/templates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
 
                // Replace username with a call
                $eval = str_replace('$username', '".getUsername()."', $eval);
@@ -3677,7 +3689,7 @@ function readTemplateCache ($template) {
        // Check it again
        if (isTemplateCached($template)) {
                // Generate FQFN
-               $FQFN = sprintf("%stemplates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
+               $FQFN = sprintf("%s_compiled/templates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
 
                // And read from it
                $GLOBALS['template_eval'][$template] = readFromFile($FQFN);
index b8cce1b19423db278235b5b50e74437558973397..54c5929a051c2ef155d76962ffc8aedb468f4b1a 100644 (file)
@@ -257,7 +257,7 @@ function executePrimeraWithdraw ($primusNick, $userMd5, $amount) {
        $api = new PrimeraApi($primusNick, $userMd5);
 
        // Prepare purpose
-       eval("\$purpose = \"".compileCode(sprintf(getMessage('PRIMERA_API_PURPOSE_WITHDRAW'), getSession('sponsorid')))."\";");
+       eval("\$purpose = \"".compileRawCode(sprintf(getMessage('PRIMERA_API_PURPOSE_WITHDRAW'), getSession('sponsorid')))."\";");
 
        // Pay the Primera
        return $api->payPrimera($primusNick, $amount, $purpose);
@@ -269,7 +269,7 @@ function executePrimeraPayout ($primusNick, $userMd5, $amount) {
        $api = new PrimeraApi(getConfig('primera_api_name'), getConfig('primera_api_md5'));
 
        // Prepare purpose
-       eval("\$purpose = \"".compileCode(sprintf(getMessage('PRIMERA_API_PURPOSE_PAYOUT'), getUserId()))."\";");
+       eval("\$purpose = \"".compileRawCode(sprintf(getMessage('PRIMERA_API_PURPOSE_PAYOUT'), getUserId()))."\";");
 
        // Pay the Primera
        return $api->payPrimera($primusNick, $amount, $purpose);
index b1ea78fb9f8d6ead9853a7c54cfa2b69529c9597..be5acd5de2d79c2d2405fe5103f5072f99e28fff 100644 (file)
@@ -238,7 +238,7 @@ function WERNIS_EXECUTE_WITHDRAW ($wdsId, $userMd5, $amount) {
        $result = false;
 
        // Prepare the purpose
-       eval("\$purpose = \"".compileCode(sprintf(getMessage('WERNIS_API_PURPOSE_WITHDRAW'), getUserId()))."\";");
+       eval("\$purpose = \"".compileRawCode(sprintf(getMessage('WERNIS_API_PURPOSE_WITHDRAW'), getUserId()))."\";");
 
        // Prepare the request data
        $requestData = array(
@@ -278,7 +278,7 @@ function WERNIS_EXECUTE_PAYOUT ($wdsId, $amount) {
        $result = false;
 
        // Prepare the purpose
-       eval("\$purpose = \"".compileCode(sprintf(getMessage('WERNIS_API_PURPOSE_PAYOUT'), getUserId()))."\";");
+       eval("\$purpose = \"".compileRawCode(sprintf(getMessage('WERNIS_API_PURPOSE_PAYOUT'), getUserId()))."\";");
 
        // Prepare the request data
        $requestData = array(
index de90da0cd27fcd303e1d738d028138db2c093fea..4034faef7d39d43af39461c91a9ae1c640c3f240 100644 (file)
@@ -37,7 +37,7 @@
  ************************************************************************/
 
 // XDEBUG call
-/* DEBUG: */ xdebug_start_trace();
+//* DEBUG: */ xdebug_start_trace();
 
 // Load security stuff here
 require('inc/libs/security_functions.php');