]> git.mxchange.org Git - mailer.git/blobdiff - inc/template-functions.php
AJAX installation is 'basicly finished' :) Plus I threw in a small christmas present...
[mailer.git] / inc / template-functions.php
index a4c4d6f0a9f114da1630cba0dfb5805466aeea63..f53fc9115a00cd3c73838c308652d0e632793b28 100644 (file)
@@ -93,7 +93,7 @@ function getColorSwitchCode ($template) {
 }
 
 // Output HTML code directly or 'render' it. You addionally switch the new-line character off
-function outputHtml ($htmlCode, $newLine = TRUE) {
+function outputHtml ($htmlCode = NULL, $newLine = TRUE) {
        // Init output
        if (!isset($GLOBALS['__output'])) {
                $GLOBALS['__output'] = '';
@@ -101,7 +101,7 @@ function outputHtml ($htmlCode, $newLine = TRUE) {
 
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getOutputMode()=' . getOutputMode() . ',htmlCode(length)=' . strlen($htmlCode) . ',output(length)=' . strlen($GLOBALS['__output']));
        // Is there HTML-Code here?
-       if (!empty($htmlCode)) {
+       if ((!is_null($htmlCode)) && (!empty($htmlCode))) {
                // Yes, so we handle it as you have configured
                switch (getOutputMode()) {
                        case 'render':
@@ -344,6 +344,10 @@ function loadTemplate ($template, $return = FALSE, $content = array(), $compileC
                                        // JavaScripts don't like entities, dollar signs and timings
                                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
                                        $GLOBALS['template_eval']['html'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), FALSE, TRUE, TRUE, $compileCode) . '");';
+                               } elseif (isAjaxOutputMode()) {
+                                       // AJAX (JSON content)
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
+                                       $GLOBALS['template_eval']['html'][$template] = '$ret = "' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), FALSE, TRUE, TRUE, $compileCode) . '";';
                                } else {
                                        // Prepare eval() command, other output doesn't like entities, maybe
                                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
@@ -354,6 +358,10 @@ function loadTemplate ($template, $return = FALSE, $content = array(), $compileC
                                $ret = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['template_content']['html'][$template] . '<!-- Template ' . $template . ' - End //-->';
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
                                $GLOBALS['template_eval']['html'][$template] = '$ret = "' . getColorSwitchCode($template) . compileRawCode(escapeQuotes($ret), FALSE, TRUE, TRUE, $compileCode) . '";';
+                       } elseif (isAjaxOutputMode()) {
+                               // AJAX (JSON content)
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
+                               $GLOBALS['template_eval']['html'][$template] = '$ret = "' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), FALSE, TRUE, TRUE, $compileCode) . '";';
                        } else {
                                // JavaScript again
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
@@ -467,7 +475,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
        // Is content an array?
        if (is_array($content)) {
                // Add expiration to array
-               if ((isExtensionInstalled('autopurge')) && (getAutoPurge() == '0')) {
+               if ((isExtensionInstalled('autopurge')) && (isConfigEntrySet('auto_purge')) && (getAutoPurge() == '0')) {
                        // Will never expire!
                        $content['expiration'] = '{--MAIL_WILL_NEVER_EXPIRE--}';
                } elseif ((isExtensionInstalled('autopurge')) && (isConfigEntrySet('auto_purge'))) {
@@ -506,6 +514,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
                        $GLOBALS['template_content']['email'][$template] = readFromFile($FQFN);
 
                        // Run code
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
                        $GLOBALS['template_eval']['email'][$template] = '$newContent = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['template_content']['email'][$template])) . '");';
                } elseif (!empty($template)) {
                        // Template file not found
@@ -536,7 +545,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
        if ((isset($GLOBALS['template_eval']['email'][$template])) && ($GLOBALS['template_eval']['email'][$template] != '404')) {
                // Eval the code
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'template=' . $template . ' - BEFORE EVAL');
-               ///* DEBUG: */ print('<pre>'.htmlentities($GLOBALS['template_eval']['email'][$template]).'</pre>');
+               //* DEBUG: */ print('<pre>'.htmlentities($GLOBALS['template_eval']['email'][$template]).'</pre>');
                eval($GLOBALS['template_eval']['email'][$template]);
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'template=' . $template . ' - AFTER EVAL');
        } // END - if
@@ -1208,8 +1217,14 @@ function app_exit ($F, $L, $message) {
        // Make sure, that the script realy realy diese here and now
        $GLOBALS['app_died'] = TRUE;
 
-       // Set content type as text/html
-       setContentType('text/html');
+       // Is this AJAX mode?
+       if (isAjaxOutputMode()) {
+               // Set content type as application/json
+               setContentType('application/json');
+       } else {
+               // Set content type as text/html
+               setContentType('text/html');
+       }
 
        // Load header
        loadIncludeOnce('inc/header.php');
@@ -1222,8 +1237,17 @@ function app_exit ($F, $L, $message) {
                $message
        );
 
-       // Load the message template
-       loadTemplate('app_exit_message', FALSE, $message);
+       // Is this AJAX mode again
+       if (isAjaxOutputMode()) {
+               // Load the message template
+               $OUT = loadTemplate('ajax_app_exit_message', TRUE, $message);
+
+               // Output it as JSON encoded
+               outputHtml(encodeJson(array('reply_content' => urlencode(doFinalCompilation($OUT)))));
+       } else {
+               // Load the message template
+               loadTemplate('app_exit_message', FALSE, $message);
+       }
 
        // Load footer
        loadIncludeOnce('inc/footer.php');
@@ -1678,7 +1702,7 @@ function sendModeMails ($mod, $modes) {
                $hash = encodeHashForCookie(getUserData('password'));
 
                // Does the hash match or should we change it?
-               if (($hash == getSession('u_hash')) || (postRequestElement('pass1') == postRequestElement('pass2'))) {
+               if (($hash == getSession('u_hash')) || (postRequestElement('password1') == postRequestElement('password2'))) {
                        // Load the data
                        $content = getUserDataArray();