mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
added CDATA,
fixed variable-names
This commit is contained in:
@@ -26,8 +26,9 @@
|
|||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>exemple d'utilisation de MySQL pour la source du cache</title>
|
<title>exemple d'utilisation de MySQL pour la source du cache</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
<?php
|
<![CDATA[
|
||||||
|
<?php
|
||||||
/*
|
/*
|
||||||
|
|
||||||
exemple d'usage :
|
exemple d'usage :
|
||||||
@@ -36,9 +37,9 @@ include('Smarty.class.php');
|
|||||||
include('mysql_cache_handler.php');
|
include('mysql_cache_handler.php');
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->cache_handler_func = 'mysql_cache_handler';
|
$smarty-i>cache_handler_func = 'mysql_cache_handler';
|
||||||
|
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
|
||||||
la base mysql est attendu dans ce format :
|
la base mysql est attendu dans ce format :
|
||||||
@@ -52,7 +53,7 @@ CacheContents MEDIUMTEXT NOT NULL
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function mysql_cache_handler($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null)
|
function mysql_cache_handler($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null)
|
||||||
{
|
{
|
||||||
// l'h(te de la bd, l'utilisateur, et le mot de passe
|
// l'h(te de la bd, l'utilisateur, et le mot de passe
|
||||||
$db_host = 'localhost';
|
$db_host = 'localhost';
|
||||||
@@ -65,7 +66,7 @@ function mysql_cache_handler($action, &$smarty_obj, &$cache_content, $tp
|
|||||||
$CacheID = md5($tpl_file.$cache_id.$compile_id);
|
$CacheID = md5($tpl_file.$cache_id.$compile_id);
|
||||||
|
|
||||||
if(! $link = mysql_pconnect($db_host, $db_user, $db_pass)) {
|
if(! $link = mysql_pconnect($db_host, $db_user, $db_pass)) {
|
||||||
$smarty_obj->_trigger_error_msg("cache_handler: could not connect to database");
|
$smarty_obj->_trigger_error_msg("cache_handler: could not connect to database");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mysql_select_db($db_name);
|
mysql_select_db($db_name);
|
||||||
@@ -75,21 +76,21 @@ function mysql_cache_handler($action, &$smarty_obj, &$cache_content, $tp
|
|||||||
// r<>cup<75>re le cache dans la base de donn<6E>es
|
// r<>cup<75>re le cache dans la base de donn<6E>es
|
||||||
$results = mysql_query("select CacheContents from CACHE_PAGES where CacheID='$CacheID'");
|
$results = mysql_query("select CacheContents from CACHE_PAGES where CacheID='$CacheID'");
|
||||||
if(!$results) {
|
if(!$results) {
|
||||||
$smarty_obj->_trigger_error_msg("cache_handler: query failed.");
|
$smarty_obj->_trigger_error_msg("cache_handler: query failed.");
|
||||||
}
|
}
|
||||||
$row = mysql_fetch_array($results,MYSQL_ASSOC);
|
$row = mysql_fetch_array($results,MYSQL_ASSOC);
|
||||||
|
|
||||||
if($use_gzip && function_exists("gzuncompress")) {
|
if($use_gzip && function_exists("gzuncompress")) {
|
||||||
$cache_contents = gzuncompress($row["CacheContents"]);
|
$cache_content = gzuncompress($row["CacheContents"]);
|
||||||
} else {
|
} else {
|
||||||
$cache_contents = $row["CacheContents"];
|
$cache_content = $row["CacheContents"];
|
||||||
}
|
}
|
||||||
$return = $results;
|
$return = $results;
|
||||||
break;
|
break;
|
||||||
case 'write':
|
case 'write':
|
||||||
// sauvegarde le cache dans la base de donn<6E>es
|
// sauvegarde le cache dans la base de donn<6E>es
|
||||||
|
|
||||||
if($use_gzip && function_exists("gzcompress")) {
|
if($use_gzip && function_exists("gzcompress")) {
|
||||||
// compresse le contenu pour gagner de la place
|
// compresse le contenu pour gagner de la place
|
||||||
$contents = gzcompress($cache_content);
|
$contents = gzcompress($cache_content);
|
||||||
} else {
|
} else {
|
||||||
@@ -100,26 +101,26 @@ function mysql_cache_handler($action, &$smarty_obj, &$cache_content, $tp
|
|||||||
'".addslashes($contents)."')
|
'".addslashes($contents)."')
|
||||||
");
|
");
|
||||||
if(!$results) {
|
if(!$results) {
|
||||||
$smarty_obj->_trigger_error_msg("cache_handler: query failed.");
|
$smarty_obj->_trigger_error_msg("cache_handler: query failed.");
|
||||||
}
|
}
|
||||||
$return = $results;
|
$return = $results;
|
||||||
break;
|
break;
|
||||||
case 'clear':
|
case 'clear':
|
||||||
// efface les donn<6E>es du cache
|
// efface les donn<6E>es du cache
|
||||||
if(empty($cache_id) && empty($compile_id) && empty($tpl_file)) {
|
if(empty($cache_id) && empty($compile_id) && empty($tpl_file)) {
|
||||||
// les efface toutes
|
// les efface toutes
|
||||||
$results = mysql_query("delete from CACHE_PAGES");
|
$results = mysql_query("delete from CACHE_PAGES");
|
||||||
} else {
|
} else {
|
||||||
$results = mysql_query("delete from CACHE_PAGES where CacheID='$CacheID'");
|
$results = mysql_query("delete from CACHE_PAGES where CacheID='$CacheID'");
|
||||||
}
|
}
|
||||||
if(!$results) {
|
if(!$results) {
|
||||||
$smarty_obj->_trigger_error_msg("cache_handler: query failed.");
|
$smarty_obj->_trigger_error_msg("cache_handler: query failed.");
|
||||||
}
|
}
|
||||||
$return = $results;
|
$return = $results;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// erreur, action inconnue
|
// erreur, action inconnue
|
||||||
$smarty_obj->_trigger_error_msg("cache_handler: unknown action \"$action\"");
|
$smarty_obj->_trigger_error_msg("cache_handler: unknown action \"$action\"");
|
||||||
$return = false;
|
$return = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -128,7 +129,9 @@ function mysql_cache_handler($action, &$smarty_obj, &$cache_content, $tp
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?></programlisting>
|
?>
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<!-- Keep this comment at the end of the file
|
<!-- Keep this comment at the end of the file
|
||||||
|
Reference in New Issue
Block a user