OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / include / container / baseTemplateContainer.php
1 <?php
2 /**
3  * テンプレートコンテナ作成用ベースクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
9  * @package    Magic3 Framework
10  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11  * @copyright  Copyright 2006-2009 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: baseTemplateContainer.php 1653 2009-03-27 05:24:28Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 // テンプレートライブラリ読み込み
17 require_once($gEnvManager->getLibPath() . '/patTemplate/patTemplate.php');
18 require_once($gEnvManager->getLibPath() . '/patTemplate/patError.php');
19 require_once($gEnvManager->getLibPath() . '/patTemplate/patErrorManager.php');
20
21 class BaseTemplateContainer
22 {
23         protected $tmpl;                // テンプレートオブジェクト
24         private $errorMessage    = array();             // アプリケーションのエラー
25         private $warningMessage  = array();             // ユーザ操作の誤り
26         private $guidanceMessage = array();             // ガイダンス
27         
28         /**
29          * コンストラクタ
30          */
31         function __construct()
32         {
33                 // 親クラスを呼び出す
34                 parent::__construct();
35         }
36
37         /**
38          * 起動マネージャから呼ばれる唯一のメソッド
39          *
40          * @param RequestManager $request               HTTPリクエスト処理クラス
41          */
42         function process($request)
43         {
44                 // サブクラスの前処理を実行
45                 $this->_preBuffer($request);
46                 
47                 if (method_exists($this, '_setTemplate')){
48                         $templateFile = $this->_setTemplate();
49                         
50                         // テンプレートファイル名が空文字列のときは、テンプレートライブラリを使用しない
51                         if ($templateFile != ''){
52                                 // 値を取得
53                                 //$mode = self::valueOf('_mode');
54                                 $mode = $request->valueOf('_mode');
55                                                 
56                                 // テンプレートオブジェクト作成
57                                 self::__setTemplate();
58                                 
59                                 // テンプレートファイルを設定
60                                 $this->tmpl->readTemplatesFromFile($templateFile);
61
62                                 // エラーメッセージ組み込み
63                                 self::__assign();
64
65                                 // 各ウィジェットごとののテンプレート処理
66                                 if (method_exists($this, '_assign')) $this->_assign($mode);
67
68                                 // エラーメッセージ出力
69                                 //self::displayMsg();
70         
71                                 // HTML生成
72                                 self::__parse();
73                         }
74                 } else {        // メソッドが存在しないときはエラーメッセージを出力
75                         echo 'method not found: BaseTemplateContainer::_setTemplate()';
76                 }
77
78                 // サブクラスの後処理の呼び出し
79                 $this->_postBuffer($request);
80         }
81
82         /**
83          * テンプレートの設定
84          */
85         private function __setTemplate()
86         {
87                 // テンプレートオブジェクト作成
88                 $this->tmpl = new PatTemplate();
89  
90                 // テンプレート読み込みディレクトリ
91                 global $gEnvManager;
92                 $this->tmpl->setRoot($gEnvManager->getTemplatesPath());
93                 
94                 // エラーメッセージテンプレートを埋め込む
95                 $this->tmpl->applyInputFilter('ErrorMessage');
96                 
97                 // 機能付きタグを変換
98                 //$this->tmpl->applyInputFilter('FunctionTag');
99                 
100                 // コメントを削除
101                 //$this->tmpl->applyInputFilter('StripComments');
102                 
103                 // テンプレートファイルを設定
104                 //$this->tmpl->readTemplatesFromFile($filename);
105         }
106         
107         /**
108          * 出力用の変数に値を設定する
109          *
110          * このクラスでは、共通項目を設定
111          */
112         private function __assign()
113         {
114                 // テンプレートに値を設定
115                 $now = date("Y/m/d H:i:s");
116                 $this->tmpl->addVar("_page", "DATE", "created $now");
117                 
118                 // リソース読み込みディレクトリを設定
119                 //$this->tmpl->addVar("_page", "RES", M3_SYSTEM_RES_DIR);
120                 //$this->tmpl->addVar("_page_body", "RES", M3_SYSTEM_RES_DIR);
121                 
122                 // post名を設定
123                 //$this->tmpl->addVar("_page", "POST_NAME", M3_COMPONENT_POST_NAME);
124                 //$this->tmpl->addVar("_page_body", "POST_NAME", M3_COMPONENT_POST_NAME);
125         }
126
127         /**
128          * 出力データ作成
129          */
130         private function __parse()
131         {
132                 echo $this->tmpl->getParsedTemplate('_page');
133         }
134 }
135 ?>