// 旧システムがある場合はadminディレクトリまでアクセスしてインストーラを実行。
$isRedirect = false;
- if ($this->_isExistsOldSystemDir()){
+ if ($this->_isExistsOldSystemDir()){ // ディレクトリアクセス権がない場合も旧システムが存在するものとしてリダイレクトを行う
if ($this->gEnv->isAdminDirAccess()) $isRedirect = true;
} else {
$isRedirect = true;
// 画面を作成
$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); // キャッシュデータを設定
// アクセス不可ページへ遷移
$this->gPage->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
- // システム制御モードに変更
- //$this->gPage->setSystemHandleMode(11/*アクセス不可*/);
-
- // システム制御画面を表示
- //$this->_showSystemPage($request, 0/*アクセス不可画面*/);
}
- }
+ }*/
} else {
echo $cacheData;
}
$this->gPage->startWidgetXml($cmd);
// 指定のウィジェットを実行
- $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
+ $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/' . M3_FILENAME_INDEX;
if (file_exists($widgetIndexFile)){
// 実行のログを残す
$this->gPage->startWidgetRss($cmd);
// 指定のウィジェットを実行
- $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
+ $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/' . M3_FILENAME_INDEX;
if (file_exists($widgetIndexFile)){
// ウィジェット定義ID、ページ定義のシリアル番号を取得
// 指定のウィジェットを実行
if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){ // ウィジェット設定のとき
- $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/admin/index.php'; // 管理用画面
+ $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/admin/' . M3_FILENAME_INDEX; // 管理用画面
} else {
- $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/index.php';
+ $widgetIndexFile = $this->gEnv->getWidgetsPath() . '/' . $widgetId . '/' . M3_FILENAME_INDEX;
}
if (file_exists($widgetIndexFile)){
// ウィジェット定義ID、ページ定義のシリアル番号を取得
*/
function _createPage($request, $curTemplate, $subTemplateId = '')
{
- $defaultIndexFile = 'index.php'; // テンプレートの起動ファイル
+ $defaultIndexFile = M3_FILENAME_INDEX; // テンプレートの起動ファイル
$cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); // 実行コマンドを取得
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);
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');
require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-term.php');
require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-walker-page.php');
require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-theme.php');
+ require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-widget.php');
+ require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-widget-factory.php');
require_once($this->gEnv->getWordpressRootPath() . '/wp-includes/class-wp-list-util.php');
// 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');
// ##### データ初期化 #####
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は未使用?
// 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以外の主コンテンツ用のプラグイン(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(); // 言語リソース読み込み後に生成
- if ( file_exists(TEMPLATEPATH . '/functions.php')) include(TEMPLATEPATH . '/functions.php');// テンプレート初期処理
+
+ // functions.phpを読み込む。ファイル内で定義されている変数はグローバル変数に変換する。
+ $this->_loadFileAsGlobal(TEMPLATEPATH . '/functions.php');
+
do_action('after_setup_theme'); // wp-multibyte-patchプラグイン読み込み
do_action('init'); // テンプレート側からの初期処理(ウィジェットのCSSの初期化等)
do_action('wp_loaded');
// $firstValue = $params[$firstKey];
// コンテンツタイプに合わせて起動PHPファイルを決める。デフォルトはindex.phpで一覧形式で表示。
+ $pageTypeDefined = false; // ページタイプ確定したかどうか
+ $wpIndexFile = get_index_template(); // WordPress用テンプレート起動ファイル
$contentType = $GLOBALS['gContentApi']->getContentType();
switch ($contentType){
case M3_VIEW_TYPE_CONTENT: // 汎用コンテンツ
$GLOBALS['gContentApi']->setPageType('page');
// フルパスで返るので相対パスに修正
- $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template()); // 固定ページテンプレート
+// $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template()); // 固定ページテンプレート
+ $wpIndexFile = get_page_template(); // 固定ページテンプレート
// コンテンツID設定
$firstValue = $request->trimValueOf($firstKey);
$GLOBALS['gContentApi']->setContentId($firstValue);
+
+ $pageTypeDefined = true; // ページタイプ確定
}
break;
case M3_VIEW_TYPE_PRODUCT: // 製品
+ if ($firstKey == M3_REQUEST_PARAM_PRODUCT_ID || $firstKey == M3_REQUEST_PARAM_PRODUCT_ID_SHORT){ // 製品IDのとき
+ // ページタイプを設定
+ $GLOBALS['gContentApi']->setPageType('single');
+
+ // フルパスで返るので相対パスに修正
+ //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_single_template()); // 記事詳細テンプレート
+ $wpIndexFile = get_single_template(); // 記事詳細テンプレート
+
+ // コンテンツID設定
+ $firstValue = $request->trimValueOf($firstKey);
+ $GLOBALS['gContentApi']->setContentId($firstValue);
+
+ $pageTypeDefined = true; // ページタイプ確定
+ }
break;
case M3_VIEW_TYPE_BBS: // BBS
break;
case M3_VIEW_TYPE_BLOG: // ブログ
-// if ($firstKey == M3_REQUEST_PARAM_BLOG_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ID_SHORT || // ブログIDのとき
-// $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT){ // ブログ記事IDのとき
if ($firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT){ // ブログ記事IDのとき
// ページタイプを設定
$GLOBALS['gContentApi']->setPageType('single');
// フルパスで返るので相対パスに修正
- $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_single_template()); // 記事詳細テンプレート
+ //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_single_template()); // 記事詳細テンプレート
+ $wpIndexFile = get_single_template(); // 記事詳細テンプレート
// コンテンツID設定
$firstValue = $request->trimValueOf($firstKey);
$GLOBALS['gContentApi']->setContentId($firstValue);
+
+ $pageTypeDefined = true; // ページタイプ確定
} else {
// カテゴリーが設定されている場合はカテゴリー画面を表示
- $pageTypeDefined = false; // ページタイプ確定したかどうか
$value = $request->trimValueOf(M3_REQUEST_PARAM_CATEGORY_ID);
if (!empty($value)){
// ページタイプを設定
// カテゴリー用テンプレート取得
$template = get_category_template();
if (empty($template)) $template = get_archive_template(); // カテゴリー用のテンプレートが取得できない場合はアーカイブ用テンプレートを取得
-
+ if (!empty($template)) $wpIndexFile = $template;
+
// フルパスで返るので相対パスに修正
- $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $template); // カテゴリーテンプレート
+ //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $template); // カテゴリーテンプレート
$pageTypeDefined = true; // ページタイプ確定
}
// 年月日用テンプレート取得
$template = get_date_template();
if (empty($template)) $template = get_archive_template(); // 年月日用のテンプレートが取得できない場合はアーカイブ用テンプレートを取得
+ if (!empty($template)) $wpIndexFile = $template;
// フルパスで返るので相対パスに修正
- $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $template);
+ //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $template);
$pageTypeDefined = true; // ページタイプ確定
}
$GLOBALS['gContentApi']->setPageType('search'); // 検索結果表示
// フルパスで返るので相対パスに修正
- $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_search_template()); // 検索結果テンプレート
+ //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_search_template()); // 検索結果テンプレート
+ $template = get_search_template(); // 検索結果テンプレート
+ if (!empty($template)) $wpIndexFile = $template;
+
+ $pageTypeDefined = true; // ページタイプ確定
}
}
}
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()); // 固定ページテンプレート
+ //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_page_template()); // 固定ページテンプレート
+ $wpIndexFile = get_page_template(); // 固定ページテンプレート
+
+ $pageTypeDefined = true; // ページタイプ確定
break;
}
+ // コンテンツタイプが設定されているページでページタイプが設定されていないページの場合はデフォルトテンプレート(index.php)の代わりにホーム用テンプレートを取得
+ if (!empty($contentType) && !$pageTypeDefined){
+ // フルパスで返るので相対パスに修正
+ //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, get_home_template()); // ホーム用テンプレート
+ $wpIndexFile = get_home_template(); // ホーム用テンプレート
+ }
+
+ // サイトのトップページを表示する場合(コンテンツタイプが設定されていないページをデフォルトで表示する場合)は優先してフロント用テンプレートを表示
+ if (empty($contentType)){
+ //if (!$GLOBALS['gContentApi']->isHomeUrl()){
+// if ($defaultIndexFile == M3_FILENAME_INDEX){ // テンプレートの起動ファイル
+ $pageSubId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);
+ if ($this->gEnv->getCurrentPageSubId() == $this->gEnv->getDefaultPageSubId() && empty($pageSubId)){ // デフォルトページを表示し「sub」なしに限定
+ $frontPageTemplate = get_front_page_template();
+ if (!empty($frontPageTemplate)){
+ //$defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $frontPageTemplate); // フロントページテンプレート
+ $wpIndexFile = $frontPageTemplate; // フロントページテンプレート
+ }
+ }
+ }
+
+ // プラグインからの起動ファイルパス変換
+ $wpIndexFile = apply_filters('template_include', $wpIndexFile);
+
+ // Magic3用のテンプレート起動ファイルパスに変換
+// $defaultIndexFile = $this->_getRelativeTemplateIndexPath($curTemplate, $wpIndexFile);
+ $defaultIndexFile = $wpIndexFile;
+
+ // ##### テンプレート前処理(起動ファイル決定後に実行) #####
+ do_action('template_redirect');
+
// WordPressオブジェクト作成
wp();
} else if ($convType >= 1){ // Joomla!v1.5,v2.5テンプレートのとき
}
// ################### テンプレート読み込み ###################
- // テンプレートのポジションタグからウィジェットが実行される
- //$templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/index.php';
- $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/' . $defaultIndexFile;
+ // フルパスに変換
+ if (strStartsWith($defaultIndexFile, '/')){ // フルパス起動(WordPressテンプレート)のとき
+ $templateIndexFile = $defaultIndexFile;
+ } else {
+ $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplate . '/' . $defaultIndexFile;
+ }
+
if (file_exists($templateIndexFile)){
require_once($templateIndexFile);
} else { // テンプレートが存在しないとき
// 一般向けにはメンテナンス画面を表示
$this->gPage->setSystemHandleMode(10/*サイト非公開中*/);
$this->_showSystemPage($request, 2/*サイト非公開画面*/);// システム制御画面を表示
-
+
// 運用ログに記録(一度だけ出力したい)
//$this->gOpeLog->writeFatal(__METHOD__, 'テンプレートが存在しません。メンテナンス画面を表示します。(テンプレートID=' . $curTemplate . ')', 1100);
return;
// サブクラスの後処理の呼び出し
if (method_exists($this, '_postBuffer')) $this->_postBuffer($request);
+ // ##### WordPressテンプレートの場合は終了イベントを実行。WordPressのエラーメッセージは画面に出力させる。 #####
+ if ($convType == 100){ // WordPressテンプレートのとき
+ do_action('shutdown');
+ }
+
// 現在の出力内容を取得し、一旦内容をクリア
$srcContents = ob_get_contents();
ob_clean();
// バッファを破棄
//ob_end_flush();
ob_end_clean();
-
+
// 送信データを返す
return $destContents;
}
}
// オプションのテンプレートがある場合はオプションを優先
- $optionTemplate = $this->gPage->getOptionTemplateId();
+ list($optionTemplate, $optionSubTemplate) = $this->gPage->getOptionTemplateId();
if (!empty($optionTemplate)){
$curTemplate = $optionTemplate;
+ $subTemplateId = $optionSubTemplate;
$templateDefined = true; // テンプレート固定かどうか
}
$curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
} else {
// テンプレートの存在チェック
- $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplateId . '/index.php';
+ $templateIndexFile = $this->gEnv->getTemplatesPath() . '/' . $curTemplateId . '/' . M3_FILENAME_INDEX;
if (!file_exists($templateIndexFile)) $curTemplateId = self::SYSTEM_TEMPLATE;// システム画面用テンプレート
}
}
// テンプレートまでのパスを削除
$path = str_replace($templatePath, '', $path);
- if ($path == $savedPath) $path = 'index.php';
+ if ($path == $savedPath) $path = M3_FILENAME_INDEX;
return $path;
}
/**
$currentDir = $this->gEnv->getSystemRootPath();
$parentDir = dirname($currentDir);
$dirName = basename($currentDir);
- if (is_dir($parentDir . '/_' . $dirName)){
+
+ // ##### open_basedir等のアクセス制限が掛かっていてディレクトリが見えない場合はis_dir()はfalseを返す #####
+ // 親ディレクトリへのアクセス権をチェック
+ if (@is_dir($parentDir)){
+ if (@is_dir($parentDir . '/_' . $dirName)){
+ return true;
+ } else {
+ return false;
+ }
+ } else { // 親ディレクトリへのアクセス権がない場合は旧システムが存在すると判断する
+ return true;
+ }
+ }
+ /**
+ * PHPファイルを読み込み、定義値をグローバル値に変換する
+ *
+ * @param string $path ファイルパス
+ * @return bool true=ファイル読み込み完了、false=ファイル読み込み失敗
+ */
+ function _loadFileAsGlobal($path)
+ {
+ if (file_exists($path)){
+ include($path);
+
+ // グローバル変数に変換
+ $vars = get_defined_vars();
+ foreach($vars as $varName => $varValue){
+ if (!isset($GLOBALS[$varName])) $GLOBALS[$varName] = $varValue;
+ }
return true;
} else {
return false;