[grisbi-cvs] grisbi-web xml.php,1.7,1.8

NIEL Gérald gegeweb at users.sourceforge.net
Sun May 30 20:18:33 CEST 2010


Update of /cvsroot/grisbi/grisbi-web
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv1897

Modified Files:
	xml.php 
Log Message:

cache system

Index: xml.php
===================================================================
RCS file: /cvsroot/grisbi/grisbi-web/xml.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- xml.php	30 May 2010 16:51:27 -0000	1.7
+++ xml.php	30 May 2010 18:18:30 -0000	1.8
@@ -11,41 +11,57 @@
 else $xsl_file=$xml_file;
 
 $path=$xml_file;
+$cache="$path/$xsl_file.$lang.html";
 $xml_file="$path/$xml_file.xml";
 $xsl_file="$path/$xsl_file.xsl";
 
-if (!file_exists($xml_file)) {
-	trigger_error("file $xml_file do not exist", E_USER_ERROR);
-	exit();
-}
-if (!file_exists($xsl_file)) {
-	trigger_error("file $xsl_file do not exist", E_USER_ERROR);
-	exit();
+$expire = time() -3600 ; // valable une heure
+ 
+if(file_exists($cache) && filemtime($cache) > $expire)
+{
+        readfile($cache);
 }
+else {
+	ob_start(); // ouverture du tampon
+	
+	if (!file_exists($xml_file)) {
+		trigger_error("file $xml_file do not exist", E_USER_ERROR);
+		exit();
+	}
+	if (!file_exists($xsl_file)) {
+		trigger_error("file $xsl_file do not exist", E_USER_ERROR);
+		exit();
+	}
 
-$xp = new XsltProcessor();
+	$xp = new XsltProcessor();
 
-// create a DOM document and load the XSL stylesheet
-$xsl = new DomDocument;
-$xsl->load("$xsl_file");
+	// create a DOM document and load the XSL stylesheet
+	$xsl = new DomDocument;
+	$xsl->load("$xsl_file");
   
-// import the XSL styelsheet into the XSLT process
-$xp->importStylesheet($xsl);
-
-// create a DOM document and load the XML datat
-$xml_doc = new DomDocument;
-$xml_doc->load("$xml_file");
+	// import the XSL styelsheet into the XSLT process
+	$xp->importStylesheet($xsl);
 
-$params['param.1'] = $lang;
-$xp->setParameter($namespace, $params);
+	// create a DOM document and load the XML datat
+	$xml_doc = new DomDocument;
+	$xml_doc->load("$xml_file");
 
-// transform the XML into HTML using the XSL file
-if ($result = $xp->transformToXML($xml_doc)) {
-	$result=str_replace("<php>","<?php",$result);
-	$result=str_replace("</php>","?>",$result);
-    echo $result;
-} else {
-    trigger_error('XSL transformation failed.', E_USER_ERROR);
-} // if 
+	$params['param.1'] = $lang;
+	$xp->setParameter($namespace, $params);
 
+	// transform the XML into HTML using the XSL file
+	if ($result = $xp->transformToXML($xml_doc)) {
+		$result=str_replace("<php>","<?php",$result);
+		$result=str_replace("</php>","?>",$result);
+    	echo $result;
+	} else {
+    	trigger_error('XSL transformation failed.', E_USER_ERROR);
+	} // if
+	
+	$page = ob_get_contents(); // copie du contenu du tampon dans une chaîne
+	ob_end_clean(); // effacement du contenu du tampon et arrêt de son fonctionnement
+	file_put_contents($cache, $page);
+	
+	echo $page;
+}
 ?>
\ No newline at end of file



More information about the cvs mailing list