OSDN Git Service

シャットダウンイベント追加。
[magic3/magic3.git] / include / container / baseFrameContainer.php
index d2dafbf..b16c68b 100644 (file)
@@ -376,7 +376,11 @@ class BaseFrameContainer extends Core
                                // 画面を作成
                                $pageData = $this->_createPage($request, $curTemplateId, $subTemplateId);
                                
-                               // 使用した非共通ウィジェットの数をチェック
+                               // ##### 非共通ウィジェットがページ上になくてもエラーとしない #####
+                               $this->gCache->setPageCache($request, $pageData);               // キャッシュデータを設定
+                               echo $pageData;
+                                       
+/*                             // 使用した非共通ウィジェットの数をチェック
                                $nonSharedWidgetCount = $this->gPage->getNonSharedWidgetCount();
                                if ($nonSharedWidgetCount == -1){               // カウントなしの場合
                                        $this->gCache->setPageCache($request, $pageData);               // キャッシュデータを設定
@@ -395,13 +399,8 @@ class BaseFrameContainer extends Core
 
                                                // アクセス不可ページへ遷移
                                                $this->gPage->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
-                                               // システム制御モードに変更
-                                               //$this->gPage->setSystemHandleMode(11/*アクセス不可*/);
-
-                                               // システム制御画面を表示
-                                               //$this->_showSystemPage($request, 0/*アクセス不可画面*/);
                                        }
-                               }
+                               }*/
                        } else {
                                echo $cacheData;
                        }
@@ -690,6 +689,7 @@ class BaseFrameContainer extends Core
        
                if ($convType == 100){          // WordPressテンプレートのとき
                        // WordPress用ベース定義値
+                       define('WP_DEBUG', true);                       // ##### エラーメッセージ表示制御(true時noticeを表示) #####
                        define('WPINC', 'wp-includes');
                        define('ABSPATH', $this->gEnv->getWordpressRootPath() . '/' );
                        define('TEMPLATEPATH', $this->gEnv->getTemplatesPath() . '/' . $curTemplate);
@@ -707,6 +707,7 @@ class BaseFrameContainer extends Core
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/functions.php');
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/default-filters.php');
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/l10n.php');
+                       require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-error.php');
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp.php');
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-locale.php');
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-user.php');
@@ -722,6 +723,8 @@ class BaseFrameContainer extends Core
 //                     require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-walker-nav-menu.php');
 //                     require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-dependency.php');
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-post.php');                   // コンテンツAPIマネージャーからWP_Post型でデータを取得
+                       require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-post-type.php');
+                       require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-embed.php');
 
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/query.php');
                        require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/pluggable.php');
@@ -765,6 +768,9 @@ class BaseFrameContainer extends Core
 
                        // ##### データ初期化 #####
                        wp_initial_constants();                 // WordPressその他定義値設定
+                       wp_cookie_constants();                  // クッキー用定義
+                       create_initial_post_types();    // WP_Post型データ型登録
+                       register_shutdown_function('shutdown_action_hook');             // 終了時イベント登録
                        
                        // プラグイン初期化
                        $GLOBALS['wp_plugin_paths'] = array();                  // $wp_plugin_pathsは未使用?
@@ -777,24 +783,27 @@ class BaseFrameContainer extends Core
                        // WordPressメインオブジェクト作成
                        $GLOBALS['wp_version'] = '4.7.0';                       // 下位互換性チェックで引っかかるのでv4.7.0に定める
                        $GLOBALS['locale'] = $this->gEnv->getCurrentLanguage();         // 表示言語を設定
+                       $GLOBALS['wp_embed'] = new WP_Embed();
                        $GLOBALS['wp_the_query'] = new WP_Query();                              // $wp_the_queryは変更不可変数で$wp_queryは変更可変数
                        $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
                        $GLOBALS['wp'] = new WP();
                        $GLOBALS['wp_widget_factory'] = new WP_Widget_Factory();
                        $GLOBALS['gContentApi'] = new contentApi();                     // Magic3コンテンツAPIオブジェクト
                        $GLOBALS['gMenuApi'] = new menuApi();                   // Magic3メニュー情報APIオブジェクト
+                       $GLOBALS['m3WpOptions'] = array();                              // 定義値初期化
                        // テンプレートから参照可能にする
                        global $wp_query;
 
-                       // ページに配置されているウィジェットの状況からWordPress以外の主コンテンツ用のプラグインをロード
+                       // ページに配置されているウィジェットの状況からWordPress以外の主コンテンツ用のプラグイン(WooCommerce等)をロード
+                       // setup_themeイベント処理を設定
                        $GLOBALS['gContentApi']->loadPlugin();
-
+                       
                        // テンプレート初期処理
                        do_action('setup_theme');
                        load_default_textdomain();                      // 言語リソースを読み込む
                        m3WpInit();                                                     // 言語リソース読み込み後にMagic3用インターフェイス初期化。$GLOBALS['m3WpOptions']を初期化し、get_option()はここから使用可能にする。
                        $GLOBALS['wp_locale'] = new WP_Locale();                // 言語リソース読み込み後に生成
-                       
+
                        // functions.phpを読み込む。ファイル内で定義されている変数はグローバル変数に変換する。
                        $this->_loadFileAsGlobal(TEMPLATEPATH . '/functions.php');
 
@@ -873,8 +882,8 @@ class BaseFrameContainer extends Core
                                                // カテゴリー用テンプレート取得
                                                $template = get_category_template();
                                                if (empty($template)) $template = get_archive_template();               // カテゴリー用のテンプレートが取得できない場合はアーカイブ用テンプレートを取得
-                                               $wpIndexFile = $template;
-                                               
+                                               if (!empty($template)) $wpIndexFile = $template;
+
                                                // フルパスで返るので相対パスに修正
                                                //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $template);            // カテゴリーテンプレート
                                                
@@ -892,7 +901,7 @@ class BaseFrameContainer extends Core
                                                        // 年月日用テンプレート取得
                                                        $template = get_date_template();
                                                        if (empty($template)) $template = get_archive_template();               // 年月日用のテンプレートが取得できない場合はアーカイブ用テンプレートを取得
-                                                       $wpIndexFile = $template;               // 記事詳細テンプレート
+                                                       if (!empty($template)) $wpIndexFile = $template;
                                                
                                                        // フルパスで返るので相対パスに修正
                                                        //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $template);
@@ -909,7 +918,8 @@ class BaseFrameContainer extends Core
                                        
                                                        // フルパスで返るので相対パスに修正
                                                        //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_search_template());                // 検索結果テンプレート
-                                                       $wpIndexFile = get_search_template();           // 検索結果テンプレート
+                                                       $template = get_search_template();              // 検索結果テンプレート
+                                                       if (!empty($template)) $wpIndexFile = $template;
                                                        
                                                        $pageTypeDefined = true;                // ページタイプ確定
                                                }
