mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 06:11:37 +01:00 
			
		
		
		
	
		
			
	
	
		
			163 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			163 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| 
								 | 
							
								<?xml version="1.0" encoding="iso-8859-1"?>
							 | 
						|||
| 
								 | 
							
								<!-- $Revision$ -->
							 | 
						|||
| 
								 | 
							
								   <sect1 id="plugins.resources"><title>Fuentes</title>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Las fuentes de los plugins son como una forma generica de suministrar
							 | 
						|||
| 
								 | 
							
								     c<>digo fuente de template o componentes de script PHP al Smarty. 
							 | 
						|||
| 
								 | 
							
								     Algunos ejemplos de fuentes: base de datos, LDAP, memoria compartida, 
							 | 
						|||
| 
								 | 
							
								     sockets, etc.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Existe un total de 4 funciones que necesitan estar registradas para 
							 | 
						|||
| 
								 | 
							
								     cada tipo de fuente. Cada funci<63>n recibir<69> el fuente requerido como 
							 | 
						|||
| 
								 | 
							
								     primer par<61>metro y el objeto de Smarty como ultimo par<61>metro.
							 | 
						|||
| 
								 | 
							
								     El resto de los par<61>metros dependen de la funci<63>n.
							 | 
						|||
| 
								 | 
							
								    </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>
							 | 
						|||
| 
								 | 
							
								     La primera funci<63>n debe devolver el recurso.
							 | 
						|||
| 
								 | 
							
								     Su segundo par<61>metro es una variable pasada por referencia donde
							 | 
						|||
| 
								 | 
							
								     el resultado debe ser almacenado.
							 | 
						|||
| 
								 | 
							
								     La funci<63>n debe retornar <literal>true</literal> si esta pudo 
							 | 
						|||
| 
								 | 
							
								     recuperar satisfactoriamente el recurso y en caso contrario
							 | 
						|||
| 
								 | 
							
								     retornara  <literal>false</literal>.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     La segunda funci<63>n debe devolver la ultima modificaci<63>n del
							 | 
						|||
| 
								 | 
							
								     recurso requerido (como un timestamp Unix). El segundo par<61>metro 
							 | 
						|||
| 
								 | 
							
								     es una variable pasada por referencia donde el timestamp sera
							 | 
						|||
| 
								 | 
							
								     almacenado. La funci<63>n debe retornar  <literal>true</literal>
							 | 
						|||
| 
								 | 
							
								     si el timestamp pudo ser determinado satisfactoriamente, y en 
							 | 
						|||
| 
								 | 
							
								     caso contrario retornara <literal>false</literal>.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     La tercera funci<63>n debe retornar <literal>true</literal> o
							 | 
						|||
| 
								 | 
							
								     <literal>false</literal>, dependiendo si el recurso requerido
							 | 
						|||
| 
								 | 
							
								     es seguro o no. Esta funci<63>n es usada solo para recursos de 
							 | 
						|||
| 
								 | 
							
								     template pero esta debe ser definida.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     La cuarta funci<63>n debe retornar <literal>true</literal> o
							 | 
						|||
| 
								 | 
							
								     <literal>false</literal>, dependiendo si el recurso requerido 
							 | 
						|||
| 
								 | 
							
								     es seguro o no. Esta funci<63>n es usada solo para componetes de 
							 | 
						|||
| 
								 | 
							
								     script de PHP solicitado por las etiquetas 
							 | 
						|||
| 
								 | 
							
								     <command>include_php</command> o <command>insert</command>
							 | 
						|||
| 
								 | 
							
								     con el atributo <structfield>src</structfield>. Sin embargo, 
							 | 
						|||
| 
								 | 
							
								     este debe ser definido para los recurso del template.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								     Vea tambi<62>n
							 | 
						|||
| 
								 | 
							
								     <link linkend="api.register.resource">register_resource()</link>,
							 | 
						|||
| 
								 | 
							
								     <link linkend="api.unregister.resource">unregister_resource()</link>.
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								    <example>
							 | 
						|||
| 
								 | 
							
								     <title>Plugin resource (recurso)</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)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    // do database call here to fetch your template,
							 | 
						|||
| 
								 | 
							
								    // populating $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)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    // do database call here to populate $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)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    // assume all templates are secure
							 | 
						|||
| 
								 | 
							
								    return true;
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								function smarty_resource_db_trusted($tpl_name, &$smarty)
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    // not used for templates
							 | 
						|||
| 
								 | 
							
								}
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								     </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
							 | 
						|||
| 
								 | 
							
								-->
							 |