Compilation time added, some compileCode() calles removed, ADMIN_WHAT_404 added
[mailer.git] / inc / functions.php
index 8d4cc44e906a65030c6543570847e47885006dbe..c9d530034735a1d88b48db113107bd8082ac0f42 100644 (file)
@@ -226,7 +226,10 @@ function loadTemplate ($template, $return=false, $content=array()) {
        global $DATA;
 
        // Do we have cache?
-       if (!isset($GLOBALS['template_eval'][$template])) {
+       if (isTemplateCached($template)) {
+               // Evaluate the cache
+               eval(readTemplateCache($template));
+       } elseif (!isset($GLOBALS['template_eval'][$template])) {
                // Add more variables which you want to use in your template files
                $username = getUsername();
 
@@ -240,12 +243,6 @@ function loadTemplate ($template, $return=false, $content=array()) {
                $ret = '';
                if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0;
 
-               // Generate date/time string
-               $date_time = generateDateTime(time(), 1);
-
-               // Is content an array
-               if (is_array($content)) $content['date_time'] = $date_time;
-
                // Base directory
                $basePath = sprintf("%stemplates/%s/html/", getConfig('PATH'), getLanguage());
                $mode = '';
@@ -330,7 +327,7 @@ function loadTemplate ($template, $return=false, $content=array()) {
                                        $ret = "<!-- Template " . $template . " - Start -->\n" . $GLOBALS['tpl_content'] . "<!-- Template " . $template . " - End -->\n";
 
                                        // Prepare eval() command
-                                       $eval = '$ret = "' . compileCode(smartAddSlashes($GLOBALS['tpl_content'])) . '";';
+                                       $eval = '$ret = "' . compileCode(smartAddSlashes($ret)) . '";';
                                } else {
                                        // Prepare eval() command
                                        $eval = '$ret = "' . compileCode(smartAddSlashes($GLOBALS['tpl_content'])) . '";';
@@ -999,6 +996,9 @@ function compileCode ($code, $simple = false, $constants = true, $full = true) {
                return $code;
        } // END - if
 
+       // Start couting
+       $startCompile = explode(' ', microtime());
+
        // Init replacement-array with full security characters
        $secChars = $GLOBALS['security_chars'];
 
@@ -1074,6 +1074,12 @@ 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 $code;
 }
@@ -1755,9 +1761,6 @@ function sendPostRequest ($script, $postData) {
                return array('', '', '');
        } // END - if
 
-       // Compile the script name
-       $script = compileCode($script);
-
        // Extract host name from script
        $host = extractHostnameFromUrl($script);
 
@@ -1898,9 +1901,6 @@ function sendRawRequest ($host, $request) {
 
 // Taken from www.php.net eregi() user comments
 function isEmailValid ($email) {
-       // Compile email
-       $email = compileCode($email);
-
        // Check first part of email address
        $first = '[-a-z0-9!#$%&\'*+/=?^_<{|}~]+(\.[-a-zA-Z0-9!#$%&\'*+/=?^_<{|}~]+)*';
 
@@ -2919,7 +2919,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
 }
 // Send notification to admin
 function sendAdminNotification ($subject, $templateName, $content=array(), $userid = 0) {
-       if (getExtensionVersion('admins') >= '0.4.1') {
+       if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
                // Send new way
                sendAdminsEmails($subject, $templateName, $content, $userid);
        } else {
@@ -3642,6 +3642,51 @@ function determinePageTitle () {
        return $pageTitle;
 }
 
+// Checks wethere there is a cache file there. This function is cached.
+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);
+
+               // Is it there?
+               $GLOBALS['template_cache'][$template] = isFileReadable($FQFN);
+       } // END - if
+
+       // Return it
+       return $GLOBALS['template_cache'][$template];
+}
+
+// Flushes non-flushed template cache to disk
+function flushTemplateCache ($template, $eval) {
+       // Is this cache flushed?
+       if (!isTemplateCached($template)) {
+               // Generate FQFN
+               $FQFN = sprintf("%stemplates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
+
+               // Replace username with a call
+               $eval = str_replace('$username', '".getUsername()."', $eval);
+
+               // And flush it
+               writeToFile($FQFN, $eval, true);
+       } // END - if
+}
+
+// Reads a template cache
+function readTemplateCache ($template) {
+       // Check it again
+       if (isTemplateCached($template)) {
+               // Generate FQFN
+               $FQFN = sprintf("%stemplates/%s.tpl.cache", getConfig('CACHE_PATH'), $template);
+
+               // And read from it
+               $GLOBALS['template_eval'][$template] = readFromFile($FQFN);
+       } // END - if
+
+       // And return it
+       return $GLOBALS['template_eval'][$template];
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////