Smartyを使った絵文字の出力です。
Smartyの基本的なことについてはこちらを参照ください。
有る程度触ったことのある人を対象としています。(register_outputfilterを使用)
以下ファイルを作成します。
filter.php
<?php
require_once(dirname(__FILE__) . "/MySmarty.class.php");
$smarty =& new MySmarty;
$smarty->display("filter.tpl");
?>
MySmarty.class.php
<?php
define("ROOT_DIR", dirname(__FILE__) . "/Smarty-2.6.18");
require_once(ROOT_DIR . "/libs/Smarty.class.php");
require_once(dirname(__FILE__) . "/Emo-x.x.x/libs/Emo.php");
class MySmarty extends Smarty
{
function MySmarty()
{
function EmoOutputFilter($tpl_output, &$this)
{
$Emo =& new Emo;
$tpl_output = $Emo->decode($tpl_output);
return $tpl_output;
}
$this->left_delimiter = '{{';
$this->right_delimiter = '}}';
$this->register_outputfilter("EmoOutputFilter");
$this->Smarty();
}
}
?>
templates/filter.tpl
晴れ[[d-E63E]],冷や汗[[d-E722]],i-mode[[d-E6D1]],
男の子[[s-E001]],泣いたり笑ったり[[s-E412]],トイレ[[s-E309]],
![[e-E481]],晴れ時々曇り[[e-E48E]],受信BOX[[e-E593]],
以上のようにSmartyを継承したクラスを使っている場合は赤字の部分のみ追加で対応できます。
処理の流れはfilter.phpを実行し、
Smartyを継承したMySmartyの出力部分にEmoを噛ませ、
filter.tplを置換し出力します。