Source for file Smarty4Maple.php

Documentation is available at Smarty4Maple.php

  1. <?php
  2. /**
  3.  * Teeple2 - PHP5 Web Application Framework inspired by Seasar2
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @package     teeple
  14.  * @author      Mitsutaka Sato <miztaka@gmail.com>
  15.  * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
  16.  */
  17.  
  18. require_once SMARTY_DIR ."Smarty.class.php";
  19.  
  20. /**
  21.  * Smartyクラスを拡張して使用する
  22.  *
  23.  * @package     teeple
  24.  */
  25. class Teeple_Smarty4Maple extends Smarty
  26. {
  27.     /**
  28.      * コンストラクター
  29.      * Smarty4MapleクラスはSingletonとして使うので直接newしてはいけない
  30.      *
  31.      */
  32.     protected function __construct()
  33.     {
  34.         $this->Smarty();
  35.  
  36.         $constants array(
  37.             'VIEW_TEMPLATE_DIR'     => 'template_dir',
  38.             'VIEW_COMPILE_DIR'      => 'compile_dir',
  39.             'VIEW_CONFIG_DIR'       => 'config_dir',
  40.             'VIEW_CACHE_DIR'        => 'cache_dir',
  41.             
  42.             'SMARTY_TEMPLATE_DIR'   => 'template_dir',
  43.             'SMARTY_COMPILE_DIR'    => 'compile_dir',
  44.             'SMARTY_CONFIG_DIR'     => 'config_dir',
  45.             'SMARTY_CACHE_DIR'      => 'cache_dir',
  46.             
  47.             'SMARTY_CACHING'        => 'caching',
  48.             'SMARTY_CACHE_LIFETIME' => 'cache_lifetime',
  49.             'SMARTY_COMPILE_CHECK'  => 'compile_check',
  50.             'SMARTY_FORCE_COMPILE'  => 'force_compile',
  51.         
  52.             'SMARTY_LEFT_DELIMITER' => 'left_delimiter',
  53.             'SMARTY_RIGHT_DELIMITER' => 'right_delimiter'
  54.             );
  55.         
  56.         foreach($constants as $constName => $attr{
  57.             if(defined($constName)) {
  58.                 $this->$attr constant($constName);
  59.             }
  60.         }
  61.         
  62.         if(defined('SMARTY_DEFAULT_MODIFIERS')) {
  63.             $this->default_modifiers array(SMARTY_DEFAULT_MODIFIERS);
  64.         }
  65.         
  66.         if (defined('SMARTY_PULGINS_DIR')) {
  67.             array_push($this->plugins_dirSMARTY_PULGINS_DIR);
  68.         }
  69.  
  70.         $this->_registerFilters();
  71.     }
  72.  
  73.     /**
  74.      * Smarty4Mapleクラスの唯一のインスタンスを返却
  75.      *
  76.      * @return  Teeple_Smarty4Maple 
  77.      */
  78.     public function getInstance({
  79.  
  80.         static $instance;
  81.         if ($instance === NULL{
  82.             $instance new Teeple_Smarty4Maple();
  83.         }
  84.         return $instance;
  85.     }
  86.  
  87.     /**
  88.      * 唯一のインスタンスに対して設定を行う
  89.      * 
  90.      * @static
  91.      * @param  array    $opts 
  92.      */
  93.     public static function setOptions($opts{
  94.  
  95.         $instance Teeple_Smarty4Maple::getInstance();
  96.  
  97.         foreach($opts as $attr => $value{
  98.             if(array_key_exists($attr$instance)) {
  99.                 $instance->$attr $value;
  100.             }
  101.         }
  102.     }
  103.  
  104.     /**
  105.      * filterを登録する
  106.      */
  107.     private function _registerFilters({
  108.  
  109.         if (TEMPLATE_CODE != INTERNAL_CODE{
  110.             // プリフィルタを登録
  111.             $this->register_prefilter('smarty4maple_prefilter');
  112.         }
  113.         if (OUTPUT_CODE != INTERNAL_CODE{
  114.             // アウトプットフィルタを登録
  115.             $this->register_outputfilter('smarty4maple_outputfilter');
  116.         }
  117.     }
  118.  
  119.     /**
  120.      * コンパイルディレクトリの中身を全て破棄する
  121.      *
  122.      */
  123.     public function clearTemplates_c({
  124.  
  125.         $result $this->clear_compiled_tpl();
  126.  
  127.         if ($result{
  128.             echo "Clear";
  129.         else {
  130.             echo "NG";
  131.         }
  132.  
  133.         return true;
  134.     }
  135.  
  136.     /**
  137.      * テンプレートのキャッシュを破棄する
  138.      *
  139.      * @param   string  $tpl    テンプレート名
  140.      */
  141.     function clearCache($tpl ""{
  142.  
  143.         $result $this->clear_cache($tpl);
  144.  
  145.         if ($result{
  146.             echo "Cache Clear";
  147.         else {
  148.             echo "NG";
  149.         }
  150.  
  151.         return true;
  152.     }
  153.  
  154.     /**
  155.      * Actionをセットする
  156.      *
  157.      * @param   Teeple_ActionBase  $action Actionのインスタンス
  158.      */
  159.     public function setAction($action{
  160.         $this->assign('a'$action);
  161.     }
  162.  
  163.     /**
  164.      * Tokenをセットする
  165.      *
  166.      * @param   Teeple_Token $token  Tokenのインスタンス
  167.      */
  168.     public function setToken($token{
  169.  
  170.         $this->register_object("token"$token);
  171.         $this->assign('token'array(
  172.             'name'  => $token->getName(),
  173.             'value' => $token->getValue(),
  174.         ));
  175.     }
  176.  
  177.     /**
  178.      * Sessionをセットする
  179.      *
  180.      * @param   Teeple_Session  $session    Sessionのインスタンス
  181.      */
  182.     public function setSession($session{
  183.         $this->assign('s'$session);
  184.     }
  185.  
  186.     /**
  187.      * Requestをセットする
  188.      *
  189.      * @param   Teeple_Request  $request    Requestのインスタンス
  190.      */
  191.     public function setRequest($request{
  192.         $this->assign('r'$request);
  193.     }
  194.     
  195.     /**
  196.      * ScriptNameをセットする
  197.      *
  198.      * @param   string  $scriptName ScriptName
  199.      */
  200.     function setScriptName($scriptName{
  201.         $scriptName htmlspecialchars($scriptNameENT_QUOTES);
  202.         $this->assign('scriptName'$scriptName);
  203.     }
  204. }
  205.  
  206. /**
  207.  * プリフィルタ
  208.  */
  209. function smarty4maple_prefilter($source&$Smarty)
  210. {
  211.     return mb_convert_encoding($sourceINTERNAL_CODETEMPLATE_CODE);
  212. }
  213.  
  214. /**
  215.  * ポストフィルタ
  216.  */
  217. function smarty4maple_postfilter($source&$Smarty)
  218. {
  219.     return mb_convert_encoding($sourceOUTPUT_CODEINTERNAL_CODE);
  220. }
  221.  
  222. /**
  223.  * アウトプットフィルタ
  224.  */
  225. function smarty4maple_outputfilter($source&$Smarty)
  226. {
  227.     return mb_convert_encoding($sourceOUTPUT_CODEINTERNAL_CODE);
  228. }
  229. ?>

Documentation generated on Mon, 26 Apr 2010 08:59:58 +0900 by phpDocumentor 1.4.3