]> git.mxchange.org Git - mailer.git/blobdiff - inc/template-functions.php
Refback and referal points hopefully fixed:
[mailer.git] / inc / template-functions.php
index 4280695bdb50a2dea032859caaa2f98b63e66343..6e2e4730660d0f0e803575ab0fc29e97f4435cb1 100644 (file)
@@ -240,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;
 }
@@ -425,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!
@@ -447,24 +460,24 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0', $loadU
        } // END - if
 
        // Load user's data
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UID={$userid},template={$template},content[]=".gettype($content));
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UID=' . $userid . ',template=' . $template . ',content[]=' . gettype($content));
        if ((isValidUserId($userid)) && (is_array($content))) {
                // If nickname extension is installed, fetch nickname as well
                if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
                        // Load by nickname
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NICKNAME!<br />");
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - NICKNAME!');
                        fetchUserData($userid, 'nickname');
                } elseif (isNicknameUsed($userid)) {
                        // Non-number characters entered but no ext-nickname found
                        debug_report_bug(__FUNCTION__, __LINE__, 'userid=' . $userid . ': is no id number and ext-nickname is gone.');
                } else {
                        // Load by userid
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NO-NICK!<br />");
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ' - USERID!');
                        fetchUserData($userid);
                }
 
                // Merge data if valid
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "content()=".count($content)." - PRE<br />");
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'content()=' . count($content) . ' - PRE!');
                if ((isUserDataValid()) && ($loadUserData === true)) {
                        // It is valid
                        $content = merge_array($content, getUserDataArray());
@@ -473,7 +486,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0', $loadU
                        unset($content['password']);
                } // END - if
 
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "content()=".count($content)." - AFTER<br />");
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'content()=' . count($content) . ' - AFTER!');
        } // END - if
 
        // Base directory
@@ -617,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)) {
@@ -634,31 +647,36 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true
                                $test = substr($found, 0, strlen($match));
 
                                // Does this entry exist?
-                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "found={$found},match={$match},set={$set}<br />");
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'found=' . $found . ',match=' . $match . ',set=' . $set);
                                if ($test == $match) {
                                        // Match found
-                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "fuzzyFound!<br />");
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'fuzzyFound!');
                                        $fuzzyFound = true;
                                        break;
                                } // END - if
                        } // 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]]))) {
                                // Replace it in the code
-                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "key={$key},match={$match}<br />");
+                               //* DEBUG: */ logDebugMessage(__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;
+                               $matchesFound[$match] = true;
                        } elseif (!isset($matchesFound[$match])) {
                                // Not yet replaced!
-                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "match={$match}<br />");
+                               //* 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
@@ -1113,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;
 }
@@ -1428,7 +1443,10 @@ function determinePageTitle () {
                $pageTitle = '{--NO_CONFIG_FOUND_TITLE--}';
 
                // Do not add the fatal message in installation mode
-               if ((!isInstalling()) && (!isConfigurationLoaded())) addFatalMessage(__FUNCTION__, __LINE__, '{--NO_CONFIG_FOUND--}');
+               if ((!isInstalling()) && (!isConfigurationLoaded())) {
+                       // Please report this
+                       debug_report_bug(__FUNCTION__, __LINE__, 'No configuration data found!');
+               } // END - if
        }
 
        // Return title
@@ -1690,8 +1708,8 @@ function generateMetaDescriptionCode () {
                $GLOBALS['page_header'] .= '<meta name="description" content="' . $DESCR . '" />';
        } // END - if
 
-       // Remove depth
-       unset($GLOBALS['ref_level']);
+       // Initialize referal system
+       initReferalSystem();
 }
 
 // Generates an FQFN for template cache from the given template name