]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Template cache introduced to shortcut expensive compileCode() calls:
[mailer.git] / inc / functions.php
index 7b691f4bfe5e4686c0423e3512f2cfe9aa8e1e40..049a7cb9c1252dd342cb910a3de412b67222fed1 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 = '';
@@ -3642,6 +3639,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 //
 //////////////////////////////////////////////////