| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  | <?xml version="1.0" encoding="iso-8859-1"?> | 
					
						
							|  |  |  | <!-- $Revision$ --> | 
					
						
							| 
									
										
										
										
											2004-07-16 14:32:31 +00:00
										 |  |  | <!-- EN-Revision: 1.2 Maintainer: andreas Status: ready --> | 
					
						
							| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  |   <sect1 id="plugins.resources"><title>Ressourcen</title> | 
					
						
							|  |  |  |    <para> | 
					
						
							|  |  |  |     Ressourcen-Plugins stellen einen generischen Weg dar, um Smarty mit | 
					
						
							|  |  |  |     Template-Quellen oder PHP-Skripten zu versorgen. Einige Beispiele von Ressourcen: | 
					
						
							|  |  |  |     Datenbanken, LDAP, shared Memory, Sockets, usw. | 
					
						
							|  |  |  |    </para> | 
					
						
							|  |  |  |     | 
					
						
							|  |  |  |    <para> | 
					
						
							|  |  |  |     Für jeden Ressource-Typ müssen 4 Funktionen registriert werden. Jede dieser | 
					
						
							|  |  |  |     Funktionen erhält die verlangte Ressource als ersten Parameter und das Smarty Objekt | 
					
						
							|  |  |  |     als letzten. Die restlichen Parameter hängen von der Funktion ab. | 
					
						
							|  |  |  |    </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> | 
					
						
							|  |  |  |     Die erste Funktion wird verwendet, um die Ressource zu laden. Der | 
					
						
							|  |  |  |     zweite Parameter ist eine Variable, die via Referenz übergeben | 
					
						
							|  |  |  |     wird und in der das Resultat gespeichert werden soll. Die Funktion | 
					
						
							|  |  |  |     gibt <literal>true</literal> zurück, wenn der Ladevorgang erfolgreich war -  | 
					
						
							|  |  |  |     andernfalls <literal>false</literal>. | 
					
						
							|  |  |  |    </para> | 
					
						
							|  |  |  |     | 
					
						
							|  |  |  |    <para> | 
					
						
							|  |  |  |     Die zweite Funktion fragt das letzte Änderungsdatum der angeforderten | 
					
						
							|  |  |  |     Ressource (als Unix-Timestamp) ab. Der zweite Parameter ist die Variable, | 
					
						
							|  |  |  |     welche via Referenz übergeben wird und in der das Resultat gespeichert werden soll. | 
					
						
							|  |  |  |     Gibt <literal>true</literal> zurück, wenn das Änderungsdatum ermittelt | 
					
						
							|  |  |  |     werden konnte und <literal>false</literal> wenn nicht. | 
					
						
							|  |  |  |    </para> | 
					
						
							|  |  |  |     | 
					
						
							|  |  |  |    <para> | 
					
						
							|  |  |  |     Die dritte Funktion gibt <literal>true</literal> oder <literal>false</literal> | 
					
						
							|  |  |  |     zurück, je nachdem ob die angeforderte Ressource als sicher bezeichnet wird | 
					
						
							|  |  |  |     oder nicht. Diese Funktion wird nur für Template-Ressourcen verwendet, | 
					
						
							|  |  |  |     sollte aber in jedem Fall definiert werden. | 
					
						
							|  |  |  |    </para> | 
					
						
							|  |  |  |     | 
					
						
							|  |  |  |    <para> | 
					
						
							|  |  |  |     Die vierte Funktion gibt <literal>true</literal> oder <literal>false</literal> | 
					
						
							|  |  |  |     zurück, je nachdem ob die angeforderte Ressource als vertrauenswürdig angesehen wird | 
					
						
							|  |  |  |     oder nicht. Diese Funktion wird nur verwendet, wenn PHP-Skripte via <command>include_php</command> | 
					
						
							|  |  |  |     oder <command>insert</command> eingebunden werden sollen und ein 'src' Attribut übergeben wurde. | 
					
						
							|  |  |  |     Die Funktion sollte aber in jedem Fall definiert werden. | 
					
						
							|  |  |  |    </para> | 
					
						
							|  |  |  |    <para> | 
					
						
							|  |  |  |     Sehen Sie dazu: | 
					
						
							|  |  |  |     <link linkend="api.register.resource">register_resource()</link>, | 
					
						
							|  |  |  |      <link linkend="api.unregister.resource">unregister_resource()</link>. | 
					
						
							|  |  |  |    </para> | 
					
						
							|  |  |  |    <example> | 
					
						
							|  |  |  |     <title>Ressourcen Plugin</title> | 
					
						
							|  |  |  |     <programlisting> | 
					
						
							| 
									
										
										
										
											2004-07-16 14:32:31 +00:00
										 |  |  | <![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> | 
					
						
							| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  |    </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 | 
					
						
							| 
									
										
										
										
											2004-07-16 14:32:31 +00:00
										 |  |  | --> |