OSDN Git Service

携帯関係のウィジェット、テンプレートを削除。
[magic3/magic3.git] / include / manager / pageManager.php
1 <?php
2 /**
3  * 画面制御マネージャー
4  *
5  * 画面の作成、遷移を処理する
6  *
7  * PHP versions 5
8  *
9  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
10  *
11  * @package    Magic3 Framework
12  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
13  * @copyright  Copyright 2006-2018 Magic3 Project.
14  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
15  * @version    SVN: $Id$
16  * @link       http://www.magic3.org
17  */
18 require_once(M3_SYSTEM_INCLUDE_PATH . '/common/core.php');
19 require_once(M3_SYSTEM_INCLUDE_PATH . '/common/scriptLibInfo.php');
20
21 class PageManager extends Core
22 {
23         private $popupMsg;                              // ポップアップダイアログメッセージ
24         private $showPositionMode;                      // ポジション表示モード
25         private $showWidget;                    // ウィジェットの単体表示
26         private $systemHandleMode;                      // システム制御遷移モード(1=サイト非公開時)
27         private $isPageEditable;                // フロント画面ページ編集可能モード
28         private $isTransparentMode;             // 画面透過モード
29         private $isPersonalMode;                // 機能アクセスパーソナルモード
30         private $isEditMode;                    // フロント画面編集モード
31         private $isLayout;                              // 画面レイアウト中かどうか
32         private $isPageTopUrl;                  // ページトップ(サブページ内のトップ位置)のURLかどうか
33         private $isContentDetailPage;   // コンテンツ詳細画面のページかどうか
34         private $tmpData;                               // データ作成用
35         private $db;                                    // DBオブジェクト
36         private $defaultScriptFiles;    // デフォルトで読み込むスクリプトファイル
37         private $defaultCssFiles;               // デフォルトで読み込むCSSファイル
38         private $defaultAdminScriptFiles;       // デフォルトで読み込むスクリプトファイル(管理用)
39         private $defaultAdminCssFiles;          // デフォルトで読み込むCSSファイル(管理用)
40         private $defaultAdminDirScriptFiles;    // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
41         private $defaultAdminDirCssFiles;       // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
42         private $headScriptFiles = array();             // ウィジェットからの追加で読み込むスクリプトファイル
43         private $headPreMobileScriptFiles = array();// ウィジェットからの追加で読み込むスクリプトファイル(jQueryMobile用挿入ファイル)
44         private $headCssFiles = array();                // ウィジェットからの追加で読み込むCSSファイル
45         private $headRssFiles = array();                // HTMLヘッダに出力するRSS配信情報
46         private $currentWidgetPosition;                 // 現在のウィジェットのポジション
47         private $currentWidgetIndex;                    // 現在のウィジェットのポジション番号
48         private $pageDefPosition;               // 現在取得しているページ定義のポジション
49         private $pageDefRows;                   // ページ定義レコード
50         private $nonSharedWidgetCount = -1;     // 非共通ウィジェットの数(-1=ページ作成でないとき)
51         private $replaceHeadDone;                       // ヘッダマクロ変換処理が完了したかどうか
52         private $useHelp = false;               // 標準ヘルプ機能を使用するかどうか
53         private $hasScriptCache = false;        // JavaScriptファイルをブラウザにキャッシュさせるかどうか
54         private $isAccessPointWithAdminMenu;                            // 管理メニューを使用するアクセスポイントかどうか
55         private $lateLaunchWidgetList;  // 遅延実行ウィジェットのリスト
56         private $latelaunchWidgetParam;         // 遅延実行ウィジェットのパラメータ
57         private $defPositions = array();        // テンプレート上のポジション(画面定義データすべて)
58         private $viewPositions = array();       // テンプレート上のポジション(ウィジェット表示ありのみ)
59         private $viewPosId = array();           // テンプレート上のポジションのタグID
60         private $updateParentWindow;            // 親ウィンドウを再描画するかどうか
61         private $updateDefSerial;                       // 更新する項目のページ定義シリアル番号
62         private $headDescription;                               // HTMLヘッダ「description」に出力する文字列
63         private $headKeywords;                          // HTMLヘッダ「keywords」に出力する文字列
64         private $headOthers;                            // HTMLヘッダに出力するタグ文字列
65         private $adminHeadOthers;                               // HTMLヘッダに出力するタグ文字列(管理画面用)
66         private $lastHeadTitle;                         // 最後にヘッダ部titleにセットした文字列
67         private $lastHeadDescription;           // 最後にヘッダ部descriptionにセットした文字列
68         private $lastHeadKeywords;                      // 最後にヘッダ部keywordsにセットした文字列
69         private $headFirstTag;                          // HTMLヘッダに最初に出力するタグ文字列
70         private $headCss = array();                     // HTMLヘッダにCSS出力する文字列
71         private $headScript = array();          // HTMLヘッダにJavascript出力する文字列
72         private $headPreMobileScript = array();         // HTMLヘッダにJavascript出力する文字列(jQueryMobile用挿入スクリプト)
73         private $headString = array();          // HTMLヘッダに出力する任意文字列
74         private $exportCss = array();           // 外部出力でCSS出力する文字列
75         private $lastHeadCss;                           // 最後に設定したHTMLヘッダにCSS出力する文字列
76         private $lastHeadScript;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
77         private $lastHeadString;                        // 最後に設定したHTMLヘッダに出力する任意文字列
78         private $headSubTitle = array();                                // ヘッダタグサブタイトル
79         private $headSubTitleUrl = array();                             // ヘッダサブタイトルのリンク先
80         private $headCanonicalUrl;                              // カノニカル属性URL
81         private $initScript = '';                               // ウィンドウ初期化時に実行されるスクリプト
82         private $outputByHtml = true;                           // HTMLフォーマットで出力するかどうか
83         private $outputByStandardHead;          // HTML文書の標準のヘッダタグを出力するかどうか
84         private $outputHead;                            // HTMLヘッダ出力を行ったかどうか
85         private $outputTheme;                           // jQueryUIテーマ出力を行ったかどうか
86         private $outputAjaxResponseBody;        // AJAX用のレスポンスボディデータかどうか
87         private $isAbort;                                       // ページ作成処理を中断するかどうか
88         private $isWidgetAbort;                         // 各ウィジェット処理を中断するかどうか
89         private $isRedirect;                            // リダイレクトするかどうか
90         private $isSystemPage;                          // システム制御ページを表示するかどうか
91         private $libFiles;                                      // javascript追加用ライブラリ
92         private $pageDefRev = 234;                              // 画面定義のリビジョン番号
93         private $pageInfo;                                      // すべてのページ情報
94         private $currentPageInfo;                       // 現在のページのページ情報
95         private $configWidgetInfo;                      // ウィジェット設定画面のウィジェットの情報
96         private $contentType = '';                              // ページのコンテンツタイプ
97         private $mainContentTypeInfo;                           // フロント画面で使用する主要コンテンツタイプ
98         private $subContentTypeInfo;                            // フロント画面で使用する補助コンテンツタイプ
99         private $mainFeatureTypeInfo;                           // フロント画面で使用する主要機能タイプ
100         private $adminFeatureTypeInfo;                                          // 管理画面専用で使用する主要機能タイプ
101         private $rssVersion;                                    // RSSバージョン
102         private $rssChannel;                            // RSSチャンネルデータ
103         private $selectedJQueryFilename;                // 使用対象のjQueryファイル
104         private $selectedJQueryUiFilename;              // 使用対象のjQuery UIファイル
105         private $selectedJQueryMobileFilename;          // 使用対象のjQueryMobileファイル
106         private $urlParamOrder;                                 // URLパラメータの並び順
107         private $wysiwygEditor;                         // 管理画面用WYSIWYGエディター
108         private $optionTemplateId;                      // 追加設定するテンプレートID
109         private $optionSubTemplateId;                   // 追加設定するサブテンプレートID
110         private $isContentGooglemaps;           // コンテンツにGoogleマップが含むかどうか
111         private $useGooglemaps;                         // Googleマップを使用するかどうか
112         private $useBootstrap;                          // Bootstrapを使用するかどうか
113         private $isHtml5;                                       // HTML5で出力するかどうか
114         private $ckeditorCssFiles = array();    // CKEditor用のCSSファイル
115         private $ckeditorTemplateType;                  // CKEditor用のテンプレートタイプ
116         private $adminSubNavbarDef = array();           // 管理画面用のサブメニューバーの定義
117         private $adminBreadcrumbDef = array();                  // 管理画面用パンくずリスト定義
118         private $adminBreadcrumbDefHelp = array();                              // 管理画面用パンくずリストヘルプ定義
119         const CONFIG_KEY_HEAD_TITLE_FORMAT = 'head_title_format';               // ヘッダ作成用フォーマット
120         const ADMIN_WIDGET_ID = 'admin_main';           // 管理用ウィジェットのウィジェットID
121         //const CONTENT_TYPE_WIKI = 'wiki';             // ページのコンテンツタイプ(Wiki)
122         const WIDGET_ID_TAG_START = '{{WIDGETID:';              // 遅延実行用タグ
123         const WIDGET_ID_TAG_END = '}}';         // 遅延実行用タグ
124         const WIDGET_ID_TITLE_TAG_START = '{{WIDGETID_TITLE:';          // 遅延実行用タグ(タイトル埋め込み用)
125         const WIDGET_ID_TITLE_TAG_END = '}}';                                           // 遅延実行用タグ(タイトル埋め込み用)
126         const WIDGET_ID_SEPARATOR = ',';
127         const HEAD_TAGS                         = '{{HEAD_TAGS}}';                              // HTMLヘッダ出力用タグ
128         const MENUBAR_TAGS                      = '{{MENUBAR_TAGS}}';                   // メニューバー出力用タグ
129         const MENUBAR_SCRIPT_TAGS       = '{{MENUBAR_SCRIPT_TAGS}}';                            // メニューバー出力用スクリプトタグ
130         const WIDGET_ICON_IMG_SIZE = 32;                        // ウィジェットアイコンサイズ
131         const WIDGET_INVISIBLE_CLASS = 'm3invisible';                   // 非表示ウィジェットクラス
132         const WIDGET_LOGIN_STATUS_CLASS = 'm3loginstatus';              // ログイン状態連動クラス
133         const WIDGET_OUTER_CLASS = 'm3_widget_outer';                   // ウィジェット外枠クラス
134         const WIDGET_OUTER_CLASS_HEAD_POSITION = 'm3_pos_';                     // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
135         const WIDGET_OUTER_CLASS_WIDGET_TAG = 'm3_';                            // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
136 //      const WIDGET_INNER_CLASS = 'm3_widget_inner';                   // ウィジェットの内側クラス
137         const POSITION_TAG_HEAD = 'm3pos_';                     // ポジションの識別用タグIDヘッダ
138         const WIDGET_TAG_HEAD = 'm3widget_';                    // ウィジェットの識別用タグIDヘッダ
139 //      const WIDGET_TAG_HEAD_SHORT = 'm3_';                    // ウィジェットの識別用タグIDヘッダ
140         const WIDGET_TYPE_TAG_HEAD = 'm3widgettype_';                   // ウィジェット種別の識別用タグIDヘッダ
141         const WIDTET_CLASS_NAME = 'm3widget';                   // ウィジェットオブジェクトのタグクラス名
142         const WIDTET_CLASS_TYPE_0 = 'm3widget_type0';                   // ウィジェットオブジェクトのタグクラス(グローバル属性でない)
143         const WIDTET_CLASS_TYPE_1 = 'm3widget_type1';                   // ウィジェットオブジェクトのタグクラス(グローバル属性)
144         const POSITION_CLASS_NAME = 'm3position';               // ポジションオブジェクトのタグクラス名
145         const JOOMLA10_DEFAULT_WIDGET_MENU_PARAM = 'class="moduletable"';       // Joomla!1.0用デフォルトメニューパラメータ値
146         const ADMIN_TEMPLATE = '_admin';                // PC管理用テンプレートID
147         const M_ADMIN_TEMPLATE = 'm/_admin';    // 携帯用管理画面テンプレートID
148         const SCRIPT_LIB_SEPARATOR = ';';                       // JavaScriptライブラリ読み込み設定のライブラリの区切り
149         const PAGE_ID_SEPARATOR = ',';                          // ページIDとページサブID連結用
150         const DEFAULT_ADMIN_FAVICON_FILE = '/images/system/favicon.ico';                        // デフォルトの管理画面用faviconファイル
151         const DEFAULT_FAVICON_FILE = '/favicon.ico';                    // デフォルトのfaviconファイル
152 //      const DEFAULT_SITE_NAME = 'サイト名未設定';              // 管理画面用のデフォルトサイト名
153         const DEFAULT_ADMIN_TITLE = '管理画面';                     // デフォルトの管理画面名
154         const WIDGET_TITLE_START = '[';                                 // ウィジェットのタイトルの括弧
155         const WIDGET_TITLE_END = ']';                                   // ウィジェットのタイトルの括弧
156         const DEFAULT_RSS_VERSION = '1.0';                              // デフォルトのRSSのバージョン
157         const CF_ACCESS_IN_INTRANET = 'access_in_intranet';             // イントラネット運用かどうか
158         const CF_USE_LATEST_SCRIPT_LIB = 'dev_use_latest_script_lib';           // 最新のJavaScriptライブラリを使用するかどうか
159         const CF_GOOGLE_MAPS_KEY = 'google_maps_key';                           // Googleマップ利用キー
160         const CF_CONFIG_WINDOW_OPEN_TYPE = 'config_window_open_type';           // ウィジェット設定画面のウィンドウ表示タイプ(0=別ウィンドウ、1=タブ)
161         const CF_JQUERY_VERSION = 'jquery_version';                     // jQueryバージョン
162         const CF_EXTERNAL_JQUERY = 'external_jquery';                   // システム外部のjQueryを使用するかどうか
163         const CF_WYSIWYG_EDITOR = 'wysiwyg_editor';             // 管理画面用WYSIWYGエディター
164         const CF_ADMIN_JQUERY_VERSION = 'admin_jquery_version';                 // 管理画面用jQueryバージョン
165         const CF_USE_JQUERY = 'use_jquery';                             // jQueryを常に使用するかどうか
166         const CF_SMARTPHONE_USE_JQUERY_MOBILE = 'smartphone_use_jquery_mobile';         // スマートフォン画面でjQuery Mobileを使用
167         const SD_HEAD_OTHERS    = 'head_others';                // ヘッダその他タグ
168         const DEFAULT_THEME_DIR = '/ui/themes/';                                // jQueryUIテーマ格納ディレクトリ
169         const THEME_CSS_FILE = 'jquery-ui.custom.css';          // テーマファイル
170         const CONFIG_ICON_FILE = '/images/system/config.png';                   // ウィジェット定義画面アイコン
171         const ADJUST_ICON_FILE = '/images/system/adjust_widget.png';    // 位置調整アイコン
172         const SHARED_ICON_FILE = '/images/system/shared.png';   // グローバル属性
173         const DELETE_ICON_FILE = '/images/system/delete.png';   // ウィジェット削除
174         const CONFIG_ICON32_FILE = '/images/system/config32.png';                       // ウィジェット定義画面アイコン(ツールチップ用)
175         const ADJUST_ICON32_FILE = '/images/system/adjust_widget32.png';        // 位置調整アイコン(ツールチップ用)
176         const CLOSE_BOX_ICON32_FILE = '/images/system/close_box.png';           // ウィンドウ閉じるアイコン(ツールチップ用)
177         const NOTICE_ICON_FILE = '/images/system/notice16.png';         // ウィジェット配置注意アイコン
178         const ALERT_ICON_FILE = '/images/system/alert16.png';           // ウィジェット配置警告アイコン
179 //      const ADMIN_ICON_FILE = '/images/system/admin64.png';           // パネルメニュー管理画面遷移用アイコン
180 //      const LOGOUT_ICON_FILE = '/images/system/logout64.png';         // パネルメニューログアウト用アイコン
181 //      const EDIT_PAGE_ICON_FILE = '/images/system/create_page64.png';         // パネルメニュー編集用アイコン   
182         const ADMIN_ICON_FILE = '/images/system/home32.png';            // パネルメニュー管理画面遷移用アイコン
183         const LOGOUT_ICON_FILE = '/images/system/logout32.png';         // パネルメニューログアウト用アイコン
184         const EDIT_PAGE_ICON_FILE = '/images/system/create_page32.png';         // パネルメニュー編集用アイコン   
185 //      const EDIT_END_ICON_FILE = '/images/system/close32.png';                // パネルメニュー編集終了用アイコン
186         const EDIT_END_ICON_FILE = '/images/system/back32.png';         // パネルメニュー編集終了用アイコン
187         const CLOSE_ICON_FILE = '/images/system/close32.png';           // ウィンドウ閉じるアイコン
188         const PREV_ICON_FILE = '/images/system/prev48.png';             // ウィンドウ「前へ」アイコン
189         const NEXT_ICON_FILE = '/images/system/next48.png';             // ウィンドウ「次へ」アイコン
190         const DEFAULT_READMORE_TITLE = 'もっと読む';                       // もっと読むボタンのデフォルトタイトル
191         const POS_HEAD_NAV_MENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー" data-placement="auto"></i> ';               // 特殊ポジションブロック(ナビゲーションメニュー型)
192         const POS_HEAD_MAIN = '<i class="glyphicon glyphicon-stop" rel="m3help" title="メイン型" data-placement="auto"></i> ';              // 特殊ポジションブロック(メイン型)
193         const WIDGET_MARK_MAIN = '<i class="glyphicon glyphicon-stop" rel="m3help" title="メイン型" data-placement="auto"></i> ';           // ウィジェットの機能マーク(メイン型ウィジェット)
194         const WIDGET_MARK_NAVMENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー" data-placement="auto"></i> ';             // ウィジェットの機能マーク(ナビゲーションメニュー)
195         const WIDGET_FUNCTION_MARK_BOOTSTRAP = ' <span class="label label-warning" rel="m3help" title="Bootstrap型テンプレート対応" data-placement="auto">B</span>';                   // ウィジェット機能マーク(Boostrap型テンプレート
196         const WIDGET_FUNCTION_MARK_WORDPRESS = ' <span class="label label-warning" rel="m3help" title="WordPress型テンプレート対応" data-placement="auto">W</span>';                   // ウィジェット機能マーク(WordPress型テンプレート
197         const WIDGET_STYLE_NAVMENU = '_navmenu';                // ウィジェットの表示スタイル(ナビゲーションメニュー)
198         const WIDGET_STYLE_WORDPRESS = '_wordpress';                                            // ウィジェットの表示スタイル(WordPressテンプレート用出力)
199         const WIDGET_STYLE_WORDPRESS_NOTITLE = '_wordpress_notitle';            // ウィジェットの表示スタイル(WordPressテンプレート(タイトルなし)用出力)
200         
201         // アドオンオブジェクト用
202         const CONTENT_OBJ_ID    = 'contentlib'; // 汎用コンテンツオブジェクトID
203         const BLOG_OBJ_ID               = 'bloglib';            // ブログオブジェクトID
204         const LINKINFO_OBJ_ID   = 'linkinfo';   // リンク情報オブジェクトID
205         
206         // インナーウィジェット用
207         const IWIDTET_CMD_CONTENT = 'content';          // コンテンツ取得
208         const IWIDTET_CMD_INIT = 'init';                        // 初期化
209         const IWIDTET_CMD_UPDATE = 'update';            // 更新
210         const IWIDTET_CMD_CALC = 'calc';                        // 計算
211         
212         // Magic3用スクリプト
213         const M3_ADMIN_SCRIPT_FILENAME                  = 'm3admin2.0.2.js';                            // 管理機能用スクリプト(FCKEditor2.6.6、CKEditor4.0.1対応)
214         const M3_ADMIN_WIDGET_SCRIPT_FILENAME   = 'm3admin_widget2.0.10.js';    // 管理機能(ウィジェット操作)用スクリプト(Magic3 v1.15.0以降)
215         const M3_ADMIN_WIDGET_CSS_FILE                  = '/m3/widget.css';                     // 管理機能(ウィジェット操作)用CSSファイル
216         const M3_STD_SCRIPT_FILENAME                    = 'm3std1.5.2.js';                      // 一般、管理機能共通スクリプト
217         const M3_OPTION_SCRIPT_FILENAME                 = 'm3opt1.2.1.js';                      // AJAXを含んだオプションライブラリファイル(jQuery必須)
218         const M3_ADMIN_CSS_FILE                                 = 'm3/admin.css';                       // 管理機能用のCSS
219         const M3_EDIT_CSS_FILE                                  = 'm3/edit.css';                        // フロント画面編集用のCSS
220         const M3_DEFAULT_CSS_FILE                               = 'm3/default.css';                     // フロント画面共通のデフォルトCSS
221         const M3_CKEDITOR_CSS_FILE                              = 'm3/ckeditor.css';                    // CKEditorの編集エリア用CSS
222         
223         // 読み込み制御
224         const USE_BOOTSTRAP_ADMIN       = false;                        // 管理画面でBootstrapを使用するかどうか(デフォルト値)
225         const BOOTSTRAP_BUTTON_CLASS = 'btn btn-default';
226         
227         // UI
228         const FILEBROWSER_WIDTH_RATIO = '0.8';                  // ファイルブラウザ幅比率
229         const FILEBROWSER_HEIGHT_RATIO = '0.8';                 // ファイルブラウザ高さ比率
230         
231         /**
232          * コンストラクタ
233          */
234         function __construct()
235         {
236                 global $gInstanceManager;
237                 global $gEnvManager;
238                 global $gSystemManager;
239                 global $gRequestManager;
240                                 
241                 // 親クラスを呼び出す
242                 parent::__construct();
243                 
244                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
245                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
246                 
247                 // システムDBオブジェクト取得
248                 $this->db = $gInstanceManager->getSytemDbObject();
249                 
250                 // 運用方法
251                 $value = $gSystemManager->getSystemConfig(self::CF_ACCESS_IN_INTRANET);         // イントラネット運用かどうか
252                 if (empty($value)){             // インターネット運用
253                         $this->useGooglemaps = true;                            // Googleマップを使用するかどうか
254                 }
255                 $this->useHelp = true;          // ヘルプ機能
256                 
257                 // デフォルトのWYSIWYGエディターを取得
258                 $this->wysiwygEditor = $gSystemManager->getSystemConfig(self::CF_WYSIWYG_EDITOR);                               // 管理画面用WYSIWYGエディター
259                 
260                 // ##### Javascriptライブラリのバージョン設定 #####
261                 // jQueryバージョン設定
262                 // アクセスする画面に応じてjQueryのバージョンを設定
263                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
264                         $value = $gSystemManager->getSystemConfig(self::CF_ADMIN_JQUERY_VERSION);// 管理画面用jQueryバージョン
265                         
266                         // 管理画面にBOOTSTRAPを使用するかどうか(初期値)
267                         $this->useBootstrap = self::USE_BOOTSTRAP_ADMIN;
268                         
269                         // CKEditorのバージョン設定
270                         // 小画面デバイス最適化の場合は最新バージョンを使用
271                         if ($gEnvManager->isSmallDeviceAdmin()) ScriptLibInfo::setCkeditorVer(1/*最新*/);
272                 } else {
273                         $value = $gSystemManager->getSystemConfig(self::CF_JQUERY_VERSION);// jQueryバージョン
274                 }
275                 ScriptLibInfo::setJQueryVer($value);
276                 
277                 // WYSISIGエディターのタイプを設定。ScriptLibInfo::getLib()を実行する前に設定。
278                 ScriptLibInfo::setWysiwygEditorType($this->wysiwygEditor);
279                 
280                 // Javascriptライブラリ
281                 $this->libFiles = ScriptLibInfo::getLib();                      // ライブラリ取得
282                 
283                 // jQueryファイル名取得
284                 $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(0);                    // 使用対象のjQueryファイル
285                 $this->selectedJQueryUiFilename = ScriptLibInfo::getJQueryFilename(1);          // 使用対象のjQuery UIファイル
286
287                 // ##### フロント画面用のデフォルトのJavascript、CSSを取得 #####
288                 $this->defaultScriptFiles       =       array(
289                                                                                         $this->selectedJQueryFilename,                  // jQuery
290                                                                                         self::M3_STD_SCRIPT_FILENAME
291                                                                                 );
292                 $this->defaultCssFiles          =       array(
293                                                                                         self::M3_DEFAULT_CSS_FILE                               // フロント画面共通のデフォルトCSS
294                                                                                 );
295                 
296                 // ##### 管理機能用のデフォルトのJavascript、CSSを取得 #####
297                 if (defined('M3_STATE_IN_INSTALL')){            // インストーラの場合のスクリプト
298                         $this->defaultAdminScriptFiles  =       array(
299                                                                                                         $this->selectedJQueryFilename,                  // jQuery
300                                                                                                 //      self::M3_STD_SCRIPT_FILENAME,
301                                                                                                         self::M3_ADMIN_SCRIPT_FILENAME
302                                                                                                 );
303                         $this->defaultAdminCssFiles             =       array();        // 管理機能用のCSS
304                 } else {
305                         $this->defaultAdminScriptFiles  =       array(
306                                                                                                         $this->selectedJQueryFilename,                  // jQuery
307                                                                                                         $this->selectedJQueryUiFilename,                                // jQuery UI Core
308                                                                                                         ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME,             // jQuery Contextmenu Lib
309                                                                                                         self::M3_STD_SCRIPT_FILENAME,
310                                                                                                         self::M3_ADMIN_SCRIPT_FILENAME,
311                                                                                                         self::M3_OPTION_SCRIPT_FILENAME
312                                                                                                 );
313                         $this->defaultAdminCssFiles             =       array(
314                                                                                                         self::M3_ADMIN_CSS_FILE                 // 管理機能用のCSS
315                                                                                                 );
316                         
317                         // Javascriptライブラリ
318                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);     // 管理パネル用
319                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_EASING);            // 管理パネル用
320                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_NUMERIC);           // 入力制限プラグイン
321 //                      $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_RESPONSIVETABLE);// 管理画面作成用
322                 }
323                 
324                 // 管理権限なしで管理ディレクトリアクセスで読み込むスクリプトファイル
325                 $this->defaultAdminDirScriptFiles = array($this->selectedJQueryFilename);                       // jQuery
326                 
327                 // 遅延ウィジェットリスト                                                                    
328                 $this->lateLaunchWidgetList = array();
329                 $this->latelaunchWidgetParam = array();
330                 
331                 // DB接続可能なときは設定値を取得
332                 if ($gEnvManager->canUseDb()){
333                         $value = $this->gSystem->getSystemConfig('script_cache_in_browser');    // ブラウザにJavaScriptファイルのキャッシュを保持するかどうか
334                         if ($value != '') $this->hasScriptCache = $value;
335                 }
336                 
337                 $this->rssVersion = self::DEFAULT_RSS_VERSION;                                  // RSSバージョン
338                 
339                 // フロント画面で使用する主要コンテンツタイプ
340                 $this->mainContentTypeInfo       = array(
341                                                                                                 array(  'name' => '会員情報',                                       'value' => M3_VIEW_TYPE_MEMBER),
342                                                                                                 array(  'name' => '汎用コンテンツ',                              'value' => M3_VIEW_TYPE_CONTENT),
343                                                                                                 array(  'name' => '製品',                                             'value' => M3_VIEW_TYPE_PRODUCT),
344                                                                                                 array(  'name' => 'BBS',                                                'value' => M3_VIEW_TYPE_BBS),
345                                                                                                 array(  'name' => 'ブログ',                                          'value' => M3_VIEW_TYPE_BLOG),
346                                                                                                 array(  'name' => 'Wiki',                                               'value' => M3_VIEW_TYPE_WIKI),
347                                                                                                 array(  'name' => 'ユーザ作成コンテンツ',             'value' => M3_VIEW_TYPE_USER),
348                                                                                                 array(  'name' => 'イベント情報',                         'value' => M3_VIEW_TYPE_EVENT),
349                                                                                                 array(  'name' => 'フォトギャラリー',                   'value' => M3_VIEW_TYPE_PHOTO)
350                                                                                         );
351                 // フロント画面で使用する補助コンテンツタイプ(ページ属性に対応しない)
352                 $this->subContentTypeInfo        = array(       array(  'name' => '新着情報',                                       'value' => M3_VIEW_TYPE_NEWS),
353                                                                                                 array(  'name' => 'コメント',                                       'value' => M3_VIEW_TYPE_COMMENT),
354                                                                                                 array(  'name' => 'イベント予約',                         'value' => M3_VIEW_TYPE_EVENTENTRY),
355                                                                                                 array(  'name' => 'バナー',                                          'value' => M3_VIEW_TYPE_BANNER)
356                                                                                         );
357                 // フロント画面で使用する主要機能タイプ(「ダッシュボード」は含まない)
358                 $this->mainFeatureTypeInfo       = array(       array(  'name' => '検索',                                             'value' => M3_VIEW_TYPE_SEARCH),
359                                                                                                 array(  'name' => 'Eコマース',                                      'value' => M3_VIEW_TYPE_COMMERCE),
360                                                                                                 array(  'name' => 'カレンダー',                                    'value' => M3_VIEW_TYPE_CALENDAR)
361                                                                                         );
362                 // 管理画面専用で使用する機能タイプ
363                 $this->adminFeatureTypeInfo      = array(       array(  'name' => 'ダッシュボード',                              'value' => M3_VIEW_TYPE_DASHBOARD)
364                                                                                         );
365                                                                                         
366                 // URLパラメータ並び順
367                 $this->urlParamOrder = array(
368                         // コンテンツID
369                         M3_REQUEST_PARAM_CONTENT_ID                             => -20,         // 汎用コンテンツID
370                         M3_REQUEST_PARAM_CONTENT_ID_SHORT               => -19,         // 汎用コンテンツID(略式)
371                         M3_REQUEST_PARAM_PRODUCT_ID                             => -18,         // 製品ID
372                         M3_REQUEST_PARAM_PRODUCT_ID_SHORT               => -17,         // 製品ID(略式)
373                         M3_REQUEST_PARAM_BLOG_ID                                => -16,         // ブログID
374                         M3_REQUEST_PARAM_BLOG_ID_SHORT                  => -15,         // ブログID(略式)
375                         M3_REQUEST_PARAM_BLOG_ENTRY_ID                  => -14,         // ブログ記事ID
376                         M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT    => -13,         // ブログ記事ID(略式)
377                         M3_REQUEST_PARAM_BBS_ID                                 => -12,         // 掲示板投稿記事ID
378                         M3_REQUEST_PARAM_BBS_ID_SHORT                   => -11,         // 掲示板投稿記事ID(略式)
379                         M3_REQUEST_PARAM_BBS_THREAD_ID                  => -10,         // 掲示板投稿スレッドID
380                         M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT    => -9,          // 掲示板投稿スレッドID(略式)
381                         M3_REQUEST_PARAM_USER_ID                                => -8,          // ユーザ作成コンテンツID
382                         M3_REQUEST_PARAM_USER_ID_SHORT                  => -7,          // ユーザ作成コンテンツID(略式)
383                         M3_REQUEST_PARAM_ROOM_ID                                => -6,          // ユーザ作成コンテンツ区画ID
384                         M3_REQUEST_PARAM_ROOM_ID_SHORT                  => -5,          // ユーザ作成コンテンツ区画ID(略式)
385                         M3_REQUEST_PARAM_EVENT_ID                               => -4,          // イベントID
386                         M3_REQUEST_PARAM_EVENT_ID_SHORT                 => -3,          // イベントID(略式)
387                         M3_REQUEST_PARAM_PHOTO_ID                               => -2,          // 画像ID
388                         M3_REQUEST_PARAM_PHOTO_ID_SHORT                 => -1,          // 画像ID(略式)
389                         // URLパラメータ
390                         M3_REQUEST_PARAM_PAGE_SUB_ID                    => 1,           // ページサブID
391                         M3_REQUEST_PARAM_PAGE_CONTENT_ID                => 2,           // ページコンテンツID
392                         M3_REQUEST_PARAM_WIDGET_ID                              => 3,           // ウィジェットID
393                         M3_REQUEST_PARAM_TEMPLATE_ID                    => 4,           // テンプレートID
394                         M3_REQUEST_PARAM_URL                                    => 5,           // リンク先等のURL
395                         M3_REQUEST_PARAM_STAMP                                  => 6,           // 公開発行ID
396                         M3_REQUEST_PARAM_OPTION                                 => 7,           // 通信オプション
397                         M3_REQUEST_PARAM_OPERATION_COMMAND              => 8,           // 実行処理
398                         M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND => 9,           // Wikiコマンド実行
399                         M3_REQUEST_PARAM_OPERATION_TASK                 => 10,          // ウィジェット間共通処理
400                         M3_REQUEST_PARAM_OPERATION_ACT                  => 11,          // クライアントからの実行処理
401                         M3_REQUEST_PARAM_OPERATION_LANG                 => 12,          // 言語指定表示
402                         M3_REQUEST_PARAM_SERIAL_NO                              => 13,          // シリアル番号
403                         M3_REQUEST_PARAM_PAGE_NO                        => 14,          // ページ番号
404                         M3_REQUEST_PARAM_LIST_NO                                => 15,          // 一覧番号
405                         M3_REQUEST_PARAM_ITEM_NO                        => 16,          // 項目番号
406                         M3_REQUEST_PARAM_OPERATION_TODO                 => 17,          // 指定ウィジェットに実行させる処理
407                         M3_REQUEST_PARAM_FROM                                   => 18,          // メッセージの送信元ウィジェットID
408                         M3_REQUEST_PARAM_VIEW_STYLE                             => 19,          // 表示スタイル
409                         M3_REQUEST_PARAM_FORWARD                                => 20,          // 画面遷移用パラメータ
410                         M3_REQUEST_PARAM_OPEN_BY                                => 22,          // ウィンドウの開き方
411                         M3_REQUEST_PARAM_SHOW_HEADER                    => 23,          // ヘッダ部表示制御
412                         M3_REQUEST_PARAM_SHOW_FOOTER                    => 24,          // フッタ部表示制御
413                         M3_REQUEST_PARAM_SHOW_MENU                              => 25,          // メニュー部表示制御
414                         M3_REQUEST_PARAM_KEYWORD                                => 26,          // 検索キーワード
415                         M3_REQUEST_PARAM_HISTORY                                => 27,          // 履歴インデックスNo
416                         M3_REQUEST_PARAM_DEF_PAGE_ID                    => 28,          // ページID(画面編集用)
417                         M3_REQUEST_PARAM_DEF_PAGE_SUB_ID                => 29,          // ページサブID(画面編集用)
418                         M3_REQUEST_PARAM_PAGE_DEF_SERIAL                => 30,          // ページ定義のレコードシリアル番号(設定画面起動時)
419                         M3_REQUEST_PARAM_PAGE_DEF_CONFIG_ID             => 31,          // ページ定義のウィジェット定義ID(設定画面起動時)
420                         M3_REQUEST_PARAM_BACK_URL                               => 32,          // 戻り先URL
421                         M3_REQUEST_PARAM_BACKUP_URL                             => 33,          // URL退避用(画面編集時)
422                         M3_REQUEST_PARAM_SERVER                                 => 34,          // サーバ指定
423                         M3_REQUEST_PARAM_CATEGORY_ID                    => 35,          // カテゴリID(共通)
424                         M3_REQUEST_PARAM_WIDTH                                  => 36,          // 幅
425                         M3_REQUEST_PARAM_HEIGHT                                 => 37);         // 高さ
426         }
427         /**
428          * メインコンテンツタイプを取得
429          *
430          * @return array        コンテンツタイプ
431          */
432         public function _getAllContentType()
433         {
434                 global $M3_ALL_CONTENT_TYPE;
435                 
436 /*              $contentType = array(   M3_VIEW_TYPE_CONTENT,                           // 汎用コンテンツ
437                                                                 M3_VIEW_TYPE_PRODUCT,                           // 製品
438                                                                 M3_VIEW_TYPE_BBS,                                       // BBS
439                                                                 M3_VIEW_TYPE_BLOG,                              // ブログ
440                                                                 M3_VIEW_TYPE_WIKI,                              // wiki
441                                                                 M3_VIEW_TYPE_USER,                              // ユーザ作成コンテンツ
442                                                                 M3_VIEW_TYPE_EVENT,                             // イベント
443                                                                 M3_VIEW_TYPE_PHOTO);                            // フォトギャラリー
444                 return $contentType;*/
445                 return $M3_ALL_CONTENT_TYPE;
446         }
447         /**
448          * 機能タイプを取得
449          *
450          * @return array        機能タイプ
451          */
452         public function _getAllFeatureType()
453         {
454                 global $M3_ALL_FEATURE_TYPE;
455                 
456 /*              $featureType = array(   M3_VIEW_TYPE_DASHBOARD,                 // ダッシュボード
457                                                                 M3_VIEW_TYPE_SEARCH,                    // 検索結果
458                                                                 M3_VIEW_TYPE_COMMERCE);                 // Eコマース
459                 return $featureType;*/
460                 return $M3_ALL_FEATURE_TYPE;
461         }
462         /**
463          * タイムアウトを停止
464          *
465          * @return なし
466          */
467         function setNoTimeout()
468         {
469                 if (ini_get('safe_mode') == '0') set_time_limit(0);
470         }
471         /**
472          * ポップアップメッセージを設定
473          *
474          * @param string $msg   メッセージ
475          */
476         function setPopupMsg($msg)
477         {
478                 $this->popupMsg = $msg;
479         }
480         /**
481          * HTMLヘッダ「description」に出力する文字列を設定
482          *
483          * @param string $str   出力文字列
484          */
485         function setHeadDescription($str)
486         {
487                 if (is_string($str) && !empty($str)){
488                         $this->headDescription = $str;
489                         $this->lastHeadDescription = $str;      // 最後に設定した値を退避
490                 }
491         }
492         /**
493          * HTMLヘッダ「description」に出力する文字列を取得
494          *
495          * @return string $str   出力文字列
496          */
497         function getHeadDescription()
498         {
499                 return $this->headDescription;
500         }
501         /**
502          * HTMLヘッダ「keywords」に出力する文字列を設定
503          *
504          * @param string $str   出力文字列
505          */
506         function setHeadKeywords($str)
507         {
508                 if (is_string($str) && !empty($str)){
509                         $this->headKeywords = $str;
510                         $this->lastHeadKeywords = $str;         // 最後に設定した値を退避
511                 }
512         }
513         /**
514          * HTMLヘッダ「keywords」に出力する文字列を取得
515          *
516          * @return string $str   出力文字列
517          */
518         function getHeadKeywords()
519         {
520                 return $this->headKeywords;
521         }
522         /**
523          * HTMLヘッダに出力するタグ文字列を設定
524          *
525          * @param string $str   出力文字列
526          * @return なし
527          */
528         function setHeadOthers($str)
529         {
530                 if (is_string($str) && !empty($str)){
531                         $this->headOthers = $str;
532                 }
533         }
534         /**
535          * HTMLヘッダに出力するタグ文字列を追加
536          *
537          * @param string $str   出力文字列
538          * @return なし
539          */
540         function addHeadOthers($str)
541         {
542                 if (is_string($str) && !empty($str)){
543                         // 追加されていない場合のみ追加
544                         $pos = strpos($this->headOthers, $str);
545                         if ($pos === false) $this->headOthers .= $str;
546                 }
547         }
548         /**
549          * HTMLヘッダに出力するタグ文字列を追加(管理画面用)
550          *
551          * @param string $str   出力文字列
552          * @return なし
553          */
554         function addAdminHeadOthers($str)
555         {
556                 if (is_string($str) && !empty($str)){
557                         // 追加されていない場合のみ追加
558                         $pos = strpos($this->adminHeadOthers, $str);
559                         if ($pos === false) $this->adminHeadOthers .= $str;
560                 }
561         }
562         /**
563          * HTMLヘッダ「title」のサブタイトル出力する文字列を設定
564          *
565          * @param string $str           出力文字列
566          * @param string $url           リンク先
567          * @param bool $isDefault       デフォルト値かどうか
568          * @return                                      なし
569          */
570         function setHeadSubTitle($str = '', $url = '', $isDefault = false)
571         {
572                 // ##### ページのサブタイトルはデフォルトでページのMETAタイトルを使用し、メインウィジェット側で上書きする #####
573                 
574                 static $isUpdated = false;                      // デフォルト値が更新されているかどうか
575                 
576                 if (!is_string($str) || empty($str)) return;
577                 
578                 // デフォルト値の場合はデータを初期化
579                 if ($isDefault){
580                         $this->headSubTitle = array();
581                         $this->headSubTitleUrl = array();
582                         $this->lastHeadTitle = '';
583                         $isUpdated = false;
584                 } else {                        // デフォルトでない場合はデータを追加
585                         if (!$isUpdated){                       // デフォルト値が更新されていない場合は以前のデータを削除
586                                 $this->headSubTitle = array();
587                                 $this->headSubTitleUrl = array();
588                                 $this->lastHeadTitle = '';
589                                 $isUpdated = true;                      // デフォルト値は更新された
590                         }
591                 }
592                 // タイトル追加
593                 $this->headSubTitle[] = $str;
594                 $this->headSubTitleUrl[] = $url;
595                 $this->lastHeadTitle = $str;    // 最後に設定した値を退避
596         }
597         /**
598          * HTMLヘッダ「title」のサブタイトル出力する文字列を取得
599          *
600          * @return $array   サブタイトルに設定されている文字列を連想配列(title=タイトル、url=リンク先URL)の配列で返す
601          */
602         function getHeadSubTitle()
603         {
604                 $titleArray = array();
605                 $titleCount = count($this->headSubTitle);
606                 for ($i = 0; $i < $titleCount; $i++){
607                         $line = array('title' => $this->headSubTitle[$i], 'url' => $this->headSubTitleUrl[$i]);
608                         $titleArray[] = $line;
609                 }
610                 return $titleArray;
611         }
612         /**
613          * HTMLヘッダに出力するCSSの文字列を設定
614          *
615          * @param string $css   追加するCSS内容
616          * @return                              なし
617          */
618         function addHeadCss($css)
619         {
620                 $destCss = trim($css);
621                 if (!empty($destCss)){
622                         //if (!in_array($css, $this->headCss)) $this->headCss[] = $css;
623                         if (!in_array($css, $this->exportCss)) $this->exportCss[] = $css;               // CSS動的外部出力
624                         
625                         $this->lastHeadCss = $css;                      // 最後に設定したHTMLヘッダにCSS出力する文字列
626                 }
627         }
628         /**
629          * 外部出力で出力するCSSの文字列を設定(ウィジェット共通設定からの設定値)
630          *
631          * @param string $css   追加するCSS内容
632          * @return                              なし
633          */
634         function addExportCss($css)
635         {
636                 $destCss = trim($css);
637                 if (!empty($destCss)){
638                         if (!in_array($css, $this->exportCss)) $this->exportCss[] = $css;
639                 }
640         }
641         /**
642          * HTMLヘッダに出力するJavascriptの文字列を設定
643          *
644          * @param string $script        追加するJavascript内容
645          * @return                                      なし
646          */
647         function addHeadScript($script)
648         {
649                 $destScript = trim($script);
650                 if (!empty($destScript)){
651                         if (!in_array($script, $this->headScript)) $this->headScript[] = $script;
652                         
653                         $this->lastHeadScript = $script;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
654                 }
655         }
656         /**
657          * HTMLヘッダに出力するJavascriptの文字列(jQueryMobile用挿入スクリプト)を設定
658          *
659          * @param string $script        追加するJavascript内容
660          * @return                                      なし
661          */
662         function addHeadPreMobileScript($script)
663         {
664                 $destScript = trim($script);
665                 if (!empty($destScript)){
666                         if (!in_array($script, $this->headPreMobileScript)) $this->headPreMobileScript[] = $script;
667                 }
668         }
669         /**
670          * HTMLヘッダに出力する任意文字列を設定
671          *
672          * @param string $str   追加する任意文字列
673          * @return                              なし
674          */
675         function addHeadString($str)
676         {
677                 $destScript = trim($str);
678                 if (!empty($destScript)){
679                         if (!in_array($str, $this->headString)) $this->headString[] = $str;
680                         
681                         $this->lastHeadString = $str;                   // 最後に設定したHTMLヘッダに出力する任意文字列
682                 }
683         }
684         /**
685          * HTMLヘッダに出力するCSSファイルを追加
686          *
687          * @param string,array $cssFile CSSファイルURLパス
688          * @return                              なし
689          */
690         function addHeadCssFile($cssFile)
691         {
692                 if (is_array($cssFile)){        // 配列の場合
693                         for ($i = 0; $i < count($cssFile); $i++){
694                                 $destCss = trim($cssFile[$i]);
695                                 if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
696                         }
697                 } else {                // 文字列の場合
698                         $destCss = trim($cssFile);
699                         if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
700                 }
701         }
702         /**
703          * HTMLヘッダに出力するJavascriptライブラリを追加
704          *
705          * @param string,array $scriptLib       JavascriptライブラリID
706          * @return                                      なし
707          */
708         function addHeadAdminScriptLib($scriptLib)
709         {
710                 if (is_array($scriptLib)){      // 配列の場合
711                         for ($i = 0; $i < count($scriptLib); $i++){
712                                 $destScript = trim($scriptLib[$i]);
713                                 if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
714                         }
715                 } else {                // 文字列の場合
716                         $destScript = trim($scriptLib);
717                         if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
718                 }
719         }
720         /**
721          * HTMLヘッダに出力するJavascriptライブラリを追加
722          *
723          * @param string,array $scriptLib       JavascriptライブラリID
724          * @return                                      なし
725          */
726         function addHeadScriptLib($scriptLib)
727         {
728                 if (is_array($scriptLib)){      // 配列の場合
729                         for ($i = 0; $i < count($scriptLib); $i++){
730                                 $destScript = trim($scriptLib[$i]);
731                                 if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
732                         }
733                 } else {                // 文字列の場合
734                         $destScript = trim($scriptLib);
735                         if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
736                 }
737         }
738         /**
739          * HTMLヘッダに出力するJavascriptファイルを追加
740          *
741          * @param string,array $scriptFile      JavascriptファイルURLパス
742          * @return                                      なし
743          */
744         function addHeadScriptFile($scriptFile)
745         {
746                 if (is_array($scriptFile)){     // 配列の場合
747                         for ($i = 0; $i < count($scriptFile); $i++){
748                                 $destScript = trim($scriptFile[$i]);
749                                 if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
750                         }
751                 } else {                // 文字列の場合
752                         $destScript = trim($scriptFile);
753                         if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
754                 }
755         }
756         /**
757          * HTMLヘッダに出力するJavascriptファイル(jQueryMobile用挿入ファイル)を追加
758          *
759          * @param string,array $scriptFile      JavascriptファイルURLパス
760          * @return                                      なし
761          */
762         function addHeadPreMobileScriptFile($scriptFile)
763         {
764                 if (is_array($scriptFile)){     // 配列の場合
765                         for ($i = 0; $i < count($scriptFile); $i++){
766                                 $destScript = trim($scriptFile[$i]);
767                                 if (!empty($destScript) && !in_array($destScript, $this->headPreMobileScriptFiles)) $this->headPreMobileScriptFiles[] = $destScript;
768                         }
769                 } else {                // 文字列の場合
770                         $destScript = trim($scriptFile);
771                         if (!empty($destScript) && !in_array($destScript, $this->headPreMobileScriptFiles)) $this->headPreMobileScriptFiles[] = $destScript;
772                 }
773         }
774         /**
775          * HTMLヘッダに出力するRSSファイルを追加
776          *
777          * @param array $rssFile        タイトル(title)、配信用URL(href)の連想配列。複数の場合は連想配列の配列。
778          * @return                                      なし
779          */
780         function addHeadRssFile($rssFile)
781         {
782                 // パラメータエラーチェック
783                 if (!is_array($rssFile)) return;
784                 
785                 $line = $rssFile[0];
786                 if (is_array($line)){   // 複数追加の場合
787                         for ($i = 0; $i < count($line); $i++){
788                                 // すでに追加済みかどうかチェック
789                                 $url = trim($line[$i]['href']);
790                                 if (!empty($url)){
791                                         for ($j = 0; $j < count($this->headRssFiles); $j++){
792                                                 $storedUrl = $this->headRssFiles[$j]['href'];
793                                                 if ($url == $storedUrl) break;
794                                         }
795                                         if ($j == count($this->headRssFiles)){          // 見つからないときは追加
796                                                 $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
797                                                                                                                 'title' => $line[$i]['title']);         // タイトル
798                                         }
799                                 }
800                         }
801                 } else {                // 単数追加のとき
802                         // すでに追加済みかどうかチェック
803                         $url = trim($rssFile['href']);
804                         if (!empty($url)){
805                                 for ($i = 0; $i < count($this->headRssFiles); $i++){
806                                         $storedUrl = $this->headRssFiles[$i]['href'];
807                                         if ($url == $storedUrl) break;
808                                 }
809                                 if ($i == count($this->headRssFiles)){          // 見つからないときは追加
810                                         $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
811                                                                                                         'title' => $rssFile['title']);          // タイトル
812                                 }
813                         }
814                 }
815         }
816         /**
817          * HTMLヘッダに最初に出力するタグ文字列を設定
818          *
819          * @param string $str   追加するタグ文字列
820          * @return                              なし
821          */
822         function setHeadFirstTag($str)
823         {
824                 if (!empty($str)) $this->headFirstTag = $str;
825         }
826         /**
827          * ヘッダ部に出力するカノニカル属性URLを設定
828          *
829          * @param string $url           URL
830          * @return                                      なし
831          */
832         function setCanonicalUrl($url)
833         {
834                 if (!empty($url)) $this->headCanonicalUrl = $url;                               // カノニカル属性URL
835         }
836         /**
837          * RSSチャンネル部に出力するデータを設定
838          *
839          * @param array $rssData        RSSチャンネル部データ
840          * @return                                      なし
841          */
842         function setRssChannel($rssData)
843         {
844                 if (!empty($rssData)) $this->rssChannel = $rssData;                             // RSSチャンネルデータ
845         }
846         /**
847          * 表示ポジションを表示するかどうか
848          *
849          * @param int $mode   0=ポジション表示しない(通常画面)、1=ポジション表示、2=ウィジェット込みポジション表示
850          */
851         function showPosition($mode)
852         {
853                 $this->showPositionMode = $mode;
854         }
855         /**
856          * 画面レイアウト中かどうか
857          *
858          * @return bool         true=レイアウト中、false=レイアウト中でない
859          */
860         function isLayout()
861         {
862                 return $this->isLayout;                         // 画面レイアウト中かどうか
863         }
864         /**
865          * ウィジェットの単体表示を設定
866          */
867         function showWidget()
868         {
869                 $this->showWidget = true;
870         }
871         /**
872          * ウィジェットの単体表示を取得
873          *
874          * @param bool          true=単体表示、false=単体表示でない
875          */
876         function getShowWidget()
877         {
878                 return $this->showWidget;
879         }
880         /**
881          * システム制御遷移モードを設定
882          *
883          * @param int $mode   0=設定なし、1=ログイン画面、10=サイト非公開、11=アクセス不可、12=存在しないページ
884          */
885         function setSystemHandleMode($mode)
886         {
887                 $this->systemHandleMode = $mode;
888         }
889         /**
890          * システム制御遷移モード取得
891          */
892         function getSystemHandleMode()
893         {
894                 return $this->systemHandleMode;
895         }
896         /**
897          * フロント画面編集モードを設定
898          *
899          * @return                              なし
900          */
901         function setEditMode()
902         {
903                 $this->isEditMode = true;
904         }
905         /**
906          * フロント画面編集モードを取得
907          *
908          * @return bool         true=編集モードオン、false=編集モードオフ
909          */
910         function isEditMode()
911         {
912                 return $this->isEditMode;
913         }
914         /**
915          * 機能アクセスパーソナルモードを設定
916          *
917          * @return                              なし
918          */
919         function setPersonalMode()
920         {
921                 $this->isPersonalMode = true;
922         }
923         /**
924          * 機能アクセスパーソナルモードを取得
925          *
926          * @return bool         true=パーソナルモードオン、false=パーソナルモードオフ
927          */
928         function isPersonalMode()
929         {
930                 return $this->isPersonalMode;
931         }
932         /**
933          * 出力フォーマットがHTMLであるかを設定
934          *
935          * @param bool $isHtml  HTMLフォーマットかどうか
936          * @return                              なし
937          */
938         function setOutputByHtml($isHtml)
939         {
940                 $this->outputByHtml = $isHtml;
941         }
942         
943         /**
944          * AJAX用のレスポンスボディデータかどうかを設定
945          *
946          * @param bool $isResponseBody  レスポンスボディデータかどうか
947          * @return                                              なし
948          */     
949         function setOutputAjaxResponseBody($isResponseBody)
950         {
951                 $this->outputAjaxResponseBody = $isResponseBody;
952         }
953         /**
954          * ヘルプ機能の使用可否を設定
955          *
956          * @param bool $status  ヘルプ機能を使用するかどうか
957          * @return                              なし
958          */
959         function setUseHelp($status)
960         {
961                 $this->useHelp = $status;
962         }
963         /**
964          * ヘルプ機能の使用可否を取得
965          *
966          * @return bool ヘルプ機能を使用するかどうか
967          */
968         function getUseHelp()
969         {
970                 return $this->useHelp;
971         }
972         /**
973          * 表示するコンテンツにGoogleマップが含まれているかを設定
974          *
975          * @param bool $status  Googleマップを含むかどうか
976          * @return                              なし
977          */
978         function setIsContentGooglemaps($status)
979         {
980                 $this->isContentGooglemaps = $status;           // コンテンツにGoogleマップが含むかどうか
981         }
982         /**
983          * 表示するコンテンツにGoogleマップが含まれているかを取得
984          *
985          * @return bool ヘルプ機能を使用するかどうか
986          */
987         function isContentGooglemaps()
988         {
989                 return $this->isContentGooglemaps;
990         }
991         /**
992          * JavaScriptのブラウザキャッシュの使用可否を設定
993          *
994          * @param bool $status  ブラウザキャッシュを使用するかどうか
995          * @return                              なし
996          */
997         function setHasScriptCache($status)
998         {
999                 $this->hasScriptCache = $status;
1000         }
1001         /**
1002          * Bootstrapを使用に設定
1003          *
1004          * @return                              なし
1005          */
1006         function useBootstrap()
1007         {
1008                 $this->useBootstrap = true;                             // Bootstrapを使用するかどうか
1009         }
1010         /**
1011          * Bootstrapを強制的に未使用に設定
1012          *
1013          * @return                              なし
1014          */
1015         function cancelBootstrap()
1016         {
1017                 $this->useBootstrap = false;                            // Bootstrapを使用するかどうか
1018         }
1019         /**
1020          * Bootstrap使用状況を取得
1021          *
1022          * @return bool                 true=使用、false=使用しない
1023          */
1024         function getUseBootstrap()
1025         {
1026                 return $this->useBootstrap;                             // Bootstrapを使用するかどうか
1027         }
1028         /**
1029          * HTML5を使用に設定
1030          *
1031          * @return                              なし
1032          */
1033         function setHtml5()
1034         {
1035                 $this->isHtml5 = true;                                  // HTML5で出力するかどうか
1036         }
1037         /**
1038          * ページ作成処理を中断するかどうかを取得
1039          *
1040          * @return bool         true=中断、false=継続
1041          */
1042         function isPageAbort()
1043         {
1044                 return $this->isAbort;
1045         }
1046         /**
1047          * 現在のウィジェットのポジションを取得
1048          *
1049          * @param string $pos           ポジション
1050          * @param int    $index         インデックス番号
1051          * @return                      なし
1052          */
1053         function getCurrentWidgetPosition(&$pos, &$index)
1054         {
1055                 $pos = $this->currentWidgetPosition;                    // 現在のウィジェットのポジション
1056                 $index = $this->currentWidgetIndex;                     // 現在のウィジェットのポジション番号
1057         }
1058         /**
1059          * 親ウィンドウを再描画
1060          *
1061          * @param int $defSerial        ページ定義シリアル番号
1062          * @return                                      なし
1063          */
1064         function updateParentWindow($defSerial = 0)
1065         {
1066                 $this->updateParentWindow = true;
1067                 $this->updateDefSerial = $defSerial;                    // 更新する項目のページ定義シリアル番号
1068         }
1069         /**
1070          * CSSファイルの追加
1071          *
1072          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1073          * @return                              なし
1074          */
1075         function addCssFile($path)
1076         {
1077                 $destPath = trim($path, '/');
1078                 if (!in_array($destPath, $this->defaultCssFiles)) $this->defaultCssFiles[] = $destPath;
1079         }
1080         /**
1081          * CSSファイルの追加
1082          *
1083          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
1084          * @return                              なし
1085          */
1086         function addAdminCssFile($path)
1087         {
1088                 $destPath = trim($path, '/');
1089                 if (!in_array($destPath, $this->defaultAdminCssFiles)) $this->defaultAdminCssFiles[] = $destPath;
1090         }
1091         /**
1092          * 編集エリア用のCSSファイルの追加
1093          *
1094          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
1095          * @return                              なし
1096          */
1097         function addCkeditorCssFile($path)
1098         {
1099                 $destPath = trim($path, '/');
1100                 if (!in_array($destPath, $this->ckeditorCssFiles)) $this->ckeditorCssFiles[] = $destPath;
1101         }
1102         /**
1103          * JavaScriptファイルの追加
1104          *
1105          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1106          * @return                              なし
1107          */
1108         function addScriptFile($path)
1109         {
1110                 $destPath = trim($path, '/');
1111                 if (!empty($destPath) && !in_array($destPath, $this->defaultScriptFiles)) $this->defaultScriptFiles[] = $destPath;
1112         }
1113         /**
1114          * JavaScriptファイルの追加
1115          *
1116          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1117          * @return                              なし
1118          */
1119         function addAdminScriptFile($path)
1120         {
1121                 $destPath = trim($path, '/');
1122                 if (!in_array($destPath, $this->defaultAdminScriptFiles)) $this->defaultAdminScriptFiles[] = $destPath;
1123         }
1124         /**
1125          * 追加設定するテンプレートIDを返す
1126          *
1127          * @return array                                                テンプレートID,サブテンプレートIDの配列
1128          */
1129         function getOptionTemplateId()
1130         {
1131                 global $gEnvManager;
1132                 
1133                 // ページ情報取得
1134                 $pageId = $gEnvManager->getCurrentPageId();
1135
1136                 switch ($this->contentType){
1137                         case M3_VIEW_TYPE_CONTENT:              // ページのコンテンツタイプ                         
1138                                 // コンテンツ単位のテンプレート設定
1139                                 $contentLibObj = $this->gInstance->getObject(self::CONTENT_OBJ_ID);
1140                                 if (isset($contentLibObj)) list($this->optionTemplateId, $this->optionSubTemplateId) = $contentLibObj->getOptionTemplate();
1141                                 break;
1142                         case M3_VIEW_TYPE_BLOG:         // ページがブログタイプのとき
1143                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // PCサイトのとき
1144                                         // ブログライブラリオブジェクトからテンプレートを取得
1145                                         $blogLibObj = $this->gInstance->getObject(self::BLOG_OBJ_ID);
1146                                         if (isset($blogLibObj)) list($this->optionTemplateId, $this->optionSubTemplateId) = $blogLibObj->getOptionTemplate();
1147                                 }
1148                                 break;
1149                 }
1150                 return array($this->optionTemplateId, $this->optionSubTemplateId);
1151         }
1152         /**
1153          * 使用した非共通ウィジェットの数を取得
1154          *
1155          * @return int                          ウィジェット数
1156          */
1157         function getNonSharedWidgetCount()
1158         {
1159                 return $this->nonSharedWidgetCount;
1160         }
1161         /**
1162          * ページのコンテンツタイプを取得
1163          *
1164          * @return string                       コンテンツタイプ
1165          */
1166         function getContentType()
1167         {
1168                 return $this->contentType;
1169         }
1170         /**
1171          * フロント画面で使用する主要コンテンツタイプの情報取得
1172          *
1173          * @return array                        コンテンツタイプの情報の連想配列
1174          */
1175         function getMainContentTypeInfo()
1176         {
1177                 return $this->mainContentTypeInfo;                              // 主要コンテンツタイプ
1178         }
1179         /**
1180          * フロント画面で使用する補助コンテンツタイプの情報取得
1181          *
1182          * @return array                        コンテンツタイプの情報の連想配列
1183          */
1184         function getSubContentTypeInfo()
1185         {
1186                 return $this->subContentTypeInfo;                               // 補助コンテンツタイプ
1187         }
1188         /**
1189          * フロント画面で使用する主要コンテンツタイプを取得
1190          *
1191          * @return array                        コンテンツタイプの配列
1192          */
1193         function getMainContentTypes()
1194         {
1195                 // 「value」値のみ取得
1196                 //return array_map(create_function('$a', 'return $a["value"];'), $this->mainContentTypeInfo);
1197                 $types = array_map(function($a){ return $a["value"]; }, $this->mainContentTypeInfo);
1198                 return $types;
1199         }
1200         /**
1201          * フロント画面で使用するサブコンテンツタイプを取得
1202          *
1203          * @return array                        コンテンツタイプの配列
1204          */
1205         function getSubContentTypes()
1206         {
1207                 // 「value」値のみ取得
1208 //              return array_map(create_function('$a', 'return $a["value"];'), $this->subContentTypeInfo);
1209                 $types = array_map(function($a){ return $a["value"]; }, $this->subContentTypeInfo);
1210                 return $types;
1211         }
1212         /**
1213          * フロント画面で使用する主要機能タイプ情報を取得
1214          *
1215          * @return array                        機能タイプの情報の連想配列
1216          */
1217         function getMainFeatureTypeInfo()
1218         {
1219                 return $this->mainFeatureTypeInfo;                              // 主要機能タイプ
1220         }
1221         /**
1222          * フロント画面で使用する主要機能タイプを取得
1223          *
1224          * @return array                        機能タイプの配列
1225          */
1226         function getMainFeatureTypes()
1227         {
1228                 // 「value」値のみ取得
1229 //              return array_map(create_function('$a', 'return $a["value"];'), $this->mainFeatureTypeInfo);
1230                 $types = array_map(function($a){ return $a["value"]; }, $this->mainFeatureTypeInfo);
1231                 return $types;
1232         }
1233         
1234         /**
1235          * すべてのページ属性情報を取得
1236          *
1237          * @return array                        ページ属性情報の連想配列
1238          */
1239         function getAllPageAttributeTypeInfo()
1240         {
1241                 return array_merge($this->mainContentTypeInfo, $this->subContentTypeInfo, $this->mainFeatureTypeInfo, $this->adminFeatureTypeInfo);
1242         }
1243         /**
1244          * 管理画面用のサブメニューバーの定義を設定
1245          *
1246          * @param array $def    メニューバー定義
1247          * @return                              なし
1248          */
1249         function setAdminSubNavbarDef($def)
1250         {
1251                 $this->adminSubNavbarDef = $def;
1252         }
1253         /**
1254          * 管理画面用のサブメニューバーの定義を取得
1255          *
1256          * @return array メニューバーの定義
1257          */
1258         function getAdminSubNavbarDef()
1259         {
1260                 return $this->adminSubNavbarDef;
1261         }
1262         /**
1263          * 管理画面用パンくずリスト定義を設定
1264          *
1265          * @param array $def    パンくずリスト定義
1266          * @param array $help   ヘルプ(title,bodyの連想配列)
1267          * @return                              なし
1268          */
1269         function setAdminBreadcrumbDef($def, $help = array())
1270         {
1271                 $this->adminBreadcrumbDef = $def;
1272                 if (!empty($help)) $this->adminBreadcrumbDefHelp = $help;                               // 管理画面用パンくずリストヘルプ定義
1273         }
1274         /**
1275          * 管理画面用パンくずリスト定義を取得
1276          *
1277          * @param array $help   ヘルプ(title,bodyの連想配列)
1278          * @return array                パンくずリスト定義
1279          */
1280         function getAdminBreadcrumbDef(&$help)
1281         {
1282                 // パラメータ数を取得
1283                 $argNum = func_num_args();
1284                 
1285                 // ヘルプ取得用パラメータが存在する場合は定義を設定
1286                 if ($argNum > 0) $help = $this->adminBreadcrumbDefHelp;
1287
1288                 return $this->adminBreadcrumbDef;
1289         }
1290         /**
1291          * ページ作成開始
1292          *
1293          * HTTPヘッダを設定する。セッションを取得する。サブページIDを設定する。
1294          *
1295          * @param RequestManager $request               HTTPリクエスト処理クラス
1296          * @return                                                              なし
1297          */
1298         function startPage($request)
1299         {
1300                 global $gEnvManager;
1301                 global $gRequestManager;
1302                 global $gInstanceManager;
1303                 global $gAccessManager;
1304                 global $gSystemManager;
1305                 global $gDispManager;
1306                 global $gOpeLogManager;
1307                 
1308                 // 実行コマンドを取得
1309                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
1310                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
1311                 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
1312                 $pageId = $gEnvManager->getCurrentPageId();
1313
1314                 // ###### クライアントIDの読み込み、再設定 ######
1315                 // この後、クライアントIDがアクセスログに記録される
1316                 $clientId = $request->getCookieValue(M3_COOKIE_CLIENT_ID);
1317                 if (empty($clientId)){  // クライアントIDが設定されていないとき(初回アクセス)
1318                         // クライアントIDを生成
1319                         $clientId = $this->gAccess->createClientId();
1320                 } else {
1321                         $this->gAccess->setClientId($clientId); // クライアントIDを設定
1322                 
1323                         // クッキーの使用可否を設定
1324                         $this->gEnv->setCanUseCookie(true);
1325                 }
1326                 $request->setCookieValue(M3_COOKIE_CLIENT_ID, $clientId, M3_COOKIE_EXPIRE_CLIENT_ID);
1327                         
1328                 // インストール時の管理画面用ライブラリを追加(フレームコンテナでの設定を反映)
1329                 if (defined('M3_STATE_IN_INSTALL')){
1330                         // Bootstrapライブラリ追加
1331                         if ($this->useBootstrap){
1332                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
1333                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
1334                         }
1335                 } else {
1336                         // 管理者キーがあればGETまたはPOST値のセッションIDを使用する
1337 //                      if ($gEnvManager->isAdminDirAccess()){
1338 //                              if ($gAccessManager->isValidAdminKey()) session_id($gRequestManager->trimValueOf(session_name()));
1339 //                      }
1340                 }
1341
1342                 // 最終HTML(ページ全体で使用するHTML)の出力
1343                 if ($cmd == M3_REQUEST_CMD_CSS){                // CSS生成のとき
1344                         $gRequestManager->stopSessionUpdate();                  // セッションの更新を停止
1345                 }
1346                 
1347                 // セッション変数を取得可能にする
1348                 session_start();
1349                 
1350                 // ##### インストール時はここで終了 #####
1351                 if (defined('M3_STATE_IN_INSTALL')) return;             // インストール時は実行しない
1352                 
1353                 // セッションを再生成する(セキュリティ対策)
1354                 if ($gSystemManager->regenerateSessionId()){
1355                         $gAccessManager->setOldSessionId(session_id());         // 古いセッションIDを保存
1356                         session_regenerate_id(true);
1357                 }
1358                 
1359                 // セッションからユーザ情報を取得
1360                 $userInfo = $gRequestManager->getSessionValueWithSerialize(M3_SESSION_USER_INFO);
1361                 if (!$gAccessManager->checkSessionSecurity($userInfo)) return;                  // セキュリティ問題ありの場合はここで終了
1362                 // ##### ここで終了した場合はページサブIDが未設定のためページ不正のエラーが発生しアクセスエラー画面が表示される #####
1363                 
1364                 // ##### POST時のリファラーチェック #####
1365                 // WooCommerceのAJAX処理が通らないのでチェックしない?
1366 /*              if ($gRequestManager->isPostMethod() && !$this->_checkReferer()){
1367                         $errMsg = '不正なPOSTデータ(リファラー異常)を検出しました。アクセス元IP: ' . $gAccessManager->getClientIp();
1368                         $msgDetail = 'アクセスをブロックしました。account=' . $userInfo->account . ', userid=' . $userInfo->userId;
1369                         $gOpeLogManager->writeUserError(__METHOD__, $errMsg, 2210, $msgDetail);
1370                         return;
1371                 }*/
1372                 
1373                 // その他セッション情報取得
1374                 $gRequestManager->_doSessionOpenEventCallback();
1375
1376                 // ユーザ情報をロード
1377                 $gInstanceManager->setUserInfo($userInfo);
1378
1379                 // ##### 自動ログイン #####
1380                 // ログイン中でない場合は自動ログインでユーザ情報を取得
1381                 $gAccessManager->startAutoLogin();
1382                 
1383                 // デバッグモードの表示
1384                 if (M3_SYSTEM_DEBUG) echo 'Debug mode<br />';
1385                 
1386                 // ##### ユーザアクセスモードの設定 #####
1387                 if (!empty($userInfo) && $userInfo->isPersonal()) $this->setPersonalMode();             // パーソナルモードをオン
1388 /*              if (($userInfo->userType == UserInfo::USER_TYPE_MANAGER && $userInfo->userOptType == UserInfo::USER_OPT_TYPE_PAGE_MANAGER)||                    // ページ運用者の場合
1389                         $userInfo->userType < UserInfo::USER_TYPE_MANAGER){                     // システム運用者よりも権限が低い場合
1390                         
1391                         // パーソナルモードをオン
1392                         $this->setPersonalMode();
1393                 }*/
1394
1395                 // ##### ページIDの修正 #####
1396                 // ポジション表示の場合はページID、ページサブIDを再設定。再設定はシステム管理者のみ可能。
1397                 if (($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                                    // 管理画面(ウィジェットなしポジション表示)のとき
1398                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) &&            // 管理画面(ウィジェット付きポジション表示)のとき
1399 //                      $gEnvManager->isSystemAdmin()){
1400                         $gEnvManager->isSystemManageUser()){    // システム運用可能の場合(2018/8/5変更)
1401
1402                         $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1403                         if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId();          // 値がないときはデフォルトのページIDを設定
1404                         $this->gEnv->setCurrentPageId($pageId);
1405                         $subId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1406                         if (!empty($subId)) $this->gEnv->setCurrentPageSubId($subId);
1407                 }
1408                 
1409                 // ##### サブページIDの設定 #####
1410                 if ($gEnvManager->isAdminDirAccess() &&         // 管理画面へのアクセスのとき
1411                         ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT)){                               // ログイン、ログアウト場合は管理画面のページサブIDを指定
1412                         $subId = $gEnvManager->getAdminDefaultPageSubId();              // 管理画面用のデフォルトページサブID
1413                 } else {
1414                         if (empty($subId)) $subId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);// ページサブIDを取得
1415                         
1416                         if (empty($subId)){                     // サブページIDが設定されていないとき
1417                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1418                                 $params = $gRequestManager->getQueryArray();
1419                                 $paramCount = count($params);
1420
1421                                 // コマンド以外のパラメータ数が1つだけのときはパラメータからページ属性を判断する
1422                                 // 値が空でもキーがあれば属性を持つとする
1423                                 if ($paramCount == 0){
1424                                         $this->isPageTopUrl = true;                     // ページトップ(サブページ内のトップ位置)のURLかどうか
1425                                         
1426                                         //if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemAdmin() && empty($task)){
1427                                         if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser() && empty($task)){
1428                                                 // ダッシュボード機能は、パラメータなし、管理者ディレクトリ、システム運用者の条件で使用可能(2018/8/5変更)
1429                                                 // POST値にタスクがある場合はダッシュボードとしない
1430                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_DASHBOARD, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1431                                         }
1432                                 } else if ($paramCount > 0 && !$gEnvManager->isAdminDirAccess()){               // パラメータ付きの場合(2013/3/23)
1433                                         // ##### ページ属性から画面を選択(管理画面は対応しない) ###
1434                                         // 最初のURLパラメータでコンテンツを判断
1435                                         // プレビュー(cmd=preview)等のパターンで複数パラメータがある
1436                                         reset($params);
1437                                         $firstKey = key($params);
1438                                         $firstValue = $params[$firstKey];
1439
1440                                         if (!empty($firstValue)){               // 「key=value」の形式であること
1441                                                 switch ($firstKey){
1442                                                         case M3_REQUEST_PARAM_CONTENT_ID:               // コンテンツIDのとき
1443                                                         case M3_REQUEST_PARAM_CONTENT_ID_SHORT:
1444                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1445                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1446                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1447                                                         
1448                                                                 // ローカルメニューのURLからページを特定。ページが特定できないときはページ属性で取得。
1449                                                                 $url = $gEnvManager->getMacroPath($gEnvManager->getCurrentRequestUri());
1450                                                                 $ret = $this->db->getSubPageIdByMenuItemUrl($url, $gEnvManager->getCurrentPageId(), M3_VIEW_TYPE_CONTENT, $rows);
1451                                                                 if ($ret){
1452                                                                         $rowCount = count($rows);
1453                                                                         for ($i = 0; $i < $rowCount; $i++){
1454                                                                                 // コンテンツを表示するウィジェットがあるときはページサブIDを確定
1455                                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);
1456                                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);// コンテンツタイプでの取得に変更(2012/6/20)
1457                                                                                 if (!empty($widgetId)){
1458                                                                                         $subId = $rows[$i]['pd_sub_id'];
1459                                                                                         break;
1460                                                                                 }
1461                                                                         }
1462                                                                 }
1463                                                                 if (empty($subId)) $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_CONTENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1464                                                                 $this->contentType = M3_VIEW_TYPE_CONTENT;              // ページのコンテンツタイプ
1465                                                                 
1466                                                                 // コンテンツ詳細ページかどうかを設定
1467                                                                 if ($firstKey == M3_REQUEST_PARAM_CONTENT_ID || $firstKey == M3_REQUEST_PARAM_CONTENT_ID_SHORT) $this->isContentDetailPage = true;
1468                                                                 break;
1469                                                         case M3_REQUEST_PARAM_PRODUCT_ID:       // 製品IDのとき
1470                                                         case M3_REQUEST_PARAM_PRODUCT_ID_SHORT:
1471                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1472                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1473                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1474                                                                 
1475                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PRODUCT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1476                                                                 $this->contentType = M3_VIEW_TYPE_PRODUCT;              // ページのコンテンツタイプ
1477                                                                 
1478                                                                 // コンテンツ詳細ページかどうかを設定
1479                                                                 $this->isContentDetailPage = true;
1480                                                                 break;
1481                                                         case M3_REQUEST_PARAM_BBS_ID:           // 掲示板投稿記事のとき
1482                                                         case M3_REQUEST_PARAM_BBS_ID_SHORT:
1483                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID:
1484                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT:
1485                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1486                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1487                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1488                                                                 
1489                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BBS, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1490                                                                 $this->contentType = M3_VIEW_TYPE_BBS;          // ページのコンテンツタイプ
1491                                                                 
1492                                                                 // コンテンツ詳細ページかどうかを設定
1493                                                                 if ($firstKey == M3_REQUEST_PARAM_BBS_THREAD_ID || $firstKey == M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT) $this->isContentDetailPage = true;
1494                                                                 break;
1495                                                         case M3_REQUEST_PARAM_EVENT_ID:         // イベント記事のとき
1496                                                         case M3_REQUEST_PARAM_EVENT_ID_SHORT:
1497                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1498                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1499                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1500                                                                 
1501                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_EVENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1502                                                                 $this->contentType = M3_VIEW_TYPE_EVENT;                // ページのコンテンツタイプ
1503                                                                 
1504                                                                 // コンテンツ詳細ページかどうかを設定
1505                                                                 $this->isContentDetailPage = true;
1506                                                                 break;
1507                                                         case M3_REQUEST_PARAM_PHOTO_ID:         // フォトギャラリー写真のとき
1508                                                         case M3_REQUEST_PARAM_PHOTO_ID_SHORT:
1509                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1510                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1511                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1512                                                                 
1513                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PHOTO, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1514                                                                 $this->contentType = M3_VIEW_TYPE_PHOTO;                // ページのコンテンツタイプ
1515                                                                 
1516                                                                 // コンテンツ詳細ページかどうかを設定
1517                                                                 $this->isContentDetailPage = true;
1518                                                                 break;
1519                                                         case M3_REQUEST_PARAM_BLOG_ID:          // ブログIDのとき
1520                                                         case M3_REQUEST_PARAM_BLOG_ID_SHORT:
1521                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID:
1522                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT:
1523                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1524                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1525                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1526                 
1527                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BLOG, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1528                                                                 $this->contentType = M3_VIEW_TYPE_BLOG;         // ページのコンテンツタイプ
1529                                                                 
1530                                                                 // コンテンツ詳細ページかどうかを設定
1531                                                                 if ($firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT) $this->isContentDetailPage = true;
1532                                                                 break;
1533                                                         case M3_REQUEST_PARAM_ROOM_ID:          // ユーザ作成コンテンツのとき
1534                                                         case M3_REQUEST_PARAM_ROOM_ID_SHORT:
1535                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1536                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1537                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1538                                                                 
1539                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_USER, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1540                                                                 $this->contentType = M3_VIEW_TYPE_USER;         // ページのコンテンツタイプ
1541                                                 
1542                                                                 // コンテンツ詳細ページかどうかを設定
1543                                                                 $this->isContentDetailPage = true;
1544                                                                 
1545                                                                 // コンテンツを表示するウィジェットを取得
1546                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);
1547                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);// コンテンツタイプでの取得に変更(2012/6/20)
1548                                                                 if (!empty($widgetId)){
1549                                                                         // ルーム用の定義ID(所属グループID)を取得
1550                                                                         $roomId = isset($params[M3_REQUEST_PARAM_ROOM_ID]) ? $params[M3_REQUEST_PARAM_ROOM_ID] : $params[M3_REQUEST_PARAM_ROOM_ID_SHORT];
1551                                                                         $configId = $this->db->getWidgetConfigIdForRoom($roomId);
1552
1553                                                                         // グループIDを定義IDとするページのページサブIDを取得
1554                                                                         $subPageId = $this->getPageSubIdByWidget($gEnvManager->getCurrentPageId(), $widgetId, $configId);
1555                                                                         if (!empty($subPageId)) $subId = $subPageId;
1556                                                                 }
1557                                                                 break;
1558                                                         default:                // オプションのURLコンテンツパラメータからサブページIDを取得
1559                                                                 $ret = $this->db->getSubPageIdByUrlContentParam($gEnvManager->getCurrentPageId(), $firstKey, $row);
1560                                                                 if ($ret) $subId = $row['pd_sub_id'];
1561                                                                 break;
1562                                                 }
1563                                         }
1564                                 }
1565
1566                                 // wiki用パラメータの取得
1567                                 if (empty($subId)){
1568                                         // 「http://www.example.com?ページ名」「wcmd」の場合はwikiコンテンツページを選択
1569                                         $wikiCmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND);
1570                                         $pageName = $gRequestManager->getWikiPageFromQuery();           // 「=」なしのパラメータはwikiパラメータとする
1571                         
1572                                         if (!empty($wikiCmd) || !empty($pageName)){                     // Wikiコンテンツページを指定のとき
1573                                                 // ページサブIDを取得
1574                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_WIKI, $gEnvManager->getCurrentPageId());
1575                                                 $this->contentType = M3_VIEW_TYPE_WIKI;         // ページのコンテンツタイプ
1576                                                 
1577                                                 // コンテンツ詳細ページかどうかを設定
1578                                                 $this->isContentDetailPage = true;
1579                                         }
1580                                 }
1581                                 // その他のGET,POSTパラメータからページサブID取得
1582                                 if (empty($subId)){
1583                                         // 検索用パラメータなどでリダイレクト先のURLが取得できた場合は遷移
1584                                         $subId = $this->getPageSubIdByParam($request, $redirectUrl);
1585                                         if (!empty($subId) && !empty($redirectUrl)) $this->redirect($redirectUrl);
1586                                 }
1587                                 
1588                                 // ページサブIDが取得できない場合はデフォルトを使用
1589                                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
1590                         } else {                // ページサブIDが設定されているとき
1591                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1592                                 $params = $gRequestManager->getQueryArray();
1593                                 $paramCount = count($params);
1594                                 if ($paramCount == 1) $this->isPageTopUrl = true;                       // ページトップ(サブページ内のトップ位置)のURLかどうか
1595                         }
1596                 }
1597                 $gEnvManager->setCurrentPageSubId($subId);// サブページIDを設定
1598                 
1599                 // SSL通信機能がオンの場合は、アクセスされたURLのSSLをチェックし不正の場合は正しいURLにリダイレクト
1600                 // 設定に間違いがある場合、管理画面にアクセスできなくなるので、フロント画面のみ制御
1601 //              if ($gEnvManager->getUseSsl() || $gEnvManager->getUseSslAdmin()){
1602                 if ($gEnvManager->getUseSsl()){                 // フロント画面のSSL設定のみチェック(2016/7/30)
1603                         if (!$gEnvManager->isAdminDirAccess()){         // 管理画面以外へのアクセスのとき
1604                                 // ルートURLがSSLの場合はSSLに固定
1605                                 if ($gEnvManager->isRootUrlSsl()){              // ルートURLがSSLの場合はフロント画面のすべてがSSL付き
1606                                         $isSsl = true;
1607                                 } else {
1608                                         $isSsl = $gEnvManager->isSslByCurrentPage();
1609                                 }
1610                                 $currentUrl = $gEnvManager->getCurrentRequestUri();
1611                                 if ($isSsl){
1612                                         $correctUrl = str_replace('http://', 'https://', $currentUrl);
1613                                 } else {
1614                                         $correctUrl = str_replace('https://', 'http://', $currentUrl);
1615                                 }
1616                                 if ($currentUrl != $correctUrl) $this->redirect($correctUrl);
1617                         }
1618                 }
1619                 // マルチドメイン用設定初期化
1620                 $gEnvManager->initMultiDomain();
1621                 
1622                 // 画面設定取得
1623                 $gDispManager->load();
1624                         
1625                 // ##### 画面に必要なスクリプトを追加 #####
1626                 // スマートフォン用URLのときはスマートフォン用のjQueryを使用
1627                 if ($gEnvManager->getIsSmartphoneSite()){
1628                         $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(10);                   // スマートフォン用jQueryファイル
1629                         
1630                         if (isset($this->libFiles[ScriptLibInfo::LIB_JQUERYS_MOBILE]['script'])){
1631                                 $scriptFiles = $this->libFiles[ScriptLibInfo::LIB_JQUERYS_MOBILE]['script'];
1632                                 if (count($scriptFiles) > 0) $this->selectedJQueryMobileFilename = $scriptFiles[0];             // 使用対象のjQueryMobileファイル
1633                         }
1634                 }
1635                 
1636                 // Magic3管理用のスクリプトを追加
1637                 if (!$gEnvManager->getIsMobileSite()){          // 携帯用URL以外のとき
1638                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
1639                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
1640 //                                      $this->isEditMode = true;                       // フロント画面編集モード
1641                                         $this->isPageEditable = true;           // フロント画面ページ編集可能モードに設定(コンテキストメニュー表示)
1642                                                 
1643                                         // 管理画面用ライブラリを追加
1644                                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1645                                         //if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){                                          // ウィジェット設定画面またはテンプレート設定画面のとき
1646                                                 $this->addAdminScript('', ScriptLibInfo::getWysiwygEditorLibId());      // WYSIWYGエディターを追加
1647                                                 
1648                                                 // Googleマップライブラリの読み込み
1649                                                 if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1650                                                         $this->defaultAdminScriptFiles[] = ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS);
1651                                                 }
1652                                         } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // 管理画面(ウィジェット付きポジション表示)のとき
1653                                                 $this->isLayout = true;         // 画面レイアウト中かどうか
1654                                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_IDTABS);                    // 管理パネル用スクリプト追加(ポジション表示追加分)
1655                                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_DROPDOWN);               // 管理パネル用スクリプト追加(ドロップダウンメニュー)
1656                                                 //$this->useBootstrap = true;           // Bootstrapを使用
1657                                                 //$this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);             // パネルメニュー(フロント画面と管理画面の切り替え等)用
1658                                         }
1659                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1660                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1661                                         
1662                                         // スクリプトが必要なウィジェットをすべて取得
1663                                         $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1664                                         for ($i = 0; $i < count($rows); $i++){
1665                                                 $this->addAdminScript($task, trim($rows[$i]['wd_add_script_lib']));
1666                                         }
1667                                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1668                                                 // ウィジェット情報取得
1669                                                 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
1670                                                 $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
1671                                                 if ($ret) $this->addAdminScript($task, trim($this->configWidgetInfo['wd_add_script_lib_a']));           // 管理機能用スクリプト
1672                                         }
1673                                 }
1674                         } else {                // フロント画面へのアクセスのとき
1675                                 // フロント画面用スクリプトファイル追加
1676                                 $value = $gSystemManager->getSystemConfig(self::CF_USE_JQUERY);// 常にjQueryを使用するかどうか
1677                                 if ($value) $this->addScriptFile($this->selectedJQueryFilename);
1678                 
1679                                 if ($cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                 // ウィジェット単体実行でない
1680                                         $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
1681                                         if ($gEnvManager->isSystemManageUser()){
1682                                                 $this->isEditMode = true;                       // フロント画面編集モード
1683                                                 $this->isPageEditable = true;           // フロント画面ページ編集可能モードに設定
1684                                         
1685                                                 // システム運用権限がある場合は管理用スクリプトを追加
1686                                                 // フロント画面と管理画面の切り替え用のスライドメニューバーには管理用スクリプト,CSSが必要
1687                                                 $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1688                                                 $this->addScriptFile(ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME);               // jQuery Contextmenu Lib
1689                                                 $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1690                                                 //$this->addScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);          // パネルメニュー(フロント画面と管理画面の切り替え等)用
1691                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);  // 管理パネル用スクリプト追加
1692                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_COOKIE);                 // 管理パネル用スクリプト追加
1693                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_EASING);                 // 管理パネル用スクリプト追加
1694                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1695                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1696                                         
1697                                                 $this->addCssFile(self::M3_ADMIN_CSS_FILE);             // 管理機能用CSS
1698                                         } else if ($gEnvManager->isContentEditableUser()){              // コンテンツ編集可能ユーザの場合
1699                                                 $this->isEditMode = true;                       // フロント画面編集モード
1700                                         }
1701                                 } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
1702                                         if ($gEnvManager->isContentEditableUser()){             // コンテンツ編集可能ユーザの場合
1703                                                 $this->isEditMode = true;                       // フロント画面編集モード
1704                                         
1705 //                                              $this->addScript('', ScriptLibInfo::LIB_JQUERY_RESPONSIVETABLE);// 管理画面作成用
1706                                                 $this->addScript('', ScriptLibInfo::getWysiwygEditorLibId());   // WYSIWYGエディターを追加
1707                                                 $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1708                                                 $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
1709                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1710                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1711                                                 
1712                                                 // Googleマップライブラリの読み込み
1713                                                 if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1714                                                         $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));
1715                                                 }
1716                                         }
1717                                 }
1718                         }
1719                 }
1720
1721                 // デフォルトのページ情報を取得
1722                 $row = $this->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
1723                 if (!empty($row)){
1724                         // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1725                         if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1726                 
1727                         // 現在のページ情報を設定
1728                         $this->currentPageInfo = $row;                  // 現在のページのページ情報
1729                 }
1730                         
1731                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)のとき
1732 /*                      $defPageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1733                         $defPageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1734                         
1735                         // デフォルトのページ情報を取得
1736                         $row = $this->getPageInfo($defPageId, $defPageSubId);
1737                         if (!empty($row)){
1738                                 // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1739                                 if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1740                         
1741                                 // 現在のページ情報を設定
1742                                 $this->currentPageInfo = $row;                  // 現在のページのページ情報
1743                         }*/
1744                         
1745                         // テンプレートの情報を取得
1746         //              $ret = $this->db->getPageDefOnPage($defPageId, $defPageSubId, $rows);
1747                         $ret = $this->db->getPageDefOnPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1748                         if ($ret){
1749                                 for ($i = 0; $i < count($rows); $i++){
1750                                         $position = $rows[$i]['pd_position_id'];
1751                                         if (!in_array($position, $this->defPositions)) $this->defPositions[] = $position;       // 画面定義データのポジション(すべて)
1752                                 }
1753                         }
1754                 }
1755                 
1756                 // 画面透過モードを設定
1757                 if ($openBy == 'tabs') $this->isTransparentMode = true;         // 画面透過モード
1758         }
1759         /**
1760          * URLの最初のパラメータが不正文字の場合はエラー画面へリダイレクト
1761          *
1762          * @param string $value                 URLの最初のパラメータ値
1763          * @return bool                                 true=正常、false=異常
1764          */
1765         function _checkFirstValueRedirect($value)
1766         {
1767                 global $gEnvManager;
1768                 global $gOpeLogManager;
1769                 
1770                 // 半角英小文字大文字、数字、アンダーバー、ハイフン、カンマのみ使用可能。
1771                 if (preg_match("/[^0-9a-zA-Z-_,]/", $value)){
1772                         $errMessage = 'URLパラメータの不正。';
1773                         $gOpeLogManager->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2200, 'アクセスをブロックしました。URL: ' . $gEnvManager->getCurrentRequestUri());
1774                         
1775         //              $this->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
1776                         // システム制御ページへ遷移
1777                         $this->isSystemPage = true;
1778                         return false;
1779                 } else {
1780                         return true;
1781                 }
1782         }
1783         /**
1784          * 言語に依存する情報を取り込む
1785          *
1786          * @return                                                      なし
1787          */
1788         function loadLang()
1789         {
1790                 global $gEnvManager;
1791                 global $gSystemManager;
1792                 
1793                 $lang = $gEnvManager->getCurrentLanguage();
1794                 
1795                 // デフォルト言語とカレント言語が異なる場合のみ実行
1796                 if ($lang != $gEnvManager->getDefaultLanguage()){
1797                         // 指定言語のサイト定義取得
1798                         $gSystemManager->roadSiteDefByLang($lang);
1799                 }
1800                 
1801                 // 現在の言語でヘッダ初期化
1802                 $this->headDescription  = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_DESCRIPTION);    // HTMLヘッダ「description」に出力する文字列
1803                 $this->headKeywords             = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_KEYWORDS);               // HTMLヘッダ「keywords」に出力する文字列
1804                 $this->headOthers               = $gSystemManager->getSiteDef(self::SD_HEAD_OTHERS);                    // HTMLヘッダに出力するタグ文字列
1805
1806                 // デフォルトのページ情報でヘッダを更新
1807                 if (!empty($this->currentPageInfo)){
1808                         $title          = $this->currentPageInfo['pn_meta_title'];              // 画面タイトル
1809                         $desc           = $this->currentPageInfo['pn_meta_description'];                // ページ要約
1810                         $keyword        = $this->currentPageInfo['pn_meta_keywords'];           // ページキーワード
1811                         $headOthers     = $this->currentPageInfo['pn_head_others'];             // ヘッダその他タグ
1812                         
1813                         if (!empty($title)) $this->setHeadSubTitle($title, '', true);           // デフォルト値として設定
1814                         if (!empty($desc)) $this->setHeadDescription($desc);
1815                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1816                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1817                 }
1818
1819                 // 現在の言語のページ情報でヘッダを更新
1820                 $ret = $this->db->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $lang, $row);
1821                 if ($ret){
1822                         $title          = $row['pn_meta_title'];                // 画面タイトル
1823                         $desc           = $row['pn_meta_description'];          // ページ要約
1824                         $keyword        = $row['pn_meta_keywords'];             // ページキーワード
1825                         $headOthers = $row['pn_head_others'];           // ヘッダその他タグ
1826                         
1827                         if (!empty($title)) $this->setHeadSubTitle($title, '', true);           // デフォルト値として設定
1828                         if (!empty($desc)) $this->setHeadDescription($desc);
1829                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1830                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1831                         
1832                         // 現在のページ情報を設定
1833 //                      $this->currentPageInfo = $row;                  // 現在のページのページ情報
1834                 }
1835         }
1836         /**
1837          * スクリプト追加情報から、管理機能用のJavascriptファイル、CSSを追加する
1838          *
1839          * @param string $task                          指定タスク
1840          * @param string $scriptInfo            スクリプト追加情報
1841          * @return                                                      なし
1842          */
1843         function addAdminScript($task, $scriptInfo)
1844         {
1845                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1846                 for ($i = 0; $i < count($itemArray); $i++){
1847                         $pos = strpos($itemArray[$i], '=');
1848                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1849                                 $libs = trim($itemArray[$i]);
1850                         } else {                // タスク指定のとき
1851                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1852                                 $libTask = trim($libTask);
1853                                 $libs = trim($libs);
1854                                 
1855                                 if (strEndsWith($libTask, '_')){                // 「task_subtask」形式のタスクのとき
1856                                         if (!strStartsWith($task, $libTask)) $libs = '';                        // タスクIDの先頭部が異なるときは追加しない
1857                                 } else {
1858                                         if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1859                                 }
1860                         }
1861                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1862                                 $libsArray = explode(',', $libs);
1863                                 for ($j = 0; $j < count($libsArray); $j++){
1864                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1865                                         
1866                                         // ライブラリセットを展開
1867                                         $setLibArray = ScriptLibInfo::getLibSet($lib);
1868                                         $setLibCount = count($setLibArray);
1869                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1870                                                 for ($k = 0; $k < $setLibCount; $k++){
1871                                                         $this->_addAdminScript($setLibArray[$k]);
1872                                                 }
1873                                         } else {
1874                                                 $this->_addAdminScript($lib);
1875                                         }
1876                                 }
1877                         }
1878                 }
1879         }
1880         /**
1881          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
1882          *
1883          * @param string $lib                           ライブラリID
1884          * @return                                                      なし
1885          */
1886         function _addAdminScript($lib)
1887         {
1888                 // ライブラリが存在しないときは終了
1889                 if (!isset($this->libFiles[$lib])) return;
1890                 
1891                 // 依存ライブラリを取得
1892 //              if (strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){         // elFinder、timepickerを使用する場合
1893                 // jQuery UIライブラリを追加
1894                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
1895                 if (isset($dependentLib)){
1896                         for ($i = 0; $i < count($dependentLib); $i++){
1897                                 $addLib = $dependentLib[$i];
1898
1899                                 // ライブラリのファイルを追加
1900                                 if (isset($this->libFiles[$addLib]['script'])){
1901                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1902                                         for ($m = 0; $m < count($scriptFiles); $m++){
1903                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1904                                         }
1905                                 }
1906                                 // ライブラリの言語ファイルを追加
1907                                 if (isset($this->libFiles[$addLib]['script_lang'])){
1908                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);
1909                                         for ($m = 0; $m < count($scriptFiles); $m++){
1910                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1911                                         }
1912                                 }
1913                                 // ライブラリのCSSファイルを追加
1914                                 if (isset($this->libFiles[$addLib]['css'])){
1915                                         $cssFiles = $this->libFiles[$addLib]['css'];
1916                                         for ($m = 0; $m < count($cssFiles); $m++){
1917                                                 $this->addAdminCssFile($cssFiles[$m]);          // 通常機能用のCSS追加
1918                                         }
1919                                 }
1920                         }
1921                         // jQueryUIテーマを追加
1922                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1923                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1924                                 $this->outputTheme = true;
1925                         }
1926                 }
1927
1928                 // Javascript追加
1929                 if (isset($this->libFiles[$lib]['script'])){
1930                         $scriptFiles = $this->libFiles[$lib]['script'];
1931
1932                         // ##### ライブラリ情報を作成する場合 #####
1933                         if (empty($scriptFiles)){
1934                                 $generatedLib = ScriptLibInfo::generateLib($lib);                       // ライブラリ取得
1935                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
1936                         }
1937                         
1938                         for ($i = 0; $i < count($scriptFiles); $i++){
1939                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1940                         }
1941                 }
1942                 // ライブラリの言語ファイルを追加
1943                 if (isset($this->libFiles[$lib]['script_lang'])){
1944                         $scriptFiles = ScriptLibInfo::getLangScript($lib);
1945                         for ($i = 0; $i < count($scriptFiles); $i++){
1946                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1947                         }
1948                 }
1949                 // CSS追加
1950                 if (isset($this->libFiles[$lib]['css'])){
1951                         $cssFiles = $this->libFiles[$lib]['css'];
1952                         for ($i = 0; $i < count($cssFiles); $i++){
1953                                 $this->addAdminCssFile($cssFiles[$i]);          // 管理機能用のCSS追加
1954                         }
1955                 }
1956                 // その他
1957                 if (strncmp($lib, 'jquery-ui.', 10) == 0){              // jQuery UIのwidgetsまたはeffectsのとき。jQuery UI Coreはデフォルトで読み込まれている。
1958                         // jQueryUIテーマを追加
1959                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1960                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1961                                 $this->outputTheme = true;
1962                         }
1963                 }
1964         }
1965         /**
1966          * スクリプト追加情報から、通常機能用のJavascriptファイル、CSSを追加する
1967          *
1968          * @param string $task                          指定タスク
1969          * @param string $scriptInfo            スクリプト追加情報
1970          * @return                                                      なし
1971          */
1972         function addScript($task, $scriptInfo)
1973         {
1974                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1975                 for ($i = 0; $i < count($itemArray); $i++){
1976                         $pos = strpos($itemArray[$i], '=');
1977                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1978                                 $libs = trim($itemArray[$i]);
1979                         } else {                // タスク指定のとき
1980                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1981                                 $libTask = trim($libTask);
1982                                 $libs = trim($libs);
1983                                 if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1984                         }
1985                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1986                                 $libsArray = explode(',', $libs);
1987                                 for ($j = 0; $j < count($libsArray); $j++){
1988                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1989                                         
1990                                         // jQueryライブラリ等、デフォルトでは追加されないライブラリを追加
1991                                         $setLibArray = ScriptLibInfo::getLibSet($lib);// ライブラリセットを展開
1992                                         $setLibCount = count($setLibArray);
1993                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1994                                                 for ($k = 0; $k < $setLibCount; $k++){
1995                                                         $this->_addScript($setLibArray[$k]);
1996                                                 }
1997                                         } else {
1998                                                 $this->_addScript($lib);
1999                                         }
2000                                 }
2001                         }
2002                 }
2003         }
2004         /**
2005          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
2006          *
2007          * @param string $lib                           ライブラリID
2008          * @return                                                      なし
2009          */
2010         function _addScript($lib)
2011         {
2012                 // ライブラリが存在しないときは終了
2013                 if (!isset($this->libFiles[$lib])) return;
2014
2015                 // ライブラリの依存ライブラリファイルを追加
2016                 if (strcmp($lib, 'jquery') == 0){// jQuery本体のとき
2017                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
2018                 } else if (strncmp($lib, 'jquery.', 7) == 0){           // jQueryプラグインのとき
2019                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
2020                         if (strcmp($lib, 'jquery.mobile') == 0){        // jQueryMobileファイルのとき
2021                                 // ##### jQueryMobileが読み込まれる前に読み込む必要があるスクリプトを設定 #####
2022                                 if (!empty($this->headPreMobileScriptFiles)){           // jQueryMobileファイルの前に出力
2023                                         for ($i = 0; $i < count($this->headPreMobileScriptFiles); $i++){
2024                                                 $this->addScriptFile($this->headPreMobileScriptFiles[$i]);              // 通常機能用のスクリプト追加
2025                                         }
2026                                 }
2027                         } else {
2028                                 // 依存ライブラリ追加
2029                                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
2030                                 if (isset($dependentLib)){
2031                                         for ($i = 0; $i < count($dependentLib); $i++){
2032                                                 $addLib = $dependentLib[$i];
2033                                 
2034                                                 // ライブラリのファイルを追加
2035                                                 if (isset($this->libFiles[$addLib]['script'])){
2036                                                         $scriptFiles = $this->libFiles[$addLib]['script'];
2037                                                         for ($m = 0; $m < count($scriptFiles); $m++){
2038                                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
2039                                                         }
2040                                                 }
2041                                                 // ライブラリの言語ファイルを追加
2042                                                 if (isset($this->libFiles[$addLib]['script_lang'])){
2043                                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);
2044                                                         for ($m = 0; $m < count($scriptFiles); $m++){
2045                                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
2046                                                         }
2047                                                 }
2048                                                 // ライブラリのCSSファイルを追加
2049                                                 if (isset($this->libFiles[$addLib]['css'])){
2050                                                         $cssFiles = $this->libFiles[$addLib]['css'];
2051                                                         for ($m = 0; $m < count($cssFiles); $m++){
2052                                                                 $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
2053                                                         }
2054                                                 }
2055                                         }
2056                                 }
2057                         }
2058                 } else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI) == 0){    // jQuery UI
2059                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
2060                 //} else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI_PLUS) == 0){     // jQuery UI plus
2061                 //      $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
2062                 //      $this->addScriptFile($this->selectedJQueryUiFilename);          // jQuery Coreスクリプト追加
2063                 } else if (strncmp($lib, 'jquery-ui.', 10) == 0 ||              // jQuery UIのwidgetsまたはeffectsのとき
2064                         strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){             // elFinder、timepickerを使用する場合
2065
2066                         // 依存ライブラリ追加
2067                         if (strncmp($lib, 'jquery-ui.', 10) == 0){
2068                                 $jQueryUiInfo = ScriptLibInfo::getJQueryUiInfo();// ライブラリ情報取得
2069                                 $dependentLib = $jQueryUiInfo[$lib];            // 依存ライブラリ取得
2070                         } else {
2071                                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
2072                         }
2073                         for ($i = 0; $i < count($dependentLib); $i++){
2074                                 $addLib = $dependentLib[$i];
2075                                 
2076                                 // ライブラリのファイルを追加
2077                                 if (isset($this->libFiles[$addLib]['script'])){
2078                                         $scriptFiles = $this->libFiles[$addLib]['script'];
2079                                         for ($m = 0; $m < count($scriptFiles); $m++){
2080                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
2081                                         }
2082                                 }
2083                                 // ライブラリの言語ファイルを追加
2084                                 if (isset($this->libFiles[$addLib]['script_lang'])){
2085                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);;
2086                                         for ($m = 0; $m < count($scriptFiles); $m++){
2087                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
2088                                         }
2089                                 }
2090                                 // ライブラリのCSSファイルを追加
2091                                 if (isset($this->libFiles[$addLib]['css'])){
2092                                         $cssFiles = $this->libFiles[$addLib]['css'];
2093                                         for ($m = 0; $m < count($cssFiles); $m++){
2094                                                 $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
2095                                         }
2096                                 }
2097                         }
2098                         // jQueryUIテーマを追加
2099                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
2100                                 $this->addCssFile($this->getDefaultThemeUrl());         // 通常機能用のCSS追加
2101                                 $this->outputTheme = true;
2102                         }
2103                 }
2104                 
2105                 // ライブラリ自体のファイルを追加
2106                 if (isset($this->libFiles[$lib]['script'])){
2107                         $scriptFiles = $this->libFiles[$lib]['script'];
2108                         
2109                         // ##### ライブラリ情報を作成する場合 #####
2110                         if (empty($scriptFiles)){
2111                                 $generatedLib = ScriptLibInfo::generateLib($lib);                       // ライブラリ取得
2112                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2113                         }
2114                         
2115                         for ($i = 0; $i < count($scriptFiles); $i++){
2116                                 $this->addScriptFile($scriptFiles[$i]);         // 通常機能用のスクリプト追加
2117                         }
2118                 }
2119                 // ライブラリの言語ファイルを追加
2120                 if (isset($this->libFiles[$lib]['script_lang'])){
2121                         $scriptFiles = ScriptLibInfo::getLangScript($lib);
2122                         for ($i = 0; $i < count($scriptFiles); $i++){
2123                                 $this->addScriptFile($scriptFiles[$i]);         // 通常機能用のスクリプト追加
2124                         }
2125                 }
2126                 // ライブラリのCSSファイルを追加
2127                 if (isset($this->libFiles[$lib]['css'])){
2128                         $cssFiles = $this->libFiles[$lib]['css'];
2129                         for ($i = 0; $i < count($cssFiles); $i++){
2130                                 $this->addCssFile($cssFiles[$i]);               // 通常機能用のCSS追加
2131                         }
2132                 }
2133         }
2134         /**
2135          * 非ログイン時の管理機能用のJavascriptファイル、CSSを追加する
2136          *
2137          * @param array, string         $lib            追加ライブラリID
2138          * @return                                      なし
2139          */
2140         function addPermittedAdminScript($lib)
2141         {
2142                 if (is_array($lib)){
2143                         for ($j = 0; $j < count($lib); $j++){
2144                                 $libId = $lib[$j];
2145                         
2146                                 // Javascript追加
2147                                 if (isset($this->libFiles[$libId]['script'])){
2148                                         $scriptFiles = $this->libFiles[$libId]['script'];
2149                                         
2150                                         // ##### ライブラリ情報を作成する場合 #####
2151                                         if (empty($scriptFiles)){
2152                                                 $generatedLib = ScriptLibInfo::generateLib($libId);                     // ライブラリ取得
2153                                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2154                                         }
2155                         
2156                                         for ($i = 0; $i < count($scriptFiles); $i++){
2157                                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2158                                         }
2159                                 }
2160                                 // ライブラリの言語ファイルを追加
2161                                 if (isset($this->libFiles[$libId]['script_lang'])){
2162                                         $scriptFiles = ScriptLibInfo::getLangScript($libId);
2163                                         for ($i = 0; $i < count($scriptFiles); $i++){
2164                                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2165                                         }
2166                                 }
2167                                 // CSS追加
2168                                 if (isset($this->libFiles[$libId]['css'])){
2169                                         $cssFiles = $this->libFiles[$libId]['css'];
2170                                         for ($i = 0; $i < count($cssFiles); $i++){
2171                                                 $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
2172                                         }
2173                                 }
2174                         }
2175                 } else {
2176                         $libId = $lib;
2177                         
2178                         // Javascript追加
2179                         if (isset($this->libFiles[$libId]['script'])){
2180                                 $scriptFiles = $this->libFiles[$libId]['script'];
2181                                 
2182                                 // ##### ライブラリ情報を作成する場合 #####
2183                                 if (empty($scriptFiles)){
2184                                         $generatedLib = ScriptLibInfo::generateLib($libId);                     // ライブラリ取得
2185                                         if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2186                                 }
2187                         
2188                                 for ($i = 0; $i < count($scriptFiles); $i++){
2189                                         $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2190                                 }
2191                         }
2192                         // ライブラリの言語ファイルを追加
2193                         if (isset($this->libFiles[$libId]['script_lang'])){
2194                                 $scriptFiles = ScriptLibInfo::getLangScript($libId);
2195                                 for ($i = 0; $i < count($scriptFiles); $i++){
2196                                         $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2197                                 }
2198                         }
2199                         // CSS追加
2200                         if (isset($this->libFiles[$libId]['css'])){
2201                                 $cssFiles = $this->libFiles[$libId]['css'];
2202                                 for ($i = 0; $i < count($cssFiles); $i++){
2203                                         $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
2204                                 }
2205                         }
2206                 }
2207         }
2208         /**
2209          * ページ作成終了
2210          *
2211          * ・最終HTML出力
2212          * ・セッション情報の保存
2213          * ・ウィジェットで生成されたHTTPヘッダを設定する
2214          *
2215          * @param RequestManager $request               HTTPリクエスト処理クラス
2216          * @param bool $getOutput                               出力を取得するかどうか
2217          * @return string                                       最終出力HTML
2218          */
2219         function endPage($request, $getOutput = false)
2220         {
2221                 global $gRequestManager;
2222                 global $gInstanceManager;
2223                 global $gEnvManager;
2224                 global $gDispManager;
2225                 global $gAccessManager;
2226                 
2227                 // ページ作成処理を中断するかどうか
2228                 if ($this->isAbort) return '';
2229                 
2230                 $contents = '';
2231                 
2232                 // 実行コマンドを取得
2233                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2234                 
2235                 // 最終HTML(ページ全体で使用するHTML)の出力
2236                 if ($cmd == M3_REQUEST_CMD_CSS){                // CSS生成のとき
2237                         // 外部出力形式でCSS出力
2238                         if (count($this->exportCss) > 0){
2239                                 for ($i = 0; $i < count($this->exportCss); $i++){
2240                                         $contents .= $this->exportCss[$i] . M3_NL;
2241                                 }
2242                         }
2243                         
2244                         // ヘッダ出力
2245                         header('Content-type: text/css');
2246                         
2247                         // 画面情報、ユーザ情報の保存は行わない
2248                         return $contents;
2249                 } else if ($cmd != M3_REQUEST_CMD_DO_WIDGET){           // ウィジェット単体オペレーションのときは出力しない
2250 /*                      if ($getOutput){
2251                                 $contents = $this->getLastContents($request);
2252                         } else {
2253                                 echo $this->getLastContents($request);
2254                         }*/
2255                 }
2256                 
2257                 // セッションへユーザ情報を保存
2258                 $userInfo = $gInstanceManager->getUserInfo();
2259                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
2260                 
2261                 // その他セッション情報保存
2262                 $gRequestManager->_doSessionCloseEventCallback();
2263                 
2264                 // 画面設定保存
2265                 $gDispManager->save();
2266                         
2267                 // キャッシュリミッタは、各リクエスト毎に(アウトプットバッファー が無効な場合は、
2268                 // session_start()がコールされる 前に) session_cache_limiter()をコールする必要がある。
2269                 // キャッシュを残す設定
2270 //              session_cache_limiter('private');
2271 //              session_cache_expire(5);
2272                 if ($this->isRedirect) return '';                       // リダイレクトの場合は終了
2273
2274                 // ########## HTTPヘッダ出力処理 ########
2275                 if (headers_sent($filename, $linenum)){         // HTTPヘッダが既に送信されているとき
2276                         echo "$filename の $linenum 行目でヘッダがすでに送信されています。";
2277                 } else {
2278                         if ($gEnvManager->isMobile()){          // 携帯の場合
2279                                 // ドコモ端末の場合はリクエストヘッダにXHTMLを指定しないとXHTMLを処理しない
2280                                 $agent = $gInstanceManager->getMobileAgent();
2281                                 if ($agent->isDoCoMo()){        // ドコモ端末のとき
2282                                         header('Content-Type: application/xhtml+xml;');
2283                                 }
2284                         } else {
2285                                 // キャッシュを無効にする場合
2286                                 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');// 過去の日付
2287                                 header('Cache-Control: no-store, no-cache, must-revalidate');// HTTP/1.1
2288                                 header('Cache-Control: post-check=0, pre-check=0', false);
2289                                 header('Pragma: no-cache');
2290                 
2291                                 // 更新日時
2292                                 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
2293                 
2294                                 // 文字コード設定
2295                                 header('Content-Type: text/html; charset=UTF-8');                       // 2018/4/19 Firefoxで文字化けが起きる場合があるので追加
2296                                 
2297                                 // Ajax用JSON型データをHTTPヘッダに格納
2298                                 $gInstanceManager->getAjaxManager()->header();
2299                         }
2300                         // システム制御画面が設定されている場合はステータスコードを変更
2301                         //if ($this->gEnv->getIsMaintenance()){
2302                         if (!$this->isRedirect){                        // リダイレクトがセットされていない場合
2303                                 switch ($this->systemHandleMode){
2304                                         case 10:                        // サイト非公開(システムメンテナンス)
2305                                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
2306                                                 header('Status: 503 Service Temporarily Unavailable');
2307                                                 break;
2308                                         case 11:                        // アクセス禁止のとき
2309                                                 header('HTTP/1.1 403 Forbidden');
2310                                                 header('Status: 403 Forbidden');
2311                                                 break;
2312                                         case 12:                        // 存在しないページのとき
2313                                                 header("HTTP/1.1 404 Not Found");
2314                                                 header("Status: 404 Not Found");
2315                                                 break;
2316                                 }
2317                         }
2318                 }
2319                 // ##### 自動ログイン #####
2320                 $gAccessManager->endAutoLogin();
2321                 
2322                 return $contents;
2323         }
2324         /**
2325          * ページ作成処理中断
2326          *
2327          * 注意)exitSystem()でシステムを終了させる必要あり
2328          *
2329          * @return                                                      なし
2330          */
2331         function abortPage()
2332         {
2333                 global $gInstanceManager;
2334                 global $gRequestManager;
2335                 
2336                 // HTTPヘッダを削除(PHP 5.3以上で有効)
2337                 if (version_compare(PHP_VERSION, '5.3.0') >= 0) header_remove();
2338
2339                 // exit()等でabortPage()が最後の処理になってしまう可能性があるのでなるべく必要な処理を行う
2340                 //if (ob_get_level() > 0) ob_end_clean();// バッファ内容が残っているときは破棄
2341                 while (ob_get_level()) ob_end_clean();  // バッファ削除方法変更(2009/12/2)
2342                 
2343                 // セッションへユーザ情報を保存
2344                 $userInfo = $gInstanceManager->getUserInfo();
2345                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
2346                 
2347                 // その他セッション情報保存
2348                 $gRequestManager->_doSessionCloseEventCallback();
2349                 
2350                 $this->isAbort = true;                                  // ページ作成処理を中断するかどうか
2351         }
2352         /**
2353          * ウィジェット処理中断
2354          *
2355          * @return                                                      なし
2356          */
2357         function abortWidget()
2358         {
2359                 $this->isWidgetAbort = true;                                    // 各ウィジェット処理を中断するかどうか
2360         }
2361         /**
2362          * 強制終了を実行
2363          *
2364          * @return              なし
2365          */
2366         function exitSystem()
2367         {
2368                 global $gEnvManager;
2369                 global $gAccessManager;
2370                 
2371                 // DBが使用可能であれば、アクセスログのユーザを登録
2372                 if ($gEnvManager->canUseDb()) $gAccessManager->accessLogUser();
2373                 
2374                 exit();         // システム終了
2375         }
2376         /**
2377          * Joomla!v1.5タグを読み込んでウィジェット実行
2378          *
2379          * @param string        $srcBuf                 バッファデータ
2380          * @param int           $templateVer    テンプレートバージョン(99=レイアウト用テンプレート、0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
2381          * @return string                                       変換後文字列
2382          */
2383         function launchWidgetByJoomlaTag($srcBuf, $templateVer)
2384         {
2385                 $replace = array();
2386                 $matches = array();
2387                 $destBuf = $srcBuf;
2388                 
2389                 if (preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\s*\/>#iU', $srcBuf, $matches)){
2390                         $count = count($matches[1]);
2391                         for ($i = 0; $i < $count; $i++)
2392                         {
2393                                 $contents = '';
2394                                 $type  = $matches[1][$i];
2395                                 $attr = array();
2396                                 if (strcasecmp($type, 'head') == 0){            // ヘッダ埋め込みタグの場合
2397                                         ob_clean();
2398                                         $this->getHeader();
2399                                         $contents = ob_get_contents();
2400                                 } else if (strcasecmp($type, 'modules') == 0 || strcasecmp($type, 'module') == 0 ||             // 一般ウィジェット用配置ブロックの場合
2401                                                         strcasecmp($type, 'navmenu') == 0){                                                                                     // ナビゲーションメニューウィジェット用配置ブロックの場合
2402                                         $name = '';                     // ポジション名
2403                                         $posType = '';          // ポジションのタイプ
2404                                         $style = '';            // 表示スタイル
2405                                         $params = explode(' ', $matches[2][$i]);
2406                                         $paramArray = array();
2407                                         for ($j = 0; $j < count($params); $j++){
2408                                                 list($key, $value) = explode('=', $params[$j]);
2409                                                 $key = trim($key);
2410                                                 $value = trim($value, "\"'");
2411                                                 if (!empty($key)) $paramArray[$key] = $value;
2412                                         }
2413                                         $value = $paramArray['name'];
2414                                         if (isset($value)){
2415                                                 $name = $value;
2416                                                 $attr['name'] = $value;
2417                                         }
2418                                         $value = $paramArray['type'];           // 配置ブロックのタイプを属性に格納。テンプレート内での参照用。
2419                                         if (isset($value)){
2420                                                 $posType = $value;
2421                                                 $attr['type'] = $value;
2422                                         }
2423                                         $value = $paramArray['id'];
2424                                         if (isset($value)) $attr['id'] = $value;
2425                                         
2426                                         // スタイルが設定されている場合はオプションスタイルを取得
2427                                         $value = $paramArray['style'];
2428                                         if (isset($value)){
2429                                                 $style = $value;
2430                                                 $attr['style'] = $value;
2431                                                 
2432                                                 $optionStyle = $paramArray[$value];             // オプションのスタイル
2433                                                 if (isset($optionStyle)) $attr[$value] = $optionStyle;
2434                                         }
2435 /*                                      for ($j = 0; $j < count($params); $j++){
2436                                                 list($key, $value) = explode('=', $params[$j]);
2437                                                 if (strcasecmp($key, 'name') == 0){
2438                                                         $name = strtolower(trim($value, "\"'"));
2439                                                         $attr['name'] = $name;
2440                                                 } else if (strcasecmp($key, 'style') == 0){
2441                                                         // スタイルは大文字小文字の区別あり
2442                                                         $style = trim($value, "\"'");
2443                                                 } else if (strcasecmp($key, 'artstyle') == 0){          // テンプレート側指定の表示スタイル(Artisteer用)
2444                                                         $attr['artstyle'] = trim($value, "\"'");
2445                                                 } else if (strcasecmp($key, 'bootstyle') == 0){         // テンプレート側指定の表示スタイル(Bootstrap用)
2446                                                         $attr['bootstyle'] = trim($value, "\"'");
2447                                                 } else if (strcasecmp($key, 'drstyle') == 0){           // テンプレート側指定の表示スタイル(Themer用)
2448                                                         $attr['drstyle'] = trim($value, "\"'");
2449                                                 }
2450                                         }*/
2451
2452                                         if (!empty($name)){             // ポジション名が取得できたとき
2453                                                 // Joomla!では、テンプレートの「jdoc:include」タグの属性styleが空のときは「none」で処理される
2454                                                 // Joomla!デフォルトで設定可能なのは「none,table,horz,xhtml,rounded,outline」
2455                                                 // 配置ブロックがナビゲーション型に固定されていない場合はテンプレートの種類によってナビゲーションかどうかを判断
2456                                                 if (strcasecmp($type, 'navmenu') == 0){                                                                                 // メニューウィジェット用配置ブロックの場合
2457                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2458                                                         $attr['type'] = $type;                  // テンプレート内での参照用
2459                                                 } else {
2460                                                         switch ($templateVer){
2461                                                         case 0:                 // デフォルトテンプレート(Joomla!v1.0)
2462                                                         case 1:                 // Joomla!v1.5
2463                                                         case 2:                 // Joomla!v2.5
2464                                                         case 10:                // Bootstrap v3.0
2465                                                         default:
2466                                                                 if (strcasecmp($name, 'user3') == 0 ||          // ナビゲーションメニュー位置の場合
2467                                                                         strcasecmp($name, 'position-1') == 0 ||         // Joomla!v2.5テンプレート対応
2468                                                                         strcasecmp($posType, 'hmenu') == 0){            // Joomla!v3テンプレート対応
2469                                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2470                                                                 }
2471                                                                 break;
2472                                                         case 99:                // レイアウト用テンプレート
2473                                                                 global $gRequestManager;
2474                                                                 static $templateType;           // レイアウト用テンプレートタイプを一度だけ取得
2475                                                                 static $templateGenerator;
2476                                                                 
2477                                                                 if (!isset($templateType)){
2478                                                                         $templateType = 99;
2479                                                                         
2480                                                                         // レイアウト用テンプレートの場合は対象とするテンプレートの情報を取得して判断する
2481                                                                         $pageId         = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
2482                                                                         $pageSubId      = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
2483                                                                 
2484                                                                         // ページ用個別に設定されたテンプレートがある場合は取得
2485                                                                         $curTemplate = '';
2486                                                                         $line = $this->getPageInfo($pageId, $pageSubId);
2487                                                                         if (!empty($line)) $curTemplate = $line['pn_template_id'];
2488                                 
2489                                                                         // 取得できなければデフォルトを取得
2490                                                                         if (empty($curTemplate)){
2491                                                                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
2492                                                                                         $curTemplate = $this->gSystem->defaultTemplateId();
2493                                                                                 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
2494                                                                                         $curTemplate = $this->gSystem->defaultSmartphoneTemplateId();           // スマートフォン用デフォルトテンプレート
2495                                                                                 }
2496                                                                         }
2497                                                                         
2498                                                                         // テンプレートのタイプを取得
2499                                                                         $ret = $this->db->getTemplate($curTemplate, $row);
2500                                                                         if ($ret){
2501                                                                                 $templateType = $row['tm_type'];
2502                                                                                 $templateGenerator = $row['tm_generator'];
2503                                                                         }
2504                                                                 }
2505                                                                 
2506                                                                 if ($templateType != 99){
2507                                                                         // Themlerテンプレート場合は配置ポジション名が「hmenu」をナビゲーション型とする
2508                                                                         if ($templateGenerator == 'themler'){
2509                                                                                 if (strcasecmp($name, 'hmenu') == 0){           // Joomla!v3テンプレート対応
2510                                                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2511                                                                                 }
2512                                                                         } else {
2513                                                                                 if (strcasecmp($name, 'user3') == 0 ||          // ナビゲーションメニュー位置の場合
2514                                                                                         strcasecmp($name, 'position-1') == 0){          // Joomla!v2.5テンプレート対応
2515                                                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2516                                                                                 }
2517                                                                         }
2518                                                                 }
2519                                                                 break;
2520                                                         }
2521                                                 }
2522                                                 if (empty($style)) $style = 'none';
2523                                                 
2524                                                 // ウィジェットの出力を取得
2525                                                 $contents = $this->getContents($name, $style, $templateVer, $attr);
2526                                         }
2527                                 } else if (strcasecmp($type, 'component') == 0){        // メインポジションタグの場合
2528                                         // スタイルを取得
2529                                         $style = '';            // 表示スタイル
2530                                         $params = explode(' ', $matches[2][$i]);
2531                                         for ($j = 0; $j < count($params); $j++){
2532                                                 list($key, $value) = explode('=', $params[$j]);
2533                                                 if (strcasecmp($key, 'style') == 0){
2534                                                         // スタイルは大文字小文字の区別あり
2535                                                         $style = trim($value, "\"'");
2536                                                         break;
2537                                                 }
2538                                         }
2539                                         if ($style != 'none') $style = 'xhtml';
2540                                         $contents = $this->getContents('main', $style, $templateVer, $attr);
2541                                 } else if (strcasecmp($type, 'message') == 0){  // メッセージタグの場合
2542                                 }
2543                                 $replace[$i] = $contents;
2544                         }
2545                         ob_clean();
2546                         $destBuf = str_replace($matches[0], $replace, $srcBuf);
2547                 }
2548                 return $destBuf;
2549         }
2550         /**
2551          * 遅延ウィジェット実行
2552          *
2553          * 遅延実行インデックスのついているウィジェットをインデックス順に実行し、出力バッファデータ内のタグの位置に出力を埋め込む
2554          *
2555          * @param RequestManager $request               HTTPリクエスト処理クラス
2556          * @param string         $srcBuf                バッファデータ
2557          * @return string                                               変換後文字列
2558          */
2559         function lateLaunchWidget($request, $srcBuf)
2560         {
2561                 static $render;         // HTML生成オブジェクト
2562                 global $gEnvManager;
2563                 global $gErrorManager;
2564                 global $gDesignManager;
2565                 
2566                 // ページ作成中断またはウィジェット処理中断のときは終了
2567                 if ($this->isAbort || $this->isWidgetAbort) return '';
2568                 
2569                 // ウィジェットヘッダ(Joomla!1.0用)を出力のタイプを取得
2570                 $widgetHeaderType = $this->getTemplateWidgetHeaderType();
2571                 
2572                 // テンプレートタイプ取得
2573                 $templateVer = $gEnvManager->getCurrentTemplateType();
2574                 
2575                 // 遅延実行ウィジェットをインデックス順にソート
2576                 asort($this->lateLaunchWidgetList, SORT_NUMERIC);
2577                 
2578                 // タグを置換
2579                 $destBuf = $srcBuf;
2580                 foreach ($this->lateLaunchWidgetList as $widgetId => $value){
2581                         // 実行パラメータ取得
2582                         $count = count($this->latelaunchWidgetParam);
2583                         for ($i = 0; $i < $count; $i++){
2584                                 list($wId, $maxNo, $confId, $preId, $serial, $style, $cssStyle, $title, $shared, $exportCss, $position, $index, $pageDefRec) = $this->latelaunchWidgetParam[$i];
2585                                 if ($wId == $widgetId){
2586                                         // パラメータ初期化
2587                                         $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
2588                                         $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
2589                                         $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
2590                                         
2591                                         // 現在のウィジェットのポジション
2592                                         $this->currentWidgetPosition = $position;                       // 現在のウィジェットのポジション
2593                                         $this->currentWidgetIndex = $index;                     // 現在のウィジェットのポジション番号
2594         
2595                                         // バッファ作成
2596                                         ob_start();
2597
2598                                         // ウィジェット実行ファイル取得
2599                                         $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
2600
2601                                         // その他パラメータ取得
2602                                         $configId = $confId;            // ウィジェット定義ID
2603                                         if ($configId == 0) $configId = '';
2604                                         $prefix = $preId;               // サフィックス文字列
2605                         
2606                                         // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
2607                                         $joomlaTitleVisble = false;
2608                                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
2609                                                 if (!empty($title)){
2610                                                         if ($widgetHeaderType == 1){            // PC用ウィジェットヘッダ出力
2611                                                                 echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
2612                                                                 echo '<tr><th>' . $title . '</th></tr>' . M3_NL;
2613                                                                 echo '<tr><td>' . M3_NL;
2614                                                                 $joomlaTitleVisble = true;
2615                                                         } else if ($widgetHeaderType == 2){                     // 携帯用ウィジェットヘッダ出力
2616                                                                 echo '<div>' . $title . '</div>' . M3_NL;
2617                                                                 $joomlaTitleVisble = true;
2618                                                         }
2619                                                 }
2620                                         }
2621                                         // ウィジェットの外枠タグを設定
2622                                         //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
2623                                         // ウィジェット親のCSS定義があるときは、タグを追加
2624                                         if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
2625                                         
2626                                         // ウィジェットの前出力
2627                                         echo $gDesignManager->getAdditionalWidgetOutput(true);
2628                                 
2629                                         // 作業中のウィジェットIDを設定
2630                                         $gEnvManager->setCurrentWidgetId($widgetId);
2631
2632                                         // ウィジェット定義IDを設定
2633                                         $gEnvManager->setCurrentWidgetConfigId($configId);
2634                                         
2635                                         // ページ定義のシリアル番号を設定
2636                                         $gEnvManager->setCurrentPageDefSerial($serial);
2637                 
2638                                         // ページ定義レコードを設定
2639                                         $gEnvManager->setCurrentPageDefRec($pageDefRec);
2640                                 
2641                                         // パラメータを設定
2642                                         $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
2643                 
2644                                         // ウィジェットのタイトルを設定
2645                                         $gEnvManager->setCurrentWidgetTitle('');
2646                                         
2647                                         // ウィジェットのスタイルを設定
2648                                         $gEnvManager->setCurrentWidgetStyle($style);
2649                                 
2650                                         // ウィジェットのグローバル属性状況を設定
2651                                         $gEnvManager->setIsCurrentWidgetShared($shared);
2652                                 
2653                                         // 実行ログを残す
2654                                         $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
2655                                         
2656                                         // ウィジェットを実行
2657                                         // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
2658                                         $msg = 'widget-start(' . $widgetId . ')';
2659                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
2660                                         require($widgetIndexFile);
2661                                         $msg = 'widget-end(' . $widgetId . ')';
2662                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
2663
2664                                         // 作業中のウィジェットIDを解除
2665                                         $gEnvManager->setCurrentWidgetId('');
2666                 
2667                                         // ウィジェット定義IDを解除
2668                                         $gEnvManager->setCurrentWidgetConfigId('');
2669                                         
2670                                         // ページ定義のシリアル番号を解除
2671                                         $gEnvManager->setCurrentPageDefSerial(0);
2672                 
2673                                         // ページ定義レコードを解除
2674                                         $gEnvManager->setCurrentPageDefRec();
2675                                         
2676                                         // パラメータを解除
2677                                         $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
2678                                         
2679                                         // ウィジェットのスタイルを解除
2680                                         $gEnvManager->setCurrentWidgetStyle('');
2681                                         
2682                                         // ウィジェットのグローバル属性状況を解除
2683                                         $gEnvManager->setIsCurrentWidgetShared(false);
2684                                         
2685                                         // ウィジェットのタイトルを取得
2686                                         $newTitle = $gEnvManager->getCurrentWidgetTitle();
2687
2688                                         // ウィジェットの後出力
2689                                         echo $gDesignManager->getAdditionalWidgetOutput(false);
2690                                 
2691                                         // ウィジェット親のCSS定義があるときは、タグを追加
2692                                         if (!empty($cssStyle)) echo '</div>' . M3_NL;
2693                                         // ウィジェットの外枠タグを設定
2694                                         //echo '</div>' . M3_NL;
2695                                         
2696                                         // Joomla!1.0テンプレートのときはタイトルを出力
2697                                         if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用ウィジェットヘッダ出力
2698                                                 echo '</td></tr>' . M3_NL;
2699                                                 echo '</table>' . M3_NL;
2700                                         }
2701                                         
2702                                         // 現在のバッファ内容を取得し、バッファを破棄
2703                                         $srcContents = ob_get_contents();
2704                                         ob_end_clean();
2705                                         
2706                                         // ### テンプレート側のウィジェット生成処理使える場合はウィジェットの出力と入れ替える ###
2707                                         // ### 先のrequire($widgetIndexFile)で必要なデータは作成されている                    ###
2708                                         if ($templateVer >= 1 && $templateVer < 100){           // Joomla!v1.5,v2.5テンプレートのとき
2709                                                 $widgetType = $pageDefRec['wd_type'];           // ウィジェットタイプ
2710                                                 if ($widgetType == 'breadcrumb'){               // パンくずリスト
2711                                                         // 描画オブジェクト作成
2712                                                         if (!isset($render)) $render = new JRender();
2713
2714                                                         $templateContents = $render->getBreadcrumbContents('', '', '', array(), array(), $pageDefRec, $templateVer);                    // テンプレートバージョンのみ必要
2715                                                         if (!empty($templateContents)) $srcContents = $templateContents;
2716                                                 }
2717                                         }
2718
2719                                         // ウィジェットの出力を取得
2720                                         $tag = self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;
2721                                         $destBuf = str_replace($tag, $srcContents, $destBuf);
2722                                         
2723                                         // タイトルの出力
2724                                         if (!empty($newTitle)) $title = $newTitle;
2725                                         $tag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
2726                                         $destBuf = str_replace($tag, $title, $destBuf);
2727                                         
2728                                         // ##### 外部出力用のCSSがある場合は追加 #####
2729                                         if (!empty($exportCss)){
2730                                                 // ウィジェットのタグIDを変換
2731                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $index;                          // ウィジェット識別用ユニークタグ
2732                                                 $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
2733                                                 $this->addExportCss($exportCss);
2734                                         }
2735                                 }
2736                         }
2737                 }
2738                 
2739                 // ##### HTMLヘッダ出力処理 #####
2740                 $destBuf = $this->replaceHead($destBuf);
2741                 
2742                 return $destBuf;
2743         }
2744         /**
2745          * ジョブ実行
2746          *
2747          * @param string $jobType               ジョブタイプ
2748          * @return                                              なし
2749          */
2750         function launchJob($jobType)
2751         {
2752                 global $gEnvManager;
2753                 
2754                 // ジョブタイプから実行するウィジェットIDを取得
2755                 $widgetId = $this->getWidgetIdByJobType($jobType);
2756                 if (empty($widgetId)) return;
2757
2758                 // 作業中のウィジェットIDを設定
2759                 $gEnvManager->setCurrentWidgetId($widgetId);
2760                         
2761                 // 指定のウィジェットを実行
2762                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/admin/job.php';
2763                         
2764                 if (file_exists($widgetIndexFile)){
2765 //                      // 実行のログを残す
2766 //                      $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
2767
2768                         require_once($widgetIndexFile);
2769                 } else {
2770                         echo 'file not found: ' . $widgetIndexFile;
2771                 }
2772                                 
2773                 // 作業中のウィジェットIDを解除
2774                 $gEnvManager->setCurrentWidgetId();
2775         }
2776         /**
2777          * ヘッダ部マクロ変換処理
2778          *
2779          * @param string         $srcBuf                変換元
2780          * @return string                                               変換後文字列
2781          */
2782         function replaceHead($srcBuf)
2783         {
2784                 $destBuf = $srcBuf;
2785
2786                 // ##### ヘッダ部分の置換 #####
2787                 if ($this->outputHead){                         // HTMLヘッダ出力を行っているとき
2788                         $replaceStr = '';
2789                         
2790                         // HTMLヘッダに最初に出力するタグ文字列がある場合は追加
2791                         if (!empty($this->headFirstTag)) $replaceStr .= $this->headFirstTag;
2792                         
2793                         // METAタグcharset等のHTML文書の標準のヘッダタグを出力
2794                         if ($this->outputByStandardHead) $replaceStr .= $this->getStandardHead();
2795                 
2796                         // タグ変換用文字列の取得
2797                         $replaceStr .= $this->getHeaderOutput();
2798                         
2799                         // HTMLヘッダのデータ埋め込み
2800                         $destBuf = str_replace(self::HEAD_TAGS, $replaceStr, $destBuf);
2801                 }
2802                 $this->replaceHeadDone = true;                  // ヘッダマクロ変換処理が完了したかどうか
2803                 return $destBuf;
2804         }
2805         /**
2806          * ヘッダ部マクロ変換を有効にする
2807          *
2808          * @return                                      なし
2809          */
2810         function enableReplaceHead()
2811         {
2812                 $this->outputHead = true;
2813         }
2814         /**
2815          * ウィジェット検索モードの場合のページサブIDの設定
2816          *
2817          * @param RequestManager $request               HTTPリクエスト処理クラス
2818          */
2819         function redirectToUpdatedPageSubId($request)
2820         {
2821                 global $gEnvManager;
2822                 
2823                 // 現在設定されているページIDを取得
2824                 $pageId         = $gEnvManager->getCurrentPageId();
2825                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2826                 
2827                 // 送信元のウィジェットIDを取得
2828                 $fromWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_FROM);
2829                 
2830                 // 対象のウィジェットIDを取得
2831                 $targetWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
2832                 
2833                 // 対象のウィジェットのページサブIDを取得
2834                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2835                 if ($ret){// データが存在する
2836                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2837                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2838                                 if ($ret){// データが存在する
2839                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2840                                         } else {
2841                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2842                                         }
2843                                 }
2844                         } else {
2845                                 // 送信元があるか順にチェック
2846                                 for ($i = 0; $i < count($rows); $i++){
2847                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2848                                         if ($ret){      
2849                                                 break;
2850                                         }
2851                                 }
2852                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2853                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2854                                 } else {
2855                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2856                                 }
2857                         }
2858                 } else {                // 対象のウィジェットが見つからない場合は、互換ウィジェットを探す
2859                         $widgetId = $this->db->getCompatibleWidgetId($targetWidgetId);
2860                         if (!empty($widgetId)){
2861                                 $targetWidgetId = $widgetId;
2862                                 
2863                                 // 対象のウィジェットのページサブIDを取得
2864                                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2865                                 if ($ret){// データが存在する
2866                                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2867                                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2868                                                 if ($ret){// データが存在する
2869                                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2870                                                         } else {
2871                                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2872                                                         }
2873                                                 }
2874                                         } else {
2875                                                 // 送信元があるか順にチェック
2876                                                 for ($i = 0; $i < count($rows); $i++){
2877                                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2878                                                         if ($ret){      
2879                                                                 break;
2880                                                         }
2881                                                 }
2882                                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2883                                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2884                                                 } else {
2885                                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2886                                                 }
2887                                         }
2888                                 }
2889                         }
2890                 }
2891                 // ページサブIDが見つからないときは、既に設定されている値を使用
2892                 // 既に設定されている値は、URL「sub」パラメータで指定されている値か
2893                 // 設定されていない場合はデフォルトのサブページID
2894                 // ********** 指定ページへリダイレクト ***********
2895                 // 実行パラメータ取得
2896                 $todo = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TODO);
2897                 $todo = str_replace(M3_TODO_SEPARATOR, '&', $todo);             // セパレータを変換
2898 //              $redirectUrl = '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2899                 $redirectUrl = $gEnvManager->createPageUrl() . '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2900                 if (!empty($todo)) $redirectUrl .= '&' . $todo;
2901                 if ($gEnvManager->getIsMobileSite()){           // 携帯用アクセスポイントの場合
2902                         $this->redirect($redirectUrl, true/*遷移時のダイアログ表示を抑止*/);
2903                 } else {
2904                         $this->redirect($redirectUrl);
2905                 }
2906         }
2907         /**
2908          * 最終HTML出力処理
2909          *
2910          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2911          * 追加するHTMLは主にウィンドウ制御用のスクリプト
2912          *
2913          * @return string                                       最終HTML
2914          */
2915         function getLastContents()
2916         {
2917                 global $gEnvManager;
2918                 global $gRequestManager;
2919                 
2920                 $contents = '';
2921                 $initScript = '';               // 初期化用スクリプト
2922                 $pageId         = $gEnvManager->getCurrentPageId();
2923                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2924                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2925                 
2926                 if (!$gEnvManager->isSystemManageUser()) return '';             // システム運用権限がない場合は終了
2927                 
2928                 // 処理を行わない場合は終了
2929                 if ($cmd == M3_REQUEST_CMD_RSS ||                                               // RSS配信のときは終了
2930                         $cmd == M3_REQUEST_CMD_DO_WIDGET) return '';            // ウィジェット単体オペレーションのときは出力しない
2931                 
2932                 if ($gEnvManager->getIsMobileSite()) return '';         // 携帯用URLのときは終了
2933                 
2934                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2935                         // ウィジェットレイアウト用カーソル
2936                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
2937 /*                              // テンプレート上のポジション名
2938                                 if (count($this->viewPosId) > 0){
2939                                         $posArrayStr = '[';
2940                                         for ($i = 0; $i < count($this->viewPosId); $i++){
2941                                                 $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
2942                                                 if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
2943                                         }
2944                                         $posArrayStr .= ']';
2945                                         $contents .= 'var M3_POSITIONS=' . $posArrayStr . ';' . M3_NL;
2946                                 }
2947                                 // 画面定義のリビジョン番号
2948                                 $contents .= 'var M3_REVISION=' . $this->pageDefRev . ';' . M3_NL;*/
2949                 
2950                                 // 更新用関数追加
2951                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2952                                 $contents .= M3_INDENT_SPACE . 'window.m3.m3UpdateByConfig(serial);' . M3_NL;
2953                                 $contents .= '}' . M3_NL;
2954                         } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){                       // ウィジェット設定画面
2955                         } else {                // ダッシュボード画面、メイン管理画面
2956                                 // 画面更新用関数追加
2957                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2958                                 $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2959                                 $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2960                                 $contents .= '}' . M3_NL;
2961                         }
2962                         
2963                         // ウィジェット単体実行以外のときの処理
2964                         if (!$this->showWidget){
2965                                 if ($this->updateParentWindow){                 // 管理画面からの親画面の更新
2966                                         $initScript .= M3_INDENT_SPACE . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
2967                                 }
2968                         }
2969                 } else {                // 通常画面のとき
2970                         // 画面更新用関数追加
2971                         $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2972                         $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2973                         $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2974                         $contents .= '}' . M3_NL;
2975                 }
2976
2977                 $destContents = '';
2978                 if (!empty($contents) || !empty($initScript)){
2979 //                      $destContents .= '<script type="text/javascript">' . M3_NL;
2980 //                      $destContents .= '//<![CDATA[' . M3_NL;
2981                         $destContents .= $contents;
2982                         if (!empty($initScript)){               // 初期化用スクリプト
2983                                 $destContents .= '$(function(){' . M3_NL;
2984                                 $destContents .= $initScript;
2985                                 $destContents .= '});' . M3_NL;
2986                         }
2987 //                      $destContents .= '//]]>' . M3_NL;
2988 //                      $destContents .= '</script>' . M3_NL;
2989                 }
2990                 return $destContents;
2991         }
2992         /**
2993          * オプションHTML出力処理
2994          *
2995          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2996          *
2997          * @param RequestManager $request               HTTPリクエスト処理クラス
2998          * @return string                                       最終HTML
2999          */
3000         function getOptionContents($request)
3001         {
3002                 global $gEnvManager;
3003                 
3004                 $contents = '';
3005                 
3006                 // ページ作成中断のときは終了
3007                 if ($this->isAbort) return '';
3008                 
3009                 // AJAX用のレスポンスボディデータのときは終了
3010                 if ($this->outputAjaxResponseBody) return '';
3011                 
3012                 // ウィジェット処理中断のとき
3013                 // AJAXを送信する場合は空文字列では送信できないので、ダミーデータを返す
3014                 if ($this->isWidgetAbort) $contents .= 'NO DATA' . M3_NL;
3015                 
3016                 // Magic3出力コメント
3017                 if (!$gEnvManager->isMobile() && $this->outputByHtml){          // 携帯以外で、HTML出力のとき
3018                         $contents .= '<!-- created by ' . M3_SYSTEM_NAME . ' v' . M3_SYSTEM_VERSION . ' - http://www.magic3.org -->' . M3_NL;
3019                         $contents .= '<!-- convert time: ' . sprintf('%01.03f', microtime(true) - M3_MTIME) . ' -->' . M3_NL;
3020                 }
3021                 return $contents;
3022         }
3023         /**
3024          * Widget単体起動用のHTMLのヘッダ部(headタグ)出力
3025          *
3026          * startWidget(),endWidget()は、以下のコマンドを処理する
3027          *  ・M3_REQUEST_CMD_SHOW_WIDGET(ウィジェットの単体表示)
3028          *  ・M3_REQUEST_CMD_CONFIG_WIDGET(ウィジェット設定画面)
3029          *  ・M3_REQUEST_CMD_CONFIG_TEMPLATE(テンプレート設定画面)
3030          *  ・M3_REQUEST_CMD_DO_WIDGET(ウィジェット単体実行)
3031          * Widgetの出力方法は、以下のパターンがある
3032          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
3033          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
3034          *
3035          * @param string $cmd           起動コマンド
3036          */
3037         function startWidget($cmd)
3038         {
3039                 global $gEnvManager;
3040                 global $gRequestManager;
3041
3042                 // ウィジェット単体表示のときのみ出力
3043                 if (!$this->showWidget) return;
3044
3045                 // パラメータ取得
3046                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
3047                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
3048
3049                 $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
3050                 if (intval($tempVer) >= 2) $this->isHtml5 = true;               // HTML5で出力するかどうか                             
3051                 
3052                 // DOCTYPEの設定
3053                 if ($this->isHtml5){
3054                         echo '<!DOCTYPE html>' . M3_NL;
3055                         echo '<html dir="ltr" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
3056                         echo '<head>' . M3_NL;
3057                 } else {
3058                         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . M3_NL;
3059                         echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $gEnvManager->getCurrentLanguage() . '" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
3060                         echo '<head>' . M3_NL;
3061 //                      echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . M3_NL;
3062                 }
3063
3064                 // HTMLのヘッダ部(headタグ内)出力
3065                 $this->getHeader();
3066
3067                 // ##### 作成対象がウィジェットの場合とテンプレートの場合に分ける #####
3068                 if ($cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){                    // テンプレート設定画面の場合
3069                         $templateId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);// テンプレートID
3070                 } else {
3071                         // 現在のウィジェットを取得
3072                         $widgetId = $gEnvManager->getCurrentWidgetId();         // カレントのウィジェットID
3073                 }
3074                 
3075                 // URLを作成
3076                 if ($gEnvManager->getUseSslAdmin()){
3077                         $rootUrl = $gEnvManager->getSslRootUrl();
3078                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
3079                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
3080                 } else {
3081                         $rootUrl = $gEnvManager->getRootUrl();
3082                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
3083                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
3084                 }
3085
3086                 // ##### テンプレートのCSSの読み込み #####
3087                 // テンプレートは管理用テンプレートに固定されている
3088                 //if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||           // ウィジェット設定のとき
3089                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                           // ウィジェット設定画面またはテンプレート設定画面のとき
3090                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy) && $gEnvManager->isContentEditableUser())){        // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
3091                         $curTemplateUrl = $templatesUrl . '/' . $gEnvManager->getCurrentTemplateId();
3092                         if ($this->isHtml5){
3093                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/style.css" media="screen">' . M3_NL;
3094                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/widget.css" media="screen">' . M3_NL;            // ウィジェット設定画面用CSS
3095                         echo '<!--[if IE]><link rel="stylesheet" href="' . $curTemplateUrl . '/css/iestyles.css" media="screen"><![endif]-->' . M3_NL;
3096                                 echo '<!--[if lt IE 9]><script src="' . $curTemplateUrl . '/html5shiv.js"></script><![endif]-->' . M3_NL;
3097                         } else {
3098                                 echo '<link href="' . $curTemplateUrl . '/css/style.css" rel="stylesheet" type="text/css" />' . M3_NL;
3099                                 echo '<!--[if IE]><link rel="stylesheet" type="text/css" media="screen" href="' . $curTemplateUrl . '/css/iestyles.css" /><![endif]-->' . M3_NL;
3100                         }
3101                 }
3102                 // ウィジェット情報取得
3103                 $ret = $this->db->getWidgetInfo($widgetId, $row);
3104
3105                 // ##### 共通ライブラリ読み込み設定 #####
3106                 if ($cmd == M3_REQUEST_CMD_DO_WIDGET){          // ウィジェット単体実行のとき
3107                         $scritLib = trim($row['wd_add_script_lib']);
3108                         if (!empty($scritLib)) $this->addScript($task, $scritLib);
3109                 }
3110                                 
3111                 // CSS読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
3112                 if ($row['wd_read_css']){
3113                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_CSS;
3114                         if (is_dir($searchPath)){
3115                                 $dir = dir($searchPath);
3116                                 while (($file = $dir->read()) !== false){
3117                                         $filePath = $searchPath . '/' . $file;
3118                                         if ($file != '.' && $file != '..' && is_file($filePath)
3119                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3120                                                 
3121                                                 // CSSへのURLを作成
3122                                                 $cssURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_CSS . '/' . $file;
3123                                                 echo '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3124                                         }
3125                                 }
3126                                 $dir->close();
3127                         }
3128                 }
3129                 
3130                 // スクリプト読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
3131                 if ($row['wd_read_scripts']){
3132                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS;
3133                         if (is_dir($searchPath)){
3134                                 $dir = dir($searchPath);
3135                                 while (($file = $dir->read()) !== false){
3136                                         $filePath = $searchPath . '/' . $file;
3137                                         if ($file != '.' && $file != '..' && is_file($filePath)
3138                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3139                                                 
3140                                                 // スクリプトへのURLを作成
3141                                                 $scriptURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
3142                                                 
3143                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3144                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3145                                                 echo '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3146                                         }
3147                                 }
3148                                 $dir->close();
3149                         }
3150                 }
3151                 // ##### スクリプト用出力用タグを埋め込む #####
3152                 // ウィジェット設定画面用メニューバーの作成
3153                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                           // ウィジェット設定画面またはテンプレート設定画面のとき
3154                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){       // ウィジェット設定画面またはフロント画面編集モードのとき
3155                         echo self::MENUBAR_SCRIPT_TAGS;                 // メニューバー出力用タグ
3156                 }
3157                 
3158                 // ##### 作成対象がウィジェットの場合とテンプレートの場合に分ける #####
3159                 // ウィジェットのタイトルを設定
3160                 if ($cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){                    // テンプレート設定画面の場合
3161                         $title = self::WIDGET_TITLE_START . 'テンプレート' . self::WIDGET_TITLE_END . ' ' . $templateId;
3162                         $gEnvManager->setCurrentWidgetTitle($title);
3163                         echo '<title>' . htmlspecialchars($title) . '</title>' . M3_NL;
3164                 } else {
3165                         $title = $row['wd_name'];
3166                         if (empty($title)) $title = $row['wd_id'];
3167                         $gEnvManager->setCurrentWidgetTitle($title);
3168                         echo '<title>' . self::WIDGET_TITLE_START . htmlspecialchars($title) . self::WIDGET_TITLE_END . '</title>' . M3_NL;
3169                 }
3170                 echo '</head>' . M3_NL;
3171                 
3172                 // タブでウィンドウを開く場合は背景を透過モードにする
3173                 if ($this->isTransparentMode){
3174                         echo '<body style="background-color:transparent;">' . M3_NL;
3175                 } else {
3176                         echo '<body>' . M3_NL;
3177                 }
3178                 // ウィジェット設定画面用メニューバーの作成
3179                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                           // ウィジェット設定画面またはテンプレート設定画面のとき
3180                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){       // ウィジェット設定画面またはフロント画面編集モードのとき
3181                         // ウィジェット情報を設定
3182                         $desc = $row['wd_description'];         // 説明
3183                         $gEnvManager->setCurrentWidgetParams('desc', $desc);
3184                         
3185                         echo self::MENUBAR_TAGS;                        // メニューバー出力用タグ
3186                 }
3187                 // Bootstrap用のタグ出力
3188                 if ($this->useBootstrap) echo '<div class="container">' . M3_NL;
3189                 
3190                 // 別ウィンドウで表示のときは、「閉じる」ボタンを表示
3191                 if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET ||               // ウィジェットの単体表示のとき
3192                         $cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                               // ウィジェット設定画面またはテンプレート設定画面のとき
3193                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){               // ウィジェット単体実行でフロント画面編集モードのとき
3194
3195 //                      if ($this->isEditMode){// フロント画面編集モードのとき
3196                                 if (!empty($openBy)){
3197                                         // サーバ指定されている場合はサーバ情報を取得
3198                                         $serverName = '';
3199                                         $server = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_SERVER);
3200                                         if (!empty($server)){
3201                                                 // 設定データを取得
3202                                                 $ret = $this->db->getServerById($server, $row);
3203                                                 if ($ret){
3204                                                         $serverName = 'サーバ名:' . $row['ts_name'];// サーバ名
3205                                                         echo '<div align="left" style="float:left;padding-left:30px;"><label>' . convertToHtmlEntity($serverName) . '</label></div>';
3206                                                 }
3207                                         }
3208                                         // タブ、インナーフレーム、ダイアログ表示以外のときは「閉じる」ボタンを表示
3209                                         if ($openBy != 'tabs' && $openBy != 'iframe' && $openBy != 'dialog'){           // 以外
3210                                                 if ($openBy == 'logout'){
3211                                                         $titleStr = 'ログアウト';
3212                                                         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 . 
3213                                                                                 '" alt="' . $titleStr . '" /></a></div>' . M3_NL;
3214                                                 } else {
3215                                                         $titleStr = '閉じる';
3216                                                         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 . 
3217                                                                                 '" alt="' . $titleStr . '" /></a></div>' . M3_NL;
3218                                                 }
3219                                         }
3220                                 }
3221                                 // 「前へ」「次へ」ボタン
3222                                 $titleStr = '前へ';
3223                                 echo '<div class="m3configprev" style="display:none;"><a id="m3configprev" href="#"><img src="' . $rootUrl . self::PREV_ICON_FILE . 
3224                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" rel="m3help" /></a></div>' . M3_NL;
3225                                 $titleStr = '次へ';
3226                                 echo '<div class="m3confignext" style="display:none;"><a id="m3confignext" href="#"><img src="' . $rootUrl . self::NEXT_ICON_FILE . 
3227                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" rel="m3help" /></a></div>' . M3_NL;
3228 //                      }
3229                 }
3230                 echo '<!-- Widget Start -->' . M3_NL;
3231         }
3232         /**
3233          * Widget単体起動の終了処理
3234          *
3235          * startWidget(),endWidget()は、以下のコマンドを処理する
3236          *  ・M3_REQUEST_CMD_SHOW_WIDGET(ウィジェットの単体表示)
3237          *  ・M3_REQUEST_CMD_CONFIG_WIDGET(ウィジェット設定画面)
3238          *  ・M3_REQUEST_CMD_CONFIG_TEMPLATE(テンプレート設定画面)
3239          *  ・M3_REQUEST_CMD_DO_WIDGET(ウィジェット単体実行)
3240          *
3241          * @param string $cmd                   起動コマンド
3242          * @param string $srcContent    HTML出力ソース
3243          */
3244         function endWidget($cmd, $srcContent)
3245         {
3246                 global $gDesignManager;
3247                 
3248                 // ウィジェット単体表示のときのみ出力
3249                 if (!$this->showWidget) return;
3250                 
3251                 // メニューバー出力
3252                 // パンくずリストを表示
3253                 $breadcrumbHtml = '';
3254                 if (!empty($this->adminSubNavbarDef)) $breadcrumbHtml .= $gDesignManager->createSubMenubar($this->adminSubNavbarDef);
3255                 if (!empty($this->adminBreadcrumbDef)) $breadcrumbHtml .= $gDesignManager->createAdminBreadcrumb($this->adminBreadcrumbDef);
3256                 $destContent = str_replace(self::MENUBAR_TAGS, $breadcrumbHtml, $srcContent);
3257
3258                 // ヘッドタグ出力
3259                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
3260                 $replaceStr .= '//<![CDATA[' . M3_NL;
3261                 
3262                 // ##### 追加関数 #####
3263                 // ウィジェット設定画面用
3264                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェットの設定管理
3265                         // 画面更新用関数追加
3266                         $replaceStr .= 'function m3UpdateByConfig(serial){' . M3_NL;
3267                         $replaceStr .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
3268                         $replaceStr .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
3269                         $replaceStr .= M3_INDENT_SPACE . 'm3UpdateParentWindow();' . M3_NL;             // 親ウィンドウ更新
3270                         $replaceStr .= '}' . M3_NL;
3271                 
3272                         // IEエラーメッセージ出力抑止
3273                         $replaceStr .= 'function hideIEErrors(){' . M3_NL;
3274                         $replaceStr .= M3_INDENT_SPACE . 'return true;' . M3_NL;
3275                         $replaceStr .= '}' . M3_NL;
3276                         $replaceStr .= 'window.onerror = hideIEErrors;' . M3_NL;
3277                 }
3278                 
3279                 // ##### 初期処理 #####
3280                 $replaceStr .= '$(function(){' . M3_NL;
3281                 // トップ位置修正
3282                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                           // ウィジェット設定画面またはテンプレート設定画面のとき
3283                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){               // フロント画面編集モードのとき
3284                         if (!empty($this->adminSubNavbarDef) || !empty($this->adminBreadcrumbDef)){
3285                                 $menubarHeight = $gDesignManager->getSubMenubarHeight();
3286                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . '$("nav.secondlevel").css("margin-top", "0");' . M3_NL;
3287                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . '$("body").css("padding-top", "' . $menubarHeight . 'px");' . M3_NL;
3288                         }
3289                 }
3290                 // ##### ウィジェットからの指定による処理 #####
3291                 if ($this->updateParentWindow){                 // 親ウィンドウ再描画のとき
3292                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット詳細設定画面のとき
3293                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
3294                         } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){                   // ウィジェット単体実行のとき
3295                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindow();' . M3_NL;
3296                         }
3297                 }
3298                 $replaceStr .= '});' . M3_NL;
3299                 $replaceStr .= '//]]>' . M3_NL;
3300                 $replaceStr .= '</script>' . M3_NL;
3301                 $destContent = str_replace(self::MENUBAR_SCRIPT_TAGS, $replaceStr, $destContent);
3302                 echo $destContent;// 変換したコンテンツを出力
3303                 
3304                 echo '<!-- Widget End -->' . M3_NL;
3305                 
3306                 // Bootstrap用のタグ出力
3307                 if ($this->useBootstrap) echo '</div>' . M3_NL;
3308                 
3309                 echo '</body>' . M3_NL;
3310                 echo '</html>' . M3_NL;
3311         }
3312         /**
3313          * Widget単体RSS出力用のHTMLのヘッダ部(headタグ)出力
3314          *
3315          * Widgetの出力方法は、以下のパターンがある
3316          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
3317          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
3318          *
3319          * @param string $cmd           起動コマンド
3320          */
3321         function startWidgetRss($cmd)
3322         {
3323         }
3324         /**
3325          * Widget単体RSS出力用のタグを閉じる
3326          *
3327          * @param string $cmd                   起動コマンド
3328          * @param string $rssContent    RSS配信内容
3329          */
3330         function endWidgetRss($cmd, $rssContent)
3331         {
3332                 global $gEnvManager;
3333                 
3334                 // ページ作成中断のときは終了
3335                 if ($this->isAbort) return;
3336                 
3337                 echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
3338                 
3339                 // RSSチャンネルデータ取得
3340                 $lang   = $gEnvManager->getCurrentLanguage();
3341                 $date   = getW3CDate();         // RSS1.0用日付
3342                 $copyright = $gEnvManager->getSiteCopyRight();          // 著作権
3343                 $title  = $this->rssChannel['title'];                           // タイトル
3344                 $link   = $this->rssChannel['link'];                            // RSS取得用URL
3345                 $desc   = $this->rssChannel['description'];                     // 説明
3346                 $seq    = $this->rssChannel['seq'];                                     // 項目の並び順(URL)
3347                 
3348                 switch ($this->rssVersion){                                     // RSSバージョン
3349                         case '1.0':
3350                         default:
3351                                 echo '<rdf:RDF xmlns="http://purl.org/rss/1.0/" ';
3352                                 echo 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ';
3353                                 echo 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
3354                                 echo 'xml:lang="' . $lang . '">' . M3_NL;
3355                                 echo '<channel rdf:about="' . convertUrlToHtmlEntity($link) . '">' . M3_NL;
3356                                 echo '<title>' . convertToHtmlEntity($title) . '</title>' . M3_NL;
3357                                 echo '<link>' . convertUrlToHtmlEntity($link) . '</link>' . M3_NL;              // 「convertUrlToHtmlEntity」が必要
3358                                 echo '<description>' . convertToHtmlEntity($desc) . '</description>' . M3_NL;
3359                                 echo '<dc:language>' . $lang . '</dc:language>' . M3_NL;
3360                                 if (!empty($copyright)) echo '<dc:rights>' . convertToHtmlEntity($copyright) . '</dc:rights>' . M3_NL;
3361                                 echo '<dc:date>' . $date . '</dc:date>' . M3_NL;
3362                                 echo '<items>' . M3_NL;
3363                                 if (count($seq) > 0){
3364                                         echo str_repeat(M3_INDENT_SPACE, 1) . '<rdf:Seq>' . M3_NL;
3365                                         for ($i = 0; $i < count($seq); $i++){
3366                                                 echo str_repeat(M3_INDENT_SPACE, 2) . '<rdf:li rdf:resource="' . convertUrlToHtmlEntity($seq[$i]) . '" />' . M3_NL;
3367                                         }
3368                                         echo str_repeat(M3_INDENT_SPACE, 1) . '</rdf:Seq>' . M3_NL;
3369                                 }
3370                                 echo '</items>' . M3_NL;
3371                                 echo '</channel>' . M3_NL;
3372                                 echo $rssContent;
3373                                 echo '</rdf:RDF>' . M3_NL;
3374                                 break;
3375                         case '2.0':
3376                                 break;
3377                 }
3378                 
3379                 // HTTPレスポンスヘッダ設定
3380                 header("Content-type: text/xml; charset=utf-8");
3381         }
3382         /**
3383          * 直サーバ接続時のXML出力用のHTMLのヘッダ部(headタグ)出力
3384          *
3385          * @param string $cmd           起動コマンド
3386          * @return                                      なし
3387          */
3388         function startWidgetXml($cmd)
3389         {
3390                 // HTTPレスポンスヘッダ
3391                 //header("Content-type: text/xml; charset=utf-8");
3392         }
3393         /**
3394          * 直サーバ接続時のXML出力終了
3395          *
3396          * @param string $cmd           起動コマンド
3397          * @return                                      なし
3398          */
3399         function endWidgetXml()
3400         {
3401         }
3402         /**
3403          * 携帯用ドキュメントタイプ出力
3404          *
3405          * @return string                               ドキュメントタイプ出力
3406          */
3407         function getMobileDocType()
3408         {
3409                 global $gEnvManager;
3410                 global $gInstanceManager;
3411                 global $gRequestManager;
3412                 
3413                 $docTypeStr = '';               // 出力するDocType
3414                 $agent = $gInstanceManager->getMobileAgent();
3415                 if ($agent->isDoCoMo()){        // ドコモ端末のとき
3416                         $htmlVer = $agent->getHTMLVersion();
3417                         switch ($htmlVer){
3418                                 case '4.0':
3419                                         $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">';
3420                                         break;
3421                                 case '5.0':
3422                                         $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">';
3423                                         break;
3424                                 case '6.0':
3425                                         $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">';
3426                                         break;
3427                                 case '7.0':
3428                                         $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">';
3429                                         break;
3430                                 case '7.1':
3431                                         $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">';
3432                                         break;
3433                                 case '7.2':
3434                                         $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">';
3435                                         break;
3436                                 default:
3437                                         if (preg_match("/^DoCoMo\/1\.0/i", $gRequestManager->trimServerValueOf('HTTP_USER_AGENT'))){            // mova端末のとき
3438                                                 // mova端末のときはドキュメントタイプなしにすると画面表示可能
3439                                                 return '';
3440                                         }
3441                                         break;
3442                         }
3443                 } else if ($agent->isEZweb()){  // au端末のとき
3444                         if ($agent->isWAP2()){
3445                                 $docTypeStr = '<!DOCTYPE html PUBLIC "-//OPENWAVE//DTD XHTML 1.0//EN" "http://www.openwave.com/DTD/xhtml-basic.dtd">';
3446                         }
3447                 } else if ($agent->isSoftBank()){       // ソフトバンク端末のとき
3448                         if ($agent->isTypeW() || $agent->isType3GC()){
3449                                 $docTypeStr = '<!DOCTYPE html PUBLIC "-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN" "xhtml-basic10-plus.dtd">';
3450                         }
3451                 }
3452                 echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
3453                 if (empty($docTypeStr)) $docTypeStr = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
3454                 echo $docTypeStr . M3_NL;
3455         }
3456         /**
3457          * デフォルトのXML宣言取得
3458          *
3459          * @return string       XML宣言
3460          */
3461         function getDefaultXmlDeclaration()
3462         {
3463                 return '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>';
3464         }
3465         /**
3466          * HTMLのヘッダ部(headタグ内)出力
3467          *
3468          * システムに共通な定義をHTMLのheadタグ内に出力する
3469          * mosFunc.phpからも実行されるので、このメソッドは引数なしに固定。
3470          * この関数は、以下の「形式1」または「形式2」でheadタグ内に記述する
3471          *
3472          * 形式1:            <!-- m3:HTMLHeader -->
3473          * 形式2(old style): <?php mosShowHead(); ?>
3474          */
3475         function getHeader()
3476         {
3477                 // ヘッダタグ変換の設定
3478                 $this->outputHead = true;                               // HTMLヘッダ出力を行ったかどうか
3479                 $this->outputByStandardHead = true;             // HTML文書の標準のヘッダタグを出力するか
3480                 
3481                 // ##### Magic3システムで必要なヘッダ出力用のタグを埋め込む #####
3482                 echo self::HEAD_TAGS;                   // HTMLヘッダの埋め込みデータ
3483         }
3484         /**
3485          * HTML文書の標準のヘッダタグを出力
3486          *
3487          * @return string                       標準ヘッダ文字列
3488          */
3489         function getStandardHead()
3490         {
3491                 global $gEnvManager;
3492                 global $gRequestManager;
3493                 
3494                 $headStr = '';                  // ヘッダ文字列;
3495                 
3496                 // 実行コマンドを取得
3497                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3498                 
3499                 if ($gEnvManager->getIsSmartphoneSite()){               // スマートフォン用サイトのときはHTML5で設定
3500                         $this->isHtml5 = true;
3501                 } else {
3502                         $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
3503                         if (intval($tempVer) >= 2) $this->isHtml5 = true;
3504                 }
3505                 
3506                 // キャラクターセット
3507                 if ($this->isHtml5){
3508                         $headStr .= '<meta charset="' . M3_HTML_CHARSET . '">' . M3_NL;
3509                 } else {
3510                         $headStr .= '<meta http-equiv="content-script-type" content="text/javascript" />' . M3_NL;
3511                         $headStr .= '<meta http-equiv="content-style-type" content="text/css" />' . M3_NL;
3512                         $headStr .= '<meta http-equiv="content-type" content="application/xhtml+xml; charset=' . M3_HTML_CHARSET .'" />' . M3_NL;
3513                 }
3514                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3515                         // Bootstrapで必要なMETAタグを追加
3516                         $headStr .= '<meta name="viewport" content="width=device-width, initial-scale=1">' . M3_NL;
3517                 }
3518                 
3519                 // 基準ディレクトリの指定
3520                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
3521                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
3522                 
3523                         if ($gEnvManager->getUseSslAdmin()){
3524                                 $rootUrl = $gEnvManager->getSslRootUrl();
3525                         } else {
3526                                 $rootUrl = $gEnvManager->getRootUrl();
3527                         }
3528                         $headStr .= '<base href="' . $rootUrl . '/" />' . M3_NL;
3529                 }
3530                 return $headStr;
3531         }
3532         /**
3533          * HTMLヘッダ出力文字列の取得
3534          *
3535          * @return string               HTMLヘッダ出力文字列
3536          */
3537         function getHeaderOutput()
3538         {
3539                 global $gEnvManager;
3540                 global $gRequestManager;
3541                 global $gInstanceManager;
3542                 global $gSystemManager;
3543
3544                 $replaceStr = '';               // 変換文字列
3545                 
3546                 // 実行コマンドを取得
3547                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3548                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
3549                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
3550                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
3551                 
3552                 // ********************************************************
3553                 //               ヘッダ文字列作成の前処理
3554                 // ********************************************************
3555                 // ##### テンプレートの設定、フレームの設定から必要なライブラリを取得 #####
3556                 // Bootstrapライブラリ
3557 //              if (!$this->useBootstrap) $this->useBootstrap = $gEnvManager->getCurrentTemplateUseBootstrap();
3558                 if ($this->useBootstrap){
3559                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3560                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
3561                                         $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
3562                                         if ($cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)以外のとき
3563                                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
3564                                         } else {
3565                                                 // テンプレートタイプが管理画面のBootstrapバージョン(v3.0)と異なる場合はBootstrapを使用しない場合の管理機能用スクリプトを読み込む
3566                                                 $templateType = $gEnvManager->getCurrentTemplateType();
3567                                                 if ($templateType != 10) $this->addAdminScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);             // Bootstrapを使用しない場合の管理機能用スクリプト
3568                                         }
3569                                 } else {                // ログインしていない場合(ログイン画面等)
3570                                         $this->addPermittedAdminScript(ScriptLibInfo::LIB_BOOTSTRAP);
3571                                         $this->addPermittedAdminScript(ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);// Bootstrap管理画面オプション
3572                                 }
3573                         } else {                // フロント画面へのアクセスの場合
3574                                 // ### Bootstrapのjsとcssはテンプレート側で読み込む ###
3575                                 // ### フロントからプレビューコマンドでログイン画面を表示させるパターンがあるので注意 ###
3576 //                              if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW ||                          // ログイン、ログアウト場合
3577                                 if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || ($cmd == M3_REQUEST_CMD_PREVIEW && !$gEnvManager->isCurrentUserLogined()) ||                               // ログイン、ログアウト場合
3578                                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy) && $gEnvManager->isContentEditableUser())){                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
3579                                         
3580                                         $this->addScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);               // Bootstrap管理画面オプション
3581                                 } else {
3582                                         if ($gEnvManager->isSystemManageUser() ||               // システム運用権限がある場合
3583                                                 $gEnvManager->isContentEditableUser()){         // 投稿ユーザの場合
3584                                                 // テンプレートタイプが管理画面のBootstrapバージョン(v3.0)と異なる場合はBootstrapを使用しない場合の管理機能用スクリプトを読み込む
3585                                                 $templateType = $gEnvManager->getCurrentTemplateType();
3586                                                 if ($templateType != 10) $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);          // Bootstrapを使用しない場合の管理機能用スクリプト
3587                                         }
3588                                 }
3589                         }
3590                 } else {
3591                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
3592                                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3593                                         $this->addAdminScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);              // Bootstrapを使用しない場合の管理機能用スクリプト
3594                                 } else {
3595                                         $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
3596                                 }
3597                         } else if ($gEnvManager->isContentEditableUser()){              // 投稿ユーザの場合
3598                                 $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
3599                         }
3600                 }
3601                 
3602                 // ********************************************************
3603                 //               ヘッダ文字列作成処理
3604                 // ********************************************************
3605                 // ##### インストール時のヘッダ出力 #####
3606                 if (defined('M3_STATE_IN_INSTALL')){
3607                         // タイトルの作成
3608                         $title = '';
3609                         if (count($this->headSubTitle) > 0) $title = htmlspecialchars(trim($this->headSubTitle[0]));
3610                         
3611                         // ********** メタタグの設定 **********
3612                         $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
3613                         
3614                         // ##### インストーラ用のファイルの読み込み #####
3615                         $scriptsUrl = '../scripts';
3616                         
3617                         // 管理機能用共通ライブラリのCSSの読み込み
3618                         $count = count($this->defaultAdminCssFiles);
3619                         for ($i = 0; $i < $count; $i++){
3620                                 // CSSへのURLを作成
3621                                 $cssFilename = $this->defaultAdminCssFiles[$i];
3622                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3623                                         $cssURL = $cssFilename;
3624                                 } else {
3625                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
3626                                 }
3627                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3628                         }
3629                         
3630                         // 管理画面用の共通スクリプトを読み込む
3631                         $count = count($this->defaultAdminScriptFiles);
3632                         for ($i = 0; $i < $count; $i++){
3633                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
3634
3635                                 // スクリプトのURLを修正
3636                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3637                                         $scriptURL = $scriptFilename;
3638                                         
3639                                         // SSLをページの状態に合わせる
3640                                         if ($isSslPage){
3641                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3642                                         } else {
3643                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3644                                         }
3645                                 } else {
3646                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3647                                 }
3648                         
3649                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3650                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3651                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3652                         }
3653                         
3654                         // ##### ページへJavascriptの埋め込む #####
3655                         // JavaScriptグローバル変数の設定
3656                         $rootUrl = $gEnvManager->getRootUrl();
3657                         if (empty($rootUrl)) $rootUrl = $gEnvManager->calcSystemRootUrl();
3658                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3659                         $replaceStr .= '//<![CDATA[' . M3_NL;
3660                         $replaceStr .= '// Magic3 Global values' . M3_NL;
3661                         if (!empty($rootUrl)) $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;           // システムルートURL
3662                         $replaceStr .= '//]]>' . M3_NL;
3663                         $replaceStr .= '</script>' . M3_NL;
3664                         return $replaceStr;
3665                 }
3666                 
3667                 // テンプレートの情報を取得
3668                 $cleanType = $gEnvManager->getCurrentTemplateCleanType();               // テンプレートクリーンタイプ
3669 /*              if ($this->db->getTemplate($gEnvManager->getCurrentTemplateId(), $templateRow)){
3670                         $cleanType = $templateRow['tm_clean_type'];
3671                 }*/
3672                 
3673                 // URLの作成
3674                 $isSslPage = false;
3675                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3676                         // 管理画面のSSL状態を参照
3677                         if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
3678                 } else {
3679                         $isSslPage = $this->isSslPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
3680                 }
3681                 if ($isSslPage){
3682                         $rootUrl = $gEnvManager->getSslRootUrl();
3683                         $scriptsUrl = $gEnvManager->getSslScriptsUrl();         // スクリプト読み込み用パス
3684                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
3685                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
3686                 } else {
3687                         $rootUrl = $gEnvManager->getRootUrl();
3688                         $scriptsUrl = $gEnvManager->getScriptsUrl();            // スクリプト読み込み用パス
3689                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
3690                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
3691                 }
3692
3693                 // タイトルの設定
3694                 if (!$this->showWidget){// 単体実行以外のとき
3695                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスの場合
3696                                 // 管理画面のタイトル
3697                                 // メイン画面は「サイト名 - 管理画面」、サブ画面は個別画面名
3698                                 $siteName = $gEnvManager->getSiteName();
3699 //                              if (empty($siteName)) $siteName = self::DEFAULT_SITE_NAME;
3700                                 $title = $siteName . ' - ' . self::DEFAULT_ADMIN_TITLE;
3701                                 $titleCount = count($this->headSubTitle);
3702                                 if ($titleCount > 0) $title = $this->headSubTitle[$titleCount -1];              // サブタイトルが設定されている場合は変更
3703                                 $replaceStr .= '<title>' . htmlspecialchars($title) . '</title>' . M3_NL;
3704                                 
3705                                 // その他HTMLヘッダに出力するタグ文字列
3706                                 if (!empty($this->adminHeadOthers)){
3707                                         // マクロを変換
3708                                         $this->adminHeadOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->adminHeadOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
3709                                         $replaceStr .= $this->adminHeadOthers . M3_NL;
3710                                 }
3711                         } else {                        // 管理画面以外の画面へのアクセスの場合
3712                                 // 画面タイトル
3713                                 $titleItemCount = 0;            // タイトル項目数
3714                                 $defaultTitle = trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_TITLE));
3715                                 if (!empty($defaultTitle)) $titleItemCount++;
3716                                 if (!empty($this->headSubTitle)){               // サブタイトルが設定されているとき
3717                                         $titleItemCount += count($this->headSubTitle);
3718                                 }
3719                                 // タイトルフォーマットを取得
3720                                 $title = '';
3721                                 if ($titleItemCount > 0){
3722                                         $format = $this->gSystem->getSystemConfig(self::CONFIG_KEY_HEAD_TITLE_FORMAT);
3723                                         if (empty($format)){
3724                                                 $title = htmlspecialchars($defaultTitle);
3725                                         } else {
3726                                                 $formats = explode(';', $format);
3727                                                 $titleItemCount = ($titleItemCount > count($formats)) ? count($formats) : $titleItemCount;
3728                                                 $title = $formats[$titleItemCount -1];
3729                                                 $number = 1;
3730                                                 if (!empty($defaultTitle)){
3731                                                         $title = str_replace('$1', htmlspecialchars($defaultTitle), $title);
3732                                                         $number++;
3733                                                 }
3734                                                 for ($i = 0; $i < count($this->headSubTitle); $i++){
3735                                                         $key = '$' . $number;
3736                                                         $value = htmlspecialchars(trim($this->headSubTitle[$i]));
3737                                                         $title = str_replace($key, $value, $title);
3738                                                         $number++;
3739                                                 }
3740                                         }
3741                                 }
3742                                 if (!empty($title)) $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
3743
3744                                 // サイトの説明
3745                                 if (!empty($this->headDescription)) $replaceStr .= '<meta name="description" content="' . htmlspecialchars($this->headDescription) . '" />' . M3_NL;
3746                 
3747                                 // 検索エンジン用キーワード
3748                                 if (!empty($this->headKeywords)) $replaceStr .= '<meta name="keywords" content="' . htmlspecialchars($this->headKeywords) . '" />' . M3_NL;
3749                                 
3750                                 // その他HTMLヘッダに出力するタグ文字列
3751                                 if (!empty($this->headOthers)){
3752                                         // マクロを変換
3753                                         $this->headOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->headOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
3754                                         $replaceStr .= $this->headOthers . M3_NL;
3755                                 }
3756                         }
3757                 }
3758                 
3759                 // ##### PC用URLと携帯用URLのアクセス別に処理 #####
3760                 if ($gEnvManager->getIsMobileSite()){           // 携帯用URLのとき
3761                 } else {                        // PC用URLまたはスマートフォン用URLのとき
3762                         // ##### テンプレート情報に応じた処理 #####
3763                         // テンプレートクリーンが必要な場合はJQueryを追加
3764                         if ($cleanType != 0) $this->addScriptFile($this->selectedJQueryFilename);               // JQueryスクリプト追加
3765                         
3766                         // 検索ロボットへの指示
3767                         $robots = htmlspecialchars(trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_ROBOTS)));
3768                         if (!empty($robots)){
3769                                 $replaceStr .= '<meta name="robots" content="' . $robots . '" />' . M3_NL;
3770                         }
3771                 
3772                         // サイト構築エンジン
3773                         $replaceStr .= '<meta name="generator" content="' . M3_SYSTEM_NAME . ' ver.' . M3_SYSTEM_VERSION . ' - ' . M3_SYSTEM_DESCRIPTION . '" />' . M3_NL;              
3774
3775                         // カノニカル属性、Faviconの読み込み
3776                         $templateId = $gEnvManager->getCurrentTemplateId();
3777                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3778                                 // テンプレートのFaviconがない場合はシステムのデフォルトのFaviconを使用
3779                                 $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3780                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
3781                                         $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3782                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3783                                 } else {
3784                                         // 管理画面のアイコンを設定
3785                                         $faviconPath = $gEnvManager->getSystemRootPath() . self::DEFAULT_ADMIN_FAVICON_FILE;
3786                                         if (file_exists($faviconPath)){         // ファイルが存在しているとき
3787                                                 $faviconFile = $rootUrl . self::DEFAULT_ADMIN_FAVICON_FILE;
3788                                                 $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3789                                         }
3790                                 }
3791                         } else {
3792                                 // カノニカル属性
3793                                 if (!empty($this->headCanonicalUrl)) $replaceStr .= '<link rel="canonical" href="' . convertUrlToHtmlEntity($this->headCanonicalUrl) .'" />' . M3_NL;                           // カノニカル属性URL
3794                                 
3795                                 // Favicon
3796                                 $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3797                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
3798                                         $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3799                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3800                                 }
3801                         }
3802                         // ##### 追加ライブラリの読み込み #####
3803                         if ($gEnvManager->getIsSmartphoneSite()){                       // スマートフォン用URLのとき
3804                                 $value = $gSystemManager->getSystemConfig(self::CF_SMARTPHONE_USE_JQUERY_MOBILE);// スマートフォン画面で常にjQuery Mobileを使用
3805                                 if ($value){
3806                                         // ##### jQueryMobileが読み込まれる前に読み込む必要があるスクリプトを設定 #####
3807                                         if (!empty($this->headPreMobileScriptFiles)){           // jQueryMobileファイルの前に出力
3808                                                 for ($l = 0; $l < count($this->headPreMobileScriptFiles); $l++){
3809                                                         $this->addScriptFile($this->headPreMobileScriptFiles[$l]);              // 通常機能用のスクリプト追加
3810                                                 }
3811                                         }
3812                                         $this->addScriptFile($this->selectedJQueryMobileFilename);
3813                                 }
3814                         }
3815                         
3816                         // ##### Ajaxライブラリの読み込み #####
3817                         if (!$gEnvManager->isAdminDirAccess()){         // 通常画面へのアクセスのとき
3818                                 if ($this->db->isExistsWidgetWithAjax($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId())){// Ajaxライブラリを使用しているウィジェットがあるときは追加
3819                                         $this->addScriptFile($this->selectedJQueryFilename);            // デフォルトAjaxライブラリ追加
3820                                         $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
3821                                 }
3822                         }
3823                                 
3824                         // ##### 共通ライブラリの読み込み #####
3825                         if (!$this->showWidget){// 単体実行以外のとき
3826                                 $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3827                                 for ($i = 0; $i < count($rows); $i++){
3828                                         $this->addScript($task, trim($rows[$i]['wd_add_script_lib']));
3829                                 }
3830                         }
3831
3832                         // ##### 共通CSS読み込み #####
3833                         if (($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()) || $this->isEditMode){                     // フロント画面編集モード
3834                                 $cssURL = $scriptsUrl . '/' . self::M3_EDIT_CSS_FILE;
3835                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3836                         }
3837                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3838                                 //if ($gEnvManager->isSystemAdmin()){           // 管理者権限がある場合のみ有効
3839                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3840                                         // 管理機能用共通ライブラリのCSSの読み込み
3841                                         $count = count($this->defaultAdminCssFiles);
3842                                         for ($i = 0; $i < $count; $i++){
3843                                                 // CSSへのURLを作成
3844                                                 //$cssURL = $scriptsUrl . '/' . $this->defaultAdminCssFiles[$i];
3845                                                 $cssFilename = $this->defaultAdminCssFiles[$i];
3846                                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3847                                                         $cssURL = $cssFilename;
3848                                                 } else {
3849                                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
3850                                                 }
3851                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3852                                         }
3853                                 } else {
3854                                         // 管理権限なしで管理ディレクトリアクセスで必要なCSSファイルを読み込む
3855                                         $count = count($this->defaultAdminDirCssFiles);
3856                                         for ($i = 0; $i < $count; $i++){
3857                                                 // CSSへのURLを作成
3858                                                 $cssURL = $scriptsUrl . '/' . $this->defaultAdminDirCssFiles[$i];
3859                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3860                                         }
3861                                 }
3862                         } else {
3863                                 // 共通ライブラリのCSSの読み込み
3864                                 $count = count($this->defaultCssFiles);
3865                                 for ($i = 0; $i < $count; $i++){
3866                                         // CSSへのURLを作成
3867                                         $cssFilename = $this->defaultCssFiles[$i];
3868                                         if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3869                                                 $cssURL = $cssFilename;
3870                                         } else {
3871                                                 $cssURL = $scriptsUrl . '/' . $cssFilename;
3872                                         }
3873                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3874                                 }
3875                         }
3876                         
3877                         // ##### 表示モードによるCSS読み込み #####
3878                         // ウィジェット付きポジション画面は管理画面のアクセスではない
3879                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
3880                                 // ウィジェット操作用CSS
3881                                 $cssURL = $scriptsUrl . self::M3_ADMIN_WIDGET_CSS_FILE;
3882                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3883                         }
3884                         
3885                         // ##### ウィジェットごとのCSS読み込み #####
3886                         // CSSがあるウィジェットを取得
3887                         $this->db->getWidgetsIdWithCss($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3888                         for ($i = 0; $i < count($rows); $i++){
3889                                 $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS;
3890                                 // ディレクトリがあるときはディレクトリ内読み込み
3891                                 if (is_dir($searchPath)){
3892                                         $dir = dir($searchPath);
3893                                         while (($file = $dir->read()) !== false){
3894                                                 $filePath = $searchPath . '/' . $file;
3895                                                 if ($file != '.' && $file != '..' && is_file($filePath)
3896                                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3897                                         
3898                                                         // CSSへのURLを作成
3899                                                         $cssURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS . '/' . $file;
3900                                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3901                                                 }
3902                                         }
3903                                         $dir->close();
3904                                 }
3905                         }
3906                         // ##### 外部出力用CSS読み込み #####
3907                         // ウィジェットからの追加のCSS読み込み
3908                         $count = count($this->headCssFiles);
3909                         for ($i = 0; $i < $count; $i++){
3910                                 $cssUrl = $this->headCssFiles[$i];
3911                                 if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3912                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . convertUrlToHtmlEntity($cssUrl) . '" />' . M3_NL;
3913                         }
3914                         
3915                         // 外部出力用CSSデータがある場合はURLを追加
3916                         if (!empty($this->exportCss)){
3917                                 $cssUrl = $this->createCssCmdUrl($isSslPage, date('YmdHis'));
3918                                 if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3919                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . convertUrlToHtmlEntity($cssUrl) . '" />' . M3_NL;
3920                         }
3921                         
3922                         // ##### RSS配信情報の読み込み #####
3923                         $count = count($this->headRssFiles);
3924                         for ($i = 0; $i < $count; $i++){
3925                                 $rssUrl = $this->headRssFiles[$i]['href'];// リンク先URL
3926                                 $rssTitle = $this->headRssFiles[$i]['title'];// タイトル
3927                                 $replaceStr .=  '<link rel="alternate" type="application/rss+xml" title="' . $rssTitle . '" href="' . convertUrlToHtmlEntity($rssUrl) . '" />' . M3_NL;
3928                         }
3929                                                                         
3930                         // ##### 共通Javascriptの読み込み #####
3931                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3932                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3933                                         // 管理画面用の共通スクリプトを読み込む
3934                                         $count = count($this->defaultAdminScriptFiles);
3935                                         for ($i = 0; $i < $count; $i++){
3936                                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
3937
3938                                                 // スクリプトのURLを修正
3939                                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3940                                                         $scriptURL = $scriptFilename;
3941                                                         
3942                                                         // SSLをページの状態に合わせる
3943                                                         if ($isSslPage){
3944                                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3945                                                         } else {
3946                                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3947                                                         }
3948                                                 } else {
3949                                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3950                                                 }
3951                                         
3952                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3953                                                 //$scriptURL = $scriptsUrl . '/' . $scriptFilename;
3954                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3955                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3956                                         }
3957                                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示のときは、ウィジェット操作ライブラリを読み込む
3958                                                 // wigetのドラッグドロップ用
3959                                                 $scriptURL = $scriptsUrl . '/' . self::M3_ADMIN_WIDGET_SCRIPT_FILENAME;
3960                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();// スクリプトをキャッシュ保存しない場合は、パラメータを付加
3961                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3962                                         }
3963                                 } else {                // システム運用権限がない場合
3964                                         // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
3965                                         $count = count($this->defaultAdminDirScriptFiles);
3966                                         for ($i = 0; $i < $count; $i++){
3967                                                 $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
3968
3969                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3970                                                 $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3971                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3972                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3973                                         }
3974                                 }
3975                         } else {                        // 通常画面
3976                                 // Googleマップライブラリの読み込み
3977                                 if ($this->useGooglemaps && $this->isContentGooglemaps) $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));  // コンテンツにGoogleマップが含むかどうか
3978
3979                                 $useExternalJquery = $gSystemManager->getSystemConfig(self::CF_EXTERNAL_JQUERY);                // システム外部のjQueryを使用するかどうか
3980                                 
3981                                 $count = count($this->defaultScriptFiles);
3982                                 for ($i = 0; $i < $count; $i++){
3983                                         $defaultScriptFile = $this->defaultScriptFiles[$i];
3984
3985                                         // 外部のjQueryを使用する場合はSCRIPTタグを出力しない
3986                                         if ($defaultScriptFile == $this->selectedJQueryFilename && $useExternalJquery) continue;
3987                                         
3988                                         // ##### jQueryMobileスクリプトを追加する場合は直前に初期化スクリプトを追加 #####
3989                                         if ($defaultScriptFile == $this->selectedJQueryMobileFilename){
3990                                                 if (count($this->headPreMobileScript) > 0){
3991                                                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3992                                                         $replaceStr .= '//<![CDATA[' . M3_NL;
3993                                                         for ($j = 0; $j < count($this->headPreMobileScript); $j++){
3994                                                                 $replaceStr .= $this->headPreMobileScript[$j];
3995                                                         }
3996                                                         $replaceStr .= M3_NL;
3997                                                         $replaceStr .= '//]]>' . M3_NL;
3998                                                         $replaceStr .= '</script>' . M3_NL;
3999                                                 }
4000                                         }
4001                                         
4002                                         // スクリプトのURLを修正
4003                                         if (strncasecmp($defaultScriptFile, 'http://', 7) == 0 || strncasecmp($defaultScriptFile, 'https://', 8) == 0){
4004                                                 $scriptURL = $defaultScriptFile;
4005                                                 
4006                                                 // SSLをページの状態に合わせる
4007                                                 if ($isSslPage){
4008                                                         $scriptURL = str_replace('http://', 'https://', $scriptURL);
4009                                                 } else {
4010                                                         $scriptURL = str_replace('https://', 'http://', $scriptURL);
4011                                                 }
4012                                         } else {
4013                                                 $scriptURL = $scriptsUrl . '/' . $defaultScriptFile;
4014                                         }
4015
4016                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
4017                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
4018                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
4019                                 }
4020                                 
4021                                 // ### フロントからプレビューコマンドでログイン画面を表示させるパターンがあるので注意 ###
4022 //                              if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW){                           // ログイン、ログアウト場合
4023                                 if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || ($cmd == M3_REQUEST_CMD_PREVIEW && !$gEnvManager->isCurrentUserLogined())){                                // ログイン、ログアウト場合
4024                                         // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
4025                                         $count = count($this->defaultAdminDirScriptFiles);
4026                                         for ($i = 0; $i < $count; $i++){
4027                                                 $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
4028                                                 if (!in_array($scriptFilename, $this->defaultScriptFiles)){             // 既に追加されていない場合のみ追加
4029                                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
4030                                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
4031                                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
4032                                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
4033                                                 }
4034                                         }
4035                                 }
4036                                 
4037                                 // ***** [WordPressテンプレート] jQueryの読み込み後、ヘッダ部に出力するテンプレート用のJavascriptがあれば読み込む *****
4038                                 $headData = $this->gEnv->getWpHeadScriptsData();
4039                                 if (!empty($headData)) $replaceStr .= $headData;
4040                         }
4041                         // ##### ウィジェットごとのJavaScript読み込み #####
4042                         // スクリプトがあるウィジェットを取得
4043                         $this->db->getWidgetsIdWithScript($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
4044                         for ($i = 0; $i < count($rows); $i++){
4045                                 $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS;
4046                         
4047                                 // ディレクトリがあるときはディレクトリ内読み込み
4048                                 if (is_dir($searchPath)){
4049                                         $dir = dir($searchPath);
4050                                         while (($file = $dir->read()) !== false){
4051                                                 $filePath = $searchPath . '/' . $file;
4052                                                 if ($file != '.' && $file != '..' && is_file($filePath)
4053                                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
4054                                                 
4055                                                         // スクリプトへのURLを作成
4056                                                         $scriptURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
4057                                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
4058                                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
4059                                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
4060                                                 }
4061                                         }
4062                                         $dir->close();
4063                                 }
4064                         }
4065                         // ウィジェットからの追加のCSS読み込み
4066                         $count = count($this->headScriptFiles);
4067                         for ($i = 0; $i < $count; $i++){
4068                                 $scriptUrl = $this->headScriptFiles[$i];
4069                                 if ($isSslPage) $scriptUrl = str_replace('http://', 'https://', $scriptUrl);                    // SSL化が必要なときは変換
4070                 
4071                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
4072                                 if (!$this->hasScriptCache) $scriptUrl .= $this->getCacheParam();
4073                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptUrl) . '"></script>' . M3_NL;
4074                         }
4075                         
4076                         // 設定値取得
4077                         $openType = $this->gSystem->getSystemConfig(self::CF_CONFIG_WINDOW_OPEN_TYPE);// ウィジェット設定画面のウィンドウ表示タイプ(0=別ウィンドウ、1=タブ)
4078                         
4079                         // ##### ページへJavascriptの埋め込む #####
4080                         // JavaScriptグローバル変数の設定
4081                         //$replaceStr .= '<script type="text/javascript">' . M3_NL;
4082                         //$replaceStr .= '<!--' . M3_NL;
4083                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
4084                         $replaceStr .= '//<![CDATA[' . M3_NL;
4085                         $replaceStr .= '// Magic3 Global values' . M3_NL;
4086                         $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;         // システムルートURL
4087
4088                         if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()){            // 管理画面へのアクセス、システム運用権限があり
4089                                 $pageId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);          // ページID
4090                                 $pageSubId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);// ページサブID
4091                                         
4092                                 // 管理画面のオープン設定
4093                                 $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
4094                                 if ($openType != '') $replaceStr .= 'var M3_CONFIG_WINDOW_OPEN_TYPE = ' . $openType . ';' . M3_NL;
4095                                 
4096                                 // ページID、ページサブID
4097                                 $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
4098                                 $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
4099                                 // WYSIWYGエディター
4100                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4101                                 
4102                                 // ファイルブラウザ
4103                                 $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;           // バージョン
4104                                 $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4105                                 $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4106         
4107                                 // Googleマップライブラリの読み込み
4108                                 if ($this->useGooglemaps){
4109                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
4110                                         
4111                                         // CKEditor拡張プラグイン用の定義
4112                                         $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
4113                                         if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
4114                                 } else {
4115                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
4116                                 }
4117
4118                                 // 起動がパーソナルモードかどうか
4119                                 if ($this->isPersonalMode){
4120                                         $replaceStr .= 'var M3_PERSONAL_MODE = true;' . M3_NL;
4121                                 } else {
4122                                         $replaceStr .= 'var M3_PERSONAL_MODE = false;' . M3_NL;
4123                                 }
4124                                 // 管理画面の小画面デバイス最適化を行うかどうか
4125                                 if ($gEnvManager->isSmallDeviceAdmin()){
4126                                         $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = true;' . M3_NL;
4127                                 } else {
4128                                         $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = false;' . M3_NL;
4129                                 }
4130                                 
4131                                 // ウィジェット詳細設定画面専用のJavaScriptグローバル変数
4132                                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){
4133                                 //if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){                                          // ウィジェット設定画面またはテンプレート設定画面のとき
4134                                         // ##### CKEditor用の設定 #####
4135                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
4136                                         
4137                                         // CKEditor用のCSSファイル
4138                                         if (!empty($this->ckeditorCssFiles)){
4139                                                 // 編集エリア用のCSSファイルを追加
4140                                                 $this->ckeditorCssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4141                                                 //array_unshift($this->ckeditorCssFiles, $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE);
4142                                                 
4143                                                 //$fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $this->ckeditorCssFiles));
4144                                                 $fileList = implode(', ', array_map(function($a){ return "'" . $a . "'"; }, $this->ckeditorCssFiles));
4145                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4146                                         }
4147                                         // CKEditor用(レイアウト)のCSSファイル
4148                                         $cssFiles = array();
4149                                         $cssFiles[] = $scriptsUrl . '/' . ScriptLibInfo::BOOTSTRAP_ADMIN_CSS;           // BootstrapのCSSを追加
4150                                         $cssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4151 //                                      $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $cssFiles));
4152                                         $fileList = implode(', ', array_map(function($a){ return "'" . $a . "'"; }, $cssFiles));
4153                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_LAYOUT_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4154                                         
4155                                         // CKEditor用のテンプレートタイプ
4156                                         if (isset($this->ckeditorTemplateType)){
4157                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_TEMPLATE_TYPE = ' . $this->ckeditorTemplateType . ';' . M3_NL;
4158                                         }
4159                                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION){               // ポジション表示
4160                                         $replaceStr .= 'var M3_POSITION_DATA = "' . implode(',', $this->defPositions) . '";' . M3_NL;                   // 管理画面画面の端末タイプ(主にテスト用に使用)
4161                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = 0;' . M3_NL;                 // 管理画面画面の端末タイプ(主にテスト用に使用)
4162                                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // ウィジェット付きポジション表示
4163                                         // その他のポジションデータを取得
4164                                         $positionData = $this->getRestPositionData();
4165                                         
4166                                         // テンプレート上のポジション名
4167                                         if (count($this->viewPosId) > 0){
4168                                                 $posArrayStr = '[';
4169                                                 for ($i = 0; $i < count($this->viewPosId); $i++){
4170                                                         $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
4171                                                         if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
4172                                                 }
4173                                                 $posArrayStr .= ']';
4174                                                 $replaceStr .= 'var M3_POSITIONS = ' . $posArrayStr . ';' . M3_NL;
4175                                         }
4176                                         // 画面定義のリビジョン番号
4177                                         $replaceStr .= 'var M3_REVISION = ' . $this->pageDefRev . ';' . M3_NL;
4178                                         
4179                                         // その他のポジションデータ
4180                                         $replaceStr .= 'var M3_REST_POSITION_DATA = \'' . $positionData . '\';' . M3_NL;
4181                                 } else if (!empty($pageId)){
4182                                         $accessPoint = $this->gEnv->getAllDefaultPageId();
4183                                         for ($i = 0; $i < count($accessPoint); $i++){
4184                                                 if ($pageId == $accessPoint[$i]){
4185                                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $i . ';' . M3_NL;                        // ウィジェット設定画面のウィジェットの端末タイプ
4186                                                         break;
4187                                                 }
4188                                         }
4189                                 } else {                // メインの管理画面の場合
4190                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = 0;' . M3_NL;                 // 管理画面画面の端末タイプ(主にテスト用に使用)
4191                                 }
4192                                                 
4193                                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
4194                                         if (!empty($task)){             // 戻りタスクが設定されているときのみ最大化可能
4195                                                 $replaceStr .= 'function gobackPagedef(){' . M3_NL;
4196                                                 $replaceStr .= '    window.location.href = "' . $gEnvManager->getDefaultAdminUrl() . '?pageid=' . $pageId . '&pagesubid=' . $pageSubId . '&task=' . $task . '";' . M3_NL;
4197                                                 $replaceStr .= '}' . M3_NL;
4198                                                 $replaceStr .= '$(function(){' . M3_NL;
4199                                                 $replaceStr .= '    $(document).keyup(function(e){' . M3_NL;
4200                                                 $replaceStr .= '        if (e.which == 36) gobackPagedef();' . M3_NL;
4201                                                 $replaceStr .= '    });' . M3_NL;
4202                                                 $replaceStr .= '});' . M3_NL;
4203                                         }
4204                                 } else {
4205                                         // ##### 管理用テンプレートを使用している場合の処理 #####
4206                                         // Bootstrap用のスクリプト処理
4207                                         if ($this->useBootstrap){
4208                                                 $replaceStr .= '$(function(){' . M3_NL;
4209                                                 $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
4210                                                 $replaceStr .= '});' . M3_NL;
4211                                         }
4212                                 }
4213                         } else if ($this->isPageEditable){              // フロント画面ページ編集可能モードのとき
4214                                 $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
4215                                 if ($openType != '') $replaceStr .= 'var M3_CONFIG_WINDOW_OPEN_TYPE = ' . $openType . ';' . M3_NL;
4216                                 
4217                                 // ページID、ページサブID
4218                                 $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
4219                                 $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
4220                                 // WYSIWYGエディター
4221                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4222                                 
4223                                 // ファイルブラウザ
4224                                 $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;   // バージョン
4225                                 $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4226                                 $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4227                                 
4228                                 // Googleマップライブラリの読み込み
4229                                 if ($this->useGooglemaps){
4230                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
4231                                         
4232                                         // CKEditor拡張プラグイン用の定義
4233                                         $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
4234                                         if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
4235                                 } else {
4236                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
4237                                 }
4238
4239                                 // 起動がパーソナルモードかどうか
4240                                 if ($this->isPersonalMode){
4241                                         $replaceStr .= 'var M3_PERSONAL_MODE = true;' . M3_NL;
4242                                 } else {
4243                                         $replaceStr .= 'var M3_PERSONAL_MODE = false;' . M3_NL;
4244                                 }
4245                                 
4246                                 // テンプレートタイプ
4247                                 $templateType = $gEnvManager->getCurrentTemplateType();
4248                                 if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4249                         } else if ($this->isEditMode){                  // フロント画面編集モード(コンテンツ編集可能ユーザ)
4250                                 if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                               // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
4251                                         // WYSIWYGエディター
4252                                         $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4253                                 
4254                                         // ファイルブラウザ
4255                                         $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;   // バージョン
4256                                         $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4257                                         $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4258                                 
4259                                         // Googleマップライブラリの読み込み
4260                                         if ($this->useGooglemaps){
4261                                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
4262                                                 
4263                                                 // CKEditor拡張プラグイン用の定義
4264                                                 $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
4265                                                 if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
4266                                         } else {
4267                                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
4268                                         }
4269                                 
4270                                         // 起動がパーソナルモードかどうか(常にパーソナルモード)
4271                                         $replaceStr .= 'var M3_PERSONAL_MODE = true;' . M3_NL;
4272                                 
4273                                         // 管理画面の小画面デバイス最適化を行うかどうか
4274                                         if ($gEnvManager->isSmallDeviceAdmin()){
4275                                                 $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = true;' . M3_NL;
4276                                         } else {
4277                                                 $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = false;' . M3_NL;
4278                                         }
4279                                 
4280                                         // ##### CKEditor用の設定 #####
4281                                         // ウィジェット情報取得
4282                                         $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
4283                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
4284                                 
4285                                         // CKEditor用のCSSファイル
4286                                         if (!empty($this->ckeditorCssFiles)){
4287                                                 // 編集エリア用のCSSファイルを追加
4288                                                 $this->ckeditorCssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4289                                                 //array_unshift($this->ckeditorCssFiles, $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE);
4290                                         
4291 //                                              $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $this->ckeditorCssFiles));
4292                                                 $fileList = implode(', ', array_map(function($a){ return "'" . $a . "'"; }, $this->ckeditorCssFiles));
4293                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4294                                         }
4295                                         // CKEditor用(レイアウト)のCSSファイル
4296                                         $cssFiles = array();
4297                                         $cssFiles[] = $scriptsUrl . '/' . ScriptLibInfo::BOOTSTRAP_ADMIN_CSS;           // BootstrapのCSSを追加
4298                                         $cssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4299                 //                      $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $cssFiles));
4300                                         $fileList = implode(', ', array_map(function($a){ return "'" . $a . "'"; }, $cssFiles));
4301                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_LAYOUT_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4302                                         
4303                                         // CKEditor用のテンプレートタイプ
4304                                         if (isset($this->ckeditorTemplateType)){
4305                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_TEMPLATE_TYPE = ' . $this->ckeditorTemplateType . ';' . M3_NL;
4306                                         }
4307                                         
4308                                         // Bootstrap用のスクリプト処理
4309                                         if ($this->useBootstrap){
4310                                                 $replaceStr .= '$(function(){' . M3_NL;
4311                                                 $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
4312                                                 $replaceStr .= '});' . M3_NL;
4313                                         }
4314                                 } else {
4315                                         // プレビュー画面用にテンプレートタイプを出力
4316                                         $templateType = $gEnvManager->getCurrentTemplateType();
4317                                         if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4318                                         
4319                                         // ##### ヘルプシステムの組み込み #####
4320                                         if ($this->useHelp){                    // ヘルプ表示のとき
4321                                                 $replaceStr .= '$(function(){' . M3_NL;
4322                                                 $replaceStr .= '    if (jQuery().tooltip) $(\'[rel=m3help]\').tooltip({ placement: \'top\'});' . M3_NL;
4323                                                 $replaceStr .= '});' . M3_NL;
4324                                         }
4325                                 }
4326                         } else {                        // 権限なしの場合
4327                                 if (!$gEnvManager->isAdminDirAccess()){                 // フロント画面のとき
4328                                         // テンプレートタイプを追加(ファイルローダ等で使用)
4329                                         $templateType = $gEnvManager->getCurrentTemplateType();
4330                                         if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4331                                 }
4332                         }
4333                         
4334                         // ##### パネルメニュー(フロント画面と管理画面の切り替え等)の表示 #####
4335                         // PC用、携帯用、スマートフォン用画面とウィジェット付きポジションの管理画面時に表示
4336                         if (($gEnvManager->isAdminDirAccess() && $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) ||           // 管理画面(ウィジェット付きポジション表示)のとき
4337                                 (!$gEnvManager->isAdminDirAccess() &&                                                   // 一般用画面のとき
4338                                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
4339                                         $cmd != M3_REQUEST_CMD_RSS)){                                                           // RSS配信でない
4340                                 //if ($gEnvManager->isSystemAdmin()){                           // 管理者権限がある場合のみ有効
4341                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限ありの場合
4342                                         // トップメニュー項目作成
4343                                         $menubarTag = '';       // 管理用メニューバー
4344                                         $adminTag = '';         // 管理画面ボタン
4345                                         $editTag = '';          // 編集ボタン
4346                                         $logoutTag = '';                // ログアウトボタン
4347                                         
4348                                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面(ウィジェット付きポジション表示)の場合
4349                                                 // 編集ボタン
4350 /*                                              $titleStr = '編集終了';
4351                                                 $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4352                                                 if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4353                                                 $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
4354                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></li>';
4355                                                 */
4356                                                 $titleStr = '編集終了';
4357                                                 $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4358                                                 if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4359                                                 //$editTag = '<div class="m3editend"><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4360                                                 //$editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" /></a></div>';
4361                                                 $editTag = '<div class="m3editend m3topright"><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4362                                                 $editTag .= '<i class="glyphicon glyphicon-ok-sign"></i></a></div>';
4363                                                 $menubarTag .= $editTag;
4364                                                 
4365                                 //              $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
4366                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window == window.parent){' . M3_NL;// インラインフレームでないときパネルメニューを表示(修正 2016/9/1)
4367                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").prepend(\'' . $menubarTag . '\');' . M3_NL;            // appendでうまく表示できないのでprependで表示
4368                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
4369                                         } else if ($this->isAccessPointWithAdminMenu){          // 通常画面は、管理メニューを使用するアクセスポイントの場合のみ表示
4370                                                 // 管理画面ボタン
4371                                                 $titleStr = '管理画面へ遷移';
4372                                                 $linkUrl = $gEnvManager->getDefaultAdminUrl();
4373                                                 $adminTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4374                                                 $adminTag .= '<img src="' . $rootUrl . self::ADMIN_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4375                                         
4376                                                 // 編集ボタン
4377                                                 $titleStr = '画面を編集';
4378                                                 $linkUrl  = $gEnvManager->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' .M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET;
4379                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_ID . '=' . $gEnvManager->getCurrentPageId();
4380                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
4381                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_BACKUP_URL . '=' . urlencode($gEnvManager->getCurrentRequestUri());                  // URL退避用
4382                                                 $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4383                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_PAGE_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4384                                                 
4385                                                 // ログアウトボタン
4386                                                 $titleStr = 'ログアウト';
4387 //                                              if ($gEnvManager->isAdminDirAccess()){          // 管理画面の場合
4388 //                                                      $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4389 //                                                      if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4390 //                                              } else {
4391                                                         $linkUrl = $gEnvManager->getCurrentRequestUri();
4392 //                                              }
4393                                                 $linkUrl = createUrl($linkUrl, M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_LOGOUT);
4394                                                 $logoutTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4395                                                 $logoutTag .= '<img src="' . $rootUrl . self::LOGOUT_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4396                                         
4397                                                 // ウィジェットツール表示制御ボタン
4398                                                 $widgetToolTag .= '<li><div class="m3widgettoolbutton m3-nav m3-navbar-nav" data-toggle="buttons">';
4399                                                 $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>';
4400                                                 $widgetToolTag .= '<input type="checkbox" class="hidden" />';
4401                                                 $widgetToolTag .= '</div></li>';
4402                                                 
4403                                                 //$menubarTag .= '<div id="m3slidepanel">';
4404                                                 $menubarTag .= '<div id="m3slidepanel" class="m3panel_top m3-navbar-default" style="top:-60px; visibility: visible;">';
4405                                                 $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>';                           
4406                                 //              $menubarTag .= '<div tabindex="0" class="m3panel_wrap">';
4407                                                 $menubarTag .= '<div>';
4408                                                 $menubarTag .= '<ul class="m3-nav m3-navbar-nav">';
4409                                                 if ($gEnvManager->isSystemAdmin()){                             // 管理画面、編集モードは、管理者権限がある場合のみ有効
4410                                                         $menubarTag .= $adminTag;
4411                                                         $menubarTag .= $editTag;
4412                                                 }
4413                                                 $menubarTag .= $logoutTag;
4414                                                 $menubarTag .= $widgetToolTag;
4415                                                 $menubarTag .= '</ul>';
4416                                                 $menubarTag .= '</div>';
4417                                                 $menubarTag .= '</div>';
4418                                         //      $menubarTag .= '</div>';
4419
4420                                         //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
4421                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window == window.parent){' . M3_NL;// インラインフレームでないときパネルメニューを表示(修正 2016/9/1)
4422                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").append(\'' . $menubarTag . '\');' . M3_NL;
4423                                                 //$this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("#m3slidemenubarpanel").m3SlideMenubar();' . M3_NL;
4424                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(".m3panel_top").m3slidepanel({ "position": "top", "type": "push" });' . M3_NL;
4425                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").css("position", "relative");' . M3_NL;
4426                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'm3SetHelp($(\'#m3slidepanel\'));' . M3_NL;
4427                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'm3SetupWidgetTool(\'m3widgettoolbutton\');' . M3_NL;
4428                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
4429                                         }
4430                                 }
4431                         }
4432                         // ##### フロント画面からのウィジェット操作用ツールバー #####
4433                         if (!$gEnvManager->isAdminDirAccess() && 
4434                                 $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
4435                                 $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
4436                                 if ($gEnvManager->isSystemManageUser()){                // 一般用画面で管理者権限がある場合のみ有効
4437                                         // 管理用ツールバー
4438                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').each(function(){' . M3_NL;
4439                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var attrs = m3_splitAttr($(this).attr(\'m3\'));' . M3_NL;
4440                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var widgetId = attrs[\'widgetid\'];' . M3_NL;
4441                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var serialNo = attrs[\'serial\'];' . M3_NL;
4442                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var configId = attrs[\'configid\'];' . M3_NL;
4443                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var useconfig = attrs[\'useconfig\'];' . M3_NL;
4444                                         
4445                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'\';' . M3_NL;
4446                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (useconfig == 1){' . M3_NL;
4447                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
4448                                                                                 'html += \'<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\\\'\' + widgetId + \'\\\', \' + configId + \', \' + serialNo + \');return false;" rel="m3help" data-container="body" title="ウィジェット設定">' .
4449                                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON32_FILE . '" alt="ウィジェット設定" width="32" height="32" /></a>\';' . M3_NL;
4450                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4451                                         if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
4452                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 
4453                                                                                         '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="タイトル・スタイル調整">' .
4454                                                                                         '<img src="' . $rootUrl . self::ADJUST_ICON32_FILE . '" alt="タイトル・スタイル調整" width="32" height="32" /></a>\';' . M3_NL;
4455                                         }
4456                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (html != \'\'){' . M3_NL;
4457                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
4458                                                                                         'html = \'<div class="m3tooltip" style="display:none;">\' + html + \'<a class="m3closebox" href="javascript:void(0);" rel="m3help" data-container="body" title="閉じる">' . 
4459                                                                                         '<img src="' . $rootUrl . self::CLOSE_BOX_ICON32_FILE . '" alt="閉じる" width="11" height="11" /></a></div>\';' . M3_NL;
4460                                                                                         
4461                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).append(html);' . M3_NL;
4462                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4463                                         // クリックイベントの設定
4464                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).click(function(){' . M3_NL;
4465                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4466                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (tooltipObj.css(\'display\') == \'none\'){' . M3_NL;
4467                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (_m3ShowWidgetTool){' . M3_NL;
4468                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'tooltipObj.show();' . M3_NL;
4469                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
4470                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
4471                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.hide();' . M3_NL;
4472                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4473                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4474                                         // ウィジェットボーダーハイライト、ツールチップ表示
4475                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).hover(function(){' . M3_NL;
4476                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (_m3ShowWidgetTool){' . M3_NL;
4477                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(this).addClass(\'m3_widget_highlight\');' . M3_NL;
4478                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4479                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var pos = $(this).position();' . M3_NL;
4480                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var width = $(this).outerWidth();' . M3_NL;
4481                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var tooltipWidth = tooltipObj.outerWidth(true);' . M3_NL;
4482                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var x = pos.left + width - tooltipWidth;' . M3_NL;
4483                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var y = pos.top;' . M3_NL;
4484                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.css({position: "absolute",top: y + "px", left: x + "px"}).show();' . M3_NL;
4485                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4486                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}, function(){' . M3_NL;
4487                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).removeClass(\'m3_widget_highlight\');' . M3_NL;
4488                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4489                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'tooltipObj.hide();' . M3_NL;
4490                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4491                                         // 閉じるボタン処理
4492                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3closebox\').click(function(event){' . M3_NL;
4493                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).children(\'.m3tooltip\').hide();' . M3_NL;
4494                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4495                                         // コンテンツ編集ボタンの位置修正
4496                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
4497                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var offset = $(this).offset();' . M3_NL;
4498                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).outerWidth();' . M3_NL;
4499                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3edittool\').each(function(){' . M3_NL;
4500                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).offset({left: offset.left});' . M3_NL;
4501                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).width(width);' . M3_NL;
4502                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4503                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4504                                         
4505                                         // コンテキストメニューを作成
4506                                         $this->initScript .= M3_INDENT_SPACE . 'var widgetWindow = \'<div class="m3_contextmenu" id="m3_widgetmenu" style="visibility:hidden;">\';' . M3_NL;
4507                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'<ul>\';' . M3_NL;
4508                                         $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;
4509                                         if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
4510                                                 $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;
4511                                         }
4512                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</ul>\';' . M3_NL;
4513                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</div>\';' . M3_NL;
4514                                         $this->initScript .= M3_INDENT_SPACE . '$("body").append(widgetWindow);' . M3_NL;
4515                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').contextMenu(\'m3_widgetmenu\', {' . M3_NL;
4516                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'menuStyle: {' . M3_NL;
4517                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// border : "2px solid green",' . M3_NL;
4518                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'backgroundColor: \'#FFFFFF\',' . M3_NL;
4519                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'width: "150px",' . M3_NL;
4520                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'textAlign: \'left\',' . M3_NL;
4521                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'font: \'12px/1.5 Arial, sans-serif\'' . M3_NL;
4522                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4523                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'itemStyle: {' . M3_NL;
4524                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'padding: \'3px 3px\'' . M3_NL;
4525                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4526                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'bindings: {' . M3_NL;
4527                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wconfig\': function(t){' . M3_NL;
4528                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
4529                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
4530                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'alert("このウィジェットには設定画面がありません");' . M3_NL;
4531                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'return;' . M3_NL;
4532                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
4533                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowConfigWindow(attrs[\'widgetid\'], attrs[\'configid\'], attrs[\'serial\']);' . M3_NL;
4534                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '},' . M3_NL;
4535                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wadjust\': function(t){' . M3_NL;
4536                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
4537                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowAdjustWindow(attrs[\'configid\'], attrs[\'serial\'], M3_PAGE_ID, M3_PAGE_SUB_ID);' . M3_NL;
4538                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4539                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4540                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onContextMenu: function(e){' . M3_NL;
4541                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (_m3ShowWidgetTool){' . M3_NL;
4542                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'return true;' . M3_NL;
4543                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
4544                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'return false;' . M3_NL;
4545                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4546                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4547                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onShowMenu: function(e, menu){' . M3_NL;
4548                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// メニュー項目の変更' . M3_NL;
4549                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var attrs = m3_splitAttr($(e.target).parents(\'dl\').attr(\'m3\'));' . M3_NL;
4550                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
4551                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(\'#m3_wconfig\', menu).remove();' . M3_NL;
4552                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4553                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'return menu;' . M3_NL;
4554                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4555                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4556                                         
4557                                         // コンテンツの「非公開」表示
4558                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3content_private\').each(function(){' . M3_NL;
4559 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
4560 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var top = pos.top;' . M3_NL;
4561 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var left = pos.left;' . M3_NL;
4562 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).css(\'width\');' . M3_NL;
4563 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var height = $(this).css(\'height\');' . M3_NL;
4564                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'<div class="m3content_overlay"><div><h2>非公開</h2></div></div>\';' . M3_NL;
4565                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).prepend(html);' . M3_NL;
4566                                 //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var overlayObj = $(this).children(\'.m3content_overlay div\');' . M3_NL;
4567                                 //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'overlayObj.css({ position:"absolute", top:top + "px", left:left + "px" }).show();' . M3_NL;
4568                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4569                                 }
4570                         }
4571                         // ##### フロント画面のデフォルトのJavaスクリプト #####
4572 //                      if (!$gEnvManager->isAdminDirAccess()){
4573 //                              $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (jQuery().tooltip) $(\'[rel=tooltip]\').tooltip();' . M3_NL;          // 標準ツールチップ作成
4574 //                      }
4575                         // ポップアップメッセージがある場合は表示
4576                         if (!empty($this->popupMsg)){
4577                                 $replaceStr .=  'alert("' . $this->popupMsg . '");' . M3_NL;
4578                         }
4579                         // テンプレートに応じた処理
4580                         if ($cleanType == 1){
4581                                 // HTMLのクリーン処理が必要なときはコードを埋め込む
4582                                 $this->initScript .= '    $(\'.PostHeaderIcons\').remove();' . M3_NL;// 不要なアイコン表示タグの削除
4583                                 $this->initScript .= '    $(\'.PostMetadataHeader\').each(function(i){' . M3_NL;
4584                                 $this->initScript .= '        if ($(this).text().trim() == \'\') $(this).remove();' . M3_NL;
4585                                 $this->initScript .= '    });' . M3_NL;
4586                         }
4587                         
4588                         // 管理画面用スクリプト追加
4589                         $replaceStr .= $this->getLastContents();
4590                         
4591                         // 初期処理用スクリプト埋め込み
4592                         if (!empty($this->initScript)){
4593                                 $replaceStr .= '$(function(){' . M3_NL;
4594                                 $replaceStr .= $this->initScript;
4595                                 $replaceStr .= '});' . M3_NL;
4596                         }
4597                         
4598                         //$replaceStr .= '// -->' . M3_NL;
4599                         //$replaceStr .= '</script>' . M3_NL;
4600                         $replaceStr .= '//]]>' . M3_NL;
4601                         $replaceStr .= '</script>' . M3_NL;
4602
4603                         // HEADタグに埋め込むCSS,JavaScript,任意文字列
4604                         if (count($this->headCss) > 0){
4605                                 // CSSの場合は全体をstyleタグで囲む
4606                                 $replaceStr .= '<style type="text/css">' . M3_NL;
4607                                 $replaceStr .= '<!--' . M3_NL;
4608                                 for ($i = 0; $i < count($this->headCss); $i++){
4609                                         $replaceStr .= $this->headCss[$i];
4610                                 }
4611                                 $replaceStr .= M3_NL . '//-->' . M3_NL;
4612                                 $replaceStr .= '</style>' . M3_NL;
4613                         }
4614                         if (count($this->headScript) > 0){
4615                                 // JavaScriptの場合は全体をscriptタグで囲む
4616                                 //$replaceStr .= '<script type="text/javascript">' . M3_NL;
4617                                 //$replaceStr .= '<!--' . M3_NL;
4618                                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
4619                                 $replaceStr .= '//<![CDATA[' . M3_NL;
4620                                 for ($i = 0; $i < count($this->headScript); $i++){
4621                                         $replaceStr .= $this->headScript[$i];
4622                                 }
4623                                 //$replaceStr .= M3_NL . '//-->' . M3_NL;
4624                                 //$replaceStr .= '</script>' . M3_NL;
4625                                 $replaceStr .= M3_NL;
4626                                 $replaceStr .= '//]]>' . M3_NL;
4627                                 $replaceStr .= '</script>' . M3_NL;
4628                         }
4629                         if (count($this->headString) > 0){
4630                                 // 任意文字列の場合はそのまま追加
4631                                 for ($i = 0; $i < count($this->headString); $i++){
4632                                         $replaceStr .= $this->headString[$i];
4633                                 }
4634                         }
4635                 }
4636                 return $replaceStr;
4637         }
4638         /**
4639          * 各部品のHTML出力
4640          *
4641          * @param string $position                      HTMLテンプレート上の書き出し位置
4642          * @param string $style                         ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
4643          * @param int    $templateVer           テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
4644          * @param array  $attr                          その他属性
4645          * @return string                                       出力コンテンツ
4646          */
4647         function getContents($position, $style = '', $templateVer = 0, $attr = array())
4648         {
4649                 static $render;         // HTML生成オブジェクト
4650                 global $gRequestManager;
4651                 global $gEnvManager;
4652                 
4653                 // ファイル名、ページ名を取得
4654                 $filename       = $gEnvManager->getCurrentPageId();
4655                 $subId          = $gEnvManager->getCurrentPageSubId();
4656                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
4657
4658                 // ポジション名表示モードに応じて出力を作成
4659                 $contents = '';         // 出力コンテンツ
4660                 switch ($this->showPositionMode){
4661                         case 0:         // 通常画面
4662                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
4663                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
4664                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
4665                                         if ($ret){      // 1行以上データが取得できたとき
4666                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
4667                                                 $this->pageDefPosition = $position;
4668                                         } else {
4669                                                 $this->pageDefRows = array();
4670                                                 $this->pageDefPosition = '';
4671                                         }
4672                                 }
4673                                 // ウィジェットを実行
4674                                 $count = count($this->pageDefRows);
4675                                 
4676                                 if ($templateVer == 0){                 // ########## Joomla!v1.0テンプレートの場合 ##########
4677                                         ob_start();// バッファ作成
4678
4679                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
4680                                         $widgetHeaderType = $this->getTemplateWidgetHeaderType();
4681                                         for ($i = 0; $i < $count; $i++){
4682                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4683                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4684                                                 
4685                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4686                                                 // キャッシュデータがあるときはキャッシュデータを使用
4687                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4688
4689                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4690                                                         ob_clean();
4691                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $launchWidgetTag, $titleTag, $widgetHeaderType);
4692                                                         if (!$ret) break;
4693                                                         $widgetContent = ob_get_contents();
4694                                                         
4695                                                         // ウィジェット共通のコンテンツ処理
4696                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4697
4698                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4699                                                 //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4700                                                                                 
4701                                                         // キャッシュデータを設定
4702                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4703                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4704                                                                                                                         
4705                                                         // ウィジェットの外枠タグを設定
4706                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4707                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4708                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4709                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
4710                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4711                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4712                                                                 // ウィジェット表示タイプによる表示制御
4713                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4714                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
4715                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4716                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4717                                                                 if (!empty($controlType)){
4718                                                                         switch ($controlType){
4719                                                                                 case 1:                 // ログイン時のみ表示
4720                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4721                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
4722                                                                                         break;
4723                                                                                 case 2:                 // 非ログイン時のみ表示
4724                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4725                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
4726                                                                                         break;
4727                                                                                 default:
4728                                                                                         break;
4729                                                                         }
4730                                                                 }
4731                                                                 if (!empty($pageState)){
4732                                                                         switch ($pageState){
4733                                                                                 case 1:                 // トップ時のみ表示
4734                                                                                         if (!$this->isPageTopUrl){
4735                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
4736                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
4737                                                                                         }
4738                                                                                         break;
4739                                                                                 default:
4740                                                                                         break;
4741                                                                         }
4742                                                                 }
4743                 
4744                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4745                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4746                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4747                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4748                                                                 $shared = '0';          // 共通属性があるかどうか
4749                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4750                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4751                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4752                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
4753                                                         } else {
4754                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4755                                                                 $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4756                                                         }
4757                                                 } else {                // キャッシュデータがあるとき
4758                                                         $widgetContent = $cacheData;
4759                                                         
4760                                                         // HTMLのメタタグを設定
4761                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4762                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4763                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4764                                                 }
4765                                                 $contents .= $widgetContent;
4766                                                 
4767                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4768                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4769                                                 if (!empty($exportCss)){
4770                                                         // ウィジェットのタグIDを変換
4771                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4772                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4773                                                         $this->addExportCss($exportCss);
4774                                                 }
4775                                         }
4776                                         ob_end_clean();         // バッファ破棄
4777                                         
4778                                         if ($i < $count) return '';// 処理中断のときは終了
4779                                 } else if ($templateVer == 100){                        // ########## WordPressテンプレートの場合 ##########
4780                                         ob_start();// バッファ作成
4781
4782                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
4783                                         //$widgetHeaderType = $this->getTemplateWidgetHeaderType();
4784                                         for ($i = 0; $i < $count; $i++){
4785                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4786                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4787                                                 
4788                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4789                                                 // キャッシュデータがあるときはキャッシュデータを使用
4790                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4791
4792                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4793                                                         // WordPressウィジェット用のパラメータ設定
4794                                                         $gEnvManager->setWpWidgetClass('');                             // ウィジェットクラス名初期化
4795                                                         
4796                                                         ob_clean();
4797                                         //              $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $launchWidgetTag, $titleTag, $widgetHeaderType);
4798                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $launchWidgetTag, $titleTag, 0/*タイトル出力なし*/);
4799                                                         if (!$ret) break;
4800                                                         $widgetContent = ob_get_contents();
4801
4802                                                         // WordPressウィジェット用のパラメータ設定
4803                                                         $widgetClassName = $gEnvManager->getWpWidgetClass();                            // ウィジェットクラス名
4804                                                         
4805                                                         $trimContent = trim($widgetContent);
4806                                                         if (!empty($trimContent)){              // 出力が空でない場合
4807                                                         
4808                                                                 // オブジェクト作成
4809                                                                 if (!isset($render)) $render = new WPRender();          // WordPress用HTML生成オブジェクト
4810                                                         
4811                                                                 // デフォルトのウィジェットタイトル取得
4812                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
4813                                         
4814                                                                 // Joomla用のパラメータを取得
4815                                                                 //$joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
4816
4817                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
4818                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
4819                                         
4820                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
4821                                                                 $title = $this->pageDefRows[$i]['pd_title'];
4822                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
4823                                                                         if (empty($title)) $title = $defaultTitle;
4824                                                                 } else {
4825                                                                         $title = '';                    // タイトルは非表示
4826                                                                 }
4827                                                         
4828                                                                 // 強制的にタイトルを非表示にする場合はタイトルを修正
4829                                                                 if (!empty($title) && $this->pageDefRows[$i]['wd_hide_title']){
4830                                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4831                                                                                 $title = '[' . $title . ']';
4832                                                                         } else {
4833                                                                                 $title = '';
4834                                                                         }
4835                                                                 }
4836                                                                 
4837                                                                 // WordPress用パラメータ作成
4838                                                                 $params = array();                              // ウィジェットごとの属性
4839                                                                 if (!empty($widgetClassName))  $params['moduleclass'] = $widgetClassName;       // ウィジェットクラス名
4840                                                                                 
4841                                                                 // ウィジェット生成
4842                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . ($i + 1);                                // ウィジェット識別用ユニークタグ
4843                                                                 
4844                                                                 if (strcmp($position, 'main') == 0){// メイン部のとき
4845                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer, $widgetTag);
4846                                                                 } else {
4847                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer, $widgetTag);
4848                                                                 }
4849                                                         
4850                                                                 // ウィジェット共通のコンテンツ処理
4851                                                         //      $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4852
4853                                                                 // ウィジェットの内枠(コンテンツ外枠)を設定
4854                                                         //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4855                                                         }
4856                                                         
4857                                                         // キャッシュデータを設定
4858                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4859                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4860                                                                                                                         
4861                                                         // ウィジェットの外枠タグを設定
4862                                         //              $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4863                                         //              $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4864                                         //              if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4865                                         //              $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
4866                                         //              $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4867                                         
4868                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4869                                                                 // ウィジェット表示タイプによる表示制御
4870                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4871                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
4872                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4873                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4874                                                                 if (!empty($controlType)){
4875                                                                         switch ($controlType){
4876                                                                                 case 1:                 // ログイン時のみ表示
4877                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4878                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
4879                                                                                         break;
4880                                                                                 case 2:                 // 非ログイン時のみ表示
4881                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4882                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
4883                                                                                         break;
4884                                                                                 default:
4885                                                                                         break;
4886                                                                         }
4887                                                                 }
4888                                                                 if (!empty($pageState)){
4889                                                                         switch ($pageState){
4890                                                                                 case 1:                 // トップ時のみ表示
4891                                                                                         if (!$this->isPageTopUrl){
4892                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
4893                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
4894                                                                                         }
4895                                                                                         break;
4896                                                                                 default:
4897                                                                                         break;
4898                                                                         }
4899                                                                 }
4900                                                                 
4901                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4902                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4903                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4904                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4905                                                                 $shared = '0';          // 共通属性があるかどうか
4906                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4907                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4908                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4909                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
4910                                                         } else {
4911                                                 //              $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4912                                                 //              $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4913                                                         }
4914                                                 } else {                // キャッシュデータがあるとき
4915                                                         $widgetContent = $cacheData;
4916                                                         
4917                                                         // HTMLのメタタグを設定
4918                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4919                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4920                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4921                                                 }
4922                                                 $contents .= $widgetContent;
4923                                                 
4924                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4925                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4926                                                 if (!empty($exportCss)){
4927                                                         // ウィジェットのタグIDを変換
4928                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4929                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4930                                                         $this->addExportCss($exportCss);
4931                                                 }
4932                                         }
4933                                         ob_end_clean();         // バッファ破棄
4934                                         
4935                                         if ($i < $count) return '';// 処理中断のときは終了
4936                                 } else {                        // ########## Joomla!v1.5テンプレートの場合 ##########
4937                                         // テンプレート側で指定されたメニューの表示属性を設定
4938                                         $gEnvManager->setMenuAttr($attr);
4939                                         
4940                                         // ポジションタイプ
4941                                         $posType = '';
4942                                         if (!empty($attr['type'])) $posType = $attr['type'];
4943                                         
4944                                         for ($i = 0; $i < $count; $i++){
4945                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4946                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4947                                                                                                                 
4948                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4949                                                 // キャッシュデータがあるときはキャッシュデータを使用
4950                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4951                                                         
4952                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4953                                                         // ウィジェットのタイトルを初期化
4954                                                         $gEnvManager->setCurrentWidgetTitle('');
4955                                                 
4956                                                         // Joomla用のパラメータを初期化
4957                                                         $gEnvManager->setCurrentWidgetJoomlaParam(array());
4958                                                         
4959                                                         // ウィジェットの出力を取得
4960                                                         ob_clean();
4961                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $launchWidgetTag, $titleTag, 0/*タイトル出力なし*/);
4962                                                         $widgetContent = ob_get_contents();
4963
4964                                                         $trimContent = trim($widgetContent);
4965                                                         if (!empty($trimContent)){              // 出力が空でない場合
4966                                                                 $isRendered = false;            // Joomla!の描画処理を行ったかどうか
4967                                                                 if (!empty($this->pageDefRows[$i]['pd_use_render'])){                   // Joomla!の描画処理を使用する場合
4968                                                                         // Joomla!ウィジェットの出力に埋め込む
4969                                                                         if (strcasecmp($style, 'none') != 0){
4970                                                                                 // オブジェクト作成
4971                                                                                 if (!isset($render)) $render = new JRender();
4972                                                                 
4973                                                                                 // デフォルトのウィジェットタイトル取得
4974                                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
4975                                                                 
4976                                                                                 // Joomla用のパラメータを取得
4977                                                                                 $joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
4978
4979                                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
4980                                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
4981                                                                 
4982                                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
4983                                                                                 $title = $this->pageDefRows[$i]['pd_title'];
4984                                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
4985                                                                                         if (empty($title)) $title = $defaultTitle;
4986                                                                                 } else {
4987                                                                                         $title = '';                    // タイトルは非表示
4988                                                                                 }
4989                                                                         
4990                                                                                 // 強制的にタイトルを非表示にする場合はタイトルを修正
4991                                                                                 if (!empty($title) && $this->pageDefRows[$i]['wd_hide_title']){
4992                                                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4993                                                                                                 $title = '[' . $title . ']';
4994                                                                                         } else {
4995                                                                                                 $title = '';
4996                                                                                         }
4997                                                                                 }
4998                                                                                 
4999                                                                                 // Joomla用パラメータ作成
5000                                                                                 $params = array();                              // ウィジェットごとの属性
5001                                                                                 $widgetType = $this->pageDefRows[$i]['wd_type'];                // ウィジェットタイプ
5002                                                                                 
5003                                                                                 // オプションのJoomlaクラス(縦型メニュー(art-vmenu)等)
5004                                                                                 $joomlaClass = $this->pageDefRows[$i]['wd_joomla_class'];               // 「wd_joomla_class」は使っていない?
5005                                                                                 if (!empty($joomlaClass)) $params['moduleclass_sfx'] = $joomlaClass;
5006                                                                                 if (isset($joomlaParam['moduleclass_sfx'])) $params['moduleclass_sfx'] = $joomlaParam['moduleclass_sfx'];// ウィジェットでjoomla用パラメータの設定があるとき
5007                                                                 
5008                                                                                 if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
5009                                                                                         $moduleContent = '';
5010                                                                                         
5011                                                                                         // ウィジェットタイプがメニューのときはナビゲーションメニューを生成
5012                                                                                         if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5013                                                                 
5014                                                                                         // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
5015                                                                                         if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5016                                                                                         $widgetContent = $moduleContent;
5017                                                                                 } else {
5018                                                                                         // ウィジェットタイプに応じた処理を実行
5019                                                                                         if ($widgetType == 'breadcrumb'){               // パンくずリスト
5020                                                                                                 $moduleContent = '';
5021                                                                                                 
5022                                                                                                 if (empty($launchWidgetTag)){                   // 遅延実行の場合はここでパンくずリストを作成しないで遅延実行時に行う
5023                                                                                                         $moduleContent = $render->getBreadcrumbContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5024                                                                                                 } else {
5025                                                                                                         $moduleContent = $launchWidgetTag;              // 遅延実行ウィジェットのタグのみ取得
5026                                                                                                 }
5027                                                                                                 
5028                                                                                                 // パンくずリストで作成できないときはデフォルトの出力を取得
5029                                                                                                 if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5030                                                                                                 $widgetContent = $moduleContent;
5031                                                                                         } else {
5032                                                                                                 if (strcmp($position, 'main') == 0){// メイン部のとき
5033                                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
5034                                                                                                         // ウィジェットの内枠はレンダーで設定
5035                                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
5036                                                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5037                                                                                                 } else {                // その他の位置のとき
5038                                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
5039                                                                                                         // ウィジェットの内枠はレンダーで設定
5040                                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
5041                                                                                         
5042                                                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5043                                                                                                 }
5044                                                                                         }
5045                                                                                 }
5046 /*                                                                              if (strcmp($position, 'main') == 0){// メイン部のとき
5047                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
5048                                                                                         // ウィジェットの内枠はレンダーで設定
5049                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
5050                                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5051 //                                                                              } else if (strStartsWith($position, 'user') ||                          // ナビゲーションメニュー位置の場合
5052                                                                                 } else if (strcasecmp($position, 'user3') == 0 ||                               // ナビゲーションメニュー位置の場合
5053                                                                                                 strcasecmp($position, 'position-1') == 0 ||                             // Joomla!v2.5テンプレート対応
5054                                                                                                 strcasecmp($posType, 'hmenu') == 0){            // Joomla!v3テンプレート対応
5055
5056                                                                                         $moduleContent = '';
5057                                                                                         if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
5058                                                                                                 if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5059                                                                         
5060                                                                                                 // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
5061                                                                                                 if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5062                                                                                         } else {
5063                                                                                                 $moduleContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5064                                                                                         }
5065                                                                                         $widgetContent = $moduleContent;
5066                                                                                         
5067                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定。メニュー処理後に付加。
5068                                                                                         // ウィジェットの内枠はレンダーで設定
5069                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
5070                                                                                 } else {                // その他の位置のとき
5071                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
5072                                                                                         // ウィジェットの内枠はレンダーで設定
5073                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
5074                                                                                         
5075                                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
5076                                                                                 }*/
5077                                                                                 $isRendered = true;             // Joomla!の描画処理を行ったかどうか
5078                                                                         }
5079                                                                 }
5080                                                                 if (!$isRendered){              // Joomla!の描画処理を行っていない場合
5081                                                                         // ウィジェット共通のコンテンツ処理
5082                                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
5083                                                                         
5084                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
5085                                                                 //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
5086                                                                 }
5087                                                         }
5088                                                         if (!$ret) return '';           // 処理中断のときは終了
5089                                                         
5090                                                         // キャッシュデータを設定
5091                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
5092                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
5093                                                                                                                         
5094                                                         // ウィジェットの外枠タグを設定
5095                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
5096                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
5097                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
5098                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;  // ポジションブロッククラス
5099                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
5100                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
5101                                                                 // ウィジェット表示タイプによる表示制御
5102                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
5103                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
5104                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
5105                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
5106                                                                 if (!empty($controlType)){
5107                                                                         switch ($controlType){
5108                                                                                 case 1:                 // ログイン時のみ表示
5109                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
5110                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
5111                                                                                         break;
5112                                                                                 case 2:                 // 非ログイン時のみ表示
5113                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
5114                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
5115                                                                                         break;
5116                                                                                 default:
5117                                                                                         break;
5118                                                                         }
5119                                                                 }
5120                                                                 if (!empty($pageState)){
5121                                                                         switch ($pageState){
5122                                                                                 case 1:                 // トップ時のみ表示
5123                                                                                         if (!$this->isPageTopUrl){
5124                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
5125                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
5126                                                                                         }
5127                                                                                         break;
5128                                                                                 default:
5129                                                                                         break;
5130                                                                         }
5131                                                                 }
5132                         
5133                                                                 //$editInfo = 'widgetid:' . $this->pageDefRows[$i]['wd_id'];
5134                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
5135                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
5136                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
5137                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
5138                                                                 $shared = '0';          // 共通属性があるかどうか
5139                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
5140                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
5141                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
5142                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
5143                                                         } else {
5144                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
5145                                                                 $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
5146                                                         }
5147                                                 } else {                // キャッシュデータがあるとき
5148                                                         $widgetContent = $cacheData;
5149                                                         
5150                                                         // HTMLのメタタグを設定
5151                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
5152                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
5153                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
5154                                                 }
5155                                                 $contents .= $widgetContent;
5156                                                 
5157                                                 // ##### 外部出力用のCSSがある場合は追加 #####
5158                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
5159                                                 if (!empty($exportCss)){
5160                                                         // ウィジェットのタグIDを変換
5161                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
5162                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
5163                                                         $this->addExportCss($exportCss);
5164                                                 }
5165                                         }
5166                                 }
5167                         
5168                                 if ($position == 'main'){               // メイン部のときは、メッセージを出力
5169                                         /*if (strlen($this->popupMsg) > 0){
5170                                                 echo "\n<script language=\"javascript\">alert('" . addslashes($this->popupMsg) . "');</script>";
5171                                         }*/
5172                                 } else if ($position == 'debug'){               // デバッグ文出力
5173                                 } else {
5174
5175                                 }
5176                                 break;
5177                         case 1:         // ポジション表示
5178                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:3px solid #f00;color:#700;">ポジション名: ';
5179                                 $contents .= '<b>' . $position . '</b>';
5180                                 $contents .= '</div>';
5181                                 
5182                                 // ポジションを保存
5183                                 if (!in_array($position, $this->defPositions)) $this->defPositions[] = $position;       // テンプレート上のポジション
5184                                 break;
5185                         case 2:         // ポジション表示(ウィジェット付き)
5186                                 $rev = '555';                   // データのリビジョン番号
5187                                 // ポジションのHTMLタグIDを作成
5188                                 $num = 0;
5189                                 $posId = '';
5190                                 for ($i = 0; $i < 100; $i++){
5191                                         $posId = $position . '_' . $num;
5192                                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
5193                                         if (!in_array($viewPosId, $this->viewPosId)) break;
5194                                         $num++;
5195                                 }
5196                                 $this->viewPosId[] = $viewPosId;// IDを保存
5197                                 
5198                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
5199                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
5200                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows);
5201                                         if ($ret){      // 1行以上データが取得できたとき
5202                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
5203                                                 $this->pageDefPosition = $position;
5204                                         } else {
5205                                                 $this->pageDefRows = array();
5206                                                 $this->pageDefPosition = '';
5207                                         }
5208                                 }
5209                                 $posHead = '';
5210                                 // ナビゲーション型のポジションの場合はアイコン付加
5211                                 //if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
5212                                 if ($style == self::WIDGET_STYLE_NAVMENU){
5213                                         $posHead = self::POS_HEAD_NAV_MENU;             // 特殊ポジションブロックのアイコン付加(ナビゲーションメニュー型)
5214                                 } else if (strcasecmp($position, 'main') == 0){
5215                                         $posHead = self::POS_HEAD_MAIN;         // 特殊ポジションブロックのアイコン付加(メイン型)
5216                                 }
5217                                 $contents .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;             // リビジョン番号を付加
5218                                 $contents .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
5219                                 
5220                                 // ウィジェットイメージを表示
5221                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
5222                                 //$contents .= $this->getWidgetList($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $widgetTagHead, $this->pageDefRows);
5223                                 $contents .= $this->getWidgetList($filename, $subId, $widgetTagHead, $this->pageDefRows);
5224
5225                                 $contents .= '</div>' . M3_NL;
5226                                 break;
5227                         default:
5228                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:1px solid #f00;color:#700;">param error</div>';
5229                                 break;
5230                 }
5231                 // ポジションを保存
5232                 $this->viewPositions[] = $position;
5233
5234                 return $contents;
5235         }
5236         /**
5237          * 各部品のHTML出力(WordPressテンプレート専用)
5238          *
5239          * @param string $position                      HTMLテンプレート上の書き出し位置
5240          * @param bool $showTitle                       タイトルを表示するかどうか
5241          * @return string                                       出力コンテンツ
5242          */
5243         function getWPContents($position, $showTitle = true)
5244         {
5245                 if ($showTitle){
5246                         return $this->getContents($position, self::WIDGET_STYLE_WORDPRESS/*WordPressテンプレート用出力*/, 100/*WordPressテンプレート*/);
5247                 } else {
5248                         return $this->getContents($position, self::WIDGET_STYLE_WORDPRESS_NOTITLE/*WordPressテンプレート(タイトルなし)用出力*/, 100/*WordPressテンプレート*/);
5249                 }
5250         }
5251         /**
5252          * その他のポジションブロックデータを取得
5253          *
5254          * @param string                ポジション作成用タグ
5255          */
5256         function getRestPositionData()
5257         {
5258                 global $gEnvManager;
5259                 
5260                 $restPositionData = '';
5261                 $rev = '888';
5262                 $pageId = $gEnvManager->getCurrentPageId();
5263                 $subId = $gEnvManager->getCurrentPageSubId();
5264                 
5265                 $restPositions = array_values(array_diff($this->defPositions/*全ポジション*/, $this->viewPositions/*表示済みポジション*/));
5266                 $positionCount = count($restPositions);
5267                 for ($i = 0; $i < $positionCount; $i++){
5268                         $posHead = '';          // アイコン付加用
5269                         $position = $restPositions[$i];
5270                         $posId = $position . '_0';
5271                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
5272
5273                         // 画面情報を取得
5274                         $ret = $this->db->getPageDef($pageId, $subId, $position, $rows);
5275                         if ($ret){
5276                                 //$pageDefRows = $rows;                 // ページ定義レコード
5277                                                 
5278                                 $restPositionData .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">';             // リビジョン番号を付加
5279                                 $restPositionData .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>';
5280                         
5281                                 // ウィジェットイメージを表示
5282                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
5283                                 $contents = $this->getWidgetList($pageId, $subId, $widgetTagHead, $rows);
5284                                 $contents = str_replace(M3_NL, '', $contents);
5285                                 $contents = str_replace('\'', '\\\'', $contents);
5286                                 $restPositionData .= $contents;
5287                                 $restPositionData .= '</div>';
5288                                 
5289                                 $this->viewPosId[] = $viewPosId;// IDを保存
5290                         }
5291                 }
5292                 return $restPositionData;
5293         }
5294         /**
5295          * ウィジェット共通のコンテンツ追加処理
5296          *
5297          * @param string $src                           ウィジェット出力
5298          * @param array $pageDefParam           画面定義レコード
5299          * @return string                                       コンテンツを付加したウィジェット出力
5300          */
5301         function _addOptionContent($src, $pageDefParam)
5302         {
5303                 // 前後コンテンツ追加
5304                 $dest = $pageDefParam['pd_top_content'] . $src . $pageDefParam['pd_bottom_content'];
5305                 
5306                 // 「もっと読む」ボタンを追加
5307                 if ($pageDefParam['pd_show_readmore']){
5308                         $title = $pageDefParam['pd_readmore_title'];
5309                         if (empty($title)) $title = self::DEFAULT_READMORE_TITLE;
5310                         $dest .= '<div><a href="' . convertUrlToHtmlEntity($pageDefParam['pd_readmore_url']) . '">' . convertToHtmlEntity($title) . '</a></div>';
5311                 }
5312                 return $dest;
5313         }
5314         /**
5315          * BODYタグに付加するスタイルを取得(管理画面用)
5316          *
5317          * @param string                CSS文字列
5318          */
5319         function getBodyStyle()
5320         {
5321                 // 画面透過モードのときスタイルを追加
5322                 $transCss = '';
5323                 if ($this->isTransparentMode) $transCss = ' style="background-color:transparent;"';
5324                 return $transCss;
5325         }
5326         /**
5327          * 各ポジションのウィジェット数を取得
5328          *
5329          * @param string $position              HTMLテンプレート上の書き出し位置
5330          * @return int                                  ウィジェットの数
5331          */
5332         function getWidgetsCount($position)
5333         {
5334                 global $gRequestManager;
5335                 global $gEnvManager;
5336                 static $widgetCountArray = array();
5337
5338                 // 管理画面へのアクセスでログインされていないときは0を返す
5339                 if ($gEnvManager->isAdminDirAccess() && !$gEnvManager->isSystemManageUser()){           // 管理画面へのアクセスのときでシステム運用権限がない場合
5340                         return 0;
5341                 }
5342                                 
5343                 // 実行コマンドを取得
5344                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
5345                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                                     // 管理画面(ウィジェットなしポジション表示)のとき
5346                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){              // 管理画面(ウィジェット付きポジション表示)のとき
5347                         return 1;               // ウィジェットが設定されていないポジション名を表示するために固定で値を返す
5348                 }
5349                 
5350                 // 単一ポジション以外の設定のときは固定で返す(or等)
5351                 $pos = strpos($position, ' ');
5352                 if ($pos !== false) return 1;
5353                 
5354                 // 既にウィジェット数が取得されている場合は保存値を返す
5355                 $widgetCount = $widgetCountArray[$position];
5356                 if (isset($widgetCount)) return $widgetCount;
5357                 
5358                 // ファイル名、ページ名を取得
5359                 $filename       = $gEnvManager->getCurrentPageId();
5360                 $subId          = $gEnvManager->getCurrentPageSubId();
5361                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
5362
5363                 // 取得しようとするページ定義のポジションが既に取得しているポジションと異なるときはデータを取得
5364                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // 現在取得しているページ定義のポジション
5365                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
5366                         if ($ret){      // 1行以上データが取得できたとき
5367                                 $this->pageDefRows = $rows;                     // ページ定義レコード
5368                                 $this->pageDefPosition = $position;
5369                         } else {
5370                                 $this->pageDefRows = array();
5371                                 $this->pageDefPosition = '';
5372                         }
5373                 }
5374                 // ### ウィジェット数を取得 ###
5375                 // テンプレートのカラム制御を行うためにウィジェット表示条件でウィジェット数を取得
5376                 $widgetCount = 0;
5377                 $rowCount = count($this->pageDefRows);
5378                 for ($i = 0; $i < $rowCount; $i++){
5379         //              $condition = trim($this->pageDefRows[$i]['wd_visible_condition']);
5380                         $condition = trim($this->pageDefRows[$i]['pd_visible_condition']);
5381                         if (empty($condition)){                 // ウィジェット表示条件が設定されていない場合はウィジェットを表示
5382                                 $widgetCount++;
5383                         } else {                        // ウィジェット表示条件が設定されている場合はパラメータをチェック
5384                                 $conds = explode(';', $condition);
5385                                 for ($j = 0; $j < count($conds); $j++){
5386                                         $pos = strpos($conds[$j], '=');
5387                                         if ($pos !== false){            // URLクエリーパラメータ条件がマッチした場合はウィジェットを表示
5388                                                 list($key, $value) = explode('=', trim($conds[$j]));
5389                                                 $key = trim($key);
5390                                                 $value = trim($value);
5391                                                 if (!empty($key) && !empty($value)){
5392                                                         $requestValue = $gRequestManager->trimValueOf($key);
5393                                                         if ($value == $requestValue) $widgetCount++;
5394                                                 }
5395                                         }
5396                                 }
5397                         }
5398                 }
5399 //              $widgetCount = count($this->pageDefRows);
5400                 $widgetCountArray[$position] = $widgetCount;
5401                 return $widgetCount;
5402         }
5403         /**
5404          * ウィジェットのページ定義シリアル番号からウィジェットCSS IDを取得
5405          *
5406          * @param int $defSerial                ページ定義シリアル番号
5407          * @param string $pageId                ページID
5408          * @param string $subpage       ページサブID
5409          * @param string $position              表示位置ID
5410          * @return string                               CSSエレメントID
5411          */
5412         function getWidgetCssId($defSerial, $pageId, $pageSubId, $position)
5413         {
5414                 $elementId = '';
5415                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
5416                 if ($ret){
5417                         $rowCount = count($rows);
5418                         for ($i = 0; $i < $rowCount; $i++){
5419                                 $row = $rows[$i];
5420                                 if ($row['pd_serial'] == $defSerial){
5421                                         $elementId = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
5422                                         break;
5423                                 }
5424                         }
5425                 }
5426                 return $elementId;
5427         }
5428         /**
5429          * ウィジェット情報取得
5430          *
5431          * 画面作成機能でウィジェット情報を取得するためのAjaxインターフェイス
5432          *
5433          * @param RequestManager $request               HTTPリクエスト処理クラス
5434          */
5435         function getWidgetInfoByAjax($request)
5436         {
5437                 global $gEnvManager;
5438                 global $gDesignManager;
5439                 global $gCacheManager;
5440                 
5441                 // アクセスするページIDからPC用、携帯用、スマートフォン用かを判断
5442                 $widgetDeviceType = 0;          // 端末タイプをPC用に初期化
5443                 $pageId         = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
5444                 $pageSubId      = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
5445                 $mobilePageIdPrefix = M3_DIR_NAME_MOBILE . '_';
5446                 $smartphonePageIdPrefix = M3_DIR_NAME_SMARTPHONE . '_';
5447                 if (strncmp($pageId, $mobilePageIdPrefix, strlen($mobilePageIdPrefix)) == 0){
5448                         $widgetDeviceType = 1;          // 携帯用
5449                 } else if (strncmp($pageId, $smartphonePageIdPrefix, strlen($smartphonePageIdPrefix)) == 0){
5450                         $widgetDeviceType = 2;          // スマートフォン用
5451                 }
5452
5453                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
5454                 if ($task == 'list'){
5455                         // ウィジェット一覧を取得
5456                         $ret = $this->db->getAvailableWidgetList($widgetDeviceType, $rows);
5457                         if ($ret){
5458                                 $currentCategoryId = '_none';           // 現在のウィジェットカテゴリー初期化
5459                                 for ($i = 0; $i < count($rows); $i++){
5460                                         $widgetId = $rows[$i]['wd_id'];
5461                                         $desc = $rows[$i]['wd_description'];
5462                                         $widgetTag = self::WIDGET_TYPE_TAG_HEAD . $widgetId;
5463                                         $categoryId = $rows[$i]['wd_category_id'];
5464                                         
5465                                         // カテゴリーの開始タグを追加
5466                                         if ($categoryId != $currentCategoryId){
5467                                                 if ($i > 0){
5468                                                         echo '</dd>' . M3_NL;
5469                                                         echo '</dl>' . M3_NL;
5470                                                 }
5471                                                 echo '<dl class="m3accordion">' . M3_NL;
5472                                                 echo '<dt>' . $rows[$i]['wt_name'] . '</dt>' . M3_NL;
5473                                                 echo '<dd>' . M3_NL;
5474                                                 
5475                                                 // 現在のカテゴリー更新
5476                                                 $currentCategoryId = $categoryId;
5477                                         }
5478                                         
5479                                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
5480                                         if ($gEnvManager->getUseSslAdmin()){
5481                                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
5482                                                 $image = $gEnvManager->getSslUrl($image);
5483                                         }
5484                                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
5485                                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
5486                                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
5487                                         $imageTag .= ' />';
5488                                         
5489                                         // ウィジェット機能マーク
5490                                         $widgetMark = '';
5491                                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メイン型ウィジェット
5492                                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
5493
5494                                         // ウィジェット機能一覧
5495                                         $functionMark = '';
5496                                         if (!empty($rows[$i]['wd_template_type'])){             // 対応テンプレートタイプ
5497                                                 $templateTypeArray = explode(',', $rows[$i]['wd_template_type']);
5498                                                 if (in_array('bootstrap', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_BOOTSTRAP;           // Bootstrap型テンプレート対応
5499                                                 if (in_array('wordpress', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_WORDPRESS;           // WordPress型テンプレート対応
5500                                         }
5501                                         if (!empty($functionMark)) $functionMark = '<hr />' . $functionMark;
5502                         
5503                                         echo '<dl class="m3_widgetlist_item" id="' . $widgetTag . '">' . M3_NL;
5504                                         echo '<dt>' . $widgetMark . $rows[$i]['wd_name'] . '</dt>' . M3_NL;                     // ウィジェット名
5505                                         echo '<dd><table style="width:100%;"><tr style="vertical-align:top;"><td style="width:35px;">' . $imageTag . '</td><td>' . $desc . '</td></tr></table>';
5506                                         echo $functionMark . '</dd>' . M3_NL;
5507                                         echo '</dl>' . M3_NL;
5508                                         
5509                                         // カテゴリーの終了タグを追加
5510                                         if ($i == count($rows) - 1){
5511                                                 echo '</dd>' . M3_NL;
5512                                                 echo '</dl>' . M3_NL;
5513                                         }
5514                                 }
5515                         }
5516                 } else if ($task == 'wget' || $task == 'wdelete' || $task == 'wtoggle' || $task == 'wadd' || $task == 'wmove'){ // ウィジェット再取得、ウィジェット削除,ウィジェット共通属性変更、ウィジェット追加、ウィジェット移動のとき
5517                         $rev    = $request->trimValueOf('rev');                 // リビジョン
5518                         $serial = $request->trimValueOf('serial');
5519                         $position = $request->trimValueOf('pos');
5520                         $widgetsStr = $request->trimValueOf('widgets');
5521                         if (empty($widgetsStr)){
5522                                 $widgets = array();
5523                         } else {
5524                                 $widgets = explode(',', $widgetsStr);
5525                         }
5526                         $shared = $request->trimValueOf('shared');
5527                         $updatepos = explode(',', $request->trimValueOf('updatepos'));
5528                         $index = $request->trimValueOf('index');
5529                         
5530                         // 処理ごとのパラメータ
5531                         if ($task == 'wmove'){
5532                                 $positions = explode(',', $position);
5533                                 if (count($positions) >= 2){
5534                                         $position = $positions[0];
5535                                         $position2 = $positions[1];
5536                                 } else {
5537                                         $position = $positions[0];
5538                                         $position2 = '';
5539                                 }
5540                         }
5541                         // ##### エラーチェック #####
5542                         $isErr = false;
5543                         // リビジョンのエラーチェック
5544                         $rev = '111';                   // データのリビジョン番号
5545
5546                         // 変更前データ取得
5547                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);    // 0レコードでも正常とする
5548                         
5549                         // 変更前のウィジェットのシリアル番号をチェック
5550                         if (count($widgets) == count($rows)){
5551                                 if (!($task == 'wmove' && empty($position2))){                  // 同一ブロック内の移動の場合はチェックなし
5552                                         for ($i = 0; $i < count($rows); $i++){
5553                                                 if ($widgets[$i] != $rows[$i]['pd_serial']){// シリアル番号
5554                                                         $isErr = true;
5555                                                         break;
5556                                                 }
5557                                         }
5558                                 }
5559                         } else {
5560                                 $isErr = true;
5561                         }
5562
5563                         // データの更新
5564                         if (!$isErr){           // エラーなしのとき
5565                                 if ($task == 'wdelete'){
5566                                         $ret = $this->db->deleteWidget($serial);
5567                                 } else if ($task == 'wtoggle'){
5568                                         $newShared = 0;
5569                                         if (empty($shared)) $newShared = 1;
5570                                         $ret = $this->db->toggleSharedWidget($pageId, $pageSubId, $serial, $newShared);
5571                                 } else if ($task == 'wadd'){    // ウィジェットの追加
5572                                         $widget = $request->trimValueOf('widget');
5573                                         
5574                                         // エラーチェック
5575                                         if (empty($widget)) $isErr = true;
5576                                         
5577                                         // ウィジェットを追加
5578                                         if (!$isErr) $this->db->addWidget($pageId, $pageSubId, $position, $widget, $index);
5579                                 } else if ($task == 'wmove'){
5580                                         // ウィジェットを移動
5581                                         if (!$isErr) $this->db->moveWidget($pageId, $pageSubId, $position, $serial, $index);
5582                                 }
5583                         }
5584                         // 再表示データ取得
5585                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);// 0レコードでも正常とする
5586                         
5587                         // 移動のときは、移動元と移動先の再表示データを取得
5588                         if ($task == 'wmove' && !empty($position2)){
5589                                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position2, $rows2);// 0レコードでも正常とする
5590                         }
5591
5592                         // ##### 該当するページのテンプレートタイプを取得 #####
5593                         $templateType = 99;
5594                         $templateGenerator = '';
5595                 
5596                         // ページ用個別に設定されたテンプレートがある場合は取得
5597                         $curTemplate = '';
5598                         $line = $this->getPageInfo($pageId, $pageSubId);
5599                         if (!empty($line)) $curTemplate = $line['pn_template_id'];
5600
5601                         // 取得できなければデフォルトを取得
5602                         if (empty($curTemplate)){
5603                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
5604                                         $curTemplate = $this->gSystem->defaultTemplateId();
5605                                 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
5606                                         $curTemplate = $this->gSystem->defaultSmartphoneTemplateId();           // スマートフォン用デフォルトテンプレート
5607                                 }
5608                         }
5609                         
5610                         // テンプレートのタイプを取得
5611                         $ret = $this->db->getTemplate($curTemplate, $row);
5612                         if ($ret){
5613                                 $templateType = $row['tm_type'];
5614                                 $templateGenerator = $row['tm_generator'];
5615                         }
5616
5617                         // 更新データを作成
5618                         // 更新対象のポジションブロック
5619                         echo '<div>' . M3_NL;
5620                         for ($i = 0; $i < count($updatepos); $i++){
5621                                 // ウィジェットIDヘッダ作成
5622                                 $widgetTagHead = str_replace(self::POSITION_TAG_HEAD, self::WIDGET_TAG_HEAD, $updatepos[$i]);
5623                                         
5624                                 // ポジション名取得
5625                                 $posName = str_replace(self::POSITION_TAG_HEAD, '', substr($updatepos[$i], 0, strlen($updatepos[$i]) - strlen(strrchr($updatepos[$i], "_"))));
5626                                 if ($task == 'wmove' && $posName == $position2){
5627                                         // Themlerテンプレート場合は配置ポジション名が「hmenu」をナビゲーション型とする
5628                                         $style = '';
5629                                         if ($templateGenerator == 'themler'){
5630                                                 if (strcasecmp($position2, 'hmenu') == 0){              // Joomla!v3テンプレート対応
5631                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
5632                                                 }
5633                                         } else {
5634                                                 if (strcasecmp($position2, 'user3') == 0 ||             // ナビゲーションメニュー位置の場合
5635                                                         strcasecmp($position2, 'position-1') == 0){             // Joomla!v2.5テンプレート対応
5636                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
5637                                                 }
5638                                         }
5639                                                                         
5640                                         // ウィジェット一覧外枠
5641                                         $posHead = '';
5642                                         if ($style == self::WIDGET_STYLE_NAVMENU){
5643                                                 $posHead = self::POS_HEAD_NAV_MENU;             // 特殊ポジションブロックのアイコン付加(ナビゲーションメニュー型)
5644                                         } else if (strcasecmp($position2, 'main') == 0){
5645                                                 $posHead = self::POS_HEAD_MAIN;         // 特殊ポジションブロックのアイコン付加(メイン型)
5646                                         }
5647                                         //if (strcasecmp($position2, 'user3') == 0 || strcasecmp($position2, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;            // 特殊ポジションブロックのアイコン付加
5648                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position2 . ';rev:' . $rev . ';">' . M3_NL;                // リビジョン番号を付加
5649                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position2 . '</h2>' . M3_NL;
5650                                 
5651                                         // ウィジェット一覧出力
5652                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows2);
5653                                 } else {
5654                                         // Themlerテンプレート場合は配置ポジション名が「hmenu」をナビゲーション型とする
5655                                         $style = '';
5656                                         if ($templateGenerator == 'themler'){
5657                                                 if (strcasecmp($position, 'hmenu') == 0){               // Joomla!v3テンプレート対応
5658                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
5659                                                 }
5660                                         } else {
5661                                                 if (strcasecmp($position, 'user3') == 0 ||              // ナビゲーションメニュー位置の場合
5662                                                         strcasecmp($position, 'position-1') == 0){              // Joomla!v2.5テンプレート対応
5663                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
5664                                                 }
5665                                         }
5666                                         
5667                                         // ウィジェット一覧外枠
5668                                         $posHead = '';
5669                                         if ($style == self::WIDGET_STYLE_NAVMENU){
5670                                                 $posHead = self::POS_HEAD_NAV_MENU;             // 特殊ポジションブロックのアイコン付加(ナビゲーションメニュー型)
5671                                         } else if (strcasecmp($position, 'main') == 0){
5672                                                 $posHead = self::POS_HEAD_MAIN;         // 特殊ポジションブロックのアイコン付加(メイン型)
5673                                         }
5674                                         //if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
5675                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;         // リビジョン番号を付加
5676                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
5677                                 
5678                                         // ウィジェット一覧出力
5679                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows);
5680                                 }
5681                                 // ウィジェット一覧外枠
5682                                 echo '</div>' . M3_NL;
5683                         }
5684                         echo '</div>' . M3_NL;
5685                         
5686                         // キャッシュデータをクリア
5687                         $gCacheManager->clearAllCache();
5688                 }
5689         }
5690         /**
5691          * 画面作成用ウィジェット一覧データ出力
5692          *
5693          * @param string $pageId                        ページID
5694          * @param string $pageSubId                     ページサブID
5695          * @param string $widgetTagHead         HTMLウィジェットID用のヘッダ
5696          * @param array $rows                           ウィジェット一覧データ
5697          * @return string                                       ウィジェット一覧出力
5698          */
5699         function getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows)
5700         {
5701                 global $gEnvManager;
5702                 global $gDesignManager;
5703                 global $gSystemManager;
5704                 
5705                 if ($gEnvManager->getUseSslAdmin()){
5706                         $rootUrl = $gEnvManager->getSslRootUrl();
5707                 } else {
5708                         $rootUrl = $gEnvManager->getRootUrl();
5709                 }
5710
5711                 // ページのコンテンツタイプを取得
5712                 $line = $this->getPageInfo($pageId, $pageSubId);
5713                 if (!empty($line)) $pageContentType = $line['pn_content_type'];
5714                         
5715                 $contents = '';         // ウィジェット一覧出力コンテンツ
5716                 for ($i = 0; $i < count($rows); $i++){
5717                         $widgetId = $rows[$i]['wd_id'];
5718                         $desc = $rows[$i]['wd_description'];
5719                         $widgetIndex = $rows[$i]['pd_index'];           // 表示順
5720                         $configId = $rows[$i]['pd_config_id'];          // 定義ID
5721                         $serial = $rows[$i]['pd_serial'];               // シリアル番号
5722                         $isShared = empty($rows[$i]['pd_sub_id']);                      // グローバル属性が設定されているかどうか
5723                         $widgetTag = $widgetTagHead . '_' . $i;                         // ウィジェット識別用ユニークタグ
5724                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
5725                         if ($gEnvManager->getUseSslAdmin()){
5726                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
5727                                 $image = $gEnvManager->getSslUrl($image);
5728                         }
5729                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
5730                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
5731                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
5732                         $imageTag .= ' />';
5733                         // 定義名
5734                         if (empty($rows[$i]['pd_config_name'])){
5735                                 if ($rows[$i]['wd_use_instance_def'] && $configId == 0){                // インスタンス定義が必要で未定義のとき
5736                                         $configName = '<span style="color:red;">[未設定]</span>';
5737                                 } else {
5738                                         $configName = '';
5739                                 }
5740                         } else {
5741                                 $configName = '[' . $rows[$i]['pd_config_name'] . ']';
5742                         }
5743                         $hasAdmin = '0';                // 管理画面があるかどうか
5744                         $configImg = '';        // 設定アイコンの表示
5745                         
5746                         // ウィジェットの配置位置に問題があるかどうかを表示
5747                         // メインコンテンツとページ属性が一致するかどうかチェック
5748                         $widgetContentType = $rows[$i]['wd_content_type'];
5749                         //if (!empty($widgetContentType) && $widgetContentType != $pageContentType && 
5750                         if (!empty($widgetContentType) && $widgetContentType != $pageContentType && empty($rows[$i]['wd_content_widget_id']) &&                 // 編集用のウィジェットが別にある場合は除く(2015/3/24))
5751                                                 (in_array($widgetContentType, $this->_getAllContentType()) || in_array($widgetContentType, $this->_getAllFeatureType()))){
5752                                 //$title = 'ウィジェット配置注意';
5753                                 $title = 'ページ属性と不一致';
5754                                 $configImg .= '<span rel="m3help" data-container="body" title="' . $title . '"><img src="' . $rootUrl . self::NOTICE_ICON_FILE . '" alt="' . $title . '" /></span>&nbsp;';
5755                         }
5756                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type']) && $isShared){                                 // メイン型ウィジェットがグローバル属性を持つとき
5757                                 $title = 'メイン型ウィジェットはグローバル属性を設定できません';
5758                                 $configImg .= '<span rel="m3help" data-container="body" title="' . $title . '"><img src="' . $rootUrl . self::ALERT_ICON_FILE . '" alt="' . $title . '" /></span>&nbsp;';
5759                         }
5760                         if ($rows[$i]['wd_has_admin']){
5761                                 $hasAdmin = '1';
5762                                 $title = 'ウィジェット設定';
5763                                 $configImg .= '<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\'' . $widgetId . '\', \'' . $configId . '\', \'' . $serial . '\');return false;" rel="m3help" data-container="body" title="' . $title . '">' .
5764                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" alt="' . $title . '"/></a>&nbsp;';
5765                         }
5766                         // 表示順
5767                         $configImg .= '<span rel="m3help" data-container="body" title="表示順">' . $widgetIndex . '</span>';
5768                         
5769                         $shared = '0';          // 共通属性があるかどうか
5770                         $sharedClassName = '';
5771                         //if (empty($rows[$i]['pd_sub_id'])){
5772                         if ($isShared){                                 // グローバル属性ウィジェットのとき
5773                                 $shared = '1';
5774                                 $sharedClassName = 'm3_widget_shared';                  // 共通ウィジェットのクラス
5775                         }
5776                         $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
5777                         
5778                         // ウィジェット機能マーク
5779                         $widgetMark = '';
5780                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メイン型ウィジェット
5781                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
5782                         
5783                         // 操作メニュー
5784                         $dropdownMenuId = $widgetTag . '_dropdown';
5785                         $operationMenu = '<div class="m3widgetdropdown">';
5786 //                      $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#"><i class="glyphicon glyphicon-list-alt"></i> <b class="caret"></b></a>';
5787                         $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#" data-horizontal-offset="4"><b class="caret"></b></a>';
5788                         $operationMenu .= '<div id="' . $dropdownMenuId . '" class="m3dropdown m3dropdown-tip m3dropdown-relative m3dropdown-anchor-right">';
5789                         $operationMenu .= '<ul class="m3dropdown-menu">';
5790                         if ($hasAdmin) $operationMenu .= '<li class="m3_wconfig"><a href="#"><img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" /> <span>ウィジェットの設定</span></a></li>';
5791                         $operationMenu .= '<li class="m3_wadjust"><a href="#"><img src="' . $rootUrl . self::ADJUST_ICON_FILE . '" /> <span>タイトル・スタイル調整</span></a></li>';
5792                         if ($shared){
5793                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>グローバル属性を解除</span></a></li>';
5794                         } else {
5795                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>グローバル属性を設定</span></a></li>';
5796                         }
5797                         $operationMenu .= '<li class="m3_wdelete"><a href="#"><img src="' . $rootUrl . self::DELETE_ICON_FILE . '" /> <span>このウィジェットを削除</span></a></li>';
5798                         $operationMenu .= '</ul>';
5799                         $operationMenu .= '</div>';
5800                         $operationMenu .= '</div>';
5801                         
5802                         $contents .= '<dl class="m3_widget m3_widget_sortable" id="' . $widgetTag . '" ' . $m3Option . ' >' . M3_NL;
5803                         $contents .= '<dt class="m3_widget_with_check_box ' . $sharedClassName . '"><div class="m3widgettitle">' . $widgetMark . $rows[$i]['wd_name'] . '</div>' . $operationMenu . '</dt>' . M3_NL;
5804                         $contents .= '<dd><table style="width:100%;"><tr style="vertical-align:top;"><td style="width:35px;border:none;">' . $imageTag . '</td><td style="border:none;">' . $desc . '</td></tr></table><hr />' . M3_NL;
5805                         $contents .= '<table style="width:100%;"><tr><td style="border:none;">' . $configName . '</td><td style="text-align:right;border:none;">' . $configImg . '</td></tr></table></dd>' . M3_NL;
5806                         $contents .= '</dl>' . M3_NL;
5807                 }
5808                 return $contents;
5809         }
5810         /**
5811          * ウィジェット出力を処理
5812          *
5813          * @param string $position                      HTMLテンプレート上の書き出し位置
5814          * @param int $index                            行番号
5815          * @param array $fetchedRow                     fetch取得した行
5816          * @param string $style                         ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
5817          * @param string $launchWidgetTag       遅延ウィジェット埋め込み用タグ(遅延ウィジェットの場合のみ作成)
5818          * @param string $titleTag              タイトル埋め込み用タグ(遅延ウィジェットの場合のみ作成)
5819          * @param int $widgetHeaderType         ウィジェットタイトルを出力方法(0=出力なし、1=Joomla!v1.0PC用出力、2=Joomla!v1.0携帯用出力)
5820          * @return bool                                         処理を継続するかどうか(true=続行、false=中断)
5821          */
5822         function pageDefLoop($position, $index, $fetchedRow, $style, &$launchWidgetTag, &$titleTag, $widgetHeaderType = 0)
5823         {
5824                 global $gEnvManager;
5825                 global $gErrorManager;
5826                 global $gDesignManager;
5827
5828                 // ページ作成中断またはウィジェット処理中断のときは終了
5829                 if ($this->isAbort || $this->isWidgetAbort) return false;
5830
5831                 // ウィジェット実行停止中のときは空で返す
5832                 // 管理者、運営者どのレベルで制限をかける?
5833                 if (!$fetchedRow['wd_active']) return true;
5834                 
5835                 // グローバル属性ありの場合は現在のページが例外ページにないかチェック
5836                 if (empty($fetchedRow['pd_sub_id'])){
5837                         $exceptPageStr = $fetchedRow['pd_except_sub_id'];
5838                         if (!empty($exceptPageStr)){
5839                                 $exceptPageArray = explode(',', $exceptPageStr);
5840                                 if (in_array($gEnvManager->getCurrentPageSubId(), $exceptPageArray)) return true;               // 例外ページの場合は出力しない
5841                         }
5842                 }
5843                 
5844                 // ウィジェット表示タイプによる表示制御。システム管理者以上の場合は常時表示。
5845                 if (!$gEnvManager->isSystemAdmin()){
5846                         if (!empty($fetchedRow['pd_view_control_type'])){
5847                                 switch ($fetchedRow['pd_view_control_type']){
5848                                         case 1:                 // ログイン時のみ表示
5849                                                 if (!$gEnvManager->isCurrentUserLogined()) return true;         // ログインしていなければ終了
5850                                                 break;
5851                                         case 2:                 // 非ログイン時のみ表示
5852                                                 if ($gEnvManager->isCurrentUserLogined()) return true;          // ログインしていれば終了
5853                                                 break;
5854                                         default:
5855                                                 break;
5856                                 }
5857                         }
5858                         if (!empty($fetchedRow['pd_view_page_state'])){
5859                                 switch ($fetchedRow['pd_view_page_state']){
5860                                         case 1:                 // トップ時のみ表示
5861                                                 if (!$this->isPageTopUrl) return true;          // ページトップ(サブページ内のトップ位置)でなければ終了
5862                                                 break;
5863                                         default:
5864                                                 break;
5865                                 }
5866                         }
5867                 }
5868                 
5869                 // パラメータ初期化
5870                 $launchWidgetTag = '';          // 遅延ウィジェット埋め込み用タグ
5871                 $titleTag = '';
5872                 
5873                 // ウィジェットID取得
5874                 $widgetId = $fetchedRow['wd_id'];               
5875                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
5876
5877                 // その他パラメータ取得
5878                 $configId = $fetchedRow['pd_config_id'];                // ウィジェット定義ID
5879                 if ($configId == 0) $configId = '';
5880                 $prefix = $fetchedRow['wd_suffix'];             // サフィックス文字列
5881                 $title = $fetchedRow['wd_name'];                // デフォルトのウィジェットタイトル
5882                 if (empty($title)) $title = $fetchedRow['wd_id'];
5883                 $widgetHeadTitle = $fetchedRow['pd_title'];             // ウィジェットのヘッドタイトル
5884                 if (empty($widgetHeadTitle)) $widgetHeadTitle = $title;                 // ウィジェットのヘッドタイトルが空の場合はウィジェットタイトルを取得
5885                 $serial = $fetchedRow['pd_serial'];             // シリアル番号
5886                 $cssStyle       = $fetchedRow['pd_style'];              // CSS
5887                 $lateLaunchIndex = $fetchedRow['wd_launch_index'];              // 遅延実行インデックス
5888                 $shared = false;
5889                 if (empty($fetchedRow['pd_sub_id'])) $shared = true;// 共通属性あり
5890                 if ($this->nonSharedWidgetCount == -1) $this->nonSharedWidgetCount = 0;         // 初期化されていない場合は初期化
5891                 if (!$shared) $this->nonSharedWidgetCount++;    // 非共通ウィジェットの数を更新
5892                 
5893                 // ウィジェットが遅延実行に指定されている場合は、ウィジェットのタグのみ埋め込む
5894                 if ($lateLaunchIndex > 0){              // 遅延実行のとき
5895                         // 遅延実行ウィジェットリストに追加
5896                         if (!isset($this->lateLaunchWidgetList[$widgetId])){
5897                                 $this->lateLaunchWidgetList[$widgetId] = (int)$lateLaunchIndex;
5898                         }
5899                         // 実行パラメータ保存
5900                         $maxNo = 0;             // 最大シリアル番号
5901                         $count = count($this->latelaunchWidgetParam);
5902                         for ($i = 0; $i < $count; $i++){
5903                                 list($wId, $maxNo, $tmp1, $tmp2, $tmp3, $tmp4, $tmp5, $tmp6, $tmp7, $tmp8, $tmp9, $tmp10, $tmp11) = $this->latelaunchWidgetParam[$i];
5904                                 if ($wId == $widgetId) $maxNo = $maxNo + 1;
5905                         }
5906                         // Joomla!1.0テンプレートの場合はタイトルを修正
5907                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
5908                                 if (!empty($fetchedRow['pd_title'])) $title = $fetchedRow['pd_title'];
5909                         }
5910                         $this->latelaunchWidgetParam[] = array($widgetId, $maxNo, $configId, $prefix, $serial, $style, $cssStyle, $title, $shared, $exportCss, $position, $index, $fetchedRow);
5911                         
5912                         // 遅延実行用タグを埋め込む
5913                         $launchWidgetTag = self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;                // 遅延ウィジェット埋め込み用タグ
5914                         echo $launchWidgetTag;
5915                         
5916                         // タイトル用タグ作成
5917                         $titleTag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
5918                 } else {
5919                         // ウィジェットが存在する場合は実行
5920                         if (!file_exists($widgetIndexFile)) {
5921                                 if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
5922                         } else {
5923                                 // パラメータ初期化
5924                                 $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
5925                                 $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
5926                                 $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
5927                                 $this->lastHeadTitle = '';                      // ヘッダ部titleにセットした文字列
5928                                 $this->lastHeadDescription = '';        // ヘッダ部descriptionにセットした文字列
5929                                 $this->lastHeadKeywords = '';           // ヘッダ部keywordsにセットした文字列
5930                         
5931                                 // 現在のウィジェットのポジション
5932                                 $this->currentWidgetPosition = $position;                       // 現在のウィジェットのポジション
5933                                 $this->currentWidgetIndex = $index;                     // 現在のウィジェットのポジション番号
5934                                         
5935                                 // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
5936                                 $joomlaTitleVisble = false;
5937                                 if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
5938                                         if ($fetchedRow['pd_title_visible']){
5939                                                 if ($widgetHeaderType == 1){            // PC用出力のとき
5940                                                         $joomlaTitle = $fetchedRow['pd_title'];
5941                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
5942                                                         echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
5943                                                         echo '<tr><th>' . $joomlaTitle . '</th></tr>' . M3_NL;
5944                                                         echo '<tr><td>' . M3_NL;
5945                                                         $joomlaTitleVisble = true;
5946                                                 } else if ($widgetHeaderType == 2){             // 携帯用出力のとき
5947                                                         $joomlaTitle = $fetchedRow['pd_title'];
5948                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
5949                                                         echo '<div>' . $joomlaTitle . '</div>' . M3_NL;
5950                                                         $joomlaTitleVisble = true;
5951                                                 }
5952                                         }
5953                                 }
5954                                 // ウィジェットの外枠タグを設定
5955                                 //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
5956                                 // ウィジェット親のCSS定義があるときは、タグを追加
5957                                 if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
5958                                         
5959                                 // ウィジェットの前出力
5960                                 echo $gDesignManager->getAdditionalWidgetOutput(true);
5961                                 
5962                                 // 作業中のウィジェットIDを設定
5963                                 $gEnvManager->setCurrentWidgetId($widgetId);
5964         
5965                                 // ウィジェット定義IDを設定
5966                                 $gEnvManager->setCurrentWidgetConfigId($configId);
5967                         
5968                                 // ページ定義のシリアル番号を設定
5969                                 $gEnvManager->setCurrentPageDefSerial($fetchedRow['pd_serial']);
5970                                 
5971                                 // ページ定義レコードを設定
5972                                 $gEnvManager->setCurrentPageDefRec($fetchedRow);
5973                                 
5974                                 // パラメータを設定
5975                                 $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
5976                         
5977                                 // ウィジェットのヘッドタイトルを設定
5978                                 $gEnvManager->setCurrentWidgetHeadTitle($widgetHeadTitle);
5979
5980                                 // ウィジェットのタイトルを設定
5981                                 $gEnvManager->setCurrentWidgetTitle($title);
5982                                 
5983                                 // ウィジェットのスタイルを設定
5984                                 $gEnvManager->setCurrentWidgetStyle($style);
5985                                 
5986                                 // ウィジェットのグローバル属性状況を設定
5987                                 $gEnvManager->setIsCurrentWidgetShared($shared);
5988                                         
5989                                 // 実行ログを残す
5990                                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
5991                                 
5992                                 // ウィジェットを実行
5993                                 //require_once($widgetIndexFile);
5994                                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5995                                 $msg = 'widget-start(' . $widgetId . ')';
5996                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5997                                 require($widgetIndexFile);
5998                                 $msg = 'widget-end(' . $widgetId . ')';
5999                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
6000
6001                                 // 作業中のウィジェットIDを解除
6002                                 $gEnvManager->setCurrentWidgetId('');
6003                         
6004                                 // ウィジェット定義IDを解除
6005                                 $gEnvManager->setCurrentWidgetConfigId('');
6006                                 
6007                                 // ページ定義のシリアル番号を解除
6008                                 $gEnvManager->setCurrentPageDefSerial(0);
6009                         
6010                                 // ページ定義レコードを解除
6011                                 $gEnvManager->setCurrentPageDefRec();
6012                                 
6013                                 // パラメータを解除
6014                                 $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
6015
6016                                 // ウィジェットのスタイルを解除
6017                                 $gEnvManager->setCurrentWidgetStyle('');
6018                                 
6019                                 // ウィジェットのグローバル属性状況を解除
6020                                 $gEnvManager->setIsCurrentWidgetShared(false);
6021                                 
6022                                 // ウィジェットの後出力
6023                                 echo $gDesignManager->getAdditionalWidgetOutput(false);
6024 //                              echo "<!-- ".time()." -->";
6025
6026                                 // ウィジェット親のCSS定義があるときは、タグを追加
6027                                 if (!empty($cssStyle)) echo '</div>' . M3_NL;
6028                                 // ウィジェットの外枠タグを設定
6029                                 //echo '</div>' . M3_NL;
6030                                 
6031                                 // Joomla!1.0テンプレートのときはタイトルを出力
6032                                 if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用出力のとき
6033                                         echo '</td></tr>' . M3_NL;
6034                                         echo '</table>' . M3_NL;
6035                                 }
6036                         }
6037                 }
6038                 return true;            // 処理継続
6039         }
6040         /**
6041          * 定義IDを指定してウィジェットの出力を取得
6042          *
6043          * @param string $widgetId              ウィジェットID
6044          * @param int $configId                 ウィジェット定義ID
6045          * @return string                               ウィジェットの出力
6046          */
6047         function getWidgetOutput($widgetId, $configId = 0)
6048         {
6049                 global $gEnvManager;
6050                 global $gErrorManager;
6051
6052                 // ウィジェットのアクセス権をチェック
6053                 if (!$this->db->canAccessWidget($widgetId)) return '';
6054
6055                 // ウィジェット情報取得
6056                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
6057
6058                 // 端末タイプをチェック
6059                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
6060                 
6061                 // 必要なJavascriptライブラリを追加
6062                 $scritLib = trim($row['wd_add_script_lib']);
6063                 if (!empty($scritLib)) $this->addScript('', $scritLib);
6064                 
6065                 // バッファ作成
6066                 ob_start();
6067
6068                 // ウィジェット実行ファイル取得
6069                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
6070                                         
6071                 // 作業中のウィジェットIDを設定
6072                 $saveWidgetId = $gEnvManager->getCurrentWidgetId();
6073                 $gEnvManager->setCurrentWidgetId($widgetId);
6074
6075                 // ウィジェット定義IDを設定
6076                 $saveConfigId = $gEnvManager->getCurrentWidgetConfigId();
6077                 $gEnvManager->setCurrentWidgetConfigId($configId);
6078         
6079                 // ページ定義のシリアル番号を設定
6080                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
6081                         
6082                 // パラメータを設定
6083                 //$gEnvManager->setCurrentWidgetPrefix($prefix);                // プレフィックス文字列
6084         
6085                 // ウィジェットのタイトルを設定
6086                 //$gEnvManager->setCurrentWidgetTitle($title);
6087                 
6088                 // ウィジェットのグローバル属性状況を設定
6089                 //$gEnvManager->setIsCurrentWidgetShared($shared);
6090                         
6091                 // 実行ログを残す
6092                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
6093                 
6094                 // ウィジェットを実行
6095                 //require_once($widgetIndexFile);
6096                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
6097                 $msg = 'widget-start(' . $widgetId . ')';
6098                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
6099                 if (file_exists($widgetIndexFile)){
6100                         require($widgetIndexFile);
6101                 } else {
6102                         if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
6103                 }
6104                 $msg = 'widget-end(' . $widgetId . ')';
6105                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
6106
6107                 // 作業中のウィジェットIDを戻す
6108                 $gEnvManager->setCurrentWidgetId($saveWidgetId);
6109         
6110                 // ウィジェット定義IDを戻す
6111                 $gEnvManager->setCurrentWidgetConfigId($saveConfigId);
6112                 
6113                 // ページ定義のシリアル番号を解除
6114                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
6115         
6116                 // パラメータを解除
6117                 //$gEnvManager->setCurrentWidgetPrefix('');                             // プレフィックス文字列
6118
6119                 // ウィジェットのグローバル属性状況を解除
6120                 //$gEnvManager->setIsCurrentWidgetShared(false);
6121
6122                 // 現在のバッファ内容を取得し、バッファを破棄
6123                 $output = ob_get_contents();
6124                 ob_end_clean();
6125                                         
6126                 return $output;
6127         }
6128         /**
6129          * インナーウィジェットの操作
6130          *
6131          * @param int $cmdNo                            実行コマンド(0=初期化、1=更新、2=計算、10=コンテンツ取得)
6132          * @param string $id                            ウィジェットID+インナーウィジェットID
6133          * @param string $configId                      インナーウィジェット定義ID
6134          * @param object $paramObj                      インナーウィジェットに渡すパラメータオブジェクト
6135          * @param object $optionParamObj        インナーウィジェットに渡すパラメータオブジェクト(オプション)
6136          * @param object $resultObj                     インナーウィジェットから返る結果オブジェクト
6137          * @param string $content                       出力内容
6138          * @param bool $isAdmin                         管理者機能(adminディレクトリ以下)かどうか
6139          * @return bool                                         true=成功、false=失敗
6140          */
6141         function commandIWidget($cmdNo, $id, $configId, &$paramObj, &$optionParamObj, &$resultObj, &$content, $isAdmin = false)
6142         {
6143                 global $gEnvManager;
6144                 
6145                 // ウィジェットIDとインナーウィジェットIDを取り出す
6146                 list($widgetId, $iWidgetId) = explode(M3_WIDGET_ID_SEPARATOR, $id);
6147
6148                 // インナーウィジェットに渡すパラメータを設定
6149                 switch ($cmdNo){
6150                         case 0:
6151                                 $cmd = self::IWIDTET_CMD_INIT;                  // 初期化
6152                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
6153                                 break;
6154                         case 1:
6155                                 $cmd = self::IWIDTET_CMD_UPDATE;                // 更新
6156                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
6157                                 break;
6158                         case 2:
6159                                 $cmd = self::IWIDTET_CMD_CALC;                  // 計算
6160                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
6161                                 break;
6162                         case 10:
6163                                 $cmd = self::IWIDTET_CMD_CONTENT;                       // コンテンツ取得
6164                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
6165                                 break;
6166                         default:
6167                                 $cmd = '';
6168                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
6169                                 break;
6170                 }
6171
6172                 // インナーウィジェットのエラー出力は呼び出しウィジェット側で受けるため、出力を抑止する
6173                 ob_start();// バッファ作成
6174
6175                 // ウィジェット実行ファイル取得
6176                 if (empty($widgetId)){          // ウィジェットIDが指定されていないときは共通ディレクトリ
6177                 //$gEnvManager->getIWidgetsPath() . '/' . $iWidgetId . '/' . $containerClass . '.php';
6178                 } else {
6179                         if ($isAdmin){
6180                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/' . M3_DIR_NAME_ADMIN . '/index.php';
6181                         } else {
6182                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/index.php';
6183                         }
6184                 }
6185
6186                 // 作業中のインナーウィジェットIDを設定
6187                 $gEnvManager->setCurrentIWidgetId($id);         // インナーウィジェットを設定
6188
6189                 // インナーウィジェット定義IDを設定
6190                 $gEnvManager->setCurrentIWidgetConfigId($configId);
6191                 
6192                 // ウィジェットを実行
6193                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
6194                 if (file_exists($widgetIndexFile)){
6195                         require($widgetIndexFile);
6196                 } else {
6197                         echo 'file not found error: ' . $widgetIndexFile;
6198                 }
6199                 
6200                 // 作業中のウィジェットIDを解除
6201                 $gEnvManager->setCurrentIWidgetId('');
6202         
6203                 // インナーウィジェット定義IDを解除
6204                 $gEnvManager->setCurrentIWidgetConfigId('');
6205                 
6206                 // 現在のバッファ内容を取得し、バッファを破棄
6207                 $content = ob_get_contents();
6208                 ob_end_clean();
6209                 
6210                 // 値を再取得
6211                 if ($this->gInstance->getCmdParamManager()->getParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $obj, $option)){
6212                         $paramObj = $obj;
6213                         $optionParamObj = $option;
6214                 }
6215
6216                 // 結果を取得
6217                 if ($this->gInstance->getCmdParamManager()->getResult($id . M3_WIDGET_ID_SEPARATOR . $configId, $resObj)) $resultObj = $resObj;
6218                 return true;
6219         }
6220         /**
6221          * コールバックメソッドを実行し、出力を返す
6222          *
6223          * @param array $callback               実行するコールバック
6224          * @return string                               出力結果
6225          */
6226         function getOutputByCallbackMethod($callback)
6227         {
6228                 ob_start();// バッファ作成
6229                 
6230                 // コールバック関数を実行
6231                 if (is_callable($callback)) call_user_func($callback);
6232                 
6233                 // 現在のバッファ内容を取得し、バッファを破棄
6234                 $content = ob_get_contents();
6235                 ob_end_clean();
6236                 return $content;
6237         }
6238         /**
6239          * ページ作成処理中断を行った場合のレスポンスヘッダ設定
6240          *
6241          * @param int $responseCode             レスポンスコード
6242          * @return                                              なし
6243          */
6244         function setResponse($responseCode)
6245         {
6246                 switch ($responseCode){
6247                         case 400:                       // リクエストにエラーがあるとき
6248                                 header('HTTP/1.1 400 Bad request');
6249                                 header('Status: 400 Bad request');
6250                                 break;
6251                         case 403:                       // アクセス禁止のとき
6252                                 header('HTTP/1.1 403 Forbidden');
6253                                 header('Status: 403 Forbidden');
6254                                 break;
6255                         case 404:                       // 存在しないページのとき
6256                                 header("HTTP/1.1 404 Not Found");
6257                                 header("Status: 404 Not Found");
6258                                 break;
6259                         case 500:                       // サーバ内部エラー
6260                                 header('HTTP/1.1 500 Internal Server Error');
6261                                 header('Status: 500 Internal Server Error');
6262                                 break;
6263                         case 503:                       // サイト非公開(システムメンテナンス)
6264                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
6265                                 header('Status: 503 Service Temporarily Unavailable');
6266                                 break;
6267                 }
6268         }
6269         /**
6270          * ファイルダウンロード
6271          *
6272          * @param string $filePath                      ダウンロードするファイルのファイルパス
6273          * @param string $downloadFilename      ダウンロード時のファイル名
6274          * @param bool   $deleteFile            実行後ファイルを削除するかどうか(成功失敗に関係なく)
6275          * @return bool                                         true=成功、false=失敗
6276          */
6277         function downloadFile($filePath, $downloadFilename, $deleteFile=false)
6278         {
6279                 // エラーチェック
6280                 if (!file_exists($filePath)) return false;
6281                 
6282                 // ファイルサイズ取得
6283                 $fileSize = filesize($filePath);
6284                 
6285                 // バッファ内容が残っているときは破棄
6286                 if (ob_get_level() > 0) ob_end_clean();
6287                 
6288                 header('Cache-Control: public');                // IE6+SSHでダウンロードエラーが出る問題を回避
6289                 header('Pragma: public');                               // IE6+SSHでダウンロードエラーが出る問題を回避
6290             header('Content-Disposition: attachment; filename=' . $downloadFilename);
6291                 header('Content-Length: ' . $fileSize);
6292             header('Content-Type: application/octet-stream; name=' . $downloadFilename);
6293             $fp = fopen($filePath, "r");
6294             echo fread($fp, $fileSize);
6295             fclose($fp);
6296                 
6297                 ob_end_flush();
6298                 
6299                 // ファイル削除
6300                 if ($deleteFile) unlink($filePath);
6301                 return true;
6302         }
6303         /**
6304          * システム制御ページを表示するかどうかを返す
6305          *
6306          * @return bool         true=システム制御ページを表示、false=システム制御ページを表示しない
6307          */
6308         function isSystemPage()
6309         {
6310                 return $this->isSystemPage;
6311         }
6312         /**
6313          * 指定URLへリダイレクト
6314          *
6315          * @param string $url                   遷移先URL。未指定の場合は現在のスクリプト。URLでないときは、現在のスクリプトに付加。
6316          * @param bool $noMessage               画面を遷移させたとき、ドコモ携帯端末でダイアログ(サイトが移動しました(301))が出ないようにするオプション
6317          * @param int  $responseCode    レスポンスコード
6318          * @param bool $autoSsl                 リダイレクト先のページの状態に合わせてSSLを制御するかどうか
6319          * @return                                              なし
6320          */
6321         function redirect($url = '', $noMessage = false, $responseCode = 0, $autoSsl = true)
6322         {
6323                 global $gEnvManager;
6324
6325                 // すでにリダイレクトが設定されている場合は終了
6326                 if ($this->isRedirect) return;                          // リダイレクトするかどうか
6327                 
6328                 $toUrl = $url;
6329                 if (empty($toUrl)){
6330                         $toUrl = $gEnvManager->getCurrentScriptUrl();
6331                 } else if (strncmp($toUrl, 'http://', 7) != 0 && strncmp($toUrl, 'https://', 8) != 0){  // URL以外のときはクエリー文字列と判断する
6332                         $toUrl = $gEnvManager->getCurrentScriptUrl() . $toUrl;
6333                 }
6334
6335                 // SSL化が必要な場合はhttpsに変更
6336                 if ($autoSsl){
6337                         $isSslPage = false;
6338                         if ($gEnvManager->isAdminUrlAccess($toUrl)){            // 管理画面へのアクセスのとき
6339                                 // ルートURLがSSLの場合は管理画面は常にSSL付き
6340                                 if ($gEnvManager->isRootUrlSsl()) $isSslPage = true;
6341                                 
6342                                 // 管理画面のSSL状態を参照
6343                                 if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
6344                         } else {                // フロント画面へのアクセスのとき
6345                                 // ファイル名を取得
6346                                 $paramArray = array();
6347                                 //list($filename, $query) = explode('?', basename($toUrl));
6348                                 list($url, $query) = explode('?', $toUrl);
6349                                 $baseUrl = dirname($url);
6350                                 $filename = basename($url);
6351                                 if (empty($filename)) $filename = M3_FILENAME_INDEX;
6352                                 if (!empty($query)) parse_str($query, $paramArray);             // クエリーの解析
6353                 
6354                                 // ページIDを取得
6355                                 $pageId = basename($filename, '.php');
6356                                 $pageSubId = $paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID];
6357                         
6358                                 // ページのSSL設定状況を取得
6359                                 $isSslPage = $this->isSslPage($pageId, $pageSubId);
6360                         
6361                                 // 階層化ページの場合はURLを修正
6362                                 if ($this->gSystem->hierarchicalPage() && $filename == M3_FILENAME_INDEX){
6363                                         $toUrl = $baseUrl . '/' . $pageSubId . '/';
6364                                         unset($paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID]);
6365                                         
6366                                         $paramStr = $this->_createUrlParamStr($paramArray);
6367                                         if (!empty($paramStr)) $toUrl .= '?' . $paramStr;
6368                                 }
6369                         }
6370                         if ($isSslPage){
6371                                 //$toUrl = str_replace('http://', 'https://', $toUrl);
6372                                 $toUrl = $gEnvManager->getSslUrl($toUrl);               // SSL用URLに変換
6373                         } else {
6374                                 $toUrl = str_replace('https://', 'http://', $toUrl);
6375                         }
6376                 }
6377
6378                 // バッファ内容が残っているときは破棄
6379                 if (ob_get_level() > 0) ob_end_clean();
6380
6381                 if (empty($responseCode)){
6382                         if ($noMessage){
6383                                 header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
6384                         } else {
6385 //                              header('HTTP/1.1 301 Moved Permanently');
6386                                 header('HTTP/1.1 302 Moved Temporary');                         // ドメインのURLをHTTPからHTTPに変更するとChromeで問題が発生したので301から302リダイレクトに変更(2018/4/30)
6387                         }
6388                 } else {                // レスポンスコードが指定されている場合
6389                         switch ($responseCode){
6390                                 case 301:
6391                                         // ##### 301リダイレクトはChromeではブラウザにキャッシュされてしまうので注意 #####
6392                                         header('HTTP/1.1 301 Moved Permanently');
6393                                         break;
6394                                 case 302:
6395                                         header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
6396                                         break;
6397                                 case 303:
6398                                         header('HTTP/1.1 303 See Other');
6399                                         break;
6400                                 case 500:                       // サーバ内部エラー
6401                                         header('HTTP/1.1 500 Internal Server Error');
6402                                         header('Status: 500 Internal Server Error');
6403                                         break;
6404                                 case 503:                       // サイト非公開(システムメンテナンス)
6405                                         header('HTTP/1.1 503 Service Temporarily Unavailable');
6406                                         header('Status: 503 Service Temporarily Unavailable');
6407                                         break;
6408                                 default:
6409                                         header('HTTP/1.1 ' . (string)$responseCode);
6410                                         break;
6411                         }
6412                 }
6413                 header('Location: ' . $toUrl);
6414                 
6415                 $this->isRedirect = true;                               // リダイレクトするかどうか
6416         }
6417         /**
6418          * リダイレクト処理かどうかを返す
6419          *
6420          * @return bool         true=リダイレクト、false=リダイレクトでない
6421          */
6422         function isRedirect()
6423         {
6424                 return $this->isRedirect;
6425         }
6426         /**
6427          * 指定URLのディレクトリへリダイレクト
6428          *
6429          * @return                                              なし
6430          */
6431         function redirectToDirectory()
6432         {
6433                 global $gEnvManager;
6434
6435                 // ファイル名を削除
6436                 $dirPath = dirname($gEnvManager->getCurrentScriptUrl()) . '/';
6437                 //$this->redirect($dirPath);
6438                 $this->redirect($dirPath, false, 303, false/*SSLは自動制御しない*/);                    // Firefoxでredirect先がキャッシュに残る問題を回避(2012/7/23)
6439         }
6440         /**
6441          * インストール時のリダイレクト処理
6442          *
6443          * @param string $url                   遷移先URL
6444          * @return                                              なし
6445          */
6446         function redirectInInstall($url)
6447         {
6448                 $this->redirect($url, false, 303, false/*SSLは自動制御しない*/);                        // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
6449         }
6450         /**
6451          * インストール用URLへリダイレクト
6452          *
6453          * @return                                              なし
6454          */
6455         function redirectToInstall()
6456         {
6457                 global $gEnvManager;
6458                 
6459                 $sytemRootUrl = $gEnvManager->calcSystemRootUrl();
6460                 //$this->redirect($sytemRootUrl . '/admin/install.php');
6461                 $this->redirect($sytemRootUrl . '/admin/install.php', false, 303, false/*SSLは自動制御しない*/);                        // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
6462         }
6463         /**
6464          * ログイン、ログアウト処理を行った後、リダイレクト
6465          *
6466          * @param RequestManager        $request                HTTPリクエスト処理クラス
6467          * @param bool                          $success                ログインの成否
6468          * @param string                        $redirectUrl    ログイン成功の場合のリダイレクト先
6469          * @return int                                                          0=何も処理しなかった場合、1=ログイン処理、2=ログアウト処理、3=パスワード送信
6470          */
6471         function standardLoginLogoutRedirect($request, &$success, $redirectUrl = '')
6472         {
6473                 global $gEnvManager;
6474                 global $gAccessManager;
6475                 global $gRequestManager;
6476                 
6477                 // ログイン、ログアウト処理、および、コンテナの起動
6478                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
6479                 if ($cmd == M3_REQUEST_CMD_LOGIN){                      // ログインの場合
6480                         $act = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_ACT);
6481                         if ($act == 'sendpwd'){         // パスワード送信の場合
6482                                 $success = $gAccessManager->sendPassword($request);
6483                                 return 3;
6484                         } else {
6485                                 // ユーザ認証
6486                                 $ret = $gAccessManager->userLogin($request);
6487                                 if ($ret){
6488                                         if (empty($redirectUrl)){
6489                                                 // システム運用可能ユーザの場合でリダイレクト先が設定されていない場合はデフォルトの管理画面URLへ遷移
6490                                                 $userInfo = $gEnvManager->getCurrentUserInfo();// ユーザ情報取得
6491                                                 if ($userInfo->userType >= UserInfo::USER_TYPE_MANAGER){
6492                                                         $ret = $this->db->getLoginUserRecordById($userInfo->userId, $userInfoRow);
6493                                                         if ($ret && !empty($userInfoRow['lu_default_admin_url'])){
6494                                                                 $redirectUrl = $gEnvManager->getDefaultAdminUrl() . $userInfoRow['lu_default_admin_url'];
6495                                                         }
6496                                                 }
6497                                         }
6498                                 
6499                                         // リダイレクト処理
6500                                         $this->redirect($redirectUrl);
6501                                         $success = true;                // ログイン成功
6502                                 } else {        // ログイン失敗のとき
6503                                         $success = false;               // ログイン失敗
6504                                 }
6505                                 return 1;
6506                         }
6507                 } else if ($cmd == M3_REQUEST_CMD_LOGOUT){              // ログアウト
6508                         // ログアウト処理
6509                         $gAccessManager->userLogout(true);
6510                         
6511                         // リダイレクト処理
6512                         $this->redirect($redirectUrl);
6513                         return 2;
6514                 } else {
6515                         return 0;
6516                 }
6517         }
6518         /**
6519          * エラー画面を表示
6520          *
6521          * @param int $errStatus                HTTPエラーステータスコード
6522          * @return                                              なし
6523          */
6524         function showError($errStatus)
6525         {
6526                 // レスポンスヘッダ設定
6527                 $this->setResponse($errStatus);
6528                 
6529                 // メッセージ設定
6530                 $msg = 'NOT DEFINED ERROR';
6531                 switch ($errStatus){
6532                         case 403:                       // アクセス禁止のとき
6533                                 $msg = 'Forbidden';
6534                                 break;
6535                         case 404:                       // 存在しないページのとき
6536                                 $msg = 'Not Found';
6537                                 break;
6538                         case 500:                       // サーバ内部エラー
6539                                 $msg = 'Internal Server Error';
6540                                 break;
6541                         case 503:                       // サイト非公開(システムメンテナンス)
6542                                 $msg = 'Service Temporarily Unavailable';
6543                                 break;
6544                 }
6545                 
6546                 echo '<!doctype html>';
6547                 echo '<html>';
6548                 echo '<head>';
6549                 echo '<title>' . $msg . '</title>';
6550                 echo '</head>';
6551                 echo '<body>';
6552                 echo '<h2>' . $msg . '</h2>';
6553                 echo '</body>';
6554                 echo '</html>';
6555         }
6556         /**
6557          * ウィジェットがセットされているページサブIDを取得
6558          *
6559          * @param string $pageId                ページID
6560          * @param string $widgetId              対象ウィジェットID
6561          * @param int $configId                 ウィジェット定義ID
6562          * @return string                               ページサブID
6563          */
6564         function getPageSubIdByWidget($pageId, $widgetId, $configId = 0)
6565         {
6566                 $pageSubId = '';
6567                 
6568                 // 対象のウィジェットのページサブIDを取得
6569                 $ret = $this->db->getSubPageId($widgetId, $pageId, $rows);
6570                 if ($ret){// データが存在する
6571                         for ($i = 0; $i < count($rows); $i++){
6572                                 if (!empty($rows[$i]['pd_sub_id']) && $rows[$i]['pd_config_id'] == $configId){
6573                                         $pageSubId = $rows[$i]['pd_sub_id'];
6574                                         break;
6575                                 }
6576                         }
6577                 }
6578                 return $pageSubId;
6579         }
6580         /**
6581          * その他のGET,POSTパラメータからページサブID取得
6582          *
6583          * @param RequestManager $request               HTTPリクエスト処理クラス
6584          * @param string $redirectUrl                   リダイレクト用URL
6585          * @return string                                               ページサブID
6586          */
6587         function getPageSubIdByParam($request, &$redirectUrl)
6588         {
6589                 global $gEnvManager;
6590                 
6591                 $subId = '';
6592                 $redirectUrl = '';
6593                 $task = $request->trimValueOf('task');
6594                 $option = $request->trimValueOf('option');
6595                 if ($task == 'search' && $option == 'com_search'){              // joomla!の検索結果表示の場合
6596                         $this->contentType = M3_VIEW_TYPE_SEARCH;               // ページのコンテンツタイプ
6597                                 
6598                         $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_SEARCH, $gEnvManager->getCurrentPageId());// ページサブIDを取得
6599                         if (!empty($subId)){
6600                                 // リダイレクト用URLを作成
6601                                 $keyword = $request->trimValueOf('searchword');
6602                                 $redirectUrl = $gEnvManager->createPageUrl();
6603                                 $redirectUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subId;
6604                                 $redirectUrl .= '&' . M3_REQUEST_PARAM_OPERATION_TASK . '=search&' . M3_REQUEST_PARAM_KEYWORD . '=' . urlencode($keyword);
6605                         }
6606                 }
6607                 return $subId;
6608         }
6609         /**
6610          * コンテンツタイプとページIDからページサブID取得
6611          *
6612          * @param string $contentType   コンテンツタイプ
6613          * @param string $pageId                ページID
6614          * @return string                               ページサブID
6615          */
6616         function getPageSubIdByContentType($contentType, $pageId)
6617         {
6618                 $subId = $this->db->getSubPageIdWithContent($contentType, $pageId);// ページサブIDを取得
6619                 return $subId;
6620         }
6621         /**
6622          * 指定のウィジェットがページ上にあるかを取得
6623          *
6624          * @param string $pageId                ページID
6625          * @param string $widgetId              対象ウィジェットID
6626          * @param bool $activePageOnly  公開中のページのウィジェットに制限するかどうか。falseの場合はすべてのページのウィジェットを対象とする。
6627          * @return bool                                 true=ページ上にあり、false=ページ上になし
6628          */
6629         function isWidgetOnPage($pageId, $widgetId, $activePageOnly=true)
6630         {
6631                 $ret = $this->db->isWidgetOnPage($pageId, $widgetId, $activePageOnly, 0/*定義セットID*/);
6632                 return $ret;
6633         }
6634         /**
6635          * URLで示されるページ上のウィジェットをウィジェット種別で取得
6636          *
6637          * @param string $url                   URL
6638          * @param string $widgetType    対象ウィジェットタイプ
6639          * @return string                               ウィジェットID
6640          */
6641         function getWidgetIdByWidgetType($url, $widgetType)
6642         {
6643                 $ret = $this->getPageIdFromUrl($url, $pageId, $pageSubId, $param);
6644                 
6645                 // ウィジェットIDを取得
6646                 if ($ret) $widgetId = $this->db->getWidgetIdByType($pageId, $pageSubId, $widgetType);
6647                 return $widgetId;
6648         }
6649         /**
6650          * ページコンテンツタイプ、コンテンツタイプからウィジェットIDを取得
6651          *
6652          * @param string $pageId                ページID
6653          * @param string $contentType    コンテンツタイプ
6654          * @return string                               ウィジェットID
6655          */
6656         function getWidgetIdWithPageInfoByContentType($pageId, $contentType)
6657         {
6658                 $widgetId = $this->db->getWidgetIdWithPageInfoByContentType($pageId, $contentType);
6659                 return $widgetId;
6660         }
6661         /**
6662          * ジョブタイプからウィジェットIDを取得
6663          *
6664          * @param string $jobType               ジョブタイプ
6665          * @return string                               ウィジェットID
6666          */
6667         function getWidgetIdByJobType($jobType)
6668         {
6669                 global $gEnvManager;
6670                 global $gErrorManager;
6671
6672                 // ジョブ実行用ウィジェット取得
6673                 $widgetId = '';
6674                 $linkInfoObj = $this->gInstance->getObject(self::LINKINFO_OBJ_ID);
6675                 if (isset($linkInfoObj)) $widgetId = $linkInfoObj->getJobWidget($jobType);
6676                 
6677                 // ウィジェットのアクセス権をチェック
6678                 if (!$this->db->canAccessWidget($widgetId)) return '';
6679
6680                 // ウィジェット情報取得
6681                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
6682
6683                 // 端末タイプをチェック
6684                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
6685                 
6686                 return $widgetId;
6687         }
6688         /**
6689          * 現在アクティブなメイン型ウィジェットをウィジェット種別で取得
6690          *
6691          * @param string $widgetType    対象ウィジェットタイプ
6692          * @return string                               ウィジェットID
6693          */
6694         function getActiveMainWidgetIdByWidgetType($widgetType)
6695         {
6696                 // ウィジェットIDを取得
6697                 $widgetId = $this->db->getActiveMainWidgetIdByType($widgetType);
6698                 return $widgetId;
6699         }
6700         /**
6701          * URLを解析して、ページID,サブページIDを取得
6702          *
6703          * @param string $url                   URL
6704          * @param string $pageId                ページID
6705          * @param string $pageSubId             ページサブID
6706          * @param array  $urlParam              URLパラメータ
6707          * @return bool                                 true=成功、false=失敗
6708          */
6709         function getPageIdFromUrl($url, &$pageId, &$pageSubId, &$urlParam)
6710         {
6711                 global $gEnvManager;
6712                         
6713                 // ページID、ページサブIDを求める
6714                 list($page, $other) = explode('?', str_replace($gEnvManager->getRootUrl(), '', $url));
6715                 parse_str($other, $urlParam);
6716                 
6717                 $pageId = str_replace('/', '_', trim($page, '/'));
6718                 $pageId = basename($pageId, '.php');
6719
6720                 // ページサブIDを取得
6721                 $pageSubId = $param[M3_REQUEST_PARAM_PAGE_SUB_ID];
6722                 if (empty($pageSubId)) $pageSubId = $gEnvManager->getDefaultPageSubId();
6723                 return true;
6724         }
6725         /**
6726          * ウィジェットが組み込まれているページのURLを生成
6727          *
6728          * @param string $widgetId      送信元ウィジェットID
6729          * @param string $param         実行パラメータ
6730          * @param string $pageId        ウィジェットが存在するページID
6731          * @return string                       生成したURL
6732          */
6733         function getDefaultPageUrlByWidget($widgetId, $param = '', $pageId = '')
6734         {
6735                 global $gEnvManager;
6736
6737                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6738                 
6739                 // このウィジェットがマップされているページサブIDを取得
6740                 $sub = '';
6741                 $subPageId = $this->getPageSubIdByWidget($pageId, $widgetId);
6742                 if (empty($subPageId)){
6743                         // 見つからないときは互換ウィジェットを探す
6744                         $targetWidgetId = $this->db->getCompatibleWidgetId($widgetId);
6745                         if (!empty($targetWidgetId)){
6746                                 $subPageId = $this->getPageSubIdByWidget($pageId, $targetWidgetId);
6747                         }
6748                 }
6749                 if (!empty($subPageId)) $sub = M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subPageId;
6750                 
6751                 //$url = $gEnvManager->getDefaultUrl();
6752                 $url = $gEnvManager->createPageUrl($pageId);
6753                 if (!empty($sub)) $url .= '?' . $sub;
6754                 if (!empty($param)) $url .= '&' . $param;
6755                 return $url;
6756         }
6757         /**
6758          * 現在のアクセスポイントの指定のページ属性のページURLを生成
6759          *
6760          * @param string $contentType   コンテンツタイプ
6761          * @param string $param                 追加パラメータ
6762          * @param bool $omitPageId              ページID省略形を使用するかどうか
6763          * @return string                               生成したURL
6764          */
6765         function createContentPageUrl($contentType, $param = '', $omitPageId = true)
6766         {
6767                 global $gEnvManager;
6768                 static $urlArray = array();
6769                 
6770                 // 複数回呼ばれるのでコンテンツタイプごとにページまでのURLは保存しておく
6771                 $baseUrl = $urlArray[$contentType];
6772                 if (!isset($baseUrl)){
6773                         // コンテンツタイプからページサブIDを取得
6774                         $pageSubId = $this->getPageSubIdByContentType($contentType, $gEnvManager->getCurrentPageId());          // DBから取得
6775                 
6776                         if (empty($pageSubId)){ // ページサブIDが取得できない場合はデフォルトのページサブIDを取得
6777                                 $pageSubId = $gEnvManager->getDefaultPageSubId();
6778                         } else if ($pageSubId == $gEnvManager->getDefaultPageSubId()){          // デフォルトページの場合
6779                                 if ($omitPageId) $pageSubId = '';       // ページID省略形を使用する場合はページサブIDを省略
6780                         }
6781                         
6782                         // 現在のアクセスポイントのURLを取得
6783                         $baseUrl = $gEnvManager->createPageUrl();
6784                         
6785                         // ページサブIDを付加
6786                         if (!empty($pageSubId)) $baseUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId;
6787                         
6788                         // URLを保存
6789                         $urlArray[$contentType] = $baseUrl;
6790                 }
6791                 
6792                 // 追加パラメータ
6793                 $url = $baseUrl;
6794                 if (!empty($param)){
6795                         if (strEndsWith($url, '.php') || strEndsWith($url, '/')){
6796                                 $url .= '?';
6797                         } else {
6798                                 $url .= '&';
6799                         }
6800                         $url .= $param;
6801                 }
6802                 return $url;
6803         }
6804         /**
6805          * ウィジェット指定呼び出し用のURLを生成
6806          *
6807          * @param string $toWidgetId    送信先ウィジェットID
6808          * @param string $fromWidgetId  送信元ウィジェットID
6809          * @param string $todo                  実行パラメータ
6810          * @param string $pageId                ページID(空のときは現在のURL)
6811          * @return string                               生成したURL
6812          */
6813         function createWidgetCmdUrl($toWidgetId, $fromWidgetId, $todo, $pageId = '')
6814         {
6815                 global $gEnvManager;
6816                 
6817                 $url = $gEnvManager->createPageUrl($pageId);
6818                 
6819                 $url .= '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_FIND_WIDGET;
6820                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $toWidgetId;
6821                 if (!empty($fromWidgetId)) $url .= '&' . M3_REQUEST_PARAM_FROM . '=' . $fromWidgetId;           // 送信元
6822                 if (!empty($todo)) $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=' . urlencode($todo);
6823                 return $url;
6824         }
6825         /**
6826          * RSS配信用のURLを生成
6827          *
6828          * @param string $widgetId              実行ウィジェットID
6829          * @param string $optionParam   追加パラメータ
6830          * @param string $pageId                ページID(空のときは現在のURL)
6831          * @param string $pageSubId             ページサブID
6832          * @return string                               生成したURL
6833          */
6834         function createRssCmdUrl($widgetId, $optionParam = '', $pageId = '', $pageSubId = '')
6835         {
6836                 global $gEnvManager;
6837                 
6838                 // 現在のページURLを取得
6839                 $url = $gEnvManager->createPageUrl() . '?';
6840                 
6841                 // ページサブIDを取得
6842                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // グローバル属性ありのときは空
6843                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6844                 
6845                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_RSS;
6846                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
6847                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6848                 return $url;
6849         }
6850         /**
6851          * CSS生成用のURLを生成
6852          *
6853          * @param bool   $isSslPage             SSLが必要なページかどうか
6854          * @param string $optionParam   追加パラメータ
6855          * @return string                               生成したURL
6856          */
6857         function createCssCmdUrl($isSslPage, $optionParam = '')
6858         {
6859                 global $gEnvManager;
6860                 global $gRequestManager;
6861                 
6862                 // 現在のページURLを取得
6863         //      $url = $gEnvManager->createPageUrl() . '?';
6864                 $url = $gEnvManager->createPageUrl(''/*現在のページ*/, $isSslPage) . '?';
6865                 
6866                 // ページサブIDを取得
6867                 $pageSubId = $this->gEnv->getCurrentPageSubId();
6868                 $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6869                 
6870                 // コンテンツ詳細画面の場合はコンテンツパラメータを追加
6871                 if ($this->isContentDetailPage){
6872                         switch ($this->contentType){
6873                                 case M3_VIEW_TYPE_CONTENT:              // 汎用コンテンツ
6874                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_CONTENT_ID);
6875                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_CONTENT_ID_SHORT);
6876                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentsId . '&';
6877                                         break;
6878                                 case M3_VIEW_TYPE_PRODUCT:      // 製品
6879                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PRODUCT_ID);
6880                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PRODUCT_ID_SHORT);
6881                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_PRODUCT_ID . '=' . $contentsId . '&';
6882                                         break;
6883                                 case M3_VIEW_TYPE_BBS:  // BBS
6884                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BBS_THREAD_ID);
6885                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT);
6886                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $contentsId . '&';
6887                                         break;
6888                                 case M3_VIEW_TYPE_BLOG: // ブログ
6889                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BLOG_ENTRY_ID);
6890                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT);
6891                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $contentsId . '&';
6892                                         break;
6893                                 case M3_VIEW_TYPE_WIKI: // Wiki
6894                                         $contentsId = $gRequestManager->getWikiPageFromQuery();         // 「=」なしのパラメータはwikiパラメータとする
6895                                         if (!empty($contentsId)) $url .= $contentsId . '&';
6896                                         break;
6897                                 case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ
6898                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_ROOM_ID);
6899                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_ROOM_ID_SHORT);
6900                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_ROOM_ID . '=' . $contentsId . '&';
6901                                         break;
6902                                 case M3_VIEW_TYPE_EVENT:        // イベント
6903                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_EVENT_ID);
6904                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_EVENT_ID_SHORT);
6905                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_EVENT_ID . '=' . $contentsId . '&';
6906                                         break;
6907                                 case M3_VIEW_TYPE_PHOTO:        // フォトギャラリー
6908                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID);
6909                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID_SHORT);
6910                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_PHOTO_ID . '=' . $contentsId . '&';
6911                                         break;
6912                         }
6913                 }
6914                 
6915                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_CSS;
6916                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6917                 return $url;
6918         }
6919         /**
6920          * ウィジェット実行用のURLを生成
6921          *
6922          * @param string $widgetId      実行ウィジェットID
6923          * @param string $optionParam   追加パラメータ
6924          * @param bool $byMacro         マクロ変換で返すかどうか
6925          * @param string $pageId                ページID(空のときは現在のURL)
6926          * @param string $pageSubId             ページサブID
6927          * @return string                               生成したURL
6928          */
6929         function createDirectWidgetCmdUrl($widgetId, $optionParam = '', $byMacro = false, $pageId = '', $pageSubId = '')
6930         {
6931                 global $gEnvManager;
6932                 
6933                 // 現在のページURLを取得
6934                 if ($byMacro){
6935                         $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_FILENAME_INDEX . '?';
6936                 } else {
6937                         $url = $gEnvManager->createPageUrl() . '?';
6938                 }
6939                 
6940                 // ページサブIDを取得
6941                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // グローバル属性ありのときは空
6942                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6943                 
6944                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_DO_WIDGET;
6945                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
6946                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6947                 return $url;
6948         }
6949         /**
6950          * URLパラメータの並び順を取得
6951          *
6952          * @return array                                        パラメータ文字列の配列
6953          */
6954         function getUrlParamOrder()
6955         {
6956                 return $this->urlParamOrder;                                    // URLパラメータの並び順
6957         }
6958         /**
6959          * キャッシュ制御用の付加パラメータを取得
6960          *
6961          * @return string                               パラメータ
6962          */     
6963         function getCacheParam()
6964         {
6965                 $addParam = '?' . date('YmdHis');
6966                 return $addParam;
6967         }
6968         /**
6969          * 現在のURLにアクセス可能かチェック
6970          *
6971          * @param bool $isActivePage    ページが有効かどうか
6972          * @param int  $errCode                 エラーコード
6973          * @return bool                                 true=可能、false=不可
6974          */     
6975         function canAccessUrl(&$isActivePage, &$errCode)
6976         {
6977                 global $gEnvManager;
6978
6979                 $errCode = 0;                   // エラーコード初期化
6980                 
6981                 // 現在設定されているページIDを取得
6982                 $pageId         = $gEnvManager->getCurrentPageId();
6983                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
6984                 $ret = $this->db->canAccessPage($pageId, $pageSubId, $pageVisible, $pageSubVisible, $isAdminMenu);
6985                 if ($ret){              // アクセス可能なときは、ユーザ制限もチェックする
6986                         $isActivePage = true;
6987                         
6988                         // ページが表示可能かチェック
6989                         if (!$pageVisible || !$pageSubVisible) return false;
6990
6991                         if (!$gEnvManager->isCurrentUserLogined() && $this->isUserLimitedPage($pageId, $pageSubId)){                    // ユーザがログインされていない状態でユーザ制限されていればアクセス不可
6992                                 return false;
6993                         } else {
6994                                 $this->isAccessPointWithAdminMenu = $isAdminMenu;                               // 管理メニューを使用するアクセスポイントかどうか
6995                                 return true;
6996                         }
6997                 } else {                        // 無効ページのとき
6998                         $isActivePage = false;
6999                         
7000                         // ページIDの文字のチェック。ページIDは半角英小文字、数字、アンダーバー、ハイフンのみ使用可能。
7001                         if (preg_match("/[^0-9a-z-_]/", $pageSubId)) $errCode = 1;                      // 不正文字検出
7002                 }
7003                 return false;
7004         }
7005         /**
7006          * ウィジェットヘッダ(Joomla!1.0用)を出力タイプを取得
7007          *
7008          * @return int                          0=出力しない、1=Joomla!1.0テンプレートPC用、2=Joomla!1.0テンプレート携帯用
7009          */     
7010         function getTemplateWidgetHeaderType()
7011         {
7012                 global $gEnvManager;
7013                 
7014                 $templateId = $gEnvManager->getCurrentTemplateId();
7015                 if ($templateId == self::ADMIN_TEMPLATE ||              // PC管理用テンプレート
7016                         $templateId == self::M_ADMIN_TEMPLATE){         // 携帯管理用テンプレート
7017                         return 0;
7018                 } else if(strncmp($templateId, 'm/', 2) == 0){          // 携帯用テンプレート
7019                         return 2;               // 携帯テンプレート用出力
7020                 } else {
7021                         return 1;               // PCテンプレート用出力
7022                 }
7023         }
7024         /**
7025          * SSLが必要なページかどうかを判断
7026          *
7027          * @param string $pageId        ページID
7028          * @param string $pageSubId     ページサブID
7029          * @return bool                         true=必要、false=不要
7030          */     
7031         function isSslPage($pageId, $pageSubId)
7032         {
7033                 global $gEnvManager;
7034                 
7035                 // パラメータ修正
7036                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
7037                 
7038                 // 管理用ページの場合
7039                 if ($pageId == $gEnvManager->getDefaultAdminPageId()){
7040                         if ($gEnvManager->getUseSslAdmin()){            // 管理用ページにSSLを使用するかどうか
7041                                 return true;
7042                         } else {
7043                                 return false;
7044                         }
7045                 }
7046                 
7047                 // ##### フロント画面の場合 #####
7048                 if ($gEnvManager->isRootUrlSsl()) return true;          // ルートURLがSSLの場合はフロント画面のすべてがSSL付き
7049                 
7050                 // 一般用ページにSSLを使用しない場合は不要を返す
7051                 if (!$gEnvManager->getUseSsl()) return false;
7052                                         
7053                 // 一般用ページでSSLを使用する場合は、データベースの設定をチェックする
7054                 $line = $this->getPageInfo($pageId, $pageSubId);
7055                 if (!empty($line)){
7056                         if ($line['pn_use_ssl']){
7057                                 return true;
7058                         } else {
7059                                 return false;
7060                         }
7061                 }
7062                 return false;
7063         }
7064         /**
7065          * ユーザ制限が必要なページかどうかを判断
7066          *
7067          * @param string $pageId        ページID
7068          * @param string $pageSubId     ページサブID
7069          * @return bool                         true=必要、false=不要
7070          */     
7071         function isUserLimitedPage($pageId, $pageSubId)
7072         {
7073                 global $gEnvManager;
7074                 
7075                 // パラメータ修正
7076                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
7077                 
7078                 $line = $this->getPageInfo($pageId, $pageSubId);
7079                 if (!empty($line)){
7080                         if ($line['pn_user_limited']){
7081                                 return true;
7082                         } else {
7083                                 return false;
7084                         }
7085                 }
7086                 return false;
7087         }
7088         /**
7089          * ページ情報を取得
7090          *
7091          * @param string $pageId        ページID
7092          * @param string $pageSubId     ページサブID
7093          * @return array                        ページ情報レコード
7094          */     
7095         function getPageInfo($pageId, $pageSubId)
7096         {
7097                 // ページ情報が空のときはデータをロード
7098                 if (empty($this->pageInfo)){
7099                         $records = $this->db->getPageInfoRecords();
7100                         $count = count($records);
7101                         $this->pageInfo = array();
7102                         for ($i = 0; $i < $count; $i++){
7103                                 $pId = $records[$i]['pn_id'] . self::PAGE_ID_SEPARATOR . $records[$i]['pn_sub_id'];
7104                                 $this->pageInfo[$pId] = $records[$i];
7105                         }
7106                 }
7107                 return $this->pageInfo[$pageId . self::PAGE_ID_SEPARATOR . $pageSubId];
7108         }
7109         /**
7110          * 現在のページのページ情報を取得
7111          *
7112          * @return array                        ページ情報レコード
7113          */     
7114         function getCurrentPageInfo()
7115         {
7116                 return $this->currentPageInfo;
7117         }
7118         /**
7119          * 現在のページ情報からテンプレートIDを取得
7120          *
7121          * @param string $subTemplateId         テンプレートIDが取得できるときはサブページIDが返る
7122          * @return string                                       テンプレートID
7123          */     
7124         function getTemplateIdFromCurrentPageInfo(&$subTemplateId)
7125         {
7126                 $templateId = '';
7127                 if (!empty($this->currentPageInfo)){
7128                         $templateId = $this->currentPageInfo['pn_template_id'];
7129                         $subTemplateId = $this->currentPageInfo['pn_sub_template_id'];                  // サブテンプレートID
7130                 }
7131                 return $templateId;
7132         }
7133         /**
7134          * JavascriptライブラリのIDを取得
7135          *
7136          * @param int $type                     種別(0=すべて、1=jQuery関係すべて、2=jQueryプラグインのみ)
7137          * @return array                        JavascriptライブラリのID
7138          */     
7139         function getScriptLibId($type = 0)
7140         {
7141                 // Javascriptライブラリのすべてのキーを取得
7142                 $keys = array_keys($this->libFiles);
7143                 
7144                 $destKeys = array();
7145                 for ($i = 0; $i < count($keys); $i++){
7146                         switch ($type){
7147                                 case 1:         // jQuery関係すべて
7148                                         if (strStartsWith($keys[$i], 'jquery')) $destKeys[] = $keys[$i];
7149                                         break;
7150                                 case 2:         // jQueryプラグインのみ
7151                                         if (strStartsWith($keys[$i], 'jquery.')) $destKeys[] = $keys[$i];
7152                                         break;
7153                         }
7154                 }
7155                 return $destKeys;
7156         }
7157         /**
7158          * Javascriptライブラリの情報を取得
7159          *
7160          * @param string $id            ライブラリID
7161          * @return array                        ライブラリの情報
7162          */     
7163         function getScriptLibInfo($id)
7164         {
7165                 $libInfo = $this->libFiles[$id];
7166                 if (isset($libInfo)){
7167                         return $libInfo;
7168                 } else {
7169                         return array();
7170                 }
7171         }
7172         /**
7173          * 管理画面用jQueryUIテーマのURLを取得
7174          *
7175          * @return string                       テーマURL
7176          */     
7177         function getAdminDefaultThemeUrl()
7178         {
7179 //              $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
7180                 $themeFile = $this->gEnv->getAdminUrl(true/*「admin」削除*/) . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
7181                 return $themeFile;
7182         }
7183         /**
7184          * フロント画面用jQueryUIテーマのURLを取得
7185          *
7186          * @return string                       テーマURL
7187          */     
7188         function getDefaultThemeUrl()
7189         {
7190                 static $themeFile;
7191                 
7192                 if (!isset($themeFile)){
7193                         $themeFile = '';
7194                         $theme = $this->gSystem->defaultTheme();
7195                         if (!empty($theme)){
7196                                 $path = $this->gEnv->getSystemRootPath() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
7197                                 if (file_exists($path)) $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
7198                         }
7199                 }
7200                 return $themeFile;
7201         }
7202         /**
7203          * URLパラメータ文字列作成
7204          *
7205          * @param array $paramArray                     URL作成用のパス
7206          * @return string                                       作成したURLパラメータ
7207          */
7208         function _createUrlParamStr($paramArray)
7209         {
7210                 $destParam = '';
7211                 if (count($paramArray) == 0) return $destParam;
7212
7213                 $sortParam = array();
7214                 $keys = array_keys($paramArray);
7215                 $keyCount = count($keys);
7216                 for ($i = 0; $i < $keyCount; $i++){
7217                         $key = $keys[$i];
7218                         $value = $paramArray[$key];
7219                         $orderNo = $this->urlParamOrder[$key];
7220                         if (!isset($orderNo)) $orderNo = 100;
7221                         $sortParam[] = array('key' => $key, 'value' => $value, 'no' => $orderNo);
7222                 }
7223 //              usort($sortParam, create_function('$a,$b', 'return $a["no"] - $b["no"];'));
7224                 usort($sortParam, function($a, $b)
7225                 {
7226                         return $a['no'] - $b['no'];
7227                 });
7228                 
7229                 // 文字列を作成
7230                 $sortCount = count($sortParam);
7231                 for ($i = 0; $i < $sortCount; $i++){
7232                         if ($i > 0) $destParam .= '&';
7233                         $destParam .= rawurlencode($sortParam[$i]['key']) . '=' . rawurlencode($sortParam[$i]['value']);
7234                 }
7235                 return $destParam;
7236         }
7237         /**
7238          * DBからCSSファイル(テンプレート独自のCSSまたは外部のCSS)を取得
7239          *
7240          * @param string $templateId    テンプレートID
7241          * @return bool                                 true=取得成功、false=取得失敗
7242          */
7243         function loadCssFiles($templateId = '')
7244         {
7245                 if (empty($templateId)) $templateId = $this->gSystem->defaultTemplateId();              // PC画面デフォルトのテンプレートを取得
7246
7247                 $ret = $this->db->getTemplate($templateId, $row);
7248                 if (!$ret) return false;
7249                 
7250                 // 編集エディタ用パラメータが初期化されていない場合は初期化
7251                 if (empty($row['tm_editor_param'])){
7252                         // テンプレートを解析し、使用しているCSSファイルを取得
7253                         $editorParamObj = $this->parseTemplate($templateId);
7254                         
7255                         // テンプレートの情報を更新
7256                         $updateParam = array();
7257                         $updateParam['tm_editor_param'] = serialize($editorParamObj);
7258                         $ret = $this->db->updateTemplate($templateId, $updateParam);
7259                 } else {
7260                         $editorParamObj = unserialize($row['tm_editor_param']);
7261                 }
7262                 
7263                 if (isset($editorParamObj)){
7264                         $this->ckeditorCssFiles = array();
7265                         $cssFiles = $editorParamObj->cssFiles;
7266                         for ($i = 0; $i < count($cssFiles); $i++){
7267                                 $cssFile = $cssFiles[$i];
7268                                 
7269                                 if (strStartsWith($cssFile, '//')){             // URLが「//」で始まる外部ファイルの場合はそのまま追加
7270                                         $this->ckeditorCssFiles[] = $cssFile;
7271                                 } else if (strStartsWith($cssFile, '/')){               // URLが「/」で始まる相対パスの場合はURLに変換
7272                                         $this->ckeditorCssFiles[] = $this->gEnv->getAdminUrl(true/*adminディレクトリ削除*/) . $cssFile;
7273                                 } else {
7274                                         $this->ckeditorCssFiles[] = $cssFile;
7275                                 }
7276                         }
7277                         return true;
7278                 } else {
7279                         return false;
7280                 }
7281         }
7282         /**
7283          * URLで指定した画面のCSSファイル(テンプレート独自のCSSまたは外部のCSS)を取得
7284          *
7285          * @param string $url   取得画面のURL
7286          * @return                              なし
7287          */
7288         function loadCssFilesByUrl($url)
7289         {
7290                 // ##### cURLを使用する場合はセッションのブロックを解除する #####
7291                 session_write_close();
7292                 
7293                 $ch = curl_init();
7294                 curl_setopt($ch, CURLOPT_URL, $url);
7295                 curl_setopt($ch, CURLOPT_USERAGENT, M3_SYSTEM_NAME . '/' . M3_SYSTEM_VERSION);          // ユーザエージェント
7296                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         // 画面に出力しない
7297                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
7298                 curl_setopt($ch, CURLOPT_TIMEOUT, 3);
7299                 curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());          // セッションを維持
7300                 $content = curl_exec($ch);
7301                 curl_close($ch);
7302
7303                 // HEADタグを取り出す
7304                 $urlArray = array();
7305                 $headContent = '';
7306                 $pattern = '/<head\b[^>]*?>(.*?)<\/head\b[^>]*?>/si';
7307                 if (preg_match($pattern, $content, $matches)) $headContent = $matches[0];
7308
7309                 // CSSファイル取り出し
7310                 $pattern = '/<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
7311                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7312                         foreach ($matches as $match){
7313                                 if (strEndsWith($match[1], '.css')){            // ファイル名の拡張子が「css」の場合
7314                                         $urlArray[] = $match[1];
7315                                 } else {
7316                                         // typeが「text/css」を取得
7317                                         $attrPattern = '/type\s*=\s*[\'"]+(.+?)[\'"]/si';
7318                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7319                                                 if (strcasecmp($attrMatch[1], 'text/css') == 0){
7320                                                         $urlArray[] = $match[1];
7321                                                         continue;
7322                                                 }
7323                                         }
7324                                         // relが「stylesheet」を取得
7325                                         $attrPattern = '/rel\s*=\s*[\'"]+(.+?)[\'"]/si';
7326                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7327                                                 if (strcasecmp($attrMatch[1], 'stylesheet') == 0){
7328                                                         $urlArray[] = $match[1];
7329                                                         continue;
7330                                                 }
7331                                         }
7332                                 }
7333                         }
7334                 }
7335
7336                 // ifで制御されているCSSファイルを除く
7337                 $delUrlArray = array();
7338                 $pattern = '/<!--\[if\b.*?\]>[\s\S]*<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>[\s\S]*<!\[endif\]-->/si';
7339                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7340                         foreach ($matches as $match) $delUrlArray[] = $match[1];
7341                 }
7342
7343                 // ##### テンプレート独自のCSSまたは外部のCSSを取得する #####
7344                 $this->ckeditorCssFiles = array();
7345                 $cssFiles = array_merge(array_diff($urlArray, $delUrlArray));   // CKEditor用のCSSファイル
7346                 for ($i = 0; $i < count($cssFiles); $i++){
7347                         $cssFileUrl = $cssFiles[$i];
7348                         $baseUrl = '';
7349                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7350                                 $baseUrl = $this->gEnv->getRootUrl();
7351                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7352                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7353                         }
7354                         // パスを解析
7355                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7356                         
7357                         if (strStartsWith($relativePath, '//')){                // URLが「//」で始まる外部ファイルの場合
7358                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7359                         } else if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){            // テンプレートディレクトリの場合
7360                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7361                         } else if (strStartsWith($relativePath, '/')){          // テンプレートディレクトリ以外のディレクトリの場合
7362                         } else {                        // 外部URLの場合
7363                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7364                         }
7365                 }
7366
7367                 // テンプレートタイプを取得
7368                 $pattern = '/var\s*M3_TEMPLATE_TYPE\s*=\s*(\d+?)\s*;/si';
7369                 if (preg_match($pattern, $headContent, $matches)) $this->ckeditorTemplateType = $matches[1];                    // CKEditor用のテンプレートタイプ
7370         }
7371         /**
7372          * CKEditor用のテンプレートタイプを取得
7373          *
7374          * @return int                  テンプレートタイプ
7375          */     
7376         function getCkeditorTemplateType()
7377         {
7378                 return $this->ckeditorTemplateType;
7379         }
7380         /**
7381          * POST時のリファラーチェック
7382          *
7383          * @return bool         true=正常、false=不正
7384          */
7385 /*      function _checkReferer()
7386         {
7387                 global $gEnvManager;
7388                 global $gRequestManager;
7389                 
7390                 // リファラーをチェック
7391                 $referer        = $gRequestManager->trimServerValueOf('HTTP_REFERER');
7392                 $uri            = $gEnvManager->getCurrentRequestUri();
7393                 if (empty($referer) || $referer != $uri){
7394                         return false;
7395                 } else {
7396                         return true;
7397                 }
7398         }*/
7399         /**
7400          * テンプレート画面を解析してCSSファイルやポジションの情報を取得
7401          *
7402          * @param string $templateId    テンプレートID
7403          * @return                                              テンプレート情報オブジェクト
7404          */
7405         function parseTemplate($templateId)
7406         {
7407                 // ##### cURLを使用する場合はセッションのブロックを解除する #####
7408                 session_write_close();
7409
7410                 // テンプレートのURL
7411                 $url = $this->gEnv->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_SHOW_POSITION . '&template=' . $templateId;
7412                 
7413                 // テンプレート情報オブジェクト
7414                 $tmplateInfoObj = new stdClass;
7415                 $tmplateInfoObj->cssFiles       = array();              // テンプレートで使用されているCSSファイル
7416                 
7417                 $ch = curl_init();
7418                 curl_setopt($ch, CURLOPT_URL, $url);
7419                 curl_setopt($ch, CURLOPT_USERAGENT, M3_SYSTEM_NAME . '/' . M3_SYSTEM_VERSION);          // ユーザエージェント
7420                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         // 画面に出力しない
7421                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
7422                 curl_setopt($ch, CURLOPT_TIMEOUT, 3);
7423                 curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());          // セッションを維持
7424                 $content = curl_exec($ch);
7425                 curl_close($ch);
7426
7427                 // HEADタグを取り出す
7428                 $urlArray = array();
7429                 $headContent = '';
7430                 $pattern = '/<head\b[^>]*?>(.*?)<\/head\b[^>]*?>/si';
7431                 if (preg_match($pattern, $content, $matches)) $headContent = $matches[0];
7432
7433                 // CSSファイル取り出し
7434                 $pattern = '/<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
7435                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7436                         foreach ($matches as $match){
7437                                 if (strEndsWith($match[1], '.css')){            // ファイル名の拡張子が「css」の場合
7438                                         $urlArray[] = $match[1];
7439                                 } else {
7440                                         // typeが「text/css」を取得
7441                                         $attrPattern = '/type\s*=\s*[\'"]+(.+?)[\'"]/si';
7442                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7443                                                 if (strcasecmp($attrMatch[1], 'text/css') == 0){
7444                                                         $urlArray[] = $match[1];
7445                                                         continue;
7446                                                 }
7447                                         }
7448                                         // relが「stylesheet」を取得
7449                                         $attrPattern = '/rel\s*=\s*[\'"]+(.+?)[\'"]/si';
7450                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7451                                                 if (strcasecmp($attrMatch[1], 'stylesheet') == 0){
7452                                                         $urlArray[] = $match[1];
7453                                                         continue;
7454                                                 }
7455                                         }
7456                                 }
7457                         }
7458                 }
7459
7460                 // ifで制御されているCSSファイルを除く
7461                 $delUrlArray = array();
7462                 $pattern = '/<!--\[if\b.*?\]>[\s\S]*<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>[\s\S]*<!\[endif\]-->/si';
7463                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7464                         foreach ($matches as $match) $delUrlArray[] = $match[1];
7465                 }
7466
7467                 // テンプレート独自のCSSまたは外部のCSSを取得する
7468                 $cssFiles = array_merge(array_diff($urlArray, $delUrlArray));   // CKEditor用のCSSファイル
7469                 for ($i = 0; $i < count($cssFiles); $i++){
7470                         $cssFileUrl = $cssFiles[$i];
7471                         $baseUrl = '';
7472                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7473                                 $baseUrl = $this->gEnv->getRootUrl();
7474                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7475                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7476                         }
7477                         // パスを解析
7478                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7479                         
7480                         if (strStartsWith($relativePath, '//')){                // URLが「//」で始まる外部ファイルの場合
7481                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7482                         } else if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){            // テンプレートディレクトリの場合
7483                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7484                         } else if (strStartsWith($relativePath, '/')){          // テンプレートディレクトリ以外のディレクトリの場合
7485                         } else {                        // 外部URLの場合
7486                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7487                         }
7488                 }
7489                 
7490                 // パスを相対パスに変換
7491                 for ($i = 0; $i < count($tmplateInfoObj->cssFiles); $i++){
7492                         $cssFileUrl = $tmplateInfoObj->cssFiles[$i];
7493                         
7494                         $baseUrl = '';
7495                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7496                                 $baseUrl = $this->gEnv->getRootUrl();
7497                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7498                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7499                         }
7500                         // パスを解析
7501                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7502                         
7503                         // テンプレート内のCSSの場合は相対パスに変換
7504                         if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){// テンプレートディレクトリの場合
7505                                 $tmplateInfoObj->cssFiles[$i] = $relativePath;
7506                         } else {
7507                                 $tmplateInfoObj->cssFiles[$i] = $cssFileUrl;
7508                         }
7509                 }
7510                 
7511                 // テンプレートのポジションを取得
7512                 $tmplateInfoObj->positions = array();
7513                 $pattern = '/var\s*M3_POSITION_DATA\s*=\s*[\'"]+(.+?)[\'"]/si';
7514                 if (preg_match($pattern, $headContent, $matches) && !empty($matches[1])){
7515                         $tmplateInfoObj->positions = explode(',', $matches[1]);
7516                 }
7517                 return $tmplateInfoObj;
7518         }
7519         /**
7520          * デフォルトのテンプレートからレイアウト用テンプレートで使用していないポジションを取得
7521          *
7522          * @return array                                ポジション名の配列
7523          */
7524         function getLayoutTemplatePosition()
7525         {
7526                 $removePositions = array('header', 'extra1', 'extra2', 'brand', 'hmenu', 'user3', 'banner1', 'top1', 'top2', 'top3',
7527                                                                 'left', 'banner2', 'breadcrumb', 'user1', 'user2', 'banner3', 'main-top', 'main', 'main-bottom', 'banner4', 'user4', 'user5', 'banner5', 
7528                                                                 'right','bottom1', 'bottom2', 'bottom3', 'banner6', 'syndicate', 'copyright', 'footer');                // レイアウト用テンプレートに存在するので削除するポジション
7529                 
7530                 // URLパラメータからデフォルトのテンプレートを取得
7531                 $pageId = $this->gRequest->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
7532
7533                 $templateId = '';
7534                 if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
7535                         $templateId = $this->gSystem->defaultTemplateId();
7536                 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
7537                         $templateId = $this->gSystem->defaultSmartphoneTemplateId();            // スマートフォン用デフォルトテンプレート
7538                 }
7539
7540                 // テンプレート情報取得
7541                 $ret = $this->db->getTemplate($templateId, $row);
7542                 if (!$ret) return array();
7543                 if (empty($row['tm_editor_param'])) return array();
7544         
7545                 // レイアウト用テンプレートに存在しないポジション名のみ返す
7546                 $editorParamObj = unserialize($row['tm_editor_param']);
7547                 if (isset($editorParamObj)){
7548                         if (isset($editorParamObj->positions)){
7549                                 $srcArray = $editorParamObj->positions;
7550                                 $destArray = array();
7551                                 for ($i = 0; $i < count($srcArray); $i++){
7552                                         $position = $srcArray[$i];
7553                                         if (!in_array($position, $removePositions)) $destArray[] = $position;
7554                                 }
7555                                 return $destArray;
7556                         }
7557                 }
7558                 return array();
7559         }
7560 }
7561 ?>