]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Cache path changed and compileRawCode() introduced
[mailer.git] / inc / functions.php
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);