mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-08 16:21:39 +01:00
169 lines
6.3 KiB
XML
169 lines
6.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1.3 Maintainer: takagi Status: ready -->
|
|
<!-- CREDITS: mat-sh,daichi,joe -->
|
|
<sect1 id="plugins.resources"><title>リソースプラグイン</title>
|
|
<para>
|
|
リソースプラグインは、テンプレートソースやPHPスクリプトのコンポーネントを
|
|
Smarty に提供する一般的な方法と意図されています
|
|
(例: データベース, LDAP, 共有メモリ, ソケット等)。
|
|
</para>
|
|
|
|
<para>
|
|
各種リソースのために4つの関数を登録する必要があります。
|
|
これらの関数の最初のパラメータには要求されたリソースが渡され、
|
|
最後のパラメータには Smarty のオブジェクトが渡されます。
|
|
残りのパラメータは関数によって異なります。
|
|
</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>
|
|
|
|
<itemizedlist>
|
|
<listitem><para>
|
|
1つめの関数 <literal>source()</literal> ではリソースを取得します。
|
|
第2パラメータ <parameter>$source</parameter>
|
|
は参照で渡され、ここに結果が格納されます。
|
|
戻り値は、リソースの取得に成功すれば &true;、
|
|
それ以外は &false; となります。
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
2つめの関数 <literal>timestamp()</literal> は、
|
|
要求されたリソースが最後に修正された時間(UNIXタイムスタンプ)を取得します。
|
|
第2パラメータ <parameter>$timestamp</parameter> は参照で渡され、
|
|
ここにタイムスタンプが格納されます。タイムスタンプが取得できれば
|
|
&true;、それ以外は &false; を返します。
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
3つめの関数 <literal>secure()</literal> は、
|
|
要求されたリソースがセキュアであるかどうかに応じて &true; 又は &false; を返します。
|
|
この関数はテンプレートリソースのためにだけ用いられますが、定義する必要があります。
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
4つめの関数 <literal>trusted()</literal> は、
|
|
要求されたリソースが信用できるかどうかに応じて &true; 又は &false; を返します。
|
|
この関数を使用するのは、<link linkend="language.function.include.php">
|
|
<varname>{include_php}</varname></link> タグあるいは
|
|
<link linkend="language.function.insert"><varname>{insert}</varname></link>
|
|
タグで <parameter>src</parameter> 属性によって要求された PHP
|
|
スクリプトコンポーネントのみです。
|
|
しかし、テンプレートリソースであっても定義する必要があります。
|
|
</para></listitem>
|
|
</itemizedlist>
|
|
|
|
|
|
<example>
|
|
<title>リソースプラグイン</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/*
|
|
* Smarty plugin
|
|
* -------------------------------------------------------------
|
|
* File: resource.db.php
|
|
* Type: resource
|
|
* Name: db
|
|
* Purpose: データベースからテンプレートを取得する
|
|
* -------------------------------------------------------------
|
|
*/
|
|
function smarty_resource_db_source($tpl_name, &$tpl_source, &$smarty)
|
|
{
|
|
// ここでデータベースを呼び出し、
|
|
// $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)
|
|
{
|
|
// ここでデータベースを呼び出し、$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)
|
|
{
|
|
// 全てのテンプレートがセキュアであるとみなします
|
|
return true;
|
|
}
|
|
|
|
function smarty_resource_db_trusted($tpl_name, &$smarty)
|
|
{
|
|
// テンプレートでは使用しません
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<para>
|
|
<link linkend="api.register.resource"><varname>register_resource()</varname></link>
|
|
および
|
|
<link linkend="api.unregister.resource"><varname>unregister_resource()</varname></link>
|
|
も参照してください。
|
|
</para>
|
|
|
|
</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
|
|
-->
|