From: Stricted Date: Mon, 11 Jan 2016 15:42:46 +0000 (+0100) Subject: cache compiled language variables X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=01885ee5f9eae3e5d86ca73b6be744d5ea0bbdf1;p=GitHub%2FStricted%2FDomain-Control-Panel.git cache compiled language variables --- diff --git a/lang/de.lang.php b/lang/de.lang.php index 0c13536..eeff2da 100644 --- a/lang/de.lang.php +++ b/lang/de.lang.php @@ -1,6 +1,7 @@ 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]; diff --git a/lib/system/template/plugins/block.lang.php b/lib/system/template/plugins/block.lang.php index ed89977..4742769 100644 --- a/lib/system/template/plugins/block.lang.php +++ b/lib/system/template/plugins/block.lang.php @@ -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];