@@ -925,14 +935,46 @@ class BaseFrameContainer extends Core
                        case M3_VIEW_TYPE_PHOTO:        // フォトギャラリー
                                break;
                        default:
+                               // 検索キーワードが設定されている場合は検索結果画面を表示
+                               $value = $request->trimValueOf('s');
+                               if (!empty($value)){
+                                       // ページ指定されていない場合(フロント画面等)、検索結果表示用ページがある場合はリダイレクト
+                                       $subId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);
+                                       if (empty($subId)){
+                                               $subId = $this->_db->getSubPageIdWithContent(M3_VIEW_TYPE_SEARCH, $this->gEnv->getCurrentPageId());// ページサブIDを取得
+                                               if (!empty($subId)){
+                                                       // リダイレクト用URLを作成
+                                                       $redirectUrl = $this->gEnv->createPageUrl();
+                                                       $redirectUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subId;
+                                                       //$redirectUrl .= '&s=' . urlencode($value);                                                    // 検索キーワード
+                                                       $redirectUrl .= '&' . M3_REQUEST_PARAM_OPERATION_TASK . '=search&' . M3_REQUEST_PARAM_KEYWORD . '=' . urlencode($value);                // 検索キーワード
+                                                       
+                                                       $this->gPage->redirect($redirectUrl);
+                                                       return;                         // ここで終了
+                                               }
+                                       }
+//                             } else {
+//                                     // 検索キーワードが設定されている場合は画面タイトルを設定
+//                                     $value = $request->trimValueOf(M3_REQUEST_PARAM_KEYWORD);
+//                                     if (!empty($value)){
+//                                     }
+                               }
+                               
+                               // ##### デフォルトのページタイトルを設定 #####
+                               $pageInfo = $this->gPage->getCurrentPageInfo();
+                               if (!empty($pageInfo)){
+                                       $pageTitle = $pageInfo['pg_name'];
+                                       if (!empty($pageTitle)) $GLOBALS['gContentApi']->setPostTitle($pageTitle);
+                               }
+                               
                                // コンテンツタイプが設定されていないページ(お問合わせページ等)に場合は、固定ページ用のテンプレートを使用
                                // ページタイプを設定
                                $GLOBALS['gContentApi']->setPageType('page');
-                                       
+                               
                                // フルパスで返るので相対パスに修正
                                //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template());          // 固定ページテンプレート
                                $wpIndexFile = get_page_template();             // 固定ページテンプレート
-                               
+                       
                                $pageTypeDefined = true;                // ページタイプ確定
                                break;
                        }
@@ -957,7 +999,7 @@ class BaseFrameContainer extends Core
                                        }
                                }
                        }
-                       
+
                        // プラグインからの起動ファイルパス変換
                        $wpIndexFile = apply_filters('template_include', $wpIndexFile);
 
@@ -1201,9 +1243,10 @@ class BaseFrameContainer extends Core
                                }
                                
                                // オプションのテンプレートがある場合はオプションを優先
-                               $optionTemplate = $this->gPage->getOptionTemplateId();
+                               list($optionTemplate, $optionSubTemplate) = $this->gPage->getOptionTemplateId();
                                if (!empty($optionTemplate)){
                                        $curTemplate = $optionTemplate;
+                                       $subTemplateId = $optionSubTemplate;
                                        $templateDefined = true;                // テンプレート固定かどうか
                                }
                                
@@ -1468,8 +1511,9 @@ class BaseFrameContainer extends Core
                        
                        // グローバル変数に変換
                        $vars = get_defined_vars();
-                       foreach($vars as $varName => $varValue) $GLOBALS[$varName] = $varValue;
-                       
+                       foreach($vars as $varName => $varValue){
+                               if (!isset($GLOBALS[$varName])) $GLOBALS[$varName] = $varValue;
+                       }
                        return true;
                } else {
                        return false;