2004-04-13 11:47:32 +00:00
|
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
|
|
|
<!-- $Revision$ -->
|
2004-12-26 20:05:31 +00:00
|
|
|
|
<!-- EN-Revision: 1.2 Maintainer: yannick Status: ready -->
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<sect1 id="plugins.resources"><title>Ressources</title>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Les plugins ressources sont un moyen g<>n<EFBFBD>rique de fournir des sources
|
2004-12-26 20:05:31 +00:00
|
|
|
|
de templates ou des composants de scripts PHP <20> Smarty. Quelques exemples
|
|
|
|
|
|
de ressources : bases de donn<6E>es, LDAP, m<>moire partag<61>e, sockets, etc.
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
<para>
|
|
|
|
|
|
Il y au total 4 fonctions qui ont besoin d'<27>tre enregistr<74>es pour
|
2004-12-26 20:05:31 +00:00
|
|
|
|
chaque type de ressource. Chaque fonction re<72>oit le nom de la ressource demand<6E>e
|
|
|
|
|
|
comme premier param<61>tre et l'objet Smarty comme dernier param<61>tre.
|
|
|
|
|
|
Les autres param<61>tres d<>pendent de la fonction.
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
<funcsynopsis>
|
|
|
|
|
|
<funcprototype>
|
|
|
|
|
|
<funcdef>bool <function>smarty_resource_<replaceable>name</replaceable>_source</function></funcdef>
|
|
|
|
|
|
<paramdef>string <parameter>$rsrc_name</parameter></paramdef>
|
|
|
|
|
|
<paramdef>string <parameter>&$source</parameter></paramdef>
|
|
|
|
|
|
<paramdef>object <parameter>&$smarty</parameter></paramdef>
|
|
|
|
|
|
</funcprototype>
|
|
|
|
|
|
<funcprototype>
|
|
|
|
|
|
<funcdef>bool <function>smarty_resource_<replaceable>name</replaceable>_timestamp</function></funcdef>
|
|
|
|
|
|
<paramdef>string <parameter>$rsrc_name</parameter></paramdef>
|
|
|
|
|
|
<paramdef>int <parameter>&$timestamp</parameter></paramdef>
|
|
|
|
|
|
<paramdef>object <parameter>&$smarty</parameter></paramdef>
|
|
|
|
|
|
</funcprototype>
|
|
|
|
|
|
<funcprototype>
|
|
|
|
|
|
<funcdef>bool <function>smarty_resource_<replaceable>name</replaceable>_secure</function></funcdef>
|
|
|
|
|
|
<paramdef>string <parameter>$rsrc_name</parameter></paramdef>
|
|
|
|
|
|
<paramdef>object <parameter>&$smarty</parameter></paramdef>
|
|
|
|
|
|
</funcprototype>
|
|
|
|
|
|
<funcprototype>
|
|
|
|
|
|
<funcdef>bool <function>smarty_resource_<replaceable>name</replaceable>_trusted</function></funcdef>
|
|
|
|
|
|
<paramdef>string <parameter>$rsrc_name</parameter></paramdef>
|
|
|
|
|
|
<paramdef>object <parameter>&$smarty</parameter></paramdef>
|
|
|
|
|
|
</funcprototype>
|
|
|
|
|
|
</funcsynopsis>
|
2004-04-13 11:47:32 +00:00
|
|
|
|
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<para>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
La premi<6D>re fonction est suppos<6F>e r<>cup<75>rer la ressource. Son second
|
|
|
|
|
|
param<61>tre est une variable pass<73>e par r<>f<EFBFBD>rence o<> le r<>sultat doit <20>tre
|
2004-05-23 15:50:53 +00:00
|
|
|
|
stock<63>. La fonction est suppos<6F>e retourner <literal>true</literal> si
|
2004-12-26 20:05:31 +00:00
|
|
|
|
elle r<>ussit <20> r<>cup<75>rer la ressource et <literal>false</literal> sinon.
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</para>
|
2004-04-13 11:47:32 +00:00
|
|
|
|
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<para>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
La seconde fonction est suppos<6F>e r<>cup<75>rer la date de derni<6E>re modification
|
|
|
|
|
|
de la ressource demand<6E>e (comme un timestamp UNIX). Le second param<61>tre
|
2004-05-23 15:50:53 +00:00
|
|
|
|
est une variable pass<73>e par r<>f<EFBFBD>rence dans laquelle la date doit
|
|
|
|
|
|
<20>tre stock<63>e. La fonction est suppos<6F>e renvoyer <literal>true</literal> si elle
|
2004-12-26 20:05:31 +00:00
|
|
|
|
r<>ussit <20> r<>cup<75>rer la date et <literal>false</literal> sinon.
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</para>
|
2004-04-13 11:47:32 +00:00
|
|
|
|
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<para>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
La troisi<73>me fonction est suppos<6F>e retourner <literal>true</literal>
|
|
|
|
|
|
ou <literal>false</literal> selon si la ressource demand<6E>e est s<>re
|
2004-05-23 15:50:53 +00:00
|
|
|
|
ou non. La fonction est utilis<69>e seulement pour les ressources templates
|
|
|
|
|
|
mais doit tout de m<>me <20>tre d<>finie.
|
|
|
|
|
|
</para>
|
2004-04-13 11:47:32 +00:00
|
|
|
|
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<para>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
La quatri<72>me fonction est suppos<6F>e retourner <literal>true</literal>
|
|
|
|
|
|
ou <literal>false</literal> selon si l'on peut faire confiance ou
|
|
|
|
|
|
non <20> la ressource demand<6E>e. Cette fonction est utilis<69>e seulement
|
2004-05-23 15:50:53 +00:00
|
|
|
|
pour les composants de scripts PHP demand<6E>s par les balises
|
|
|
|
|
|
<command>include_php</command> ou <command>insert</command>
|
|
|
|
|
|
ayant un attribut <structfield>src</structfield>. Quoiqu'il en soit,
|
|
|
|
|
|
elle doit <20>tre d<>finie pour les ressources templates.
|
|
|
|
|
|
</para>
|
2004-04-13 11:47:32 +00:00
|
|
|
|
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<para>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
Lisez <20>galement
|
|
|
|
|
|
<link linkend="api.register.resource">register_resource()</link> et
|
|
|
|
|
|
<link linkend="api.unregister.resource">unregister_resource()</link>.
|
|
|
|
|
|
</para>
|
|
|
|
|
|
<example>
|
|
|
|
|
|
<title>resource plugin</title>
|
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
|
<![CDATA[
|
|
|
|
|
|
<?php
|
2004-04-13 11:47:32 +00:00
|
|
|
|
/*
|
|
|
|
|
|
* Smarty plugin
|
|
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
|
|
* Fichier : resource.db.php
|
|
|
|
|
|
* Type : ressource
|
|
|
|
|
|
* Nom : db
|
|
|
|
|
|
* R<>le : R<>cup<75>re des templates depuis une base de donn<6E>es
|
|
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
|
|
*/
|
2004-12-26 20:05:31 +00:00
|
|
|
|
function smarty_resource_db_source($tpl_name, &$tpl_source, &$smarty)
|
2004-04-13 11:47:32 +00:00
|
|
|
|
{
|
|
|
|
|
|
// fait des requ<71>tes BD pour r<>cup<75>rer votre template
|
|
|
|
|
|
// et remplir $tpl_source
|
|
|
|
|
|
$sql = new SQL;
|
|
|
|
|
|
$sql->query("select tpl_source
|
|
|
|
|
|
from my_table
|
|
|
|
|
|
where tpl_name='$tpl_name'");
|
|
|
|
|
|
if ($sql->num_rows) {
|
|
|
|
|
|
$tpl_source = $sql->record['tpl_source'];
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-26 20:05:31 +00:00
|
|
|
|
function smarty_resource_db_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
|
2004-04-13 11:47:32 +00:00
|
|
|
|
{
|
|
|
|
|
|
// fait des requ<71>tes BD pour remplir $tpl_timestamp
|
|
|
|
|
|
$sql = new SQL;
|
|
|
|
|
|
$sql->query("select tpl_timestamp
|
|
|
|
|
|
from my_table
|
|
|
|
|
|
where tpl_name='$tpl_name'");
|
|
|
|
|
|
if ($sql->num_rows) {
|
|
|
|
|
|
$tpl_timestamp = $sql->record['tpl_timestamp'];
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-26 20:05:31 +00:00
|
|
|
|
function smarty_resource_db_secure($tpl_name, &$smarty)
|
2004-04-13 11:47:32 +00:00
|
|
|
|
{
|
|
|
|
|
|
// suppose que tous les templates sont svrs
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-26 20:05:31 +00:00
|
|
|
|
function smarty_resource_db_trusted($tpl_name, &$smarty)
|
2004-04-13 11:47:32 +00:00
|
|
|
|
{
|
|
|
|
|
|
// inutilis<69>e pour les templates
|
|
|
|
|
|
}
|
2004-12-26 20:05:31 +00:00
|
|
|
|
?>
|
|
|
|
|
|
]]>
|
|
|
|
|
|
</programlisting>
|
|
|
|
|
|
</example>
|
|
|
|
|
|
</sect1>
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
|
|
Local variables:
|
|
|
|
|
|
mode: sgml
|
|
|
|
|
|
sgml-omittag:t
|
|
|
|
|
|
sgml-shorttag:t
|
|
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
|
|
sgml-indent-step:1
|
|
|
|
|
|
sgml-indent-data:t
|
|
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
|
|
sgml-parent-document:nil
|
|
|
|
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
|
|
End:
|
|
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
|
|
-->
|