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