mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-02 13:21:36 +01:00
156 lines
5.5 KiB
XML
156 lines
5.5 KiB
XML
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|||
|
|
<!-- $Revision$ -->
|
|||
|
|
<sect1 id="plugins.resources"><title>Recursos (Resources)</title>
|
|||
|
|
<para>
|
|||
|
|
Os plugins de Recursos s<>o como uma forma gen<65>rica de fornecer c<>digos fontes de template
|
|||
|
|
ou componentes de script PHP para a Smarty. Alguns exemplos de recursos:
|
|||
|
|
banco de dados, LDAP, mem<65>ria compartilhada, sockets, e assim por diante.
|
|||
|
|
</para>
|
|||
|
|
|
|||
|
|
<para>
|
|||
|
|
H<> um total de 4 fun<75><6E>es que precisam estar registradas
|
|||
|
|
para cada tipo de recurso. Cada fun<75><6E>o receber<65>
|
|||
|
|
o recurso requisitado como o primeiro par<61>metro e o objeto da Smarty como o <20>ltimo par<61>metro. O resto
|
|||
|
|
dos par<61>metros dependem da fun<75><6E>o.
|
|||
|
|
</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>
|
|||
|
|
A primeira fun<75><6E>o deve devolver o recurso. Seu segundo par<61>metro <20> uma vari<72>vel passada por
|
|||
|
|
refer<65>ncia onde o resultado seria armazenado.
|
|||
|
|
A fun<75><6E>o deve retornar <literal>true</literal> se
|
|||
|
|
ela est<73> apta a devolver com sucesso o recurso e
|
|||
|
|
caso contr<74>rio retorna <literal>false</literal>.
|
|||
|
|
</para>
|
|||
|
|
|
|||
|
|
<para>
|
|||
|
|
A segunda fun<75><6E>o deve devolver a <20>ltima modifica<63><61>o do
|
|||
|
|
recurso requisitado (como um timestamp Unix).
|
|||
|
|
O segundo par<61>metro <20> uma vari<72>vel passada por refer<65>ncia onde o timestamp seria armazenado.
|
|||
|
|
A fun<75><6E>o deve retornar <literal>true</literal>
|
|||
|
|
se o timestamp poderia ser determinado com sucesso,
|
|||
|
|
e caso contr<74>rio retornaria <literal>false</literal>.
|
|||
|
|
</para>
|
|||
|
|
|
|||
|
|
<para>
|
|||
|
|
A terceira fun<75><6E>o deve retornar <literal>true</literal> ou
|
|||
|
|
<literal>false</literal>, dependendo do recurso requisitado
|
|||
|
|
est<73> seguro ou n<>o. Esta fun<75><6E>o <20> usada
|
|||
|
|
apenas para recursos de template mas ainda assim seria definida.
|
|||
|
|
</para>
|
|||
|
|
|
|||
|
|
<para>
|
|||
|
|
A quarta fun<75><6E>o deve retornar <literal>true</literal>
|
|||
|
|
ou <literal>false</literal>, dependendo
|
|||
|
|
do recurso requisitado ser confi<66>vel ou n<>o.
|
|||
|
|
Esta fun<75><6E>o <20> usada apenas para componentes de
|
|||
|
|
script PHP requisitados pelas tags <command>include_php</command> ou
|
|||
|
|
<command>insert</command> com o atributo <structfield>src</structfield>.
|
|||
|
|
Entretanto, ela ainda assim mesmo seria definida para os recursos de template.
|
|||
|
|
</para>
|
|||
|
|
<para>
|
|||
|
|
Veja tamb<6D>m:
|
|||
|
|
<link linkend="api.register.resource">register_resource()</link>,
|
|||
|
|
<link linkend="api.unregister.resource">unregister_resource()</link>.
|
|||
|
|
</para>
|
|||
|
|
<example>
|
|||
|
|
<title>Plugin resource (recurso)</title>
|
|||
|
|
<programlisting>
|
|||
|
|
<?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)
|
|||
|
|
{
|
|||
|
|
// faz o banco de dados chamar aqui para preencher $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 que todos os templates s<>o seguros
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function smarty_resource_db_trusted($tpl_name, &$smarty)
|
|||
|
|
{
|
|||
|
|
// n<>o usado para 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
|
|||
|
|
-->
|