OSDN Git Service

エラーメッセージ修正。
[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-2016 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からアクセス権をチェック
126                         $isPublicUrl = $this->gPage->canAccessUrl($isActivePage);
127                         if (!$isPublicUrl && !$isSystemManageUser){// システム運用可能ユーザかどうか
128                                 $canAccess = false;
129                                 $isErrorAccess = true;          // 不正アクセスかどうか
130                                 $errMessage = 'ユーザに公開されていないページへのアクセス。';
131                                 
132                                 if (!$isActivePage) $toAdminType = 3;           // 有効なアクセスポイントでない場合は存在しないページとする
133                         }
134
135                         // ################### ユーザアクセス制御 ######################
136                         // クッキーがないため権限を識別できない場合でも、管理者として処理する場合があるので、サブクラスの_checkAccess()メソッドは必ず通るようにする
137                         if ($canAccess){                // アクセス可能な場合はユーザをチェック
138                                 if (method_exists($this, '_checkAccess')){
139                                         // 管理画面へのアクセスを制御
140                                         $canAccess = $this->_checkAccess($request);             // サブクラスメソッドの呼び出し
141                                         
142                                         // フロント画面から直接管理画面が呼ばれた場合は一旦ログインへ遷移
143                                         if (!$canAccess && 
144                                                 ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||                                                // ウィジェットの設定
145                                                 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET)){                     // 表示位置を表示するとき(ウィジェット付き)
146                                                 // 管理画面で処理
147                                                 $toAdminType = 1;               // ログイン画面へ
148                                         }
149                                 } else {                        // _checkAccess()がないときは、標準のアクセス制御
150                                         // フロント画面へのアクセスを制御
151                                         $canAccess = $this->_accessSite($request);              // サイト公開制御
152                                         if ($canAccess){
153                                                 if ($cmd == M3_REQUEST_CMD_LOGIN ||                                     // ログイン画面を表示のとき
154                                                         $cmd == M3_REQUEST_CMD_LOGOUT){                         // ログアウトのとき
155
156                                                         // 管理画面で処理
157                                                         $canAccess = false;
158                                                         $toAdminType = 1;               // ログイン画面へ
159                                                 } else if ($cmd != '' &&                                                                // コマンドなし
160                                                         $cmd != M3_REQUEST_CMD_CHANGE_TEMPLATE &&                       // テンプレート変更
161                                                         $cmd != M3_REQUEST_CMD_SHOW_POSITION &&                         // 表示位置を表示するとき
162                                                         $cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET &&     // 表示位置を表示するとき(ウィジェット付き)
163                                                         $cmd != M3_REQUEST_CMD_FIND_WIDGET &&                           // ウィジェットを検索
164                                                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                     // ウィジェット単体実行
165                                                         $cmd != M3_REQUEST_CMD_PREVIEW &&                                       // サイトのプレビューを表示
166                                                         $cmd != M3_REQUEST_CMD_RSS &&                                           // RSS配信
167                                                         $cmd != M3_REQUEST_CMD_CSS){                                            // CSS生成
168                                                         
169                                                         // 標準のアクセスでは、上記コマンド以外は受け付けない
170                                                         $canAccess = false;
171                                                         $isErrorAccess = true;          // 不正アクセス
172                                                         $errMessage = '不正なコマンドの実行。';
173                                                         $messageDetail = 'アクセスポイント状態=公開';
174                                                 }
175                                         } else {                // サイトアクセスできない場合は、管理画面でメッセージを表示
176                                                 if ($cmd == M3_REQUEST_CMD_LOGIN ||                                     // ログイン画面を表示のとき
177                                                         $cmd == M3_REQUEST_CMD_LOGOUT ||                                // ログアウトのとき
178                                                         $cmd == M3_REQUEST_CMD_PREVIEW){                                        // サイトのプレビューを表示
179                                                         $toAdminType = 1;               // ログイン画面へ
180                                                 } else {
181                                                         $toAdminType = 2;               // サイト非公開画面へ
182                                                 }
183                                                 
184                                                 // 不正なコマンドはログを残す
185                                                 if ($cmd != '' &&                                                               // コマンドなし
186                                                         $cmd != M3_REQUEST_CMD_LOGIN &&                         // ログイン画面を表示のとき
187                                                         $cmd != M3_REQUEST_CMD_LOGOUT &&                                        // ログアウトのとき
188                                                         $cmd != M3_REQUEST_CMD_CHANGE_TEMPLATE &&                       // テンプレート変更
189                                                         $cmd != M3_REQUEST_CMD_SHOW_POSITION &&                         // 表示位置を表示するとき
190                                                         $cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET &&     // 表示位置を表示するとき(ウィジェット付き)
191                                                         $cmd != M3_REQUEST_CMD_FIND_WIDGET &&                           // ウィジェットを検索
192                                                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                     // ウィジェット単体実行
193                                                         $cmd != M3_REQUEST_CMD_PREVIEW &&                                       // サイトのプレビューを表示
194                                                         $cmd != M3_REQUEST_CMD_RSS &&                                           // RSS配信
195                                                         $cmd != M3_REQUEST_CMD_CSS){                                            // CSS生成
196                                                         
197                                                         $isErrorAccess = true;          // 不正アクセス
198                                                         $errMessage = '不正なコマンドの実行。';
199                                                         $messageDetail = 'アクセスポイント状態=非公開';
200                                                 }
201                                         }
202                                 }
203                                 // システム運用可能ユーザはアクセス可。
204                                 // ログアウトのときはすでに管理ユーザの可能性があるので、ログアウト時は変更しない
205                                 //if ($isSystemManageUser && $cmd != M3_REQUEST_CMD_LOGOUT) $canAccess = true;
206                                 if ($isSystemAdmin && $cmd != M3_REQUEST_CMD_LOGOUT) $canAccess = true;                 // 2011/8/31 システム管理者のみに変更
207                         }
208                         // #################### アクセスログ記録 #######################
209                         // DBが使用可能であれば、ログイン処理終了後、アクセスログを残す
210                         if ($this->gEnv->canUseDb()) $this->gAccess->accessLog();
211
212                         // アクセス不可のときはここで終了
213                         if (!$canAccess){
214                                 switch ($toAdminType){
215                                         case 1:                 // ログイン画面へ
216                                                 // システム制御モードに変更
217                                                 $this->gPage->setSystemHandleMode(1/*管理画面*/);
218                                                 break;
219                                         case 2:                 // サイト非公開画面へ
220                                                 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
221                                                 break;
222                                         case 3:                 // 存在しないページ画面へ(システム運用可能ユーザ以外)
223                                                 // サイトが非公開の場合は、メンテナンス中画面のみ表示
224                                                 if ($this->_accessSite($request)){              // サイト公開中の場合
225                                                         $messageDetail = 'アクセスポイント状態=公開';
226                                                         $this->gPage->setSystemHandleMode(12/*存在しないページ*/);
227                                                 } else {
228                                                         $messageDetail = 'アクセスポイント状態=非公開';
229                                                         $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
230                                                 }
231                                                 break;
232                                         default:                // アクセス不可画面へ
233                                                 // システム制御モードに変更
234                                                 $this->gPage->setSystemHandleMode(11/*アクセス不可*/);
235                                                 break;
236                                 }
237                                 // システム制御画面を表示
238                                 $this->_showSystemPage($request, $toAdminType);
239                                                 
240                                 // 不正アクセスの場合は、アクセスエラーログを残す
241                                 if ($isErrorAccess) $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2201, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
242                                 return;
243                         }
244                         // #################### URLの遷移 #######################
245                         //if ($this->gSystem->getSystemConfig(self::CF_MOBILE_AUTO_REDIRECT)){          // 携帯自動遷移を行う場合
246                         if ($this->gSystem->mobileAutoRedirect()){              // 携帯自動遷移を行う場合
247                                 // 携帯のときは携帯用URLへ遷移
248                                 if ($this->gEnv->isMobile() && !$this->gEnv->getIsMobileSite()){
249                                         $this->gPage->redirect($this->gEnv->getDefaultMobileUrl(true/*携帯用パラメータ付加*/), true/*遷移時のダイアログ表示を抑止*/);
250                                         return;
251                                 }
252                         }
253                         if ($this->gSystem->smartphoneAutoRedirect()){          // スマートフォン自動遷移を行う場合
254                                 // スマートフォンのときはスマートフォンURLへ遷移
255                                 if ($this->gEnv->isSmartphone() && !$this->gEnv->getIsSmartphoneSite()){
256                                         $this->gPage->redirect($this->gEnv->getDefaultSmartphoneUrl());
257                                         return;
258                                 }
259                         }
260                 }
261
262                 // ################## 実行コマンドから処理を確定 ##################
263                 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
264                 
265                 // 画面作成モードか、ウィジェット単体処理モードかを決定
266                 $createPage = true;             // 画面作成モード
267                 if ($cmd == M3_REQUEST_CMD_INIT_DB){    // DB初期化オペレーションのとき
268                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION){               // 表示位置を表示するとき
269                         // 管理者権限がある場合のみ実行可能
270                         //if ($this->gEnv->isSystemAdmin()){
271                         if ($isSystemAdmin){
272                                 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
273                                 // ページIDを再設定
274                                 $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
275                                 if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId();          // 値がないときはデフォルトのページIDを設定
276                                 $this->gEnv->setCurrentPageId($pageId);
277                                 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
278                                 if (!empty($pageSubId)) $this->gEnv->setCurrentPageSubId($pageSubId);
279                                 
280                                 $this->gPage->showPosition(1);                  // ポジションを表示
281                         } else {
282                                 return;
283                         }
284                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // 表示位置を表示するとき(ウィジェット付き)
285                         // 管理者権限がある場合のみ実行可能
286                         //if ($this->gEnv->isSystemAdmin()){
287                         if ($isSystemAdmin){
288                                 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
289                                 // ページIDを再設定
290                                 $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
291                                 if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId();          // 値がないときはデフォルトのページIDを設定
292                                 $this->gEnv->setCurrentPageId($pageId);
293                                 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
294                                 if (!empty($pageSubId)) $this->gEnv->setCurrentPageSubId($pageSubId);
295                                 
296                                 $this->gPage->showPosition(2);                  // ウィジェット付きポジションを表示
297                         } else {
298                                 return;
299                         }
300                 } else if ($cmd == M3_REQUEST_CMD_GET_WIDGET_INFO){             // ウィジェット各種情報取得(AJAX用)
301                         // ウィジェット情報取得
302                         $this->gPage->getWidgetInfoByAjax($request);
303                         return;
304                 } else if ($cmd == M3_REQUEST_CMD_SHOW_PHPINFO){        // phpinfoの表示
305                         // phpinfo画面を表示
306                         $this->_showPhpinfoPage($request);
307                         return;
308                 } else if ($cmd == M3_REQUEST_CMD_FIND_WIDGET){         // ウィジェットを検索し、前面表示
309                         // 目的のウィジェットのあるページサブIDへ遷移
310                         $this->gPage->redirectToUpdatedPageSubId($request);
311                         return;
312                 } else if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET){         // ウィジェットの単体表示
313                         $createPage = false;            // ウィジェット単体処理モードに設定
314                         $this->gPage->showWidget();     // ウィジェット表示
315                 } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){               // ウィジェットの設定管理
316                         $createPage = false;            // ウィジェット単体処理モードに設定
317                         $this->gPage->showWidget();     // ウィジェット表示
318                 } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){           // ウィジェット単体オペレーション
319                         $createPage = false;            // ウィジェット単体処理モードに設定
320                         
321                         // ウィンドウオープンタイプ指定のときは、テンプレートを表示する
322                         if (!empty($openBy)) $this->gPage->showWidget();        // ウィジェット表示
323                 } else if ($cmd == M3_REQUEST_CMD_RSS){         // RSS配信
324                         $createPage = false;            // ウィジェット単体処理モードに設定
325                 } else if ($cmd == M3_REQUEST_CMD_CSS){         // CSS生成
326                 
327                 } else if ($this->gEnv->isServerConnector()){           // サーバ接続の場合
328                         $createPage = false;            // ウィジェット単体処理モードに設定
329                 }
330
331                 // ################### クライアントへの出力方法の制御 ######################
332                 // ウィジェットIDの取得
333                 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
334                 if ($createPage){                               // 通常の画面作成の場合
335                         // 画面のキャッシュデータを取得
336                         $this->gCache->initCache($request);             // キャッシュ機能初期化
337                         $cacheData = $this->gCache->getPageCache($request);
338                         
339                         if (empty($cacheData)){         // キャッシュデータがないときは画面を作成
340                                 // カレントのテンプレートを決定
341                                 $curTemplateId = $this->_defineTemplate($request, $subTemplateId);
342
343                                 // 画面を作成
344                                 $pageData = $this->_createPage($request, $curTemplateId, $subTemplateId);
345                                 
346                                 // 使用した非共通ウィジェットの数をチェック
347                                 $nonSharedWidgetCount = $this->gPage->getNonSharedWidgetCount();
348                                 if ($nonSharedWidgetCount == -1){               // カウントなしの場合
349                                         $this->gCache->setPageCache($request, $pageData);               // キャッシュデータを設定
350                                         echo $pageData;
351                                 } else {
352                                         if ($isSystemAdmin || $nonSharedWidgetCount > 0){
353                                                 $this->gCache->setPageCache($request, $pageData);               // キャッシュデータを設定
354                                                 echo $pageData;
355                                         } else {                // 管理者以外で、非共通のウィジェットが使用されていないページはアクセス不可とする
356                                                 $errMessage = 'ユーザに公開されていないページへのアクセス。';
357                                                 $messageDetail = 'アクセスポイント状態=公開, 要因: グローバルウィジェットのみのページへのアクセスはできません。ページには1つ以上のローカルウィジェットが必要です。';
358                                                 $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2202, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
359
360                                                 // アクセス不可ページへ遷移
361                                                 $this->gPage->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
362                                                 // システム制御モードに変更
363                                                 //$this->gPage->setSystemHandleMode(11/*アクセス不可*/);
364
365                                                 // システム制御画面を表示
366                                                 //$this->_showSystemPage($request, 0/*アクセス不可画面*/);
367                                         }
368                                 }
369                         } else {
370                                 echo $cacheData;
371                         }
372                         
373                         if ($cmd != M3_REQUEST_CMD_CSS){                // 画面出力(CSS生成以外)のとき
374                                 // オプション出力(時間計測等)追加
375                                 echo $this->gPage->getOptionContents($request);
376                         }
377                 } else {                // ウィジェット単体実行モードのとき
378                         // ###################ウィジェット指定で出力の場合####################
379                         // ウィジェット単体を直接実行するインターフェイスで、HTTPヘッダは送信しない。
380                         // 以下のパターンで使用する。
381                         // ・Ajaxを使って、データをやり取りしたい場合
382                         // ・ウィジェット単体での実行(ウィジェットが生成したタグのみ)
383                         // ・ウィジェット単体での実行(HTMLやJavascriptの追加あり)
384                         // ・ウィジェット個別の設定(セキュリティの必要あり)
385
386                         // ################# アクセスチェック ################
387                         // ウィジェット単体オペレーションのときは、ウィジェット情報の単体実行許可があるかどうか判断(管理権限にかかわらず同じ動作)
388                         if ($cmd == M3_REQUEST_CMD_DO_WIDGET ||         // ウィジェット単体実行
389                                 $cmd == M3_REQUEST_CMD_RSS){            // RSS配信
390                                 if (empty($widgetId)){
391                                         $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットIDが設定されていません。', 2200,
392                                                 '実行処理はキャンセルされました。');
393                                         return;
394                                 } else if ($this->_db->getWidgetInfo($widgetId, $row)){                 // ウィジェット情報取得
395                                         if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !$row['wd_enable_operation']){  // ウィジェット単体実行
396                                                 // アクセスエラーのログを残す
397                                                 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
398                                                 
399                                                 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは単体起動できません。(ウィジェットID: ' . $widgetId . ')', 2200,
400                                                 '実行処理はキャンセルされました。このウィジェットは単体起動できないウィジェットです。単体起動を許可するにはウィジェット情報(_widgets)の単体起動フラグ(wd_enable_operation)がtrueになっている必要があります。');
401                                                 return;
402                                         } else if ($cmd == M3_REQUEST_CMD_RSS && !$row['wd_has_rss']){                          // RSS配信
403                                                 // アクセスエラーのログを残す
404                                                 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
405                                                 
406                                                 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットはRSS配信できません。(ウィジェットID: ' . $widgetId . ')', 2200,
407                                                 '実行処理はキャンセルされました。このウィジェットはRSS配信できないウィジェットです。RSS配信を許可するにはウィジェット情報(_widgets)のRSS配信フラグ(wd_has_rss)がtrueになっている必要があります。');
408                                                 return;
409                                         }
410                                 } else {
411                                         $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは実行許可がありません。(ウィジェットID: ' . $widgetId . ')', 2200,
412                                                 '実行処理はキャンセルされました。ウィジェット情報(_widgets)が見つかりません。');
413                                         return;
414                                 }
415                         }
416                         
417                         // 管理権限がない場合は、ウィジェットのページへの配置状況からアクセス権限をチェックする
418                         if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && !$this->_db->canAccessWidget($widgetId)){
419                                 // アクセスエラーのログを残す
420                                 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
421                                 
422                                 $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットへの不正なアクセスを検出しました。(ウィジェットID: ' . $widgetId . ')', 2200,
423                                                 '実行処理はキャンセルされました。このウィジェットは一般ユーザに公開されているページ上に存在しないため単体実行できません。');
424                                 return;
425                         }
426                         
427                         // ################# パラメータチェック ################
428                         if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && $this->gEnv->isServerConnector()){            // サーバ接続の場合
429                                 // クエリーパラメータはウィジェットIDのみ正常とする
430                                 $params = $this->gRequest->getQueryArray();
431                                 $paramCount = count($params);
432                                 if (!($paramCount == 1 && !empty($params[M3_REQUEST_PARAM_WIDGET_ID]))){
433                                         // アクセスエラーのログを残す
434                                         $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
435                                 
436                                         $this->gOpeLog->writeUserAccess(__METHOD__, 'サーバ接続アクセスポイントへの不正なアクセスを検出しました。', 2200,
437                                                         '実行処理はキャンセルされました。URLのクエリー部が不正です。URL=' . $this->gEnv->getCurrentRequestUri());
438                                         return;
439                                 }
440                         }
441
442                         // 画面表示する場合はテンプレートを設定。画面に表示しない場合はテンプレートが必要ない。
443                         if ($this->gPage->getShowWidget()){
444                                 // 管理用テンプレートに固定
445                                 //$curTemplate = $this->_defineTemplate($request);
446                                 $curTemplate = $this->gSystem->defaultAdminTemplateId();
447
448                                 // カレントのテンプレートIDを設定
449                                 $this->gEnv->setCurrentTemplateId($curTemplate);
450                         }
451                         
452                         // ################### バッファリング開始 ######################
453                         // ob_end_flush()までの出力をバッファリングする
454                         ob_start();
455                         
456                         // サブクラスの前処理を実行
457                         if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
458                 
459                         // 作業中のウィジェットIDを設定
460                         $this->gEnv->setCurrentWidgetId($widgetId);
461                         
462                         if ($this->gEnv->isServerConnector()){          // サーバ接続の場合
463                                 // ウィジェット用のHTMLヘッダを出力
464                                 $this->gPage->startWidgetXml($cmd);
465
466                                 // 指定のウィジェットを実行
467                                 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
468
469                                 if (file_exists($widgetIndexFile)){
470                                         // 実行のログを残す
471                                         $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
472
473                                         require_once($widgetIndexFile);
474                                 } else {
475                                         echo 'file not found: ' . $widgetIndexFile;
476                                 }
477                         
478                                 // ウィジェット用のタグを閉じる
479                                 $this->gPage->endWidgetXml($cmd);
480                         } else if ($cmd == M3_REQUEST_CMD_RSS){         // RSS配信のとき
481                                 ob_start();// バッファ作成
482                                 
483                                 // ウィジェット用のHTMLヘッダを出力
484                                 $this->gPage->startWidgetRss($cmd);
485                                 
486                                 // 指定のウィジェットを実行
487                                 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
488
489                                 if (file_exists($widgetIndexFile)){
490                                         // ウィジェット定義ID、ページ定義のシリアル番号を取得
491                                         $configId = 0;          // 定義ID
492                                         $serial = 0;            // シリアル番号
493                                         if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
494                                                 $configId = $row['pd_config_id'];               // 定義ID
495                                                 $serial = $row['pd_serial'];            // シリアル番号
496                                         }
497
498                                         // ウィジェット定義IDを設定
499                                         $this->gEnv->setCurrentWidgetConfigId($configId);
500                         
501                                         // ページ定義のシリアル番号を設定
502                                         $this->gEnv->setCurrentPageDefSerial($serial);
503                                 
504                                         // 実行のログを残す
505                                         $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
506
507                                         require_once($widgetIndexFile);
508                                         
509                                         // ウィジェット定義IDを解除
510                                         $this->gEnv->setCurrentWidgetConfigId('');
511                                 
512                                         // ページ定義のシリアル番号を解除
513                                         $this->gEnv->setCurrentPageDefSerial(0);
514                                 } else {
515                                         echo 'file not found: ' . $widgetIndexFile;
516                                 }
517                         
518                                 // 現在のバッファ内容を取得し、バッファを破棄
519                                 $content = ob_get_contents();
520                                 ob_end_clean();
521                                 
522                                 // ウィジェット用のタグを閉じる
523                                 $this->gPage->endWidgetRss($cmd, $content);
524                         } else {                // RSS配信以外のとき
525                                 ob_start();// バッファ作成
526                                                         
527                                 // ウィジェット用のHTMLヘッダを出力
528                                 $this->gPage->startWidget($cmd);
529                                 
530                                 // 指定のウィジェットを実行
531                                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット設定のとき
532                                         $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/admin/index.php';                // 管理用画面
533                                 } else {
534                                         $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
535                                 }
536                                 if (file_exists($widgetIndexFile)){
537                                         // ウィジェット定義ID、ページ定義のシリアル番号を取得
538                                         $configId = 0;          // 定義ID
539                                         $serial = 0;            // シリアル番号
540                                         if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
541                                                 $configId = $row['pd_config_id'];               // 定義ID
542                                                 $serial = $row['pd_serial'];            // シリアル番号
543                                         }
544
545                                         // ウィジェット定義IDを設定
546                                         $this->gEnv->setCurrentWidgetConfigId($configId);
547                         
548                                         // ページ定義のシリアル番号を設定
549                                         $this->gEnv->setCurrentPageDefSerial($serial);
550                                         
551                                         // 実行のログを残す
552                                         $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
553
554                                         require_once($widgetIndexFile);
555                                         
556                                         // ウィジェット定義IDを解除
557                                         $this->gEnv->setCurrentWidgetConfigId('');
558                                 
559                                         // ページ定義のシリアル番号を解除
560                                         $this->gEnv->setCurrentPageDefSerial(0);
561                                 } else {
562                                         echo 'file not found: ' . $widgetIndexFile;
563                                 }
564                         
565                                 // 現在のバッファ内容を取得し、バッファを破棄
566                                 $content = ob_get_contents();
567                                 ob_end_clean();
568                                 
569                                 // ウィジェット用のタグを閉じる
570                                 $this->gPage->endWidget($cmd, $content);
571                         }
572                 
573                         // 作業中のウィジェットIDを解除
574                         $this->gEnv->setCurrentWidgetId('');
575                         
576                         // サブクラスの後処理の呼び出し
577                         if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
578                         
579                         if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET ||               // ウィジェットの単体表示
580                                 $cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||         // ウィジェット設定のとき
581                                 ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy))){         // ウィンドウオープンタイプ指定でウィジェット単体実行のとき
582                                 
583                                 // 現在の出力内容を取得し、一旦内容をクリア
584                                 $srcContents = ob_get_contents();
585                                 ob_clean();
586                                 
587                                 // 追加変換処理。HTMLヘッダ出力する。
588                                 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
589                                 
590                                 echo $destContents;
591                         }
592                         
593                         // ページ作成終了処理(HTTPヘッダ出力)
594                         $this->gPage->endPage($request);
595
596                         if ($cmd != M3_REQUEST_CMD_RSS){                // 画面出力(RSS配信以外)のとき
597                                 // オプション出力(時間計測等)追加
598                                 echo $this->gPage->getOptionContents($request);
599                         }
600
601                         // バッファ内容を送信(クライアントへの送信完了)
602                         ob_end_flush();
603                 }
604                 if (!defined('M3_STATE_IN_INSTALL')){           // インストールモード以外のとき
605                         // #################### アクセスログ記録 #######################
606                         // DBが使用可能であれば、アクセスログのユーザを登録
607                         if ($this->gEnv->canUseDb()) $this->gAccess->accessLogUser();
608                 }
609
610                 // 終了ログ出力
611                 //$this->gLog->info(__METHOD__, 'フレーム作成終了');
612         }
613         /**
614          * 画面を作成
615          *
616          * @param RequestManager $request               HTTPリクエスト処理クラス
617          * @param string $curTemplate                   テンプレートID
618          * @param string $subTemplateId                 サブページID
619          * @return string                                               画面出力
620          */
621         function _createPage($request, $curTemplate, $subTemplateId = '')
622         {
623                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);               // 実行コマンドを取得
624                 
625                 // カレントのテンプレートIDを設定
626                 $this->gEnv->setCurrentTemplateId($curTemplate, $subTemplateId);
627
628                 // テンプレート情報を取得
629                 $convType = 0;          // 変換処理タイプ(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
630                 if ($this->gEnv->getIsMobileSite()){
631                         $convType = -1;         // 携帯サイト用変換
632                 } else {
633                         // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
634                         $convType = $this->gEnv->getCurrentTemplateType();
635                 }
636
637                 // バッファリングの準備
638                 if (method_exists($this, '_prepareBuffer')) $this->_prepareBuffer($request);
639         
640                 // ################### バッファリング開始 ######################
641                 // ob_end_flush()までの出力をバッファリングする
642                 if ($convType == -1){// 携帯用サイトの場合は出力エンコーディングを変更
643                         $mobileEncoding = $this->gEnv->getMobileEncoding();             // 携帯用エンコーディングを取得
644                         mb_http_output($mobileEncoding);
645                         ob_start("mb_output_handler"); // 出力のバッファリング開始
646                 } else {
647                         ob_start();
648                 }
649
650                 // サブクラスの前処理を実行
651                 if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
652         
653                 if ($convType >= 1){            // Joomla!v1.5,v2.5テンプレートのとき
654                         global $mainframe;
655                         require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
656                         require_once($this->gEnv->getJoomlaRootPath() . '/JParameter.php');
657                         require_once($this->gEnv->getJoomlaRootPath() . '/JRender.php');
658                                                 
659                         // 設定ファイルの読み込み
660                         //$params = array();
661                         $paramFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/params.ini';
662                         if (is_readable($paramFile)){
663                                 $content = file_get_contents($paramFile);
664                                 $params = new JParameter($content);
665                         } else {
666                                 $params = new JParameter();
667                         }
668                         // テンプレートヘッダ画像上のテキスト設定(Joomla!テンプレート2.5以降)
669                         $params->set('siteTitle',               $this->gEnv->getSiteName());            // サイト名
670                         $params->set('siteSlogan',              $this->gSystem->getSiteDef(M3_TB_FIELD_SITE_SLOGAN));           // サイトスローガン
671                         
672                         // Joomla!テンプレート共通の設定
673                         define('_JEXEC', 1);
674                                                 
675                         // Joomla!v1.5用の設定
676                         define('JPATH_BASE', dirname(__FILE__));
677                         define('JPATH_SITE', $this->gEnv->getSystemRootPath());
678                         define('JPATH_PLUGINS', $gEnvManager->getJoomlaRootPath() . '/class/plugins');                  // プラグインパス
679 //                      define('JPATH_THEMES', $gEnvManager->getTemplatesPath());                                                               // テンプレートパス             ## テンプレート内でエラーが発生するのでここでは定義しない(2015/10/13)
680                         define('DS', DIRECTORY_SEPARATOR);
681                         $this->language = $this->gEnv->getCurrentLanguage();
682                         $this->template = $curTemplate;
683                         //$this->baseurl  = $this->gEnv->getRootUrl();
684                         $this->baseurl          = $this->gEnv->getRootUrlByCurrentPage();
685                         $this->direction = 'ltr';
686                         $this->params   = $params;
687                         
688                         // サブテンプレート用の設定
689                         if ($this->gEnv->getCurrentTemplateGenerator() == self::TEMPLATE_GENERATOR_THEMLER){            // Themlerテンプレートの場合はサブテンプレート用のパラメータを設定
690                                 // JRequest経由でレンダー側にサブテンプレートIDを渡す
691                                 if (!empty($subTemplateId)) JRequest::injectSetVar('file_template_name', $subTemplateId);
692
693                                 // サブテンプレートIDの渡し方は以下の方法もある(Themlerテンプレート1.39以降はこちらが有効)
694                                 // サブテンプレートIDを埋め込む
695                                 if (!empty($subTemplateId)) $this->setBuffer('<!--TEMPLATE ' . $subTemplateId . ' /-->', 'component');
696                         }
697                         
698                         // 現在のJoomla!ドキュメントを設定
699                         $this->gEnv->setJoomlaDocument($this);
700                 } else {                        // デフォルト(Joomla!v1.0テンプレート)テンプレートのとき(PC用および携帯用)
701                         // Joomla!テンプレート共通の設定
702                         define('_JEXEC', 1);
703                         
704                         // Joomlaテンプレート用定義
705                         global $mosConfig_absolute_path;
706                         global $mosConfig_live_site;
707                         global $mosConfig_sitename;
708                         global $mosConfig_favicon;
709                         global $mosConfig_sef;
710                         global $cur_template;
711                         global $mainframe;
712                         require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
713                         require_once($this->gEnv->getJoomlaRootPath() . '/mosFunc.php');
714                         require_once($this->gEnv->getJoomlaRootPath() . '/includes/sef.php');
715                 }
716
717                 // ################### テンプレート読み込み ###################
718                 // テンプレートのポジションタグからウィジェットが実行される
719                 $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/index.php';
720                 if (file_exists($templateIndexFile)){
721                         require_once($templateIndexFile);
722                 } else {                // テンプレートが存在しないとき
723                         if ($this->gEnv->isSystemManageUser()){         // システム管理ユーザのとき
724                                 echo 'template not found error: ' . $curTemplate;
725                         } else {
726                                 // 一般向けにはメンテナンス画面を表示
727                                 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
728                                 $this->_showSystemPage($request, 2/*サイト非公開画面*/);// システム制御画面を表示
729                                                 
730                                 // 運用ログに記録(一度だけ出力したい)
731                                 //$this->gOpeLog->writeFatal(__METHOD__, 'テンプレートが存在しません。メンテナンス画面を表示します。(テンプレートID=' . $curTemplate . ')', 1100);
732                                 return;
733                         }
734                 }
735
736                 // サブクラスの後処理の呼び出し
737                 if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
738
739                 // 現在の出力内容を取得し、一旦内容をクリア
740                 $srcContents = ob_get_contents();
741                 ob_clean();
742
743                 // Joomla!タグの変換処理(ウィジェット実行)
744                 if ($convType >= 1){            // Joomla!v1.5,v2.5テンプレートのとき
745                         $srcContents = $this->gPage->launchWidgetByJoomlaTag($srcContents, $convType);
746                 }
747         
748                 // 遅延実行ウィジェットの出力を埋め込む。HTMLヘッダ出力する。
749                 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
750
751                 // 携帯インターフェイスのときのときは、手動変換後、バイナリコード(絵文字等)を埋め込む
752                 if ($convType == -1){                   // 携帯アクセスポイントの場合
753                         // 出力するコードに変換
754                         $destContents = mb_convert_encoding($destContents, $mobileEncoding, M3_ENCODING);
755         
756                         // コンテンツ変換メソッドがある場合は実行
757                         if (method_exists($this, '_convContents')){
758                                 $destContents = $this->_convContents($destContents);// 絵文字埋め込み処理等
759                         }
760                 }
761                 
762                 // ##### CSS生成の場合は、すべてのウィジェット実行後出力を削除する #####
763                 if ($cmd == M3_REQUEST_CMD_CSS) $destContents = '';             // CSS生成のとき
764
765                 // ページ作成終了処理(HTTPヘッダ出力)
766                 $destContents .= $this->gPage->endPage($request, true/*出力を取得*/);              // 最終HTMLを追加
767                 if ($this->gPage->isRedirect()) return '';// リダイレクトの場合ob_end_clean()を実行すると、ログインできないことがあるのでここで終了(2011/11/11)
768                 
769                 // バッファを破棄
770                 //ob_end_flush();
771                 ob_end_clean();
772
773                 // 送信データを返す
774                 return $destContents;
775         }
776         /**
777          * テンプレートを決定
778          *
779          * @param RequestManager $request       HTTPリクエスト処理クラス
780          * @param string $subTemplateId         テンプレートIDが取得できるときはサブページIDが返る
781          * @return string                                       テンプレート名
782          */
783         function _defineTemplate($request, &$subTemplateId)
784         {
785                 // ########### テンプレートID(ディレクトリ名)を設定 ############
786                 // テンプレートIDの指定の方法は2パターン
787                 //  1.サブクラスで固定に指定
788                 //  2.コンテンツからの指定
789                 //  3.セッションに保持
790                 // テンプレートIDの優先順位
791                 //  1.サブクラスの_setTemplate()で固定設定にしている場合の固定値
792                 //  2.セッションに持っている値
793                 //  3.DBのデフォルト値
794                 $curTemplate = '';
795                 $subTemplateId = '';
796                 $isSystemManageUser = $this->gEnv->isSystemManageUser();                // システム運用可能かどうか
797                 $useSubClassDefine = true;                      // サブクラスでの定義を使用するかどうか
798                 
799                 // テンプレート変更のときは、セッションのテンプレートIDを変更
800                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);               // 実行コマンドを取得
801                 if ($cmd == M3_REQUEST_CMD_CHANGE_TEMPLATE){
802                         // テンプレートIDをセッションに残す場合
803                         if ($this->gSystem->useTemplateIdInSession()){          // セッションに保存する場合
804                                 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $request->trimValueOf(M3_SYSTEM_TAG_CHANGE_TEMPLATE));
805                         }
806                 }
807
808                 // サブクラスでテンプレートIDを指定している場合はそちらを使用
809                 $templateDefined = false;               // テンプレート固定かどうか
810                 if ($useSubClassDefine){
811                         $tmplStr = trim($this->_setTemplate($request));
812                         if (strlen($tmplStr) > 0){
813                                 $curTemplate = $tmplStr;
814                                 $templateDefined = true;                // テンプレート固定かどうか
815                         }
816                 }
817
818                 // セッションにあるときは、セッションの値を使用(携帯でないとき)
819                 $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
820                 if (empty($curTemplate)){
821                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
822                                 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
823                                 // URLの引数として、ページIDとページサブIDが指定されてくる
824                                 // URLの引数のテンプレートを優先し、引数で指定されていなければ、ページ用個別のテンプレートを取得する
825                                 
826                                 // URLの引数でテンプレートIDが指定されている場合は設定
827                                 $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);              // テンプレートIDを取得
828                                 if (!empty($templateId)) $curTemplate = $templateId;
829                                         
830                                 // ページ用個別に設定されたテンプレートがある場合は取得
831                                 if (empty($curTemplate)){
832                                         $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
833                                         $line = $this->gPage->getPageInfo($pageId, $pageSubId);
834                                         if (!empty($line)){
835                                                 $pageTemplateId = $line['pn_template_id'];
836                                                 $subTemplateId = $line['pn_sub_template_id'];           // サブテンプレートID
837                                         }
838                                         if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
839                                 }
840                                 
841                                 // 取得できなければデフォルトを取得
842                                 if (empty($curTemplate)){
843                                         if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
844                                                 $curTemplate = $this->gSystem->defaultTemplateId();
845                                                 $subTemplateId = $this->gSystem->defaultSubTemplateId();
846                                         } else if ($pageId == $this->gEnv->getDefaultMobilePageId()){           // 携帯サイトのとき
847                                                 $curTemplate = $this->gSystem->defaultMobileTemplateId();               // 携帯用デフォルトテンプレート
848                                         } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
849                                                 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId();           // スマートフォン用デフォルトテンプレート
850                                         } else if ($pageId == $this->gEnv->getDefaultAdminPageId() ||           // 管理サイトのとき
851                                                                 $pageId == $this->gEnv->getDefaultRegistPageId()){              // 登録サイトのとき
852                                                 $curTemplate = $this->gSystem->defaultAdminTemplateId();
853                                         } else if (empty($pageId)){                     // ページIDが指定されていないときは、ウィジェットを表示しないテンプレートのみの表示
854                                                 // URLの引数でテンプレートIDが指定されている場合は設定
855         //                                      $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);              // テンプレートIDを取得
856         //                                      if (!empty($templateId)) $curTemplate = $templateId;
857                                         }
858                                 }
859                         } else {
860                                 // ページ用のテンプレートがあるときは優先
861                                 $pageTemplateId = $this->gPage->getTemplateIdFromCurrentPageInfo($subTemplateId);
862                                 if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
863
864                                 // テンプレートIDをセッションから取得
865                                 if (empty($curTemplate) && !$isSystemManageUser){                       // システム運用者はセッション値を使用できない
866                                         if ($this->gSystem->useTemplateIdInSession()){          // セッションに保存する場合
867                                                 if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite()){
868                                                         $curTemplate = $request->getSessionValue(M3_SESSION_CURRENT_TEMPLATE);// 携帯サイト、スマートフォンサイトでないときはセッション値を取得
869                                                 }
870                                         }
871                                 }
872                                 
873                                 // オプションのテンプレートがある場合はオプションを優先
874                                 $optionTemplate = $this->gPage->getOptionTemplateId();
875                                 if (!empty($optionTemplate)){
876                                         $curTemplate = $optionTemplate;
877                                         $templateDefined = true;                // テンプレート固定かどうか
878                                 }
879                                 
880                                 // セッションにないときはデフォルトを取得
881                                 if (empty($curTemplate)){
882                                         if ($this->gEnv->getIsMobileSite()){// 携帯用サイトの場合
883                                                 $curTemplate = $this->gSystem->defaultMobileTemplateId();               // 携帯用デフォルトテンプレート
884                                         } else if ($this->gEnv->getIsSmartphoneSite()){// スマートフォン用サイトの場合
885                                                 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId();           // スマートフォン用デフォルトテンプレート
886                                         } else {
887                                                 $curTemplate = $this->gSystem->defaultTemplateId();
888                                                 $subTemplateId = $this->gSystem->defaultSubTemplateId();
889                                         }
890                                 }
891                         }
892                 }
893
894                 if (empty($curTemplate)){
895                         // テンプレートが1つもみつからないときは、管理用テンプレートを使用
896                         $curTemplate = $this->gSystem->defaultAdminTemplateId();
897                         echo 'template not found. viewing by administration template. [' . $curTemplate . ']';
898                 } else {        // セッションにテンプレートIDを保存
899                         // テンプレートIDをセッションに残す場合
900 /*                      if ($this->gSystem->useTemplateIdInSession()){          // セッションに保存する場合
901                                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
902                                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
903                                 } else {
904                                         if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite() && !$templateDefined){               // PC用画面でサブクラス固定でないとき場合は保存
905                                                 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $curTemplate);
906                                         }
907                                 }
908                         }*/
909                 }
910                 return $curTemplate;
911         }
912         /**
913          * サイト公開制御
914          *
915          * @param RequestManager $request               HTTPリクエスト処理クラス
916          * @return bool                                                 サイトにアクセスできるかどうか
917          */
918         function _accessSite($request)
919         {
920                 // サイトの公開状況を取得
921                 $isOpen = $this->gSystem->siteInPublic();
922                 if ($isOpen){
923                         // PC用サイト、携帯用サイト、スマートフォン用サイトの公開状況をチェック
924                         if ($this->gEnv->getIsPcSite()){
925                                 if ($this->gSystem->sitePcInPublic()) return true;
926                         } else if ($this->gEnv->getIsMobileSite()){
927                                 if ($this->gSystem->siteMobileInPublic()) return true;
928                         } else if ($this->gEnv->getIsSmartphoneSite()){
929                                 if ($this->gSystem->siteSmartphoneInPublic()) return true;
930                         }
931                         return false;
932                 } else {
933                         // 例外とするIPアドレスをチェック
934                         $ip = $this->gSystem->getSystemConfig(self::SITE_ACCESS_EXCEPTION_IP);
935                         if (!empty($ip) && $ip = $request->trimServerValueOf('REMOTE_ADDR')){
936                                 return true;
937                         } else {
938                                 return false;
939                         }
940                 }
941         }
942         /**
943          * システム制御画面表示
944          *
945          * @param RequestManager $request               HTTPリクエスト処理クラス
946          * @param int $type                                             画面タイプ(0=アクセス不可、1=ログイン画面、2=サイト非公開画面)
947          * @return なし
948          */
949         function _showSystemPage($request, $type)
950         {
951                 // ページIDを設定
952                 $pageId = 'admin_index';                // 管理画面を表示
953                 $this->gEnv->setCurrentPageId($pageId);                                                         // ここでデフォルトページサブIDが再設定される
954                 $this->gEnv->setCurrentPageSubId($this->gEnv->getDefaultPageSubId());// デフォルトページサブIDをカレントにする
955                 
956                 // テンプレートの設定
957                 // DBで設定されている値を取得し、なければ管理用デフォルトテンプレートを使用
958                 if ($this->gEnv->getIsMobileSite()){            // 携帯用サイトのアクセスの場合
959                         $curTemplateId = self::M_ADMIN_TEMPLATE;        // 携帯管理画面用テンプレート
960                 } else {                        // 携帯以外のサイトへのアクセスの場合
961                         if ($type == 1){                        // ログインはデフォルトの管理画面テンプレートに固定
962                                 $curTemplateId = $this->gSystem->defaultAdminTemplateId();
963                         } else {
964                                 $curTemplateId = $this->gSystem->getSystemConfig(self::CONFIG_KEY_MSG_TEMPLATE);
965                                 if (empty($curTemplateId)){
966                                         $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
967                                 } else {
968                                         // テンプレートの存在チェック
969                                         $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplateId . '/index.php';
970                                         if (!file_exists($templateIndexFile)) $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
971                                 }
972                         }
973                 }
974
975                 // 画面を作成
976                 $pageData = $this->_createPage($request, $curTemplateId);
977                 echo $pageData;
978         }
979         /**
980          * phpinfo画面表示
981          *
982          * @param RequestManager $request               HTTPリクエスト処理クラス
983          * @return なし
984          */
985         function _showPhpinfoPage($request)
986         {
987                 // ################### バッファリング開始 ######################
988                 // ob_end_flush()までの出力をバッファリングする
989                 ob_start();
990                 
991                 phpinfo();
992                 
993                 // バッファ内容を送信(クライアントへの送信完了)
994                 ob_end_flush();
995         }
996         /**
997          * 以下、Joomla!v1.5テンプレート専用
998          */
999         /**
1000          * ウィジェット数を取得
1001          *
1002          * @param string $pos           ポジション
1003          * @return int                          ウィジェット数
1004          */
1005         function countModules($pos)
1006         {
1007                 $count = $this->gPage->getWidgetsCount($pos);
1008                 return $count;
1009         }
1010         function getBuffer($type = null, $name = null, $attribs = array())
1011         {
1012                 if (isset($this->joomlaBufArray[$type])){
1013                         return $this->joomlaBufArray[$type];
1014                 } else {
1015                         return '';
1016                 }
1017         }
1018         function setBuffer($contents, $type, $name = null)
1019         {
1020                 $this->joomlaBufArray[$type] = $contents;
1021                 return;
1022         }
1023         /**
1024          * 出力タイプ取得
1025          *
1026          * @return string                               出力タイプ
1027          */
1028         function getType()
1029         {
1030                 return 'html';
1031         }
1032         /**
1033          * HTMLヘッダ情報取得
1034          *
1035          * @return array                                ヘッダ情報
1036          */
1037         function getHeadData()
1038         {
1039                 $data = array();
1040                 /*$data['title']                = $this->title;
1041                 $data['description']= $this->description;
1042                 $data['link']           = $this->link;
1043                 $data['metaTags']       = $this->_metaTags;
1044                 $data['links']          = $this->_links;
1045                 $data['styleSheets']= $this->_styleSheets;
1046                 $data['style']          = $this->_style;
1047                 $data['scripts']        = $this->_scripts;
1048                 $data['script']         = $this->_script;
1049                 $data['custom']         = $this->_custom;*/
1050                 return $data;
1051         }
1052         /**
1053          * BASEタグ設定用
1054          *
1055          * @return string                               ベースパス
1056          */
1057         function getBase()
1058         {
1059                 return '';
1060         }
1061          /**
1062          * Adds a linked script to the page
1063          *
1064          * @param       string  $url            URL to the linked script
1065          * @param       string  $type           Type of script. Defaults to 'text/javascript'
1066          * @access   public
1067          */
1068         function addScript($url, $type="text/javascript") {
1069                 $this->_scripts[$url] = $type;
1070         }
1071         /**
1072          * Adds a script to the page
1073          *
1074          * @access   public
1075          * @param       string  $content   Script
1076          * @param       string  $type   Scripting mime (defaults to 'text/javascript')
1077          * @return   void
1078          */
1079         function addScriptDeclaration($content, $type = 'text/javascript')
1080         {
1081                 if (!isset($this->_script[strtolower($type)])) {
1082                         $this->_script[strtolower($type)] = $content;
1083                 } else {
1084                         $this->_script[strtolower($type)] .= chr(13).$content;
1085                 }
1086         }
1087 }
1088 ?>