cache compiled language variables
authorStricted <info@stricted.de>
Mon, 11 Jan 2016 15:42:46 +0000 (16:42 +0100)
committerStricted <info@stricted.de>
Mon, 11 Jan 2016 15:42:46 +0000 (16:42 +0100)
lang/de.lang.php
lang/en.lang.php
lib/system/DNS.class.php
lib/system/template/plugins/block.lang.php

index 0c13536f1d35528fd9d2b8ee9cd34cd7479fd489..eeff2da21d74b21fa06ed86be9a6e24630a09ce7 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /* language file for german variables */
 $lang = array();
+$lang['languageCode'] = 'de';
 $lang['header.welcome'] = 'Angemeldet als: {$username}';
 $lang['datatable.empty'] = 'Keine Daten vorhanden.';
 $lang['datatable.first'] = 'Erste';
index 2d813b755248d4a62cf7a5b77881711996d76666..cbbcc109dd5fdb8affbb9bb61b910f689ef5cdd2 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /* language file for english variables */
 $lang = array();
+$lang['languageCode'] = 'en';
 $lang['header.welcome'] = 'Logged in as: {$username}';
 $lang['datatable.empty'] = 'No data available in table';
 $lang['datatable.first'] = 'First';
index 1b1dc515d8ff30ef7b506a81c2c544a8792149c8..87ac902f3b4f005d29d03ce5cb92181abac08bb1 100644 (file)
@@ -259,9 +259,29 @@ class DNS {
                if (isset($lang[$item])) {
                        if (strpos($lang[$item], self::getTPL()->left_delimiter) !== false && strpos($lang[$item], self::getTPL()->right_delimiter) !== false) {
                                $data = str_replace("\$", '$', $lang[$item]);
-                               $template_class = self::getTPL()->template_class;
-                               $template = new $template_class('eval:'.$data, self::getTPL(), self::getTPL());
-                               return $template->fetch();
+                               $dir = self::getTPL()->getTemplateDir();
+                               
+                               if (is_array($dir)) {
+                                       $dir = $dir[0];
+                               }
+                               
+                               $filename = "lang.".$lang['languageCode'].".".$content.".tpl";
+                               if (file_exists($dir.$filename)) {
+                                       $mtime = filemtime($dir.$filename);
+                                       $maxLifetime = 3600;
+                                       
+                                       if ($mtime === false || ($maxLifetime > 0 && (time() - $mtime) > $maxLifetime)) {
+                                               @unlink($dir.$filename);
+                                       }
+                               }
+                               
+                               if (!file_exists($dir.$filename)) {
+                                       $h = fopen($dir.$filename, "a+");
+                                       fwrite($h, $lang[$content]);
+                                       fclose($h);
+                               }
+                               
+                               return self::getTPL()->fetch($filename);
                        }
                        
                        return $lang[$item];
index ed89977901bd47a75f54161336dc4477544dd367..4742769aa0aa58e71c8e40bb40c04ab89569f1fd 100644 (file)
@@ -28,8 +28,30 @@ function smarty_block_lang($params, $content, $template, &$repeat) {
        if (isset($lang[$content])) {
                if (strpos($lang[$content], $template->smarty->left_delimiter) !== false && strpos($lang[$content], $template->smarty->right_delimiter) !== false) {
                        $data = str_replace("\$", '$', $lang[$content]);
-                       $_template = new $template->smarty->template_class('eval:'.$data, $template->smarty, $template);
-                       return $_template->fetch();
+                       
+                       $dir = $template->smarty->getTemplateDir();
+                       
+                       if (is_array($dir)) {
+                               $dir = $dir[0];
+                       }
+                       
+                       $filename = "lang.".$lang['languageCode'].".".$content.".tpl";
+                       if (file_exists($dir.$filename)) {
+                               $mtime = filemtime($dir.$filename);
+                               $maxLifetime = 3600;
+                               
+                               if ($mtime === false || ($maxLifetime > 0 && (time() - $mtime) > $maxLifetime)) {
+                                       @unlink($dir.$filename);
+                               }
+                       }
+                       
+                       if (!file_exists($dir.$filename)) {
+                               $h = fopen($dir.$filename, "a+");
+                               fwrite($h, $lang[$content]);
+                               fclose($h);
+                       }
+                       
+                       return $template->smarty->fetch($filename);
                }
                
                return $lang[$content];