From ae68d538e864bc74287665ae43498591c4cdc485 Mon Sep 17 00:00:00 2001 From: rmontagne Date: Wed, 30 Apr 2014 14:57:51 +0200 Subject: [PATCH] Add patch for NFS compatibility --- library/Rain/Tpl.php | 1 + library/Rain/Tpl/Parser.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/library/Rain/Tpl.php b/library/Rain/Tpl.php index 32f6333..8c4e846 100644 --- a/library/Rain/Tpl.php +++ b/library/Rain/Tpl.php @@ -39,6 +39,7 @@ class Tpl { 'sandbox' => true, 'remove_comments' => false, 'registered_tags' => array(), + 'nfs' => false, ); // tags registered by the developers diff --git a/library/Rain/Tpl/Parser.php b/library/Rain/Tpl/Parser.php index df33049..b940f15 100644 --- a/library/Rain/Tpl/Parser.php +++ b/library/Rain/Tpl/Parser.php @@ -113,6 +113,15 @@ public function compileFile( $parsedTemplateFilepath ) { + //Copy on TMP file used for NFS + if ($this->config['nfs']) + { + $tmpFile = uniqid(); + copy($templateFilepath, '/tmp/'.$tmpFile); + $templateFilepath = '/tmp/'.$tmpFile; + } + + // open the template $fp = fopen($templateFilepath, "r"); @@ -160,6 +169,10 @@ public function compileFile( // close the file fclose($fp); + + //Delete TMP file + if ($this->config['nfs']) + unlink($templateFilepath); } /** @@ -173,6 +186,14 @@ public function compileFile( */ public function compileString($templateName, $templateBasedir, $templateFilepath, $parsedTemplateFilepath, $code) { + //Copy on TMP file used for NFS + if ($this->config['nfs']) + { + $tmpFile = uniqid(); + copy($templateFilepath, '/tmp/'.$tmpFile); + $templateFilepath = '/tmp/'.$tmpFile; + } + // open the template $fp = fopen($parsedTemplateFilepath, "w"); @@ -215,6 +236,10 @@ public function compileString($templateName, $templateBasedir, $templateFilepath // close the file fclose($fp); + + //Delete TMP file + if ($this->config['nfs']) + unlink($templateFilepath); } /**