OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / s / jquery_header / include / container / s_jquery_headerWidgetContainer.php
1 <?php
2 /**
3  * index.php用コンテナクラス
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-2011 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: s_jquery_headerWidgetContainer.php 4559 2012-01-03 16:26:59Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17
18 class s_jquery_headerWidgetContainer extends BaseWidgetContainer
19 {
20         private $langId;                // 現在の言語
21         private $initScript;    // 初期化用スクリプト
22         private $autoBackButton;                // 自動的に戻るボタンを表示するかどうか
23         private $headPreMobileScript;   // jQueryMobileの前に読み込む必要のあるスクリプト
24         const DEFAULT_CONFIG_ID = 0;
25         const DEFAULT_TITLE = 'jQueryページ専用ヘッダ';                 // デフォルトのウィジェットタイトル
26         const INIT_SCRIPT_FILE = '/init.js';                                    // メニュー初期化ファイル
27         
28         /**
29          * コンストラクタ
30          */
31         function __construct()
32         {
33                 // 親クラスを呼び出す
34                 parent::__construct();
35         }
36         /**
37          * テンプレートファイルを設定
38          *
39          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
40          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
41          *
42          * @param RequestManager $request               HTTPリクエスト処理クラス
43          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
44          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
45          */
46         function _setTemplate($request, &$param)
47         {
48                 return 'index.tmpl.html';
49         }
50         /**
51          * テンプレートにデータ埋め込む
52          *
53          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
54          *
55          * @param RequestManager $request               HTTPリクエスト処理クラス
56          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
57          * @param                                                               なし
58          */
59         function _assign($request, &$param)
60         {
61                 $this->langId = $this->gEnv->getCurrentLanguage();
62                 
63                 // 定義ID取得
64                 $configId = $this->gEnv->getCurrentWidgetConfigId();
65                 if (empty($configId)) $configId = self::DEFAULT_CONFIG_ID;
66                 
67                 // パラメータオブジェクトを取得
68                 $targetObj = $this->getWidgetParamObjByConfigId($configId);
69                 if (!empty($targetObj)){                // 定義データが取得できたとき
70                         $name           = $targetObj->name;// 定義名
71                         $content        = $targetObj->content;          // タグ内容
72                         $this->autoBackButton = $targetObj->autoBackButton;             // 自動的に戻るボタンを表示するかどうか
73
74                         $act = $request->trimValueOf('act');
75                         if ($act == 'initscript'){                      // 初期化スクリプト取得のとき
76                                 // 初期化スクリプトを作成
77                                 $initTemplate = $this->getParsedTemplateData('init.tmpl.js', array($this, 'makeInitScript'));// 初期化スクリプト
78                                 
79                                 // 標準のテンプレート変換をキャンセルし、直接出力
80                                 $this->cancelParse();
81                                 $this->gPage->setOutputByHtml(false);   // HTML出力をキャンセル
82                                 echo $initTemplate;
83                         } else {
84                                 // タイトルを変換
85                                 $title = '';
86                                 $titleArray = $this->gPage->getHeadSubTitle();
87                                 if (count($titleArray) > 0){
88                                         $title = $titleArray[count($titleArray) -1]['title'];                   // 最後に追加されたタイトルを取得
89                                 }
90                                 // タイトルが設定されていないときはページ名を取得
91                                 if (empty($title)){
92                                         $line = $this->gPage->getPageInfo($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId());
93                                         if (!empty($line) && !empty($line['pn_name'])) $title = $line['pn_name'];
94                                 }
95                                 
96                                 $keyTag = M3_TAG_START . M3_TAG_MACRO_TITLE . M3_TAG_END;
97                                 $content = str_replace($keyTag, $this->convertToDispString($title), $content);
98                                 
99                                 // 初期化用スクリプトのURLを作成
100                                 $this->initScript = $this->getUrl($this->createCmdUrlToCurrentWidget('act=initscript'));
101 //                              $this->headPreMobileScript = $this->getParsedTemplateData('add_head.tmpl.js', array($this, 'makeAddScript'));   // jQueryMobileの前に読み込む必要のあるスクリプト
102
103                                 // 表示データ埋め込み
104                                 $this->tmpl->addVar("_widget", "content",       $content);
105                         }
106                 }
107         }
108         /**
109          * ウィジェットのタイトルを設定
110          *
111          * @param RequestManager $request               HTTPリクエスト処理クラス
112          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
113          * @return string                                               ウィジェットのタイトル名
114          */
115         function _setTitle($request, &$param)
116         {
117                 return self::DEFAULT_TITLE;
118         }
119         /**
120          * JavascriptファイルをHTMLヘッダ部に設定
121          *
122          * JavascriptファイルをHTMLのheadタグ内に追加出力する。
123          * _assign()よりも後に実行される。
124          *
125          * @param RequestManager $request               HTTPリクエスト処理クラス
126          * @param object         $param                 任意使用パラメータ。
127          * @return string                                               Javascriptファイル。出力しない場合は空文字列を設定。
128          */
129         function _addPreMobileScriptFileToHead($request, &$param)
130         {
131                 return $this->initScript;
132         }
133         /**
134          * テンプレートデータ作成処理コールバック
135          *
136          * @param object         $tmpl                  テンプレートオブジェクト
137          * @param                                                               なし
138          */
139         function makeInitScript($tmpl)
140         {
141                 $valueStr = 'false';
142                 if (!empty($this->autoBackButton)) $valueStr = 'true';          // 自動的に戻るボタンを表示するかどうか
143                 $tmpl->addVar("_tmpl", "auto_back_button",      $valueStr);
144         }
145         /**
146          * JavascriptをHTMLヘッダ部に設定
147          *
148          * CSSデータをHTMLのheadタグ内に追加出力する。
149          * _assign()よりも後に実行される。
150          *
151          * @param RequestManager $request               HTTPリクエスト処理クラス
152          * @param object         $param                 任意使用パラメータ。
153          * @return string                                               CSS文字列。出力しない場合は空文字列を設定。
154          */
155         function _addPreMobileScriptToHead($request, &$param)
156         {
157                 return $this->headPreMobileScript;
158         }
159         /**
160          * テンプレートデータ作成処理コールバック
161          *
162          * @param object         $tmpl                  テンプレートオブジェクト
163          * @param                                                               なし
164          */
165         function makeAddScript($tmpl)
166         {
167 /*              $valueStr = 'false';
168                 if (!empty($this->autoBackButton)) $valueStr = 'true';          // 自動的に戻るボタンを表示するかどうか
169                 $tmpl->addVar("_tmpl", "auto_back_button",      $valueStr);*/
170         }
171 }
172 ?>