X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=049a7cb9c1252dd342cb910a3de412b67222fed1;hb=16de7d9e8b98108627db01688bc095240b5ba8d2;hp=8d4cc44e906a65030c6543570847e47885006dbe;hpb=9f6c30cc0e06098171d773d671292081ecee3d29;p=mailer.git diff --git a/inc/functions.php b/inc/functions.php index 8d4cc44e90..049a7cb9c1 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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 = ''; @@ -2919,7 +2916,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 +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 // //////////////////////////////////////////////////