OSDN Git Service

パンくずリスト生成機能追加。
[magic3/magic3.git] / include / manager / pageManager.php
1 <?php
2 /**
3  * 画面制御マネージャー
4  *
5  * 画面の作成、遷移を処理する
6  *
7  * PHP versions 5
8  *
9  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
10  *
11  * @package    Magic3 Framework
12  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
13  * @copyright  Copyright 2006-2018 Magic3 Project.
14  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
15  * @version    SVN: $Id$
16  * @link       http://www.magic3.org
17  */
18 require_once(M3_SYSTEM_INCLUDE_PATH . '/common/core.php');
19 require_once(M3_SYSTEM_INCLUDE_PATH . '/common/scriptLibInfo.php');
20
21 class PageManager extends Core
22 {
23         private $popupMsg;                              // ポップアップダイアログメッセージ
24         private $showPositionMode;                      // ポジション表示モード
25         private $showWidget;                    // ウィジェットの単体表示
26         private $systemHandleMode;                      // システム制御遷移モード(1=サイト非公開時)
27         private $isPageEditable;                // フロント画面ページ編集可能モード
28         private $isTransparentMode;             // 画面透過モード
29         private $isEditMode;                    // フロント画面編集モード
30         private $isLayout;                              // 画面レイアウト中かどうか
31         private $isPageTopUrl;                  // ページトップ(サブページ内のトップ位置)のURLかどうか
32         private $isContentDetailPage;   // コンテンツ詳細画面のページかどうか
33         private $tmpData;                               // データ作成用
34         private $db;                                    // DBオブジェクト
35         private $defaultScriptFiles;    // デフォルトで読み込むスクリプトファイル
36         private $defaultCssFiles;               // デフォルトで読み込むCSSファイル
37         private $defaultAdminScriptFiles;       // デフォルトで読み込むスクリプトファイル(管理用)
38         private $defaultAdminCssFiles;          // デフォルトで読み込むCSSファイル(管理用)
39         private $defaultAdminDirScriptFiles;    // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
40         private $defaultAdminDirCssFiles;       // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
41         private $headScriptFiles = array();             // ウィジェットからの追加で読み込むスクリプトファイル
42         private $headPreMobileScriptFiles = array();// ウィジェットからの追加で読み込むスクリプトファイル(jQueryMobile用挿入ファイル)
43         private $headCssFiles = array();                // ウィジェットからの追加で読み込むCSSファイル
44         private $headRssFiles = array();                // HTMLヘッダに出力するRSS配信情報
45         private $currentWidgetPosition;                 // 現在のウィジェットのポジション
46         private $currentWidgetIndex;                    // 現在のウィジェットのポジション番号
47         private $pageDefPosition;               // 現在取得しているページ定義のポジション
48         private $pageDefRows;                   // ページ定義レコード
49         private $nonSharedWidgetCount = -1;     // 非共通ウィジェットの数(-1=ページ作成でないとき)
50         private $replaceHeadDone;                       // ヘッダマクロ変換処理が完了したかどうか
51         private $useHelp = false;               // 標準ヘルプ機能を使用するかどうか
52         private $hasScriptCache = false;        // JavaScriptファイルをブラウザにキャッシュさせるかどうか
53         private $isAccessPointWithAdminMenu;                            // 管理メニューを使用するアクセスポイントかどうか
54         private $lateLaunchWidgetList;  // 遅延実行ウィジェットのリスト
55         private $latelaunchWidgetParam;         // 遅延実行ウィジェットのパラメータ
56         private $defPositions = array();        // テンプレート上のポジション(画面定義データすべて)
57         private $viewPositions = array();       // テンプレート上のポジション(ウィジェット表示ありのみ)
58         private $viewPosId = array();           // テンプレート上のポジションのタグID
59         private $updateParentWindow;            // 親ウィンドウを再描画するかどうか
60         private $updateDefSerial;                       // 更新する項目のページ定義シリアル番号
61         private $headDescription;                               // HTMLヘッダ「description」に出力する文字列
62         private $headKeywords;                          // HTMLヘッダ「keywords」に出力する文字列
63         private $headOthers;                            // HTMLヘッダに出力するタグ文字列
64         private $adminHeadOthers;                               // HTMLヘッダに出力するタグ文字列(管理画面用)
65         private $lastHeadTitle;                         // 最後にヘッダ部titleにセットした文字列
66         private $lastHeadDescription;           // 最後にヘッダ部descriptionにセットした文字列
67         private $lastHeadKeywords;                      // 最後にヘッダ部keywordsにセットした文字列
68         private $headCss = array();                     // HTMLヘッダにCSS出力する文字列
69         private $headScript = array();          // HTMLヘッダにJavascript出力する文字列
70         private $headPreMobileScript = array();         // HTMLヘッダにJavascript出力する文字列(jQueryMobile用挿入スクリプト)
71         private $headString = array();          // HTMLヘッダに出力する任意文字列
72         private $exportCss = array();           // 外部出力でCSS出力する文字列
73         private $lastHeadCss;                           // 最後に設定したHTMLヘッダにCSS出力する文字列
74         private $lastHeadScript;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
75         private $lastHeadString;                        // 最後に設定したHTMLヘッダに出力する任意文字列
76         private $initScript = '';                               // ウィンドウ初期化時に実行されるスクリプト
77         private $outputByHtml = true;                           // HTMLフォーマットで出力するかどうか
78         private $outputHead;                            // HTMLヘッダ出力を行ったかどうか
79         private $outputTheme;                           // jQueryUIテーマ出力を行ったかどうか
80         private $outputAjaxResponseBody;        // AJAX用のレスポンスボディデータかどうか
81         private $isAbort;                                       // ページ作成処理を中断するかどうか
82         private $isWidgetAbort;                         // 各ウィジェット処理を中断するかどうか
83         private $isRedirect;                            // リダイレクトするかどうか
84         private $isSystemPage;                          // システム制御ページを表示するかどうか
85         private $libFiles;                                      // javascript追加用ライブラリ
86         private $pageDefRev = 234;                              // 画面定義のリビジョン番号
87         private $headSubTitle = array();                                // ヘッダタグサブタイトル
88         private $headSubTitleUrl = array();                             // ヘッダサブタイトルのリンク先
89         private $pageInfo;                                      // すべてのページ情報
90         private $currentPageInfo;                       // 現在のページのページ情報
91         private $configWidgetInfo;                      // ウィジェット設定画面のウィジェットの情報
92         private $contentType = '';                              // ページのコンテンツタイプ
93         private $mainContentTypeInfo;                           // フロント画面で使用する主要コンテンツタイプ
94         private $subContentTypeInfo;                            // フロント画面で使用する補助コンテンツタイプ
95         private $mainFeatureTypeInfo;                           // フロント画面で使用する主要機能タイプ
96         private $adminFeatureTypeInfo;                                          // 管理画面専用で使用する主要機能タイプ
97         private $rssVersion;                                    // RSSバージョン
98         private $rssChannel;                            // RSSチャンネルデータ
99         private $selectedJQueryFilename;                // 使用対象のjQueryファイル
100         private $selectedJQueryUiFilename;              // 使用対象のjQuery UIファイル
101         private $selectedJQueryMobileFilename;          // 使用対象のjQueryMobileファイル
102         private $urlParamOrder;                                 // URLパラメータの並び順
103         private $wysiwygEditor;                         // 管理画面用WYSIWYGエディター
104         private $optionTemplateId;                      // 追加設定するテンプレートID
105         private $optionSubTemplateId;                   // 追加設定するサブテンプレートID
106         private $isContentGooglemaps;           // コンテンツにGoogleマップが含むかどうか
107         private $useGooglemaps;                         // Googleマップを使用するかどうか
108         private $useBootstrap;                          // Bootstrapを使用するかどうか
109         private $isHtml5;                                       // HTML5で出力するかどうか
110         private $ckeditorCssFiles = array();    // CKEditor用のCSSファイル
111         private $ckeditorTemplateType;                  // CKEditor用のテンプレートタイプ
112         private $adminSubNavbarDef = array();           // 管理画面用のサブメニューバーの定義
113         private $adminBreadcrumbDef = array();                  // 管理画面用パンくずリスト定義
114         private $adminBreadcrumbDefHelp = array();                              // 管理画面用パンくずリストヘルプ定義
115         const CONFIG_KEY_HEAD_TITLE_FORMAT = 'head_title_format';               // ヘッダ作成用フォーマット
116         const ADMIN_WIDGET_ID = 'admin_main';           // 管理用ウィジェットのウィジェットID
117         //const CONTENT_TYPE_WIKI = 'wiki';             // ページのコンテンツタイプ(Wiki)
118         const WIDGET_ID_TAG_START = '{{WIDGETID:';              // 遅延実行用タグ
119         const WIDGET_ID_TAG_END = '}}';         // 遅延実行用タグ
120         const WIDGET_ID_TITLE_TAG_START = '{{WIDGETID_TITLE:';          // 遅延実行用タグ(タイトル埋め込み用)
121         const WIDGET_ID_TITLE_TAG_END = '}}';                                           // 遅延実行用タグ(タイトル埋め込み用)
122         const WIDGET_ID_SEPARATOR = ',';
123         const HEAD_TAGS                         = '{{HEAD_TAGS}}';                              // HTMLヘッダ出力用タグ
124         const MENUBAR_TAGS                      = '{{MENUBAR_TAGS}}';                           // メニューバー出力用タグ
125         const MENUBAR_SCRIPT_TAGS       = '{{MENUBAR_SCRIPT_TAGS}}';                            // メニューバー出力用スクリプトタグ
126         const WIDGET_ICON_IMG_SIZE = 32;                        // ウィジェットアイコンサイズ
127         const WIDGET_INVISIBLE_CLASS = 'm3invisible';                   // 非表示ウィジェットクラス
128         const WIDGET_LOGIN_STATUS_CLASS = 'm3loginstatus';              // ログイン状態連動クラス
129         const WIDGET_OUTER_CLASS = 'm3_widget_outer';                   // ウィジェット外枠クラス
130         const WIDGET_OUTER_CLASS_HEAD_POSITION = 'm3_pos_';                     // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
131         const WIDGET_OUTER_CLASS_WIDGET_TAG = 'm3_';                            // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
132 //      const WIDGET_INNER_CLASS = 'm3_widget_inner';                   // ウィジェットの内側クラス
133         const POSITION_TAG_HEAD = 'm3pos_';                     // ポジションの識別用タグIDヘッダ
134         const WIDGET_TAG_HEAD = 'm3widget_';                    // ウィジェットの識別用タグIDヘッダ
135 //      const WIDGET_TAG_HEAD_SHORT = 'm3_';                    // ウィジェットの識別用タグIDヘッダ
136         const WIDGET_TYPE_TAG_HEAD = 'm3widgettype_';                   // ウィジェット種別の識別用タグIDヘッダ
137         const WIDTET_CLASS_NAME = 'm3widget';                   // ウィジェットオブジェクトのタグクラス名
138         const WIDTET_CLASS_TYPE_0 = 'm3widget_type0';                   // ウィジェットオブジェクトのタグクラス(グローバル属性でない)
139         const WIDTET_CLASS_TYPE_1 = 'm3widget_type1';                   // ウィジェットオブジェクトのタグクラス(グローバル属性)
140         const POSITION_CLASS_NAME = 'm3position';               // ポジションオブジェクトのタグクラス名
141         const JOOMLA10_DEFAULT_WIDGET_MENU_PARAM = 'class="moduletable"';       // Joomla!1.0用デフォルトメニューパラメータ値
142         const ADMIN_TEMPLATE = '_admin';                // PC管理用テンプレートID
143         const M_ADMIN_TEMPLATE = 'm/_admin';    // 携帯用管理画面テンプレートID
144         const SCRIPT_LIB_SEPARATOR = ';';                       // JavaScriptライブラリ読み込み設定のライブラリの区切り
145         const PAGE_ID_SEPARATOR = ',';                          // ページIDとページサブID連結用
146         const DEFAULT_ADMIN_FAVICON_FILE = '/images/system/favicon.ico';                        // デフォルトの管理画面用faviconファイル
147         const DEFAULT_FAVICON_FILE = '/favicon.ico';                    // デフォルトのfaviconファイル
148 //      const DEFAULT_SITE_NAME = 'サイト名未設定';              // 管理画面用のデフォルトサイト名
149         const DEFAULT_ADMIN_TITLE = '管理画面';                     // デフォルトの管理画面名
150         const WIDGET_TITLE_START = '[';                                 // ウィジェットのタイトルの括弧
151         const WIDGET_TITLE_END = ']';                                   // ウィジェットのタイトルの括弧
152         const DEFAULT_RSS_VERSION = '1.0';                              // デフォルトのRSSのバージョン
153         const CF_ACCESS_IN_INTRANET = 'access_in_intranet';             // イントラネット運用かどうか
154         const CF_USE_LATEST_SCRIPT_LIB = 'dev_use_latest_script_lib';           // 最新のJavaScriptライブラリを使用するかどうか
155         const CF_GOOGLE_MAPS_KEY = 'google_maps_key';                           // Googleマップ利用キー
156         const CF_CONFIG_WINDOW_OPEN_TYPE = 'config_window_open_type';           // ウィジェット設定画面のウィンドウ表示タイプ(0=別ウィンドウ、1=タブ)
157         const CF_JQUERY_VERSION = 'jquery_version';                     // jQueryバージョン
158         const CF_EXTERNAL_JQUERY = 'external_jquery';                   // システム外部のjQueryを使用するかどうか
159         const CF_WYSIWYG_EDITOR = 'wysiwyg_editor';             // 管理画面用WYSIWYGエディター
160         const CF_ADMIN_JQUERY_VERSION = 'admin_jquery_version';                 // 管理画面用jQueryバージョン
161         const CF_USE_JQUERY = 'use_jquery';                             // jQueryを常に使用するかどうか
162         const CF_SMARTPHONE_USE_JQUERY_MOBILE = 'smartphone_use_jquery_mobile';         // スマートフォン画面でjQuery Mobileを使用
163         const SD_HEAD_OTHERS    = 'head_others';                // ヘッダその他タグ
164         const DEFAULT_THEME_DIR = '/ui/themes/';                                // jQueryUIテーマ格納ディレクトリ
165         const THEME_CSS_FILE = 'jquery-ui.custom.css';          // テーマファイル
166         const CONFIG_ICON_FILE = '/images/system/config.png';                   // ウィジェット定義画面アイコン
167         const ADJUST_ICON_FILE = '/images/system/adjust_widget.png';    // 位置調整アイコン
168         const SHARED_ICON_FILE = '/images/system/shared.png';   // グローバル属性
169         const DELETE_ICON_FILE = '/images/system/delete.png';   // ウィジェット削除
170         const CONFIG_ICON32_FILE = '/images/system/config32.png';                       // ウィジェット定義画面アイコン(ツールチップ用)
171         const ADJUST_ICON32_FILE = '/images/system/adjust_widget32.png';        // 位置調整アイコン(ツールチップ用)
172         const CLOSE_BOX_ICON32_FILE = '/images/system/close_box.png';           // ウィンドウ閉じるアイコン(ツールチップ用)
173         const NOTICE_ICON_FILE = '/images/system/notice16.png';         // ウィジェット配置注意アイコン
174         const ALERT_ICON_FILE = '/images/system/alert16.png';           // ウィジェット配置警告アイコン
175 //      const ADMIN_ICON_FILE = '/images/system/admin64.png';           // パネルメニュー管理画面遷移用アイコン
176 //      const LOGOUT_ICON_FILE = '/images/system/logout64.png';         // パネルメニューログアウト用アイコン
177 //      const EDIT_PAGE_ICON_FILE = '/images/system/create_page64.png';         // パネルメニュー編集用アイコン   
178         const ADMIN_ICON_FILE = '/images/system/home32.png';            // パネルメニュー管理画面遷移用アイコン
179         const LOGOUT_ICON_FILE = '/images/system/logout32.png';         // パネルメニューログアウト用アイコン
180         const EDIT_PAGE_ICON_FILE = '/images/system/create_page32.png';         // パネルメニュー編集用アイコン   
181 //      const EDIT_END_ICON_FILE = '/images/system/close32.png';                // パネルメニュー編集終了用アイコン
182         const EDIT_END_ICON_FILE = '/images/system/back32.png';         // パネルメニュー編集終了用アイコン
183         const CLOSE_ICON_FILE = '/images/system/close32.png';           // ウィンドウ閉じるアイコン
184         const PREV_ICON_FILE = '/images/system/prev48.png';             // ウィンドウ「前へ」アイコン
185         const NEXT_ICON_FILE = '/images/system/next48.png';             // ウィンドウ「次へ」アイコン
186         const DEFAULT_READMORE_TITLE = 'もっと読む';                       // もっと読むボタンのデフォルトタイトル
187         const POS_HEAD_NAV_MENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー" data-placement="auto"></i> ';               // 特殊ポジションブロック(ナビゲーションメニュー)
188         const WIDGET_MARK_MAIN = '<i class="glyphicon glyphicon-tower" rel="m3help" title="メイン型" data-placement="auto"></i> ';          // ウィジェットの機能マーク(メイン型ウィジェット)
189         const WIDGET_MARK_NAVMENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー" data-placement="auto"></i> ';             // ウィジェットの機能マーク(ナビゲーションメニュー)
190         const WIDGET_FUNCTION_MARK_BOOTSTRAP = ' <span class="label label-warning" rel="m3help" title="Bootstrap型テンプレート対応" data-placement="auto">B</span>';                   // ウィジェット機能マーク(Boostrap型テンプレート
191         const WIDGET_FUNCTION_MARK_WORDPRESS = ' <span class="label label-warning" rel="m3help" title="WordPress型テンプレート対応" data-placement="auto">W</span>';                   // ウィジェット機能マーク(WordPress型テンプレート
192         const WIDGET_STYLE_NAVMENU = '_navmenu';                // ウィジェットの表示スタイル(ナビゲーションメニュー)
193         const WIDGET_STYLE_WORDPRESS = '_wordpress';                                            // ウィジェットの表示スタイル(WordPressテンプレート用出力)
194         const WIDGET_STYLE_WORDPRESS_NOTITLE = '_wordpress_notitle';            // ウィジェットの表示スタイル(WordPressテンプレート(タイトルなし)用出力)
195         
196         // アドオンオブジェクト用
197         const CONTENT_OBJ_ID    = 'contentlib'; // 汎用コンテンツオブジェクトID
198         const BLOG_OBJ_ID               = 'bloglib';            // ブログオブジェクトID
199         const LINKINFO_OBJ_ID   = 'linkinfo';   // リンク情報オブジェクトID
200         
201         // インナーウィジェット用
202         const IWIDTET_CMD_CONTENT = 'content';          // コンテンツ取得
203         const IWIDTET_CMD_INIT = 'init';                        // 初期化
204         const IWIDTET_CMD_UPDATE = 'update';            // 更新
205         const IWIDTET_CMD_CALC = 'calc';                        // 計算
206         
207         // Magic3用スクリプト
208         const M3_ADMIN_SCRIPT_FILENAME                  = 'm3admin2.0.1.js';                            // 管理機能用スクリプト(FCKEditor2.6.6、CKEditor4.0.1対応)
209         const M3_ADMIN_WIDGET_SCRIPT_FILENAME   = 'm3admin_widget2.0.10.js';    // 管理機能(ウィジェット操作)用スクリプト(Magic3 v1.15.0以降)
210         const M3_ADMIN_WIDGET_CSS_FILE                  = '/m3/widget.css';                     // 管理機能(ウィジェット操作)用CSSファイル
211         const M3_STD_SCRIPT_FILENAME                    = 'm3std1.5.2.js';                      // 一般、管理機能共通スクリプト
212 //      const M3_PLUS_SCRIPT_FILENAME                   = 'm3plus1.6.2.js';                     // フロント画面追加用スクリプト(FCKEditor2.6.6対応、CKEditor4.0.1対応)
213         const M3_OPTION_SCRIPT_FILENAME                 = 'm3opt1.2.1.js';                      // AJAXを含んだオプションライブラリファイル(jQuery必須)
214         const M3_ADMIN_CSS_FILE                                 = 'm3/admin.css';                       // 管理機能用のCSS
215         const M3_EDIT_CSS_FILE                                  = 'm3/edit.css';                        // フロント画面編集用のCSS
216         const M3_DEFAULT_CSS_FILE                               = 'm3/default.css';                     // フロント画面共通のデフォルトCSS
217         const M3_CKEDITOR_CSS_FILE                              = 'm3/ckeditor.css';                    // CKEditorの編集エリア用CSS
218         
219         // 読み込み制御
220         const USE_BOOTSTRAP_ADMIN       = false;                        // 管理画面でBootstrapを使用するかどうか(デフォルト値)
221         const BOOTSTRAP_BUTTON_CLASS = 'btn btn-default';
222         
223         // UI
224         const FILEBROWSER_WIDTH_RATIO = '0.8';                  // ファイルブラウザ幅比率
225         const FILEBROWSER_HEIGHT_RATIO = '0.8';                 // ファイルブラウザ高さ比率
226         
227         /**
228          * コンストラクタ
229          */
230         function __construct()
231         {
232                 global $gInstanceManager;
233                 global $gEnvManager;
234                 global $gSystemManager;
235                 global $gRequestManager;
236                                 
237                 // 親クラスを呼び出す
238                 parent::__construct();
239                 
240                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
241                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
242                 
243                 // システムDBオブジェクト取得
244                 $this->db = $gInstanceManager->getSytemDbObject();
245                 
246                 // 運用方法
247                 $value = $gSystemManager->getSystemConfig(self::CF_ACCESS_IN_INTRANET);         // イントラネット運用かどうか
248                 if (empty($value)){             // インターネット運用
249                         $this->useGooglemaps = true;                            // Googleマップを使用するかどうか
250                 }
251                 $this->useHelp = true;          // ヘルプ機能
252                 
253                 // デフォルトのWYSIWYGエディターを取得
254                 $this->wysiwygEditor = $gSystemManager->getSystemConfig(self::CF_WYSIWYG_EDITOR);                               // 管理画面用WYSIWYGエディター
255                 
256                 // ##### Javascriptライブラリのバージョン設定 #####
257                 // jQueryバージョン設定
258                 // アクセスする画面に応じてjQueryのバージョンを設定
259                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
260                         $value = $gSystemManager->getSystemConfig(self::CF_ADMIN_JQUERY_VERSION);// 管理画面用jQueryバージョン
261                         
262                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET && strStartsWith($widgetId, 'm/')){// 携帯用アクセスポイント用の管理画面の場合はWYSIWYGエディターはFCKEditorに固定
263                                 $this->wysiwygEditor = ScriptLibInfo::LIB_FCKEDITOR;                            // FCKEditorに固定
264                         }
265                         
266                         // 管理画面にBOOTSTRAPを使用するかどうか(初期値)
267                         $this->useBootstrap = self::USE_BOOTSTRAP_ADMIN;
268                         
269                         // CKEditorのバージョン設定
270                         // 小画面デバイス最適化の場合は最新バージョンを使用
271                         if ($gEnvManager->isSmallDeviceAdmin()) ScriptLibInfo::setCkeditorVer(1/*最新*/);
272                 } else {
273                         $value = $gSystemManager->getSystemConfig(self::CF_JQUERY_VERSION);// jQueryバージョン
274                 }
275                 ScriptLibInfo::setJQueryVer($value);
276                 
277                 // WYSISIGエディターのタイプを設定。ScriptLibInfo::getLib()を実行する前に設定。
278                 ScriptLibInfo::setWysiwygEditorType($this->wysiwygEditor);
279                 
280                 // Javascriptライブラリ
281                 $this->libFiles = ScriptLibInfo::getLib();                      // ライブラリ取得
282                 
283                 // jQueryファイル名取得
284                 $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(0);                    // 使用対象のjQueryファイル
285                 $this->selectedJQueryUiFilename = ScriptLibInfo::getJQueryFilename(1);          // 使用対象のjQuery UIファイル
286
287                 // ##### フロント画面用のデフォルトのJavascript、CSSを取得 #####
288                 $this->defaultScriptFiles       =       array(
289                                                                                         $this->selectedJQueryFilename,                  // jQuery
290                                                                                         self::M3_STD_SCRIPT_FILENAME
291                                                                                 );
292                 $this->defaultCssFiles          =       array(
293                                                                                         self::M3_DEFAULT_CSS_FILE                               // フロント画面共通のデフォルトCSS
294                                                                                 );
295                 
296                 // ##### 管理機能用のデフォルトのJavascript、CSSを取得 #####
297                 if (defined('M3_STATE_IN_INSTALL')){            // インストーラの場合のスクリプト
298                         $this->defaultAdminScriptFiles  =       array(
299                                                                                                         $this->selectedJQueryFilename,                  // jQuery
300                                                                                                 //      self::M3_STD_SCRIPT_FILENAME,
301                                                                                                         self::M3_ADMIN_SCRIPT_FILENAME
302                                                                                                 );
303                         $this->defaultAdminCssFiles             =       array();        // 管理機能用のCSS
304                 } else {
305                         $this->defaultAdminScriptFiles  =       array(
306                                                                                                         $this->selectedJQueryFilename,                  // jQuery
307                                                                                                         $this->selectedJQueryUiFilename,                                // jQuery UI Core
308                                                                                                         ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME,             // jQuery Contextmenu Lib
309                                                                                                         self::M3_STD_SCRIPT_FILENAME,
310                                                                                                         self::M3_ADMIN_SCRIPT_FILENAME,
311                                                                                                         self::M3_OPTION_SCRIPT_FILENAME
312                                                                                                 );
313                         $this->defaultAdminCssFiles             =       array(
314                                                                                                         self::M3_ADMIN_CSS_FILE                 // 管理機能用のCSS
315                                                                                                 );
316                         
317                         // Javascriptライブラリ
318                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);     // 管理パネル用
319                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_EASING);            // 管理パネル用
320                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_NUMERIC);           // 入力制限プラグイン
321 //                      $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_RESPONSIVETABLE);// 管理画面作成用
322                 }
323                 
324                 // 管理権限なしで管理ディレクトリアクセスで読み込むスクリプトファイル
325                 $this->defaultAdminDirScriptFiles = array($this->selectedJQueryFilename);                       // jQuery
326                 
327                 // 遅延ウィジェットリスト                                                                    
328                 $this->lateLaunchWidgetList = array();
329                 $this->latelaunchWidgetParam = array();
330                 
331                 // DB接続可能なときは設定値を取得
332                 if ($gEnvManager->canUseDb()){
333                         $value = $this->gSystem->getSystemConfig('script_cache_in_browser');    // ブラウザにJavaScriptファイルのキャッシュを保持するかどうか
334                         if ($value != '') $this->hasScriptCache = $value;
335                 }
336                 
337                 $this->rssVersion = self::DEFAULT_RSS_VERSION;                                  // RSSバージョン
338                 
339                 // フロント画面で使用する主要コンテンツタイプ
340                 $this->mainContentTypeInfo       = array(
341                                                                                                 array(  'name' => '会員情報',                                       'value' => M3_VIEW_TYPE_MEMBER),
342                                                                                                 array(  'name' => '汎用コンテンツ',                              'value' => M3_VIEW_TYPE_CONTENT),
343                                                                                                 array(  'name' => '製品',                                             'value' => M3_VIEW_TYPE_PRODUCT),
344                                                                                                 array(  'name' => 'BBS',                                                'value' => M3_VIEW_TYPE_BBS),
345                                                                                                 array(  'name' => 'ブログ',                                          'value' => M3_VIEW_TYPE_BLOG),
346                                                                                                 array(  'name' => 'Wiki',                                               'value' => M3_VIEW_TYPE_WIKI),
347                                                                                                 array(  'name' => 'ユーザ作成コンテンツ',             'value' => M3_VIEW_TYPE_USER),
348                                                                                                 array(  'name' => 'イベント情報',                         'value' => M3_VIEW_TYPE_EVENT),
349                                                                                                 array(  'name' => 'フォトギャラリー',                   'value' => M3_VIEW_TYPE_PHOTO)
350                                                                                         );
351                 // フロント画面で使用する補助コンテンツタイプ(ページ属性に対応しない)
352                 $this->subContentTypeInfo        = array(       array(  'name' => '新着情報',                                       'value' => M3_VIEW_TYPE_NEWS),
353                                                                                                 array(  'name' => 'コメント',                                       'value' => M3_VIEW_TYPE_COMMENT),
354                                                                                                 array(  'name' => 'イベント予約',                         'value' => M3_VIEW_TYPE_EVENTENTRY),
355                                                                                                 array(  'name' => 'バナー',                                          'value' => M3_VIEW_TYPE_BANNER)
356                                                                                         );
357                 // フロント画面で使用する主要機能タイプ(「ダッシュボード」は含まない)
358                 $this->mainFeatureTypeInfo       = array(       array(  'name' => '検索',                                             'value' => M3_VIEW_TYPE_SEARCH),
359                                                                                                 array(  'name' => 'Eコマース',                                      'value' => M3_VIEW_TYPE_COMMERCE),
360                                                                                                 array(  'name' => 'カレンダー',                                    'value' => M3_VIEW_TYPE_CALENDAR)
361                                                                                         );
362                 // 管理画面専用で使用する機能タイプ
363                 $this->adminFeatureTypeInfo      = array(       array(  'name' => 'ダッシュボード',                              'value' => M3_VIEW_TYPE_DASHBOARD)
364                                                                                         );
365                                                                                         
366                 // URLパラメータ並び順
367                 $this->urlParamOrder = array(
368                         // コンテンツID
369                         M3_REQUEST_PARAM_CONTENT_ID                             => -20,         // 汎用コンテンツID
370                         M3_REQUEST_PARAM_CONTENT_ID_SHORT               => -19,         // 汎用コンテンツID(略式)
371                         M3_REQUEST_PARAM_PRODUCT_ID                             => -18,         // 製品ID
372                         M3_REQUEST_PARAM_PRODUCT_ID_SHORT               => -17,         // 製品ID(略式)
373                         M3_REQUEST_PARAM_BLOG_ID                                => -16,         // ブログID
374                         M3_REQUEST_PARAM_BLOG_ID_SHORT                  => -15,         // ブログID(略式)
375                         M3_REQUEST_PARAM_BLOG_ENTRY_ID                  => -14,         // ブログ記事ID
376                         M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT    => -13,         // ブログ記事ID(略式)
377                         M3_REQUEST_PARAM_BBS_ID                                 => -12,         // 掲示板投稿記事ID
378                         M3_REQUEST_PARAM_BBS_ID_SHORT                   => -11,         // 掲示板投稿記事ID(略式)
379                         M3_REQUEST_PARAM_BBS_THREAD_ID                  => -10,         // 掲示板投稿スレッドID
380                         M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT    => -9,          // 掲示板投稿スレッドID(略式)
381                         M3_REQUEST_PARAM_USER_ID                                => -8,          // ユーザ作成コンテンツID
382                         M3_REQUEST_PARAM_USER_ID_SHORT                  => -7,          // ユーザ作成コンテンツID(略式)
383                         M3_REQUEST_PARAM_ROOM_ID                                => -6,          // ユーザ作成コンテンツ区画ID
384                         M3_REQUEST_PARAM_ROOM_ID_SHORT                  => -5,          // ユーザ作成コンテンツ区画ID(略式)
385                         M3_REQUEST_PARAM_EVENT_ID                               => -4,          // イベントID
386                         M3_REQUEST_PARAM_EVENT_ID_SHORT                 => -3,          // イベントID(略式)
387                         M3_REQUEST_PARAM_PHOTO_ID                               => -2,          // 画像ID
388                         M3_REQUEST_PARAM_PHOTO_ID_SHORT                 => -1,          // 画像ID(略式)
389                         // URLパラメータ
390                         M3_REQUEST_PARAM_PAGE_SUB_ID                    => 1,           // ページサブID
391                         M3_REQUEST_PARAM_PAGE_CONTENT_ID                => 2,           // ページコンテンツID
392                         M3_REQUEST_PARAM_WIDGET_ID                              => 3,           // ウィジェットID
393                         M3_REQUEST_PARAM_TEMPLATE_ID                    => 4,           // テンプレートID
394                         M3_REQUEST_PARAM_URL                                    => 5,           // リンク先等のURL
395                         M3_REQUEST_PARAM_STAMP                                  => 6,           // 公開発行ID
396                         M3_REQUEST_PARAM_OPTION                                 => 7,           // 通信オプション
397                         M3_REQUEST_PARAM_OPERATION_COMMAND              => 8,           // 実行処理
398                         M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND => 9,           // Wikiコマンド実行
399                         M3_REQUEST_PARAM_OPERATION_TASK                 => 10,          // ウィジェット間共通処理
400                         M3_REQUEST_PARAM_OPERATION_ACT                  => 11,          // クライアントからの実行処理
401                         M3_REQUEST_PARAM_OPERATION_LANG                 => 12,          // 言語指定表示
402                         M3_REQUEST_PARAM_SERIAL_NO                              => 13,          // シリアル番号
403                         M3_REQUEST_PARAM_PAGE_NO                        => 14,          // ページ番号
404                         M3_REQUEST_PARAM_LIST_NO                                => 15,          // 一覧番号
405                         M3_REQUEST_PARAM_ITEM_NO                        => 16,          // 項目番号
406                         M3_REQUEST_PARAM_OPERATION_TODO                 => 17,          // 指定ウィジェットに実行させる処理
407                         M3_REQUEST_PARAM_FROM                                   => 18,          // メッセージの送信元ウィジェットID
408                         M3_REQUEST_PARAM_VIEW_STYLE                             => 19,          // 表示スタイル
409                         M3_REQUEST_PARAM_FORWARD                                => 20,          // 画面遷移用パラメータ
410                         M3_REQUEST_PARAM_ADMIN_KEY                              => 21,          // 管理者一時キー
411                         M3_REQUEST_PARAM_OPEN_BY                                => 22,          // ウィンドウの開き方
412                         M3_REQUEST_PARAM_SHOW_HEADER                    => 23,          // ヘッダ部表示制御
413                         M3_REQUEST_PARAM_SHOW_FOOTER                    => 24,          // フッタ部表示制御
414                         M3_REQUEST_PARAM_SHOW_MENU                              => 25,          // メニュー部表示制御
415                         M3_REQUEST_PARAM_KEYWORD                                => 26,          // 検索キーワード
416                         M3_REQUEST_PARAM_HISTORY                                => 27,          // 履歴インデックスNo
417                         M3_REQUEST_PARAM_DEF_PAGE_ID                    => 28,          // ページID(画面編集用)
418                         M3_REQUEST_PARAM_DEF_PAGE_SUB_ID                => 29,          // ページサブID(画面編集用)
419                         M3_REQUEST_PARAM_PAGE_DEF_SERIAL                => 30,          // ページ定義のレコードシリアル番号(設定画面起動時)
420                         M3_REQUEST_PARAM_PAGE_DEF_CONFIG_ID             => 31,          // ページ定義のウィジェット定義ID(設定画面起動時)
421                         M3_REQUEST_PARAM_BACK_URL                               => 32,          // 戻り先URL
422                         M3_REQUEST_PARAM_BACKUP_URL                             => 33,          // URL退避用(画面編集時)
423                         M3_REQUEST_PARAM_SERVER                                 => 34,          // サーバ指定
424                         M3_REQUEST_PARAM_CATEGORY_ID                    => 35,          // カテゴリID(共通)
425                         M3_REQUEST_PARAM_WIDTH                                  => 36,          // 幅
426                         M3_REQUEST_PARAM_HEIGHT                                 => 37);         // 高さ
427         }
428         /**
429          * メインコンテンツタイプを取得
430          *
431          * @return array        コンテンツタイプ
432          */
433         public function _getAllContentType()
434         {
435                 global $M3_ALL_CONTENT_TYPE;
436                 
437 /*              $contentType = array(   M3_VIEW_TYPE_CONTENT,                           // 汎用コンテンツ
438                                                                 M3_VIEW_TYPE_PRODUCT,                           // 製品
439                                                                 M3_VIEW_TYPE_BBS,                                       // BBS
440                                                                 M3_VIEW_TYPE_BLOG,                              // ブログ
441                                                                 M3_VIEW_TYPE_WIKI,                              // wiki
442                                                                 M3_VIEW_TYPE_USER,                              // ユーザ作成コンテンツ
443                                                                 M3_VIEW_TYPE_EVENT,                             // イベント
444                                                                 M3_VIEW_TYPE_PHOTO);                            // フォトギャラリー
445                 return $contentType;*/
446                 return $M3_ALL_CONTENT_TYPE;
447         }
448         /**
449          * 機能タイプを取得
450          *
451          * @return array        機能タイプ
452          */
453         public function _getAllFeatureType()
454         {
455                 global $M3_ALL_FEATURE_TYPE;
456                 
457 /*              $featureType = array(   M3_VIEW_TYPE_DASHBOARD,                 // ダッシュボード
458                                                                 M3_VIEW_TYPE_SEARCH,                    // 検索結果
459                                                                 M3_VIEW_TYPE_COMMERCE);                 // Eコマース
460                 return $featureType;*/
461                 return $M3_ALL_FEATURE_TYPE;
462         }
463         /**
464          * タイムアウトを停止
465          *
466          * @return なし
467          */
468         function setNoTimeout()
469         {
470                 if (ini_get('safe_mode') == '0') set_time_limit(0);
471         }
472         /**
473          * ポップアップメッセージを設定
474          *
475          * @param string $msg   メッセージ
476          */
477         function setPopupMsg($msg)
478         {
479                 $this->popupMsg = $msg;
480         }
481         /**
482          * HTMLヘッダ「description」に出力する文字列を設定
483          *
484          * @param string $str   出力文字列
485          */
486         function setHeadDescription($str)
487         {
488                 if (is_string($str) && !empty($str)){
489                         $this->headDescription = $str;
490                         $this->lastHeadDescription = $str;      // 最後に設定した値を退避
491                 }
492         }
493         /**
494          * HTMLヘッダ「description」に出力する文字列を取得
495          *
496          * @return string $str   出力文字列
497          */
498         function getHeadDescription()
499         {
500                 return $this->headDescription;
501         }
502         /**
503          * HTMLヘッダ「keywords」に出力する文字列を設定
504          *
505          * @param string $str   出力文字列
506          */
507         function setHeadKeywords($str)
508         {
509                 if (is_string($str) && !empty($str)){
510                         $this->headKeywords = $str;
511                         $this->lastHeadKeywords = $str;         // 最後に設定した値を退避
512                 }
513         }
514         /**
515          * HTMLヘッダ「keywords」に出力する文字列を取得
516          *
517          * @return string $str   出力文字列
518          */
519         function getHeadKeywords()
520         {
521                 return $this->headKeywords;
522         }
523         /**
524          * HTMLヘッダに出力するタグ文字列を設定
525          *
526          * @param string $str   出力文字列
527          * @return なし
528          */
529         function setHeadOthers($str)
530         {
531                 if (is_string($str) && !empty($str)){
532                         $this->headOthers = $str;
533                 }
534         }
535         /**
536          * HTMLヘッダに出力するタグ文字列を追加
537          *
538          * @param string $str   出力文字列
539          * @return なし
540          */
541         function addHeadOthers($str)
542         {
543                 if (is_string($str) && !empty($str)){
544                         // 追加されていない場合のみ追加
545                         $pos = strpos($this->headOthers, $str);
546                         if ($pos === false) $this->headOthers .= $str;
547                 }
548         }
549         /**
550          * HTMLヘッダに出力するタグ文字列を追加(管理画面用)
551          *
552          * @param string $str   出力文字列
553          * @return なし
554          */
555         function addAdminHeadOthers($str)
556         {
557                 if (is_string($str) && !empty($str)){
558                         // 追加されていない場合のみ追加
559                         $pos = strpos($this->adminHeadOthers, $str);
560                         if ($pos === false) $this->adminHeadOthers .= $str;
561                 }
562         }
563         /**
564          * HTMLヘッダ「title」のサブタイトル出力する文字列を設定
565          *
566          * @param string $str   出力文字列
567          * @param string $url   リンク先
568          */
569         function setHeadSubTitle($str = '', $url = '')
570         {
571                 global $gEnvManager;
572                 
573                 if (is_string($str)){
574                         // 空の場合はウィジェットのヘッドタイトルから取得
575                         if (empty($str)) $str = $gEnvManager->getCurrentWidgetHeadTitle();
576
577                         if (!empty($str)){
578                                 $this->headSubTitle[] = $str;
579                                 $this->headSubTitleUrl[] = $url;
580                                 $this->lastHeadTitle = $str;    // 最後に設定した値を退避
581                         }
582                 }
583         }
584         /**
585          * HTMLヘッダ「title」のサブタイトル出力する文字列を取得
586          *
587          * @return $array   サブタイトルに設定されている文字列を連想配列(title=タイトル、url=リンク先URL)の配列で返す
588          */
589         function getHeadSubTitle()
590         {
591                 $titleArray = array();
592                 $titleCount = count($this->headSubTitle);
593                 for ($i = 0; $i < $titleCount; $i++){
594                         $line = array('title' => $this->headSubTitle[$i], 'url' => $this->headSubTitleUrl[$i]);
595                         $titleArray[] = $line;
596                 }
597                 return $titleArray;
598         }
599         /**
600          * HTMLヘッダに出力するCSSの文字列を設定
601          *
602          * @param string $css   追加するCSS内容
603          * @return                              なし
604          */
605         function addHeadCss($css)
606         {
607                 $destCss = trim($css);
608                 if (!empty($destCss)){
609                         //if (!in_array($css, $this->headCss)) $this->headCss[] = $css;
610                         if (!in_array($css, $this->exportCss)) $this->exportCss[] = $css;               // CSS動的外部出力
611                         
612                         $this->lastHeadCss = $css;                      // 最後に設定したHTMLヘッダにCSS出力する文字列
613                 }
614         }
615         /**
616          * 外部出力で出力するCSSの文字列を設定(ウィジェット共通設定からの設定値)
617          *
618          * @param string $css   追加するCSS内容
619          * @return                              なし
620          */
621         function addExportCss($css)
622         {
623                 $destCss = trim($css);
624                 if (!empty($destCss)){
625                         if (!in_array($css, $this->exportCss)) $this->exportCss[] = $css;
626                 }
627         }
628         /**
629          * HTMLヘッダに出力するJavascriptの文字列を設定
630          *
631          * @param string $script        追加するJavascript内容
632          * @return                                      なし
633          */
634         function addHeadScript($script)
635         {
636                 $destScript = trim($script);
637                 if (!empty($destScript)){
638                         if (!in_array($script, $this->headScript)) $this->headScript[] = $script;
639                         
640                         $this->lastHeadScript = $script;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
641                 }
642         }
643         /**
644          * HTMLヘッダに出力するJavascriptの文字列(jQueryMobile用挿入スクリプト)を設定
645          *
646          * @param string $script        追加するJavascript内容
647          * @return                                      なし
648          */
649         function addHeadPreMobileScript($script)
650         {
651                 $destScript = trim($script);
652                 if (!empty($destScript)){
653                         if (!in_array($script, $this->headPreMobileScript)) $this->headPreMobileScript[] = $script;
654                 }
655         }
656         /**
657          * HTMLヘッダに出力する任意文字列を設定
658          *
659          * @param string $str   追加する任意文字列
660          * @return                              なし
661          */
662         function addHeadString($str)
663         {
664                 $destScript = trim($str);
665                 if (!empty($destScript)){
666                         if (!in_array($str, $this->headString)) $this->headString[] = $str;
667                         
668                         $this->lastHeadString = $str;                   // 最後に設定したHTMLヘッダに出力する任意文字列
669                 }
670         }
671         /**
672          * HTMLヘッダに出力するCSSファイルを追加
673          *
674          * @param string,array $cssFile CSSファイルURLパス
675          * @return                              なし
676          */
677         function addHeadCssFile($cssFile)
678         {
679                 if (is_array($cssFile)){        // 配列の場合
680                         for ($i = 0; $i < count($cssFile); $i++){
681                                 $destCss = trim($cssFile[$i]);
682                                 if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
683                         }
684                 } else {                // 文字列の場合
685                         $destCss = trim($cssFile);
686                         if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
687                 }
688         }
689         /**
690          * HTMLヘッダに出力するJavascriptライブラリを追加
691          *
692          * @param string,array $scriptLib       JavascriptライブラリID
693          * @return                                      なし
694          */
695         function addHeadAdminScriptLib($scriptLib)
696         {
697                 if (is_array($scriptLib)){      // 配列の場合
698                         for ($i = 0; $i < count($scriptLib); $i++){
699                                 $destScript = trim($scriptLib[$i]);
700                                 if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
701                         }
702                 } else {                // 文字列の場合
703                         $destScript = trim($scriptLib);
704                         if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
705                 }
706         }
707         /**
708          * HTMLヘッダに出力するJavascriptライブラリを追加
709          *
710          * @param string,array $scriptLib       JavascriptライブラリID
711          * @return                                      なし
712          */
713         function addHeadScriptLib($scriptLib)
714         {
715                 if (is_array($scriptLib)){      // 配列の場合
716                         for ($i = 0; $i < count($scriptLib); $i++){
717                                 $destScript = trim($scriptLib[$i]);
718                                 if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
719                         }
720                 } else {                // 文字列の場合
721                         $destScript = trim($scriptLib);
722                         if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
723                 }
724         }
725         /**
726          * HTMLヘッダに出力するJavascriptファイルを追加
727          *
728          * @param string,array $scriptFile      JavascriptファイルURLパス
729          * @return                                      なし
730          */
731         function addHeadScriptFile($scriptFile)
732         {
733                 if (is_array($scriptFile)){     // 配列の場合
734                         for ($i = 0; $i < count($scriptFile); $i++){
735                                 $destScript = trim($scriptFile[$i]);
736                                 if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
737                         }
738                 } else {                // 文字列の場合
739                         $destScript = trim($scriptFile);
740                         if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
741                 }
742         }
743         /**
744          * HTMLヘッダに出力するJavascriptファイル(jQueryMobile用挿入ファイル)を追加
745          *
746          * @param string,array $scriptFile      JavascriptファイルURLパス
747          * @return                                      なし
748          */
749         function addHeadPreMobileScriptFile($scriptFile)
750         {
751                 if (is_array($scriptFile)){     // 配列の場合
752                         for ($i = 0; $i < count($scriptFile); $i++){
753                                 $destScript = trim($scriptFile[$i]);
754                                 if (!empty($destScript) && !in_array($destScript, $this->headPreMobileScriptFiles)) $this->headPreMobileScriptFiles[] = $destScript;
755                         }
756                 } else {                // 文字列の場合
757                         $destScript = trim($scriptFile);
758                         if (!empty($destScript) && !in_array($destScript, $this->headPreMobileScriptFiles)) $this->headPreMobileScriptFiles[] = $destScript;
759                 }
760         }
761         /**
762          * HTMLヘッダに出力するRSSファイルを追加
763          *
764          * @param array $rssFile        タイトル(title)、配信用URL(href)の連想配列。複数の場合は連想配列の配列。
765          * @return                                      なし
766          */
767         function addHeadRssFile($rssFile)
768         {
769                 // パラメータエラーチェック
770                 if (!is_array($rssFile)) return;
771                 
772                 $line = $rssFile[0];
773                 if (is_array($line)){   // 複数追加の場合
774                         for ($i = 0; $i < count($line); $i++){
775                                 // すでに追加済みかどうかチェック
776                                 $url = trim($line[$i]['href']);
777                                 if (!empty($url)){
778                                         for ($j = 0; $j < count($this->headRssFiles); $j++){
779                                                 $storedUrl = $this->headRssFiles[$j]['href'];
780                                                 if ($url == $storedUrl) break;
781                                         }
782                                         if ($j == count($this->headRssFiles)){          // 見つからないときは追加
783                                                 $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
784                                                                                                                 'title' => $line[$i]['title']);         // タイトル
785                                         }
786                                 }
787                         }
788                 } else {                // 単数追加のとき
789                         // すでに追加済みかどうかチェック
790                         $url = trim($rssFile['href']);
791                         if (!empty($url)){
792                                 for ($i = 0; $i < count($this->headRssFiles); $i++){
793                                         $storedUrl = $this->headRssFiles[$i]['href'];
794                                         if ($url == $storedUrl) break;
795                                 }
796                                 if ($i == count($this->headRssFiles)){          // 見つからないときは追加
797                                         $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
798                                                                                                         'title' => $rssFile['title']);          // タイトル
799                                 }
800                         }
801                 }
802         }
803         /**
804          * RSSチャンネル部に出力するデータを設定
805          *
806          * @param array $rssData        RSSチャンネル部データ
807          * @return                                      なし
808          */
809         function setRssChannel($rssData)
810         {
811                 if (!empty($rssData)) $this->rssChannel = $rssData;                             // RSSチャンネルデータ
812         }
813         /**
814          * 表示ポジションを表示するかどうか
815          *
816          * @param int $mode   0=ポジション表示しない(通常画面)、1=ポジション表示、2=ウィジェット込みポジション表示
817          */
818         function showPosition($mode)
819         {
820                 $this->showPositionMode = $mode;
821         }
822         /**
823          * 画面レイアウト中かどうか
824          *
825          * @return bool         true=レイアウト中、false=レイアウト中でない
826          */
827         function isLayout()
828         {
829                 return $this->isLayout;                         // 画面レイアウト中かどうか
830         }
831         /**
832          * ウィジェットの単体表示を設定
833          */
834         function showWidget()
835         {
836                 $this->showWidget = true;
837         }
838         /**
839          * ウィジェットの単体表示を取得
840          *
841          * @param bool          true=単体表示、false=単体表示でない
842          */
843         function getShowWidget()
844         {
845                 return $this->showWidget;
846         }
847         /**
848          * システム制御遷移モードを設定
849          *
850          * @param int $mode   0=設定なし、1=ログイン画面、10=サイト非公開、11=アクセス不可、12=存在しないページ
851          */
852         function setSystemHandleMode($mode)
853         {
854                 $this->systemHandleMode = $mode;
855         }
856         /**
857          * システム制御遷移モード取得
858          */
859         function getSystemHandleMode()
860         {
861                 return $this->systemHandleMode;
862         }
863         /**
864          * フロント画面編集モードを設定
865          *
866          * @return                              なし
867          */
868         function setEditMode()
869         {
870                 $this->isEditMode = true;
871         }
872         /**
873          * フロント画面編集モードを取得
874          *
875          * @return bool         true=編集モードオン、false=編集モードオフ
876          */
877         function idEditMode()
878         {
879                 return $this->isEditMode;
880         }
881         /**
882          * 出力フォーマットがHTMLであるかを設定
883          *
884          * @param bool $isHtml  HTMLフォーマットかどうか
885          * @return                              なし
886          */
887         function setOutputByHtml($isHtml)
888         {
889                 $this->outputByHtml = $isHtml;
890         }
891         
892         /**
893          * AJAX用のレスポンスボディデータかどうかを設定
894          *
895          * @param bool $isResponseBody  レスポンスボディデータかどうか
896          * @return                                              なし
897          */     
898         function setOutputAjaxResponseBody($isResponseBody)
899         {
900                 $this->outputAjaxResponseBody = $isResponseBody;
901         }
902         /**
903          * ヘルプ機能の使用可否を設定
904          *
905          * @param bool $status  ヘルプ機能を使用するかどうか
906          * @return                              なし
907          */
908         function setUseHelp($status)
909         {
910                 $this->useHelp = $status;
911         }
912         /**
913          * ヘルプ機能の使用可否を取得
914          *
915          * @return bool ヘルプ機能を使用するかどうか
916          */
917         function getUseHelp()
918         {
919                 return $this->useHelp;
920         }
921         /**
922          * 表示するコンテンツにGoogleマップが含まれているかを設定
923          *
924          * @param bool $status  Googleマップを含むかどうか
925          * @return                              なし
926          */
927         function setIsContentGooglemaps($status)
928         {
929                 $this->isContentGooglemaps = $status;           // コンテンツにGoogleマップが含むかどうか
930         }
931         /**
932          * 表示するコンテンツにGoogleマップが含まれているかを取得
933          *
934          * @return bool ヘルプ機能を使用するかどうか
935          */
936         function isContentGooglemaps()
937         {
938                 return $this->isContentGooglemaps;
939         }
940         /**
941          * JavaScriptのブラウザキャッシュの使用可否を設定
942          *
943          * @param bool $status  ブラウザキャッシュを使用するかどうか
944          * @return                              なし
945          */
946         function setHasScriptCache($status)
947         {
948                 $this->hasScriptCache = $status;
949         }
950         /**
951          * Bootstrapを使用に設定
952          *
953          * @return                              なし
954          */
955         function useBootstrap()
956         {
957                 $this->useBootstrap = true;                             // Bootstrapを使用するかどうか
958         }
959         /**
960          * Bootstrapを強制的に未使用に設定
961          *
962          * @return                              なし
963          */
964         function cancelBootstrap()
965         {
966                 $this->useBootstrap = false;                            // Bootstrapを使用するかどうか
967         }
968         /**
969          * Bootstrap使用状況を取得
970          *
971          * @return bool                 true=使用、false=使用しない
972          */
973         function getUseBootstrap()
974         {
975                 return $this->useBootstrap;                             // Bootstrapを使用するかどうか
976         }
977         /**
978          * HTML5を使用に設定
979          *
980          * @return                              なし
981          */
982         function setHtml5()
983         {
984                 $this->isHtml5 = true;                                  // HTML5で出力するかどうか
985         }
986         /**
987          * ページ作成処理を中断するかどうかを取得
988          *
989          * @return bool         true=中断、false=継続
990          */
991         function isPageAbort()
992         {
993                 return $this->isAbort;
994         }
995         /**
996          * 現在のウィジェットのポジションを取得
997          *
998          * @param string $pos           ポジション
999          * @param int    $index         インデックス番号
1000          * @return                      なし
1001          */
1002         function getCurrentWidgetPosition(&$pos, &$index)
1003         {
1004                 $pos = $this->currentWidgetPosition;                    // 現在のウィジェットのポジション
1005                 $index = $this->currentWidgetIndex;                     // 現在のウィジェットのポジション番号
1006         }
1007         /**
1008          * 親ウィンドウを再描画
1009          *
1010          * @param int $defSerial        ページ定義シリアル番号
1011          * @return                                      なし
1012          */
1013         function updateParentWindow($defSerial = 0)
1014         {
1015                 $this->updateParentWindow = true;
1016                 $this->updateDefSerial = $defSerial;                    // 更新する項目のページ定義シリアル番号
1017         }
1018         /**
1019          * CSSファイルの追加
1020          *
1021          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1022          * @return                              なし
1023          */
1024         function addCssFile($path)
1025         {
1026                 $destPath = trim($path, '/');
1027                 if (!in_array($destPath, $this->defaultCssFiles)) $this->defaultCssFiles[] = $destPath;
1028         }
1029         /**
1030          * CSSファイルの追加
1031          *
1032          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
1033          * @return                              なし
1034          */
1035         function addAdminCssFile($path)
1036         {
1037                 $destPath = trim($path, '/');
1038                 if (!in_array($destPath, $this->defaultAdminCssFiles)) $this->defaultAdminCssFiles[] = $destPath;
1039         }
1040         /**
1041          * 編集エリア用のCSSファイルの追加
1042          *
1043          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
1044          * @return                              なし
1045          */
1046         function addCkeditorCssFile($path)
1047         {
1048                 $destPath = trim($path, '/');
1049                 if (!in_array($destPath, $this->ckeditorCssFiles)) $this->ckeditorCssFiles[] = $destPath;
1050         }
1051         /**
1052          * JavaScriptファイルの追加
1053          *
1054          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1055          * @return                              なし
1056          */
1057         function addScriptFile($path)
1058         {
1059                 $destPath = trim($path, '/');
1060                 if (!empty($destPath) && !in_array($destPath, $this->defaultScriptFiles)) $this->defaultScriptFiles[] = $destPath;
1061         }
1062         /**
1063          * JavaScriptファイルの追加
1064          *
1065          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1066          * @return                              なし
1067          */
1068         function addAdminScriptFile($path)
1069         {
1070                 $destPath = trim($path, '/');
1071                 if (!in_array($destPath, $this->defaultAdminScriptFiles)) $this->defaultAdminScriptFiles[] = $destPath;
1072         }
1073         /**
1074          * 追加設定するテンプレートIDを返す
1075          *
1076          * @return array                                                テンプレートID,サブテンプレートIDの配列
1077          */
1078         function getOptionTemplateId()
1079         {
1080                 global $gEnvManager;
1081                 
1082                 // ページ情報取得
1083                 $pageId = $gEnvManager->getCurrentPageId();
1084
1085                 switch ($this->contentType){
1086                         case M3_VIEW_TYPE_CONTENT:              // ページのコンテンツタイプ                         
1087                                 // コンテンツ単位のテンプレート設定
1088                                 $contentLibObj = $this->gInstance->getObject(self::CONTENT_OBJ_ID);
1089                                 if (isset($contentLibObj)) list($this->optionTemplateId, $this->optionSubTemplateId) = $contentLibObj->getOptionTemplate();
1090                                 break;
1091                         case M3_VIEW_TYPE_BLOG:         // ページがブログタイプのとき
1092                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // PCサイトのとき
1093                                         // ブログライブラリオブジェクトからテンプレートを取得
1094                                         $blogLibObj = $this->gInstance->getObject(self::BLOG_OBJ_ID);
1095                                         if (isset($blogLibObj)) list($this->optionTemplateId, $this->optionSubTemplateId) = $blogLibObj->getOptionTemplate();
1096                                 }
1097                                 break;
1098                 }
1099                 return array($this->optionTemplateId, $this->optionSubTemplateId);
1100         }
1101         /**
1102          * 使用した非共通ウィジェットの数を取得
1103          *
1104          * @return int                          ウィジェット数
1105          */
1106         function getNonSharedWidgetCount()
1107         {
1108                 return $this->nonSharedWidgetCount;
1109         }
1110         /**
1111          * ページのコンテンツタイプを取得
1112          *
1113          * @return string                       コンテンツタイプ
1114          */
1115         function getContentType()
1116         {
1117                 return $this->contentType;
1118         }
1119         /**
1120          * フロント画面で使用する主要コンテンツタイプの情報取得
1121          *
1122          * @return array                        コンテンツタイプの情報の連想配列
1123          */
1124         function getMainContentTypeInfo()
1125         {
1126                 return $this->mainContentTypeInfo;                              // 主要コンテンツタイプ
1127         }
1128         /**
1129          * フロント画面で使用する補助コンテンツタイプの情報取得
1130          *
1131          * @return array                        コンテンツタイプの情報の連想配列
1132          */
1133         function getSubContentTypeInfo()
1134         {
1135                 return $this->subContentTypeInfo;                               // 補助コンテンツタイプ
1136         }
1137         /**
1138          * フロント画面で使用する主要コンテンツタイプを取得
1139          *
1140          * @return array                        コンテンツタイプの配列
1141          */
1142         function getMainContentTypes()
1143         {
1144                 // 「value」値のみ取得
1145                 return array_map(create_function('$a', 'return $a["value"];'), $this->mainContentTypeInfo);
1146         }
1147         /**
1148          * フロント画面で使用するサブコンテンツタイプを取得
1149          *
1150          * @return array                        コンテンツタイプの配列
1151          */
1152         function getSubContentTypes()
1153         {
1154                 // 「value」値のみ取得
1155                 return array_map(create_function('$a', 'return $a["value"];'), $this->subContentTypeInfo);
1156         }
1157         /**
1158          * フロント画面で使用する主要機能タイプ情報を取得
1159          *
1160          * @return array                        機能タイプの情報の連想配列
1161          */
1162         function getMainFeatureTypeInfo()
1163         {
1164                 return $this->mainFeatureTypeInfo;                              // 主要機能タイプ
1165         }
1166         /**
1167          * フロント画面で使用する主要機能タイプを取得
1168          *
1169          * @return array                        機能タイプの配列
1170          */
1171         function getMainFeatureTypes()
1172         {
1173                 // 「value」値のみ取得
1174                 return array_map(create_function('$a', 'return $a["value"];'), $this->mainFeatureTypeInfo);
1175         }
1176         
1177         /**
1178          * すべてのページ属性情報を取得
1179          *
1180          * @return array                        ページ属性情報の連想配列
1181          */
1182         function getAllPageAttributeTypeInfo()
1183         {
1184                 return array_merge($this->mainContentTypeInfo, $this->subContentTypeInfo, $this->mainFeatureTypeInfo, $this->adminFeatureTypeInfo);
1185         }
1186         /**
1187          * 管理画面用のサブメニューバーの定義を設定
1188          *
1189          * @param array $def    メニューバー定義
1190          * @return                              なし
1191          */
1192         function setAdminSubNavbarDef($def)
1193         {
1194                 $this->adminSubNavbarDef = $def;
1195         }
1196         /**
1197          * 管理画面用のサブメニューバーの定義を取得
1198          *
1199          * @return array メニューバーの定義
1200          */
1201         function getAdminSubNavbarDef()
1202         {
1203                 return $this->adminSubNavbarDef;
1204         }
1205         /**
1206          * 管理画面用パンくずリスト定義を設定
1207          *
1208          * @param array $def    パンくずリスト定義
1209          * @param array $help   ヘルプ(title,bodyの連想配列)
1210          * @return                              なし
1211          */
1212         function setAdminBreadcrumbDef($def, $help = array())
1213         {
1214                 $this->adminBreadcrumbDef = $def;
1215                 if (!empty($help)) $this->adminBreadcrumbDefHelp = $help;                               // 管理画面用パンくずリストヘルプ定義
1216         }
1217         /**
1218          * 管理画面用パンくずリスト定義を取得
1219          *
1220          * @param array $help   ヘルプ(title,bodyの連想配列)
1221          * @return array                パンくずリスト定義
1222          */
1223         function getAdminBreadcrumbDef(&$help)
1224         {
1225                 // パラメータ数を取得
1226                 $argNum = func_num_args();
1227                 
1228                 // ヘルプ取得用パラメータが存在する場合は定義を設定
1229                 if ($argNum > 0) $help = $this->adminBreadcrumbDefHelp;
1230
1231                 return $this->adminBreadcrumbDef;
1232         }
1233         /**
1234          * ページ作成開始
1235          *
1236          * HTTPヘッダを設定する。セッションを取得する。サブページIDを設定する。
1237          *
1238          * @param RequestManager $request               HTTPリクエスト処理クラス
1239          * @return                                                              なし
1240          */
1241         function startPage($request)
1242         {
1243                 global $gEnvManager;
1244                 global $gRequestManager;
1245                 global $gInstanceManager;
1246                 global $gAccessManager;
1247                 global $gSystemManager;
1248                 global $gDispManager;
1249                 global $gOpeLogManager;
1250                 
1251                 // 実行コマンドを取得
1252                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
1253                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
1254                 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
1255                 $pageId = $gEnvManager->getCurrentPageId();
1256
1257                 // ###### クライアントIDの読み込み、再設定 ######
1258                 // この後、クライアントIDがアクセスログに記録される
1259                 $clientId = $request->getCookieValue(M3_COOKIE_CLIENT_ID);
1260                 if (empty($clientId)){  // クライアントIDが設定されていないとき(初回アクセス)
1261                         // クライアントIDを生成
1262                         $clientId = $this->gAccess->createClientId();
1263                 } else {
1264                         $this->gAccess->setClientId($clientId); // クライアントIDを設定
1265                 
1266                         // クッキーの使用可否を設定
1267                         $this->gEnv->setCanUseCookie(true);
1268                 }
1269                 $request->setCookieValue(M3_COOKIE_CLIENT_ID, $clientId, M3_COOKIE_EXPIRE_CLIENT_ID);
1270                         
1271                 // インストール時の管理画面用ライブラリを追加(フレームコンテナでの設定を反映)
1272                 if (defined('M3_STATE_IN_INSTALL')){
1273                         // Bootstrapライブラリ追加
1274                         if ($this->useBootstrap){
1275                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
1276                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
1277                         }
1278                 } else {
1279                         // 管理者キーがあればGETまたはPOST値のセッションIDを使用する
1280                         if ($gEnvManager->isAdminDirAccess()){
1281                                 if ($gAccessManager->isValidAdminKey()) session_id($gRequestManager->trimValueOf(session_name()));
1282                         }
1283                 }
1284
1285                 // 最終HTML(ページ全体で使用するHTML)の出力
1286                 if ($cmd == M3_REQUEST_CMD_CSS){                // CSS生成のとき
1287                         $gRequestManager->stopSessionUpdate();                  // セッションの更新を停止
1288                 }
1289                 
1290                 // セッション変数を取得可能にする
1291                 session_start();
1292                 
1293                 // ##### インストール時はここで終了 #####
1294                 if (defined('M3_STATE_IN_INSTALL')) return;             // インストール時は実行しない
1295                 
1296                 // セッションを再生成する(セキュリティ対策)
1297                 if ($gSystemManager->regenerateSessionId()){
1298                         $gAccessManager->setOldSessionId(session_id());         // 古いセッションIDを保存
1299                         session_regenerate_id(true);
1300                 }
1301                 
1302                 // セッションからユーザ情報を取得
1303                 $userInfo = $gRequestManager->getSessionValueWithSerialize(M3_SESSION_USER_INFO);
1304                 if (!$gAccessManager->checkSessionSecurity($userInfo)) return;                  // セキュリティ問題ありの場合はここで終了
1305                 // ##### ここで終了した場合はページサブIDが未設定のためページ不正のエラーが発生しアクセスエラー画面が表示される #####
1306                 
1307                 // ##### POST時のリファラーチェック #####
1308                 // WooCommerceのAJAX処理が通らないのでチェックしない?
1309 /*              if ($gRequestManager->isPostMethod() && !$this->_checkReferer()){
1310                         $errMsg = '不正なPOSTデータ(リファラー異常)を検出しました。アクセス元IP: ' . $gAccessManager->getClientIp();
1311                         $msgDetail = 'アクセスをブロックしました。account=' . $userInfo->account . ', userid=' . $userInfo->userId;
1312                         $gOpeLogManager->writeUserError(__METHOD__, $errMsg, 2210, $msgDetail);
1313                         return;
1314                 }*/
1315                 
1316                 // その他セッション情報取得
1317                 $gRequestManager->_doSessionOpenEventCallback();
1318
1319                 // ユーザ情報をロード
1320                 $gInstanceManager->setUserInfo($userInfo);
1321
1322                 // ##### 自動ログイン #####
1323                 // ログイン中でない場合は自動ログインでユーザ情報を取得
1324                 $gAccessManager->startAutoLogin();
1325                 
1326                 // デバッグモードの表示
1327                 if (M3_SYSTEM_DEBUG) echo 'Debug mode<br />';
1328                 
1329                 // ##### ページIDの修正 #####
1330                 // ポジション表示の場合はページID、ページサブIDを再設定。再設定はシステム管理者のみ可能。
1331                 if (($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                                    // 管理画面(ウィジェットなしポジション表示)のとき
1332                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) &&            // 管理画面(ウィジェット付きポジション表示)のとき
1333                         $gEnvManager->isSystemAdmin()){
1334
1335                         $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1336                         if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId();          // 値がないときはデフォルトのページIDを設定
1337                         $this->gEnv->setCurrentPageId($pageId);
1338                         $subId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1339                         if (!empty($subId)) $this->gEnv->setCurrentPageSubId($subId);
1340                 }
1341                 
1342                 // ##### サブページIDの設定 #####
1343                 if ($gEnvManager->isAdminDirAccess() &&         // 管理画面へのアクセスのとき
1344                         ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT)){                               // ログイン、ログアウト場合は管理画面のページサブIDを指定
1345                         $subId = $gEnvManager->getAdminDefaultPageSubId();              // 管理画面用のデフォルトページサブID
1346                 } else {
1347                         if (empty($subId)) $subId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);// ページサブIDを取得
1348                         
1349                         if (empty($subId)){                     // サブページIDが設定されていないとき
1350                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1351                                 $params = $gRequestManager->getQueryArray();
1352                                 $paramCount = count($params);
1353
1354                                 // コマンド以外のパラメータ数が1つだけのときはパラメータからページ属性を判断する
1355                                 // 値が空でもキーがあれば属性を持つとする
1356                                 if ($paramCount == 0){
1357                                         $this->isPageTopUrl = true;                     // ページトップ(サブページ内のトップ位置)のURLかどうか
1358                                         
1359                                         if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemAdmin() && empty($task)){
1360                                                 // ダッシュボード機能は、パラメータなし、管理者ディレクトリ、システム管理者の条件で使用可能
1361                                                 // POST値にタスクがある場合はダッシュボードとしない
1362                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_DASHBOARD, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1363                                         }
1364                                 } else if ($paramCount > 0 && !$gEnvManager->isAdminDirAccess()){               // パラメータ付きの場合(2013/3/23)
1365                                         // ##### ページ属性から画面を選択(管理画面は対応しない) ###
1366                                         // 最初のURLパラメータでコンテンツを判断
1367                                         // プレビュー(cmd=preview)等のパターンで複数パラメータがある
1368                                         reset($params);
1369                                         $firstKey = key($params);
1370                                         $firstValue = $params[$firstKey];
1371
1372                                         if (!empty($firstValue)){               // 「key=value」の形式であること
1373                                                 switch ($firstKey){
1374                                                         case M3_REQUEST_PARAM_CONTENT_ID:               // コンテンツIDのとき
1375                                                         case M3_REQUEST_PARAM_CONTENT_ID_SHORT:
1376                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1377                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1378                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1379                                                         
1380                                                                 // ローカルメニューのURLからページを特定。ページが特定できないときはページ属性で取得。
1381                                                                 $url = $gEnvManager->getMacroPath($gEnvManager->getCurrentRequestUri());
1382                                                                 $ret = $this->db->getSubPageIdByMenuItemUrl($url, $gEnvManager->getCurrentPageId(), M3_VIEW_TYPE_CONTENT, $rows);
1383                                                                 if ($ret){
1384                                                                         $rowCount = count($rows);
1385                                                                         for ($i = 0; $i < $rowCount; $i++){
1386                                                                                 // コンテンツを表示するウィジェットがあるときはページサブIDを確定
1387                                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);
1388                                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);// コンテンツタイプでの取得に変更(2012/6/20)
1389                                                                                 if (!empty($widgetId)){
1390                                                                                         $subId = $rows[$i]['pd_sub_id'];
1391                                                                                         break;
1392                                                                                 }
1393                                                                         }
1394                                                                 }
1395                                                                 if (empty($subId)) $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_CONTENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1396                                                                 $this->contentType = M3_VIEW_TYPE_CONTENT;              // ページのコンテンツタイプ
1397                                                                 
1398                                                                 // コンテンツ詳細ページかどうかを設定
1399                                                                 if ($firstKey == M3_REQUEST_PARAM_CONTENT_ID || $firstKey == M3_REQUEST_PARAM_CONTENT_ID_SHORT) $this->isContentDetailPage = true;
1400                                                                 break;
1401                                                         case M3_REQUEST_PARAM_PRODUCT_ID:       // 製品IDのとき
1402                                                         case M3_REQUEST_PARAM_PRODUCT_ID_SHORT:
1403                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1404                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1405                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1406                                                                 
1407                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PRODUCT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1408                                                                 $this->contentType = M3_VIEW_TYPE_PRODUCT;              // ページのコンテンツタイプ
1409                                                                 
1410                                                                 // コンテンツ詳細ページかどうかを設定
1411                                                                 $this->isContentDetailPage = true;
1412                                                                 break;
1413                                                         case M3_REQUEST_PARAM_BBS_ID:           // 掲示板投稿記事のとき
1414                                                         case M3_REQUEST_PARAM_BBS_ID_SHORT:
1415                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID:
1416                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT:
1417                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1418                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1419                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1420                                                                 
1421                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BBS, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1422                                                                 $this->contentType = M3_VIEW_TYPE_BBS;          // ページのコンテンツタイプ
1423                                                                 
1424                                                                 // コンテンツ詳細ページかどうかを設定
1425                                                                 if ($firstKey == M3_REQUEST_PARAM_BBS_THREAD_ID || $firstKey == M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT) $this->isContentDetailPage = true;
1426                                                                 break;
1427                                                         case M3_REQUEST_PARAM_EVENT_ID:         // イベント記事のとき
1428                                                         case M3_REQUEST_PARAM_EVENT_ID_SHORT:
1429                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1430                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1431                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1432                                                                 
1433                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_EVENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1434                                                                 $this->contentType = M3_VIEW_TYPE_EVENT;                // ページのコンテンツタイプ
1435                                                                 
1436                                                                 // コンテンツ詳細ページかどうかを設定
1437                                                                 $this->isContentDetailPage = true;
1438                                                                 break;
1439                                                         case M3_REQUEST_PARAM_PHOTO_ID:         // フォトギャラリー写真のとき
1440                                                         case M3_REQUEST_PARAM_PHOTO_ID_SHORT:
1441                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1442                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1443                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1444                                                                 
1445                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PHOTO, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1446                                                                 $this->contentType = M3_VIEW_TYPE_PHOTO;                // ページのコンテンツタイプ
1447                                                                 
1448                                                                 // コンテンツ詳細ページかどうかを設定
1449                                                                 $this->isContentDetailPage = true;
1450                                                                 break;
1451                                                         case M3_REQUEST_PARAM_BLOG_ID:          // ブログIDのとき
1452                                                         case M3_REQUEST_PARAM_BLOG_ID_SHORT:
1453                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID:
1454                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT:
1455                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1456                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1457                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1458                 
1459                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BLOG, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1460                                                                 $this->contentType = M3_VIEW_TYPE_BLOG;         // ページのコンテンツタイプ
1461                                                                 
1462                                                                 // コンテンツ詳細ページかどうかを設定
1463                                                                 if ($firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT) $this->isContentDetailPage = true;
1464                                                                 break;
1465                                                         case M3_REQUEST_PARAM_ROOM_ID:          // ユーザ作成コンテンツのとき
1466                                                         case M3_REQUEST_PARAM_ROOM_ID_SHORT:
1467                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1468                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1469                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1470                                                                 
1471                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_USER, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1472                                                                 $this->contentType = M3_VIEW_TYPE_USER;         // ページのコンテンツタイプ
1473                                                 
1474                                                                 // コンテンツ詳細ページかどうかを設定
1475                                                                 $this->isContentDetailPage = true;
1476                                                                 
1477                                                                 // コンテンツを表示するウィジェットを取得
1478                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);
1479                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);// コンテンツタイプでの取得に変更(2012/6/20)
1480                                                                 if (!empty($widgetId)){
1481                                                                         // ルーム用の定義ID(所属グループID)を取得
1482                                                                         $roomId = isset($params[M3_REQUEST_PARAM_ROOM_ID]) ? $params[M3_REQUEST_PARAM_ROOM_ID] : $params[M3_REQUEST_PARAM_ROOM_ID_SHORT];
1483                                                                         $configId = $this->db->getWidgetConfigIdForRoom($roomId);
1484
1485                                                                         // グループIDを定義IDとするページのページサブIDを取得
1486                                                                         $subPageId = $this->getPageSubIdByWidget($gEnvManager->getCurrentPageId(), $widgetId, $configId);
1487                                                                         if (!empty($subPageId)) $subId = $subPageId;
1488                                                                 }
1489                                                                 break;
1490                                                         default:                // オプションのURLコンテンツパラメータからサブページIDを取得
1491                                                                 $ret = $this->db->getSubPageIdByUrlContentParam($gEnvManager->getCurrentPageId(), $firstKey, $row);
1492                                                                 if ($ret) $subId = $row['pd_sub_id'];
1493                                                                 break;
1494                                                 }
1495                                         }
1496                                 }
1497
1498                                 // wiki用パラメータの取得
1499                                 if (empty($subId)){
1500                                         // 「http://www.example.com?ページ名」「wcmd」の場合はwikiコンテンツページを選択
1501                                         $wikiCmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND);
1502                                         $pageName = $gRequestManager->getWikiPageFromQuery();           // 「=」なしのパラメータはwikiパラメータとする
1503                         
1504                                         if (!empty($wikiCmd) || !empty($pageName)){                     // Wikiコンテンツページを指定のとき
1505                                                 // ページサブIDを取得
1506                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_WIKI, $gEnvManager->getCurrentPageId());
1507                                                 $this->contentType = M3_VIEW_TYPE_WIKI;         // ページのコンテンツタイプ
1508                                                 
1509                                                 // コンテンツ詳細ページかどうかを設定
1510                                                 $this->isContentDetailPage = true;
1511                                         }
1512                                 }
1513                                 // その他のGET,POSTパラメータからページサブID取得
1514                                 if (empty($subId)){
1515                                         // 検索用パラメータなどでリダイレクト先のURLが取得できた場合は遷移
1516                                         $subId = $this->getPageSubIdByParam($request, $redirectUrl);
1517                                         if (!empty($subId) && !empty($redirectUrl)) $this->redirect($redirectUrl);
1518                                 }
1519                                 
1520                                 // ページサブIDが取得できない場合はデフォルトを使用
1521                                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
1522                         } else {                // ページサブIDが設定されているとき
1523                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1524                                 $params = $gRequestManager->getQueryArray();
1525                                 $paramCount = count($params);
1526                                 if ($paramCount == 1) $this->isPageTopUrl = true;                       // ページトップ(サブページ内のトップ位置)のURLかどうか
1527                         }
1528                 }
1529                 $gEnvManager->setCurrentPageSubId($subId);// サブページIDを設定
1530                 
1531                 // SSL通信機能がオンの場合は、アクセスされたURLのSSLをチェックし不正の場合は正しいURLにリダイレクト
1532                 // 設定に間違いがある場合、管理画面にアクセスできなくなるので、フロント画面のみ制御
1533 //              if ($gEnvManager->getUseSsl() || $gEnvManager->getUseSslAdmin()){
1534                 if ($gEnvManager->getUseSsl()){                 // フロント画面のSSL設定のみチェック(2016/7/30)
1535                         if (!$gEnvManager->isAdminDirAccess()){         // 管理画面以外へのアクセスのとき
1536                                 // ルートURLがSSLの場合はSSLに固定
1537                                 if ($gEnvManager->isRootUrlSsl()){              // ルートURLがSSLの場合はフロント画面のすべてがSSL付き
1538                                         $isSsl = true;
1539                                 } else {
1540                                         $isSsl = $gEnvManager->isSslByCurrentPage();
1541                                 }
1542                                 $currentUrl = $gEnvManager->getCurrentRequestUri();
1543                                 if ($isSsl){
1544                                         $correctUrl = str_replace('http://', 'https://', $currentUrl);
1545                                 } else {
1546                                         $correctUrl = str_replace('https://', 'http://', $currentUrl);
1547                                 }
1548                                 if ($currentUrl != $correctUrl) $this->redirect($correctUrl);
1549                         }
1550                 }
1551                 // マルチドメイン用設定初期化
1552                 $gEnvManager->initMultiDomain();
1553                 
1554                 // 画面設定取得
1555                 $gDispManager->load();
1556                         
1557                 // ##### 画面に必要なスクリプトを追加 #####
1558                 // スマートフォン用URLのときはスマートフォン用のjQueryを使用
1559                 if ($gEnvManager->getIsSmartphoneSite()){
1560                         $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(10);                   // スマートフォン用jQueryファイル
1561                         
1562                         if (isset($this->libFiles[ScriptLibInfo::LIB_JQUERYS_MOBILE]['script'])){
1563                                 $scriptFiles = $this->libFiles[ScriptLibInfo::LIB_JQUERYS_MOBILE]['script'];
1564                                 if (count($scriptFiles) > 0) $this->selectedJQueryMobileFilename = $scriptFiles[0];             // 使用対象のjQueryMobileファイル
1565                         }
1566                 }
1567                 
1568                 // Magic3管理用のスクリプトを追加
1569                 if (!$gEnvManager->getIsMobileSite()){          // 携帯用URL以外のとき
1570                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
1571                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
1572 //                                      $this->isEditMode = true;                       // フロント画面編集モード
1573                                         $this->isPageEditable = true;           // フロント画面ページ編集可能モードに設定(コンテキストメニュー表示)
1574                                                 
1575                                         // 管理画面用ライブラリを追加
1576                                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1577                                                 $this->addAdminScript('', ScriptLibInfo::getWysiwygEditorLibId());      // WYSIWYGエディターを追加
1578                                                 
1579                                                 // Googleマップライブラリの読み込み
1580                                                 if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1581                                                         $this->defaultAdminScriptFiles[] = ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS);
1582                                                 }
1583                                         } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // 管理画面(ウィジェット付きポジション表示)のとき
1584                                                 $this->isLayout = true;         // 画面レイアウト中かどうか
1585                                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_IDTABS);                    // 管理パネル用スクリプト追加(ポジション表示追加分)
1586                                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_DROPDOWN);               // 管理パネル用スクリプト追加(ドロップダウンメニュー)
1587                                                 //$this->useBootstrap = true;           // Bootstrapを使用
1588                                                 //$this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);             // パネルメニュー(フロント画面と管理画面の切り替え等)用
1589                                         }
1590                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1591                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1592                                         
1593                                         // スクリプトが必要なウィジェットをすべて取得
1594                                         $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1595                                         for ($i = 0; $i < count($rows); $i++){
1596                                                 $this->addAdminScript($task, trim($rows[$i]['wd_add_script_lib']));
1597                                         }
1598                                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1599                                                 // ウィジェット情報取得
1600                                                 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
1601                                                 $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
1602                                                 if ($ret) $this->addAdminScript($task, trim($this->configWidgetInfo['wd_add_script_lib_a']));           // 管理機能用スクリプト
1603                                         }
1604                                 }
1605                         } else {                // フロント画面へのアクセスのとき
1606                                 // フロント画面用スクリプトファイル追加
1607                                 $value = $gSystemManager->getSystemConfig(self::CF_USE_JQUERY);// 常にjQueryを使用するかどうか
1608                                 if ($value) $this->addScriptFile($this->selectedJQueryFilename);
1609                 
1610                                 if ($cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                 // ウィジェット単体実行でない
1611                                         $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
1612                                         if ($gEnvManager->isSystemManageUser()){
1613                                                 $this->isEditMode = true;                       // フロント画面編集モード
1614                                                 $this->isPageEditable = true;           // フロント画面ページ編集可能モードに設定
1615                                         
1616                                                 // システム運用権限がある場合は管理用スクリプトを追加
1617                                                 // フロント画面と管理画面の切り替え用のスライドメニューバーには管理用スクリプト,CSSが必要
1618                                                 $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1619                                                 $this->addScriptFile(ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME);               // jQuery Contextmenu Lib
1620                                                 $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1621                                                 //$this->addScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);          // パネルメニュー(フロント画面と管理画面の切り替え等)用
1622                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);  // 管理パネル用スクリプト追加
1623                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_COOKIE);                 // 管理パネル用スクリプト追加
1624                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_EASING);                 // 管理パネル用スクリプト追加
1625                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1626                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1627                                         
1628                                                 $this->addCssFile(self::M3_ADMIN_CSS_FILE);             // 管理機能用CSS
1629                                         } else if ($gEnvManager->isContentEditableUser()){              // コンテンツ編集可能ユーザの場合
1630                                                 $this->isEditMode = true;                       // フロント画面編集モード
1631                                         }
1632                                 } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
1633                                         if ($gEnvManager->isContentEditableUser()){             // コンテンツ編集可能ユーザの場合
1634                                                 $this->isEditMode = true;                       // フロント画面編集モード
1635                                         
1636 //                                              $this->addScript('', ScriptLibInfo::LIB_JQUERY_RESPONSIVETABLE);// 管理画面作成用
1637                                                 $this->addScript('', ScriptLibInfo::getWysiwygEditorLibId());   // WYSIWYGエディターを追加
1638                                         //      $this->addScriptFile(self::M3_PLUS_SCRIPT_FILENAME);            // フロント画面追加用スクリプト追加(PLUSライブラリを追加する場合はFCKEditorも使用可能にする)
1639                                                 $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1640                                                 $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
1641                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1642                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1643                                                 
1644                                                 // Googleマップライブラリの読み込み
1645                                                 if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1646                                                         $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));
1647                                                 }
1648                                         }
1649                                 }
1650                         }
1651                 }
1652
1653                 // デフォルトのページ情報を取得
1654                 $row = $this->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
1655                 if (!empty($row)){
1656                         // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1657                         if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1658                 
1659                         // 現在のページ情報を設定
1660                         $this->currentPageInfo = $row;                  // 現在のページのページ情報
1661                 }
1662                         
1663                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)のとき
1664 /*                      $defPageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1665                         $defPageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1666                         
1667                         // デフォルトのページ情報を取得
1668                         $row = $this->getPageInfo($defPageId, $defPageSubId);
1669                         if (!empty($row)){
1670                                 // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1671                                 if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1672                         
1673                                 // 現在のページ情報を設定
1674                                 $this->currentPageInfo = $row;                  // 現在のページのページ情報
1675                         }*/
1676                         
1677                         // テンプレートの情報を取得
1678         //              $ret = $this->db->getPageDefOnPage($defPageId, $defPageSubId, $rows);
1679                         $ret = $this->db->getPageDefOnPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1680                         if ($ret){
1681                                 for ($i = 0; $i < count($rows); $i++){
1682                                         $position = $rows[$i]['pd_position_id'];
1683                                         if (!in_array($position, $this->defPositions)) $this->defPositions[] = $position;       // 画面定義データのポジション(すべて)
1684                                 }
1685                         }
1686                 }
1687                 
1688                 // 画面透過モードを設定
1689                 if ($openBy == 'tabs') $this->isTransparentMode = true;         // 画面透過モード
1690         }
1691         /**
1692          * URLの最初のパラメータが不正文字の場合はエラー画面へリダイレクト
1693          *
1694          * @param string $value                 URLの最初のパラメータ値
1695          * @return bool                                 true=正常、false=異常
1696          */
1697         function _checkFirstValueRedirect($value)
1698         {
1699                 global $gEnvManager;
1700                 global $gOpeLogManager;
1701                 
1702                 // 半角英小文字大文字、数字、アンダーバー、ハイフン、カンマのみ使用可能。
1703                 if (preg_match("/[^0-9a-zA-Z-_,]/", $value)){
1704                         $errMessage = 'URLパラメータの不正。';
1705                         $gOpeLogManager->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2200, 'アクセスをブロックしました。URL: ' . $gEnvManager->getCurrentRequestUri());
1706                         
1707         //              $this->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
1708                         // システム制御ページへ遷移
1709                         $this->isSystemPage = true;
1710                         return false;
1711                 } else {
1712                         return true;
1713                 }
1714         }
1715         /**
1716          * 言語に依存する情報を取り込む
1717          *
1718          * @return                                                      なし
1719          */
1720         function loadLang()
1721         {
1722                 global $gEnvManager;
1723                 global $gSystemManager;
1724                 
1725                 $lang = $gEnvManager->getCurrentLanguage();
1726                 
1727                 // デフォルト言語とカレント言語が異なる場合のみ実行
1728                 if ($lang != $gEnvManager->getDefaultLanguage()){
1729                         // 指定言語のサイト定義取得
1730                         $gSystemManager->roadSiteDefByLang($lang);
1731                 }
1732                 
1733                 // 現在の言語でヘッダ初期化
1734                 $this->headDescription  = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_DESCRIPTION);    // HTMLヘッダ「description」に出力する文字列
1735                 $this->headKeywords             = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_KEYWORDS);               // HTMLヘッダ「keywords」に出力する文字列
1736                 $this->headOthers               = $gSystemManager->getSiteDef(self::SD_HEAD_OTHERS);                    // HTMLヘッダに出力するタグ文字列
1737
1738                 // デフォルトのページ情報でヘッダを更新
1739                 if (!empty($this->currentPageInfo)){
1740                         $title          = $this->currentPageInfo['pn_meta_title'];              // 画面タイトル
1741                         $desc           = $this->currentPageInfo['pn_meta_description'];                // ページ要約
1742                         $keyword        = $this->currentPageInfo['pn_meta_keywords'];           // ページキーワード
1743                         $headOthers     = $this->currentPageInfo['pn_head_others'];             // ヘッダその他タグ
1744                         
1745                         if (!empty($title)) $this->setHeadSubTitle($title);
1746                         if (!empty($desc)) $this->setHeadDescription($desc);
1747                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1748                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1749                 }
1750
1751                 // 現在の言語のページ情報でヘッダを更新
1752                 $ret = $this->db->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $lang, $row);
1753                 if ($ret){
1754                         $title          = $row['pn_meta_title'];                // 画面タイトル
1755                         $desc           = $row['pn_meta_description'];          // ページ要約
1756                         $keyword        = $row['pn_meta_keywords'];             // ページキーワード
1757                         $headOthers = $row['pn_head_others'];           // ヘッダその他タグ
1758                         
1759                         if (!empty($title)) $this->setHeadSubTitle($title);
1760                         if (!empty($desc)) $this->setHeadDescription($desc);
1761                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1762                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1763                         
1764                         // 現在のページ情報を設定
1765 //                      $this->currentPageInfo = $row;                  // 現在のページのページ情報
1766                 }
1767         }
1768         /**
1769          * スクリプト追加情報から、管理機能用のJavascriptファイル、CSSを追加する
1770          *
1771          * @param string $task                          指定タスク
1772          * @param string $scriptInfo            スクリプト追加情報
1773          * @return                                                      なし
1774          */
1775         function addAdminScript($task, $scriptInfo)
1776         {
1777                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1778                 for ($i = 0; $i < count($itemArray); $i++){
1779                         $pos = strpos($itemArray[$i], '=');
1780                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1781                                 $libs = trim($itemArray[$i]);
1782                         } else {                // タスク指定のとき
1783                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1784                                 $libTask = trim($libTask);
1785                                 $libs = trim($libs);
1786                                 
1787                                 if (strEndsWith($libTask, '_')){                // 「task_subtask」形式のタスクのとき
1788                                         if (!strStartsWith($task, $libTask)) $libs = '';                        // タスクIDの先頭部が異なるときは追加しない
1789                                 } else {
1790                                         if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1791                                 }
1792                         }
1793                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1794                                 $libsArray = explode(',', $libs);
1795                                 for ($j = 0; $j < count($libsArray); $j++){
1796                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1797                                         
1798                                         // ライブラリセットを展開
1799                                         $setLibArray = ScriptLibInfo::getLibSet($lib);
1800                                         $setLibCount = count($setLibArray);
1801                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1802                                                 for ($k = 0; $k < $setLibCount; $k++){
1803                                                         $this->_addAdminScript($setLibArray[$k]);
1804                                                 }
1805                                         } else {
1806                                                 $this->_addAdminScript($lib);
1807                                         }
1808                                 }
1809                         }
1810                 }
1811         }
1812         /**
1813          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
1814          *
1815          * @param string $lib                           ライブラリID
1816          * @return                                                      なし
1817          */
1818         function _addAdminScript($lib)
1819         {
1820                 // ライブラリが存在しないときは終了
1821                 if (!isset($this->libFiles[$lib])) return;
1822                 
1823                 // 依存ライブラリを取得
1824 //              if (strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){         // elFinder、timepickerを使用する場合
1825                 // jQuery UIライブラリを追加
1826                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
1827                 if (isset($dependentLib)){
1828                         for ($i = 0; $i < count($dependentLib); $i++){
1829                                 $addLib = $dependentLib[$i];
1830
1831                                 // ライブラリのファイルを追加
1832                                 if (isset($this->libFiles[$addLib]['script'])){
1833                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1834                                         for ($m = 0; $m < count($scriptFiles); $m++){
1835                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1836                                         }
1837                                 }
1838                                 // ライブラリの言語ファイルを追加
1839                                 if (isset($this->libFiles[$addLib]['script_lang'])){
1840                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);
1841                                         for ($m = 0; $m < count($scriptFiles); $m++){
1842                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1843                                         }
1844                                 }
1845                                 // ライブラリのCSSファイルを追加
1846                                 if (isset($this->libFiles[$addLib]['css'])){
1847                                         $cssFiles = $this->libFiles[$addLib]['css'];
1848                                         for ($m = 0; $m < count($cssFiles); $m++){
1849                                                 $this->addAdminCssFile($cssFiles[$m]);          // 通常機能用のCSS追加
1850                                         }
1851                                 }
1852                         }
1853                         // jQueryUIテーマを追加
1854                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1855                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1856                                 $this->outputTheme = true;
1857                         }
1858                 }
1859
1860                 // Javascript追加
1861                 if (isset($this->libFiles[$lib]['script'])){
1862                         $scriptFiles = $this->libFiles[$lib]['script'];
1863
1864                         // ##### ライブラリ情報を作成する場合 #####
1865                         if (empty($scriptFiles)){
1866                                 $generatedLib = ScriptLibInfo::generateLib($lib);                       // ライブラリ取得
1867                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
1868                         }
1869                         
1870                         for ($i = 0; $i < count($scriptFiles); $i++){
1871                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1872                         }
1873                 }
1874                 // ライブラリの言語ファイルを追加
1875                 if (isset($this->libFiles[$lib]['script_lang'])){
1876                         $scriptFiles = ScriptLibInfo::getLangScript($lib);
1877                         for ($i = 0; $i < count($scriptFiles); $i++){
1878                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1879                         }
1880                 }
1881                 // CSS追加
1882                 if (isset($this->libFiles[$lib]['css'])){
1883                         $cssFiles = $this->libFiles[$lib]['css'];
1884                         for ($i = 0; $i < count($cssFiles); $i++){
1885                                 $this->addAdminCssFile($cssFiles[$i]);          // 管理機能用のCSS追加
1886                         }
1887                 }
1888                 // その他
1889                 if (strncmp($lib, 'jquery-ui.', 10) == 0){              // jQuery UIのwidgetsまたはeffectsのとき。jQuery UI Coreはデフォルトで読み込まれている。
1890                         // jQueryUIテーマを追加
1891                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1892                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1893                                 $this->outputTheme = true;
1894                         }
1895                 }
1896         }
1897         /**
1898          * スクリプト追加情報から、通常機能用のJavascriptファイル、CSSを追加する
1899          *
1900          * @param string $task                          指定タスク
1901          * @param string $scriptInfo            スクリプト追加情報
1902          * @return                                                      なし
1903          */
1904         function addScript($task, $scriptInfo)
1905         {
1906                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1907                 for ($i = 0; $i < count($itemArray); $i++){
1908                         $pos = strpos($itemArray[$i], '=');
1909                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1910                                 $libs = trim($itemArray[$i]);
1911                         } else {                // タスク指定のとき
1912                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1913                                 $libTask = trim($libTask);
1914                                 $libs = trim($libs);
1915                                 if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1916                         }
1917                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1918                                 $libsArray = explode(',', $libs);
1919                                 for ($j = 0; $j < count($libsArray); $j++){
1920                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1921                                         
1922                                         // jQueryライブラリ等、デフォルトでは追加されないライブラリを追加
1923                                         $setLibArray = ScriptLibInfo::getLibSet($lib);// ライブラリセットを展開
1924                                         $setLibCount = count($setLibArray);
1925                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1926                                                 for ($k = 0; $k < $setLibCount; $k++){
1927                                                         $this->_addScript($setLibArray[$k]);
1928                                                 }
1929                                         } else {
1930                                                 $this->_addScript($lib);
1931                                         }
1932                                 }
1933                         }
1934                 }
1935         }
1936         /**
1937          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
1938          *
1939          * @param string $lib                           ライブラリID
1940          * @return                                                      なし
1941          */
1942         function _addScript($lib)
1943         {
1944                 // ライブラリが存在しないときは終了
1945                 if (!isset($this->libFiles[$lib])) return;
1946
1947                 // ライブラリの依存ライブラリファイルを追加
1948                 if (strcmp($lib, 'jquery') == 0){// jQuery本体のとき
1949                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1950                 } else if (strncmp($lib, 'jquery.', 7) == 0){           // jQueryプラグインのとき
1951                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1952                         if (strcmp($lib, 'jquery.mobile') == 0){        // jQueryMobileファイルのとき
1953                                 // ##### jQueryMobileが読み込まれる前に読み込む必要があるスクリプトを設定 #####
1954                                 if (!empty($this->headPreMobileScriptFiles)){           // jQueryMobileファイルの前に出力
1955                                         for ($i = 0; $i < count($this->headPreMobileScriptFiles); $i++){
1956                                                 $this->addScriptFile($this->headPreMobileScriptFiles[$i]);              // 通常機能用のスクリプト追加
1957                                         }
1958                                 }
1959                         } else {
1960                                 // 依存ライブラリ追加
1961                                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
1962                                 if (isset($dependentLib)){
1963                                         for ($i = 0; $i < count($dependentLib); $i++){
1964                                                 $addLib = $dependentLib[$i];
1965                                 
1966                                                 // ライブラリのファイルを追加
1967                                                 if (isset($this->libFiles[$addLib]['script'])){
1968                                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1969                                                         for ($m = 0; $m < count($scriptFiles); $m++){
1970                                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1971                                                         }
1972                                                 }
1973                                                 // ライブラリの言語ファイルを追加
1974                                                 if (isset($this->libFiles[$addLib]['script_lang'])){
1975                                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);
1976                                                         for ($m = 0; $m < count($scriptFiles); $m++){
1977                                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1978                                                         }
1979                                                 }
1980                                                 // ライブラリのCSSファイルを追加
1981                                                 if (isset($this->libFiles[$addLib]['css'])){
1982                                                         $cssFiles = $this->libFiles[$addLib]['css'];
1983                                                         for ($m = 0; $m < count($cssFiles); $m++){
1984                                                                 $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
1985                                                         }
1986                                                 }
1987                                         }
1988                                 }
1989                         }
1990                 } else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI) == 0){    // jQuery UI
1991                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1992                 //} else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI_PLUS) == 0){     // jQuery UI plus
1993                 //      $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1994                 //      $this->addScriptFile($this->selectedJQueryUiFilename);          // jQuery Coreスクリプト追加
1995                 } else if (strncmp($lib, 'jquery-ui.', 10) == 0 ||              // jQuery UIのwidgetsまたはeffectsのとき
1996                         strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){             // elFinder、timepickerを使用する場合
1997
1998                         // 依存ライブラリ追加
1999                         if (strncmp($lib, 'jquery-ui.', 10) == 0){
2000                                 $jQueryUiInfo = ScriptLibInfo::getJQueryUiInfo();// ライブラリ情報取得
2001                                 $dependentLib = $jQueryUiInfo[$lib];            // 依存ライブラリ取得
2002                         } else {
2003                                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
2004                         }
2005                         for ($i = 0; $i < count($dependentLib); $i++){
2006                                 $addLib = $dependentLib[$i];
2007                                 
2008                                 // ライブラリのファイルを追加
2009                                 if (isset($this->libFiles[$addLib]['script'])){
2010                                         $scriptFiles = $this->libFiles[$addLib]['script'];
2011                                         for ($m = 0; $m < count($scriptFiles); $m++){
2012                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
2013                                         }
2014                                 }
2015                                 // ライブラリの言語ファイルを追加
2016                                 if (isset($this->libFiles[$addLib]['script_lang'])){
2017                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);;
2018                                         for ($m = 0; $m < count($scriptFiles); $m++){
2019                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
2020                                         }
2021                                 }
2022                                 // ライブラリのCSSファイルを追加
2023                                 if (isset($this->libFiles[$addLib]['css'])){
2024                                         $cssFiles = $this->libFiles[$addLib]['css'];
2025                                         for ($m = 0; $m < count($cssFiles); $m++){
2026                                                 $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
2027                                         }
2028                                 }
2029                         }
2030                         // jQueryUIテーマを追加
2031                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
2032                                 $this->addCssFile($this->getDefaultThemeUrl());         // 通常機能用のCSS追加
2033                                 $this->outputTheme = true;
2034                         }
2035                 }
2036                 
2037                 // ライブラリ自体のファイルを追加
2038                 if (isset($this->libFiles[$lib]['script'])){
2039                         $scriptFiles = $this->libFiles[$lib]['script'];
2040                         
2041                         // ##### ライブラリ情報を作成する場合 #####
2042                         if (empty($scriptFiles)){
2043                                 $generatedLib = ScriptLibInfo::generateLib($lib);                       // ライブラリ取得
2044                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2045                         }
2046                         
2047                         for ($i = 0; $i < count($scriptFiles); $i++){
2048                                 $this->addScriptFile($scriptFiles[$i]);         // 通常機能用のスクリプト追加
2049                         }
2050                 }
2051                 // ライブラリの言語ファイルを追加
2052                 if (isset($this->libFiles[$lib]['script_lang'])){
2053                         $scriptFiles = ScriptLibInfo::getLangScript($lib);
2054                         for ($i = 0; $i < count($scriptFiles); $i++){
2055                                 $this->addScriptFile($scriptFiles[$i]);         // 通常機能用のスクリプト追加
2056                         }
2057                 }
2058                 // ライブラリのCSSファイルを追加
2059                 if (isset($this->libFiles[$lib]['css'])){
2060                         $cssFiles = $this->libFiles[$lib]['css'];
2061                         for ($i = 0; $i < count($cssFiles); $i++){
2062                                 $this->addCssFile($cssFiles[$i]);               // 通常機能用のCSS追加
2063                         }
2064                 }
2065         }
2066         /**
2067          * 非ログイン時の管理機能用のJavascriptファイル、CSSを追加する
2068          *
2069          * @param array, string         $lib            追加ライブラリID
2070          * @return                                      なし
2071          */
2072         function addPermittedAdminScript($lib)
2073         {
2074                 if (is_array($lib)){
2075                         for ($j = 0; $j < count($lib); $j++){
2076                                 $libId = $lib[$j];
2077                         
2078                                 // Javascript追加
2079                                 if (isset($this->libFiles[$libId]['script'])){
2080                                         $scriptFiles = $this->libFiles[$libId]['script'];
2081                                         
2082                                         // ##### ライブラリ情報を作成する場合 #####
2083                                         if (empty($scriptFiles)){
2084                                                 $generatedLib = ScriptLibInfo::generateLib($libId);                     // ライブラリ取得
2085                                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2086                                         }
2087                         
2088                                         for ($i = 0; $i < count($scriptFiles); $i++){
2089                                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2090                                         }
2091                                 }
2092                                 // ライブラリの言語ファイルを追加
2093                                 if (isset($this->libFiles[$libId]['script_lang'])){
2094                                         $scriptFiles = ScriptLibInfo::getLangScript($libId);
2095                                         for ($i = 0; $i < count($scriptFiles); $i++){
2096                                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2097                                         }
2098                                 }
2099                                 // CSS追加
2100                                 if (isset($this->libFiles[$libId]['css'])){
2101                                         $cssFiles = $this->libFiles[$libId]['css'];
2102                                         for ($i = 0; $i < count($cssFiles); $i++){
2103                                                 $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
2104                                         }
2105                                 }
2106                         }
2107                 } else {
2108                         $libId = $lib;
2109                         
2110                         // Javascript追加
2111                         if (isset($this->libFiles[$libId]['script'])){
2112                                 $scriptFiles = $this->libFiles[$libId]['script'];
2113                                 
2114                                 // ##### ライブラリ情報を作成する場合 #####
2115                                 if (empty($scriptFiles)){
2116                                         $generatedLib = ScriptLibInfo::generateLib($libId);                     // ライブラリ取得
2117                                         if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2118                                 }
2119                         
2120                                 for ($i = 0; $i < count($scriptFiles); $i++){
2121                                         $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2122                                 }
2123                         }
2124                         // ライブラリの言語ファイルを追加
2125                         if (isset($this->libFiles[$libId]['script_lang'])){
2126                                 $scriptFiles = ScriptLibInfo::getLangScript($libId);
2127                                 for ($i = 0; $i < count($scriptFiles); $i++){
2128                                         $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2129                                 }
2130                         }
2131                         // CSS追加
2132                         if (isset($this->libFiles[$libId]['css'])){
2133                                 $cssFiles = $this->libFiles[$libId]['css'];
2134                                 for ($i = 0; $i < count($cssFiles); $i++){
2135                                         $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
2136                                 }
2137                         }
2138                 }
2139         }
2140         /**
2141          * ページ作成終了
2142          *
2143          * ・最終HTML出力
2144          * ・セッション情報の保存
2145          * ・ウィジェットで生成されたHTTPヘッダを設定する
2146          *
2147          * @param RequestManager $request               HTTPリクエスト処理クラス
2148          * @param bool $getOutput                               出力を取得するかどうか
2149          * @return string                                       最終出力HTML
2150          */
2151         function endPage($request, $getOutput = false)
2152         {
2153                 global $gRequestManager;
2154                 global $gInstanceManager;
2155                 global $gEnvManager;
2156                 global $gDispManager;
2157                 global $gAccessManager;
2158                 
2159                 // ページ作成処理を中断するかどうか
2160                 if ($this->isAbort) return '';
2161                 
2162                 $contents = '';
2163                 
2164                 // 実行コマンドを取得
2165                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2166                 
2167                 // 最終HTML(ページ全体で使用するHTML)の出力
2168                 if ($cmd == M3_REQUEST_CMD_CSS){                // CSS生成のとき
2169                         // 外部出力形式でCSS出力
2170                         if (count($this->exportCss) > 0){
2171                                 for ($i = 0; $i < count($this->exportCss); $i++){
2172                                         $contents .= $this->exportCss[$i] . M3_NL;
2173                                 }
2174                         }
2175                         
2176                         // ヘッダ出力
2177                         header('Content-type: text/css');
2178                         
2179                         // 画面情報、ユーザ情報の保存は行わない
2180                         return $contents;
2181                 } else if ($cmd != M3_REQUEST_CMD_DO_WIDGET){           // ウィジェット単体オペレーションのときは出力しない
2182 /*                      if ($getOutput){
2183                                 $contents = $this->getLastContents($request);
2184                         } else {
2185                                 echo $this->getLastContents($request);
2186                         }*/
2187                 }
2188                 
2189                 // セッションへユーザ情報を保存
2190                 $userInfo = $gInstanceManager->getUserInfo();
2191                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
2192                 
2193                 // その他セッション情報保存
2194                 $gRequestManager->_doSessionCloseEventCallback();
2195                 
2196                 // 画面設定保存
2197                 $gDispManager->save();
2198                         
2199                 // キャッシュリミッタは、各リクエスト毎に(アウトプットバッファー が無効な場合は、
2200                 // session_start()がコールされる 前に) session_cache_limiter()をコールする必要がある。
2201                 // キャッシュを残す設定
2202 //              session_cache_limiter('private');
2203 //              session_cache_expire(5);
2204                 if ($this->isRedirect) return '';                       // リダイレクトの場合は終了
2205
2206                 // ########## HTTPヘッダ出力処理 ########
2207                 if (headers_sent($filename, $linenum)){         // HTTPヘッダが既に送信されているとき
2208                         echo "$filename の $linenum 行目でヘッダがすでに送信されています。";
2209                 } else {
2210                         if ($gEnvManager->isMobile()){          // 携帯の場合
2211                                 // ドコモ端末の場合はリクエストヘッダにXHTMLを指定しないとXHTMLを処理しない
2212                                 $agent = $gInstanceManager->getMobileAgent();
2213                                 if ($agent->isDoCoMo()){        // ドコモ端末のとき
2214                                         header('Content-Type: application/xhtml+xml;');
2215                                 }
2216                         } else {
2217                                 // キャッシュを無効にする場合
2218                                 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');// 過去の日付
2219                                 header('Cache-Control: no-store, no-cache, must-revalidate');// HTTP/1.1
2220                                 header('Cache-Control: post-check=0, pre-check=0', false);
2221                                 header('Pragma: no-cache');
2222                 
2223                                 // 更新日時
2224                                 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
2225                 
2226                                 // Ajax用JSON型データをHTTPヘッダに格納
2227                                 $gInstanceManager->getAjaxManager()->header();
2228                         }
2229                         // システム制御画面が設定されている場合はステータスコードを変更
2230                         //if ($this->gEnv->getIsMaintenance()){
2231                         if (!$this->isRedirect){                        // リダイレクトがセットされていない場合
2232                                 switch ($this->systemHandleMode){
2233                                         case 10:                        // サイト非公開(システムメンテナンス)
2234                                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
2235                                                 header('Status: 503 Service Temporarily Unavailable');
2236                                                 break;
2237                                         case 11:                        // アクセス禁止のとき
2238                                                 header('HTTP/1.1 403 Forbidden');
2239                                                 header('Status: 403 Forbidden');
2240                                                 break;
2241                                         case 12:                        // 存在しないページのとき
2242                                                 header("HTTP/1.1 404 Not Found");
2243                                                 header("Status: 404 Not Found");
2244                                                 break;
2245                                 }
2246                         }
2247                 }
2248                 // ##### 自動ログイン #####
2249                 $gAccessManager->endAutoLogin();
2250                 
2251                 return $contents;
2252         }
2253         /**
2254          * ページ作成処理中断
2255          *
2256          * 注意)exitSystem()でシステムを終了させる必要あり
2257          *
2258          * @return                                                      なし
2259          */
2260         function abortPage()
2261         {
2262                 global $gInstanceManager;
2263                 global $gRequestManager;
2264                 
2265                 // HTTPヘッダを削除(PHP 5.3以上で有効)
2266                 if (version_compare(PHP_VERSION, '5.3.0') >= 0) header_remove();
2267
2268                 // exit()等でabortPage()が最後の処理になってしまう可能性があるのでなるべく必要な処理を行う
2269                 //if (ob_get_level() > 0) ob_end_clean();// バッファ内容が残っているときは破棄
2270                 while (ob_get_level()) ob_end_clean();  // バッファ削除方法変更(2009/12/2)
2271                 
2272                 // セッションへユーザ情報を保存
2273                 $userInfo = $gInstanceManager->getUserInfo();
2274                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
2275                 
2276                 // その他セッション情報保存
2277                 $gRequestManager->_doSessionCloseEventCallback();
2278                 
2279                 $this->isAbort = true;                                  // ページ作成処理を中断するかどうか
2280         }
2281         /**
2282          * ウィジェット処理中断
2283          *
2284          * @return                                                      なし
2285          */
2286         function abortWidget()
2287         {
2288                 $this->isWidgetAbort = true;                                    // 各ウィジェット処理を中断するかどうか
2289         }
2290         /**
2291          * 強制終了を実行
2292          *
2293          * @return              なし
2294          */
2295         function exitSystem()
2296         {
2297                 global $gEnvManager;
2298                 global $gAccessManager;
2299                 
2300                 // DBが使用可能であれば、アクセスログのユーザを登録
2301                 if ($gEnvManager->canUseDb()) $gAccessManager->accessLogUser();
2302                 
2303                 exit();         // システム終了
2304         }
2305         /**
2306          * Joomla!v1.5タグを読み込んでウィジェット実行
2307          *
2308          * @param string        $srcBuf                 バッファデータ
2309          * @param int           $templateVer    テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
2310          * @return string                                       変換後文字列
2311          */
2312         function launchWidgetByJoomlaTag($srcBuf, $templateVer)
2313         {
2314                 $replace = array();
2315                 $matches = array();
2316                 $destBuf = $srcBuf;
2317                 
2318                 if (preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\s*\/>#iU', $srcBuf, $matches)){
2319                         $count = count($matches[1]);
2320                         for ($i = 0; $i < $count; $i++)
2321                         {
2322                                 $contents = '';
2323                                 $type  = $matches[1][$i];
2324                                 $attr = array();
2325                                 if (strcasecmp($type, 'head') == 0){            // ヘッダ埋め込みタグの場合
2326                                         ob_clean();
2327                                         $this->getHeader();
2328                                         $contents = ob_get_contents();
2329                                 } else if (strcasecmp($type, 'modules') == 0 || strcasecmp($type, 'module') == 0 ||             // 一般ウィジェット用配置ブロックの場合
2330                                                         strcasecmp($type, 'navmenu') == 0){                                                                                     // ナビゲーションメニューウィジェット用配置ブロックの場合
2331                                         $name = '';                     // ポジション名
2332                                         $posType = '';          // ポジションのタイプ
2333                                         $style = '';            // 表示スタイル
2334                                         $params = explode(' ', $matches[2][$i]);
2335                                         $paramArray = array();
2336                                         for ($j = 0; $j < count($params); $j++){
2337                                                 list($key, $value) = explode('=', $params[$j]);
2338                                                 $key = trim($key);
2339                                                 $value = trim($value, "\"'");
2340                                                 if (!empty($key)) $paramArray[$key] = $value;
2341                                         }
2342                                         $value = $paramArray['name'];
2343                                         if (isset($value)){
2344                                                 $name = $value;
2345                                                 $attr['name'] = $value;
2346                                         }
2347                                         $value = $paramArray['type'];           // 配置ブロックのタイプを属性に格納。テンプレート内での参照用。
2348                                         if (isset($value)){
2349                                                 $posType = $value;
2350                                                 $attr['type'] = $value;
2351                                         }
2352                                         $value = $paramArray['id'];
2353                                         if (isset($value)) $attr['id'] = $value;
2354                                         
2355                                         // スタイルが設定されている場合はオプションスタイルを取得
2356                                         $value = $paramArray['style'];
2357                                         if (isset($value)){
2358                                                 $style = $value;
2359                                                 $attr['style'] = $value;
2360                                                 
2361                                                 $optionStyle = $paramArray[$value];             // オプションのスタイル
2362                                                 if (isset($optionStyle)) $attr[$value] = $optionStyle;
2363                                         }
2364 /*                                      for ($j = 0; $j < count($params); $j++){
2365                                                 list($key, $value) = explode('=', $params[$j]);
2366                                                 if (strcasecmp($key, 'name') == 0){
2367                                                         $name = strtolower(trim($value, "\"'"));
2368                                                         $attr['name'] = $name;
2369                                                 } else if (strcasecmp($key, 'style') == 0){
2370                                                         // スタイルは大文字小文字の区別あり
2371                                                         $style = trim($value, "\"'");
2372                                                 } else if (strcasecmp($key, 'artstyle') == 0){          // テンプレート側指定の表示スタイル(Artisteer用)
2373                                                         $attr['artstyle'] = trim($value, "\"'");
2374                                                 } else if (strcasecmp($key, 'bootstyle') == 0){         // テンプレート側指定の表示スタイル(Bootstrap用)
2375                                                         $attr['bootstyle'] = trim($value, "\"'");
2376                                                 } else if (strcasecmp($key, 'drstyle') == 0){           // テンプレート側指定の表示スタイル(Themer用)
2377                                                         $attr['drstyle'] = trim($value, "\"'");
2378                                                 }
2379                                         }*/
2380
2381                                         if (!empty($name)){             // ポジション名が取得できたとき
2382                                                 // Joomla!では、テンプレートの「jdoc:include」タグの属性styleが空のときは「none」で処理される
2383                                                 // Joomla!デフォルトで設定可能なのは「none,table,horz,xhtml,rounded,outline」
2384 /*                                              if (empty($style)){
2385                                                         if (strStartsWith($name, 'user') ||             // ナビゲーションメニュー位置の場合
2386                                                                 strcasecmp($name, 'position-1') == 0){                          // Joomla!v2.5テンプレート対応
2387                                                                 $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2388                                                         } else {
2389                                                                 $style = 'none';
2390                                                         }
2391                                                 }*/
2392                                                 if (strcasecmp($type, 'navmenu') == 0){                                                                                 // メニューウィジェット用配置ブロックの場合
2393                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2394                                                         $attr['type'] = $type;                  // テンプレート内での参照用
2395                                                 } else if (strcasecmp($name, 'user3') == 0 ||           // ナビゲーションメニュー位置の場合
2396                                                         strcasecmp($name, 'position-1') == 0 ||         // Joomla!v2.5テンプレート対応
2397                                                         strcasecmp($posType, 'hmenu') == 0){            // Joomla!v3テンプレート対応
2398                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2399                                                 } else if (empty($style)){
2400                                                         $style = 'none';
2401                                                 }
2402                                                 // ウィジェットの出力を取得
2403                                                 $contents = $this->getContents($name, $style, $templateVer, $attr);
2404                                         }
2405                                 } else if (strcasecmp($type, 'component') == 0){        // メインポジションタグの場合
2406                                         // スタイルを取得
2407                                         $style = '';            // 表示スタイル
2408                                         $params = explode(' ', $matches[2][$i]);
2409                                         for ($j = 0; $j < count($params); $j++){
2410                                                 list($key, $value) = explode('=', $params[$j]);
2411                                                 if (strcasecmp($key, 'style') == 0){
2412                                                         // スタイルは大文字小文字の区別あり
2413                                                         $style = trim($value, "\"'");
2414                                                         break;
2415                                                 }
2416                                         }
2417                                         if ($style != 'none') $style = 'xhtml';
2418                                         $contents = $this->getContents('main', $style, $templateVer, $attr);
2419                                 } else if (strcasecmp($type, 'message') == 0){  // メッセージタグの場合
2420                                 }
2421                                 $replace[$i] = $contents;
2422                         }
2423                         ob_clean();
2424                         $destBuf = str_replace($matches[0], $replace, $srcBuf);
2425                 }
2426                 return $destBuf;
2427         }
2428         /**
2429          * 遅延ウィジェット実行
2430          *
2431          * 遅延実行インデックスのついているウィジェットをインデックス順に実行し、出力バッファデータ内のタグの位置に出力を埋め込む
2432          *
2433          * @param RequestManager $request               HTTPリクエスト処理クラス
2434          * @param string         $srcBuf                バッファデータ
2435          * @return string                                               変換後文字列
2436          */
2437         function lateLaunchWidget($request, $srcBuf)
2438         {
2439                 global $gEnvManager;
2440                 global $gErrorManager;
2441                 global $gDesignManager;
2442                 
2443                 // ページ作成中断またはウィジェット処理中断のときは終了
2444                 if ($this->isAbort || $this->isWidgetAbort) return '';
2445                 
2446                 // ウィジェットヘッダ(Joomla!1.0用)を出力のタイプを取得
2447                 $widgetHeaderType = $this->getTemplateWidgetHeaderType();
2448                                         
2449                 // 遅延実行ウィジェットをインデックス順にソート
2450                 asort($this->lateLaunchWidgetList, SORT_NUMERIC);
2451                 
2452                 // タグを置換
2453                 $destBuf = $srcBuf;
2454                 foreach ($this->lateLaunchWidgetList as $widgetId => $value){
2455                         // 実行パラメータ取得
2456                         $count = count($this->latelaunchWidgetParam);
2457                         for ($i = 0; $i < $count; $i++){
2458                                 list($wId, $maxNo, $confId, $preId, $serial, $style, $cssStyle, $title, $shared, $exportCss, $position, $index, $pageDefRec) = $this->latelaunchWidgetParam[$i];
2459                                 if ($wId == $widgetId){
2460                                         // パラメータ初期化
2461                                         $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
2462                                         $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
2463                                         $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
2464                                         
2465                                         // 現在のウィジェットのポジション
2466                                         $this->currentWidgetPosition = $position;                       // 現在のウィジェットのポジション
2467                                         $this->currentWidgetIndex = $index;                     // 現在のウィジェットのポジション番号
2468         
2469                                         // バッファ作成
2470                                         ob_start();
2471
2472                                         // ウィジェット実行ファイル取得
2473                                         $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
2474
2475                                         // その他パラメータ取得
2476                                         $configId = $confId;            // ウィジェット定義ID
2477                                         if ($configId == 0) $configId = '';
2478                                         $prefix = $preId;               // サフィックス文字列
2479                         
2480                                         // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
2481                                         $joomlaTitleVisble = false;
2482                                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
2483                                                 if (!empty($title)){
2484                                                         if ($widgetHeaderType == 1){            // PC用ウィジェットヘッダ出力
2485                                                                 echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
2486                                                                 echo '<tr><th>' . $title . '</th></tr>' . M3_NL;
2487                                                                 echo '<tr><td>' . M3_NL;
2488                                                                 $joomlaTitleVisble = true;
2489                                                         } else if ($widgetHeaderType == 2){                     // 携帯用ウィジェットヘッダ出力
2490                                                                 echo '<div>' . $title . '</div>' . M3_NL;
2491                                                                 $joomlaTitleVisble = true;
2492                                                         }
2493                                                 }
2494                                         }
2495                                         // ウィジェットの外枠タグを設定
2496                                         //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
2497                                         // ウィジェット親のCSS定義があるときは、タグを追加
2498                                         if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
2499                                         
2500                                         // ウィジェットの前出力
2501                                         echo $gDesignManager->getAdditionalWidgetOutput(true);
2502                                 
2503                                         // 作業中のウィジェットIDを設定
2504                                         $gEnvManager->setCurrentWidgetId($widgetId);
2505
2506                                         // ウィジェット定義IDを設定
2507                                         $gEnvManager->setCurrentWidgetConfigId($configId);
2508                                         
2509                                         // ページ定義のシリアル番号を設定
2510                                         $gEnvManager->setCurrentPageDefSerial($serial);
2511                 
2512                                         // ページ定義レコードを設定
2513                                         $gEnvManager->setCurrentPageDefRec($pageDefRec);
2514                                 
2515                                         // パラメータを設定
2516                                         $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
2517                 
2518                                         // ウィジェットのタイトルを設定
2519                                         $gEnvManager->setCurrentWidgetTitle('');
2520                                         
2521                                         // ウィジェットのスタイルを設定
2522                                         $gEnvManager->setCurrentWidgetStyle($style);
2523                                 
2524                                         // ウィジェットのグローバル属性状況を設定
2525                                         $gEnvManager->setIsCurrentWidgetShared($shared);
2526                                 
2527                                         // 実行ログを残す
2528                                         $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
2529                                         
2530                                         // ウィジェットを実行
2531                                         // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
2532                                         $msg = 'widget-start(' . $widgetId . ')';
2533                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
2534                                         require($widgetIndexFile);
2535                                         $msg = 'widget-end(' . $widgetId . ')';
2536                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
2537
2538                                         // 作業中のウィジェットIDを解除
2539                                         $gEnvManager->setCurrentWidgetId('');
2540                 
2541                                         // ウィジェット定義IDを解除
2542                                         $gEnvManager->setCurrentWidgetConfigId('');
2543                                         
2544                                         // ページ定義のシリアル番号を解除
2545                                         $gEnvManager->setCurrentPageDefSerial(0);
2546                 
2547                                         // ページ定義レコードを解除
2548                                         $gEnvManager->setCurrentPageDefRec();
2549                                         
2550                                         // パラメータを解除
2551                                         $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
2552                                         
2553                                         // ウィジェットのスタイルを解除
2554                                         $gEnvManager->setCurrentWidgetStyle('');
2555                                         
2556                                         // ウィジェットのグローバル属性状況を解除
2557                                         $gEnvManager->setIsCurrentWidgetShared(false);
2558                                         
2559                                         // ウィジェットのタイトルを取得
2560                                         $newTitle = $gEnvManager->getCurrentWidgetTitle();
2561
2562                                         // ウィジェットの後出力
2563                                         echo $gDesignManager->getAdditionalWidgetOutput(false);
2564                                 
2565                                         // ウィジェット親のCSS定義があるときは、タグを追加
2566                                         if (!empty($cssStyle)) echo '</div>' . M3_NL;
2567                                         // ウィジェットの外枠タグを設定
2568                                         //echo '</div>' . M3_NL;
2569                                         
2570                                         // Joomla!1.0テンプレートのときはタイトルを出力
2571                                         if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用ウィジェットヘッダ出力
2572                                                 echo '</td></tr>' . M3_NL;
2573                                                 echo '</table>' . M3_NL;
2574                                         }
2575                                         
2576                                         // 現在のバッファ内容を取得し、バッファを破棄
2577                                         $srcContents = ob_get_contents();
2578                                         ob_end_clean();
2579                                         
2580                                         // ウィジェットの出力を取得
2581                                         $tag = self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;
2582                                         $destBuf = str_replace($tag, $srcContents, $destBuf);
2583                                         
2584                                         // タイトルの出力
2585                                         if (!empty($newTitle)) $title = $newTitle;
2586                                         $tag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
2587                                         $destBuf = str_replace($tag, $title, $destBuf);
2588                                         
2589                                         // ##### 外部出力用のCSSがある場合は追加 #####
2590                                         if (!empty($exportCss)){
2591                                                 // ウィジェットのタグIDを変換
2592                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $index;                          // ウィジェット識別用ユニークタグ
2593                                                 $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
2594                                                 $this->addExportCss($exportCss);
2595                                         }
2596                                 }
2597                         }
2598                 }
2599                 
2600                 // ##### HTMLヘッダ出力処理 #####
2601                 $destBuf = $this->replaceHead($destBuf);
2602                 
2603                 return $destBuf;
2604         }
2605         /**
2606          * ジョブ実行
2607          *
2608          * @param string $jobType               ジョブタイプ
2609          * @return                                              なし
2610          */
2611         function launchJob($jobType)
2612         {
2613                 global $gEnvManager;
2614                 
2615                 // ジョブタイプから実行するウィジェットIDを取得
2616                 $widgetId = $this->getWidgetIdByJobType($jobType);
2617                 if (empty($widgetId)) return;
2618
2619                 // 作業中のウィジェットIDを設定
2620                 $gEnvManager->setCurrentWidgetId($widgetId);
2621                         
2622                 // 指定のウィジェットを実行
2623                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/admin/job.php';
2624                         
2625                 if (file_exists($widgetIndexFile)){
2626 //                      // 実行のログを残す
2627 //                      $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
2628
2629                         require_once($widgetIndexFile);
2630                 } else {
2631                         echo 'file not found: ' . $widgetIndexFile;
2632                 }
2633                                 
2634                 // 作業中のウィジェットIDを解除
2635                 $gEnvManager->setCurrentWidgetId();
2636         }
2637         /**
2638          * ヘッダ部マクロ変換処理
2639          *
2640          * @param string         $srcBuf                変換元
2641          * @return string                                               変換後文字列
2642          */
2643         function replaceHead($srcBuf)
2644         {
2645                 $destBuf = $srcBuf;
2646
2647                 // ##### ヘッダ部分の置換 #####
2648                 if ($this->outputHead){                         // HTMLヘッダ出力を行っているとき
2649                         // タグ変換用文字列の取得
2650                         $replaceStr = $this->getHeaderOutput();
2651                         
2652                         // HTMLヘッダのデータ埋め込み
2653                         $destBuf = str_replace(self::HEAD_TAGS, $replaceStr, $destBuf);
2654                 }
2655                 $this->replaceHeadDone = true;                  // ヘッダマクロ変換処理が完了したかどうか
2656                 return $destBuf;
2657         }
2658         /**
2659          * ヘッダ部マクロ変換を有効にする
2660          *
2661          * @return                                      なし
2662          */
2663         function enableReplaceHead()
2664         {
2665                 $this->outputHead = true;
2666         }
2667         /**
2668          * ウィジェット検索モードの場合のページサブIDの設定
2669          *
2670          * @param RequestManager $request               HTTPリクエスト処理クラス
2671          */
2672         function redirectToUpdatedPageSubId($request)
2673         {
2674                 global $gEnvManager;
2675                 
2676                 // 現在設定されているページIDを取得
2677                 $pageId         = $gEnvManager->getCurrentPageId();
2678                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2679                 
2680                 // 送信元のウィジェットIDを取得
2681                 $fromWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_FROM);
2682                 
2683                 // 対象のウィジェットIDを取得
2684                 $targetWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
2685                 
2686                 // 対象のウィジェットのページサブIDを取得
2687                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2688                 if ($ret){// データが存在する
2689                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2690                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2691                                 if ($ret){// データが存在する
2692                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2693                                         } else {
2694                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2695                                         }
2696                                 }
2697                         } else {
2698                                 // 送信元があるか順にチェック
2699                                 for ($i = 0; $i < count($rows); $i++){
2700                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2701                                         if ($ret){      
2702                                                 break;
2703                                         }
2704                                 }
2705                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2706                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2707                                 } else {
2708                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2709                                 }
2710                         }
2711                 } else {                // 対象のウィジェットが見つからない場合は、互換ウィジェットを探す
2712                         $widgetId = $this->db->getCompatibleWidgetId($targetWidgetId);
2713                         if (!empty($widgetId)){
2714                                 $targetWidgetId = $widgetId;
2715                                 
2716                                 // 対象のウィジェットのページサブIDを取得
2717                                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2718                                 if ($ret){// データが存在する
2719                                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2720                                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2721                                                 if ($ret){// データが存在する
2722                                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2723                                                         } else {
2724                                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2725                                                         }
2726                                                 }
2727                                         } else {
2728                                                 // 送信元があるか順にチェック
2729                                                 for ($i = 0; $i < count($rows); $i++){
2730                                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2731                                                         if ($ret){      
2732                                                                 break;
2733                                                         }
2734                                                 }
2735                                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2736                                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2737                                                 } else {
2738                                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2739                                                 }
2740                                         }
2741                                 }
2742                         }
2743                 }
2744                 // ページサブIDが見つからないときは、既に設定されている値を使用
2745                 // 既に設定されている値は、URL「sub」パラメータで指定されている値か
2746                 // 設定されていない場合はデフォルトのサブページID
2747                 // ********** 指定ページへリダイレクト ***********
2748                 // 実行パラメータ取得
2749                 $todo = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TODO);
2750                 $todo = str_replace(M3_TODO_SEPARATOR, '&', $todo);             // セパレータを変換
2751 //              $redirectUrl = '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2752                 $redirectUrl = $gEnvManager->createPageUrl() . '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2753                 if (!empty($todo)) $redirectUrl .= '&' . $todo;
2754                 if ($gEnvManager->getIsMobileSite()){           // 携帯用アクセスポイントの場合
2755                         $this->redirect($redirectUrl, true/*遷移時のダイアログ表示を抑止*/);
2756                 } else {
2757                         $this->redirect($redirectUrl);
2758                 }
2759         }
2760         /**
2761          * 最終HTML出力処理
2762          *
2763          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2764          * 追加するHTMLは主にウィンドウ制御用のスクリプト
2765          *
2766          * @return string                                       最終HTML
2767          */
2768         function getLastContents()
2769         {
2770                 global $gEnvManager;
2771                 global $gRequestManager;
2772                 
2773                 $contents = '';
2774                 $initScript = '';               // 初期化用スクリプト
2775                 $pageId         = $gEnvManager->getCurrentPageId();
2776                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2777                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2778                 
2779                 if (!$gEnvManager->isSystemManageUser()) return '';             // システム運用権限がない場合は終了
2780                 
2781                 // 処理を行わない場合は終了
2782                 if ($cmd == M3_REQUEST_CMD_RSS ||                                               // RSS配信のときは終了
2783                         $cmd == M3_REQUEST_CMD_DO_WIDGET) return '';            // ウィジェット単体オペレーションのときは出力しない
2784                 
2785                 if ($gEnvManager->getIsMobileSite()) return '';         // 携帯用URLのときは終了
2786                 
2787                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2788                         // ウィジェットレイアウト用カーソル
2789                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
2790 /*                              // テンプレート上のポジション名
2791                                 if (count($this->viewPosId) > 0){
2792                                         $posArrayStr = '[';
2793                                         for ($i = 0; $i < count($this->viewPosId); $i++){
2794                                                 $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
2795                                                 if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
2796                                         }
2797                                         $posArrayStr .= ']';
2798                                         $contents .= 'var M3_POSITIONS=' . $posArrayStr . ';' . M3_NL;
2799                                 }
2800                                 // 画面定義のリビジョン番号
2801                                 $contents .= 'var M3_REVISION=' . $this->pageDefRev . ';' . M3_NL;*/
2802                 
2803                                 // 更新用関数追加
2804                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2805                                 $contents .= M3_INDENT_SPACE . 'window.m3.m3UpdateByConfig(serial);' . M3_NL;
2806                                 $contents .= '}' . M3_NL;
2807                         } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){                       // ウィジェット設定画面
2808                         } else {                // ダッシュボード画面、メイン管理画面
2809                                 // 画面更新用関数追加
2810                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2811                                 $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2812                                 $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2813                                 $contents .= '}' . M3_NL;
2814                         }
2815                         
2816                         // ウィジェット単体実行以外のときの処理
2817                         if (!$this->showWidget){
2818                                 if ($this->updateParentWindow){                 // 管理画面からの親画面の更新
2819                                         $initScript .= M3_INDENT_SPACE . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
2820                                 }
2821                         }
2822                 } else {                // 通常画面のとき
2823                         // 画面更新用関数追加
2824                         $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2825                         $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2826                         $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2827                         $contents .= '}' . M3_NL;
2828                 }
2829
2830                 $destContents = '';
2831                 if (!empty($contents) || !empty($initScript)){
2832 //                      $destContents .= '<script type="text/javascript">' . M3_NL;
2833 //                      $destContents .= '//<![CDATA[' . M3_NL;
2834                         $destContents .= $contents;
2835                         if (!empty($initScript)){               // 初期化用スクリプト
2836                                 $destContents .= '$(function(){' . M3_NL;
2837                                 $destContents .= $initScript;
2838                                 $destContents .= '});' . M3_NL;
2839                         }
2840 //                      $destContents .= '//]]>' . M3_NL;
2841 //                      $destContents .= '</script>' . M3_NL;
2842                 }
2843                 return $destContents;
2844         }
2845         /**
2846          * オプションHTML出力処理
2847          *
2848          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2849          *
2850          * @param RequestManager $request               HTTPリクエスト処理クラス
2851          * @return string                                       最終HTML
2852          */
2853         function getOptionContents($request)
2854         {
2855                 global $gEnvManager;
2856                 
2857                 $contents = '';
2858                 
2859                 // ページ作成中断のときは終了
2860                 if ($this->isAbort) return '';
2861                 
2862                 // AJAX用のレスポンスボディデータのときは終了
2863                 if ($this->outputAjaxResponseBody) return '';
2864                 
2865                 // ウィジェット処理中断のとき
2866                 // AJAXを送信する場合は空文字列では送信できないので、ダミーデータを返す
2867                 if ($this->isWidgetAbort) $contents .= 'NO DATA' . M3_NL;
2868                 
2869                 // Magic3出力コメント
2870                 if (!$gEnvManager->isMobile() && $this->outputByHtml){          // 携帯以外で、HTML出力のとき
2871                         $contents .= '<!-- created by ' . M3_SYSTEM_NAME . ' v' . M3_SYSTEM_VERSION . ' - http://www.magic3.org -->' . M3_NL;
2872                         $contents .= '<!-- convert time: ' . sprintf('%01.03f', microtime(true) - M3_MTIME) . ' -->' . M3_NL;
2873                 }
2874                 return $contents;
2875         }
2876         /**
2877          * Widget単体起動用のHTMLのヘッダ部(headタグ)出力
2878          *
2879          * startWidget(),endWidget()は、以下のコマンドを処理する
2880          *  ・M3_REQUEST_CMD_SHOW_WIDGET(ウィジェットの単体表示)
2881          *  ・M3_REQUEST_CMD_CONFIG_WIDGET(ウィジェット設定画面)
2882          *  ・M3_REQUEST_CMD_DO_WIDGET(ウィジェット単体実行)
2883          * Widgetの出力方法は、以下のパターンがある
2884          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
2885          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
2886          *
2887          * @param string $cmd           起動コマンド
2888          */
2889         function startWidget($cmd)
2890         {
2891                 global $gEnvManager;
2892                 global $gRequestManager;
2893
2894                 // ウィジェット単体表示のときのみ出力
2895                 if (!$this->showWidget) return;
2896
2897                 // パラメータ取得
2898                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
2899                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
2900
2901 //              $isHtml5 = false;               // HTML5で出力するかどうか
2902                 $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
2903                 if (intval($tempVer) >= 2) $this->isHtml5 = true;               // HTML5で出力するかどうか                             
2904                 
2905                 // DOCTYPEの設定
2906                 if ($this->isHtml5){
2907                         echo '<!DOCTYPE html>' . M3_NL;
2908                         echo '<html dir="ltr" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
2909                         echo '<head>' . M3_NL;
2910                 } else {
2911                         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . M3_NL;
2912                         echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $gEnvManager->getCurrentLanguage() . '" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
2913                         echo '<head>' . M3_NL;
2914 //                      echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . M3_NL;
2915                 }
2916
2917                 // HTMLのヘッダ部(headタグ内)出力
2918                 $this->getHeader();
2919
2920                 // 現在のウィジェットを取得
2921                 $widgetId = $gEnvManager->getCurrentWidgetId();         // カレントのウィジェットID
2922                 
2923                 // URLを作成
2924                 if ($gEnvManager->getUseSslAdmin()){
2925                         $rootUrl = $gEnvManager->getSslRootUrl();
2926                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
2927                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
2928                 } else {
2929                         $rootUrl = $gEnvManager->getRootUrl();
2930                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
2931                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
2932                 }
2933
2934                 // ##### テンプレートのCSSの読み込み #####
2935                 // テンプレートは管理用テンプレートに固定されている
2936                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||             // ウィジェット設定のとき
2937                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy) && $gEnvManager->isContentEditableUser())){        // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
2938                         $curTemplateUrl = $templatesUrl . '/' . $gEnvManager->getCurrentTemplateId();
2939                         if ($this->isHtml5){
2940                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/style.css" media="screen">' . M3_NL;
2941                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/widget.css" media="screen">' . M3_NL;            // ウィジェット設定画面用CSS
2942                         echo '<!--[if IE]><link rel="stylesheet" href="' . $curTemplateUrl . '/css/iestyles.css" media="screen"><![endif]-->' . M3_NL;
2943                                 echo '<!--[if lt IE 9]><script src="' . $curTemplateUrl . '/html5shiv.js"></script><![endif]-->' . M3_NL;
2944                         } else {
2945                                 echo '<link href="' . $curTemplateUrl . '/css/style.css" rel="stylesheet" type="text/css" />' . M3_NL;
2946                                 echo '<!--[if IE]><link rel="stylesheet" type="text/css" media="screen" href="' . $curTemplateUrl . '/css/iestyles.css" /><![endif]-->' . M3_NL;
2947                         }
2948                 }
2949                 // ウィジェット情報取得
2950                 $ret = $this->db->getWidgetInfo($widgetId, $row);
2951
2952                 // ##### 共通ライブラリ読み込み設定 #####
2953                 if ($cmd == M3_REQUEST_CMD_DO_WIDGET){          // ウィジェット単体実行のとき
2954                         $scritLib = trim($row['wd_add_script_lib']);
2955                         if (!empty($scritLib)) $this->addScript($task, $scritLib);
2956                 }
2957                                 
2958                 // CSS読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
2959                 if ($row['wd_read_css']){
2960                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_CSS;
2961                         if (is_dir($searchPath)){
2962                                 $dir = dir($searchPath);
2963                                 while (($file = $dir->read()) !== false){
2964                                         $filePath = $searchPath . '/' . $file;
2965                                         if ($file != '.' && $file != '..' && is_file($filePath)
2966                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
2967                                                 
2968                                                 // CSSへのURLを作成
2969                                                 $cssURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_CSS . '/' . $file;
2970                                                 echo '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
2971                                         }
2972                                 }
2973                                 $dir->close();
2974                         }
2975                 }
2976                 
2977                 // スクリプト読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
2978                 if ($row['wd_read_scripts']){
2979                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS;
2980                         if (is_dir($searchPath)){
2981                                 $dir = dir($searchPath);
2982                                 while (($file = $dir->read()) !== false){
2983                                         $filePath = $searchPath . '/' . $file;
2984                                         if ($file != '.' && $file != '..' && is_file($filePath)
2985                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
2986                                                 
2987                                                 // スクリプトへのURLを作成
2988                                                 $scriptURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
2989                                                 
2990                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
2991                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
2992                                                 echo '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
2993                                         }
2994                                 }
2995                                 $dir->close();
2996                         }
2997                 }
2998                 // ##### スクリプト用出力用タグを埋め込む #####
2999                 // ウィジェット設定画面用メニューバーの作成
3000                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){   // ウィジェット設定画面またはフロント画面編集モードのとき
3001                         echo self::MENUBAR_SCRIPT_TAGS;                 // メニューバー出力用タグ
3002                 }
3003                 
3004                 // ウィジェットのタイトルを設定
3005                 $title = $row['wd_name'];
3006                 if (empty($title)) $title = $row['wd_id'];
3007                 $gEnvManager->setCurrentWidgetTitle($title);
3008                 echo '<title>' . self::WIDGET_TITLE_START . htmlspecialchars($title) . self::WIDGET_TITLE_END . '</title>' . M3_NL;
3009                 echo '</head>' . M3_NL;
3010                 // タブでウィンドウを開く場合は背景を透過モードにする
3011                 if ($this->isTransparentMode){
3012                         echo '<body style="background-color:transparent;">' . M3_NL;
3013                 } else {
3014                         echo '<body>' . M3_NL;
3015                 }
3016                 // ウィジェット設定画面用メニューバーの作成
3017                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){   // ウィジェット設定画面またはフロント画面編集モードのとき
3018                         // ウィジェット情報を設定
3019                         $desc = $row['wd_description'];         // 説明
3020                         $gEnvManager->setCurrentWidgetParams('desc', $desc);
3021                         
3022                         echo self::MENUBAR_TAGS;                        // メニューバー出力用タグ
3023                 }
3024                 // Bootstrap用のタグ出力
3025                 if ($this->useBootstrap) echo '<div class="container">' . M3_NL;
3026                 
3027                 // 別ウィンドウで表示のときは、「閉じる」ボタンを表示
3028                 if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET ||               // ウィジェットの単体表示のとき
3029                         $cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェット詳細設定画面のとき
3030                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){               // ウィジェット単体実行でフロント画面編集モードのとき
3031
3032 //                      if ($this->isEditMode){// フロント画面編集モードのとき
3033                                 if (!empty($openBy)){
3034                                         // サーバ指定されている場合はサーバ情報を取得
3035                                         $serverName = '';
3036                                         $server = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_SERVER);
3037                                         if (!empty($server)){
3038                                                 // 設定データを取得
3039                                                 $ret = $this->db->getServerById($server, $row);
3040                                                 if ($ret){
3041                                                         $serverName = 'サーバ名:' . $row['ts_name'];// サーバ名
3042                                                         echo '<div align="left" style="float:left;padding-left:30px;"><label>' . convertToHtmlEntity($serverName) . '</label></div>';
3043                                                 }
3044                                         }
3045                                         // タブ、インナーフレーム、ダイアログ表示以外のときは「閉じる」ボタンを表示
3046                                         if ($openBy != 'tabs' && $openBy != 'iframe' && $openBy != 'dialog'){           // 以外
3047                                                 if ($openBy == 'logout'){
3048                                                         $titleStr = 'ログアウト';
3049                                                         echo '<div class="m3configclose"><a href="#" onclick="location.href=\'?cmd=logout\';" data-placement="left" data-container="body" title="' . $titleStr . '" rel="m3help"><img src="' . $rootUrl . self::CLOSE_ICON_FILE . 
3050                                                                                 '" alt="' . $titleStr . '" /></a></div>' . M3_NL;
3051                                                 } else {
3052                                                         $titleStr = '閉じる';
3053                                                         echo '<div class="m3configclose"><a href="#" onclick="window.close();" data-placement="left" data-container="body" title="' . $titleStr . '" rel="m3help"><img src="' . $rootUrl . self::CLOSE_ICON_FILE . 
3054                                                                                 '" alt="' . $titleStr . '" /></a></div>' . M3_NL;
3055                                                 }
3056                                         }
3057                                 }
3058                                 // 「前へ」「次へ」ボタン
3059                                 $titleStr = '前へ';
3060                                 echo '<div class="m3configprev" style="display:none;"><a id="m3configprev" href="#"><img src="' . $rootUrl . self::PREV_ICON_FILE . 
3061                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" rel="m3help" /></a></div>' . M3_NL;
3062                                 $titleStr = '次へ';
3063                                 echo '<div class="m3confignext" style="display:none;"><a id="m3confignext" href="#"><img src="' . $rootUrl . self::NEXT_ICON_FILE . 
3064                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" rel="m3help" /></a></div>' . M3_NL;
3065 //                      }
3066                 }
3067 //              echo '<div class="row">' . M3_NL;
3068                 echo '<!-- Widget Start -->' . M3_NL;
3069         }
3070         /**
3071          * Widget単体起動の終了処理
3072          *
3073          * startWidget(),endWidget()は、以下のコマンドを処理する
3074          *  ・M3_REQUEST_CMD_SHOW_WIDGET(ウィジェットの単体表示)
3075          *  ・M3_REQUEST_CMD_CONFIG_WIDGET(ウィジェット設定画面)
3076          *  ・M3_REQUEST_CMD_DO_WIDGET(ウィジェット単体実行)
3077          *
3078          * @param string $cmd                   起動コマンド
3079          * @param string $srcContent    HTML出力ソース
3080          */
3081         function endWidget($cmd, $srcContent)
3082         {
3083                 global $gDesignManager;
3084                 
3085                 // ウィジェット単体表示のときのみ出力
3086                 if (!$this->showWidget) return;
3087                 
3088                 // メニューバー出力
3089                 // パンくずリストを表示
3090                 $breadcrumbHtml = '';
3091                 if (!empty($this->adminSubNavbarDef)) $breadcrumbHtml .= $gDesignManager->createSubMenubar($this->adminSubNavbarDef);
3092                 if (!empty($this->adminBreadcrumbDef)) $breadcrumbHtml .= $gDesignManager->createAdminBreadcrumb($this->adminBreadcrumbDef);
3093                 $destContent = str_replace(self::MENUBAR_TAGS, $breadcrumbHtml, $srcContent);
3094
3095                 // ヘッドタグ出力
3096                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
3097                 $replaceStr .= '//<![CDATA[' . M3_NL;
3098                 
3099                 // ##### 追加関数 #####
3100                 // ウィジェット設定画面用
3101                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェットの設定管理
3102                         // 画面更新用関数追加
3103                         $replaceStr .= 'function m3UpdateByConfig(serial){' . M3_NL;
3104                         $replaceStr .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
3105                         $replaceStr .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
3106                         $replaceStr .= M3_INDENT_SPACE . 'm3UpdateParentWindow();' . M3_NL;             // 親ウィンドウ更新
3107                         $replaceStr .= '}' . M3_NL;
3108                 
3109                         // IEエラーメッセージ出力抑止
3110                         $replaceStr .= 'function hideIEErrors(){' . M3_NL;
3111                         $replaceStr .= M3_INDENT_SPACE . 'return true;' . M3_NL;
3112                         $replaceStr .= '}' . M3_NL;
3113                         $replaceStr .= 'window.onerror = hideIEErrors;' . M3_NL;
3114                 }
3115                 
3116                 // ##### 初期処理 #####
3117                 $replaceStr .= '$(function(){' . M3_NL;
3118                 // トップ位置修正
3119                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){           // ウィジェット設定画面またはフロント画面編集モードのとき
3120                         if (!empty($this->adminSubNavbarDef) || !empty($this->adminBreadcrumbDef)){
3121                                 $menubarHeight = $gDesignManager->getSubMenubarHeight();
3122                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . '$("nav.secondlevel").css("margin-top", "0");' . M3_NL;
3123                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . '$("body").css("padding-top", "' . $menubarHeight . 'px");' . M3_NL;
3124                         }
3125                 }
3126                 // ##### ウィジェットからの指定による処理 #####
3127                 if ($this->updateParentWindow){                 // 親ウィンドウ再描画のとき
3128                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット詳細設定画面のとき
3129                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
3130                         } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){                   // ウィジェット単体実行のとき
3131                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindow();' . M3_NL;
3132                         }
3133                 }
3134                 $replaceStr .= '});' . M3_NL;
3135                 $replaceStr .= '//]]>' . M3_NL;
3136                 $replaceStr .= '</script>' . M3_NL;
3137                 $destContent = str_replace(self::MENUBAR_SCRIPT_TAGS, $replaceStr, $destContent);
3138                 echo $destContent;// 変換したコンテンツを出力
3139                 
3140 //              echo '</div>' . M3_NL;                  // row
3141                 echo '<!-- Widget End -->' . M3_NL;
3142                 
3143                 // ##### ウィジェットからの指定による処理 #####
3144 /*              if ($this->updateParentWindow){                 // 親ウィンドウ再描画のとき
3145                         echo '<script type="text/javascript">' . M3_NL;
3146                         echo '//<![CDATA[' . M3_NL;
3147                         echo '$(function(){' . M3_NL;
3148                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット詳細設定画面のとき
3149                                 echo str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
3150                         } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){                   // ウィジェット単体実行のとき
3151                                 echo str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindow();' . M3_NL;
3152                         }
3153                         echo '});' . M3_NL;
3154                         echo '//]]>' . M3_NL;
3155                         echo '</script>' . M3_NL;
3156                 }*/
3157                 
3158                 // Bootstrap用のタグ出力
3159                 if ($this->useBootstrap) echo '</div>' . M3_NL;
3160                 
3161                 echo '</body>' . M3_NL;
3162                 echo '</html>' . M3_NL;
3163         }
3164         /**
3165          * Widget単体RSS出力用のHTMLのヘッダ部(headタグ)出力
3166          *
3167          * Widgetの出力方法は、以下のパターンがある
3168          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
3169          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
3170          *
3171          * @param string $cmd           起動コマンド
3172          */
3173         function startWidgetRss($cmd)
3174         {
3175         }
3176         /**
3177          * Widget単体RSS出力用のタグを閉じる
3178          *
3179          * @param string $cmd                   起動コマンド
3180          * @param string $rssContent    RSS配信内容
3181          */
3182         function endWidgetRss($cmd, $rssContent)
3183         {
3184                 global $gEnvManager;
3185                 
3186                 // ページ作成中断のときは終了
3187                 if ($this->isAbort) return;
3188                 
3189                 echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
3190                 
3191                 // RSSチャンネルデータ取得
3192                 $lang   = $gEnvManager->getCurrentLanguage();
3193                 $date   = getW3CDate();         // RSS1.0用日付
3194                 $copyright = $gEnvManager->getSiteCopyRight();          // 著作権
3195                 $title  = $this->rssChannel['title'];                           // タイトル
3196                 $link   = $this->rssChannel['link'];                            // RSS取得用URL
3197                 $desc   = $this->rssChannel['description'];                     // 説明
3198                 $seq    = $this->rssChannel['seq'];                                     // 項目の並び順(URL)
3199                 
3200                 switch ($this->rssVersion){                                     // RSSバージョン
3201                         case '1.0':
3202                         default:
3203                                 echo '<rdf:RDF xmlns="http://purl.org/rss/1.0/" ';
3204                                 echo 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ';
3205                                 echo 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
3206                                 echo 'xml:lang="' . $lang . '">' . M3_NL;
3207                                 echo '<channel rdf:about="' . convertUrlToHtmlEntity($link) . '">' . M3_NL;
3208                                 echo '<title>' . convertToHtmlEntity($title) . '</title>' . M3_NL;
3209                                 echo '<link>' . convertUrlToHtmlEntity($link) . '</link>' . M3_NL;              // 「convertUrlToHtmlEntity」が必要
3210                                 echo '<description>' . convertToHtmlEntity($desc) . '</description>' . M3_NL;
3211                                 echo '<dc:language>' . $lang . '</dc:language>' . M3_NL;
3212                                 if (!empty($copyright)) echo '<dc:rights>' . convertToHtmlEntity($copyright) . '</dc:rights>' . M3_NL;
3213                                 echo '<dc:date>' . $date . '</dc:date>' . M3_NL;
3214                                 echo '<items>' . M3_NL;
3215                                 if (count($seq) > 0){
3216                                         echo str_repeat(M3_INDENT_SPACE, 1) . '<rdf:Seq>' . M3_NL;
3217                                         for ($i = 0; $i < count($seq); $i++){
3218                                                 echo str_repeat(M3_INDENT_SPACE, 2) . '<rdf:li rdf:resource="' . convertUrlToHtmlEntity($seq[$i]) . '" />' . M3_NL;
3219                                         }
3220                                         echo str_repeat(M3_INDENT_SPACE, 1) . '</rdf:Seq>' . M3_NL;
3221                                 }
3222                                 echo '</items>' . M3_NL;
3223                                 echo '</channel>' . M3_NL;
3224                                 echo $rssContent;
3225                                 echo '</rdf:RDF>' . M3_NL;
3226                                 break;
3227                         case '2.0':
3228                                 break;
3229                 }
3230                 
3231                 // HTTPレスポンスヘッダ設定
3232                 header("Content-type: text/xml; charset=utf-8");
3233         }
3234         /**
3235          * 直サーバ接続時のXML出力用のHTMLのヘッダ部(headタグ)出力
3236          *
3237          * @param string $cmd           起動コマンド
3238          * @return                                      なし
3239          */
3240         function startWidgetXml($cmd)
3241         {
3242                 // HTTPレスポンスヘッダ
3243                 //header("Content-type: text/xml; charset=utf-8");
3244         }
3245         /**
3246          * 直サーバ接続時のXML出力終了
3247          *
3248          * @param string $cmd           起動コマンド
3249          * @return                                      なし
3250          */
3251         function endWidgetXml()
3252         {
3253         }
3254         /**
3255          * 携帯用ドキュメントタイプ出力
3256          *
3257          * @return string                               ドキュメントタイプ出力
3258          */
3259         function getMobileDocType()
3260         {
3261                 global $gEnvManager;
3262                 global $gInstanceManager;
3263                 global $gRequestManager;
3264                 
3265                 $docTypeStr = '';               // 出力するDocType
3266                 $agent = $gInstanceManager->getMobileAgent();
3267                 if ($agent->isDoCoMo()){        // ドコモ端末のとき
3268                         $htmlVer = $agent->getHTMLVersion();
3269                         switch ($htmlVer){
3270                                 case '4.0':
3271                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/1.0) 1.0//EN" "i-xhtml_4ja_10.dtd">';
3272                                         break;
3273                                 case '5.0':
3274                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/1.1) 1.0//EN" "i-xhtml_4ja_10.dtd">';
3275                                         break;
3276                                 case '6.0':
3277                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.0) 1.0//EN" "i-xhtml_4ja_10.dtd">';
3278                                         break;
3279                                 case '7.0':
3280                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.1) 1.0//EN" "i-xhtml_4ja_10.dtd">';
3281                                         break;
3282                                 case '7.1':
3283                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.2) 1.0//EN" "i-xhtml_4ja_10.dtd">';
3284                                         break;
3285                                 case '7.2':
3286                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN" "i-xhtml_4ja_10.dtd">';
3287                                         break;
3288                                 default:
3289                                         if (preg_match("/^DoCoMo\/1\.0/i", $gRequestManager->trimServerValueOf('HTTP_USER_AGENT'))){            // mova端末のとき
3290                                                 // mova端末のときはドキュメントタイプなしにすると画面表示可能
3291                                                 return '';
3292                                         }
3293                                         break;
3294                         }
3295                 } else if ($agent->isEZweb()){  // au端末のとき
3296                         if ($agent->isWAP2()){
3297                                 $docTypeStr = '<!DOCTYPE html PUBLIC "-//OPENWAVE//DTD XHTML 1.0//EN" "http://www.openwave.com/DTD/xhtml-basic.dtd">';
3298                         }
3299                 } else if ($agent->isSoftBank()){       // ソフトバンク端末のとき
3300                         if ($agent->isTypeW() || $agent->isType3GC()){
3301                                 $docTypeStr = '<!DOCTYPE html PUBLIC "-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN" "xhtml-basic10-plus.dtd">';
3302                         }
3303                 }
3304                 if ($gEnvManager->getIsMobileSite()){           // 携帯用サイトへのアクセスの場合
3305                         echo '<?xml version="1.0" encoding="' . $gEnvManager->getMobileCharset() . '" ?>' . M3_NL;
3306                 } else {
3307                         echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
3308                 }
3309                 if (empty($docTypeStr)) $docTypeStr = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
3310                 echo $docTypeStr . M3_NL;
3311         }
3312         /**
3313          * デフォルトのXML宣言取得
3314          *
3315          * @return string       XML宣言
3316          */
3317         function getDefaultXmlDeclaration()
3318         {
3319                 return '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>';
3320         }
3321         /**
3322          * HTMLのヘッダ部(headタグ内)出力
3323          *
3324          * システムに共通な定義をHTMLのheadタグ内に出力する
3325          * mosFunc.phpからも実行されるので、このメソッドは引数なしに固定。
3326          * この関数は、以下の「形式1」または「形式2」でheadタグ内に記述する
3327          *
3328          * 形式1:            <!-- m3:HTMLHeader -->
3329          * 形式2(old style): <?php mosShowHead(); ?>
3330          */
3331         function getHeader()
3332         {
3333                 global $gEnvManager;
3334                 global $gRequestManager;
3335
3336                 $this->outputHead = true;                               // HTMLヘッダ出力を行ったかどうか
3337                 
3338                 // 実行コマンドを取得
3339                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3340                 
3341                 // ######### 携帯用サイトの場合は別にヘッダを作成する #########
3342                 if ($gEnvManager->getIsMobileSite()){
3343                         // キャラクターセット
3344                         echo '<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=' . $gEnvManager->getMobileCharset() . '" />' . M3_NL;
3345
3346                         // キャッシュを保存させない
3347                         echo '<meta http-equiv="Pragma" content="no-cache" />' . M3_NL;
3348                         echo '<meta http-equiv="Cache-Control" content="no-cache" />' . M3_NL;
3349                         echo '<meta http-equiv="Expires" content="-1" />' . M3_NL;
3350                 
3351                         // サイト構築エンジン
3352                         echo '<meta name="generator" content="' . M3_SYSTEM_NAME . ' ver.' . M3_SYSTEM_VERSION . ' - ' . M3_SYSTEM_DESCRIPTION . '" />' . M3_NL;
3353                 } else {                // PC用サイト、管理用サイト、スマートフォン用サイトのとき
3354 //                      $isHtml5 = false;               // HTML5で出力するかどうか
3355                         if ($gEnvManager->getIsSmartphoneSite()){               // スマートフォン用サイトのときはHTML5で設定
3356                                 $this->isHtml5 = true;
3357                         } else {
3358                                 $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
3359                                 if (intval($tempVer) >= 2) $this->isHtml5 = true;
3360                         }
3361                         
3362                         // ********** メタタグの設定 **********
3363                         // キャラクターセット
3364                         //if ($gEnvManager->getIsSmartphoneSite()){             // スマートフォン用サイトのときはHTML5で設定
3365                         if ($this->isHtml5){
3366                                 //echo '<meta http-equiv="content-type" content="text/html; charset=' . M3_HTML_CHARSET .'" />' . M3_NL;
3367                                 echo '<meta charset="' . M3_HTML_CHARSET . '">' . M3_NL;
3368                         } else {
3369                                 echo '<meta http-equiv="content-script-type" content="text/javascript" />' . M3_NL;
3370                                 echo '<meta http-equiv="content-style-type" content="text/css" />' . M3_NL;
3371                                 echo '<meta http-equiv="content-type" content="application/xhtml+xml; charset=' . M3_HTML_CHARSET .'" />' . M3_NL;
3372                         }
3373                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3374                                 // Bootstrapで必要なMETAタグを追加
3375                                 echo '<meta name="viewport" content="width=device-width, initial-scale=1">' . M3_NL;
3376                         }
3377                         
3378                         // 基準ディレクトリの指定
3379                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
3380                                 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
3381                         
3382                                 if ($gEnvManager->getUseSslAdmin()){
3383                                         $rootUrl = $gEnvManager->getSslRootUrl();
3384                                 } else {
3385                                         $rootUrl = $gEnvManager->getRootUrl();
3386                                 }
3387                                 echo '<base href="' . $rootUrl . '/" />' . M3_NL;
3388                         }
3389                 }
3390                 echo self::HEAD_TAGS;                   // HTMLヘッダの埋め込みデータ
3391         }
3392         /**
3393          * HTMLヘッダ出力文字列の取得
3394          *
3395          * @return string               HTMLヘッダ出力文字列
3396          */
3397         function getHeaderOutput()
3398         {
3399                 global $gEnvManager;
3400                 global $gRequestManager;
3401                 global $gInstanceManager;
3402                 global $gSystemManager;
3403
3404                 $replaceStr = '';               // 変換文字列
3405                 
3406                 // 実行コマンドを取得
3407                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3408                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
3409                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
3410                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
3411                 
3412                 // ********************************************************
3413                 //               ヘッダ文字列作成の前処理
3414                 // ********************************************************
3415                 // ##### テンプレートの設定、フレームの設定から必要なライブラリを取得 #####
3416                 // Bootstrapライブラリ
3417 //              if (!$this->useBootstrap) $this->useBootstrap = $gEnvManager->getCurrentTemplateUseBootstrap();
3418                 if ($this->useBootstrap){
3419                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3420                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
3421                                         $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
3422                                         if ($cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)以外のとき
3423                                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
3424                                         }
3425                                 } else {                // ログインしていない場合(ログイン画面等)
3426                                         $this->addPermittedAdminScript(ScriptLibInfo::LIB_BOOTSTRAP);
3427                                         $this->addPermittedAdminScript(ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);// Bootstrap管理画面オプション
3428                                 }
3429                         } else {                // フロント画面へのアクセスの場合
3430                                 // ### Bootstrapのjsとcssはテンプレート側で読み込む ###
3431 //                              $this->addScript('', ScriptLibInfo::LIB_BOOTSTRAP);             // Bootstrapライブラリ
3432                                 if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW ||                          // ログイン、ログアウト場合
3433                                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy) && $gEnvManager->isContentEditableUser())){                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
3434                                         $this->addScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);               // Bootstrap管理画面オプション
3435                                 }
3436                         }
3437                 } else {
3438                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
3439                                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3440                                         $this->addAdminScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);              // Bootstrapを使用しない場合の管理機能用スクリプト
3441                                 } else {
3442                                         $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
3443                                 }
3444                         } else if ($gEnvManager->isContentEditableUser()){              // 投稿ユーザの場合
3445                                 $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
3446                         }
3447                 }
3448                 
3449                 // ********************************************************
3450                 //               ヘッダ文字列作成処理
3451                 // ********************************************************
3452                 // ##### インストール時のヘッダ出力 #####
3453                 if (defined('M3_STATE_IN_INSTALL')){
3454                         // タイトルの作成
3455                         $title = '';
3456                         if (count($this->headSubTitle) > 0) $title = htmlspecialchars(trim($this->headSubTitle[0]));
3457                         
3458                         // ********** メタタグの設定 **********
3459                         $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
3460                         
3461                         // ##### インストーラ用のファイルの読み込み #####
3462                         $scriptsUrl = '../scripts';
3463                         
3464                         // 管理機能用共通ライブラリのCSSの読み込み
3465                         $count = count($this->defaultAdminCssFiles);
3466                         for ($i = 0; $i < $count; $i++){
3467                                 // CSSへのURLを作成
3468                                 $cssFilename = $this->defaultAdminCssFiles[$i];
3469                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3470                                         $cssURL = $cssFilename;
3471                                 } else {
3472                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
3473                                 }
3474                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3475                         }
3476                         
3477                         // 管理画面用の共通スクリプトを読み込む
3478                         $count = count($this->defaultAdminScriptFiles);
3479                         for ($i = 0; $i < $count; $i++){
3480                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
3481
3482                                 // スクリプトのURLを修正
3483                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3484                                         $scriptURL = $scriptFilename;
3485                                         
3486                                         // SSLをページの状態に合わせる
3487                                         if ($isSslPage){
3488                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3489                                         } else {
3490                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3491                                         }
3492                                 } else {
3493                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3494                                 }
3495                         
3496                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3497                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3498                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3499                         }
3500                         
3501                         // ##### ページへJavascriptの埋め込む #####
3502                         // JavaScriptグローバル変数の設定
3503                         $rootUrl = $gEnvManager->getRootUrl();
3504                         if (empty($rootUrl)) $rootUrl = $gEnvManager->calcSystemRootUrl();
3505                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3506                         $replaceStr .= '//<![CDATA[' . M3_NL;
3507                         $replaceStr .= '// Magic3 Global values' . M3_NL;
3508                         if (!empty($rootUrl)) $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;           // システムルートURL
3509                         $replaceStr .= '//]]>' . M3_NL;
3510                         $replaceStr .= '</script>' . M3_NL;
3511                         return $replaceStr;
3512                 }
3513                 
3514                 // テンプレートの情報を取得
3515                 $cleanType = $gEnvManager->getCurrentTemplateCleanType();               // テンプレートクリーンタイプ
3516 /*              if ($this->db->getTemplate($gEnvManager->getCurrentTemplateId(), $templateRow)){
3517                         $cleanType = $templateRow['tm_clean_type'];
3518                 }*/
3519                 
3520                 // URLの作成
3521                 $isSslPage = false;
3522                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3523                         // 管理画面のSSL状態を参照
3524                         if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
3525                 } else {
3526                         $isSslPage = $this->isSslPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
3527                 }
3528                 if ($isSslPage){
3529                         $rootUrl = $gEnvManager->getSslRootUrl();
3530                         $scriptsUrl = $gEnvManager->getSslScriptsUrl();         // スクリプト読み込み用パス
3531                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
3532                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
3533                 } else {
3534                         $rootUrl = $gEnvManager->getRootUrl();
3535                         $scriptsUrl = $gEnvManager->getScriptsUrl();            // スクリプト読み込み用パス
3536                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
3537                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
3538                 }
3539
3540                 // タイトルの設定
3541                 if (!$this->showWidget){// 単体実行以外のとき
3542                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスの場合
3543                                 // 管理画面のタイトル
3544                                 // メイン画面は「サイト名 - 管理画面」、サブ画面は個別画面名
3545                                 $siteName = $gEnvManager->getSiteName();
3546 //                              if (empty($siteName)) $siteName = self::DEFAULT_SITE_NAME;
3547                                 $title = $siteName . ' - ' . self::DEFAULT_ADMIN_TITLE;
3548                                 $titleCount = count($this->headSubTitle);
3549                                 if ($titleCount > 0) $title = $this->headSubTitle[$titleCount -1];              // サブタイトルが設定されている場合は変更
3550                                 $replaceStr .= '<title>' . htmlspecialchars($title) . '</title>' . M3_NL;
3551                                 
3552                                 // その他HTMLヘッダに出力するタグ文字列
3553                                 if (!empty($this->adminHeadOthers)){
3554                                         // マクロを変換
3555                                         $this->adminHeadOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->adminHeadOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
3556                                         $replaceStr .= $this->adminHeadOthers . M3_NL;
3557                                 }
3558                         } else {                        // 管理画面以外の画面へのアクセスの場合
3559                                 // 画面タイトル
3560                                 $titleItemCount = 0;            // タイトル項目数
3561                                 $defaultTitle = trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_TITLE));
3562                                 if (!empty($defaultTitle)) $titleItemCount++;
3563                                 if (!empty($this->headSubTitle)){               // サブタイトルが設定されているとき
3564                                         $titleItemCount += count($this->headSubTitle);
3565                                 }
3566                                 // タイトルフォーマットを取得
3567                                 $title = '';
3568                                 if ($titleItemCount > 0){
3569                                         $format = $this->gSystem->getSystemConfig(self::CONFIG_KEY_HEAD_TITLE_FORMAT);
3570                                         if (empty($format)){
3571                                                 $title = htmlspecialchars($defaultTitle);
3572                                         } else {
3573                                                 $formats = explode(';', $format);
3574                                                 $titleItemCount = ($titleItemCount > count($formats)) ? count($formats) : $titleItemCount;
3575                                                 $title = $formats[$titleItemCount -1];
3576                                                 $number = 1;
3577                                                 if (!empty($defaultTitle)){
3578                                                         $title = str_replace('$1', htmlspecialchars($defaultTitle), $title);
3579                                                         $number++;
3580                                                 }
3581                                                 for ($i = 0; $i < count($this->headSubTitle); $i++){
3582                                                         $key = '$' . $number;
3583                                                         $value = htmlspecialchars(trim($this->headSubTitle[$i]));
3584                                                         $title = str_replace($key, $value, $title);
3585                                                         $number++;
3586                                                 }
3587                                         }
3588                                 }
3589                                 if (!empty($title)) $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
3590
3591                                 // サイトの説明
3592                                 if (!empty($this->headDescription)) $replaceStr .= '<meta name="description" content="' . htmlspecialchars($this->headDescription) . '" />' . M3_NL;
3593                 
3594                                 // 検索エンジン用キーワード
3595                                 if (!empty($this->headKeywords)) $replaceStr .= '<meta name="keywords" content="' . htmlspecialchars($this->headKeywords) . '" />' . M3_NL;
3596                                 
3597                                 // その他HTMLヘッダに出力するタグ文字列
3598                                 if (!empty($this->headOthers)){
3599                                         // マクロを変換
3600                                         $this->headOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->headOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
3601                                         $replaceStr .= $this->headOthers . M3_NL;
3602                                 }
3603                         }
3604                 }
3605                 
3606                 // ##### PC用URLと携帯用URLのアクセス別に処理 #####
3607                 if ($gEnvManager->getIsMobileSite()){           // 携帯用URLのとき
3608                 } else {                        // PC用URLまたはスマートフォン用URLのとき
3609                         // ##### テンプレート情報に応じた処理 #####
3610                         // テンプレートクリーンが必要な場合はJQueryを追加
3611                         if ($cleanType != 0) $this->addScriptFile($this->selectedJQueryFilename);               // JQueryスクリプト追加
3612                         
3613                         // 検索ロボットへの指示
3614                         $robots = htmlspecialchars(trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_ROBOTS)));
3615                         if (!empty($robots)){
3616                                 $replaceStr .= '<meta name="robots" content="' . $robots . '" />' . M3_NL;
3617                         }
3618                 
3619                         // サイト構築エンジン
3620                         $replaceStr .= '<meta name="generator" content="' . M3_SYSTEM_NAME . ' ver.' . M3_SYSTEM_VERSION . ' - ' . M3_SYSTEM_DESCRIPTION . '" />' . M3_NL;              
3621
3622                         // Faviconの読み込み
3623                         $templateId = $gEnvManager->getCurrentTemplateId();
3624                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3625                                 // テンプレートのFaviconがない場合はシステムのデフォルトのFaviconを使用
3626                                 $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3627                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
3628                                         $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3629                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3630                                 } else {
3631                                         // 管理画面のアイコンを設定
3632                                         $faviconPath = $gEnvManager->getSystemRootPath() . self::DEFAULT_ADMIN_FAVICON_FILE;
3633                                         if (file_exists($faviconPath)){         // ファイルが存在しているとき
3634                                                 $faviconFile = $rootUrl . self::DEFAULT_ADMIN_FAVICON_FILE;
3635                                                 $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3636                                         }
3637                                 }
3638                         } else {
3639                                 $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3640                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
3641                                         $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3642                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3643                                 }
3644                         }
3645                         // ##### 追加ライブラリの読み込み #####
3646                         if ($gEnvManager->getIsSmartphoneSite()){                       // スマートフォン用URLのとき
3647                                 $value = $gSystemManager->getSystemConfig(self::CF_SMARTPHONE_USE_JQUERY_MOBILE);// スマートフォン画面で常にjQuery Mobileを使用
3648                                 if ($value){
3649                                         // ##### jQueryMobileが読み込まれる前に読み込む必要があるスクリプトを設定 #####
3650                                         if (!empty($this->headPreMobileScriptFiles)){           // jQueryMobileファイルの前に出力
3651                                                 for ($l = 0; $l < count($this->headPreMobileScriptFiles); $l++){
3652                                                         $this->addScriptFile($this->headPreMobileScriptFiles[$l]);              // 通常機能用のスクリプト追加
3653                                                 }
3654                                         }
3655                                         $this->addScriptFile($this->selectedJQueryMobileFilename);
3656                                 }
3657                         }
3658                         
3659                         // ##### Ajaxライブラリの読み込み #####
3660                         if (!$gEnvManager->isAdminDirAccess()){         // 通常画面へのアクセスのとき
3661                                 if ($this->db->isExistsWidgetWithAjax($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId())){// Ajaxライブラリを使用しているウィジェットがあるときは追加
3662                                         $this->addScriptFile($this->selectedJQueryFilename);            // デフォルトAjaxライブラリ追加
3663                                         $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
3664                                 }
3665                         }
3666                                 
3667                         // ##### 共通ライブラリの読み込み #####
3668                         if (!$this->showWidget){// 単体実行以外のとき
3669                                 $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3670                                 for ($i = 0; $i < count($rows); $i++){
3671                                         $this->addScript($task, trim($rows[$i]['wd_add_script_lib']));
3672                                 }
3673                         }
3674
3675                         // ##### 共通CSS読み込み #####
3676                         if (($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()) || $this->isEditMode){                     // フロント画面編集モード
3677                                 $cssURL = $scriptsUrl . '/' . self::M3_EDIT_CSS_FILE;
3678                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3679                         }
3680                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3681                                 //if ($gEnvManager->isSystemAdmin()){           // 管理者権限がある場合のみ有効
3682                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3683                                         // 管理機能用共通ライブラリのCSSの読み込み
3684                                         $count = count($this->defaultAdminCssFiles);
3685                                         for ($i = 0; $i < $count; $i++){
3686                                                 // CSSへのURLを作成
3687                                                 //$cssURL = $scriptsUrl . '/' . $this->defaultAdminCssFiles[$i];
3688                                                 $cssFilename = $this->defaultAdminCssFiles[$i];
3689                                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3690                                                         $cssURL = $cssFilename;
3691                                                 } else {
3692                                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
3693                                                 }
3694                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3695                                         }
3696                                 } else {
3697                                         // 管理権限なしで管理ディレクトリアクセスで必要なCSSファイルを読み込む
3698                                         $count = count($this->defaultAdminDirCssFiles);
3699                                         for ($i = 0; $i < $count; $i++){
3700                                                 // CSSへのURLを作成
3701                                                 $cssURL = $scriptsUrl . '/' . $this->defaultAdminDirCssFiles[$i];
3702                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3703                                         }
3704                                 }
3705                         } else {
3706                                 // 共通ライブラリのCSSの読み込み
3707                                 $count = count($this->defaultCssFiles);
3708                                 for ($i = 0; $i < $count; $i++){
3709                                         // CSSへのURLを作成
3710                                         $cssFilename = $this->defaultCssFiles[$i];
3711                                         if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3712                                                 $cssURL = $cssFilename;
3713                                         } else {
3714                                                 $cssURL = $scriptsUrl . '/' . $cssFilename;
3715                                         }
3716                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3717                                 }
3718                         }
3719                         
3720                         // ##### 表示モードによるCSS読み込み #####
3721                         // ウィジェット付きポジション画面は管理画面のアクセスではない
3722                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
3723                                 // ウィジェット操作用CSS
3724                                 $cssURL = $scriptsUrl . self::M3_ADMIN_WIDGET_CSS_FILE;
3725                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3726                         }
3727                         
3728                         // ##### ウィジェットごとのCSS読み込み #####
3729                         // CSSがあるウィジェットを取得
3730                         $this->db->getWidgetsIdWithCss($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3731                         for ($i = 0; $i < count($rows); $i++){
3732                                 $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS;
3733                                 // ディレクトリがあるときはディレクトリ内読み込み
3734                                 if (is_dir($searchPath)){
3735                                         $dir = dir($searchPath);
3736                                         while (($file = $dir->read()) !== false){
3737                                                 $filePath = $searchPath . '/' . $file;
3738                                                 if ($file != '.' && $file != '..' && is_file($filePath)
3739                                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3740                                         
3741                                                         // CSSへのURLを作成
3742                                                         $cssURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS . '/' . $file;
3743                                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3744                                                 }
3745                                         }
3746                                         $dir->close();
3747                                 }
3748                         }
3749                         // ##### 外部出力用CSS読み込み #####
3750                         // ウィジェットからの追加のCSS読み込み
3751                         $count = count($this->headCssFiles);
3752                         for ($i = 0; $i < $count; $i++){
3753                                 $cssUrl = $this->headCssFiles[$i];
3754                                 if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3755                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . convertUrlToHtmlEntity($cssUrl) . '" />' . M3_NL;
3756                         }
3757                         
3758                         // 外部出力用CSSデータがある場合はURLを追加
3759                         if (!empty($this->exportCss)){
3760                                 $cssUrl = $this->createCssCmdUrl($isSslPage, date('YmdHis'));
3761                                 if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3762                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . convertUrlToHtmlEntity($cssUrl) . '" />' . M3_NL;
3763                         }
3764                         
3765                         // ##### RSS配信情報の読み込み #####
3766                         $count = count($this->headRssFiles);
3767                         for ($i = 0; $i < $count; $i++){
3768                                 $rssUrl = $this->headRssFiles[$i]['href'];// リンク先URL
3769                                 $rssTitle = $this->headRssFiles[$i]['title'];// タイトル
3770                                 $replaceStr .=  '<link rel="alternate" type="application/rss+xml" title="' . $rssTitle . '" href="' . convertUrlToHtmlEntity($rssUrl) . '" />' . M3_NL;
3771                         }
3772                                                                         
3773                         // ##### 共通Javascriptの読み込み #####
3774                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3775                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3776                                         // 管理画面用の共通スクリプトを読み込む
3777                                         $count = count($this->defaultAdminScriptFiles);
3778                                         for ($i = 0; $i < $count; $i++){
3779                                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
3780
3781                                                 // スクリプトのURLを修正
3782                                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3783                                                         $scriptURL = $scriptFilename;
3784                                                         
3785                                                         // SSLをページの状態に合わせる
3786                                                         if ($isSslPage){
3787                                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3788                                                         } else {
3789                                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3790                                                         }
3791                                                 } else {
3792                                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3793                                                 }
3794                                         
3795                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3796                                                 //$scriptURL = $scriptsUrl . '/' . $scriptFilename;
3797                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3798                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3799                                         }
3800                                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示のときは、ウィジェット操作ライブラリを読み込む
3801                                                 // wigetのドラッグドロップ用
3802                                                 $scriptURL = $scriptsUrl . '/' . self::M3_ADMIN_WIDGET_SCRIPT_FILENAME;
3803                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();// スクリプトをキャッシュ保存しない場合は、パラメータを付加
3804                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3805                                         }
3806                                 } else {                // システム運用権限がない場合
3807                                         // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
3808                                         $count = count($this->defaultAdminDirScriptFiles);
3809                                         for ($i = 0; $i < $count; $i++){
3810                                                 $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
3811
3812                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3813                                                 $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3814                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3815                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3816                                         }
3817                                 }
3818                         } else {                        // 通常画面
3819                                 // Googleマップライブラリの読み込み
3820                                 if ($this->useGooglemaps && $this->isContentGooglemaps) $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));  // コンテンツにGoogleマップが含むかどうか
3821
3822                                 $useExternalJquery = $gSystemManager->getSystemConfig(self::CF_EXTERNAL_JQUERY);                // システム外部のjQueryを使用するかどうか
3823                                 
3824                                 $count = count($this->defaultScriptFiles);
3825                                 for ($i = 0; $i < $count; $i++){
3826                                         $defaultScriptFile = $this->defaultScriptFiles[$i];
3827
3828                                         // 外部のjQueryを使用する場合はSCRIPTタグを出力しない
3829                                         if ($defaultScriptFile == $this->selectedJQueryFilename && $useExternalJquery) continue;
3830                                         
3831                                         // ##### jQueryMobileスクリプトを追加する場合は直前に初期化スクリプトを追加 #####
3832                                         if ($defaultScriptFile == $this->selectedJQueryMobileFilename){
3833                                                 if (count($this->headPreMobileScript) > 0){
3834                                                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3835                                                         $replaceStr .= '//<![CDATA[' . M3_NL;
3836                                                         for ($j = 0; $j < count($this->headPreMobileScript); $j++){
3837                                                                 $replaceStr .= $this->headPreMobileScript[$j];
3838                                                         }
3839                                                         $replaceStr .= M3_NL;
3840                                                         $replaceStr .= '//]]>' . M3_NL;
3841                                                         $replaceStr .= '</script>' . M3_NL;
3842                                                 }
3843                                         }
3844                                         
3845                                         // スクリプトのURLを修正
3846                                         if (strncasecmp($defaultScriptFile, 'http://', 7) == 0 || strncasecmp($defaultScriptFile, 'https://', 8) == 0){
3847                                                 $scriptURL = $defaultScriptFile;
3848                                                 
3849                                                 // SSLをページの状態に合わせる
3850                                                 if ($isSslPage){
3851                                                         $scriptURL = str_replace('http://', 'https://', $scriptURL);
3852                                                 } else {
3853                                                         $scriptURL = str_replace('https://', 'http://', $scriptURL);
3854                                                 }
3855                                         } else {
3856                                                 $scriptURL = $scriptsUrl . '/' . $defaultScriptFile;
3857                                         }
3858
3859                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3860                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3861                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3862                                 }
3863                                 
3864                                 if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW){                           // ログイン、ログアウト場合
3865                                         // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
3866                                         $count = count($this->defaultAdminDirScriptFiles);
3867                                         for ($i = 0; $i < $count; $i++){
3868                                                 $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
3869                                                 if (!in_array($scriptFilename, $this->defaultScriptFiles)){             // 既に追加されていない場合のみ追加
3870                                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3871                                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3872                                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3873                                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3874                                                 }
3875                                         }
3876                                 }
3877                                 
3878                                 // ***** [WordPressテンプレート] jQueryの読み込み後、ヘッダ部に出力するテンプレート用のJavascriptがあれば読み込む *****
3879                                 $headData = $this->gEnv->getWpHeadScriptsData();
3880                                 if (!empty($headData)) $replaceStr .= $headData;
3881                         }
3882                         // ##### ウィジェットごとのJavaScript読み込み #####
3883                         // スクリプトがあるウィジェットを取得
3884                         $this->db->getWidgetsIdWithScript($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3885                         for ($i = 0; $i < count($rows); $i++){
3886                                 $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS;
3887                         
3888                                 // ディレクトリがあるときはディレクトリ内読み込み
3889                                 if (is_dir($searchPath)){
3890                                         $dir = dir($searchPath);
3891                                         while (($file = $dir->read()) !== false){
3892                                                 $filePath = $searchPath . '/' . $file;
3893                                                 if ($file != '.' && $file != '..' && is_file($filePath)
3894                                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3895                                                 
3896                                                         // スクリプトへのURLを作成
3897                                                         $scriptURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
3898                                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3899                                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3900                                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3901                                                 }
3902                                         }
3903                                         $dir->close();
3904                                 }
3905                         }
3906                         // ウィジェットからの追加のCSS読み込み
3907                         $count = count($this->headScriptFiles);
3908                         for ($i = 0; $i < $count; $i++){
3909                                 $scriptUrl = $this->headScriptFiles[$i];
3910                                 if ($isSslPage) $scriptUrl = str_replace('http://', 'https://', $scriptUrl);                    // SSL化が必要なときは変換
3911                 
3912                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3913                                 if (!$this->hasScriptCache) $scriptUrl .= $this->getCacheParam();
3914                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptUrl) . '"></script>' . M3_NL;
3915                         }
3916                         
3917                         // 設定値取得
3918                         $openType = $this->gSystem->getSystemConfig(self::CF_CONFIG_WINDOW_OPEN_TYPE);// ウィジェット設定画面のウィンドウ表示タイプ(0=別ウィンドウ、1=タブ)
3919                         
3920                         // ##### ページへJavascriptの埋め込む #####
3921                         // JavaScriptグローバル変数の設定
3922                         //$replaceStr .= '<script type="text/javascript">' . M3_NL;
3923                         //$replaceStr .= '<!--' . M3_NL;
3924                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3925                         $replaceStr .= '//<![CDATA[' . M3_NL;
3926                         $replaceStr .= '// Magic3 Global values' . M3_NL;
3927                         $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;         // システムルートURL
3928
3929                         if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()){            // 管理画面へのアクセス、システム運用権限があり
3930                                 $pageId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);          // ページID
3931                                 $pageSubId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);// ページサブID
3932                                         
3933                                 // 管理画面のオープン設定
3934                                 $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
3935                                 if ($openType != '') $replaceStr .= 'var M3_CONFIG_WINDOW_OPEN_TYPE = ' . $openType . ';' . M3_NL;
3936                                 
3937                                 // ページID、ページサブID
3938                                 $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
3939                                 $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
3940                                 // WYSIWYGエディター
3941                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
3942                                 
3943                                 // ファイルブラウザ
3944                                 $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;           // バージョン
3945                                 $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
3946                                 $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
3947         
3948                                 // Googleマップライブラリの読み込み
3949                                 if ($this->useGooglemaps){
3950                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
3951                                         
3952                                         // CKEditor拡張プラグイン用の定義
3953                                         $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
3954                                         if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
3955                                 } else {
3956                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
3957                                 }
3958
3959                                 // 管理画面の小画面デバイス最適化を行うかどうか
3960                                 if ($gEnvManager->isSmallDeviceAdmin()){
3961                                         $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = true;' . M3_NL;
3962                                 } else {
3963                                         $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = false;' . M3_NL;
3964                                 }
3965                                 
3966                                 // ウィジェット詳細設定画面専用のJavaScriptグローバル変数
3967                                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){
3968                                         // ##### CKEditor用の設定 #####
3969                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
3970                                         
3971                                         // CKEditor用のCSSファイル
3972                                         if (!empty($this->ckeditorCssFiles)){
3973                                                 // 編集エリア用のCSSファイルを追加
3974                                                 $this->ckeditorCssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
3975                                                 //array_unshift($this->ckeditorCssFiles, $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE);
3976                                                 
3977                                                 $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $this->ckeditorCssFiles));
3978                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
3979                                         }
3980                                         // CKEditor用(レイアウト)のCSSファイル
3981                                         $cssFiles = array();
3982                                         $cssFiles[] = $scriptsUrl . '/' . ScriptLibInfo::BOOTSTRAP_ADMIN_CSS;           // BootstrapのCSSを追加
3983                                         $cssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
3984                                         $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $cssFiles));
3985                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_LAYOUT_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
3986                                         
3987                                         // CKEditor用のテンプレートタイプ
3988                                         if (isset($this->ckeditorTemplateType)){
3989                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_TEMPLATE_TYPE = ' . $this->ckeditorTemplateType . ';' . M3_NL;
3990                                         }
3991                                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION){               // ポジション表示
3992                                         $replaceStr .= 'var M3_POSITION_DATA = "' . implode(',', $this->defPositions) . '";' . M3_NL;                   // 管理画面画面の端末タイプ(主にテスト用に使用)
3993                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = 0;' . M3_NL;                 // 管理画面画面の端末タイプ(主にテスト用に使用)
3994                                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // ウィジェット付きポジション表示
3995                                         // その他のポジションデータを取得
3996                                         $positionData = $this->getRestPositionData();
3997                                         
3998                                         // テンプレート上のポジション名
3999                                         if (count($this->viewPosId) > 0){
4000                                                 $posArrayStr = '[';
4001                                                 for ($i = 0; $i < count($this->viewPosId); $i++){
4002                                                         $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
4003                                                         if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
4004                                                 }
4005                                                 $posArrayStr .= ']';
4006                                                 $replaceStr .= 'var M3_POSITIONS = ' . $posArrayStr . ';' . M3_NL;
4007                                         }
4008                                         // 画面定義のリビジョン番号
4009                                         $replaceStr .= 'var M3_REVISION = ' . $this->pageDefRev . ';' . M3_NL;
4010                                         
4011                                         // その他のポジションデータ
4012                                         $replaceStr .= 'var M3_REST_POSITION_DATA = \'' . $positionData . '\';' . M3_NL;
4013                                 } else if (!empty($pageId)){
4014                                         $accessPoint = $this->gEnv->getAllDefaultPageId();
4015                                         for ($i = 0; $i < count($accessPoint); $i++){
4016                                                 if ($pageId == $accessPoint[$i]){
4017                                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $i . ';' . M3_NL;                        // ウィジェット設定画面のウィジェットの端末タイプ
4018                                                         break;
4019                                                 }
4020                                         }
4021                                 } else {                // メインの管理画面の場合
4022                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = 0;' . M3_NL;                 // 管理画面画面の端末タイプ(主にテスト用に使用)
4023                                 }
4024                                                 
4025                                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
4026                                         if (!empty($task)){             // 戻りタスクが設定されているときのみ最大化可能
4027                                                 $replaceStr .= 'function gobackPagedef(){' . M3_NL;
4028                                                 $replaceStr .= '    window.location.href = "' . $gEnvManager->getDefaultAdminUrl() . '?pageid=' . $pageId . '&pagesubid=' . $pageSubId . '&task=' . $task . '";' . M3_NL;
4029                                                 $replaceStr .= '}' . M3_NL;
4030                                                 $replaceStr .= '$(function(){' . M3_NL;
4031                                                 $replaceStr .= '    $(document).keyup(function(e){' . M3_NL;
4032                                                 $replaceStr .= '        if (e.which == 36) gobackPagedef();' . M3_NL;
4033                                                 $replaceStr .= '    });' . M3_NL;
4034                                                 $replaceStr .= '});' . M3_NL;
4035                                         }
4036                                 } else {
4037                                         // ##### 管理用テンプレートを使用している場合の処理 #####
4038                                         // Bootstrap用のスクリプト処理
4039                                         if ($this->useBootstrap){
4040                                                 $replaceStr .= '$(function(){' . M3_NL;
4041                                                 $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
4042                                                 $replaceStr .= '});' . M3_NL;
4043                                         }
4044                                 }
4045                         } else if ($this->isPageEditable){              // フロント画面ページ編集可能モードのとき
4046                                 $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
4047                                 if ($openType != '') $replaceStr .= 'var M3_CONFIG_WINDOW_OPEN_TYPE = ' . $openType . ';' . M3_NL;
4048                                 
4049                                 // ページID、ページサブID
4050                                 $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
4051                                 $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
4052                                 // WYSIWYGエディター
4053                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4054                                 
4055                                 // ファイルブラウザ
4056                                 $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;   // バージョン
4057                                 $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4058                                 $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4059                                 
4060                                 // テンプレートタイプ
4061                                 $templateType = $gEnvManager->getCurrentTemplateType();
4062                                 if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4063                         } else if ($this->isEditMode){                  // フロント画面編集モード(コンテンツ編集可能ユーザ)
4064                                 if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                               // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
4065                                         // WYSIWYGエディター
4066                                         $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4067                                 
4068                                         // ファイルブラウザ
4069                                         $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;   // バージョン
4070                                         $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4071                                         $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4072                                 
4073                                         // Googleマップライブラリの読み込み
4074                                         if ($this->useGooglemaps){
4075                                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
4076                                                 
4077                                                 // CKEditor拡張プラグイン用の定義
4078                                                 $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
4079                                                 if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
4080                                         } else {
4081                                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
4082                                         }
4083                                 
4084                                         // 管理画面の小画面デバイス最適化を行うかどうか
4085                                         if ($gEnvManager->isSmallDeviceAdmin()){
4086                                                 $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = true;' . M3_NL;
4087                                         } else {
4088                                                 $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = false;' . M3_NL;
4089                                         }
4090                                 
4091                                         // ##### CKEditor用の設定 #####
4092                                         // ウィジェット情報取得
4093                                         $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
4094                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
4095                                 
4096                                         // CKEditor用のCSSファイル
4097                                         if (!empty($this->ckeditorCssFiles)){
4098                                                 // 編集エリア用のCSSファイルを追加
4099                                                 $this->ckeditorCssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4100                                                 //array_unshift($this->ckeditorCssFiles, $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE);
4101                                         
4102                                                 $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $this->ckeditorCssFiles));
4103                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4104                                         }
4105                                         // CKEditor用(レイアウト)のCSSファイル
4106                                         $cssFiles = array();
4107                                         $cssFiles[] = $scriptsUrl . '/' . ScriptLibInfo::BOOTSTRAP_ADMIN_CSS;           // BootstrapのCSSを追加
4108                                         $cssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4109                                         $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $cssFiles));
4110                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_LAYOUT_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4111                                         
4112                                         // CKEditor用のテンプレートタイプ
4113                                         if (isset($this->ckeditorTemplateType)){
4114                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_TEMPLATE_TYPE = ' . $this->ckeditorTemplateType . ';' . M3_NL;
4115                                         }
4116                                         
4117                                         // Bootstrap用のスクリプト処理
4118                                         if ($this->useBootstrap){
4119                                                 $replaceStr .= '$(function(){' . M3_NL;
4120                                                 $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
4121                                                 $replaceStr .= '});' . M3_NL;
4122                                         }
4123                                 } else {
4124                                         // プレビュー画面用にテンプレートタイプを出力
4125                                         $templateType = $gEnvManager->getCurrentTemplateType();
4126                                         if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4127                                         
4128                                         // ##### ヘルプシステムの組み込み #####
4129                                         if ($this->useHelp){                    // ヘルプ表示のとき
4130                                                 $replaceStr .= '$(function(){' . M3_NL;
4131                                                 $replaceStr .= '    if (jQuery().tooltip) $(\'[rel=m3help]\').tooltip({ placement: \'top\'});' . M3_NL;
4132                                                 $replaceStr .= '});' . M3_NL;
4133                                         }
4134                                 }
4135                         } else {                        // 権限なしの場合
4136                                 if (!$gEnvManager->isAdminDirAccess()){                 // フロント画面のとき
4137                                         // テンプレートタイプを追加(ファイルローダ等で使用)
4138                                         $templateType = $gEnvManager->getCurrentTemplateType();
4139                                         if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4140                                 }
4141                         }
4142                         
4143                         // ##### パネルメニュー(フロント画面と管理画面の切り替え等)の表示 #####
4144                         // PC用、携帯用、スマートフォン用画面とウィジェット付きポジションの管理画面時に表示
4145                         if (($gEnvManager->isAdminDirAccess() && $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) ||           // 管理画面(ウィジェット付きポジション表示)のとき
4146                                 (!$gEnvManager->isAdminDirAccess() &&                                                   // 一般用画面のとき
4147                                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
4148                                         $cmd != M3_REQUEST_CMD_RSS)){                                                           // RSS配信でない
4149                                 //if ($gEnvManager->isSystemAdmin()){                           // 管理者権限がある場合のみ有効
4150                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限ありの場合
4151                                         // トップメニュー項目作成
4152                                         $menubarTag = '';       // 管理用メニューバー
4153                                         $adminTag = '';         // 管理画面ボタン
4154                                         $editTag = '';          // 編集ボタン
4155                                         $logoutTag = '';                // ログアウトボタン
4156                                         
4157                                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面(ウィジェット付きポジション表示)の場合
4158                                                 // 編集ボタン
4159 /*                                              $titleStr = '編集終了';
4160                                                 $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4161                                                 if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4162                                                 $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
4163                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></li>';
4164                                                 */
4165                                                 $titleStr = '編集終了';
4166                                                 $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4167                                                 if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4168                                                 //$editTag = '<div class="m3editend"><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4169                                                 //$editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" /></a></div>';
4170                                                 $editTag = '<div class="m3editend m3topright"><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4171                                                 $editTag .= '<i class="glyphicon glyphicon-ok-sign"></i></a></div>';
4172                                                 $menubarTag .= $editTag;
4173                                                 
4174                                 //              $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
4175                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window == window.parent){' . M3_NL;// インラインフレームでないときパネルメニューを表示(修正 2016/9/1)
4176                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").prepend(\'' . $menubarTag . '\');' . M3_NL;            // appendでうまく表示できないのでprependで表示
4177                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
4178                                         } else if ($this->isAccessPointWithAdminMenu){          // 通常画面は、管理メニューを使用するアクセスポイントの場合のみ表示
4179                                                 // 管理画面ボタン
4180                                                 $titleStr = '管理画面へ遷移';
4181                                                 $linkUrl = $gEnvManager->getDefaultAdminUrl();
4182                                                 $adminTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4183                                                 $adminTag .= '<img src="' . $rootUrl . self::ADMIN_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4184                                         
4185                                                 // 編集ボタン
4186                                                 $titleStr = '画面を編集';
4187                                                 $linkUrl  = $gEnvManager->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' .M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET;
4188                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_ID . '=' . $gEnvManager->getCurrentPageId();
4189                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
4190                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_BACKUP_URL . '=' . urlencode($gEnvManager->getCurrentRequestUri());                  // URL退避用
4191                                                 $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4192                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_PAGE_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4193                                                 
4194                                                 // ログアウトボタン
4195                                                 $titleStr = 'ログアウト';
4196 //                                              if ($gEnvManager->isAdminDirAccess()){          // 管理画面の場合
4197 //                                                      $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4198 //                                                      if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4199 //                                              } else {
4200                                                         $linkUrl = $gEnvManager->getCurrentRequestUri();
4201 //                                              }
4202                                                 $linkUrl = createUrl($linkUrl, M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_LOGOUT);
4203                                                 $logoutTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4204                                                 $logoutTag .= '<img src="' . $rootUrl . self::LOGOUT_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4205                                         
4206                                                 // ウィジェットツール表示制御ボタン
4207                                                 $widgetToolTag .= '<li><div class="m3widgettoolbutton m3-nav m3-navbar-nav" data-toggle="buttons">';
4208                                                 $widgetToolTag .= '<button type="button" class="m3-navbar-btn btn btn-sm" data-color="success" rel="m3help" data-placement="bottom" data-container="body" title="ウィジェットツール"><span class="title"> ウィジェットツール</span></button>';
4209                                                 $widgetToolTag .= '<input type="checkbox" class="hidden" />';
4210                                                 $widgetToolTag .= '</div></li>';
4211                                                 
4212                                                 //$menubarTag .= '<div id="m3slidepanel">';
4213                                                 $menubarTag .= '<div id="m3slidepanel" class="m3panel_top m3-navbar-default" style="top:-60px; visibility: visible;">';
4214                                                 $menubarTag .= '<div class="m3panelopener m3topleft"><a href="#" rel="m3help" data-placement="bottom" data-container="body" title="メニューバーを表示"><i class="glyphicon glyphicon-align-justify"></i></a></div>';                           
4215                                 //              $menubarTag .= '<div tabindex="0" class="m3panel_wrap">';
4216                                                 $menubarTag .= '<div>';
4217                                                 $menubarTag .= '<ul class="m3-nav m3-navbar-nav">';
4218                                                 if ($gEnvManager->isSystemAdmin()){                             // 管理画面、編集モードは、管理者権限がある場合のみ有効
4219                                                         $menubarTag .= $adminTag;
4220                                                         $menubarTag .= $editTag;
4221                                                 }
4222                                                 $menubarTag .= $logoutTag;
4223                                                 $menubarTag .= $widgetToolTag;
4224                                                 $menubarTag .= '</ul>';
4225                                                 $menubarTag .= '</div>';
4226                                                 $menubarTag .= '</div>';
4227                                         //      $menubarTag .= '</div>';
4228
4229                                         //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
4230                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window == window.parent){' . M3_NL;// インラインフレームでないときパネルメニューを表示(修正 2016/9/1)
4231                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").append(\'' . $menubarTag . '\');' . M3_NL;
4232                                                 //$this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("#m3slidemenubarpanel").m3SlideMenubar();' . M3_NL;
4233                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(".m3panel_top").m3slidepanel({ "position": "top", "type": "push" });' . M3_NL;
4234                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").css("position", "relative");' . M3_NL;
4235                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'm3SetHelp($(\'#m3slidepanel\'));' . M3_NL;
4236                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'm3SetupWidgetTool(\'m3widgettoolbutton\');' . M3_NL;
4237                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
4238                                         }
4239                                 }
4240                         }
4241                         // ##### フロント画面からのウィジェット操作用ツールバー #####
4242                         if (!$gEnvManager->isAdminDirAccess() && 
4243                                 $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
4244                                 $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
4245                                 if ($gEnvManager->isSystemManageUser()){                // 一般用画面で管理者権限がある場合のみ有効
4246                                         // 管理用ツールバー
4247                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').each(function(){' . M3_NL;
4248                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var attrs = m3_splitAttr($(this).attr(\'m3\'));' . M3_NL;
4249                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var widgetId = attrs[\'widgetid\'];' . M3_NL;
4250                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var serialNo = attrs[\'serial\'];' . M3_NL;
4251                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var configId = attrs[\'configid\'];' . M3_NL;
4252                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var useconfig = attrs[\'useconfig\'];' . M3_NL;
4253                                         
4254                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'\';' . M3_NL;
4255                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (useconfig == 1){' . M3_NL;
4256                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
4257                                                                                 'html += \'<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\\\'\' + widgetId + \'\\\', \' + configId + \', \' + serialNo + \');return false;" rel="m3help" data-container="body" title="ウィジェット設定">' .
4258                                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON32_FILE . '" alt="ウィジェット設定" width="32" height="32" /></a>\';' . M3_NL;
4259                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4260                                         if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
4261                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 
4262                                                                                         'html += \'<a href="javascript:void(0);" onclick="m3ShowAdjustWindow(\' + configId + \', \' + serialNo + \', M3_PAGE_ID, M3_PAGE_SUB_ID);return false;" rel="m3help" data-container="body" title="タイトル・スタイル調整">' .
4263                                                                                         '<img src="' . $rootUrl . self::ADJUST_ICON32_FILE . '" alt="タイトル・スタイル調整" width="32" height="32" /></a>\';' . M3_NL;
4264                                         }
4265                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (html != \'\'){' . M3_NL;
4266                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
4267                                                                                         'html = \'<div class="m3tooltip" style="display:none;">\' + html + \'<a class="m3closebox" href="javascript:void(0);" rel="m3help" data-container="body" title="閉じる">' . 
4268                                                                                         '<img src="' . $rootUrl . self::CLOSE_BOX_ICON32_FILE . '" alt="閉じる" width="11" height="11" /></a></div>\';' . M3_NL;
4269                                                                                         
4270                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).append(html);' . M3_NL;
4271                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4272                                         // クリックイベントの設定
4273                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).click(function(){' . M3_NL;
4274                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4275                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (tooltipObj.css(\'display\') == \'none\'){' . M3_NL;
4276                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (_m3ShowWidgetTool){' . M3_NL;
4277                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'tooltipObj.show();' . M3_NL;
4278                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
4279                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
4280                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.hide();' . M3_NL;
4281                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4282                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4283                                         // ウィジェットボーダーハイライト、ツールチップ表示
4284                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).hover(function(){' . M3_NL;
4285                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (_m3ShowWidgetTool){' . M3_NL;
4286                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(this).addClass(\'m3_widget_highlight\');' . M3_NL;
4287                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4288                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var pos = $(this).position();' . M3_NL;
4289                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var width = $(this).outerWidth();' . M3_NL;
4290                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var tooltipWidth = tooltipObj.outerWidth(true);' . M3_NL;
4291                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var x = pos.left + width - tooltipWidth;' . M3_NL;
4292                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var y = pos.top;' . M3_NL;
4293                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.css({position: "absolute",top: y + "px", left: x + "px"}).show();' . M3_NL;
4294                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4295                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}, function(){' . M3_NL;
4296                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).removeClass(\'m3_widget_highlight\');' . M3_NL;
4297                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4298                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'tooltipObj.hide();' . M3_NL;
4299                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4300                                         // 閉じるボタン処理
4301                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3closebox\').click(function(event){' . M3_NL;
4302                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).children(\'.m3tooltip\').hide();' . M3_NL;
4303                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4304                                         // コンテンツ編集ボタンの位置修正
4305                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
4306                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var offset = $(this).offset();' . M3_NL;
4307                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).outerWidth();' . M3_NL;
4308                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3edittool\').each(function(){' . M3_NL;
4309                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).offset({left: offset.left});' . M3_NL;
4310                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).width(width);' . M3_NL;
4311                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4312                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4313                                         
4314                                         // コンテキストメニューを作成
4315                                         $this->initScript .= M3_INDENT_SPACE . 'var widgetWindow = \'<div class="m3_contextmenu" id="m3_widgetmenu" style="visibility:hidden;">\';' . M3_NL;
4316                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'<ul>\';' . M3_NL;
4317                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'<li id="m3_wconfig"><img src="\' + M3_ROOT_URL + \'/images/system/config.png" />&nbsp;<span>ウィジェットの設定</span></li>\';' . M3_NL;
4318                                         if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
4319                                                 $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'<li id="m3_wadjust"><img src="\' + M3_ROOT_URL + \'/images/system/adjust_widget.png" />&nbsp;<span>タイトル・スタイル調整</span></li>\';' . M3_NL;
4320                                         }
4321                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</ul>\';' . M3_NL;
4322                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</div>\';' . M3_NL;
4323                                         $this->initScript .= M3_INDENT_SPACE . '$("body").append(widgetWindow);' . M3_NL;
4324                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').contextMenu(\'m3_widgetmenu\', {' . M3_NL;
4325                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'menuStyle: {' . M3_NL;
4326                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// border : "2px solid green",' . M3_NL;
4327                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'backgroundColor: \'#FFFFFF\',' . M3_NL;
4328                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'width: "150px",' . M3_NL;
4329                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'textAlign: \'left\',' . M3_NL;
4330                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'font: \'12px/1.5 Arial, sans-serif\'' . M3_NL;
4331                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4332                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'itemStyle: {' . M3_NL;
4333                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'padding: \'3px 3px\'' . M3_NL;
4334                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4335                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'bindings: {' . M3_NL;
4336                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wconfig\': function(t){' . M3_NL;
4337                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
4338                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
4339                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'alert("このウィジェットには設定画面がありません");' . M3_NL;
4340                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'return;' . M3_NL;
4341                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
4342                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowConfigWindow(attrs[\'widgetid\'], attrs[\'configid\'], attrs[\'serial\']);' . M3_NL;
4343                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '},' . M3_NL;
4344                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wadjust\': function(t){' . M3_NL;
4345                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
4346                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowAdjustWindow(attrs[\'configid\'], attrs[\'serial\'], M3_PAGE_ID, M3_PAGE_SUB_ID);' . M3_NL;
4347                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4348                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4349                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onContextMenu: function(e){' . M3_NL;
4350                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (_m3ShowWidgetTool){' . M3_NL;
4351                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'return true;' . M3_NL;
4352                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
4353                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'return false;' . M3_NL;
4354                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4355                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4356                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onShowMenu: function(e, menu){' . M3_NL;
4357                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// メニュー項目の変更' . M3_NL;
4358                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var attrs = m3_splitAttr($(e.target).parents(\'dl\').attr(\'m3\'));' . M3_NL;
4359                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
4360                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(\'#m3_wconfig\', menu).remove();' . M3_NL;
4361                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4362                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'return menu;' . M3_NL;
4363                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4364                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4365                                         
4366                                         // コンテンツの「非公開」表示
4367                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3content_private\').each(function(){' . M3_NL;
4368 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
4369 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var top = pos.top;' . M3_NL;
4370 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var left = pos.left;' . M3_NL;
4371 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).css(\'width\');' . M3_NL;
4372 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var height = $(this).css(\'height\');' . M3_NL;
4373                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'<div class="m3content_overlay"><div><h2>非公開</h2></div></div>\';' . M3_NL;
4374                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).prepend(html);' . M3_NL;
4375                                 //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var overlayObj = $(this).children(\'.m3content_overlay div\');' . M3_NL;
4376                                 //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'overlayObj.css({ position:"absolute", top:top + "px", left:left + "px" }).show();' . M3_NL;
4377                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4378                                 }
4379                         }
4380                         // ##### フロント画面のデフォルトのJavaスクリプト #####
4381 //                      if (!$gEnvManager->isAdminDirAccess()){
4382 //                              $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (jQuery().tooltip) $(\'[rel=tooltip]\').tooltip();' . M3_NL;          // 標準ツールチップ作成
4383 //                      }
4384                         // ポップアップメッセージがある場合は表示
4385                         if (!empty($this->popupMsg)){
4386                                 $replaceStr .=  'alert("' . $this->popupMsg . '");' . M3_NL;
4387                         }
4388                         // テンプレートに応じた処理
4389                         if ($cleanType == 1){
4390                                 // HTMLのクリーン処理が必要なときはコードを埋め込む
4391                                 $this->initScript .= '    $(\'.PostHeaderIcons\').remove();' . M3_NL;// 不要なアイコン表示タグの削除
4392                                 $this->initScript .= '    $(\'.PostMetadataHeader\').each(function(i){' . M3_NL;
4393                                 $this->initScript .= '        if ($(this).text().trim() == \'\') $(this).remove();' . M3_NL;
4394                                 $this->initScript .= '    });' . M3_NL;
4395                         }
4396                         
4397                         // 管理画面用スクリプト追加
4398                         $replaceStr .= $this->getLastContents();
4399                         
4400                         // 初期処理用スクリプト埋め込み
4401                         if (!empty($this->initScript)){
4402                                 $replaceStr .= '$(function(){' . M3_NL;
4403                                 $replaceStr .= $this->initScript;
4404                                 $replaceStr .= '});' . M3_NL;
4405                         }
4406                         
4407                         //$replaceStr .= '// -->' . M3_NL;
4408                         //$replaceStr .= '</script>' . M3_NL;
4409                         $replaceStr .= '//]]>' . M3_NL;
4410                         $replaceStr .= '</script>' . M3_NL;
4411
4412                         // HEADタグに埋め込むCSS,JavaScript,任意文字列
4413                         if (count($this->headCss) > 0){
4414                                 // CSSの場合は全体をstyleタグで囲む
4415                                 $replaceStr .= '<style type="text/css">' . M3_NL;
4416                                 $replaceStr .= '<!--' . M3_NL;
4417                                 for ($i = 0; $i < count($this->headCss); $i++){
4418                                         $replaceStr .= $this->headCss[$i];
4419                                 }
4420                                 $replaceStr .= M3_NL . '//-->' . M3_NL;
4421                                 $replaceStr .= '</style>' . M3_NL;
4422                         }
4423                         if (count($this->headScript) > 0){
4424                                 // JavaScriptの場合は全体をscriptタグで囲む
4425                                 //$replaceStr .= '<script type="text/javascript">' . M3_NL;
4426                                 //$replaceStr .= '<!--' . M3_NL;
4427                                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
4428                                 $replaceStr .= '//<![CDATA[' . M3_NL;
4429                                 for ($i = 0; $i < count($this->headScript); $i++){
4430                                         $replaceStr .= $this->headScript[$i];
4431                                 }
4432                                 //$replaceStr .= M3_NL . '//-->' . M3_NL;
4433                                 //$replaceStr .= '</script>' . M3_NL;
4434                                 $replaceStr .= M3_NL;
4435                                 $replaceStr .= '//]]>' . M3_NL;
4436                                 $replaceStr .= '</script>' . M3_NL;
4437                         }
4438                         if (count($this->headString) > 0){
4439                                 // 任意文字列の場合はそのまま追加
4440                                 for ($i = 0; $i < count($this->headString); $i++){
4441                                         $replaceStr .= $this->headString[$i];
4442                                 }
4443                         }
4444                 }
4445                 return $replaceStr;
4446         }
4447         /**
4448          * 各部品のHTML出力
4449          *
4450          * @param string $position                      HTMLテンプレート上の書き出し位置
4451          * @param string $style                         ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
4452          * @param int    $templateVer           テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
4453          * @param array  $attr                          その他属性
4454          * @return string                                       出力コンテンツ
4455          */
4456         function getContents($position, $style = '', $templateVer = 0, $attr = array())
4457         {
4458                 static $render;         // HTML生成オブジェクト
4459                 global $gRequestManager;
4460                 global $gEnvManager;
4461                 
4462                 // ファイル名、ページ名を取得
4463                 $filename       = $gEnvManager->getCurrentPageId();
4464                 $subId          = $gEnvManager->getCurrentPageSubId();
4465                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
4466
4467                 // ポジション名表示モードに応じて出力を作成
4468                 $contents = '';         // 出力コンテンツ
4469                 switch ($this->showPositionMode){
4470                         case 0:         // 通常画面
4471                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
4472                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
4473                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
4474                                         if ($ret){      // 1行以上データが取得できたとき
4475                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
4476                                                 $this->pageDefPosition = $position;
4477                                         } else {
4478                                                 $this->pageDefRows = array();
4479                                                 $this->pageDefPosition = '';
4480                                         }
4481                                 }
4482                                 // ウィジェットを実行
4483                                 $count = count($this->pageDefRows);
4484                                 
4485                                 if ($templateVer == 0){                 // ########## Joomla!v1.0テンプレートの場合 ##########
4486                                         ob_start();// バッファ作成
4487
4488                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
4489                                         $widgetHeaderType = $this->getTemplateWidgetHeaderType();
4490                                         for ($i = 0; $i < $count; $i++){
4491                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4492                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4493                                                 
4494                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4495                                                 // キャッシュデータがあるときはキャッシュデータを使用
4496                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4497
4498                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4499                                                         ob_clean();
4500                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $titleTag, $widgetHeaderType);
4501                                                         if (!$ret) break;
4502                                                         $widgetContent = ob_get_contents();
4503                                                         
4504                                                         // ウィジェット共通のコンテンツ処理
4505                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4506
4507                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4508                                                 //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4509                                                                                 
4510                                                         // キャッシュデータを設定
4511                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4512                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4513                                                                                                                         
4514                                                         // ウィジェットの外枠タグを設定
4515                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4516                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4517                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4518                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
4519                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4520                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4521                                                                 // ウィジェット表示タイプによる表示制御
4522                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4523                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
4524                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4525                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4526                                                                 if (!empty($controlType)){
4527                                                                         switch ($controlType){
4528                                                                                 case 1:                 // ログイン時のみ表示
4529                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4530                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
4531                                                                                         break;
4532                                                                                 case 2:                 // 非ログイン時のみ表示
4533                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4534                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
4535                                                                                         break;
4536                                                                                 default:
4537                                                                                         break;
4538                                                                         }
4539                                                                 }
4540                                                                 if (!empty($pageState)){
4541                                                                         switch ($pageState){
4542                                                                                 case 1:                 // トップ時のみ表示
4543                                                                                         if (!$this->isPageTopUrl){
4544                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
4545                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
4546                                                                                         }
4547                                                                                         break;
4548                                                                                 default:
4549                                                                                         break;
4550                                                                         }
4551                                                                 }
4552                 
4553                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4554                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4555                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4556                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4557                                                                 $shared = '0';          // 共通属性があるかどうか
4558                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4559                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4560                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4561                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
4562                                                         } else {
4563                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4564                                                                 $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4565                                                         }
4566                                                 } else {                // キャッシュデータがあるとき
4567                                                         $widgetContent = $cacheData;
4568                                                         
4569                                                         // HTMLのメタタグを設定
4570                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4571                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4572                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4573                                                 }
4574                                                 $contents .= $widgetContent;
4575                                                 
4576                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4577                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4578                                                 if (!empty($exportCss)){
4579                                                         // ウィジェットのタグIDを変換
4580                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4581                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4582                                                         $this->addExportCss($exportCss);
4583                                                 }
4584                                         }
4585                                         ob_end_clean();         // バッファ破棄
4586                                         
4587                                         if ($i < $count) return '';// 処理中断のときは終了
4588                                 } else if ($templateVer == 100){                        // ########## WordPressテンプレートの場合 ##########
4589                                         ob_start();// バッファ作成
4590
4591                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
4592                                         //$widgetHeaderType = $this->getTemplateWidgetHeaderType();
4593                                         for ($i = 0; $i < $count; $i++){
4594                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4595                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4596                                                 
4597                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4598                                                 // キャッシュデータがあるときはキャッシュデータを使用
4599                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4600
4601                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4602                                                         // WordPressウィジェット用のパラメータ設定
4603                                                         $gEnvManager->setWpWidgetClass('');                             // ウィジェットクラス名初期化
4604                                                         
4605                                                         ob_clean();
4606                                         //              $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $titleTag, $widgetHeaderType);
4607                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $titleTag, 0/*タイトル出力なし*/);
4608                                                         if (!$ret) break;
4609                                                         $widgetContent = ob_get_contents();
4610
4611                                                         // WordPressウィジェット用のパラメータ設定
4612                                                         $widgetClassName = $gEnvManager->getWpWidgetClass();                            // ウィジェットクラス名
4613                                                         
4614                                                         $trimContent = trim($widgetContent);
4615                                                         if (!empty($trimContent)){              // 出力が空でない場合
4616                                                         
4617                                                                 // オブジェクト作成
4618                                                                 if (!isset($render)) $render = new WPRender();          // WordPress用HTML生成オブジェクト
4619                                                         
4620                                                                 // デフォルトのウィジェットタイトル取得
4621                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
4622                                         
4623                                                                 // Joomla用のパラメータを取得
4624                                                                 //$joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
4625
4626                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
4627                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
4628                                         
4629                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
4630                                                                 $title = $this->pageDefRows[$i]['pd_title'];
4631                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
4632                                                                         if (empty($title)) $title = $defaultTitle;
4633                                                                 } else {
4634                                                                         $title = '';                    // タイトルは非表示
4635                                                                 }
4636                                                         
4637                                                                 // WordPress用パラメータ作成
4638                                                                 $params = array();                              // ウィジェットごとの属性
4639                                                                 if (!empty($widgetClassName))  $params['moduleclass'] = $widgetClassName;       // ウィジェットクラス名
4640                                                                                 
4641                                                                 // ウィジェット生成
4642                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . ($i + 1);                                // ウィジェット識別用ユニークタグ
4643                                                                 
4644                                                                 if (strcmp($position, 'main') == 0){// メイン部のとき
4645                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer, $widgetTag);
4646                                                                 } else {
4647                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer, $widgetTag);
4648                                                                 }
4649                                                         
4650                                                                 // ウィジェット共通のコンテンツ処理
4651                                                         //      $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4652
4653                                                                 // ウィジェットの内枠(コンテンツ外枠)を設定
4654                                                         //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4655                                                         }
4656                                                         
4657                                                         // キャッシュデータを設定
4658                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4659                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4660                                                                                                                         
4661                                                         // ウィジェットの外枠タグを設定
4662                                         //              $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4663                                         //              $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4664                                         //              if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4665                                         //              $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
4666                                         //              $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4667                                         
4668                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4669                                                                 // ウィジェット表示タイプによる表示制御
4670                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4671                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
4672                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4673                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4674                                                                 if (!empty($controlType)){
4675                                                                         switch ($controlType){
4676                                                                                 case 1:                 // ログイン時のみ表示
4677                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4678                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
4679                                                                                         break;
4680                                                                                 case 2:                 // 非ログイン時のみ表示
4681                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4682                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
4683                                                                                         break;
4684                                                                                 default:
4685                                                                                         break;
4686                                                                         }
4687                                                                 }
4688                                                                 if (!empty($pageState)){
4689                                                                         switch ($pageState){
4690                                                                                 case 1:                 // トップ時のみ表示
4691                                                                                         if (!$this->isPageTopUrl){
4692                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
4693                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
4694                                                                                         }
4695                                                                                         break;
4696                                                                                 default:
4697                                                                                         break;
4698                                                                         }
4699                                                                 }
4700                                                                 
4701                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4702                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4703                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4704                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4705                                                                 $shared = '0';          // 共通属性があるかどうか
4706                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4707                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4708                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4709                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
4710                                                         } else {
4711                                                 //              $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4712                                                 //              $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4713                                                         }
4714                                                 } else {                // キャッシュデータがあるとき
4715                                                         $widgetContent = $cacheData;
4716                                                         
4717                                                         // HTMLのメタタグを設定
4718                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4719                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4720                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4721                                                 }
4722                                                 $contents .= $widgetContent;
4723                                                 
4724                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4725                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4726                                                 if (!empty($exportCss)){
4727                                                         // ウィジェットのタグIDを変換
4728                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4729                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4730                                                         $this->addExportCss($exportCss);
4731                                                 }
4732                                         }
4733                                         ob_end_clean();         // バッファ破棄
4734                                         
4735                                         if ($i < $count) return '';// 処理中断のときは終了
4736                                 } else {                        // ########## Joomla!v1.5テンプレートの場合 ##########
4737                                         // テンプレート側で指定されたメニューの表示属性を設定
4738                                         $gEnvManager->setMenuAttr($attr);
4739                                         
4740                                         // ポジションタイプ
4741                                         $posType = '';
4742                                         if (!empty($attr['type'])) $posType = $attr['type'];
4743                                         
4744                                         for ($i = 0; $i < $count; $i++){
4745                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4746                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4747                                                                                                                 
4748                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4749                                                 // キャッシュデータがあるときはキャッシュデータを使用
4750                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4751                                                         
4752                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4753                                                         // ウィジェットのタイトルを初期化
4754                                                         $gEnvManager->setCurrentWidgetTitle('');
4755                                                 
4756                                                         // Joomla用のパラメータを初期化
4757                                                         $gEnvManager->setCurrentWidgetJoomlaParam(array());
4758                                                         
4759                                                         // ウィジェットの出力を取得
4760                                                         ob_clean();
4761                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $titleTag, 0/*タイトル出力なし*/);
4762                                                         $widgetContent = ob_get_contents();
4763
4764                                                         $trimContent = trim($widgetContent);
4765                                                         if (!empty($trimContent)){              // 出力が空でない場合
4766                                                                 $isRendered = false;            // Joomla!の描画処理を行ったかどうか
4767                                                                 if (!empty($this->pageDefRows[$i]['pd_use_render'])){                   // Joomla!の描画処理を使用する場合
4768                                                                         // Joomla!ウィジェットの出力に埋め込む
4769                                                                         if (strcasecmp($style, 'none') != 0){
4770                                                                                 // オブジェクト作成
4771                                                                                 if (!isset($render)) $render = new JRender();
4772                                                                 
4773                                                                                 // デフォルトのウィジェットタイトル取得
4774                                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
4775                                                                 
4776                                                                                 // Joomla用のパラメータを取得
4777                                                                                 $joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
4778
4779                                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
4780                                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
4781                                                                 
4782                                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
4783                                                                                 $title = $this->pageDefRows[$i]['pd_title'];
4784                                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
4785                                                                                         if (empty($title)) $title = $defaultTitle;
4786                                                                                 } else {
4787                                                                                         $title = '';                    // タイトルは非表示
4788                                                                                 }
4789                                                                         
4790                                                                                 // Joomla用パラメータ作成
4791                                                                                 $params = array();                              // ウィジェットごとの属性
4792                                                                                 $widgetType = $this->pageDefRows[$i]['wd_type'];                // ウィジェットタイプ
4793                                                                                 
4794                                                                                 // オプションのJoomlaクラス(縦型メニュー(art-vmenu)等)
4795                                                                                 $joomlaClass = $this->pageDefRows[$i]['wd_joomla_class'];               // 「wd_joomla_class」は使っていない?
4796                                                                                 if (!empty($joomlaClass)) $params['moduleclass_sfx'] = $joomlaClass;
4797                                                                                 if (isset($joomlaParam['moduleclass_sfx'])) $params['moduleclass_sfx'] = $joomlaParam['moduleclass_sfx'];// ウィジェットでjoomla用パラメータの設定があるとき
4798                                                                 
4799                                                                                 if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
4800                                                                                         $moduleContent = '';
4801                                                                                         
4802                                                                                         // ウィジェットタイプがメニューのときはナビゲーションメニューを生成
4803                                                                                         if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4804                                                                 
4805                                                                                         // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
4806                                                                                         if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4807                                                                                         $widgetContent = $moduleContent;
4808                                                                                 } else {
4809                                                                                         // ウィジェットタイプに応じた処理を実行
4810                                                                                         if ($widgetType == 'breadcrumb'){               // パンくずリスト
4811                                                                                                 $moduleContent = $render->getBreadcrumbContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4812                                                                                                 
4813                                                                                                 // パンくずリストで作成できないときはデフォルトの出力を取得
4814                                                                                                 if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4815                                                                                                 $widgetContent = $moduleContent;
4816                                                                                         } else {
4817                                                                                                 if (strcmp($position, 'main') == 0){// メイン部のとき
4818                                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4819                                                                                                         // ウィジェットの内枠はレンダーで設定
4820                                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4821                                                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4822                                                                                                 } else {                // その他の位置のとき
4823                                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4824                                                                                                         // ウィジェットの内枠はレンダーで設定
4825                                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4826                                                                                         
4827                                                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4828                                                                                                 }
4829                                                                                         }
4830                                                                                 }
4831 /*                                                                              if (strcmp($position, 'main') == 0){// メイン部のとき
4832                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4833                                                                                         // ウィジェットの内枠はレンダーで設定
4834                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4835                                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4836 //                                                                              } else if (strStartsWith($position, 'user') ||                          // ナビゲーションメニュー位置の場合
4837                                                                                 } else if (strcasecmp($position, 'user3') == 0 ||                               // ナビゲーションメニュー位置の場合
4838                                                                                                 strcasecmp($position, 'position-1') == 0 ||                             // Joomla!v2.5テンプレート対応
4839                                                                                                 strcasecmp($posType, 'hmenu') == 0){            // Joomla!v3テンプレート対応
4840
4841                                                                                         $moduleContent = '';
4842                                                                                         if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
4843                                                                                                 if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4844                                                                         
4845                                                                                                 // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
4846                                                                                                 if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4847                                                                                         } else {
4848                                                                                                 $moduleContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4849                                                                                         }
4850                                                                                         $widgetContent = $moduleContent;
4851                                                                                         
4852                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定。メニュー処理後に付加。
4853                                                                                         // ウィジェットの内枠はレンダーで設定
4854                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4855                                                                                 } else {                // その他の位置のとき
4856                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4857                                                                                         // ウィジェットの内枠はレンダーで設定
4858                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4859                                                                                         
4860                                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4861                                                                                 }*/
4862                                                                                 $isRendered = true;             // Joomla!の描画処理を行ったかどうか
4863                                                                         }
4864                                                                 }
4865                                                                 if (!$isRendered){              // Joomla!の描画処理を行っていない場合
4866                                                                         // ウィジェット共通のコンテンツ処理
4867                                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4868                                                                         
4869                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4870                                                                 //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4871                                                                 }
4872                                                         }
4873                                                         if (!$ret) return '';           // 処理中断のときは終了
4874                                                         
4875                                                         // キャッシュデータを設定
4876                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4877                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4878                                                                                                                         
4879                                                         // ウィジェットの外枠タグを設定
4880                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4881                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4882                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4883                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;  // ポジションブロッククラス
4884                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4885                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4886                                                                 // ウィジェット表示タイプによる表示制御
4887                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4888                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
4889                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4890                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4891                                                                 if (!empty($controlType)){
4892                                                                         switch ($controlType){
4893                                                                                 case 1:                 // ログイン時のみ表示
4894                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4895                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
4896                                                                                         break;
4897                                                                                 case 2:                 // 非ログイン時のみ表示
4898                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4899                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
4900                                                                                         break;
4901                                                                                 default:
4902                                                                                         break;
4903                                                                         }
4904                                                                 }
4905                                                                 if (!empty($pageState)){
4906                                                                         switch ($pageState){
4907                                                                                 case 1:                 // トップ時のみ表示
4908                                                                                         if (!$this->isPageTopUrl){
4909                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
4910                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
4911                                                                                         }
4912                                                                                         break;
4913                                                                                 default:
4914                                                                                         break;
4915                                                                         }
4916                                                                 }
4917                         
4918                                                                 //$editInfo = 'widgetid:' . $this->pageDefRows[$i]['wd_id'];
4919                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4920                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4921                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4922                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4923                                                                 $shared = '0';          // 共通属性があるかどうか
4924                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4925                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4926                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4927                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
4928                                                         } else {
4929                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4930                                                                 $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4931                                                         }
4932                                                 } else {                // キャッシュデータがあるとき
4933                                                         $widgetContent = $cacheData;
4934                                                         
4935                                                         // HTMLのメタタグを設定
4936                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4937                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4938                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4939                                                 }
4940                                                 $contents .= $widgetContent;
4941                                                 
4942                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4943                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4944                                                 if (!empty($exportCss)){
4945                                                         // ウィジェットのタグIDを変換
4946                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4947                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4948                                                         $this->addExportCss($exportCss);
4949                                                 }
4950                                         }
4951                                 }
4952                         
4953                                 if ($position == 'main'){               // メイン部のときは、メッセージを出力
4954                                         /*if (strlen($this->popupMsg) > 0){
4955                                                 echo "\n<script language=\"javascript\">alert('" . addslashes($this->popupMsg) . "');</script>";
4956                                         }*/
4957                                 } else if ($position == 'debug'){               // デバッグ文出力
4958                                 } else {
4959
4960                                 }
4961                                 break;
4962                         case 1:         // ポジション表示
4963                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:3px solid #f00;color:#700;">ポジション名: ';
4964                                 $contents .= '<b>' . $position . '</b>';
4965                                 $contents .= '</div>';
4966                                 
4967                                 // ポジションを保存
4968                                 if (!in_array($position, $this->defPositions)) $this->defPositions[] = $position;       // テンプレート上のポジション
4969                                 break;
4970                         case 2:         // ポジション表示(ウィジェット付き)
4971                                 $rev = '555';                   // データのリビジョン番号
4972                                 // ポジションのHTMLタグIDを作成
4973                                 $num = 0;
4974                                 $posId = '';
4975                                 for ($i = 0; $i < 100; $i++){
4976                                         $posId = $position . '_' . $num;
4977                                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
4978                                         if (!in_array($viewPosId, $this->viewPosId)) break;
4979                                         $num++;
4980                                 }
4981                                 $this->viewPosId[] = $viewPosId;// IDを保存
4982                                 
4983                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
4984                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
4985                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows);
4986                                         if ($ret){      // 1行以上データが取得できたとき
4987                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
4988                                                 $this->pageDefPosition = $position;
4989                                         } else {
4990                                                 $this->pageDefRows = array();
4991                                                 $this->pageDefPosition = '';
4992                                         }
4993                                 }
4994                                 $posHead = '';
4995                                 // ナビゲーション型のポジションの場合はアイコン付加
4996                                 //if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
4997                                 if ($style == self::WIDGET_STYLE_NAVMENU) $posHead = self::POS_HEAD_NAV_MENU;           // 特殊ポジションブロックのアイコン付加
4998                                 $contents .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;             // リビジョン番号を付加
4999                                 $contents .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
5000                                 
5001                                 // ウィジェットイメージを表示
5002                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
5003                                 //$contents .= $this->getWidgetList($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $widgetTagHead, $this->pageDefRows);
5004                                 $contents .= $this->getWidgetList($filename, $subId, $widgetTagHead, $this->pageDefRows);
5005
5006                                 $contents .= '</div>' . M3_NL;
5007                                 break;
5008                         default:
5009                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:1px solid #f00;color:#700;">param error</div>';
5010                                 break;
5011                 }
5012                 // ポジションを保存
5013                 $this->viewPositions[] = $position;
5014
5015                 return $contents;
5016         }
5017         /**
5018          * 各部品のHTML出力(WordPressテンプレート専用)
5019          *
5020          * @param string $position                      HTMLテンプレート上の書き出し位置
5021          * @param bool $showTitle                       タイトルを表示するかどうか
5022          * @return string                                       出力コンテンツ
5023          */
5024         function getWPContents($position, $showTitle = true)
5025         {
5026                 if ($showTitle){
5027                         return $this->getContents($position, self::WIDGET_STYLE_WORDPRESS/*WordPressテンプレート用出力*/, 100/*WordPressテンプレート*/);
5028                 } else {
5029                         return $this->getContents($position, self::WIDGET_STYLE_WORDPRESS_NOTITLE/*WordPressテンプレート(タイトルなし)用出力*/, 100/*WordPressテンプレート*/);
5030                 }
5031         }
5032         /**
5033          * その他のポジションブロックデータを取得
5034          *
5035          * @param string                ポジション作成用タグ
5036          */
5037         function getRestPositionData()
5038         {
5039                 global $gEnvManager;
5040                 
5041                 $restPositionData = '';
5042                 $rev = '888';
5043                 $pageId = $gEnvManager->getCurrentPageId();
5044                 $subId = $gEnvManager->getCurrentPageSubId();
5045                 
5046                 $restPositions = array_values(array_diff($this->defPositions/*全ポジション*/, $this->viewPositions/*表示済みポジション*/));
5047                 $positionCount = count($restPositions);
5048                 for ($i = 0; $i < $positionCount; $i++){
5049                         $posHead = '';          // アイコン付加用
5050                         $position = $restPositions[$i];
5051                         $posId = $position . '_0';
5052                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
5053
5054                         // 画面情報を取得
5055                         $ret = $this->db->getPageDef($pageId, $subId, $position, $rows);
5056                         if ($ret){
5057                                 //$pageDefRows = $rows;                 // ページ定義レコード
5058                                                 
5059                                 $restPositionData .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">';             // リビジョン番号を付加
5060                                 $restPositionData .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>';
5061                         
5062                                 // ウィジェットイメージを表示
5063                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
5064                                 $contents = $this->getWidgetList($pageId, $subId, $widgetTagHead, $rows);
5065                                 $contents = str_replace(M3_NL, '', $contents);
5066                                 $contents = str_replace('\'', '\\\'', $contents);
5067                                 $restPositionData .= $contents;
5068                                 $restPositionData .= '</div>';
5069                                 
5070                                 $this->viewPosId[] = $viewPosId;// IDを保存
5071                         }
5072                 }
5073                 return $restPositionData;
5074         }
5075         /**
5076          * ウィジェット共通のコンテンツ追加処理
5077          *
5078          * @param string $src                           ウィジェット出力
5079          * @param array $pageDefParam           画面定義レコード
5080          * @return string                                       コンテンツを付加したウィジェット出力
5081          */
5082         function _addOptionContent($src, $pageDefParam)
5083         {
5084                 // 前後コンテンツ追加
5085                 $dest = $pageDefParam['pd_top_content'] . $src . $pageDefParam['pd_bottom_content'];
5086                 
5087                 // 「もっと読む」ボタンを追加
5088                 if ($pageDefParam['pd_show_readmore']){
5089                         $title = $pageDefParam['pd_readmore_title'];
5090                         if (empty($title)) $title = self::DEFAULT_READMORE_TITLE;
5091                         $dest .= '<div><a href="' . convertUrlToHtmlEntity($pageDefParam['pd_readmore_url']) . '">' . convertToHtmlEntity($title) . '</a></div>';
5092                 }
5093                 return $dest;
5094         }
5095         /**
5096          * BODYタグに付加するスタイルを取得(管理画面用)
5097          *
5098          * @param string                CSS文字列
5099          */
5100         function getBodyStyle()
5101         {
5102                 // 画面透過モードのときスタイルを追加
5103                 $transCss = '';
5104                 if ($this->isTransparentMode) $transCss = ' style="background-color:transparent;"';
5105                 return $transCss;
5106         }
5107         /**
5108          * 各ポジションのウィジェット数を取得
5109          *
5110          * @param string $position              HTMLテンプレート上の書き出し位置
5111          * @return int                                  ウィジェットの数
5112          */
5113         function getWidgetsCount($position)
5114         {
5115                 global $gRequestManager;
5116                 global $gEnvManager;
5117                 static $widgetCountArray = array();
5118
5119                 // 管理画面へのアクセスでログインされていないときは0を返す
5120                 if ($gEnvManager->isAdminDirAccess() && !$gEnvManager->isSystemManageUser()){           // 管理画面へのアクセスのときでシステム運用権限がない場合
5121                         return 0;
5122                 }
5123                                 
5124                 // 実行コマンドを取得
5125                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
5126                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                                     // 管理画面(ウィジェットなしポジション表示)のとき
5127                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){              // 管理画面(ウィジェット付きポジション表示)のとき
5128                         return 1;               // ウィジェットが設定されていないポジション名を表示するために固定で値を返す
5129                 }
5130                 
5131                 // 単一ポジション以外の設定のときは固定で返す(or等)
5132                 $pos = strpos($position, ' ');
5133                 if ($pos !== false) return 1;
5134                 
5135                 // 既にウィジェット数が取得されている場合は保存値を返す
5136                 $widgetCount = $widgetCountArray[$position];
5137                 if (isset($widgetCount)) return $widgetCount;
5138                 
5139                 // ファイル名、ページ名を取得
5140                 $filename       = $gEnvManager->getCurrentPageId();
5141                 $subId          = $gEnvManager->getCurrentPageSubId();
5142                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
5143
5144                 // 取得しようとするページ定義のポジションが既に取得しているポジションと異なるときはデータを取得
5145                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // 現在取得しているページ定義のポジション
5146                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
5147                         if ($ret){      // 1行以上データが取得できたとき
5148                                 $this->pageDefRows = $rows;                     // ページ定義レコード
5149                                 $this->pageDefPosition = $position;
5150                         } else {
5151                                 $this->pageDefRows = array();
5152                                 $this->pageDefPosition = '';
5153                         }
5154                 }
5155                 // ### ウィジェット数を取得 ###
5156                 // テンプレートのカラム制御を行うためにウィジェット表示条件でウィジェット数を取得
5157                 $widgetCount = 0;
5158                 $rowCount = count($this->pageDefRows);
5159                 for ($i = 0; $i < $rowCount; $i++){
5160         //              $condition = trim($this->pageDefRows[$i]['wd_visible_condition']);
5161                         $condition = trim($this->pageDefRows[$i]['pd_visible_condition']);
5162                         if (empty($condition)){                 // ウィジェット表示条件が設定されていない場合はウィジェットを表示
5163                                 $widgetCount++;
5164                         } else {                        // ウィジェット表示条件が設定されている場合はパラメータをチェック
5165                                 $conds = explode(';', $condition);
5166                                 for ($j = 0; $j < count($conds); $j++){
5167                                         $pos = strpos($conds[$j], '=');
5168                                         if ($pos !== false){            // URLクエリーパラメータ条件がマッチした場合はウィジェットを表示
5169                                                 list($key, $value) = explode('=', trim($conds[$j]));
5170                                                 $key = trim($key);
5171                                                 $value = trim($value);
5172                                                 if (!empty($key) && !empty($value)){
5173                                                         $requestValue = $gRequestManager->trimValueOf($key);
5174                                                         if ($value == $requestValue) $widgetCount++;
5175                                                 }
5176                                         }
5177                                 }
5178                         }
5179                 }
5180 //              $widgetCount = count($this->pageDefRows);
5181                 $widgetCountArray[$position] = $widgetCount;
5182                 return $widgetCount;
5183         }
5184         /**
5185          * ウィジェットのページ定義シリアル番号からウィジェットCSS IDを取得
5186          *
5187          * @param int $defSerial                ページ定義シリアル番号
5188          * @param string $pageId                ページID
5189          * @param string $subpage       ページサブID
5190          * @param string $position              表示位置ID
5191          * @return string                               CSSエレメントID
5192          */
5193         function getWidgetCssId($defSerial, $pageId, $pageSubId, $position)
5194         {
5195                 $elementId = '';
5196                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
5197                 if ($ret){
5198                         $rowCount = count($rows);
5199                         for ($i = 0; $i < $rowCount; $i++){
5200                                 $row = $rows[$i];
5201                                 if ($row['pd_serial'] == $defSerial){
5202                                         $elementId = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
5203                                         break;
5204                                 }
5205                         }
5206                 }
5207                 return $elementId;
5208         }
5209         /**
5210          * ウィジェット情報取得
5211          *
5212          * 画面作成機能でウィジェット情報を取得するためのAjaxインターフェイス
5213          *
5214          * @param RequestManager $request               HTTPリクエスト処理クラス
5215          */
5216         function getWidgetInfoByAjax($request)
5217         {
5218                 global $gEnvManager;
5219                 global $gDesignManager;
5220                 global $gCacheManager;
5221                 
5222                 // アクセスするページIDからPC用、携帯用、スマートフォン用かを判断
5223                 $widgetDeviceType = 0;          // 端末タイプをPC用に初期化
5224                 $pageId         = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
5225                 $pageSubId      = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
5226                 $mobilePageIdPrefix = M3_DIR_NAME_MOBILE . '_';
5227                 $smartphonePageIdPrefix = M3_DIR_NAME_SMARTPHONE . '_';
5228                 if (strncmp($pageId, $mobilePageIdPrefix, strlen($mobilePageIdPrefix)) == 0){
5229                         $widgetDeviceType = 1;          // 携帯用
5230                 } else if (strncmp($pageId, $smartphonePageIdPrefix, strlen($smartphonePageIdPrefix)) == 0){
5231                         $widgetDeviceType = 2;          // スマートフォン用
5232                 }
5233
5234                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
5235                 if ($task == 'list'){
5236                         // ウィジェット一覧を取得
5237                         $ret = $this->db->getAvailableWidgetList($widgetDeviceType, $rows);
5238                         if ($ret){
5239                                 $currentCategoryId = '_none';           // 現在のウィジェットカテゴリー初期化
5240                                 for ($i = 0; $i < count($rows); $i++){
5241                                         $widgetId = $rows[$i]['wd_id'];
5242                                         $desc = $rows[$i]['wd_description'];
5243                                         $widgetTag = self::WIDGET_TYPE_TAG_HEAD . $widgetId;
5244                                         $categoryId = $rows[$i]['wd_category_id'];
5245                                         
5246                                         // カテゴリーの開始タグを追加
5247                                         if ($categoryId != $currentCategoryId){
5248                                                 if ($i > 0){
5249                                                         echo '</dd>' . M3_NL;
5250                                                         echo '</dl>' . M3_NL;
5251                                                 }
5252                                                 echo '<dl class="m3accordion">' . M3_NL;
5253                                                 echo '<dt>' . $rows[$i]['wt_name'] . '</dt>' . M3_NL;
5254                                                 echo '<dd>' . M3_NL;
5255                                                 
5256                                                 // 現在のカテゴリー更新
5257                                                 $currentCategoryId = $categoryId;
5258                                         }
5259                                         
5260                                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
5261                                         if ($gEnvManager->getUseSslAdmin()){
5262                                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
5263                                                 $image = $gEnvManager->getSslUrl($image);
5264                                         }
5265                                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
5266                                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
5267                                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
5268                                         $imageTag .= ' />';
5269                                         
5270                                         // ウィジェット機能マーク
5271                                         $widgetMark = '';
5272                                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メイン型ウィジェット
5273                                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
5274
5275                                         // ウィジェット機能一覧
5276                                         $functionMark = '';
5277                                         if (!empty($rows[$i]['wd_template_type'])){             // 対応テンプレートタイプ
5278                                                 $templateTypeArray = explode(',', $rows[$i]['wd_template_type']);
5279                                                 if (in_array('bootstrap', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_BOOTSTRAP;           // Bootstrap型テンプレート対応
5280                                                 if (in_array('wordpress', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_WORDPRESS;           // WordPress型テンプレート対応
5281                                         }
5282                                         if (!empty($functionMark)) $functionMark = '<hr />' . $functionMark;
5283                         
5284                                         echo '<dl class="m3_widgetlist_item" id="' . $widgetTag . '">' . M3_NL;
5285                                         echo '<dt>' . $widgetMark . $rows[$i]['wd_name'] . '</dt>' . M3_NL;                     // ウィジェット名
5286                                         echo '<dd><table style="width:100%;"><tr style="vertical-align:top;"><td style="width:35px;">' . $imageTag . '</td><td>' . $desc . '</td></tr></table>';
5287                                         echo $functionMark . '</dd>' . M3_NL;
5288                                         echo '</dl>' . M3_NL;
5289                                         
5290                                         // カテゴリーの終了タグを追加
5291                                         if ($i == count($rows) - 1){
5292                                                 echo '</dd>' . M3_NL;
5293                                                 echo '</dl>' . M3_NL;
5294                                         }
5295                                 }
5296                         }
5297                 } else if ($task == 'wget' || $task == 'wdelete' || $task == 'wtoggle' || $task == 'wadd' || $task == 'wmove'){ // ウィジェット再取得、ウィジェット削除,ウィジェット共通属性変更、ウィジェット追加、ウィジェット移動のとき
5298                         $rev    = $request->trimValueOf('rev');                 // リビジョン
5299                         $serial = $request->trimValueOf('serial');
5300                         $position = $request->trimValueOf('pos');
5301                         $widgetsStr = $request->trimValueOf('widgets');
5302                         if (empty($widgetsStr)){
5303                                 $widgets = array();
5304                         } else {
5305                                 $widgets = explode(',', $widgetsStr);
5306                         }
5307                         $shared = $request->trimValueOf('shared');
5308                         $updatepos = explode(',', $request->trimValueOf('updatepos'));
5309                         $index = $request->trimValueOf('index');
5310                         
5311                         // 処理ごとのパラメータ
5312                         if ($task == 'wmove'){
5313                                 $positions = explode(',', $position);
5314                                 if (count($positions) >= 2){
5315                                         $position = $positions[0];
5316                                         $position2 = $positions[1];
5317                                 } else {
5318                                         $position = $positions[0];
5319                                         $position2 = '';
5320                                 }
5321                         }
5322                         // ##### エラーチェック #####
5323                         $isErr = false;
5324                         // リビジョンのエラーチェック
5325                         $rev = '111';                   // データのリビジョン番号
5326
5327                         // 変更前データ取得
5328                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);    // 0レコードでも正常とする
5329                         
5330                         // 変更前のウィジェットのシリアル番号をチェック
5331                         if (count($widgets) == count($rows)){
5332                                 if (!($task == 'wmove' && empty($position2))){                  // 同一ブロック内の移動の場合はチェックなし
5333                                         for ($i = 0; $i < count($rows); $i++){
5334                                                 if ($widgets[$i] != $rows[$i]['pd_serial']){// シリアル番号
5335                                                         $isErr = true;
5336                                                         break;
5337                                                 }
5338                                         }
5339                                 }
5340                         } else {
5341                                 $isErr = true;
5342                         }
5343
5344                         // データの更新
5345                         if (!$isErr){           // エラーなしのとき
5346                                 if ($task == 'wdelete'){
5347                                         $ret = $this->db->deleteWidget($serial);
5348                                 } else if ($task == 'wtoggle'){
5349                                         $newShared = 0;
5350                                         if (empty($shared)) $newShared = 1;
5351                                         $ret = $this->db->toggleSharedWidget($pageId, $pageSubId, $serial, $newShared);
5352                                 } else if ($task == 'wadd'){    // ウィジェットの追加
5353                                         $widget = $request->trimValueOf('widget');
5354                                         
5355                                         // エラーチェック
5356                                         if (empty($widget)) $isErr = true;
5357                                         
5358                                         // ウィジェットを追加
5359                                         if (!$isErr) $this->db->addWidget($pageId, $pageSubId, $position, $widget, $index);
5360                                 } else if ($task == 'wmove'){
5361                                         // ウィジェットを移動
5362                                         if (!$isErr) $this->db->moveWidget($pageId, $pageSubId, $position, $serial, $index);
5363                                 }
5364                         }
5365                         // 再表示データ取得
5366                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);// 0レコードでも正常とする
5367                         
5368                         // 移動のときは、移動元と移動先の再表示データを取得
5369                         if ($task == 'wmove' && !empty($position2)){
5370                                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position2, $rows2);// 0レコードでも正常とする
5371                         }
5372
5373                         // 更新データを作成
5374                         // 更新対象のポジションブロック
5375                         echo '<div>' . M3_NL;
5376                         for ($i = 0; $i < count($updatepos); $i++){
5377                                 // ウィジェットIDヘッダ作成
5378                                 $widgetTagHead = str_replace(self::POSITION_TAG_HEAD, self::WIDGET_TAG_HEAD, $updatepos[$i]);
5379                                         
5380                                 // ポジション名取得
5381                                 $posName = str_replace(self::POSITION_TAG_HEAD, '', substr($updatepos[$i], 0, strlen($updatepos[$i]) - strlen(strrchr($updatepos[$i], "_"))));
5382                                 if ($task == 'wmove' && $posName == $position2){
5383                                         // ウィジェット一覧外枠
5384                                         $posHead = '';
5385                                         if (strcasecmp($position2, 'user3') == 0 || strcasecmp($position2, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
5386                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position2 . ';rev:' . $rev . ';">' . M3_NL;                // リビジョン番号を付加
5387                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position2 . '</h2>' . M3_NL;
5388                                 
5389                                         // ウィジェット一覧出力
5390                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows2);
5391                                 } else {
5392                                         // ウィジェット一覧外枠
5393                                         $posHead = '';
5394                                         if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;                // 特殊ポジションブロックのアイコン付加
5395                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;         // リビジョン番号を付加
5396                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
5397                                 
5398                                         // ウィジェット一覧出力
5399                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows);
5400                                 }
5401                                 // ウィジェット一覧外枠
5402                                 echo '</div>' . M3_NL;
5403                         }
5404                         echo '</div>' . M3_NL;
5405                         
5406                         // キャッシュデータをクリア
5407                         $gCacheManager->clearAllCache();
5408                 }
5409         }
5410         /**
5411          * 画面作成用ウィジェット一覧データ出力
5412          *
5413          * @param string $pageId                        ページID
5414          * @param string $pageSubId                     ページサブID
5415          * @param string $widgetTagHead         HTMLウィジェットID用のヘッダ
5416          * @param array $rows                           ウィジェット一覧データ
5417          * @return string                                       ウィジェット一覧出力
5418          */
5419         function getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows)
5420         {
5421                 global $gEnvManager;
5422                 global $gDesignManager;
5423                 global $gSystemManager;
5424                 
5425                 if ($gEnvManager->getUseSslAdmin()){
5426                         $rootUrl = $gEnvManager->getSslRootUrl();
5427                 } else {
5428                         $rootUrl = $gEnvManager->getRootUrl();
5429                 }
5430
5431                 // ページのコンテンツタイプを取得
5432                 $line = $this->getPageInfo($pageId, $pageSubId);
5433                 if (!empty($line)) $pageContentType = $line['pn_content_type'];
5434                         
5435                 $contents = '';         // ウィジェット一覧出力コンテンツ
5436                 for ($i = 0; $i < count($rows); $i++){
5437                         $widgetId = $rows[$i]['wd_id'];
5438                         $desc = $rows[$i]['wd_description'];
5439                         $widgetIndex = $rows[$i]['pd_index'];           // 表示順
5440                         $configId = $rows[$i]['pd_config_id'];          // 定義ID
5441                         $serial = $rows[$i]['pd_serial'];               // シリアル番号
5442                         $isShared = empty($rows[$i]['pd_sub_id']);                      // グローバル属性が設定されているかどうか
5443                         $widgetTag = $widgetTagHead . '_' . $i;                         // ウィジェット識別用ユニークタグ
5444                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
5445                         if ($gEnvManager->getUseSslAdmin()){
5446                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
5447                                 $image = $gEnvManager->getSslUrl($image);
5448                         }
5449                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
5450                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
5451                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
5452                         $imageTag .= ' />';
5453                         // 定義名
5454                         if (empty($rows[$i]['pd_config_name'])){
5455                                 if ($rows[$i]['wd_use_instance_def'] && $configId == 0){                // インスタンス定義が必要で未定義のとき
5456                                         $configName = '<span style="color:red;">[未設定]</span>';
5457                                 } else {
5458                                         $configName = '';
5459                                 }
5460                         } else {
5461                                 $configName = '[' . $rows[$i]['pd_config_name'] . ']';
5462                         }
5463                         $hasAdmin = '0';                // 管理画面があるかどうか
5464                         $configImg = '';        // 設定アイコンの表示
5465                         
5466                         // ウィジェットの配置位置に問題があるかどうかを表示
5467                         // メインコンテンツとページ属性が一致するかどうかチェック
5468                         $widgetContentType = $rows[$i]['wd_content_type'];
5469                         //if (!empty($widgetContentType) && $widgetContentType != $pageContentType && 
5470                         if (!empty($widgetContentType) && $widgetContentType != $pageContentType && empty($rows[$i]['wd_content_widget_id']) &&                 // 編集用のウィジェットが別にある場合は除く(2015/3/24))
5471                                                 (in_array($widgetContentType, $this->_getAllContentType()) || in_array($widgetContentType, $this->_getAllFeatureType()))){
5472                                 //$title = 'ウィジェット配置注意';
5473                                 $title = 'ページ属性と不一致';
5474                                 $configImg .= '<span rel="m3help" data-container="body" title="' . $title . '"><img src="' . $rootUrl . self::NOTICE_ICON_FILE . '" alt="' . $title . '" /></span>&nbsp;';
5475                         }
5476                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type']) && $isShared){                                 // メイン型ウィジェットがグローバル属性を持つとき
5477                                 $title = 'メイン型ウィジェットはグローバル属性を設定できません';
5478                                 $configImg .= '<span rel="m3help" data-container="body" title="' . $title . '"><img src="' . $rootUrl . self::ALERT_ICON_FILE . '" alt="' . $title . '" /></span>&nbsp;';
5479                         }
5480                         if ($rows[$i]['wd_has_admin']){
5481                                 $hasAdmin = '1';
5482                                 $title = 'ウィジェット設定';
5483                                 $configImg .= '<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\'' . $widgetId . '\', \'' . $configId . '\', \'' . $serial . '\');return false;" rel="m3help" data-container="body" title="' . $title . '">' .
5484                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" alt="' . $title . '"/></a>&nbsp;';
5485                         }
5486                         // 表示順
5487                         $configImg .= '<span rel="m3help" data-container="body" title="表示順">' . $widgetIndex . '</span>';
5488                         
5489                         $shared = '0';          // 共通属性があるかどうか
5490                         $sharedClassName = '';
5491                         //if (empty($rows[$i]['pd_sub_id'])){
5492                         if ($isShared){                                 // グローバル属性ウィジェットのとき
5493                                 $shared = '1';
5494                                 $sharedClassName = 'm3_widget_shared';                  // 共通ウィジェットのクラス
5495                         }
5496                         $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
5497                         
5498                         // ウィジェット機能マーク
5499                         $widgetMark = '';
5500                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メイン型ウィジェット
5501                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
5502                         
5503                         // 操作メニュー
5504                         $dropdownMenuId = $widgetTag . '_dropdown';
5505                         $operationMenu = '<div class="m3widgetdropdown">';
5506 //                      $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#"><i class="glyphicon glyphicon-list-alt"></i> <b class="caret"></b></a>';
5507                         $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#" data-horizontal-offset="4"><b class="caret"></b></a>';
5508                         $operationMenu .= '<div id="' . $dropdownMenuId . '" class="m3dropdown m3dropdown-tip m3dropdown-relative m3dropdown-anchor-right">';
5509                         $operationMenu .= '<ul class="m3dropdown-menu">';
5510                         if ($hasAdmin) $operationMenu .= '<li class="m3_wconfig"><a href="#"><img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" /> <span>ウィジェットの設定</span></a></li>';
5511                         $operationMenu .= '<li class="m3_wadjust"><a href="#"><img src="' . $rootUrl . self::ADJUST_ICON_FILE . '" /> <span>タイトル・スタイル調整</span></a></li>';
5512                         if ($shared){
5513                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>グローバル属性を解除</span></a></li>';
5514                         } else {
5515                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>グローバル属性を設定</span></a></li>';
5516                         }
5517                         $operationMenu .= '<li class="m3_wdelete"><a href="#"><img src="' . $rootUrl . self::DELETE_ICON_FILE . '" /> <span>このウィジェットを削除</span></a></li>';
5518                         $operationMenu .= '</ul>';
5519                         $operationMenu .= '</div>';
5520                         $operationMenu .= '</div>';
5521                         
5522                         $contents .= '<dl class="m3_widget m3_widget_sortable" id="' . $widgetTag . '" ' . $m3Option . ' >' . M3_NL;
5523                         $contents .= '<dt class="m3_widget_with_check_box ' . $sharedClassName . '"><div class="m3widgettitle">' . $widgetMark . $rows[$i]['wd_name'] . '</div>' . $operationMenu . '</dt>' . M3_NL;
5524                         $contents .= '<dd><table style="width:100%;"><tr style="vertical-align:top;"><td style="width:35px;">' . $imageTag . '</td><td>' . $desc . '</td></tr></table><hr />' . M3_NL;
5525                         $contents .= '<table style="width:100%;"><tr><td>' . $configName . '</td><td style="text-align:right;">' . $configImg . '</td></tr></table></dd>' . M3_NL;
5526                         $contents .= '</dl>' . M3_NL;
5527                 }
5528                 return $contents;
5529         }
5530         /**
5531          * ウィジェット出力を処理
5532          *
5533          * @param string $position                      HTMLテンプレート上の書き出し位置
5534          * @param int $index                    行番号
5535          * @param array $fetchedRow             fetch取得した行
5536          * @param string $style                 ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
5537          * @param string $titleTag      タイトル埋め込み用タグ(遅延ウィジェットの場合のみ作成)
5538          * @param int $widgetHeaderType ウィジェットタイトルを出力方法(0=出力なし、1=Joomla!v1.0PC用出力、2=Joomla!v1.0携帯用出力)
5539          * @return bool                                 処理を継続するかどうか(true=続行、false=中断)
5540          */
5541         function pageDefLoop($position, $index, $fetchedRow, $style, &$titleTag, $widgetHeaderType = 0)
5542         {
5543                 global $gEnvManager;
5544                 global $gErrorManager;
5545                 global $gDesignManager;
5546
5547                 // ページ作成中断またはウィジェット処理中断のときは終了
5548                 if ($this->isAbort || $this->isWidgetAbort) return false;
5549
5550                 // ウィジェット実行停止中のときは空で返す
5551                 // 管理者、運営者どのレベルで制限をかける?
5552                 if (!$fetchedRow['wd_active']) return true;
5553                 
5554                 // グローバル属性ありの場合は現在のページが例外ページにないかチェック
5555                 if (empty($fetchedRow['pd_sub_id'])){
5556                         $exceptPageStr = $fetchedRow['pd_except_sub_id'];
5557                         if (!empty($exceptPageStr)){
5558                                 $exceptPageArray = explode(',', $exceptPageStr);
5559                                 if (in_array($gEnvManager->getCurrentPageSubId(), $exceptPageArray)) return true;               // 例外ページの場合は出力しない
5560                         }
5561                 }
5562                 
5563                 // ウィジェット表示タイプによる表示制御。システム管理者以上の場合は常時表示。
5564                 if (!$gEnvManager->isSystemAdmin()){
5565                         if (!empty($fetchedRow['pd_view_control_type'])){
5566                                 switch ($fetchedRow['pd_view_control_type']){
5567                                         case 1:                 // ログイン時のみ表示
5568                                                 if (!$gEnvManager->isCurrentUserLogined()) return true;         // ログインしていなければ終了
5569                                                 break;
5570                                         case 2:                 // 非ログイン時のみ表示
5571                                                 if ($gEnvManager->isCurrentUserLogined()) return true;          // ログインしていれば終了
5572                                                 break;
5573                                         default:
5574                                                 break;
5575                                 }
5576                         }
5577                         if (!empty($fetchedRow['pd_view_page_state'])){
5578                                 switch ($fetchedRow['pd_view_page_state']){
5579                                         case 1:                 // トップ時のみ表示
5580                                                 if (!$this->isPageTopUrl) return true;          // ページトップ(サブページ内のトップ位置)でなければ終了
5581                                                 break;
5582                                         default:
5583                                                 break;
5584                                 }
5585                         }
5586                 }
5587                 
5588                 // パラメータ初期化
5589                 $titleTag = '';
5590                 
5591                 // ウィジェットID取得
5592                 $widgetId = $fetchedRow['wd_id'];               
5593                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
5594
5595                 // その他パラメータ取得
5596                 $configId = $fetchedRow['pd_config_id'];                // ウィジェット定義ID
5597                 if ($configId == 0) $configId = '';
5598                 $prefix = $fetchedRow['wd_suffix'];             // サフィックス文字列
5599                 $title = $fetchedRow['wd_name'];                // デフォルトのウィジェットタイトル
5600                 if (empty($title)) $title = $fetchedRow['wd_id'];
5601                 $widgetHeadTitle = $fetchedRow['pd_title'];             // ウィジェットのヘッドタイトル
5602                 if (empty($widgetHeadTitle)) $widgetHeadTitle = $title;                 // ウィジェットのヘッドタイトルが空の場合はウィジェットタイトルを取得
5603                 $serial = $fetchedRow['pd_serial'];             // シリアル番号
5604                 $cssStyle       = $fetchedRow['pd_style'];              // CSS
5605                 $lateLaunchIndex = $fetchedRow['wd_launch_index'];              // 遅延実行インデックス
5606                 $shared = false;
5607                 if (empty($fetchedRow['pd_sub_id'])) $shared = true;// 共通属性あり
5608                 if ($this->nonSharedWidgetCount == -1) $this->nonSharedWidgetCount = 0;         // 初期化されていない場合は初期化
5609                 if (!$shared) $this->nonSharedWidgetCount++;    // 非共通ウィジェットの数を更新
5610                 
5611                 // ウィジェットが遅延実行に指定されている場合は、ウィジェットのタグのみ埋め込む
5612                 if ($lateLaunchIndex > 0){              // 遅延実行のとき
5613                         // 遅延実行ウィジェットリストに追加
5614                         if (!isset($this->lateLaunchWidgetList[$widgetId])){
5615                                 $this->lateLaunchWidgetList[$widgetId] = (int)$lateLaunchIndex;
5616                         }
5617                         // 実行パラメータ保存
5618                         $maxNo = 0;             // 最大シリアル番号
5619                         $count = count($this->latelaunchWidgetParam);
5620                         for ($i = 0; $i < $count; $i++){
5621                                 list($wId, $maxNo, $tmp1, $tmp2, $tmp3, $tmp4, $tmp5, $tmp6, $tmp7, $tmp8, $tmp9, $tmp10, $tmp11) = $this->latelaunchWidgetParam[$i];
5622                                 if ($wId == $widgetId) $maxNo = $maxNo + 1;
5623                         }
5624                         // Joomla!1.0テンプレートの場合はタイトルを修正
5625                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
5626                                 if (!empty($fetchedRow['pd_title'])) $title = $fetchedRow['pd_title'];
5627                         }
5628                         $this->latelaunchWidgetParam[] = array($widgetId, $maxNo, $configId, $prefix, $serial, $style, $cssStyle, $title, $shared, $exportCss, $position, $index, $fetchedRow);
5629                         
5630                         // 遅延実行用タグを埋め込む
5631                         echo self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;
5632                         
5633                         // タイトル用タグ作成
5634                         $titleTag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
5635                 } else {
5636                         // ウィジェットが存在する場合は実行
5637                         if (!file_exists($widgetIndexFile)) {
5638                                 if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
5639                         } else {
5640                                 // パラメータ初期化
5641                                 $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
5642                                 $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
5643                                 $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
5644                                 $this->lastHeadTitle = '';                      // ヘッダ部titleにセットした文字列
5645                                 $this->lastHeadDescription = '';        // ヘッダ部descriptionにセットした文字列
5646                                 $this->lastHeadKeywords = '';           // ヘッダ部keywordsにセットした文字列
5647                         
5648                                 // 現在のウィジェットのポジション
5649                                 $this->currentWidgetPosition = $position;                       // 現在のウィジェットのポジション
5650                                 $this->currentWidgetIndex = $index;                     // 現在のウィジェットのポジション番号
5651                                         
5652                                 // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
5653                                 $joomlaTitleVisble = false;
5654                                 if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
5655                                         if ($fetchedRow['pd_title_visible']){
5656                                                 if ($widgetHeaderType == 1){            // PC用出力のとき
5657                                                         $joomlaTitle = $fetchedRow['pd_title'];
5658                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
5659                                                         echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
5660                                                         echo '<tr><th>' . $joomlaTitle . '</th></tr>' . M3_NL;
5661                                                         echo '<tr><td>' . M3_NL;
5662                                                         $joomlaTitleVisble = true;
5663                                                 } else if ($widgetHeaderType == 2){             // 携帯用出力のとき
5664                                                         $joomlaTitle = $fetchedRow['pd_title'];
5665                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
5666                                                         echo '<div>' . $joomlaTitle . '</div>' . M3_NL;
5667                                                         $joomlaTitleVisble = true;
5668                                                 }
5669                                         }
5670                                 }
5671                                 // ウィジェットの外枠タグを設定
5672                                 //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
5673                                 // ウィジェット親のCSS定義があるときは、タグを追加
5674                                 if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
5675                                         
5676                                 // ウィジェットの前出力
5677                                 echo $gDesignManager->getAdditionalWidgetOutput(true);
5678                                 
5679                                 // 作業中のウィジェットIDを設定
5680                                 $gEnvManager->setCurrentWidgetId($widgetId);
5681         
5682                                 // ウィジェット定義IDを設定
5683                                 $gEnvManager->setCurrentWidgetConfigId($configId);
5684                         
5685                                 // ページ定義のシリアル番号を設定
5686                                 $gEnvManager->setCurrentPageDefSerial($fetchedRow['pd_serial']);
5687                                 
5688                                 // ページ定義レコードを設定
5689                                 $gEnvManager->setCurrentPageDefRec($fetchedRow);
5690                                 
5691                                 // パラメータを設定
5692                                 $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
5693                         
5694                                 // ウィジェットのヘッドタイトルを設定
5695                                 $gEnvManager->setCurrentWidgetHeadTitle($widgetHeadTitle);
5696
5697                                 // ウィジェットのタイトルを設定
5698                                 $gEnvManager->setCurrentWidgetTitle($title);
5699                                 
5700                                 // ウィジェットのスタイルを設定
5701                                 $gEnvManager->setCurrentWidgetStyle($style);
5702                                 
5703                                 // ウィジェットのグローバル属性状況を設定
5704                                 $gEnvManager->setIsCurrentWidgetShared($shared);
5705                                         
5706                                 // 実行ログを残す
5707                                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
5708                                 
5709                                 // ウィジェットを実行
5710                                 //require_once($widgetIndexFile);
5711                                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5712                                 $msg = 'widget-start(' . $widgetId . ')';
5713                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5714                                 require($widgetIndexFile);
5715                                 $msg = 'widget-end(' . $widgetId . ')';
5716                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5717
5718                                 // 作業中のウィジェットIDを解除
5719                                 $gEnvManager->setCurrentWidgetId('');
5720                         
5721                                 // ウィジェット定義IDを解除
5722                                 $gEnvManager->setCurrentWidgetConfigId('');
5723                                 
5724                                 // ページ定義のシリアル番号を解除
5725                                 $gEnvManager->setCurrentPageDefSerial(0);
5726                         
5727                                 // ページ定義レコードを解除
5728                                 $gEnvManager->setCurrentPageDefRec();
5729                                 
5730                                 // パラメータを解除
5731                                 $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
5732
5733                                 // ウィジェットのスタイルを解除
5734                                 $gEnvManager->setCurrentWidgetStyle('');
5735                                 
5736                                 // ウィジェットのグローバル属性状況を解除
5737                                 $gEnvManager->setIsCurrentWidgetShared(false);
5738                                 
5739                                 // ウィジェットの後出力
5740                                 echo $gDesignManager->getAdditionalWidgetOutput(false);
5741 //                              echo "<!-- ".time()." -->";
5742
5743                                 // ウィジェット親のCSS定義があるときは、タグを追加
5744                                 if (!empty($cssStyle)) echo '</div>' . M3_NL;
5745                                 // ウィジェットの外枠タグを設定
5746                                 //echo '</div>' . M3_NL;
5747                                 
5748                                 // Joomla!1.0テンプレートのときはタイトルを出力
5749                                 if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用出力のとき
5750                                         echo '</td></tr>' . M3_NL;
5751                                         echo '</table>' . M3_NL;
5752                                 }
5753                         }
5754                 }
5755                 return true;            // 処理継続
5756         }
5757         /**
5758          * 定義IDを指定してウィジェットの出力を取得
5759          *
5760          * @param string $widgetId              ウィジェットID
5761          * @param int $configId                 ウィジェット定義ID
5762          * @return string                               ウィジェットの出力
5763          */
5764         function getWidgetOutput($widgetId, $configId = 0)
5765         {
5766                 global $gEnvManager;
5767                 global $gErrorManager;
5768
5769                 // ウィジェットのアクセス権をチェック
5770                 if (!$this->db->canAccessWidget($widgetId)) return '';
5771
5772                 // ウィジェット情報取得
5773                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
5774
5775                 // 端末タイプをチェック
5776                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
5777                 
5778                 // 必要なJavascriptライブラリを追加
5779                 $scritLib = trim($row['wd_add_script_lib']);
5780                 if (!empty($scritLib)) $this->addScript('', $scritLib);
5781                 
5782                 // バッファ作成
5783                 ob_start();
5784
5785                 // ウィジェット実行ファイル取得
5786                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
5787                                         
5788                 // 作業中のウィジェットIDを設定
5789                 $saveWidgetId = $gEnvManager->getCurrentWidgetId();
5790                 $gEnvManager->setCurrentWidgetId($widgetId);
5791
5792                 // ウィジェット定義IDを設定
5793                 $saveConfigId = $gEnvManager->getCurrentWidgetConfigId();
5794                 $gEnvManager->setCurrentWidgetConfigId($configId);
5795         
5796                 // ページ定義のシリアル番号を設定
5797                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
5798                         
5799                 // パラメータを設定
5800                 //$gEnvManager->setCurrentWidgetPrefix($prefix);                // プレフィックス文字列
5801         
5802                 // ウィジェットのタイトルを設定
5803                 //$gEnvManager->setCurrentWidgetTitle($title);
5804                 
5805                 // ウィジェットのグローバル属性状況を設定
5806                 //$gEnvManager->setIsCurrentWidgetShared($shared);
5807                         
5808                 // 実行ログを残す
5809                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
5810                 
5811                 // ウィジェットを実行
5812                 //require_once($widgetIndexFile);
5813                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5814                 $msg = 'widget-start(' . $widgetId . ')';
5815                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5816                 if (file_exists($widgetIndexFile)){
5817                         require($widgetIndexFile);
5818                 } else {
5819                         if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
5820                 }
5821                 $msg = 'widget-end(' . $widgetId . ')';
5822                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5823
5824                 // 作業中のウィジェットIDを戻す
5825                 $gEnvManager->setCurrentWidgetId($saveWidgetId);
5826         
5827                 // ウィジェット定義IDを戻す
5828                 $gEnvManager->setCurrentWidgetConfigId($saveConfigId);
5829                 
5830                 // ページ定義のシリアル番号を解除
5831                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
5832         
5833                 // パラメータを解除
5834                 //$gEnvManager->setCurrentWidgetPrefix('');                             // プレフィックス文字列
5835
5836                 // ウィジェットのグローバル属性状況を解除
5837                 //$gEnvManager->setIsCurrentWidgetShared(false);
5838
5839                 // 現在のバッファ内容を取得し、バッファを破棄
5840                 $output = ob_get_contents();
5841                 ob_end_clean();
5842                                         
5843                 return $output;
5844         }
5845         /**
5846          * インナーウィジェットの操作
5847          *
5848          * @param int $cmdNo                            実行コマンド(0=初期化、1=更新、2=計算、10=コンテンツ取得)
5849          * @param string $id                            ウィジェットID+インナーウィジェットID
5850          * @param string $configId                      インナーウィジェット定義ID
5851          * @param object $paramObj                      インナーウィジェットに渡すパラメータオブジェクト
5852          * @param object $optionParamObj        インナーウィジェットに渡すパラメータオブジェクト(オプション)
5853          * @param object $resultObj                     インナーウィジェットから返る結果オブジェクト
5854          * @param string $content                       出力内容
5855          * @param bool $isAdmin                         管理者機能(adminディレクトリ以下)かどうか
5856          * @return bool                                         true=成功、false=失敗
5857          */
5858         function commandIWidget($cmdNo, $id, $configId, &$paramObj, &$optionParamObj, &$resultObj, &$content, $isAdmin = false)
5859         {
5860                 global $gEnvManager;
5861                 
5862                 // ウィジェットIDとインナーウィジェットIDを取り出す
5863                 list($widgetId, $iWidgetId) = explode(M3_WIDGET_ID_SEPARATOR, $id);
5864
5865                 // インナーウィジェットに渡すパラメータを設定
5866                 switch ($cmdNo){
5867                         case 0:
5868                                 $cmd = self::IWIDTET_CMD_INIT;                  // 初期化
5869                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5870                                 break;
5871                         case 1:
5872                                 $cmd = self::IWIDTET_CMD_UPDATE;                // 更新
5873                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
5874                                 break;
5875                         case 2:
5876                                 $cmd = self::IWIDTET_CMD_CALC;                  // 計算
5877                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5878                                 break;
5879                         case 10:
5880                                 $cmd = self::IWIDTET_CMD_CONTENT;                       // コンテンツ取得
5881                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
5882                                 break;
5883                         default:
5884                                 $cmd = '';
5885                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5886                                 break;
5887                 }
5888
5889                 // インナーウィジェットのエラー出力は呼び出しウィジェット側で受けるため、出力を抑止する
5890                 ob_start();// バッファ作成
5891
5892                 // ウィジェット実行ファイル取得
5893                 if (empty($widgetId)){          // ウィジェットIDが指定されていないときは共通ディレクトリ
5894                 //$gEnvManager->getIWidgetsPath() . '/' . $iWidgetId . '/' . $containerClass . '.php';
5895                 } else {
5896                         if ($isAdmin){
5897                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/' . M3_DIR_NAME_ADMIN . '/index.php';
5898                         } else {
5899                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/index.php';
5900                         }
5901                 }
5902
5903                 // 作業中のインナーウィジェットIDを設定
5904                 $gEnvManager->setCurrentIWidgetId($id);         // インナーウィジェットを設定
5905
5906                 // インナーウィジェット定義IDを設定
5907                 $gEnvManager->setCurrentIWidgetConfigId($configId);
5908                 
5909                 // ウィジェットを実行
5910                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5911                 if (file_exists($widgetIndexFile)){
5912                         require($widgetIndexFile);
5913                 } else {
5914                         echo 'file not found error: ' . $widgetIndexFile;
5915                 }
5916                 
5917                 // 作業中のウィジェットIDを解除
5918                 $gEnvManager->setCurrentIWidgetId('');
5919         
5920                 // インナーウィジェット定義IDを解除
5921                 $gEnvManager->setCurrentIWidgetConfigId('');
5922                 
5923                 // 現在のバッファ内容を取得し、バッファを破棄
5924                 $content = ob_get_contents();
5925                 ob_end_clean();
5926                 
5927                 // 値を再取得
5928                 if ($this->gInstance->getCmdParamManager()->getParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $obj, $option)){
5929                         $paramObj = $obj;
5930                         $optionParamObj = $option;
5931                 }
5932
5933                 // 結果を取得
5934                 if ($this->gInstance->getCmdParamManager()->getResult($id . M3_WIDGET_ID_SEPARATOR . $configId, $resObj)) $resultObj = $resObj;
5935                 return true;
5936         }
5937         /**
5938          * コールバックメソッドを実行し、出力を返す
5939          *
5940          * @param array $callback               実行するコールバック
5941          * @return string                               出力結果
5942          */
5943         function getOutputByCallbackMethod($callback)
5944         {
5945                 ob_start();// バッファ作成
5946                 
5947                 // コールバック関数を実行
5948                 if (is_callable($callback)) call_user_func($callback);
5949                 
5950                 // 現在のバッファ内容を取得し、バッファを破棄
5951                 $content = ob_get_contents();
5952                 ob_end_clean();
5953                 return $content;
5954         }
5955         /**
5956          * ページ作成処理中断を行った場合のレスポンスヘッダ設定
5957          *
5958          * @param int $responseCode             レスポンスコード
5959          * @return                                              なし
5960          */
5961         function setResponse($responseCode)
5962         {
5963                 switch ($responseCode){
5964                         case 403:                       // アクセス禁止のとき
5965                                 header('HTTP/1.1 403 Forbidden');
5966                                 header('Status: 403 Forbidden');
5967                                 break;
5968                         case 404:                       // 存在しないページのとき
5969                                 header("HTTP/1.1 404 Not Found");
5970                                 header("Status: 404 Not Found");
5971                                 break;
5972                         case 500:                       // サーバ内部エラー
5973                                 header('HTTP/1.1 500 Internal Server Error');
5974                                 header('Status: 500 Internal Server Error');
5975                                 break;
5976                         case 503:                       // サイト非公開(システムメンテナンス)
5977                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
5978                                 header('Status: 503 Service Temporarily Unavailable');
5979                                 break;
5980                 }
5981         }
5982         /**
5983          * ファイルダウンロード
5984          *
5985          * @param string $filePath                      ダウンロードするファイルのファイルパス
5986          * @param string $downloadFilename      ダウンロード時のファイル名
5987          * @param bool   $deleteFile            実行後ファイルを削除するかどうか(成功失敗に関係なく)
5988          * @return bool                                         true=成功、false=失敗
5989          */
5990         function downloadFile($filePath, $downloadFilename, $deleteFile=false)
5991         {
5992                 // エラーチェック
5993                 if (!file_exists($filePath)) return false;
5994                 
5995                 // ファイルサイズ取得
5996                 $fileSize = filesize($filePath);
5997                 
5998                 // バッファ内容が残っているときは破棄
5999                 if (ob_get_level() > 0) ob_end_clean();
6000                 
6001                 header('Cache-Control: public');                // IE6+SSHでダウンロードエラーが出る問題を回避
6002                 header('Pragma: public');                               // IE6+SSHでダウンロードエラーが出る問題を回避
6003             header('Content-Disposition: attachment; filename=' . $downloadFilename);
6004                 header('Content-Length: ' . $fileSize);
6005             header('Content-Type: application/octet-stream; name=' . $downloadFilename);
6006             $fp = fopen($filePath, "r");
6007             echo fread($fp, $fileSize);
6008             fclose($fp);
6009                 
6010                 ob_end_flush();
6011                 
6012                 // ファイル削除
6013                 if ($deleteFile) unlink($filePath);
6014                 return true;
6015         }
6016         /**
6017          * システム制御ページを表示するかどうかを返す
6018          *
6019          * @return bool         true=システム制御ページを表示、false=システム制御ページを表示しない
6020          */
6021         function isSystemPage()
6022         {
6023                 return $this->isSystemPage;
6024         }
6025         /**
6026          * 指定URLへリダイレクト
6027          *
6028          * @param string $url                   遷移先URL。未指定の場合は現在のスクリプト。URLでないときは、現在のスクリプトに付加。
6029          * @param bool $noMessage               画面を遷移させたとき、ドコモ携帯端末でダイアログ(サイトが移動しました(301))が出ないようにするオプション
6030          * @param int  $responseCode    レスポンスコード
6031          * @param bool $autoSsl                 リダイレクト先のページの状態に合わせてSSLを制御するかどうか
6032          * @return                                              なし
6033          */
6034         function redirect($url = '', $noMessage = false, $responseCode = 0, $autoSsl = true)
6035         {
6036                 global $gEnvManager;
6037
6038                 // すでにリダイレクトが設定されている場合は終了
6039                 if ($this->isRedirect) return;                          // リダイレクトするかどうか
6040                 
6041                 $toUrl = $url;
6042                 if (empty($toUrl)){
6043                         $toUrl = $gEnvManager->getCurrentScriptUrl();
6044                 } else if (strncmp($toUrl, 'http://', 7) != 0 && strncmp($toUrl, 'https://', 8) != 0){  // URL以外のときはクエリー文字列と判断する
6045                         $toUrl = $gEnvManager->getCurrentScriptUrl() . $toUrl;
6046                 }
6047
6048                 // SSL化が必要な場合はhttpsに変更
6049                 if ($autoSsl){
6050                         $isSslPage = false;
6051                         if ($gEnvManager->isAdminUrlAccess($toUrl)){            // 管理画面へのアクセスのとき
6052                                 // 管理画面のSSL状態を参照
6053                                 if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
6054                         } else {                // フロント画面へのアクセスのとき
6055                                 // ファイル名を取得
6056                                 $paramArray = array();
6057                                 //list($filename, $query) = explode('?', basename($toUrl));
6058                                 list($url, $query) = explode('?', $toUrl);
6059                                 $baseUrl = dirname($url);
6060                                 $filename = basename($url);
6061                                 if (empty($filename)) $filename = M3_FILENAME_INDEX;
6062                                 if (!empty($query)) parse_str($query, $paramArray);             // クエリーの解析
6063                 
6064                                 // ページIDを取得
6065                                 $pageId = basename($filename, '.php');
6066                                 $pageSubId = $paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID];
6067                         
6068                                 // ページのSSL設定状況を取得
6069                                 $isSslPage = $this->isSslPage($pageId, $pageSubId);
6070                         
6071                                 // 階層化ページの場合はURLを修正
6072                                 if ($this->gSystem->hierarchicalPage() && $filename == M3_FILENAME_INDEX){
6073                                         $toUrl = $baseUrl . '/' . $pageSubId . '/';
6074                                         unset($paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID]);
6075                                         
6076                                         $paramStr = $this->_createUrlParamStr($paramArray);
6077                                         if (!empty($paramStr)) $toUrl .= '?' . $paramStr;
6078                                 }
6079                         }
6080                         if ($isSslPage){
6081                                 //$toUrl = str_replace('http://', 'https://', $toUrl);
6082                                 $toUrl = $gEnvManager->getSslUrl($toUrl);               // SSL用URLに変換
6083                         } else {
6084                                 $toUrl = str_replace('https://', 'http://', $toUrl);
6085                         }
6086                 }
6087
6088                 // バッファ内容が残っているときは破棄
6089                 if (ob_get_level() > 0) ob_end_clean();
6090
6091                 if (empty($responseCode)){
6092                         if ($noMessage){
6093                                 header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
6094                         } else {
6095                                 header('HTTP/1.1 301 Moved Permanently');
6096                         }
6097                 } else {                // レスポンスコードが指定されている場合
6098                         switch ($responseCode){
6099                                 case 301:
6100                                         header('HTTP/1.1 301 Moved Permanently');
6101                                         break;
6102                                 case 302:
6103                                         header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
6104                                         break;
6105                                 case 303:
6106                                         header('HTTP/1.1 303 See Other');
6107                                         break;
6108                                 case 500:                       // サーバ内部エラー
6109                                         header('HTTP/1.1 500 Internal Server Error');
6110                                         header('Status: 500 Internal Server Error');
6111                                         break;
6112                                 case 503:                       // サイト非公開(システムメンテナンス)
6113                                         header('HTTP/1.1 503 Service Temporarily Unavailable');
6114                                         header('Status: 503 Service Temporarily Unavailable');
6115                                         break;
6116                                 default:
6117                                         header('HTTP/1.1 ' . (string)$responseCode);
6118                                         break;
6119                         }
6120                 }
6121                 header('Location: ' . $toUrl);
6122                 
6123                 $this->isRedirect = true;                               // リダイレクトするかどうか
6124         }
6125         /**
6126          * リダイレクト処理かどうかを返す
6127          *
6128          * @return bool         true=リダイレクト、false=リダイレクトでない
6129          */
6130         function isRedirect()
6131         {
6132                 return $this->isRedirect;
6133         }
6134         /**
6135          * 指定URLのディレクトリへリダイレクト
6136          *
6137          * @return                                              なし
6138          */
6139         function redirectToDirectory()
6140         {
6141                 global $gEnvManager;
6142
6143                 // ファイル名を削除
6144                 $dirPath = dirname($gEnvManager->getCurrentScriptUrl()) . '/';
6145                 //$this->redirect($dirPath);
6146                 $this->redirect($dirPath, false, 303, false/*SSLは自動制御しない*/);                    // Firefoxでredirect先がキャッシュに残る問題を回避(2012/7/23)
6147         }
6148         /**
6149          * インストール時のリダイレクト処理
6150          *
6151          * @param string $url                   遷移先URL
6152          * @return                                              なし
6153          */
6154         function redirectInInstall($url)
6155         {
6156                 $this->redirect($url, false, 303, false/*SSLは自動制御しない*/);                        // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
6157         }
6158         /**
6159          * インストール用URLへリダイレクト
6160          *
6161          * @return                                              なし
6162          */
6163         function redirectToInstall()
6164         {
6165                 global $gEnvManager;
6166                 
6167                 $sytemRootUrl = $gEnvManager->calcSystemRootUrl();
6168                 //$this->redirect($sytemRootUrl . '/admin/install.php');
6169                 $this->redirect($sytemRootUrl . '/admin/install.php', false, 303, false/*SSLは自動制御しない*/);                        // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
6170         }
6171         /**
6172          * ログイン、ログアウト処理を行った後、リダイレクト
6173          *
6174          * @param RequestManager        $request                HTTPリクエスト処理クラス
6175          * @param bool                          $success                ログインの成否
6176          * @param string                        $redirectUrl    ログイン成功の場合のリダイレクト先
6177          * @return int                                                          0=何も処理しなかった場合、1=ログイン処理、2=ログアウト処理、3=パスワード送信
6178          */
6179         function standardLoginLogoutRedirect($request, &$success, $redirectUrl = '')
6180         {
6181                 global $gEnvManager;
6182                 global $gAccessManager;
6183                 global $gRequestManager;
6184                 
6185                 // ログイン、ログアウト処理、および、コンテナの起動
6186                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
6187                 if ($cmd == M3_REQUEST_CMD_LOGIN){                      // ログインの場合
6188                         $act = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_ACT);
6189                         if ($act == 'sendpwd'){         // パスワード送信の場合
6190                                 $success = $gAccessManager->sendPassword($request);
6191                                 return 3;
6192                         } else {
6193                                 // ユーザ認証
6194                                 $ret = $gAccessManager->userLogin($request);
6195                                 if ($ret){
6196                                         if (empty($redirectUrl)){
6197                                                 // システム運用可能ユーザの場合でリダイレクト先が設定されていない場合はデフォルトの管理画面URLへ遷移
6198                                                 $userInfo = $gEnvManager->getCurrentUserInfo();// ユーザ情報取得
6199                                                 if ($userInfo->userType >= UserInfo::USER_TYPE_MANAGER){
6200                                                         $ret = $this->db->getLoginUserRecordById($userInfo->userId, $userInfoRow);
6201                                                         if ($ret && !empty($userInfoRow['lu_default_admin_url'])){
6202                                                                 $redirectUrl = $gEnvManager->getDefaultAdminUrl() . $userInfoRow['lu_default_admin_url'];
6203                                                         }
6204                                                 }
6205                                         }
6206                                         
6207                                         // リダイレクト処理
6208                                         $this->redirect($redirectUrl);
6209                                         $success = true;                // ログイン成功
6210                                 } else {        // ログイン失敗のとき
6211                                         $success = false;               // ログイン失敗
6212                                 }
6213                                 return 1;
6214                         }
6215                 } else if ($cmd == M3_REQUEST_CMD_LOGOUT){              // ログアウト
6216                         // ログアウト処理
6217                         $gAccessManager->userLogout(true);
6218                         
6219                         // リダイレクト処理
6220                         $this->redirect($redirectUrl);
6221                         return 2;
6222                 } else {
6223                         return 0;
6224                 }
6225         }
6226         /**
6227          * エラー画面を表示
6228          *
6229          * @param int $errStatus                HTTPエラーステータスコード
6230          * @return                                              なし
6231          */
6232         function showError($errStatus)
6233         {
6234                 // レスポンスヘッダ設定
6235                 $this->setResponse($errStatus);
6236                 
6237                 // メッセージ設定
6238                 $msg = 'NOT DEFINED ERROR';
6239                 switch ($errStatus){
6240                         case 403:                       // アクセス禁止のとき
6241                                 $msg = 'Forbidden';
6242                                 break;
6243                         case 404:                       // 存在しないページのとき
6244                                 $msg = 'Not Found';
6245                                 break;
6246                         case 500:                       // サーバ内部エラー
6247                                 $msg = 'Internal Server Error';
6248                                 break;
6249                         case 503:                       // サイト非公開(システムメンテナンス)
6250                                 $msg = 'Service Temporarily Unavailable';
6251                                 break;
6252                 }
6253                 
6254                 echo '<!doctype html>';
6255                 echo '<html>';
6256                 echo '<head>';
6257                 echo '<title>' . $msg . '</title>';
6258                 echo '</head>';
6259                 echo '<body>';
6260                 echo '<h2>' . $msg . '</h2>';
6261                 echo '</body>';
6262                 echo '</html>';
6263         }
6264         /**
6265          * ウィジェットがセットされているページサブIDを取得
6266          *
6267          * @param string $pageId                ページID
6268          * @param string $widgetId              対象ウィジェットID
6269          * @param int $configId                 ウィジェット定義ID
6270          * @return string                               ページサブID
6271          */
6272         function getPageSubIdByWidget($pageId, $widgetId, $configId = 0)
6273         {
6274                 $pageSubId = '';
6275                 
6276                 // 対象のウィジェットのページサブIDを取得
6277                 $ret = $this->db->getSubPageId($widgetId, $pageId, $rows);
6278                 if ($ret){// データが存在する
6279                         for ($i = 0; $i < count($rows); $i++){
6280                                 if (!empty($rows[$i]['pd_sub_id']) && $rows[$i]['pd_config_id'] == $configId){
6281                                         $pageSubId = $rows[$i]['pd_sub_id'];
6282                                         break;
6283                                 }
6284                         }
6285                 }
6286                 return $pageSubId;
6287         }
6288         /**
6289          * その他のGET,POSTパラメータからページサブID取得
6290          *
6291          * @param RequestManager $request               HTTPリクエスト処理クラス
6292          * @param string $redirectUrl                   リダイレクト用URL
6293          * @return string                                               ページサブID
6294          */
6295         function getPageSubIdByParam($request, &$redirectUrl)
6296         {
6297                 global $gEnvManager;
6298                 
6299                 $subId = '';
6300                 $redirectUrl = '';
6301                 $task = $request->trimValueOf('task');
6302                 $option = $request->trimValueOf('option');
6303                 if ($task == 'search' && $option == 'com_search'){              // joomla!の検索結果表示の場合
6304                         $this->contentType = M3_VIEW_TYPE_SEARCH;               // ページのコンテンツタイプ
6305                                 
6306                         $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_SEARCH, $gEnvManager->getCurrentPageId());// ページサブIDを取得
6307                         if (!empty($subId)){
6308                                 // リダイレクト用URLを作成
6309                                 $keyword = $request->trimValueOf('searchword');
6310                                 $redirectUrl = $gEnvManager->createPageUrl();
6311                                 $redirectUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subId;
6312                                 $redirectUrl .= '&' . M3_REQUEST_PARAM_OPERATION_TASK . '=search&' . M3_REQUEST_PARAM_KEYWORD . '=' . urlencode($keyword);
6313                         }
6314                 }
6315                 return $subId;
6316         }
6317         /**
6318          * コンテンツタイプとページIDからページサブID取得
6319          *
6320          * @param string $contentType   コンテンツタイプ
6321          * @param string $pageId                ページID
6322          * @return string                               ページサブID
6323          */
6324         function getPageSubIdByContentType($contentType, $pageId)
6325         {
6326                 $subId = $this->db->getSubPageIdWithContent($contentType, $pageId);// ページサブIDを取得
6327                 return $subId;
6328         }
6329         /**
6330          * 指定のウィジェットがページ上にあるかを取得
6331          *
6332          * @param string $pageId                ページID
6333          * @param string $widgetId              対象ウィジェットID
6334          * @param bool $activePageOnly  公開中のページのウィジェットに制限するかどうか。falseの場合はすべてのページのウィジェットを対象とする。
6335          * @return bool                                 true=ページ上にあり、false=ページ上になし
6336          */
6337         function isWidgetOnPage($pageId, $widgetId, $activePageOnly=true)
6338         {
6339                 $ret = $this->db->isWidgetOnPage($pageId, $widgetId, $activePageOnly, 0/*定義セットID*/);
6340                 return $ret;
6341         }
6342         /**
6343          * URLで示されるページ上のウィジェットをウィジェット種別で取得
6344          *
6345          * @param string $url                   URL
6346          * @param string $widgetType    対象ウィジェットタイプ
6347          * @return string                               ウィジェットID
6348          */
6349         function getWidgetIdByWidgetType($url, $widgetType)
6350         {
6351                 $ret = $this->getPageIdFromUrl($url, $pageId, $pageSubId, $param);
6352                 
6353                 // ウィジェットIDを取得
6354                 if ($ret) $widgetId = $this->db->getWidgetIdByType($pageId, $pageSubId, $widgetType);
6355                 return $widgetId;
6356         }
6357         /**
6358          * ページコンテンツタイプ、コンテンツタイプからウィジェットIDを取得
6359          *
6360          * @param string $pageId                ページID
6361          * @param string $contentType    コンテンツタイプ
6362          * @return string                               ウィジェットID
6363          */
6364         function getWidgetIdWithPageInfoByContentType($pageId, $contentType)
6365         {
6366                 $widgetId = $this->db->getWidgetIdWithPageInfoByContentType($pageId, $contentType);
6367                 return $widgetId;
6368         }
6369         /**
6370          * ジョブタイプからウィジェットIDを取得
6371          *
6372          * @param string $jobType               ジョブタイプ
6373          * @return string                               ウィジェットID
6374          */
6375         function getWidgetIdByJobType($jobType)
6376         {
6377                 global $gEnvManager;
6378                 global $gErrorManager;
6379
6380                 // ジョブ実行用ウィジェット取得
6381                 $widgetId = '';
6382                 $linkInfoObj = $this->gInstance->getObject(self::LINKINFO_OBJ_ID);
6383                 if (isset($linkInfoObj)) $widgetId = $linkInfoObj->getJobWidget($jobType);
6384                 
6385                 // ウィジェットのアクセス権をチェック
6386                 if (!$this->db->canAccessWidget($widgetId)) return '';
6387
6388                 // ウィジェット情報取得
6389                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
6390
6391                 // 端末タイプをチェック
6392                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
6393                 
6394                 return $widgetId;
6395         }
6396         /**
6397          * 現在アクティブなメイン型ウィジェットをウィジェット種別で取得
6398          *
6399          * @param string $widgetType    対象ウィジェットタイプ
6400          * @return string                               ウィジェットID
6401          */
6402         function getActiveMainWidgetIdByWidgetType($widgetType)
6403         {
6404                 // ウィジェットIDを取得
6405                 $widgetId = $this->db->getActiveMainWidgetIdByType($widgetType);
6406                 return $widgetId;
6407         }
6408         /**
6409          * URLを解析して、ページID,サブページIDを取得
6410          *
6411          * @param string $url                   URL
6412          * @param string $pageId                ページID
6413          * @param string $pageSubId             ページサブID
6414          * @param array  $urlParam              URLパラメータ
6415          * @return bool                                 true=成功、false=失敗
6416          */
6417         function getPageIdFromUrl($url, &$pageId, &$pageSubId, &$urlParam)
6418         {
6419                 global $gEnvManager;
6420                         
6421                 // ページID、ページサブIDを求める
6422                 list($page, $other) = explode('?', str_replace($gEnvManager->getRootUrl(), '', $url));
6423                 parse_str($other, $urlParam);
6424                 
6425                 $pageId = str_replace('/', '_', trim($page, '/'));
6426                 $pageId = basename($pageId, '.php');
6427
6428                 // ページサブIDを取得
6429                 $pageSubId = $param[M3_REQUEST_PARAM_PAGE_SUB_ID];
6430                 if (empty($pageSubId)) $pageSubId = $gEnvManager->getDefaultPageSubId();
6431                 return true;
6432         }
6433         /**
6434          * ウィジェットが組み込まれているページのURLを生成
6435          *
6436          * @param string $widgetId      送信元ウィジェットID
6437          * @param string $param         実行パラメータ
6438          * @param string $pageId        ウィジェットが存在するページID
6439          * @return string                       生成したURL
6440          */
6441         function getDefaultPageUrlByWidget($widgetId, $param = '', $pageId = '')
6442         {
6443                 global $gEnvManager;
6444
6445                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6446                 
6447                 // このウィジェットがマップされているページサブIDを取得
6448                 $sub = '';
6449                 $subPageId = $this->getPageSubIdByWidget($pageId, $widgetId);
6450                 if (empty($subPageId)){
6451                         // 見つからないときは互換ウィジェットを探す
6452                         $targetWidgetId = $this->db->getCompatibleWidgetId($widgetId);
6453                         if (!empty($targetWidgetId)){
6454                                 $subPageId = $this->getPageSubIdByWidget($pageId, $targetWidgetId);
6455                         }
6456                 }
6457                 if (!empty($subPageId)) $sub = M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subPageId;
6458                 
6459                 //$url = $gEnvManager->getDefaultUrl();
6460                 $url = $gEnvManager->createPageUrl($pageId);
6461                 if (!empty($sub)) $url .= '?' . $sub;
6462                 if (!empty($param)) $url .= '&' . $param;
6463                 return $url;
6464         }
6465         /**
6466          * 現在のアクセスポイントの指定のページ属性のページURLを生成
6467          *
6468          * @param string $contentType   コンテンツタイプ
6469          * @param string $param                 追加パラメータ
6470          * @param bool $omitPageId              ページID省略形を使用するかどうか
6471          * @return string                               生成したURL
6472          */
6473         function createContentPageUrl($contentType, $param = '', $omitPageId = true)
6474         {
6475                 global $gEnvManager;
6476                 static $urlArray = array();
6477                 
6478                 // 複数回呼ばれるのでコンテンツタイプごとにページまでのURLは保存しておく
6479                 $baseUrl = $urlArray[$contentType];
6480                 if (!isset($baseUrl)){
6481                         // コンテンツタイプからページサブIDを取得
6482                         $pageSubId = $this->getPageSubIdByContentType($contentType, $gEnvManager->getCurrentPageId());          // DBから取得
6483                 
6484                         if (empty($pageSubId)){ // ページサブIDが取得できない場合はデフォルトのページサブIDを取得
6485                                 $pageSubId = $gEnvManager->getDefaultPageSubId();
6486                         } else if ($pageSubId == $gEnvManager->getDefaultPageSubId()){          // デフォルトページの場合
6487                                 if ($omitPageId) $pageSubId = '';       // ページID省略形を使用する場合はページサブIDを省略
6488                         }
6489                         
6490                         // 現在のアクセスポイントのURLを取得
6491                         $baseUrl = $gEnvManager->createPageUrl();
6492                         
6493                         // ページサブIDを付加
6494                         if (!empty($pageSubId)) $baseUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId;
6495                         
6496                         // URLを保存
6497                         $urlArray[$contentType] = $baseUrl;
6498                 }
6499                 
6500                 // 追加パラメータ
6501                 $url = $baseUrl;
6502                 if (!empty($param)){
6503                         if (strEndsWith($url, '.php') || strEndsWith($url, '/')){
6504                                 $url .= '?';
6505                         } else {
6506                                 $url .= '&';
6507                         }
6508                         $url .= $param;
6509                 }
6510                 return $url;
6511         }
6512         /**
6513          * ウィジェット指定呼び出し用のURLを生成
6514          *
6515          * @param string $toWidgetId    送信先ウィジェットID
6516          * @param string $fromWidgetId  送信元ウィジェットID
6517          * @param string $todo                  実行パラメータ
6518          * @param string $pageId                ページID(空のときは現在のURL)
6519          * @return string                               生成したURL
6520          */
6521         function createWidgetCmdUrl($toWidgetId, $fromWidgetId, $todo, $pageId = '')
6522         {
6523                 global $gEnvManager;
6524                 
6525                 $url = $gEnvManager->createPageUrl($pageId);
6526                 
6527                 $url .= '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_FIND_WIDGET;
6528                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $toWidgetId;
6529                 if (!empty($fromWidgetId)) $url .= '&' . M3_REQUEST_PARAM_FROM . '=' . $fromWidgetId;           // 送信元
6530                 if (!empty($todo)) $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=' . urlencode($todo);
6531                 return $url;
6532         }
6533         /**
6534          * RSS配信用のURLを生成
6535          *
6536          * @param string $widgetId              実行ウィジェットID
6537          * @param string $optionParam   追加パラメータ
6538          * @param string $pageId                ページID(空のときは現在のURL)
6539          * @param string $pageSubId             ページサブID
6540          * @return string                               生成したURL
6541          */
6542         function createRssCmdUrl($widgetId, $optionParam = '', $pageId = '', $pageSubId = '')
6543         {
6544                 global $gEnvManager;
6545                 
6546                 // 現在のページURLを取得
6547                 $url = $gEnvManager->createPageUrl() . '?';
6548                 
6549                 // ページサブIDを取得
6550                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // グローバル属性ありのときは空
6551                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6552                 
6553                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_RSS;
6554                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
6555                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6556                 return $url;
6557         }
6558         /**
6559          * CSS生成用のURLを生成
6560          *
6561          * @param bool   $isSslPage             SSLが必要なページかどうか
6562          * @param string $optionParam   追加パラメータ
6563          * @return string                               生成したURL
6564          */
6565         function createCssCmdUrl($isSslPage, $optionParam = '')
6566         {
6567                 global $gEnvManager;
6568                 global $gRequestManager;
6569                 
6570                 // 現在のページURLを取得
6571         //      $url = $gEnvManager->createPageUrl() . '?';
6572                 $url = $gEnvManager->createPageUrl(''/*現在のページ*/, $isSslPage) . '?';
6573                 
6574                 // ページサブIDを取得
6575                 $pageSubId = $this->gEnv->getCurrentPageSubId();
6576                 $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6577                 
6578                 // コンテンツ詳細画面の場合はコンテンツパラメータを追加
6579                 if ($this->isContentDetailPage){
6580                         switch ($this->contentType){
6581                                 case M3_VIEW_TYPE_CONTENT:              // 汎用コンテンツ
6582                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_CONTENT_ID);
6583                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_CONTENT_ID_SHORT);
6584                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentsId . '&';
6585                                         break;
6586                                 case M3_VIEW_TYPE_PRODUCT:      // 製品
6587                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PRODUCT_ID);
6588                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PRODUCT_ID_SHORT);
6589                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_PRODUCT_ID . '=' . $contentsId . '&';
6590                                         break;
6591                                 case M3_VIEW_TYPE_BBS:  // BBS
6592                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BBS_THREAD_ID);
6593                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT);
6594                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $contentsId . '&';
6595                                         break;
6596                                 case M3_VIEW_TYPE_BLOG: // ブログ
6597                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BLOG_ENTRY_ID);
6598                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT);
6599                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $contentsId . '&';
6600                                         break;
6601                                 case M3_VIEW_TYPE_WIKI: // Wiki
6602                                         $contentsId = $gRequestManager->getWikiPageFromQuery();         // 「=」なしのパラメータはwikiパラメータとする
6603                                         if (!empty($contentsId)) $url .= $contentsId . '&';
6604                                         break;
6605                                 case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ
6606                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_ROOM_ID);
6607                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_ROOM_ID_SHORT);
6608                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_ROOM_ID . '=' . $contentsId . '&';
6609                                         break;
6610                                 case M3_VIEW_TYPE_EVENT:        // イベント
6611                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_EVENT_ID);
6612                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_EVENT_ID_SHORT);
6613                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_EVENT_ID . '=' . $contentsId . '&';
6614                                         break;
6615                                 case M3_VIEW_TYPE_PHOTO:        // フォトギャラリー
6616                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID);
6617                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID_SHORT);
6618                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_PHOTO_ID . '=' . $contentsId . '&';
6619                                         break;
6620                         }
6621                 }
6622                 
6623                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_CSS;
6624                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6625                 return $url;
6626         }
6627         /**
6628          * ウィジェット実行用のURLを生成
6629          *
6630          * @param string $widgetId      実行ウィジェットID
6631          * @param string $optionParam   追加パラメータ
6632          * @param bool $byMacro         マクロ変換で返すかどうか
6633          * @param string $pageId                ページID(空のときは現在のURL)
6634          * @param string $pageSubId             ページサブID
6635          * @return string                               生成したURL
6636          */
6637         function createDirectWidgetCmdUrl($widgetId, $optionParam = '', $byMacro = false, $pageId = '', $pageSubId = '')
6638         {
6639                 global $gEnvManager;
6640                 
6641                 // 現在のページURLを取得
6642                 if ($byMacro){
6643                         $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_FILENAME_INDEX . '?';
6644                 } else {
6645                         $url = $gEnvManager->createPageUrl() . '?';
6646                 }
6647                 
6648                 // ページサブIDを取得
6649                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // グローバル属性ありのときは空
6650                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6651                 
6652                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_DO_WIDGET;
6653                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
6654                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6655                 return $url;
6656         }
6657         /**
6658          * URLパラメータの並び順を取得
6659          *
6660          * @return array                                        パラメータ文字列の配列
6661          */
6662         function getUrlParamOrder()
6663         {
6664                 return $this->urlParamOrder;                                    // URLパラメータの並び順
6665         }
6666         /**
6667          * キャッシュ制御用の付加パラメータを取得
6668          *
6669          * @return string                               パラメータ
6670          */     
6671         function getCacheParam()
6672         {
6673                 $addParam = '?' . date('YmdHis');
6674                 return $addParam;
6675         }
6676         /**
6677          * 現在のURLにアクセス可能かチェック
6678          *
6679          * @param bool $isActivePage    ページが有効かどうか
6680          * @param int  $errCode                 エラーコード
6681          * @return bool                                 true=可能、false=不可
6682          */     
6683         function canAccessUrl(&$isActivePage, &$errCode)
6684         {
6685                 global $gEnvManager;
6686
6687                 $errCode = 0;                   // エラーコード初期化
6688                 
6689                 // 現在設定されているページIDを取得
6690                 $pageId         = $gEnvManager->getCurrentPageId();
6691                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
6692                 $ret = $this->db->canAccessPage($pageId, $pageSubId, $pageVisible, $pageSubVisible, $isAdminMenu);
6693                 if ($ret){              // アクセス可能なときは、ユーザ制限もチェックする
6694                         $isActivePage = true;
6695                         
6696                         // ページが表示可能かチェック
6697                         if (!$pageVisible || !$pageSubVisible) return false;
6698
6699                         if (!$gEnvManager->isCurrentUserLogined() && $this->isUserLimitedPage($pageId, $pageSubId)){                    // ユーザがログインされていない状態でユーザ制限されていればアクセス不可
6700                                 return false;
6701                         } else {
6702                                 $this->isAccessPointWithAdminMenu = $isAdminMenu;                               // 管理メニューを使用するアクセスポイントかどうか
6703                                 return true;
6704                         }
6705                 } else {                        // 無効ページのとき
6706                         $isActivePage = false;
6707                         
6708                         // ページIDの文字のチェック。ページIDは半角英小文字、数字、アンダーバー、ハイフンのみ使用可能。
6709                         if (preg_match("/[^0-9a-z-_]/", $pageSubId)) $errCode = 1;                      // 不正文字検出
6710                 }
6711                 return false;
6712         }
6713         /**
6714          * ウィジェットヘッダ(Joomla!1.0用)を出力タイプを取得
6715          *
6716          * @return int                          0=出力しない、1=Joomla!1.0テンプレートPC用、2=Joomla!1.0テンプレート携帯用
6717          */     
6718         function getTemplateWidgetHeaderType()
6719         {
6720                 global $gEnvManager;
6721                 
6722                 $templateId = $gEnvManager->getCurrentTemplateId();
6723                 if ($templateId == self::ADMIN_TEMPLATE ||              // PC管理用テンプレート
6724                         $templateId == self::M_ADMIN_TEMPLATE){         // 携帯管理用テンプレート
6725                         return 0;
6726                 } else if(strncmp($templateId, 'm/', 2) == 0){          // 携帯用テンプレート
6727                         return 2;               // 携帯テンプレート用出力
6728                 } else {
6729                         return 1;               // PCテンプレート用出力
6730                 }
6731         }
6732         /**
6733          * SSLが必要なページかどうかを判断
6734          *
6735          * @param string $pageId        ページID
6736          * @param string $pageSubId     ページサブID
6737          * @return bool                         true=必要、false=不要
6738          */     
6739         function isSslPage($pageId, $pageSubId)
6740         {
6741                 global $gEnvManager;
6742                 
6743                 // パラメータ修正
6744                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6745                 
6746                 // 管理用ページの場合
6747                 if ($pageId == $gEnvManager->getDefaultAdminPageId()){
6748                         if ($gEnvManager->getUseSslAdmin()){            // 管理用ページにSSLを使用するかどうか
6749                                 return true;
6750                         } else {
6751                                 return false;
6752                         }
6753                 }
6754                 
6755                 // ##### フロント画面の場合 #####
6756                 if ($gEnvManager->isRootUrlSsl()) return true;          // ルートURLがSSLの場合はフロント画面のすべてがSSL付き
6757                 
6758                 // 一般用ページにSSLを使用しない場合は不要を返す
6759                 if (!$gEnvManager->getUseSsl()) return false;
6760                                         
6761                 // 一般用ページでSSLを使用する場合は、データベースの設定をチェックする
6762                 $line = $this->getPageInfo($pageId, $pageSubId);
6763                 if (!empty($line)){
6764                         if ($line['pn_use_ssl']){
6765                                 return true;
6766                         } else {
6767                                 return false;
6768                         }
6769                 }
6770                 return false;
6771         }
6772         /**
6773          * ユーザ制限が必要なページかどうかを判断
6774          *
6775          * @param string $pageId        ページID
6776          * @param string $pageSubId     ページサブID
6777          * @return bool                         true=必要、false=不要
6778          */     
6779         function isUserLimitedPage($pageId, $pageSubId)
6780         {
6781                 global $gEnvManager;
6782                 
6783                 // パラメータ修正
6784                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6785                 
6786                 $line = $this->getPageInfo($pageId, $pageSubId);
6787                 if (!empty($line)){
6788                         if ($line['pn_user_limited']){
6789                                 return true;
6790                         } else {
6791                                 return false;
6792                         }
6793                 }
6794                 return false;
6795         }
6796         /**
6797          * ページ情報を取得
6798          *
6799          * @param string $pageId        ページID
6800          * @param string $pageSubId     ページサブID
6801          * @return array                        ページ情報レコード
6802          */     
6803         function getPageInfo($pageId, $pageSubId)
6804         {
6805                 // ページ情報が空のときはデータをロード
6806                 if (empty($this->pageInfo)){
6807                         $records = $this->db->getPageInfoRecords();
6808                         $count = count($records);
6809                         $this->pageInfo = array();
6810                         for ($i = 0; $i < $count; $i++){
6811                                 $pId = $records[$i]['pn_id'] . self::PAGE_ID_SEPARATOR . $records[$i]['pn_sub_id'];
6812                                 $this->pageInfo[$pId] = $records[$i];
6813                         }
6814                 }
6815                 return $this->pageInfo[$pageId . self::PAGE_ID_SEPARATOR . $pageSubId];
6816         }
6817         /**
6818          * 現在のページのページ情報を取得
6819          *
6820          * @return array                        ページ情報レコード
6821          */     
6822         function getCurrentPageInfo()
6823         {
6824                 return $this->currentPageInfo;
6825         }
6826         /**
6827          * 現在のページ情報からテンプレートIDを取得
6828          *
6829          * @param string $subTemplateId         テンプレートIDが取得できるときはサブページIDが返る
6830          * @return string                                       テンプレートID
6831          */     
6832         function getTemplateIdFromCurrentPageInfo(&$subTemplateId)
6833         {
6834                 $templateId = '';
6835                 if (!empty($this->currentPageInfo)){
6836                         $templateId = $this->currentPageInfo['pn_template_id'];
6837                         $subTemplateId = $this->currentPageInfo['pn_sub_template_id'];                  // サブテンプレートID
6838                 }
6839                 return $templateId;
6840         }
6841         /**
6842          * JavascriptライブラリのIDを取得
6843          *
6844          * @param int $type                     種別(0=すべて、1=jQuery関係すべて、2=jQueryプラグインのみ)
6845          * @return array                        JavascriptライブラリのID
6846          */     
6847         function getScriptLibId($type = 0)
6848         {
6849                 // Javascriptライブラリのすべてのキーを取得
6850                 $keys = array_keys($this->libFiles);
6851                 
6852                 $destKeys = array();
6853                 for ($i = 0; $i < count($keys); $i++){
6854                         switch ($type){
6855                                 case 1:         // jQuery関係すべて
6856                                         if (strStartsWith($keys[$i], 'jquery')) $destKeys[] = $keys[$i];
6857                                         break;
6858                                 case 2:         // jQueryプラグインのみ
6859                                         if (strStartsWith($keys[$i], 'jquery.')) $destKeys[] = $keys[$i];
6860                                         break;
6861                         }
6862                 }
6863                 return $destKeys;
6864         }
6865         /**
6866          * Javascriptライブラリの情報を取得
6867          *
6868          * @param string $id            ライブラリID
6869          * @return array                        ライブラリの情報
6870          */     
6871         function getScriptLibInfo($id)
6872         {
6873                 $libInfo = $this->libFiles[$id];
6874                 if (isset($libInfo)){
6875                         return $libInfo;
6876                 } else {
6877                         return array();
6878                 }
6879         }
6880         /**
6881          * 管理画面用jQueryUIテーマのURLを取得
6882          *
6883          * @return string                       テーマURL
6884          */     
6885         function getAdminDefaultThemeUrl()
6886         {
6887 //              $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
6888                 $themeFile = $this->gEnv->getAdminUrl(true/*「admin」削除*/) . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
6889                 return $themeFile;
6890         }
6891         /**
6892          * フロント画面用jQueryUIテーマのURLを取得
6893          *
6894          * @return string                       テーマURL
6895          */     
6896         function getDefaultThemeUrl()
6897         {
6898                 static $themeFile;
6899                 
6900                 if (!isset($themeFile)){
6901                         $themeFile = '';
6902                         $theme = $this->gSystem->defaultTheme();
6903                         if (!empty($theme)){
6904                                 $path = $this->gEnv->getSystemRootPath() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
6905                                 if (file_exists($path)) $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
6906                         }
6907                 }
6908                 return $themeFile;
6909         }
6910         /**
6911          * URLパラメータ文字列作成
6912          *
6913          * @param array $paramArray                     URL作成用のパス
6914          * @return string                                       作成したURLパラメータ
6915          */
6916         function _createUrlParamStr($paramArray)
6917         {
6918                 $destParam = '';
6919                 if (count($paramArray) == 0) return $destParam;
6920
6921                 $sortParam = array();
6922                 $keys = array_keys($paramArray);
6923                 $keyCount = count($keys);
6924                 for ($i = 0; $i < $keyCount; $i++){
6925                         $key = $keys[$i];
6926                         $value = $paramArray[$key];
6927                         $orderNo = $this->urlParamOrder[$key];
6928                         if (!isset($orderNo)) $orderNo = 100;
6929                         $sortParam[] = array('key' => $key, 'value' => $value, 'no' => $orderNo);
6930                 }
6931 //              usort($sortParam, create_function('$a,$b', 'return $a["no"] - $b["no"];'));
6932                 usort($sortParam, function($a, $b)
6933                 {
6934                         return $a['no'] - $b['no'];
6935                 });
6936                 
6937                 // 文字列を作成
6938                 $sortCount = count($sortParam);
6939                 for ($i = 0; $i < $sortCount; $i++){
6940                         if ($i > 0) $destParam .= '&';
6941                         $destParam .= rawurlencode($sortParam[$i]['key']) . '=' . rawurlencode($sortParam[$i]['value']);
6942                 }
6943                 return $destParam;
6944         }
6945         /**
6946          * DBからCSSファイル(テンプレート独自のCSSまたは外部のCSS)を取得
6947          *
6948          * @param string $templateId    テンプレートID
6949          * @return bool                                 true=取得成功、false=取得失敗
6950          */
6951         function loadCssFiles($templateId = '')
6952         {
6953                 if (empty($templateId)) $templateId = $this->gSystem->defaultTemplateId();              // PC画面デフォルトのテンプレートを取得
6954                 
6955                 $ret = $this->db->getTemplate($templateId, $row);
6956                 if (!$ret) return false;
6957                 if (empty($row['tm_editor_param'])) return false;
6958         
6959                 $editorParamObj = unserialize($row['tm_editor_param']);
6960                 if (isset($editorParamObj)){
6961                         $this->ckeditorCssFiles = array();
6962                         $cssFiles = $editorParamObj->cssFiles;
6963                         for ($i = 0; $i < count($cssFiles); $i++){
6964                                 $cssFile = $cssFiles[$i];
6965                                 
6966                                 if (strStartsWith($cssFile, '//')){             // URLが「//」で始まる外部ファイルの場合はそのまま追加
6967                                         $this->ckeditorCssFiles[] = $cssFile;
6968                                 } else if (strStartsWith($cssFile, '/')){               // URLが「/」で始まる相対パスの場合はURLに変換
6969                                         $this->ckeditorCssFiles[] = $this->gEnv->getAdminUrl(true/*adminディレクトリ削除*/) . $cssFile;
6970                                 } else {
6971                                         $this->ckeditorCssFiles[] = $cssFile;
6972                                 }
6973                         }
6974                         return true;
6975                 } else {
6976                         return false;
6977                 }
6978         }
6979         /**
6980          * URLで指定した画面のCSSファイル(テンプレート独自のCSSまたは外部のCSS)を取得
6981          *
6982          * @param string $url   取得画面のURL
6983          * @return                              なし
6984          */
6985         function loadCssFilesByUrl($url)
6986         {
6987                 $ch = curl_init();
6988                 curl_setopt($ch, CURLOPT_URL, $url);
6989                 curl_setopt($ch, CURLOPT_USERAGENT, M3_SYSTEM_NAME . '/' . M3_SYSTEM_VERSION);          // ユーザエージェント
6990                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         // 画面に出力しない
6991                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
6992                 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
6993                 curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());          // セッションを維持
6994                 $content = curl_exec($ch);
6995                 curl_close($ch);
6996
6997                 // HEADタグを取り出す
6998                 $urlArray = array();
6999                 $headContent = '';
7000                 $pattern = '/<head\b[^>]*?>(.*?)<\/head\b[^>]*?>/si';
7001                 if (preg_match($pattern, $content, $matches)) $headContent = $matches[0];
7002
7003                 // CSSファイル取り出し
7004                 $pattern = '/<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
7005                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7006                         foreach ($matches as $match){
7007                                 if (strEndsWith($match[1], '.css')){            // ファイル名の拡張子が「css」の場合
7008                                         $urlArray[] = $match[1];
7009                                 } else {
7010                                         // typeが「text/css」を取得
7011                                         $attrPattern = '/type\s*=\s*[\'"]+(.+?)[\'"]/si';
7012                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7013                                                 if (strcasecmp($attrMatch[1], 'text/css') == 0){
7014                                                         $urlArray[] = $match[1];
7015                                                         continue;
7016                                                 }
7017                                         }
7018                                         // relが「stylesheet」を取得
7019                                         $attrPattern = '/rel\s*=\s*[\'"]+(.+?)[\'"]/si';
7020                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7021                                                 if (strcasecmp($attrMatch[1], 'stylesheet') == 0){
7022                                                         $urlArray[] = $match[1];
7023                                                         continue;
7024                                                 }
7025                                         }
7026                                 }
7027                         }
7028                 }
7029
7030                 // ifで制御されているCSSファイルを除く
7031                 $delUrlArray = array();
7032                 $pattern = '/<!--\[if\b.*?\]>[\s\S]*<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>[\s\S]*<!\[endif\]-->/si';
7033                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7034                         foreach ($matches as $match) $delUrlArray[] = $match[1];
7035                 }
7036
7037                 // ##### テンプレート独自のCSSまたは外部のCSSを取得する #####
7038                 $this->ckeditorCssFiles = array();
7039                 $cssFiles = array_merge(array_diff($urlArray, $delUrlArray));   // CKEditor用のCSSファイル
7040                 for ($i = 0; $i < count($cssFiles); $i++){
7041                         $cssFileUrl = $cssFiles[$i];
7042                         $baseUrl = '';
7043                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7044                                 $baseUrl = $this->gEnv->getRootUrl();
7045                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7046                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7047                         }
7048                         // パスを解析
7049                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7050                         
7051                         if (strStartsWith($relativePath, '//')){                // URLが「//」で始まる外部ファイルの場合
7052                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7053                         } else if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){            // テンプレートディレクトリの場合
7054                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7055                         } else if (strStartsWith($relativePath, '/')){          // テンプレートディレクトリ以外のディレクトリの場合
7056                         } else {                        // 外部URLの場合
7057                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7058                         }
7059                 }
7060
7061                 // テンプレートタイプを取得
7062                 $pattern = '/var\s*M3_TEMPLATE_TYPE\s*=\s*(\d+?)\s*;/si';
7063                 if (preg_match($pattern, $headContent, $matches)) $this->ckeditorTemplateType = $matches[1];                    // CKEditor用のテンプレートタイプ
7064         }
7065         /**
7066          * CKEditor用のテンプレートタイプを取得
7067          *
7068          * @return int                  テンプレートタイプ
7069          */     
7070         function getCkeditorTemplateType()
7071         {
7072                 return $this->ckeditorTemplateType;
7073         }
7074         /**
7075          * POST時のリファラーチェック
7076          *
7077          * @return bool         true=正常、false=不正
7078          */
7079 /*      function _checkReferer()
7080         {
7081                 global $gEnvManager;
7082                 global $gRequestManager;
7083                 
7084                 // リファラーをチェック
7085                 $referer        = $gRequestManager->trimServerValueOf('HTTP_REFERER');
7086                 $uri            = $gEnvManager->getCurrentRequestUri();
7087                 if (empty($referer) || $referer != $uri){
7088                         return false;
7089                 } else {
7090                         return true;
7091                 }
7092         }*/
7093         /**
7094          * テンプレート画面を解析してCSSファイルやポジションの情報を取得
7095          *
7096          * @param string $templateId    テンプレートID
7097          * @return                                              テンプレート情報オブジェクト
7098          */
7099         function parseTemplate($templateId)
7100         {
7101                 // テンプレートのURL
7102                 $url = $this->gEnv->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_SHOW_POSITION . '&template=' . $templateId;
7103                 
7104                 // テンプレート情報オブジェクト
7105                 $tmplateInfoObj = new stdClass;
7106                 $tmplateInfoObj->cssFiles       = array();              // テンプレートで使用されているCSSファイル
7107                 
7108                 $ch = curl_init();
7109                 curl_setopt($ch, CURLOPT_URL, $url);
7110                 curl_setopt($ch, CURLOPT_USERAGENT, M3_SYSTEM_NAME . '/' . M3_SYSTEM_VERSION);          // ユーザエージェント
7111                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         // 画面に出力しない
7112                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
7113                 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
7114                 curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());          // セッションを維持
7115                 $content = curl_exec($ch);
7116                 curl_close($ch);
7117
7118                 // HEADタグを取り出す
7119                 $urlArray = array();
7120                 $headContent = '';
7121                 $pattern = '/<head\b[^>]*?>(.*?)<\/head\b[^>]*?>/si';
7122                 if (preg_match($pattern, $content, $matches)) $headContent = $matches[0];
7123
7124                 // CSSファイル取り出し
7125                 $pattern = '/<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
7126                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7127                         foreach ($matches as $match){
7128                                 if (strEndsWith($match[1], '.css')){            // ファイル名の拡張子が「css」の場合
7129                                         $urlArray[] = $match[1];
7130                                 } else {
7131                                         // typeが「text/css」を取得
7132                                         $attrPattern = '/type\s*=\s*[\'"]+(.+?)[\'"]/si';
7133                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7134                                                 if (strcasecmp($attrMatch[1], 'text/css') == 0){
7135                                                         $urlArray[] = $match[1];
7136                                                         continue;
7137                                                 }
7138                                         }
7139                                         // relが「stylesheet」を取得
7140                                         $attrPattern = '/rel\s*=\s*[\'"]+(.+?)[\'"]/si';
7141                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7142                                                 if (strcasecmp($attrMatch[1], 'stylesheet') == 0){
7143                                                         $urlArray[] = $match[1];
7144                                                         continue;
7145                                                 }
7146                                         }
7147                                 }
7148                         }
7149                 }
7150
7151                 // ifで制御されているCSSファイルを除く
7152                 $delUrlArray = array();
7153                 $pattern = '/<!--\[if\b.*?\]>[\s\S]*<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>[\s\S]*<!\[endif\]-->/si';
7154                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7155                         foreach ($matches as $match) $delUrlArray[] = $match[1];
7156                 }
7157
7158                 // テンプレート独自のCSSまたは外部のCSSを取得する
7159                 $cssFiles = array_merge(array_diff($urlArray, $delUrlArray));   // CKEditor用のCSSファイル
7160                 for ($i = 0; $i < count($cssFiles); $i++){
7161                         $cssFileUrl = $cssFiles[$i];
7162                         $baseUrl = '';
7163                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7164                                 $baseUrl = $this->gEnv->getRootUrl();
7165                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7166                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7167                         }
7168                         // パスを解析
7169                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7170                         
7171                         if (strStartsWith($relativePath, '//')){                // URLが「//」で始まる外部ファイルの場合
7172                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7173                         } else if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){            // テンプレートディレクトリの場合
7174                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7175                         } else if (strStartsWith($relativePath, '/')){          // テンプレートディレクトリ以外のディレクトリの場合
7176                         } else {                        // 外部URLの場合
7177                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7178                         }
7179                 }
7180                 
7181                 // パスを相対パスに変換
7182                 for ($i = 0; $i < count($tmplateInfoObj->cssFiles); $i++){
7183                         $cssFileUrl = $tmplateInfoObj->cssFiles[$i];
7184                         
7185                         $baseUrl = '';
7186                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7187                                 $baseUrl = $this->gEnv->getRootUrl();
7188                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7189                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7190                         }
7191                         // パスを解析
7192                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7193                         
7194                         // テンプレート内のCSSの場合は相対パスに変換
7195                         if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){// テンプレートディレクトリの場合
7196                                 $tmplateInfoObj->cssFiles[$i] = $relativePath;
7197                         } else {
7198                                 $tmplateInfoObj->cssFiles[$i] = $cssFileUrl;
7199                         }
7200                 }
7201                 
7202                 // テンプレートのポジションを取得
7203                 $tmplateInfoObj->positions = array();
7204                 $pattern = '/var\s*M3_POSITION_DATA\s*=\s*[\'"]+(.+?)[\'"]/si';
7205                 if (preg_match($pattern, $headContent, $matches) && !empty($matches[1])){
7206                         $tmplateInfoObj->positions = explode(',', $matches[1]);
7207                 }
7208                 return $tmplateInfoObj;
7209         }
7210         /**
7211          * デフォルトのテンプレートからレイアウト用テンプレートで使用していないポジションを取得
7212          *
7213          * @return array                                ポジション名の配列
7214          */
7215         function getLayoutTemplatePosition()
7216         {
7217                 $removePositions = array('header', 'extra1', 'extra2', 'brand', 'hmenu', 'user3', 'banner1', 'top1', 'top2', 'top3',
7218                                                                 'left', 'banner2', 'breadcrumb', 'user1', 'user2', 'banner3', 'main-top', 'main', 'main-bottom', 'banner4', 'user4', 'user5', 'banner5', 
7219                                                                 'right','bottom1', 'bottom2', 'bottom3', 'banner6', 'syndicate', 'copyright', 'footer');                // レイアウト用テンプレートに存在するので削除するポジション
7220                 
7221                 // URLパラメータからデフォルトのテンプレートを取得
7222                 $pageId = $this->gRequest->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
7223
7224                 $templateId = '';
7225                 if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
7226                         $templateId = $this->gSystem->defaultTemplateId();
7227                 } else if ($pageId == $this->gEnv->getDefaultMobilePageId()){           // 携帯サイトのとき
7228                         $templateId = $this->gSystem->defaultMobileTemplateId();                // 携帯用デフォルトテンプレート
7229                 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
7230                         $templateId = $this->gSystem->defaultSmartphoneTemplateId();            // スマートフォン用デフォルトテンプレート
7231                 }
7232
7233                 // テンプレート情報取得
7234                 $ret = $this->db->getTemplate($templateId, $row);
7235                 if (!$ret) return array();
7236                 if (empty($row['tm_editor_param'])) return array();
7237         
7238                 // レイアウト用テンプレートに存在しないポジション名のみ返す
7239                 $editorParamObj = unserialize($row['tm_editor_param']);
7240                 if (isset($editorParamObj)){
7241                         if (isset($editorParamObj->positions)){
7242                                 $srcArray = $editorParamObj->positions;
7243                                 $destArray = array();
7244                                 for ($i = 0; $i < count($srcArray); $i++){
7245                                         $position = $srcArray[$i];
7246                                         if (!in_array($position, $removePositions)) $destArray[] = $position;
7247                                 }
7248                                 return $destArray;
7249                         }
7250                 }
7251                 return array();
7252         }
7253 }
7254 ?>