]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Template fixes, lesser admin data will be loaded from database
[mailer.git] / inc / functions.php
index 3cdcf706954d99018397dba1f6d6ee480f3508cd..3a8bf9c0fd2ba9fea5fbcb95a8ca53ff19e67ecf 100644 (file)
@@ -131,6 +131,7 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) {
                $OUTPUT = ob_get_contents();
 
                // Clear output buffer for later output
+               die();
                ob_end_clean();
 
                // Extension "rewrite" installed?
@@ -704,13 +705,13 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
        $REMOTE_ADDR     = getenv('REMOTE_ADDR');
        $HTTP_USER_AGENT = getenv('HTTP_USER_AGENT');
 
+       // Default admin
        $ADMIN = MAIN_TITLE;
-       if (isSessionVariableSet('admin_login')) {
+
+       // Is the admin logged in?
+       if (IS_ADMIN()) {
                // Load Admin data
-               $result = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
-                       array(get_session('admin_login')), __FILE__, __LINE__);
-               list($ADMIN) = SQL_FETCHROW($result);
-               SQL_FREERESULT($result);
+               $ADMIN = GET_ADMIN_EMAIL(get_session('admin_login'));
        } // END - if
 
        // Neutral email address is default
@@ -744,7 +745,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
                                array(bigintval($UID)), __FILE__, __LINE__);
                } else {
                        //* DEBUG: */ echo __FUNCTION__.":NO-NICK!<br />\n";
-                       // Load normal data
+                       /// Load normal data
                        $result = SQL_QUERY_ESC("SELECT surname, family, gender, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
                                array(bigintval($UID)), __FILE__, __LINE__);
                }
@@ -811,7 +812,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
 
                // Run code
                $tmpl_file = "\$newContent=html_entity_decode(\"".COMPILE_CODE($tmpl_file)."\");";
-               eval($tmpl_file);
+               @eval($tmpl_file);
        } elseif (!empty($template)) {
                // Template file not found!
                $newContent = TEMPLATE_404.": ".$template."<br />
@@ -831,7 +832,8 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
        // Is there some content?
        if (empty($newContent)) {
                // Compiling failed
-               $newContent = "Compiler error for template {$template}!";
+               $newContent = "Compiler error for template {$template}!\nUncompiled content:\n".$tmpl_file;
+               if (function_exists('error_get_last')) $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
        } // END - if
 
        // Return compiled content
@@ -911,13 +913,13 @@ function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
                // BEFORE 0.2.1 : Not used
                // WITH 0.2.1+  : Data constants
                $code = str_replace('{!','".', str_replace("!}", '."', $code));
-       }
+       } // END - if
 
        // Compile QUOT and other non-HTML codes
        foreach ($ARRAY['to'] as $k => $to) {
                // Do the reversed thing as in inc/libs/security_functions.php
                $code = str_replace($to, $ARRAY['from'][$k], $code);
-       }
+       } // END - foreach
 
        // But shall I keep simple quotes for later use?
        if ($simple) $code = str_replace("\'", '{QUOT}', $code);
@@ -930,22 +932,43 @@ function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
                // Replace all matches
                $matchesFound = array();
                foreach ($matches[0] as $key => $match) {
-                       // Avoid replacing matches multiple times
-                       if (!isset($matchesFound[$match])) {
-                               // Not yet replaced!
-                               $code = str_replace($match, "\".".$match.".\"", $code);
-                               $matchesFound[$match] = 1;
-                       } // END - if
+                       // Fuzzy look has failed by default
+                       $fuzzyFound = false;
+
+                       // Fuzzy look on match if already found
+                       foreach ($matchesFound as $found => $set) {
+                               // Get test part
+                               $test = substr($found, 0, strlen($match));
+
+                               // Does this entry exist?
+                               //* DEBUG: */ echo __FUNCTION__.":found={$found},match={$match},set={$set}<br />\n";
+                               if ($test == $match) {
+                                       // Match found!
+                                       //* DEBUG: */ echo __FUNCTION__.":fuzzyFound!<br />\n";
+                                       $fuzzyFound = true;
+                                       break;
+                               } // END - if
+                       } // END - foreach
+
+                       // Skip this entry?
+                       if ($fuzzyFound) continue;
 
                        // Take all string elements
-                       if ((is_string($matches[4][$key])) && (!isset($matchesFound[$key."_".$matches[4][$key]]))) {
+                       if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key."_".$matches[4][$key]]))) {
                                // Replace it in the code
+                               //* DEBUG: */ echo __FUNCTION__.":key={$key},match={$match}<br />\n";
                                $newMatch = str_replace("[".$matches[4][$key]."]", "['".$matches[4][$key]."']", $match);
-                               $code = str_replace($match, $newMatch, $code);
+                               $code = str_replace($match, "\".".$newMatch.".\"", $code);
                                $matchesFound[$key."_".$matches[4][$key]] = 1;
-                       } // END - if
-               }
-       }
+                               $matchesFound[$match] = 1;
+                       } elseif (!isset($matchesFound[$match])) {
+                               // Not yet replaced!
+                               //* DEBUG: */ echo __FUNCTION__.":match={$match}<br />\n";
+                               $code = str_replace($match, "\".".$match.".\"", $code);
+                               $matchesFound[$match] = 1;
+                       }
+               } // END - foreach
+       } // END - if
 
        // Return compiled code
        return $code;