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-2017 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以外のURLパラメータをチェック。ページマネージャーでの処理(startPage())の結果を反映。
126 $ret = $this->gPage->isSystemPage(); // システム制御ページへ遷移するかどうか
133 // ページID,ページサブIDからアクセス権をチェック
135 $isPublicUrl = $this->gPage->canAccessUrl($isActivePage, $errCode);
136 if (!$isPublicUrl && !$isSystemManageUser){// システム運用可能ユーザかどうか
138 $isErrorAccess = true; // 不正アクセスかどうか
139 $errMessage = 'ユーザに公開されていないページへのアクセス。';
142 if ($errCode == 1){ // ページIDが不正な場合
145 $toAdminType = 3; // 有効なアクセスポイント、ページでない場合は存在しないページとする
151 // ################### ユーザアクセス制御 ######################
152 // クッキーがないため権限を識別できない場合でも、管理者として処理する場合があるので、サブクラスの_checkAccess()メソッドは必ず通るようにする
153 if ($canAccess){ // アクセス可能な場合はユーザをチェック
154 if (method_exists($this, '_checkAccess')){
156 $canAccess = $this->_checkAccess($request); // サブクラスメソッドの呼び出し
158 // フロント画面から直接管理画面が呼ばれた場合は一旦ログインへ遷移
160 ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェットの設定
161 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET)){ // 表示位置を表示するとき(ウィジェット付き)
163 $toAdminType = 1; // ログイン画面へ
165 } else { // _checkAccess()がないときは、標準のアクセス制御
167 $canAccess = $this->_accessSite($request); // サイト公開制御
169 if ($cmd == M3_REQUEST_CMD_LOGIN || // ログイン画面を表示のとき
170 $cmd == M3_REQUEST_CMD_LOGOUT){ // ログアウトのとき
174 $toAdminType = 1; // ログイン画面へ
175 } else if ($cmd != '' && // コマンドなし
176 $cmd != M3_REQUEST_CMD_CHANGE_TEMPLATE && // テンプレート変更
177 $cmd != M3_REQUEST_CMD_SHOW_POSITION && // 表示位置を表示するとき
178 $cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET && // 表示位置を表示するとき(ウィジェット付き)
179 $cmd != M3_REQUEST_CMD_FIND_WIDGET && // ウィジェットを検索
180 $cmd != M3_REQUEST_CMD_DO_WIDGET && // ウィジェット単体実行
181 $cmd != M3_REQUEST_CMD_PREVIEW && // サイトのプレビューを表示
182 $cmd != M3_REQUEST_CMD_RSS && // RSS配信
183 $cmd != M3_REQUEST_CMD_CSS){ // CSS生成
185 // 標準のアクセスでは、上記コマンド以外は受け付けない
187 $isErrorAccess = true; // 不正アクセス
188 $errMessage = '不正なコマンドの実行。';
189 $messageDetail = 'アクセスポイント状態=公開';
191 } else { // サイトアクセスできない場合は、管理画面でメッセージを表示
192 if ($cmd == M3_REQUEST_CMD_LOGIN || // ログイン画面を表示のとき
193 $cmd == M3_REQUEST_CMD_LOGOUT || // ログアウトのとき
194 $cmd == M3_REQUEST_CMD_PREVIEW){ // サイトのプレビューを表示
195 $toAdminType = 1; // ログイン画面へ
197 $toAdminType = 2; // サイト非公開画面へ
201 if ($cmd != '' && // コマンドなし
202 $cmd != M3_REQUEST_CMD_LOGIN && // ログイン画面を表示のとき
203 $cmd != M3_REQUEST_CMD_LOGOUT && // ログアウトのとき
204 $cmd != M3_REQUEST_CMD_CHANGE_TEMPLATE && // テンプレート変更
205 $cmd != M3_REQUEST_CMD_SHOW_POSITION && // 表示位置を表示するとき
206 $cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET && // 表示位置を表示するとき(ウィジェット付き)
207 $cmd != M3_REQUEST_CMD_FIND_WIDGET && // ウィジェットを検索
208 $cmd != M3_REQUEST_CMD_DO_WIDGET && // ウィジェット単体実行
209 $cmd != M3_REQUEST_CMD_PREVIEW && // サイトのプレビューを表示
210 $cmd != M3_REQUEST_CMD_RSS && // RSS配信
211 $cmd != M3_REQUEST_CMD_CSS){ // CSS生成
213 $isErrorAccess = true; // 不正アクセス
214 $errMessage = '不正なコマンドの実行。';
215 $messageDetail = 'アクセスポイント状態=非公開';
219 // システム運用可能ユーザはアクセス可。
220 // ログアウトのときはすでに管理ユーザの可能性があるので、ログアウト時は変更しない
221 //if ($isSystemManageUser && $cmd != M3_REQUEST_CMD_LOGOUT) $canAccess = true;
222 if ($isSystemAdmin && $cmd != M3_REQUEST_CMD_LOGOUT) $canAccess = true; // 2011/8/31 システム管理者のみに変更
224 // #################### アクセスログ記録 #######################
225 // DBが使用可能であれば、ログイン処理終了後、アクセスログを残す
226 if ($this->gEnv->canUseDb()) $this->gAccess->accessLog();
230 switch ($toAdminType){
233 $this->gPage->setSystemHandleMode(1/*管理画面*/);
236 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
238 case 3: // 存在しないページ画面へ(システム運用可能ユーザ以外)
239 // サイトが非公開の場合は、メンテナンス中画面のみ表示
240 if ($this->_accessSite($request)){ // サイト公開中の場合
241 $messageDetail = 'アクセスポイント状態=公開';
242 $this->gPage->setSystemHandleMode(12/*存在しないページ*/);
244 $messageDetail = 'アクセスポイント状態=非公開';
245 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
248 case 4: // 不正なページIDの指定
249 $messageDetail = '不正なページIDの指定';
250 $this->gPage->setSystemHandleMode(12/*存在しないページ*/);
252 default: // アクセス不可画面へ
254 $this->gPage->setSystemHandleMode(11/*アクセス不可*/);
258 $this->_showSystemPage($request, $toAdminType);
260 // 不正アクセスの場合は、アクセスエラーログを残す
261 if ($isErrorAccess) $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2201, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
264 // #################### URLの遷移 #######################
265 //if ($this->gSystem->getSystemConfig(self::CF_MOBILE_AUTO_REDIRECT)){ // 携帯自動遷移を行う場合
266 if ($this->gSystem->mobileAutoRedirect()){ // 携帯自動遷移を行う場合
268 if ($this->gEnv->isMobile() && !$this->gEnv->getIsMobileSite()){
269 $this->gPage->redirect($this->gEnv->getDefaultMobileUrl(true/*携帯用パラメータ付加*/), true/*遷移時のダイアログ表示を抑止*/);
273 if ($this->gSystem->smartphoneAutoRedirect()){ // スマートフォン自動遷移を行う場合
274 // スマートフォンのときはスマートフォンURLへ遷移
275 if ($this->gEnv->isSmartphone() && !$this->gEnv->getIsSmartphoneSite()){
276 $this->gPage->redirect($this->gEnv->getDefaultSmartphoneUrl());
282 // ################## 実行コマンドから処理を確定 ##################
283 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY); // ウィンドウオープンタイプ
285 // 画面作成モードか、ウィジェット単体処理モードかを決定
286 $createPage = true; // 画面作成モード
287 if ($cmd == M3_REQUEST_CMD_INIT_DB){ // DB初期化オペレーションのとき
288 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION){ // 表示位置を表示するとき
290 //if ($this->gEnv->isSystemAdmin()){
292 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
294 /* $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
295 if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId(); // 値がないときはデフォルトのページIDを設定
296 $this->gEnv->setCurrentPageId($pageId);
297 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
298 if (!empty($pageSubId)) $this->gEnv->setCurrentPageSubId($pageSubId);
300 $this->gPage->showPosition(1); // ポジションを表示
304 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
306 //if ($this->gEnv->isSystemAdmin()){
308 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
310 /* $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
311 if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId(); // 値がないときはデフォルトのページIDを設定
312 $this->gEnv->setCurrentPageId($pageId);
313 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
314 if (!empty($pageSubId)) $this->gEnv->setCurrentPageSubId($pageSubId);
316 $this->gPage->showPosition(2); // ウィジェット付きポジションを表示
320 } else if ($cmd == M3_REQUEST_CMD_GET_WIDGET_INFO){ // ウィジェット各種情報取得(AJAX用)
322 $this->gPage->getWidgetInfoByAjax($request);
324 } else if ($cmd == M3_REQUEST_CMD_SHOW_PHPINFO){ // phpinfoの表示
326 $this->_showPhpinfoPage($request);
328 } else if ($cmd == M3_REQUEST_CMD_FIND_WIDGET){ // ウィジェットを検索し、前面表示
329 // 目的のウィジェットのあるページサブIDへ遷移
330 $this->gPage->redirectToUpdatedPageSubId($request);
332 } else if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET){ // ウィジェットの単体表示
333 $createPage = false; // ウィジェット単体処理モードに設定
334 $this->gPage->showWidget(); // ウィジェット表示
335 } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){ // ウィジェットの設定管理
336 $createPage = false; // ウィジェット単体処理モードに設定
337 $this->gPage->showWidget(); // ウィジェット表示
338 } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){ // ウィジェット単体オペレーション
339 $createPage = false; // ウィジェット単体処理モードに設定
341 // ウィンドウオープンタイプ指定のときは、テンプレートを表示する
342 if (!empty($openBy)) $this->gPage->showWidget(); // ウィジェット表示
343 } else if ($cmd == M3_REQUEST_CMD_RSS){ // RSS配信
344 $createPage = false; // ウィジェット単体処理モードに設定
345 } else if ($cmd == M3_REQUEST_CMD_CSS){ // CSS生成
347 } else if ($this->gEnv->isServerConnector()){ // サーバ接続の場合
348 $createPage = false; // ウィジェット単体処理モードに設定
351 // ################### クライアントへの出力方法の制御 ######################
353 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
354 if ($createPage){ // 通常の画面作成の場合
356 $this->gCache->initCache($request); // キャッシュ機能初期化
357 $cacheData = $this->gCache->getPageCache($request);
359 if (empty($cacheData)){ // キャッシュデータがないときは画面を作成
361 $curTemplateId = $this->_defineTemplate($request, $subTemplateId);
364 $pageData = $this->_createPage($request, $curTemplateId, $subTemplateId);
366 // 使用した非共通ウィジェットの数をチェック
367 $nonSharedWidgetCount = $this->gPage->getNonSharedWidgetCount();
368 if ($nonSharedWidgetCount == -1){ // カウントなしの場合
369 $this->gCache->setPageCache($request, $pageData); // キャッシュデータを設定
372 if ($isSystemAdmin || $nonSharedWidgetCount > 0){
373 $this->gCache->setPageCache($request, $pageData); // キャッシュデータを設定
375 } else { // 管理者以外で、非共通のウィジェットが使用されていないページはアクセス不可とする
376 $errMessage = 'ユーザに公開されていないページへのアクセス。';
377 $messageDetail = 'アクセスポイント状態=公開, 要因: グローバルウィジェットのみのページへのアクセスはできません。ページには1つ以上のローカルウィジェットが必要です。';
378 $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2202, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
381 $this->gPage->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
383 //$this->gPage->setSystemHandleMode(11/*アクセス不可*/);
386 //$this->_showSystemPage($request, 0/*アクセス不可画面*/);
393 if ($cmd != M3_REQUEST_CMD_CSS){ // 画面出力(CSS生成以外)のとき
395 echo $this->gPage->getOptionContents($request);
397 } else { // ウィジェット単体実行モードのとき
398 // ###################ウィジェット指定で出力の場合####################
399 // ウィジェット単体を直接実行するインターフェイスで、HTTPヘッダは送信しない。
401 // ・Ajaxを使って、データをやり取りしたい場合
402 // ・ウィジェット単体での実行(ウィジェットが生成したタグのみ)
403 // ・ウィジェット単体での実行(HTMLやJavascriptの追加あり)
404 // ・ウィジェット個別の設定(セキュリティの必要あり)
406 // ################# アクセスチェック ################
407 // ウィジェット単体オペレーションのときは、ウィジェット情報の単体実行許可があるかどうか判断(管理権限にかかわらず同じ動作)
408 if ($cmd == M3_REQUEST_CMD_DO_WIDGET || // ウィジェット単体実行
409 $cmd == M3_REQUEST_CMD_RSS){ // RSS配信
410 if (empty($widgetId)){
411 $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットIDが設定されていません。', 2200,
414 } else if ($this->_db->getWidgetInfo($widgetId, $row)){ // ウィジェット情報取得
415 if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !$row['wd_enable_operation']){ // ウィジェット単体実行
417 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
419 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは単体起動できません。(ウィジェットID: ' . $widgetId . ')', 2200,
420 '実行処理はキャンセルされました。このウィジェットは単体起動できないウィジェットです。単体起動を許可するにはウィジェット情報(_widgets)の単体起動フラグ(wd_enable_operation)がtrueになっている必要があります。');
422 } else if ($cmd == M3_REQUEST_CMD_RSS && !$row['wd_has_rss']){ // RSS配信
424 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
426 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットはRSS配信できません。(ウィジェットID: ' . $widgetId . ')', 2200,
427 '実行処理はキャンセルされました。このウィジェットはRSS配信できないウィジェットです。RSS配信を許可するにはウィジェット情報(_widgets)のRSS配信フラグ(wd_has_rss)がtrueになっている必要があります。');
431 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは実行許可がありません。(ウィジェットID: ' . $widgetId . ')', 2200,
432 '実行処理はキャンセルされました。ウィジェット情報(_widgets)が見つかりません。');
437 // 管理権限がない場合は、ウィジェットのページへの配置状況からアクセス権限をチェックする
438 if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && !$this->_db->canAccessWidget($widgetId)){
440 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
442 $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットへの不正なアクセスを検出しました。(ウィジェットID: ' . $widgetId . ')', 2200,
443 '実行処理はキャンセルされました。このウィジェットは一般ユーザに公開されているページ上に存在しないため単体実行できません。');
447 // ################# パラメータチェック ################
448 if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && $this->gEnv->isServerConnector()){ // サーバ接続の場合
449 // クエリーパラメータはウィジェットIDのみ正常とする
450 $params = $this->gRequest->getQueryArray();
451 $paramCount = count($params);
452 if (!($paramCount == 1 && !empty($params[M3_REQUEST_PARAM_WIDGET_ID]))){
454 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
456 $this->gOpeLog->writeUserAccess(__METHOD__, 'サーバ接続アクセスポイントへの不正なアクセスを検出しました。', 2200,
457 '実行処理はキャンセルされました。URLのクエリー部が不正です。URL=' . $this->gEnv->getCurrentRequestUri());
462 // 画面表示する場合はテンプレートを設定。画面に表示しない場合はテンプレートが必要ない。
463 if ($this->gPage->getShowWidget()){
465 //$curTemplate = $this->_defineTemplate($request);
466 $curTemplate = $this->gSystem->defaultAdminTemplateId();
469 $this->gEnv->setCurrentTemplateId($curTemplate);
472 // ################### バッファリング開始 ######################
473 // ob_end_flush()までの出力をバッファリングする
477 if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
480 $this->gEnv->setCurrentWidgetId($widgetId);
482 if ($this->gEnv->isServerConnector()){ // サーバ接続の場合
483 // ウィジェット用のHTMLヘッダを出力
484 $this->gPage->startWidgetXml($cmd);
487 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
489 if (file_exists($widgetIndexFile)){
491 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
493 require_once($widgetIndexFile);
495 echo 'file not found: ' . $widgetIndexFile;
499 $this->gPage->endWidgetXml($cmd);
500 } else if ($cmd == M3_REQUEST_CMD_RSS){ // RSS配信のとき
503 // ウィジェット用のHTMLヘッダを出力
504 $this->gPage->startWidgetRss($cmd);
507 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
509 if (file_exists($widgetIndexFile)){
510 // ウィジェット定義ID、ページ定義のシリアル番号を取得
511 $configId = 0; // 定義ID
512 $serial = 0; // シリアル番号
513 if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
514 $configId = $row['pd_config_id']; // 定義ID
515 $serial = $row['pd_serial']; // シリアル番号
519 $this->gEnv->setCurrentWidgetConfigId($configId);
522 $this->gEnv->setCurrentPageDefSerial($serial);
525 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
527 require_once($widgetIndexFile);
530 $this->gEnv->setCurrentWidgetConfigId('');
533 $this->gEnv->setCurrentPageDefSerial(0);
535 echo 'file not found: ' . $widgetIndexFile;
538 // 現在のバッファ内容を取得し、バッファを破棄
539 $content = ob_get_contents();
543 $this->gPage->endWidgetRss($cmd, $content);
544 } else { // RSS配信以外のとき
547 // ウィジェット用のHTMLヘッダを出力
548 $this->gPage->startWidget($cmd);
551 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){ // ウィジェット設定のとき
552 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/admin/index.php'; // 管理用画面
554 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
556 if (file_exists($widgetIndexFile)){
557 // ウィジェット定義ID、ページ定義のシリアル番号を取得
558 $configId = 0; // 定義ID
559 $serial = 0; // シリアル番号
560 if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
561 $configId = $row['pd_config_id']; // 定義ID
562 $serial = $row['pd_serial']; // シリアル番号
566 $this->gEnv->setCurrentWidgetConfigId($configId);
569 $this->gEnv->setCurrentPageDefSerial($serial);
572 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
574 require_once($widgetIndexFile);
577 $this->gEnv->setCurrentWidgetConfigId('');
580 $this->gEnv->setCurrentPageDefSerial(0);
582 echo 'file not found: ' . $widgetIndexFile;
585 // 現在のバッファ内容を取得し、バッファを破棄
586 $content = ob_get_contents();
590 $this->gPage->endWidget($cmd, $content);
594 $this->gEnv->setCurrentWidgetId('');
597 if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
599 if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET || // ウィジェットの単体表示
600 $cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェット設定のとき
601 ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy))){ // ウィンドウオープンタイプ指定でウィジェット単体実行のとき
603 // 現在の出力内容を取得し、一旦内容をクリア
604 $srcContents = ob_get_contents();
607 // 追加変換処理。HTMLヘッダ出力する。
608 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
613 // ページ作成終了処理(HTTPヘッダ出力)
614 $this->gPage->endPage($request);
616 if ($cmd != M3_REQUEST_CMD_RSS){ // 画面出力(RSS配信以外)のとき
618 echo $this->gPage->getOptionContents($request);
621 // バッファ内容を送信(クライアントへの送信完了)
624 if (!defined('M3_STATE_IN_INSTALL')){ // インストールモード以外のとき
625 // #################### アクセスログ記録 #######################
626 // DBが使用可能であれば、アクセスログのユーザを登録
627 if ($this->gEnv->canUseDb()) $this->gAccess->accessLogUser();
631 //$this->gLog->info(__METHOD__, 'フレーム作成終了');
636 * @param RequestManager $request HTTPリクエスト処理クラス
637 * @param string $curTemplate テンプレートID
638 * @param string $subTemplateId サブページID
639 * @return string 画面出力
641 function _createPage($request, $curTemplate, $subTemplateId = '')
643 $defaultIndexFile = 'index.php'; // テンプレートの起動ファイル
645 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); // 実行コマンドを取得
648 $this->gEnv->setCurrentTemplateId($curTemplate, $subTemplateId);
651 $convType = 0; // 変換処理タイプ(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
652 if ($this->gEnv->getIsMobileSite()){
653 $convType = -1; // 携帯サイト用変換
655 // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
656 $convType = $this->gEnv->getCurrentTemplateType();
660 if (method_exists($this, '_prepareBuffer')) $this->_prepareBuffer($request);
662 // ################### バッファリング開始 ######################
663 // ob_end_flush()までの出力をバッファリングする
664 if ($convType == -1){// 携帯用サイトの場合は出力エンコーディングを変更
665 $mobileEncoding = $this->gEnv->getMobileEncoding(); // 携帯用エンコーディングを取得
666 mb_http_output($mobileEncoding);
667 ob_start("mb_output_handler"); // 出力のバッファリング開始
673 if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
675 if ($convType == 100){ // WordPressテンプレートのとき
677 define('WPINC', 'wp-includes');
678 define('ABSPATH', $this->gEnv->getWordpressRootPath() . '/' );
679 define('TEMPLATEPATH', $this->gEnv->getTemplatesPath() . '/' . $curTemplate);
680 define('STYLESHEETPATH', $this->gEnv->getTemplatesPath() . '/' . $curTemplate); // 子テンプレートを使用している場合は子テンプレートを示す。デフォルトはテンプレートを示す。
681 define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
682 define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages');
683 define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
684 define('WP_CONTENT_URL', '/wp-content'); // 定義自体は必要であるが使用しないのでダミー値で定義
685 define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins'); // 定義自体は必要であるが使用しないのでダミー値で定義
687 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/load.php');
688 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/default-constants.php'); // デフォルト値取得
689 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/plugin.php');
691 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/functions.php');
692 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/default-filters.php');
693 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/l10n.php');
694 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp.php');
695 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-walker.php');
696 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-query.php');
697 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-walker-page.php');
698 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-theme.php');
699 // require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-walker-nav-menu.php');
700 // require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-dependency.php');
701 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-post.php'); // コンテンツAPIマネージャーからWP_Post型でデータを取得
703 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/query.php');
704 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pluggable.php');
705 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post.php');
706 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/user.php');
707 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/widgets.php');
708 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/http.php');
709 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/kses.php');
710 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/script-loader.php');
711 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/theme.php');
712 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/template.php');
713 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/link-template.php');
714 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/category-template.php');
715 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-template.php');
716 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-thumbnail-template.php');
717 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/comment-template.php');
718 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/author-template.php');
719 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/nav-menu-template.php');
720 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/nav-menu.php');
721 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/general-template.php');
722 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/cache.php');
723 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/shortcodes.php');
724 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/formatting.php');
725 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-formats.php');
726 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/taxonomy.php');
727 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/media.php');
728 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/embed.php');
729 // require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/option.php');
730 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pomo/translations.php');
731 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pomo/mo.php');
734 require_once($this->gEnv->getWordpressRootPath() . '/wpInit.php'); // 初期値取得
735 require_once($this->gEnv->getWordpressRootPath() . '/contentApi.php'); // コンテンツ取得API
736 require_once($this->gEnv->getWordpressRootPath() . '/menuApi.php'); // メニュー情報取得API
738 // ##### データ初期化 #####
739 wp_initial_constants(); // 定義値取得
740 m3WpInit(); // Magic3用インターフェイス初期化。$GLOBALS['m3WpOptions']を初期化し、get_option()はここから使用可能にする。
743 $GLOBALS['wp_plugin_paths'] = array(); // $wp_plugin_pathsは未使用?
744 foreach (wp_get_active_and_valid_plugins() as $plugin) {// プラグインロード
745 wp_register_plugin_realpath($plugin);
746 include_once($plugin);
750 // WordPressメインオブジェクト作成
751 $GLOBALS['locale'] = $this->gEnv->getCurrentLanguage();
752 $GLOBALS['wp'] = new WP();
753 $GLOBALS['wp_the_query'] = new WP_Query();
754 $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
755 $GLOBALS['gContentApi'] = new contentApi(); // Magic3コンテンツAPIオブジェクト
756 $GLOBALS['gMenuApi'] = new menuApi(); // Magic3メニュー情報APIオブジェクト
759 if ( file_exists(TEMPLATEPATH . '/functions.php')) include(TEMPLATEPATH . '/functions.php');
762 do_action('setup_theme');
763 load_default_textdomain();
764 do_action('after_setup_theme'); // wp-multibyte-patchプラグイン読み込み
765 do_action('wp_loaded');
767 // ##### 起動PHPファイル取得。データ取得用パラメータ設定。#####
768 // URLパラメータからコンテンツ形式を取得し、ページを選択
769 $params = $this->gRequest->getQueryArray();
770 $paramCount = count($params);
772 $firstKey = key($params);
773 // $firstValue = $params[$firstKey];
775 $contentType = $GLOBALS['gContentApi']->getContentType();
776 switch ($contentType){
777 case M3_VIEW_TYPE_CONTENT: // 汎用コンテンツ
778 if ($firstKey == M3_REQUEST_PARAM_CONTENT_ID || $firstKey == M3_REQUEST_PARAM_CONTENT_ID_SHORT){ // コンテンツIDのとき
780 $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template()); // 固定ページテンプレート
783 $firstValue = $this->gRequest->trimValueOf($firstKey);
784 $GLOBALS['gContentApi']->setContentId($firstValue);
787 case M3_VIEW_TYPE_PRODUCT: // 製品
789 case M3_VIEW_TYPE_BBS: // BBS
791 case M3_VIEW_TYPE_BLOG: // ブログ
792 // if ($firstKey == M3_REQUEST_PARAM_BLOG_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ID_SHORT || // ブログIDのとき
793 // $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT){ // ブログ記事IDのとき
794 if ($firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT){ // ブログ記事IDのとき
796 $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_single_template()); // 記事詳細テンプレート
799 $firstValue = $this->gRequest->trimValueOf($firstKey);
800 $GLOBALS['gContentApi']->setContentId($firstValue);
803 case M3_VIEW_TYPE_WIKI: // Wiki
805 case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ
807 case M3_VIEW_TYPE_EVENT: // イベント
809 case M3_VIEW_TYPE_PHOTO: // フォトギャラリー
812 // コンテンツタイプが設定されていないページに場合は、固定ページ用のテンプレートを使用
814 $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template()); // 固定ページテンプレート
820 } else if ($convType >= 1){ // Joomla!v1.5,v2.5テンプレートのとき
822 require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
823 require_once($this->gEnv->getJoomlaRootPath() . '/JParameter.php');
824 require_once($this->gEnv->getJoomlaRootPath() . '/JRender.php');
828 $paramFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/params.ini';
829 if (is_readable($paramFile)){
830 $content = file_get_contents($paramFile);
831 $params = new JParameter($content);
833 $params = new JParameter();
835 // テンプレートヘッダ画像上のテキスト設定(Joomla!テンプレート2.5以降)
836 $params->set('siteTitle', $this->gEnv->getSiteName()); // サイト名
837 $params->set('siteSlogan', $this->gSystem->getSiteDef(M3_TB_FIELD_SITE_SLOGAN)); // サイトスローガン
839 // Joomla!テンプレート共通の設定
843 define('JPATH_BASE', dirname(__FILE__));
844 define('JPATH_SITE', $this->gEnv->getSystemRootPath());
845 define('JPATH_PLUGINS', $this->gEnv->getJoomlaRootPath() . '/class/plugins'); // プラグインパス
846 // define('JPATH_THEMES', $this->gEnv->getTemplatesPath()); // テンプレートパス ## テンプレート内でエラーが発生するのでここでは定義しない(2015/10/13)
847 define('DS', DIRECTORY_SEPARATOR);
848 $this->language = $this->gEnv->getCurrentLanguage();
849 $this->template = $curTemplate;
850 //$this->baseurl = $this->gEnv->getRootUrl();
851 $this->baseurl = $this->gEnv->getRootUrlByCurrentPage();
852 $this->direction = 'ltr';
853 $this->params = $params;
856 if ($this->gEnv->getCurrentTemplateGenerator() == self::TEMPLATE_GENERATOR_THEMLER){ // Themlerテンプレートの場合はサブテンプレート用のパラメータを設定
857 // JRequest経由でレンダー側にサブテンプレートIDを渡す
858 if (!empty($subTemplateId)) JRequest::injectSetVar('file_template_name', $subTemplateId);
860 // サブテンプレートIDの渡し方は以下の方法もある(Themlerテンプレート1.39以降はこちらが有効)
862 if (!empty($subTemplateId)) $this->setBuffer('<!--TEMPLATE ' . $subTemplateId . ' /-->', 'component');
865 // 現在のJoomla!ドキュメントを設定
866 $this->gEnv->setJoomlaDocument($this);
867 } else { // デフォルト(Joomla!v1.0テンプレート)テンプレートのとき(PC用および携帯用)
868 // Joomla!テンプレート共通の設定
872 global $mosConfig_absolute_path;
873 global $mosConfig_live_site;
874 global $mosConfig_sitename;
875 global $mosConfig_favicon;
876 global $mosConfig_sef;
877 global $cur_template;
879 require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
880 require_once($this->gEnv->getJoomlaRootPath() . '/mosFunc.php');
881 require_once($this->gEnv->getJoomlaRootPath() . '/includes/sef.php');
884 // ################### テンプレート読み込み ###################
885 // テンプレートのポジションタグからウィジェットが実行される
886 //$templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/index.php';
887 $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/' . $defaultIndexFile;
888 if (file_exists($templateIndexFile)){
889 require_once($templateIndexFile);
890 } else { // テンプレートが存在しないとき
891 if ($this->gEnv->isSystemManageUser()){ // システム管理ユーザのとき
892 echo 'template not found error: ' . $curTemplate . ', path=' . $templateIndexFile;
895 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
896 $this->_showSystemPage($request, 2/*サイト非公開画面*/);// システム制御画面を表示
898 // 運用ログに記録(一度だけ出力したい)
899 //$this->gOpeLog->writeFatal(__METHOD__, 'テンプレートが存在しません。メンテナンス画面を表示します。(テンプレートID=' . $curTemplate . ')', 1100);
905 if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
907 // 現在の出力内容を取得し、一旦内容をクリア
908 $srcContents = ob_get_contents();
911 // Joomla!タグの変換処理(ウィジェット実行)
912 if ($convType >= 1){ // Joomla!v1.5,v2.5テンプレートのとき
913 $srcContents = $this->gPage->launchWidgetByJoomlaTag($srcContents, $convType);
916 // 遅延実行ウィジェットの出力を埋め込む。HTMLヘッダ出力する。
917 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
919 // 携帯インターフェイスのときのときは、手動変換後、バイナリコード(絵文字等)を埋め込む
920 if ($convType == -1){ // 携帯アクセスポイントの場合
922 $destContents = mb_convert_encoding($destContents, $mobileEncoding, M3_ENCODING);
924 // コンテンツ変換メソッドがある場合は実行
925 if (method_exists($this, '_convContents')){
926 $destContents = $this->_convContents($destContents);// 絵文字埋め込み処理等
930 // ##### CSS生成の場合は、すべてのウィジェット実行後出力を削除する #####
931 if ($cmd == M3_REQUEST_CMD_CSS) $destContents = ''; // CSS生成のとき
933 // ページ作成終了処理(HTTPヘッダ出力)
934 $destContents .= $this->gPage->endPage($request, true/*出力を取得*/); // 最終HTMLを追加
935 if ($this->gPage->isRedirect()) return '';// リダイレクトの場合ob_end_clean()を実行すると、ログインできないことがあるのでここで終了(2011/11/11)
942 return $destContents;
947 * @param RequestManager $request HTTPリクエスト処理クラス
948 * @param string $subTemplateId テンプレートIDが取得できるときはサブページIDが返る
949 * @return string テンプレート名
951 function _defineTemplate($request, &$subTemplateId)
953 // ########### テンプレートID(ディレクトリ名)を設定 ############
954 // テンプレートIDの指定の方法は2パターン
959 // 1.サブクラスの_setTemplate()で固定設定にしている場合の固定値
964 $isSystemManageUser = $this->gEnv->isSystemManageUser(); // システム運用可能かどうか
965 $useSubClassDefine = true; // サブクラスでの定義を使用するかどうか
967 // テンプレート変更のときは、セッションのテンプレートIDを変更
968 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); // 実行コマンドを取得
969 if ($cmd == M3_REQUEST_CMD_CHANGE_TEMPLATE){
970 // テンプレートIDをセッションに残す場合
971 if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
972 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $request->trimValueOf(M3_SYSTEM_TAG_CHANGE_TEMPLATE));
976 // サブクラスでテンプレートIDを指定している場合はそちらを使用
977 $templateDefined = false; // テンプレート固定かどうか
978 if ($useSubClassDefine){
979 $tmplStr = trim($this->_setTemplate($request));
980 if (strlen($tmplStr) > 0){
981 $curTemplate = $tmplStr;
982 $templateDefined = true; // テンプレート固定かどうか
986 // セッションにあるときは、セッションの値を使用(携帯でないとき)
987 $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
988 if (empty($curTemplate)){
989 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION || // 表示位置を表示するとき
990 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
991 // URLの引数として、ページIDとページサブIDが指定されてくる
992 // URLの引数のテンプレートを優先し、引数で指定されていなければ、ページ用個別のテンプレートを取得する
994 // URLの引数でテンプレートIDが指定されている場合は設定
995 $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID); // テンプレートIDを取得
996 if (!empty($templateId)) $curTemplate = $templateId;
998 // ページ用個別に設定されたテンプレートがある場合は取得
999 if (empty($curTemplate)){
1000 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1001 $line = $this->gPage->getPageInfo($pageId, $pageSubId);
1003 $pageTemplateId = $line['pn_template_id'];
1004 $subTemplateId = $line['pn_sub_template_id']; // サブテンプレートID
1006 if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
1010 if (empty($curTemplate)){
1011 if ($pageId == $this->gEnv->getDefaultPageId()){ // 通常サイトのとき
1012 $curTemplate = $this->gSystem->defaultTemplateId();
1013 $subTemplateId = $this->gSystem->defaultSubTemplateId();
1014 } else if ($pageId == $this->gEnv->getDefaultMobilePageId()){ // 携帯サイトのとき
1015 $curTemplate = $this->gSystem->defaultMobileTemplateId(); // 携帯用デフォルトテンプレート
1016 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){ // スマートフォン用サイトのとき
1017 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId(); // スマートフォン用デフォルトテンプレート
1018 } else if ($pageId == $this->gEnv->getDefaultAdminPageId() || // 管理サイトのとき
1019 $pageId == $this->gEnv->getDefaultRegistPageId()){ // 登録サイトのとき
1020 $curTemplate = $this->gSystem->defaultAdminTemplateId();
1021 } else if (empty($pageId)){ // ページIDが指定されていないときは、ウィジェットを表示しないテンプレートのみの表示
1022 // URLの引数でテンプレートIDが指定されている場合は設定
1023 // $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID); // テンプレートIDを取得
1024 // if (!empty($templateId)) $curTemplate = $templateId;
1028 // ページ用のテンプレートがあるときは優先
1029 $pageTemplateId = $this->gPage->getTemplateIdFromCurrentPageInfo($subTemplateId);
1030 if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
1032 // テンプレートIDをセッションから取得
1033 if (empty($curTemplate) && !$isSystemManageUser){ // システム運用者はセッション値を使用できない
1034 if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
1035 if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite()){
1036 $curTemplate = $request->getSessionValue(M3_SESSION_CURRENT_TEMPLATE);// 携帯サイト、スマートフォンサイトでないときはセッション値を取得
1041 // オプションのテンプレートがある場合はオプションを優先
1042 $optionTemplate = $this->gPage->getOptionTemplateId();
1043 if (!empty($optionTemplate)){
1044 $curTemplate = $optionTemplate;
1045 $templateDefined = true; // テンプレート固定かどうか
1048 // セッションにないときはデフォルトを取得
1049 if (empty($curTemplate)){
1050 if ($this->gEnv->getIsMobileSite()){// 携帯用サイトの場合
1051 $curTemplate = $this->gSystem->defaultMobileTemplateId(); // 携帯用デフォルトテンプレート
1052 } else if ($this->gEnv->getIsSmartphoneSite()){// スマートフォン用サイトの場合
1053 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId(); // スマートフォン用デフォルトテンプレート
1055 $curTemplate = $this->gSystem->defaultTemplateId();
1056 $subTemplateId = $this->gSystem->defaultSubTemplateId();
1062 if (empty($curTemplate)){
1063 // テンプレートが1つもみつからないときは、管理用テンプレートを使用
1064 $curTemplate = $this->gSystem->defaultAdminTemplateId();
1065 echo 'template not found. viewing by administration template. [' . $curTemplate . ']';
1066 } else { // セッションにテンプレートIDを保存
1067 // テンプレートIDをセッションに残す場合
1068 /* if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
1069 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION || // 表示位置を表示するとき
1070 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
1072 if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite() && !$templateDefined){ // PC用画面でサブクラス固定でないとき場合は保存
1073 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $curTemplate);
1078 return $curTemplate;
1083 * @param RequestManager $request HTTPリクエスト処理クラス
1084 * @return bool サイトにアクセスできるかどうか
1086 function _accessSite($request)
1089 $isOpen = $this->gSystem->siteInPublic();
1091 // PC用サイト、携帯用サイト、スマートフォン用サイトの公開状況をチェック
1092 if ($this->gEnv->getIsPcSite()){
1093 if ($this->gSystem->sitePcInPublic()) return true;
1094 } else if ($this->gEnv->getIsMobileSite()){
1095 if ($this->gSystem->siteMobileInPublic()) return true;
1096 } else if ($this->gEnv->getIsSmartphoneSite()){
1097 if ($this->gSystem->siteSmartphoneInPublic()) return true;
1102 $ip = $this->gSystem->getSystemConfig(self::SITE_ACCESS_EXCEPTION_IP);
1103 if (!empty($ip) && $ip = $request->trimServerValueOf('REMOTE_ADDR')){
1113 * @param RequestManager $request HTTPリクエスト処理クラス
1114 * @param int $type 画面タイプ(0=アクセス不可、1=ログイン画面、2=サイト非公開画面)
1117 function _showSystemPage($request, $type)
1120 $pageId = 'admin_index'; // 管理画面を表示
1121 $this->gEnv->setCurrentPageId($pageId); // ここでデフォルトページサブIDが再設定される
1122 $this->gEnv->setCurrentPageSubId($this->gEnv->getDefaultPageSubId());// デフォルトページサブIDをカレントにする
1125 // DBで設定されている値を取得し、なければ管理用デフォルトテンプレートを使用
1126 if ($this->gEnv->getIsMobileSite()){ // 携帯用サイトのアクセスの場合
1127 $curTemplateId = self::M_ADMIN_TEMPLATE; // 携帯管理画面用テンプレート
1128 } else { // 携帯以外のサイトへのアクセスの場合
1129 if ($type == 1){ // ログインはデフォルトの管理画面テンプレートに固定
1130 $curTemplateId = $this->gSystem->defaultAdminTemplateId();
1132 $curTemplateId = $this->gSystem->getSystemConfig(self::CONFIG_KEY_MSG_TEMPLATE);
1133 if (empty($curTemplateId)){
1134 $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
1137 $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplateId . '/index.php';
1138 if (!file_exists($templateIndexFile)) $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
1144 $pageData = $this->_createPage($request, $curTemplateId);
1150 * @param RequestManager $request HTTPリクエスト処理クラス
1153 function _showPhpinfoPage($request)
1155 // ################### バッファリング開始 ######################
1156 // ob_end_flush()までの出力をバッファリングする
1161 // バッファ内容を送信(クライアントへの送信完了)
1165 * 以下、Joomla!v1.5テンプレート専用
1170 * @param string $pos ポジション
1171 * @return int ウィジェット数
1173 function countModules($pos)
1175 $count = $this->gPage->getWidgetsCount($pos);
1178 function getBuffer($type = null, $name = null, $attribs = array())
1180 if (isset($this->joomlaBufArray[$type])){
1181 return $this->joomlaBufArray[$type];
1186 function setBuffer($contents, $type, $name = null)
1188 $this->joomlaBufArray[$type] = $contents;
1194 * @return string 出力タイプ
1203 * @return array ヘッダ情報
1205 function getHeadData()
1208 /*$data['title'] = $this->title;
1209 $data['description']= $this->description;
1210 $data['link'] = $this->link;
1211 $data['metaTags'] = $this->_metaTags;
1212 $data['links'] = $this->_links;
1213 $data['styleSheets']= $this->_styleSheets;
1214 $data['style'] = $this->_style;
1215 $data['scripts'] = $this->_scripts;
1216 $data['script'] = $this->_script;
1217 $data['custom'] = $this->_custom;*/
1223 * @return string ベースパス
1230 * Adds a linked script to the page
1232 * @param string $url URL to the linked script
1233 * @param string $type Type of script. Defaults to 'text/javascript'
1236 function addScript($url, $type="text/javascript") {
1237 $this->_scripts[$url] = $type;
1240 * Adds a script to the page
1243 * @param string $content Script
1244 * @param string $type Scripting mime (defaults to 'text/javascript')
1247 function addScriptDeclaration($content, $type = 'text/javascript')
1249 if (!isset($this->_script[strtolower($type)])) {
1250 $this->_script[strtolower($type)] = $content;
1252 $this->_script[strtolower($type)] .= chr(13).$content;
1256 * WordPressテンプレートの起動ファイルパスを相対パスに変換
1258 * @param string $templateId テンプレートID
1259 * @param string $path テンプレートの起動ファイル絶対パス
1260 * @return string テンプレート内での相対パス。エラー発生の場合はデフォルト(index.php)を返す。
1262 function _getRelativeTemplateIndexPath($templateId, $path)
1265 $templatePath = $this->gEnv->getTemplatesPath() . '/' . $templateId . '/';
1268 $path = str_replace($templatePath, '', $path);
1269 if ($path == $savedPath) $path = 'index.php';