]> git.mxchange.org Git - mailer.git/blobdiff - inc/template-functions.php
Refback and referal points hopefully fixed:
[mailer.git] / inc / template-functions.php
index 10e1240b1d6c25c9c4a29ada1be7d95a2a7e5fd7..6e2e4730660d0f0e803575ab0fc29e97f4435cb1 100644 (file)
@@ -217,9 +217,6 @@ function doFinalCompilation ($code, $insertComments = true, $enableCodes = true)
        // Init counter
        $count = 0;
 
-       // Compile the raw code
-       $code = compileRawCode($code);
-
        // Compile all out
        while (((strpos($code, '{--') !== false) || (strpos($code, '{DQUOTE}') !== false) || (strpos($code, '{?') !== false) || (strpos($code, '{%') !== false)) && ($count < 7)) {
                // Init common variables
@@ -243,10 +240,22 @@ function doFinalCompilation ($code, $insertComments = true, $enableCodes = true)
                // Use it again
                $code = $newContent;
 
+               // Compile the final code if insertComments is true
+               if ($insertComments == true) {
+                       // ... because SQL queries shall keep OPEN_CONFIG and such in
+                       $code = compileRawCode($code);
+               } // END - if
+
                // Count round
                $count++;
        } // END - while
 
+       // Add debugging data in HTML code, if mode is enabled
+       if ((isDebugModeEnabled()) && ($insertComments === true)) {
+               // Add loop count
+               $code .= '<!-- Total compilation loop=' . $count . ' //-->';
+       } // END - if
+
        // Return the compiled code
        return $code;
 }
@@ -428,7 +437,8 @@ function detectExtraTemplatePath ($template) {
 }
 
 // Loads an email template and compiles it
-function loadEmailTemplate ($template, $content = array(), $userid = '0', $loadUserData = true) {
+function loadEmailTemplate ($template, $content = array(), $userid = NULL, $loadUserData = true) {
+       // @TODO $DATA is deprecated and should be avoided and replaced with $content
        global $DATA;
 
        // Make sure all template names are lowercase!
@@ -620,8 +630,8 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true
        $code = str_replace($secChars['to'], $secChars['from'], $code);
 
        // Find $content[bla][blub] entries
-       // @TODO Do only use $content and deprecate $GLOBALS and $DATA in templates
-       preg_match_all('/\$(content|GLOBALS|DATA)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
+       // @TODO Do only use $content and deprecate $DATA in templates
+       preg_match_all('/\$(content|DATA)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
 
        // Are some matches found?
        if ((count($matches) > 0) && (count($matches[0]) > 0)) {
@@ -647,7 +657,9 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true
                        } // END - foreach
 
                        // Skip this entry?
-                       if ($fuzzyFound === true) continue;
+                       if ($fuzzyFound === true) {
+                               continue;
+                       } // END - if
 
                        // Take all string elements
                        if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key.'_' . $matches[4][$key]]))) {
@@ -656,12 +668,15 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true
                                $newMatch = str_replace('[', "['", str_replace(']', "']", $match));
                                $code = str_replace($match, '".' . $newMatch . '."', $code);
                                $matchesFound[$key . '_' . $matches[4][$key]] = 1;
-                               $matchesFound[$match] = 1;
+                               $matchesFound[$match] = true;
                        } elseif (!isset($matchesFound[$match])) {
                                // Not yet replaced!
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'match=' . $match);
                                $code = str_replace($match, '".' . $match . '."', $code);
                                $matchesFound[$match] = 1;
+                       } else {
+                               // Everthing else should be a least logged
+                               logDebugMessage(__FUNCTION__, __LINE__, 'match=' . $match . ',key=' . $key);
                        }
                } // END - foreach
        } // END - if
@@ -1116,9 +1131,6 @@ function generateEmailLink ($email, $table = 'admins') {
                $EMAIL = generateSponsorEmailLink($email);
        }
 
-       // Shall I close the link when there is no admin?
-       if ((!isAdmin()) && ($EMAIL == $email)) $EMAIL = '#'; // Closed!
-
        // Return email link
        return $EMAIL;
 }