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()){ // 設定ファイルに設定がないとき(初回インストール)
58 // 旧システムがある場合はadminディレクトリまでアクセスしてインストーラを実行。
60 if ($this->_isExistsOldSystemDir()){ // ディレクトリアクセス権がない場合も旧システムが存在するものとしてリダイレクトを行う
61 if ($this->gEnv->isAdminDirAccess()) $isRedirect = true;
68 $this->gInstance->getFileManager()->recoverInstaller();
70 $this->gPage->redirectToInstall();
72 // サイト非公開(システムメンテナンス)表示
73 $this->gPage->showError(503);
76 } else if ($this->gConfig->isConfigured() && !$this->gEnv->canUseDb()){ // DB接続失敗のとき
77 if ($this->gEnv->isAdminDirAccess()){ // 管理画面の場合のみインストーラ起動
79 $this->gInstance->getFileManager()->recoverInstaller();
81 $this->gPage->redirectToInstall();
84 $this->gPage->showError(500);
91 //$this->gLog->info(__METHOD__, 'フレーム作成開始');
94 // セッション変数読み込み。サブページIDの設定。
95 $this->gPage->startPage($request);
98 $isSystemAdmin = $this->gEnv->isSystemAdmin(); // 管理者権限があるかどうか
99 $isSystemManageUser = $this->gEnv->isSystemManageUser(); // システム運用可能かどうか
101 if (!defined('M3_STATE_IN_INSTALL')){ // インストールモード以外のとき
102 // ############## ユーザごとの設定の読み込み ###################
103 // 引数での言語設定取得、言語変更可能な場合は変更
104 // 言語の優先順は、URLの言語設定、クッキーの言語設定の順
105 if (!$this->gEnv->isAdminDirAccess()){ // 管理画面以外の場合
106 if ($this->gEnv->getCanChangeLang() && $this->gEnv->isMultiLanguageSite()){ // 言語変更可能で多言語対応サイトのとき
107 $lang = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_LANG);
110 $lang = $request->getCookieValue(M3_COOKIE_LANG);
114 if (in_array($lang, $this->gSystem->getAcceptLanguage())){
115 $this->gEnv->setCurrentLanguage($lang);
118 $request->setCookieValue(M3_COOKIE_LANG, $lang);
119 } else { // アクセス不可の場合はクッキーを削除
121 $request->setCookieValue(M3_COOKIE_LANG, '', -1);
125 $request->setCookieValue(M3_COOKIE_LANG, '', -1);
128 $this->gPage->loadLang();
130 // ################### URLアクセス制御 ######################
131 // 非公開URLへは管理権限がないとアクセスできない
132 $canAccess = true; // アクセス可能かどうか
133 $isErrorAccess = false; // 不正アクセスかどうか
134 $toAdminType = 0; // 管理画面の遷移タイプ(0=アクセス不可、1=ログイン画面、2=サイト非公開画面, 3=存在しないページ)
135 $errMessage = ''; // エラーメッセージ
136 $messageDetail = ''; // 詳細メッセージ
138 // ページID,ページサブID以外のURLパラメータをチェック。ページマネージャーでの処理(startPage())の結果を反映。
139 $ret = $this->gPage->isSystemPage(); // システム制御ページへ遷移するかどうか
146 // ページID,ページサブIDからアクセス権をチェック
148 $isPublicUrl = $this->gPage->canAccessUrl($isActivePage, $errCode);
149 if (!$isPublicUrl && !$isSystemManageUser){// システム運用可能ユーザかどうか
151 $isErrorAccess = true; // 不正アクセスかどうか
152 $errMessage = 'ユーザに公開されていないページへのアクセス。';
155 if ($errCode == 1){ // ページIDが不正な場合
158 $toAdminType = 3; // 有効なアクセスポイント、ページでない場合は存在しないページとする
164 // ################### ユーザアクセス制御 ######################
165 // クッキーがないため権限を識別できない場合でも、管理者として処理する場合があるので、サブクラスの_checkAccess()メソッドは必ず通るようにする
166 if ($canAccess){ // アクセス可能な場合はユーザをチェック
167 if (method_exists($this, '_checkAccess')){
169 $canAccess = $this->_checkAccess($request); // サブクラスメソッドの呼び出し
171 // フロント画面から直接管理画面が呼ばれた場合は一旦ログインへ遷移
173 ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェットの設定
174 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET)){ // 表示位置を表示するとき(ウィジェット付き)
176 $toAdminType = 1; // ログイン画面へ
178 } else { // _checkAccess()がないときは、標準のアクセス制御
180 $canAccess = $this->_accessSite($request); // サイト公開制御
182 if ($cmd == M3_REQUEST_CMD_LOGIN || // ログイン画面を表示のとき
183 $cmd == M3_REQUEST_CMD_LOGOUT){ // ログアウトのとき
187 $toAdminType = 1; // ログイン画面へ
188 } else if ($cmd != '' && // コマンドなし
189 $cmd != M3_REQUEST_CMD_CHANGE_TEMPLATE && // テンプレート変更
190 $cmd != M3_REQUEST_CMD_SHOW_POSITION && // 表示位置を表示するとき
191 $cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET && // 表示位置を表示するとき(ウィジェット付き)
192 $cmd != M3_REQUEST_CMD_FIND_WIDGET && // ウィジェットを検索
193 $cmd != M3_REQUEST_CMD_DO_WIDGET && // ウィジェット単体実行
194 $cmd != M3_REQUEST_CMD_PREVIEW && // サイトのプレビューを表示
195 $cmd != M3_REQUEST_CMD_RSS && // RSS配信
196 $cmd != M3_REQUEST_CMD_CSS){ // CSS生成
198 // 標準のアクセスでは、上記コマンド以外は受け付けない
200 $isErrorAccess = true; // 不正アクセス
201 $errMessage = '不正なコマンドの実行。';
202 $messageDetail = 'アクセスポイント状態=公開';
204 } else { // サイトアクセスできない場合は、管理画面でメッセージを表示
205 if ($cmd == M3_REQUEST_CMD_LOGIN || // ログイン画面を表示のとき
206 $cmd == M3_REQUEST_CMD_LOGOUT || // ログアウトのとき
207 $cmd == M3_REQUEST_CMD_PREVIEW){ // サイトのプレビューを表示
208 $toAdminType = 1; // ログイン画面へ
210 $toAdminType = 2; // サイト非公開画面へ
214 if ($cmd != '' && // コマンドなし
215 $cmd != M3_REQUEST_CMD_LOGIN && // ログイン画面を表示のとき
216 $cmd != M3_REQUEST_CMD_LOGOUT && // ログアウトのとき
217 $cmd != M3_REQUEST_CMD_CHANGE_TEMPLATE && // テンプレート変更
218 $cmd != M3_REQUEST_CMD_SHOW_POSITION && // 表示位置を表示するとき
219 $cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET && // 表示位置を表示するとき(ウィジェット付き)
220 $cmd != M3_REQUEST_CMD_FIND_WIDGET && // ウィジェットを検索
221 $cmd != M3_REQUEST_CMD_DO_WIDGET && // ウィジェット単体実行
222 $cmd != M3_REQUEST_CMD_PREVIEW && // サイトのプレビューを表示
223 $cmd != M3_REQUEST_CMD_RSS && // RSS配信
224 $cmd != M3_REQUEST_CMD_CSS){ // CSS生成
226 $isErrorAccess = true; // 不正アクセス
227 $errMessage = '不正なコマンドの実行。';
228 $messageDetail = 'アクセスポイント状態=非公開';
232 // システム運用可能ユーザはアクセス可。
233 // ログアウトのときはすでに管理ユーザの可能性があるので、ログアウト時は変更しない
234 //if ($isSystemManageUser && $cmd != M3_REQUEST_CMD_LOGOUT) $canAccess = true;
235 if ($isSystemAdmin && $cmd != M3_REQUEST_CMD_LOGOUT) $canAccess = true; // 2011/8/31 システム管理者のみに変更
237 // #################### アクセスログ記録 #######################
238 // DBが使用可能であれば、ログイン処理終了後、アクセスログを残す
239 if ($this->gEnv->canUseDb()) $this->gAccess->accessLog();
243 switch ($toAdminType){
246 $this->gPage->setSystemHandleMode(1/*管理画面*/);
249 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
251 case 3: // 存在しないページ画面へ(システム運用可能ユーザ以外)
252 // サイトが非公開の場合は、メンテナンス中画面のみ表示
253 if ($this->_accessSite($request)){ // サイト公開中の場合
254 $messageDetail = 'アクセスポイント状態=公開';
255 $this->gPage->setSystemHandleMode(12/*存在しないページ*/);
257 $messageDetail = 'アクセスポイント状態=非公開';
258 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
261 case 4: // 不正なページIDの指定
262 $messageDetail = '不正なページIDの指定';
263 $this->gPage->setSystemHandleMode(12/*存在しないページ*/);
265 default: // アクセス不可画面へ
267 $this->gPage->setSystemHandleMode(11/*アクセス不可*/);
271 $this->_showSystemPage($request, $toAdminType);
273 // 不正アクセスの場合は、アクセスエラーログを残す
274 if ($isErrorAccess) $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2201, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
277 // #################### URLの遷移 #######################
278 //if ($this->gSystem->getSystemConfig(self::CF_MOBILE_AUTO_REDIRECT)){ // 携帯自動遷移を行う場合
279 if ($this->gSystem->mobileAutoRedirect()){ // 携帯自動遷移を行う場合
281 if ($this->gEnv->isMobile() && !$this->gEnv->getIsMobileSite()){
282 $this->gPage->redirect($this->gEnv->getDefaultMobileUrl(true/*携帯用パラメータ付加*/), true/*遷移時のダイアログ表示を抑止*/);
286 if ($this->gSystem->smartphoneAutoRedirect()){ // スマートフォン自動遷移を行う場合
287 // スマートフォンのときはスマートフォンURLへ遷移
288 if ($this->gEnv->isSmartphone() && !$this->gEnv->getIsSmartphoneSite()){
289 $this->gPage->redirect($this->gEnv->getDefaultSmartphoneUrl());
295 // ################## 実行コマンドから処理を確定 ##################
296 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY); // ウィンドウオープンタイプ
298 // 画面作成モードか、ウィジェット単体処理モードかを決定
299 $createPage = true; // 画面作成モード
300 if ($cmd == M3_REQUEST_CMD_INIT_DB){ // DB初期化オペレーションのとき
301 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION){ // 表示位置を表示するとき
303 //if ($this->gEnv->isSystemAdmin()){
305 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
307 /* $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
308 if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId(); // 値がないときはデフォルトのページIDを設定
309 $this->gEnv->setCurrentPageId($pageId);
310 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
311 if (!empty($pageSubId)) $this->gEnv->setCurrentPageSubId($pageSubId);
313 $this->gPage->showPosition(1); // ポジションを表示
317 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
319 //if ($this->gEnv->isSystemAdmin()){
321 // ポジションの表示画面のアクセスは、すべて管理機能URLで受け付ける
323 /* $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
324 if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId(); // 値がないときはデフォルトのページIDを設定
325 $this->gEnv->setCurrentPageId($pageId);
326 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
327 if (!empty($pageSubId)) $this->gEnv->setCurrentPageSubId($pageSubId);
329 $this->gPage->showPosition(2); // ウィジェット付きポジションを表示
333 } else if ($cmd == M3_REQUEST_CMD_GET_WIDGET_INFO){ // ウィジェット各種情報取得(AJAX用)
335 $this->gPage->getWidgetInfoByAjax($request);
337 } else if ($cmd == M3_REQUEST_CMD_SHOW_PHPINFO){ // phpinfoの表示
339 $this->_showPhpinfoPage($request);
341 } else if ($cmd == M3_REQUEST_CMD_FIND_WIDGET){ // ウィジェットを検索し、前面表示
342 // 目的のウィジェットのあるページサブIDへ遷移
343 $this->gPage->redirectToUpdatedPageSubId($request);
345 } else if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET){ // ウィジェットの単体表示
346 $createPage = false; // ウィジェット単体処理モードに設定
347 $this->gPage->showWidget(); // ウィジェット表示
348 } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){ // ウィジェットの設定管理
349 $createPage = false; // ウィジェット単体処理モードに設定
350 $this->gPage->showWidget(); // ウィジェット表示
351 } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){ // ウィジェット単体オペレーション
352 $createPage = false; // ウィジェット単体処理モードに設定
354 // ウィンドウオープンタイプ指定のときは、テンプレートを表示する
355 if (!empty($openBy)) $this->gPage->showWidget(); // ウィジェット表示
356 } else if ($cmd == M3_REQUEST_CMD_RSS){ // RSS配信
357 $createPage = false; // ウィジェット単体処理モードに設定
358 } else if ($cmd == M3_REQUEST_CMD_CSS){ // CSS生成
360 } else if ($this->gEnv->isServerConnector()){ // サーバ接続の場合
361 $createPage = false; // ウィジェット単体処理モードに設定
364 // ################### クライアントへの出力方法の制御 ######################
366 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
367 if ($createPage){ // 通常の画面作成の場合
369 $this->gCache->initCache($request); // キャッシュ機能初期化
370 $cacheData = $this->gCache->getPageCache($request);
372 if (empty($cacheData)){ // キャッシュデータがないときは画面を作成
374 $curTemplateId = $this->_defineTemplate($request, $subTemplateId);
377 $pageData = $this->_createPage($request, $curTemplateId, $subTemplateId);
379 // ##### 非共通ウィジェットがページ上になくてもエラーとしない #####
380 $this->gCache->setPageCache($request, $pageData); // キャッシュデータを設定
383 /* // 使用した非共通ウィジェットの数をチェック
384 $nonSharedWidgetCount = $this->gPage->getNonSharedWidgetCount();
385 if ($nonSharedWidgetCount == -1){ // カウントなしの場合
386 $this->gCache->setPageCache($request, $pageData); // キャッシュデータを設定
389 // ***** WordPressテンプレートの場合は非共通のウィジェットが使用されていなくても表示可とする *****
390 if ($this->gEnv->getCurrentTemplateType() == 100) $nonSharedWidgetCount = 1;
392 if ($isSystemAdmin || $nonSharedWidgetCount > 0){
393 $this->gCache->setPageCache($request, $pageData); // キャッシュデータを設定
395 } else { // 管理者以外で、非共通のウィジェットが使用されていないページはアクセス不可とする
396 $errMessage = 'ユーザに公開されていないページへのアクセス。';
397 $messageDetail = 'アクセスポイント状態=公開, 要因: グローバルウィジェットのみのページへのアクセスはできません。ページには1つ以上のローカルウィジェットが必要です。';
398 $this->gOpeLog->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2202, 'アクセスをブロックしました。URL: ' . $this->gEnv->getCurrentRequestUri() . ', ' . $messageDetail);
401 $this->gPage->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
408 if ($cmd != M3_REQUEST_CMD_CSS){ // 画面出力(CSS生成以外)のとき
410 echo $this->gPage->getOptionContents($request);
412 } else { // ウィジェット単体実行モードのとき
413 // ###################ウィジェット指定で出力の場合####################
414 // ウィジェット単体を直接実行するインターフェイスで、HTTPヘッダは送信しない。
416 // ・Ajaxを使って、データをやり取りしたい場合
417 // ・ウィジェット単体での実行(ウィジェットが生成したタグのみ)
418 // ・ウィジェット単体での実行(HTMLやJavascriptの追加あり)
419 // ・ウィジェット個別の設定(セキュリティの必要あり)
421 // ################# アクセスチェック ################
422 // ウィジェット単体オペレーションのときは、ウィジェット情報の単体実行許可があるかどうか判断(管理権限にかかわらず同じ動作)
423 if ($cmd == M3_REQUEST_CMD_DO_WIDGET || // ウィジェット単体実行
424 $cmd == M3_REQUEST_CMD_RSS){ // RSS配信
425 if (empty($widgetId)){
426 $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットIDが設定されていません。', 2200,
429 } else if ($this->_db->getWidgetInfo($widgetId, $row)){ // ウィジェット情報取得
430 if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !$row['wd_enable_operation']){ // ウィジェット単体実行
432 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
434 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは単体起動できません。(ウィジェットID: ' . $widgetId . ')', 2200,
435 '実行処理はキャンセルされました。このウィジェットは単体起動できないウィジェットです。単体起動を許可するにはウィジェット情報(_widgets)の単体起動フラグ(wd_enable_operation)がtrueになっている必要があります。');
437 } else if ($cmd == M3_REQUEST_CMD_RSS && !$row['wd_has_rss']){ // RSS配信
439 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
441 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットはRSS配信できません。(ウィジェットID: ' . $widgetId . ')', 2200,
442 '実行処理はキャンセルされました。このウィジェットはRSS配信できないウィジェットです。RSS配信を許可するにはウィジェット情報(_widgets)のRSS配信フラグ(wd_has_rss)がtrueになっている必要があります。');
446 $this->gOpeLog->writeUserAccess(__METHOD__, 'このウィジェットは実行許可がありません。(ウィジェットID: ' . $widgetId . ')', 2200,
447 '実行処理はキャンセルされました。ウィジェット情報(_widgets)が見つかりません。');
452 // 管理権限がない場合は、ウィジェットのページへの配置状況からアクセス権限をチェックする
453 if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && !$this->_db->canAccessWidget($widgetId)){
455 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
457 $this->gOpeLog->writeUserAccess(__METHOD__, 'ウィジェットへの不正なアクセスを検出しました。(ウィジェットID: ' . $widgetId . ')', 2200,
458 '実行処理はキャンセルされました。このウィジェットは一般ユーザに公開されているページ上に存在しないため単体実行できません。');
462 // ################# パラメータチェック ################
463 if (!$isSystemManageUser && !$this->gAccess->isValidAdminKey() && $this->gEnv->isServerConnector()){ // サーバ接続の場合
464 // クエリーパラメータはウィジェットIDのみ正常とする
465 $params = $request->getQueryArray();
466 $paramCount = count($params);
467 if (!($paramCount == 1 && !empty($params[M3_REQUEST_PARAM_WIDGET_ID]))){
469 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd, self::ERR_MESSAGE_ACCESS_DENY);
471 $this->gOpeLog->writeUserAccess(__METHOD__, 'サーバ接続アクセスポイントへの不正なアクセスを検出しました。', 2200,
472 '実行処理はキャンセルされました。URLのクエリー部が不正です。URL=' . $this->gEnv->getCurrentRequestUri());
477 // 画面表示する場合はテンプレートを設定。画面に表示しない場合はテンプレートが必要ない。
478 if ($this->gPage->getShowWidget()){
480 //$curTemplate = $this->_defineTemplate($request);
481 $curTemplate = $this->gSystem->defaultAdminTemplateId();
484 $this->gEnv->setCurrentTemplateId($curTemplate);
487 // ################### バッファリング開始 ######################
488 // ob_end_flush()までの出力をバッファリングする
492 if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
495 $this->gEnv->setCurrentWidgetId($widgetId);
497 if ($this->gEnv->isServerConnector()){ // サーバ接続の場合
498 // ウィジェット用のHTMLヘッダを出力
499 $this->gPage->startWidgetXml($cmd);
502 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/' . M3_FILENAME_INDEX;
504 if (file_exists($widgetIndexFile)){
506 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
508 require_once($widgetIndexFile);
510 echo 'file not found: ' . $widgetIndexFile;
514 $this->gPage->endWidgetXml($cmd);
515 } else if ($cmd == M3_REQUEST_CMD_RSS){ // RSS配信のとき
518 // ウィジェット用のHTMLヘッダを出力
519 $this->gPage->startWidgetRss($cmd);
522 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/' . M3_FILENAME_INDEX;
524 if (file_exists($widgetIndexFile)){
525 // ウィジェット定義ID、ページ定義のシリアル番号を取得
526 $configId = 0; // 定義ID
527 $serial = 0; // シリアル番号
528 if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
529 $configId = $row['pd_config_id']; // 定義ID
530 $serial = $row['pd_serial']; // シリアル番号
534 $this->gEnv->setCurrentWidgetConfigId($configId);
537 $this->gEnv->setCurrentPageDefSerial($serial);
540 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
542 require_once($widgetIndexFile);
545 $this->gEnv->setCurrentWidgetConfigId('');
548 $this->gEnv->setCurrentPageDefSerial(0);
550 echo 'file not found: ' . $widgetIndexFile;
553 // 現在のバッファ内容を取得し、バッファを破棄
554 $content = ob_get_contents();
558 $this->gPage->endWidgetRss($cmd, $content);
559 } else { // RSS配信以外のとき
562 // ウィジェット用のHTMLヘッダを出力
563 $this->gPage->startWidget($cmd);
566 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){ // ウィジェット設定のとき
567 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/admin/' . M3_FILENAME_INDEX; // 管理用画面
569 $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/' . M3_FILENAME_INDEX;
571 if (file_exists($widgetIndexFile)){
572 // ウィジェット定義ID、ページ定義のシリアル番号を取得
573 $configId = 0; // 定義ID
574 $serial = 0; // シリアル番号
575 if ($this->_db->getPageDefOnPageByWidgetId($this->gEnv->getCurrentPageId(), $this->gEnv->getCurrentPageSubId(), $widgetId, $row)){
576 $configId = $row['pd_config_id']; // 定義ID
577 $serial = $row['pd_serial']; // シリアル番号
581 $this->gEnv->setCurrentWidgetConfigId($configId);
584 $this->gEnv->setCurrentPageDefSerial($serial);
587 $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
589 require_once($widgetIndexFile);
592 $this->gEnv->setCurrentWidgetConfigId('');
595 $this->gEnv->setCurrentPageDefSerial(0);
597 echo 'file not found: ' . $widgetIndexFile;
600 // 現在のバッファ内容を取得し、バッファを破棄
601 $content = ob_get_contents();
605 $this->gPage->endWidget($cmd, $content);
609 $this->gEnv->setCurrentWidgetId('');
612 if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
614 if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET || // ウィジェットの単体表示
615 $cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェット設定のとき
616 ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy))){ // ウィンドウオープンタイプ指定でウィジェット単体実行のとき
618 // 現在の出力内容を取得し、一旦内容をクリア
619 $srcContents = ob_get_contents();
622 // 追加変換処理。HTMLヘッダ出力する。
623 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
628 // ページ作成終了処理(HTTPヘッダ出力)
629 $this->gPage->endPage($request);
631 if ($cmd != M3_REQUEST_CMD_RSS){ // 画面出力(RSS配信以外)のとき
633 echo $this->gPage->getOptionContents($request);
636 // バッファ内容を送信(クライアントへの送信完了)
639 if (!defined('M3_STATE_IN_INSTALL')){ // インストールモード以外のとき
640 // #################### アクセスログ記録 #######################
641 // DBが使用可能であれば、アクセスログのユーザを登録
642 if ($this->gEnv->canUseDb()) $this->gAccess->accessLogUser();
646 //$this->gLog->info(__METHOD__, 'フレーム作成終了');
651 * @param RequestManager $request HTTPリクエスト処理クラス
652 * @param string $curTemplate テンプレートID
653 * @param string $subTemplateId サブページID
654 * @return string 画面出力
656 function _createPage($request, $curTemplate, $subTemplateId = '')
658 $defaultIndexFile = M3_FILENAME_INDEX; // テンプレートの起動ファイル
660 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); // 実行コマンドを取得
663 $this->gEnv->setCurrentTemplateId($curTemplate, $subTemplateId);
666 $convType = 0; // 変換処理タイプ(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
667 if ($this->gEnv->getIsMobileSite()){
668 $convType = -1; // 携帯サイト用変換
670 // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
671 $convType = $this->gEnv->getCurrentTemplateType();
675 if (method_exists($this, '_prepareBuffer')) $this->_prepareBuffer($request);
677 // ################### バッファリング開始 ######################
678 // ob_end_flush()までの出力をバッファリングする
679 if ($convType == -1){// 携帯用サイトの場合は出力エンコーディングを変更
680 $mobileEncoding = $this->gEnv->getMobileEncoding(); // 携帯用エンコーディングを取得
681 mb_http_output($mobileEncoding);
682 ob_start("mb_output_handler"); // 出力のバッファリング開始
688 if (method_exists($this, '_preBuffer')) $this->_preBuffer($request);
690 if ($convType == 100){ // WordPressテンプレートのとき
692 define('WP_DEBUG', true); // ##### エラーメッセージ表示制御(true時noticeを表示) #####
693 define('WPINC', 'wp-includes');
694 define('ABSPATH', $this->gEnv->getWordpressRootPath() . '/' );
695 define('TEMPLATEPATH', $this->gEnv->getTemplatesPath() . '/' . $curTemplate);
696 define('STYLESHEETPATH', $this->gEnv->getTemplatesPath() . '/' . $curTemplate); // 子テンプレートを使用している場合は子テンプレートを示す。デフォルトはテンプレートを示す。
697 define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
698 define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages');
699 define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
700 define('WP_CONTENT_URL', '/wp-content'); // 定義自体は必要であるが使用しないのでダミー値で定義
701 define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins'); // 定義自体は必要であるが使用しないのでダミー値で定義
703 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/load.php');
704 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/default-constants.php'); // デフォルト値取得
705 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/plugin.php');
707 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/functions.php');
708 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/default-filters.php');
709 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/l10n.php');
710 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp.php');
711 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-locale.php');
712 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-user.php');
713 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-walker.php');
714 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-query.php'); // コンテンツデータ取得
715 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-comment-query.php');
716 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-term.php');
717 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-walker-page.php');
718 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-theme.php');
719 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-widget.php');
720 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-widget-factory.php');
721 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-list-util.php');
722 // require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-walker-nav-menu.php');
723 // require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-dependency.php');
724 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-post.php'); // コンテンツAPIマネージャーからWP_Post型でデータを取得
725 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-post-type.php');
727 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/query.php');
728 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pluggable.php');
729 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post.php');
730 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/user.php');
731 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/widgets.php');
732 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/comment.php');
733 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/http.php');
734 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/kses.php');
735 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/script-loader.php');
736 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/theme.php');
737 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/template.php');
738 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/link-template.php');
739 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/category.php');
740 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/category-template.php');
741 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-template.php');
742 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-thumbnail-template.php');
743 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/comment-template.php');
744 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/author-template.php');
745 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/nav-menu-template.php');
746 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/nav-menu.php');
747 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/general-template.php');
748 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/cache.php');
749 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/shortcodes.php');
750 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/formatting.php');
751 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/post-formats.php');
752 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/taxonomy.php');
753 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/media.php');
754 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/embed.php');
755 // require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/option.php');
756 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pomo/translations.php');
757 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pomo/mo.php');
758 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/capabilities.php');
759 require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/meta.php');
762 require_once($this->gEnv->getWordpressRootPath() . '/wpInit.php'); // 初期値取得
763 require_once($this->gEnv->getWordpressRootPath() . '/contentApi.php'); // コンテンツ取得API
764 require_once($this->gEnv->getWordpressRootPath() . '/menuApi.php'); // メニュー情報取得API
765 require_once($this->gEnv->getWordpressRootPath() . '/WPRender.php'); // ウィジェット描画クラス
767 // ##### データ初期化 #####
768 wp_initial_constants(); // WordPressその他定義値設定
769 create_initial_post_types(); // WP_Post型データ型登録
772 $GLOBALS['wp_plugin_paths'] = array(); // $wp_plugin_pathsは未使用?
773 foreach (wp_get_active_and_valid_plugins() as $plugin) {// プラグインロード
774 wp_register_plugin_realpath($plugin);
775 include_once($plugin);
779 // WordPressメインオブジェクト作成
780 $GLOBALS['wp_version'] = '4.7.0'; // 下位互換性チェックで引っかかるのでv4.7.0に定める
781 $GLOBALS['locale'] = $this->gEnv->getCurrentLanguage(); // 表示言語を設定
782 $GLOBALS['wp_the_query'] = new WP_Query(); // $wp_the_queryは変更不可変数で$wp_queryは変更可変数
783 $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
784 $GLOBALS['wp'] = new WP();
785 $GLOBALS['wp_widget_factory'] = new WP_Widget_Factory();
786 $GLOBALS['gContentApi'] = new contentApi(); // Magic3コンテンツAPIオブジェクト
787 $GLOBALS['gMenuApi'] = new menuApi(); // Magic3メニュー情報APIオブジェクト
791 // ページに配置されているウィジェットの状況からWordPress以外の主コンテンツ用のプラグインをロード
792 $GLOBALS['gContentApi']->loadPlugin();
795 do_action('setup_theme');
796 load_default_textdomain(); // 言語リソースを読み込む
797 m3WpInit(); // 言語リソース読み込み後にMagic3用インターフェイス初期化。$GLOBALS['m3WpOptions']を初期化し、get_option()はここから使用可能にする。
798 $GLOBALS['wp_locale'] = new WP_Locale(); // 言語リソース読み込み後に生成
800 // functions.phpを読み込む。ファイル内で定義されている変数はグローバル変数に変換する。
801 $this->_loadFileAsGlobal(TEMPLATEPATH . '/functions.php');
803 do_action('after_setup_theme'); // wp-multibyte-patchプラグイン読み込み
804 do_action('init'); // テンプレート側からの初期処理(ウィジェットのCSSの初期化等)
805 do_action('wp_loaded');
807 // ##### 起動PHPファイル取得。データ取得用パラメータ設定。#####
808 // URLパラメータからコンテンツ形式を取得し、ページを選択
809 $params = $request->getQueryArray();
810 $paramCount = count($params);
812 $firstKey = key($params);
813 // $firstValue = $params[$firstKey];
815 // コンテンツタイプに合わせて起動PHPファイルを決める。デフォルトはindex.phpで一覧形式で表示。
816 $pageTypeDefined = false; // ページタイプ確定したかどうか
817 $wpIndexFile = get_index_template(); // WordPress用テンプレート起動ファイル
818 $contentType = $GLOBALS['gContentApi']->getContentType();
819 switch ($contentType){
820 case M3_VIEW_TYPE_CONTENT: // 汎用コンテンツ
821 if ($firstKey == M3_REQUEST_PARAM_CONTENT_ID || $firstKey == M3_REQUEST_PARAM_CONTENT_ID_SHORT){ // コンテンツIDのとき
823 $GLOBALS['gContentApi']->setPageType('page');
826 // $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template()); // 固定ページテンプレート
827 $wpIndexFile = get_page_template(); // 固定ページテンプレート
830 $firstValue = $request->trimValueOf($firstKey);
831 $GLOBALS['gContentApi']->setContentId($firstValue);
833 $pageTypeDefined = true; // ページタイプ確定
836 case M3_VIEW_TYPE_PRODUCT: // 製品
837 if ($firstKey == M3_REQUEST_PARAM_PRODUCT_ID || $firstKey == M3_REQUEST_PARAM_PRODUCT_ID_SHORT){ // 製品IDのとき
839 $GLOBALS['gContentApi']->setPageType('single');
842 //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_single_template()); // 記事詳細テンプレート
843 $wpIndexFile = get_single_template(); // 記事詳細テンプレート
846 $firstValue = $request->trimValueOf($firstKey);
847 $GLOBALS['gContentApi']->setContentId($firstValue);
849 $pageTypeDefined = true; // ページタイプ確定
852 case M3_VIEW_TYPE_BBS: // BBS
854 case M3_VIEW_TYPE_BLOG: // ブログ
855 if ($firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT){ // ブログ記事IDのとき
857 $GLOBALS['gContentApi']->setPageType('single');
860 //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_single_template()); // 記事詳細テンプレート
861 $wpIndexFile = get_single_template(); // 記事詳細テンプレート
864 $firstValue = $request->trimValueOf($firstKey);
865 $GLOBALS['gContentApi']->setContentId($firstValue);
867 $pageTypeDefined = true; // ページタイプ確定
869 // カテゴリーが設定されている場合はカテゴリー画面を表示
870 $value = $request->trimValueOf(M3_REQUEST_PARAM_CATEGORY_ID);
873 $GLOBALS['gContentApi']->setPageType('category'); // カテゴリー表示
876 $template = get_category_template();
877 if (empty($template)) $template = get_archive_template(); // カテゴリー用のテンプレートが取得できない場合はアーカイブ用テンプレートを取得
878 if (!empty($template)) $wpIndexFile = $template;
881 //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $template); // カテゴリーテンプレート
883 $pageTypeDefined = true; // ページタイプ確定
885 if (!$pageTypeDefined){
886 $year = $request->trimValueOf(M3_REQUEST_PARAM_YEAR); // 年指定
887 $month = $request->trimValueOf(M3_REQUEST_PARAM_MONTH); // 月指定
888 $day = $request->trimValueOf(M3_REQUEST_PARAM_DAY); // 日指定
890 if (!empty($year)){ // 年月日指定のとき
892 $GLOBALS['gContentApi']->setPageType('date'); // 年月日表示
895 $template = get_date_template();
896 if (empty($template)) $template = get_archive_template(); // 年月日用のテンプレートが取得できない場合はアーカイブ用テンプレートを取得
897 if (!empty($template)) $wpIndexFile = $template;
900 //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $template);
902 $pageTypeDefined = true; // ページタイプ確定
905 // 検索条件が設定されている場合は検索画面を表示
906 if (!$pageTypeDefined){
907 $value = $request->trimValueOf('s');
910 $GLOBALS['gContentApi']->setPageType('search'); // 検索結果表示
913 //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_search_template()); // 検索結果テンプレート
914 $template = get_search_template(); // 検索結果テンプレート
915 if (!empty($template)) $wpIndexFile = $template;
917 $pageTypeDefined = true; // ページタイプ確定
922 case M3_VIEW_TYPE_WIKI: // Wiki
924 case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ
926 case M3_VIEW_TYPE_EVENT: // イベント
928 case M3_VIEW_TYPE_PHOTO: // フォトギャラリー
931 // 検索キーワードが設定されている場合は検索結果画面を表示
932 $value = $request->trimValueOf('s');
934 // ページ指定されていない場合(フロント画面等)、検索結果表示用ページがある場合はリダイレクト
935 $subId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);
937 $subId = $this->_db->getSubPageIdWithContent(M3_VIEW_TYPE_SEARCH, $this->gEnv->getCurrentPageId());// ページサブIDを取得
940 $redirectUrl = $this->gEnv->createPageUrl();
941 $redirectUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subId;
942 //$redirectUrl .= '&s=' . urlencode($value); // 検索キーワード
943 $redirectUrl .= '&' . M3_REQUEST_PARAM_OPERATION_TASK . '=search&' . M3_REQUEST_PARAM_KEYWORD . '=' . urlencode($value); // 検索キーワード
945 $this->gPage->redirect($redirectUrl);
950 // // 検索キーワードが設定されている場合は画面タイトルを設定
951 // $value = $request->trimValueOf(M3_REQUEST_PARAM_KEYWORD);
952 // if (!empty($value)){
956 // ##### デフォルトのページタイトルを設定 #####
957 $pageInfo = $this->gPage->getCurrentPageInfo();
958 if (!empty($pageInfo)){
959 $pageTitle = $pageInfo['pg_name'];
960 if (!empty($pageTitle)) $GLOBALS['gContentApi']->setPostTitle($pageTitle);
963 // コンテンツタイプが設定されていないページ(お問合わせページ等)に場合は、固定ページ用のテンプレートを使用
965 $GLOBALS['gContentApi']->setPageType('page');
968 //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template()); // 固定ページテンプレート
969 $wpIndexFile = get_page_template(); // 固定ページテンプレート
971 $pageTypeDefined = true; // ページタイプ確定
975 // コンテンツタイプが設定されているページでページタイプが設定されていないページの場合はデフォルトテンプレート(index.php)の代わりにホーム用テンプレートを取得
976 if (!empty($contentType) && !$pageTypeDefined){
978 //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_home_template()); // ホーム用テンプレート
979 $wpIndexFile = get_home_template(); // ホーム用テンプレート
982 // サイトのトップページを表示する場合(コンテンツタイプが設定されていないページをデフォルトで表示する場合)は優先してフロント用テンプレートを表示
983 if (empty($contentType)){
984 //if (!$GLOBALS['gContentApi']->isHomeUrl()){
985 // if ($defaultIndexFile == M3_FILENAME_INDEX){ // テンプレートの起動ファイル
986 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);
987 if ($this->gEnv->getCurrentPageSubId() == $this->gEnv->getDefaultPageSubId() && empty($pageSubId)){ // デフォルトページを表示し「sub」なしに限定
988 $frontPageTemplate = get_front_page_template();
989 if (!empty($frontPageTemplate)){
990 //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $frontPageTemplate); // フロントページテンプレート
991 $wpIndexFile = $frontPageTemplate; // フロントページテンプレート
996 // プラグインからの起動ファイルパス変換
997 $wpIndexFile = apply_filters('template_include', $wpIndexFile);
999 // Magic3用のテンプレート起動ファイルパスに変換
1000 // $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $wpIndexFile);
1001 $defaultIndexFile = $wpIndexFile;
1003 // ##### テンプレート前処理(起動ファイル決定後に実行) #####
1004 do_action('template_redirect');
1006 // WordPressオブジェクト作成
1008 } else if ($convType >= 1){ // Joomla!v1.5,v2.5テンプレートのとき
1010 require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
1011 require_once($this->gEnv->getJoomlaRootPath() . '/JParameter.php');
1012 require_once($this->gEnv->getJoomlaRootPath() . '/JRender.php');
1015 //$params = array();
1016 $paramFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/params.ini';
1017 if (is_readable($paramFile)){
1018 $content = file_get_contents($paramFile);
1019 $params = new JParameter($content);
1021 $params = new JParameter();
1023 // テンプレートヘッダ画像上のテキスト設定(Joomla!テンプレート2.5以降)
1024 $params->set('siteTitle', $this->gEnv->getSiteName()); // サイト名
1025 $params->set('siteSlogan', $this->gSystem->getSiteDef(M3_TB_FIELD_SITE_SLOGAN)); // サイトスローガン
1027 // Joomla!テンプレート共通の設定
1028 define('_JEXEC', 1);
1031 define('JPATH_BASE', dirname(__FILE__));
1032 define('JPATH_SITE', $this->gEnv->getSystemRootPath());
1033 define('JPATH_PLUGINS', $this->gEnv->getJoomlaRootPath() . '/class/plugins'); // プラグインパス
1034 // define('JPATH_THEMES', $this->gEnv->getTemplatesPath()); // テンプレートパス ## テンプレート内でエラーが発生するのでここでは定義しない(2015/10/13)
1035 define('DS', DIRECTORY_SEPARATOR);
1036 $this->language = $this->gEnv->getCurrentLanguage();
1037 $this->template = $curTemplate;
1038 //$this->baseurl = $this->gEnv->getRootUrl();
1039 $this->baseurl = $this->gEnv->getRootUrlByCurrentPage();
1040 $this->direction = 'ltr';
1041 $this->params = $params;
1044 if ($this->gEnv->getCurrentTemplateGenerator() == self::TEMPLATE_GENERATOR_THEMLER){ // Themlerテンプレートの場合はサブテンプレート用のパラメータを設定
1045 // JRequest経由でレンダー側にサブテンプレートIDを渡す
1046 if (!empty($subTemplateId)) JRequest::injectSetVar('file_template_name', $subTemplateId);
1048 // サブテンプレートIDの渡し方は以下の方法もある(Themlerテンプレート1.39以降はこちらが有効)
1050 if (!empty($subTemplateId)) $this->setBuffer('<!--TEMPLATE ' . $subTemplateId . ' /-->', 'component');
1053 // 現在のJoomla!ドキュメントを設定
1054 $this->gEnv->setJoomlaDocument($this);
1055 } else { // デフォルト(Joomla!v1.0テンプレート)テンプレートのとき(PC用および携帯用)
1056 // Joomla!テンプレート共通の設定
1057 define('_JEXEC', 1);
1060 global $mosConfig_absolute_path;
1061 global $mosConfig_live_site;
1062 global $mosConfig_sitename;
1063 global $mosConfig_favicon;
1064 global $mosConfig_sef;
1065 global $cur_template;
1067 require_once($this->gEnv->getJoomlaRootPath() . '/mosDef.php');// Joomla定義読み込み
1068 require_once($this->gEnv->getJoomlaRootPath() . '/mosFunc.php');
1069 require_once($this->gEnv->getJoomlaRootPath() . '/includes/sef.php');
1072 // ################### テンプレート読み込み ###################
1074 if (strStartsWith($defaultIndexFile, '/')){ // フルパス起動(WordPressテンプレート)のとき
1075 $templateIndexFile = $defaultIndexFile;
1077 $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/' . $defaultIndexFile;
1080 if (file_exists($templateIndexFile)){
1081 require_once($templateIndexFile);
1082 } else { // テンプレートが存在しないとき
1083 if ($this->gEnv->isSystemManageUser()){ // システム管理ユーザのとき
1084 echo 'template not found error: ' . $curTemplate . ', path=' . $templateIndexFile;
1086 // 一般向けにはメンテナンス画面を表示
1087 $this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
1088 $this->_showSystemPage($request, 2/*サイト非公開画面*/);// システム制御画面を表示
1090 // 運用ログに記録(一度だけ出力したい)
1091 //$this->gOpeLog->writeFatal(__METHOD__, 'テンプレートが存在しません。メンテナンス画面を表示します。(テンプレートID=' . $curTemplate . ')', 1100);
1097 if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
1099 // ##### WordPressテンプレートの場合は終了イベントを実行。WordPressのエラーメッセージは画面に出力させる。 #####
1100 if ($convType == 100){ // WordPressテンプレートのとき
1101 do_action('shutdown');
1104 // 現在の出力内容を取得し、一旦内容をクリア
1105 $srcContents = ob_get_contents();
1108 // Joomla!タグの変換処理(ウィジェット実行)
1109 if ($convType >= 1 && $convType < 100){ // Joomla!v1.5,v2.5テンプレートのとき
1110 $srcContents = $this->gPage->launchWidgetByJoomlaTag($srcContents, $convType);
1113 // 遅延実行ウィジェットの出力を埋め込む。HTMLヘッダ出力する。
1114 $destContents = $this->gPage->lateLaunchWidget($request, $srcContents);
1116 // 携帯インターフェイスのときのときは、手動変換後、バイナリコード(絵文字等)を埋め込む
1117 if ($convType == -1){ // 携帯アクセスポイントの場合
1119 $destContents = mb_convert_encoding($destContents, $mobileEncoding, M3_ENCODING);
1121 // コンテンツ変換メソッドがある場合は実行
1122 if (method_exists($this, '_convContents')){
1123 $destContents = $this->_convContents($destContents);// 絵文字埋め込み処理等
1127 // ##### CSS生成の場合は、すべてのウィジェット実行後出力を削除する #####
1128 if ($cmd == M3_REQUEST_CMD_CSS) $destContents = ''; // CSS生成のとき
1130 // ページ作成終了処理(HTTPヘッダ出力)
1131 $destContents .= $this->gPage->endPage($request, true/*出力を取得*/); // 最終HTMLを追加
1132 if ($this->gPage->isRedirect()) return '';// リダイレクトの場合ob_end_clean()を実行すると、ログインできないことがあるのでここで終了(2011/11/11)
1139 return $destContents;
1144 * @param RequestManager $request HTTPリクエスト処理クラス
1145 * @param string $subTemplateId テンプレートIDが取得できるときはサブページIDが返る
1146 * @return string テンプレート名
1148 function _defineTemplate($request, &$subTemplateId)
1150 // ########### テンプレートID(ディレクトリ名)を設定 ############
1151 // テンプレートIDの指定の方法は2パターン
1156 // 1.サブクラスの_setTemplate()で固定設定にしている場合の固定値
1160 $subTemplateId = '';
1161 $isSystemManageUser = $this->gEnv->isSystemManageUser(); // システム運用可能かどうか
1162 $useSubClassDefine = true; // サブクラスでの定義を使用するかどうか
1164 // テンプレート変更のときは、セッションのテンプレートIDを変更
1165 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); // 実行コマンドを取得
1166 if ($cmd == M3_REQUEST_CMD_CHANGE_TEMPLATE){
1167 // テンプレートIDをセッションに残す場合
1168 if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
1169 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $request->trimValueOf(M3_SYSTEM_TAG_CHANGE_TEMPLATE));
1173 // サブクラスでテンプレートIDを指定している場合はそちらを使用
1174 $templateDefined = false; // テンプレート固定かどうか
1175 if ($useSubClassDefine){
1176 $tmplStr = trim($this->_setTemplate($request));
1177 if (strlen($tmplStr) > 0){
1178 $curTemplate = $tmplStr;
1179 $templateDefined = true; // テンプレート固定かどうか
1183 // セッションにあるときは、セッションの値を使用(携帯でないとき)
1184 $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1185 if (empty($curTemplate)){
1186 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION || // 表示位置を表示するとき
1187 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
1188 // URLの引数として、ページIDとページサブIDが指定されてくる
1189 // URLの引数のテンプレートを優先し、引数で指定されていなければ、ページ用個別のテンプレートを取得する
1191 // URLの引数でテンプレートIDが指定されている場合は設定
1192 $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID); // テンプレートIDを取得
1193 if (!empty($templateId)) $curTemplate = $templateId;
1195 // ページ用個別に設定されたテンプレートがある場合は取得
1196 if (empty($curTemplate)){
1197 $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1198 $line = $this->gPage->getPageInfo($pageId, $pageSubId);
1200 $pageTemplateId = $line['pn_template_id'];
1201 $subTemplateId = $line['pn_sub_template_id']; // サブテンプレートID
1203 if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
1207 if (empty($curTemplate)){
1208 if ($pageId == $this->gEnv->getDefaultPageId()){ // 通常サイトのとき
1209 $curTemplate = $this->gSystem->defaultTemplateId();
1210 $subTemplateId = $this->gSystem->defaultSubTemplateId();
1211 } else if ($pageId == $this->gEnv->getDefaultMobilePageId()){ // 携帯サイトのとき
1212 $curTemplate = $this->gSystem->defaultMobileTemplateId(); // 携帯用デフォルトテンプレート
1213 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){ // スマートフォン用サイトのとき
1214 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId(); // スマートフォン用デフォルトテンプレート
1215 } else if ($pageId == $this->gEnv->getDefaultAdminPageId() || // 管理サイトのとき
1216 $pageId == $this->gEnv->getDefaultRegistPageId()){ // 登録サイトのとき
1217 $curTemplate = $this->gSystem->defaultAdminTemplateId();
1218 } else if (empty($pageId)){ // ページIDが指定されていないときは、ウィジェットを表示しないテンプレートのみの表示
1219 // URLの引数でテンプレートIDが指定されている場合は設定
1220 // $templateId = $request->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID); // テンプレートIDを取得
1221 // if (!empty($templateId)) $curTemplate = $templateId;
1225 // ページ用のテンプレートがあるときは優先
1226 $pageTemplateId = $this->gPage->getTemplateIdFromCurrentPageInfo($subTemplateId);
1227 if (!empty($pageTemplateId)) $curTemplate = $pageTemplateId;
1229 // テンプレートIDをセッションから取得
1230 if (empty($curTemplate) && !$isSystemManageUser){ // システム運用者はセッション値を使用できない
1231 if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
1232 if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite()){
1233 $curTemplate = $request->getSessionValue(M3_SESSION_CURRENT_TEMPLATE);// 携帯サイト、スマートフォンサイトでないときはセッション値を取得
1238 // オプションのテンプレートがある場合はオプションを優先
1239 $optionTemplate = $this->gPage->getOptionTemplateId();
1240 if (!empty($optionTemplate)){
1241 $curTemplate = $optionTemplate;
1242 $templateDefined = true; // テンプレート固定かどうか
1245 // セッションにないときはデフォルトを取得
1246 if (empty($curTemplate)){
1247 if ($this->gEnv->getIsMobileSite()){// 携帯用サイトの場合
1248 $curTemplate = $this->gSystem->defaultMobileTemplateId(); // 携帯用デフォルトテンプレート
1249 } else if ($this->gEnv->getIsSmartphoneSite()){// スマートフォン用サイトの場合
1250 $curTemplate = $this->gSystem->defaultSmartphoneTemplateId(); // スマートフォン用デフォルトテンプレート
1252 $curTemplate = $this->gSystem->defaultTemplateId();
1253 $subTemplateId = $this->gSystem->defaultSubTemplateId();
1259 if (empty($curTemplate)){
1260 // テンプレートが1つもみつからないときは、管理用テンプレートを使用
1261 $curTemplate = $this->gSystem->defaultAdminTemplateId();
1262 echo 'template not found. viewing by administration template. [' . $curTemplate . ']';
1263 } else { // セッションにテンプレートIDを保存
1264 // テンプレートIDをセッションに残す場合
1265 /* if ($this->gSystem->useTemplateIdInSession()){ // セッションに保存する場合
1266 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION || // 表示位置を表示するとき
1267 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){ // 表示位置を表示するとき(ウィジェット付き)
1269 if (!$this->gEnv->getIsMobileSite() && !$this->gEnv->getIsSmartphoneSite() && !$templateDefined){ // PC用画面でサブクラス固定でないとき場合は保存
1270 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $curTemplate);
1275 return $curTemplate;
1280 * @param RequestManager $request HTTPリクエスト処理クラス
1281 * @return bool サイトにアクセスできるかどうか
1283 function _accessSite($request)
1286 $isOpen = $this->gSystem->siteInPublic();
1288 // PC用サイト、携帯用サイト、スマートフォン用サイトの公開状況をチェック
1289 if ($this->gEnv->getIsPcSite()){
1290 if ($this->gSystem->sitePcInPublic()) return true;
1291 } else if ($this->gEnv->getIsMobileSite()){
1292 if ($this->gSystem->siteMobileInPublic()) return true;
1293 } else if ($this->gEnv->getIsSmartphoneSite()){
1294 if ($this->gSystem->siteSmartphoneInPublic()) return true;
1299 $ip = $this->gSystem->getSystemConfig(self::SITE_ACCESS_EXCEPTION_IP);
1300 if (!empty($ip) && $ip = $request->trimServerValueOf('REMOTE_ADDR')){
1310 * @param RequestManager $request HTTPリクエスト処理クラス
1311 * @param int $type 画面タイプ(0=アクセス不可、1=ログイン画面、2=サイト非公開画面)
1314 function _showSystemPage($request, $type)
1317 $pageId = 'admin_index'; // 管理画面を表示
1318 $this->gEnv->setCurrentPageId($pageId); // ここでデフォルトページサブIDが再設定される
1319 $this->gEnv->setCurrentPageSubId($this->gEnv->getDefaultPageSubId());// デフォルトページサブIDをカレントにする
1322 // DBで設定されている値を取得し、なければ管理用デフォルトテンプレートを使用
1323 if ($this->gEnv->getIsMobileSite()){ // 携帯用サイトのアクセスの場合
1324 $curTemplateId = self::M_ADMIN_TEMPLATE; // 携帯管理画面用テンプレート
1325 } else { // 携帯以外のサイトへのアクセスの場合
1326 if ($type == 1){ // ログインはデフォルトの管理画面テンプレートに固定
1327 $curTemplateId = $this->gSystem->defaultAdminTemplateId();
1329 $curTemplateId = $this->gSystem->getSystemConfig(self::CONFIG_KEY_MSG_TEMPLATE);
1330 if (empty($curTemplateId)){
1331 $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
1334 $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplateId . '/' . M3_FILENAME_INDEX;
1335 if (!file_exists($templateIndexFile)) $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
1341 $pageData = $this->_createPage($request, $curTemplateId);
1347 * @param RequestManager $request HTTPリクエスト処理クラス
1350 function _showPhpinfoPage($request)
1352 // ################### バッファリング開始 ######################
1353 // ob_end_flush()までの出力をバッファリングする
1358 // バッファ内容を送信(クライアントへの送信完了)
1362 * 以下、Joomla!v1.5テンプレート専用
1367 * @param string $pos ポジション
1368 * @return int ウィジェット数
1370 function countModules($pos)
1372 $count = $this->gPage->getWidgetsCount($pos);
1375 function getBuffer($type = null, $name = null, $attribs = array())
1377 if (isset($this->joomlaBufArray[$type])){
1378 return $this->joomlaBufArray[$type];
1383 function setBuffer($contents, $type, $name = null)
1385 $this->joomlaBufArray[$type] = $contents;
1391 * @return string 出力タイプ
1400 * @return array ヘッダ情報
1402 function getHeadData()
1405 /*$data['title'] = $this->title;
1406 $data['description']= $this->description;
1407 $data['link'] = $this->link;
1408 $data['metaTags'] = $this->_metaTags;
1409 $data['links'] = $this->_links;
1410 $data['styleSheets']= $this->_styleSheets;
1411 $data['style'] = $this->_style;
1412 $data['scripts'] = $this->_scripts;
1413 $data['script'] = $this->_script;
1414 $data['custom'] = $this->_custom;*/
1420 * @return string ベースパス
1427 * Adds a linked script to the page
1429 * @param string $url URL to the linked script
1430 * @param string $type Type of script. Defaults to 'text/javascript'
1433 function addScript($url, $type="text/javascript") {
1434 $this->_scripts[$url] = $type;
1437 * Adds a script to the page
1440 * @param string $content Script
1441 * @param string $type Scripting mime (defaults to 'text/javascript')
1444 function addScriptDeclaration($content, $type = 'text/javascript')
1446 if (!isset($this->_script[strtolower($type)])) {
1447 $this->_script[strtolower($type)] = $content;
1449 $this->_script[strtolower($type)] .= chr(13).$content;
1453 * WordPressテンプレートの起動ファイルパスを相対パスに変換
1455 * @param string $templateId テンプレートID
1456 * @param string $path テンプレートの起動ファイル絶対パス
1457 * @return string テンプレート内での相対パス。エラー発生の場合はデフォルト(index.php)を返す。
1459 function _getRelativeTemplateIndexPath($templateId, $path)
1462 $templatePath = $this->gEnv->getTemplatesPath() . '/' . $templateId . '/';
1465 $path = str_replace($templatePath, '', $path);
1466 if ($path == $savedPath) $path = M3_FILENAME_INDEX;
1470 * 旧システムディレクトリが存在するかどうかを取得
1472 * @return bool true=存在する、false=存在しない
1474 function _isExistsOldSystemDir()
1476 // 旧システムディレクトリは同ディレクト階層に存在し、ディレクトリ名の先頭に「_」が付加されているディレクトリ
1477 $currentDir = $this->gEnv->getSystemRootPath();
1478 $parentDir = dirname($currentDir);
1479 $dirName = basename($currentDir);
1481 // ##### open_basedir等のアクセス制限が掛かっていてディレクトリが見えない場合はis_dir()はfalseを返す #####
1482 // 親ディレクトリへのアクセス権をチェック
1483 if (@is_dir($parentDir)){
1484 if (@is_dir($parentDir . '/_' . $dirName)){
1489 } else { // 親ディレクトリへのアクセス権がない場合は旧システムが存在すると判断する
1494 * PHPファイルを読み込み、定義値をグローバル値に変換する
1496 * @param string $path ファイルパス
1497 * @return bool true=ファイル読み込み完了、false=ファイル読み込み失敗
1499 function _loadFileAsGlobal($path)
1501 if (file_exists($path)){
1505 $vars = get_defined_vars();
1506 foreach($vars as $varName => $varValue){
1507 if (!isset($GLOBALS[$varName])) $GLOBALS[$varName] = $varValue;