mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-03 22:01:36 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			160 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			160 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
<?xml version="1.0" encoding="iso-8859-1"?>
 | 
						|
<!-- $Revision$ -->
 | 
						|
   <sect1 id="plugins.resources"><title>Risorse</title>
 | 
						|
    <para>
 | 
						|
     I plugin risorsa vanno considerati un modo generico di fornire sorgenti
 | 
						|
     di template o script PHP a Smarty. Alcuni esempi di risorse:
 | 
						|
     database, directory LDAP, memorie condivisse, socket, e così via.
 | 
						|
    </para>
 | 
						|
 | 
						|
    <para>
 | 
						|
     Per ogni tipo di risorsa deve essere registrato un totale di 4 funzioni.
 | 
						|
     Ogni funzione riceverà la risorsa richiesta come primo parametro e l'oggetto
 | 
						|
     Smarty come ultimo parametro. Il resto dei parametri dipende dalla
 | 
						|
     funzione.
 | 
						|
    </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>
 | 
						|
 | 
						|
    <para>
 | 
						|
     Lo scopo della prima funzione è di recuperare la risorsa. Il suo
 | 
						|
     secondo parametro è una variabile passata per riferimento nella
 | 
						|
     quale memorizzare il risultato. Ci si aspetta che la funzione
 | 
						|
     restituisca <literal>true</literal> se è riuscita a recuperare
 | 
						|
     la risorsa e <literal>false</literal> nel caso opposto.
 | 
						|
    </para>
 | 
						|
 | 
						|
    <para>
 | 
						|
     Lo scopo della seconda funzione è di indicare il momento dell'ultima
 | 
						|
     modifica effettuata sulla risorsa richiesta (nel formato timestamp
 | 
						|
     UNIX). Il secondo parametro è una variabile passata per riferimento
 | 
						|
     nella quale memorizzare il timestamp. Ci si aspetta che la funzione
 | 
						|
     restituisca <literal>true</literal> se è riuscita a determinare il
 | 
						|
     timestamp, e <literal>false</literal> nel caso opposto.
 | 
						|
    </para>
 | 
						|
 | 
						|
    <para>
 | 
						|
     La terza funzione deve restituire <literal>true</literal> o
 | 
						|
     <literal>false</literal>, a seconda che la risorsa richiesta sia
 | 
						|
     sicura o no. Questa funzione è usata solo per risorse di template ma
 | 
						|
     deve ancora essere definita.
 | 
						|
    </para>
 | 
						|
 | 
						|
    <para>
 | 
						|
     La quarta funzione deve restituire <literal>true</literal> o
 | 
						|
     <literal>false</literal>, a seconda che la risorsa richiesta sia
 | 
						|
     considerata affidabile o no. Questa funzione è usata solo per script
 | 
						|
     PHP richiesti con i tag <command>include_php</command> o
 | 
						|
     <command>insert</command> con l'attributo <structfield>src</structfield>.
 | 
						|
     Comunque, deve ancora essere definita per le risorse di template.
 | 
						|
    </para>
 | 
						|
    <para>
 | 
						|
     Vedere anche
 | 
						|
     <link linkend="api.register.resource">register_resource()</link>,
 | 
						|
     <link linkend="api.unregister.resource">unregister_resource()</link>.
 | 
						|
    </para>
 | 
						|
    <example>
 | 
						|
     <title>plugin risorsa</title>
 | 
						|
     <programlisting role="php">
 | 
						|
<![CDATA[
 | 
						|
<?php
 | 
						|
/*
 | 
						|
 * Smarty plugin
 | 
						|
 * ------------------------------------------------------------- 
 | 
						|
 * File:     resource.db.php
 | 
						|
 * Type:     resource
 | 
						|
 * Name:     db
 | 
						|
 * Purpose:  Fetches templates from a database
 | 
						|
 * -------------------------------------------------------------
 | 
						|
 */
 | 
						|
function smarty_resource_db_source($tpl_name, &$tpl_source, &$smarty)
 | 
						|
{
 | 
						|
    // fate qui le chiamate al db per ottenere il template
 | 
						|
    // e popolare $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;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
function smarty_resource_db_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
 | 
						|
{
 | 
						|
    // fate qui la chiamata al db per popolare $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;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
function smarty_resource_db_secure($tpl_name, &$smarty)
 | 
						|
{
 | 
						|
    // diciamo che tutti i template sono sicuri
 | 
						|
    return true;
 | 
						|
}
 | 
						|
 | 
						|
function smarty_resource_db_trusted($tpl_name, &$smarty)
 | 
						|
{
 | 
						|
    // non si usa per i template
 | 
						|
}
 | 
						|
?>
 | 
						|
]]>
 | 
						|
     </programlisting>
 | 
						|
    </example>
 | 
						|
   </sect1>
 | 
						|
 | 
						|
<!-- 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
 | 
						|
-->
 |