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-2017 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_VISIBLE_IN_LOGIN_CLASS = 'm3visible_in_login';                                     // ログイン時のみ表示ウィジェットクラス
129         const WIDGET_VISIBLE_IN_NOT_LOGIN_CLASS = 'm3visible_in_not_login';                     // 非ログイン時のみ表示ウィジェットクラス
130         const WIDGET_OUTER_CLASS = 'm3_widget_outer';                   // ウィジェット外枠クラス
131         const WIDGET_OUTER_CLASS_HEAD_POSITION = 'm3_pos_';                     // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
132         const WIDGET_OUTER_CLASS_WIDGET_TAG = 'm3_';                            // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
133 //      const WIDGET_INNER_CLASS = 'm3_widget_inner';                   // ウィジェットの内側クラス
134         const POSITION_TAG_HEAD = 'm3pos_';                     // ポジションの識別用タグIDヘッダ
135         const WIDGET_TAG_HEAD = 'm3widget_';                    // ウィジェットの識別用タグIDヘッダ
136 //      const WIDGET_TAG_HEAD_SHORT = 'm3_';                    // ウィジェットの識別用タグIDヘッダ
137         const WIDGET_TYPE_TAG_HEAD = 'm3widgettype_';                   // ウィジェット種別の識別用タグIDヘッダ
138         const WIDTET_CLASS_NAME = 'm3widget';                   // ウィジェットオブジェクトのタグクラス名
139         const WIDTET_CLASS_TYPE_0 = 'm3widget_type0';                   // ウィジェットオブジェクトのタグクラス(グローバル属性でない)
140         const WIDTET_CLASS_TYPE_1 = 'm3widget_type1';                   // ウィジェットオブジェクトのタグクラス(グローバル属性)
141         const POSITION_CLASS_NAME = 'm3position';               // ポジションオブジェクトのタグクラス名
142         const JOOMLA10_DEFAULT_WIDGET_MENU_PARAM = 'class="moduletable"';       // Joomla!1.0用デフォルトメニューパラメータ値
143         const ADMIN_TEMPLATE = '_admin';                // PC管理用テンプレートID
144         const M_ADMIN_TEMPLATE = 'm/_admin';    // 携帯用管理画面テンプレートID
145         const SCRIPT_LIB_SEPARATOR = ';';                       // JavaScriptライブラリ読み込み設定のライブラリの区切り
146         const PAGE_ID_SEPARATOR = ',';                          // ページIDとページサブID連結用
147         const DEFAULT_ADMIN_FAVICON_FILE = '/images/system/favicon.ico';                        // デフォルトの管理画面用faviconファイル
148         const DEFAULT_FAVICON_FILE = '/favicon.ico';                    // デフォルトのfaviconファイル
149 //      const DEFAULT_SITE_NAME = 'サイト名未設定';              // 管理画面用のデフォルトサイト名
150         const DEFAULT_ADMIN_TITLE = '管理画面';                     // デフォルトの管理画面名
151         const WIDGET_TITLE_START = '[';                                 // ウィジェットのタイトルの括弧
152         const WIDGET_TITLE_END = ']';                                   // ウィジェットのタイトルの括弧
153         const DEFAULT_RSS_VERSION = '1.0';                              // デフォルトのRSSのバージョン
154         const CF_ACCESS_IN_INTRANET = 'access_in_intranet';             // イントラネット運用かどうか
155         const CF_USE_LATEST_SCRIPT_LIB = 'dev_use_latest_script_lib';           // 最新のJavaScriptライブラリを使用するかどうか
156         const CF_GOOGLE_MAPS_KEY = 'google_maps_key';                           // Googleマップ利用キー
157         const CF_CONFIG_WINDOW_OPEN_TYPE = 'config_window_open_type';           // ウィジェット設定画面のウィンドウ表示タイプ(0=別ウィンドウ、1=タブ)
158         const CF_JQUERY_VERSION = 'jquery_version';                     // jQueryバージョン
159         const CF_EXTERNAL_JQUERY = 'external_jquery';                   // システム外部のjQueryを使用するかどうか
160         const CF_WYSIWYG_EDITOR = 'wysiwyg_editor';             // 管理画面用WYSIWYGエディター
161         const CF_ADMIN_JQUERY_VERSION = 'admin_jquery_version';                 // 管理画面用jQueryバージョン
162         const CF_USE_JQUERY = 'use_jquery';                             // jQueryを常に使用するかどうか
163         const CF_SMARTPHONE_USE_JQUERY_MOBILE = 'smartphone_use_jquery_mobile';         // スマートフォン画面でjQuery Mobileを使用
164         const SD_HEAD_OTHERS    = 'head_others';                // ヘッダその他タグ
165         const DEFAULT_THEME_DIR = '/ui/themes/';                                // jQueryUIテーマ格納ディレクトリ
166         const THEME_CSS_FILE = 'jquery-ui.custom.css';          // テーマファイル
167         const CONFIG_ICON_FILE = '/images/system/config.png';                   // ウィジェット定義画面アイコン
168         const ADJUST_ICON_FILE = '/images/system/adjust_widget.png';    // 位置調整アイコン
169         const SHARED_ICON_FILE = '/images/system/shared.png';   // グローバル属性
170         const DELETE_ICON_FILE = '/images/system/delete.png';   // ウィジェット削除
171         const CONFIG_ICON32_FILE = '/images/system/config32.png';                       // ウィジェット定義画面アイコン(ツールチップ用)
172         const ADJUST_ICON32_FILE = '/images/system/adjust_widget32.png';        // 位置調整アイコン(ツールチップ用)
173         const CLOSE_BOX_ICON32_FILE = '/images/system/close_box.png';           // ウィンドウ閉じるアイコン(ツールチップ用)
174         const NOTICE_ICON_FILE = '/images/system/notice16.png';         // ウィジェット配置注意アイコン
175         const ALERT_ICON_FILE = '/images/system/alert16.png';           // ウィジェット配置警告アイコン
176 //      const ADMIN_ICON_FILE = '/images/system/admin64.png';           // パネルメニュー管理画面遷移用アイコン
177 //      const LOGOUT_ICON_FILE = '/images/system/logout64.png';         // パネルメニューログアウト用アイコン
178 //      const EDIT_PAGE_ICON_FILE = '/images/system/create_page64.png';         // パネルメニュー編集用アイコン   
179         const ADMIN_ICON_FILE = '/images/system/home32.png';            // パネルメニュー管理画面遷移用アイコン
180         const LOGOUT_ICON_FILE = '/images/system/logout32.png';         // パネルメニューログアウト用アイコン
181         const EDIT_PAGE_ICON_FILE = '/images/system/create_page32.png';         // パネルメニュー編集用アイコン   
182 //      const EDIT_END_ICON_FILE = '/images/system/close32.png';                // パネルメニュー編集終了用アイコン
183         const EDIT_END_ICON_FILE = '/images/system/back32.png';         // パネルメニュー編集終了用アイコン
184         const CLOSE_ICON_FILE = '/images/system/close32.png';           // ウィンドウ閉じるアイコン
185         const PREV_ICON_FILE = '/images/system/prev48.png';             // ウィンドウ「前へ」アイコン
186         const NEXT_ICON_FILE = '/images/system/next48.png';             // ウィンドウ「次へ」アイコン
187         const DEFAULT_READMORE_TITLE = 'もっと読む';                       // もっと読むボタンのデフォルトタイトル
188         const POS_HEAD_NAV_MENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー" data-placement="auto"></i> ';               // 特殊ポジションブロック(ナビゲーションメニュー)
189         const WIDGET_MARK_MAIN = '<i class="glyphicon glyphicon-tower" rel="m3help" title="メイン型" data-placement="auto"></i> ';          // ウィジェットの機能マーク(メイン型ウィジェット)
190         const WIDGET_MARK_NAVMENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー" data-placement="auto"></i> ';             // ウィジェットの機能マーク(ナビゲーションメニュー)
191         const WIDGET_FUNCTION_MARK_BOOTSTRAP = ' <span class="label label-warning" rel="m3help" title="Bootstrap型テンプレート対応" data-placement="auto">B</span>';                   // ウィジェット機能マーク(Boostrap型テンプレート
192         const WIDGET_FUNCTION_MARK_WORDPRESS = ' <span class="label label-warning" rel="m3help" title="WordPress型テンプレート対応" data-placement="auto">W</span>';                   // ウィジェット機能マーク(WordPress型テンプレート
193         const WIDGET_STYLE_NAVMENU = '_navmenu';                // ウィジェットの表示スタイル(ナビゲーションメニュー)
194         const WIDGET_STYLE_WORDPRESS = '_wordpress';                                            // ウィジェットの表示スタイル(WordPressテンプレート用出力)
195         const WIDGET_STYLE_WORDPRESS_NOTITLE = '_wordpress_notitle';            // ウィジェットの表示スタイル(WordPressテンプレート(タイトルなし)用出力)
196         
197         // アドオンオブジェクト用
198         const CONTENT_OBJ_ID    = 'contentlib'; // 汎用コンテンツオブジェクトID
199         const BLOG_OBJ_ID               = 'bloglib';            // ブログオブジェクトID
200         const LINKINFO_OBJ_ID   = 'linkinfo';   // リンク情報オブジェクトID
201         
202         // インナーウィジェット用
203         const IWIDTET_CMD_CONTENT = 'content';          // コンテンツ取得
204         const IWIDTET_CMD_INIT = 'init';                        // 初期化
205         const IWIDTET_CMD_UPDATE = 'update';            // 更新
206         const IWIDTET_CMD_CALC = 'calc';                        // 計算
207         
208         // Magic3用スクリプト
209         const M3_ADMIN_SCRIPT_FILENAME                  = 'm3admin2.0.1.js';                            // 管理機能用スクリプト(FCKEditor2.6.6、CKEditor4.0.1対応)
210         const M3_ADMIN_WIDGET_SCRIPT_FILENAME   = 'm3admin_widget2.0.10.js';    // 管理機能(ウィジェット操作)用スクリプト(Magic3 v1.15.0以降)
211         const M3_ADMIN_WIDGET_CSS_FILE                  = '/m3/widget.css';                     // 管理機能(ウィジェット操作)用CSSファイル
212         const M3_STD_SCRIPT_FILENAME                    = 'm3std1.5.2.js';                      // 一般、管理機能共通スクリプト
213 //      const M3_PLUS_SCRIPT_FILENAME                   = 'm3plus1.6.2.js';                     // フロント画面追加用スクリプト(FCKEditor2.6.6対応、CKEditor4.0.1対応)
214         const M3_OPTION_SCRIPT_FILENAME                 = 'm3opt1.2.1.js';                      // AJAXを含んだオプションライブラリファイル(jQuery必須)
215         const M3_ADMIN_CSS_FILE                                 = 'm3/admin.css';                       // 管理機能用のCSS
216         const M3_EDIT_CSS_FILE                                  = 'm3/edit.css';                        // フロント画面編集用のCSS
217         const M3_DEFAULT_CSS_FILE                               = 'm3/default.css';                     // フロント画面共通のデフォルトCSS
218         const M3_CKEDITOR_CSS_FILE                              = 'm3/ckeditor.css';                    // CKEditorの編集エリア用CSS
219         
220         // 読み込み制御
221         const USE_BOOTSTRAP_ADMIN       = false;                        // 管理画面でBootstrapを使用するかどうか(デフォルト値)
222         const BOOTSTRAP_BUTTON_CLASS = 'btn btn-default';
223         
224         // UI
225         const FILEBROWSER_WIDTH_RATIO = '0.8';                  // ファイルブラウザ幅比率
226         const FILEBROWSER_HEIGHT_RATIO = '0.8';                 // ファイルブラウザ高さ比率
227         
228         /**
229          * コンストラクタ
230          */
231         function __construct()
232         {
233                 global $gInstanceManager;
234                 global $gEnvManager;
235                 global $gSystemManager;
236                 global $gRequestManager;
237                                 
238                 // 親クラスを呼び出す
239                 parent::__construct();
240                 
241                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
242                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
243                 
244                 // システムDBオブジェクト取得
245                 $this->db = $gInstanceManager->getSytemDbObject();
246                 
247                 // 運用方法
248                 $value = $gSystemManager->getSystemConfig(self::CF_ACCESS_IN_INTRANET);         // イントラネット運用かどうか
249                 if (empty($value)){             // インターネット運用
250                         $this->useGooglemaps = true;                            // Googleマップを使用するかどうか
251                 }
252                 $this->useHelp = true;          // ヘルプ機能
253                 
254                 // デフォルトのWYSIWYGエディターを取得
255                 $this->wysiwygEditor = $gSystemManager->getSystemConfig(self::CF_WYSIWYG_EDITOR);                               // 管理画面用WYSIWYGエディター
256                 
257                 // ##### Javascriptライブラリのバージョン設定 #####
258                 // jQueryバージョン設定
259                 // アクセスする画面に応じてjQueryのバージョンを設定
260                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
261                         $value = $gSystemManager->getSystemConfig(self::CF_ADMIN_JQUERY_VERSION);// 管理画面用jQueryバージョン
262                         
263                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET && strStartsWith($widgetId, 'm/')){// 携帯用アクセスポイント用の管理画面の場合はWYSIWYGエディターはFCKEditorに固定
264                                 $this->wysiwygEditor = ScriptLibInfo::LIB_FCKEDITOR;                            // FCKEditorに固定
265                         }
266                         
267                         // 管理画面にBOOTSTRAPを使用するかどうか(初期値)
268                         $this->useBootstrap = self::USE_BOOTSTRAP_ADMIN;
269                         
270                         // CKEditorのバージョン設定
271                         // 小画面デバイス最適化の場合は最新バージョンを使用
272                         if ($gEnvManager->isSmallDeviceAdmin()) ScriptLibInfo::setCkeditorVer(1/*最新*/);
273                 } else {
274                         $value = $gSystemManager->getSystemConfig(self::CF_JQUERY_VERSION);// jQueryバージョン
275                 }
276                 ScriptLibInfo::setJQueryVer($value);
277                 
278                 // WYSISIGエディターのタイプを設定。ScriptLibInfo::getLib()を実行する前に設定。
279                 ScriptLibInfo::setWysiwygEditorType($this->wysiwygEditor);
280                 
281                 // Javascriptライブラリ
282                 $this->libFiles = ScriptLibInfo::getLib();                      // ライブラリ取得
283                 
284                 // jQueryファイル名取得
285                 $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(0);                    // 使用対象のjQueryファイル
286                 $this->selectedJQueryUiFilename = ScriptLibInfo::getJQueryFilename(1);          // 使用対象のjQuery UIファイル
287
288                 // ##### フロント画面用のデフォルトのJavascript、CSSを取得 #####
289                 $this->defaultScriptFiles       =       array(
290                                                                                         $this->selectedJQueryFilename,                  // jQuery
291                                                                                         self::M3_STD_SCRIPT_FILENAME
292                                                                                 );
293                 $this->defaultCssFiles          =       array(
294                                                                                         self::M3_DEFAULT_CSS_FILE                               // フロント画面共通のデフォルトCSS
295                                                                                 );
296                 
297                 // ##### 管理機能用のデフォルトのJavascript、CSSを取得 #####
298                 if (defined('M3_STATE_IN_INSTALL')){            // インストーラの場合のスクリプト
299                         $this->defaultAdminScriptFiles  =       array(
300                                                                                                         $this->selectedJQueryFilename,                  // jQuery
301                                                                                                 //      self::M3_STD_SCRIPT_FILENAME,
302                                                                                                         self::M3_ADMIN_SCRIPT_FILENAME
303                                                                                                 );
304                         $this->defaultAdminCssFiles             =       array();        // 管理機能用のCSS
305                 } else {
306                         $this->defaultAdminScriptFiles  =       array(
307                                                                                                         $this->selectedJQueryFilename,                  // jQuery
308                                                                                                         $this->selectedJQueryUiFilename,                                // jQuery UI Core
309                                                                                                         ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME,             // jQuery Contextmenu Lib
310                                                                                                         self::M3_STD_SCRIPT_FILENAME,
311                                                                                                         self::M3_ADMIN_SCRIPT_FILENAME,
312                                                                                                         self::M3_OPTION_SCRIPT_FILENAME
313                                                                                                 );
314                         $this->defaultAdminCssFiles             =       array(
315                                                                                                         self::M3_ADMIN_CSS_FILE                 // 管理機能用のCSS
316                                                                                                 );
317                         
318                         // Javascriptライブラリ
319                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);     // 管理パネル用
320                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_EASING);            // 管理パネル用
321                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_NUMERIC);           // 入力制限プラグイン
322 //                      $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_RESPONSIVETABLE);// 管理画面作成用
323                 }
324                 
325                 // 管理権限なしで管理ディレクトリアクセスで読み込むスクリプトファイル
326                 $this->defaultAdminDirScriptFiles = array($this->selectedJQueryFilename);                       // jQuery
327                 
328                 // 遅延ウィジェットリスト                                                                    
329                 $this->lateLaunchWidgetList = array();
330                 $this->latelaunchWidgetParam = array();
331                 
332                 // DB接続可能なときは設定値を取得
333                 if ($gEnvManager->canUseDb()){
334                         $value = $this->gSystem->getSystemConfig('script_cache_in_browser');    // ブラウザにJavaScriptファイルのキャッシュを保持するかどうか
335                         if ($value != '') $this->hasScriptCache = $value;
336                 }
337                 
338                 $this->rssVersion = self::DEFAULT_RSS_VERSION;                                  // RSSバージョン
339                 
340                 // フロント画面で使用する主要コンテンツタイプ
341                 $this->mainContentTypeInfo       = array(
342                                                                                                 array(  'name' => '会員情報',                                       'value' => M3_VIEW_TYPE_MEMBER),
343                                                                                                 array(  'name' => '汎用コンテンツ',                              'value' => M3_VIEW_TYPE_CONTENT),
344                                                                                                 array(  'name' => '製品',                                             'value' => M3_VIEW_TYPE_PRODUCT),
345                                                                                                 array(  'name' => 'BBS',                                                'value' => M3_VIEW_TYPE_BBS),
346                                                                                                 array(  'name' => 'ブログ',                                          'value' => M3_VIEW_TYPE_BLOG),
347                                                                                                 array(  'name' => 'Wiki',                                               'value' => M3_VIEW_TYPE_WIKI),
348                                                                                                 array(  'name' => 'ユーザ作成コンテンツ',             'value' => M3_VIEW_TYPE_USER),
349                                                                                                 array(  'name' => 'イベント情報',                         'value' => M3_VIEW_TYPE_EVENT),
350                                                                                                 array(  'name' => 'フォトギャラリー',                   'value' => M3_VIEW_TYPE_PHOTO)
351                                                                                         );
352                 // フロント画面で使用する補助コンテンツタイプ(ページ属性に対応しない)
353                 $this->subContentTypeInfo        = array(       array(  'name' => '新着情報',                                       'value' => M3_VIEW_TYPE_NEWS),
354                                                                                                 array(  'name' => 'コメント',                                       'value' => M3_VIEW_TYPE_COMMENT),
355                                                                                                 array(  'name' => 'イベント予約',                         'value' => M3_VIEW_TYPE_EVENTENTRY),
356                                                                                                 array(  'name' => 'バナー',                                          'value' => M3_VIEW_TYPE_BANNER)
357                                                                                         );
358                 // フロント画面で使用する主要機能タイプ(「ダッシュボード」は含まない)
359                 $this->mainFeatureTypeInfo       = array(       array(  'name' => '検索',                                             'value' => M3_VIEW_TYPE_SEARCH),
360                                                                                                 array(  'name' => 'Eコマース',                                      'value' => M3_VIEW_TYPE_COMMERCE),
361                                                                                                 array(  'name' => 'カレンダー',                                    'value' => M3_VIEW_TYPE_CALENDAR)
362                                                                                         );
363                 // 管理画面専用で使用する機能タイプ
364                 $this->adminFeatureTypeInfo      = array(       array(  'name' => 'ダッシュボード',                              'value' => M3_VIEW_TYPE_DASHBOARD)
365                                                                                         );
366                                                                                         
367                 // URLパラメータ並び順
368                 $this->urlParamOrder = array(
369                         // コンテンツID
370                         M3_REQUEST_PARAM_CONTENT_ID                             => -20,         // 汎用コンテンツID
371                         M3_REQUEST_PARAM_CONTENT_ID_SHORT               => -19,         // 汎用コンテンツID(略式)
372                         M3_REQUEST_PARAM_PRODUCT_ID                             => -18,         // 製品ID
373                         M3_REQUEST_PARAM_PRODUCT_ID_SHORT               => -17,         // 製品ID(略式)
374                         M3_REQUEST_PARAM_BLOG_ID                                => -16,         // ブログID
375                         M3_REQUEST_PARAM_BLOG_ID_SHORT                  => -15,         // ブログID(略式)
376                         M3_REQUEST_PARAM_BLOG_ENTRY_ID                  => -14,         // ブログ記事ID
377                         M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT    => -13,         // ブログ記事ID(略式)
378                         M3_REQUEST_PARAM_BBS_ID                                 => -12,         // 掲示板投稿記事ID
379                         M3_REQUEST_PARAM_BBS_ID_SHORT                   => -11,         // 掲示板投稿記事ID(略式)
380                         M3_REQUEST_PARAM_BBS_THREAD_ID                  => -10,         // 掲示板投稿スレッドID
381                         M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT    => -9,          // 掲示板投稿スレッドID(略式)
382                         M3_REQUEST_PARAM_USER_ID                                => -8,          // ユーザ作成コンテンツID
383                         M3_REQUEST_PARAM_USER_ID_SHORT                  => -7,          // ユーザ作成コンテンツID(略式)
384                         M3_REQUEST_PARAM_ROOM_ID                                => -6,          // ユーザ作成コンテンツ区画ID
385                         M3_REQUEST_PARAM_ROOM_ID_SHORT                  => -5,          // ユーザ作成コンテンツ区画ID(略式)
386                         M3_REQUEST_PARAM_EVENT_ID                               => -4,          // イベントID
387                         M3_REQUEST_PARAM_EVENT_ID_SHORT                 => -3,          // イベントID(略式)
388                         M3_REQUEST_PARAM_PHOTO_ID                               => -2,          // 画像ID
389                         M3_REQUEST_PARAM_PHOTO_ID_SHORT                 => -1,          // 画像ID(略式)
390                         // URLパラメータ
391                         M3_REQUEST_PARAM_PAGE_SUB_ID                    => 1,           // ページサブID
392                         M3_REQUEST_PARAM_PAGE_CONTENT_ID                => 2,           // ページコンテンツID
393                         M3_REQUEST_PARAM_WIDGET_ID                              => 3,           // ウィジェットID
394                         M3_REQUEST_PARAM_TEMPLATE_ID                    => 4,           // テンプレートID
395                         M3_REQUEST_PARAM_URL                                    => 5,           // リンク先等のURL
396                         M3_REQUEST_PARAM_STAMP                                  => 6,           // 公開発行ID
397                         M3_REQUEST_PARAM_OPTION                                 => 7,           // 通信オプション
398                         M3_REQUEST_PARAM_OPERATION_COMMAND              => 8,           // 実行処理
399                         M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND => 9,           // Wikiコマンド実行
400                         M3_REQUEST_PARAM_OPERATION_TASK                 => 10,          // ウィジェット間共通処理
401                         M3_REQUEST_PARAM_OPERATION_ACT                  => 11,          // クライアントからの実行処理
402                         M3_REQUEST_PARAM_OPERATION_LANG                 => 12,          // 言語指定表示
403                         M3_REQUEST_PARAM_SERIAL_NO                              => 13,          // シリアル番号
404                         M3_REQUEST_PARAM_PAGE_NO                        => 14,          // ページ番号
405                         M3_REQUEST_PARAM_LIST_NO                                => 15,          // 一覧番号
406                         M3_REQUEST_PARAM_ITEM_NO                        => 16,          // 項目番号
407                         M3_REQUEST_PARAM_OPERATION_TODO                 => 17,          // 指定ウィジェットに実行させる処理
408                         M3_REQUEST_PARAM_FROM                                   => 18,          // メッセージの送信元ウィジェットID
409                         M3_REQUEST_PARAM_VIEW_STYLE                             => 19,          // 表示スタイル
410                         M3_REQUEST_PARAM_FORWARD                                => 20,          // 画面遷移用パラメータ
411                         M3_REQUEST_PARAM_ADMIN_KEY                              => 21,          // 管理者一時キー
412                         M3_REQUEST_PARAM_OPEN_BY                                => 22,          // ウィンドウの開き方
413                         M3_REQUEST_PARAM_SHOW_HEADER                    => 23,          // ヘッダ部表示制御
414                         M3_REQUEST_PARAM_SHOW_FOOTER                    => 24,          // フッタ部表示制御
415                         M3_REQUEST_PARAM_SHOW_MENU                              => 25,          // メニュー部表示制御
416                         M3_REQUEST_PARAM_KEYWORD                                => 26,          // 検索キーワード
417                         M3_REQUEST_PARAM_HISTORY                                => 27,          // 履歴インデックスNo
418                         M3_REQUEST_PARAM_DEF_PAGE_ID                    => 28,          // ページID(画面編集用)
419                         M3_REQUEST_PARAM_DEF_PAGE_SUB_ID                => 29,          // ページサブID(画面編集用)
420                         M3_REQUEST_PARAM_PAGE_DEF_SERIAL                => 30,          // ページ定義のレコードシリアル番号(設定画面起動時)
421                         M3_REQUEST_PARAM_PAGE_DEF_CONFIG_ID             => 31,          // ページ定義のウィジェット定義ID(設定画面起動時)
422                         M3_REQUEST_PARAM_BACK_URL                               => 32,          // 戻り先URL
423                         M3_REQUEST_PARAM_BACKUP_URL                             => 33,          // URL退避用(画面編集時)
424                         M3_REQUEST_PARAM_SERVER                                 => 34,          // サーバ指定
425                         M3_REQUEST_PARAM_CATEGORY_ID                    => 35,          // カテゴリID(共通)
426                         M3_REQUEST_PARAM_WIDTH                                  => 36,          // 幅
427                         M3_REQUEST_PARAM_HEIGHT                                 => 37);         // 高さ
428         }
429         /**
430          * メインコンテンツタイプを取得
431          *
432          * @return array        コンテンツタイプ
433          */
434         public function _getAllContentType()
435         {
436                 global $M3_ALL_CONTENT_TYPE;
437                 
438 /*              $contentType = array(   M3_VIEW_TYPE_CONTENT,                           // 汎用コンテンツ
439                                                                 M3_VIEW_TYPE_PRODUCT,                           // 製品
440                                                                 M3_VIEW_TYPE_BBS,                                       // BBS
441                                                                 M3_VIEW_TYPE_BLOG,                              // ブログ
442                                                                 M3_VIEW_TYPE_WIKI,                              // wiki
443                                                                 M3_VIEW_TYPE_USER,                              // ユーザ作成コンテンツ
444                                                                 M3_VIEW_TYPE_EVENT,                             // イベント
445                                                                 M3_VIEW_TYPE_PHOTO);                            // フォトギャラリー
446                 return $contentType;*/
447                 return $M3_ALL_CONTENT_TYPE;
448         }
449         /**
450          * 機能タイプを取得
451          *
452          * @return array        機能タイプ
453          */
454         public function _getAllFeatureType()
455         {
456                 global $M3_ALL_FEATURE_TYPE;
457                 
458 /*              $featureType = array(   M3_VIEW_TYPE_DASHBOARD,                 // ダッシュボード
459                                                                 M3_VIEW_TYPE_SEARCH,                    // 検索結果
460                                                                 M3_VIEW_TYPE_COMMERCE);                 // Eコマース
461                 return $featureType;*/
462                 return $M3_ALL_FEATURE_TYPE;
463         }
464         /**
465          * タイムアウトを停止
466          *
467          * @return なし
468          */
469         function setNoTimeout()
470         {
471                 if (ini_get('safe_mode') == '0') set_time_limit(0);
472         }
473         /**
474          * ポップアップメッセージを設定
475          *
476          * @param string $msg   メッセージ
477          */
478         function setPopupMsg($msg)
479         {
480                 $this->popupMsg = $msg;
481         }
482         /**
483          * HTMLヘッダ「description」に出力する文字列を設定
484          *
485          * @param string $str   出力文字列
486          */
487         function setHeadDescription($str)
488         {
489                 if (is_string($str) && !empty($str)){
490                         $this->headDescription = $str;
491                         $this->lastHeadDescription = $str;      // 最後に設定した値を退避
492                 }
493         }
494         /**
495          * HTMLヘッダ「description」に出力する文字列を取得
496          *
497          * @return string $str   出力文字列
498          */
499         function getHeadDescription()
500         {
501                 return $this->headDescription;
502         }
503         /**
504          * HTMLヘッダ「keywords」に出力する文字列を設定
505          *
506          * @param string $str   出力文字列
507          */
508         function setHeadKeywords($str)
509         {
510                 if (is_string($str) && !empty($str)){
511                         $this->headKeywords = $str;
512                         $this->lastHeadKeywords = $str;         // 最後に設定した値を退避
513                 }
514         }
515         /**
516          * HTMLヘッダ「keywords」に出力する文字列を取得
517          *
518          * @return string $str   出力文字列
519          */
520         function getHeadKeywords()
521         {
522                 return $this->headKeywords;
523         }
524         /**
525          * HTMLヘッダに出力するタグ文字列を設定
526          *
527          * @param string $str   出力文字列
528          * @return なし
529          */
530         function setHeadOthers($str)
531         {
532                 if (is_string($str) && !empty($str)){
533                         $this->headOthers = $str;
534                 }
535         }
536         /**
537          * HTMLヘッダに出力するタグ文字列を追加
538          *
539          * @param string $str   出力文字列
540          * @return なし
541          */
542         function addHeadOthers($str)
543         {
544                 if (is_string($str) && !empty($str)){
545                         // 追加されていない場合のみ追加
546                         $pos = strpos($this->headOthers, $str);
547                         if ($pos === false) $this->headOthers .= $str;
548                 }
549         }
550         /**
551          * HTMLヘッダに出力するタグ文字列を追加(管理画面用)
552          *
553          * @param string $str   出力文字列
554          * @return なし
555          */
556         function addAdminHeadOthers($str)
557         {
558                 if (is_string($str) && !empty($str)){
559                         // 追加されていない場合のみ追加
560                         $pos = strpos($this->adminHeadOthers, $str);
561                         if ($pos === false) $this->adminHeadOthers .= $str;
562                 }
563         }
564         /**
565          * HTMLヘッダ「title」のサブタイトル出力する文字列を設定
566          *
567          * @param string $str   出力文字列
568          * @param string $url   リンク先
569          */
570         function setHeadSubTitle($str = '', $url = '')
571         {
572                 global $gEnvManager;
573                 
574                 if (is_string($str)){
575                         // 空の場合はウィジェットのヘッドタイトルから取得
576                         if (empty($str)) $str = $gEnvManager->getCurrentWidgetHeadTitle();
577
578                         if (!empty($str)){
579                                 $this->headSubTitle[] = $str;
580                                 $this->headSubTitleUrl[] = $url;
581                                 $this->lastHeadTitle = $str;    // 最後に設定した値を退避
582                         }
583                 }
584         }
585         /**
586          * HTMLヘッダ「title」のサブタイトル出力する文字列を取得
587          *
588          * @return $array   サブタイトルに設定されている文字列を連想配列(title=タイトル、url=リンク先URL)の配列で返す
589          */
590         function getHeadSubTitle()
591         {
592                 $titleArray = array();
593                 $titleCount = count($this->headSubTitle);
594                 for ($i = 0; $i < $titleCount; $i++){
595                         $line = array('title' => $this->headSubTitle[$i], 'url' => $this->headSubTitleUrl[$i]);
596                         $titleArray[] = $line;
597                 }
598                 return $titleArray;
599         }
600         /**
601          * HTMLヘッダに出力するCSSの文字列を設定
602          *
603          * @param string $css   追加するCSS内容
604          * @return                              なし
605          */
606         function addHeadCss($css)
607         {
608                 $destCss = trim($css);
609                 if (!empty($destCss)){
610                         //if (!in_array($css, $this->headCss)) $this->headCss[] = $css;
611                         if (!in_array($css, $this->exportCss)) $this->exportCss[] = $css;               // CSS動的外部出力
612                         
613                         $this->lastHeadCss = $css;                      // 最後に設定したHTMLヘッダにCSS出力する文字列
614                 }
615         }
616         /**
617          * 外部出力で出力するCSSの文字列を設定(ウィジェット共通設定からの設定値)
618          *
619          * @param string $css   追加するCSS内容
620          * @return                              なし
621          */
622         function addExportCss($css)
623         {
624                 $destCss = trim($css);
625                 if (!empty($destCss)){
626                         if (!in_array($css, $this->exportCss)) $this->exportCss[] = $css;
627                 }
628         }
629         /**
630          * HTMLヘッダに出力するJavascriptの文字列を設定
631          *
632          * @param string $script        追加するJavascript内容
633          * @return                                      なし
634          */
635         function addHeadScript($script)
636         {
637                 $destScript = trim($script);
638                 if (!empty($destScript)){
639                         if (!in_array($script, $this->headScript)) $this->headScript[] = $script;
640                         
641                         $this->lastHeadScript = $script;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
642                 }
643         }
644         /**
645          * HTMLヘッダに出力するJavascriptの文字列(jQueryMobile用挿入スクリプト)を設定
646          *
647          * @param string $script        追加するJavascript内容
648          * @return                                      なし
649          */
650         function addHeadPreMobileScript($script)
651         {
652                 $destScript = trim($script);
653                 if (!empty($destScript)){
654                         if (!in_array($script, $this->headPreMobileScript)) $this->headPreMobileScript[] = $script;
655                 }
656         }
657         /**
658          * HTMLヘッダに出力する任意文字列を設定
659          *
660          * @param string $str   追加する任意文字列
661          * @return                              なし
662          */
663         function addHeadString($str)
664         {
665                 $destScript = trim($str);
666                 if (!empty($destScript)){
667                         if (!in_array($str, $this->headString)) $this->headString[] = $str;
668                         
669                         $this->lastHeadString = $str;                   // 最後に設定したHTMLヘッダに出力する任意文字列
670                 }
671         }
672         /**
673          * HTMLヘッダに出力するCSSファイルを追加
674          *
675          * @param string,array $cssFile CSSファイルURLパス
676          * @return                              なし
677          */
678         function addHeadCssFile($cssFile)
679         {
680                 if (is_array($cssFile)){        // 配列の場合
681                         for ($i = 0; $i < count($cssFile); $i++){
682                                 $destCss = trim($cssFile[$i]);
683                                 if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
684                         }
685                 } else {                // 文字列の場合
686                         $destCss = trim($cssFile);
687                         if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
688                 }
689         }
690         /**
691          * HTMLヘッダに出力するJavascriptライブラリを追加
692          *
693          * @param string,array $scriptLib       JavascriptライブラリID
694          * @return                                      なし
695          */
696         function addHeadAdminScriptLib($scriptLib)
697         {
698                 if (is_array($scriptLib)){      // 配列の場合
699                         for ($i = 0; $i < count($scriptLib); $i++){
700                                 $destScript = trim($scriptLib[$i]);
701                                 if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
702                         }
703                 } else {                // 文字列の場合
704                         $destScript = trim($scriptLib);
705                         if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
706                 }
707         }
708         /**
709          * HTMLヘッダに出力するJavascriptライブラリを追加
710          *
711          * @param string,array $scriptLib       JavascriptライブラリID
712          * @return                                      なし
713          */
714         function addHeadScriptLib($scriptLib)
715         {
716                 if (is_array($scriptLib)){      // 配列の場合
717                         for ($i = 0; $i < count($scriptLib); $i++){
718                                 $destScript = trim($scriptLib[$i]);
719                                 if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
720                         }
721                 } else {                // 文字列の場合
722                         $destScript = trim($scriptLib);
723                         if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
724                 }
725         }
726         /**
727          * HTMLヘッダに出力するJavascriptファイルを追加
728          *
729          * @param string,array $scriptFile      JavascriptファイルURLパス
730          * @return                                      なし
731          */
732         function addHeadScriptFile($scriptFile)
733         {
734                 if (is_array($scriptFile)){     // 配列の場合
735                         for ($i = 0; $i < count($scriptFile); $i++){
736                                 $destScript = trim($scriptFile[$i]);
737                                 if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
738                         }
739                 } else {                // 文字列の場合
740                         $destScript = trim($scriptFile);
741                         if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
742                 }
743         }
744         /**
745          * HTMLヘッダに出力するJavascriptファイル(jQueryMobile用挿入ファイル)を追加
746          *
747          * @param string,array $scriptFile      JavascriptファイルURLパス
748          * @return                                      なし
749          */
750         function addHeadPreMobileScriptFile($scriptFile)
751         {
752                 if (is_array($scriptFile)){     // 配列の場合
753                         for ($i = 0; $i < count($scriptFile); $i++){
754                                 $destScript = trim($scriptFile[$i]);
755                                 if (!empty($destScript) && !in_array($destScript, $this->headPreMobileScriptFiles)) $this->headPreMobileScriptFiles[] = $destScript;
756                         }
757                 } else {                // 文字列の場合
758                         $destScript = trim($scriptFile);
759                         if (!empty($destScript) && !in_array($destScript, $this->headPreMobileScriptFiles)) $this->headPreMobileScriptFiles[] = $destScript;
760                 }
761         }
762         /**
763          * HTMLヘッダに出力するRSSファイルを追加
764          *
765          * @param array $rssFile        タイトル(title)、配信用URL(href)の連想配列。複数の場合は連想配列の配列。
766          * @return                                      なし
767          */
768         function addHeadRssFile($rssFile)
769         {
770                 // パラメータエラーチェック
771                 if (!is_array($rssFile)) return;
772                 
773                 $line = $rssFile[0];
774                 if (is_array($line)){   // 複数追加の場合
775                         for ($i = 0; $i < count($line); $i++){
776                                 // すでに追加済みかどうかチェック
777                                 $url = trim($line[$i]['href']);
778                                 if (!empty($url)){
779                                         for ($j = 0; $j < count($this->headRssFiles); $j++){
780                                                 $storedUrl = $this->headRssFiles[$j]['href'];
781                                                 if ($url == $storedUrl) break;
782                                         }
783                                         if ($j == count($this->headRssFiles)){          // 見つからないときは追加
784                                                 $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
785                                                                                                                 'title' => $line[$i]['title']);         // タイトル
786                                         }
787                                 }
788                         }
789                 } else {                // 単数追加のとき
790                         // すでに追加済みかどうかチェック
791                         $url = trim($rssFile['href']);
792                         if (!empty($url)){
793                                 for ($i = 0; $i < count($this->headRssFiles); $i++){
794                                         $storedUrl = $this->headRssFiles[$i]['href'];
795                                         if ($url == $storedUrl) break;
796                                 }
797                                 if ($i == count($this->headRssFiles)){          // 見つからないときは追加
798                                         $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
799                                                                                                         'title' => $rssFile['title']);          // タイトル
800                                 }
801                         }
802                 }
803         }
804         /**
805          * RSSチャンネル部に出力するデータを設定
806          *
807          * @param array $rssData        RSSチャンネル部データ
808          * @return                                      なし
809          */
810         function setRssChannel($rssData)
811         {
812                 if (!empty($rssData)) $this->rssChannel = $rssData;                             // RSSチャンネルデータ
813         }
814         /**
815          * 表示ポジションを表示するかどうか
816          *
817          * @param int $mode   0=ポジション表示しない(通常画面)、1=ポジション表示、2=ウィジェット込みポジション表示
818          */
819         function showPosition($mode)
820         {
821                 $this->showPositionMode = $mode;
822         }
823         /**
824          * 画面レイアウト中かどうか
825          *
826          * @return bool         true=レイアウト中、false=レイアウト中でない
827          */
828         function isLayout()
829         {
830                 return $this->isLayout;                         // 画面レイアウト中かどうか
831         }
832         /**
833          * ウィジェットの単体表示を設定
834          */
835         function showWidget()
836         {
837                 $this->showWidget = true;
838         }
839         /**
840          * ウィジェットの単体表示を取得
841          *
842          * @param bool          true=単体表示、false=単体表示でない
843          */
844         function getShowWidget()
845         {
846                 return $this->showWidget;
847         }
848         /**
849          * システム制御遷移モードを設定
850          *
851          * @param int $mode   0=設定なし、1=ログイン画面、10=サイト非公開、11=アクセス不可、12=存在しないページ
852          */
853         function setSystemHandleMode($mode)
854         {
855                 $this->systemHandleMode = $mode;
856         }
857         /**
858          * システム制御遷移モード取得
859          */
860         function getSystemHandleMode()
861         {
862                 return $this->systemHandleMode;
863         }
864         /**
865          * フロント画面編集モードを設定
866          *
867          * @return                              なし
868          */
869         function setEditMode()
870         {
871                 $this->isEditMode = true;
872         }
873         /**
874          * フロント画面編集モードを取得
875          *
876          * @return bool         true=編集モードオン、false=編集モードオフ
877          */
878         function idEditMode()
879         {
880                 return $this->isEditMode;
881         }
882         /**
883          * 出力フォーマットがHTMLであるかを設定
884          *
885          * @param bool $isHtml  HTMLフォーマットかどうか
886          * @return                              なし
887          */
888         function setOutputByHtml($isHtml)
889         {
890                 $this->outputByHtml = $isHtml;
891         }
892         
893         /**
894          * AJAX用のレスポンスボディデータかどうかを設定
895          *
896          * @param bool $isResponseBody  レスポンスボディデータかどうか
897          * @return                                              なし
898          */     
899         function setOutputAjaxResponseBody($isResponseBody)
900         {
901                 $this->outputAjaxResponseBody = $isResponseBody;
902         }
903         /**
904          * ヘルプ機能の使用可否を設定
905          *
906          * @param bool $status  ヘルプ機能を使用するかどうか
907          * @return                              なし
908          */
909         function setUseHelp($status)
910         {
911                 $this->useHelp = $status;
912         }
913         /**
914          * ヘルプ機能の使用可否を取得
915          *
916          * @return bool ヘルプ機能を使用するかどうか
917          */
918         function getUseHelp()
919         {
920                 return $this->useHelp;
921         }
922         /**
923          * 表示するコンテンツにGoogleマップが含まれているかを設定
924          *
925          * @param bool $status  Googleマップを含むかどうか
926          * @return                              なし
927          */
928         function setIsContentGooglemaps($status)
929         {
930                 $this->isContentGooglemaps = $status;           // コンテンツにGoogleマップが含むかどうか
931         }
932         /**
933          * 表示するコンテンツにGoogleマップが含まれているかを取得
934          *
935          * @return bool ヘルプ機能を使用するかどうか
936          */
937         function isContentGooglemaps()
938         {
939                 return $this->isContentGooglemaps;
940         }
941         /**
942          * JavaScriptのブラウザキャッシュの使用可否を設定
943          *
944          * @param bool $status  ブラウザキャッシュを使用するかどうか
945          * @return                              なし
946          */
947         function setHasScriptCache($status)
948         {
949                 $this->hasScriptCache = $status;
950         }
951         /**
952          * Bootstrapを使用に設定
953          *
954          * @return                              なし
955          */
956         function useBootstrap()
957         {
958                 $this->useBootstrap = true;                             // Bootstrapを使用するかどうか
959         }
960         /**
961          * Bootstrapを強制的に未使用に設定
962          *
963          * @return                              なし
964          */
965         function cancelBootstrap()
966         {
967                 $this->useBootstrap = false;                            // Bootstrapを使用するかどうか
968         }
969         /**
970          * Bootstrap使用状況を取得
971          *
972          * @return bool                 true=使用、false=使用しない
973          */
974         function getUseBootstrap()
975         {
976                 return $this->useBootstrap;                             // Bootstrapを使用するかどうか
977         }
978         /**
979          * HTML5を使用に設定
980          *
981          * @return                              なし
982          */
983         function setHtml5()
984         {
985                 $this->isHtml5 = true;                                  // HTML5で出力するかどうか
986         }
987         /**
988          * ページ作成処理を中断するかどうかを取得
989          *
990          * @return bool         true=中断、false=継続
991          */
992         function isPageAbort()
993         {
994                 return $this->isAbort;
995         }
996         /**
997          * 現在のウィジェットのポジションを取得
998          *
999          * @param string $pos           ポジション
1000          * @param int    $index         インデックス番号
1001          * @return                      なし
1002          */
1003         function getCurrentWidgetPosition(&$pos, &$index)
1004         {
1005                 $pos = $this->currentWidgetPosition;                    // 現在のウィジェットのポジション
1006                 $index = $this->currentWidgetIndex;                     // 現在のウィジェットのポジション番号
1007         }
1008         /**
1009          * 親ウィンドウを再描画
1010          *
1011          * @param int $defSerial        ページ定義シリアル番号
1012          * @return                                      なし
1013          */
1014         function updateParentWindow($defSerial = 0)
1015         {
1016                 $this->updateParentWindow = true;
1017                 $this->updateDefSerial = $defSerial;                    // 更新する項目のページ定義シリアル番号
1018         }
1019         /**
1020          * CSSファイルの追加
1021          *
1022          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1023          * @return                              なし
1024          */
1025         function addCssFile($path)
1026         {
1027                 $destPath = trim($path, '/');
1028                 if (!in_array($destPath, $this->defaultCssFiles)) $this->defaultCssFiles[] = $destPath;
1029         }
1030         /**
1031          * CSSファイルの追加
1032          *
1033          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
1034          * @return                              なし
1035          */
1036         function addAdminCssFile($path)
1037         {
1038                 $destPath = trim($path, '/');
1039                 if (!in_array($destPath, $this->defaultAdminCssFiles)) $this->defaultAdminCssFiles[] = $destPath;
1040         }
1041         /**
1042          * 編集エリア用のCSSファイルの追加
1043          *
1044          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
1045          * @return                              なし
1046          */
1047         function addCkeditorCssFile($path)
1048         {
1049                 $destPath = trim($path, '/');
1050                 if (!in_array($destPath, $this->ckeditorCssFiles)) $this->ckeditorCssFiles[] = $destPath;
1051         }
1052         /**
1053          * JavaScriptファイルの追加
1054          *
1055          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1056          * @return                              なし
1057          */
1058         function addScriptFile($path)
1059         {
1060                 $destPath = trim($path, '/');
1061                 if (!empty($destPath) && !in_array($destPath, $this->defaultScriptFiles)) $this->defaultScriptFiles[] = $destPath;
1062         }
1063         /**
1064          * JavaScriptファイルの追加
1065          *
1066          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1067          * @return                              なし
1068          */
1069         function addAdminScriptFile($path)
1070         {
1071                 $destPath = trim($path, '/');
1072                 if (!in_array($destPath, $this->defaultAdminScriptFiles)) $this->defaultAdminScriptFiles[] = $destPath;
1073         }
1074         /**
1075          * 追加設定するテンプレートIDを返す
1076          *
1077          * @return array                                                テンプレートID,サブテンプレートIDの配列
1078          */
1079         function getOptionTemplateId()
1080         {
1081                 global $gEnvManager;
1082                 
1083                 // ページ情報取得
1084                 $pageId = $gEnvManager->getCurrentPageId();
1085
1086                 switch ($this->contentType){
1087                         case M3_VIEW_TYPE_CONTENT:              // ページのコンテンツタイプ                         
1088                                 // コンテンツ単位のテンプレート設定
1089                                 $contentLibObj = $this->gInstance->getObject(self::CONTENT_OBJ_ID);
1090                                 if (isset($contentLibObj)) list($this->optionTemplateId, $this->optionSubTemplateId) = $contentLibObj->getOptionTemplate();
1091                                 break;
1092                         case M3_VIEW_TYPE_BLOG:         // ページがブログタイプのとき
1093                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // PCサイトのとき
1094                                         // ブログライブラリオブジェクトからテンプレートを取得
1095                                         $blogLibObj = $this->gInstance->getObject(self::BLOG_OBJ_ID);
1096                                         if (isset($blogLibObj)) list($this->optionTemplateId, $this->optionSubTemplateId) = $blogLibObj->getOptionTemplate();
1097                                 }
1098                                 break;
1099                 }
1100                 return array($this->optionTemplateId, $this->optionSubTemplateId);
1101         }
1102         /**
1103          * 使用した非共通ウィジェットの数を取得
1104          *
1105          * @return int                          ウィジェット数
1106          */
1107         function getNonSharedWidgetCount()
1108         {
1109                 return $this->nonSharedWidgetCount;
1110         }
1111         /**
1112          * ページのコンテンツタイプを取得
1113          *
1114          * @return string                       コンテンツタイプ
1115          */
1116         function getContentType()
1117         {
1118                 return $this->contentType;
1119         }
1120         /**
1121          * フロント画面で使用する主要コンテンツタイプの情報取得
1122          *
1123          * @return array                        コンテンツタイプの情報の連想配列
1124          */
1125         function getMainContentTypeInfo()
1126         {
1127                 return $this->mainContentTypeInfo;                              // 主要コンテンツタイプ
1128         }
1129         /**
1130          * フロント画面で使用する補助コンテンツタイプの情報取得
1131          *
1132          * @return array                        コンテンツタイプの情報の連想配列
1133          */
1134         function getSubContentTypeInfo()
1135         {
1136                 return $this->subContentTypeInfo;                               // 補助コンテンツタイプ
1137         }
1138         /**
1139          * フロント画面で使用する主要コンテンツタイプを取得
1140          *
1141          * @return array                        コンテンツタイプの配列
1142          */
1143         function getMainContentTypes()
1144         {
1145                 // 「value」値のみ取得
1146                 return array_map(create_function('$a', 'return $a["value"];'), $this->mainContentTypeInfo);
1147         }
1148         /**
1149          * フロント画面で使用するサブコンテンツタイプを取得
1150          *
1151          * @return array                        コンテンツタイプの配列
1152          */
1153         function getSubContentTypes()
1154         {
1155                 // 「value」値のみ取得
1156                 return array_map(create_function('$a', 'return $a["value"];'), $this->subContentTypeInfo);
1157         }
1158         /**
1159          * フロント画面で使用する主要機能タイプ情報を取得
1160          *
1161          * @return array                        機能タイプの情報の連想配列
1162          */
1163         function getMainFeatureTypeInfo()
1164         {
1165                 return $this->mainFeatureTypeInfo;                              // 主要機能タイプ
1166         }
1167         /**
1168          * フロント画面で使用する主要機能タイプを取得
1169          *
1170          * @return array                        機能タイプの配列
1171          */
1172         function getMainFeatureTypes()
1173         {
1174                 // 「value」値のみ取得
1175                 return array_map(create_function('$a', 'return $a["value"];'), $this->mainFeatureTypeInfo);
1176         }
1177         
1178         /**
1179          * すべてのページ属性情報を取得
1180          *
1181          * @return array                        ページ属性情報の連想配列
1182          */
1183         function getAllPageAttributeTypeInfo()
1184         {
1185                 return array_merge($this->mainContentTypeInfo, $this->subContentTypeInfo, $this->mainFeatureTypeInfo, $this->adminFeatureTypeInfo);
1186         }
1187         /**
1188          * 管理画面用のサブメニューバーの定義を設定
1189          *
1190          * @param array $def    メニューバー定義
1191          * @return                              なし
1192          */
1193         function setAdminSubNavbarDef($def)
1194         {
1195                 $this->adminSubNavbarDef = $def;
1196         }
1197         /**
1198          * 管理画面用のサブメニューバーの定義を取得
1199          *
1200          * @return array メニューバーの定義
1201          */
1202         function getAdminSubNavbarDef()
1203         {
1204                 return $this->adminSubNavbarDef;
1205         }
1206         /**
1207          * 管理画面用パンくずリスト定義を設定
1208          *
1209          * @param array $def    パンくずリスト定義
1210          * @param array $help   ヘルプ(title,bodyの連想配列)
1211          * @return                              なし
1212          */
1213         function setAdminBreadcrumbDef($def, $help = array())
1214         {
1215                 $this->adminBreadcrumbDef = $def;
1216                 if (!empty($help)) $this->adminBreadcrumbDefHelp = $help;                               // 管理画面用パンくずリストヘルプ定義
1217         }
1218         /**
1219          * 管理画面用パンくずリスト定義を取得
1220          *
1221          * @param array $help   ヘルプ(title,bodyの連想配列)
1222          * @return array                パンくずリスト定義
1223          */
1224         function getAdminBreadcrumbDef(&$help)
1225         {
1226                 // パラメータ数を取得
1227                 $argNum = func_num_args();
1228                 
1229                 // ヘルプ取得用パラメータが存在する場合は定義を設定
1230                 if ($argNum > 0) $help = $this->adminBreadcrumbDefHelp;
1231
1232                 return $this->adminBreadcrumbDef;
1233         }
1234         /**
1235          * ページ作成開始
1236          *
1237          * HTTPヘッダを設定する。セッションを取得する。サブページIDを設定する。
1238          *
1239          * @param RequestManager $request               HTTPリクエスト処理クラス
1240          * @return                                                              なし
1241          */
1242         function startPage($request)
1243         {
1244                 global $gEnvManager;
1245                 global $gRequestManager;
1246                 global $gInstanceManager;
1247                 global $gAccessManager;
1248                 global $gSystemManager;
1249                 global $gDispManager;
1250                 global $gOpeLogManager;
1251                 
1252                 // 実行コマンドを取得
1253                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
1254                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
1255                 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
1256                 $pageId = $gEnvManager->getCurrentPageId();
1257
1258                 // ###### クライアントIDの読み込み、再設定 ######
1259                 // この後、クライアントIDがアクセスログに記録される
1260                 $clientId = $request->getCookieValue(M3_COOKIE_CLIENT_ID);
1261                 if (empty($clientId)){  // クライアントIDが設定されていないとき(初回アクセス)
1262                         // クライアントIDを生成
1263                         $clientId = $this->gAccess->createClientId();
1264                 } else {
1265                         $this->gAccess->setClientId($clientId); // クライアントIDを設定
1266                 
1267                         // クッキーの使用可否を設定
1268                         $this->gEnv->setCanUseCookie(true);
1269                 }
1270                 $request->setCookieValue(M3_COOKIE_CLIENT_ID, $clientId, M3_COOKIE_EXPIRE_CLIENT_ID);
1271                         
1272                 // インストール時の管理画面用ライブラリを追加(フレームコンテナでの設定を反映)
1273                 if (defined('M3_STATE_IN_INSTALL')){
1274                         // Bootstrapライブラリ追加
1275                         if ($this->useBootstrap){
1276                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
1277                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
1278                         }
1279                 } else {
1280                         // 管理者キーがあればGETまたはPOST値のセッションIDを使用する
1281                         if ($gEnvManager->isAdminDirAccess()){
1282                                 if ($gAccessManager->isValidAdminKey()) session_id($gRequestManager->trimValueOf(session_name()));
1283                         }
1284                 }
1285
1286                 // 最終HTML(ページ全体で使用するHTML)の出力
1287                 if ($cmd == M3_REQUEST_CMD_CSS){                // CSS生成のとき
1288                         $gRequestManager->stopSessionUpdate();                  // セッションの更新を停止
1289                 }
1290                 
1291                 // セッション変数を取得可能にする
1292                 session_start();
1293                 
1294                 // ##### インストール時はここで終了 #####
1295                 if (defined('M3_STATE_IN_INSTALL')) return;             // インストール時は実行しない
1296                 
1297                 // セッションを再生成する(セキュリティ対策)
1298                 if ($gSystemManager->regenerateSessionId()){
1299                         $gAccessManager->setOldSessionId(session_id());         // 古いセッションIDを保存
1300                         session_regenerate_id(true);
1301                 }
1302                 
1303                 // セッションからユーザ情報を取得
1304                 $userInfo = $gRequestManager->getSessionValueWithSerialize(M3_SESSION_USER_INFO);
1305                 if (!$gAccessManager->checkSessionSecurity($userInfo)) return;                  // セキュリティ問題ありの場合はここで終了
1306                 // ##### ここで終了した場合はページサブIDが未設定のためページ不正のエラーが発生しアクセスエラー画面が表示される #####
1307                 
1308                 // ##### POST時のリファラーチェック #####
1309                 // WooCommerceのAJAX処理が通らないのでチェックしない?
1310 /*              if ($gRequestManager->isPostMethod() && !$this->_checkReferer()){
1311                         $errMsg = '不正なPOSTデータ(リファラー異常)を検出しました。アクセス元IP: ' . $gAccessManager->getClientIp();
1312                         $msgDetail = 'アクセスをブロックしました。account=' . $userInfo->account . ', userid=' . $userInfo->userId;
1313                         $gOpeLogManager->writeUserError(__METHOD__, $errMsg, 2210, $msgDetail);
1314                         return;
1315                 }*/
1316                 
1317                 // その他セッション情報取得
1318                 $gRequestManager->_doSessionOpenEventCallback();
1319
1320                 // ユーザ情報をロード
1321                 $gInstanceManager->setUserInfo($userInfo);
1322
1323                 // ##### 自動ログイン #####
1324                 // ログイン中でない場合は自動ログインでユーザ情報を取得
1325                 $gAccessManager->startAutoLogin();
1326                 
1327                 // デバッグモードの表示
1328                 if (M3_SYSTEM_DEBUG) echo 'Debug mode<br />';
1329                 
1330                 // ##### ページIDの修正 #####
1331                 // ポジション表示の場合はページID、ページサブIDを再設定。再設定はシステム管理者のみ可能。
1332                 if (($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                                    // 管理画面(ウィジェットなしポジション表示)のとき
1333                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) &&            // 管理画面(ウィジェット付きポジション表示)のとき
1334                         $gEnvManager->isSystemAdmin()){
1335
1336                         $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1337                         if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId();          // 値がないときはデフォルトのページIDを設定
1338                         $this->gEnv->setCurrentPageId($pageId);
1339                         $subId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1340                         if (!empty($subId)) $this->gEnv->setCurrentPageSubId($subId);
1341                 }
1342                 
1343                 // ##### サブページIDの設定 #####
1344                 if ($gEnvManager->isAdminDirAccess() &&         // 管理画面へのアクセスのとき
1345                         ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT)){                               // ログイン、ログアウト場合は管理画面のページサブIDを指定
1346                         $subId = $gEnvManager->getAdminDefaultPageSubId();              // 管理画面用のデフォルトページサブID
1347                 } else {
1348                         if (empty($subId)) $subId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);// ページサブIDを取得
1349                         
1350                         if (empty($subId)){                     // サブページIDが設定されていないとき
1351                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1352                                 $params = $gRequestManager->getQueryArray();
1353                                 $paramCount = count($params);
1354
1355                                 // コマンド以外のパラメータ数が1つだけのときはパラメータからページ属性を判断する
1356                                 // 値が空でもキーがあれば属性を持つとする
1357                                 if ($paramCount == 0){
1358                                         $this->isPageTopUrl = true;                     // ページトップ(サブページ内のトップ位置)のURLかどうか
1359                                         
1360                                         if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemAdmin() && empty($task)){
1361                                                 // ダッシュボード機能は、パラメータなし、管理者ディレクトリ、システム管理者の条件で使用可能
1362                                                 // POST値にタスクがある場合はダッシュボードとしない
1363                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_DASHBOARD, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1364                                         }
1365                                 } else if ($paramCount > 0 && !$gEnvManager->isAdminDirAccess()){               // パラメータ付きの場合(2013/3/23)
1366                                         // ##### ページ属性から画面を選択(管理画面は対応しない) ###
1367                                         // 最初のURLパラメータでコンテンツを判断
1368                                         // プレビュー(cmd=preview)等のパターンで複数パラメータがある
1369                                         reset($params);
1370                                         $firstKey = key($params);
1371                                         $firstValue = $params[$firstKey];
1372
1373                                         if (!empty($firstValue)){               // 「key=value」の形式であること
1374                                                 switch ($firstKey){
1375                                                         case M3_REQUEST_PARAM_CONTENT_ID:               // コンテンツIDのとき
1376                                                         case M3_REQUEST_PARAM_CONTENT_ID_SHORT:
1377                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1378                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1379                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1380                                                         
1381                                                                 // ローカルメニューのURLからページを特定。ページが特定できないときはページ属性で取得。
1382                                                                 $url = $gEnvManager->getMacroPath($gEnvManager->getCurrentRequestUri());
1383                                                                 $ret = $this->db->getSubPageIdByMenuItemUrl($url, $gEnvManager->getCurrentPageId(), M3_VIEW_TYPE_CONTENT, $rows);
1384                                                                 if ($ret){
1385                                                                         $rowCount = count($rows);
1386                                                                         for ($i = 0; $i < $rowCount; $i++){
1387                                                                                 // コンテンツを表示するウィジェットがあるときはページサブIDを確定
1388                                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);
1389                                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);// コンテンツタイプでの取得に変更(2012/6/20)
1390                                                                                 if (!empty($widgetId)){
1391                                                                                         $subId = $rows[$i]['pd_sub_id'];
1392                                                                                         break;
1393                                                                                 }
1394                                                                         }
1395                                                                 }
1396                                                                 if (empty($subId)) $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_CONTENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1397                                                                 $this->contentType = M3_VIEW_TYPE_CONTENT;              // ページのコンテンツタイプ
1398                                                                 
1399                                                                 // コンテンツ詳細ページかどうかを設定
1400                                                                 if ($firstKey == M3_REQUEST_PARAM_CONTENT_ID || $firstKey == M3_REQUEST_PARAM_CONTENT_ID_SHORT) $this->isContentDetailPage = true;
1401                                                                 break;
1402                                                         case M3_REQUEST_PARAM_PRODUCT_ID:       // 製品IDのとき
1403                                                         case M3_REQUEST_PARAM_PRODUCT_ID_SHORT:
1404                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1405                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1406                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1407                                                                 
1408                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PRODUCT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1409                                                                 $this->contentType = M3_VIEW_TYPE_PRODUCT;              // ページのコンテンツタイプ
1410                                                                 
1411                                                                 // コンテンツ詳細ページかどうかを設定
1412                                                                 $this->isContentDetailPage = true;
1413                                                                 break;
1414                                                         case M3_REQUEST_PARAM_BBS_ID:           // 掲示板投稿記事のとき
1415                                                         case M3_REQUEST_PARAM_BBS_ID_SHORT:
1416                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID:
1417                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT:
1418                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1419                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1420                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1421                                                                 
1422                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BBS, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1423                                                                 $this->contentType = M3_VIEW_TYPE_BBS;          // ページのコンテンツタイプ
1424                                                                 
1425                                                                 // コンテンツ詳細ページかどうかを設定
1426                                                                 if ($firstKey == M3_REQUEST_PARAM_BBS_THREAD_ID || $firstKey == M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT) $this->isContentDetailPage = true;
1427                                                                 break;
1428                                                         case M3_REQUEST_PARAM_EVENT_ID:         // イベント記事のとき
1429                                                         case M3_REQUEST_PARAM_EVENT_ID_SHORT:
1430                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1431                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1432                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1433                                                                 
1434                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_EVENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1435                                                                 $this->contentType = M3_VIEW_TYPE_EVENT;                // ページのコンテンツタイプ
1436                                                                 
1437                                                                 // コンテンツ詳細ページかどうかを設定
1438                                                                 $this->isContentDetailPage = true;
1439                                                                 break;
1440                                                         case M3_REQUEST_PARAM_PHOTO_ID:         // フォトギャラリー写真のとき
1441                                                         case M3_REQUEST_PARAM_PHOTO_ID_SHORT:
1442                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1443                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1444                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1445                                                                 
1446                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PHOTO, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1447                                                                 $this->contentType = M3_VIEW_TYPE_PHOTO;                // ページのコンテンツタイプ
1448                                                                 
1449                                                                 // コンテンツ詳細ページかどうかを設定
1450                                                                 $this->isContentDetailPage = true;
1451                                                                 break;
1452                                                         case M3_REQUEST_PARAM_BLOG_ID:          // ブログIDのとき
1453                                                         case M3_REQUEST_PARAM_BLOG_ID_SHORT:
1454                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID:
1455                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT:
1456                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1457                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1458                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1459                 
1460                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BLOG, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1461                                                                 $this->contentType = M3_VIEW_TYPE_BLOG;         // ページのコンテンツタイプ
1462                                                                 
1463                                                                 // コンテンツ詳細ページかどうかを設定
1464                                                                 if ($firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT) $this->isContentDetailPage = true;
1465                                                                 break;
1466                                                         case M3_REQUEST_PARAM_ROOM_ID:          // ユーザ作成コンテンツのとき
1467                                                         case M3_REQUEST_PARAM_ROOM_ID_SHORT:
1468                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1469                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1470                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1471                                                                 
1472                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_USER, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1473                                                                 $this->contentType = M3_VIEW_TYPE_USER;         // ページのコンテンツタイプ
1474                                                 
1475                                                                 // コンテンツ詳細ページかどうかを設定
1476                                                                 $this->isContentDetailPage = true;
1477                                                                 
1478                                                                 // コンテンツを表示するウィジェットを取得
1479                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);
1480                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);// コンテンツタイプでの取得に変更(2012/6/20)
1481                                                                 if (!empty($widgetId)){
1482                                                                         // ルーム用の定義ID(所属グループID)を取得
1483                                                                         $roomId = isset($params[M3_REQUEST_PARAM_ROOM_ID]) ? $params[M3_REQUEST_PARAM_ROOM_ID] : $params[M3_REQUEST_PARAM_ROOM_ID_SHORT];
1484                                                                         $configId = $this->db->getWidgetConfigIdForRoom($roomId);
1485
1486                                                                         // グループIDを定義IDとするページのページサブIDを取得
1487                                                                         $subPageId = $this->getPageSubIdByWidget($gEnvManager->getCurrentPageId(), $widgetId, $configId);
1488                                                                         if (!empty($subPageId)) $subId = $subPageId;
1489                                                                 }
1490                                                                 break;
1491                                                         default:                // オプションのURLコンテンツパラメータからサブページIDを取得
1492                                                                 $ret = $this->db->getSubPageIdByUrlContentParam($gEnvManager->getCurrentPageId(), $firstKey, $row);
1493                                                                 if ($ret) $subId = $row['pd_sub_id'];
1494                                                                 break;
1495                                                 }
1496                                         }
1497                                 }
1498
1499                                 // wiki用パラメータの取得
1500                                 if (empty($subId)){
1501                                         // 「http://www.example.com?ページ名」「wcmd」の場合はwikiコンテンツページを選択
1502                                         $wikiCmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND);
1503                                         $pageName = $gRequestManager->getWikiPageFromQuery();           // 「=」なしのパラメータはwikiパラメータとする
1504                         
1505                                         if (!empty($wikiCmd) || !empty($pageName)){                     // Wikiコンテンツページを指定のとき
1506                                                 // ページサブIDを取得
1507                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_WIKI, $gEnvManager->getCurrentPageId());
1508                                                 $this->contentType = M3_VIEW_TYPE_WIKI;         // ページのコンテンツタイプ
1509                                                 
1510                                                 // コンテンツ詳細ページかどうかを設定
1511                                                 $this->isContentDetailPage = true;
1512                                         }
1513                                 }
1514                                 // その他のGET,POSTパラメータからページサブID取得
1515                                 if (empty($subId)){
1516                                         // 検索用パラメータなどでリダイレクト先のURLが取得できた場合は遷移
1517                                         $subId = $this->getPageSubIdByParam($request, $redirectUrl);
1518                                         if (!empty($subId) && !empty($redirectUrl)) $this->redirect($redirectUrl);
1519                                 }
1520                                 
1521                                 // ページサブIDが取得できない場合はデフォルトを使用
1522                                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
1523                         } else {                // ページサブIDが設定されているとき
1524                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1525                                 $params = $gRequestManager->getQueryArray();
1526                                 $paramCount = count($params);
1527                                 if ($paramCount == 1) $this->isPageTopUrl = true;                       // ページトップ(サブページ内のトップ位置)のURLかどうか
1528                         }
1529                 }
1530                 $gEnvManager->setCurrentPageSubId($subId);// サブページIDを設定
1531                 
1532                 // SSL通信機能がオンの場合は、アクセスされたURLのSSLをチェックし不正の場合は正しいURLにリダイレクト
1533                 // 設定に間違いがある場合、管理画面にアクセスできなくなるので、フロント画面のみ制御
1534 //              if ($gEnvManager->getUseSsl() || $gEnvManager->getUseSslAdmin()){
1535                 if ($gEnvManager->getUseSsl()){                 // フロント画面のSSL設定のみチェック(2016/7/30)
1536                         if (!$gEnvManager->isAdminDirAccess()){         // 管理画面以外へのアクセスのとき
1537                                 // ルートURLがSSLの場合はSSLに固定
1538                                 if ($gEnvManager->isRootUrlSsl()){              // ルートURLがSSLの場合はフロント画面のすべてがSSL付き
1539                                         $isSsl = true;
1540                                 } else {
1541                                         $isSsl = $gEnvManager->isSslByCurrentPage();
1542                                 }
1543                                 $currentUrl = $gEnvManager->getCurrentRequestUri();
1544                                 if ($isSsl){
1545                                         $correctUrl = str_replace('http://', 'https://', $currentUrl);
1546                                 } else {
1547                                         $correctUrl = str_replace('https://', 'http://', $currentUrl);
1548                                 }
1549                                 if ($currentUrl != $correctUrl) $this->redirect($correctUrl);
1550                         }
1551                 }
1552                 // マルチドメイン用設定初期化
1553                 $gEnvManager->initMultiDomain();
1554                 
1555                 // 画面設定取得
1556                 $gDispManager->load();
1557                         
1558                 // ##### 画面に必要なスクリプトを追加 #####
1559                 // スマートフォン用URLのときはスマートフォン用のjQueryを使用
1560                 if ($gEnvManager->getIsSmartphoneSite()){
1561                         $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(10);                   // スマートフォン用jQueryファイル
1562                         
1563                         if (isset($this->libFiles[ScriptLibInfo::LIB_JQUERYS_MOBILE]['script'])){
1564                                 $scriptFiles = $this->libFiles[ScriptLibInfo::LIB_JQUERYS_MOBILE]['script'];
1565                                 if (count($scriptFiles) > 0) $this->selectedJQueryMobileFilename = $scriptFiles[0];             // 使用対象のjQueryMobileファイル
1566                         }
1567                 }
1568                 
1569                 // Magic3管理用のスクリプトを追加
1570                 if (!$gEnvManager->getIsMobileSite()){          // 携帯用URL以外のとき
1571                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
1572                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
1573 //                                      $this->isEditMode = true;                       // フロント画面編集モード
1574                                         $this->isPageEditable = true;           // フロント画面ページ編集可能モードに設定(コンテキストメニュー表示)
1575                                                 
1576                                         // 管理画面用ライブラリを追加
1577                                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1578                                                 $this->addAdminScript('', ScriptLibInfo::getWysiwygEditorLibId());      // WYSIWYGエディターを追加
1579                                                 
1580                                                 // Googleマップライブラリの読み込み
1581                                                 if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1582                                                         $this->defaultAdminScriptFiles[] = ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS);
1583                                                 }
1584                                         } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // 管理画面(ウィジェット付きポジション表示)のとき
1585                                                 $this->isLayout = true;         // 画面レイアウト中かどうか
1586                                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_IDTABS);                    // 管理パネル用スクリプト追加(ポジション表示追加分)
1587                                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_DROPDOWN);               // 管理パネル用スクリプト追加(ドロップダウンメニュー)
1588                                                 //$this->useBootstrap = true;           // Bootstrapを使用
1589                                                 //$this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);             // パネルメニュー(フロント画面と管理画面の切り替え等)用
1590                                         }
1591                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1592                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1593                                         
1594                                         // スクリプトが必要なウィジェットをすべて取得
1595                                         $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1596                                         for ($i = 0; $i < count($rows); $i++){
1597                                                 $this->addAdminScript($task, trim($rows[$i]['wd_add_script_lib']));
1598                                         }
1599                                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1600                                                 // ウィジェット情報取得
1601                                                 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
1602                                                 $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
1603                                                 if ($ret) $this->addAdminScript($task, trim($this->configWidgetInfo['wd_add_script_lib_a']));           // 管理機能用スクリプト
1604                                         }
1605                                 }
1606                         } else {                // フロント画面へのアクセスのとき
1607                                 // フロント画面用スクリプトファイル追加
1608                                 $value = $gSystemManager->getSystemConfig(self::CF_USE_JQUERY);// 常にjQueryを使用するかどうか
1609                                 if ($value) $this->addScriptFile($this->selectedJQueryFilename);
1610                 
1611                                 if ($cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                 // ウィジェット単体実行でない
1612                                         $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
1613                                         if ($gEnvManager->isSystemManageUser()){
1614                                                 $this->isEditMode = true;                       // フロント画面編集モード
1615                                                 $this->isPageEditable = true;           // フロント画面ページ編集可能モードに設定
1616                                         
1617                                                 // システム運用権限がある場合は管理用スクリプトを追加
1618                                                 // フロント画面と管理画面の切り替え用のスライドメニューバーには管理用スクリプト,CSSが必要
1619                                                 $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1620                                                 $this->addScriptFile(ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME);               // jQuery Contextmenu Lib
1621                                                 $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1622                                                 //$this->addScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);          // パネルメニュー(フロント画面と管理画面の切り替え等)用
1623                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);  // 管理パネル用スクリプト追加
1624                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_COOKIE);                 // 管理パネル用スクリプト追加
1625                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_EASING);                 // 管理パネル用スクリプト追加
1626                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1627                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1628                                         
1629                                                 $this->addCssFile(self::M3_ADMIN_CSS_FILE);             // 管理機能用CSS
1630                                         } else if ($gEnvManager->isContentEditableUser()){              // コンテンツ編集可能ユーザの場合
1631                                                 $this->isEditMode = true;                       // フロント画面編集モード
1632                                         }
1633                                 } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
1634                                         if ($gEnvManager->isContentEditableUser()){             // コンテンツ編集可能ユーザの場合
1635                                                 $this->isEditMode = true;                       // フロント画面編集モード
1636                                         
1637 //                                              $this->addScript('', ScriptLibInfo::LIB_JQUERY_RESPONSIVETABLE);// 管理画面作成用
1638                                                 $this->addScript('', ScriptLibInfo::getWysiwygEditorLibId());   // WYSIWYGエディターを追加
1639                                         //      $this->addScriptFile(self::M3_PLUS_SCRIPT_FILENAME);            // フロント画面追加用スクリプト追加(PLUSライブラリを追加する場合はFCKEditorも使用可能にする)
1640                                                 $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1641                                                 $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
1642                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1643                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1644                                                 
1645                                                 // Googleマップライブラリの読み込み
1646                                                 if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1647                                                         $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));
1648                                                 }
1649                                         }
1650                                 }
1651                         }
1652                 }
1653
1654                 // デフォルトのページ情報を取得
1655                 $row = $this->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
1656                 if (!empty($row)){
1657                         // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1658                         if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1659                 
1660                         // 現在のページ情報を設定
1661                         $this->currentPageInfo = $row;                  // 現在のページのページ情報
1662                 }
1663                         
1664                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)のとき
1665 /*                      $defPageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1666                         $defPageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1667                         
1668                         // デフォルトのページ情報を取得
1669                         $row = $this->getPageInfo($defPageId, $defPageSubId);
1670                         if (!empty($row)){
1671                                 // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1672                                 if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1673                         
1674                                 // 現在のページ情報を設定
1675                                 $this->currentPageInfo = $row;                  // 現在のページのページ情報
1676                         }*/
1677                         
1678                         // テンプレートの情報を取得
1679         //              $ret = $this->db->getPageDefOnPage($defPageId, $defPageSubId, $rows);
1680                         $ret = $this->db->getPageDefOnPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1681                         if ($ret){
1682                                 for ($i = 0; $i < count($rows); $i++){
1683                                         $position = $rows[$i]['pd_position_id'];
1684                                         if (!in_array($position, $this->defPositions)) $this->defPositions[] = $position;       // 画面定義データのポジション(すべて)
1685                                 }
1686                         }
1687                 }
1688                 
1689                 // 画面透過モードを設定
1690                 if ($openBy == 'tabs') $this->isTransparentMode = true;         // 画面透過モード
1691         }
1692         /**
1693          * URLの最初のパラメータが不正文字の場合はエラー画面へリダイレクト
1694          *
1695          * @param string $value                 URLの最初のパラメータ値
1696          * @return bool                                 true=正常、false=異常
1697          */
1698         function _checkFirstValueRedirect($value)
1699         {
1700                 global $gEnvManager;
1701                 global $gOpeLogManager;
1702                 
1703                 // 半角英小文字大文字、数字、アンダーバー、ハイフン、カンマのみ使用可能。
1704                 if (preg_match("/[^0-9a-zA-Z-_,]/", $value)){
1705                         $errMessage = 'URLパラメータの不正。';
1706                         $gOpeLogManager->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2200, 'アクセスをブロックしました。URL: ' . $gEnvManager->getCurrentRequestUri());
1707                         
1708         //              $this->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
1709                         // システム制御ページへ遷移
1710                         $this->isSystemPage = true;
1711                         return false;
1712                 } else {
1713                         return true;
1714                 }
1715         }
1716         /**
1717          * 言語に依存する情報を取り込む
1718          *
1719          * @return                                                      なし
1720          */
1721         function loadLang()
1722         {
1723                 global $gEnvManager;
1724                 global $gSystemManager;
1725                 
1726                 $lang = $gEnvManager->getCurrentLanguage();
1727                 
1728                 // デフォルト言語とカレント言語が異なる場合のみ実行
1729                 if ($lang != $gEnvManager->getDefaultLanguage()){
1730                         // 指定言語のサイト定義取得
1731                         $gSystemManager->roadSiteDefByLang($lang);
1732                 }
1733                 
1734                 // 現在の言語でヘッダ初期化
1735                 $this->headDescription  = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_DESCRIPTION);    // HTMLヘッダ「description」に出力する文字列
1736                 $this->headKeywords             = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_KEYWORDS);               // HTMLヘッダ「keywords」に出力する文字列
1737                 $this->headOthers               = $gSystemManager->getSiteDef(self::SD_HEAD_OTHERS);                    // HTMLヘッダに出力するタグ文字列
1738
1739                 // デフォルトのページ情報でヘッダを更新
1740                 if (!empty($this->currentPageInfo)){
1741                         $title          = $this->currentPageInfo['pn_meta_title'];              // 画面タイトル
1742                         $desc           = $this->currentPageInfo['pn_meta_description'];                // ページ要約
1743                         $keyword        = $this->currentPageInfo['pn_meta_keywords'];           // ページキーワード
1744                         $headOthers     = $this->currentPageInfo['pn_head_others'];             // ヘッダその他タグ
1745                         
1746                         if (!empty($title)) $this->setHeadSubTitle($title);
1747                         if (!empty($desc)) $this->setHeadDescription($desc);
1748                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1749                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1750                 }
1751
1752                 // 現在の言語のページ情報でヘッダを更新
1753                 $ret = $this->db->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $lang, $row);
1754                 if ($ret){
1755                         $title          = $row['pn_meta_title'];                // 画面タイトル
1756                         $desc           = $row['pn_meta_description'];          // ページ要約
1757                         $keyword        = $row['pn_meta_keywords'];             // ページキーワード
1758                         $headOthers = $row['pn_head_others'];           // ヘッダその他タグ
1759                         
1760                         if (!empty($title)) $this->setHeadSubTitle($title);
1761                         if (!empty($desc)) $this->setHeadDescription($desc);
1762                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1763                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1764                         
1765                         // 現在のページ情報を設定
1766 //                      $this->currentPageInfo = $row;                  // 現在のページのページ情報
1767                 }
1768         }
1769         /**
1770          * スクリプト追加情報から、管理機能用のJavascriptファイル、CSSを追加する
1771          *
1772          * @param string $task                          指定タスク
1773          * @param string $scriptInfo            スクリプト追加情報
1774          * @return                                                      なし
1775          */
1776         function addAdminScript($task, $scriptInfo)
1777         {
1778                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1779                 for ($i = 0; $i < count($itemArray); $i++){
1780                         $pos = strpos($itemArray[$i], '=');
1781                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1782                                 $libs = trim($itemArray[$i]);
1783                         } else {                // タスク指定のとき
1784                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1785                                 $libTask = trim($libTask);
1786                                 $libs = trim($libs);
1787                                 
1788                                 if (strEndsWith($libTask, '_')){                // 「task_subtask」形式のタスクのとき
1789                                         if (!strStartsWith($task, $libTask)) $libs = '';                        // タスクIDの先頭部が異なるときは追加しない
1790                                 } else {
1791                                         if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1792                                 }
1793                         }
1794                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1795                                 $libsArray = explode(',', $libs);
1796                                 for ($j = 0; $j < count($libsArray); $j++){
1797                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1798                                         
1799                                         // ライブラリセットを展開
1800                                         $setLibArray = ScriptLibInfo::getLibSet($lib);
1801                                         $setLibCount = count($setLibArray);
1802                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1803                                                 for ($k = 0; $k < $setLibCount; $k++){
1804                                                         $this->_addAdminScript($setLibArray[$k]);
1805                                                 }
1806                                         } else {
1807                                                 $this->_addAdminScript($lib);
1808                                         }
1809                                 }
1810                         }
1811                 }
1812         }
1813         /**
1814          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
1815          *
1816          * @param string $lib                           ライブラリID
1817          * @return                                                      なし
1818          */
1819         function _addAdminScript($lib)
1820         {
1821                 // ライブラリが存在しないときは終了
1822                 if (!isset($this->libFiles[$lib])) return;
1823                 
1824                 // 依存ライブラリを取得
1825 //              if (strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){         // elFinder、timepickerを使用する場合
1826                 // jQuery UIライブラリを追加
1827                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
1828                 if (isset($dependentLib)){
1829                         for ($i = 0; $i < count($dependentLib); $i++){
1830                                 $addLib = $dependentLib[$i];
1831
1832                                 // ライブラリのファイルを追加
1833                                 if (isset($this->libFiles[$addLib]['script'])){
1834                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1835                                         for ($m = 0; $m < count($scriptFiles); $m++){
1836                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1837                                         }
1838                                 }
1839                                 // ライブラリの言語ファイルを追加
1840                                 if (isset($this->libFiles[$addLib]['script_lang'])){
1841                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);
1842                                         for ($m = 0; $m < count($scriptFiles); $m++){
1843                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1844                                         }
1845                                 }
1846                                 // ライブラリのCSSファイルを追加
1847                                 if (isset($this->libFiles[$addLib]['css'])){
1848                                         $cssFiles = $this->libFiles[$addLib]['css'];
1849                                         for ($m = 0; $m < count($cssFiles); $m++){
1850                                                 $this->addAdminCssFile($cssFiles[$m]);          // 通常機能用のCSS追加
1851                                         }
1852                                 }
1853                         }
1854                         // jQueryUIテーマを追加
1855                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1856                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1857                                 $this->outputTheme = true;
1858                         }
1859                 }
1860
1861                 // Javascript追加
1862                 if (isset($this->libFiles[$lib]['script'])){
1863                         $scriptFiles = $this->libFiles[$lib]['script'];
1864
1865                         // ##### ライブラリ情報を作成する場合 #####
1866                         if (empty($scriptFiles)){
1867                                 $generatedLib = ScriptLibInfo::generateLib($lib);                       // ライブラリ取得
1868                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
1869                         }
1870                         
1871                         for ($i = 0; $i < count($scriptFiles); $i++){
1872                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1873                         }
1874                 }
1875                 // ライブラリの言語ファイルを追加
1876                 if (isset($this->libFiles[$lib]['script_lang'])){
1877                         $scriptFiles = ScriptLibInfo::getLangScript($lib);
1878                         for ($i = 0; $i < count($scriptFiles); $i++){
1879                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1880                         }
1881                 }
1882                 // CSS追加
1883                 if (isset($this->libFiles[$lib]['css'])){
1884                         $cssFiles = $this->libFiles[$lib]['css'];
1885                         for ($i = 0; $i < count($cssFiles); $i++){
1886                                 $this->addAdminCssFile($cssFiles[$i]);          // 管理機能用のCSS追加
1887                         }
1888                 }
1889                 // その他
1890                 if (strncmp($lib, 'jquery-ui.', 10) == 0){              // jQuery UIのwidgetsまたはeffectsのとき。jQuery UI Coreはデフォルトで読み込まれている。
1891                         // jQueryUIテーマを追加
1892                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1893                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1894                                 $this->outputTheme = true;
1895                         }
1896                 }
1897         }
1898         /**
1899          * スクリプト追加情報から、通常機能用のJavascriptファイル、CSSを追加する
1900          *
1901          * @param string $task                          指定タスク
1902          * @param string $scriptInfo            スクリプト追加情報
1903          * @return                                                      なし
1904          */
1905         function addScript($task, $scriptInfo)
1906         {
1907                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1908                 for ($i = 0; $i < count($itemArray); $i++){
1909                         $pos = strpos($itemArray[$i], '=');
1910                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1911                                 $libs = trim($itemArray[$i]);
1912                         } else {                // タスク指定のとき
1913                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1914                                 $libTask = trim($libTask);
1915                                 $libs = trim($libs);
1916                                 if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1917                         }
1918                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1919                                 $libsArray = explode(',', $libs);
1920                                 for ($j = 0; $j < count($libsArray); $j++){
1921                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1922                                         
1923                                         // jQueryライブラリ等、デフォルトでは追加されないライブラリを追加
1924                                         $setLibArray = ScriptLibInfo::getLibSet($lib);// ライブラリセットを展開
1925                                         $setLibCount = count($setLibArray);
1926                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1927                                                 for ($k = 0; $k < $setLibCount; $k++){
1928                                                         $this->_addScript($setLibArray[$k]);
1929                                                 }
1930                                         } else {
1931                                                 $this->_addScript($lib);
1932                                         }
1933                                 }
1934                         }
1935                 }
1936         }
1937         /**
1938          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
1939          *
1940          * @param string $lib                           ライブラリID
1941          * @return                                                      なし
1942          */
1943         function _addScript($lib)
1944         {
1945                 // ライブラリが存在しないときは終了
1946                 if (!isset($this->libFiles[$lib])) return;
1947
1948                 // ライブラリの依存ライブラリファイルを追加
1949                 if (strcmp($lib, 'jquery') == 0){// jQuery本体のとき
1950                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1951                 } else if (strncmp($lib, 'jquery.', 7) == 0){           // jQueryプラグインのとき
1952                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1953                         if (strcmp($lib, 'jquery.mobile') == 0){        // jQueryMobileファイルのとき
1954                                 // ##### jQueryMobileが読み込まれる前に読み込む必要があるスクリプトを設定 #####
1955                                 if (!empty($this->headPreMobileScriptFiles)){           // jQueryMobileファイルの前に出力
1956                                         for ($i = 0; $i < count($this->headPreMobileScriptFiles); $i++){
1957                                                 $this->addScriptFile($this->headPreMobileScriptFiles[$i]);              // 通常機能用のスクリプト追加
1958                                         }
1959                                 }
1960                         } else {
1961                                 // 依存ライブラリ追加
1962                                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
1963                                 if (isset($dependentLib)){
1964                                         for ($i = 0; $i < count($dependentLib); $i++){
1965                                                 $addLib = $dependentLib[$i];
1966                                 
1967                                                 // ライブラリのファイルを追加
1968                                                 if (isset($this->libFiles[$addLib]['script'])){
1969                                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1970                                                         for ($m = 0; $m < count($scriptFiles); $m++){
1971                                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1972                                                         }
1973                                                 }
1974                                                 // ライブラリの言語ファイルを追加
1975                                                 if (isset($this->libFiles[$addLib]['script_lang'])){
1976                                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);
1977                                                         for ($m = 0; $m < count($scriptFiles); $m++){
1978                                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1979                                                         }
1980                                                 }
1981                                                 // ライブラリのCSSファイルを追加
1982                                                 if (isset($this->libFiles[$addLib]['css'])){
1983                                                         $cssFiles = $this->libFiles[$addLib]['css'];
1984                                                         for ($m = 0; $m < count($cssFiles); $m++){
1985                                                                 $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
1986                                                         }
1987                                                 }
1988                                         }
1989                                 }
1990                         }
1991                 } else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI) == 0){    // jQuery UI
1992                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1993                 //} else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI_PLUS) == 0){     // jQuery UI plus
1994                 //      $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1995                 //      $this->addScriptFile($this->selectedJQueryUiFilename);          // jQuery Coreスクリプト追加
1996                 } else if (strncmp($lib, 'jquery-ui.', 10) == 0 ||              // jQuery UIのwidgetsまたはeffectsのとき
1997                         strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){             // elFinder、timepickerを使用する場合
1998
1999                         // 依存ライブラリ追加
2000                         if (strncmp($lib, 'jquery-ui.', 10) == 0){
2001                                 $jQueryUiInfo = ScriptLibInfo::getJQueryUiInfo();// ライブラリ情報取得
2002                                 $dependentLib = $jQueryUiInfo[$lib];            // 依存ライブラリ取得
2003                         } else {
2004                                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
2005                         }
2006                         for ($i = 0; $i < count($dependentLib); $i++){
2007                                 $addLib = $dependentLib[$i];
2008                                 
2009                                 // ライブラリのファイルを追加
2010                                 if (isset($this->libFiles[$addLib]['script'])){
2011                                         $scriptFiles = $this->libFiles[$addLib]['script'];
2012                                         for ($m = 0; $m < count($scriptFiles); $m++){
2013                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
2014                                         }
2015                                 }
2016                                 // ライブラリの言語ファイルを追加
2017                                 if (isset($this->libFiles[$addLib]['script_lang'])){
2018                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);;
2019                                         for ($m = 0; $m < count($scriptFiles); $m++){
2020                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
2021                                         }
2022                                 }
2023                                 // ライブラリのCSSファイルを追加
2024                                 if (isset($this->libFiles[$addLib]['css'])){
2025                                         $cssFiles = $this->libFiles[$addLib]['css'];
2026                                         for ($m = 0; $m < count($cssFiles); $m++){
2027                                                 $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
2028                                         }
2029                                 }
2030                         }
2031                         // jQueryUIテーマを追加
2032                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
2033                                 $this->addCssFile($this->getDefaultThemeUrl());         // 通常機能用のCSS追加
2034                                 $this->outputTheme = true;
2035                         }
2036                 }
2037                 
2038                 // ライブラリ自体のファイルを追加
2039                 if (isset($this->libFiles[$lib]['script'])){
2040                         $scriptFiles = $this->libFiles[$lib]['script'];
2041                         
2042                         // ##### ライブラリ情報を作成する場合 #####
2043                         if (empty($scriptFiles)){
2044                                 $generatedLib = ScriptLibInfo::generateLib($lib);                       // ライブラリ取得
2045                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2046                         }
2047                         
2048                         for ($i = 0; $i < count($scriptFiles); $i++){
2049                                 $this->addScriptFile($scriptFiles[$i]);         // 通常機能用のスクリプト追加
2050                         }
2051                 }
2052                 // ライブラリの言語ファイルを追加
2053                 if (isset($this->libFiles[$lib]['script_lang'])){
2054                         $scriptFiles = ScriptLibInfo::getLangScript($lib);
2055                         for ($i = 0; $i < count($scriptFiles); $i++){
2056                                 $this->addScriptFile($scriptFiles[$i]);         // 通常機能用のスクリプト追加
2057                         }
2058                 }
2059                 // ライブラリのCSSファイルを追加
2060                 if (isset($this->libFiles[$lib]['css'])){
2061                         $cssFiles = $this->libFiles[$lib]['css'];
2062                         for ($i = 0; $i < count($cssFiles); $i++){
2063                                 $this->addCssFile($cssFiles[$i]);               // 通常機能用のCSS追加
2064                         }
2065                 }
2066         }
2067         /**
2068          * 非ログイン時の管理機能用のJavascriptファイル、CSSを追加する
2069          *
2070          * @param array, string         $lib            追加ライブラリID
2071          * @return                                      なし
2072          */
2073         function addPermittedAdminScript($lib)
2074         {
2075                 if (is_array($lib)){
2076                         for ($j = 0; $j < count($lib); $j++){
2077                                 $libId = $lib[$j];
2078                         
2079                                 // Javascript追加
2080                                 if (isset($this->libFiles[$libId]['script'])){
2081                                         $scriptFiles = $this->libFiles[$libId]['script'];
2082                                         
2083                                         // ##### ライブラリ情報を作成する場合 #####
2084                                         if (empty($scriptFiles)){
2085                                                 $generatedLib = ScriptLibInfo::generateLib($libId);                     // ライブラリ取得
2086                                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2087                                         }
2088                         
2089                                         for ($i = 0; $i < count($scriptFiles); $i++){
2090                                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2091                                         }
2092                                 }
2093                                 // ライブラリの言語ファイルを追加
2094                                 if (isset($this->libFiles[$libId]['script_lang'])){
2095                                         $scriptFiles = ScriptLibInfo::getLangScript($libId);
2096                                         for ($i = 0; $i < count($scriptFiles); $i++){
2097                                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2098                                         }
2099                                 }
2100                                 // CSS追加
2101                                 if (isset($this->libFiles[$libId]['css'])){
2102                                         $cssFiles = $this->libFiles[$libId]['css'];
2103                                         for ($i = 0; $i < count($cssFiles); $i++){
2104                                                 $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
2105                                         }
2106                                 }
2107                         }
2108                 } else {
2109                         $libId = $lib;
2110                         
2111                         // Javascript追加
2112                         if (isset($this->libFiles[$libId]['script'])){
2113                                 $scriptFiles = $this->libFiles[$libId]['script'];
2114                                 
2115                                 // ##### ライブラリ情報を作成する場合 #####
2116                                 if (empty($scriptFiles)){
2117                                         $generatedLib = ScriptLibInfo::generateLib($libId);                     // ライブラリ取得
2118                                         if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2119                                 }
2120                         
2121                                 for ($i = 0; $i < count($scriptFiles); $i++){
2122                                         $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2123                                 }
2124                         }
2125                         // ライブラリの言語ファイルを追加
2126                         if (isset($this->libFiles[$libId]['script_lang'])){
2127                                 $scriptFiles = ScriptLibInfo::getLangScript($libId);
2128                                 for ($i = 0; $i < count($scriptFiles); $i++){
2129                                         $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2130                                 }
2131                         }
2132                         // CSS追加
2133                         if (isset($this->libFiles[$libId]['css'])){
2134                                 $cssFiles = $this->libFiles[$libId]['css'];
2135                                 for ($i = 0; $i < count($cssFiles); $i++){
2136                                         $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
2137                                 }
2138                         }
2139                 }
2140         }
2141         /**
2142          * ページ作成終了
2143          *
2144          * ・最終HTML出力
2145          * ・セッション情報の保存
2146          * ・ウィジェットで生成されたHTTPヘッダを設定する
2147          *
2148          * @param RequestManager $request               HTTPリクエスト処理クラス
2149          * @param bool $getOutput                               出力を取得するかどうか
2150          * @return string                                       最終出力HTML
2151          */
2152         function endPage($request, $getOutput = false)
2153         {
2154                 global $gRequestManager;
2155                 global $gInstanceManager;
2156                 global $gEnvManager;
2157                 global $gDispManager;
2158                 global $gAccessManager;
2159                 
2160                 // ページ作成処理を中断するかどうか
2161                 if ($this->isAbort) return '';
2162                 
2163                 $contents = '';
2164                 
2165                 // 実行コマンドを取得
2166                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2167                 
2168                 // 最終HTML(ページ全体で使用するHTML)の出力
2169                 if ($cmd == M3_REQUEST_CMD_CSS){                // CSS生成のとき
2170                         // 外部出力形式でCSS出力
2171                         if (count($this->exportCss) > 0){
2172                                 for ($i = 0; $i < count($this->exportCss); $i++){
2173                                         $contents .= $this->exportCss[$i] . M3_NL;
2174                                 }
2175                         }
2176                         
2177                         // ヘッダ出力
2178                         header('Content-type: text/css');
2179                         
2180                         // 画面情報、ユーザ情報の保存は行わない
2181                         return $contents;
2182                 } else if ($cmd != M3_REQUEST_CMD_DO_WIDGET){           // ウィジェット単体オペレーションのときは出力しない
2183 /*                      if ($getOutput){
2184                                 $contents = $this->getLastContents($request);
2185                         } else {
2186                                 echo $this->getLastContents($request);
2187                         }*/
2188                 }
2189                 
2190                 // セッションへユーザ情報を保存
2191                 $userInfo = $gInstanceManager->getUserInfo();
2192                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
2193                 
2194                 // その他セッション情報保存
2195                 $gRequestManager->_doSessionCloseEventCallback();
2196                 
2197                 // 画面設定保存
2198                 $gDispManager->save();
2199                         
2200                 // キャッシュリミッタは、各リクエスト毎に(アウトプットバッファー が無効な場合は、
2201                 // session_start()がコールされる 前に) session_cache_limiter()をコールする必要がある。
2202                 // キャッシュを残す設定
2203 //              session_cache_limiter('private');
2204 //              session_cache_expire(5);
2205                 if ($this->isRedirect) return '';                       // リダイレクトの場合は終了
2206
2207                 // ########## HTTPヘッダ出力処理 ########
2208                 if (headers_sent($filename, $linenum)){         // HTTPヘッダが既に送信されているとき
2209                         echo "$filename の $linenum 行目でヘッダがすでに送信されています。";
2210                 } else {
2211                         if ($gEnvManager->isMobile()){          // 携帯の場合
2212                                 // ドコモ端末の場合はリクエストヘッダにXHTMLを指定しないとXHTMLを処理しない
2213                                 $agent = $gInstanceManager->getMobileAgent();
2214                                 if ($agent->isDoCoMo()){        // ドコモ端末のとき
2215                                         header('Content-Type: application/xhtml+xml;');
2216                                 }
2217                         } else {
2218                                 // キャッシュを無効にする場合
2219                                 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');// 過去の日付
2220                                 header('Cache-Control: no-store, no-cache, must-revalidate');// HTTP/1.1
2221                                 header('Cache-Control: post-check=0, pre-check=0', false);
2222                                 header('Pragma: no-cache');
2223                 
2224                                 // 更新日時
2225                                 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
2226                 
2227                                 // Ajax用JSON型データをHTTPヘッダに格納
2228                                 $gInstanceManager->getAjaxManager()->header();
2229                         }
2230                         // システム制御画面が設定されている場合はステータスコードを変更
2231                         //if ($this->gEnv->getIsMaintenance()){
2232                         if (!$this->isRedirect){                        // リダイレクトがセットされていない場合
2233                                 switch ($this->systemHandleMode){
2234                                         case 10:                        // サイト非公開(システムメンテナンス)
2235                                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
2236                                                 header('Status: 503 Service Temporarily Unavailable');
2237                                                 break;
2238                                         case 11:                        // アクセス禁止のとき
2239                                                 header('HTTP/1.1 403 Forbidden');
2240                                                 header('Status: 403 Forbidden');
2241                                                 break;
2242                                         case 12:                        // 存在しないページのとき
2243                                                 header("HTTP/1.1 404 Not Found");
2244                                                 header("Status: 404 Not Found");
2245                                                 break;
2246                                 }
2247                         }
2248                 }
2249                 // ##### 自動ログイン #####
2250                 $gAccessManager->endAutoLogin();
2251                 
2252                 return $contents;
2253         }
2254         /**
2255          * ページ作成処理中断
2256          *
2257          * 注意)exitSystem()でシステムを終了させる必要あり
2258          *
2259          * @return                                                      なし
2260          */
2261         function abortPage()
2262         {
2263                 global $gInstanceManager;
2264                 global $gRequestManager;
2265                 
2266                 // HTTPヘッダを削除(PHP 5.3以上で有効)
2267                 if (version_compare(PHP_VERSION, '5.3.0') >= 0) header_remove();
2268
2269                 // exit()等でabortPage()が最後の処理になってしまう可能性があるのでなるべく必要な処理を行う
2270                 //if (ob_get_level() > 0) ob_end_clean();// バッファ内容が残っているときは破棄
2271                 while (ob_get_level()) ob_end_clean();  // バッファ削除方法変更(2009/12/2)
2272                 
2273                 // セッションへユーザ情報を保存
2274                 $userInfo = $gInstanceManager->getUserInfo();
2275                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
2276                 
2277                 // その他セッション情報保存
2278                 $gRequestManager->_doSessionCloseEventCallback();
2279                 
2280                 $this->isAbort = true;                                  // ページ作成処理を中断するかどうか
2281         }
2282         /**
2283          * ウィジェット処理中断
2284          *
2285          * @return                                                      なし
2286          */
2287         function abortWidget()
2288         {
2289                 $this->isWidgetAbort = true;                                    // 各ウィジェット処理を中断するかどうか
2290         }
2291         /**
2292          * 強制終了を実行
2293          *
2294          * @return              なし
2295          */
2296         function exitSystem()
2297         {
2298                 global $gEnvManager;
2299                 global $gAccessManager;
2300                 
2301                 // DBが使用可能であれば、アクセスログのユーザを登録
2302                 if ($gEnvManager->canUseDb()) $gAccessManager->accessLogUser();
2303                 
2304                 exit();         // システム終了
2305         }
2306         /**
2307          * Joomla!v1.5タグを読み込んでウィジェット実行
2308          *
2309          * @param string        $srcBuf                 バッファデータ
2310          * @param int           $templateVer    テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
2311          * @return string                                       変換後文字列
2312          */
2313         function launchWidgetByJoomlaTag($srcBuf, $templateVer)
2314         {
2315                 $replace = array();
2316                 $matches = array();
2317                 $destBuf = $srcBuf;
2318                 
2319                 if (preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\s*\/>#iU', $srcBuf, $matches)){
2320                         $count = count($matches[1]);
2321                         for ($i = 0; $i < $count; $i++)
2322                         {
2323                                 $contents = '';
2324                                 $type  = $matches[1][$i];
2325                                 $attr = array();
2326                                 if (strcasecmp($type, 'head') == 0){            // ヘッダ埋め込みタグの場合
2327                                         ob_clean();
2328                                         $this->getHeader();
2329                                         $contents = ob_get_contents();
2330                                 } else if (strcasecmp($type, 'modules') == 0 || strcasecmp($type, 'module') == 0 ||             // 一般ウィジェット用配置ブロックの場合
2331                                                         strcasecmp($type, 'navmenu') == 0){                                                                                     // ナビゲーションメニューウィジェット用配置ブロックの場合
2332                                         $name = '';                     // ポジション名
2333                                         $posType = '';          // ポジションのタイプ
2334                                         $style = '';            // 表示スタイル
2335                                         $params = explode(' ', $matches[2][$i]);
2336                                         $paramArray = array();
2337                                         for ($j = 0; $j < count($params); $j++){
2338                                                 list($key, $value) = explode('=', $params[$j]);
2339                                                 $key = trim($key);
2340                                                 $value = trim($value, "\"'");
2341                                                 if (!empty($key)) $paramArray[$key] = $value;
2342                                         }
2343                                         $value = $paramArray['name'];
2344                                         if (isset($value)){
2345                                                 $name = $value;
2346                                                 $attr['name'] = $value;
2347                                         }
2348                                         $value = $paramArray['type'];           // 配置ブロックのタイプを属性に格納。テンプレート内での参照用。
2349                                         if (isset($value)){
2350                                                 $posType = $value;
2351                                                 $attr['type'] = $value;
2352                                         }
2353                                         $value = $paramArray['id'];
2354                                         if (isset($value)) $attr['id'] = $value;
2355                                         
2356                                         // スタイルが設定されている場合はオプションスタイルを取得
2357                                         $value = $paramArray['style'];
2358                                         if (isset($value)){
2359                                                 $style = $value;
2360                                                 $attr['style'] = $value;
2361                                                 
2362                                                 $optionStyle = $paramArray[$value];             // オプションのスタイル
2363                                                 if (isset($optionStyle)) $attr[$value] = $optionStyle;
2364                                         }
2365 /*                                      for ($j = 0; $j < count($params); $j++){
2366                                                 list($key, $value) = explode('=', $params[$j]);
2367                                                 if (strcasecmp($key, 'name') == 0){
2368                                                         $name = strtolower(trim($value, "\"'"));
2369                                                         $attr['name'] = $name;
2370                                                 } else if (strcasecmp($key, 'style') == 0){
2371                                                         // スタイルは大文字小文字の区別あり
2372                                                         $style = trim($value, "\"'");
2373                                                 } else if (strcasecmp($key, 'artstyle') == 0){          // テンプレート側指定の表示スタイル(Artisteer用)
2374                                                         $attr['artstyle'] = trim($value, "\"'");
2375                                                 } else if (strcasecmp($key, 'bootstyle') == 0){         // テンプレート側指定の表示スタイル(Bootstrap用)
2376                                                         $attr['bootstyle'] = trim($value, "\"'");
2377                                                 } else if (strcasecmp($key, 'drstyle') == 0){           // テンプレート側指定の表示スタイル(Themer用)
2378                                                         $attr['drstyle'] = trim($value, "\"'");
2379                                                 }
2380                                         }*/
2381
2382                                         if (!empty($name)){             // ポジション名が取得できたとき
2383                                                 // Joomla!では、テンプレートの「jdoc:include」タグの属性styleが空のときは「none」で処理される
2384                                                 // Joomla!デフォルトで設定可能なのは「none,table,horz,xhtml,rounded,outline」
2385 /*                                              if (empty($style)){
2386                                                         if (strStartsWith($name, 'user') ||             // ナビゲーションメニュー位置の場合
2387                                                                 strcasecmp($name, 'position-1') == 0){                          // Joomla!v2.5テンプレート対応
2388                                                                 $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2389                                                         } else {
2390                                                                 $style = 'none';
2391                                                         }
2392                                                 }*/
2393                                                 if (strcasecmp($type, 'navmenu') == 0){                                                                                 // メニューウィジェット用配置ブロックの場合
2394                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2395                                                         $attr['type'] = $type;                  // テンプレート内での参照用
2396                                                 } else if (strcasecmp($name, 'user3') == 0 ||           // ナビゲーションメニュー位置の場合
2397                                                         strcasecmp($name, 'position-1') == 0 ||         // Joomla!v2.5テンプレート対応
2398                                                         strcasecmp($posType, 'hmenu') == 0){            // Joomla!v3テンプレート対応
2399                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2400                                                 } else if (empty($style)){
2401                                                         $style = 'none';
2402                                                 }
2403                                                 // ウィジェットの出力を取得
2404                                                 $contents = $this->getContents($name, $style, $templateVer, $attr);
2405                                         }
2406                                 } else if (strcasecmp($type, 'component') == 0){        // メインポジションタグの場合
2407                                         // スタイルを取得
2408                                         $style = '';            // 表示スタイル
2409                                         $params = explode(' ', $matches[2][$i]);
2410                                         for ($j = 0; $j < count($params); $j++){
2411                                                 list($key, $value) = explode('=', $params[$j]);
2412                                                 if (strcasecmp($key, 'style') == 0){
2413                                                         // スタイルは大文字小文字の区別あり
2414                                                         $style = trim($value, "\"'");
2415                                                         break;
2416                                                 }
2417                                         }
2418                                         if ($style != 'none') $style = 'xhtml';
2419                                         $contents = $this->getContents('main', $style, $templateVer, $attr);
2420                                 } else if (strcasecmp($type, 'message') == 0){  // メッセージタグの場合
2421                                 }
2422                                 $replace[$i] = $contents;
2423                         }
2424                         ob_clean();
2425                         $destBuf = str_replace($matches[0], $replace, $srcBuf);
2426                 }
2427                 return $destBuf;
2428         }
2429         /**
2430          * 遅延ウィジェット実行
2431          *
2432          * 遅延実行インデックスのついているウィジェットをインデックス順に実行し、出力バッファデータ内のタグの位置に出力を埋め込む
2433          *
2434          * @param RequestManager $request               HTTPリクエスト処理クラス
2435          * @param string         $srcBuf                バッファデータ
2436          * @return string                                               変換後文字列
2437          */
2438         function lateLaunchWidget($request, $srcBuf)
2439         {
2440                 global $gEnvManager;
2441                 global $gErrorManager;
2442                 global $gDesignManager;
2443                 
2444                 // ページ作成中断またはウィジェット処理中断のときは終了
2445                 if ($this->isAbort || $this->isWidgetAbort) return '';
2446                 
2447                 // ウィジェットヘッダ(Joomla!1.0用)を出力のタイプを取得
2448                 $widgetHeaderType = $this->getTemplateWidgetHeaderType();
2449                                         
2450                 // 遅延実行ウィジェットをインデックス順にソート
2451                 asort($this->lateLaunchWidgetList, SORT_NUMERIC);
2452                 
2453                 // タグを置換
2454                 $destBuf = $srcBuf;
2455                 foreach ($this->lateLaunchWidgetList as $widgetId => $value){
2456                         // 実行パラメータ取得
2457                         $count = count($this->latelaunchWidgetParam);
2458                         for ($i = 0; $i < $count; $i++){
2459                                 list($wId, $maxNo, $confId, $preId, $serial, $style, $cssStyle, $title, $shared, $exportCss, $position, $index, $pageDefRec) = $this->latelaunchWidgetParam[$i];
2460                                 if ($wId == $widgetId){
2461                                         // パラメータ初期化
2462                                         $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
2463                                         $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
2464                                         $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
2465                                         
2466                                         // 現在のウィジェットのポジション
2467                                         $this->currentWidgetPosition = $position;                       // 現在のウィジェットのポジション
2468                                         $this->currentWidgetIndex = $index;                     // 現在のウィジェットのポジション番号
2469         
2470                                         // バッファ作成
2471                                         ob_start();
2472
2473                                         // ウィジェット実行ファイル取得
2474                                         $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
2475
2476                                         // その他パラメータ取得
2477                                         $configId = $confId;            // ウィジェット定義ID
2478                                         if ($configId == 0) $configId = '';
2479                                         $prefix = $preId;               // サフィックス文字列
2480                         
2481                                         // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
2482                                         $joomlaTitleVisble = false;
2483                                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
2484                                                 if (!empty($title)){
2485                                                         if ($widgetHeaderType == 1){            // PC用ウィジェットヘッダ出力
2486                                                                 echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
2487                                                                 echo '<tr><th>' . $title . '</th></tr>' . M3_NL;
2488                                                                 echo '<tr><td>' . M3_NL;
2489                                                                 $joomlaTitleVisble = true;
2490                                                         } else if ($widgetHeaderType == 2){                     // 携帯用ウィジェットヘッダ出力
2491                                                                 echo '<div>' . $title . '</div>' . M3_NL;
2492                                                                 $joomlaTitleVisble = true;
2493                                                         }
2494                                                 }
2495                                         }
2496                                         // ウィジェットの外枠タグを設定
2497                                         //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
2498                                         // ウィジェット親のCSS定義があるときは、タグを追加
2499                                         if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
2500                                         
2501                                         // ウィジェットの前出力
2502                                         echo $gDesignManager->getAdditionalWidgetOutput(true);
2503                                 
2504                                         // 作業中のウィジェットIDを設定
2505                                         $gEnvManager->setCurrentWidgetId($widgetId);
2506
2507                                         // ウィジェット定義IDを設定
2508                                         $gEnvManager->setCurrentWidgetConfigId($configId);
2509                                         
2510                                         // ページ定義のシリアル番号を設定
2511                                         $gEnvManager->setCurrentPageDefSerial($serial);
2512                 
2513                                         // ページ定義レコードを設定
2514                                         $gEnvManager->setCurrentPageDefRec($pageDefRec);
2515                                 
2516                                         // パラメータを設定
2517                                         $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
2518                 
2519                                         // ウィジェットのタイトルを設定
2520                                         $gEnvManager->setCurrentWidgetTitle('');
2521                                         
2522                                         // ウィジェットのスタイルを設定
2523                                         $gEnvManager->setCurrentWidgetStyle($style);
2524                                 
2525                                         // ウィジェットのグローバル属性状況を設定
2526                                         $gEnvManager->setIsCurrentWidgetShared($shared);
2527                                 
2528                                         // 実行ログを残す
2529                                         $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
2530                                         
2531                                         // ウィジェットを実行
2532                                         // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
2533                                         $msg = 'widget-start(' . $widgetId . ')';
2534                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
2535                                         require($widgetIndexFile);
2536                                         $msg = 'widget-end(' . $widgetId . ')';
2537                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
2538
2539                                         // 作業中のウィジェットIDを解除
2540                                         $gEnvManager->setCurrentWidgetId('');
2541                 
2542                                         // ウィジェット定義IDを解除
2543                                         $gEnvManager->setCurrentWidgetConfigId('');
2544                                         
2545                                         // ページ定義のシリアル番号を解除
2546                                         $gEnvManager->setCurrentPageDefSerial(0);
2547                 
2548                                         // ページ定義レコードを解除
2549                                         $gEnvManager->setCurrentPageDefRec();
2550                                         
2551                                         // パラメータを解除
2552                                         $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
2553                                         
2554                                         // ウィジェットのスタイルを解除
2555                                         $gEnvManager->setCurrentWidgetStyle('');
2556                                         
2557                                         // ウィジェットのグローバル属性状況を解除
2558                                         $gEnvManager->setIsCurrentWidgetShared(false);
2559                                         
2560                                         // ウィジェットのタイトルを取得
2561                                         $newTitle = $gEnvManager->getCurrentWidgetTitle();
2562
2563                                         // ウィジェットの後出力
2564                                         echo $gDesignManager->getAdditionalWidgetOutput(false);
2565                                 
2566                                         // ウィジェット親のCSS定義があるときは、タグを追加
2567                                         if (!empty($cssStyle)) echo '</div>' . M3_NL;
2568                                         // ウィジェットの外枠タグを設定
2569                                         //echo '</div>' . M3_NL;
2570                                         
2571                                         // Joomla!1.0テンプレートのときはタイトルを出力
2572                                         if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用ウィジェットヘッダ出力
2573                                                 echo '</td></tr>' . M3_NL;
2574                                                 echo '</table>' . M3_NL;
2575                                         }
2576                                         
2577                                         // 現在のバッファ内容を取得し、バッファを破棄
2578                                         $srcContents = ob_get_contents();
2579                                         ob_end_clean();
2580                                         
2581                                         // ウィジェットの出力を取得
2582                                         $tag = self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;
2583                                         $destBuf = str_replace($tag, $srcContents, $destBuf);
2584                                         
2585                                         // タイトルの出力
2586                                         if (!empty($newTitle)) $title = $newTitle;
2587                                         $tag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
2588                                         $destBuf = str_replace($tag, $title, $destBuf);
2589                                         
2590                                         // ##### 外部出力用のCSSがある場合は追加 #####
2591                                         if (!empty($exportCss)){
2592                                                 // ウィジェットのタグIDを変換
2593                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $index;                          // ウィジェット識別用ユニークタグ
2594                                                 $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
2595                                                 $this->addExportCss($exportCss);
2596                                         }
2597                                 }
2598                         }
2599                 }
2600                 
2601                 // ##### HTMLヘッダ出力処理 #####
2602                 $destBuf = $this->replaceHead($destBuf);
2603                 
2604                 return $destBuf;
2605         }
2606         /**
2607          * ジョブ実行
2608          *
2609          * @param string $jobType               ジョブタイプ
2610          * @return                                              なし
2611          */
2612         function launchJob($jobType)
2613         {
2614                 global $gEnvManager;
2615                 
2616                 // ジョブタイプから実行するウィジェットIDを取得
2617                 $widgetId = $this->getWidgetIdByJobType($jobType);
2618                 if (empty($widgetId)) return;
2619
2620                 // 作業中のウィジェットIDを設定
2621                 $gEnvManager->setCurrentWidgetId($widgetId);
2622                         
2623                 // 指定のウィジェットを実行
2624                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/admin/job.php';
2625                         
2626                 if (file_exists($widgetIndexFile)){
2627 //                      // 実行のログを残す
2628 //                      $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
2629
2630                         require_once($widgetIndexFile);
2631                 } else {
2632                         echo 'file not found: ' . $widgetIndexFile;
2633                 }
2634                                 
2635                 // 作業中のウィジェットIDを解除
2636                 $gEnvManager->setCurrentWidgetId();
2637         }
2638         /**
2639          * ヘッダ部マクロ変換処理
2640          *
2641          * @param string         $srcBuf                変換元
2642          * @return string                                               変換後文字列
2643          */
2644         function replaceHead($srcBuf)
2645         {
2646                 $destBuf = $srcBuf;
2647
2648                 // ##### ヘッダ部分の置換 #####
2649                 if ($this->outputHead){                         // HTMLヘッダ出力を行っているとき
2650                         // タグ変換用文字列の取得
2651                         $replaceStr = $this->getHeaderOutput();
2652                         
2653                         // HTMLヘッダのデータ埋め込み
2654                         $destBuf = str_replace(self::HEAD_TAGS, $replaceStr, $destBuf);
2655                 }
2656                 $this->replaceHeadDone = true;                  // ヘッダマクロ変換処理が完了したかどうか
2657                 return $destBuf;
2658         }
2659         /**
2660          * ヘッダ部マクロ変換を有効にする
2661          *
2662          * @return                                      なし
2663          */
2664         function enableReplaceHead()
2665         {
2666                 $this->outputHead = true;
2667         }
2668         /**
2669          * ウィジェット検索モードの場合のページサブIDの設定
2670          *
2671          * @param RequestManager $request               HTTPリクエスト処理クラス
2672          */
2673         function redirectToUpdatedPageSubId($request)
2674         {
2675                 global $gEnvManager;
2676                 
2677                 // 現在設定されているページIDを取得
2678                 $pageId         = $gEnvManager->getCurrentPageId();
2679                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2680                 
2681                 // 送信元のウィジェットIDを取得
2682                 $fromWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_FROM);
2683                 
2684                 // 対象のウィジェットIDを取得
2685                 $targetWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
2686                 
2687                 // 対象のウィジェットのページサブIDを取得
2688                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2689                 if ($ret){// データが存在する
2690                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2691                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2692                                 if ($ret){// データが存在する
2693                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2694                                         } else {
2695                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2696                                         }
2697                                 }
2698                         } else {
2699                                 // 送信元があるか順にチェック
2700                                 for ($i = 0; $i < count($rows); $i++){
2701                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2702                                         if ($ret){      
2703                                                 break;
2704                                         }
2705                                 }
2706                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2707                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2708                                 } else {
2709                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2710                                 }
2711                         }
2712                 } else {                // 対象のウィジェットが見つからない場合は、互換ウィジェットを探す
2713                         $widgetId = $this->db->getCompatibleWidgetId($targetWidgetId);
2714                         if (!empty($widgetId)){
2715                                 $targetWidgetId = $widgetId;
2716                                 
2717                                 // 対象のウィジェットのページサブIDを取得
2718                                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2719                                 if ($ret){// データが存在する
2720                                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2721                                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2722                                                 if ($ret){// データが存在する
2723                                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2724                                                         } else {
2725                                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2726                                                         }
2727                                                 }
2728                                         } else {
2729                                                 // 送信元があるか順にチェック
2730                                                 for ($i = 0; $i < count($rows); $i++){
2731                                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2732                                                         if ($ret){      
2733                                                                 break;
2734                                                         }
2735                                                 }
2736                                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2737                                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2738                                                 } else {
2739                                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2740                                                 }
2741                                         }
2742                                 }
2743                         }
2744                 }
2745                 // ページサブIDが見つからないときは、既に設定されている値を使用
2746                 // 既に設定されている値は、URL「sub」パラメータで指定されている値か
2747                 // 設定されていない場合はデフォルトのサブページID
2748                 // ********** 指定ページへリダイレクト ***********
2749                 // 実行パラメータ取得
2750                 $todo = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TODO);
2751                 $todo = str_replace(M3_TODO_SEPARATOR, '&', $todo);             // セパレータを変換
2752 //              $redirectUrl = '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2753                 $redirectUrl = $gEnvManager->createPageUrl() . '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2754                 if (!empty($todo)) $redirectUrl .= '&' . $todo;
2755                 if ($gEnvManager->getIsMobileSite()){           // 携帯用アクセスポイントの場合
2756                         $this->redirect($redirectUrl, true/*遷移時のダイアログ表示を抑止*/);
2757                 } else {
2758                         $this->redirect($redirectUrl);
2759                 }
2760         }
2761         /**
2762          * 最終HTML出力処理
2763          *
2764          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2765          * 追加するHTMLは主にウィンドウ制御用のスクリプト
2766          *
2767          * @return string                                       最終HTML
2768          */
2769         function getLastContents()
2770         {
2771                 global $gEnvManager;
2772                 global $gRequestManager;
2773                 
2774                 $contents = '';
2775                 $initScript = '';               // 初期化用スクリプト
2776                 $pageId         = $gEnvManager->getCurrentPageId();
2777                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2778                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2779                 
2780                 if (!$gEnvManager->isSystemManageUser()) return '';             // システム運用権限がない場合は終了
2781                 
2782                 // 処理を行わない場合は終了
2783                 if ($cmd == M3_REQUEST_CMD_RSS ||                                               // RSS配信のときは終了
2784                         $cmd == M3_REQUEST_CMD_DO_WIDGET) return '';            // ウィジェット単体オペレーションのときは出力しない
2785                 
2786                 if ($gEnvManager->getIsMobileSite()) return '';         // 携帯用URLのときは終了
2787                 
2788                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2789                         // ウィジェットレイアウト用カーソル
2790                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
2791 /*                              // テンプレート上のポジション名
2792                                 if (count($this->viewPosId) > 0){
2793                                         $posArrayStr = '[';
2794                                         for ($i = 0; $i < count($this->viewPosId); $i++){
2795                                                 $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
2796                                                 if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
2797                                         }
2798                                         $posArrayStr .= ']';
2799                                         $contents .= 'var M3_POSITIONS=' . $posArrayStr . ';' . M3_NL;
2800                                 }
2801                                 // 画面定義のリビジョン番号
2802                                 $contents .= 'var M3_REVISION=' . $this->pageDefRev . ';' . M3_NL;*/
2803                 
2804                                 // 更新用関数追加
2805                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2806                                 $contents .= M3_INDENT_SPACE . 'window.m3.m3UpdateByConfig(serial);' . M3_NL;
2807                                 $contents .= '}' . M3_NL;
2808                         } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){                       // ウィジェット設定画面
2809                         } else {                // ダッシュボード画面、メイン管理画面
2810                                 // 画面更新用関数追加
2811                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2812                                 $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2813                                 $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2814                                 $contents .= '}' . M3_NL;
2815                         }
2816                         
2817                         // ウィジェット単体実行以外のときの処理
2818                         if (!$this->showWidget){
2819                                 if ($this->updateParentWindow){                 // 管理画面からの親画面の更新
2820                                         $initScript .= M3_INDENT_SPACE . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
2821                                 }
2822                         }
2823                 } else {                // 通常画面のとき
2824                         // 画面更新用関数追加
2825                         $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2826                         $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2827                         $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2828                         $contents .= '}' . M3_NL;
2829                 }
2830
2831                 $destContents = '';
2832                 if (!empty($contents) || !empty($initScript)){
2833 //                      $destContents .= '<script type="text/javascript">' . M3_NL;
2834 //                      $destContents .= '//<![CDATA[' . M3_NL;
2835                         $destContents .= $contents;
2836                         if (!empty($initScript)){               // 初期化用スクリプト
2837                                 $destContents .= '$(function(){' . M3_NL;
2838                                 $destContents .= $initScript;
2839                                 $destContents .= '});' . M3_NL;
2840                         }
2841 //                      $destContents .= '//]]>' . M3_NL;
2842 //                      $destContents .= '</script>' . M3_NL;
2843                 }
2844                 return $destContents;
2845         }
2846         /**
2847          * オプションHTML出力処理
2848          *
2849          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2850          *
2851          * @param RequestManager $request               HTTPリクエスト処理クラス
2852          * @return string                                       最終HTML
2853          */
2854         function getOptionContents($request)
2855         {
2856                 global $gEnvManager;
2857                 
2858                 $contents = '';
2859                 
2860                 // ページ作成中断のときは終了
2861                 if ($this->isAbort) return '';
2862                 
2863                 // AJAX用のレスポンスボディデータのときは終了
2864                 if ($this->outputAjaxResponseBody) return '';
2865                 
2866                 // ウィジェット処理中断のとき
2867                 // AJAXを送信する場合は空文字列では送信できないので、ダミーデータを返す
2868                 if ($this->isWidgetAbort) $contents .= 'NO DATA' . M3_NL;
2869                 
2870                 // Magic3出力コメント
2871                 if (!$gEnvManager->isMobile() && $this->outputByHtml){          // 携帯以外で、HTML出力のとき
2872                         $contents .= '<!-- created by ' . M3_SYSTEM_NAME . ' v' . M3_SYSTEM_VERSION . ' - http://www.magic3.org -->' . M3_NL;
2873                         $contents .= '<!-- convert time: ' . sprintf('%01.03f', microtime(true) - M3_MTIME) . ' -->' . M3_NL;
2874                 }
2875                 return $contents;
2876         }
2877         /**
2878          * Widget単体起動用のHTMLのヘッダ部(headタグ)出力
2879          *
2880          * startWidget(),endWidget()は、以下のコマンドを処理する
2881          *  ・M3_REQUEST_CMD_SHOW_WIDGET(ウィジェットの単体表示)
2882          *  ・M3_REQUEST_CMD_CONFIG_WIDGET(ウィジェット設定画面)
2883          *  ・M3_REQUEST_CMD_DO_WIDGET(ウィジェット単体実行)
2884          * Widgetの出力方法は、以下のパターンがある
2885          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
2886          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
2887          *
2888          * @param string $cmd           起動コマンド
2889          */
2890         function startWidget($cmd)
2891         {
2892                 global $gEnvManager;
2893                 global $gRequestManager;
2894
2895                 // ウィジェット単体表示のときのみ出力
2896                 if (!$this->showWidget) return;
2897
2898                 // パラメータ取得
2899                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
2900                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
2901
2902 //              $isHtml5 = false;               // HTML5で出力するかどうか
2903                 $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
2904                 if (intval($tempVer) >= 2) $this->isHtml5 = true;               // HTML5で出力するかどうか                             
2905                 
2906                 // DOCTYPEの設定
2907                 if ($this->isHtml5){
2908                         echo '<!DOCTYPE html>' . M3_NL;
2909                         echo '<html dir="ltr" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
2910                         echo '<head>' . M3_NL;
2911                 } else {
2912                         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . M3_NL;
2913                         echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $gEnvManager->getCurrentLanguage() . '" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
2914                         echo '<head>' . M3_NL;
2915 //                      echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . M3_NL;
2916                 }
2917
2918                 // HTMLのヘッダ部(headタグ内)出力
2919                 $this->getHeader();
2920
2921                 // 現在のウィジェットを取得
2922                 $widgetId = $gEnvManager->getCurrentWidgetId();         // カレントのウィジェットID
2923                 
2924                 // URLを作成
2925                 if ($gEnvManager->getUseSslAdmin()){
2926                         $rootUrl = $gEnvManager->getSslRootUrl();
2927                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
2928                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
2929                 } else {
2930                         $rootUrl = $gEnvManager->getRootUrl();
2931                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
2932                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
2933                 }
2934
2935                 // ##### テンプレートのCSSの読み込み #####
2936                 // テンプレートは管理用テンプレートに固定されている
2937                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||             // ウィジェット設定のとき
2938                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy) && $gEnvManager->isContentEditableUser())){        // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
2939                         $curTemplateUrl = $templatesUrl . '/' . $gEnvManager->getCurrentTemplateId();
2940                         if ($this->isHtml5){
2941                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/style.css" media="screen">' . M3_NL;
2942                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/widget.css" media="screen">' . M3_NL;            // ウィジェット設定画面用CSS
2943                         echo '<!--[if IE]><link rel="stylesheet" href="' . $curTemplateUrl . '/css/iestyles.css" media="screen"><![endif]-->' . M3_NL;
2944                                 echo '<!--[if lt IE 9]><script src="' . $curTemplateUrl . '/html5shiv.js"></script><![endif]-->' . M3_NL;
2945                         } else {
2946                                 echo '<link href="' . $curTemplateUrl . '/css/style.css" rel="stylesheet" type="text/css" />' . M3_NL;
2947                                 echo '<!--[if IE]><link rel="stylesheet" type="text/css" media="screen" href="' . $curTemplateUrl . '/css/iestyles.css" /><![endif]-->' . M3_NL;
2948                         }
2949                 }
2950                 // ウィジェット情報取得
2951                 $ret = $this->db->getWidgetInfo($widgetId, $row);
2952
2953                 // ##### 共通ライブラリ読み込み設定 #####
2954                 if ($cmd == M3_REQUEST_CMD_DO_WIDGET){          // ウィジェット単体実行のとき
2955                         $scritLib = trim($row['wd_add_script_lib']);
2956                         if (!empty($scritLib)) $this->addScript($task, $scritLib);
2957                 }
2958                                 
2959                 // CSS読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
2960                 if ($row['wd_read_css']){
2961                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_CSS;
2962                         if (is_dir($searchPath)){
2963                                 $dir = dir($searchPath);
2964                                 while (($file = $dir->read()) !== false){
2965                                         $filePath = $searchPath . '/' . $file;
2966                                         if ($file != '.' && $file != '..' && is_file($filePath)
2967                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
2968                                                 
2969                                                 // CSSへのURLを作成
2970                                                 $cssURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_CSS . '/' . $file;
2971                                                 echo '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
2972                                         }
2973                                 }
2974                                 $dir->close();
2975                         }
2976                 }
2977                 
2978                 // スクリプト読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
2979                 if ($row['wd_read_scripts']){
2980                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS;
2981                         if (is_dir($searchPath)){
2982                                 $dir = dir($searchPath);
2983                                 while (($file = $dir->read()) !== false){
2984                                         $filePath = $searchPath . '/' . $file;
2985                                         if ($file != '.' && $file != '..' && is_file($filePath)
2986                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
2987                                                 
2988                                                 // スクリプトへのURLを作成
2989                                                 $scriptURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
2990                                                 
2991                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
2992                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
2993                                                 echo '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
2994                                         }
2995                                 }
2996                                 $dir->close();
2997                         }
2998                 }
2999                 // ##### スクリプト用出力用タグを埋め込む #####
3000                 // ウィジェット設定画面用メニューバーの作成
3001                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){   // ウィジェット設定画面またはフロント画面編集モードのとき
3002                         echo self::MENUBAR_SCRIPT_TAGS;                 // メニューバー出力用タグ
3003                 }
3004                 
3005                 // ウィジェットのタイトルを設定
3006                 $title = $row['wd_name'];
3007                 if (empty($title)) $title = $row['wd_id'];
3008                 $gEnvManager->setCurrentWidgetTitle($title);
3009                 echo '<title>' . self::WIDGET_TITLE_START . htmlspecialchars($title) . self::WIDGET_TITLE_END . '</title>' . M3_NL;
3010                 echo '</head>' . M3_NL;
3011                 // タブでウィンドウを開く場合は背景を透過モードにする
3012                 if ($this->isTransparentMode){
3013                         echo '<body style="background-color:transparent;">' . M3_NL;
3014                 } else {
3015                         echo '<body>' . M3_NL;
3016                 }
3017                 // ウィジェット設定画面用メニューバーの作成
3018                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){   // ウィジェット設定画面またはフロント画面編集モードのとき
3019                         // ウィジェット情報を設定
3020                         $desc = $row['wd_description'];         // 説明
3021                         $gEnvManager->setCurrentWidgetParams('desc', $desc);
3022                         
3023                         echo self::MENUBAR_TAGS;                        // メニューバー出力用タグ
3024                 }
3025                 // Bootstrap用のタグ出力
3026                 if ($this->useBootstrap) echo '<div class="container">' . M3_NL;
3027                 
3028                 // 別ウィンドウで表示のときは、「閉じる」ボタンを表示
3029                 if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET ||               // ウィジェットの単体表示のとき
3030                         $cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェット詳細設定画面のとき
3031                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){               // ウィジェット単体実行でフロント画面編集モードのとき
3032
3033 //                      if ($this->isEditMode){// フロント画面編集モードのとき
3034                                 if (!empty($openBy)){
3035                                         // サーバ指定されている場合はサーバ情報を取得
3036                                         $serverName = '';
3037                                         $server = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_SERVER);
3038                                         if (!empty($server)){
3039                                                 // 設定データを取得
3040                                                 $ret = $this->db->getServerById($server, $row);
3041                                                 if ($ret){
3042                                                         $serverName = 'サーバ名:' . $row['ts_name'];// サーバ名
3043                                                         echo '<div align="left" style="float:left;padding-left:30px;"><label>' . convertToHtmlEntity($serverName) . '</label></div>';
3044                                                 }
3045                                         }
3046                                         // タブ、インナーフレーム、ダイアログ表示以外のときは「閉じる」ボタンを表示
3047                                         if ($openBy != 'tabs' && $openBy != 'iframe' && $openBy != 'dialog'){           // 以外
3048                                                 if ($openBy == 'logout'){
3049                                                         $titleStr = 'ログアウト';
3050                                                         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 . 
3051                                                                                 '" alt="' . $titleStr . '" /></a></div>' . M3_NL;
3052                                                 } else {
3053                                                         $titleStr = '閉じる';
3054                                                         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 . 
3055                                                                                 '" alt="' . $titleStr . '" /></a></div>' . M3_NL;
3056                                                 }
3057                                         }
3058                                 }
3059                                 // 「前へ」「次へ」ボタン
3060                                 $titleStr = '前へ';
3061                                 echo '<div class="m3configprev" style="display:none;"><a id="m3configprev" href="#"><img src="' . $rootUrl . self::PREV_ICON_FILE . 
3062                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" rel="m3help" /></a></div>' . M3_NL;
3063                                 $titleStr = '次へ';
3064                                 echo '<div class="m3confignext" style="display:none;"><a id="m3confignext" href="#"><img src="' . $rootUrl . self::NEXT_ICON_FILE . 
3065                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" rel="m3help" /></a></div>' . M3_NL;
3066 //                      }
3067                 }
3068 //              echo '<div class="row">' . M3_NL;
3069                 echo '<!-- Widget Start -->' . M3_NL;
3070         }
3071         /**
3072          * Widget単体起動の終了処理
3073          *
3074          * startWidget(),endWidget()は、以下のコマンドを処理する
3075          *  ・M3_REQUEST_CMD_SHOW_WIDGET(ウィジェットの単体表示)
3076          *  ・M3_REQUEST_CMD_CONFIG_WIDGET(ウィジェット設定画面)
3077          *  ・M3_REQUEST_CMD_DO_WIDGET(ウィジェット単体実行)
3078          *
3079          * @param string $cmd                   起動コマンド
3080          * @param string $srcContent    HTML出力ソース
3081          */
3082         function endWidget($cmd, $srcContent)
3083         {
3084                 global $gDesignManager;
3085                 
3086                 // ウィジェット単体表示のときのみ出力
3087                 if (!$this->showWidget) return;
3088                 
3089                 // メニューバー出力
3090                 // パンくずリストを表示
3091                 $breadcrumbHtml = '';
3092                 if (!empty($this->adminSubNavbarDef)) $breadcrumbHtml .= $gDesignManager->createSubMenubar($this->adminSubNavbarDef);
3093                 if (!empty($this->adminBreadcrumbDef)) $breadcrumbHtml .= $gDesignManager->createAdminBreadcrumb($this->adminBreadcrumbDef);
3094                 $destContent = str_replace(self::MENUBAR_TAGS, $breadcrumbHtml, $srcContent);
3095
3096                 // ヘッドタグ出力
3097                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
3098                 $replaceStr .= '//<![CDATA[' . M3_NL;
3099                 
3100                 // ##### 追加関数 #####
3101                 // ウィジェット設定画面用
3102                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェットの設定管理
3103                         // 画面更新用関数追加
3104                         $replaceStr .= 'function m3UpdateByConfig(serial){' . M3_NL;
3105                         $replaceStr .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
3106                         $replaceStr .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
3107                         $replaceStr .= M3_INDENT_SPACE . 'm3UpdateParentWindow();' . M3_NL;             // 親ウィンドウ更新
3108                         $replaceStr .= '}' . M3_NL;
3109                 
3110                         // IEエラーメッセージ出力抑止
3111                         $replaceStr .= 'function hideIEErrors(){' . M3_NL;
3112                         $replaceStr .= M3_INDENT_SPACE . 'return true;' . M3_NL;
3113                         $replaceStr .= '}' . M3_NL;
3114                         $replaceStr .= 'window.onerror = hideIEErrors;' . M3_NL;
3115                 }
3116                 
3117                 // ##### 初期処理 #####
3118                 $replaceStr .= '$(function(){' . M3_NL;
3119                 // トップ位置修正
3120                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){           // ウィジェット設定画面またはフロント画面編集モードのとき
3121                         if (!empty($this->adminSubNavbarDef) || !empty($this->adminBreadcrumbDef)){
3122                                 $menubarHeight = $gDesignManager->getSubMenubarHeight();
3123                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . '$("nav.secondlevel").css("margin-top", "0");' . M3_NL;
3124                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . '$("body").css("padding-top", "' . $menubarHeight . 'px");' . M3_NL;
3125                         }
3126                 }
3127                 // ##### ウィジェットからの指定による処理 #####
3128                 if ($this->updateParentWindow){                 // 親ウィンドウ再描画のとき
3129                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット詳細設定画面のとき
3130                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
3131                         } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){                   // ウィジェット単体実行のとき
3132                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindow();' . M3_NL;
3133                         }
3134                 }
3135                 $replaceStr .= '});' . M3_NL;
3136                 $replaceStr .= '//]]>' . M3_NL;
3137                 $replaceStr .= '</script>' . M3_NL;
3138                 $destContent = str_replace(self::MENUBAR_SCRIPT_TAGS, $replaceStr, $destContent);
3139                 echo $destContent;// 変換したコンテンツを出力
3140                 
3141 //              echo '</div>' . M3_NL;                  // row
3142                 echo '<!-- Widget End -->' . M3_NL;
3143                 
3144                 // ##### ウィジェットからの指定による処理 #####
3145 /*              if ($this->updateParentWindow){                 // 親ウィンドウ再描画のとき
3146                         echo '<script type="text/javascript">' . M3_NL;
3147                         echo '//<![CDATA[' . M3_NL;
3148                         echo '$(function(){' . M3_NL;
3149                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット詳細設定画面のとき
3150                                 echo str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
3151                         } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){                   // ウィジェット単体実行のとき
3152                                 echo str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindow();' . M3_NL;
3153                         }
3154                         echo '});' . M3_NL;
3155                         echo '//]]>' . M3_NL;
3156                         echo '</script>' . M3_NL;
3157                 }*/
3158                 
3159                 // Bootstrap用のタグ出力
3160                 if ($this->useBootstrap) echo '</div>' . M3_NL;
3161                 
3162                 echo '</body>' . M3_NL;
3163                 echo '</html>' . M3_NL;
3164         }
3165         /**
3166          * Widget単体RSS出力用のHTMLのヘッダ部(headタグ)出力
3167          *
3168          * Widgetの出力方法は、以下のパターンがある
3169          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
3170          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
3171          *
3172          * @param string $cmd           起動コマンド
3173          */
3174         function startWidgetRss($cmd)
3175         {
3176         }
3177         /**
3178          * Widget単体RSS出力用のタグを閉じる
3179          *
3180          * @param string $cmd                   起動コマンド
3181          * @param string $rssContent    RSS配信内容
3182          */
3183         function endWidgetRss($cmd, $rssContent)
3184         {
3185                 global $gEnvManager;
3186                 
3187                 // ページ作成中断のときは終了
3188                 if ($this->isAbort) return;
3189                 
3190                 echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
3191                 
3192                 // RSSチャンネルデータ取得
3193                 $lang   = $gEnvManager->getCurrentLanguage();
3194                 $date   = getW3CDate();         // RSS1.0用日付
3195                 $copyright = $gEnvManager->getSiteCopyRight();          // 著作権
3196                 $title  = $this->rssChannel['title'];                           // タイトル
3197                 $link   = $this->rssChannel['link'];                            // RSS取得用URL
3198                 $desc   = $this->rssChannel['description'];                     // 説明
3199                 $seq    = $this->rssChannel['seq'];                                     // 項目の並び順(URL)
3200                 
3201                 switch ($this->rssVersion){                                     // RSSバージョン
3202                         case '1.0':
3203                         default:
3204                                 echo '<rdf:RDF xmlns="http://purl.org/rss/1.0/" ';
3205                                 echo 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ';
3206                                 echo 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
3207                                 echo 'xml:lang="' . $lang . '">' . M3_NL;
3208                                 echo '<channel rdf:about="' . convertUrlToHtmlEntity($link) . '">' . M3_NL;
3209                                 echo '<title>' . convertToHtmlEntity($title) . '</title>' . M3_NL;
3210                                 echo '<link>' . convertUrlToHtmlEntity($link) . '</link>' . M3_NL;              // 「convertUrlToHtmlEntity」が必要
3211                                 echo '<description>' . convertToHtmlEntity($desc) . '</description>' . M3_NL;
3212                                 echo '<dc:language>' . $lang . '</dc:language>' . M3_NL;
3213                                 if (!empty($copyright)) echo '<dc:rights>' . convertToHtmlEntity($copyright) . '</dc:rights>' . M3_NL;
3214                                 echo '<dc:date>' . $date . '</dc:date>' . M3_NL;
3215                                 echo '<items>' . M3_NL;
3216                                 if (count($seq) > 0){
3217                                         echo str_repeat(M3_INDENT_SPACE, 1) . '<rdf:Seq>' . M3_NL;
3218                                         for ($i = 0; $i < count($seq); $i++){
3219                                                 echo str_repeat(M3_INDENT_SPACE, 2) . '<rdf:li rdf:resource="' . convertUrlToHtmlEntity($seq[$i]) . '" />' . M3_NL;
3220                                         }
3221                                         echo str_repeat(M3_INDENT_SPACE, 1) . '</rdf:Seq>' . M3_NL;
3222                                 }
3223                                 echo '</items>' . M3_NL;
3224                                 echo '</channel>' . M3_NL;
3225                                 echo $rssContent;
3226                                 echo '</rdf:RDF>' . M3_NL;
3227                                 break;
3228                         case '2.0':
3229                                 break;
3230                 }
3231                 
3232                 // HTTPレスポンスヘッダ設定
3233                 header("Content-type: text/xml; charset=utf-8");
3234         }
3235         /**
3236          * 直サーバ接続時のXML出力用のHTMLのヘッダ部(headタグ)出力
3237          *
3238          * @param string $cmd           起動コマンド
3239          * @return                                      なし
3240          */
3241         function startWidgetXml($cmd)
3242         {
3243                 // HTTPレスポンスヘッダ
3244                 //header("Content-type: text/xml; charset=utf-8");
3245         }
3246         /**
3247          * 直サーバ接続時のXML出力終了
3248          *
3249          * @param string $cmd           起動コマンド
3250          * @return                                      なし
3251          */
3252         function endWidgetXml()
3253         {
3254         }
3255         /**
3256          * 携帯用ドキュメントタイプ出力
3257          *
3258          * @return string                               ドキュメントタイプ出力
3259          */
3260         function getMobileDocType()
3261         {
3262                 global $gEnvManager;
3263                 global $gInstanceManager;
3264                 global $gRequestManager;
3265                 
3266                 $docTypeStr = '';               // 出力するDocType
3267                 $agent = $gInstanceManager->getMobileAgent();
3268                 if ($agent->isDoCoMo()){        // ドコモ端末のとき
3269                         $htmlVer = $agent->getHTMLVersion();
3270                         switch ($htmlVer){
3271                                 case '4.0':
3272                                         $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">';
3273                                         break;
3274                                 case '5.0':
3275                                         $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">';
3276                                         break;
3277                                 case '6.0':
3278                                         $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">';
3279                                         break;
3280                                 case '7.0':
3281                                         $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">';
3282                                         break;
3283                                 case '7.1':
3284                                         $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">';
3285                                         break;
3286                                 case '7.2':
3287                                         $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">';
3288                                         break;
3289                                 default:
3290                                         if (preg_match("/^DoCoMo\/1\.0/i", $gRequestManager->trimServerValueOf('HTTP_USER_AGENT'))){            // mova端末のとき
3291                                                 // mova端末のときはドキュメントタイプなしにすると画面表示可能
3292                                                 return '';
3293                                         }
3294                                         break;
3295                         }
3296                 } else if ($agent->isEZweb()){  // au端末のとき
3297                         if ($agent->isWAP2()){
3298                                 $docTypeStr = '<!DOCTYPE html PUBLIC "-//OPENWAVE//DTD XHTML 1.0//EN" "http://www.openwave.com/DTD/xhtml-basic.dtd">';
3299                         }
3300                 } else if ($agent->isSoftBank()){       // ソフトバンク端末のとき
3301                         if ($agent->isTypeW() || $agent->isType3GC()){
3302                                 $docTypeStr = '<!DOCTYPE html PUBLIC "-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN" "xhtml-basic10-plus.dtd">';
3303                         }
3304                 }
3305                 if ($gEnvManager->getIsMobileSite()){           // 携帯用サイトへのアクセスの場合
3306                         echo '<?xml version="1.0" encoding="' . $gEnvManager->getMobileCharset() . '" ?>' . M3_NL;
3307                 } else {
3308                         echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
3309                 }
3310                 if (empty($docTypeStr)) $docTypeStr = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
3311                 echo $docTypeStr . M3_NL;
3312         }
3313         /**
3314          * デフォルトのXML宣言取得
3315          *
3316          * @return string       XML宣言
3317          */
3318         function getDefaultXmlDeclaration()
3319         {
3320                 return '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>';
3321         }
3322         /**
3323          * HTMLのヘッダ部(headタグ内)出力
3324          *
3325          * システムに共通な定義をHTMLのheadタグ内に出力する
3326          * mosFunc.phpからも実行されるので、このメソッドは引数なしに固定。
3327          * この関数は、以下の「形式1」または「形式2」でheadタグ内に記述する
3328          *
3329          * 形式1:            <!-- m3:HTMLHeader -->
3330          * 形式2(old style): <?php mosShowHead(); ?>
3331          */
3332         function getHeader()
3333         {
3334                 global $gEnvManager;
3335                 global $gRequestManager;
3336
3337                 $this->outputHead = true;                               // HTMLヘッダ出力を行ったかどうか
3338                 
3339                 // 実行コマンドを取得
3340                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3341                 
3342                 // ######### 携帯用サイトの場合は別にヘッダを作成する #########
3343                 if ($gEnvManager->getIsMobileSite()){
3344                         // キャラクターセット
3345                         echo '<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=' . $gEnvManager->getMobileCharset() . '" />' . M3_NL;
3346
3347                         // キャッシュを保存させない
3348                         echo '<meta http-equiv="Pragma" content="no-cache" />' . M3_NL;
3349                         echo '<meta http-equiv="Cache-Control" content="no-cache" />' . M3_NL;
3350                         echo '<meta http-equiv="Expires" content="-1" />' . M3_NL;
3351                 
3352                         // サイト構築エンジン
3353                         echo '<meta name="generator" content="' . M3_SYSTEM_NAME . ' ver.' . M3_SYSTEM_VERSION . ' - ' . M3_SYSTEM_DESCRIPTION . '" />' . M3_NL;
3354                 } else {                // PC用サイト、管理用サイト、スマートフォン用サイトのとき
3355 //                      $isHtml5 = false;               // HTML5で出力するかどうか
3356                         if ($gEnvManager->getIsSmartphoneSite()){               // スマートフォン用サイトのときはHTML5で設定
3357                                 $this->isHtml5 = true;
3358                         } else {
3359                                 $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
3360                                 if (intval($tempVer) >= 2) $this->isHtml5 = true;
3361                         }
3362                         
3363                         // ********** メタタグの設定 **********
3364                         // キャラクターセット
3365                         //if ($gEnvManager->getIsSmartphoneSite()){             // スマートフォン用サイトのときはHTML5で設定
3366                         if ($this->isHtml5){
3367                                 //echo '<meta http-equiv="content-type" content="text/html; charset=' . M3_HTML_CHARSET .'" />' . M3_NL;
3368                                 echo '<meta charset="' . M3_HTML_CHARSET . '">' . M3_NL;
3369                         } else {
3370                                 echo '<meta http-equiv="content-script-type" content="text/javascript" />' . M3_NL;
3371                                 echo '<meta http-equiv="content-style-type" content="text/css" />' . M3_NL;
3372                                 echo '<meta http-equiv="content-type" content="application/xhtml+xml; charset=' . M3_HTML_CHARSET .'" />' . M3_NL;
3373                         }
3374                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3375                                 // Bootstrapで必要なMETAタグを追加
3376                                 echo '<meta name="viewport" content="width=device-width, initial-scale=1">' . M3_NL;
3377                         }
3378                         
3379                         // 基準ディレクトリの指定
3380                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
3381                                 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
3382                         
3383                                 if ($gEnvManager->getUseSslAdmin()){
3384                                         $rootUrl = $gEnvManager->getSslRootUrl();
3385                                 } else {
3386                                         $rootUrl = $gEnvManager->getRootUrl();
3387                                 }
3388                                 echo '<base href="' . $rootUrl . '/" />' . M3_NL;
3389                         }
3390                 }
3391                 echo self::HEAD_TAGS;                   // HTMLヘッダの埋め込みデータ
3392         }
3393         /**
3394          * HTMLヘッダ出力文字列の取得
3395          *
3396          * @return string               HTMLヘッダ出力文字列
3397          */
3398         function getHeaderOutput()
3399         {
3400                 global $gEnvManager;
3401                 global $gRequestManager;
3402                 global $gInstanceManager;
3403                 global $gSystemManager;
3404
3405                 $replaceStr = '';               // 変換文字列
3406                 
3407                 // 実行コマンドを取得
3408                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3409                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
3410                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
3411                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
3412                 
3413                 // ********************************************************
3414                 //               ヘッダ文字列作成の前処理
3415                 // ********************************************************
3416                 // ##### テンプレートの設定、フレームの設定から必要なライブラリを取得 #####
3417                 // Bootstrapライブラリ
3418 //              if (!$this->useBootstrap) $this->useBootstrap = $gEnvManager->getCurrentTemplateUseBootstrap();
3419                 if ($this->useBootstrap){
3420                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3421                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
3422                                         $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
3423                                         if ($cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)以外のとき
3424                                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
3425                                         }
3426                                 } else {                // ログインしていない場合(ログイン画面等)
3427                                         $this->addPermittedAdminScript(ScriptLibInfo::LIB_BOOTSTRAP);
3428                                         $this->addPermittedAdminScript(ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);// Bootstrap管理画面オプション
3429                                 }
3430                         } else {                // フロント画面へのアクセスの場合
3431                                 // ### Bootstrapのjsとcssはテンプレート側で読み込む ###
3432 //                              $this->addScript('', ScriptLibInfo::LIB_BOOTSTRAP);             // Bootstrapライブラリ
3433                                 if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW ||                          // ログイン、ログアウト場合
3434                                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy) && $gEnvManager->isContentEditableUser())){                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
3435                                         $this->addScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);               // Bootstrap管理画面オプション
3436                                 }
3437                         }
3438                 } else {
3439                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
3440                                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3441                                         $this->addAdminScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);              // Bootstrapを使用しない場合の管理機能用スクリプト
3442                                 } else {
3443                                         $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
3444                                 }
3445                         } else if ($gEnvManager->isContentEditableUser()){              // 投稿ユーザの場合
3446                                 $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
3447                         }
3448                 }
3449                 
3450                 // ********************************************************
3451                 //               ヘッダ文字列作成処理
3452                 // ********************************************************
3453                 // ##### インストール時のヘッダ出力 #####
3454                 if (defined('M3_STATE_IN_INSTALL')){
3455                         // タイトルの作成
3456                         $title = '';
3457                         if (count($this->headSubTitle) > 0) $title = htmlspecialchars(trim($this->headSubTitle[0]));
3458                         
3459                         // ********** メタタグの設定 **********
3460                         $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
3461                         
3462                         // ##### インストーラ用のファイルの読み込み #####
3463                         $scriptsUrl = '../scripts';
3464                         
3465                         // 管理機能用共通ライブラリのCSSの読み込み
3466                         $count = count($this->defaultAdminCssFiles);
3467                         for ($i = 0; $i < $count; $i++){
3468                                 // CSSへのURLを作成
3469                                 $cssFilename = $this->defaultAdminCssFiles[$i];
3470                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3471                                         $cssURL = $cssFilename;
3472                                 } else {
3473                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
3474                                 }
3475                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3476                         }
3477                         
3478                         // 管理画面用の共通スクリプトを読み込む
3479                         $count = count($this->defaultAdminScriptFiles);
3480                         for ($i = 0; $i < $count; $i++){
3481                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
3482
3483                                 // スクリプトのURLを修正
3484                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3485                                         $scriptURL = $scriptFilename;
3486                                         
3487                                         // SSLをページの状態に合わせる
3488                                         if ($isSslPage){
3489                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3490                                         } else {
3491                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3492                                         }
3493                                 } else {
3494                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3495                                 }
3496                         
3497                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3498                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3499                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3500                         }
3501                         
3502                         // ##### ページへJavascriptの埋め込む #####
3503                         // JavaScriptグローバル変数の設定
3504                         $rootUrl = $gEnvManager->getRootUrl();
3505                         if (empty($rootUrl)) $rootUrl = $gEnvManager->calcSystemRootUrl();
3506                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3507                         $replaceStr .= '//<![CDATA[' . M3_NL;
3508                         $replaceStr .= '// Magic3 Global values' . M3_NL;
3509                         if (!empty($rootUrl)) $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;           // システムルートURL
3510                         $replaceStr .= '//]]>' . M3_NL;
3511                         $replaceStr .= '</script>' . M3_NL;
3512                         return $replaceStr;
3513                 }
3514                 
3515                 // テンプレートの情報を取得
3516                 $cleanType = $gEnvManager->getCurrentTemplateCleanType();               // テンプレートクリーンタイプ
3517 /*              if ($this->db->getTemplate($gEnvManager->getCurrentTemplateId(), $templateRow)){
3518                         $cleanType = $templateRow['tm_clean_type'];
3519                 }*/
3520                 
3521                 // URLの作成
3522                 $isSslPage = false;
3523                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3524                         // 管理画面のSSL状態を参照
3525                         if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
3526                 } else {
3527                         $isSslPage = $this->isSslPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
3528                 }
3529                 if ($isSslPage){
3530                         $rootUrl = $gEnvManager->getSslRootUrl();
3531                         $scriptsUrl = $gEnvManager->getSslScriptsUrl();         // スクリプト読み込み用パス
3532                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
3533                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
3534                 } else {
3535                         $rootUrl = $gEnvManager->getRootUrl();
3536                         $scriptsUrl = $gEnvManager->getScriptsUrl();            // スクリプト読み込み用パス
3537                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
3538                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
3539                 }
3540
3541                 // タイトルの設定
3542                 if (!$this->showWidget){// 単体実行以外のとき
3543                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスの場合
3544                                 // 管理画面のタイトル
3545                                 // メイン画面は「サイト名 - 管理画面」、サブ画面は個別画面名
3546                                 $siteName = $gEnvManager->getSiteName();
3547 //                              if (empty($siteName)) $siteName = self::DEFAULT_SITE_NAME;
3548                                 $title = $siteName . ' - ' . self::DEFAULT_ADMIN_TITLE;
3549                                 $titleCount = count($this->headSubTitle);
3550                                 if ($titleCount > 0) $title = $this->headSubTitle[$titleCount -1];              // サブタイトルが設定されている場合は変更
3551                                 $replaceStr .= '<title>' . htmlspecialchars($title) . '</title>' . M3_NL;
3552                                 
3553                                 // その他HTMLヘッダに出力するタグ文字列
3554                                 if (!empty($this->adminHeadOthers)){
3555                                         // マクロを変換
3556                                         $this->adminHeadOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->adminHeadOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
3557                                         $replaceStr .= $this->adminHeadOthers . M3_NL;
3558                                 }
3559                         } else {                        // 管理画面以外の画面へのアクセスの場合
3560                                 // 画面タイトル
3561                                 $titleItemCount = 0;            // タイトル項目数
3562                                 $defaultTitle = trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_TITLE));
3563                                 if (!empty($defaultTitle)) $titleItemCount++;
3564                                 if (!empty($this->headSubTitle)){               // サブタイトルが設定されているとき
3565                                         $titleItemCount += count($this->headSubTitle);
3566                                 }
3567                                 // タイトルフォーマットを取得
3568                                 $title = '';
3569                                 if ($titleItemCount > 0){
3570                                         $format = $this->gSystem->getSystemConfig(self::CONFIG_KEY_HEAD_TITLE_FORMAT);
3571                                         if (empty($format)){
3572                                                 $title = htmlspecialchars($defaultTitle);
3573                                         } else {
3574                                                 $formats = explode(';', $format);
3575                                                 $titleItemCount = ($titleItemCount > count($formats)) ? count($formats) : $titleItemCount;
3576                                                 $title = $formats[$titleItemCount -1];
3577                                                 $number = 1;
3578                                                 if (!empty($defaultTitle)){
3579                                                         $title = str_replace('$1', htmlspecialchars($defaultTitle), $title);
3580                                                         $number++;
3581                                                 }
3582                                                 for ($i = 0; $i < count($this->headSubTitle); $i++){
3583                                                         $key = '$' . $number;
3584                                                         $value = htmlspecialchars(trim($this->headSubTitle[$i]));
3585                                                         $title = str_replace($key, $value, $title);
3586                                                         $number++;
3587                                                 }
3588                                         }
3589                                 }
3590                                 if (!empty($title)) $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
3591
3592                                 // サイトの説明
3593                                 if (!empty($this->headDescription)) $replaceStr .= '<meta name="description" content="' . htmlspecialchars($this->headDescription) . '" />' . M3_NL;
3594                 
3595                                 // 検索エンジン用キーワード
3596                                 if (!empty($this->headKeywords)) $replaceStr .= '<meta name="keywords" content="' . htmlspecialchars($this->headKeywords) . '" />' . M3_NL;
3597                                 
3598                                 // その他HTMLヘッダに出力するタグ文字列
3599                                 if (!empty($this->headOthers)){
3600                                         // マクロを変換
3601                                         $this->headOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->headOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
3602                                         $replaceStr .= $this->headOthers . M3_NL;
3603                                 }
3604                         }
3605                 }
3606                 
3607                 // ##### PC用URLと携帯用URLのアクセス別に処理 #####
3608                 if ($gEnvManager->getIsMobileSite()){           // 携帯用URLのとき
3609                 } else {                        // PC用URLまたはスマートフォン用URLのとき
3610                         // ##### テンプレート情報に応じた処理 #####
3611                         // テンプレートクリーンが必要な場合はJQueryを追加
3612                         if ($cleanType != 0) $this->addScriptFile($this->selectedJQueryFilename);               // JQueryスクリプト追加
3613                         
3614                         // 検索ロボットへの指示
3615                         $robots = htmlspecialchars(trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_ROBOTS)));
3616                         if (!empty($robots)){
3617                                 $replaceStr .= '<meta name="robots" content="' . $robots . '" />' . M3_NL;
3618                         }
3619                 
3620                         // サイト構築エンジン
3621                         $replaceStr .= '<meta name="generator" content="' . M3_SYSTEM_NAME . ' ver.' . M3_SYSTEM_VERSION . ' - ' . M3_SYSTEM_DESCRIPTION . '" />' . M3_NL;              
3622
3623                         // Faviconの読み込み
3624                         $templateId = $gEnvManager->getCurrentTemplateId();
3625                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3626                                 // テンプレートのFaviconがない場合はシステムのデフォルトのFaviconを使用
3627                                 $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3628                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
3629                                         $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3630                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3631                                 } else {
3632                                         // 管理画面のアイコンを設定
3633                                         $faviconPath = $gEnvManager->getSystemRootPath() . self::DEFAULT_ADMIN_FAVICON_FILE;
3634                                         if (file_exists($faviconPath)){         // ファイルが存在しているとき
3635                                                 $faviconFile = $rootUrl . self::DEFAULT_ADMIN_FAVICON_FILE;
3636                                                 $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3637                                         }
3638                                 }
3639                         } else {
3640                                 $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3641                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
3642                                         $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3643                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3644                                 }
3645                         }
3646                         // ##### 追加ライブラリの読み込み #####
3647                         if ($gEnvManager->getIsSmartphoneSite()){                       // スマートフォン用URLのとき
3648                                 $value = $gSystemManager->getSystemConfig(self::CF_SMARTPHONE_USE_JQUERY_MOBILE);// スマートフォン画面で常にjQuery Mobileを使用
3649                                 if ($value){
3650                                         // ##### jQueryMobileが読み込まれる前に読み込む必要があるスクリプトを設定 #####
3651                                         if (!empty($this->headPreMobileScriptFiles)){           // jQueryMobileファイルの前に出力
3652                                                 for ($l = 0; $l < count($this->headPreMobileScriptFiles); $l++){
3653                                                         $this->addScriptFile($this->headPreMobileScriptFiles[$l]);              // 通常機能用のスクリプト追加
3654                                                 }
3655                                         }
3656                                         $this->addScriptFile($this->selectedJQueryMobileFilename);
3657                                 }
3658                         }
3659                         
3660                         // ##### Ajaxライブラリの読み込み #####
3661                         if (!$gEnvManager->isAdminDirAccess()){         // 通常画面へのアクセスのとき
3662                                 if ($this->db->isExistsWidgetWithAjax($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId())){// Ajaxライブラリを使用しているウィジェットがあるときは追加
3663                                         $this->addScriptFile($this->selectedJQueryFilename);            // デフォルトAjaxライブラリ追加
3664                                         $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
3665                                 }
3666                         }
3667                                 
3668                         // ##### 共通ライブラリの読み込み #####
3669                         if (!$this->showWidget){// 単体実行以外のとき
3670                                 $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3671                                 for ($i = 0; $i < count($rows); $i++){
3672                                         $this->addScript($task, trim($rows[$i]['wd_add_script_lib']));
3673                                 }
3674                         }
3675
3676                         // ##### 共通CSS読み込み #####
3677                         if (($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()) || $this->isEditMode){                     // フロント画面編集モード
3678                                 $cssURL = $scriptsUrl . '/' . self::M3_EDIT_CSS_FILE;
3679                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3680                         }
3681                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3682                                 //if ($gEnvManager->isSystemAdmin()){           // 管理者権限がある場合のみ有効
3683                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3684                                         // 管理機能用共通ライブラリのCSSの読み込み
3685                                         $count = count($this->defaultAdminCssFiles);
3686                                         for ($i = 0; $i < $count; $i++){
3687                                                 // CSSへのURLを作成
3688                                                 //$cssURL = $scriptsUrl . '/' . $this->defaultAdminCssFiles[$i];
3689                                                 $cssFilename = $this->defaultAdminCssFiles[$i];
3690                                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3691                                                         $cssURL = $cssFilename;
3692                                                 } else {
3693                                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
3694                                                 }
3695                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3696                                         }
3697                                 } else {
3698                                         // 管理権限なしで管理ディレクトリアクセスで必要なCSSファイルを読み込む
3699                                         $count = count($this->defaultAdminDirCssFiles);
3700                                         for ($i = 0; $i < $count; $i++){
3701                                                 // CSSへのURLを作成
3702                                                 $cssURL = $scriptsUrl . '/' . $this->defaultAdminDirCssFiles[$i];
3703                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3704                                         }
3705                                 }
3706                         } else {
3707                                 // 共通ライブラリのCSSの読み込み
3708                                 $count = count($this->defaultCssFiles);
3709                                 for ($i = 0; $i < $count; $i++){
3710                                         // CSSへのURLを作成
3711                                         $cssFilename = $this->defaultCssFiles[$i];
3712                                         if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3713                                                 $cssURL = $cssFilename;
3714                                         } else {
3715                                                 $cssURL = $scriptsUrl . '/' . $cssFilename;
3716                                         }
3717                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3718                                 }
3719                         }
3720                         
3721                         // ##### 表示モードによるCSS読み込み #####
3722                         // ウィジェット付きポジション画面は管理画面のアクセスではない
3723                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
3724                                 // ウィジェット操作用CSS
3725                                 $cssURL = $scriptsUrl . self::M3_ADMIN_WIDGET_CSS_FILE;
3726                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3727                         }
3728                         
3729                         // ##### ウィジェットごとのCSS読み込み #####
3730                         // CSSがあるウィジェットを取得
3731                         $this->db->getWidgetsIdWithCss($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3732                         for ($i = 0; $i < count($rows); $i++){
3733                                 $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS;
3734                                 // ディレクトリがあるときはディレクトリ内読み込み
3735                                 if (is_dir($searchPath)){
3736                                         $dir = dir($searchPath);
3737                                         while (($file = $dir->read()) !== false){
3738                                                 $filePath = $searchPath . '/' . $file;
3739                                                 if ($file != '.' && $file != '..' && is_file($filePath)
3740                                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3741                                         
3742                                                         // CSSへのURLを作成
3743                                                         $cssURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS . '/' . $file;
3744                                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3745                                                 }
3746                                         }
3747                                         $dir->close();
3748                                 }
3749                         }
3750                         // ##### 外部出力用CSS読み込み #####
3751                         // ウィジェットからの追加のCSS読み込み
3752                         $count = count($this->headCssFiles);
3753                         for ($i = 0; $i < $count; $i++){
3754                                 $cssUrl = $this->headCssFiles[$i];
3755                                 if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3756                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . convertUrlToHtmlEntity($cssUrl) . '" />' . M3_NL;
3757                         }
3758                         
3759                         // 外部出力用CSSデータがある場合はURLを追加
3760                         if (!empty($this->exportCss)){
3761                                 $cssUrl = $this->createCssCmdUrl($isSslPage, date('YmdHis'));
3762                                 if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3763                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . convertUrlToHtmlEntity($cssUrl) . '" />' . M3_NL;
3764                         }
3765                         
3766                         // ##### RSS配信情報の読み込み #####
3767                         $count = count($this->headRssFiles);
3768                         for ($i = 0; $i < $count; $i++){
3769                                 $rssUrl = $this->headRssFiles[$i]['href'];// リンク先URL
3770                                 $rssTitle = $this->headRssFiles[$i]['title'];// タイトル
3771                                 $replaceStr .=  '<link rel="alternate" type="application/rss+xml" title="' . $rssTitle . '" href="' . convertUrlToHtmlEntity($rssUrl) . '" />' . M3_NL;
3772                         }
3773                                                                         
3774                         // ##### 共通Javascriptの読み込み #####
3775                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3776                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3777                                         // 管理画面用の共通スクリプトを読み込む
3778                                         $count = count($this->defaultAdminScriptFiles);
3779                                         for ($i = 0; $i < $count; $i++){
3780                                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
3781
3782                                                 // スクリプトのURLを修正
3783                                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3784                                                         $scriptURL = $scriptFilename;
3785                                                         
3786                                                         // SSLをページの状態に合わせる
3787                                                         if ($isSslPage){
3788                                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3789                                                         } else {
3790                                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3791                                                         }
3792                                                 } else {
3793                                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3794                                                 }
3795                                         
3796                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3797                                                 //$scriptURL = $scriptsUrl . '/' . $scriptFilename;
3798                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3799                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3800                                         }
3801                                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示のときは、ウィジェット操作ライブラリを読み込む
3802                                                 // wigetのドラッグドロップ用
3803                                                 $scriptURL = $scriptsUrl . '/' . self::M3_ADMIN_WIDGET_SCRIPT_FILENAME;
3804                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();// スクリプトをキャッシュ保存しない場合は、パラメータを付加
3805                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3806                                         }
3807                                 } else {                // システム運用権限がない場合
3808                                         // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
3809                                         $count = count($this->defaultAdminDirScriptFiles);
3810                                         for ($i = 0; $i < $count; $i++){
3811                                                 $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
3812
3813                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3814                                                 $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3815                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3816                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3817                                         }
3818                                 }
3819                         } else {                        // 通常画面
3820                                 // Googleマップライブラリの読み込み
3821                                 if ($this->useGooglemaps && $this->isContentGooglemaps) $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));  // コンテンツにGoogleマップが含むかどうか
3822
3823                                 $useExternalJquery = $gSystemManager->getSystemConfig(self::CF_EXTERNAL_JQUERY);                // システム外部のjQueryを使用するかどうか
3824                                 
3825                                 $count = count($this->defaultScriptFiles);
3826                                 for ($i = 0; $i < $count; $i++){
3827                                         $defaultScriptFile = $this->defaultScriptFiles[$i];
3828
3829                                         // 外部のjQueryを使用する場合はSCRIPTタグを出力しない
3830                                         if ($defaultScriptFile == $this->selectedJQueryFilename && $useExternalJquery) continue;
3831                                         
3832                                         // ##### jQueryMobileスクリプトを追加する場合は直前に初期化スクリプトを追加 #####
3833                                         if ($defaultScriptFile == $this->selectedJQueryMobileFilename){
3834                                                 if (count($this->headPreMobileScript) > 0){
3835                                                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3836                                                         $replaceStr .= '//<![CDATA[' . M3_NL;
3837                                                         for ($j = 0; $j < count($this->headPreMobileScript); $j++){
3838                                                                 $replaceStr .= $this->headPreMobileScript[$j];
3839                                                         }
3840                                                         $replaceStr .= M3_NL;
3841                                                         $replaceStr .= '//]]>' . M3_NL;
3842                                                         $replaceStr .= '</script>' . M3_NL;
3843                                                 }
3844                                         }
3845                                         
3846                                         // スクリプトのURLを修正
3847                                         if (strncasecmp($defaultScriptFile, 'http://', 7) == 0 || strncasecmp($defaultScriptFile, 'https://', 8) == 0){
3848                                                 $scriptURL = $defaultScriptFile;
3849                                                 
3850                                                 // SSLをページの状態に合わせる
3851                                                 if ($isSslPage){
3852                                                         $scriptURL = str_replace('http://', 'https://', $scriptURL);
3853                                                 } else {
3854                                                         $scriptURL = str_replace('https://', 'http://', $scriptURL);
3855                                                 }
3856                                         } else {
3857                                                 $scriptURL = $scriptsUrl . '/' . $defaultScriptFile;
3858                                         }
3859
3860                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3861                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3862                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3863                                 }
3864                                 
3865                                 if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW){                           // ログイン、ログアウト場合
3866                                         // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
3867                                         $count = count($this->defaultAdminDirScriptFiles);
3868                                         for ($i = 0; $i < $count; $i++){
3869                                                 $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
3870                                                 if (!in_array($scriptFilename, $this->defaultScriptFiles)){             // 既に追加されていない場合のみ追加
3871                                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3872                                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3873                                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3874                                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3875                                                 }
3876                                         }
3877                                 }
3878                                 
3879                                 // ***** [WordPressテンプレート] jQueryの読み込み後、ヘッダ部に出力するテンプレート用のJavascriptがあれば読み込む *****
3880                                 $headData = $this->gEnv->getWpHeadScriptsData();
3881                                 if (!empty($headData)) $replaceStr .= $headData;
3882                         }
3883                         // ##### ウィジェットごとのJavaScript読み込み #####
3884                         // スクリプトがあるウィジェットを取得
3885                         $this->db->getWidgetsIdWithScript($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3886                         for ($i = 0; $i < count($rows); $i++){
3887                                 $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS;
3888                         
3889                                 // ディレクトリがあるときはディレクトリ内読み込み
3890                                 if (is_dir($searchPath)){
3891                                         $dir = dir($searchPath);
3892                                         while (($file = $dir->read()) !== false){
3893                                                 $filePath = $searchPath . '/' . $file;
3894                                                 if ($file != '.' && $file != '..' && is_file($filePath)
3895                                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3896                                                 
3897                                                         // スクリプトへのURLを作成
3898                                                         $scriptURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
3899                                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3900                                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3901                                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3902                                                 }
3903                                         }
3904                                         $dir->close();
3905                                 }
3906                         }
3907                         // ウィジェットからの追加のCSS読み込み
3908                         $count = count($this->headScriptFiles);
3909                         for ($i = 0; $i < $count; $i++){
3910                                 $scriptUrl = $this->headScriptFiles[$i];
3911                                 if ($isSslPage) $scriptUrl = str_replace('http://', 'https://', $scriptUrl);                    // SSL化が必要なときは変換
3912                 
3913                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3914                                 if (!$this->hasScriptCache) $scriptUrl .= $this->getCacheParam();
3915                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptUrl) . '"></script>' . M3_NL;
3916                         }
3917                         
3918                         // 設定値取得
3919                         $openType = $this->gSystem->getSystemConfig(self::CF_CONFIG_WINDOW_OPEN_TYPE);// ウィジェット設定画面のウィンドウ表示タイプ(0=別ウィンドウ、1=タブ)
3920                         
3921                         // ##### ページへJavascriptの埋め込む #####
3922                         // JavaScriptグローバル変数の設定
3923                         //$replaceStr .= '<script type="text/javascript">' . M3_NL;
3924                         //$replaceStr .= '<!--' . M3_NL;
3925                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3926                         $replaceStr .= '//<![CDATA[' . M3_NL;
3927                         $replaceStr .= '// Magic3 Global values' . M3_NL;
3928                         $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;         // システムルートURL
3929
3930                         if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()){            // 管理画面へのアクセス、システム運用権限があり
3931                                 $pageId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);          // ページID
3932                                 $pageSubId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);// ページサブID
3933                                         
3934                                 // 管理画面のオープン設定
3935                                 $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
3936                                 if ($openType != '') $replaceStr .= 'var M3_CONFIG_WINDOW_OPEN_TYPE = ' . $openType . ';' . M3_NL;
3937                                 
3938                                 // ページID、ページサブID
3939                                 $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
3940                                 $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
3941                                 // WYSIWYGエディター
3942                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
3943                                 
3944                                 // ファイルブラウザ
3945                                 $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;           // バージョン
3946                                 $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
3947                                 $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
3948         
3949                                 // Googleマップライブラリの読み込み
3950                                 if ($this->useGooglemaps){
3951                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
3952                                         
3953                                         // CKEditor拡張プラグイン用の定義
3954                                         $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
3955                                         if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
3956                                 } else {
3957                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
3958                                 }
3959
3960                                 // 管理画面の小画面デバイス最適化を行うかどうか
3961                                 if ($gEnvManager->isSmallDeviceAdmin()){
3962                                         $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = true;' . M3_NL;
3963                                 } else {
3964                                         $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = false;' . M3_NL;
3965                                 }
3966                                 
3967                                 // ウィジェット詳細設定画面専用のJavaScriptグローバル変数
3968                                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){
3969                                         // ##### CKEditor用の設定 #####
3970                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
3971                                         
3972                                         // CKEditor用のCSSファイル
3973                                         if (!empty($this->ckeditorCssFiles)){
3974                                                 // 編集エリア用のCSSファイルを追加
3975                                                 $this->ckeditorCssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
3976                                                 //array_unshift($this->ckeditorCssFiles, $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE);
3977                                                 
3978                                                 $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $this->ckeditorCssFiles));
3979                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
3980                                         }
3981                                         // CKEditor用(レイアウト)のCSSファイル
3982                                         $cssFiles = array();
3983                                         $cssFiles[] = $scriptsUrl . '/' . ScriptLibInfo::BOOTSTRAP_ADMIN_CSS;           // BootstrapのCSSを追加
3984                                         $cssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
3985                                         $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $cssFiles));
3986                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_LAYOUT_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
3987                                         
3988                                         // CKEditor用のテンプレートタイプ
3989                                         if (isset($this->ckeditorTemplateType)){
3990                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_TEMPLATE_TYPE = ' . $this->ckeditorTemplateType . ';' . M3_NL;
3991                                         }
3992                                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // ウィジェット付きポジション表示
3993                                         // その他のポジションデータを取得
3994                                         $positionData = $this->getRestPositionData();
3995                                         
3996                                         // テンプレート上のポジション名
3997                                         if (count($this->viewPosId) > 0){
3998                                                 $posArrayStr = '[';
3999                                                 for ($i = 0; $i < count($this->viewPosId); $i++){
4000                                                         $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
4001                                                         if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
4002                                                 }
4003                                                 $posArrayStr .= ']';
4004                                                 $replaceStr .= 'var M3_POSITIONS = ' . $posArrayStr . ';' . M3_NL;
4005                                         }
4006                                         // 画面定義のリビジョン番号
4007                                         $replaceStr .= 'var M3_REVISION = ' . $this->pageDefRev . ';' . M3_NL;
4008                                         
4009                                         // その他のポジションデータ
4010                                         $replaceStr .= 'var M3_REST_POSITION_DATA = \'' . $positionData . '\';' . M3_NL;
4011                                 } else if (!empty($pageId)){
4012                                         $accessPoint = $this->gEnv->getAllDefaultPageId();
4013                                         for ($i = 0; $i < count($accessPoint); $i++){
4014                                                 if ($pageId == $accessPoint[$i]){
4015                                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $i . ';' . M3_NL;                        // ウィジェット設定画面のウィジェットの端末タイプ
4016                                                         break;
4017                                                 }
4018                                         }
4019                                 } else {                // メインの管理画面の場合
4020                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = 0;' . M3_NL;                 // 管理画面画面の端末タイプ(主にテスト用に使用)
4021                                 }
4022                                                 
4023                                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
4024                                         if (!empty($task)){             // 戻りタスクが設定されているときのみ最大化可能
4025                                                 $replaceStr .= 'function gobackPagedef(){' . M3_NL;
4026                                                 $replaceStr .= '    window.location.href = "' . $gEnvManager->getDefaultAdminUrl() . '?pageid=' . $pageId . '&pagesubid=' . $pageSubId . '&task=' . $task . '";' . M3_NL;
4027                                                 $replaceStr .= '}' . M3_NL;
4028                                                 $replaceStr .= '$(function(){' . M3_NL;
4029                                                 $replaceStr .= '    $(document).keyup(function(e){' . M3_NL;
4030                                                 $replaceStr .= '        if (e.which == 36) gobackPagedef();' . M3_NL;
4031                                                 $replaceStr .= '    });' . M3_NL;
4032                                                 $replaceStr .= '});' . M3_NL;
4033                                         }
4034                                 } else {
4035                                         // ##### 管理用テンプレートを使用している場合の処理 #####
4036                                         // Bootstrap用のスクリプト処理
4037                                         if ($this->useBootstrap){
4038                                                 $replaceStr .= '$(function(){' . M3_NL;
4039                                                 $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
4040                                                 $replaceStr .= '});' . M3_NL;
4041                                         }
4042                                 }
4043                         } else if ($this->isPageEditable){              // フロント画面ページ編集可能モードのとき
4044                                 $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
4045                                 if ($openType != '') $replaceStr .= 'var M3_CONFIG_WINDOW_OPEN_TYPE = ' . $openType . ';' . M3_NL;
4046                                 
4047                                 // ページID、ページサブID
4048                                 $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
4049                                 $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
4050                                 // WYSIWYGエディター
4051                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4052                                 
4053                                 // ファイルブラウザ
4054                                 $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;   // バージョン
4055                                 $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4056                                 $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4057                                 
4058                                 // テンプレートタイプ
4059                                 $templateType = $gEnvManager->getCurrentTemplateType();
4060                                 if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4061                         } else if ($this->isEditMode){                  // フロント画面編集モード(コンテンツ編集可能ユーザ)
4062                                 if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                               // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
4063                                         // WYSIWYGエディター
4064                                         $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4065                                 
4066                                         // ファイルブラウザ
4067                                         $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;   // バージョン
4068                                         $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4069                                         $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4070                                 
4071                                         // Googleマップライブラリの読み込み
4072                                         if ($this->useGooglemaps){
4073                                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
4074                                                 
4075                                                 // CKEditor拡張プラグイン用の定義
4076                                                 $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
4077                                                 if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
4078                                         } else {
4079                                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
4080                                         }
4081                                 
4082                                         // 管理画面の小画面デバイス最適化を行うかどうか
4083                                         if ($gEnvManager->isSmallDeviceAdmin()){
4084                                                 $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = true;' . M3_NL;
4085                                         } else {
4086                                                 $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = false;' . M3_NL;
4087                                         }
4088                                 
4089                                         // ##### CKEditor用の設定 #####
4090                                         // ウィジェット情報取得
4091                                         $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
4092                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
4093                                 
4094                                         // CKEditor用のCSSファイル
4095                                         if (!empty($this->ckeditorCssFiles)){
4096                                                 // 編集エリア用のCSSファイルを追加
4097                                                 $this->ckeditorCssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4098                                                 //array_unshift($this->ckeditorCssFiles, $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE);
4099                                         
4100                                                 $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $this->ckeditorCssFiles));
4101                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4102                                         }
4103                                         // CKEditor用(レイアウト)のCSSファイル
4104                                         $cssFiles = array();
4105                                         $cssFiles[] = $scriptsUrl . '/' . ScriptLibInfo::BOOTSTRAP_ADMIN_CSS;           // BootstrapのCSSを追加
4106                                         $cssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4107                                         $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $cssFiles));
4108                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_LAYOUT_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4109                                         
4110                                         // CKEditor用のテンプレートタイプ
4111                                         if (isset($this->ckeditorTemplateType)){
4112                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_TEMPLATE_TYPE = ' . $this->ckeditorTemplateType . ';' . M3_NL;
4113                                         }
4114                                         
4115                                         // Bootstrap用のスクリプト処理
4116                                         if ($this->useBootstrap){
4117                                                 $replaceStr .= '$(function(){' . M3_NL;
4118                                                 $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
4119                                                 $replaceStr .= '});' . M3_NL;
4120                                         }
4121                                 } else {
4122                                         // プレビュー画面用にテンプレートタイプを出力
4123                                         $templateType = $gEnvManager->getCurrentTemplateType();
4124                                         if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4125                                         
4126                                         // ##### ヘルプシステムの組み込み #####
4127                                         if ($this->useHelp){                    // ヘルプ表示のとき
4128                                                 $replaceStr .= '$(function(){' . M3_NL;
4129                                                 $replaceStr .= '    if (jQuery().tooltip) $(\'[rel=m3help]\').tooltip({ placement: \'top\'});' . M3_NL;
4130                                                 $replaceStr .= '});' . M3_NL;
4131                                         }
4132                                 }
4133                         } else {                        // 権限なしの場合
4134                                 if (!$gEnvManager->isAdminDirAccess()){                 // フロント画面のとき
4135                                         // テンプレートタイプを追加(ファイルローダ等で使用)
4136                                         $templateType = $gEnvManager->getCurrentTemplateType();
4137                                         if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4138                                 }
4139                         }
4140                         
4141                         // ##### パネルメニュー(フロント画面と管理画面の切り替え等)の表示 #####
4142                         // PC用、携帯用、スマートフォン用画面とウィジェット付きポジションの管理画面時に表示
4143                         if (($gEnvManager->isAdminDirAccess() && $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) ||           // 管理画面(ウィジェット付きポジション表示)のとき
4144                                 (!$gEnvManager->isAdminDirAccess() &&                                                   // 一般用画面のとき
4145                                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
4146                                         $cmd != M3_REQUEST_CMD_RSS)){                                                           // RSS配信でない
4147                                 //if ($gEnvManager->isSystemAdmin()){                           // 管理者権限がある場合のみ有効
4148                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限ありの場合
4149                                         // トップメニュー項目作成
4150                                         $menubarTag = '';       // 管理用メニューバー
4151                                         $adminTag = '';         // 管理画面ボタン
4152                                         $editTag = '';          // 編集ボタン
4153                                         $logoutTag = '';                // ログアウトボタン
4154                                         
4155                                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面(ウィジェット付きポジション表示)の場合
4156                                                 // 編集ボタン
4157 /*                                              $titleStr = '編集終了';
4158                                                 $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4159                                                 if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4160                                                 $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
4161                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></li>';
4162                                                 */
4163                                                 $titleStr = '編集終了';
4164                                                 $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4165                                                 if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4166                                                 //$editTag = '<div class="m3editend"><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4167                                                 //$editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" /></a></div>';
4168                                                 $editTag = '<div class="m3editend m3topright"><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4169                                                 $editTag .= '<i class="glyphicon glyphicon-ok-sign"></i></a></div>';
4170                                                 $menubarTag .= $editTag;
4171                                                 
4172                                 //              $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
4173                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window == window.parent){' . M3_NL;// インラインフレームでないときパネルメニューを表示(修正 2016/9/1)
4174                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").prepend(\'' . $menubarTag . '\');' . M3_NL;            // appendでうまく表示できないのでprependで表示
4175                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
4176                                         } else if ($this->isAccessPointWithAdminMenu){          // 通常画面は、管理メニューを使用するアクセスポイントの場合のみ表示
4177                                                 // 管理画面ボタン
4178                                                 $titleStr = '管理画面へ遷移';
4179                                                 $linkUrl = $gEnvManager->getDefaultAdminUrl();
4180                                                 $adminTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4181                                                 $adminTag .= '<img src="' . $rootUrl . self::ADMIN_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4182                                         
4183                                                 // 編集ボタン
4184                                                 $titleStr = '画面を編集';
4185                                                 $linkUrl  = $gEnvManager->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' .M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET;
4186                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_ID . '=' . $gEnvManager->getCurrentPageId();
4187                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
4188                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_BACKUP_URL . '=' . urlencode($gEnvManager->getCurrentRequestUri());                  // URL退避用
4189                                                 $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4190                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_PAGE_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4191                                                 
4192                                                 // ログアウトボタン
4193                                                 $titleStr = 'ログアウト';
4194 //                                              if ($gEnvManager->isAdminDirAccess()){          // 管理画面の場合
4195 //                                                      $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4196 //                                                      if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4197 //                                              } else {
4198                                                         $linkUrl = $gEnvManager->getCurrentRequestUri();
4199 //                                              }
4200                                                 $linkUrl = createUrl($linkUrl, M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_LOGOUT);
4201                                                 $logoutTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4202                                                 $logoutTag .= '<img src="' . $rootUrl . self::LOGOUT_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4203                                         
4204                                                 // ウィジェットツール表示制御ボタン
4205                                                 $widgetToolTag .= '<li><div class="m3widgettoolbutton m3-nav m3-navbar-nav" data-toggle="buttons">';
4206                                                 $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>';
4207                                                 $widgetToolTag .= '<input type="checkbox" class="hidden" />';
4208                                                 $widgetToolTag .= '</div></li>';
4209                                                 
4210                                                 //$menubarTag .= '<div id="m3slidepanel">';
4211                                                 $menubarTag .= '<div id="m3slidepanel" class="m3panel_top m3-navbar-default" style="top:-60px; visibility: visible;">';
4212                                                 $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>';                           
4213                                 //              $menubarTag .= '<div tabindex="0" class="m3panel_wrap">';
4214                                                 $menubarTag .= '<div>';
4215                                                 $menubarTag .= '<ul class="m3-nav m3-navbar-nav">';
4216                                                 if ($gEnvManager->isSystemAdmin()){                             // 管理画面、編集モードは、管理者権限がある場合のみ有効
4217                                                         $menubarTag .= $adminTag;
4218                                                         $menubarTag .= $editTag;
4219                                                 }
4220                                                 $menubarTag .= $logoutTag;
4221                                                 $menubarTag .= $widgetToolTag;
4222                                                 $menubarTag .= '</ul>';
4223                                                 $menubarTag .= '</div>';
4224                                                 $menubarTag .= '</div>';
4225                                         //      $menubarTag .= '</div>';
4226
4227                                         //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
4228                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window == window.parent){' . M3_NL;// インラインフレームでないときパネルメニューを表示(修正 2016/9/1)
4229                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").append(\'' . $menubarTag . '\');' . M3_NL;
4230                                                 //$this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("#m3slidemenubarpanel").m3SlideMenubar();' . M3_NL;
4231                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(".m3panel_top").m3slidepanel({ "position": "top", "type": "push" });' . M3_NL;
4232                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").css("position", "relative");' . M3_NL;
4233                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'm3SetHelp($(\'#m3slidepanel\'));' . M3_NL;
4234                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'm3SetupWidgetTool(\'m3widgettoolbutton\');' . M3_NL;
4235                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
4236                                         }
4237                                 }
4238                         }
4239                         // ##### フロント画面からのウィジェット操作用ツールバー #####
4240                         if (!$gEnvManager->isAdminDirAccess() && 
4241                                 $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
4242                                 $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
4243                                 if ($gEnvManager->isSystemManageUser()){                // 一般用画面で管理者権限がある場合のみ有効
4244                                         // 管理用ツールバー
4245                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').each(function(){' . M3_NL;
4246                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var attrs = m3_splitAttr($(this).attr(\'m3\'));' . M3_NL;
4247                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var widgetId = attrs[\'widgetid\'];' . M3_NL;
4248                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var serialNo = attrs[\'serial\'];' . M3_NL;
4249                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var configId = attrs[\'configid\'];' . M3_NL;
4250                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var useconfig = attrs[\'useconfig\'];' . M3_NL;
4251                                         
4252                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'\';' . M3_NL;
4253                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (useconfig == 1){' . M3_NL;
4254                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
4255                                                                                 'html += \'<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\\\'\' + widgetId + \'\\\', \' + configId + \', \' + serialNo + \');return false;" rel="m3help" data-container="body" title="ウィジェット設定">' .
4256                                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON32_FILE . '" alt="ウィジェット設定" width="32" height="32" /></a>\';' . M3_NL;
4257                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4258                                         if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
4259                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 
4260                                                                                         '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="タイトル・スタイル調整">' .
4261                                                                                         '<img src="' . $rootUrl . self::ADJUST_ICON32_FILE . '" alt="タイトル・スタイル調整" width="32" height="32" /></a>\';' . M3_NL;
4262                                         }
4263                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (html != \'\'){' . M3_NL;
4264                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
4265                                                                                         'html = \'<div class="m3tooltip" style="display:none;">\' + html + \'<a class="m3closebox" href="javascript:void(0);" rel="m3help" data-container="body" title="閉じる">' . 
4266                                                                                         '<img src="' . $rootUrl . self::CLOSE_BOX_ICON32_FILE . '" alt="閉じる" width="11" height="11" /></a></div>\';' . M3_NL;
4267                                                                                         
4268                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).append(html);' . M3_NL;
4269                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4270                                         // クリックイベントの設定
4271                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).click(function(){' . M3_NL;
4272                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4273                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (tooltipObj.css(\'display\') == \'none\'){' . M3_NL;
4274                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (_m3ShowWidgetTool){' . M3_NL;
4275                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'tooltipObj.show();' . M3_NL;
4276                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
4277                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
4278                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.hide();' . M3_NL;
4279                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4280                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4281                                         // ウィジェットボーダーハイライト、ツールチップ表示
4282                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).hover(function(){' . M3_NL;
4283                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (_m3ShowWidgetTool){' . M3_NL;
4284                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(this).addClass(\'m3_widget_highlight\');' . M3_NL;
4285                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4286                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var pos = $(this).position();' . M3_NL;
4287                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var width = $(this).outerWidth();' . M3_NL;
4288                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var tooltipWidth = tooltipObj.outerWidth(true);' . M3_NL;
4289                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var x = pos.left + width - tooltipWidth;' . M3_NL;
4290                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var y = pos.top;' . M3_NL;
4291                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.css({position: "absolute",top: y + "px", left: x + "px"}).show();' . M3_NL;
4292                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4293                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}, function(){' . M3_NL;
4294                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).removeClass(\'m3_widget_highlight\');' . M3_NL;
4295                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4296                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'tooltipObj.hide();' . M3_NL;
4297                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4298                                         // 閉じるボタン処理
4299                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3closebox\').click(function(event){' . M3_NL;
4300                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).children(\'.m3tooltip\').hide();' . M3_NL;
4301                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4302                                         // コンテンツ編集ボタンの位置修正
4303                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
4304                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var offset = $(this).offset();' . M3_NL;
4305                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).outerWidth();' . M3_NL;
4306                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3edittool\').each(function(){' . M3_NL;
4307                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).offset({left: offset.left});' . M3_NL;
4308                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).width(width);' . M3_NL;
4309                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4310                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4311                                         
4312                                         // コンテキストメニューを作成
4313                                         $this->initScript .= M3_INDENT_SPACE . 'var widgetWindow = \'<div class="m3_contextmenu" id="m3_widgetmenu" style="visibility:hidden;">\';' . M3_NL;
4314                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'<ul>\';' . M3_NL;
4315                                         $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;
4316                                         if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
4317                                                 $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;
4318                                         }
4319                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</ul>\';' . M3_NL;
4320                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</div>\';' . M3_NL;
4321                                         $this->initScript .= M3_INDENT_SPACE . '$("body").append(widgetWindow);' . M3_NL;
4322                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').contextMenu(\'m3_widgetmenu\', {' . M3_NL;
4323                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'menuStyle: {' . M3_NL;
4324                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// border : "2px solid green",' . M3_NL;
4325                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'backgroundColor: \'#FFFFFF\',' . M3_NL;
4326                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'width: "150px",' . M3_NL;
4327                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'textAlign: \'left\',' . M3_NL;
4328                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'font: \'12px/1.5 Arial, sans-serif\'' . M3_NL;
4329                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4330                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'itemStyle: {' . M3_NL;
4331                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'padding: \'3px 3px\'' . M3_NL;
4332                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4333                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'bindings: {' . M3_NL;
4334                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wconfig\': function(t){' . M3_NL;
4335                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
4336                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
4337                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'alert("このウィジェットには設定画面がありません");' . M3_NL;
4338                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'return;' . M3_NL;
4339                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
4340                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowConfigWindow(attrs[\'widgetid\'], attrs[\'configid\'], attrs[\'serial\']);' . M3_NL;
4341                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '},' . M3_NL;
4342                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wadjust\': function(t){' . M3_NL;
4343                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
4344                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowAdjustWindow(attrs[\'configid\'], attrs[\'serial\'], M3_PAGE_ID, M3_PAGE_SUB_ID);' . M3_NL;
4345                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4346                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4347                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onContextMenu: function(e){' . M3_NL;
4348                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (_m3ShowWidgetTool){' . M3_NL;
4349                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'return true;' . M3_NL;
4350                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
4351                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'return false;' . M3_NL;
4352                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4353                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4354                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onShowMenu: function(e, menu){' . M3_NL;
4355                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// メニュー項目の変更' . M3_NL;
4356                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var attrs = m3_splitAttr($(e.target).parents(\'dl\').attr(\'m3\'));' . M3_NL;
4357                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
4358                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(\'#m3_wconfig\', menu).remove();' . M3_NL;
4359                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4360                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'return menu;' . M3_NL;
4361                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4362                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4363                                         
4364                                         // コンテンツの「非公開」表示
4365                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3content_private\').each(function(){' . M3_NL;
4366 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
4367 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var top = pos.top;' . M3_NL;
4368 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var left = pos.left;' . M3_NL;
4369 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).css(\'width\');' . M3_NL;
4370 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var height = $(this).css(\'height\');' . M3_NL;
4371                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'<div class="m3content_overlay"><div><h2>非公開</h2></div></div>\';' . M3_NL;
4372                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).prepend(html);' . M3_NL;
4373                                 //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var overlayObj = $(this).children(\'.m3content_overlay div\');' . M3_NL;
4374                                 //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'overlayObj.css({ position:"absolute", top:top + "px", left:left + "px" }).show();' . M3_NL;
4375                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4376                                 }
4377                         }
4378                         // ##### フロント画面のデフォルトのJavaスクリプト #####
4379 //                      if (!$gEnvManager->isAdminDirAccess()){
4380 //                              $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (jQuery().tooltip) $(\'[rel=tooltip]\').tooltip();' . M3_NL;          // 標準ツールチップ作成
4381 //                      }
4382                         // ポップアップメッセージがある場合は表示
4383                         if (!empty($this->popupMsg)){
4384                                 $replaceStr .=  'alert("' . $this->popupMsg . '");' . M3_NL;
4385                         }
4386                         // テンプレートに応じた処理
4387                         if ($cleanType == 1){
4388                                 // HTMLのクリーン処理が必要なときはコードを埋め込む
4389                                 $this->initScript .= '    $(\'.PostHeaderIcons\').remove();' . M3_NL;// 不要なアイコン表示タグの削除
4390                                 $this->initScript .= '    $(\'.PostMetadataHeader\').each(function(i){' . M3_NL;
4391                                 $this->initScript .= '        if ($(this).text().trim() == \'\') $(this).remove();' . M3_NL;
4392                                 $this->initScript .= '    });' . M3_NL;
4393                         }
4394                         
4395                         // 管理画面用スクリプト追加
4396                         $replaceStr .= $this->getLastContents();
4397                         
4398                         // 初期処理用スクリプト埋め込み
4399                         if (!empty($this->initScript)){
4400                                 $replaceStr .= '$(function(){' . M3_NL;
4401                                 $replaceStr .= $this->initScript;
4402                                 $replaceStr .= '});' . M3_NL;
4403                         }
4404                         
4405                         //$replaceStr .= '// -->' . M3_NL;
4406                         //$replaceStr .= '</script>' . M3_NL;
4407                         $replaceStr .= '//]]>' . M3_NL;
4408                         $replaceStr .= '</script>' . M3_NL;
4409
4410                         // HEADタグに埋め込むCSS,JavaScript,任意文字列
4411                         if (count($this->headCss) > 0){
4412                                 // CSSの場合は全体をstyleタグで囲む
4413                                 $replaceStr .= '<style type="text/css">' . M3_NL;
4414                                 $replaceStr .= '<!--' . M3_NL;
4415                                 for ($i = 0; $i < count($this->headCss); $i++){
4416                                         $replaceStr .= $this->headCss[$i];
4417                                 }
4418                                 $replaceStr .= M3_NL . '//-->' . M3_NL;
4419                                 $replaceStr .= '</style>' . M3_NL;
4420                         }
4421                         if (count($this->headScript) > 0){
4422                                 // JavaScriptの場合は全体をscriptタグで囲む
4423                                 //$replaceStr .= '<script type="text/javascript">' . M3_NL;
4424                                 //$replaceStr .= '<!--' . M3_NL;
4425                                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
4426                                 $replaceStr .= '//<![CDATA[' . M3_NL;
4427                                 for ($i = 0; $i < count($this->headScript); $i++){
4428                                         $replaceStr .= $this->headScript[$i];
4429                                 }
4430                                 //$replaceStr .= M3_NL . '//-->' . M3_NL;
4431                                 //$replaceStr .= '</script>' . M3_NL;
4432                                 $replaceStr .= M3_NL;
4433                                 $replaceStr .= '//]]>' . M3_NL;
4434                                 $replaceStr .= '</script>' . M3_NL;
4435                         }
4436                         if (count($this->headString) > 0){
4437                                 // 任意文字列の場合はそのまま追加
4438                                 for ($i = 0; $i < count($this->headString); $i++){
4439                                         $replaceStr .= $this->headString[$i];
4440                                 }
4441                         }
4442                 }
4443                 return $replaceStr;
4444         }
4445         /**
4446          * 各部品のHTML出力
4447          *
4448          * @param string $position                      HTMLテンプレート上の書き出し位置
4449          * @param string $style                         ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
4450          * @param int    $templateVer           テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
4451          * @param array  $attr                          その他属性
4452          * @return string                                       出力コンテンツ
4453          */
4454         function getContents($position, $style = '', $templateVer = 0, $attr = array())
4455         {
4456                 static $render;         // HTML生成オブジェクト
4457                 global $gRequestManager;
4458                 global $gEnvManager;
4459                 
4460                 // ファイル名、ページ名を取得
4461                 $filename       = $gEnvManager->getCurrentPageId();
4462                 $subId          = $gEnvManager->getCurrentPageSubId();
4463                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
4464
4465                 // ポジション名表示モードに応じて出力を作成
4466                 $contents = '';         // 出力コンテンツ
4467                 switch ($this->showPositionMode){
4468                         case 0:         // 通常画面
4469                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
4470                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
4471                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
4472                                         if ($ret){      // 1行以上データが取得できたとき
4473                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
4474                                                 $this->pageDefPosition = $position;
4475                                         } else {
4476                                                 $this->pageDefRows = array();
4477                                                 $this->pageDefPosition = '';
4478                                         }
4479                                 }
4480                                 // ウィジェットを実行
4481                                 $count = count($this->pageDefRows);
4482                                 
4483                                 if ($templateVer == 0){                 // ########## Joomla!v1.0テンプレートの場合 ##########
4484                                         ob_start();// バッファ作成
4485
4486                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
4487                                         $widgetHeaderType = $this->getTemplateWidgetHeaderType();
4488                                         for ($i = 0; $i < $count; $i++){
4489                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4490                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4491                                                 
4492                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4493                                                 // キャッシュデータがあるときはキャッシュデータを使用
4494                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4495
4496                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4497                                                         ob_clean();
4498                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $titleTag, $widgetHeaderType);
4499                                                         if (!$ret) break;
4500                                                         $widgetContent = ob_get_contents();
4501                                                         
4502                                                         // ウィジェット共通のコンテンツ処理
4503                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4504
4505                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4506                                                 //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4507                                                                                 
4508                                                         // キャッシュデータを設定
4509                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4510                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4511                                                                                                                         
4512                                                         // ウィジェットの外枠タグを設定
4513                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4514                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4515                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4516                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
4517                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4518                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4519                                                                 // ウィジェット表示タイプによる表示制御
4520                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4521                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4522                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4523                                                                 if (!empty($controlType)){
4524                                                                         switch ($controlType){
4525                                                                                 case 1:                 // ログイン時のみ表示
4526                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_VISIBLE_IN_LOGIN_CLASS;        // ログイン時のみ表示ウィジェットクラス
4527                                                                                         break;
4528                                                                                 case 2:                 // 非ログイン時のみ表示
4529                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_VISIBLE_IN_NOT_LOGIN_CLASS;    // 非ログイン時のみ表示ウィジェットクラス
4530                                                                                         break;
4531                                                                                 default:
4532                                                                                         break;
4533                                                                         }
4534                                                                 }
4535                                                                 if (!empty($pageState)){
4536                                                                         switch ($pageState){
4537                                                                                 case 1:                 // トップ時のみ表示
4538                                                                                         if (!$this->isPageTopUrl) $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;             // ページトップ(サブページ内のトップ位置)でなければ非表示
4539                                                                                         break;
4540                                                                                 default:
4541                                                                                         break;
4542                                                                         }
4543                                                                 }
4544                 
4545                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4546                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4547                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4548                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4549                                                                 $shared = '0';          // 共通属性があるかどうか
4550                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4551                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4552                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4553                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . '>' . $widgetContent . '</div>';
4554                                                         } else {
4555                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4556                                                                 $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4557                                                         }
4558                                                 } else {                // キャッシュデータがあるとき
4559                                                         $widgetContent = $cacheData;
4560                                                         
4561                                                         // HTMLのメタタグを設定
4562                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4563                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4564                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4565                                                 }
4566                                                 $contents .= $widgetContent;
4567                                                 
4568                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4569                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4570                                                 if (!empty($exportCss)){
4571                                                         // ウィジェットのタグIDを変換
4572                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4573                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4574                                                         $this->addExportCss($exportCss);
4575                                                 }
4576                                         }
4577                                         ob_end_clean();         // バッファ破棄
4578                                         
4579                                         if ($i < $count) return '';// 処理中断のときは終了
4580                                 } else if ($templateVer == 100){                        // ########## WordPressテンプレートの場合 ##########
4581                                         ob_start();// バッファ作成
4582
4583                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
4584                                         //$widgetHeaderType = $this->getTemplateWidgetHeaderType();
4585                                         for ($i = 0; $i < $count; $i++){
4586                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4587                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4588                                                 
4589                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4590                                                 // キャッシュデータがあるときはキャッシュデータを使用
4591                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4592
4593                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4594                                                         // WordPressウィジェット用のパラメータ設定
4595                                                         $gEnvManager->setWpWidgetClass('');                             // ウィジェットクラス名初期化
4596                                                         
4597                                                         ob_clean();
4598                                         //              $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $titleTag, $widgetHeaderType);
4599                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $titleTag, 0/*タイトル出力なし*/);
4600                                                         if (!$ret) break;
4601                                                         $widgetContent = ob_get_contents();
4602
4603                                                         // WordPressウィジェット用のパラメータ設定
4604                                                         $widgetClassName = $gEnvManager->getWpWidgetClass();                            // ウィジェットクラス名
4605                                                         
4606                                                         $trimContent = trim($widgetContent);
4607                                                         if (!empty($trimContent)){              // 出力が空でない場合
4608                                                         
4609                                                                 // オブジェクト作成
4610                                                                 if (!isset($render)) $render = new WPRender();          // WordPress用HTML生成オブジェクト
4611                                                         
4612                                                                 // デフォルトのウィジェットタイトル取得
4613                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
4614                                         
4615                                                                 // Joomla用のパラメータを取得
4616                                                                 //$joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
4617
4618                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
4619                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
4620                                         
4621                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
4622                                                                 $title = $this->pageDefRows[$i]['pd_title'];
4623                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
4624                                                                         if (empty($title)) $title = $defaultTitle;
4625                                                                 } else {
4626                                                                         $title = '';                    // タイトルは非表示
4627                                                                 }
4628                                                         
4629                                                                 // WordPress用パラメータ作成
4630                                                                 $params = array();                              // ウィジェットごとの属性
4631                                                                 if (!empty($widgetClassName))  $params['moduleclass'] = $widgetClassName;       // ウィジェットクラス名
4632                                                                                 
4633                                                                 // ウィジェット生成
4634                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . ($i + 1);                                // ウィジェット識別用ユニークタグ
4635                                                                 
4636                                                                 if (strcmp($position, 'main') == 0){// メイン部のとき
4637                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer, $widgetTag);
4638                                                                 } else {
4639                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer, $widgetTag);
4640                                                                 }
4641                                                         
4642                                                                 // ウィジェット共通のコンテンツ処理
4643                                                         //      $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4644
4645                                                                 // ウィジェットの内枠(コンテンツ外枠)を設定
4646                                                         //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4647                                                         }
4648                                                         
4649                                                         // キャッシュデータを設定
4650                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4651                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4652                                                                                                                         
4653                                                         // ウィジェットの外枠タグを設定
4654                                         //              $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4655                                         //              $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4656                                         //              if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4657                                         //              $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
4658                                         //              $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4659                                         
4660                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4661                                                                 // ウィジェット表示タイプによる表示制御
4662                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4663                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4664                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4665                                                                 if (!empty($controlType)){
4666                                                                         switch ($controlType){
4667                                                                                 case 1:                 // ログイン時のみ表示
4668                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_VISIBLE_IN_LOGIN_CLASS;        // ログイン時のみ表示ウィジェットクラス
4669                                                                                         break;
4670                                                                                 case 2:                 // 非ログイン時のみ表示
4671                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_VISIBLE_IN_NOT_LOGIN_CLASS;    // 非ログイン時のみ表示ウィジェットクラス
4672                                                                                         break;
4673                                                                                 default:
4674                                                                                         break;
4675                                                                         }
4676                                                                 }
4677                                                                 if (!empty($pageState)){
4678                                                                         switch ($pageState){
4679                                                                                 case 1:                 // トップ時のみ表示
4680                                                                                         if (!$this->isPageTopUrl) $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;             // ページトップ(サブページ内のトップ位置)でなければ非表示
4681                                                                                         break;
4682                                                                                 default:
4683                                                                                         break;
4684                                                                         }
4685                                                                 }
4686                                                                 
4687                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4688                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4689                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4690                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4691                                                                 $shared = '0';          // 共通属性があるかどうか
4692                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4693                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4694                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4695                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . '>' . $widgetContent . '</div>';
4696                                                         } else {
4697                                                 //              $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4698                                                 //              $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4699                                                         }
4700                                                 } else {                // キャッシュデータがあるとき
4701                                                         $widgetContent = $cacheData;
4702                                                         
4703                                                         // HTMLのメタタグを設定
4704                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4705                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4706                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4707                                                 }
4708                                                 $contents .= $widgetContent;
4709                                                 
4710                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4711                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4712                                                 if (!empty($exportCss)){
4713                                                         // ウィジェットのタグIDを変換
4714                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4715                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4716                                                         $this->addExportCss($exportCss);
4717                                                 }
4718                                         }
4719                                         ob_end_clean();         // バッファ破棄
4720                                         
4721                                         if ($i < $count) return '';// 処理中断のときは終了
4722                                 } else {                        // ########## Joomla!v1.5テンプレートの場合 ##########
4723                                         // テンプレート側で指定されたメニューの表示属性を設定
4724                                         $gEnvManager->setMenuAttr($attr);
4725                                         
4726                                         // ポジションタイプ
4727                                         $posType = '';
4728                                         if (!empty($attr['type'])) $posType = $attr['type'];
4729                                         
4730                                         for ($i = 0; $i < $count; $i++){
4731                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4732                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4733                                                                                                                 
4734                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4735                                                 // キャッシュデータがあるときはキャッシュデータを使用
4736                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4737                                                         
4738                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4739                                                         // ウィジェットのタイトルを初期化
4740                                                         $gEnvManager->setCurrentWidgetTitle('');
4741                                                 
4742                                                         // Joomla用のパラメータを初期化
4743                                                         $gEnvManager->setCurrentWidgetJoomlaParam(array());
4744                                                         
4745                                                         // ウィジェットの出力を取得
4746                                                         ob_clean();
4747                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $titleTag, 0/*タイトル出力なし*/);
4748                                                         $widgetContent = ob_get_contents();
4749
4750                                                         $trimContent = trim($widgetContent);
4751                                                         if (!empty($trimContent)){              // 出力が空でない場合
4752                                                                 $isRendered = false;            // Joomla!の描画処理を行ったかどうか
4753                                                                 if (!empty($this->pageDefRows[$i]['pd_use_render'])){                   // Joomla!の描画処理を使用する場合
4754                                                                         // Joomla!ウィジェットの出力に埋め込む
4755                                                                         if (strcasecmp($style, 'none') != 0){
4756                                                                                 // オブジェクト作成
4757                                                                                 if (!isset($render)) $render = new JRender();
4758                                                                 
4759                                                                                 // デフォルトのウィジェットタイトル取得
4760                                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
4761                                                                 
4762                                                                                 // Joomla用のパラメータを取得
4763                                                                                 $joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
4764
4765                                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
4766                                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
4767                                                                 
4768                                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
4769                                                                                 $title = $this->pageDefRows[$i]['pd_title'];
4770                                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
4771                                                                                         if (empty($title)) $title = $defaultTitle;
4772                                                                                 } else {
4773                                                                                         $title = '';                    // タイトルは非表示
4774                                                                                 }
4775                                                                         
4776                                                                                 // Joomla用パラメータ作成
4777                                                                                 $params = array();                              // ウィジェットごとの属性
4778                                                                                 $widgetType = $this->pageDefRows[$i]['wd_type'];                // ウィジェットタイプ
4779                                                                                 
4780                                                                                 // オプションのJoomlaクラス(縦型メニュー(art-vmenu)等)
4781                                                                                 $joomlaClass = $this->pageDefRows[$i]['wd_joomla_class'];               // 「wd_joomla_class」は使っていない?
4782                                                                                 if (!empty($joomlaClass)) $params['moduleclass_sfx'] = $joomlaClass;
4783                                                                                 if (isset($joomlaParam['moduleclass_sfx'])) $params['moduleclass_sfx'] = $joomlaParam['moduleclass_sfx'];// ウィジェットでjoomla用パラメータの設定があるとき
4784                                                                 
4785                                                                                 if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
4786                                                                                         $moduleContent = '';
4787                                                                                         
4788                                                                                         // メニュータイプのウィジェットのみ実行
4789                                                                                         if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4790                                                                 
4791                                                                                         // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
4792                                                                                         if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4793                                                                                         $widgetContent = $moduleContent;
4794                                                                                 } else {
4795                                                                                         if (strcmp($position, 'main') == 0){// メイン部のとき
4796                                                                                                 // ウィジェットの内枠(コンテンツ外枠)を設定
4797                                                                                                 // ウィジェットの内枠はレンダーで設定
4798                                                                                                 //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4799                                                                                                 $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4800                                                                                         } else {                // その他の位置のとき
4801                                                                                                 // ウィジェットの内枠(コンテンツ外枠)を設定
4802                                                                                                 // ウィジェットの内枠はレンダーで設定
4803                                                                                                 //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4804                                                                                         
4805                                                                                                 $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4806                                                                                         }
4807                                                                                 }
4808 /*                                                                              if (strcmp($position, 'main') == 0){// メイン部のとき
4809                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4810                                                                                         // ウィジェットの内枠はレンダーで設定
4811                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4812                                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4813 //                                                                              } else if (strStartsWith($position, 'user') ||                          // ナビゲーションメニュー位置の場合
4814                                                                                 } else if (strcasecmp($position, 'user3') == 0 ||                               // ナビゲーションメニュー位置の場合
4815                                                                                                 strcasecmp($position, 'position-1') == 0 ||                             // Joomla!v2.5テンプレート対応
4816                                                                                                 strcasecmp($posType, 'hmenu') == 0){            // Joomla!v3テンプレート対応
4817
4818                                                                                         $moduleContent = '';
4819                                                                                         if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
4820                                                                                                 if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4821                                                                         
4822                                                                                                 // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
4823                                                                                                 if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4824                                                                                         } else {
4825                                                                                                 $moduleContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4826                                                                                         }
4827                                                                                         $widgetContent = $moduleContent;
4828                                                                                         
4829                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定。メニュー処理後に付加。
4830                                                                                         // ウィジェットの内枠はレンダーで設定
4831                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4832                                                                                 } else {                // その他の位置のとき
4833                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4834                                                                                         // ウィジェットの内枠はレンダーで設定
4835                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4836                                                                                         
4837                                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4838                                                                                 }*/
4839                                                                                 $isRendered = true;             // Joomla!の描画処理を行ったかどうか
4840                                                                         }
4841                                                                 }
4842                                                                 if (!$isRendered){              // Joomla!の描画処理を行っていない場合
4843                                                                         // ウィジェット共通のコンテンツ処理
4844                                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4845                                                                         
4846                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4847                                                                 //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4848                                                                 }
4849                                                         }
4850                                                         if (!$ret) return '';           // 処理中断のときは終了
4851                                                         
4852                                                         // キャッシュデータを設定
4853                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4854                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4855                                                                                                                         
4856                                                         // ウィジェットの外枠タグを設定
4857                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4858                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4859                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4860                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;  // ポジションブロッククラス
4861                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4862                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4863                                                                 // ウィジェット表示タイプによる表示制御
4864                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4865                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4866                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4867                                                                 if (!empty($controlType)){
4868                                                                         switch ($controlType){
4869                                                                                 case 1:                 // ログイン時のみ表示
4870                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_VISIBLE_IN_LOGIN_CLASS;        // ログイン時のみ表示ウィジェットクラス
4871                                                                                         break;
4872                                                                                 case 2:                 // 非ログイン時のみ表示
4873                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_VISIBLE_IN_NOT_LOGIN_CLASS;    // 非ログイン時のみ表示ウィジェットクラス
4874                                                                                         break;
4875                                                                                 default:
4876                                                                                         break;
4877                                                                         }
4878                                                                 }
4879                                                                 if (!empty($pageState)){
4880                                                                         switch ($pageState){
4881                                                                                 case 1:                 // トップ時のみ表示
4882                                                                                         if (!$this->isPageTopUrl) $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;             // ページトップ(サブページ内のトップ位置)でなければ非表示
4883                                                                                         break;
4884                                                                                 default:
4885                                                                                         break;
4886                                                                         }
4887                                                                 }
4888                         
4889                                                                 //$editInfo = 'widgetid:' . $this->pageDefRows[$i]['wd_id'];
4890                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4891                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4892                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4893                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4894                                                                 $shared = '0';          // 共通属性があるかどうか
4895                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4896                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4897                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4898                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . '>' . $widgetContent . '</div>';
4899                                                         } else {
4900                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4901                                                                 $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4902                                                         }
4903                                                 } else {                // キャッシュデータがあるとき
4904                                                         $widgetContent = $cacheData;
4905                                                         
4906                                                         // HTMLのメタタグを設定
4907                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4908                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4909                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4910                                                 }
4911                                                 $contents .= $widgetContent;
4912                                                 
4913                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4914                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4915                                                 if (!empty($exportCss)){
4916                                                         // ウィジェットのタグIDを変換
4917                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4918                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4919                                                         $this->addExportCss($exportCss);
4920                                                 }
4921                                         }
4922                                 }
4923                         
4924                                 if ($position == 'main'){               // メイン部のときは、メッセージを出力
4925                                         /*if (strlen($this->popupMsg) > 0){
4926                                                 echo "\n<script language=\"javascript\">alert('" . addslashes($this->popupMsg) . "');</script>";
4927                                         }*/
4928                                 } else if ($position == 'debug'){               // デバッグ文出力
4929                                 } else {
4930
4931                                 }
4932                                 break;
4933                         case 1:         // ポジション表示
4934                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:3px solid #f00;color:#700;">ポジション名: ';
4935                                 $contents .= '<b>' . $position . '</b>';
4936                                 $contents .= '</div>';
4937                                 break;
4938                         case 2:         // ポジション表示(ウィジェット付き)
4939                                 $rev = '555';                   // データのリビジョン番号
4940                                 // ポジションのHTMLタグIDを作成
4941                                 $num = 0;
4942                                 $posId = '';
4943                                 for ($i = 0; $i < 100; $i++){
4944                                         $posId = $position . '_' . $num;
4945                                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
4946                                         if (!in_array($viewPosId, $this->viewPosId)) break;
4947                                         $num++;
4948                                 }
4949                                 $this->viewPosId[] = $viewPosId;// IDを保存
4950                                 
4951                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
4952                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
4953                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows);
4954                                         if ($ret){      // 1行以上データが取得できたとき
4955                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
4956                                                 $this->pageDefPosition = $position;
4957                                         } else {
4958                                                 $this->pageDefRows = array();
4959                                                 $this->pageDefPosition = '';
4960                                         }
4961                                 }
4962                                 $posHead = '';
4963                                 // ナビゲーション型のポジションの場合はアイコン付加
4964                                 //if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
4965                                 if ($style == self::WIDGET_STYLE_NAVMENU) $posHead = self::POS_HEAD_NAV_MENU;           // 特殊ポジションブロックのアイコン付加
4966                                 $contents .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;             // リビジョン番号を付加
4967                                 $contents .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
4968                                 
4969                                 // ウィジェットイメージを表示
4970                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
4971                                 //$contents .= $this->getWidgetList($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $widgetTagHead, $this->pageDefRows);
4972                                 $contents .= $this->getWidgetList($filename, $subId, $widgetTagHead, $this->pageDefRows);
4973
4974                                 $contents .= '</div>' . M3_NL;
4975                                 break;
4976                         default:
4977                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:1px solid #f00;color:#700;">param error</div>';
4978                                 break;
4979                 }
4980                 // ポジションを保存
4981                 $this->viewPositions[] = $position;
4982
4983                 return $contents;
4984         }
4985         /**
4986          * 各部品のHTML出力(WordPressテンプレート専用)
4987          *
4988          * @param string $position                      HTMLテンプレート上の書き出し位置
4989          * @param bool $showTitle                       タイトルを表示するかどうか
4990          * @return string                                       出力コンテンツ
4991          */
4992         function getWPContents($position, $showTitle = true)
4993         {
4994                 if ($showTitle){
4995                         return $this->getContents($position, self::WIDGET_STYLE_WORDPRESS/*WordPressテンプレート用出力*/, 100/*WordPressテンプレート*/);
4996                 } else {
4997                         return $this->getContents($position, self::WIDGET_STYLE_WORDPRESS_NOTITLE/*WordPressテンプレート(タイトルなし)用出力*/, 100/*WordPressテンプレート*/);
4998                 }
4999         }
5000         /**
5001          * その他のポジションブロックデータを取得
5002          *
5003          * @param string                ポジション作成用タグ
5004          */
5005         function getRestPositionData()
5006         {
5007                 global $gEnvManager;
5008                 
5009                 $restPositionData = '';
5010                 $rev = '888';
5011                 $pageId = $gEnvManager->getCurrentPageId();
5012                 $subId = $gEnvManager->getCurrentPageSubId();
5013                 
5014                 $restPositions = array_values(array_diff($this->defPositions/*全ポジション*/, $this->viewPositions/*表示済みポジション*/));
5015                 $positionCount = count($restPositions);
5016                 for ($i = 0; $i < $positionCount; $i++){
5017                         $posHead = '';          // アイコン付加用
5018                         $position = $restPositions[$i];
5019                         $posId = $position . '_0';
5020                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
5021
5022                         // 画面情報を取得
5023                         $ret = $this->db->getPageDef($pageId, $subId, $position, $rows);
5024                         if ($ret){
5025                                 //$pageDefRows = $rows;                 // ページ定義レコード
5026                                                 
5027                                 $restPositionData .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">';             // リビジョン番号を付加
5028                                 $restPositionData .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>';
5029                         
5030                                 // ウィジェットイメージを表示
5031                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
5032                                 $contents = $this->getWidgetList($pageId, $subId, $widgetTagHead, $rows);
5033                                 $contents = str_replace(M3_NL, '', $contents);
5034                                 $contents = str_replace('\'', '\\\'', $contents);
5035                                 $restPositionData .= $contents;
5036                                 $restPositionData .= '</div>';
5037                                 
5038                                 $this->viewPosId[] = $viewPosId;// IDを保存
5039                         }
5040                 }
5041                 return $restPositionData;
5042         }
5043         /**
5044          * ウィジェット共通のコンテンツ追加処理
5045          *
5046          * @param string $src                           ウィジェット出力
5047          * @param array $pageDefParam           画面定義レコード
5048          * @return string                                       コンテンツを付加したウィジェット出力
5049          */
5050         function _addOptionContent($src, $pageDefParam)
5051         {
5052                 // 前後コンテンツ追加
5053                 $dest = $pageDefParam['pd_top_content'] . $src . $pageDefParam['pd_bottom_content'];
5054                 
5055                 // 「もっと読む」ボタンを追加
5056                 if ($pageDefParam['pd_show_readmore']){
5057                         $title = $pageDefParam['pd_readmore_title'];
5058                         if (empty($title)) $title = self::DEFAULT_READMORE_TITLE;
5059                         $dest .= '<div><a href="' . convertUrlToHtmlEntity($pageDefParam['pd_readmore_url']) . '">' . convertToHtmlEntity($title) . '</a></div>';
5060                 }
5061                 return $dest;
5062         }
5063         /**
5064          * BODYタグに付加するスタイルを取得(管理画面用)
5065          *
5066          * @param string                CSS文字列
5067          */
5068         function getBodyStyle()
5069         {
5070                 // 画面透過モードのときスタイルを追加
5071                 $transCss = '';
5072                 if ($this->isTransparentMode) $transCss = ' style="background-color:transparent;"';
5073                 return $transCss;
5074         }
5075         /**
5076          * 各ポジションのウィジェット数を取得
5077          *
5078          * @param string $position              HTMLテンプレート上の書き出し位置
5079          * @return int                                  ウィジェットの数
5080          */
5081         function getWidgetsCount($position)
5082         {
5083                 global $gRequestManager;
5084                 global $gEnvManager;
5085                 static $widgetCountArray = array();
5086
5087                 // 管理画面へのアクセスでログインされていないときは0を返す
5088                 if ($gEnvManager->isAdminDirAccess() && !$gEnvManager->isSystemManageUser()){           // 管理画面へのアクセスのときでシステム運用権限がない場合
5089                         return 0;
5090                 }
5091                                 
5092                 // 実行コマンドを取得
5093                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
5094                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
5095                         return 1;               // ウィジェットが設定されていないポジション名を表示するために固定で値を返す
5096                 }
5097                 
5098                 // 単一ポジション以外の設定のときは固定で返す(or等)
5099                 $pos = strpos($position, ' ');
5100                 if ($pos !== false) return 1;
5101                 
5102                 // 既にウィジェット数が取得されている場合は保存値を返す
5103                 $widgetCount = $widgetCountArray[$position];
5104                 if (isset($widgetCount)) return $widgetCount;
5105                 
5106                 // ファイル名、ページ名を取得
5107                 $filename       = $gEnvManager->getCurrentPageId();
5108                 $subId          = $gEnvManager->getCurrentPageSubId();
5109                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
5110
5111                 // 取得しようとするページ定義のポジションが既に取得しているポジションと異なるときはデータを取得
5112                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // 現在取得しているページ定義のポジション
5113                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
5114                         if ($ret){      // 1行以上データが取得できたとき
5115                                 $this->pageDefRows = $rows;                     // ページ定義レコード
5116                                 $this->pageDefPosition = $position;
5117                         } else {
5118                                 $this->pageDefRows = array();
5119                                 $this->pageDefPosition = '';
5120                         }
5121                 }
5122                 // ### ウィジェット数を取得 ###
5123                 // テンプレートのカラム制御を行うためにウィジェット表示条件でウィジェット数を取得
5124                 $widgetCount = 0;
5125                 $rowCount = count($this->pageDefRows);
5126                 for ($i = 0; $i < $rowCount; $i++){
5127         //              $condition = trim($this->pageDefRows[$i]['wd_visible_condition']);
5128                         $condition = trim($this->pageDefRows[$i]['pd_visible_condition']);
5129                         if (empty($condition)){                 // ウィジェット表示条件が設定されていない場合はウィジェットを表示
5130                                 $widgetCount++;
5131                         } else {                        // ウィジェット表示条件が設定されている場合はパラメータをチェック
5132                                 $conds = explode(';', $condition);
5133                                 for ($j = 0; $j < count($conds); $j++){
5134                                         $pos = strpos($conds[$j], '=');
5135                                         if ($pos !== false){            // URLクエリーパラメータ条件がマッチした場合はウィジェットを表示
5136                                                 list($key, $value) = explode('=', trim($conds[$j]));
5137                                                 $key = trim($key);
5138                                                 $value = trim($value);
5139                                                 if (!empty($key) && !empty($value)){
5140                                                         $requestValue = $gRequestManager->trimValueOf($key);
5141                                                         if ($value == $requestValue) $widgetCount++;
5142                                                 }
5143                                         }
5144                                 }
5145                         }
5146                 }
5147 //              $widgetCount = count($this->pageDefRows);
5148                 $widgetCountArray[$position] = $widgetCount;
5149                 return $widgetCount;
5150         }
5151         /**
5152          * ウィジェットのページ定義シリアル番号からウィジェットCSS IDを取得
5153          *
5154          * @param int $defSerial                ページ定義シリアル番号
5155          * @param string $pageId                ページID
5156          * @param string $subpage       ページサブID
5157          * @param string $position              表示位置ID
5158          * @return string                               CSSエレメントID
5159          */
5160         function getWidgetCssId($defSerial, $pageId, $pageSubId, $position)
5161         {
5162                 $elementId = '';
5163                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
5164                 if ($ret){
5165                         $rowCount = count($rows);
5166                         for ($i = 0; $i < $rowCount; $i++){
5167                                 $row = $rows[$i];
5168                                 if ($row['pd_serial'] == $defSerial){
5169                                         $elementId = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
5170                                         break;
5171                                 }
5172                         }
5173                 }
5174                 return $elementId;
5175         }
5176         /**
5177          * ウィジェット情報取得
5178          *
5179          * 画面作成機能でウィジェット情報を取得するためのAjaxインターフェイス
5180          *
5181          * @param RequestManager $request               HTTPリクエスト処理クラス
5182          */
5183         function getWidgetInfoByAjax($request)
5184         {
5185                 global $gEnvManager;
5186                 global $gDesignManager;
5187                 global $gCacheManager;
5188                 
5189                 // アクセスするページIDからPC用、携帯用、スマートフォン用かを判断
5190                 $widgetDeviceType = 0;          // 端末タイプをPC用に初期化
5191                 $pageId         = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
5192                 $pageSubId      = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
5193                 $mobilePageIdPrefix = M3_DIR_NAME_MOBILE . '_';
5194                 $smartphonePageIdPrefix = M3_DIR_NAME_SMARTPHONE . '_';
5195                 if (strncmp($pageId, $mobilePageIdPrefix, strlen($mobilePageIdPrefix)) == 0){
5196                         $widgetDeviceType = 1;          // 携帯用
5197                 } else if (strncmp($pageId, $smartphonePageIdPrefix, strlen($smartphonePageIdPrefix)) == 0){
5198                         $widgetDeviceType = 2;          // スマートフォン用
5199                 }
5200
5201                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
5202                 if ($task == 'list'){
5203                         // ウィジェット一覧を取得
5204                         $ret = $this->db->getAvailableWidgetList($widgetDeviceType, $rows);
5205                         if ($ret){
5206                                 $currentCategoryId = '_none';           // 現在のウィジェットカテゴリー初期化
5207                                 for ($i = 0; $i < count($rows); $i++){
5208                                         $widgetId = $rows[$i]['wd_id'];
5209                                         $desc = $rows[$i]['wd_description'];
5210                                         $widgetTag = self::WIDGET_TYPE_TAG_HEAD . $widgetId;
5211                                         $categoryId = $rows[$i]['wd_category_id'];
5212                                         
5213                                         // カテゴリーの開始タグを追加
5214                                         if ($categoryId != $currentCategoryId){
5215                                                 if ($i > 0){
5216                                                         echo '</dd>' . M3_NL;
5217                                                         echo '</dl>' . M3_NL;
5218                                                 }
5219                                                 echo '<dl class="m3accordion">' . M3_NL;
5220                                                 echo '<dt>' . $rows[$i]['wt_name'] . '</dt>' . M3_NL;
5221                                                 echo '<dd>' . M3_NL;
5222                                                 
5223                                                 // 現在のカテゴリー更新
5224                                                 $currentCategoryId = $categoryId;
5225                                         }
5226                                         
5227                                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
5228                                         if ($gEnvManager->getUseSslAdmin()){
5229                                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
5230                                                 $image = $gEnvManager->getSslUrl($image);
5231                                         }
5232                                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
5233                                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
5234                                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
5235                                         $imageTag .= ' />';
5236                                         
5237                                         // ウィジェット機能マーク
5238                                         $widgetMark = '';
5239                                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メイン型ウィジェット
5240                                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
5241
5242                                         // ウィジェット機能一覧
5243                                         $functionMark = '';
5244                                         if (!empty($rows[$i]['wd_template_type'])){             // 対応テンプレートタイプ
5245                                                 $templateTypeArray = explode(',', $rows[$i]['wd_template_type']);
5246                                                 if (in_array('bootstrap', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_BOOTSTRAP;           // Bootstrap型テンプレート対応
5247                                                 if (in_array('wordpress', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_WORDPRESS;           // WordPress型テンプレート対応
5248                                         }
5249                                         if (!empty($functionMark)) $functionMark = '<hr />' . $functionMark;
5250                         
5251                                         echo '<dl class="m3_widgetlist_item" id="' . $widgetTag . '">' . M3_NL;
5252                                         echo '<dt>' . $widgetMark . $rows[$i]['wd_name'] . '</dt>' . M3_NL;                     // ウィジェット名
5253                                         echo '<dd><table style="width:100%;"><tr style="vertical-align:top;"><td style="width:35px;">' . $imageTag . '</td><td>' . $desc . '</td></tr></table>';
5254                                         echo $functionMark . '</dd>' . M3_NL;
5255                                         echo '</dl>' . M3_NL;
5256                                         
5257                                         // カテゴリーの終了タグを追加
5258                                         if ($i == count($rows) - 1){
5259                                                 echo '</dd>' . M3_NL;
5260                                                 echo '</dl>' . M3_NL;
5261                                         }
5262                                 }
5263                         }
5264                 } else if ($task == 'wget' || $task == 'wdelete' || $task == 'wtoggle' || $task == 'wadd' || $task == 'wmove'){ // ウィジェット再取得、ウィジェット削除,ウィジェット共通属性変更、ウィジェット追加、ウィジェット移動のとき
5265                         $rev    = $request->trimValueOf('rev');                 // リビジョン
5266                         $serial = $request->trimValueOf('serial');
5267                         $position = $request->trimValueOf('pos');
5268                         $widgetsStr = $request->trimValueOf('widgets');
5269                         if (empty($widgetsStr)){
5270                                 $widgets = array();
5271                         } else {
5272                                 $widgets = explode(',', $widgetsStr);
5273                         }
5274                         $shared = $request->trimValueOf('shared');
5275                         $updatepos = explode(',', $request->trimValueOf('updatepos'));
5276                         $index = $request->trimValueOf('index');
5277                         
5278                         // 処理ごとのパラメータ
5279                         if ($task == 'wmove'){
5280                                 $positions = explode(',', $position);
5281                                 if (count($positions) >= 2){
5282                                         $position = $positions[0];
5283                                         $position2 = $positions[1];
5284                                 } else {
5285                                         $position = $positions[0];
5286                                         $position2 = '';
5287                                 }
5288                         }
5289                         // ##### エラーチェック #####
5290                         $isErr = false;
5291                         // リビジョンのエラーチェック
5292                         $rev = '111';                   // データのリビジョン番号
5293
5294                         // 変更前データ取得
5295                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);    // 0レコードでも正常とする
5296                         
5297                         // 変更前のウィジェットのシリアル番号をチェック
5298                         if (count($widgets) == count($rows)){
5299                                 if (!($task == 'wmove' && empty($position2))){                  // 同一ブロック内の移動の場合はチェックなし
5300                                         for ($i = 0; $i < count($rows); $i++){
5301                                                 if ($widgets[$i] != $rows[$i]['pd_serial']){// シリアル番号
5302                                                         $isErr = true;
5303                                                         break;
5304                                                 }
5305                                         }
5306                                 }
5307                         } else {
5308                                 $isErr = true;
5309                         }
5310
5311                         // データの更新
5312                         if (!$isErr){           // エラーなしのとき
5313                                 if ($task == 'wdelete'){
5314                                         $ret = $this->db->deleteWidget($serial);
5315                                 } else if ($task == 'wtoggle'){
5316                                         $newShared = 0;
5317                                         if (empty($shared)) $newShared = 1;
5318                                         $ret = $this->db->toggleSharedWidget($pageId, $pageSubId, $serial, $newShared);
5319                                 } else if ($task == 'wadd'){    // ウィジェットの追加
5320                                         $widget = $request->trimValueOf('widget');
5321                                         
5322                                         // エラーチェック
5323                                         if (empty($widget)) $isErr = true;
5324                                         
5325                                         // ウィジェットを追加
5326                                         if (!$isErr) $this->db->addWidget($pageId, $pageSubId, $position, $widget, $index);
5327                                 } else if ($task == 'wmove'){
5328                                         // ウィジェットを移動
5329                                         if (!$isErr) $this->db->moveWidget($pageId, $pageSubId, $position, $serial, $index);
5330                                 }
5331                         }
5332                         // 再表示データ取得
5333                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);// 0レコードでも正常とする
5334                         
5335                         // 移動のときは、移動元と移動先の再表示データを取得
5336                         if ($task == 'wmove' && !empty($position2)){
5337                                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position2, $rows2);// 0レコードでも正常とする
5338                         }
5339
5340                         // 更新データを作成
5341                         // 更新対象のポジションブロック
5342                         echo '<div>' . M3_NL;
5343                         for ($i = 0; $i < count($updatepos); $i++){
5344                                 // ウィジェットIDヘッダ作成
5345                                 $widgetTagHead = str_replace(self::POSITION_TAG_HEAD, self::WIDGET_TAG_HEAD, $updatepos[$i]);
5346                                         
5347                                 // ポジション名取得
5348                                 $posName = str_replace(self::POSITION_TAG_HEAD, '', substr($updatepos[$i], 0, strlen($updatepos[$i]) - strlen(strrchr($updatepos[$i], "_"))));
5349                                 if ($task == 'wmove' && $posName == $position2){
5350                                         // ウィジェット一覧外枠
5351                                         $posHead = '';
5352                                         if (strcasecmp($position2, 'user3') == 0 || strcasecmp($position2, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
5353                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position2 . ';rev:' . $rev . ';">' . M3_NL;                // リビジョン番号を付加
5354                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position2 . '</h2>' . M3_NL;
5355                                 
5356                                         // ウィジェット一覧出力
5357                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows2);
5358                                 } else {
5359                                         // ウィジェット一覧外枠
5360                                         $posHead = '';
5361                                         if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;                // 特殊ポジションブロックのアイコン付加
5362                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;         // リビジョン番号を付加
5363                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
5364                                 
5365                                         // ウィジェット一覧出力
5366                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows);
5367                                 }
5368                                 // ウィジェット一覧外枠
5369                                 echo '</div>' . M3_NL;
5370                         }
5371                         echo '</div>' . M3_NL;
5372                         
5373                         // キャッシュデータをクリア
5374                         $gCacheManager->clearAllCache();
5375                 }
5376         }
5377         /**
5378          * 画面作成用ウィジェット一覧データ出力
5379          *
5380          * @param string $pageId                        ページID
5381          * @param string $pageSubId                     ページサブID
5382          * @param string $widgetTagHead         HTMLウィジェットID用のヘッダ
5383          * @param array $rows                           ウィジェット一覧データ
5384          * @return string                                       ウィジェット一覧出力
5385          */
5386         function getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows)
5387         {
5388                 global $gEnvManager;
5389                 global $gDesignManager;
5390                 global $gSystemManager;
5391                 
5392                 if ($gEnvManager->getUseSslAdmin()){
5393                         $rootUrl = $gEnvManager->getSslRootUrl();
5394                 } else {
5395                         $rootUrl = $gEnvManager->getRootUrl();
5396                 }
5397
5398                 // ページのコンテンツタイプを取得
5399                 $line = $this->getPageInfo($pageId, $pageSubId);
5400                 if (!empty($line)) $pageContentType = $line['pn_content_type'];
5401                         
5402                 $contents = '';         // ウィジェット一覧出力コンテンツ
5403                 for ($i = 0; $i < count($rows); $i++){
5404                         $widgetId = $rows[$i]['wd_id'];
5405                         $desc = $rows[$i]['wd_description'];
5406                         $widgetIndex = $rows[$i]['pd_index'];           // 表示順
5407                         $configId = $rows[$i]['pd_config_id'];          // 定義ID
5408                         $serial = $rows[$i]['pd_serial'];               // シリアル番号
5409                         $isShared = empty($rows[$i]['pd_sub_id']);                      // グローバル属性が設定されているかどうか
5410                         $widgetTag = $widgetTagHead . '_' . $i;                         // ウィジェット識別用ユニークタグ
5411                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
5412                         if ($gEnvManager->getUseSslAdmin()){
5413                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
5414                                 $image = $gEnvManager->getSslUrl($image);
5415                         }
5416                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
5417                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
5418                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
5419                         $imageTag .= ' />';
5420                         // 定義名
5421                         if (empty($rows[$i]['pd_config_name'])){
5422                                 if ($rows[$i]['wd_use_instance_def'] && $configId == 0){                // インスタンス定義が必要で未定義のとき
5423                                         $configName = '<span style="color:red;">[未設定]</span>';
5424                                 } else {
5425                                         $configName = '';
5426                                 }
5427                         } else {
5428                                 $configName = '[' . $rows[$i]['pd_config_name'] . ']';
5429                         }
5430                         $hasAdmin = '0';                // 管理画面があるかどうか
5431                         $configImg = '';        // 設定アイコンの表示
5432                         
5433                         // ウィジェットの配置位置に問題があるかどうかを表示
5434                         // メインコンテンツとページ属性が一致するかどうかチェック
5435                         $widgetContentType = $rows[$i]['wd_content_type'];
5436                         //if (!empty($widgetContentType) && $widgetContentType != $pageContentType && 
5437                         if (!empty($widgetContentType) && $widgetContentType != $pageContentType && empty($rows[$i]['wd_content_widget_id']) &&                 // 編集用のウィジェットが別にある場合は除く(2015/3/24))
5438                                                 (in_array($widgetContentType, $this->_getAllContentType()) || in_array($widgetContentType, $this->_getAllFeatureType()))){
5439                                 //$title = 'ウィジェット配置注意';
5440                                 $title = 'ページ属性と不一致';
5441                                 $configImg .= '<span rel="m3help" data-container="body" title="' . $title . '"><img src="' . $rootUrl . self::NOTICE_ICON_FILE . '" alt="' . $title . '" /></span>&nbsp;';
5442                         }
5443                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type']) && $isShared){                                 // メイン型ウィジェットがグローバル属性を持つとき
5444                                 $title = 'メイン型ウィジェットはグローバル属性を設定できません';
5445                                 $configImg .= '<span rel="m3help" data-container="body" title="' . $title . '"><img src="' . $rootUrl . self::ALERT_ICON_FILE . '" alt="' . $title . '" /></span>&nbsp;';
5446                         }
5447                         if ($rows[$i]['wd_has_admin']){
5448                                 $hasAdmin = '1';
5449                                 $title = 'ウィジェット設定';
5450                                 $configImg .= '<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\'' . $widgetId . '\', \'' . $configId . '\', \'' . $serial . '\');return false;" rel="m3help" data-container="body" title="' . $title . '">' .
5451                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" alt="' . $title . '"/></a>&nbsp;';
5452                         }
5453                         // 表示順
5454                         $configImg .= '<span rel="m3help" data-container="body" title="表示順">' . $widgetIndex . '</span>';
5455                         
5456                         $shared = '0';          // 共通属性があるかどうか
5457                         $sharedClassName = '';
5458                         //if (empty($rows[$i]['pd_sub_id'])){
5459                         if ($isShared){                                 // グローバル属性ウィジェットのとき
5460                                 $shared = '1';
5461                                 $sharedClassName = 'm3_widget_shared';                  // 共通ウィジェットのクラス
5462                         }
5463                         $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
5464                         
5465                         // ウィジェット機能マーク
5466                         $widgetMark = '';
5467                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メイン型ウィジェット
5468                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
5469                         
5470                         // 操作メニュー
5471                         $dropdownMenuId = $widgetTag . '_dropdown';
5472                         $operationMenu = '<div class="m3widgetdropdown">';
5473 //                      $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#"><i class="glyphicon glyphicon-list-alt"></i> <b class="caret"></b></a>';
5474                         $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#" data-horizontal-offset="4"><b class="caret"></b></a>';
5475                         $operationMenu .= '<div id="' . $dropdownMenuId . '" class="m3dropdown m3dropdown-tip m3dropdown-relative m3dropdown-anchor-right">';
5476                         $operationMenu .= '<ul class="m3dropdown-menu">';
5477                         if ($hasAdmin) $operationMenu .= '<li class="m3_wconfig"><a href="#"><img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" /> <span>ウィジェットの設定</span></a></li>';
5478                         $operationMenu .= '<li class="m3_wadjust"><a href="#"><img src="' . $rootUrl . self::ADJUST_ICON_FILE . '" /> <span>タイトル・スタイル調整</span></a></li>';
5479                         if ($shared){
5480                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>グローバル属性を解除</span></a></li>';
5481                         } else {
5482                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>グローバル属性を設定</span></a></li>';
5483                         }
5484                         $operationMenu .= '<li class="m3_wdelete"><a href="#"><img src="' . $rootUrl . self::DELETE_ICON_FILE . '" /> <span>このウィジェットを削除</span></a></li>';
5485                         $operationMenu .= '</ul>';
5486                         $operationMenu .= '</div>';
5487                         $operationMenu .= '</div>';
5488                         
5489                         $contents .= '<dl class="m3_widget m3_widget_sortable" id="' . $widgetTag . '" ' . $m3Option . ' >' . M3_NL;
5490                         $contents .= '<dt class="m3_widget_with_check_box ' . $sharedClassName . '"><div class="m3widgettitle">' . $widgetMark . $rows[$i]['wd_name'] . '</div>' . $operationMenu . '</dt>' . M3_NL;
5491                         $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;
5492                         $contents .= '<table style="width:100%;"><tr><td>' . $configName . '</td><td style="text-align:right;">' . $configImg . '</td></tr></table></dd>' . M3_NL;
5493                         $contents .= '</dl>' . M3_NL;
5494                 }
5495                 return $contents;
5496         }
5497         /**
5498          * ウィジェット出力を処理
5499          *
5500          * @param string $position                      HTMLテンプレート上の書き出し位置
5501          * @param int $index                    行番号
5502          * @param array $fetchedRow             fetch取得した行
5503          * @param string $style                 ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
5504          * @param string $titleTag      タイトル埋め込み用タグ(遅延ウィジェットの場合のみ作成)
5505          * @param int $widgetHeaderType ウィジェットタイトルを出力方法(0=出力なし、1=Joomla!v1.0PC用出力、2=Joomla!v1.0携帯用出力)
5506          * @return bool                                 処理を継続するかどうか(true=続行、false=中断)
5507          */
5508         function pageDefLoop($position, $index, $fetchedRow, $style, &$titleTag, $widgetHeaderType = 0)
5509         {
5510                 global $gEnvManager;
5511                 global $gErrorManager;
5512                 global $gDesignManager;
5513
5514                 // ページ作成中断またはウィジェット処理中断のときは終了
5515                 if ($this->isAbort || $this->isWidgetAbort) return false;
5516
5517                 // ウィジェット実行停止中のときは空で返す
5518                 // 管理者、運営者どのレベルで制限をかける?
5519                 if (!$fetchedRow['wd_active']) return true;
5520                 
5521                 // グローバル属性ありの場合は現在のページが例外ページにないかチェック
5522                 if (empty($fetchedRow['pd_sub_id'])){
5523                         $exceptPageStr = $fetchedRow['pd_except_sub_id'];
5524                         if (!empty($exceptPageStr)){
5525                                 $exceptPageArray = explode(',', $exceptPageStr);
5526                                 if (in_array($gEnvManager->getCurrentPageSubId(), $exceptPageArray)) return true;               // 例外ページの場合は出力しない
5527                         }
5528                 }
5529                 
5530                 // ウィジェット表示タイプによる表示制御。システム管理者以上の場合は常時表示。
5531                 if (!$gEnvManager->isSystemAdmin()){
5532                         if (!empty($fetchedRow['pd_view_control_type'])){
5533                                 switch ($fetchedRow['pd_view_control_type']){
5534                                         case 1:                 // ログイン時のみ表示
5535                                                 if (!$gEnvManager->isCurrentUserLogined()) return true;         // ログインしていなければ終了
5536                                                 break;
5537                                         case 2:                 // 非ログイン時のみ表示
5538                                                 if ($gEnvManager->isCurrentUserLogined()) return true;          // ログインしていれば終了
5539                                                 break;
5540                                         default:
5541                                                 break;
5542                                 }
5543                         }
5544                         if (!empty($fetchedRow['pd_view_page_state'])){
5545                                 switch ($fetchedRow['pd_view_page_state']){
5546                                         case 1:                 // トップ時のみ表示
5547                                                 if (!$this->isPageTopUrl) return true;          // ページトップ(サブページ内のトップ位置)でなければ終了
5548                                                 break;
5549                                         default:
5550                                                 break;
5551                                 }
5552                         }
5553                 }
5554                 
5555                 // パラメータ初期化
5556                 $titleTag = '';
5557                 
5558                 // ウィジェットID取得
5559                 $widgetId = $fetchedRow['wd_id'];               
5560                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
5561
5562                 // その他パラメータ取得
5563                 $configId = $fetchedRow['pd_config_id'];                // ウィジェット定義ID
5564                 if ($configId == 0) $configId = '';
5565                 $prefix = $fetchedRow['wd_suffix'];             // サフィックス文字列
5566                 $title = $fetchedRow['wd_name'];                // デフォルトのウィジェットタイトル
5567                 if (empty($title)) $title = $fetchedRow['wd_id'];
5568                 $widgetHeadTitle = $fetchedRow['pd_title'];             // ウィジェットのヘッドタイトル
5569                 if (empty($widgetHeadTitle)) $widgetHeadTitle = $title;                 // ウィジェットのヘッドタイトルが空の場合はウィジェットタイトルを取得
5570                 $serial = $fetchedRow['pd_serial'];             // シリアル番号
5571                 $cssStyle       = $fetchedRow['pd_style'];              // CSS
5572                 $lateLaunchIndex = $fetchedRow['wd_launch_index'];              // 遅延実行インデックス
5573                 $shared = false;
5574                 if (empty($fetchedRow['pd_sub_id'])) $shared = true;// 共通属性あり
5575                 if ($this->nonSharedWidgetCount == -1) $this->nonSharedWidgetCount = 0;         // 初期化されていない場合は初期化
5576                 if (!$shared) $this->nonSharedWidgetCount++;    // 非共通ウィジェットの数を更新
5577                 
5578                 // ウィジェットが遅延実行に指定されている場合は、ウィジェットのタグのみ埋め込む
5579                 if ($lateLaunchIndex > 0){              // 遅延実行のとき
5580                         // 遅延実行ウィジェットリストに追加
5581                         if (!isset($this->lateLaunchWidgetList[$widgetId])){
5582                                 $this->lateLaunchWidgetList[$widgetId] = (int)$lateLaunchIndex;
5583                         }
5584                         // 実行パラメータ保存
5585                         $maxNo = 0;             // 最大シリアル番号
5586                         $count = count($this->latelaunchWidgetParam);
5587                         for ($i = 0; $i < $count; $i++){
5588                                 list($wId, $maxNo, $tmp1, $tmp2, $tmp3, $tmp4, $tmp5, $tmp6, $tmp7, $tmp8, $tmp9, $tmp10, $tmp11) = $this->latelaunchWidgetParam[$i];
5589                                 if ($wId == $widgetId) $maxNo = $maxNo + 1;
5590                         }
5591                         // Joomla!1.0テンプレートの場合はタイトルを修正
5592                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
5593                                 if (!empty($fetchedRow['pd_title'])) $title = $fetchedRow['pd_title'];
5594                         }
5595                         $this->latelaunchWidgetParam[] = array($widgetId, $maxNo, $configId, $prefix, $serial, $style, $cssStyle, $title, $shared, $exportCss, $position, $index, $fetchedRow);
5596                         
5597                         // 遅延実行用タグを埋め込む
5598                         echo self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;
5599                         
5600                         // タイトル用タグ作成
5601                         $titleTag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
5602                 } else {
5603                         // ウィジェットが存在する場合は実行
5604                         if (!file_exists($widgetIndexFile)) {
5605                                 if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
5606                         } else {
5607                                 // パラメータ初期化
5608                                 $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
5609                                 $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
5610                                 $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
5611                                 $this->lastHeadTitle = '';                      // ヘッダ部titleにセットした文字列
5612                                 $this->lastHeadDescription = '';        // ヘッダ部descriptionにセットした文字列
5613                                 $this->lastHeadKeywords = '';           // ヘッダ部keywordsにセットした文字列
5614                         
5615                                 // 現在のウィジェットのポジション
5616                                 $this->currentWidgetPosition = $position;                       // 現在のウィジェットのポジション
5617                                 $this->currentWidgetIndex = $index;                     // 現在のウィジェットのポジション番号
5618                                         
5619                                 // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
5620                                 $joomlaTitleVisble = false;
5621                                 if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
5622                                         if ($fetchedRow['pd_title_visible']){
5623                                                 if ($widgetHeaderType == 1){            // PC用出力のとき
5624                                                         $joomlaTitle = $fetchedRow['pd_title'];
5625                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
5626                                                         echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
5627                                                         echo '<tr><th>' . $joomlaTitle . '</th></tr>' . M3_NL;
5628                                                         echo '<tr><td>' . M3_NL;
5629                                                         $joomlaTitleVisble = true;
5630                                                 } else if ($widgetHeaderType == 2){             // 携帯用出力のとき
5631                                                         $joomlaTitle = $fetchedRow['pd_title'];
5632                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
5633                                                         echo '<div>' . $joomlaTitle . '</div>' . M3_NL;
5634                                                         $joomlaTitleVisble = true;
5635                                                 }
5636                                         }
5637                                 }
5638                                 // ウィジェットの外枠タグを設定
5639                                 //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
5640                                 // ウィジェット親のCSS定義があるときは、タグを追加
5641                                 if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
5642                                         
5643                                 // ウィジェットの前出力
5644                                 echo $gDesignManager->getAdditionalWidgetOutput(true);
5645                                 
5646                                 // 作業中のウィジェットIDを設定
5647                                 $gEnvManager->setCurrentWidgetId($widgetId);
5648         
5649                                 // ウィジェット定義IDを設定
5650                                 $gEnvManager->setCurrentWidgetConfigId($configId);
5651                         
5652                                 // ページ定義のシリアル番号を設定
5653                                 $gEnvManager->setCurrentPageDefSerial($fetchedRow['pd_serial']);
5654                                 
5655                                 // ページ定義レコードを設定
5656                                 $gEnvManager->setCurrentPageDefRec($fetchedRow);
5657                                 
5658                                 // パラメータを設定
5659                                 $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
5660                         
5661                                 // ウィジェットのヘッドタイトルを設定
5662                                 $gEnvManager->setCurrentWidgetHeadTitle($widgetHeadTitle);
5663
5664                                 // ウィジェットのタイトルを設定
5665                                 $gEnvManager->setCurrentWidgetTitle($title);
5666                                 
5667                                 // ウィジェットのスタイルを設定
5668                                 $gEnvManager->setCurrentWidgetStyle($style);
5669                                 
5670                                 // ウィジェットのグローバル属性状況を設定
5671                                 $gEnvManager->setIsCurrentWidgetShared($shared);
5672                                         
5673                                 // 実行ログを残す
5674                                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
5675                                 
5676                                 // ウィジェットを実行
5677                                 //require_once($widgetIndexFile);
5678                                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5679                                 $msg = 'widget-start(' . $widgetId . ')';
5680                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5681                                 require($widgetIndexFile);
5682                                 $msg = 'widget-end(' . $widgetId . ')';
5683                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5684
5685                                 // 作業中のウィジェットIDを解除
5686                                 $gEnvManager->setCurrentWidgetId('');
5687                         
5688                                 // ウィジェット定義IDを解除
5689                                 $gEnvManager->setCurrentWidgetConfigId('');
5690                                 
5691                                 // ページ定義のシリアル番号を解除
5692                                 $gEnvManager->setCurrentPageDefSerial(0);
5693                         
5694                                 // ページ定義レコードを解除
5695                                 $gEnvManager->setCurrentPageDefRec();
5696                                 
5697                                 // パラメータを解除
5698                                 $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
5699
5700                                 // ウィジェットのスタイルを解除
5701                                 $gEnvManager->setCurrentWidgetStyle('');
5702                                 
5703                                 // ウィジェットのグローバル属性状況を解除
5704                                 $gEnvManager->setIsCurrentWidgetShared(false);
5705                                 
5706                                 // ウィジェットの後出力
5707                                 echo $gDesignManager->getAdditionalWidgetOutput(false);
5708 //                              echo "<!-- ".time()." -->";
5709
5710                                 // ウィジェット親のCSS定義があるときは、タグを追加
5711                                 if (!empty($cssStyle)) echo '</div>' . M3_NL;
5712                                 // ウィジェットの外枠タグを設定
5713                                 //echo '</div>' . M3_NL;
5714                                 
5715                                 // Joomla!1.0テンプレートのときはタイトルを出力
5716                                 if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用出力のとき
5717                                         echo '</td></tr>' . M3_NL;
5718                                         echo '</table>' . M3_NL;
5719                                 }
5720                         }
5721                 }
5722                 return true;            // 処理継続
5723         }
5724         /**
5725          * 定義IDを指定してウィジェットの出力を取得
5726          *
5727          * @param string $widgetId              ウィジェットID
5728          * @param int $configId                 ウィジェット定義ID
5729          * @return string                               ウィジェットの出力
5730          */
5731         function getWidgetOutput($widgetId, $configId = 0)
5732         {
5733                 global $gEnvManager;
5734                 global $gErrorManager;
5735
5736                 // ウィジェットのアクセス権をチェック
5737                 if (!$this->db->canAccessWidget($widgetId)) return '';
5738
5739                 // ウィジェット情報取得
5740                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
5741
5742                 // 端末タイプをチェック
5743                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
5744                 
5745                 // 必要なJavascriptライブラリを追加
5746                 $scritLib = trim($row['wd_add_script_lib']);
5747                 if (!empty($scritLib)) $this->addScript('', $scritLib);
5748                 
5749                 // バッファ作成
5750                 ob_start();
5751
5752                 // ウィジェット実行ファイル取得
5753                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
5754                                         
5755                 // 作業中のウィジェットIDを設定
5756                 $saveWidgetId = $gEnvManager->getCurrentWidgetId();
5757                 $gEnvManager->setCurrentWidgetId($widgetId);
5758
5759                 // ウィジェット定義IDを設定
5760                 $saveConfigId = $gEnvManager->getCurrentWidgetConfigId();
5761                 $gEnvManager->setCurrentWidgetConfigId($configId);
5762         
5763                 // ページ定義のシリアル番号を設定
5764                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
5765                         
5766                 // パラメータを設定
5767                 //$gEnvManager->setCurrentWidgetPrefix($prefix);                // プレフィックス文字列
5768         
5769                 // ウィジェットのタイトルを設定
5770                 //$gEnvManager->setCurrentWidgetTitle($title);
5771                 
5772                 // ウィジェットのグローバル属性状況を設定
5773                 //$gEnvManager->setIsCurrentWidgetShared($shared);
5774                         
5775                 // 実行ログを残す
5776                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
5777                 
5778                 // ウィジェットを実行
5779                 //require_once($widgetIndexFile);
5780                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5781                 $msg = 'widget-start(' . $widgetId . ')';
5782                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5783                 if (file_exists($widgetIndexFile)){
5784                         require($widgetIndexFile);
5785                 } else {
5786                         if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
5787                 }
5788                 $msg = 'widget-end(' . $widgetId . ')';
5789                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5790
5791                 // 作業中のウィジェットIDを戻す
5792                 $gEnvManager->setCurrentWidgetId($saveWidgetId);
5793         
5794                 // ウィジェット定義IDを戻す
5795                 $gEnvManager->setCurrentWidgetConfigId($saveConfigId);
5796                 
5797                 // ページ定義のシリアル番号を解除
5798                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
5799         
5800                 // パラメータを解除
5801                 //$gEnvManager->setCurrentWidgetPrefix('');                             // プレフィックス文字列
5802
5803                 // ウィジェットのグローバル属性状況を解除
5804                 //$gEnvManager->setIsCurrentWidgetShared(false);
5805
5806                 // 現在のバッファ内容を取得し、バッファを破棄
5807                 $output = ob_get_contents();
5808                 ob_end_clean();
5809                                         
5810                 return $output;
5811         }
5812         /**
5813          * インナーウィジェットの操作
5814          *
5815          * @param int $cmdNo                            実行コマンド(0=初期化、1=更新、2=計算、10=コンテンツ取得)
5816          * @param string $id                            ウィジェットID+インナーウィジェットID
5817          * @param string $configId                      インナーウィジェット定義ID
5818          * @param object $paramObj                      インナーウィジェットに渡すパラメータオブジェクト
5819          * @param object $optionParamObj        インナーウィジェットに渡すパラメータオブジェクト(オプション)
5820          * @param object $resultObj                     インナーウィジェットから返る結果オブジェクト
5821          * @param string $content                       出力内容
5822          * @param bool $isAdmin                         管理者機能(adminディレクトリ以下)かどうか
5823          * @return bool                                         true=成功、false=失敗
5824          */
5825         function commandIWidget($cmdNo, $id, $configId, &$paramObj, &$optionParamObj, &$resultObj, &$content, $isAdmin = false)
5826         {
5827                 global $gEnvManager;
5828                 
5829                 // ウィジェットIDとインナーウィジェットIDを取り出す
5830                 list($widgetId, $iWidgetId) = explode(M3_WIDGET_ID_SEPARATOR, $id);
5831
5832                 // インナーウィジェットに渡すパラメータを設定
5833                 switch ($cmdNo){
5834                         case 0:
5835                                 $cmd = self::IWIDTET_CMD_INIT;                  // 初期化
5836                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5837                                 break;
5838                         case 1:
5839                                 $cmd = self::IWIDTET_CMD_UPDATE;                // 更新
5840                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
5841                                 break;
5842                         case 2:
5843                                 $cmd = self::IWIDTET_CMD_CALC;                  // 計算
5844                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5845                                 break;
5846                         case 10:
5847                                 $cmd = self::IWIDTET_CMD_CONTENT;                       // コンテンツ取得
5848                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
5849                                 break;
5850                         default:
5851                                 $cmd = '';
5852                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5853                                 break;
5854                 }
5855
5856                 // インナーウィジェットのエラー出力は呼び出しウィジェット側で受けるため、出力を抑止する
5857                 ob_start();// バッファ作成
5858
5859                 // ウィジェット実行ファイル取得
5860                 if (empty($widgetId)){          // ウィジェットIDが指定されていないときは共通ディレクトリ
5861                 //$gEnvManager->getIWidgetsPath() . '/' . $iWidgetId . '/' . $containerClass . '.php';
5862                 } else {
5863                         if ($isAdmin){
5864                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/' . M3_DIR_NAME_ADMIN . '/index.php';
5865                         } else {
5866                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/index.php';
5867                         }
5868                 }
5869
5870                 // 作業中のインナーウィジェットIDを設定
5871                 $gEnvManager->setCurrentIWidgetId($id);         // インナーウィジェットを設定
5872
5873                 // インナーウィジェット定義IDを設定
5874                 $gEnvManager->setCurrentIWidgetConfigId($configId);
5875                 
5876                 // ウィジェットを実行
5877                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5878                 if (file_exists($widgetIndexFile)){
5879                         require($widgetIndexFile);
5880                 } else {
5881                         echo 'file not found error: ' . $widgetIndexFile;
5882                 }
5883                 
5884                 // 作業中のウィジェットIDを解除
5885                 $gEnvManager->setCurrentIWidgetId('');
5886         
5887                 // インナーウィジェット定義IDを解除
5888                 $gEnvManager->setCurrentIWidgetConfigId('');
5889                 
5890                 // 現在のバッファ内容を取得し、バッファを破棄
5891                 $content = ob_get_contents();
5892                 ob_end_clean();
5893                 
5894                 // 値を再取得
5895                 if ($this->gInstance->getCmdParamManager()->getParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $obj, $option)){
5896                         $paramObj = $obj;
5897                         $optionParamObj = $option;
5898                 }
5899
5900                 // 結果を取得
5901                 if ($this->gInstance->getCmdParamManager()->getResult($id . M3_WIDGET_ID_SEPARATOR . $configId, $resObj)) $resultObj = $resObj;
5902                 return true;
5903         }
5904         /**
5905          * コールバックメソッドを実行し、出力を返す
5906          *
5907          * @param array $callback               実行するコールバック
5908          * @return string                               出力結果
5909          */
5910         function getOutputByCallbackMethod($callback)
5911         {
5912                 ob_start();// バッファ作成
5913                 
5914                 // コールバック関数を実行
5915                 if (is_callable($callback)) call_user_func($callback);
5916                 
5917                 // 現在のバッファ内容を取得し、バッファを破棄
5918                 $content = ob_get_contents();
5919                 ob_end_clean();
5920                 return $content;
5921         }
5922         /**
5923          * ページ作成処理中断を行った場合のレスポンスヘッダ設定
5924          *
5925          * @param int $responseCode             レスポンスコード
5926          * @return                                              なし
5927          */
5928         function setResponse($responseCode)
5929         {
5930                 switch ($responseCode){
5931                         case 403:                       // アクセス禁止のとき
5932                                 header('HTTP/1.1 403 Forbidden');
5933                                 header('Status: 403 Forbidden');
5934                                 break;
5935                         case 404:                       // 存在しないページのとき
5936                                 header("HTTP/1.1 404 Not Found");
5937                                 header("Status: 404 Not Found");
5938                                 break;
5939                         case 500:                       // サーバ内部エラー
5940                                 header('HTTP/1.1 500 Internal Server Error');
5941                                 header('Status: 500 Internal Server Error');
5942                                 break;
5943                         case 503:                       // サイト非公開(システムメンテナンス)
5944                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
5945                                 header('Status: 503 Service Temporarily Unavailable');
5946                                 break;
5947                 }
5948         }
5949         /**
5950          * ファイルダウンロード
5951          *
5952          * @param string $filePath                      ダウンロードするファイルのファイルパス
5953          * @param string $downloadFilename      ダウンロード時のファイル名
5954          * @param bool   $deleteFile            実行後ファイルを削除するかどうか(成功失敗に関係なく)
5955          * @return bool                                         true=成功、false=失敗
5956          */
5957         function downloadFile($filePath, $downloadFilename, $deleteFile=false)
5958         {
5959                 // エラーチェック
5960                 if (!file_exists($filePath)) return false;
5961                 
5962                 // ファイルサイズ取得
5963                 $fileSize = filesize($filePath);
5964                 
5965                 // バッファ内容が残っているときは破棄
5966                 if (ob_get_level() > 0) ob_end_clean();
5967                 
5968                 header('Cache-Control: public');                // IE6+SSHでダウンロードエラーが出る問題を回避
5969                 header('Pragma: public');                               // IE6+SSHでダウンロードエラーが出る問題を回避
5970             header('Content-Disposition: attachment; filename=' . $downloadFilename);
5971                 header('Content-Length: ' . $fileSize);
5972             header('Content-Type: application/octet-stream; name=' . $downloadFilename);
5973             $fp = fopen($filePath, "r");
5974             echo fread($fp, $fileSize);
5975             fclose($fp);
5976                 
5977                 ob_end_flush();
5978                 
5979                 // ファイル削除
5980                 if ($deleteFile) unlink($filePath);
5981                 return true;
5982         }
5983         /**
5984          * システム制御ページを表示するかどうかを返す
5985          *
5986          * @return bool         true=システム制御ページを表示、false=システム制御ページを表示しない
5987          */
5988         function isSystemPage()
5989         {
5990                 return $this->isSystemPage;
5991         }
5992         /**
5993          * 指定URLへリダイレクト
5994          *
5995          * @param string $url                   遷移先URL。未指定の場合は現在のスクリプト。URLでないときは、現在のスクリプトに付加。
5996          * @param bool $noMessage               画面を遷移させたとき、ドコモ携帯端末でダイアログ(サイトが移動しました(301))が出ないようにするオプション
5997          * @param int  $responseCode    レスポンスコード
5998          * @param bool $autoSsl                 リダイレクト先のページの状態に合わせてSSLを制御するかどうか
5999          * @return                                              なし
6000          */
6001         function redirect($url = '', $noMessage = false, $responseCode = 0, $autoSsl = true)
6002         {
6003                 global $gEnvManager;
6004
6005                 // すでにリダイレクトが設定されている場合は終了
6006                 if ($this->isRedirect) return;                          // リダイレクトするかどうか
6007                 
6008                 $toUrl = $url;
6009                 if (empty($toUrl)){
6010                         $toUrl = $gEnvManager->getCurrentScriptUrl();
6011                 } else if (strncmp($toUrl, 'http://', 7) != 0 && strncmp($toUrl, 'https://', 8) != 0){  // URL以外のときはクエリー文字列と判断する
6012                         $toUrl = $gEnvManager->getCurrentScriptUrl() . $toUrl;
6013                 }
6014
6015                 // SSL化が必要な場合はhttpsに変更
6016                 if ($autoSsl){
6017                         $isSslPage = false;
6018                         if ($gEnvManager->isAdminUrlAccess($toUrl)){            // 管理画面へのアクセスのとき
6019                                 // 管理画面のSSL状態を参照
6020                                 if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
6021                         } else {                // フロント画面へのアクセスのとき
6022                                 // ファイル名を取得
6023                                 $paramArray = array();
6024                                 //list($filename, $query) = explode('?', basename($toUrl));
6025                                 list($url, $query) = explode('?', $toUrl);
6026                                 $baseUrl = dirname($url);
6027                                 $filename = basename($url);
6028                                 if (empty($filename)) $filename = M3_FILENAME_INDEX;
6029                                 if (!empty($query)) parse_str($query, $paramArray);             // クエリーの解析
6030                 
6031                                 // ページIDを取得
6032                                 $pageId = basename($filename, '.php');
6033                                 $pageSubId = $paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID];
6034                         
6035                                 // ページのSSL設定状況を取得
6036                                 $isSslPage = $this->isSslPage($pageId, $pageSubId);
6037                         
6038                                 // 階層化ページの場合はURLを修正
6039                                 if ($this->gSystem->hierarchicalPage() && $filename == M3_FILENAME_INDEX){
6040                                         $toUrl = $baseUrl . '/' . $pageSubId . '/';
6041                                         unset($paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID]);
6042                                         
6043                                         $paramStr = $this->_createUrlParamStr($paramArray);
6044                                         if (!empty($paramStr)) $toUrl .= '?' . $paramStr;
6045                                 }
6046                         }
6047                         if ($isSslPage){
6048                                 //$toUrl = str_replace('http://', 'https://', $toUrl);
6049                                 $toUrl = $gEnvManager->getSslUrl($toUrl);               // SSL用URLに変換
6050                         } else {
6051                                 $toUrl = str_replace('https://', 'http://', $toUrl);
6052                         }
6053                 }
6054
6055                 // バッファ内容が残っているときは破棄
6056                 if (ob_get_level() > 0) ob_end_clean();
6057
6058                 if (empty($responseCode)){
6059                         if ($noMessage){
6060                                 header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
6061                         } else {
6062                                 header('HTTP/1.1 301 Moved Permanently');
6063                         }
6064                 } else {                // レスポンスコードが指定されている場合
6065                         switch ($responseCode){
6066                                 case 301:
6067                                         header('HTTP/1.1 301 Moved Permanently');
6068                                         break;
6069                                 case 302:
6070                                         header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
6071                                         break;
6072                                 case 303:
6073                                         header('HTTP/1.1 303 See Other');
6074                                         break;
6075                                 case 500:                       // サーバ内部エラー
6076                                         header('HTTP/1.1 500 Internal Server Error');
6077                                         header('Status: 500 Internal Server Error');
6078                                         break;
6079                                 case 503:                       // サイト非公開(システムメンテナンス)
6080                                         header('HTTP/1.1 503 Service Temporarily Unavailable');
6081                                         header('Status: 503 Service Temporarily Unavailable');
6082                                         break;
6083                                 default:
6084                                         header('HTTP/1.1 ' . (string)$responseCode);
6085                                         break;
6086                         }
6087                 }
6088                 header('Location: ' . $toUrl);
6089                 
6090                 $this->isRedirect = true;                               // リダイレクトするかどうか
6091         }
6092         /**
6093          * リダイレクト処理かどうかを返す
6094          *
6095          * @return bool         true=リダイレクト、false=リダイレクトでない
6096          */
6097         function isRedirect()
6098         {
6099                 return $this->isRedirect;
6100         }
6101         /**
6102          * 指定URLのディレクトリへリダイレクト
6103          *
6104          * @return                                              なし
6105          */
6106         function redirectToDirectory()
6107         {
6108                 global $gEnvManager;
6109
6110                 // ファイル名を削除
6111                 $dirPath = dirname($gEnvManager->getCurrentScriptUrl()) . '/';
6112                 //$this->redirect($dirPath);
6113                 $this->redirect($dirPath, false, 303, false/*SSLは自動制御しない*/);                    // Firefoxでredirect先がキャッシュに残る問題を回避(2012/7/23)
6114         }
6115         /**
6116          * インストール時のリダイレクト処理
6117          *
6118          * @param string $url                   遷移先URL
6119          * @return                                              なし
6120          */
6121         function redirectInInstall($url)
6122         {
6123                 $this->redirect($url, false, 303, false/*SSLは自動制御しない*/);                        // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
6124         }
6125         /**
6126          * インストール用URLへリダイレクト
6127          *
6128          * @return                                              なし
6129          */
6130         function redirectToInstall()
6131         {
6132                 global $gEnvManager;
6133                 
6134                 $sytemRootUrl = $gEnvManager->calcSystemRootUrl();
6135                 //$this->redirect($sytemRootUrl . '/admin/install.php');
6136                 $this->redirect($sytemRootUrl . '/admin/install.php', false, 303, false/*SSLは自動制御しない*/);                        // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
6137         }
6138         /**
6139          * ログイン、ログアウト処理を行った後、リダイレクト
6140          *
6141          * @param RequestManager        $request                HTTPリクエスト処理クラス
6142          * @param bool                          $success                ログインの成否
6143          * @param string                        $redirectUrl    ログイン成功の場合のリダイレクト先
6144          * @return int                                                          0=何も処理しなかった場合、1=ログイン処理、2=ログアウト処理、3=パスワード送信
6145          */
6146         function standardLoginLogoutRedirect($request, &$success, $redirectUrl = '')
6147         {
6148                 global $gEnvManager;
6149                 global $gAccessManager;
6150                 global $gRequestManager;
6151                 
6152                 // ログイン、ログアウト処理、および、コンテナの起動
6153                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
6154                 if ($cmd == M3_REQUEST_CMD_LOGIN){                      // ログインの場合
6155                         $act = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_ACT);
6156                         if ($act == 'sendpwd'){         // パスワード送信の場合
6157                                 $success = $gAccessManager->sendPassword($request);
6158                                 return 3;
6159                         } else {
6160                                 // ユーザ認証
6161                                 $ret = $gAccessManager->userLogin($request);
6162                                 if ($ret){
6163                                         if (empty($redirectUrl)){
6164                                                 // システム運用可能ユーザの場合でリダイレクト先が設定されていない場合はデフォルトの管理画面URLへ遷移
6165                                                 $userInfo = $gEnvManager->getCurrentUserInfo();// ユーザ情報取得
6166                                                 if ($userInfo->userType >= UserInfo::USER_TYPE_MANAGER){
6167                                                         $ret = $this->db->getLoginUserRecordById($userInfo->userId, $userInfoRow);
6168                                                         if ($ret && !empty($userInfoRow['lu_default_admin_url'])){
6169                                                                 $redirectUrl = $gEnvManager->getDefaultAdminUrl() . $userInfoRow['lu_default_admin_url'];
6170                                                         }
6171                                                 }
6172                                         }
6173                                         
6174                                         // リダイレクト処理
6175                                         $this->redirect($redirectUrl);
6176                                         $success = true;                // ログイン成功
6177                                 } else {        // ログイン失敗のとき
6178                                         $success = false;               // ログイン失敗
6179                                 }
6180                                 return 1;
6181                         }
6182                 } else if ($cmd == M3_REQUEST_CMD_LOGOUT){              // ログアウト
6183                         // ログアウト処理
6184                         $gAccessManager->userLogout(true);
6185                         
6186                         // リダイレクト処理
6187                         $this->redirect($redirectUrl);
6188                         return 2;
6189                 } else {
6190                         return 0;
6191                 }
6192         }
6193         /**
6194          * エラー画面を表示
6195          *
6196          * @param int $errStatus                HTTPエラーステータスコード
6197          * @return                                              なし
6198          */
6199         function showError($errStatus)
6200         {
6201                 // レスポンスヘッダ設定
6202                 $this->setResponse($errStatus);
6203                 
6204                 // メッセージ設定
6205                 $msg = 'NOT DEFINED ERROR';
6206                 switch ($errStatus){
6207                         case 403:                       // アクセス禁止のとき
6208                                 $msg = 'Forbidden';
6209                                 break;
6210                         case 404:                       // 存在しないページのとき
6211                                 $msg = 'Not Found';
6212                                 break;
6213                         case 500:                       // サーバ内部エラー
6214                                 $msg = 'Internal Server Error';
6215                                 break;
6216                         case 503:                       // サイト非公開(システムメンテナンス)
6217                                 $msg = 'Service Temporarily Unavailable';
6218                                 break;
6219                 }
6220                 
6221                 echo '<!doctype html>';
6222                 echo '<html>';
6223                 echo '<head>';
6224                 echo '<title>' . $msg . '</title>';
6225                 echo '</head>';
6226                 echo '<body>';
6227                 echo '<h2>' . $msg . '</h2>';
6228                 echo '</body>';
6229                 echo '</html>';
6230         }
6231         /**
6232          * ウィジェットがセットされているページサブIDを取得
6233          *
6234          * @param string $pageId                ページID
6235          * @param string $widgetId              対象ウィジェットID
6236          * @param int $configId                 ウィジェット定義ID
6237          * @return string                               ページサブID
6238          */
6239         function getPageSubIdByWidget($pageId, $widgetId, $configId = 0)
6240         {
6241                 $pageSubId = '';
6242                 
6243                 // 対象のウィジェットのページサブIDを取得
6244                 $ret = $this->db->getSubPageId($widgetId, $pageId, $rows);
6245                 if ($ret){// データが存在する
6246                         for ($i = 0; $i < count($rows); $i++){
6247                                 if (!empty($rows[$i]['pd_sub_id']) && $rows[$i]['pd_config_id'] == $configId){
6248                                         $pageSubId = $rows[$i]['pd_sub_id'];
6249                                         break;
6250                                 }
6251                         }
6252                 }
6253                 return $pageSubId;
6254         }
6255         /**
6256          * その他のGET,POSTパラメータからページサブID取得
6257          *
6258          * @param RequestManager $request               HTTPリクエスト処理クラス
6259          * @param string $redirectUrl                   リダイレクト用URL
6260          * @return string                                               ページサブID
6261          */
6262         function getPageSubIdByParam($request, &$redirectUrl)
6263         {
6264                 global $gEnvManager;
6265                 
6266                 $subId = '';
6267                 $redirectUrl = '';
6268                 $task = $request->trimValueOf('task');
6269                 $option = $request->trimValueOf('option');
6270                 if ($task == 'search' && $option == 'com_search'){              // joomla!の検索結果表示の場合
6271                         $this->contentType = M3_VIEW_TYPE_SEARCH;               // ページのコンテンツタイプ
6272                                 
6273                         $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_SEARCH, $gEnvManager->getCurrentPageId());// ページサブIDを取得
6274                         if (!empty($subId)){
6275                                 // リダイレクト用URLを作成
6276                                 $keyword = $request->trimValueOf('searchword');
6277                                 $redirectUrl = $gEnvManager->createPageUrl();
6278                                 $redirectUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subId;
6279                                 $redirectUrl .= '&' . M3_REQUEST_PARAM_OPERATION_TASK . '=search&' . M3_REQUEST_PARAM_KEYWORD . '=' . urlencode($keyword);
6280                         }
6281                 }
6282                 return $subId;
6283         }
6284         /**
6285          * コンテンツタイプとページIDからページサブID取得
6286          *
6287          * @param string $contentType   コンテンツタイプ
6288          * @param string $pageId                ページID
6289          * @return string                               ページサブID
6290          */
6291         function getPageSubIdByContentType($contentType, $pageId)
6292         {
6293                 $subId = $this->db->getSubPageIdWithContent($contentType, $pageId);// ページサブIDを取得
6294                 return $subId;
6295         }
6296         /**
6297          * 指定のウィジェットがページ上にあるかを取得
6298          *
6299          * @param string $pageId                ページID
6300          * @param string $widgetId              対象ウィジェットID
6301          * @param bool $activePageOnly  公開中のページのウィジェットに制限するかどうか。falseの場合はすべてのページのウィジェットを対象とする。
6302          * @return bool                                 true=ページ上にあり、false=ページ上になし
6303          */
6304         function isWidgetOnPage($pageId, $widgetId, $activePageOnly=true)
6305         {
6306                 $ret = $this->db->isWidgetOnPage($pageId, $widgetId, $activePageOnly, 0/*定義セットID*/);
6307                 return $ret;
6308         }
6309         /**
6310          * URLで示されるページ上のウィジェットをウィジェット種別で取得
6311          *
6312          * @param string $url                   URL
6313          * @param string $widgetType    対象ウィジェットタイプ
6314          * @return string                               ウィジェットID
6315          */
6316         function getWidgetIdByWidgetType($url, $widgetType)
6317         {
6318                 $ret = $this->getPageIdFromUrl($url, $pageId, $pageSubId, $param);
6319                 
6320                 // ウィジェットIDを取得
6321                 if ($ret) $widgetId = $this->db->getWidgetIdByType($pageId, $pageSubId, $widgetType);
6322                 return $widgetId;
6323         }
6324         /**
6325          * ページコンテンツタイプ、コンテンツタイプからウィジェットIDを取得
6326          *
6327          * @param string $pageId                ページID
6328          * @param string $contentType    コンテンツタイプ
6329          * @return string                               ウィジェットID
6330          */
6331         function getWidgetIdWithPageInfoByContentType($pageId, $contentType)
6332         {
6333                 $widgetId = $this->db->getWidgetIdWithPageInfoByContentType($pageId, $contentType);
6334                 return $widgetId;
6335         }
6336         /**
6337          * ジョブタイプからウィジェットIDを取得
6338          *
6339          * @param string $jobType               ジョブタイプ
6340          * @return string                               ウィジェットID
6341          */
6342         function getWidgetIdByJobType($jobType)
6343         {
6344                 global $gEnvManager;
6345                 global $gErrorManager;
6346
6347                 // ジョブ実行用ウィジェット取得
6348                 $widgetId = '';
6349                 $linkInfoObj = $this->gInstance->getObject(self::LINKINFO_OBJ_ID);
6350                 if (isset($linkInfoObj)) $widgetId = $linkInfoObj->getJobWidget($jobType);
6351                 
6352                 // ウィジェットのアクセス権をチェック
6353                 if (!$this->db->canAccessWidget($widgetId)) return '';
6354
6355                 // ウィジェット情報取得
6356                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
6357
6358                 // 端末タイプをチェック
6359                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
6360                 
6361                 return $widgetId;
6362         }
6363         /**
6364          * 現在アクティブなメイン型ウィジェットをウィジェット種別で取得
6365          *
6366          * @param string $widgetType    対象ウィジェットタイプ
6367          * @return string                               ウィジェットID
6368          */
6369         function getActiveMainWidgetIdByWidgetType($widgetType)
6370         {
6371                 // ウィジェットIDを取得
6372                 $widgetId = $this->db->getActiveMainWidgetIdByType($widgetType);
6373                 return $widgetId;
6374         }
6375         /**
6376          * URLを解析して、ページID,サブページIDを取得
6377          *
6378          * @param string $url                   URL
6379          * @param string $pageId                ページID
6380          * @param string $pageSubId             ページサブID
6381          * @param array  $urlParam              URLパラメータ
6382          * @return bool                                 true=成功、false=失敗
6383          */
6384         function getPageIdFromUrl($url, &$pageId, &$pageSubId, &$urlParam)
6385         {
6386                 global $gEnvManager;
6387                         
6388                 // ページID、ページサブIDを求める
6389                 list($page, $other) = explode('?', str_replace($gEnvManager->getRootUrl(), '', $url));
6390                 parse_str($other, $urlParam);
6391                 
6392                 $pageId = str_replace('/', '_', trim($page, '/'));
6393                 $pageId = basename($pageId, '.php');
6394
6395                 // ページサブIDを取得
6396                 $pageSubId = $param[M3_REQUEST_PARAM_PAGE_SUB_ID];
6397                 if (empty($pageSubId)) $pageSubId = $gEnvManager->getDefaultPageSubId();
6398                 return true;
6399         }
6400         /**
6401          * ウィジェットが組み込まれているページのURLを生成
6402          *
6403          * @param string $widgetId      送信元ウィジェットID
6404          * @param string $param         実行パラメータ
6405          * @param string $pageId        ウィジェットが存在するページID
6406          * @return string                       生成したURL
6407          */
6408         function getDefaultPageUrlByWidget($widgetId, $param = '', $pageId = '')
6409         {
6410                 global $gEnvManager;
6411
6412                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6413                 
6414                 // このウィジェットがマップされているページサブIDを取得
6415                 $sub = '';
6416                 $subPageId = $this->getPageSubIdByWidget($pageId, $widgetId);
6417                 if (empty($subPageId)){
6418                         // 見つからないときは互換ウィジェットを探す
6419                         $targetWidgetId = $this->db->getCompatibleWidgetId($widgetId);
6420                         if (!empty($targetWidgetId)){
6421                                 $subPageId = $this->getPageSubIdByWidget($pageId, $targetWidgetId);
6422                         }
6423                 }
6424                 if (!empty($subPageId)) $sub = M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subPageId;
6425                 
6426                 //$url = $gEnvManager->getDefaultUrl();
6427                 $url = $gEnvManager->createPageUrl($pageId);
6428                 if (!empty($sub)) $url .= '?' . $sub;
6429                 if (!empty($param)) $url .= '&' . $param;
6430                 return $url;
6431         }
6432         /**
6433          * 現在のアクセスポイントの指定のページ属性のページURLを生成
6434          *
6435          * @param string $contentType   コンテンツタイプ
6436          * @param string $param                 追加パラメータ
6437          * @param bool $omitPageId              ページID省略形を使用するかどうか
6438          * @return string                               生成したURL
6439          */
6440         function createContentPageUrl($contentType, $param = '', $omitPageId = true)
6441         {
6442                 global $gEnvManager;
6443                 static $urlArray = array();
6444                 
6445                 // 複数回呼ばれるのでコンテンツタイプごとにページまでのURLは保存しておく
6446                 $baseUrl = $urlArray[$contentType];
6447                 if (!isset($baseUrl)){
6448                         // コンテンツタイプからページサブIDを取得
6449                         $pageSubId = $this->getPageSubIdByContentType($contentType, $gEnvManager->getCurrentPageId());          // DBから取得
6450                 
6451                         if (empty($pageSubId)){ // ページサブIDが取得できない場合はデフォルトのページサブIDを取得
6452                                 $pageSubId = $gEnvManager->getDefaultPageSubId();
6453                         } else if ($pageSubId == $gEnvManager->getDefaultPageSubId()){          // デフォルトページの場合
6454                                 if ($omitPageId) $pageSubId = '';       // ページID省略形を使用する場合はページサブIDを省略
6455                         }
6456                         
6457                         // 現在のアクセスポイントのURLを取得
6458                         $baseUrl = $gEnvManager->createPageUrl();
6459                         
6460                         // ページサブIDを付加
6461                         if (!empty($pageSubId)) $baseUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId;
6462                         
6463                         // URLを保存
6464                         $urlArray[$contentType] = $baseUrl;
6465                 }
6466                 
6467                 // 追加パラメータ
6468                 $url = $baseUrl;
6469                 if (!empty($param)){
6470                         if (strEndsWith($url, '.php') || strEndsWith($url, '/')){
6471                                 $url .= '?';
6472                         } else {
6473                                 $url .= '&';
6474                         }
6475                         $url .= $param;
6476                 }
6477                 return $url;
6478         }
6479         /**
6480          * ウィジェット指定呼び出し用のURLを生成
6481          *
6482          * @param string $toWidgetId    送信先ウィジェットID
6483          * @param string $fromWidgetId  送信元ウィジェットID
6484          * @param string $todo                  実行パラメータ
6485          * @param string $pageId                ページID(空のときは現在のURL)
6486          * @return string                               生成したURL
6487          */
6488         function createWidgetCmdUrl($toWidgetId, $fromWidgetId, $todo, $pageId = '')
6489         {
6490                 global $gEnvManager;
6491                 
6492                 $url = $gEnvManager->createPageUrl($pageId);
6493                 
6494                 $url .= '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_FIND_WIDGET;
6495                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $toWidgetId;
6496                 if (!empty($fromWidgetId)) $url .= '&' . M3_REQUEST_PARAM_FROM . '=' . $fromWidgetId;           // 送信元
6497                 if (!empty($todo)) $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=' . urlencode($todo);
6498                 return $url;
6499         }
6500         /**
6501          * RSS配信用のURLを生成
6502          *
6503          * @param string $widgetId              実行ウィジェットID
6504          * @param string $optionParam   追加パラメータ
6505          * @param string $pageId                ページID(空のときは現在のURL)
6506          * @param string $pageSubId             ページサブID
6507          * @return string                               生成したURL
6508          */
6509         function createRssCmdUrl($widgetId, $optionParam = '', $pageId = '', $pageSubId = '')
6510         {
6511                 global $gEnvManager;
6512                 
6513                 // 現在のページURLを取得
6514                 $url = $gEnvManager->createPageUrl() . '?';
6515                 
6516                 // ページサブIDを取得
6517                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // グローバル属性ありのときは空
6518                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6519                 
6520                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_RSS;
6521                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
6522                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6523                 return $url;
6524         }
6525         /**
6526          * CSS生成用のURLを生成
6527          *
6528          * @param bool   $isSslPage             SSLが必要なページかどうか
6529          * @param string $optionParam   追加パラメータ
6530          * @return string                               生成したURL
6531          */
6532         function createCssCmdUrl($isSslPage, $optionParam = '')
6533         {
6534                 global $gEnvManager;
6535                 global $gRequestManager;
6536                 
6537                 // 現在のページURLを取得
6538         //      $url = $gEnvManager->createPageUrl() . '?';
6539                 $url = $gEnvManager->createPageUrl(''/*現在のページ*/, $isSslPage) . '?';
6540                 
6541                 // ページサブIDを取得
6542                 $pageSubId = $this->gEnv->getCurrentPageSubId();
6543                 $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6544                 
6545                 // コンテンツ詳細画面の場合はコンテンツパラメータを追加
6546                 if ($this->isContentDetailPage){
6547                         switch ($this->contentType){
6548                                 case M3_VIEW_TYPE_CONTENT:              // 汎用コンテンツ
6549                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_CONTENT_ID);
6550                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_CONTENT_ID_SHORT);
6551                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentsId . '&';
6552                                         break;
6553                                 case M3_VIEW_TYPE_PRODUCT:      // 製品
6554                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PRODUCT_ID);
6555                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PRODUCT_ID_SHORT);
6556                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_PRODUCT_ID . '=' . $contentsId . '&';
6557                                         break;
6558                                 case M3_VIEW_TYPE_BBS:  // BBS
6559                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BBS_THREAD_ID);
6560                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT);
6561                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $contentsId . '&';
6562                                         break;
6563                                 case M3_VIEW_TYPE_BLOG: // ブログ
6564                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BLOG_ENTRY_ID);
6565                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT);
6566                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $contentsId . '&';
6567                                         break;
6568                                 case M3_VIEW_TYPE_WIKI: // Wiki
6569                                         $contentsId = $gRequestManager->getWikiPageFromQuery();         // 「=」なしのパラメータはwikiパラメータとする
6570                                         if (!empty($contentsId)) $url .= $contentsId . '&';
6571                                         break;
6572                                 case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ
6573                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_ROOM_ID);
6574                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_ROOM_ID_SHORT);
6575                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_ROOM_ID . '=' . $contentsId . '&';
6576                                         break;
6577                                 case M3_VIEW_TYPE_EVENT:        // イベント
6578                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_EVENT_ID);
6579                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_EVENT_ID_SHORT);
6580                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_EVENT_ID . '=' . $contentsId . '&';
6581                                         break;
6582                                 case M3_VIEW_TYPE_PHOTO:        // フォトギャラリー
6583                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID);
6584                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID_SHORT);
6585                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_PHOTO_ID . '=' . $contentsId . '&';
6586                                         break;
6587                         }
6588                 }
6589                 
6590                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_CSS;
6591                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6592                 return $url;
6593         }
6594         /**
6595          * ウィジェット実行用のURLを生成
6596          *
6597          * @param string $widgetId      実行ウィジェットID
6598          * @param string $optionParam   追加パラメータ
6599          * @param bool $byMacro         マクロ変換で返すかどうか
6600          * @param string $pageId                ページID(空のときは現在のURL)
6601          * @param string $pageSubId             ページサブID
6602          * @return string                               生成したURL
6603          */
6604         function createDirectWidgetCmdUrl($widgetId, $optionParam = '', $byMacro = false, $pageId = '', $pageSubId = '')
6605         {
6606                 global $gEnvManager;
6607                 
6608                 // 現在のページURLを取得
6609                 if ($byMacro){
6610                         $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_FILENAME_INDEX . '?';
6611                 } else {
6612                         $url = $gEnvManager->createPageUrl() . '?';
6613                 }
6614                 
6615                 // ページサブIDを取得
6616                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // グローバル属性ありのときは空
6617                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6618                 
6619                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_DO_WIDGET;
6620                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
6621                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6622                 return $url;
6623         }
6624         /**
6625          * URLパラメータの並び順を取得
6626          *
6627          * @return array                                        パラメータ文字列の配列
6628          */
6629         function getUrlParamOrder()
6630         {
6631                 return $this->urlParamOrder;                                    // URLパラメータの並び順
6632         }
6633         /**
6634          * キャッシュ制御用の付加パラメータを取得
6635          *
6636          * @return string                               パラメータ
6637          */     
6638         function getCacheParam()
6639         {
6640                 $addParam = '?' . date('YmdHis');
6641                 return $addParam;
6642         }
6643         /**
6644          * 現在のURLにアクセス可能かチェック
6645          *
6646          * @param bool $isActivePage    ページが有効かどうか
6647          * @param int  $errCode                 エラーコード
6648          * @return bool                                 true=可能、false=不可
6649          */     
6650         function canAccessUrl(&$isActivePage, &$errCode)
6651         {
6652                 global $gEnvManager;
6653
6654                 $errCode = 0;                   // エラーコード初期化
6655                 
6656                 // 現在設定されているページIDを取得
6657                 $pageId         = $gEnvManager->getCurrentPageId();
6658                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
6659                 $ret = $this->db->canAccessPage($pageId, $pageSubId, $pageVisible, $pageSubVisible, $isAdminMenu);
6660                 if ($ret){              // アクセス可能なときは、ユーザ制限もチェックする
6661                         $isActivePage = true;
6662                         
6663                         // ページが表示可能かチェック
6664                         if (!$pageVisible || !$pageSubVisible) return false;
6665
6666                         if (!$gEnvManager->isCurrentUserLogined() && $this->isUserLimitedPage($pageId, $pageSubId)){                    // ユーザがログインされていない状態でユーザ制限されていればアクセス不可
6667                                 return false;
6668                         } else {
6669                                 $this->isAccessPointWithAdminMenu = $isAdminMenu;                               // 管理メニューを使用するアクセスポイントかどうか
6670                                 return true;
6671                         }
6672                 } else {                        // 無効ページのとき
6673                         $isActivePage = false;
6674                         
6675                         // ページIDの文字のチェック。ページIDは半角英小文字、数字、アンダーバー、ハイフンのみ使用可能。
6676                         if (preg_match("/[^0-9a-z-_]/", $pageSubId)) $errCode = 1;                      // 不正文字検出
6677                 }
6678                 return false;
6679         }
6680         /**
6681          * ウィジェットヘッダ(Joomla!1.0用)を出力タイプを取得
6682          *
6683          * @return int                          0=出力しない、1=Joomla!1.0テンプレートPC用、2=Joomla!1.0テンプレート携帯用
6684          */     
6685         function getTemplateWidgetHeaderType()
6686         {
6687                 global $gEnvManager;
6688                 
6689                 $templateId = $gEnvManager->getCurrentTemplateId();
6690                 if ($templateId == self::ADMIN_TEMPLATE ||              // PC管理用テンプレート
6691                         $templateId == self::M_ADMIN_TEMPLATE){         // 携帯管理用テンプレート
6692                         return 0;
6693                 } else if(strncmp($templateId, 'm/', 2) == 0){          // 携帯用テンプレート
6694                         return 2;               // 携帯テンプレート用出力
6695                 } else {
6696                         return 1;               // PCテンプレート用出力
6697                 }
6698         }
6699         /**
6700          * SSLが必要なページかどうかを判断
6701          *
6702          * @param string $pageId        ページID
6703          * @param string $pageSubId     ページサブID
6704          * @return bool                         true=必要、false=不要
6705          */     
6706         function isSslPage($pageId, $pageSubId)
6707         {
6708                 global $gEnvManager;
6709                 
6710                 // パラメータ修正
6711                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6712                 
6713                 // 管理用ページの場合
6714                 if ($pageId == $gEnvManager->getDefaultAdminPageId()){
6715                         if ($gEnvManager->getUseSslAdmin()){            // 管理用ページにSSLを使用するかどうか
6716                                 return true;
6717                         } else {
6718                                 return false;
6719                         }
6720                 }
6721                 
6722                 // ##### フロント画面の場合 #####
6723                 if ($gEnvManager->isRootUrlSsl()) return true;          // ルートURLがSSLの場合はフロント画面のすべてがSSL付き
6724                 
6725                 // 一般用ページにSSLを使用しない場合は不要を返す
6726                 if (!$gEnvManager->getUseSsl()) return false;
6727                                         
6728                 // 一般用ページでSSLを使用する場合は、データベースの設定をチェックする
6729                 $line = $this->getPageInfo($pageId, $pageSubId);
6730                 if (!empty($line)){
6731                         if ($line['pn_use_ssl']){
6732                                 return true;
6733                         } else {
6734                                 return false;
6735                         }
6736                 }
6737                 return false;
6738         }
6739         /**
6740          * ユーザ制限が必要なページかどうかを判断
6741          *
6742          * @param string $pageId        ページID
6743          * @param string $pageSubId     ページサブID
6744          * @return bool                         true=必要、false=不要
6745          */     
6746         function isUserLimitedPage($pageId, $pageSubId)
6747         {
6748                 global $gEnvManager;
6749                 
6750                 // パラメータ修正
6751                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6752                 
6753                 $line = $this->getPageInfo($pageId, $pageSubId);
6754                 if (!empty($line)){
6755                         if ($line['pn_user_limited']){
6756                                 return true;
6757                         } else {
6758                                 return false;
6759                         }
6760                 }
6761                 return false;
6762         }
6763         /**
6764          * ページ情報を取得
6765          *
6766          * @param string $pageId        ページID
6767          * @param string $pageSubId     ページサブID
6768          * @return array                        ページ情報レコード
6769          */     
6770         function getPageInfo($pageId, $pageSubId)
6771         {
6772                 // ページ情報が空のときはデータをロード
6773                 if (empty($this->pageInfo)){
6774                         $records = $this->db->getPageInfoRecords();
6775                         $count = count($records);
6776                         $this->pageInfo = array();
6777                         for ($i = 0; $i < $count; $i++){
6778                                 $pId = $records[$i]['pn_id'] . self::PAGE_ID_SEPARATOR . $records[$i]['pn_sub_id'];
6779                                 $this->pageInfo[$pId] = $records[$i];
6780                         }
6781                 }
6782                 return $this->pageInfo[$pageId . self::PAGE_ID_SEPARATOR . $pageSubId];
6783         }
6784         /**
6785          * 現在のページのページ情報を取得
6786          *
6787          * @return array                        ページ情報レコード
6788          */     
6789         function getCurrentPageInfo()
6790         {
6791                 return $this->currentPageInfo;
6792         }
6793         /**
6794          * 現在のページ情報からテンプレートIDを取得
6795          *
6796          * @param string $subTemplateId         テンプレートIDが取得できるときはサブページIDが返る
6797          * @return string                                       テンプレートID
6798          */     
6799         function getTemplateIdFromCurrentPageInfo(&$subTemplateId)
6800         {
6801                 $templateId = '';
6802                 if (!empty($this->currentPageInfo)){
6803                         $templateId = $this->currentPageInfo['pn_template_id'];
6804                         $subTemplateId = $this->currentPageInfo['pn_sub_template_id'];                  // サブテンプレートID
6805                 }
6806                 return $templateId;
6807         }
6808         /**
6809          * JavascriptライブラリのIDを取得
6810          *
6811          * @param int $type                     種別(0=すべて、1=jQuery関係すべて、2=jQueryプラグインのみ)
6812          * @return array                        JavascriptライブラリのID
6813          */     
6814         function getScriptLibId($type = 0)
6815         {
6816                 // Javascriptライブラリのすべてのキーを取得
6817                 $keys = array_keys($this->libFiles);
6818                 
6819                 $destKeys = array();
6820                 for ($i = 0; $i < count($keys); $i++){
6821                         switch ($type){
6822                                 case 1:         // jQuery関係すべて
6823                                         if (strStartsWith($keys[$i], 'jquery')) $destKeys[] = $keys[$i];
6824                                         break;
6825                                 case 2:         // jQueryプラグインのみ
6826                                         if (strStartsWith($keys[$i], 'jquery.')) $destKeys[] = $keys[$i];
6827                                         break;
6828                         }
6829                 }
6830                 return $destKeys;
6831         }
6832         /**
6833          * Javascriptライブラリの情報を取得
6834          *
6835          * @param string $id            ライブラリID
6836          * @return array                        ライブラリの情報
6837          */     
6838         function getScriptLibInfo($id)
6839         {
6840                 $libInfo = $this->libFiles[$id];
6841                 if (isset($libInfo)){
6842                         return $libInfo;
6843                 } else {
6844                         return array();
6845                 }
6846         }
6847         /**
6848          * 管理画面用jQueryUIテーマのURLを取得
6849          *
6850          * @return string                       テーマURL
6851          */     
6852         function getAdminDefaultThemeUrl()
6853         {
6854 //              $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
6855                 $themeFile = $this->gEnv->getAdminUrl(true/*「admin」削除*/) . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
6856                 return $themeFile;
6857         }
6858         /**
6859          * フロント画面用jQueryUIテーマのURLを取得
6860          *
6861          * @return string                       テーマURL
6862          */     
6863         function getDefaultThemeUrl()
6864         {
6865                 static $themeFile;
6866                 
6867                 if (!isset($themeFile)){
6868                         $themeFile = '';
6869                         $theme = $this->gSystem->defaultTheme();
6870                         if (!empty($theme)){
6871                                 $path = $this->gEnv->getSystemRootPath() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
6872                                 if (file_exists($path)) $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
6873                         }
6874                 }
6875                 return $themeFile;
6876         }
6877         /**
6878          * URLパラメータ文字列作成
6879          *
6880          * @param array $paramArray                     URL作成用のパス
6881          * @return string                                       作成したURLパラメータ
6882          */
6883         function _createUrlParamStr($paramArray)
6884         {
6885                 $destParam = '';
6886                 if (count($paramArray) == 0) return $destParam;
6887
6888                 $sortParam = array();
6889                 $keys = array_keys($paramArray);
6890                 $keyCount = count($keys);
6891                 for ($i = 0; $i < $keyCount; $i++){
6892                         $key = $keys[$i];
6893                         $value = $paramArray[$key];
6894                         $orderNo = $this->urlParamOrder[$key];
6895                         if (!isset($orderNo)) $orderNo = 100;
6896                         $sortParam[] = array('key' => $key, 'value' => $value, 'no' => $orderNo);
6897                 }
6898 //              usort($sortParam, create_function('$a,$b', 'return $a["no"] - $b["no"];'));
6899                 usort($sortParam, function($a, $b)
6900                 {
6901                         return $a['no'] - $b['no'];
6902                 });
6903                 
6904                 // 文字列を作成
6905                 $sortCount = count($sortParam);
6906                 for ($i = 0; $i < $sortCount; $i++){
6907                         if ($i > 0) $destParam .= '&';
6908                         $destParam .= rawurlencode($sortParam[$i]['key']) . '=' . rawurlencode($sortParam[$i]['value']);
6909                 }
6910                 return $destParam;
6911         }
6912         /**
6913          * URLで指定した画面のCSSファイルを取得
6914          *
6915          * @param string $url   取得画面のURL
6916          * @return                              なし
6917          */
6918         function loadCssFilesByUrl($url)
6919         {
6920                 $ch = curl_init();
6921                 curl_setopt($ch, CURLOPT_URL, $url);
6922                 curl_setopt($ch, CURLOPT_USERAGENT, M3_SYSTEM_NAME . '/' . M3_SYSTEM_VERSION);          // ユーザエージェント
6923                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         // 画面に出力しない
6924                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
6925                 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
6926                 curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());          // セッションを維持
6927                 $content = curl_exec($ch);
6928                 curl_close($ch);
6929
6930                 // HEADタグを取り出す
6931                 $urlArray = array();
6932                 $headContent = '';
6933                 $pattern = '/<head\b[^>]*?>(.*?)<\/head\b[^>]*?>/si';
6934                 if (preg_match($pattern, $content, $matches)) $headContent = $matches[0];
6935
6936                 // CSSファイル取り出し
6937                 $pattern = '/<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
6938                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
6939                         foreach ($matches as $match){
6940                                 if (strEndsWith($match[1], '.css')){            // ファイル名の拡張子が「css」の場合
6941                                         $urlArray[] = $match[1];
6942                                 } else {
6943                                         // typeが「text/css」の場合も取得
6944                                         $attrPattern = '/type\s*=\s*[\'"]+(.+?)[\'"]/si';
6945                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
6946                                                 if (strcasecmp($attrMatch[1], 'text/css') == 0) $urlArray[] = $match[1];
6947                                         }
6948                                 }
6949                         }
6950                 }
6951
6952                 // ifで制御されているCSSファイルを除く
6953                 $delUrlArray = array();
6954                 $pattern = '/<!--\[if\b.*?\]>[\b]*<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>[\b]*<!\[endif\]-->/si';
6955                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
6956                         foreach ($matches as $match) $delUrlArray[] = $match[1];
6957                 }
6958
6959                 // テンプレート独自のCSSまたは外部のCSSを取得する
6960                 $this->ckeditorCssFiles = array();
6961                 $cssFiles = array_merge(array_diff($urlArray, $delUrlArray));   // CKEditor用のCSSファイル
6962                 for ($i = 0; $i < count($cssFiles); $i++){
6963                         $cssFileUrl = $cssFiles[$i];
6964                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
6965                                 $baseUrl = $this->gEnv->getRootUrl();
6966                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
6967                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
6968                         }
6969                         // パスを解析
6970                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
6971                         
6972                         if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){           // テンプレートディレクトリの場合
6973                                 $this->ckeditorCssFiles[] = $cssFileUrl;
6974                         } else if (strStartsWith($relativePath, '/')){          // テンプレートディレクトリ以外のディレクトリの場合
6975                         } else {                        // 外部URLの場合
6976                                 $this->ckeditorCssFiles[] = $cssFileUrl;
6977                         }
6978                 }
6979                 
6980                 // テンプレートタイプを取得
6981                 $pattern = '/var\s*M3_TEMPLATE_TYPE\s*=\s*(\d+?)\s*;/si';
6982                 if (preg_match($pattern, $headContent, $matches)) $this->ckeditorTemplateType = $matches[1];                    // CKEditor用のテンプレートタイプ
6983         }
6984         /**
6985          * CKEditor用のテンプレートタイプを取得
6986          *
6987          * @return int                  テンプレートタイプ
6988          */     
6989         function getCkeditorTemplateType()
6990         {
6991                 return $this->ckeditorTemplateType;
6992         }
6993         /**
6994          * POST時のリファラーチェック
6995          *
6996          * @return bool         true=正常、false=不正
6997          */
6998 /*      function _checkReferer()
6999         {
7000                 global $gEnvManager;
7001                 global $gRequestManager;
7002                 
7003                 // リファラーをチェック
7004                 $referer        = $gRequestManager->trimServerValueOf('HTTP_REFERER');
7005                 $uri            = $gEnvManager->getCurrentRequestUri();
7006                 if (empty($referer) || $referer != $uri){
7007                         return false;
7008                 } else {
7009                         return true;
7010                 }
7011         }*/
7012 }
7013 ?>