OSDN Git Service

WordPressテンプレート機能更新。
[magic3/magic3.git] / include / container / baseFrameContainer.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-2017 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id$
14  * @link       http://www.magic3.org
15  */
16 require_once(M3_SYSTEM_INCLUDE_PATH . '/db/systemDb.php');              // システムDBアクセスクラス
17 require_once(M3_SYSTEM_INCLUDE_PATH . '/common/core.php');
18
19 class BaseFrameContainer extends Core
20 {
21         protected $_db; // DB接続オブジェクト
22         private $joomlaBufArray = array();                      // Joomla!データ受け渡し用
23         const SYSTEM_TEMPLATE = '_system';              // システム画面用テンプレート
24         const M_ADMIN_TEMPLATE = 'm/_admin';    // 携帯用管理画面テンプレート
25         const ERR_MESSAGE_ACCESS_DENY = 'Access denied.';               // ウィジェットアクセスエラーのメッセージ
26         const SITE_ACCESS_EXCEPTION_IP = 'site_access_exception_ip';            // アクセス制御、例外とするIP
27         const CONFIG_KEY_MSG_TEMPLATE = 'msg_template';                 // メッセージ用テンプレート取得キー
28 //      const CF_MOBILE_AUTO_REDIRECT = 'mobile_auto_redirect';         // 携帯の自動遷移
29         const TEMPLATE_GENERATOR_THEMLER = 'themler';                   // テンプレート作成アプリケーション(Themler)
30                 
31         /**
32          * コンストラクタ
33          */
34         function __construct()
35         {
36                 // 親クラスを呼び出す
37                 parent::__construct();
38                 
39                 // DBオブジェクト取得
40                 $this->_db = $this->gInstance->getSytemDbObject();
41         }
42         /**
43          * 起動マネージャから呼ばれる唯一のメソッド
44          *
45          * @param RequestManager $request               HTTPリクエスト処理クラス
46          */
47         function process($request)
48         {
49                 // パラメータを取得
50                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);               // 実行コマンドを取得
51                                 
52                 // インストール画面への制御は、install.phpファイルの作成、削除で制御する
53                 // 最小限の設定が行われていない場合,DBに接続できない場合は、インストール画面へ
54                 if (!defined('M3_STATE_IN_INSTALL')){
55                         if (($this->gEnv->canUseDb() && $this->gSystem->canInitSystem()) ||             // システム初期化モードのとき
56                                 !$this->gConfig->isConfigured()){                                                                       // 設定ファイルに設定がないとき(初回インストール)
57                                 
58                                 // 旧システムがある場合はadminディレクトリまでアクセスしてインストーラを実行。
59                                 $isRedirect = false;
60                                 if ($this->_isExistsOldSystemDir()){
61                                         if ($this->gEnv->isAdminDirAccess()) $isRedirect = true;
62                                 } else {
63                                         $isRedirect = true;
64                                 }
65                                 
66                                 if ($isRedirect){
67                                         // インストーラファイルがない場合は回復
68                                         $this->gInstance->getFileManager()->recoverInstaller();
69
70                                         $this->gPage->redirectToInstall();
71                                 } else {
72                                         // サイト非公開(システムメンテナンス)表示
73                                         $this->gPage->showError(503);
74                                 }
75                                 return;
76                         } else if ($this->gConfig->isConfigured() && !$this->gEnv->canUseDb()){         // DB接続失敗のとき
77                                 if ($this->gEnv->isAdminDirAccess()){           // 管理画面の場合のみインストーラ起動
78                                         // インストーラファイルがない場合は回復
79                                         $this->gInstance->getFileManager()->recoverInstaller();
80
81                                         $this->gPage->redirectToInstall();
82                                 } else {
83                                         // サーバ内部エラーメッセージ表示
84                                         $this->gPage->showError(500);
85                                 }
86                                 return;
87                         }
88                 }
89                 
90                 // 開始ログ出力
91                 //$this->gLog->info(__METHOD__, 'フレーム作成開始');
92
93                 // ページ作成開始
94                 // セッション変数読み込み。サブページIDの設定。
95                 $this->gPage->startPage($request);
96                 
97                 // パラメータ取得
98                 $isSystemAdmin = $this->gEnv->isSystemAdmin();          // 管理者権限があるかどうか
99                 $isSystemManageUser = $this->gEnv->isSystemManageUser();                // システム運用可能かどうか
100                         
101                 if (!defined('M3_STATE_IN_INSTALL')){           // インストールモード以外のとき
102                         // ############## ユーザごとの設定の読み込み ###################
103                         // 引数での言語設定取得、言語変更可能な場合は変更
104                         // 言語の優先順は、URLの言語設定、クッキーの言語設定の順
105                         if (!$this->gEnv->isAdminDirAccess()){          // 管理画面以外の場合
106                                 if ($this->gEnv->getCanChangeLang() && $this->gEnv->isMultiLanguageSite()){     // 言語変更可能で多言語対応サイトのとき
107                                         $lang = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_LANG);
108                                         if (empty($lang)){
109                                                 // 空の場合はクッキーから言語値を取得
110                                                 $lang = $request->getCookieValue(M3_COOKIE_LANG);
111                                         }
112
113                                         // アクセス可能な言語な場合は変更
114                                         if (in_array($lang, $this->gSystem->getAcceptLanguage())){
115                                                 $this->gEnv->setCurrentLanguage($lang);
116                                                 
117                                                 // クッキーに言語を保存
118                                                 $request->setCookieValue(M3_COOKIE_LANG, $lang);
119                                         } else {                // アクセス不可の場合はクッキーを削除
120                                                 // クッキーを削除
121                                                 $request->setCookieValue(M3_COOKIE_LANG, '', -1);
122                                         }
123                                 } else {
124                                         // クッキーを削除
125                                         $request->setCookieValue(M3_COOKIE_LANG, '', -1);
126                                 }
127                                 // 言語に依存する情報を取り込む
128                                 $this->gPage->loadLang();
129                         }
130                         // ################### URLアクセス制御 ######################
131                         // 非公開URLへは管理権限がないとアクセスできない
132                         $canAccess = true;              // アクセス可能かどうか
133                         $isErrorAccess = false;         // 不正アクセスかどうか
134                         $toAdminType = 0;               // 管理画面の遷移タイプ(0=アクセス不可、1=ログイン画面、2=サイト非公開画面, 3=存在しないページ)
135                         $errMessage = '';       // エラーメッセージ
136                         $messageDetail = '';    // 詳細メッセージ
137                         
138                         // ページID,ページサブID以外のURLパラメータをチェック。ページマネージャーでの処理(startPage())の結果を反映。
139                         $ret = $this->gPage->isSystemPage();            // システム制御ページへ遷移するかどうか
140                         if ($ret){
141                                 // ページが見つかりません画面へ遷移
142                                 $canAccess = false;
143                                 $toAdminType = 4;
144                         }
145                         
146                         // ページID,ページサブIDからアクセス権をチェック
147                         if ($canAccess){
148                                 $isPublicUrl = $this->gPage->canAccessUrl($isActivePage, $errCode);
149                                 if (!$isPublicUrl && !$isSystemManageUser){// システム運用可能ユーザかどうか
150                                         $canAccess = false;
151                                         $isErrorAccess = true;          // 不正アクセスかどうか
152                                         $errMessage = 'ユーザに公開されていないページへのアクセス。';
153                                 
154                                         if (!$isActivePage){
155                                                 if ($errCode == 1){                     // ページIDが不正な場合
156                                                         $toAdminType = 4;
157                                                 } else {
158                                                         $toAdminType = 3;               // 有効なアクセスポイント、ページでない場合は存在しないページとする
159                                                 }
160                                         }
161                                 }
162                         }
163                         
164                         // ################### ユーザアクセス制御 ######################
165                         // クッキーがないため権限を識別できない場合でも、管理者として処理する場合があるので、サブクラスの_checkAccess()メソッドは必ず通るようにする
166                         if ($canAccess){                // アクセス可能な場合はユーザをチェック
167                                 if (method_exists($this, '_checkAccess')){
168                                         // 管理画面へのアクセスを制御
169                                         $canAccess = $this->_checkAccess($request);             // サブクラスメソッドの呼び出し
170                                         
171                                         // フロント画面から直接管理画面が呼ばれた場合は一旦ログインへ遷移
172                                         if (!$canAccess && 
173                                                 ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||                                                // ウィジェットの設定
174                                                 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET)){                     // 表示位置を表示するとき(ウィジェット付き)
175                                                 // 管理画面で処理
176                                                 $toAdminType = 1;               // ログイン画面へ
177                                         }
178                                 } else {                        // _checkAccess()がないときは、標準のアクセス制御
179                                         // フロント画面へのアクセスを制御
180                                         $canAccess = $this->_accessSite($request);              // サイト公開制御
181                                         if ($canAccess){
182                                                 if ($cmd == M3_REQUEST_CMD_LOGIN ||                                     // ログイン画面を表示のとき
183                                                         $cmd == M3_REQUEST_CMD_LOGOUT){                         // ログアウトのとき
184
185                                                         // 管理画面で処理
186                                                         $canAccess = false;
187                                                         $toAdminType = 1;               // ログイン画面へ
188                                                 } else if ($cmd != '' &&                                                                // コマンドなし
189                                                         $cmd != M3_REQUEST_CMD_CHANGE_TEMPLATE &&                       // テンプレート変更
190                                                         $cmd != M3_REQUEST_CMD_SHOW_POSITION &&                         // 表示位置を表示するとき
191                                                         $cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET &&     // 表示位置を表示するとき(ウィジェット付き)
192                                                         $cmd != M3_REQUEST_CMD_FIND_WIDGET &&                           // ウィジェットを検索
193                                                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                     // ウィジェット単体実行
194                                                         $cmd != M3_REQUEST_CMD_PREVIEW &&                                       // サイトのプレビューを表示
195                                                         $cmd != M3_REQUEST_CMD_RSS &&                                           // RSS配信
196                                                         $cmd != M3_REQUEST_CMD_CSS){                                            // CSS生成
197                                                         
198                                                         // 標準のアクセスでは、上記コマンド以外は受け付けない
199                                                         $canAccess = false;
200                                                         $isErrorAccess = true;          // 不正アクセス
201                                                         $errMessage = '不正なコマンドの実行。';
202                                                         $messageDetail = 'アクセスポイント状態=公開';
203                                                 }
204                                         } else {                // サイトアクセスできない場合は、管理画面でメッセージを表示
205                                                 if ($cmd == M3_REQUEST_CMD_LOGIN ||                                     // ログイン画面を表示のとき
206                                                         $cmd == M3_REQUEST_CMD_LOGOUT ||                                // ログアウトのとき
207                                                         $cmd == M3_REQUEST_CMD_PREVIEW){                                        // サイトのプレビューを表示
208                                                         $toAdminType = 1;               // ログイン画面へ
209                                                 } else {
210                                                         $toAdminType = 2;               // サイト非公開画面へ
211                                                 }
212                                                 
213                                                 // 不正なコマンドはログを残す
214                                                 if ($cmd != '' &&                                                               // コマンドなし
215                                                         $cmd != M3_REQUEST_CMD_LOGIN &&                         // ログイン画面を表示のとき
216                                                         $cmd != M3_REQUEST_CMD_LOGOUT &&                                        // ログアウトのとき
217                                                         $cmd != M3_REQUEST_CMD_CHANGE_TEMPLATE &&                       // テンプレート変更
218                                                         $cmd != M3_REQUEST_CMD_SHOW_POSITION &&                         // 表示位置を表示するとき
219                                                         $cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET &&     // 表示位置を表示するとき(ウィジェット付き)
220                                                         $cmd != M3_REQUEST_CMD_FIND_WIDGET &&                           // ウィジェットを検索
221                                                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                     // ウィジェット単体実行
222                                                         $cmd != M3_REQUEST_CMD_PREVIEW &&                                       // サイトのプレビューを表示
223                                                         $cmd != M3_REQUEST_CMD_RSS &&                                           // RSS配信
224                                                         $cmd != M3_REQUEST_CMD_CSS){                                            // CSS生成
225                                                         
226                                                         $isErrorAccess = true;          // 不正アクセス
227                                                         $errMessage = '不正なコマンドの実行。';
228                                                         $messageDetail = 'アクセスポイント状態=非公開';
229                                                 }
230                                         }
231                                 }
232                                 // システム運用可能ユーザはアクセス可。
233                                 // ログアウトのときはすでに管理ユーザの可能性があるので、ログアウト時は変更しない
234                                 //if ($isSystemManageUser && $cmd != M3_REQUEST_CMD_LOGOUT) $canAccess = true;
235                                 if ($isSystemAdmin && $cmd != M3_REQUEST_CMD_LOGOUT) $canAccess = true;                 // 2011/8/31 システム管理者のみに変更
236                         }
237                         // #################### アクセスログ記録 #######################
238                         // DBが使用可能であれば、ログイン処理終了後、アクセスログを残す
239                         if ($this->gEnv->canUseDb()) $this->gAccess->accessLog();
240
241                         // アクセス不可のときはここで終了
242                         if (!$canAccess){
243                                 switch ($toAdminType){
244                                         case 1:                 // ログイン画面へ
245                                                 // システム制御モードに変更
246                                                 $this->gPage->setSystemHandleMode(1/*管理画面*/);
247                                                 break;
248                                         case 2:                 // サイト非公開画面へ
249                                                 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
250                                                 break;
251                                         case 3:                 // 存在しないページ画面へ(システム運用可能ユーザ以外)
252                                                 // サイトが非公開の場合は、メンテナンス中画面のみ表示
253                                                 if ($this->_accessSite($request)){              // サイト公開中の場合
254                                                         $messageDetail = 'アクセスポイント状態=公開';
255                                                         $this->gPage->setSystemHandleMode(12/*存在しないページ*/);
256                                                 } else {
257                                                         $messageDetail = 'アクセスポイント状態=非公開';
258                                                         $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
259                                                 }
260                                                 break;
261                                         case 4:         // 不正なページIDの指定
262                                                 $messageDetail = '不正なページIDの指定';
263                                                 $this->gPage->setSystemHandleMode(12/*存在しないページ*/);
264                                                 break;
265                                         default:                // アクセス不可画面へ
266                                                 // システム制御モードに変更
267                                                 $this->gPage->setSystemHandleMode(11/*アクセス不可*/);
268                                                 break;
269                                 }
270                                 // システム制御画面を表示
271                                 $this->_showSystemPage($request, $toAdminType);
272                                                 
273                                 // 不正アクセスの場合は、アクセスエラーログを残す
274                                 if ($isErrorAccess) $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2201, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
275                                 return;
276                         }
277                         // #################### URLの遷移 #######################
278                         //if ($this->gSystem->getSystemConfig(self::CF_MOBILE_AUTO_REDIRECT)){          // 携帯自動遷移を行う場合
279                         if ($this->gSystem->mobileAutoRedirect()){              // 携帯自動遷移を行う場合
280                                 // 携帯のときは携帯用URLへ遷移
281                                 if ($this->gEnv->isMobile() && !$this->gEnv->getIsMobileSite()){
282                                         $this->gPage->redirect($this->gEnv->getDefaultMobileUrl(true/*携帯用パラメータ付加*/), true/*遷移時のダイアログ表示を抑止*/);
283                                         return;
284                                 }
285                         }
286                         if ($this->gSystem->smartphoneAutoRedirect()){          // スマートフォン自動遷移を行う場合
287                                 // スマートフォンのときはスマートフォンURLへ遷移
288                                 if ($this->gEnv->isSmartphone() && !$this->gEnv->getIsSmartphoneSite()){
289                                         $this->gPage->redirect($this->gEnv->getDefaultSmartphoneUrl());
290                                         return;
291                                 }
292                         }
293                 }
294
295                 // ################## 実行コマンドから処理を確定 ##################
296                 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
297                 
298                 // 画面作成モードか、ウィジェット単体処理モードかを決定
299                 $createPage = true;             // 画面作成モード
300                 if ($cmd == M3_REQUEST_CMD_INIT_DB){    // DB初期化オペレーションのとき
301                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION){               // 表示位置を表示するとき
302                         // 管理者権限がある場合のみ実行可能
303                         //if ($this->gEnv->isSystemAdmin()){
304                         if ($isSystemAdmin){
305                                 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
306                                 // ページIDを再設定
307 /*                              $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
308                                 if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId();          // 値がないときはデフォルトのページIDを設定
309                                 $this->gEnv->setCurrentPageId($pageId);
310                                 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
311                                 if (!empty($pageSubId)) $this->gEnv->setCurrentPageSubId($pageSubId);
312                         */
313                                 $this->gPage->showPosition(1);                  // ポジションを表示
314                         } else {
315                                 return;
316                         }
317                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // 表示位置を表示するとき(ウィジェット付き)
318                         // 管理者権限がある場合のみ実行可能
319                         //if ($this->gEnv->isSystemAdmin()){
320                         if ($isSystemAdmin){
321                                 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
322                                 // ページIDを再設定
323 /*                              $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
324                                 if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId();          // 値がないときはデフォルトのページIDを設定
325                                 $this->gEnv->setCurrentPageId($pageId);
326                                 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
327                                 if (!empty($pageSubId)) $this->gEnv->setCurrentPageSubId($pageSubId);
328                                 */
329                                 $this->gPage->showPosition(2);                  // ウィジェット付きポジションを表示
330                         } else {
331                                 return;
332                         }
333                 } else if ($cmd == M3_REQUEST_CMD_GET_WIDGET_INFO){             // ウィジェット各種情報取得(AJAX用)
334                         // ウィジェット情報取得
335                         $this->gPage->getWidgetInfoByAjax($request);
336                         return;
337                 } else if ($cmd == M3_REQUEST_CMD_SHOW_PHPINFO){        // phpinfoの表示
338                         // phpinfo画面を表示
339                         $this->_showPhpinfoPage($request);
340                         return;
341                 } else if ($cmd == M3_REQUEST_CMD_FIND_WIDGET){         // ウィジェットを検索し、前面表示
342                         // 目的のウィジェットのあるページサブIDへ遷移
343                         $this->gPage->redirectToUpdatedPageSubId($request);
344                         return;
345                 } else if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET){         // ウィジェットの単体表示
346                         $createPage = false;            // ウィジェット単体処理モードに設定
347                         $this->gPage->showWidget();     // ウィジェット表示
348                 } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){               // ウィジェットの設定管理
349                         $createPage = false;            // ウィジェット単体処理モードに設定
350                         $this->gPage->showWidget();     // ウィジェット表示
351                 } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){           // ウィジェット単体オペレーション
352                         $createPage = false;            // ウィジェット単体処理モードに設定
353                         
354                         // ウィンドウオープンタイプ指定のときは、テンプレートを表示する
355                         if (!empty($openBy)) $this->gPage->showWidget();        // ウィジェット表示
356                 } else if ($cmd == M3_REQUEST_CMD_RSS){         // RSS配信
357                         $createPage = false;            // ウィジェット単体処理モードに設定
358                 } else if ($cmd == M3_REQUEST_CMD_CSS){         // CSS生成
359                 
360                 } else if ($this->gEnv->isServerConnector()){           // サーバ接続の場合
361                         $createPage = false;            // ウィジェット単体処理モードに設定
362                 }
363
364                 // ################### クライアントへの出力方法の制御 ######################
365                 // ウィジェットIDの取得
366                 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
367                 if ($createPage){                               // 通常の画面作成の場合
368                         // 画面のキャッシュデータを取得
369                         $this->gCache->initCache($request);             // キャッシュ機能初期化
370                         $cacheData = $this->gCache->getPageCache($request);
371                         
372                         if (empty($cacheData)){         // キャッシュデータがないときは画面を作成
373                                 // カレントのテンプレートを決定
374                                 $curTemplateId = $this->_defineTemplate($request, $subTemplateId);
375
376                                 // 画面を作成
377                                 $pageData = $this->_createPage($request, $curTemplateId, $subTemplateId);
378                                 
379                                 // 使用した非共通ウィジェットの数をチェック
380                                 $nonSharedWidgetCount = $this->gPage->getNonSharedWidgetCount();
381                                 if ($nonSharedWidgetCount == -1){               // カウントなしの場合
382                                         $this->gCache->setPageCache($request, $pageData);               // キャッシュデータを設定
383                                         echo $pageData;
384                                 } else {
385                                         if ($isSystemAdmin || $nonSharedWidgetCount > 0){
386                                                 $this->gCache->setPageCache($request, $pageData);               // キャッシュデータを設定
387                                                 echo $pageData;
388                                         } else {                // 管理者以外で、非共通のウィジェットが使用されていないページはアクセス不可とする
389                                                 $errMessage = 'ユーザに公開されていないページへのアクセス。';
390                                                 $messageDetail = 'アクセスポイント状態=公開, 要因: グローバルウィジェットのみのページへのアクセスはできません。ページには1つ以上のローカルウィジェットが必要です。';
391                                                 $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2202, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
392
393                                                 // アクセス不可ページへ遷移
394                                                 $this->gPage->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
395                                                 // システム制御モードに変更
396                                                 //$this->gPage->setSystemHandleMode(11/*アクセス不可*/);
397
398                                                 // システム制御画面を表示
399                                                 //$this->_showSystemPage($request, 0/*アクセス不可画面*/);
400                                         }
401                                 }
402                         } else {
403                                 echo $cacheData;
404                         }
405                         
406                         if ($cmd != M3_REQUEST_CMD_CSS){                // 画面出力(CSS生成以外)のとき
407                                 // オプション出力(時間計測等)追加
408                                 echo $this->gPage->getOptionContents($request);
409                         }
410                 } else {                // ウィジェット単体実行モードのとき
411                         // ###################ウィジェット指定で出力の場合####################
412                         // ウィジェット単体を直接実行するインターフェイスで、HTTPヘッダは送信しない。
413                         // 以下のパターンで使用する。
414                         // ・Ajaxを使って、データをやり取りしたい場合
415                         // ・ウィジェット単体での実行(ウィジェットが生成したタグのみ)
416                         // ・ウィジェット単体での実行(HTMLやJavascriptの追加あり)
417                         // ・ウィジェット個別の設定(セキュリティの必要あり)
418
419                         // ################# アクセスチェック ################
420                         // ウィジェット単体オペレーションのときは、ウィジェット情報の単体実行許可があるかどうか判断(管理権限にかかわらず同じ動作)
421                         if ($cmd == M3_REQUEST_CMD_DO_WIDGET ||         // ウィジェット単体実行
422                                 $cmd == M3_REQUEST_CMD_RSS){            // RSS配信
423                                 if (empty($widgetId)){
424                                         $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットIDが設定されていません。', 2200,
425                                                 '実行処理はキャンセルされました。');
426                                         return;
427                                 } else if ($this->_db->getWidgetInfo($widgetId, $row)){                 // ウィジェット情報取得
428                                         if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !$row['wd_enable_operation']){  // ウィジェット単体実行
429                                                 // アクセスエラーのログを残す
430                                                 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
431                                                 
432                                                 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは単体起動できません。(ウィジェットID: ' . $widgetId . ')', 2200,
433                                                 '実行処理はキャンセルされました。このウィジェットは単体起動できないウィジェットです。単体起動を許可するにはウィジェット情報(_widgets)の単体起動フラグ(wd_enable_operation)がtrueになっている必要があります。');
434                                                 return;
435                                         } else if ($cmd == M3_REQUEST_CMD_RSS && !$row['wd_has_rss']){                          // RSS配信
436                                                 // アクセスエラーのログを残す
437                                                 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
438                                                 
439                                                 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットはRSS配信できません。(ウィジェットID: ' . $widgetId . ')', 2200,
440                                                 '実行処理はキャンセルされました。このウィジェットはRSS配信できないウィジェットです。RSS配信を許可するにはウィジェット情報(_widgets)のRSS配信フラグ(wd_has_rss)がtrueになっている必要があります。');
441                                                 return;
442                                         }
443                                 } else {
444                                         $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは実行許可がありません。(ウィジェットID: ' . $widgetId . ')', 2200,
445                                                 '実行処理はキャンセルされました。ウィジェット情報(_widgets)が見つかりません。');
446                                         return;
447                                 }
448                         }
449                         
450                         // 管理権限がない場合は、ウィジェットのページへの配置状況からアクセス権限をチェックする
451                         if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && !$this->_db->canAccessWidget($widgetId)){
452                                 // アクセスエラーのログを残す
453                                 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
454                                 
455                                 $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットへの不正なアクセスを検出しました。(ウィジェットID: ' . $widgetId . ')', 2200,
456                                                 '実行処理はキャンセルされました。このウィジェットは一般ユーザに公開されているページ上に存在しないため単体実行できません。');
457                                 return;
458                         }
459                         
460                         // ################# パラメータチェック ################
461                         if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && $this->gEnv->isServerConnector()){            // サーバ接続の場合
462                                 // クエリーパラメータはウィジェットIDのみ正常とする
463                                 $params = $this->gRequest->getQueryArray();
464                                 $paramCount = count($params);
465                                 if (!($paramCount == 1 && !empty($params[M3_REQUEST_PARAM_WIDGET_ID]))){
466                                         // アクセスエラーのログを残す
467                                         $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
468                                 
469                                         $this->gOpeLog->writeUserAccess(__METHOD__, 'サーバ接続アクセスポイントへの不正なアクセスを検出しました。', 2200,
470                                                         '実行処理はキャンセルされました。URLのクエリー部が不正です。URL=' . $this->gEnv->getCurrentRequestUri());
471                                         return;
472                                 }
473                         }
474
475                         // 画面表示する場合はテンプレートを設定。画面に表示しない場合はテンプレートが必要ない。
476                         if ($this->gPage->getShowWidget()){
477                                 // 管理用テンプレートに固定
478                                 //$curTemplate = $this->_defineTemplate($request);
479                                 $curTemplate = $this->gSystem->defaultAdminTemplateId();
480
481                                 // カレントのテンプレートIDを設定
482                                 $this->gEnv->setCurrentTemplateId($curTemplate);
483                         }
484                         
485                         // ################### バッファリング開始 ######################
486                         // ob_end_flush()までの出力をバッファリングする
487                         ob_start();
488                         
489                         // サブクラスの前処理を実行
490                         if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
491                 
492                         // 作業中のウィジェットIDを設定
493                         $this->gEnv->setCurrentWidgetId($widgetId);
494                         
495                         if ($this->gEnv->isServerConnector()){          // サーバ接続の場合
496                                 // ウィジェット用のHTMLヘッダを出力
497                                 $this->gPage->startWidgetXml($cmd);
498
499                                 // 指定のウィジェットを実行
500                                 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
501
502                                 if (file_exists($widgetIndexFile)){
503                                         // 実行のログを残す
504                                         $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
505
506                                         require_once($widgetIndexFile);
507                                 } else {
508                                         echo 'file not found: ' . $widgetIndexFile;
509                                 }
510                         
511                                 // ウィジェット用のタグを閉じる
512                                 $this->gPage->endWidgetXml($cmd);
513                         } else if ($cmd == M3_REQUEST_CMD_RSS){         // RSS配信のとき
514                                 ob_start();// バッファ作成
515                                 
516                                 // ウィジェット用のHTMLヘッダを出力
517                                 $this->gPage->startWidgetRss($cmd);
518                                 
519                                 // 指定のウィジェットを実行
520                                 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
521
522                                 if (file_exists($widgetIndexFile)){
523                                         // ウィジェット定義ID、ページ定義のシリアル番号を取得
524                                         $configId = 0;          // 定義ID
525                                         $serial = 0;            // シリアル番号
526                                         if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
527                                                 $configId = $row['pd_config_id'];               // 定義ID
528                                                 $serial = $row['pd_serial'];            // シリアル番号
529                                         }
530
531                                         // ウィジェット定義IDを設定
532                                         $this->gEnv->setCurrentWidgetConfigId($configId);
533                         
534                                         // ページ定義のシリアル番号を設定
535                                         $this->gEnv->setCurrentPageDefSerial($serial);
536                                 
537                                         // 実行のログを残す
538                                         $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
539
540                                         require_once($widgetIndexFile);
541                                         
542                                         // ウィジェット定義IDを解除
543                                         $this->gEnv->setCurrentWidgetConfigId('');
544                                 
545                                         // ページ定義のシリアル番号を解除
546                                         $this->gEnv->setCurrentPageDefSerial(0);
547                                 } else {
548                                         echo 'file not found: ' . $widgetIndexFile;
549                                 }
550                         
551                                 // 現在のバッファ内容を取得し、バッファを破棄
552                                 $content = ob_get_contents();
553                                 ob_end_clean();
554                                 
555                                 // ウィジェット用のタグを閉じる
556                                 $this->gPage->endWidgetRss($cmd, $content);
557                         } else {                // RSS配信以外のとき
558                                 ob_start();// バッファ作成
559                                                         
560                                 // ウィジェット用のHTMLヘッダを出力
561                                 $this->gPage->startWidget($cmd);
562                                 
563                                 // 指定のウィジェットを実行
564                                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット設定のとき
565                                         $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/admin/index.php';                // 管理用画面
566                                 } else {
567                                         $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
568                                 }
569                                 if (file_exists($widgetIndexFile)){
570                                         // ウィジェット定義ID、ページ定義のシリアル番号を取得
571                                         $configId = 0;          // 定義ID
572                                         $serial = 0;            // シリアル番号
573                                         if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
574                                                 $configId = $row['pd_config_id'];               // 定義ID
575                                                 $serial = $row['pd_serial'];            // シリアル番号
576                                         }
577
578                                         // ウィジェット定義IDを設定
579                                         $this->gEnv->setCurrentWidgetConfigId($configId);
580                         
581                                         // ページ定義のシリアル番号を設定
582                                         $this->gEnv->setCurrentPageDefSerial($serial);
583                                         
584                                         // 実行のログを残す
585                                         $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
586
587                                         require_once($widgetIndexFile);
588                                         
589                                         // ウィジェット定義IDを解除
590                                         $this->gEnv->setCurrentWidgetConfigId('');
591                                 
592                                         // ページ定義のシリアル番号を解除
593                                         $this->gEnv->setCurrentPageDefSerial(0);
594                                 } else {
595                                         echo 'file not found: ' . $widgetIndexFile;
596                                 }
597                         
598                                 // 現在のバッファ内容を取得し、バッファを破棄
599                                 $content = ob_get_contents();
600                                 ob_end_clean();
601                                 
602                                 // ウィジェット用のタグを閉じる
603                                 $this->gPage->endWidget($cmd, $content);
604                         }
605                 
606                         // 作業中のウィジェットIDを解除
607                         $this->gEnv->setCurrentWidgetId('');
608                         
609                         // サブクラスの後処理の呼び出し
610                         if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
611                         
612                         if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET ||               // ウィジェットの単体表示
613                                 $cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||         // ウィジェット設定のとき
614                                 ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy))){         // ウィンドウオープンタイプ指定でウィジェット単体実行のとき
615                                 
616                                 // 現在の出力内容を取得し、一旦内容をクリア
617                                 $srcContents = ob_get_contents();
618                                 ob_clean();
619                                 
620                                 // 追加変換処理。HTMLヘッダ出力する。
621                                 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
622                                 
623                                 echo $destContents;
624                         }
625                         
626                         // ページ作成終了処理(HTTPヘッダ出力)
627                         $this->gPage->endPage($request);
628
629                         if ($cmd != M3_REQUEST_CMD_RSS){                // 画面出力(RSS配信以外)のとき
630                                 // オプション出力(時間計測等)追加
631                                 echo $this->gPage->getOptionContents($request);
632                         }
633
634                         // バッファ内容を送信(クライアントへの送信完了)
635                         ob_end_flush();
636                 }
637                 if (!defined('M3_STATE_IN_INSTALL')){           // インストールモード以外のとき
638                         // #################### アクセスログ記録 #######################
639                         // DBが使用可能であれば、アクセスログのユーザを登録
640                         if ($this->gEnv->canUseDb()) $this->gAccess->accessLogUser();
641                 }
642
643                 // 終了ログ出力
644                 //$this->gLog->info(__METHOD__, 'フレーム作成終了');
645         }
646         /**
647          * 画面を作成
648          *
649          * @param RequestManager $request               HTTPリクエスト処理クラス
650          * @param string $curTemplate                   テンプレートID
651          * @param string $subTemplateId                 サブページID
652          * @return string                                               画面出力
653          */
654         function _createPage($request, $curTemplate, $subTemplateId = '')
655         {
656                 $defaultIndexFile = 'index.php';                        // テンプレートの起動ファイル
657                 
658                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);               // 実行コマンドを取得
659                 
660                 // カレントのテンプレートIDを設定
661                 $this->gEnv->setCurrentTemplateId($curTemplate, $subTemplateId);
662
663                 // テンプレート情報を取得
664                 $convType = 0;          // 変換処理タイプ(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
665                 if ($this->gEnv->getIsMobileSite()){
666                         $convType = -1;         // 携帯サイト用変換
667                 } else {
668                         // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
669                         $convType = $this->gEnv->getCurrentTemplateType();
670                 }
671
672                 // バッファリングの準備
673                 if (method_exists($this, '_prepareBuffer')) $this->_prepareBuffer($request);
674         
675                 // ################### バッファリング開始 ######################
676                 // ob_end_flush()までの出力をバッファリングする
677                 if ($convType == -1){// 携帯用サイトの場合は出力エンコーディングを変更
678                         $mobileEncoding = $this->gEnv->getMobileEncoding();             // 携帯用エンコーディングを取得
679                         mb_http_output($mobileEncoding);
680                         ob_start("mb_output_handler"); // 出力のバッファリング開始
681                 } else {
682                         ob_start();
683                 }
684
685                 // サブクラスの前処理を実行
686                 if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
687         
688                 if ($convType == 100){          // WordPressテンプレートのとき
689                         // WordPress用ベース定義値
690                         define('WPINC', 'wp-includes');
691                         define('ABSPATH', $this->gEnv->getWordpressRootPath() . '/' );
692                         define('TEMPLATEPATH', $this->gEnv->getTemplatesPath() . '/' . $curTemplate);
693                         define('STYLESHEETPATH', $this->gEnv->getTemplatesPath() . '/' . $curTemplate);         // 子テンプレートを使用している場合は子テンプレートを示す。デフォルトはテンプレートを示す。
694                         define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
695                         define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages');
696                         define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
697                         define('WP_CONTENT_URL', '/wp-content');                                // 定義自体は必要であるが使用しないのでダミー値で定義
698                         define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins');   // 定義自体は必要であるが使用しないのでダミー値で定義
699                         
700                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/load.php');
701                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/default-constants.php');               // デフォルト値取得
702                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/plugin.php');
703
704                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/functions.php');
705                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/default-filters.php');
706                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/l10n.php');
707                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp.php');
708                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-user.php');
709                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-walker.php');
710                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-query.php');                          // コンテンツデータ取得
711                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-comment-query.php');
712                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-term.php');
713                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-walker-page.php');
714                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-theme.php');
715                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-list-util.php');
716 //                      require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-walker-nav-menu.php');
717 //                      require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-dependency.php');
718                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-post.php');                   // コンテンツAPIマネージャーからWP_Post型でデータを取得
719
720                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/query.php');
721                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pluggable.php');
722                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post.php');
723                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/user.php');
724                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/widgets.php');
725                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/comment.php');
726                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/http.php');
727                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/kses.php');
728                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/script-loader.php');
729                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/theme.php');
730                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/template.php');
731                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/link-template.php');
732                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/category.php');
733                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/category-template.php');
734                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-template.php');
735                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-thumbnail-template.php');
736                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/comment-template.php');
737                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/author-template.php');
738                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/nav-menu-template.php');
739                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/nav-menu.php');
740                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/general-template.php');
741                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/cache.php');
742                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/shortcodes.php');
743                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/formatting.php');
744                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-formats.php');
745                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/taxonomy.php');
746                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/media.php');
747                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/embed.php');
748 //                      require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/option.php');
749                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pomo/translations.php');
750                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pomo/mo.php');
751                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/capabilities.php');
752                         require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/meta.php');
753                 
754                         // Magic3用インターフェイス
755                         require_once($this->gEnv->getWordpressRootPath() . '/wpInit.php');              // 初期値取得
756                         require_once($this->gEnv->getWordpressRootPath() . '/contentApi.php');  // コンテンツ取得API
757                         require_once($this->gEnv->getWordpressRootPath() . '/menuApi.php');             // メニュー情報取得API
758
759                         // ##### データ初期化 #####
760                         wp_initial_constants();                 // WordPressその他定義値設定
761                         
762                         // プラグイン初期化
763                         $GLOBALS['wp_plugin_paths'] = array();                  // $wp_plugin_pathsは未使用?
764                         foreach (wp_get_active_and_valid_plugins() as $plugin) {// プラグインロード
765                                 wp_register_plugin_realpath($plugin);
766                                 include_once($plugin);
767                         }
768                         unset($plugin);
769
770                         // WordPressメインオブジェクト作成
771                         $GLOBALS['locale'] = $this->gEnv->getCurrentLanguage();         // 表示言語を設定
772                         $GLOBALS['wp_the_query'] = new WP_Query();                              // $wp_the_queryは変更不可変数で$wp_queryは変更可変数
773                         $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
774                         $GLOBALS['wp'] = new WP();
775                         $GLOBALS['gContentApi'] = new contentApi();                     // Magic3コンテンツAPIオブジェクト
776                         $GLOBALS['gMenuApi'] = new menuApi();                   // Magic3メニュー情報APIオブジェクト
777                         
778                         // テンプレート初期処理
779                         do_action('setup_theme');
780                         load_default_textdomain();                      // 言語リソースを読み込む
781                         m3WpInit();                                                     // 言語リソース読み込み後にMagic3用インターフェイス初期化。$GLOBALS['m3WpOptions']を初期化し、get_option()はここから使用可能にする。
782                         if ( file_exists(TEMPLATEPATH . '/functions.php')) include(TEMPLATEPATH . '/functions.php');// テンプレート初期処理
783                         do_action('after_setup_theme');         // wp-multibyte-patchプラグイン読み込み
784                         do_action('wp_loaded');
785                         
786                         // ##### 起動PHPファイル取得。データ取得用パラメータ設定。#####
787                         // URLパラメータからコンテンツ形式を取得し、ページを選択
788                         $params = $this->gRequest->getQueryArray();
789                         $paramCount = count($params);
790                         reset($params);
791                         $firstKey = key($params);
792 //                      $firstValue = $params[$firstKey];
793                         
794                         $contentType = $GLOBALS['gContentApi']->getContentType();
795                         switch ($contentType){
796                         case M3_VIEW_TYPE_CONTENT:              // 汎用コンテンツ
797                                 if ($firstKey == M3_REQUEST_PARAM_CONTENT_ID || $firstKey == M3_REQUEST_PARAM_CONTENT_ID_SHORT){        // コンテンツIDのとき
798                                         // ページタイプを設定
799                                         $GLOBALS['gContentApi']->setPageType('page');
800                                         
801                                         // フルパスで返るので相対パスに修正
802                                         $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template());            // 固定ページテンプレート
803                                         
804                                         // コンテンツID設定
805                                         $firstValue = $this->gRequest->trimValueOf($firstKey);
806                                         $GLOBALS['gContentApi']->setContentId($firstValue);
807                                 }
808                                 break;
809                         case M3_VIEW_TYPE_PRODUCT:      // 製品
810                                 break;
811                         case M3_VIEW_TYPE_BBS:  // BBS
812                                 break;
813                         case M3_VIEW_TYPE_BLOG: // ブログ
814 //                              if ($firstKey == M3_REQUEST_PARAM_BLOG_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ID_SHORT ||                     // ブログIDのとき
815 //                                      $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT){              // ブログ記事IDのとき
816                                 if ($firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT){          // ブログ記事IDのとき
817                                         // ページタイプを設定
818                                         $GLOBALS['gContentApi']->setPageType('single');
819                                         
820                                         // フルパスで返るので相対パスに修正
821                                         $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_single_template());          // 記事詳細テンプレート
822                                         
823                                         // コンテンツID設定
824                                         $firstValue = $this->gRequest->trimValueOf($firstKey);
825                                         $GLOBALS['gContentApi']->setContentId($firstValue);
826                                 } else {
827                                         // 検索条件が設定されている場合は検索ページを表示
828                                         $value = $this->gRequest->trimValueOf('s');
829                                         if (!empty($value)){
830                                                 // ページタイプを設定
831                                                 $GLOBALS['gContentApi']->setPageType('search');                 // 検索結果表示
832                                         
833                                                 // フルパスで返るので相対パスに修正
834                                                 $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_search_template());          // 検索結果テンプレート
835                                         }
836                                 }
837                                 break;
838                         case M3_VIEW_TYPE_WIKI: // Wiki
839                                 break;
840                         case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ
841                                 break;
842                         case M3_VIEW_TYPE_EVENT:        // イベント
843                                 break;
844                         case M3_VIEW_TYPE_PHOTO:        // フォトギャラリー
845                                 break;
846                         default:
847                                 // コンテンツタイプが設定されていないページに場合は、固定ページ用のテンプレートを使用
848                                 // ページタイプを設定
849                                 $GLOBALS['gContentApi']->setPageType('page');
850                                         
851                                 // フルパスで返るので相対パスに修正
852                                 $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template());            // 固定ページテンプレート
853                                 break;
854                         }
855                         
856                         // WordPressオブジェクト作成
857                         wp();
858                 } else if ($convType >= 1){             // Joomla!v1.5,v2.5テンプレートのとき
859                         global $mainframe;
860                         require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
861                         require_once($this->gEnv->getJoomlaRootPath() . '/JParameter.php');
862                         require_once($this->gEnv->getJoomlaRootPath() . '/JRender.php');
863                                                 
864                         // 設定ファイルの読み込み
865                         //$params = array();
866                         $paramFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/params.ini';
867                         if (is_readable($paramFile)){
868                                 $content = file_get_contents($paramFile);
869                                 $params = new JParameter($content);
870                         } else {
871                                 $params = new JParameter();
872                         }
873                         // テンプレートヘッダ画像上のテキスト設定(Joomla!テンプレート2.5以降)
874                         $params->set('siteTitle',               $this->gEnv->getSiteName());            // サイト名
875                         $params->set('siteSlogan',              $this->gSystem->getSiteDef(M3_TB_FIELD_SITE_SLOGAN));           // サイトスローガン
876                         
877                         // Joomla!テンプレート共通の設定
878                         define('_JEXEC', 1);
879                                                 
880                         // Joomla!v1.5用の設定
881                         define('JPATH_BASE', dirname(__FILE__));
882                         define('JPATH_SITE', $this->gEnv->getSystemRootPath());
883                         define('JPATH_PLUGINS', $this->gEnv->getJoomlaRootPath() . '/class/plugins');                   // プラグインパス
884 //                      define('JPATH_THEMES', $this->gEnv->getTemplatesPath());                                                                // テンプレートパス             ## テンプレート内でエラーが発生するのでここでは定義しない(2015/10/13)
885                         define('DS', DIRECTORY_SEPARATOR);
886                         $this->language = $this->gEnv->getCurrentLanguage();
887                         $this->template = $curTemplate;
888                         //$this->baseurl  = $this->gEnv->getRootUrl();
889                         $this->baseurl          = $this->gEnv->getRootUrlByCurrentPage();
890                         $this->direction = 'ltr';
891                         $this->params   = $params;
892                         
893                         // サブテンプレート用の設定
894                         if ($this->gEnv->getCurrentTemplateGenerator() == self::TEMPLATE_GENERATOR_THEMLER){            // Themlerテンプレートの場合はサブテンプレート用のパラメータを設定
895                                 // JRequest経由でレンダー側にサブテンプレートIDを渡す
896                                 if (!empty($subTemplateId)) JRequest::injectSetVar('file_template_name', $subTemplateId);
897
898                                 // サブテンプレートIDの渡し方は以下の方法もある(Themlerテンプレート1.39以降はこちらが有効)
899                                 // サブテンプレートIDを埋め込む
900                                 if (!empty($subTemplateId)) $this->setBuffer('<!--TEMPLATE ' . $subTemplateId . ' /-->', 'component');
901                         }
902                         
903                         // 現在のJoomla!ドキュメントを設定
904                         $this->gEnv->setJoomlaDocument($this);
905                 } else {                        // デフォルト(Joomla!v1.0テンプレート)テンプレートのとき(PC用および携帯用)
906                         // Joomla!テンプレート共通の設定
907                         define('_JEXEC', 1);
908                         
909                         // Joomlaテンプレート用定義
910                         global $mosConfig_absolute_path;
911                         global $mosConfig_live_site;
912                         global $mosConfig_sitename;
913                         global $mosConfig_favicon;
914                         global $mosConfig_sef;
915                         global $cur_template;
916                         global $mainframe;
917                         require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
918                         require_once($this->gEnv->getJoomlaRootPath() . '/mosFunc.php');
919                         require_once($this->gEnv->getJoomlaRootPath() . '/includes/sef.php');
920                 }
921
922                 // ################### テンプレート読み込み ###################
923                 // テンプレートのポジションタグからウィジェットが実行される
924                 //$templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/index.php';
925                 $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/' . $defaultIndexFile;
926                 if (file_exists($templateIndexFile)){
927                         require_once($templateIndexFile);
928                 } else {                // テンプレートが存在しないとき
929                         if ($this->gEnv->isSystemManageUser()){         // システム管理ユーザのとき
930                                 echo 'template not found error: ' . $curTemplate . ', path=' . $templateIndexFile;
931                         } else {
932                                 // 一般向けにはメンテナンス画面を表示
933                                 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
934                                 $this->_showSystemPage($request, 2/*サイト非公開画面*/);// システム制御画面を表示
935                                                 
936                                 // 運用ログに記録(一度だけ出力したい)
937                                 //$this->gOpeLog->writeFatal(__METHOD__, 'テンプレートが存在しません。メンテナンス画面を表示します。(テンプレートID=' . $curTemplate . ')', 1100);
938                                 return;
939                         }
940                 }
941
942                 // サブクラスの後処理の呼び出し
943                 if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
944
945                 // 現在の出力内容を取得し、一旦内容をクリア
946                 $srcContents = ob_get_contents();
947                 ob_clean();
948
949                 // Joomla!タグの変換処理(ウィジェット実行)
950                 if ($convType >= 1){            // Joomla!v1.5,v2.5テンプレートのとき
951                         $srcContents = $this->gPage->launchWidgetByJoomlaTag($srcContents, $convType);
952                 }
953         
954                 // 遅延実行ウィジェットの出力を埋め込む。HTMLヘッダ出力する。
955                 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
956
957                 // 携帯インターフェイスのときのときは、手動変換後、バイナリコード(絵文字等)を埋め込む
958                 if ($convType == -1){                   // 携帯アクセスポイントの場合
959                         // 出力するコードに変換
960                         $destContents = mb_convert_encoding($destContents, $mobileEncoding, M3_ENCODING);
961         
962                         // コンテンツ変換メソッドがある場合は実行
963                         if (method_exists($this, '_convContents')){
964                                 $destContents = $this->_convContents($destContents);// 絵文字埋め込み処理等
965                         }
966                 }
967                 
968                 // ##### CSS生成の場合は、すべてのウィジェット実行後出力を削除する #####
969                 if ($cmd == M3_REQUEST_CMD_CSS) $destContents = '';             // CSS生成のとき
970
971                 // ページ作成終了処理(HTTPヘッダ出力)
972                 $destContents .= $this->gPage->endPage($request, true/*出力を取得*/);              // 最終HTMLを追加
973                 if ($this->gPage->isRedirect()) return '';// リダイレクトの場合ob_end_clean()を実行すると、ログインできないことがあるのでここで終了(2011/11/11)
974                 
975                 // バッファを破棄
976                 //ob_end_flush();
977                 ob_end_clean();
978
979                 // 送信データを返す
980                 return $destContents;
981         }
982         /**
983          * テンプレートを決定
984          *
985          * @param RequestManager $request       HTTPリクエスト処理クラス
986          * @param string $subTemplateId         テンプレートIDが取得できるときはサブページIDが返る
987          * @return string                                       テンプレート名
988          */
989         function _defineTemplate($request, &$subTemplateId)
990         {
991                 // ########### テンプレートID(ディレクトリ名)を設定 ############
992                 // テンプレートIDの指定の方法は2パターン
993                 //  1.サブクラスで固定に指定
994                 //  2.コンテンツからの指定
995                 //  3.セッションに保持
996                 // テンプレートIDの優先順位
997                 //  1.サブクラスの_setTemplate()で固定設定にしている場合の固定値
998                 //  2.セッションに持っている値
999                 //  3.DBのデフォルト値
1000                 $curTemplate = '';
1001                 $subTemplateId = '';
1002                 $isSystemManageUser = $this->gEnv->isSystemManageUser();                // システム運用可能かどうか
1003                 $useSubClassDefine = true;                      // サブクラスでの定義を使用するかどうか
1004                 
1005                 // テンプレート変更のときは、セッションのテンプレートIDを変更
1006                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);               // 実行コマンドを取得
1007                 if ($cmd == M3_REQUEST_CMD_CHANGE_TEMPLATE){
1008                         // テンプレートIDをセッションに残す場合
1009                         if ($this->gSystem->useTemplateIdInSession()){          // セッションに保存する場合
1010                                 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $request->trimValueOf(M3_SYSTEM_TAG_CHANGE_TEMPLATE));
1011                         }
1012                 }
1013
1014                 // サブクラスでテンプレートIDを指定している場合はそちらを使用
1015                 $templateDefined = false;               // テンプレート固定かどうか
1016                 if ($useSubClassDefine){
1017                         $tmplStr = trim($this->_setTemplate($request));
1018                         if (strlen($tmplStr) > 0){
1019                                 $curTemplate = $tmplStr;
1020                                 $templateDefined = true;                // テンプレート固定かどうか
1021                         }
1022                 }
1023
1024                 // セッションにあるときは、セッションの値を使用(携帯でないとき)
1025                 $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1026                 if (empty($curTemplate)){
1027                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
1028                                 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
1029                                 // URLの引数として、ページIDとページサブIDが指定されてくる
1030                                 // URLの引数のテンプレートを優先し、引数で指定されていなければ、ページ用個別のテンプレートを取得する
1031                                 
1032                                 // URLの引数でテンプレートIDが指定されている場合は設定
1033                                 $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);              // テンプレートIDを取得
1034                                 if (!empty($templateId)) $curTemplate = $templateId;
1035                                         
1036                                 // ページ用個別に設定されたテンプレートがある場合は取得
1037                                 if (empty($curTemplate)){
1038                                         $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1039                                         $line = $this->gPage->getPageInfo($pageId, $pageSubId);
1040                                         if (!empty($line)){
1041                                                 $pageTemplateId = $line['pn_template_id'];
1042                                                 $subTemplateId = $line['pn_sub_template_id'];           // サブテンプレートID
1043                                         }
1044                                         if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
1045                                 }
1046                                 
1047                                 // 取得できなければデフォルトを取得
1048                                 if (empty($curTemplate)){
1049                                         if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
1050                                                 $curTemplate = $this->gSystem->defaultTemplateId();
1051                                                 $subTemplateId = $this->gSystem->defaultSubTemplateId();
1052                                         } else if ($pageId == $this->gEnv->getDefaultMobilePageId()){           // 携帯サイトのとき
1053                                                 $curTemplate = $this->gSystem->defaultMobileTemplateId();               // 携帯用デフォルトテンプレート
1054                                         } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
1055                                                 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId();           // スマートフォン用デフォルトテンプレート
1056                                         } else if ($pageId == $this->gEnv->getDefaultAdminPageId() ||           // 管理サイトのとき
1057                                                                 $pageId == $this->gEnv->getDefaultRegistPageId()){              // 登録サイトのとき
1058                                                 $curTemplate = $this->gSystem->defaultAdminTemplateId();
1059                                         } else if (empty($pageId)){                     // ページIDが指定されていないときは、ウィジェットを表示しないテンプレートのみの表示
1060                                                 // URLの引数でテンプレートIDが指定されている場合は設定
1061         //                                      $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);              // テンプレートIDを取得
1062         //                                      if (!empty($templateId)) $curTemplate = $templateId;
1063                                         }
1064                                 }
1065                         } else {
1066                                 // ページ用のテンプレートがあるときは優先
1067                                 $pageTemplateId = $this->gPage->getTemplateIdFromCurrentPageInfo($subTemplateId);
1068                                 if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
1069
1070                                 // テンプレートIDをセッションから取得
1071                                 if (empty($curTemplate) && !$isSystemManageUser){                       // システム運用者はセッション値を使用できない
1072                                         if ($this->gSystem->useTemplateIdInSession()){          // セッションに保存する場合
1073                                                 if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite()){
1074                                                         $curTemplate = $request->getSessionValue(M3_SESSION_CURRENT_TEMPLATE);// 携帯サイト、スマートフォンサイトでないときはセッション値を取得
1075                                                 }
1076                                         }
1077                                 }
1078                                 
1079                                 // オプションのテンプレートがある場合はオプションを優先
1080                                 $optionTemplate = $this->gPage->getOptionTemplateId();
1081                                 if (!empty($optionTemplate)){
1082                                         $curTemplate = $optionTemplate;
1083                                         $templateDefined = true;                // テンプレート固定かどうか
1084                                 }
1085                                 
1086                                 // セッションにないときはデフォルトを取得
1087                                 if (empty($curTemplate)){
1088                                         if ($this->gEnv->getIsMobileSite()){// 携帯用サイトの場合
1089                                                 $curTemplate = $this->gSystem->defaultMobileTemplateId();               // 携帯用デフォルトテンプレート
1090                                         } else if ($this->gEnv->getIsSmartphoneSite()){// スマートフォン用サイトの場合
1091                                                 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId();           // スマートフォン用デフォルトテンプレート
1092                                         } else {
1093                                                 $curTemplate = $this->gSystem->defaultTemplateId();
1094                                                 $subTemplateId = $this->gSystem->defaultSubTemplateId();
1095                                         }
1096                                 }
1097                         }
1098                 }
1099
1100                 if (empty($curTemplate)){
1101                         // テンプレートが1つもみつからないときは、管理用テンプレートを使用
1102                         $curTemplate = $this->gSystem->defaultAdminTemplateId();
1103                         echo 'template not found. viewing by administration template. [' . $curTemplate . ']';
1104                 } else {        // セッションにテンプレートIDを保存
1105                         // テンプレートIDをセッションに残す場合
1106 /*                      if ($this->gSystem->useTemplateIdInSession()){          // セッションに保存する場合
1107                                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
1108                                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
1109                                 } else {
1110                                         if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite() && !$templateDefined){               // PC用画面でサブクラス固定でないとき場合は保存
1111                                                 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $curTemplate);
1112                                         }
1113                                 }
1114                         }*/
1115                 }
1116                 return $curTemplate;
1117         }
1118         /**
1119          * サイト公開制御
1120          *
1121          * @param RequestManager $request               HTTPリクエスト処理クラス
1122          * @return bool                                                 サイトにアクセスできるかどうか
1123          */
1124         function _accessSite($request)
1125         {
1126                 // サイトの公開状況を取得
1127                 $isOpen = $this->gSystem->siteInPublic();
1128                 if ($isOpen){
1129                         // PC用サイト、携帯用サイト、スマートフォン用サイトの公開状況をチェック
1130                         if ($this->gEnv->getIsPcSite()){
1131                                 if ($this->gSystem->sitePcInPublic()) return true;
1132                         } else if ($this->gEnv->getIsMobileSite()){
1133                                 if ($this->gSystem->siteMobileInPublic()) return true;
1134                         } else if ($this->gEnv->getIsSmartphoneSite()){
1135                                 if ($this->gSystem->siteSmartphoneInPublic()) return true;
1136                         }
1137                         return false;
1138                 } else {
1139                         // 例外とするIPアドレスをチェック
1140                         $ip = $this->gSystem->getSystemConfig(self::SITE_ACCESS_EXCEPTION_IP);
1141                         if (!empty($ip) && $ip = $request->trimServerValueOf('REMOTE_ADDR')){
1142                                 return true;
1143                         } else {
1144                                 return false;
1145                         }
1146                 }
1147         }
1148         /**
1149          * システム制御画面表示
1150          *
1151          * @param RequestManager $request               HTTPリクエスト処理クラス
1152          * @param int $type                                             画面タイプ(0=アクセス不可、1=ログイン画面、2=サイト非公開画面)
1153          * @return なし
1154          */
1155         function _showSystemPage($request, $type)
1156         {
1157                 // ページIDを設定
1158                 $pageId = 'admin_index';                // 管理画面を表示
1159                 $this->gEnv->setCurrentPageId($pageId);                                                         // ここでデフォルトページサブIDが再設定される
1160                 $this->gEnv->setCurrentPageSubId($this->gEnv->getDefaultPageSubId());// デフォルトページサブIDをカレントにする
1161                 
1162                 // テンプレートの設定
1163                 // DBで設定されている値を取得し、なければ管理用デフォルトテンプレートを使用
1164                 if ($this->gEnv->getIsMobileSite()){            // 携帯用サイトのアクセスの場合
1165                         $curTemplateId = self::M_ADMIN_TEMPLATE;        // 携帯管理画面用テンプレート
1166                 } else {                        // 携帯以外のサイトへのアクセスの場合
1167                         if ($type == 1){                        // ログインはデフォルトの管理画面テンプレートに固定
1168                                 $curTemplateId = $this->gSystem->defaultAdminTemplateId();
1169                         } else {
1170                                 $curTemplateId = $this->gSystem->getSystemConfig(self::CONFIG_KEY_MSG_TEMPLATE);
1171                                 if (empty($curTemplateId)){
1172                                         $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
1173                                 } else {
1174                                         // テンプレートの存在チェック
1175                                         $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplateId . '/index.php';
1176                                         if (!file_exists($templateIndexFile)) $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
1177                                 }
1178                         }
1179                 }
1180
1181                 // 画面を作成
1182                 $pageData = $this->_createPage($request, $curTemplateId);
1183                 echo $pageData;
1184         }
1185         /**
1186          * phpinfo画面表示
1187          *
1188          * @param RequestManager $request               HTTPリクエスト処理クラス
1189          * @return なし
1190          */
1191         function _showPhpinfoPage($request)
1192         {
1193                 // ################### バッファリング開始 ######################
1194                 // ob_end_flush()までの出力をバッファリングする
1195                 ob_start();
1196                 
1197                 phpinfo();
1198                 
1199                 // バッファ内容を送信(クライアントへの送信完了)
1200                 ob_end_flush();
1201         }
1202         /**
1203          * 以下、Joomla!v1.5テンプレート専用
1204          */
1205         /**
1206          * ウィジェット数を取得
1207          *
1208          * @param string $pos           ポジション
1209          * @return int                          ウィジェット数
1210          */
1211         function countModules($pos)
1212         {
1213                 $count = $this->gPage->getWidgetsCount($pos);
1214                 return $count;
1215         }
1216         function getBuffer($type = null, $name = null, $attribs = array())
1217         {
1218                 if (isset($this->joomlaBufArray[$type])){
1219                         return $this->joomlaBufArray[$type];
1220                 } else {
1221                         return '';
1222                 }
1223         }
1224         function setBuffer($contents, $type, $name = null)
1225         {
1226                 $this->joomlaBufArray[$type] = $contents;
1227                 return;
1228         }
1229         /**
1230          * 出力タイプ取得
1231          *
1232          * @return string                               出力タイプ
1233          */
1234         function getType()
1235         {
1236                 return 'html';
1237         }
1238         /**
1239          * HTMLヘッダ情報取得
1240          *
1241          * @return array                                ヘッダ情報
1242          */
1243         function getHeadData()
1244         {
1245                 $data = array();
1246                 /*$data['title']                = $this->title;
1247                 $data['description']= $this->description;
1248                 $data['link']           = $this->link;
1249                 $data['metaTags']       = $this->_metaTags;
1250                 $data['links']          = $this->_links;
1251                 $data['styleSheets']= $this->_styleSheets;
1252                 $data['style']          = $this->_style;
1253                 $data['scripts']        = $this->_scripts;
1254                 $data['script']         = $this->_script;
1255                 $data['custom']         = $this->_custom;*/
1256                 return $data;
1257         }
1258         /**
1259          * BASEタグ設定用
1260          *
1261          * @return string                               ベースパス
1262          */
1263         function getBase()
1264         {
1265                 return '';
1266         }
1267          /**
1268          * Adds a linked script to the page
1269          *
1270          * @param       string  $url            URL to the linked script
1271          * @param       string  $type           Type of script. Defaults to 'text/javascript'
1272          * @access   public
1273          */
1274         function addScript($url, $type="text/javascript") {
1275                 $this->_scripts[$url] = $type;
1276         }
1277         /**
1278          * Adds a script to the page
1279          *
1280          * @access   public
1281          * @param       string  $content   Script
1282          * @param       string  $type   Scripting mime (defaults to 'text/javascript')
1283          * @return   void
1284          */
1285         function addScriptDeclaration($content, $type = 'text/javascript')
1286         {
1287                 if (!isset($this->_script[strtolower($type)])) {
1288                         $this->_script[strtolower($type)] = $content;
1289                 } else {
1290                         $this->_script[strtolower($type)] .= chr(13).$content;
1291                 }
1292         }
1293         /**
1294          * WordPressテンプレートの起動ファイルパスを相対パスに変換
1295          *
1296          * @param string $templateId    テンプレートID
1297          * @param string $path                  テンプレートの起動ファイル絶対パス
1298          * @return string                               テンプレート内での相対パス。エラー発生の場合はデフォルト(index.php)を返す。
1299          */
1300         function _getRelativeTemplateIndexPath($templateId, $path)
1301         {
1302                 $savedPath = $path;
1303                 $templatePath = $this->gEnv->getTemplatesPath() . '/' . $templateId . '/';
1304                 
1305                 // テンプレートまでのパスを削除
1306                 $path = str_replace($templatePath, '', $path);
1307                 if ($path == $savedPath) $path = 'index.php';
1308                 return $path;
1309         }
1310         /**
1311          * 旧システムディレクトリが存在するかどうかを取得
1312          *
1313          * @return bool                         true=存在する、false=存在しない
1314          */
1315         function _isExistsOldSystemDir()
1316         {
1317                 // 旧システムディレクトリは同ディレクト階層に存在し、ディレクトリ名の先頭に「_」が付加されているディレクトリ
1318                 $currentDir = $this->gEnv->getSystemRootPath();
1319                 $parentDir = dirname($currentDir);
1320                 $dirName = basename($currentDir);
1321                 if (is_dir($parentDir . '/_' . $dirName)){
1322                         return true;
1323                 } else {
1324                         return false;
1325                 }
1326         }
1327 }
1328 ?>