7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2015 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
14 * @link http://www.magic3.org
16 require_once(M3_SYSTEM_INCLUDE_PATH . '/db/systemDb.php'); // システムDBアクセスクラス
17 require_once(M3_SYSTEM_INCLUDE_PATH . '/common/core.php');
19 class BaseFrameContainer extends Core
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)
34 function __construct()
37 parent::__construct();
40 $this->_db = $this->gInstance->getSytemDbObject();
43 * 起動マネージャから呼ばれる唯一のメソッド
45 * @param RequestManager $request HTTPリクエスト処理クラス
47 function process($request)
50 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); // 実行コマンドを取得
52 // インストール画面への制御は、install.phpファイルの作成、削除で制御する
53 // 最小限の設定が行われていない場合,DBに接続できない場合は、インストール画面へ
54 if (!defined('M3_STATE_IN_INSTALL')){
55 if (($this->gEnv->canUseDb() && $this->gSystem->canInitSystem()) || // システム初期化モードのとき
56 !$this->gConfig->isConfigured()){ // 設定ファイルに設定がないとき(初回インストール)
59 $this->gInstance->getFileManager()->recoverInstaller();
61 $this->gPage->redirectToInstall();
63 } else if ($this->gConfig->isConfigured() && !$this->gEnv->canUseDb()){ // DB接続失敗のとき
64 if ($this->gEnv->isAdminDirAccess()){ // 管理画面の場合のみインストーラ起動
66 $this->gInstance->getFileManager()->recoverInstaller();
68 $this->gPage->redirectToInstall();
71 $this->gPage->showError(500);
78 //$this->gLog->info(__METHOD__, 'フレーム作成開始');
81 // セッション変数読み込み。サブページIDの設定。
82 $this->gPage->startPage($request);
85 $isSystemAdmin = $this->gEnv->isSystemAdmin(); // 管理者権限があるかどうか
86 $isSystemManageUser = $this->gEnv->isSystemManageUser(); // システム運用可能かどうか
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);
97 $lang = $request->getCookieValue(M3_COOKIE_LANG);
101 if (in_array($lang, $this->gSystem->getAcceptLanguage())){
102 $this->gEnv->setCurrentLanguage($lang);
105 $request->setCookieValue(M3_COOKIE_LANG, $lang);
106 } else { // アクセス不可の場合はクッキーを削除
108 $request->setCookieValue(M3_COOKIE_LANG, '', -1);
112 $request->setCookieValue(M3_COOKIE_LANG, '', -1);
115 $this->gPage->loadLang();
117 // ################### URLアクセス制御 ######################
118 // 非公開URLへは管理権限がないとアクセスできない
119 $canAccess = true; // アクセス可能かどうか
120 $isErrorAccess = false; // 不正アクセスかどうか
121 $toAdminType = 0; // 管理画面の遷移タイプ(0=アクセス不可、1=ログイン画面、2=サイト非公開画面, 3=存在しないページ)
122 $errMessage = ''; // エラーメッセージ
123 $messageDetail = ''; // 詳細メッセージ
125 // ページID,ページサブIDからアクセス権をチェック
126 $isPublicUrl = $this->gPage->canAccessUrl($isActivePage);
127 if (!$isPublicUrl && !$isSystemManageUser){// システム運用可能ユーザかどうか
129 $isErrorAccess = true; // 不正アクセスかどうか
130 $errMessage = 'ユーザに公開されていないページへのアクセス。';
132 if (!$isActivePage) $toAdminType = 3; // 有効なアクセスポイントでない場合は存在しないページとする
135 // ################### ユーザアクセス制御 ######################
136 // クッキーがないため権限を識別できない場合でも、管理者として処理する場合があるので、サブクラスの_checkAccess()メソッドは必ず通るようにする
137 if ($canAccess){ // アクセス可能な場合はユーザをチェック
138 if (method_exists($this, '_checkAccess')){
140 $canAccess = $this->_checkAccess($request); // サブクラスメソッドの呼び出し
142 // 一般画面から直接管理画面が呼ばれた場合は一旦ログインへ遷移
144 ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェットの設定
145 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET)){ // 表示位置を表示するとき(ウィジェット付き)
147 $toAdminType = 1; // ログイン画面へ
149 } else { // _checkAccess()がないときは、標準のアクセス制御
151 $canAccess = $this->_accessSite($request); // サイト公開制御
153 if ($cmd == M3_REQUEST_CMD_LOGIN || // ログイン画面を表示のとき
154 $cmd == M3_REQUEST_CMD_LOGOUT){ // ログアウトのとき
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生成
169 // 標準のアクセスでは、上記コマンド以外は受け付けない
171 $isErrorAccess = true; // 不正アクセス
172 $errMessage = '不正なコマンドの実行。';
173 $messageDetail = 'アクセスポイント状態=公開';
175 } else { // サイトアクセスできない場合は、管理画面でメッセージを表示
176 if ($cmd == M3_REQUEST_CMD_LOGIN || // ログイン画面を表示のとき
177 $cmd == M3_REQUEST_CMD_LOGOUT || // ログアウトのとき
178 $cmd == M3_REQUEST_CMD_PREVIEW){ // サイトのプレビューを表示
179 $toAdminType = 1; // ログイン画面へ
181 $toAdminType = 2; // サイト非公開画面へ
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生成
197 $isErrorAccess = true; // 不正アクセス
198 $errMessage = '不正なコマンドの実行。';
199 $messageDetail = 'アクセスポイント状態=非公開';
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 システム管理者のみに変更
208 // #################### アクセスログ記録 #######################
209 // DBが使用可能であれば、ログイン処理終了後、アクセスログを残す
210 if ($this->gEnv->canUseDb()) $this->gAccess->accessLog();
214 switch ($toAdminType){
217 $this->gPage->setSystemHandleMode(1/*管理画面*/);
220 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
222 case 3: // 存在しないページ画面へ(システム運用可能ユーザ以外)
223 // サイトが非公開の場合は、メンテナンス中画面のみ表示
224 if ($this->_accessSite($request)){ // サイト公開中の場合
225 $messageDetail = 'アクセスポイント状態=公開';
226 $this->gPage->setSystemHandleMode(12/*存在しないページ*/);
228 $messageDetail = 'アクセスポイント状態=非公開';
229 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
232 default: // アクセス不可画面へ
234 $this->gPage->setSystemHandleMode(11/*アクセス不可*/);
238 $this->_showSystemPage($request, $toAdminType);
240 // 不正アクセスの場合は、アクセスエラーログを残す
241 if ($isErrorAccess) $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2200, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
244 // #################### URLの遷移 #######################
245 //if ($this->gSystem->getSystemConfig(self::CF_MOBILE_AUTO_REDIRECT)){ // 携帯自動遷移を行う場合
246 if ($this->gSystem->mobileAutoRedirect()){ // 携帯自動遷移を行う場合
248 if ($this->gEnv->isMobile() && !$this->gEnv->getIsMobileSite()){
249 $this->gPage->redirect($this->gEnv->getDefaultMobileUrl(true/*携帯用パラメータ付加*/), true/*遷移時のダイアログ表示を抑止*/);
253 if ($this->gSystem->smartphoneAutoRedirect()){ // スマートフォン自動遷移を行う場合
254 // スマートフォンのときはスマートフォンURLへ遷移
255 if ($this->gEnv->isSmartphone() && !$this->gEnv->getIsSmartphoneSite()){
256 $this->gPage->redirect($this->gEnv->getDefaultSmartphoneUrl());
262 // ################## 実行コマンドから処理を確定 ##################
263 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY); // ウィンドウオープンタイプ
265 // 画面作成モードか、ウィジェット単体処理モードかを決定
266 $createPage = true; // 画面作成モード
267 if ($cmd == M3_REQUEST_CMD_INIT_DB){ // DB初期化オペレーションのとき
268 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION){ // 表示位置を表示するとき
270 //if ($this->gEnv->isSystemAdmin()){
272 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
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);
280 $this->gPage->showPosition(1); // ポジションを表示
284 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
286 //if ($this->gEnv->isSystemAdmin()){
288 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
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);
296 $this->gPage->showPosition(2); // ウィジェット付きポジションを表示
300 } else if ($cmd == M3_REQUEST_CMD_GET_WIDGET_INFO){ // ウィジェット各種情報取得(AJAX用)
302 $this->gPage->getWidgetInfoByAjax($request);
304 } else if ($cmd == M3_REQUEST_CMD_SHOW_PHPINFO){ // phpinfoの表示
306 $this->_showPhpinfoPage($request);
308 } else if ($cmd == M3_REQUEST_CMD_FIND_WIDGET){ // ウィジェットを検索し、前面表示
309 // 目的のウィジェットのあるページサブIDへ遷移
310 $this->gPage->redirectToUpdatedPageSubId($request);
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; // ウィジェット単体処理モードに設定
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生成
327 } else if ($this->gEnv->isServerConnector()){ // サーバ接続の場合
328 $createPage = false; // ウィジェット単体処理モードに設定
331 // ################### クライアントへの出力方法の制御 ######################
333 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
334 if ($createPage){ // 通常の画面作成の場合
336 $this->gCache->initCache($request); // キャッシュ機能初期化
337 $cacheData = $this->gCache->getPageCache($request);
339 if (empty($cacheData)){ // キャッシュデータがないときは画面を作成
341 $curTemplateId = $this->_defineTemplate($request, $subTemplateId);
344 $pageData = $this->_createPage($request, $curTemplateId, $subTemplateId);
346 // 使用した非共通ウィジェットの数をチェック
347 $nonSharedWidgetCount = $this->gPage->getNonSharedWidgetCount();
348 if ($nonSharedWidgetCount == -1){ // カウントなしの場合
349 $this->gCache->setPageCache($request, $pageData); // キャッシュデータを設定
352 if ($isSystemAdmin || $nonSharedWidgetCount > 0){
353 $this->gCache->setPageCache($request, $pageData); // キャッシュデータを設定
355 } else { // 管理者以外で、非共通のウィジェットが使用されていないページはアクセス不可とする
356 $errMessage = 'ユーザに公開されていないページへのアクセス。';
357 $messageDetail = 'アクセスポイント状態=公開, 要因: 共有ウィジェットのみのページへのアクセスは不可。';
358 $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2200, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
361 $this->gPage->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
363 //$this->gPage->setSystemHandleMode(11/*アクセス不可*/);
366 //$this->_showSystemPage($request, 0/*アクセス不可画面*/);
373 if ($cmd != M3_REQUEST_CMD_CSS){ // 画面出力(CSS生成以外)のとき
375 echo $this->gPage->getOptionContents($request);
377 } else { // ウィジェット単体実行モードのとき
378 // ###################ウィジェット指定で出力の場合####################
379 // ウィジェット単体を直接実行するインターフェイスで、HTTPヘッダは送信しない。
381 // ・Ajaxを使って、データをやり取りしたい場合
382 // ・ウィジェット単体での実行(ウィジェットが生成したタグのみ)
383 // ・ウィジェット単体での実行(HTMLやJavascriptの追加あり)
384 // ・ウィジェット個別の設定(セキュリティの必要あり)
386 // ################# アクセスチェック ################
387 // ウィジェット単体オペレーションのときは、ウィジェット情報の単体実行許可があるかどうか判断(管理権限にかかわらず同じ動作)
388 if ($cmd == M3_REQUEST_CMD_DO_WIDGET || // ウィジェット単体実行
389 $cmd == M3_REQUEST_CMD_RSS){ // RSS配信
390 if ($this->_db->getWidgetInfo($widgetId, $row)){
391 if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !$row['wd_enable_operation']){ // ウィジェット単体実行
393 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
395 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは単体起動できません。(ウィジェットID: ' . $widgetId . ')', 2200,
396 '実行処理はキャンセルされました。このウィジェットは単体起動できないウィジェットです。単体起動を許可するにはウィジェット情報(_widgets)の単体起動フラグ(wd_enable_operation)がtrueになっている必要があります。');
398 } else if ($cmd == M3_REQUEST_CMD_RSS && !$row['wd_has_rss']){ // RSS配信
400 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
402 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットはRSS配信できません。(ウィジェットID: ' . $widgetId . ')', 2200,
403 '実行処理はキャンセルされました。このウィジェットはRSS配信できないウィジェットです。RSS配信を許可するにはウィジェット情報(_widgets)のRSS配信フラグ(wd_has_rss)がtrueになっている必要があります。');
407 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは実行許可がありません。(ウィジェットID: ' . $widgetId . ')', 2200,
408 '実行処理はキャンセルされました。ウィジェット情報(_widgets)が見つかりません。');
413 // 管理権限がない場合は、ウィジェットのページへの配置状況からアクセス権限をチェックする
414 if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && !$this->_db->canAccessWidget($widgetId)){
416 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
418 $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットへの不正なアクセスを検出しました。(ウィジェットID: ' . $widgetId . ')', 2200,
419 '実行処理はキャンセルされました。このウィジェットは一般ユーザに公開されているページ上に存在しないため単体実行できません。');
423 // ################# パラメータチェック ################
424 if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && $this->gEnv->isServerConnector()){ // サーバ接続の場合
425 // クエリーパラメータはウィジェットIDのみ正常とする
426 $params = $this->gRequest->getQueryArray();
427 $paramCount = count($params);
428 if (!($paramCount == 1 && !empty($params[M3_REQUEST_PARAM_WIDGET_ID]))){
430 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
432 $this->gOpeLog->writeUserAccess(__METHOD__, 'サーバ接続アクセスポイントへの不正なアクセスを検出しました。', 2200,
433 '実行処理はキャンセルされました。URLのクエリー部が不正です。URL=' . $this->gEnv->getCurrentRequestUri());
438 // 画面表示する場合はテンプレートを設定。画面に表示しない場合はテンプレートが必要ない。
439 if ($this->gPage->getShowWidget()){
441 //$curTemplate = $this->_defineTemplate($request);
442 $curTemplate = $this->gSystem->defaultAdminTemplateId();
445 $this->gEnv->setCurrentTemplateId($curTemplate);
448 // ################### バッファリング開始 ######################
449 // ob_end_flush()までの出力をバッファリングする
453 if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
456 $this->gEnv->setCurrentWidgetId($widgetId);
458 if ($this->gEnv->isServerConnector()){ // サーバ接続の場合
459 // ウィジェット用のHTMLヘッダを出力
460 $this->gPage->startWidgetXml($cmd);
463 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
465 if (file_exists($widgetIndexFile)){
467 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
469 require_once($widgetIndexFile);
471 echo 'file not found: ' . $widgetIndexFile;
475 $this->gPage->endWidgetXml($cmd);
476 } else if ($cmd == M3_REQUEST_CMD_RSS){ // RSS配信のとき
479 // ウィジェット用のHTMLヘッダを出力
480 $this->gPage->startWidgetRss($cmd);
483 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
485 if (file_exists($widgetIndexFile)){
486 // ウィジェット定義ID、ページ定義のシリアル番号を取得
487 $configId = 0; // 定義ID
488 $serial = 0; // シリアル番号
489 if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
490 $configId = $row['pd_config_id']; // 定義ID
491 $serial = $row['pd_serial']; // シリアル番号
495 $this->gEnv->setCurrentWidgetConfigId($configId);
498 $this->gEnv->setCurrentPageDefSerial($serial);
501 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
503 require_once($widgetIndexFile);
506 $this->gEnv->setCurrentWidgetConfigId('');
509 $this->gEnv->setCurrentPageDefSerial(0);
511 echo 'file not found: ' . $widgetIndexFile;
514 // 現在のバッファ内容を取得し、バッファを破棄
515 $content = ob_get_contents();
519 $this->gPage->endWidgetRss($cmd, $content);
520 } else { // RSS配信以外のとき
523 // ウィジェット用のHTMLヘッダを出力
524 $this->gPage->startWidget($cmd);
527 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){ // ウィジェット設定のとき
528 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/admin/index.php'; // 管理用画面
530 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
532 if (file_exists($widgetIndexFile)){
533 // ウィジェット定義ID、ページ定義のシリアル番号を取得
534 $configId = 0; // 定義ID
535 $serial = 0; // シリアル番号
536 if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
537 $configId = $row['pd_config_id']; // 定義ID
538 $serial = $row['pd_serial']; // シリアル番号
542 $this->gEnv->setCurrentWidgetConfigId($configId);
545 $this->gEnv->setCurrentPageDefSerial($serial);
548 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
550 require_once($widgetIndexFile);
553 $this->gEnv->setCurrentWidgetConfigId('');
556 $this->gEnv->setCurrentPageDefSerial(0);
558 echo 'file not found: ' . $widgetIndexFile;
561 // 現在のバッファ内容を取得し、バッファを破棄
562 $content = ob_get_contents();
566 $this->gPage->endWidget($cmd, $content);
570 $this->gEnv->setCurrentWidgetId('');
573 if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
575 if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET || // ウィジェットの単体表示
576 $cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェット設定のとき
577 ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy))){ // ウィンドウオープンタイプ指定でウィジェット単体実行のとき
579 // 現在の出力内容を取得し、一旦内容をクリア
580 $srcContents = ob_get_contents();
583 // 追加変換処理。HTMLヘッダ出力する。
584 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
589 // ページ作成終了処理(HTTPヘッダ出力)
590 $this->gPage->endPage($request);
592 if ($cmd != M3_REQUEST_CMD_RSS){ // 画面出力(RSS配信以外)のとき
594 echo $this->gPage->getOptionContents($request);
597 // バッファ内容を送信(クライアントへの送信完了)
600 if (!defined('M3_STATE_IN_INSTALL')){ // インストールモード以外のとき
601 // #################### アクセスログ記録 #######################
602 // DBが使用可能であれば、アクセスログのユーザを登録
603 if ($this->gEnv->canUseDb()) $this->gAccess->accessLogUser();
607 //$this->gLog->info(__METHOD__, 'フレーム作成終了');
612 * @param RequestManager $request HTTPリクエスト処理クラス
613 * @param string $curTemplate テンプレートID
614 * @param string $subTemplateId サブページID
615 * @return string 画面出力
617 function _createPage($request, $curTemplate, $subTemplateId = '')
619 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); // 実行コマンドを取得
622 $this->gEnv->setCurrentTemplateId($curTemplate, $subTemplateId);
625 $convType = 0; // 変換処理タイプ(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
626 if ($this->gEnv->getIsMobileSite()){
627 $convType = -1; // 携帯サイト用変換
629 // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
630 $convType = $this->gEnv->getCurrentTemplateType();
634 if (method_exists($this, '_prepareBuffer')) $this->_prepareBuffer($request);
636 // ################### バッファリング開始 ######################
637 // ob_end_flush()までの出力をバッファリングする
638 if ($convType == -1){// 携帯用サイトの場合は出力エンコーディングを変更
639 $mobileEncoding = $this->gEnv->getMobileEncoding(); // 携帯用エンコーディングを取得
640 mb_http_output($mobileEncoding);
641 ob_start("mb_output_handler"); // 出力のバッファリング開始
647 if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
649 if ($convType >= 1){ // Joomla!v1.5,v2.5テンプレートのとき
651 require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
652 require_once($this->gEnv->getJoomlaRootPath() . '/JParameter.php');
653 require_once($this->gEnv->getJoomlaRootPath() . '/JRender.php');
657 $paramFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/params.ini';
658 if (is_readable($paramFile)){
659 $content = file_get_contents($paramFile);
660 $params = new JParameter($content);
662 $params = new JParameter();
664 // テンプレートヘッダ画像上のテキスト設定(Joomla!テンプレート2.5以降)
665 $params->set('siteTitle', $this->gEnv->getSiteName()); // サイト名
666 $params->set('siteSlogan', $this->gSystem->getSiteDef(M3_TB_FIELD_SITE_SLOGAN)); // サイトスローガン
668 // Joomla!テンプレート共通の設定
672 define('JPATH_BASE', dirname(__FILE__));
673 define('JPATH_SITE', $this->gEnv->getSystemRootPath());
674 define('DS', DIRECTORY_SEPARATOR);
675 $this->language = $this->gEnv->getCurrentLanguage();
676 $this->template = $curTemplate;
677 //$this->baseurl = $this->gEnv->getRootUrl();
678 $this->baseurl = $this->gEnv->getRootUrlByCurrentPage();
679 $this->direction = 'ltr';
680 $this->params = $params;
683 if ($this->gEnv->getCurrentTemplateGenerator() == self::TEMPLATE_GENERATOR_THEMLER){ // Themlerテンプレートの場合はサブテンプレート用のパラメータを設定
684 // JRequest経由でレンダー側にサブテンプレートIDを渡す
685 if (!empty($subTemplateId)) JRequest::injectSetVar('file_template_name', $subTemplateId);
687 // サブテンプレートIDの渡し方は以下の方法もある
689 // if (!empty($subTemplateId)) $this->setBuffer('<!--TEMPLATE ' . $subTemplateId . ' /-->', 'component');
692 // 現在のJoomla!ドキュメントを設定
693 $this->gEnv->setJoomlaDocument($this);
694 } else { // デフォルト(Joomla!v1.0テンプレート)テンプレートのとき(PC用および携帯用)
695 // Joomla!テンプレート共通の設定
699 global $mosConfig_absolute_path;
700 global $mosConfig_live_site;
701 global $mosConfig_sitename;
702 global $mosConfig_favicon;
703 global $mosConfig_sef;
704 global $cur_template;
706 require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
707 require_once($this->gEnv->getJoomlaRootPath() . '/mosFunc.php');
708 require_once($this->gEnv->getJoomlaRootPath() . '/includes/sef.php');
711 // ################### テンプレート読み込み ###################
712 // テンプレートのポジションタグからウィジェットが実行される
713 $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/index.php';
714 if (file_exists($templateIndexFile)){
715 require_once($templateIndexFile);
716 } else { // テンプレートが存在しないとき
717 if ($this->gEnv->isSystemManageUser()){ // システム管理ユーザのとき
718 echo 'template not found error: ' . $curTemplate;
721 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
722 $this->_showSystemPage($request, 2/*サイト非公開画面*/);// システム制御画面を表示
724 // 運用ログに記録(一度だけ出力したい)
725 //$this->gOpeLog->writeFatal(__METHOD__, 'テンプレートが存在しません。メンテナンス画面を表示します。(テンプレートID=' . $curTemplate . ')', 1100);
731 if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
733 // 現在の出力内容を取得し、一旦内容をクリア
734 $srcContents = ob_get_contents();
737 // Joomla!タグの変換処理(ウィジェット実行)
738 if ($convType >= 1){ // Joomla!v1.5,v2.5テンプレートのとき
739 $srcContents = $this->gPage->launchWidgetByJoomlaTag($srcContents, $convType);
742 // 遅延実行ウィジェットの出力を埋め込む。HTMLヘッダ出力する。
743 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
745 // 携帯インターフェイスのときのときは、手動変換後、バイナリコード(絵文字等)を埋め込む
746 if ($convType == -1){ // 携帯アクセスポイントの場合
748 $destContents = mb_convert_encoding($destContents, $mobileEncoding, M3_ENCODING);
750 // コンテンツ変換メソッドがある場合は実行
751 if (method_exists($this, '_convContents')){
752 $destContents = $this->_convContents($destContents);// 絵文字埋め込み処理等
756 // ##### CSS生成の場合は、すべてのウィジェット実行後出力を削除する #####
757 if ($cmd == M3_REQUEST_CMD_CSS) $destContents = ''; // CSS生成のとき
759 // ページ作成終了処理(HTTPヘッダ出力)
760 $destContents .= $this->gPage->endPage($request, true/*出力を取得*/); // 最終HTMLを追加
761 if ($this->gPage->isRedirect()) return '';// リダイレクトの場合ob_end_clean()を実行すると、ログインできないことがあるのでここで終了(2011/11/11)
768 return $destContents;
773 * @param RequestManager $request HTTPリクエスト処理クラス
774 * @param string $subTemplateId テンプレートIDが取得できるときはサブページIDが返る
775 * @return string テンプレート名
777 function _defineTemplate($request, &$subTemplateId)
779 // ########### テンプレートID(ディレクトリ名)を設定 ############
780 // テンプレートIDの指定の方法は2パターン
785 // 1.サブクラスの_setTemplate()で固定設定にしている場合の固定値
790 $isSystemManageUser = $this->gEnv->isSystemManageUser(); // システム運用可能かどうか
791 $useSubClassDefine = true; // サブクラスでの定義を使用するかどうか
793 // テンプレート変更のときは、セッションのテンプレートIDを変更
794 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); // 実行コマンドを取得
795 if ($cmd == M3_REQUEST_CMD_CHANGE_TEMPLATE){
796 // テンプレートIDをセッションに残す場合
797 if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
798 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $request->trimValueOf(M3_SYSTEM_TAG_CHANGE_TEMPLATE));
802 // サブクラスでテンプレートIDを指定している場合はそちらを使用
803 $templateDefined = false; // テンプレート固定かどうか
804 if ($useSubClassDefine){
805 $tmplStr = trim($this->_setTemplate($request));
806 if (strlen($tmplStr) > 0){
807 $curTemplate = $tmplStr;
808 $templateDefined = true; // テンプレート固定かどうか
812 // セッションにあるときは、セッションの値を使用(携帯でないとき)
813 $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
814 if (empty($curTemplate)){
815 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION || // 表示位置を表示するとき
816 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
817 // URLの引数として、ページIDとページサブIDが指定されてくる
818 // URLの引数のテンプレートを優先し、引数で指定されていなければ、ページ用個別のテンプレートを取得する
820 // URLの引数でテンプレートIDが指定されている場合は設定
821 $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID); // テンプレートIDを取得
822 if (!empty($templateId)) $curTemplate = $templateId;
824 // ページ用個別に設定されたテンプレートがある場合は取得
825 if (empty($curTemplate)){
826 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
827 $line = $this->gPage->getPageInfo($pageId, $pageSubId);
829 $pageTemplateId = $line['pn_template_id'];
830 $subTemplateId = $line['pn_sub_template_id']; // サブテンプレートID
832 if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
836 if (empty($curTemplate)){
837 if ($pageId == $this->gEnv->getDefaultPageId()){ // 通常サイトのとき
838 $curTemplate = $this->gSystem->defaultTemplateId();
839 $subTemplateId = $this->gSystem->defaultSubTemplateId();
840 } else if ($pageId == $this->gEnv->getDefaultMobilePageId()){ // 携帯サイトのとき
841 $curTemplate = $this->gSystem->defaultMobileTemplateId(); // 携帯用デフォルトテンプレート
842 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){ // スマートフォン用サイトのとき
843 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId(); // スマートフォン用デフォルトテンプレート
844 } else if ($pageId == $this->gEnv->getDefaultAdminPageId() || // 管理サイトのとき
845 $pageId == $this->gEnv->getDefaultRegistPageId()){ // 登録サイトのとき
846 $curTemplate = $this->gSystem->defaultAdminTemplateId();
847 } else if (empty($pageId)){ // ページIDが指定されていないときは、ウィジェットを表示しないテンプレートのみの表示
848 // URLの引数でテンプレートIDが指定されている場合は設定
849 // $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID); // テンプレートIDを取得
850 // if (!empty($templateId)) $curTemplate = $templateId;
854 // ページ用のテンプレートがあるときは優先
855 $pageTemplateId = $this->gPage->getTemplateIdFromCurrentPageInfo($subTemplateId);
856 if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
858 // テンプレートIDをセッションから取得
859 if (empty($curTemplate) && !$isSystemManageUser){ // システム運用者はセッション値を使用できない
860 if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
861 if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite()){
862 $curTemplate = $request->getSessionValue(M3_SESSION_CURRENT_TEMPLATE);// 携帯サイト、スマートフォンサイトでないときはセッション値を取得
867 // オプションのテンプレートがある場合はオプションを優先
868 $optionTemplate = $this->gPage->getOptionTemplateId();
869 if (!empty($optionTemplate)){
870 $curTemplate = $optionTemplate;
871 $templateDefined = true; // テンプレート固定かどうか
874 // セッションにないときはデフォルトを取得
875 if (empty($curTemplate)){
876 if ($this->gEnv->getIsMobileSite()){// 携帯用サイトの場合
877 $curTemplate = $this->gSystem->defaultMobileTemplateId(); // 携帯用デフォルトテンプレート
878 } else if ($this->gEnv->getIsSmartphoneSite()){// スマートフォン用サイトの場合
879 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId(); // スマートフォン用デフォルトテンプレート
881 $curTemplate = $this->gSystem->defaultTemplateId();
882 $subTemplateId = $this->gSystem->defaultSubTemplateId();
888 if (empty($curTemplate)){
889 // テンプレートが1つもみつからないときは、管理用テンプレートを使用
890 $curTemplate = $this->gSystem->defaultAdminTemplateId();
891 echo 'template not found. viewing by administration template. [' . $curTemplate . ']';
892 } else { // セッションにテンプレートIDを保存
893 // テンプレートIDをセッションに残す場合
894 /* if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
895 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION || // 表示位置を表示するとき
896 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
898 if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite() && !$templateDefined){ // PC用画面でサブクラス固定でないとき場合は保存
899 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $curTemplate);
909 * @param RequestManager $request HTTPリクエスト処理クラス
910 * @return bool サイトにアクセスできるかどうか
912 function _accessSite($request)
915 $isOpen = $this->gSystem->siteInPublic();
917 // PC用サイト、携帯用サイト、スマートフォン用サイトの公開状況をチェック
918 if ($this->gEnv->getIsPcSite()){
919 if ($this->gSystem->sitePcInPublic()) return true;
920 } else if ($this->gEnv->getIsMobileSite()){
921 if ($this->gSystem->siteMobileInPublic()) return true;
922 } else if ($this->gEnv->getIsSmartphoneSite()){
923 if ($this->gSystem->siteSmartphoneInPublic()) return true;
928 $ip = $this->gSystem->getSystemConfig(self::SITE_ACCESS_EXCEPTION_IP);
929 if (!empty($ip) && $ip = $request->trimServerValueOf('REMOTE_ADDR')){
939 * @param RequestManager $request HTTPリクエスト処理クラス
940 * @param int $type 画面タイプ(0=アクセス不可、1=ログイン画面、2=サイト非公開画面)
943 function _showSystemPage($request, $type)
946 $pageId = 'admin_index'; // 管理画面を表示
947 $this->gEnv->setCurrentPageId($pageId); // ここでデフォルトページサブIDが再設定される
948 $this->gEnv->setCurrentPageSubId($this->gEnv->getDefaultPageSubId());// デフォルトページサブIDをカレントにする
951 // DBで設定されている値を取得し、なければ管理用デフォルトテンプレートを使用
952 if ($this->gEnv->getIsMobileSite()){ // 携帯用サイトのアクセスの場合
953 $curTemplateId = self::M_ADMIN_TEMPLATE; // 携帯管理画面用テンプレート
954 } else { // 携帯以外のサイトへのアクセスの場合
955 if ($type == 1){ // ログインはデフォルトの管理画面テンプレートに固定
956 $curTemplateId = $this->gSystem->defaultAdminTemplateId();
958 $curTemplateId = $this->gSystem->getSystemConfig(self::CONFIG_KEY_MSG_TEMPLATE);
959 if (empty($curTemplateId)){
960 $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
963 $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplateId . '/index.php';
964 if (!file_exists($templateIndexFile)) $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
970 $pageData = $this->_createPage($request, $curTemplateId);
976 * @param RequestManager $request HTTPリクエスト処理クラス
979 function _showPhpinfoPage($request)
981 // ################### バッファリング開始 ######################
982 // ob_end_flush()までの出力をバッファリングする
987 // バッファ内容を送信(クライアントへの送信完了)
991 * 以下、Joomla!v1.5テンプレート専用
996 * @param string $pos ポジション
997 * @return int ウィジェット数
999 function countModules($pos)
1001 $count = $this->gPage->getWidgetsCount($pos);
1004 function getBuffer($type = null, $name = null, $attribs = array())
1006 if (isset($this->joomlaBufArray[$type])){
1007 return $this->joomlaBufArray[$type];
1012 function setBuffer($contents, $type, $name = null)
1014 $this->joomlaBufArray[$type] = $contents;
1020 * @return string 出力タイプ
1029 * @return array ヘッダ情報
1031 function getHeadData()
1034 /*$data['title'] = $this->title;
1035 $data['description']= $this->description;
1036 $data['link'] = $this->link;
1037 $data['metaTags'] = $this->_metaTags;
1038 $data['links'] = $this->_links;
1039 $data['styleSheets']= $this->_styleSheets;
1040 $data['style'] = $this->_style;
1041 $data['scripts'] = $this->_scripts;
1042 $data['script'] = $this->_script;
1043 $data['custom'] = $this->_custom;*/
1049 * @return string ベースパス
1056 * Adds a linked script to the page
1058 * @param string $url URL to the linked script
1059 * @param string $type Type of script. Defaults to 'text/javascript'
1062 function addScript($url, $type="text/javascript") {
1063 $this->_scripts[$url] = $type;
1066 * Adds a script to the page
1069 * @param string $content Script
1070 * @param string $type Scripting mime (defaults to 'text/javascript')
1073 function addScriptDeclaration($content, $type = 'text/javascript')
1075 if (!isset($this->_script[strtolower($type)])) {
1076 $this->_script[strtolower($type)] = $content;
1078 $this->_script[strtolower($type)] .= chr(13).$content;