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 $headCssFiles = array();                // ウィジェットからの追加で読み込むCSSファイル
44         private $headRssFiles = array();                // HTMLヘッダに出力するRSS配信情報
45         private $currentWidgetPosition;                 // 現在のウィジェットのポジション
46         private $currentWidgetIndex;                    // 現在のウィジェットのポジション番号
47         private $pageDefPosition;               // 現在取得しているページ定義のポジション
48         private $pageDefRows;                   // ページ定義レコード
49         private $nonSharedWidgetCount = -1;     // 非共通ウィジェットの数(-1=ページ作成でないとき)
50         private $replaceHeadDone;                       // ヘッダマクロ変換処理が完了したかどうか
51         private $useHelp = false;               // 標準ヘルプ機能を使用するかどうか
52         private $hasScriptCache = false;        // JavaScriptファイルをブラウザにキャッシュさせるかどうか
53         private $isAccessPointWithAdminMenu;                            // 管理メニューを使用するアクセスポイントかどうか
54         private $lateLaunchWidgetList;  // 遅延実行ウィジェットのリスト
55         private $latelaunchWidgetParam;         // 遅延実行ウィジェットのパラメータ
56         private $defPositions = array();        // テンプレート上のポジション(画面定義データすべて)
57         private $viewPositions = array();       // テンプレート上のポジション(ウィジェット表示ありのみ)
58         private $viewPosId = array();           // テンプレート上のポジションのタグID
59         private $updateParentWindow;            // 親ウィンドウを再描画するかどうか
60         private $updateDefSerial;                       // 更新する項目のページ定義シリアル番号
61         private $headDescription;                               // HTMLヘッダ「description」に出力する文字列
62         private $headKeywords;                          // HTMLヘッダ「keywords」に出力する文字列
63         private $headOthers;                            // HTMLヘッダに出力するタグ文字列
64         private $adminHeadOthers;                               // HTMLヘッダに出力するタグ文字列(管理画面用)
65         private $lastHeadTitle;                         // 最後にヘッダ部titleにセットした文字列
66         private $lastHeadDescription;           // 最後にヘッダ部descriptionにセットした文字列
67         private $lastHeadKeywords;                      // 最後にヘッダ部keywordsにセットした文字列
68         private $headFirstTag;                          // HTMLヘッダに最初に出力するタグ文字列
69         private $headCss = array();                     // HTMLヘッダにCSS出力する文字列
70         private $headScript = array();          // HTMLヘッダにJavascript出力する文字列
71         private $headString = array();          // HTMLヘッダに出力する任意文字列
72         private $exportCss = array();           // 外部出力でCSS出力する文字列
73         private $lastHeadCss;                           // 最後に設定したHTMLヘッダにCSS出力する文字列
74         private $lastHeadScript;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
75         private $lastHeadString;                        // 最後に設定したHTMLヘッダに出力する任意文字列
76         private $headSubTitle = array();                                // ヘッダタグサブタイトル
77         private $headSubTitleUrl = array();                             // ヘッダサブタイトルのリンク先
78         private $headCanonicalUrl;                              // カノニカル属性URL
79         private $initScript = '';                               // ウィンドウ初期化時に実行されるスクリプト
80         private $outputByHtml = true;                           // HTMLフォーマットで出力するかどうか
81         private $outputByStandardHead;          // HTML文書の標準のヘッダタグを出力するかどうか
82         private $outputHead;                            // HTMLヘッダ出力を行ったかどうか
83         private $outputTheme;                           // jQueryUIテーマ出力を行ったかどうか
84         private $outputAjaxResponseBody;        // AJAX用のレスポンスボディデータかどうか
85         private $isAbort;                                       // ページ作成処理を中断するかどうか
86         private $isWidgetAbort;                         // 各ウィジェット処理を中断するかどうか
87         private $isRedirect;                            // リダイレクトするかどうか
88         private $isSystemPage;                          // システム制御ページを表示するかどうか
89         private $libFiles;                                      // javascript追加用ライブラリ
90         private $pageDefRev = 234;                              // 画面定義のリビジョン番号
91         private $pageInfo;                                      // すべてのページ情報
92         private $currentPageInfo;                       // 現在のページのページ情報
93         private $configWidgetInfo;                      // ウィジェット設定画面のウィジェットの情報
94         private $contentType = '';                              // ページのコンテンツタイプ
95         private $mainContentTypeInfo;                           // フロント画面で使用する主要コンテンツタイプ
96         private $subContentTypeInfo;                            // フロント画面で使用する補助コンテンツタイプ
97         private $mainFeatureTypeInfo;                           // フロント画面で使用する主要機能タイプ
98         private $adminFeatureTypeInfo;                                          // 管理画面専用で使用する主要機能タイプ
99         private $rssVersion;                                    // RSSバージョン
100         private $rssChannel;                            // RSSチャンネルデータ
101         private $selectedJQueryFilename;                // 使用対象のjQueryファイル
102         private $selectedJQueryUiFilename;              // 使用対象のjQuery UIファイル
103         private $urlParamOrder;                                 // URLパラメータの並び順
104         private $wysiwygEditor;                         // 管理画面用WYSIWYGエディター
105         private $optionTemplateId;                      // 追加設定するテンプレートID
106         private $optionSubTemplateId;                   // 追加設定するサブテンプレートID
107         private $isContentGooglemaps;           // コンテンツにGoogleマップが含むかどうか
108         private $useGooglemaps;                         // Googleマップを使用するかどうか
109         private $useBootstrap;                          // Bootstrapを使用するかどうか
110         private $isHtml5;                                       // HTML5で出力するかどうか
111         private $ckeditorCssFiles = array();    // CKEditor用のCSSファイル
112         private $ckeditorTemplateType;                  // CKEditor用のテンプレートタイプ
113         private $adminSubNavbarDef = array();           // 管理画面用のサブメニューバーの定義
114         private $adminBreadcrumbDef = array();                  // 管理画面用パンくずリスト定義
115         private $adminBreadcrumbDefHelp = array();                              // 管理画面用パンくずリストヘルプ定義
116         const CONFIG_KEY_HEAD_TITLE_FORMAT = 'head_title_format';               // ヘッダ作成用フォーマット
117         const ADMIN_WIDGET_ID = 'admin_main';           // 管理用ウィジェットのウィジェットID
118         //const CONTENT_TYPE_WIKI = 'wiki';             // ページのコンテンツタイプ(Wiki)
119         const WIDGET_ID_TAG_START = '{{WIDGETID:';              // 遅延実行用タグ
120         const WIDGET_ID_TAG_END = '}}';         // 遅延実行用タグ
121         const WIDGET_ID_TITLE_TAG_START = '{{WIDGETID_TITLE:';          // 遅延実行用タグ(タイトル埋め込み用)
122         const WIDGET_ID_TITLE_TAG_END = '}}';                                           // 遅延実行用タグ(タイトル埋め込み用)
123         const WIDGET_ID_SEPARATOR = ',';
124         const HEAD_TAGS                         = '{{HEAD_TAGS}}';                              // HTMLヘッダ出力用タグ
125         const MENUBAR_TAGS                      = '{{MENUBAR_TAGS}}';                   // メニューバー出力用タグ
126         const MENUBAR_SCRIPT_TAGS       = '{{MENUBAR_SCRIPT_TAGS}}';                            // メニューバー出力用スクリプトタグ
127         const WIDGET_ICON_IMG_SIZE = 32;                        // ウィジェットアイコンサイズ
128         const WIDGET_INVISIBLE_CLASS = 'm3invisible';                   // 非表示ウィジェットクラス
129         const WIDGET_LOGIN_STATUS_CLASS = 'm3loginstatus';              // ログイン状態連動クラス
130         const WIDGET_OUTER_CLASS = 'm3_widget_outer';                   // ウィジェット外枠クラス
131         const WIDGET_OUTER_CLASS_HEAD_POSITION = 'm3_pos_';                     // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
132         const WIDGET_OUTER_CLASS_WIDGET_TAG = 'm3_';                            // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
133 //      const WIDGET_INNER_CLASS = 'm3_widget_inner';                   // ウィジェットの内側クラス
134         const POSITION_TAG_HEAD = 'm3pos_';                     // ポジションの識別用タグIDヘッダ
135         const WIDGET_TAG_HEAD = 'm3widget_';                    // ウィジェットの識別用タグIDヘッダ
136 //      const WIDGET_TAG_HEAD_SHORT = 'm3_';                    // ウィジェットの識別用タグIDヘッダ
137         const WIDGET_TYPE_TAG_HEAD = 'm3widgettype_';                   // ウィジェット種別の識別用タグIDヘッダ
138         const WIDTET_CLASS_NAME = 'm3widget';                   // ウィジェットオブジェクトのタグクラス名
139         const WIDTET_CLASS_TYPE_0 = 'm3widget_type0';                   // ウィジェットオブジェクトのタグクラス(グローバル属性でない)
140         const WIDTET_CLASS_TYPE_1 = 'm3widget_type1';                   // ウィジェットオブジェクトのタグクラス(グローバル属性)
141         const POSITION_CLASS_NAME = 'm3position';               // ポジションオブジェクトのタグクラス名
142         const JOOMLA10_DEFAULT_WIDGET_MENU_PARAM = 'class="moduletable"';       // Joomla!1.0用デフォルトメニューパラメータ値
143         const ADMIN_TEMPLATE = '_admin';                // PC管理用テンプレートID
144         const SCRIPT_LIB_SEPARATOR = ';';                       // JavaScriptライブラリ読み込み設定のライブラリの区切り
145         const PAGE_ID_SEPARATOR = ',';                          // ページIDとページサブID連結用
146         const DEFAULT_ADMIN_FAVICON_FILE = '/images/system/favicon.ico';                        // デフォルトの管理画面用faviconファイル
147         const DEFAULT_FAVICON_FILE = '/favicon.ico';                    // デフォルトのfaviconファイル
148 //      const DEFAULT_SITE_NAME = 'サイト名未設定';              // 管理画面用のデフォルトサイト名
149         const DEFAULT_ADMIN_TITLE = '管理画面';                     // デフォルトの管理画面名
150         const WIDGET_TITLE_START = '[';                                 // ウィジェットのタイトルの括弧
151         const WIDGET_TITLE_END = ']';                                   // ウィジェットのタイトルの括弧
152         const DEFAULT_RSS_VERSION = '1.0';                              // デフォルトのRSSのバージョン
153         const CF_ACCESS_IN_INTRANET = 'access_in_intranet';             // イントラネット運用かどうか
154         const CF_USE_LATEST_SCRIPT_LIB = 'dev_use_latest_script_lib';           // 最新のJavaScriptライブラリを使用するかどうか
155         const CF_GOOGLE_MAPS_KEY = 'google_maps_key';                           // Googleマップ利用キー
156         const CF_JQUERY_VERSION = 'jquery_version';                     // jQueryバージョン
157         const CF_EXTERNAL_JQUERY = 'external_jquery';                   // システム外部のjQueryを使用するかどうか
158         const CF_WYSIWYG_EDITOR = 'wysiwyg_editor';             // 管理画面用WYSIWYGエディター
159         const CF_ADMIN_JQUERY_VERSION = 'admin_jquery_version';                 // 管理画面用jQueryバージョン
160         const SD_HEAD_OTHERS    = 'head_others';                // ヘッダその他タグ
161         const DEFAULT_THEME_DIR = '/ui/themes/';                                // jQueryUIテーマ格納ディレクトリ
162         const THEME_CSS_FILE = 'jquery-ui.custom.css';          // テーマファイル
163         const CONFIG_ICON_FILE = '/images/system/config.png';                   // ウィジェット定義画面アイコン
164         const ADJUST_ICON_FILE = '/images/system/adjust_widget.png';    // 位置調整アイコン
165         const SHARED_ICON_FILE = '/images/system/shared.png';   // グローバル属性
166         const DELETE_ICON_FILE = '/images/system/delete.png';   // ウィジェット削除
167         const CONFIG_ICON32_FILE = '/images/system/config32.png';                       // ウィジェット定義画面アイコン(ツールチップ用)
168         const ADJUST_ICON32_FILE = '/images/system/adjust_widget32.png';        // 位置調整アイコン(ツールチップ用)
169         const CLOSE_BOX_ICON32_FILE = '/images/system/close_box.png';           // ウィンドウ閉じるアイコン(ツールチップ用)
170         const NOTICE_ICON_FILE = '/images/system/notice16.png';         // ウィジェット配置注意アイコン
171         const ALERT_ICON_FILE = '/images/system/alert16.png';           // ウィジェット配置警告アイコン
172 //      const ADMIN_ICON_FILE = '/images/system/admin64.png';           // パネルメニュー管理画面遷移用アイコン
173 //      const LOGOUT_ICON_FILE = '/images/system/logout64.png';         // パネルメニューログアウト用アイコン
174 //      const EDIT_PAGE_ICON_FILE = '/images/system/create_page64.png';         // パネルメニュー編集用アイコン   
175         const ADMIN_ICON_FILE = '/images/system/home32.png';            // パネルメニュー管理画面遷移用アイコン
176         const LOGOUT_ICON_FILE = '/images/system/logout32.png';         // パネルメニューログアウト用アイコン
177         const EDIT_PAGE_ICON_FILE = '/images/system/create_page32.png';         // パネルメニュー編集用アイコン   
178 //      const EDIT_END_ICON_FILE = '/images/system/close32.png';                // パネルメニュー編集終了用アイコン
179         const EDIT_END_ICON_FILE = '/images/system/back32.png';         // パネルメニュー編集終了用アイコン
180         const CLOSE_ICON_FILE = '/images/system/close32.png';           // ウィンドウ閉じるアイコン
181         const PREV_ICON_FILE = '/images/system/prev48.png';             // ウィンドウ「前へ」アイコン
182         const NEXT_ICON_FILE = '/images/system/next48.png';             // ウィンドウ「次へ」アイコン
183         const DEFAULT_READMORE_TITLE = 'もっと読む';                       // もっと読むボタンのデフォルトタイトル
184         const POS_HEAD_NAV_MENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー" data-placement="auto"></i> ';               // 特殊ポジションブロック(ナビゲーションメニュー型)
185         const POS_HEAD_MAIN = '<i class="glyphicon glyphicon-stop" rel="m3help" title="メイン型" data-placement="auto"></i> ';              // 特殊ポジションブロック(メイン型)
186         const WIDGET_MARK_MAIN = '<i class="glyphicon glyphicon-stop" rel="m3help" title="メイン型" data-placement="auto"></i> ';           // ウィジェットの機能マーク(メイン型ウィジェット)
187         const WIDGET_MARK_NAVMENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー" data-placement="auto"></i> ';             // ウィジェットの機能マーク(ナビゲーションメニュー)
188         const WIDGET_FUNCTION_MARK_BOOTSTRAP = ' <span class="label label-warning" rel="m3help" title="Bootstrap型テンプレート対応" data-placement="auto">B</span>';                   // ウィジェット機能マーク(Boostrap型テンプレート
189         const WIDGET_FUNCTION_MARK_WORDPRESS = ' <span class="label label-warning" rel="m3help" title="WordPress型テンプレート対応" data-placement="auto">W</span>';                   // ウィジェット機能マーク(WordPress型テンプレート
190         const WIDGET_STYLE_NAVMENU = '_navmenu';                // ウィジェットの表示スタイル(ナビゲーションメニュー)
191         const WIDGET_STYLE_WORDPRESS = '_wordpress';                                            // ウィジェットの表示スタイル(WordPressテンプレート用出力)
192         const WIDGET_STYLE_WORDPRESS_NOTITLE = '_wordpress_notitle';            // ウィジェットの表示スタイル(WordPressテンプレート(タイトルなし)用出力)
193         
194         // アドオンオブジェクト用
195         const CONTENT_OBJ_ID    = 'contentlib'; // 汎用コンテンツオブジェクトID
196         const BLOG_OBJ_ID               = 'bloglib';            // ブログオブジェクトID
197         const LINKINFO_OBJ_ID   = 'linkinfo';   // リンク情報オブジェクトID
198         
199         // インナーウィジェット用
200         const IWIDTET_CMD_CONTENT = 'content';          // コンテンツ取得
201         const IWIDTET_CMD_INIT = 'init';                        // 初期化
202         const IWIDTET_CMD_UPDATE = 'update';            // 更新
203         const IWIDTET_CMD_CALC = 'calc';                        // 計算
204         
205         // Magic3用スクリプト
206         const M3_ADMIN_SCRIPT_FILENAME                  = 'm3admin2.0.3.js';                            // 管理機能用スクリプト(CKEditor4.0.1対応)
207         const M3_ADMIN_WIDGET_SCRIPT_FILENAME   = 'm3admin_widget2.0.10.js';    // 管理機能(ウィジェット操作)用スクリプト
208         const M3_ADMIN_WIDGET_CSS_FILE                  = '/m3/widget.css';                     // 管理機能(ウィジェット操作)用CSSファイル
209         const M3_STD_SCRIPT_FILENAME                    = 'm3std1.5.2.js';                      // 一般、管理機能共通スクリプト
210         const M3_OPTION_SCRIPT_FILENAME                 = 'm3opt1.2.1.js';                      // AJAXを含んだオプションライブラリファイル(jQuery必須)
211         const M3_ADMIN_CSS_FILE                                 = 'm3/admin.css';                       // 管理機能用のCSS
212         const M3_EDIT_CSS_FILE                                  = 'm3/edit.css';                        // フロント画面編集用のCSS
213         const M3_DEFAULT_CSS_FILE                               = 'm3/default.css';                     // フロント画面共通のデフォルトCSS
214         const M3_CKEDITOR_CSS_FILE                              = 'm3/ckeditor.css';                    // CKEditorの編集エリア用CSS
215         
216         // 読み込み制御
217         const USE_BOOTSTRAP_ADMIN       = false;                        // 管理画面でBootstrapを使用するかどうか(デフォルト値)
218         const BOOTSTRAP_BUTTON_CLASS = 'btn btn-default';
219         
220         // UI
221         const FILEBROWSER_WIDTH_RATIO = '0.8';                  // ファイルブラウザ幅比率
222         const FILEBROWSER_HEIGHT_RATIO = '0.8';                 // ファイルブラウザ高さ比率
223         
224         /**
225          * コンストラクタ
226          */
227         function __construct()
228         {
229                 global $gInstanceManager;
230                 global $gEnvManager;
231                 global $gSystemManager;
232                 global $gRequestManager;
233                                 
234                 // 親クラスを呼び出す
235                 parent::__construct();
236                 
237                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
238                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
239                 
240                 // システムDBオブジェクト取得
241                 $this->db = $gInstanceManager->getSytemDbObject();
242                 
243                 // 運用方法
244                 $value = $gSystemManager->getSystemConfig(self::CF_ACCESS_IN_INTRANET);         // イントラネット運用かどうか
245                 if (empty($value)){             // インターネット運用
246                         $this->useGooglemaps = true;                            // Googleマップを使用するかどうか
247                 }
248                 $this->useHelp = true;          // ヘルプ機能
249                 
250                 // デフォルトのWYSIWYGエディターを取得
251                 $this->wysiwygEditor = $gSystemManager->getSystemConfig(self::CF_WYSIWYG_EDITOR);                               // 管理画面用WYSIWYGエディター
252                 
253                 // ##### Javascriptライブラリのバージョン設定 #####
254                 // jQueryバージョン設定
255                 // アクセスする画面に応じてjQueryのバージョンを設定
256                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
257                         $value = $gSystemManager->getSystemConfig(self::CF_ADMIN_JQUERY_VERSION);// 管理画面用jQueryバージョン
258                         
259                         // 管理画面にBOOTSTRAPを使用するかどうか(初期値)
260                         $this->useBootstrap = self::USE_BOOTSTRAP_ADMIN;
261                         
262                         // CKEditorのバージョン設定
263                         // 小画面デバイス最適化の場合は最新バージョンを使用
264                         if ($gEnvManager->isSmallDeviceAdmin()) ScriptLibInfo::setCkeditorVer(1/*最新*/);
265                 } else {
266                         $value = $gSystemManager->getSystemConfig(self::CF_JQUERY_VERSION);// jQueryバージョン
267                 }
268                 ScriptLibInfo::setJQueryVer($value);
269                 
270                 // WYSISIGエディターのタイプを設定。ScriptLibInfo::getLib()を実行する前に設定。
271                 ScriptLibInfo::setWysiwygEditorType($this->wysiwygEditor);
272                 
273                 // Javascriptライブラリ
274                 $this->libFiles = ScriptLibInfo::getLib();                      // ライブラリ取得
275                 
276                 // jQueryファイル名取得
277                 $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(0);                    // 使用対象のjQueryファイル
278                 $this->selectedJQueryUiFilename = ScriptLibInfo::getJQueryFilename(1);          // 使用対象のjQuery UIファイル
279
280                 // ##### フロント画面用のデフォルトのJavascript、CSSを取得 #####
281                 $this->defaultScriptFiles       =       array(
282                                                                                         $this->selectedJQueryFilename,                  // jQuery
283                                                                                         self::M3_STD_SCRIPT_FILENAME
284                                                                                 );
285                 $this->defaultCssFiles          =       array(
286                                                                                         self::M3_DEFAULT_CSS_FILE                               // フロント画面共通のデフォルトCSS
287                                                                                 );
288                 
289                 // ##### 管理機能用のデフォルトのJavascript、CSSを取得 #####
290                 if (defined('M3_STATE_IN_INSTALL')){            // インストーラの場合のスクリプト
291                         $this->defaultAdminScriptFiles  =       array(
292                                                                                                         $this->selectedJQueryFilename,                  // jQuery
293                                                                                                 //      self::M3_STD_SCRIPT_FILENAME,
294                                                                                                         self::M3_ADMIN_SCRIPT_FILENAME
295                                                                                                 );
296                         $this->defaultAdminCssFiles             =       array();        // 管理機能用のCSS
297                 } else {
298                         $this->defaultAdminScriptFiles  =       array(
299                                                                                                         $this->selectedJQueryFilename,                  // jQuery
300                                                                                                         $this->selectedJQueryUiFilename,                                // jQuery UI Core
301                                                                                                         ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME,             // jQuery Contextmenu Lib
302                                                                                                         self::M3_STD_SCRIPT_FILENAME,
303                                                                                                         self::M3_ADMIN_SCRIPT_FILENAME,
304                                                                                                         self::M3_OPTION_SCRIPT_FILENAME
305                                                                                                 );
306                         $this->defaultAdminCssFiles             =       array(
307                                                                                                         self::M3_ADMIN_CSS_FILE                 // 管理機能用のCSS
308                                                                                                 );
309                         
310                         // Javascriptライブラリ
311                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);     // 管理パネル用
312                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_EASING);            // 管理パネル用
313                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_NUMERIC);           // 入力制限プラグイン
314 //                      $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_RESPONSIVETABLE);// 管理画面作成用
315                 }
316                 
317                 // 管理権限なしで管理ディレクトリアクセスで読み込むスクリプトファイル
318                 $this->defaultAdminDirScriptFiles = array($this->selectedJQueryFilename);                       // jQuery
319                 
320                 // 遅延ウィジェットリスト                                                                    
321                 $this->lateLaunchWidgetList = array();
322                 $this->latelaunchWidgetParam = array();
323                 
324                 // DB接続可能なときは設定値を取得
325                 if ($gEnvManager->canUseDb()){
326                         $value = $this->gSystem->getSystemConfig('script_cache_in_browser');    // ブラウザにJavaScriptファイルのキャッシュを保持するかどうか
327                         if ($value != '') $this->hasScriptCache = $value;
328                 }
329                 
330                 $this->rssVersion = self::DEFAULT_RSS_VERSION;                                  // RSSバージョン
331                 
332                 // フロント画面で使用する主要コンテンツタイプ
333                 $this->mainContentTypeInfo       = array(
334                                                                                                 array(  'name' => '汎用コンテンツ',                              'value' => M3_VIEW_TYPE_CONTENT),
335                                                                                                 array(  'name' => 'ブログ',                                          'value' => M3_VIEW_TYPE_BLOG),
336                                                                                                 array(  'name' => '製品',                                             'value' => M3_VIEW_TYPE_PRODUCT),
337                                                                                                 array(  'name' => 'BBS',                                                'value' => M3_VIEW_TYPE_BBS),
338                                                                                                 array(  'name' => 'Wiki',                                               'value' => M3_VIEW_TYPE_WIKI),
339                                                                                                 array(  'name' => 'イベント情報',                         'value' => M3_VIEW_TYPE_EVENT),
340                                                                                                 array(  'name' => 'フォトギャラリー',                   'value' => M3_VIEW_TYPE_PHOTO),
341                                                                                                 array(  'name' => '会員情報',                                       'value' => M3_VIEW_TYPE_MEMBER)
342                                                                                         );
343                 // フロント画面で使用する補助コンテンツタイプ(ページ属性に対応しない)
344                 $this->subContentTypeInfo        = array(       array(  'name' => '新着情報',                                       'value' => M3_VIEW_TYPE_NEWS),
345                                                                                                 array(  'name' => 'コメント',                                       'value' => M3_VIEW_TYPE_COMMENT),
346                                                                                                 array(  'name' => 'イベント予約',                         'value' => M3_VIEW_TYPE_EVENTENTRY),
347                                                                                                 array(  'name' => 'バナー',                                          'value' => M3_VIEW_TYPE_BANNER)
348                                                                                         );
349                 // フロント画面で使用する主要機能タイプ(「ダッシュボード」は含まない)
350                 $this->mainFeatureTypeInfo       = array(       array(  'name' => '検索',                                             'value' => M3_VIEW_TYPE_SEARCH),
351                                                                                                 array(  'name' => 'Eコマース',                                      'value' => M3_VIEW_TYPE_COMMERCE),
352                                                                                                 array(  'name' => 'カレンダー',                                    'value' => M3_VIEW_TYPE_CALENDAR)
353                                                                                         );
354                 // 管理画面専用で使用する機能タイプ
355                 $this->adminFeatureTypeInfo      = array(       array(  'name' => 'ダッシュボード',                              'value' => M3_VIEW_TYPE_DASHBOARD)
356                                                                                         );
357                                                                                         
358                 // URLパラメータ並び順
359                 $this->urlParamOrder = array(
360                         // コンテンツID
361                         M3_REQUEST_PARAM_CONTENT_ID                             => -20,         // 汎用コンテンツID
362                         M3_REQUEST_PARAM_CONTENT_ID_SHORT               => -19,         // 汎用コンテンツID(略式)
363                         M3_REQUEST_PARAM_PRODUCT_ID                             => -18,         // 製品ID
364                         M3_REQUEST_PARAM_PRODUCT_ID_SHORT               => -17,         // 製品ID(略式)
365                         M3_REQUEST_PARAM_BLOG_ID                                => -16,         // ブログID
366                         M3_REQUEST_PARAM_BLOG_ID_SHORT                  => -15,         // ブログID(略式)
367                         M3_REQUEST_PARAM_BLOG_ENTRY_ID                  => -14,         // ブログ記事ID
368                         M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT    => -13,         // ブログ記事ID(略式)
369                         M3_REQUEST_PARAM_BBS_ID                                 => -12,         // 掲示板投稿記事ID
370                         M3_REQUEST_PARAM_BBS_ID_SHORT                   => -11,         // 掲示板投稿記事ID(略式)
371                         M3_REQUEST_PARAM_BBS_THREAD_ID                  => -10,         // 掲示板投稿スレッドID
372                         M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT    => -9,          // 掲示板投稿スレッドID(略式)
373                         M3_REQUEST_PARAM_EVENT_ID                               => -4,          // イベントID
374                         M3_REQUEST_PARAM_EVENT_ID_SHORT                 => -3,          // イベントID(略式)
375                         M3_REQUEST_PARAM_PHOTO_ID                               => -2,          // 画像ID
376                         M3_REQUEST_PARAM_PHOTO_ID_SHORT                 => -1,          // 画像ID(略式)
377                         // URLパラメータ
378                         M3_REQUEST_PARAM_PAGE_SUB_ID                    => 1,           // ページサブID
379                         M3_REQUEST_PARAM_PAGE_CONTENT_ID                => 2,           // ページコンテンツID
380                         M3_REQUEST_PARAM_WIDGET_ID                              => 3,           // ウィジェットID
381                         M3_REQUEST_PARAM_TEMPLATE_ID                    => 4,           // テンプレートID
382                         M3_REQUEST_PARAM_URL                                    => 5,           // リンク先等のURL
383                         M3_REQUEST_PARAM_STAMP                                  => 6,           // 公開発行ID
384                         M3_REQUEST_PARAM_OPTION                                 => 7,           // 通信オプション
385                         M3_REQUEST_PARAM_OPERATION_COMMAND              => 8,           // 実行処理
386                         M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND => 9,           // Wikiコマンド実行
387                         M3_REQUEST_PARAM_OPERATION_TASK                 => 10,          // ウィジェット間共通処理
388                         M3_REQUEST_PARAM_OPERATION_ACT                  => 11,          // クライアントからの実行処理
389                         M3_REQUEST_PARAM_OPERATION_LANG                 => 12,          // 言語指定表示
390                         M3_REQUEST_PARAM_SERIAL_NO                              => 13,          // シリアル番号
391                         M3_REQUEST_PARAM_PAGE_NO                        => 14,          // ページ番号
392                         M3_REQUEST_PARAM_LIST_NO                                => 15,          // 一覧番号
393                         M3_REQUEST_PARAM_ITEM_NO                        => 16,          // 項目番号
394                         M3_REQUEST_PARAM_OPERATION_TODO                 => 17,          // 指定ウィジェットに実行させる処理
395                         M3_REQUEST_PARAM_FROM                                   => 18,          // メッセージの送信元ウィジェットID
396                         M3_REQUEST_PARAM_VIEW_STYLE                             => 19,          // 表示スタイル
397                         M3_REQUEST_PARAM_FORWARD                                => 20,          // 画面遷移用パラメータ
398                         M3_REQUEST_PARAM_OPEN_BY                                => 22,          // ウィンドウの開き方
399                         M3_REQUEST_PARAM_SHOW_HEADER                    => 23,          // ヘッダ部表示制御
400                         M3_REQUEST_PARAM_SHOW_FOOTER                    => 24,          // フッタ部表示制御
401                         M3_REQUEST_PARAM_SHOW_MENU                              => 25,          // メニュー部表示制御
402                         M3_REQUEST_PARAM_KEYWORD                                => 26,          // 検索キーワード
403                         M3_REQUEST_PARAM_HISTORY                                => 27,          // 履歴インデックスNo
404                         M3_REQUEST_PARAM_DEF_PAGE_ID                    => 28,          // ページID(画面編集用)
405                         M3_REQUEST_PARAM_DEF_PAGE_SUB_ID                => 29,          // ページサブID(画面編集用)
406                         M3_REQUEST_PARAM_PAGE_DEF_SERIAL                => 30,          // ページ定義のレコードシリアル番号(設定画面起動時)
407                         M3_REQUEST_PARAM_PAGE_DEF_CONFIG_ID             => 31,          // ページ定義のウィジェット定義ID(設定画面起動時)
408                         M3_REQUEST_PARAM_BACK_URL                               => 32,          // 戻り先URL
409                         M3_REQUEST_PARAM_BACKUP_URL                             => 33,          // URL退避用(画面編集時)
410                         M3_REQUEST_PARAM_SERVER                                 => 34,          // サーバ指定
411                         M3_REQUEST_PARAM_CATEGORY_ID                    => 35,          // カテゴリID(共通)
412                         M3_REQUEST_PARAM_WIDTH                                  => 36,          // 幅
413                         M3_REQUEST_PARAM_HEIGHT                                 => 37);         // 高さ
414         }
415         /**
416          * メインコンテンツタイプを取得
417          *
418          * @return array        コンテンツタイプ
419          */
420         public function _getAllContentType()
421         {
422                 global $M3_ALL_CONTENT_TYPE;
423                 
424                 return $M3_ALL_CONTENT_TYPE;
425         }
426         /**
427          * 機能タイプを取得
428          *
429          * @return array        機能タイプ
430          */
431         public function _getAllFeatureType()
432         {
433                 global $M3_ALL_FEATURE_TYPE;
434                 
435 /*              $featureType = array(   M3_VIEW_TYPE_DASHBOARD,                 // ダッシュボード
436                                                                 M3_VIEW_TYPE_SEARCH,                    // 検索結果
437                                                                 M3_VIEW_TYPE_COMMERCE);                 // Eコマース
438                 return $featureType;*/
439                 return $M3_ALL_FEATURE_TYPE;
440         }
441         /**
442          * タイムアウトを停止
443          *
444          * @return なし
445          */
446         function setNoTimeout()
447         {
448                 if (ini_get('safe_mode') == '0') set_time_limit(0);
449         }
450         /**
451          * ポップアップメッセージを設定
452          *
453          * @param string $msg   メッセージ
454          */
455         function setPopupMsg($msg)
456         {
457                 $this->popupMsg = $msg;
458         }
459         /**
460          * HTMLヘッダ「description」に出力する文字列を設定
461          *
462          * @param string $str   出力文字列
463          */
464         function setHeadDescription($str)
465         {
466                 if (is_string($str) && !empty($str)){
467                         $this->headDescription = $str;
468                         $this->lastHeadDescription = $str;      // 最後に設定した値を退避
469                 }
470         }
471         /**
472          * HTMLヘッダ「description」に出力する文字列を取得
473          *
474          * @return string $str   出力文字列
475          */
476         function getHeadDescription()
477         {
478                 return $this->headDescription;
479         }
480         /**
481          * HTMLヘッダ「keywords」に出力する文字列を設定
482          *
483          * @param string $str   出力文字列
484          */
485         function setHeadKeywords($str)
486         {
487                 if (is_string($str) && !empty($str)){
488                         $this->headKeywords = $str;
489                         $this->lastHeadKeywords = $str;         // 最後に設定した値を退避
490                 }
491         }
492         /**
493          * HTMLヘッダ「keywords」に出力する文字列を取得
494          *
495          * @return string $str   出力文字列
496          */
497         function getHeadKeywords()
498         {
499                 return $this->headKeywords;
500         }
501         /**
502          * HTMLヘッダに出力するタグ文字列を設定
503          *
504          * @param string $str   出力文字列
505          * @return なし
506          */
507         function setHeadOthers($str)
508         {
509                 if (is_string($str) && !empty($str)){
510                         $this->headOthers = $str;
511                 }
512         }
513         /**
514          * HTMLヘッダに出力するタグ文字列を追加
515          *
516          * @param string $str   出力文字列
517          * @return なし
518          */
519         function addHeadOthers($str)
520         {
521                 if (is_string($str) && !empty($str)){
522                         // 追加されていない場合のみ追加
523                         $pos = strpos($this->headOthers, $str);
524                         if ($pos === false) $this->headOthers .= $str;
525                 }
526         }
527         /**
528          * HTMLヘッダに出力するタグ文字列を追加(管理画面用)
529          *
530          * @param string $str   出力文字列
531          * @return なし
532          */
533         function addAdminHeadOthers($str)
534         {
535                 if (is_string($str) && !empty($str)){
536                         // 追加されていない場合のみ追加
537                         $pos = strpos($this->adminHeadOthers, $str);
538                         if ($pos === false) $this->adminHeadOthers .= $str;
539                 }
540         }
541         /**
542          * HTMLヘッダ「title」のサブタイトル出力する文字列を設定
543          *
544          * @param string $str           出力文字列
545          * @param string $url           リンク先
546          * @param bool $isDefault       デフォルト値かどうか
547          * @return                                      なし
548          */
549         function setHeadSubTitle($str = '', $url = '', $isDefault = false)
550         {
551                 // ##### ページのサブタイトルはデフォルトでページのMETAタイトルを使用し、メインウィジェット側で上書きする #####
552                 
553                 static $isUpdated = false;                      // デフォルト値が更新されているかどうか
554                 
555                 if (!is_string($str) || empty($str)) return;
556                 
557                 // デフォルト値の場合はデータを初期化
558                 if ($isDefault){
559                         $this->headSubTitle = array();
560                         $this->headSubTitleUrl = array();
561                         $this->lastHeadTitle = '';
562                         $isUpdated = false;
563                 } else {                        // デフォルトでない場合はデータを追加
564                         if (!$isUpdated){                       // デフォルト値が更新されていない場合は以前のデータを削除
565                                 $this->headSubTitle = array();
566                                 $this->headSubTitleUrl = array();
567                                 $this->lastHeadTitle = '';
568                                 $isUpdated = true;                      // デフォルト値は更新された
569                         }
570                 }
571                 // タイトル追加
572                 $this->headSubTitle[] = $str;
573                 $this->headSubTitleUrl[] = $url;
574                 $this->lastHeadTitle = $str;    // 最後に設定した値を退避
575         }
576         /**
577          * HTMLヘッダ「title」のサブタイトル出力する文字列を取得
578          *
579          * @return $array   サブタイトルに設定されている文字列を連想配列(title=タイトル、url=リンク先URL)の配列で返す
580          */
581         function getHeadSubTitle()
582         {
583                 $titleArray = array();
584                 $titleCount = count($this->headSubTitle);
585                 for ($i = 0; $i < $titleCount; $i++){
586                         $line = array('title' => $this->headSubTitle[$i], 'url' => $this->headSubTitleUrl[$i]);
587                         $titleArray[] = $line;
588                 }
589                 return $titleArray;
590         }
591         /**
592          * HTMLヘッダに出力するCSSの文字列を設定
593          *
594          * @param string $css   追加するCSS内容
595          * @return                              なし
596          */
597         function addHeadCss($css)
598         {
599                 $destCss = trim($css);
600                 if (!empty($destCss)){
601                         //if (!in_array($css, $this->headCss)) $this->headCss[] = $css;
602                         if (!in_array($css, $this->exportCss)) $this->exportCss[] = $css;               // CSS動的外部出力
603                         
604                         $this->lastHeadCss = $css;                      // 最後に設定したHTMLヘッダにCSS出力する文字列
605                 }
606         }
607         /**
608          * 外部出力で出力するCSSの文字列を設定(ウィジェット共通設定からの設定値)
609          *
610          * @param string $css   追加するCSS内容
611          * @return                              なし
612          */
613         function addExportCss($css)
614         {
615                 $destCss = trim($css);
616                 if (!empty($destCss)){
617                         if (!in_array($css, $this->exportCss)) $this->exportCss[] = $css;
618                 }
619         }
620         /**
621          * HTMLヘッダに出力するJavascriptの文字列を設定
622          *
623          * @param string $script        追加するJavascript内容
624          * @return                                      なし
625          */
626         function addHeadScript($script)
627         {
628                 $destScript = trim($script);
629                 if (!empty($destScript)){
630                         if (!in_array($script, $this->headScript)) $this->headScript[] = $script;
631                         
632                         $this->lastHeadScript = $script;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
633                 }
634         }
635         /**
636          * HTMLヘッダに出力する任意文字列を設定
637          *
638          * @param string $str   追加する任意文字列
639          * @return                              なし
640          */
641         function addHeadString($str)
642         {
643                 $destScript = trim($str);
644                 if (!empty($destScript)){
645                         if (!in_array($str, $this->headString)) $this->headString[] = $str;
646                         
647                         $this->lastHeadString = $str;                   // 最後に設定したHTMLヘッダに出力する任意文字列
648                 }
649         }
650         /**
651          * HTMLヘッダに出力するCSSファイルを追加
652          *
653          * @param string,array $cssFile CSSファイルURLパス
654          * @return                              なし
655          */
656         function addHeadCssFile($cssFile)
657         {
658                 if (is_array($cssFile)){        // 配列の場合
659                         for ($i = 0; $i < count($cssFile); $i++){
660                                 $destCss = trim($cssFile[$i]);
661                                 if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
662                         }
663                 } else {                // 文字列の場合
664                         $destCss = trim($cssFile);
665                         if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
666                 }
667         }
668         /**
669          * HTMLヘッダに出力するJavascriptライブラリを追加
670          *
671          * @param string,array $scriptLib       JavascriptライブラリID
672          * @return                                      なし
673          */
674         function addHeadAdminScriptLib($scriptLib)
675         {
676                 if (is_array($scriptLib)){      // 配列の場合
677                         for ($i = 0; $i < count($scriptLib); $i++){
678                                 $destScript = trim($scriptLib[$i]);
679                                 if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
680                         }
681                 } else {                // 文字列の場合
682                         $destScript = trim($scriptLib);
683                         if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
684                 }
685         }
686         /**
687          * HTMLヘッダに出力するJavascriptライブラリを追加
688          *
689          * @param string,array $scriptLib       JavascriptライブラリID
690          * @return                                      なし
691          */
692         function addHeadScriptLib($scriptLib)
693         {
694                 if (is_array($scriptLib)){      // 配列の場合
695                         for ($i = 0; $i < count($scriptLib); $i++){
696                                 $destScript = trim($scriptLib[$i]);
697                                 if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
698                         }
699                 } else {                // 文字列の場合
700                         $destScript = trim($scriptLib);
701                         if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
702                 }
703         }
704         /**
705          * HTMLヘッダに出力するJavascriptファイルを追加
706          *
707          * @param string,array $scriptFile      JavascriptファイルURLパス
708          * @return                                      なし
709          */
710         function addHeadScriptFile($scriptFile)
711         {
712                 if (is_array($scriptFile)){     // 配列の場合
713                         for ($i = 0; $i < count($scriptFile); $i++){
714                                 $destScript = trim($scriptFile[$i]);
715                                 if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
716                         }
717                 } else {                // 文字列の場合
718                         $destScript = trim($scriptFile);
719                         if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
720                 }
721         }
722         /**
723          * HTMLヘッダに出力するRSSファイルを追加
724          *
725          * @param array $rssFile        タイトル(title)、配信用URL(href)の連想配列。複数の場合は連想配列の配列。
726          * @return                                      なし
727          */
728         function addHeadRssFile($rssFile)
729         {
730                 // パラメータエラーチェック
731                 if (!is_array($rssFile)) return;
732                 
733                 $line = $rssFile[0];
734                 if (is_array($line)){   // 複数追加の場合
735                         for ($i = 0; $i < count($line); $i++){
736                                 // すでに追加済みかどうかチェック
737                                 $url = trim($line[$i]['href']);
738                                 if (!empty($url)){
739                                         for ($j = 0; $j < count($this->headRssFiles); $j++){
740                                                 $storedUrl = $this->headRssFiles[$j]['href'];
741                                                 if ($url == $storedUrl) break;
742                                         }
743                                         if ($j == count($this->headRssFiles)){          // 見つからないときは追加
744                                                 $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
745                                                                                                                 'title' => $line[$i]['title']);         // タイトル
746                                         }
747                                 }
748                         }
749                 } else {                // 単数追加のとき
750                         // すでに追加済みかどうかチェック
751                         $url = trim($rssFile['href']);
752                         if (!empty($url)){
753                                 for ($i = 0; $i < count($this->headRssFiles); $i++){
754                                         $storedUrl = $this->headRssFiles[$i]['href'];
755                                         if ($url == $storedUrl) break;
756                                 }
757                                 if ($i == count($this->headRssFiles)){          // 見つからないときは追加
758                                         $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
759                                                                                                         'title' => $rssFile['title']);          // タイトル
760                                 }
761                         }
762                 }
763         }
764         /**
765          * HTMLヘッダに最初に出力するタグ文字列を設定
766          *
767          * @param string $str   追加するタグ文字列
768          * @return                              なし
769          */
770         function setHeadFirstTag($str)
771         {
772                 if (!empty($str)) $this->headFirstTag = $str;
773         }
774         /**
775          * ヘッダ部に出力するカノニカル属性URLを設定
776          *
777          * @param string $url           URL
778          * @return                                      なし
779          */
780         function setCanonicalUrl($url)
781         {
782                 if (!empty($url)) $this->headCanonicalUrl = $url;                               // カノニカル属性URL
783         }
784         /**
785          * RSSチャンネル部に出力するデータを設定
786          *
787          * @param array $rssData        RSSチャンネル部データ
788          * @return                                      なし
789          */
790         function setRssChannel($rssData)
791         {
792                 if (!empty($rssData)) $this->rssChannel = $rssData;                             // RSSチャンネルデータ
793         }
794         /**
795          * 表示ポジションを表示するかどうか
796          *
797          * @param int $mode   0=ポジション表示しない(通常画面)、1=ポジション表示、2=ウィジェット込みポジション表示
798          */
799         function showPosition($mode)
800         {
801                 $this->showPositionMode = $mode;
802         }
803         /**
804          * 画面レイアウト中かどうか
805          *
806          * @return bool         true=レイアウト中、false=レイアウト中でない
807          */
808         function isLayout()
809         {
810                 return $this->isLayout;                         // 画面レイアウト中かどうか
811         }
812         /**
813          * ウィジェットの単体表示を設定
814          */
815         function showWidget()
816         {
817                 $this->showWidget = true;
818         }
819         /**
820          * ウィジェットの単体表示を取得
821          *
822          * @param bool          true=単体表示、false=単体表示でない
823          */
824         function getShowWidget()
825         {
826                 return $this->showWidget;
827         }
828         /**
829          * システム制御遷移モードを設定
830          *
831          * @param int $mode   0=設定なし、1=ログイン画面、10=サイト非公開、11=アクセス不可、12=存在しないページ
832          */
833         function setSystemHandleMode($mode)
834         {
835                 $this->systemHandleMode = $mode;
836         }
837         /**
838          * システム制御遷移モード取得
839          */
840         function getSystemHandleMode()
841         {
842                 return $this->systemHandleMode;
843         }
844         /**
845          * フロント画面編集モードを設定
846          *
847          * @return                              なし
848          */
849         function setEditMode()
850         {
851                 $this->isEditMode = true;
852         }
853         /**
854          * フロント画面編集モードを取得
855          *
856          * @return bool         true=編集モードオン、false=編集モードオフ
857          */
858         function isEditMode()
859         {
860                 return $this->isEditMode;
861         }
862         /**
863          * 機能アクセスパーソナルモードを設定
864          *
865          * @return                              なし
866          */
867         function setPersonalMode()
868         {
869                 $this->isPersonalMode = true;
870         }
871         /**
872          * 機能アクセスパーソナルモードを取得
873          *
874          * @return bool         true=パーソナルモードオン、false=パーソナルモードオフ
875          */
876         function isPersonalMode()
877         {
878                 return $this->isPersonalMode;
879         }
880         /**
881          * 出力フォーマットがHTMLであるかを設定
882          *
883          * @param bool $isHtml  HTMLフォーマットかどうか
884          * @return                              なし
885          */
886         function setOutputByHtml($isHtml)
887         {
888                 $this->outputByHtml = $isHtml;
889         }
890         
891         /**
892          * AJAX用のレスポンスボディデータかどうかを設定
893          *
894          * @param bool $isResponseBody  レスポンスボディデータかどうか
895          * @return                                              なし
896          */     
897         function setOutputAjaxResponseBody($isResponseBody)
898         {
899                 $this->outputAjaxResponseBody = $isResponseBody;
900         }
901         /**
902          * ヘルプ機能の使用可否を設定
903          *
904          * @param bool $status  ヘルプ機能を使用するかどうか
905          * @return                              なし
906          */
907         function setUseHelp($status)
908         {
909                 $this->useHelp = $status;
910         }
911         /**
912          * ヘルプ機能の使用可否を取得
913          *
914          * @return bool ヘルプ機能を使用するかどうか
915          */
916         function getUseHelp()
917         {
918                 return $this->useHelp;
919         }
920         /**
921          * 表示するコンテンツにGoogleマップが含まれているかを設定
922          *
923          * @param bool $status  Googleマップを含むかどうか
924          * @return                              なし
925          */
926         function setIsContentGooglemaps($status)
927         {
928                 $this->isContentGooglemaps = $status;           // コンテンツにGoogleマップが含むかどうか
929         }
930         /**
931          * 表示するコンテンツにGoogleマップが含まれているかを取得
932          *
933          * @return bool ヘルプ機能を使用するかどうか
934          */
935         function isContentGooglemaps()
936         {
937                 return $this->isContentGooglemaps;
938         }
939         /**
940          * JavaScriptのブラウザキャッシュの使用可否を設定
941          *
942          * @param bool $status  ブラウザキャッシュを使用するかどうか
943          * @return                              なし
944          */
945         function setHasScriptCache($status)
946         {
947                 $this->hasScriptCache = $status;
948         }
949         /**
950          * Bootstrapを使用に設定
951          *
952          * @return                              なし
953          */
954         function useBootstrap()
955         {
956                 $this->useBootstrap = true;                             // Bootstrapを使用するかどうか
957         }
958         /**
959          * Bootstrapを強制的に未使用に設定
960          *
961          * @return                              なし
962          */
963         function cancelBootstrap()
964         {
965                 $this->useBootstrap = false;                            // Bootstrapを使用するかどうか
966         }
967         /**
968          * Bootstrap使用状況を取得
969          *
970          * @return bool                 true=使用、false=使用しない
971          */
972         function getUseBootstrap()
973         {
974                 return $this->useBootstrap;                             // Bootstrapを使用するかどうか
975         }
976         /**
977          * HTML5を使用に設定
978          *
979          * @return                              なし
980          */
981         function setHtml5()
982         {
983                 $this->isHtml5 = true;                                  // HTML5で出力するかどうか
984         }
985         /**
986          * ページ作成処理を中断するかどうかを取得
987          *
988          * @return bool         true=中断、false=継続
989          */
990         function isPageAbort()
991         {
992                 return $this->isAbort;
993         }
994         /**
995          * 現在のウィジェットのポジションを取得
996          *
997          * @param string $pos           ポジション
998          * @param int    $index         インデックス番号
999          * @return                      なし
1000          */
1001         function getCurrentWidgetPosition(&$pos, &$index)
1002         {
1003                 $pos = $this->currentWidgetPosition;                    // 現在のウィジェットのポジション
1004                 $index = $this->currentWidgetIndex;                     // 現在のウィジェットのポジション番号
1005         }
1006         /**
1007          * 親ウィンドウを再描画
1008          *
1009          * @param int $defSerial        ページ定義シリアル番号
1010          * @return                                      なし
1011          */
1012         function updateParentWindow($defSerial = 0)
1013         {
1014                 $this->updateParentWindow = true;
1015                 $this->updateDefSerial = $defSerial;                    // 更新する項目のページ定義シリアル番号
1016         }
1017         /**
1018          * CSSファイルの追加
1019          *
1020          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1021          * @return                              なし
1022          */
1023         function addCssFile($path)
1024         {
1025                 $destPath = trim($path, '/');
1026                 if (!in_array($destPath, $this->defaultCssFiles)) $this->defaultCssFiles[] = $destPath;
1027         }
1028         /**
1029          * CSSファイルの追加
1030          *
1031          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
1032          * @return                              なし
1033          */
1034         function addAdminCssFile($path)
1035         {
1036                 $destPath = trim($path, '/');
1037                 if (!in_array($destPath, $this->defaultAdminCssFiles)) $this->defaultAdminCssFiles[] = $destPath;
1038         }
1039         /**
1040          * 編集エリア用のCSSファイルの追加
1041          *
1042          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
1043          * @return                              なし
1044          */
1045         function addCkeditorCssFile($path)
1046         {
1047                 $destPath = trim($path, '/');
1048                 if (!in_array($destPath, $this->ckeditorCssFiles)) $this->ckeditorCssFiles[] = $destPath;
1049         }
1050         /**
1051          * JavaScriptファイルの追加
1052          *
1053          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1054          * @return                              なし
1055          */
1056         function addScriptFile($path)
1057         {
1058                 $destPath = trim($path, '/');
1059                 if (!empty($destPath) && !in_array($destPath, $this->defaultScriptFiles)) $this->defaultScriptFiles[] = $destPath;
1060         }
1061         /**
1062          * JavaScriptファイルの追加
1063          *
1064          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
1065          * @return                              なし
1066          */
1067         function addAdminScriptFile($path)
1068         {
1069                 $destPath = trim($path, '/');
1070                 if (!in_array($destPath, $this->defaultAdminScriptFiles)) $this->defaultAdminScriptFiles[] = $destPath;
1071         }
1072         /**
1073          * 追加設定するテンプレートIDを返す
1074          *
1075          * @return array                                                テンプレートID,サブテンプレートIDの配列
1076          */
1077         function getOptionTemplateId()
1078         {
1079                 global $gEnvManager;
1080                 
1081                 // ページ情報取得
1082                 $pageId = $gEnvManager->getCurrentPageId();
1083
1084                 switch ($this->contentType){
1085                         case M3_VIEW_TYPE_CONTENT:              // ページのコンテンツタイプ                         
1086                                 // コンテンツ単位のテンプレート設定
1087                                 $contentLibObj = $this->gInstance->getObject(self::CONTENT_OBJ_ID);
1088                                 if (isset($contentLibObj)) list($this->optionTemplateId, $this->optionSubTemplateId) = $contentLibObj->getOptionTemplate();
1089                                 break;
1090                         case M3_VIEW_TYPE_BLOG:         // ページがブログタイプのとき
1091                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // PCサイトのとき
1092                                         // ブログライブラリオブジェクトからテンプレートを取得
1093                                         $blogLibObj = $this->gInstance->getObject(self::BLOG_OBJ_ID);
1094                                         if (isset($blogLibObj)) list($this->optionTemplateId, $this->optionSubTemplateId) = $blogLibObj->getOptionTemplate();
1095                                 }
1096                                 break;
1097                 }
1098                 return array($this->optionTemplateId, $this->optionSubTemplateId);
1099         }
1100         /**
1101          * 使用した非共通ウィジェットの数を取得
1102          *
1103          * @return int                          ウィジェット数
1104          */
1105         function getNonSharedWidgetCount()
1106         {
1107                 return $this->nonSharedWidgetCount;
1108         }
1109         /**
1110          * ページのコンテンツタイプを取得
1111          *
1112          * @return string                       コンテンツタイプ
1113          */
1114         function getContentType()
1115         {
1116                 return $this->contentType;
1117         }
1118         /**
1119          * フロント画面で使用する主要コンテンツタイプの情報取得
1120          *
1121          * @return array                        コンテンツタイプの情報の連想配列
1122          */
1123         function getMainContentTypeInfo()
1124         {
1125                 return $this->mainContentTypeInfo;                              // 主要コンテンツタイプ
1126         }
1127         /**
1128          * フロント画面で使用する補助コンテンツタイプの情報取得
1129          *
1130          * @return array                        コンテンツタイプの情報の連想配列
1131          */
1132         function getSubContentTypeInfo()
1133         {
1134                 return $this->subContentTypeInfo;                               // 補助コンテンツタイプ
1135         }
1136         /**
1137          * フロント画面で使用する主要コンテンツタイプを取得
1138          *
1139          * @return array                        コンテンツタイプの配列
1140          */
1141         function getMainContentTypes()
1142         {
1143                 // 「value」値のみ取得
1144                 //return array_map(create_function('$a', 'return $a["value"];'), $this->mainContentTypeInfo);
1145                 $types = array_map(function($a){ return $a["value"]; }, $this->mainContentTypeInfo);
1146                 return $types;
1147         }
1148         /**
1149          * フロント画面で使用するサブコンテンツタイプを取得
1150          *
1151          * @return array                        コンテンツタイプの配列
1152          */
1153         function getSubContentTypes()
1154         {
1155                 // 「value」値のみ取得
1156 //              return array_map(create_function('$a', 'return $a["value"];'), $this->subContentTypeInfo);
1157                 $types = array_map(function($a){ return $a["value"]; }, $this->subContentTypeInfo);
1158                 return $types;
1159         }
1160         /**
1161          * フロント画面で使用する主要機能タイプ情報を取得
1162          *
1163          * @return array                        機能タイプの情報の連想配列
1164          */
1165         function getMainFeatureTypeInfo()
1166         {
1167                 return $this->mainFeatureTypeInfo;                              // 主要機能タイプ
1168         }
1169         /**
1170          * フロント画面で使用する主要機能タイプを取得
1171          *
1172          * @return array                        機能タイプの配列
1173          */
1174         function getMainFeatureTypes()
1175         {
1176                 // 「value」値のみ取得
1177 //              return array_map(create_function('$a', 'return $a["value"];'), $this->mainFeatureTypeInfo);
1178                 $types = array_map(function($a){ return $a["value"]; }, $this->mainFeatureTypeInfo);
1179                 return $types;
1180         }
1181         
1182         /**
1183          * すべてのページ属性情報を取得
1184          *
1185          * @return array                        ページ属性情報の連想配列
1186          */
1187         function getAllPageAttributeTypeInfo()
1188         {
1189                 return array_merge($this->mainContentTypeInfo, $this->subContentTypeInfo, $this->mainFeatureTypeInfo, $this->adminFeatureTypeInfo);
1190         }
1191         /**
1192          * 管理画面用のサブメニューバーの定義を設定
1193          *
1194          * @param array $def    メニューバー定義
1195          * @return                              なし
1196          */
1197         function setAdminSubNavbarDef($def)
1198         {
1199                 $this->adminSubNavbarDef = $def;
1200         }
1201         /**
1202          * 管理画面用のサブメニューバーの定義を取得
1203          *
1204          * @return array メニューバーの定義
1205          */
1206         function getAdminSubNavbarDef()
1207         {
1208                 return $this->adminSubNavbarDef;
1209         }
1210         /**
1211          * 管理画面用パンくずリスト定義を設定
1212          *
1213          * @param array $def    パンくずリスト定義
1214          * @param array $help   ヘルプ(title,bodyの連想配列)
1215          * @return                              なし
1216          */
1217         function setAdminBreadcrumbDef($def, $help = array())
1218         {
1219                 $this->adminBreadcrumbDef = $def;
1220                 if (!empty($help)) $this->adminBreadcrumbDefHelp = $help;                               // 管理画面用パンくずリストヘルプ定義
1221         }
1222         /**
1223          * 管理画面用パンくずリスト定義を取得
1224          *
1225          * @param array $help   ヘルプ(title,bodyの連想配列)
1226          * @return array                パンくずリスト定義
1227          */
1228         function getAdminBreadcrumbDef(&$help)
1229         {
1230                 // パラメータ数を取得
1231                 $argNum = func_num_args();
1232                 
1233                 // ヘルプ取得用パラメータが存在する場合は定義を設定
1234                 if ($argNum > 0) $help = $this->adminBreadcrumbDefHelp;
1235
1236                 return $this->adminBreadcrumbDef;
1237         }
1238         /**
1239          * ページ作成開始
1240          *
1241          * HTTPヘッダを設定する。セッションを取得する。サブページIDを設定する。
1242          *
1243          * @param RequestManager $request               HTTPリクエスト処理クラス
1244          * @return                                                              なし
1245          */
1246         function startPage($request)
1247         {
1248                 global $gEnvManager;
1249                 global $gRequestManager;
1250                 global $gInstanceManager;
1251                 global $gAccessManager;
1252                 global $gSystemManager;
1253                 global $gDispManager;
1254                 global $gOpeLogManager;
1255                 
1256                 // 実行コマンドを取得
1257                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
1258                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
1259                 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
1260                 $pageId = $gEnvManager->getCurrentPageId();
1261
1262                 // ###### クライアントIDの読み込み、再設定 ######
1263                 // この後、クライアントIDがアクセスログに記録される
1264                 $clientId = $request->getCookieValue(M3_COOKIE_CLIENT_ID);
1265                 if (empty($clientId)){  // クライアントIDが設定されていないとき(初回アクセス)
1266                         // クライアントIDを生成
1267                         $clientId = $this->gAccess->createClientId();
1268                 } else {
1269                         $this->gAccess->setClientId($clientId); // クライアントIDを設定
1270                 
1271                         // クッキーの使用可否を設定
1272                         $this->gEnv->setCanUseCookie(true);
1273                 }
1274                 $request->setCookieValue(M3_COOKIE_CLIENT_ID, $clientId, M3_COOKIE_EXPIRE_CLIENT_ID);
1275                         
1276                 // インストール時の管理画面用ライブラリを追加(フレームコンテナでの設定を反映)
1277                 if (defined('M3_STATE_IN_INSTALL')){
1278                         // Bootstrapライブラリ追加
1279                         if ($this->useBootstrap){
1280                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
1281                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
1282                         }
1283                 } else {
1284                         // 管理者キーがあればGETまたはPOST値のセッションIDを使用する
1285 //                      if ($gEnvManager->isAdminDirAccess()){
1286 //                              if ($gAccessManager->isValidAdminKey()) session_id($gRequestManager->trimValueOf(session_name()));
1287 //                      }
1288                 }
1289
1290                 // 最終HTML(ページ全体で使用するHTML)の出力
1291                 if ($cmd == M3_REQUEST_CMD_CSS){                // CSS生成のとき
1292                         $gRequestManager->stopSessionUpdate();                  // セッションの更新を停止
1293                 }
1294                 
1295                 // セッション変数を取得可能にする
1296                 session_start();
1297                 
1298                 // ##### インストール時はここで終了 #####
1299                 if (defined('M3_STATE_IN_INSTALL')) return;             // インストール時は実行しない
1300                 
1301                 // セッションを再生成する(セキュリティ対策)
1302                 if ($gSystemManager->regenerateSessionId()){
1303                         $gAccessManager->setOldSessionId(session_id());         // 古いセッションIDを保存
1304                         session_regenerate_id(true);
1305                 }
1306                 
1307                 // セッションからユーザ情報を取得
1308                 $userInfo = $gRequestManager->getSessionValueWithSerialize(M3_SESSION_USER_INFO);
1309                 if (!$gAccessManager->checkSessionSecurity($userInfo)) return;                  // セキュリティ問題ありの場合はここで終了
1310                 // ##### ここで終了した場合はページサブIDが未設定のためページ不正のエラーが発生しアクセスエラー画面が表示される #####
1311                 
1312                 // ##### POST時のリファラーチェック #####
1313                 // WooCommerceのAJAX処理が通らないのでチェックしない?
1314 /*              if ($gRequestManager->isPostMethod() && !$this->_checkReferer()){
1315                         $errMsg = '不正なPOSTデータ(リファラー異常)を検出しました。アクセス元IP: ' . $gAccessManager->getClientIp();
1316                         $msgDetail = 'アクセスをブロックしました。account=' . $userInfo->account . ', userid=' . $userInfo->userId;
1317                         $gOpeLogManager->writeUserError(__METHOD__, $errMsg, 2210, $msgDetail);
1318                         return;
1319                 }*/
1320                 
1321                 // その他セッション情報取得
1322                 $gRequestManager->_doSessionOpenEventCallback();
1323
1324                 // ユーザ情報をロード
1325                 $gInstanceManager->setUserInfo($userInfo);
1326
1327                 // ##### 自動ログイン #####
1328                 // ログイン中でない場合は自動ログインでユーザ情報を取得
1329                 $gAccessManager->startAutoLogin();
1330                 
1331                 // デバッグモードの表示
1332                 if (M3_SYSTEM_DEBUG) echo 'Debug mode<br />';
1333                 
1334                 // ##### ユーザアクセスモードの設定 #####
1335                 if (!empty($userInfo) && $userInfo->isPersonal()) $this->setPersonalMode();             // パーソナルモードをオン
1336 /*              if (($userInfo->userType == UserInfo::USER_TYPE_MANAGER && $userInfo->userOptType == UserInfo::USER_OPT_TYPE_PAGE_MANAGER)||                    // ページ運用者の場合
1337                         $userInfo->userType < UserInfo::USER_TYPE_MANAGER){                     // システム運用者よりも権限が低い場合
1338                         
1339                         // パーソナルモードをオン
1340                         $this->setPersonalMode();
1341                 }*/
1342
1343                 // ##### ページIDの修正 #####
1344                 // ポジション表示の場合はページID、ページサブIDを再設定。再設定はシステム管理者のみ可能。
1345                 if (($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                                    // 管理画面(ウィジェットなしポジション表示)のとき
1346                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) &&            // 管理画面(ウィジェット付きポジション表示)のとき
1347 //                      $gEnvManager->isSystemAdmin()){
1348                         $gEnvManager->isSystemManageUser()){    // システム運用可能の場合(2018/8/5変更)
1349
1350                         $pageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1351                         if (empty($pageId)) $pageId = $this->gEnv->getDefaultPageId();          // 値がないときはデフォルトのページIDを設定
1352                         $this->gEnv->setCurrentPageId($pageId);
1353                         $subId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1354                         if (!empty($subId)) $this->gEnv->setCurrentPageSubId($subId);
1355                 }
1356                 
1357                 // ##### サブページIDの設定 #####
1358                 if ($gEnvManager->isAdminDirAccess() &&         // 管理画面へのアクセスのとき
1359                         ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT)){                               // ログイン、ログアウト場合は管理画面のページサブIDを指定
1360                         $subId = $gEnvManager->getAdminDefaultPageSubId();              // 管理画面用のデフォルトページサブID
1361                 } else {
1362                         if (empty($subId)) $subId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);// ページサブIDを取得
1363                         
1364                         if (empty($subId)){                     // サブページIDが設定されていないとき
1365                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1366                                 $params = $gRequestManager->getQueryArray();
1367                                 $paramCount = count($params);
1368
1369                                 // コマンド以外のパラメータ数が1つだけのときはパラメータからページ属性を判断する
1370                                 // 値が空でもキーがあれば属性を持つとする
1371                                 if ($paramCount == 0){
1372                                         $this->isPageTopUrl = true;                     // ページトップ(サブページ内のトップ位置)のURLかどうか
1373                                         
1374                                         //if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemAdmin() && empty($task)){
1375                                         if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser() && empty($task)){
1376                                                 // ダッシュボード機能は、パラメータなし、管理者ディレクトリ、システム運用者の条件で使用可能(2018/8/5変更)
1377                                                 // POST値にタスクがある場合はダッシュボードとしない
1378                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_DASHBOARD, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1379                                         }
1380                                 } else if ($paramCount > 0 && !$gEnvManager->isAdminDirAccess()){               // パラメータ付きの場合(2013/3/23)
1381                                         // ##### ページ属性から画面を選択(管理画面は対応しない) ###
1382                                         // 最初のURLパラメータでコンテンツを判断
1383                                         // プレビュー(cmd=preview)等のパターンで複数パラメータがある
1384                                         reset($params);
1385                                         $firstKey = key($params);
1386                                         $firstValue = $params[$firstKey];
1387
1388                                         if (!empty($firstValue)){               // 「key=value」の形式であること
1389                                                 switch ($firstKey){
1390                                                         case M3_REQUEST_PARAM_CONTENT_ID:               // コンテンツIDのとき
1391                                                         case M3_REQUEST_PARAM_CONTENT_ID_SHORT:
1392                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1393                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1394                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1395                                                         
1396                                                                 // ローカルメニューのURLからページを特定。ページが特定できないときはページ属性で取得。
1397                                                                 $url = $gEnvManager->getMacroPath($gEnvManager->getCurrentRequestUri());
1398                                                                 $ret = $this->db->getSubPageIdByMenuItemUrl($url, $gEnvManager->getCurrentPageId(), M3_VIEW_TYPE_CONTENT, $rows);
1399                                                                 if ($ret){
1400                                                                         $rowCount = count($rows);
1401                                                                         for ($i = 0; $i < $rowCount; $i++){
1402                                                                                 // コンテンツを表示するウィジェットがあるときはページサブIDを確定
1403                                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);
1404                                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);// コンテンツタイプでの取得に変更(2012/6/20)
1405                                                                                 if (!empty($widgetId)){
1406                                                                                         $subId = $rows[$i]['pd_sub_id'];
1407                                                                                         break;
1408                                                                                 }
1409                                                                         }
1410                                                                 }
1411                                                                 if (empty($subId)) $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_CONTENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1412                                                                 $this->contentType = M3_VIEW_TYPE_CONTENT;              // ページのコンテンツタイプ
1413                                                                 
1414                                                                 // コンテンツ詳細ページかどうかを設定
1415                                                                 if ($firstKey == M3_REQUEST_PARAM_CONTENT_ID || $firstKey == M3_REQUEST_PARAM_CONTENT_ID_SHORT) $this->isContentDetailPage = true;
1416                                                                 break;
1417                                                         case M3_REQUEST_PARAM_PRODUCT_ID:       // 製品IDのとき
1418                                                         case M3_REQUEST_PARAM_PRODUCT_ID_SHORT:
1419                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1420                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1421                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1422                                                                 
1423                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PRODUCT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1424                                                                 $this->contentType = M3_VIEW_TYPE_PRODUCT;              // ページのコンテンツタイプ
1425                                                                 
1426                                                                 // コンテンツ詳細ページかどうかを設定
1427                                                                 $this->isContentDetailPage = true;
1428                                                                 break;
1429                                                         case M3_REQUEST_PARAM_BBS_ID:           // 掲示板投稿記事のとき
1430                                                         case M3_REQUEST_PARAM_BBS_ID_SHORT:
1431                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID:
1432                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT:
1433                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1434                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1435                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1436                                                                 
1437                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BBS, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1438                                                                 $this->contentType = M3_VIEW_TYPE_BBS;          // ページのコンテンツタイプ
1439                                                                 
1440                                                                 // コンテンツ詳細ページかどうかを設定
1441                                                                 if ($firstKey == M3_REQUEST_PARAM_BBS_THREAD_ID || $firstKey == M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT) $this->isContentDetailPage = true;
1442                                                                 break;
1443                                                         case M3_REQUEST_PARAM_EVENT_ID:         // イベント記事のとき
1444                                                         case M3_REQUEST_PARAM_EVENT_ID_SHORT:
1445                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1446                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1447                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1448                                                                 
1449                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_EVENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1450                                                                 $this->contentType = M3_VIEW_TYPE_EVENT;                // ページのコンテンツタイプ
1451                                                                 
1452                                                                 // コンテンツ詳細ページかどうかを設定
1453                                                                 $this->isContentDetailPage = true;
1454                                                                 break;
1455                                                         case M3_REQUEST_PARAM_PHOTO_ID:         // フォトギャラリー写真のとき
1456                                                         case M3_REQUEST_PARAM_PHOTO_ID_SHORT:
1457                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1458                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1459                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1460                                                                 
1461                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PHOTO, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1462                                                                 $this->contentType = M3_VIEW_TYPE_PHOTO;                // ページのコンテンツタイプ
1463                                                                 
1464                                                                 // コンテンツ詳細ページかどうかを設定
1465                                                                 $this->isContentDetailPage = true;
1466                                                                 break;
1467                                                         case M3_REQUEST_PARAM_BLOG_ID:          // ブログIDのとき
1468                                                         case M3_REQUEST_PARAM_BLOG_ID_SHORT:
1469                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID:
1470                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT:
1471                                                                 // ### 値をチェックし不正文字がある場合はエラー画面へ遷移 ###
1472                                                                 $checkStatus = $this->_checkFirstValueRedirect($firstValue);
1473                                                                 if (!$checkStatus) return;                      // エラーの場合は終了
1474                 
1475                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BLOG, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1476                                                                 $this->contentType = M3_VIEW_TYPE_BLOG;         // ページのコンテンツタイプ
1477                                                                 
1478                                                                 // コンテンツ詳細ページかどうかを設定
1479                                                                 if ($firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID || $firstKey == M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT) $this->isContentDetailPage = true;
1480                                                                 break;
1481                                                         default:                // オプションのURLコンテンツパラメータからサブページIDを取得
1482                                                                 $ret = $this->db->getSubPageIdByUrlContentParam($gEnvManager->getCurrentPageId(), $firstKey, $row);
1483                                                                 if ($ret) $subId = $row['pd_sub_id'];
1484                                                                 break;
1485                                                 }
1486                                         }
1487                                 }
1488
1489                                 // wiki用パラメータの取得
1490                                 if (empty($subId)){
1491                                         // 「http://www.example.com?ページ名」「wcmd」の場合はwikiコンテンツページを選択
1492                                         $wikiCmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND);
1493                                         $pageName = $gRequestManager->getWikiPageFromQuery();           // 「=」なしのパラメータはwikiパラメータとする
1494                         
1495                                         if (!empty($wikiCmd) || !empty($pageName)){                     // Wikiコンテンツページを指定のとき
1496                                                 // ページサブIDを取得
1497                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_WIKI, $gEnvManager->getCurrentPageId());
1498                                                 $this->contentType = M3_VIEW_TYPE_WIKI;         // ページのコンテンツタイプ
1499                                                 
1500                                                 // コンテンツ詳細ページかどうかを設定
1501                                                 $this->isContentDetailPage = true;
1502                                         }
1503                                 }
1504                                 // その他のGET,POSTパラメータからページサブID取得
1505                                 if (empty($subId)){
1506                                         // 検索用パラメータなどでリダイレクト先のURLが取得できた場合は遷移
1507                                         $subId = $this->getPageSubIdByParam($request, $redirectUrl);
1508                                         if (!empty($subId) && !empty($redirectUrl)) $this->redirect($redirectUrl);
1509                                 }
1510                                 
1511                                 // ページサブIDが取得できない場合はデフォルトを使用
1512                                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
1513                         } else {                // ページサブIDが設定されているとき
1514                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1515                                 $params = $gRequestManager->getQueryArray();
1516                                 $paramCount = count($params);
1517                                 if ($paramCount == 1) $this->isPageTopUrl = true;                       // ページトップ(サブページ内のトップ位置)のURLかどうか
1518                         }
1519                 }
1520                 $gEnvManager->setCurrentPageSubId($subId);// サブページIDを設定
1521                 
1522                 // SSL通信機能がオンの場合は、アクセスされたURLのSSLをチェックし不正の場合は正しいURLにリダイレクト
1523                 // 設定に間違いがある場合、管理画面にアクセスできなくなるので、フロント画面のみ制御
1524 //              if ($gEnvManager->getUseSsl() || $gEnvManager->getUseSslAdmin()){
1525                 if ($gEnvManager->getUseSsl()){                 // フロント画面のSSL設定のみチェック(2016/7/30)
1526                         if (!$gEnvManager->isAdminDirAccess()){         // 管理画面以外へのアクセスのとき
1527                                 // ルートURLがSSLの場合はSSLに固定
1528                                 if ($gEnvManager->isRootUrlSsl()){              // ルートURLがSSLの場合はフロント画面のすべてがSSL付き
1529                                         $isSsl = true;
1530                                 } else {
1531                                         $isSsl = $gEnvManager->isSslByCurrentPage();
1532                                 }
1533                                 $currentUrl = $gEnvManager->getCurrentRequestUri();
1534                                 if ($isSsl){
1535                                         $correctUrl = str_replace('http://', 'https://', $currentUrl);
1536                                 } else {
1537                                         $correctUrl = str_replace('https://', 'http://', $currentUrl);
1538                                 }
1539                                 if ($currentUrl != $correctUrl) $this->redirect($correctUrl);
1540                         }
1541                 }
1542                 // マルチドメイン用設定初期化
1543                 $gEnvManager->initMultiDomain();
1544                 
1545                 // 画面設定取得
1546                 $gDispManager->load();
1547                 
1548                 // Magic3管理用のスクリプトを追加
1549                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
1550                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
1551 //                                      $this->isEditMode = true;                       // フロント画面編集モード
1552                                 $this->isPageEditable = true;           // フロント画面ページ編集可能モードに設定(コンテキストメニュー表示)
1553                                         
1554                                 // 管理画面用ライブラリを追加
1555                                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1556                                 //if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){                                          // ウィジェット設定画面またはテンプレート設定画面のとき
1557                                         $this->addAdminScript('', ScriptLibInfo::getWysiwygEditorLibId());      // WYSIWYGエディターを追加
1558                                         
1559                                         // Googleマップライブラリの読み込み
1560                                         if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1561                                                 $this->defaultAdminScriptFiles[] = ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS);
1562                                         }
1563                                 } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // 管理画面(ウィジェット付きポジション表示)のとき
1564                                         $this->isLayout = true;         // 画面レイアウト中かどうか
1565                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_IDTABS);                    // 管理パネル用スクリプト追加(ポジション表示追加分)
1566                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_DROPDOWN);               // 管理パネル用スクリプト追加(ドロップダウンメニュー)
1567                                         //$this->useBootstrap = true;           // Bootstrapを使用
1568                                         //$this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);             // パネルメニュー(フロント画面と管理画面の切り替え等)用
1569                                 }
1570                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1571                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1572                                 
1573                                 // スクリプトが必要なウィジェットをすべて取得
1574                                 $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1575                                 for ($i = 0; $i < count($rows); $i++){
1576                                         $this->addAdminScript($task, trim($rows[$i]['wd_add_script_lib']));
1577                                 }
1578                                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1579                                         // ウィジェット情報取得
1580                                         $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
1581                                         $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
1582                                         if ($ret) $this->addAdminScript($task, trim($this->configWidgetInfo['wd_add_script_lib_a']));           // 管理機能用スクリプト
1583                                 }
1584                         }
1585                 } else {                // フロント画面へのアクセスのとき
1586                         // フロント画面用スクリプトファイル追加
1587                         $this->addScriptFile($this->selectedJQueryFilename);// 常にjQueryを使用
1588         
1589                         if ($cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                 // ウィジェット単体実行でない
1590                                 $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
1591                                 if ($gEnvManager->isSystemManageUser()){
1592                                         $this->isEditMode = true;                       // フロント画面編集モード
1593                                         $this->isPageEditable = true;           // フロント画面ページ編集可能モードに設定
1594                                 
1595                                         // システム運用権限がある場合は管理用スクリプトを追加
1596                                         // フロント画面と管理画面の切り替え用のスライドメニューバーには管理用スクリプト,CSSが必要
1597                                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1598                                         $this->addScriptFile(ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME);               // jQuery Contextmenu Lib
1599                                         $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1600                                         //$this->addScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);          // パネルメニュー(フロント画面と管理画面の切り替え等)用
1601                                         $this->addScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);  // 管理パネル用スクリプト追加
1602                                         $this->addScript('', ScriptLibInfo::LIB_JQUERY_COOKIE);                 // 管理パネル用スクリプト追加
1603                                         $this->addScript('', ScriptLibInfo::LIB_JQUERY_EASING);                 // 管理パネル用スクリプト追加
1604                                         $this->addScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1605                                         $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1606                                 
1607                                         $this->addCssFile(self::M3_ADMIN_CSS_FILE);             // 管理機能用CSS
1608                                 } else if ($gEnvManager->isContentEditableUser()){              // コンテンツ編集可能ユーザの場合
1609                                         $this->isEditMode = true;                       // フロント画面編集モード
1610                                 }
1611                         } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
1612                                 if ($gEnvManager->isContentEditableUser()){             // コンテンツ編集可能ユーザの場合
1613                                         $this->isEditMode = true;                       // フロント画面編集モード
1614                                 
1615 //                                              $this->addScript('', ScriptLibInfo::LIB_JQUERY_RESPONSIVETABLE);// 管理画面作成用
1616                                         $this->addScript('', ScriptLibInfo::getWysiwygEditorLibId());   // WYSIWYGエディターを追加
1617                                         $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1618                                         $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
1619                                         $this->addScript('', ScriptLibInfo::LIB_JQUERY_HOVERINTENT);// HELP用スクリプト追加
1620                                         $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1621                                         
1622                                         // Googleマップライブラリの読み込み
1623                                         if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1624                                                 $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));
1625                                         }
1626                                 }
1627                         }
1628                 }
1629
1630                 // デフォルトのページ情報を取得
1631                 $row = $this->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
1632                 if (!empty($row)){
1633                         // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1634                         if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1635                 
1636                         // 現在のページ情報を設定
1637                         $this->currentPageInfo = $row;                  // 現在のページのページ情報
1638                 }
1639                         
1640                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)のとき
1641 /*                      $defPageId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
1642                         $defPageSubId = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
1643                         
1644                         // デフォルトのページ情報を取得
1645                         $row = $this->getPageInfo($defPageId, $defPageSubId);
1646                         if (!empty($row)){
1647                                 // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1648                                 if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1649                         
1650                                 // 現在のページ情報を設定
1651                                 $this->currentPageInfo = $row;                  // 現在のページのページ情報
1652                         }*/
1653                         
1654                         // テンプレートの情報を取得
1655         //              $ret = $this->db->getPageDefOnPage($defPageId, $defPageSubId, $rows);
1656                         $ret = $this->db->getPageDefOnPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1657                         if ($ret){
1658                                 for ($i = 0; $i < count($rows); $i++){
1659                                         $position = $rows[$i]['pd_position_id'];
1660                                         if (!in_array($position, $this->defPositions)) $this->defPositions[] = $position;       // 画面定義データのポジション(すべて)
1661                                 }
1662                         }
1663                 }
1664                 
1665                 // 画面透過モードを設定
1666                 if ($openBy == 'tabs') $this->isTransparentMode = true;         // 画面透過モード
1667         }
1668         /**
1669          * URLの最初のパラメータが不正文字の場合はエラー画面へリダイレクト
1670          *
1671          * @param string $value                 URLの最初のパラメータ値
1672          * @return bool                                 true=正常、false=異常
1673          */
1674         function _checkFirstValueRedirect($value)
1675         {
1676                 global $gEnvManager;
1677                 global $gOpeLogManager;
1678                 
1679                 // 半角英小文字大文字、数字、アンダーバー、ハイフン、カンマのみ使用可能。
1680                 if (preg_match("/[^0-9a-zA-Z-_,]/", $value)){
1681                         $errMessage = 'URLパラメータの不正。';
1682                         $gOpeLogManager->writeUserAccess(__METHOD__, '不正なアクセスを検出しました。' . $errMessage, 2200, 'アクセスをブロックしました。URL: ' . $gEnvManager->getCurrentRequestUri());
1683                         
1684         //              $this->redirect('?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=_accessdeny');
1685                         // システム制御ページへ遷移
1686                         $this->isSystemPage = true;
1687                         return false;
1688                 } else {
1689                         return true;
1690                 }
1691         }
1692         /**
1693          * 言語に依存する情報を取り込む
1694          *
1695          * @return                                                      なし
1696          */
1697         function loadLang()
1698         {
1699                 global $gEnvManager;
1700                 global $gSystemManager;
1701                 
1702                 $lang = $gEnvManager->getCurrentLanguage();
1703                 
1704                 // デフォルト言語とカレント言語が異なる場合のみ実行
1705                 if ($lang != $gEnvManager->getDefaultLanguage()){
1706                         // 指定言語のサイト定義取得
1707                         $gSystemManager->roadSiteDefByLang($lang);
1708                 }
1709                 
1710                 // 現在の言語でヘッダ初期化
1711                 $this->headDescription  = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_DESCRIPTION);    // HTMLヘッダ「description」に出力する文字列
1712                 $this->headKeywords             = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_KEYWORDS);               // HTMLヘッダ「keywords」に出力する文字列
1713                 $this->headOthers               = $gSystemManager->getSiteDef(self::SD_HEAD_OTHERS);                    // HTMLヘッダに出力するタグ文字列
1714
1715                 // デフォルトのページ情報でヘッダを更新
1716                 if (!empty($this->currentPageInfo)){
1717                         $title          = $this->currentPageInfo['pn_meta_title'];              // 画面タイトル
1718                         $desc           = $this->currentPageInfo['pn_meta_description'];                // ページ要約
1719                         $keyword        = $this->currentPageInfo['pn_meta_keywords'];           // ページキーワード
1720                         $headOthers     = $this->currentPageInfo['pn_head_others'];             // ヘッダその他タグ
1721                         
1722                         if (!empty($title)) $this->setHeadSubTitle($title, '', true);           // デフォルト値として設定
1723                         if (!empty($desc)) $this->setHeadDescription($desc);
1724                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1725                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1726                 }
1727
1728                 // 現在の言語のページ情報でヘッダを更新
1729                 $ret = $this->db->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $lang, $row);
1730                 if ($ret){
1731                         $title          = $row['pn_meta_title'];                // 画面タイトル
1732                         $desc           = $row['pn_meta_description'];          // ページ要約
1733                         $keyword        = $row['pn_meta_keywords'];             // ページキーワード
1734                         $headOthers = $row['pn_head_others'];           // ヘッダその他タグ
1735                         
1736                         if (!empty($title)) $this->setHeadSubTitle($title, '', true);           // デフォルト値として設定
1737                         if (!empty($desc)) $this->setHeadDescription($desc);
1738                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1739                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1740                         
1741                         // 現在のページ情報を設定
1742 //                      $this->currentPageInfo = $row;                  // 現在のページのページ情報
1743                 }
1744         }
1745         /**
1746          * スクリプト追加情報から、管理機能用のJavascriptファイル、CSSを追加する
1747          *
1748          * @param string $task                          指定タスク
1749          * @param string $scriptInfo            スクリプト追加情報
1750          * @return                                                      なし
1751          */
1752         function addAdminScript($task, $scriptInfo)
1753         {
1754                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1755                 for ($i = 0; $i < count($itemArray); $i++){
1756                         $pos = strpos($itemArray[$i], '=');
1757                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1758                                 $libs = trim($itemArray[$i]);
1759                         } else {                // タスク指定のとき
1760                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1761                                 $libTask = trim($libTask);
1762                                 $libs = trim($libs);
1763                                 
1764                                 if (strEndsWith($libTask, '_')){                // 「task_subtask」形式のタスクのとき
1765                                         if (!strStartsWith($task, $libTask)) $libs = '';                        // タスクIDの先頭部が異なるときは追加しない
1766                                 } else {
1767                                         if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1768                                 }
1769                         }
1770                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1771                                 $libsArray = explode(',', $libs);
1772                                 for ($j = 0; $j < count($libsArray); $j++){
1773                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1774                                         
1775                                         // ライブラリセットを展開
1776                                         $setLibArray = ScriptLibInfo::getLibSet($lib);
1777                                         $setLibCount = count($setLibArray);
1778                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1779                                                 for ($k = 0; $k < $setLibCount; $k++){
1780                                                         $this->_addAdminScript($setLibArray[$k]);
1781                                                 }
1782                                         } else {
1783                                                 $this->_addAdminScript($lib);
1784                                         }
1785                                 }
1786                         }
1787                 }
1788         }
1789         /**
1790          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
1791          *
1792          * @param string $lib                           ライブラリID
1793          * @return                                                      なし
1794          */
1795         function _addAdminScript($lib)
1796         {
1797                 // ライブラリが存在しないときは終了
1798                 if (!isset($this->libFiles[$lib])) return;
1799                 
1800                 // 依存ライブラリを取得
1801 //              if (strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){         // elFinder、timepickerを使用する場合
1802                 // jQuery UIライブラリを追加
1803                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
1804                 if (isset($dependentLib)){
1805                         for ($i = 0; $i < count($dependentLib); $i++){
1806                                 $addLib = $dependentLib[$i];
1807
1808                                 // ライブラリのファイルを追加
1809                                 if (isset($this->libFiles[$addLib]['script'])){
1810                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1811                                         for ($m = 0; $m < count($scriptFiles); $m++){
1812                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1813                                         }
1814                                 }
1815                                 // ライブラリの言語ファイルを追加
1816                                 if (isset($this->libFiles[$addLib]['script_lang'])){
1817                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);
1818                                         for ($m = 0; $m < count($scriptFiles); $m++){
1819                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1820                                         }
1821                                 }
1822                                 // ライブラリのCSSファイルを追加
1823                                 if (isset($this->libFiles[$addLib]['css'])){
1824                                         $cssFiles = $this->libFiles[$addLib]['css'];
1825                                         for ($m = 0; $m < count($cssFiles); $m++){
1826                                                 $this->addAdminCssFile($cssFiles[$m]);          // 通常機能用のCSS追加
1827                                         }
1828                                 }
1829                         }
1830                         // jQueryUIテーマを追加
1831                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1832                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1833                                 $this->outputTheme = true;
1834                         }
1835                 }
1836
1837                 // Javascript追加
1838                 if (isset($this->libFiles[$lib]['script'])){
1839                         $scriptFiles = $this->libFiles[$lib]['script'];
1840
1841                         // ##### ライブラリ情報を作成する場合 #####
1842                         if (empty($scriptFiles)){
1843                                 $generatedLib = ScriptLibInfo::generateLib($lib);                       // ライブラリ取得
1844                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
1845                         }
1846                         
1847                         for ($i = 0; $i < count($scriptFiles); $i++){
1848                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1849                         }
1850                 }
1851                 // ライブラリの言語ファイルを追加
1852                 if (isset($this->libFiles[$lib]['script_lang'])){
1853                         $scriptFiles = ScriptLibInfo::getLangScript($lib);
1854                         for ($i = 0; $i < count($scriptFiles); $i++){
1855                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1856                         }
1857                 }
1858                 // CSS追加
1859                 if (isset($this->libFiles[$lib]['css'])){
1860                         $cssFiles = $this->libFiles[$lib]['css'];
1861                         for ($i = 0; $i < count($cssFiles); $i++){
1862                                 $this->addAdminCssFile($cssFiles[$i]);          // 管理機能用のCSS追加
1863                         }
1864                 }
1865                 // その他
1866                 if (strncmp($lib, 'jquery-ui.', 10) == 0){              // jQuery UIのwidgetsまたはeffectsのとき。jQuery UI Coreはデフォルトで読み込まれている。
1867                         // jQueryUIテーマを追加
1868                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1869                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1870                                 $this->outputTheme = true;
1871                         }
1872                 }
1873         }
1874         /**
1875          * スクリプト追加情報から、通常機能用のJavascriptファイル、CSSを追加する
1876          *
1877          * @param string $task                          指定タスク
1878          * @param string $scriptInfo            スクリプト追加情報
1879          * @return                                                      なし
1880          */
1881         function addScript($task, $scriptInfo)
1882         {
1883                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1884                 for ($i = 0; $i < count($itemArray); $i++){
1885                         $pos = strpos($itemArray[$i], '=');
1886                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1887                                 $libs = trim($itemArray[$i]);
1888                         } else {                // タスク指定のとき
1889                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1890                                 $libTask = trim($libTask);
1891                                 $libs = trim($libs);
1892                                 if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1893                         }
1894                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1895                                 $libsArray = explode(',', $libs);
1896                                 for ($j = 0; $j < count($libsArray); $j++){
1897                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1898                                         
1899                                         // jQueryライブラリ等、デフォルトでは追加されないライブラリを追加
1900                                         $setLibArray = ScriptLibInfo::getLibSet($lib);// ライブラリセットを展開
1901                                         $setLibCount = count($setLibArray);
1902                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1903                                                 for ($k = 0; $k < $setLibCount; $k++){
1904                                                         $this->_addScript($setLibArray[$k]);
1905                                                 }
1906                                         } else {
1907                                                 $this->_addScript($lib);
1908                                         }
1909                                 }
1910                         }
1911                 }
1912         }
1913         /**
1914          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
1915          *
1916          * @param string $lib                           ライブラリID
1917          * @return                                                      なし
1918          */
1919         function _addScript($lib)
1920         {
1921                 // ライブラリが存在しないときは終了
1922                 if (!isset($this->libFiles[$lib])) return;
1923
1924                 // ライブラリの依存ライブラリファイルを追加
1925                 if (strcmp($lib, 'jquery') == 0){// jQuery本体のとき
1926                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1927                 } else if (strncmp($lib, 'jquery.', 7) == 0){           // jQueryプラグインのとき
1928                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1929
1930                         // 依存ライブラリ追加
1931                         $dependentLib = ScriptLibInfo::getDependentLib($lib);
1932                         if (isset($dependentLib)){
1933                                 for ($i = 0; $i < count($dependentLib); $i++){
1934                                         $addLib = $dependentLib[$i];
1935                         
1936                                         // ライブラリのファイルを追加
1937                                         if (isset($this->libFiles[$addLib]['script'])){
1938                                                 $scriptFiles = $this->libFiles[$addLib]['script'];
1939                                                 for ($m = 0; $m < count($scriptFiles); $m++){
1940                                                         $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1941                                                 }
1942                                         }
1943                                         // ライブラリの言語ファイルを追加
1944                                         if (isset($this->libFiles[$addLib]['script_lang'])){
1945                                                 $scriptFiles = ScriptLibInfo::getLangScript($addLib);
1946                                                 for ($m = 0; $m < count($scriptFiles); $m++){
1947                                                         $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1948                                                 }
1949                                         }
1950                                         // ライブラリのCSSファイルを追加
1951                                         if (isset($this->libFiles[$addLib]['css'])){
1952                                                 $cssFiles = $this->libFiles[$addLib]['css'];
1953                                                 for ($m = 0; $m < count($cssFiles); $m++){
1954                                                         $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
1955                                                 }
1956                                         }
1957                                 }
1958                         }
1959                 } else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI) == 0){    // jQuery UI
1960                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1961                 //} else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI_PLUS) == 0){     // jQuery UI plus
1962                 //      $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1963                 //      $this->addScriptFile($this->selectedJQueryUiFilename);          // jQuery Coreスクリプト追加
1964                 } else if (strncmp($lib, 'jquery-ui.', 10) == 0 ||              // jQuery UIのwidgetsまたはeffectsのとき
1965                         strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){             // elFinder、timepickerを使用する場合
1966
1967                         // 依存ライブラリ追加
1968                         if (strncmp($lib, 'jquery-ui.', 10) == 0){
1969                                 $jQueryUiInfo = ScriptLibInfo::getJQueryUiInfo();// ライブラリ情報取得
1970                                 $dependentLib = $jQueryUiInfo[$lib];            // 依存ライブラリ取得
1971                         } else {
1972                                 $dependentLib = ScriptLibInfo::getDependentLib($lib);
1973                         }
1974                         for ($i = 0; $i < count($dependentLib); $i++){
1975                                 $addLib = $dependentLib[$i];
1976                                 
1977                                 // ライブラリのファイルを追加
1978                                 if (isset($this->libFiles[$addLib]['script'])){
1979                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1980                                         for ($m = 0; $m < count($scriptFiles); $m++){
1981                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1982                                         }
1983                                 }
1984                                 // ライブラリの言語ファイルを追加
1985                                 if (isset($this->libFiles[$addLib]['script_lang'])){
1986                                         $scriptFiles = ScriptLibInfo::getLangScript($addLib);;
1987                                         for ($m = 0; $m < count($scriptFiles); $m++){
1988                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1989                                         }
1990                                 }
1991                                 // ライブラリのCSSファイルを追加
1992                                 if (isset($this->libFiles[$addLib]['css'])){
1993                                         $cssFiles = $this->libFiles[$addLib]['css'];
1994                                         for ($m = 0; $m < count($cssFiles); $m++){
1995                                                 $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
1996                                         }
1997                                 }
1998                         }
1999                         // jQueryUIテーマを追加
2000                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
2001                                 $this->addCssFile($this->getDefaultThemeUrl());         // 通常機能用のCSS追加
2002                                 $this->outputTheme = true;
2003                         }
2004                 }
2005                 
2006                 // ライブラリ自体のファイルを追加
2007                 if (isset($this->libFiles[$lib]['script'])){
2008                         $scriptFiles = $this->libFiles[$lib]['script'];
2009                         
2010                         // ##### ライブラリ情報を作成する場合 #####
2011                         if (empty($scriptFiles)){
2012                                 $generatedLib = ScriptLibInfo::generateLib($lib);                       // ライブラリ取得
2013                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2014                         }
2015                         
2016                         for ($i = 0; $i < count($scriptFiles); $i++){
2017                                 $this->addScriptFile($scriptFiles[$i]);         // 通常機能用のスクリプト追加
2018                         }
2019                 }
2020                 // ライブラリの言語ファイルを追加
2021                 if (isset($this->libFiles[$lib]['script_lang'])){
2022                         $scriptFiles = ScriptLibInfo::getLangScript($lib);
2023                         for ($i = 0; $i < count($scriptFiles); $i++){
2024                                 $this->addScriptFile($scriptFiles[$i]);         // 通常機能用のスクリプト追加
2025                         }
2026                 }
2027                 // ライブラリのCSSファイルを追加
2028                 if (isset($this->libFiles[$lib]['css'])){
2029                         $cssFiles = $this->libFiles[$lib]['css'];
2030                         for ($i = 0; $i < count($cssFiles); $i++){
2031                                 $this->addCssFile($cssFiles[$i]);               // 通常機能用のCSS追加
2032                         }
2033                 }
2034         }
2035         /**
2036          * 非ログイン時の管理機能用のJavascriptファイル、CSSを追加する
2037          *
2038          * @param array, string         $lib            追加ライブラリID
2039          * @return                                      なし
2040          */
2041         function addPermittedAdminScript($lib)
2042         {
2043                 if (is_array($lib)){
2044                         for ($j = 0; $j < count($lib); $j++){
2045                                 $libId = $lib[$j];
2046                         
2047                                 // Javascript追加
2048                                 if (isset($this->libFiles[$libId]['script'])){
2049                                         $scriptFiles = $this->libFiles[$libId]['script'];
2050                                         
2051                                         // ##### ライブラリ情報を作成する場合 #####
2052                                         if (empty($scriptFiles)){
2053                                                 $generatedLib = ScriptLibInfo::generateLib($libId);                     // ライブラリ取得
2054                                                 if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2055                                         }
2056                         
2057                                         for ($i = 0; $i < count($scriptFiles); $i++){
2058                                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2059                                         }
2060                                 }
2061                                 // ライブラリの言語ファイルを追加
2062                                 if (isset($this->libFiles[$libId]['script_lang'])){
2063                                         $scriptFiles = ScriptLibInfo::getLangScript($libId);
2064                                         for ($i = 0; $i < count($scriptFiles); $i++){
2065                                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2066                                         }
2067                                 }
2068                                 // CSS追加
2069                                 if (isset($this->libFiles[$libId]['css'])){
2070                                         $cssFiles = $this->libFiles[$libId]['css'];
2071                                         for ($i = 0; $i < count($cssFiles); $i++){
2072                                                 $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
2073                                         }
2074                                 }
2075                         }
2076                 } else {
2077                         $libId = $lib;
2078                         
2079                         // Javascript追加
2080                         if (isset($this->libFiles[$libId]['script'])){
2081                                 $scriptFiles = $this->libFiles[$libId]['script'];
2082                                 
2083                                 // ##### ライブラリ情報を作成する場合 #####
2084                                 if (empty($scriptFiles)){
2085                                         $generatedLib = ScriptLibInfo::generateLib($libId);                     // ライブラリ取得
2086                                         if (!empty($generatedLib)) $scriptFiles = $generatedLib['script'];
2087                                 }
2088                         
2089                                 for ($i = 0; $i < count($scriptFiles); $i++){
2090                                         $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2091                                 }
2092                         }
2093                         // ライブラリの言語ファイルを追加
2094                         if (isset($this->libFiles[$libId]['script_lang'])){
2095                                 $scriptFiles = ScriptLibInfo::getLangScript($libId);
2096                                 for ($i = 0; $i < count($scriptFiles); $i++){
2097                                         $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
2098                                 }
2099                         }
2100                         // CSS追加
2101                         if (isset($this->libFiles[$libId]['css'])){
2102                                 $cssFiles = $this->libFiles[$libId]['css'];
2103                                 for ($i = 0; $i < count($cssFiles); $i++){
2104                                         $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
2105                                 }
2106                         }
2107                 }
2108         }
2109         /**
2110          * ページ作成終了
2111          *
2112          * ・最終HTML出力
2113          * ・セッション情報の保存
2114          * ・ウィジェットで生成されたHTTPヘッダを設定する
2115          *
2116          * @param RequestManager $request               HTTPリクエスト処理クラス
2117          * @param bool $getOutput                               出力を取得するかどうか
2118          * @return string                                       最終出力HTML
2119          */
2120         function endPage($request, $getOutput = false)
2121         {
2122                 global $gRequestManager;
2123                 global $gInstanceManager;
2124                 global $gEnvManager;
2125                 global $gDispManager;
2126                 global $gAccessManager;
2127                 
2128                 // ページ作成処理を中断するかどうか
2129                 if ($this->isAbort) return '';
2130                 
2131                 $contents = '';
2132                 
2133                 // 実行コマンドを取得
2134                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2135                 
2136                 // 最終HTML(ページ全体で使用するHTML)の出力
2137                 if ($cmd == M3_REQUEST_CMD_CSS){                // CSS生成のとき
2138                         // 外部出力形式でCSS出力
2139                         if (count($this->exportCss) > 0){
2140                                 for ($i = 0; $i < count($this->exportCss); $i++){
2141                                         $contents .= $this->exportCss[$i] . M3_NL;
2142                                 }
2143                         }
2144                         
2145                         // ヘッダ出力
2146                         header('Content-type: text/css');
2147                         
2148                         // 画面情報、ユーザ情報の保存は行わない
2149                         return $contents;
2150                 } else if ($cmd != M3_REQUEST_CMD_DO_WIDGET){           // ウィジェット単体オペレーションのときは出力しない
2151 /*                      if ($getOutput){
2152                                 $contents = $this->getLastContents($request);
2153                         } else {
2154                                 echo $this->getLastContents($request);
2155                         }*/
2156                 }
2157                 
2158                 // セッションへユーザ情報を保存
2159                 $userInfo = $gInstanceManager->getUserInfo();
2160                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
2161                 
2162                 // その他セッション情報保存
2163                 $gRequestManager->_doSessionCloseEventCallback();
2164                 
2165                 // 画面設定保存
2166                 $gDispManager->save();
2167                         
2168                 // キャッシュリミッタは、各リクエスト毎に(アウトプットバッファー が無効な場合は、
2169                 // session_start()がコールされる 前に) session_cache_limiter()をコールする必要がある。
2170                 // キャッシュを残す設定
2171 //              session_cache_limiter('private');
2172 //              session_cache_expire(5);
2173                 if ($this->isRedirect) return '';                       // リダイレクトの場合は終了
2174
2175                 // ########## HTTPヘッダ出力処理 ########
2176                 if (headers_sent($filename, $linenum)){         // HTTPヘッダが既に送信されているとき
2177                         echo "$filename の $linenum 行目でヘッダがすでに送信されています。";
2178                 } else {
2179                         // キャッシュを無効にする場合
2180                         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');// 過去の日付
2181                         header('Cache-Control: no-store, no-cache, must-revalidate');// HTTP/1.1
2182                         header('Cache-Control: post-check=0, pre-check=0', false);
2183                         header('Pragma: no-cache');
2184         
2185                         // 更新日時
2186                         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
2187         
2188                         // 文字コード設定
2189                         header('Content-Type: text/html; charset=UTF-8');                       // 2018/4/19 Firefoxで文字化けが起きる場合があるので追加
2190                         
2191                         // Ajax用JSON型データをHTTPヘッダに格納
2192                         $gInstanceManager->getAjaxManager()->header();
2193
2194                         // システム制御画面が設定されている場合はステータスコードを変更
2195                         if (!$this->isRedirect){                        // リダイレクトがセットされていない場合
2196                                 switch ($this->systemHandleMode){
2197                                         case 10:                        // サイト非公開(システムメンテナンス)
2198                                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
2199                                                 header('Status: 503 Service Temporarily Unavailable');
2200                                                 break;
2201                                         case 11:                        // アクセス禁止のとき
2202                                                 header('HTTP/1.1 403 Forbidden');
2203                                                 header('Status: 403 Forbidden');
2204                                                 break;
2205                                         case 12:                        // 存在しないページのとき
2206                                                 header("HTTP/1.1 404 Not Found");
2207                                                 header("Status: 404 Not Found");
2208                                                 break;
2209                                 }
2210                         }
2211                 }
2212                 // ##### 自動ログイン #####
2213                 $gAccessManager->endAutoLogin();
2214                 
2215                 return $contents;
2216         }
2217         /**
2218          * ページ作成処理中断
2219          *
2220          * 注意)exitSystem()でシステムを終了させる必要あり
2221          *
2222          * @return                                                      なし
2223          */
2224         function abortPage()
2225         {
2226                 global $gInstanceManager;
2227                 global $gRequestManager;
2228                 
2229                 // HTTPヘッダを削除(PHP 5.3以上で有効)
2230                 if (version_compare(PHP_VERSION, '5.3.0') >= 0) header_remove();
2231
2232                 // exit()等でabortPage()が最後の処理になってしまう可能性があるのでなるべく必要な処理を行う
2233                 //if (ob_get_level() > 0) ob_end_clean();// バッファ内容が残っているときは破棄
2234                 while (ob_get_level()) ob_end_clean();  // バッファ削除方法変更(2009/12/2)
2235                 
2236                 // セッションへユーザ情報を保存
2237                 $userInfo = $gInstanceManager->getUserInfo();
2238                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
2239                 
2240                 // その他セッション情報保存
2241                 $gRequestManager->_doSessionCloseEventCallback();
2242                 
2243                 $this->isAbort = true;                                  // ページ作成処理を中断するかどうか
2244         }
2245         /**
2246          * ウィジェット処理中断
2247          *
2248          * @return                                                      なし
2249          */
2250         function abortWidget()
2251         {
2252                 $this->isWidgetAbort = true;                                    // 各ウィジェット処理を中断するかどうか
2253         }
2254         /**
2255          * 強制終了を実行
2256          *
2257          * @return              なし
2258          */
2259         function exitSystem()
2260         {
2261                 global $gEnvManager;
2262                 global $gAccessManager;
2263                 
2264                 // DBが使用可能であれば、アクセスログのユーザを登録
2265                 if ($gEnvManager->canUseDb()) $gAccessManager->accessLogUser();
2266                 
2267                 exit();         // システム終了
2268         }
2269         /**
2270          * Joomla!v1.5タグを読み込んでウィジェット実行
2271          *
2272          * @param string        $srcBuf                 バッファデータ
2273          * @param int           $templateVer    テンプレートバージョン(99=レイアウト用テンプレート、0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
2274          * @return string                                       変換後文字列
2275          */
2276         function launchWidgetByJoomlaTag($srcBuf, $templateVer)
2277         {
2278                 $replace = array();
2279                 $matches = array();
2280                 $destBuf = $srcBuf;
2281                 
2282                 if (preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\s*\/>#iU', $srcBuf, $matches)){
2283                         $count = count($matches[1]);
2284                         for ($i = 0; $i < $count; $i++)
2285                         {
2286                                 $contents = '';
2287                                 $type  = $matches[1][$i];
2288                                 $attr = array();
2289                                 if (strcasecmp($type, 'head') == 0){            // ヘッダ埋め込みタグの場合
2290                                         ob_clean();
2291                                         $this->getHeader();
2292                                         $contents = ob_get_contents();
2293                                 } else if (strcasecmp($type, 'modules') == 0 || strcasecmp($type, 'module') == 0 ||             // 一般ウィジェット用配置ブロックの場合
2294                                                         strcasecmp($type, 'navmenu') == 0){                                                                                     // ナビゲーションメニューウィジェット用配置ブロックの場合
2295                                         $name = '';                     // ポジション名
2296                                         $posType = '';          // ポジションのタイプ
2297                                         $style = '';            // 表示スタイル
2298                                         $params = explode(' ', $matches[2][$i]);
2299                                         $paramArray = array();
2300                                         for ($j = 0; $j < count($params); $j++){
2301                                                 list($key, $value) = explode('=', $params[$j]);
2302                                                 $key = trim($key);
2303                                                 $value = trim($value, "\"'");
2304                                                 if (!empty($key)) $paramArray[$key] = $value;
2305                                         }
2306                                         $value = $paramArray['name'];
2307                                         if (isset($value)){
2308                                                 $name = $value;
2309                                                 $attr['name'] = $value;
2310                                         }
2311                                         $value = $paramArray['type'];           // 配置ブロックのタイプを属性に格納。テンプレート内での参照用。
2312                                         if (isset($value)){
2313                                                 $posType = $value;
2314                                                 $attr['type'] = $value;
2315                                         }
2316                                         $value = $paramArray['id'];
2317                                         if (isset($value)) $attr['id'] = $value;
2318                                         
2319                                         // スタイルが設定されている場合はオプションスタイルを取得
2320                                         $value = $paramArray['style'];
2321                                         if (isset($value)){
2322                                                 $style = $value;
2323                                                 $attr['style'] = $value;
2324                                                 
2325                                                 $optionStyle = $paramArray[$value];             // オプションのスタイル
2326                                                 if (isset($optionStyle)) $attr[$value] = $optionStyle;
2327                                         }
2328 /*                                      for ($j = 0; $j < count($params); $j++){
2329                                                 list($key, $value) = explode('=', $params[$j]);
2330                                                 if (strcasecmp($key, 'name') == 0){
2331                                                         $name = strtolower(trim($value, "\"'"));
2332                                                         $attr['name'] = $name;
2333                                                 } else if (strcasecmp($key, 'style') == 0){
2334                                                         // スタイルは大文字小文字の区別あり
2335                                                         $style = trim($value, "\"'");
2336                                                 } else if (strcasecmp($key, 'artstyle') == 0){          // テンプレート側指定の表示スタイル(Artisteer用)
2337                                                         $attr['artstyle'] = trim($value, "\"'");
2338                                                 } else if (strcasecmp($key, 'bootstyle') == 0){         // テンプレート側指定の表示スタイル(Bootstrap用)
2339                                                         $attr['bootstyle'] = trim($value, "\"'");
2340                                                 } else if (strcasecmp($key, 'drstyle') == 0){           // テンプレート側指定の表示スタイル(Themer用)
2341                                                         $attr['drstyle'] = trim($value, "\"'");
2342                                                 }
2343                                         }*/
2344
2345                                         if (!empty($name)){             // ポジション名が取得できたとき
2346                                                 // Joomla!では、テンプレートの「jdoc:include」タグの属性styleが空のときは「none」で処理される
2347                                                 // Joomla!デフォルトで設定可能なのは「none,table,horz,xhtml,rounded,outline」
2348                                                 // 配置ブロックがナビゲーション型に固定されていない場合はテンプレートの種類によってナビゲーションかどうかを判断
2349                                                 if (strcasecmp($type, 'navmenu') == 0){                                                                                 // メニューウィジェット用配置ブロックの場合
2350                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2351                                                         $attr['type'] = $type;                  // テンプレート内での参照用
2352                                                 } else {
2353                                                         switch ($templateVer){
2354                                                         case 0:                 // デフォルトテンプレート(Joomla!v1.0)
2355                                                         case 1:                 // Joomla!v1.5
2356                                                         case 2:                 // Joomla!v2.5
2357                                                         case 10:                // Bootstrap v3.0
2358                                                         default:
2359                                                                 if (strcasecmp($name, 'user3') == 0 ||          // ナビゲーションメニュー位置の場合
2360                                                                         strcasecmp($name, 'position-1') == 0 ||         // Joomla!v2.5テンプレート対応
2361                                                                         strcasecmp($posType, 'hmenu') == 0){            // Joomla!v3テンプレート対応
2362                                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2363                                                                 }
2364                                                                 break;
2365                                                         case 99:                // レイアウト用テンプレート
2366                                                                 global $gRequestManager;
2367                                                                 static $templateType;           // レイアウト用テンプレートタイプを一度だけ取得
2368                                                                 static $templateGenerator;
2369                                                                 
2370                                                                 if (!isset($templateType)){
2371                                                                         $templateType = 99;
2372                                                                         
2373                                                                         // レイアウト用テンプレートの場合は対象とするテンプレートの情報を取得して判断する
2374                                                                         $pageId         = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
2375                                                                         $pageSubId      = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
2376                                                                 
2377                                                                         // ページ用個別に設定されたテンプレートがある場合は取得
2378                                                                         $curTemplate = '';
2379                                                                         $line = $this->getPageInfo($pageId, $pageSubId);
2380                                                                         if (!empty($line)) $curTemplate = $line['pn_template_id'];
2381                                 
2382                                                                         // 取得できなければデフォルトを取得
2383                                                                         if (empty($curTemplate)){
2384                                                                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
2385                                                                                         $curTemplate = $this->gSystem->defaultTemplateId();
2386                                                                                 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
2387                                                                                         $curTemplate = $this->gSystem->defaultSmartphoneTemplateId();           // スマートフォン用デフォルトテンプレート
2388                                                                                 }
2389                                                                         }
2390                                                                         
2391                                                                         // テンプレートのタイプを取得
2392                                                                         $ret = $this->db->getTemplate($curTemplate, $row);
2393                                                                         if ($ret){
2394                                                                                 $templateType = $row['tm_type'];
2395                                                                                 $templateGenerator = $row['tm_generator'];
2396                                                                         }
2397                                                                 }
2398                                                                 
2399                                                                 if ($templateType != 99){
2400                                                                         // Themlerテンプレート場合は配置ポジション名が「hmenu」をナビゲーション型とする
2401                                                                         if ($templateGenerator == 'themler'){
2402                                                                                 if (strcasecmp($name, 'hmenu') == 0){           // Joomla!v3テンプレート対応
2403                                                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2404                                                                                 }
2405                                                                         } else {
2406                                                                                 if (strcasecmp($name, 'user3') == 0 ||          // ナビゲーションメニュー位置の場合
2407                                                                                         strcasecmp($name, 'position-1') == 0){          // Joomla!v2.5テンプレート対応
2408                                                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
2409                                                                                 }
2410                                                                         }
2411                                                                 }
2412                                                                 break;
2413                                                         }
2414                                                 }
2415                                                 if (empty($style)) $style = 'none';
2416                                                 
2417                                                 // ウィジェットの出力を取得
2418                                                 $contents = $this->getContents($name, $style, $templateVer, $attr);
2419                                         }
2420                                 } else if (strcasecmp($type, 'component') == 0){        // メインポジションタグの場合
2421                                         // スタイルを取得
2422                                         $style = '';            // 表示スタイル
2423                                         $params = explode(' ', $matches[2][$i]);
2424                                         for ($j = 0; $j < count($params); $j++){
2425                                                 list($key, $value) = explode('=', $params[$j]);
2426                                                 if (strcasecmp($key, 'style') == 0){
2427                                                         // スタイルは大文字小文字の区別あり
2428                                                         $style = trim($value, "\"'");
2429                                                         break;
2430                                                 }
2431                                         }
2432                                         if ($style != 'none') $style = 'xhtml';
2433                                         $contents = $this->getContents('main', $style, $templateVer, $attr);
2434                                 } else if (strcasecmp($type, 'message') == 0){  // メッセージタグの場合
2435                                 }
2436                                 $replace[$i] = $contents;
2437                         }
2438                         ob_clean();
2439                         $destBuf = str_replace($matches[0], $replace, $srcBuf);
2440                 }
2441                 return $destBuf;
2442         }
2443         /**
2444          * 遅延ウィジェット実行
2445          *
2446          * 遅延実行インデックスのついているウィジェットをインデックス順に実行し、出力バッファデータ内のタグの位置に出力を埋め込む
2447          *
2448          * @param RequestManager $request               HTTPリクエスト処理クラス
2449          * @param string         $srcBuf                バッファデータ
2450          * @return string                                               変換後文字列
2451          */
2452         function lateLaunchWidget($request, $srcBuf)
2453         {
2454                 static $render;         // HTML生成オブジェクト
2455                 global $gEnvManager;
2456                 global $gErrorManager;
2457                 global $gDesignManager;
2458                 
2459                 // ページ作成中断またはウィジェット処理中断のときは終了
2460                 if ($this->isAbort || $this->isWidgetAbort) return '';
2461                 
2462                 // ウィジェットヘッダ(Joomla!1.0用)を出力のタイプを取得
2463                 $widgetHeaderType = $this->getTemplateWidgetHeaderType();
2464                 
2465                 // テンプレートタイプ取得
2466                 $templateVer = $gEnvManager->getCurrentTemplateType();
2467                 
2468                 // 遅延実行ウィジェットをインデックス順にソート
2469                 asort($this->lateLaunchWidgetList, SORT_NUMERIC);
2470                 
2471                 // タグを置換
2472                 $destBuf = $srcBuf;
2473                 foreach ($this->lateLaunchWidgetList as $widgetId => $value){
2474                         // 実行パラメータ取得
2475                         $count = count($this->latelaunchWidgetParam);
2476                         for ($i = 0; $i < $count; $i++){
2477                                 list($wId, $maxNo, $confId, $preId, $serial, $style, $cssStyle, $title, $shared, $exportCss, $position, $index, $pageDefRec) = $this->latelaunchWidgetParam[$i];
2478                                 if ($wId == $widgetId){
2479                                         // パラメータ初期化
2480                                         $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
2481                                         $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
2482                                         $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
2483                                         
2484                                         // 現在のウィジェットのポジション
2485                                         $this->currentWidgetPosition = $position;                       // 現在のウィジェットのポジション
2486                                         $this->currentWidgetIndex = $index;                     // 現在のウィジェットのポジション番号
2487         
2488                                         // バッファ作成
2489                                         ob_start();
2490
2491                                         // ウィジェット実行ファイル取得
2492                                         $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
2493
2494                                         // その他パラメータ取得
2495                                         $configId = $confId;            // ウィジェット定義ID
2496                                         if ($configId == 0) $configId = '';
2497                                         $prefix = $preId;               // サフィックス文字列
2498                         
2499                                         // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
2500                                         $joomlaTitleVisble = false;
2501                                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
2502                                                 if (!empty($title)){
2503                                                         if ($widgetHeaderType == 1){            // PC用ウィジェットヘッダ出力
2504                                                                 echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
2505                                                                 echo '<tr><th>' . $title . '</th></tr>' . M3_NL;
2506                                                                 echo '<tr><td>' . M3_NL;
2507                                                                 $joomlaTitleVisble = true;
2508                                                         } else if ($widgetHeaderType == 2){                     // 携帯用ウィジェットヘッダ出力
2509                                                                 echo '<div>' . $title . '</div>' . M3_NL;
2510                                                                 $joomlaTitleVisble = true;
2511                                                         }
2512                                                 }
2513                                         }
2514                                         // ウィジェットの外枠タグを設定
2515                                         //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
2516                                         // ウィジェット親のCSS定義があるときは、タグを追加
2517                                         if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
2518                                         
2519                                         // ウィジェットの前出力
2520                                         echo $gDesignManager->getAdditionalWidgetOutput(true);
2521                                 
2522                                         // 作業中のウィジェットIDを設定
2523                                         $gEnvManager->setCurrentWidgetId($widgetId);
2524
2525                                         // ウィジェット定義IDを設定
2526                                         $gEnvManager->setCurrentWidgetConfigId($configId);
2527                                         
2528                                         // ページ定義のシリアル番号を設定
2529                                         $gEnvManager->setCurrentPageDefSerial($serial);
2530                 
2531                                         // ページ定義レコードを設定
2532                                         $gEnvManager->setCurrentPageDefRec($pageDefRec);
2533                                 
2534                                         // パラメータを設定
2535                                         $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
2536                 
2537                                         // ウィジェットのタイトルを設定
2538                                         $gEnvManager->setCurrentWidgetTitle('');
2539                                         
2540                                         // ウィジェットのスタイルを設定
2541                                         $gEnvManager->setCurrentWidgetStyle($style);
2542                                 
2543                                         // ウィジェットのグローバル属性状況を設定
2544                                         $gEnvManager->setIsCurrentWidgetShared($shared);
2545                                 
2546                                         // 実行ログを残す
2547                                         $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
2548                                         
2549                                         // ウィジェットを実行
2550                                         // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
2551                                         $msg = 'widget-start(' . $widgetId . ')';
2552                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
2553                                         require($widgetIndexFile);
2554                                         $msg = 'widget-end(' . $widgetId . ')';
2555                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
2556
2557                                         // 作業中のウィジェットIDを解除
2558                                         $gEnvManager->setCurrentWidgetId('');
2559                 
2560                                         // ウィジェット定義IDを解除
2561                                         $gEnvManager->setCurrentWidgetConfigId('');
2562                                         
2563                                         // ページ定義のシリアル番号を解除
2564                                         $gEnvManager->setCurrentPageDefSerial(0);
2565                 
2566                                         // ページ定義レコードを解除
2567                                         $gEnvManager->setCurrentPageDefRec();
2568                                         
2569                                         // パラメータを解除
2570                                         $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
2571                                         
2572                                         // ウィジェットのスタイルを解除
2573                                         $gEnvManager->setCurrentWidgetStyle('');
2574                                         
2575                                         // ウィジェットのグローバル属性状況を解除
2576                                         $gEnvManager->setIsCurrentWidgetShared(false);
2577                                         
2578                                         // ウィジェットのタイトルを取得
2579                                         $newTitle = $gEnvManager->getCurrentWidgetTitle();
2580
2581                                         // ウィジェットの後出力
2582                                         echo $gDesignManager->getAdditionalWidgetOutput(false);
2583                                 
2584                                         // ウィジェット親のCSS定義があるときは、タグを追加
2585                                         if (!empty($cssStyle)) echo '</div>' . M3_NL;
2586                                         // ウィジェットの外枠タグを設定
2587                                         //echo '</div>' . M3_NL;
2588                                         
2589                                         // Joomla!1.0テンプレートのときはタイトルを出力
2590                                         if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用ウィジェットヘッダ出力
2591                                                 echo '</td></tr>' . M3_NL;
2592                                                 echo '</table>' . M3_NL;
2593                                         }
2594                                         
2595                                         // 現在のバッファ内容を取得し、バッファを破棄
2596                                         $srcContents = ob_get_contents();
2597                                         ob_end_clean();
2598                                         
2599                                         // ### テンプレート側のウィジェット生成処理使える場合はウィジェットの出力と入れ替える ###
2600                                         // ### 先のrequire($widgetIndexFile)で必要なデータは作成されている                    ###
2601                                         if ($templateVer >= 1 && $templateVer < 100){           // Joomla!v1.5,v2.5テンプレートのとき
2602                                                 $widgetType = $pageDefRec['wd_type'];           // ウィジェットタイプ
2603                                                 if ($widgetType == 'breadcrumb'){               // パンくずリスト
2604                                                         // 描画オブジェクト作成
2605                                                         if (!isset($render)) $render = new JRender();
2606
2607                                                         $templateContents = $render->getBreadcrumbContents('', '', '', array(), array(), $pageDefRec, $templateVer);                    // テンプレートバージョンのみ必要
2608                                                         if (!empty($templateContents)) $srcContents = $templateContents;
2609                                                 }
2610                                         }
2611
2612                                         // ウィジェットの出力を取得
2613                                         $tag = self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;
2614                                         $destBuf = str_replace($tag, $srcContents, $destBuf);
2615                                         
2616                                         // タイトルの出力
2617                                         if (!empty($newTitle)) $title = $newTitle;
2618                                         $tag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
2619                                         $destBuf = str_replace($tag, $title, $destBuf);
2620                                         
2621                                         // ##### 外部出力用のCSSがある場合は追加 #####
2622                                         if (!empty($exportCss)){
2623                                                 // ウィジェットのタグIDを変換
2624                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $index;                          // ウィジェット識別用ユニークタグ
2625                                                 $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
2626                                                 $this->addExportCss($exportCss);
2627                                         }
2628                                 }
2629                         }
2630                 }
2631                 
2632                 // ##### HTMLヘッダ出力処理 #####
2633                 $destBuf = $this->replaceHead($destBuf);
2634                 
2635                 return $destBuf;
2636         }
2637         /**
2638          * ジョブ実行
2639          *
2640          * @param string $jobType               ジョブタイプ
2641          * @return                                              なし
2642          */
2643         function launchJob($jobType)
2644         {
2645                 global $gEnvManager;
2646                 
2647                 // ジョブタイプから実行するウィジェットIDを取得
2648                 $widgetId = $this->getWidgetIdByJobType($jobType);
2649                 if (empty($widgetId)) return;
2650
2651                 // 作業中のウィジェットIDを設定
2652                 $gEnvManager->setCurrentWidgetId($widgetId);
2653                         
2654                 // 指定のウィジェットを実行
2655                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/admin/job.php';
2656                         
2657                 if (file_exists($widgetIndexFile)){
2658 //                      // 実行のログを残す
2659 //                      $this->_db->writeWidgetLog($widgetId, 1/*単体実行*/, $cmd);
2660
2661                         require_once($widgetIndexFile);
2662                 } else {
2663                         echo 'file not found: ' . $widgetIndexFile;
2664                 }
2665                                 
2666                 // 作業中のウィジェットIDを解除
2667                 $gEnvManager->setCurrentWidgetId();
2668         }
2669         /**
2670          * ヘッダ部マクロ変換処理
2671          *
2672          * @param string         $srcBuf                変換元
2673          * @return string                                               変換後文字列
2674          */
2675         function replaceHead($srcBuf)
2676         {
2677                 $destBuf = $srcBuf;
2678
2679                 // ##### ヘッダ部分の置換 #####
2680                 if ($this->outputHead){                         // HTMLヘッダ出力を行っているとき
2681                         $replaceStr = '';
2682                         
2683                         // HTMLヘッダに最初に出力するタグ文字列がある場合は追加
2684                         if (!empty($this->headFirstTag)) $replaceStr .= $this->headFirstTag;
2685                         
2686                         // METAタグcharset等のHTML文書の標準のヘッダタグを出力
2687                         if ($this->outputByStandardHead) $replaceStr .= $this->getStandardHead();
2688                 
2689                         // タグ変換用文字列の取得
2690                         $replaceStr .= $this->getHeaderOutput();
2691                         
2692                         // HTMLヘッダのデータ埋め込み
2693                         $destBuf = str_replace(self::HEAD_TAGS, $replaceStr, $destBuf);
2694                 }
2695                 $this->replaceHeadDone = true;                  // ヘッダマクロ変換処理が完了したかどうか
2696                 return $destBuf;
2697         }
2698         /**
2699          * ヘッダ部マクロ変換を有効にする
2700          *
2701          * @return                                      なし
2702          */
2703         function enableReplaceHead()
2704         {
2705                 $this->outputHead = true;
2706         }
2707         /**
2708          * ウィジェット検索モードの場合のページサブIDの設定
2709          *
2710          * @param RequestManager $request               HTTPリクエスト処理クラス
2711          */
2712         function redirectToUpdatedPageSubId($request)
2713         {
2714                 global $gEnvManager;
2715                 
2716                 // 現在設定されているページIDを取得
2717                 $pageId         = $gEnvManager->getCurrentPageId();
2718                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2719                 
2720                 // 送信元のウィジェットIDを取得
2721                 $fromWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_FROM);
2722                 
2723                 // 対象のウィジェットIDを取得
2724                 $targetWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
2725                 
2726                 // 対象のウィジェットのページサブIDを取得
2727                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2728                 if ($ret){// データが存在する
2729                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2730                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2731                                 if ($ret){// データが存在する
2732                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2733                                         } else {
2734                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2735                                         }
2736                                 }
2737                         } else {
2738                                 // 送信元があるか順にチェック
2739                                 for ($i = 0; $i < count($rows); $i++){
2740                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2741                                         if ($ret){      
2742                                                 break;
2743                                         }
2744                                 }
2745                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2746                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2747                                 } else {
2748                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2749                                 }
2750                         }
2751                 } else {                // 対象のウィジェットが見つからない場合は、互換ウィジェットを探す
2752                         $widgetId = $this->db->getCompatibleWidgetId($targetWidgetId);
2753                         if (!empty($widgetId)){
2754                                 $targetWidgetId = $widgetId;
2755                                 
2756                                 // 対象のウィジェットのページサブIDを取得
2757                                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2758                                 if ($ret){// データが存在する
2759                                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2760                                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2761                                                 if ($ret){// データが存在する
2762                                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2763                                                         } else {
2764                                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2765                                                         }
2766                                                 }
2767                                         } else {
2768                                                 // 送信元があるか順にチェック
2769                                                 for ($i = 0; $i < count($rows); $i++){
2770                                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2771                                                         if ($ret){      
2772                                                                 break;
2773                                                         }
2774                                                 }
2775                                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2776                                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2777                                                 } else {
2778                                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2779                                                 }
2780                                         }
2781                                 }
2782                         }
2783                 }
2784                 // ページサブIDが見つからないときは、既に設定されている値を使用
2785                 // 既に設定されている値は、URL「sub」パラメータで指定されている値か
2786                 // 設定されていない場合はデフォルトのサブページID
2787                 // ********** 指定ページへリダイレクト ***********
2788                 // 実行パラメータ取得
2789                 $todo = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TODO);
2790                 $todo = str_replace(M3_TODO_SEPARATOR, '&', $todo);             // セパレータを変換
2791 //              $redirectUrl = '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2792                 $redirectUrl = $gEnvManager->createPageUrl() . '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2793                 if (!empty($todo)) $redirectUrl .= '&' . $todo;
2794                 $this->redirect($redirectUrl);
2795         }
2796         /**
2797          * 最終HTML出力処理
2798          *
2799          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2800          * 追加するHTMLは主にウィンドウ制御用のスクリプト
2801          *
2802          * @return string                                       最終HTML
2803          */
2804         function getLastContents()
2805         {
2806                 global $gEnvManager;
2807                 global $gRequestManager;
2808                 
2809                 $contents = '';
2810                 $initScript = '';               // 初期化用スクリプト
2811                 $pageId         = $gEnvManager->getCurrentPageId();
2812                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2813                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2814                 
2815                 if (!$gEnvManager->isSystemManageUser()) return '';             // システム運用権限がない場合は終了
2816                 
2817                 // 処理を行わない場合は終了
2818                 if ($cmd == M3_REQUEST_CMD_RSS ||                                               // RSS配信のときは終了
2819                         $cmd == M3_REQUEST_CMD_DO_WIDGET) return '';            // ウィジェット単体オペレーションのときは出力しない
2820                 
2821                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2822                         // ウィジェットレイアウト用カーソル
2823                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
2824 /*                              // テンプレート上のポジション名
2825                                 if (count($this->viewPosId) > 0){
2826                                         $posArrayStr = '[';
2827                                         for ($i = 0; $i < count($this->viewPosId); $i++){
2828                                                 $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
2829                                                 if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
2830                                         }
2831                                         $posArrayStr .= ']';
2832                                         $contents .= 'var M3_POSITIONS=' . $posArrayStr . ';' . M3_NL;
2833                                 }
2834                                 // 画面定義のリビジョン番号
2835                                 $contents .= 'var M3_REVISION=' . $this->pageDefRev . ';' . M3_NL;*/
2836                 
2837                                 // 更新用関数追加
2838                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2839                                 $contents .= M3_INDENT_SPACE . 'window.m3.m3UpdateByConfig(serial);' . M3_NL;
2840                                 $contents .= '}' . M3_NL;
2841                         } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){                       // ウィジェット設定画面
2842                         } else {                // ダッシュボード画面、メイン管理画面
2843                                 // 画面更新用関数追加
2844                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2845                                 $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2846                                 $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2847                                 $contents .= '}' . M3_NL;
2848                         }
2849                         
2850                         // ウィジェット単体実行以外のときの処理
2851                         if (!$this->showWidget){
2852                                 if ($this->updateParentWindow){                 // 管理画面からの親画面の更新
2853                                         $initScript .= M3_INDENT_SPACE . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
2854                                 }
2855                         }
2856                 } else {                // 通常画面のとき
2857                         // 画面更新用関数追加
2858                         $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2859                         $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2860                         $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2861                         $contents .= '}' . M3_NL;
2862                 }
2863
2864                 $destContents = '';
2865                 if (!empty($contents) || !empty($initScript)){
2866 //                      $destContents .= '<script type="text/javascript">' . M3_NL;
2867 //                      $destContents .= '//<![CDATA[' . M3_NL;
2868                         $destContents .= $contents;
2869                         if (!empty($initScript)){               // 初期化用スクリプト
2870                                 $destContents .= '$(function(){' . M3_NL;
2871                                 $destContents .= $initScript;
2872                                 $destContents .= '});' . M3_NL;
2873                         }
2874 //                      $destContents .= '//]]>' . M3_NL;
2875 //                      $destContents .= '</script>' . M3_NL;
2876                 }
2877                 return $destContents;
2878         }
2879         /**
2880          * オプションHTML出力処理
2881          *
2882          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2883          *
2884          * @param RequestManager $request               HTTPリクエスト処理クラス
2885          * @return string                                       最終HTML
2886          */
2887         function getOptionContents($request)
2888         {
2889                 global $gEnvManager;
2890                 
2891                 $contents = '';
2892                 
2893                 // ページ作成中断のときは終了
2894                 if ($this->isAbort) return '';
2895                 
2896                 // AJAX用のレスポンスボディデータのときは終了
2897                 if ($this->outputAjaxResponseBody) return '';
2898                 
2899                 // ウィジェット処理中断のとき
2900                 // AJAXを送信する場合は空文字列では送信できないので、ダミーデータを返す
2901                 if ($this->isWidgetAbort) $contents .= 'NO DATA' . M3_NL;
2902                 
2903                 // Magic3出力コメント
2904                 if ($this->outputByHtml){               // HTML出力のとき
2905                         $contents .= '<!-- created by ' . M3_SYSTEM_NAME . ' v' . M3_SYSTEM_VERSION . ' - http://www.magic3.org -->' . M3_NL;
2906                         $contents .= '<!-- convert time: ' . sprintf('%01.03f', microtime(true) - M3_MTIME) . ' -->' . M3_NL;
2907                 }
2908                 return $contents;
2909         }
2910         /**
2911          * Widget単体起動用のHTMLのヘッダ部(headタグ)出力
2912          *
2913          * startWidget(),endWidget()は、以下のコマンドを処理する
2914          *  ・M3_REQUEST_CMD_SHOW_WIDGET(ウィジェットの単体表示)
2915          *  ・M3_REQUEST_CMD_CONFIG_WIDGET(ウィジェット設定画面)
2916          *  ・M3_REQUEST_CMD_CONFIG_TEMPLATE(テンプレート設定画面)
2917          *  ・M3_REQUEST_CMD_DO_WIDGET(ウィジェット単体実行)
2918          * Widgetの出力方法は、以下のパターンがある
2919          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
2920          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
2921          *
2922          * @param string $cmd           起動コマンド
2923          */
2924         function startWidget($cmd)
2925         {
2926                 global $gEnvManager;
2927                 global $gRequestManager;
2928
2929                 // ウィジェット単体表示のときのみ出力
2930                 if (!$this->showWidget) return;
2931
2932                 // パラメータ取得
2933                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
2934                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
2935
2936                 $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
2937                 if (intval($tempVer) >= 2) $this->isHtml5 = true;               // HTML5で出力するかどうか                             
2938                 
2939                 // DOCTYPEの設定
2940                 if ($this->isHtml5){
2941                         echo '<!DOCTYPE html>' . M3_NL;
2942                         echo '<html dir="ltr" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
2943                         echo '<head>' . M3_NL;
2944                 } else {
2945                         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . M3_NL;
2946                         echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $gEnvManager->getCurrentLanguage() . '" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
2947                         echo '<head>' . M3_NL;
2948 //                      echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . M3_NL;
2949                 }
2950
2951                 // HTMLのヘッダ部(headタグ内)出力
2952                 $this->getHeader();
2953
2954                 // ##### 作成対象がウィジェットの場合とテンプレートの場合に分ける #####
2955                 if ($cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){                    // テンプレート設定画面の場合
2956                         $templateId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_TEMPLATE_ID);// テンプレートID
2957                 } else {
2958                         // 現在のウィジェットを取得
2959                         $widgetId = $gEnvManager->getCurrentWidgetId();         // カレントのウィジェットID
2960                 }
2961                 
2962                 // URLを作成
2963                 if ($gEnvManager->getUseSslAdmin()){
2964                         $rootUrl = $gEnvManager->getSslRootUrl();
2965                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
2966                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
2967                 } else {
2968                         $rootUrl = $gEnvManager->getRootUrl();
2969                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
2970                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
2971                 }
2972
2973                 // ##### テンプレートのCSSの読み込み #####
2974                 // テンプレートは管理用テンプレートに固定されている
2975                 //if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET ||           // ウィジェット設定のとき
2976                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                           // ウィジェット設定画面またはテンプレート設定画面のとき
2977                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy) && $gEnvManager->isContentEditableUser())){        // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
2978                         $curTemplateUrl = $templatesUrl . '/' . $gEnvManager->getCurrentTemplateId();
2979                         if ($this->isHtml5){
2980                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/style.css" media="screen">' . M3_NL;
2981                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/widget.css" media="screen">' . M3_NL;            // ウィジェット設定画面用CSS
2982                         echo '<!--[if IE]><link rel="stylesheet" href="' . $curTemplateUrl . '/css/iestyles.css" media="screen"><![endif]-->' . M3_NL;
2983                                 echo '<!--[if lt IE 9]><script src="' . $curTemplateUrl . '/html5shiv.js"></script><![endif]-->' . M3_NL;
2984                         } else {
2985                                 echo '<link href="' . $curTemplateUrl . '/css/style.css" rel="stylesheet" type="text/css" />' . M3_NL;
2986                                 echo '<!--[if IE]><link rel="stylesheet" type="text/css" media="screen" href="' . $curTemplateUrl . '/css/iestyles.css" /><![endif]-->' . M3_NL;
2987                         }
2988                 }
2989                 // ウィジェット情報取得
2990                 $ret = $this->db->getWidgetInfo($widgetId, $row);
2991
2992                 // ##### 共通ライブラリ読み込み設定 #####
2993                 if ($cmd == M3_REQUEST_CMD_DO_WIDGET){          // ウィジェット単体実行のとき
2994                         $scritLib = trim($row['wd_add_script_lib']);
2995                         if (!empty($scritLib)) $this->addScript($task, $scritLib);
2996                 }
2997                                 
2998                 // CSS読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
2999                 if ($row['wd_read_css']){
3000                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_CSS;
3001                         if (is_dir($searchPath)){
3002                                 $dir = dir($searchPath);
3003                                 while (($file = $dir->read()) !== false){
3004                                         $filePath = $searchPath . '/' . $file;
3005                                         if ($file != '.' && $file != '..' && is_file($filePath)
3006                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3007                                                 
3008                                                 // CSSへのURLを作成
3009                                                 $cssURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_CSS . '/' . $file;
3010                                                 echo '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3011                                         }
3012                                 }
3013                                 $dir->close();
3014                         }
3015                 }
3016                 
3017                 // スクリプト読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
3018                 if ($row['wd_read_scripts']){
3019                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS;
3020                         if (is_dir($searchPath)){
3021                                 $dir = dir($searchPath);
3022                                 while (($file = $dir->read()) !== false){
3023                                         $filePath = $searchPath . '/' . $file;
3024                                         if ($file != '.' && $file != '..' && is_file($filePath)
3025                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3026                                                 
3027                                                 // スクリプトへのURLを作成
3028                                                 $scriptURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
3029                                                 
3030                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3031                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3032                                                 echo '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3033                                         }
3034                                 }
3035                                 $dir->close();
3036                         }
3037                 }
3038                 // ##### スクリプト用出力用タグを埋め込む #####
3039                 // ウィジェット設定画面用メニューバーの作成
3040                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                           // ウィジェット設定画面またはテンプレート設定画面のとき
3041                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){       // ウィジェット設定画面またはフロント画面編集モードのとき
3042                         echo self::MENUBAR_SCRIPT_TAGS;                 // メニューバー出力用タグ
3043                 }
3044                 
3045                 // ##### 作成対象がウィジェットの場合とテンプレートの場合に分ける #####
3046                 // ウィジェットのタイトルを設定
3047                 if ($cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){                    // テンプレート設定画面の場合
3048                         $title = self::WIDGET_TITLE_START . 'テンプレート' . self::WIDGET_TITLE_END . ' ' . $templateId;
3049                         $gEnvManager->setCurrentWidgetTitle($title);
3050                         echo '<title>' . htmlspecialchars($title) . '</title>' . M3_NL;
3051                 } else {
3052                         $title = $row['wd_name'];
3053                         if (empty($title)) $title = $row['wd_id'];
3054                         $gEnvManager->setCurrentWidgetTitle($title);
3055                         echo '<title>' . self::WIDGET_TITLE_START . htmlspecialchars($title) . self::WIDGET_TITLE_END . '</title>' . M3_NL;
3056                 }
3057                 echo '</head>' . M3_NL;
3058                 
3059                 // タブでウィンドウを開く場合は背景を透過モードにする
3060                 if ($this->isTransparentMode){
3061                         echo '<body style="background-color:transparent;">' . M3_NL;
3062                 } else {
3063                         echo '<body>' . M3_NL;
3064                 }
3065                 // ウィジェット設定画面用メニューバーの作成
3066                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                           // ウィジェット設定画面またはテンプレート設定画面のとき
3067                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){       // ウィジェット設定画面またはフロント画面編集モードのとき
3068                         // ウィジェット情報を設定
3069                         $desc = $row['wd_description'];         // 説明
3070                         $gEnvManager->setCurrentWidgetParams('desc', $desc);
3071                         
3072                         echo self::MENUBAR_TAGS;                        // メニューバー出力用タグ
3073                 }
3074                 // Bootstrap用のタグ出力
3075                 if ($this->useBootstrap) echo '<div class="container">' . M3_NL;
3076                 
3077                 // 別ウィンドウで表示のときは、「閉じる」ボタンを表示
3078                 if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET ||               // ウィジェットの単体表示のとき
3079                         $cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                               // ウィジェット設定画面またはテンプレート設定画面のとき
3080                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){               // ウィジェット単体実行でフロント画面編集モードのとき
3081
3082 //                      if ($this->isEditMode){// フロント画面編集モードのとき
3083                                 if (!empty($openBy)){
3084                                         // サーバ指定されている場合はサーバ情報を取得
3085                                         $serverName = '';
3086                                         $server = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_SERVER);
3087                                         if (!empty($server)){
3088                                                 // 設定データを取得
3089                                                 $ret = $this->db->getServerById($server, $row);
3090                                                 if ($ret){
3091                                                         $serverName = 'サーバ名:' . $row['ts_name'];// サーバ名
3092                                                         echo '<div align="left" style="float:left;padding-left:30px;"><label>' . convertToHtmlEntity($serverName) . '</label></div>';
3093                                                 }
3094                                         }
3095                                         // タブ、インナーフレーム、ダイアログ表示以外のときは「閉じる」ボタンを表示
3096                                         if ($openBy != 'tabs' && $openBy != 'iframe' && $openBy != 'dialog'){           // 以外
3097                                                 if ($openBy == 'logout'){
3098                                                         $titleStr = 'ログアウト';
3099                                                         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 . 
3100                                                                                 '" alt="' . $titleStr . '" /></a></div>' . M3_NL;
3101                                                 } else {
3102                                                         $titleStr = '閉じる';
3103                                                         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 . 
3104                                                                                 '" alt="' . $titleStr . '" /></a></div>' . M3_NL;
3105                                                 }
3106                                         }
3107                                 }
3108                                 // 「前へ」「次へ」ボタン
3109                                 $titleStr = '前へ';
3110                                 echo '<div class="m3configprev" style="display:none;"><a id="m3configprev" href="#"><img src="' . $rootUrl . self::PREV_ICON_FILE . 
3111                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" rel="m3help" /></a></div>' . M3_NL;
3112                                 $titleStr = '次へ';
3113                                 echo '<div class="m3confignext" style="display:none;"><a id="m3confignext" href="#"><img src="' . $rootUrl . self::NEXT_ICON_FILE . 
3114                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" rel="m3help" /></a></div>' . M3_NL;
3115 //                      }
3116                 }
3117                 echo '<!-- Widget Start -->' . M3_NL;
3118         }
3119         /**
3120          * Widget単体起動の終了処理
3121          *
3122          * startWidget(),endWidget()は、以下のコマンドを処理する
3123          *  ・M3_REQUEST_CMD_SHOW_WIDGET(ウィジェットの単体表示)
3124          *  ・M3_REQUEST_CMD_CONFIG_WIDGET(ウィジェット設定画面)
3125          *  ・M3_REQUEST_CMD_CONFIG_TEMPLATE(テンプレート設定画面)
3126          *  ・M3_REQUEST_CMD_DO_WIDGET(ウィジェット単体実行)
3127          *
3128          * @param string $cmd                   起動コマンド
3129          * @param string $srcContent    HTML出力ソース
3130          */
3131         function endWidget($cmd, $srcContent)
3132         {
3133                 global $gDesignManager;
3134                 
3135                 // ウィジェット単体表示のときのみ出力
3136                 if (!$this->showWidget) return;
3137                 
3138                 // メニューバー出力
3139                 // パンくずリストを表示
3140                 $breadcrumbHtml = '';
3141                 if (!empty($this->adminSubNavbarDef)) $breadcrumbHtml .= $gDesignManager->createSubMenubar($this->adminSubNavbarDef);
3142                 if (!empty($this->adminBreadcrumbDef)) $breadcrumbHtml .= $gDesignManager->createAdminBreadcrumb($this->adminBreadcrumbDef);
3143                 $destContent = str_replace(self::MENUBAR_TAGS, $breadcrumbHtml, $srcContent);
3144
3145                 // ヘッドタグ出力
3146                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
3147                 $replaceStr .= '//<![CDATA[' . M3_NL;
3148                 
3149                 // ##### 追加関数 #####
3150                 // ウィジェット設定画面用
3151                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェットの設定管理
3152                         // 画面更新用関数追加
3153                         $replaceStr .= 'function m3UpdateByConfig(serial){' . M3_NL;
3154                         $replaceStr .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
3155                         $replaceStr .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
3156                         $replaceStr .= M3_INDENT_SPACE . 'm3UpdateParentWindow();' . M3_NL;             // 親ウィンドウ更新
3157                         $replaceStr .= '}' . M3_NL;
3158                 
3159                         // IEエラーメッセージ出力抑止
3160                         $replaceStr .= 'function hideIEErrors(){' . M3_NL;
3161                         $replaceStr .= M3_INDENT_SPACE . 'return true;' . M3_NL;
3162                         $replaceStr .= '}' . M3_NL;
3163                         $replaceStr .= 'window.onerror = hideIEErrors;' . M3_NL;
3164                 }
3165                 
3166                 // ##### 初期処理 #####
3167                 $replaceStr .= '$(function(){' . M3_NL;
3168                 // トップ位置修正
3169                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE ||                                           // ウィジェット設定画面またはテンプレート設定画面のとき
3170                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && $this->isEditMode)){               // フロント画面編集モードのとき
3171                         if (!empty($this->adminSubNavbarDef) || !empty($this->adminBreadcrumbDef)){
3172                                 $menubarHeight = $gDesignManager->getSubMenubarHeight();
3173                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . '$("nav.secondlevel").css("margin-top", "0");' . M3_NL;
3174                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . '$("body").css("padding-top", "' . $menubarHeight . 'px");' . M3_NL;
3175                         }
3176                 }
3177                 // ##### ウィジェットからの指定による処理 #####
3178                 if ($this->updateParentWindow){                 // 親ウィンドウ再描画のとき
3179                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット詳細設定画面のとき
3180                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
3181                         } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){                   // ウィジェット単体実行のとき
3182                                 $replaceStr .= str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindow();' . M3_NL;
3183                         }
3184                 }
3185                 $replaceStr .= '});' . M3_NL;
3186                 $replaceStr .= '//]]>' . M3_NL;
3187                 $replaceStr .= '</script>' . M3_NL;
3188                 $destContent = str_replace(self::MENUBAR_SCRIPT_TAGS, $replaceStr, $destContent);
3189                 echo $destContent;// 変換したコンテンツを出力
3190                 
3191                 echo '<!-- Widget End -->' . M3_NL;
3192                 
3193                 // Bootstrap用のタグ出力
3194                 if ($this->useBootstrap) echo '</div>' . M3_NL;
3195                 
3196                 echo '</body>' . M3_NL;
3197                 echo '</html>' . M3_NL;
3198         }
3199         /**
3200          * Widget単体RSS出力用のHTMLのヘッダ部(headタグ)出力
3201          *
3202          * Widgetの出力方法は、以下のパターンがある
3203          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
3204          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
3205          *
3206          * @param string $cmd           起動コマンド
3207          */
3208         function startWidgetRss($cmd)
3209         {
3210         }
3211         /**
3212          * Widget単体RSS出力用のタグを閉じる
3213          *
3214          * @param string $cmd                   起動コマンド
3215          * @param string $rssContent    RSS配信内容
3216          */
3217         function endWidgetRss($cmd, $rssContent)
3218         {
3219                 global $gEnvManager;
3220                 
3221                 // ページ作成中断のときは終了
3222                 if ($this->isAbort) return;
3223                 
3224                 echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
3225                 
3226                 // RSSチャンネルデータ取得
3227                 $lang   = $gEnvManager->getCurrentLanguage();
3228                 $date   = getW3CDate();         // RSS1.0用日付
3229                 $copyright = $gEnvManager->getSiteCopyRight();          // 著作権
3230                 $title  = $this->rssChannel['title'];                           // タイトル
3231                 $link   = $this->rssChannel['link'];                            // RSS取得用URL
3232                 $desc   = $this->rssChannel['description'];                     // 説明
3233                 $seq    = $this->rssChannel['seq'];                                     // 項目の並び順(URL)
3234                 
3235                 switch ($this->rssVersion){                                     // RSSバージョン
3236                         case '1.0':
3237                         default:
3238                                 echo '<rdf:RDF xmlns="http://purl.org/rss/1.0/" ';
3239                                 echo 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ';
3240                                 echo 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
3241                                 echo 'xml:lang="' . $lang . '">' . M3_NL;
3242                                 echo '<channel rdf:about="' . convertUrlToHtmlEntity($link) . '">' . M3_NL;
3243                                 echo '<title>' . convertToHtmlEntity($title) . '</title>' . M3_NL;
3244                                 echo '<link>' . convertUrlToHtmlEntity($link) . '</link>' . M3_NL;              // 「convertUrlToHtmlEntity」が必要
3245                                 echo '<description>' . convertToHtmlEntity($desc) . '</description>' . M3_NL;
3246                                 echo '<dc:language>' . $lang . '</dc:language>' . M3_NL;
3247                                 if (!empty($copyright)) echo '<dc:rights>' . convertToHtmlEntity($copyright) . '</dc:rights>' . M3_NL;
3248                                 echo '<dc:date>' . $date . '</dc:date>' . M3_NL;
3249                                 echo '<items>' . M3_NL;
3250                                 if (count($seq) > 0){
3251                                         echo str_repeat(M3_INDENT_SPACE, 1) . '<rdf:Seq>' . M3_NL;
3252                                         for ($i = 0; $i < count($seq); $i++){
3253                                                 echo str_repeat(M3_INDENT_SPACE, 2) . '<rdf:li rdf:resource="' . convertUrlToHtmlEntity($seq[$i]) . '" />' . M3_NL;
3254                                         }
3255                                         echo str_repeat(M3_INDENT_SPACE, 1) . '</rdf:Seq>' . M3_NL;
3256                                 }
3257                                 echo '</items>' . M3_NL;
3258                                 echo '</channel>' . M3_NL;
3259                                 echo $rssContent;
3260                                 echo '</rdf:RDF>' . M3_NL;
3261                                 break;
3262                         case '2.0':
3263                                 break;
3264                 }
3265                 
3266                 // HTTPレスポンスヘッダ設定
3267                 header("Content-type: text/xml; charset=utf-8");
3268         }
3269         /**
3270          * 直サーバ接続時のXML出力用のHTMLのヘッダ部(headタグ)出力
3271          *
3272          * @param string $cmd           起動コマンド
3273          * @return                                      なし
3274          */
3275         function startWidgetXml($cmd)
3276         {
3277                 // HTTPレスポンスヘッダ
3278                 //header("Content-type: text/xml; charset=utf-8");
3279         }
3280         /**
3281          * 直サーバ接続時のXML出力終了
3282          *
3283          * @param string $cmd           起動コマンド
3284          * @return                                      なし
3285          */
3286         function endWidgetXml()
3287         {
3288         }
3289         /**
3290          * デフォルトのXML宣言取得
3291          *
3292          * @return string       XML宣言
3293          */
3294         function getDefaultXmlDeclaration()
3295         {
3296                 return '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>';
3297         }
3298         /**
3299          * HTMLのヘッダ部(headタグ内)出力
3300          *
3301          * システムに共通な定義をHTMLのheadタグ内に出力する
3302          * mosFunc.phpからも実行されるので、このメソッドは引数なしに固定。
3303          * この関数は、以下の「形式1」または「形式2」でheadタグ内に記述する
3304          *
3305          * 形式1:            <!-- m3:HTMLHeader -->
3306          * 形式2(old style): <?php mosShowHead(); ?>
3307          */
3308         function getHeader()
3309         {
3310                 // ヘッダタグ変換の設定
3311                 $this->outputHead = true;                               // HTMLヘッダ出力を行ったかどうか
3312                 $this->outputByStandardHead = true;             // HTML文書の標準のヘッダタグを出力するか
3313                 
3314                 // ##### Magic3システムで必要なヘッダ出力用のタグを埋め込む #####
3315                 echo self::HEAD_TAGS;                   // HTMLヘッダの埋め込みデータ
3316         }
3317         /**
3318          * HTML文書の標準のヘッダタグを出力
3319          *
3320          * @return string                       標準ヘッダ文字列
3321          */
3322         function getStandardHead()
3323         {
3324                 global $gEnvManager;
3325                 global $gRequestManager;
3326                 
3327                 $headStr = '';                  // ヘッダ文字列;
3328                 
3329                 // 実行コマンドを取得
3330                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3331                 
3332                 if ($gEnvManager->getIsSmartphoneSite()){               // スマートフォン用サイトのときはHTML5で設定
3333                         $this->isHtml5 = true;
3334                 } else {
3335                         $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
3336                         if (intval($tempVer) >= 2) $this->isHtml5 = true;
3337                 }
3338                 
3339                 // キャラクターセット
3340                 if ($this->isHtml5){
3341                         $headStr .= '<meta charset="' . M3_HTML_CHARSET . '">' . M3_NL;
3342                 } else {
3343                         $headStr .= '<meta http-equiv="content-script-type" content="text/javascript" />' . M3_NL;
3344                         $headStr .= '<meta http-equiv="content-style-type" content="text/css" />' . M3_NL;
3345                         $headStr .= '<meta http-equiv="content-type" content="application/xhtml+xml; charset=' . M3_HTML_CHARSET .'" />' . M3_NL;
3346                 }
3347                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3348                         // Bootstrapで必要なMETAタグを追加
3349                         $headStr .= '<meta name="viewport" content="width=device-width, initial-scale=1">' . M3_NL;
3350                 }
3351                 
3352                 // 基準ディレクトリの指定
3353                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
3354                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
3355                 
3356                         if ($gEnvManager->getUseSslAdmin()){
3357                                 $rootUrl = $gEnvManager->getSslRootUrl();
3358                         } else {
3359                                 $rootUrl = $gEnvManager->getRootUrl();
3360                         }
3361                         $headStr .= '<base href="' . $rootUrl . '/" />' . M3_NL;
3362                 }
3363                 return $headStr;
3364         }
3365         /**
3366          * HTMLヘッダ出力文字列の取得
3367          *
3368          * @return string               HTMLヘッダ出力文字列
3369          */
3370         function getHeaderOutput()
3371         {
3372                 global $gEnvManager;
3373                 global $gRequestManager;
3374                 global $gInstanceManager;
3375                 global $gSystemManager;
3376
3377                 $replaceStr = '';               // 変換文字列
3378                 
3379                 // 実行コマンドを取得
3380                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3381                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
3382                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
3383                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
3384                 
3385                 // ********************************************************
3386                 //               ヘッダ文字列作成の前処理
3387                 // ********************************************************
3388                 // ##### テンプレートの設定、フレームの設定から必要なライブラリを取得 #####
3389                 // Bootstrapライブラリ
3390 //              if (!$this->useBootstrap) $this->useBootstrap = $gEnvManager->getCurrentTemplateUseBootstrap();
3391                 if ($this->useBootstrap){
3392                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3393                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
3394                                         $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
3395                                         if ($cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)以外のとき
3396                                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
3397                                         } else {
3398                                                 // テンプレートタイプが管理画面のBootstrapバージョン(v3.0)と異なる場合はBootstrapを使用しない場合の管理機能用スクリプトを読み込む
3399                                                 $templateType = $gEnvManager->getCurrentTemplateType();
3400                                                 if ($templateType != 10) $this->addAdminScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);             // Bootstrapを使用しない場合の管理機能用スクリプト
3401                                         }
3402                                 } else {                // ログインしていない場合(ログイン画面等)
3403                                         $this->addPermittedAdminScript(ScriptLibInfo::LIB_BOOTSTRAP);
3404                                         $this->addPermittedAdminScript(ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);// Bootstrap管理画面オプション
3405                                 }
3406                         } else {                // フロント画面へのアクセスの場合
3407                                 // ### Bootstrapのjsとcssはテンプレート側で読み込む ###
3408                                 // ### フロントからプレビューコマンドでログイン画面を表示させるパターンがあるので注意 ###
3409 //                              if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW ||                          // ログイン、ログアウト場合
3410                                 if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || ($cmd == M3_REQUEST_CMD_PREVIEW && !$gEnvManager->isCurrentUserLogined()) ||                               // ログイン、ログアウト場合
3411                                         ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy) && $gEnvManager->isContentEditableUser())){                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
3412                                         
3413                                         $this->addScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);               // Bootstrap管理画面オプション
3414                                 } else {
3415                                         if ($gEnvManager->isSystemManageUser() ||               // システム運用権限がある場合
3416                                                 $gEnvManager->isContentEditableUser()){         // 投稿ユーザの場合
3417                                                 // テンプレートタイプが管理画面のBootstrapバージョン(v3.0)と異なる場合はBootstrapを使用しない場合の管理機能用スクリプトを読み込む
3418                                                 $templateType = $gEnvManager->getCurrentTemplateType();
3419                                                 if ($templateType != 10) $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);          // Bootstrapを使用しない場合の管理機能用スクリプト
3420                                         }
3421                                 }
3422                         }
3423                 } else {
3424                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
3425                                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3426                                         $this->addAdminScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);              // Bootstrapを使用しない場合の管理機能用スクリプト
3427                                 } else {
3428                                         $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
3429                                 }
3430                         } else if ($gEnvManager->isContentEditableUser()){              // 投稿ユーザの場合
3431                                 $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
3432                         }
3433                 }
3434                 
3435                 // ********************************************************
3436                 //               ヘッダ文字列作成処理
3437                 // ********************************************************
3438                 // ##### インストール時のヘッダ出力 #####
3439                 if (defined('M3_STATE_IN_INSTALL')){
3440                         // タイトルの作成
3441                         $title = '';
3442                         if (count($this->headSubTitle) > 0) $title = htmlspecialchars(trim($this->headSubTitle[0]));
3443                         
3444                         // ********** メタタグの設定 **********
3445                         $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
3446                         
3447                         // ##### インストーラ用のファイルの読み込み #####
3448                         $scriptsUrl = '../scripts';
3449                         
3450                         // 管理機能用共通ライブラリのCSSの読み込み
3451                         $count = count($this->defaultAdminCssFiles);
3452                         for ($i = 0; $i < $count; $i++){
3453                                 // CSSへのURLを作成
3454                                 $cssFilename = $this->defaultAdminCssFiles[$i];
3455                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3456                                         $cssURL = $cssFilename;
3457                                 } else {
3458                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
3459                                 }
3460                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3461                         }
3462                         
3463                         // 管理画面用の共通スクリプトを読み込む
3464                         $count = count($this->defaultAdminScriptFiles);
3465                         for ($i = 0; $i < $count; $i++){
3466                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
3467
3468                                 // スクリプトのURLを修正
3469                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3470                                         $scriptURL = $scriptFilename;
3471                                         
3472                                         // SSLをページの状態に合わせる
3473                                         if ($isSslPage){
3474                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3475                                         } else {
3476                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3477                                         }
3478                                 } else {
3479                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3480                                 }
3481                         
3482                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3483                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3484                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3485                         }
3486                         
3487                         // ##### ページへJavascriptの埋め込む #####
3488                         // JavaScriptグローバル変数の設定
3489                         $rootUrl = $gEnvManager->getRootUrl();
3490                         if (empty($rootUrl)) $rootUrl = $gEnvManager->calcSystemRootUrl();
3491                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3492                         $replaceStr .= '//<![CDATA[' . M3_NL;
3493                         $replaceStr .= '// Magic3 Global values' . M3_NL;
3494                         if (!empty($rootUrl)) $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;           // システムルートURL
3495                         $replaceStr .= '//]]>' . M3_NL;
3496                         $replaceStr .= '</script>' . M3_NL;
3497                         return $replaceStr;
3498                 }
3499                 
3500                 // テンプレートの情報を取得
3501                 $cleanType = $gEnvManager->getCurrentTemplateCleanType();               // テンプレートクリーンタイプ
3502 /*              if ($this->db->getTemplate($gEnvManager->getCurrentTemplateId(), $templateRow)){
3503                         $cleanType = $templateRow['tm_clean_type'];
3504                 }*/
3505                 
3506                 // URLの作成
3507                 $isSslPage = false;
3508                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3509                         // 管理画面のSSL状態を参照
3510                         if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
3511                 } else {
3512                         $isSslPage = $this->isSslPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
3513                 }
3514                 if ($isSslPage){
3515                         $rootUrl = $gEnvManager->getSslRootUrl();
3516                         $scriptsUrl = $gEnvManager->getSslScriptsUrl();         // スクリプト読み込み用パス
3517                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
3518                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
3519                 } else {
3520                         $rootUrl = $gEnvManager->getRootUrl();
3521                         $scriptsUrl = $gEnvManager->getScriptsUrl();            // スクリプト読み込み用パス
3522                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
3523                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
3524                 }
3525
3526                 // タイトルの設定
3527                 if (!$this->showWidget){// 単体実行以外のとき
3528                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスの場合
3529                                 // 管理画面のタイトル
3530                                 // メイン画面は「サイト名 - 管理画面」、サブ画面は個別画面名
3531                                 $siteName = $gEnvManager->getSiteName();
3532 //                              if (empty($siteName)) $siteName = self::DEFAULT_SITE_NAME;
3533                                 $title = $siteName . ' - ' . self::DEFAULT_ADMIN_TITLE;
3534                                 $titleCount = count($this->headSubTitle);
3535                                 if ($titleCount > 0) $title = $this->headSubTitle[$titleCount -1];              // サブタイトルが設定されている場合は変更
3536                                 $replaceStr .= '<title>' . htmlspecialchars($title) . '</title>' . M3_NL;
3537                                 
3538                                 // その他HTMLヘッダに出力するタグ文字列
3539                                 if (!empty($this->adminHeadOthers)){
3540                                         // マクロを変換
3541                                         $this->adminHeadOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->adminHeadOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
3542                                         $replaceStr .= $this->adminHeadOthers . M3_NL;
3543                                 }
3544                         } else {                        // 管理画面以外の画面へのアクセスの場合
3545                                 // 画面タイトル
3546                                 $titleItemCount = 0;            // タイトル項目数
3547                                 $defaultTitle = trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_TITLE));
3548                                 if (!empty($defaultTitle)) $titleItemCount++;
3549                                 if (!empty($this->headSubTitle)){               // サブタイトルが設定されているとき
3550                                         $titleItemCount += count($this->headSubTitle);
3551                                 }
3552                                 // タイトルフォーマットを取得
3553                                 $title = '';
3554                                 if ($titleItemCount > 0){
3555                                         $format = $this->gSystem->getSystemConfig(self::CONFIG_KEY_HEAD_TITLE_FORMAT);
3556                                         if (empty($format)){
3557                                                 $title = htmlspecialchars($defaultTitle);
3558                                         } else {
3559                                                 $formats = explode(';', $format);
3560                                                 $titleItemCount = ($titleItemCount > count($formats)) ? count($formats) : $titleItemCount;
3561                                                 $title = $formats[$titleItemCount -1];
3562                                                 $number = 1;
3563                                                 if (!empty($defaultTitle)){
3564                                                         $title = str_replace('$1', htmlspecialchars($defaultTitle), $title);
3565                                                         $number++;
3566                                                 }
3567                                                 for ($i = 0; $i < count($this->headSubTitle); $i++){
3568                                                         $key = '$' . $number;
3569                                                         $value = htmlspecialchars(trim($this->headSubTitle[$i]));
3570                                                         $title = str_replace($key, $value, $title);
3571                                                         $number++;
3572                                                 }
3573                                         }
3574                                 }
3575                                 if (!empty($title)) $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
3576
3577                                 // サイトの説明
3578                                 if (!empty($this->headDescription)) $replaceStr .= '<meta name="description" content="' . htmlspecialchars($this->headDescription) . '" />' . M3_NL;
3579                 
3580                                 // 検索エンジン用キーワード
3581                                 if (!empty($this->headKeywords)) $replaceStr .= '<meta name="keywords" content="' . htmlspecialchars($this->headKeywords) . '" />' . M3_NL;
3582                                 
3583                                 // その他HTMLヘッダに出力するタグ文字列
3584                                 if (!empty($this->headOthers)){
3585                                         // マクロを変換
3586                                         $this->headOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->headOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
3587                                         $replaceStr .= $this->headOthers . M3_NL;
3588                                 }
3589                         }
3590                 }
3591                 
3592                 // ##### PC用URLと携帯用URLのアクセス別に処理 #####
3593                 // ##### テンプレート情報に応じた処理 #####
3594                 // テンプレートクリーンが必要な場合はJQueryを追加
3595                 if ($cleanType != 0) $this->addScriptFile($this->selectedJQueryFilename);               // JQueryスクリプト追加
3596                 
3597                 // 検索ロボットへの指示
3598                 $robots = htmlspecialchars(trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_ROBOTS)));
3599                 if (!empty($robots)){
3600                         $replaceStr .= '<meta name="robots" content="' . $robots . '" />' . M3_NL;
3601                 }
3602         
3603                 // サイト構築エンジン
3604                 $replaceStr .= '<meta name="generator" content="' . M3_SYSTEM_NAME . ' ver.' . M3_SYSTEM_VERSION . ' - ' . M3_SYSTEM_DESCRIPTION . '" />' . M3_NL;              
3605
3606                 // カノニカル属性、Faviconの読み込み
3607                 $templateId = $gEnvManager->getCurrentTemplateId();
3608                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3609                         // テンプレートのFaviconがない場合はシステムのデフォルトのFaviconを使用
3610                         $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3611                         if (file_exists($faviconPath)){         // ファイルが存在しているとき
3612                                 $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3613                                 $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3614                         } else {
3615                                 // 管理画面のアイコンを設定
3616                                 $faviconPath = $gEnvManager->getSystemRootPath() . self::DEFAULT_ADMIN_FAVICON_FILE;
3617                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
3618                                         $faviconFile = $rootUrl . self::DEFAULT_ADMIN_FAVICON_FILE;
3619                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3620                                 }
3621                         }
3622                 } else {
3623                         // カノニカル属性
3624                         if (!empty($this->headCanonicalUrl)) $replaceStr .= '<link rel="canonical" href="' . convertUrlToHtmlEntity($this->headCanonicalUrl) .'" />' . M3_NL;                           // カノニカル属性URL
3625                         
3626                         // Favicon
3627                         $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3628                         if (file_exists($faviconPath)){         // ファイルが存在しているとき
3629                                 $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
3630                                 $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
3631                         }
3632                 }
3633                 
3634                 // ##### Ajaxライブラリの読み込み #####
3635                 if (!$gEnvManager->isAdminDirAccess()){         // 通常画面へのアクセスのとき
3636                         if ($this->db->isExistsWidgetWithAjax($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId())){// Ajaxライブラリを使用しているウィジェットがあるときは追加
3637                                 $this->addScriptFile($this->selectedJQueryFilename);            // デフォルトAjaxライブラリ追加
3638                                 $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
3639                         }
3640                 }
3641                         
3642                 // ##### 共通ライブラリの読み込み #####
3643                 if (!$this->showWidget){// 単体実行以外のとき
3644                         $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3645                         for ($i = 0; $i < count($rows); $i++){
3646                                 $this->addScript($task, trim($rows[$i]['wd_add_script_lib']));
3647                         }
3648                 }
3649
3650                 // ##### 共通CSS読み込み #####
3651                 if (($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()) || $this->isEditMode){                     // フロント画面編集モード
3652                         $cssURL = $scriptsUrl . '/' . self::M3_EDIT_CSS_FILE;
3653                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3654                 }
3655                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3656                         //if ($gEnvManager->isSystemAdmin()){           // 管理者権限がある場合のみ有効
3657                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3658                                 // 管理機能用共通ライブラリのCSSの読み込み
3659                                 $count = count($this->defaultAdminCssFiles);
3660                                 for ($i = 0; $i < $count; $i++){
3661                                         // CSSへのURLを作成
3662                                         //$cssURL = $scriptsUrl . '/' . $this->defaultAdminCssFiles[$i];
3663                                         $cssFilename = $this->defaultAdminCssFiles[$i];
3664                                         if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3665                                                 $cssURL = $cssFilename;
3666                                         } else {
3667                                                 $cssURL = $scriptsUrl . '/' . $cssFilename;
3668                                         }
3669                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3670                                 }
3671                         } else {
3672                                 // 管理権限なしで管理ディレクトリアクセスで必要なCSSファイルを読み込む
3673                                 $count = count($this->defaultAdminDirCssFiles);
3674                                 for ($i = 0; $i < $count; $i++){
3675                                         // CSSへのURLを作成
3676                                         $cssURL = $scriptsUrl . '/' . $this->defaultAdminDirCssFiles[$i];
3677                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3678                                 }
3679                         }
3680                 } else {
3681                         // 共通ライブラリのCSSの読み込み
3682                         $count = count($this->defaultCssFiles);
3683                         for ($i = 0; $i < $count; $i++){
3684                                 // CSSへのURLを作成
3685                                 $cssFilename = $this->defaultCssFiles[$i];
3686                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
3687                                         $cssURL = $cssFilename;
3688                                 } else {
3689                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
3690                                 }
3691                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3692                         }
3693                 }
3694                 
3695                 // ##### 表示モードによるCSS読み込み #####
3696                 // ウィジェット付きポジション画面は管理画面のアクセスではない
3697                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
3698                         // ウィジェット操作用CSS
3699                         $cssURL = $scriptsUrl . self::M3_ADMIN_WIDGET_CSS_FILE;
3700                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3701                 }
3702                 
3703                 // ##### ウィジェットごとのCSS読み込み #####
3704                 // CSSがあるウィジェットを取得
3705                 $this->db->getWidgetsIdWithCss($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3706                 for ($i = 0; $i < count($rows); $i++){
3707                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS;
3708                         // ディレクトリがあるときはディレクトリ内読み込み
3709                         if (is_dir($searchPath)){
3710                                 $dir = dir($searchPath);
3711                                 while (($file = $dir->read()) !== false){
3712                                         $filePath = $searchPath . '/' . $file;
3713                                         if ($file != '.' && $file != '..' && is_file($filePath)
3714                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3715                                 
3716                                                 // CSSへのURLを作成
3717                                                 $cssURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS . '/' . $file;
3718                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3719                                         }
3720                                 }
3721                                 $dir->close();
3722                         }
3723                 }
3724                 // ##### 外部出力用CSS読み込み #####
3725                 // ウィジェットからの追加のCSS読み込み
3726                 $count = count($this->headCssFiles);
3727                 for ($i = 0; $i < $count; $i++){
3728                         $cssUrl = $this->headCssFiles[$i];
3729                         if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3730                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . convertUrlToHtmlEntity($cssUrl) . '" />' . M3_NL;
3731                 }
3732                 
3733                 // 外部出力用CSSデータがある場合はURLを追加
3734                 if (!empty($this->exportCss)){
3735                         $cssUrl = $this->createCssCmdUrl($isSslPage, date('YmdHis'));
3736                         if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3737                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . convertUrlToHtmlEntity($cssUrl) . '" />' . M3_NL;
3738                 }
3739                 
3740                 // ##### RSS配信情報の読み込み #####
3741                 $count = count($this->headRssFiles);
3742                 for ($i = 0; $i < $count; $i++){
3743                         $rssUrl = $this->headRssFiles[$i]['href'];// リンク先URL
3744                         $rssTitle = $this->headRssFiles[$i]['title'];// タイトル
3745                         $replaceStr .=  '<link rel="alternate" type="application/rss+xml" title="' . $rssTitle . '" href="' . convertUrlToHtmlEntity($rssUrl) . '" />' . M3_NL;
3746                 }
3747                                                                 
3748                 // ##### 共通Javascriptの読み込み #####
3749                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3750                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3751                                 // 管理画面用の共通スクリプトを読み込む
3752                                 $count = count($this->defaultAdminScriptFiles);
3753                                 for ($i = 0; $i < $count; $i++){
3754                                         $scriptFilename = $this->defaultAdminScriptFiles[$i];
3755
3756                                         // スクリプトのURLを修正
3757                                         if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3758                                                 $scriptURL = $scriptFilename;
3759                                                 
3760                                                 // SSLをページの状態に合わせる
3761                                                 if ($isSslPage){
3762                                                         $scriptURL = str_replace('http://', 'https://', $scriptURL);
3763                                                 } else {
3764                                                         $scriptURL = str_replace('https://', 'http://', $scriptURL);
3765                                                 }
3766                                         } else {
3767                                                 $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3768                                         }
3769                                 
3770                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3771                                         //$scriptURL = $scriptsUrl . '/' . $scriptFilename;
3772                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3773                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3774                                 }
3775                                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示のときは、ウィジェット操作ライブラリを読み込む
3776                                         // wigetのドラッグドロップ用
3777                                         $scriptURL = $scriptsUrl . '/' . self::M3_ADMIN_WIDGET_SCRIPT_FILENAME;
3778                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();// スクリプトをキャッシュ保存しない場合は、パラメータを付加
3779                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3780                                 }
3781                         } else {                // システム運用権限がない場合
3782                                 // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
3783                                 $count = count($this->defaultAdminDirScriptFiles);
3784                                 for ($i = 0; $i < $count; $i++){
3785                                         $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
3786
3787                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3788                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3789                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3790                                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3791                                 }
3792                         }
3793                 } else {                        // 通常画面
3794                         // Googleマップライブラリの読み込み
3795                         if ($this->useGooglemaps && $this->isContentGooglemaps) $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));  // コンテンツにGoogleマップが含むかどうか
3796
3797                         $useExternalJquery = $gSystemManager->getSystemConfig(self::CF_EXTERNAL_JQUERY);                // システム外部のjQueryを使用するかどうか
3798                         
3799                         $count = count($this->defaultScriptFiles);
3800                         for ($i = 0; $i < $count; $i++){
3801                                 $defaultScriptFile = $this->defaultScriptFiles[$i];
3802
3803                                 // 外部のjQueryを使用する場合はSCRIPTタグを出力しない
3804                                 if ($defaultScriptFile == $this->selectedJQueryFilename && $useExternalJquery) continue;
3805                                 
3806                                 // スクリプトのURLを修正
3807                                 if (strncasecmp($defaultScriptFile, 'http://', 7) == 0 || strncasecmp($defaultScriptFile, 'https://', 8) == 0){
3808                                         $scriptURL = $defaultScriptFile;
3809                                         
3810                                         // SSLをページの状態に合わせる
3811                                         if ($isSslPage){
3812                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3813                                         } else {
3814                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3815                                         }
3816                                 } else {
3817                                         $scriptURL = $scriptsUrl . '/' . $defaultScriptFile;
3818                                 }
3819
3820                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3821                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3822                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3823                         }
3824                         
3825                         // ### フロントからプレビューコマンドでログイン画面を表示させるパターンがあるので注意 ###
3826 //                              if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW){                           // ログイン、ログアウト場合
3827                         if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || ($cmd == M3_REQUEST_CMD_PREVIEW && !$gEnvManager->isCurrentUserLogined())){                                // ログイン、ログアウト場合
3828                                 // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
3829                                 $count = count($this->defaultAdminDirScriptFiles);
3830                                 for ($i = 0; $i < $count; $i++){
3831                                         $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
3832                                         if (!in_array($scriptFilename, $this->defaultScriptFiles)){             // 既に追加されていない場合のみ追加
3833                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3834                                                 $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3835                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3836                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3837                                         }
3838                                 }
3839                         }
3840                         
3841                         // ***** [WordPressテンプレート] jQueryの読み込み後、ヘッダ部に出力するテンプレート用のJavascriptがあれば読み込む *****
3842                         $headData = $this->gEnv->getWpHeadScriptsData();
3843                         if (!empty($headData)) $replaceStr .= $headData;
3844                 }
3845                 // ##### ウィジェットごとのJavaScript読み込み #####
3846                 // スクリプトがあるウィジェットを取得
3847                 $this->db->getWidgetsIdWithScript($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3848                 for ($i = 0; $i < count($rows); $i++){
3849                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS;
3850                 
3851                         // ディレクトリがあるときはディレクトリ内読み込み
3852                         if (is_dir($searchPath)){
3853                                 $dir = dir($searchPath);
3854                                 while (($file = $dir->read()) !== false){
3855                                         $filePath = $searchPath . '/' . $file;
3856                                         if ($file != '.' && $file != '..' && is_file($filePath)
3857                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3858                                         
3859                                                 // スクリプトへのURLを作成
3860                                                 $scriptURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
3861                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3862                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3863                                                 $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptURL) . '"></script>' . M3_NL;
3864                                         }
3865                                 }
3866                                 $dir->close();
3867                         }
3868                 }
3869                 // ウィジェットからの追加のCSS読み込み
3870                 $count = count($this->headScriptFiles);
3871                 for ($i = 0; $i < $count; $i++){
3872                         $scriptUrl = $this->headScriptFiles[$i];
3873                         if ($isSslPage) $scriptUrl = str_replace('http://', 'https://', $scriptUrl);                    // SSL化が必要なときは変換
3874         
3875                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3876                         if (!$this->hasScriptCache) $scriptUrl .= $this->getCacheParam();
3877                         $replaceStr .=  '<script type="text/javascript" src="' . convertUrlToHtmlEntity($scriptUrl) . '"></script>' . M3_NL;
3878                 }
3879                 
3880                 // ##### ページへJavascriptの埋め込む #####
3881                 // JavaScriptグローバル変数の設定
3882                 //$replaceStr .= '<script type="text/javascript">' . M3_NL;
3883                 //$replaceStr .= '<!--' . M3_NL;
3884                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
3885                 $replaceStr .= '//<![CDATA[' . M3_NL;
3886                 $replaceStr .= '// Magic3 Global values' . M3_NL;
3887                 $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;         // システムルートURL
3888
3889                 if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()){            // 管理画面へのアクセス、システム運用権限があり
3890                         $pageId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);          // ページID
3891                         $pageSubId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);// ページサブID
3892                                 
3893                         // 管理画面のオープン設定
3894                         $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
3895                         
3896                         // ページID、ページサブID
3897                         $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
3898                         $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
3899                         // WYSIWYGエディター
3900                         $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
3901                         
3902                         // ファイルブラウザ
3903                         $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;           // バージョン
3904                         $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
3905                         $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
3906
3907                         // Googleマップライブラリの読み込み
3908                         if ($this->useGooglemaps){
3909                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
3910                                 
3911                                 // CKEditor拡張プラグイン用の定義
3912                                 $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
3913                                 if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
3914                         } else {
3915                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
3916                         }
3917
3918                         // 起動がパーソナルモードかどうか
3919                         if ($this->isPersonalMode){
3920                                 $replaceStr .= 'var M3_PERSONAL_MODE = true;' . M3_NL;
3921                         } else {
3922                                 $replaceStr .= 'var M3_PERSONAL_MODE = false;' . M3_NL;
3923                         }
3924                         // 管理画面の小画面デバイス最適化を行うかどうか
3925                         if ($gEnvManager->isSmallDeviceAdmin()){
3926                                 $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = true;' . M3_NL;
3927                         } else {
3928                                 $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = false;' . M3_NL;
3929                         }
3930                         
3931                         // ウィジェット詳細設定画面専用のJavaScriptグローバル変数
3932                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){
3933                         //if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET || $cmd == M3_REQUEST_CMD_CONFIG_TEMPLATE){                                          // ウィジェット設定画面またはテンプレート設定画面のとき
3934                                 // ##### CKEditor用の設定 #####
3935                                 $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
3936                                 
3937                                 // CKEditor用のCSSファイル
3938                                 if (!empty($this->ckeditorCssFiles)){
3939                                         // 編集エリア用のCSSファイルを追加
3940                                         $this->ckeditorCssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
3941                                         //array_unshift($this->ckeditorCssFiles, $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE);
3942                                         
3943                                         //$fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $this->ckeditorCssFiles));
3944                                         $fileList = implode(', ', array_map(function($a){ return "'" . $a . "'"; }, $this->ckeditorCssFiles));
3945                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
3946                                 }
3947                                 // CKEditor用(レイアウト)のCSSファイル
3948                                 $cssFiles = array();
3949                                 $cssFiles[] = $scriptsUrl . '/' . ScriptLibInfo::BOOTSTRAP_ADMIN_CSS;           // BootstrapのCSSを追加
3950                                 $cssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
3951 //                                      $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $cssFiles));
3952                                 $fileList = implode(', ', array_map(function($a){ return "'" . $a . "'"; }, $cssFiles));
3953                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_LAYOUT_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
3954                                 
3955                                 // CKEditor用のテンプレートタイプ
3956                                 if (isset($this->ckeditorTemplateType)){
3957                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_TEMPLATE_TYPE = ' . $this->ckeditorTemplateType . ';' . M3_NL;
3958                                 }
3959                         } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION){               // ポジション表示
3960                                 $replaceStr .= 'var M3_POSITION_DATA = "' . implode(',', $this->defPositions) . '";' . M3_NL;                   // 管理画面画面の端末タイプ(主にテスト用に使用)
3961                                 $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = 0;' . M3_NL;                 // 管理画面画面の端末タイプ(主にテスト用に使用)
3962                         } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // ウィジェット付きポジション表示
3963                                 // その他のポジションデータを取得
3964                                 $positionData = $this->getRestPositionData();
3965                                 
3966                                 // テンプレート上のポジション名
3967                                 if (count($this->viewPosId) > 0){
3968                                         $posArrayStr = '[';
3969                                         for ($i = 0; $i < count($this->viewPosId); $i++){
3970                                                 $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
3971                                                 if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
3972                                         }
3973                                         $posArrayStr .= ']';
3974                                         $replaceStr .= 'var M3_POSITIONS = ' . $posArrayStr . ';' . M3_NL;
3975                                 }
3976                                 // 画面定義のリビジョン番号
3977                                 $replaceStr .= 'var M3_REVISION = ' . $this->pageDefRev . ';' . M3_NL;
3978                                 
3979                                 // その他のポジションデータ
3980                                 $replaceStr .= 'var M3_REST_POSITION_DATA = \'' . $positionData . '\';' . M3_NL;
3981                         } else if (!empty($pageId)){
3982                                 $accessPoint = $this->gEnv->getAllDefaultPageId();
3983                                 for ($i = 0; $i < count($accessPoint); $i++){
3984                                         if ($pageId == $accessPoint[$i]){
3985                                                 $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $i . ';' . M3_NL;                        // ウィジェット設定画面のウィジェットの端末タイプ
3986                                                 break;
3987                                         }
3988                                 }
3989                         } else {                // メインの管理画面の場合
3990                                 $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = 0;' . M3_NL;                 // 管理画面画面の端末タイプ(主にテスト用に使用)
3991                         }
3992                                         
3993                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
3994                                 if (!empty($task)){             // 戻りタスクが設定されているときのみ最大化可能
3995                                         $replaceStr .= 'function gobackPagedef(){' . M3_NL;
3996                                         $replaceStr .= '    window.location.href = "' . $gEnvManager->getDefaultAdminUrl() . '?pageid=' . $pageId . '&pagesubid=' . $pageSubId . '&task=' . $task . '";' . M3_NL;
3997                                         $replaceStr .= '}' . M3_NL;
3998                                         $replaceStr .= '$(function(){' . M3_NL;
3999                                         $replaceStr .= '    $(document).keyup(function(e){' . M3_NL;
4000                                         $replaceStr .= '        if (e.which == 36) gobackPagedef();' . M3_NL;
4001                                         $replaceStr .= '    });' . M3_NL;
4002                                         $replaceStr .= '});' . M3_NL;
4003                                 }
4004                         } else {
4005                                 // ##### 管理用テンプレートを使用している場合の処理 #####
4006                                 // Bootstrap用のスクリプト処理
4007                                 if ($this->useBootstrap){
4008                                         $replaceStr .= '$(function(){' . M3_NL;
4009                                         $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
4010                                         $replaceStr .= '});' . M3_NL;
4011                                 }
4012                         }
4013                 } else if ($this->isPageEditable){              // フロント画面ページ編集可能モードのとき
4014                         $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
4015                         
4016                         // ページID、ページサブID
4017                         $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
4018                         $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
4019                         // WYSIWYGエディター
4020                         $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4021                         
4022                         // ファイルブラウザ
4023                         $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;   // バージョン
4024                         $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4025                         $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4026                         
4027                         // Googleマップライブラリの読み込み
4028                         if ($this->useGooglemaps){
4029                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
4030                                 
4031                                 // CKEditor拡張プラグイン用の定義
4032                                 $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
4033                                 if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
4034                         } else {
4035                                 $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
4036                         }
4037
4038                         // 起動がパーソナルモードかどうか
4039                         if ($this->isPersonalMode){
4040                                 $replaceStr .= 'var M3_PERSONAL_MODE = true;' . M3_NL;
4041                         } else {
4042                                 $replaceStr .= 'var M3_PERSONAL_MODE = false;' . M3_NL;
4043                         }
4044                         
4045                         // テンプレートタイプ
4046                         $templateType = $gEnvManager->getCurrentTemplateType();
4047                         if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4048                 } else if ($this->isEditMode){                  // フロント画面編集モード(コンテンツ編集可能ユーザ)
4049                         if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                               // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
4050                                 // WYSIWYGエディター
4051                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
4052                         
4053                                 // ファイルブラウザ
4054                                 $replaceStr .= 'var M3_FILEBROWSER_VER = "' . $this->libFiles[ScriptLibInfo::LIB_ELFINDER]['version'] . '";' . M3_NL;   // バージョン
4055                                 $replaceStr .= 'var M3_FILEBROWSER_WIDTH_RATIO = ' . self::FILEBROWSER_WIDTH_RATIO . ';' . M3_NL;                       // ファイルブラウザ幅比率
4056                                 $replaceStr .= 'var M3_FILEBROWSER_HEIGHT_RATIO = ' . self::FILEBROWSER_HEIGHT_RATIO . ';' . M3_NL;             // ファイルブラウザ高さ比率
4057                         
4058                                 // Googleマップライブラリの読み込み
4059                                 if ($this->useGooglemaps){
4060                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
4061                                         
4062                                         // CKEditor拡張プラグイン用の定義
4063                                         $googleMapsKey = $this->gSystem->getSystemConfig(self::CF_GOOGLE_MAPS_KEY);             // Googleマップ利用キー
4064                                         if (!empty($googleMapsKey)) $replaceStr .= 'var M3_GOOGLEMAPS_KEY="' . $googleMapsKey . '";' . M3_NL;           // システムルートURL
4065                                 } else {
4066                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
4067                                 }
4068                         
4069                                 // 起動がパーソナルモードかどうか(常にパーソナルモード)
4070                                 $replaceStr .= 'var M3_PERSONAL_MODE = true;' . M3_NL;
4071                         
4072                                 // 管理画面の小画面デバイス最適化を行うかどうか
4073                                 if ($gEnvManager->isSmallDeviceAdmin()){
4074                                         $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = true;' . M3_NL;
4075                                 } else {
4076                                         $replaceStr .= 'var M3_SMALL_DEVICE_OPTIMIZE = false;' . M3_NL;
4077                                 }
4078                         
4079                                 // ##### CKEditor用の設定 #####
4080                                 // ウィジェット情報取得
4081                                 $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
4082                                 $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
4083                         
4084                                 // CKEditor用のCSSファイル
4085                                 if (!empty($this->ckeditorCssFiles)){
4086                                         // 編集エリア用のCSSファイルを追加
4087                                         $this->ckeditorCssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4088                                         //array_unshift($this->ckeditorCssFiles, $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE);
4089                                 
4090 //                                              $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $this->ckeditorCssFiles));
4091                                         $fileList = implode(', ', array_map(function($a){ return "'" . $a . "'"; }, $this->ckeditorCssFiles));
4092                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4093                                 }
4094                                 // CKEditor用(レイアウト)のCSSファイル
4095                                 $cssFiles = array();
4096                                 $cssFiles[] = $scriptsUrl . '/' . ScriptLibInfo::BOOTSTRAP_ADMIN_CSS;           // BootstrapのCSSを追加
4097                                 $cssFiles[] = $scriptsUrl . '/' . self::M3_CKEDITOR_CSS_FILE;
4098         //                      $fileList = implode(', ', array_map(create_function('$a','return "\'" . $a . "\'";'), $cssFiles));
4099                                 $fileList = implode(', ', array_map(function($a){ return "'" . $a . "'"; }, $cssFiles));
4100                                 $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_LAYOUT_CSS_FILES = [ ' . $fileList . ' ];' . M3_NL;
4101                                 
4102                                 // CKEditor用のテンプレートタイプ
4103                                 if (isset($this->ckeditorTemplateType)){
4104                                         $replaceStr .= 'var M3_CONFIG_WIDGET_CKEDITOR_TEMPLATE_TYPE = ' . $this->ckeditorTemplateType . ';' . M3_NL;
4105                                 }
4106                                 
4107                                 // Bootstrap用のスクリプト処理
4108                                 if ($this->useBootstrap){
4109                                         $replaceStr .= '$(function(){' . M3_NL;
4110                                         $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
4111                                         $replaceStr .= '});' . M3_NL;
4112                                 }
4113                         } else {
4114                                 // プレビュー画面用にテンプレートタイプを出力
4115                                 $templateType = $gEnvManager->getCurrentTemplateType();
4116                                 if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4117                                 
4118                                 // ##### ヘルプシステムの組み込み #####
4119                                 if ($this->useHelp){                    // ヘルプ表示のとき
4120                                         $replaceStr .= '$(function(){' . M3_NL;
4121                                         $replaceStr .= '    if (jQuery().tooltip) $(\'[rel=m3help]\').tooltip({ placement: \'top\'});' . M3_NL;
4122                                         $replaceStr .= '});' . M3_NL;
4123                                 }
4124                         }
4125                 } else {                        // 権限なしの場合
4126                         if (!$gEnvManager->isAdminDirAccess()){                 // フロント画面のとき
4127                                 // テンプレートタイプを追加(ファイルローダ等で使用)
4128                                 $templateType = $gEnvManager->getCurrentTemplateType();
4129                                 if (isset($templateType)) $replaceStr .= 'var M3_TEMPLATE_TYPE = ' . $templateType . ';' . M3_NL;
4130                         }
4131                 }
4132                 
4133                 // ##### パネルメニュー(フロント画面と管理画面の切り替え等)の表示 #####
4134                 // PC用、携帯用、スマートフォン用画面とウィジェット付きポジションの管理画面時に表示
4135                 if (($gEnvManager->isAdminDirAccess() && $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) ||           // 管理画面(ウィジェット付きポジション表示)のとき
4136                         (!$gEnvManager->isAdminDirAccess() &&                                                   // 一般用画面のとき
4137                                 $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
4138                                 $cmd != M3_REQUEST_CMD_RSS)){                                                           // RSS配信でない
4139                         //if ($gEnvManager->isSystemAdmin()){                           // 管理者権限がある場合のみ有効
4140                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限ありの場合
4141                                 // トップメニュー項目作成
4142                                 $menubarTag = '';       // 管理用メニューバー
4143                                 $adminTag = '';         // 管理画面ボタン
4144                                 $editTag = '';          // 編集ボタン
4145                                 $logoutTag = '';                // ログアウトボタン
4146                                 
4147                                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面(ウィジェット付きポジション表示)の場合
4148                                         // 編集ボタン
4149 /*                                              $titleStr = '編集終了';
4150                                         $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4151                                         if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4152                                         $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
4153                                         $editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></li>';
4154                                         */
4155                                         $titleStr = '編集終了';
4156                                         $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4157                                         if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4158                                         //$editTag = '<div class="m3editend"><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4159                                         //$editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" /></a></div>';
4160                                         $editTag = '<div class="m3editend m3topright"><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4161                                         $editTag .= '<i class="glyphicon glyphicon-ok-sign"></i></a></div>';
4162                                         $menubarTag .= $editTag;
4163                                         
4164                         //              $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
4165                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window == window.parent){' . M3_NL;// インラインフレームでないときパネルメニューを表示(修正 2016/9/1)
4166                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").prepend(\'' . $menubarTag . '\');' . M3_NL;            // appendでうまく表示できないのでprependで表示
4167                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
4168                                 } else if ($this->isAccessPointWithAdminMenu){          // 通常画面は、管理メニューを使用するアクセスポイントの場合のみ表示
4169                                         // 管理画面ボタン
4170                                         $titleStr = '管理画面へ遷移';
4171                                         $linkUrl = $gEnvManager->getDefaultAdminUrl();
4172                                         $adminTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4173                                         $adminTag .= '<img src="' . $rootUrl . self::ADMIN_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4174                                 
4175                                         // 編集ボタン
4176                                         $titleStr = '画面を編集';
4177                                         $linkUrl  = $gEnvManager->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' .M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET;
4178                                         $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_ID . '=' . $gEnvManager->getCurrentPageId();
4179                                         $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
4180                                         $linkUrl .= '&' . M3_REQUEST_PARAM_BACKUP_URL . '=' . urlencode($gEnvManager->getCurrentRequestUri());                  // URL退避用
4181                                         $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4182                                         $editTag .= '<img src="' . $rootUrl . self::EDIT_PAGE_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4183                                         
4184                                         // ログアウトボタン
4185                                         $titleStr = 'ログアウト';
4186 //                                              if ($gEnvManager->isAdminDirAccess()){          // 管理画面の場合
4187 //                                                      $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
4188 //                                                      if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
4189 //                                              } else {
4190                                                 $linkUrl = $gEnvManager->getCurrentRequestUri();
4191 //                                              }
4192                                         $linkUrl = createUrl($linkUrl, M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_LOGOUT);
4193                                         $logoutTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '" rel="m3help" data-placement="bottom" data-container="body" title="' . $titleStr . '">';
4194                                         $logoutTag .= '<img src="' . $rootUrl . self::LOGOUT_ICON_FILE . '" alt="' . $titleStr . '" /></a></li>';
4195                                 
4196                                         // ウィジェットツール表示制御ボタン
4197                                         $widgetToolTag .= '<li><div class="m3widgettoolbutton m3-nav m3-navbar-nav" data-toggle="buttons">';
4198                                         $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>';
4199                                         $widgetToolTag .= '<input type="checkbox" class="hidden" />';
4200                                         $widgetToolTag .= '</div></li>';
4201                                         
4202                                         //$menubarTag .= '<div id="m3slidepanel">';
4203                                         $menubarTag .= '<div id="m3slidepanel" class="m3panel_top m3-navbar-default" style="top:-60px; visibility: visible;">';
4204                                         $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>';                           
4205                         //              $menubarTag .= '<div tabindex="0" class="m3panel_wrap">';
4206                                         $menubarTag .= '<div>';
4207                                         $menubarTag .= '<ul class="m3-nav m3-navbar-nav">';
4208                                         if ($gEnvManager->isSystemAdmin()){                             // 管理画面、編集モードは、管理者権限がある場合のみ有効
4209                                                 $menubarTag .= $adminTag;
4210                                                 $menubarTag .= $editTag;
4211                                         }
4212                                         $menubarTag .= $logoutTag;
4213                                         $menubarTag .= $widgetToolTag;
4214                                         $menubarTag .= '</ul>';
4215                                         $menubarTag .= '</div>';
4216                                         $menubarTag .= '</div>';
4217                                 //      $menubarTag .= '</div>';
4218
4219                                 //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
4220                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window == window.parent){' . M3_NL;// インラインフレームでないときパネルメニューを表示(修正 2016/9/1)
4221                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").append(\'' . $menubarTag . '\');' . M3_NL;
4222                                         //$this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("#m3slidemenubarpanel").m3SlideMenubar();' . M3_NL;
4223                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(".m3panel_top").m3slidepanel({ "position": "top", "type": "push" });' . M3_NL;
4224                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").css("position", "relative");' . M3_NL;
4225                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'm3SetHelp($(\'#m3slidepanel\'));' . M3_NL;
4226                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'm3SetupWidgetTool(\'m3widgettoolbutton\');' . M3_NL;
4227                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
4228                                 }
4229                         }
4230                 }
4231                 // ##### フロント画面からのウィジェット操作用ツールバー #####
4232                 if (!$gEnvManager->isAdminDirAccess() && 
4233                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
4234                         $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
4235                         if ($gEnvManager->isSystemManageUser()){                // 一般用画面で管理者権限がある場合のみ有効
4236                                 // 管理用ツールバー
4237                                 $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').each(function(){' . M3_NL;
4238                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var attrs = m3_splitAttr($(this).attr(\'m3\'));' . M3_NL;
4239                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var widgetId = attrs[\'widgetid\'];' . M3_NL;
4240                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var serialNo = attrs[\'serial\'];' . M3_NL;
4241                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var configId = attrs[\'configid\'];' . M3_NL;
4242                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var useconfig = attrs[\'useconfig\'];' . M3_NL;
4243                                 
4244                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'\';' . M3_NL;
4245                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (useconfig == 1){' . M3_NL;
4246                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
4247                                                                         'html += \'<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\\\'\' + widgetId + \'\\\', \' + configId + \', \' + serialNo + \');return false;" rel="m3help" data-container="body" title="ウィジェット設定">' .
4248                                                                         '<img src="' . $rootUrl . self::CONFIG_ICON32_FILE . '" alt="ウィジェット設定" width="32" height="32" /></a>\';' . M3_NL;
4249                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4250                                 if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
4251                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 
4252                                                                                 '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="タイトル・スタイル調整">' .
4253                                                                                 '<img src="' . $rootUrl . self::ADJUST_ICON32_FILE . '" alt="タイトル・スタイル調整" width="32" height="32" /></a>\';' . M3_NL;
4254                                 }
4255                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (html != \'\'){' . M3_NL;
4256                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
4257                                                                                 'html = \'<div class="m3tooltip" style="display:none;">\' + html + \'<a class="m3closebox" href="javascript:void(0);" rel="m3help" data-container="body" title="閉じる">' . 
4258                                                                                 '<img src="' . $rootUrl . self::CLOSE_BOX_ICON32_FILE . '" alt="閉じる" width="11" height="11" /></a></div>\';' . M3_NL;
4259                                                                                 
4260                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).append(html);' . M3_NL;
4261                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4262                                 // クリックイベントの設定
4263                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).click(function(){' . M3_NL;
4264                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4265                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (tooltipObj.css(\'display\') == \'none\'){' . M3_NL;
4266                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (_m3ShowWidgetTool){' . M3_NL;
4267                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'tooltipObj.show();' . M3_NL;
4268                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
4269                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
4270                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.hide();' . M3_NL;
4271                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4272                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4273                                 // ウィジェットボーダーハイライト、ツールチップ表示
4274                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).hover(function(){' . M3_NL;
4275                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (_m3ShowWidgetTool){' . M3_NL;
4276                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(this).addClass(\'m3_widget_highlight\');' . M3_NL;
4277                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4278                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var pos = $(this).position();' . M3_NL;
4279                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var width = $(this).outerWidth();' . M3_NL;
4280                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var tooltipWidth = tooltipObj.outerWidth(true);' . M3_NL;
4281                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var x = pos.left + width - tooltipWidth;' . M3_NL;
4282                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var y = pos.top;' . M3_NL;
4283                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.css({position: "absolute",top: y + "px", left: x + "px"}).show();' . M3_NL;
4284                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4285                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}, function(){' . M3_NL;
4286                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).removeClass(\'m3_widget_highlight\');' . M3_NL;
4287                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
4288                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'tooltipObj.hide();' . M3_NL;
4289                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4290                                 // 閉じるボタン処理
4291                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3closebox\').click(function(event){' . M3_NL;
4292                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).children(\'.m3tooltip\').hide();' . M3_NL;
4293                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4294                                 // コンテンツ編集ボタンの位置修正
4295                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
4296                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var offset = $(this).offset();' . M3_NL;
4297                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).outerWidth();' . M3_NL;
4298                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3edittool\').each(function(){' . M3_NL;
4299                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).offset({left: offset.left});' . M3_NL;
4300                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).width(width);' . M3_NL;
4301                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
4302                                 $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4303                                 
4304                                 // コンテキストメニューを作成
4305                                 $this->initScript .= M3_INDENT_SPACE . 'var widgetWindow = \'<div class="m3_contextmenu" id="m3_widgetmenu" style="visibility:hidden;">\';' . M3_NL;
4306                                 $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'<ul>\';' . M3_NL;
4307                                 $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;
4308                                 if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
4309                                         $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;
4310                                 }
4311                                 $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</ul>\';' . M3_NL;
4312                                 $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</div>\';' . M3_NL;
4313                                 $this->initScript .= M3_INDENT_SPACE . '$("body").append(widgetWindow);' . M3_NL;
4314                                 $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').contextMenu(\'m3_widgetmenu\', {' . M3_NL;
4315                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'menuStyle: {' . M3_NL;
4316                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// border : "2px solid green",' . M3_NL;
4317                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'backgroundColor: \'#FFFFFF\',' . M3_NL;
4318                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'width: "150px",' . M3_NL;
4319                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'textAlign: \'left\',' . M3_NL;
4320                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'font: \'12px/1.5 Arial, sans-serif\'' . M3_NL;
4321                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4322                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'itemStyle: {' . M3_NL;
4323                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'padding: \'3px 3px\'' . M3_NL;
4324                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4325                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'bindings: {' . M3_NL;
4326                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wconfig\': function(t){' . M3_NL;
4327                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
4328                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
4329                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'alert("このウィジェットには設定画面がありません");' . M3_NL;
4330                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'return;' . M3_NL;
4331                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
4332                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowConfigWindow(attrs[\'widgetid\'], attrs[\'configid\'], attrs[\'serial\']);' . M3_NL;
4333                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '},' . M3_NL;
4334                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wadjust\': function(t){' . M3_NL;
4335                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
4336                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowAdjustWindow(attrs[\'configid\'], attrs[\'serial\'], M3_PAGE_ID, M3_PAGE_SUB_ID);' . M3_NL;
4337                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4338                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4339                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onContextMenu: function(e){' . M3_NL;
4340                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (_m3ShowWidgetTool){' . M3_NL;
4341                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'return true;' . M3_NL;
4342                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
4343                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'return false;' . M3_NL;
4344                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4345                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
4346                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onShowMenu: function(e, menu){' . M3_NL;
4347                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// メニュー項目の変更' . M3_NL;
4348                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var attrs = m3_splitAttr($(e.target).parents(\'dl\').attr(\'m3\'));' . M3_NL;
4349                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
4350                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(\'#m3_wconfig\', menu).remove();' . M3_NL;
4351                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
4352                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'return menu;' . M3_NL;
4353                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
4354                                 $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4355                                 
4356                                 // コンテンツの「非公開」表示
4357                                 $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3content_private\').each(function(){' . M3_NL;
4358 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
4359 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var top = pos.top;' . M3_NL;
4360 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var left = pos.left;' . M3_NL;
4361 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).css(\'width\');' . M3_NL;
4362 //                                      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var height = $(this).css(\'height\');' . M3_NL;
4363                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'<div class="m3content_overlay"><div><h2>非公開</h2></div></div>\';' . M3_NL;
4364                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).prepend(html);' . M3_NL;
4365                         //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var overlayObj = $(this).children(\'.m3content_overlay div\');' . M3_NL;
4366                         //      $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'overlayObj.css({ position:"absolute", top:top + "px", left:left + "px" }).show();' . M3_NL;
4367                                 $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
4368                         }
4369                 }
4370                 // ##### フロント画面のデフォルトのJavaスクリプト #####
4371 //                      if (!$gEnvManager->isAdminDirAccess()){
4372 //                              $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (jQuery().tooltip) $(\'[rel=tooltip]\').tooltip();' . M3_NL;          // 標準ツールチップ作成
4373 //                      }
4374                 // ポップアップメッセージがある場合は表示
4375                 if (!empty($this->popupMsg)){
4376                         $replaceStr .=  'alert("' . $this->popupMsg . '");' . M3_NL;
4377                 }
4378                 // テンプレートに応じた処理
4379                 if ($cleanType == 1){
4380                         // HTMLのクリーン処理が必要なときはコードを埋め込む
4381                         $this->initScript .= '    $(\'.PostHeaderIcons\').remove();' . M3_NL;// 不要なアイコン表示タグの削除
4382                         $this->initScript .= '    $(\'.PostMetadataHeader\').each(function(i){' . M3_NL;
4383                         $this->initScript .= '        if ($(this).text().trim() == \'\') $(this).remove();' . M3_NL;
4384                         $this->initScript .= '    });' . M3_NL;
4385                 }
4386                 
4387                 // 管理画面用スクリプト追加
4388                 $replaceStr .= $this->getLastContents();
4389                 
4390                 // 初期処理用スクリプト埋め込み
4391                 if (!empty($this->initScript)){
4392                         $replaceStr .= '$(function(){' . M3_NL;
4393                         $replaceStr .= $this->initScript;
4394                         $replaceStr .= '});' . M3_NL;
4395                 }
4396                 
4397                 //$replaceStr .= '// -->' . M3_NL;
4398                 //$replaceStr .= '</script>' . M3_NL;
4399                 $replaceStr .= '//]]>' . M3_NL;
4400                 $replaceStr .= '</script>' . M3_NL;
4401
4402                 // HEADタグに埋め込むCSS,JavaScript,任意文字列
4403                 if (count($this->headCss) > 0){
4404                         // CSSの場合は全体をstyleタグで囲む
4405                         $replaceStr .= '<style type="text/css">' . M3_NL;
4406                         $replaceStr .= '<!--' . M3_NL;
4407                         for ($i = 0; $i < count($this->headCss); $i++){
4408                                 $replaceStr .= $this->headCss[$i];
4409                         }
4410                         $replaceStr .= M3_NL . '//-->' . M3_NL;
4411                         $replaceStr .= '</style>' . M3_NL;
4412                 }
4413                 if (count($this->headScript) > 0){
4414                         // JavaScriptの場合は全体をscriptタグで囲む
4415                         //$replaceStr .= '<script type="text/javascript">' . M3_NL;
4416                         //$replaceStr .= '<!--' . M3_NL;
4417                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
4418                         $replaceStr .= '//<![CDATA[' . M3_NL;
4419                         for ($i = 0; $i < count($this->headScript); $i++){
4420                                 $replaceStr .= $this->headScript[$i];
4421                         }
4422                         //$replaceStr .= M3_NL . '//-->' . M3_NL;
4423                         //$replaceStr .= '</script>' . M3_NL;
4424                         $replaceStr .= M3_NL;
4425                         $replaceStr .= '//]]>' . M3_NL;
4426                         $replaceStr .= '</script>' . M3_NL;
4427                 }
4428                 if (count($this->headString) > 0){
4429                         // 任意文字列の場合はそのまま追加
4430                         for ($i = 0; $i < count($this->headString); $i++){
4431                                 $replaceStr .= $this->headString[$i];
4432                         }
4433                 }
4434                 return $replaceStr;
4435         }
4436         /**
4437          * 各部品のHTML出力
4438          *
4439          * @param string $position                      HTMLテンプレート上の書き出し位置
4440          * @param string $style                         ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
4441          * @param int    $templateVer           テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
4442          * @param array  $attr                          その他属性
4443          * @return string                                       出力コンテンツ
4444          */
4445         function getContents($position, $style = '', $templateVer = 0, $attr = array())
4446         {
4447                 static $render;         // HTML生成オブジェクト
4448                 global $gRequestManager;
4449                 global $gEnvManager;
4450                 
4451                 // ファイル名、ページ名を取得
4452                 $filename       = $gEnvManager->getCurrentPageId();
4453                 $subId          = $gEnvManager->getCurrentPageSubId();
4454                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
4455
4456                 // ポジション名表示モードに応じて出力を作成
4457                 $contents = '';         // 出力コンテンツ
4458                 switch ($this->showPositionMode){
4459                         case 0:         // 通常画面
4460                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
4461                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
4462                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
4463                                         if ($ret){      // 1行以上データが取得できたとき
4464                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
4465                                                 $this->pageDefPosition = $position;
4466                                         } else {
4467                                                 $this->pageDefRows = array();
4468                                                 $this->pageDefPosition = '';
4469                                         }
4470                                 }
4471                                 // ウィジェットを実行
4472                                 $count = count($this->pageDefRows);
4473                                 
4474                                 if ($templateVer == 0){                 // ########## Joomla!v1.0テンプレートの場合 ##########
4475                                         ob_start();// バッファ作成
4476
4477                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
4478                                         $widgetHeaderType = $this->getTemplateWidgetHeaderType();
4479                                         for ($i = 0; $i < $count; $i++){
4480                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4481                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4482                                                 
4483                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4484                                                 // キャッシュデータがあるときはキャッシュデータを使用
4485                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4486
4487                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4488                                                         ob_clean();
4489                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $launchWidgetTag, $titleTag, $widgetHeaderType);
4490                                                         if (!$ret) break;
4491                                                         $widgetContent = ob_get_contents();
4492                                                         
4493                                                         // ウィジェット共通のコンテンツ処理
4494                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4495
4496                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4497                                                 //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4498                                                                                 
4499                                                         // キャッシュデータを設定
4500                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4501                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4502                                                                                                                         
4503                                                         // ウィジェットの外枠タグを設定
4504                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4505                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4506                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4507                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
4508                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4509                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4510                                                                 // ウィジェット表示タイプによる表示制御
4511                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4512                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
4513                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4514                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4515                                                                 if (!empty($controlType)){
4516                                                                         switch ($controlType){
4517                                                                                 case 1:                 // ログイン時のみ表示
4518                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4519                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
4520                                                                                         break;
4521                                                                                 case 2:                 // 非ログイン時のみ表示
4522                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4523                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
4524                                                                                         break;
4525                                                                                 default:
4526                                                                                         break;
4527                                                                         }
4528                                                                 }
4529                                                                 if (!empty($pageState)){
4530                                                                         switch ($pageState){
4531                                                                                 case 1:                 // トップ時のみ表示
4532                                                                                         if (!$this->isPageTopUrl){
4533                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
4534                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
4535                                                                                         }
4536                                                                                         break;
4537                                                                                 default:
4538                                                                                         break;
4539                                                                         }
4540                                                                 }
4541                 
4542                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4543                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4544                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4545                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4546                                                                 $shared = '0';          // 共通属性があるかどうか
4547                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4548                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4549                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4550                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
4551                                                         } else {
4552                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4553                                                                 $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4554                                                         }
4555                                                 } else {                // キャッシュデータがあるとき
4556                                                         $widgetContent = $cacheData;
4557                                                         
4558                                                         // HTMLのメタタグを設定
4559                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4560                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4561                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4562                                                 }
4563                                                 $contents .= $widgetContent;
4564                                                 
4565                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4566                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4567                                                 if (!empty($exportCss)){
4568                                                         // ウィジェットのタグIDを変換
4569                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4570                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4571                                                         $this->addExportCss($exportCss);
4572                                                 }
4573                                         }
4574                                         ob_end_clean();         // バッファ破棄
4575                                         
4576                                         if ($i < $count) return '';// 処理中断のときは終了
4577                                 } else if ($templateVer == 100){                        // ########## WordPressテンプレートの場合 ##########
4578                                         ob_start();// バッファ作成
4579
4580                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
4581                                         //$widgetHeaderType = $this->getTemplateWidgetHeaderType();
4582                                         for ($i = 0; $i < $count; $i++){
4583                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4584                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4585                                                 
4586                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4587                                                 // キャッシュデータがあるときはキャッシュデータを使用
4588                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4589
4590                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4591                                                         // WordPressウィジェット用のパラメータ設定
4592                                                         $gEnvManager->setWpWidgetClass('');                             // ウィジェットクラス名初期化
4593                                                         
4594                                                         ob_clean();
4595                                         //              $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $launchWidgetTag, $titleTag, $widgetHeaderType);
4596                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $launchWidgetTag, $titleTag, 0/*タイトル出力なし*/);
4597                                                         if (!$ret) break;
4598                                                         $widgetContent = ob_get_contents();
4599
4600                                                         // WordPressウィジェット用のパラメータ設定
4601                                                         $widgetClassName = $gEnvManager->getWpWidgetClass();                            // ウィジェットクラス名
4602                                                         
4603                                                         $trimContent = trim($widgetContent);
4604                                                         if (!empty($trimContent)){              // 出力が空でない場合
4605                                                         
4606                                                                 // オブジェクト作成
4607                                                                 if (!isset($render)) $render = new WPRender();          // WordPress用HTML生成オブジェクト
4608                                                         
4609                                                                 // デフォルトのウィジェットタイトル取得
4610                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
4611                                         
4612                                                                 // Joomla用のパラメータを取得
4613                                                                 //$joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
4614
4615                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
4616                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
4617                                         
4618                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
4619                                                                 $title = $this->pageDefRows[$i]['pd_title'];
4620                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
4621                                                                         if (empty($title)) $title = $defaultTitle;
4622                                                                 } else {
4623                                                                         $title = '';                    // タイトルは非表示
4624                                                                 }
4625                                                         
4626                                                                 // 強制的にタイトルを非表示にする場合はタイトルを修正
4627                                                                 if (!empty($title) && $this->pageDefRows[$i]['wd_hide_title']){
4628                                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4629                                                                                 $title = '[' . $title . ']';
4630                                                                         } else {
4631                                                                                 $title = '';
4632                                                                         }
4633                                                                 }
4634                                                                 
4635                                                                 // WordPress用パラメータ作成
4636                                                                 $params = array();                              // ウィジェットごとの属性
4637                                                                 if (!empty($widgetClassName))  $params['moduleclass'] = $widgetClassName;       // ウィジェットクラス名
4638                                                                                 
4639                                                                 // ウィジェット生成
4640                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . ($i + 1);                                // ウィジェット識別用ユニークタグ
4641                                                                 
4642                                                                 if (strcmp($position, 'main') == 0){// メイン部のとき
4643                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer, $widgetTag);
4644                                                                 } else {
4645                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer, $widgetTag);
4646                                                                 }
4647                                                         
4648                                                                 // ウィジェット共通のコンテンツ処理
4649                                                         //      $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4650
4651                                                                 // ウィジェットの内枠(コンテンツ外枠)を設定
4652                                                         //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4653                                                         }
4654                                                         
4655                                                         // キャッシュデータを設定
4656                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4657                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4658                                                                                                                         
4659                                                         // ウィジェットの外枠タグを設定
4660                                         //              $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4661                                         //              $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4662                                         //              if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4663                                         //              $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
4664                                         //              $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4665                                         
4666                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4667                                                                 // ウィジェット表示タイプによる表示制御
4668                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4669                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
4670                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4671                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4672                                                                 if (!empty($controlType)){
4673                                                                         switch ($controlType){
4674                                                                                 case 1:                 // ログイン時のみ表示
4675                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4676                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
4677                                                                                         break;
4678                                                                                 case 2:                 // 非ログイン時のみ表示
4679                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4680                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
4681                                                                                         break;
4682                                                                                 default:
4683                                                                                         break;
4684                                                                         }
4685                                                                 }
4686                                                                 if (!empty($pageState)){
4687                                                                         switch ($pageState){
4688                                                                                 case 1:                 // トップ時のみ表示
4689                                                                                         if (!$this->isPageTopUrl){
4690                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
4691                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
4692                                                                                         }
4693                                                                                         break;
4694                                                                                 default:
4695                                                                                         break;
4696                                                                         }
4697                                                                 }
4698                                                                 
4699                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4700                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4701                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4702                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4703                                                                 $shared = '0';          // 共通属性があるかどうか
4704                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4705                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4706                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4707                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
4708                                                         } else {
4709                                                 //              $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4710                                                 //              $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4711                                                         }
4712                                                 } else {                // キャッシュデータがあるとき
4713                                                         $widgetContent = $cacheData;
4714                                                         
4715                                                         // HTMLのメタタグを設定
4716                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4717                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4718                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4719                                                 }
4720                                                 $contents .= $widgetContent;
4721                                                 
4722                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4723                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4724                                                 if (!empty($exportCss)){
4725                                                         // ウィジェットのタグIDを変換
4726                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4727                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4728                                                         $this->addExportCss($exportCss);
4729                                                 }
4730                                         }
4731                                         ob_end_clean();         // バッファ破棄
4732                                         
4733                                         if ($i < $count) return '';// 処理中断のときは終了
4734                                 } else {                        // ########## Joomla!v1.5テンプレートの場合 ##########
4735                                         // テンプレート側で指定されたメニューの表示属性を設定
4736                                         $gEnvManager->setMenuAttr($attr);
4737                                         
4738                                         // ポジションタイプ
4739                                         $posType = '';
4740                                         if (!empty($attr['type'])) $posType = $attr['type'];
4741                                         
4742                                         for ($i = 0; $i < $count; $i++){
4743                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
4744                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
4745                                                                                                                 
4746                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
4747                                                 // キャッシュデータがあるときはキャッシュデータを使用
4748                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
4749                                                         
4750                                                 if (empty($cacheData)){         // キャッシュデータがないとき
4751                                                         // ウィジェットのタイトルを初期化
4752                                                         $gEnvManager->setCurrentWidgetTitle('');
4753                                                 
4754                                                         // Joomla用のパラメータを初期化
4755                                                         $gEnvManager->setCurrentWidgetJoomlaParam(array());
4756                                                         
4757                                                         // ウィジェットの出力を取得
4758                                                         ob_clean();
4759                                                         $ret = $this->pageDefLoop($position, $i, $this->pageDefRows[$i], $style, $launchWidgetTag, $titleTag, 0/*タイトル出力なし*/);
4760                                                         $widgetContent = ob_get_contents();
4761
4762                                                         $trimContent = trim($widgetContent);
4763                                                         if (!empty($trimContent)){              // 出力が空でない場合
4764                                                                 $isRendered = false;            // Joomla!の描画処理を行ったかどうか
4765                                                                 if (!empty($this->pageDefRows[$i]['pd_use_render'])){                   // Joomla!の描画処理を使用する場合
4766                                                                         // Joomla!ウィジェットの出力に埋め込む
4767                                                                         if (strcasecmp($style, 'none') != 0){
4768                                                                                 // オブジェクト作成
4769                                                                                 if (!isset($render)) $render = new JRender();
4770                                                                 
4771                                                                                 // デフォルトのウィジェットタイトル取得
4772                                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
4773                                                                 
4774                                                                                 // Joomla用のパラメータを取得
4775                                                                                 $joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
4776
4777                                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
4778                                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
4779                                                                 
4780                                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
4781                                                                                 $title = $this->pageDefRows[$i]['pd_title'];
4782                                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
4783                                                                                         if (empty($title)) $title = $defaultTitle;
4784                                                                                 } else {
4785                                                                                         $title = '';                    // タイトルは非表示
4786                                                                                 }
4787                                                                         
4788                                                                                 // 強制的にタイトルを非表示にする場合はタイトルを修正
4789                                                                                 if (!empty($title) && $this->pageDefRows[$i]['wd_hide_title']){
4790                                                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4791                                                                                                 $title = '[' . $title . ']';
4792                                                                                         } else {
4793                                                                                                 $title = '';
4794                                                                                         }
4795                                                                                 }
4796                                                                                 
4797                                                                                 // Joomla用パラメータ作成
4798                                                                                 $params = array();                              // ウィジェットごとの属性
4799                                                                                 $widgetType = $this->pageDefRows[$i]['wd_type'];                // ウィジェットタイプ
4800                                                                                 
4801                                                                                 // オプションのJoomlaクラス(縦型メニュー(art-vmenu)等)
4802                                                                                 $joomlaClass = $this->pageDefRows[$i]['wd_joomla_class'];               // 「wd_joomla_class」は使っていない?
4803                                                                                 if (!empty($joomlaClass)) $params['moduleclass_sfx'] = $joomlaClass;
4804                                                                                 if (isset($joomlaParam['moduleclass_sfx'])) $params['moduleclass_sfx'] = $joomlaParam['moduleclass_sfx'];// ウィジェットでjoomla用パラメータの設定があるとき
4805                                                                 
4806                                                                                 if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
4807                                                                                         $moduleContent = '';
4808                                                                                         
4809                                                                                         // ウィジェットタイプがメニューのときはナビゲーションメニューを生成
4810                                                                                         if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4811                                                                 
4812                                                                                         // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
4813                                                                                         if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4814                                                                                         $widgetContent = $moduleContent;
4815                                                                                 } else {
4816                                                                                         // ウィジェットタイプに応じた処理を実行
4817                                                                                         if ($widgetType == 'breadcrumb'){               // パンくずリスト
4818                                                                                                 $moduleContent = '';
4819                                                                                                 
4820                                                                                                 if (empty($launchWidgetTag)){                   // 遅延実行の場合はここでパンくずリストを作成しないで遅延実行時に行う
4821                                                                                                         $moduleContent = $render->getBreadcrumbContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4822                                                                                                 } else {
4823                                                                                                         $moduleContent = $launchWidgetTag;              // 遅延実行ウィジェットのタグのみ取得
4824                                                                                                 }
4825                                                                                                 
4826                                                                                                 // パンくずリストで作成できないときはデフォルトの出力を取得
4827                                                                                                 if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4828                                                                                                 $widgetContent = $moduleContent;
4829                                                                                         } else {
4830                                                                                                 if (strcmp($position, 'main') == 0){// メイン部のとき
4831                                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4832                                                                                                         // ウィジェットの内枠はレンダーで設定
4833                                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4834                                                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4835                                                                                                 } else {                // その他の位置のとき
4836                                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4837                                                                                                         // ウィジェットの内枠はレンダーで設定
4838                                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4839                                                                                         
4840                                                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4841                                                                                                 }
4842                                                                                         }
4843                                                                                 }
4844 /*                                                                              if (strcmp($position, 'main') == 0){// メイン部のとき
4845                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4846                                                                                         // ウィジェットの内枠はレンダーで設定
4847                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4848                                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4849 //                                                                              } else if (strStartsWith($position, 'user') ||                          // ナビゲーションメニュー位置の場合
4850                                                                                 } else if (strcasecmp($position, 'user3') == 0 ||                               // ナビゲーションメニュー位置の場合
4851                                                                                                 strcasecmp($position, 'position-1') == 0 ||                             // Joomla!v2.5テンプレート対応
4852                                                                                                 strcasecmp($posType, 'hmenu') == 0){            // Joomla!v3テンプレート対応
4853
4854                                                                                         $moduleContent = '';
4855                                                                                         if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
4856                                                                                                 if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4857                                                                         
4858                                                                                                 // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
4859                                                                                                 if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4860                                                                                         } else {
4861                                                                                                 $moduleContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4862                                                                                         }
4863                                                                                         $widgetContent = $moduleContent;
4864                                                                                         
4865                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定。メニュー処理後に付加。
4866                                                                                         // ウィジェットの内枠はレンダーで設定
4867                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4868                                                                                 } else {                // その他の位置のとき
4869                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4870                                                                                         // ウィジェットの内枠はレンダーで設定
4871                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4872                                                                                         
4873                                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
4874                                                                                 }*/
4875                                                                                 $isRendered = true;             // Joomla!の描画処理を行ったかどうか
4876                                                                         }
4877                                                                 }
4878                                                                 if (!$isRendered){              // Joomla!の描画処理を行っていない場合
4879                                                                         // ウィジェット共通のコンテンツ処理
4880                                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
4881                                                                         
4882                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
4883                                                                 //      $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
4884                                                                 }
4885                                                         }
4886                                                         if (!$ret) return '';           // 処理中断のときは終了
4887                                                         
4888                                                         // キャッシュデータを設定
4889                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
4890                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
4891                                                                                                                         
4892                                                         // ウィジェットの外枠タグを設定
4893                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
4894                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
4895                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
4896                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;  // ポジションブロッククラス
4897                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
4898                                                         if ($this->isPageEditable){             // フロント画面ページ編集可能モードのとき
4899                                                                 // ウィジェット表示タイプによる表示制御
4900                                                                 $widgetStatusClass = '';// ウィジェットの状態表示クラス
4901                                                                 $widgetStatusLabelOption = '';          // ウィジェット状態表示ラベル
4902                                                                 $controlType = $this->pageDefRows[$i]['pd_view_control_type'];
4903                                                                 $pageState = $this->pageDefRows[$i]['pd_view_page_state'];
4904                                                                 if (!empty($controlType)){
4905                                                                         switch ($controlType){
4906                                                                                 case 1:                 // ログイン時のみ表示
4907                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4908                                                                                         $widgetStatusLabelOption .= ' data-bg-text="ログイン時のみ表示"';
4909                                                                                         break;
4910                                                                                 case 2:                 // 非ログイン時のみ表示
4911                                                                                         $widgetStatusClass .= ' ' . self::WIDGET_LOGIN_STATUS_CLASS;
4912                                                                                         $widgetStatusLabelOption .= ' data-bg-text="非ログイン時のみ表示"';
4913                                                                                         break;
4914                                                                                 default:
4915                                                                                         break;
4916                                                                         }
4917                                                                 }
4918                                                                 if (!empty($pageState)){
4919                                                                         switch ($pageState){
4920                                                                                 case 1:                 // トップ時のみ表示
4921                                                                                         if (!$this->isPageTopUrl){
4922                                                                                                 $widgetStatusClass .= ' ' . self::WIDGET_INVISIBLE_CLASS;               // ページトップ(サブページ内のトップ位置)でなければ非表示
4923                                                                                                 $widgetStatusLabelOption .= ' data-bg-text="非表示中"';
4924                                                                                         }
4925                                                                                         break;
4926                                                                                 default:
4927                                                                                         break;
4928                                                                         }
4929                                                                 }
4930                         
4931                                                                 //$editInfo = 'widgetid:' . $this->pageDefRows[$i]['wd_id'];
4932                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
4933                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
4934                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
4935                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
4936                                                                 $shared = '0';          // 共通属性があるかどうか
4937                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
4938                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4939                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4940                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget' . $widgetStatusClass . '" rel="#m3editwidget" ' . $m3Option . $widgetStatusLabelOption . '>' . $widgetContent . '</div>';
4941                                                         } else {
4942                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4943                                                                 $widgetContent = '<div id="' . $widgetTag . '">' . $widgetContent . '</div>';
4944                                                         }
4945                                                 } else {                // キャッシュデータがあるとき
4946                                                         $widgetContent = $cacheData;
4947                                                         
4948                                                         // HTMLのメタタグを設定
4949                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
4950                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
4951                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
4952                                                 }
4953                                                 $contents .= $widgetContent;
4954                                                 
4955                                                 // ##### 外部出力用のCSSがある場合は追加 #####
4956                                                 $exportCss = $this->pageDefRows[$i]['pd_css'];
4957                                                 if (!empty($exportCss)){
4958                                                         // ウィジェットのタグIDを変換
4959                                                         $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
4960                                                         $exportCss = str_replace(M3_TAG_START . M3_TAG_MACRO_WIDGET_CSS_ID . M3_TAG_END, $widgetTag, $exportCss);
4961                                                         $this->addExportCss($exportCss);
4962                                                 }
4963                                         }
4964                                 }
4965                         
4966                                 if ($position == 'main'){               // メイン部のときは、メッセージを出力
4967                                         /*if (strlen($this->popupMsg) > 0){
4968                                                 echo "\n<script language=\"javascript\">alert('" . addslashes($this->popupMsg) . "');</script>";
4969                                         }*/
4970                                 } else if ($position == 'debug'){               // デバッグ文出力
4971                                 } else {
4972
4973                                 }
4974                                 break;
4975                         case 1:         // ポジション表示
4976                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:3px solid #f00;color:#700;">ポジション名: ';
4977                                 $contents .= '<b>' . $position . '</b>';
4978                                 $contents .= '</div>';
4979                                 
4980                                 // ポジションを保存
4981                                 if (!in_array($position, $this->defPositions)) $this->defPositions[] = $position;       // テンプレート上のポジション
4982                                 break;
4983                         case 2:         // ポジション表示(ウィジェット付き)
4984                                 $rev = '555';                   // データのリビジョン番号
4985                                 // ポジションのHTMLタグIDを作成
4986                                 $num = 0;
4987                                 $posId = '';
4988                                 for ($i = 0; $i < 100; $i++){
4989                                         $posId = $position . '_' . $num;
4990                                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
4991                                         if (!in_array($viewPosId, $this->viewPosId)) break;
4992                                         $num++;
4993                                 }
4994                                 $this->viewPosId[] = $viewPosId;// IDを保存
4995                                 
4996                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
4997                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
4998                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows);
4999                                         if ($ret){      // 1行以上データが取得できたとき
5000                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
5001                                                 $this->pageDefPosition = $position;
5002                                         } else {
5003                                                 $this->pageDefRows = array();
5004                                                 $this->pageDefPosition = '';
5005                                         }
5006                                 }
5007                                 $posHead = '';
5008                                 // ナビゲーション型のポジションの場合はアイコン付加
5009                                 //if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
5010                                 if ($style == self::WIDGET_STYLE_NAVMENU){
5011                                         $posHead = self::POS_HEAD_NAV_MENU;             // 特殊ポジションブロックのアイコン付加(ナビゲーションメニュー型)
5012                                 } else if (strcasecmp($position, 'main') == 0){
5013                                         $posHead = self::POS_HEAD_MAIN;         // 特殊ポジションブロックのアイコン付加(メイン型)
5014                                 }
5015                                 $contents .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;             // リビジョン番号を付加
5016                                 $contents .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
5017                                 
5018                                 // ウィジェットイメージを表示
5019                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
5020                                 //$contents .= $this->getWidgetList($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $widgetTagHead, $this->pageDefRows);
5021                                 $contents .= $this->getWidgetList($filename, $subId, $widgetTagHead, $this->pageDefRows);
5022
5023                                 $contents .= '</div>' . M3_NL;
5024                                 break;
5025                         default:
5026                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:1px solid #f00;color:#700;">param error</div>';
5027                                 break;
5028                 }
5029                 // ポジションを保存
5030                 $this->viewPositions[] = $position;
5031
5032                 return $contents;
5033         }
5034         /**
5035          * 各部品のHTML出力(WordPressテンプレート専用)
5036          *
5037          * @param string $position                      HTMLテンプレート上の書き出し位置
5038          * @param bool $showTitle                       タイトルを表示するかどうか
5039          * @return string                                       出力コンテンツ
5040          */
5041         function getWPContents($position, $showTitle = true)
5042         {
5043                 if ($showTitle){
5044                         return $this->getContents($position, self::WIDGET_STYLE_WORDPRESS/*WordPressテンプレート用出力*/, 100/*WordPressテンプレート*/);
5045                 } else {
5046                         return $this->getContents($position, self::WIDGET_STYLE_WORDPRESS_NOTITLE/*WordPressテンプレート(タイトルなし)用出力*/, 100/*WordPressテンプレート*/);
5047                 }
5048         }
5049         /**
5050          * その他のポジションブロックデータを取得
5051          *
5052          * @param string                ポジション作成用タグ
5053          */
5054         function getRestPositionData()
5055         {
5056                 global $gEnvManager;
5057                 
5058                 $restPositionData = '';
5059                 $rev = '888';
5060                 $pageId = $gEnvManager->getCurrentPageId();
5061                 $subId = $gEnvManager->getCurrentPageSubId();
5062                 
5063                 $restPositions = array_values(array_diff($this->defPositions/*全ポジション*/, $this->viewPositions/*表示済みポジション*/));
5064                 $positionCount = count($restPositions);
5065                 for ($i = 0; $i < $positionCount; $i++){
5066                         $posHead = '';          // アイコン付加用
5067                         $position = $restPositions[$i];
5068                         $posId = $position . '_0';
5069                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
5070
5071                         // 画面情報を取得
5072                         $ret = $this->db->getPageDef($pageId, $subId, $position, $rows);
5073                         if ($ret){
5074                                 //$pageDefRows = $rows;                 // ページ定義レコード
5075                                                 
5076                                 $restPositionData .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">';             // リビジョン番号を付加
5077                                 $restPositionData .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>';
5078                         
5079                                 // ウィジェットイメージを表示
5080                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
5081                                 $contents = $this->getWidgetList($pageId, $subId, $widgetTagHead, $rows);
5082                                 $contents = str_replace(M3_NL, '', $contents);
5083                                 $contents = str_replace('\'', '\\\'', $contents);
5084                                 $restPositionData .= $contents;
5085                                 $restPositionData .= '</div>';
5086                                 
5087                                 $this->viewPosId[] = $viewPosId;// IDを保存
5088                         }
5089                 }
5090                 return $restPositionData;
5091         }
5092         /**
5093          * ウィジェット共通のコンテンツ追加処理
5094          *
5095          * @param string $src                           ウィジェット出力
5096          * @param array $pageDefParam           画面定義レコード
5097          * @return string                                       コンテンツを付加したウィジェット出力
5098          */
5099         function _addOptionContent($src, $pageDefParam)
5100         {
5101                 // 前後コンテンツ追加
5102                 $dest = $pageDefParam['pd_top_content'] . $src . $pageDefParam['pd_bottom_content'];
5103                 
5104                 // 「もっと読む」ボタンを追加
5105                 if ($pageDefParam['pd_show_readmore']){
5106                         $title = $pageDefParam['pd_readmore_title'];
5107                         if (empty($title)) $title = self::DEFAULT_READMORE_TITLE;
5108                         $dest .= '<div><a href="' . convertUrlToHtmlEntity($pageDefParam['pd_readmore_url']) . '">' . convertToHtmlEntity($title) . '</a></div>';
5109                 }
5110                 return $dest;
5111         }
5112         /**
5113          * BODYタグに付加するスタイルを取得(管理画面用)
5114          *
5115          * @param string                CSS文字列
5116          */
5117         function getBodyStyle()
5118         {
5119                 // 画面透過モードのときスタイルを追加
5120                 $transCss = '';
5121                 if ($this->isTransparentMode) $transCss = ' style="background-color:transparent;"';
5122                 return $transCss;
5123         }
5124         /**
5125          * 各ポジションのウィジェット数を取得
5126          *
5127          * @param string $position              HTMLテンプレート上の書き出し位置
5128          * @return int                                  ウィジェットの数
5129          */
5130         function getWidgetsCount($position)
5131         {
5132                 global $gRequestManager;
5133                 global $gEnvManager;
5134                 static $widgetCountArray = array();
5135
5136                 // 管理画面へのアクセスでログインされていないときは0を返す
5137                 if ($gEnvManager->isAdminDirAccess() && !$gEnvManager->isSystemManageUser()){           // 管理画面へのアクセスのときでシステム運用権限がない場合
5138                         return 0;
5139                 }
5140                                 
5141                 // 実行コマンドを取得
5142                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
5143                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                                     // 管理画面(ウィジェットなしポジション表示)のとき
5144                         $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){              // 管理画面(ウィジェット付きポジション表示)のとき
5145                         return 1;               // ウィジェットが設定されていないポジション名を表示するために固定で値を返す
5146                 }
5147                 
5148                 // 単一ポジション以外の設定のときは固定で返す(or等)
5149                 $pos = strpos($position, ' ');
5150                 if ($pos !== false) return 1;
5151                 
5152                 // 既にウィジェット数が取得されている場合は保存値を返す
5153                 $widgetCount = $widgetCountArray[$position];
5154                 if (isset($widgetCount)) return $widgetCount;
5155                 
5156                 // ファイル名、ページ名を取得
5157                 $filename       = $gEnvManager->getCurrentPageId();
5158                 $subId          = $gEnvManager->getCurrentPageSubId();
5159                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
5160
5161                 // 取得しようとするページ定義のポジションが既に取得しているポジションと異なるときはデータを取得
5162                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // 現在取得しているページ定義のポジション
5163                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
5164                         if ($ret){      // 1行以上データが取得できたとき
5165                                 $this->pageDefRows = $rows;                     // ページ定義レコード
5166                                 $this->pageDefPosition = $position;
5167                         } else {
5168                                 $this->pageDefRows = array();
5169                                 $this->pageDefPosition = '';
5170                         }
5171                 }
5172                 // ### ウィジェット数を取得 ###
5173                 // テンプレートのカラム制御を行うためにウィジェット表示条件でウィジェット数を取得
5174                 $widgetCount = 0;
5175                 $rowCount = count($this->pageDefRows);
5176                 for ($i = 0; $i < $rowCount; $i++){
5177         //              $condition = trim($this->pageDefRows[$i]['wd_visible_condition']);
5178                         $condition = trim($this->pageDefRows[$i]['pd_visible_condition']);
5179                         if (empty($condition)){                 // ウィジェット表示条件が設定されていない場合はウィジェットを表示
5180                                 $widgetCount++;
5181                         } else {                        // ウィジェット表示条件が設定されている場合はパラメータをチェック
5182                                 $conds = explode(';', $condition);
5183                                 for ($j = 0; $j < count($conds); $j++){
5184                                         $pos = strpos($conds[$j], '=');
5185                                         if ($pos !== false){            // URLクエリーパラメータ条件がマッチした場合はウィジェットを表示
5186                                                 list($key, $value) = explode('=', trim($conds[$j]));
5187                                                 $key = trim($key);
5188                                                 $value = trim($value);
5189                                                 if (!empty($key) && !empty($value)){
5190                                                         $requestValue = $gRequestManager->trimValueOf($key);
5191                                                         if ($value == $requestValue) $widgetCount++;
5192                                                 }
5193                                         }
5194                                 }
5195                         }
5196                 }
5197 //              $widgetCount = count($this->pageDefRows);
5198                 $widgetCountArray[$position] = $widgetCount;
5199                 return $widgetCount;
5200         }
5201         /**
5202          * ウィジェットのページ定義シリアル番号からウィジェットCSS IDを取得
5203          *
5204          * @param int $defSerial                ページ定義シリアル番号
5205          * @param string $pageId                ページID
5206          * @param string $subpage       ページサブID
5207          * @param string $position              表示位置ID
5208          * @return string                               CSSエレメントID
5209          */
5210         function getWidgetCssId($defSerial, $pageId, $pageSubId, $position)
5211         {
5212                 $elementId = '';
5213                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
5214                 if ($ret){
5215                         $rowCount = count($rows);
5216                         for ($i = 0; $i < $rowCount; $i++){
5217                                 $row = $rows[$i];
5218                                 if ($row['pd_serial'] == $defSerial){
5219                                         $elementId = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
5220                                         break;
5221                                 }
5222                         }
5223                 }
5224                 return $elementId;
5225         }
5226         /**
5227          * ウィジェット情報取得
5228          *
5229          * 画面作成機能でウィジェット情報を取得するためのAjaxインターフェイス
5230          *
5231          * @param RequestManager $request               HTTPリクエスト処理クラス
5232          */
5233         function getWidgetInfoByAjax($request)
5234         {
5235                 global $gEnvManager;
5236                 global $gDesignManager;
5237                 global $gCacheManager;
5238                 
5239                 // アクセスするページIDからPC用、携帯用、スマートフォン用かを判断
5240                 $widgetDeviceType = 0;          // 端末タイプをPC用に初期化
5241                 $pageId         = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
5242                 $pageSubId      = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
5243                 $mobilePageIdPrefix = M3_DIR_NAME_MOBILE . '_';
5244                 $smartphonePageIdPrefix = M3_DIR_NAME_SMARTPHONE . '_';
5245                 if (strncmp($pageId, $mobilePageIdPrefix, strlen($mobilePageIdPrefix)) == 0){
5246                         $widgetDeviceType = 1;          // 携帯用
5247                 } else if (strncmp($pageId, $smartphonePageIdPrefix, strlen($smartphonePageIdPrefix)) == 0){
5248                         $widgetDeviceType = 2;          // スマートフォン用
5249                 }
5250
5251                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
5252                 if ($task == 'list'){
5253                         // ウィジェット一覧を取得
5254                         $ret = $this->db->getAvailableWidgetList($widgetDeviceType, $rows);
5255                         if ($ret){
5256                                 $currentCategoryId = '_none';           // 現在のウィジェットカテゴリー初期化
5257                                 for ($i = 0; $i < count($rows); $i++){
5258                                         $widgetId = $rows[$i]['wd_id'];
5259                                         $desc = $rows[$i]['wd_description'];
5260                                         $widgetTag = self::WIDGET_TYPE_TAG_HEAD . $widgetId;
5261                         //              $categoryId = $rows[$i]['wd_category_id'];
5262                                         $categoryId = $rows[$i]['pid'];         // 親カテゴリーID
5263                                         
5264                                         // カテゴリーの開始タグを追加
5265                                         if ($categoryId != $currentCategoryId){
5266                                                 if ($i > 0){
5267                                                         echo '</dd>' . M3_NL;
5268                                                         echo '</dl>' . M3_NL;
5269                                                 }
5270                                                 echo '<dl class="m3accordion">' . M3_NL;
5271                                 //              echo '<dt>' . $rows[$i]['wt_name'] . '</dt>' . M3_NL;
5272                                                 echo '<dt>' . $rows[$i]['pname'] . '</dt>' . M3_NL;                     // 親カテゴリー名
5273                                                 echo '<dd>' . M3_NL;
5274                                                 
5275                                                 // 現在のカテゴリー更新
5276                                                 $currentCategoryId = $categoryId;
5277                                         }
5278                                         
5279                                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
5280                                         if ($gEnvManager->getUseSslAdmin()){
5281                                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
5282                                                 $image = $gEnvManager->getSslUrl($image);
5283                                         }
5284                                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
5285                                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
5286                                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
5287                                         $imageTag .= ' />';
5288                                         
5289                                         // ウィジェット機能マーク
5290                                         $widgetMark = '';
5291                                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メイン型ウィジェット
5292                                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
5293
5294                                         // ウィジェット機能一覧
5295                                         $functionMark = '';
5296                                         if (!empty($rows[$i]['wd_template_type'])){             // 対応テンプレートタイプ
5297                                                 $templateTypeArray = explode(',', $rows[$i]['wd_template_type']);
5298                                                 if (in_array('bootstrap', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_BOOTSTRAP;           // Bootstrap型テンプレート対応
5299                                                 if (in_array('wordpress', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_WORDPRESS;           // WordPress型テンプレート対応
5300                                         }
5301                                         if (!empty($functionMark)) $functionMark = '<hr />' . $functionMark;
5302                         
5303                                         echo '<dl class="m3_widgetlist_item" id="' . $widgetTag . '">' . M3_NL;
5304                                         echo '<dt>' . $widgetMark . $rows[$i]['wd_name'] . '</dt>' . M3_NL;                     // ウィジェット名
5305                                         echo '<dd><table style="width:100%;"><tr style="vertical-align:top;"><td style="width:35px;">' . $imageTag . '</td><td>' . $desc . '</td></tr></table>';
5306                                         echo $functionMark . '</dd>' . M3_NL;
5307                                         echo '</dl>' . M3_NL;
5308                                         
5309                                         // カテゴリーの終了タグを追加
5310                                         if ($i == count($rows) - 1){
5311                                                 echo '</dd>' . M3_NL;
5312                                                 echo '</dl>' . M3_NL;
5313                                         }
5314                                 }
5315                         }
5316                 } else if ($task == 'wget' || $task == 'wdelete' || $task == 'wtoggle' || $task == 'wadd' || $task == 'wmove'){ // ウィジェット再取得、ウィジェット削除,ウィジェット共通属性変更、ウィジェット追加、ウィジェット移動のとき
5317                         $rev    = $request->trimValueOf('rev');                 // リビジョン
5318                         $serial = $request->trimValueOf('serial');
5319                         $position = $request->trimValueOf('pos');
5320                         $widgetsStr = $request->trimValueOf('widgets');
5321                         if (empty($widgetsStr)){
5322                                 $widgets = array();
5323                         } else {
5324                                 $widgets = explode(',', $widgetsStr);
5325                         }
5326                         $shared = $request->trimValueOf('shared');
5327                         $updatepos = explode(',', $request->trimValueOf('updatepos'));
5328                         $index = $request->trimValueOf('index');
5329                         
5330                         // 処理ごとのパラメータ
5331                         if ($task == 'wmove'){
5332                                 $positions = explode(',', $position);
5333                                 if (count($positions) >= 2){
5334                                         $position = $positions[0];
5335                                         $position2 = $positions[1];
5336                                 } else {
5337                                         $position = $positions[0];
5338                                         $position2 = '';
5339                                 }
5340                         }
5341                         // ##### エラーチェック #####
5342                         $isErr = false;
5343                         // リビジョンのエラーチェック
5344                         $rev = '111';                   // データのリビジョン番号
5345
5346                         // 変更前データ取得
5347                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);    // 0レコードでも正常とする
5348                         
5349                         // 変更前のウィジェットのシリアル番号をチェック
5350                         if (count($widgets) == count($rows)){
5351                                 if (!($task == 'wmove' && empty($position2))){                  // 同一ブロック内の移動の場合はチェックなし
5352                                         for ($i = 0; $i < count($rows); $i++){
5353                                                 if ($widgets[$i] != $rows[$i]['pd_serial']){// シリアル番号
5354                                                         $isErr = true;
5355                                                         break;
5356                                                 }
5357                                         }
5358                                 }
5359                         } else {
5360                                 $isErr = true;
5361                         }
5362
5363                         // データの更新
5364                         if (!$isErr){           // エラーなしのとき
5365                                 if ($task == 'wdelete'){
5366                                         $ret = $this->db->deleteWidget($serial);
5367                                 } else if ($task == 'wtoggle'){
5368                                         $newShared = 0;
5369                                         if (empty($shared)) $newShared = 1;
5370                                         $ret = $this->db->toggleSharedWidget($pageId, $pageSubId, $serial, $newShared);
5371                                 } else if ($task == 'wadd'){    // ウィジェットの追加
5372                                         $widget = $request->trimValueOf('widget');
5373                                         
5374                                         // エラーチェック
5375                                         if (empty($widget)) $isErr = true;
5376                                         
5377                                         // ウィジェットを追加
5378                                         if (!$isErr) $this->db->addWidget($pageId, $pageSubId, $position, $widget, $index);
5379                                 } else if ($task == 'wmove'){
5380                                         // ウィジェットを移動
5381                                         if (!$isErr) $this->db->moveWidget($pageId, $pageSubId, $position, $serial, $index);
5382                                 }
5383                         }
5384                         // 再表示データ取得
5385                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);// 0レコードでも正常とする
5386                         
5387                         // 移動のときは、移動元と移動先の再表示データを取得
5388                         if ($task == 'wmove' && !empty($position2)){
5389                                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position2, $rows2);// 0レコードでも正常とする
5390                         }
5391
5392                         // ##### 該当するページのテンプレートタイプを取得 #####
5393                         $templateType = 99;
5394                         $templateGenerator = '';
5395                 
5396                         // ページ用個別に設定されたテンプレートがある場合は取得
5397                         $curTemplate = '';
5398                         $line = $this->getPageInfo($pageId, $pageSubId);
5399                         if (!empty($line)) $curTemplate = $line['pn_template_id'];
5400
5401                         // 取得できなければデフォルトを取得
5402                         if (empty($curTemplate)){
5403                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
5404                                         $curTemplate = $this->gSystem->defaultTemplateId();
5405                                 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
5406                                         $curTemplate = $this->gSystem->defaultSmartphoneTemplateId();           // スマートフォン用デフォルトテンプレート
5407                                 }
5408                         }
5409                         
5410                         // テンプレートのタイプを取得
5411                         $ret = $this->db->getTemplate($curTemplate, $row);
5412                         if ($ret){
5413                                 $templateType = $row['tm_type'];
5414                                 $templateGenerator = $row['tm_generator'];
5415                         }
5416
5417                         // 更新データを作成
5418                         // 更新対象のポジションブロック
5419                         echo '<div>' . M3_NL;
5420                         for ($i = 0; $i < count($updatepos); $i++){
5421                                 // ウィジェットIDヘッダ作成
5422                                 $widgetTagHead = str_replace(self::POSITION_TAG_HEAD, self::WIDGET_TAG_HEAD, $updatepos[$i]);
5423                                         
5424                                 // ポジション名取得
5425                                 $posName = str_replace(self::POSITION_TAG_HEAD, '', substr($updatepos[$i], 0, strlen($updatepos[$i]) - strlen(strrchr($updatepos[$i], "_"))));
5426                                 if ($task == 'wmove' && $posName == $position2){
5427                                         // Themlerテンプレート場合は配置ポジション名が「hmenu」をナビゲーション型とする
5428                                         $style = '';
5429                                         if ($templateGenerator == 'themler'){
5430                                                 if (strcasecmp($position2, 'hmenu') == 0){              // Joomla!v3テンプレート対応
5431                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
5432                                                 }
5433                                         } else {
5434                                                 if (strcasecmp($position2, 'user3') == 0 ||             // ナビゲーションメニュー位置の場合
5435                                                         strcasecmp($position2, 'position-1') == 0){             // Joomla!v2.5テンプレート対応
5436                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
5437                                                 }
5438                                         }
5439                                                                         
5440                                         // ウィジェット一覧外枠
5441                                         $posHead = '';
5442                                         if ($style == self::WIDGET_STYLE_NAVMENU){
5443                                                 $posHead = self::POS_HEAD_NAV_MENU;             // 特殊ポジションブロックのアイコン付加(ナビゲーションメニュー型)
5444                                         } else if (strcasecmp($position2, 'main') == 0){
5445                                                 $posHead = self::POS_HEAD_MAIN;         // 特殊ポジションブロックのアイコン付加(メイン型)
5446                                         }
5447                                         //if (strcasecmp($position2, 'user3') == 0 || strcasecmp($position2, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;            // 特殊ポジションブロックのアイコン付加
5448                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position2 . ';rev:' . $rev . ';">' . M3_NL;                // リビジョン番号を付加
5449                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position2 . '</h2>' . M3_NL;
5450                                 
5451                                         // ウィジェット一覧出力
5452                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows2);
5453                                 } else {
5454                                         // Themlerテンプレート場合は配置ポジション名が「hmenu」をナビゲーション型とする
5455                                         $style = '';
5456                                         if ($templateGenerator == 'themler'){
5457                                                 if (strcasecmp($position, 'hmenu') == 0){               // Joomla!v3テンプレート対応
5458                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
5459                                                 }
5460                                         } else {
5461                                                 if (strcasecmp($position, 'user3') == 0 ||              // ナビゲーションメニュー位置の場合
5462                                                         strcasecmp($position, 'position-1') == 0){              // Joomla!v2.5テンプレート対応
5463                                                         $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
5464                                                 }
5465                                         }
5466                                         
5467                                         // ウィジェット一覧外枠
5468                                         $posHead = '';
5469                                         if ($style == self::WIDGET_STYLE_NAVMENU){
5470                                                 $posHead = self::POS_HEAD_NAV_MENU;             // 特殊ポジションブロックのアイコン付加(ナビゲーションメニュー型)
5471                                         } else if (strcasecmp($position, 'main') == 0){
5472                                                 $posHead = self::POS_HEAD_MAIN;         // 特殊ポジションブロックのアイコン付加(メイン型)
5473                                         }
5474                                         //if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
5475                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;         // リビジョン番号を付加
5476                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
5477                                 
5478                                         // ウィジェット一覧出力
5479                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows);
5480                                 }
5481                                 // ウィジェット一覧外枠
5482                                 echo '</div>' . M3_NL;
5483                         }
5484                         echo '</div>' . M3_NL;
5485                         
5486                         // キャッシュデータをクリア
5487                         $gCacheManager->clearAllCache();
5488                 }
5489         }
5490         /**
5491          * 画面作成用ウィジェット一覧データ出力
5492          *
5493          * @param string $pageId                        ページID
5494          * @param string $pageSubId                     ページサブID
5495          * @param string $widgetTagHead         HTMLウィジェットID用のヘッダ
5496          * @param array $rows                           ウィジェット一覧データ
5497          * @return string                                       ウィジェット一覧出力
5498          */
5499         function getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows)
5500         {
5501                 global $gEnvManager;
5502                 global $gDesignManager;
5503                 global $gSystemManager;
5504                 
5505                 if ($gEnvManager->getUseSslAdmin()){
5506                         $rootUrl = $gEnvManager->getSslRootUrl();
5507                 } else {
5508                         $rootUrl = $gEnvManager->getRootUrl();
5509                 }
5510
5511                 // ページのコンテンツタイプを取得
5512                 $line = $this->getPageInfo($pageId, $pageSubId);
5513                 if (!empty($line)) $pageContentType = $line['pn_content_type'];
5514                         
5515                 $contents = '';         // ウィジェット一覧出力コンテンツ
5516                 for ($i = 0; $i < count($rows); $i++){
5517                         $widgetId = $rows[$i]['wd_id'];
5518                         $desc = $rows[$i]['wd_description'];
5519                         $widgetIndex = $rows[$i]['pd_index'];           // 表示順
5520                         $configId = $rows[$i]['pd_config_id'];          // 定義ID
5521                         $serial = $rows[$i]['pd_serial'];               // シリアル番号
5522                         $isShared = empty($rows[$i]['pd_sub_id']);                      // グローバル属性が設定されているかどうか
5523                         $widgetTag = $widgetTagHead . '_' . $i;                         // ウィジェット識別用ユニークタグ
5524                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
5525                         if ($gEnvManager->getUseSslAdmin()){
5526                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
5527                                 $image = $gEnvManager->getSslUrl($image);
5528                         }
5529                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
5530                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
5531                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
5532                         $imageTag .= ' />';
5533                         // 定義名
5534                         if (empty($rows[$i]['pd_config_name'])){
5535                                 if ($rows[$i]['wd_use_instance_def'] && $configId == 0){                // インスタンス定義が必要で未定義のとき
5536                                         $configName = '<span style="color:red;">[未設定]</span>';
5537                                 } else {
5538                                         $configName = '';
5539                                 }
5540                         } else {
5541                                 $configName = '[' . $rows[$i]['pd_config_name'] . ']';
5542                         }
5543                         $hasAdmin = '0';                // 管理画面があるかどうか
5544                         $configImg = '';        // 設定アイコンの表示
5545                         
5546                         // ウィジェットの配置位置に問題があるかどうかを表示
5547                         // メインコンテンツとページ属性が一致するかどうかチェック
5548                         $widgetContentType = $rows[$i]['wd_content_type'];
5549                         //if (!empty($widgetContentType) && $widgetContentType != $pageContentType && 
5550                         if (!empty($widgetContentType) && $widgetContentType != $pageContentType && empty($rows[$i]['wd_content_widget_id']) &&                 // 編集用のウィジェットが別にある場合は除く(2015/3/24))
5551                                                 (in_array($widgetContentType, $this->_getAllContentType()) || in_array($widgetContentType, $this->_getAllFeatureType()))){
5552                                 //$title = 'ウィジェット配置注意';
5553                                 $title = 'ページ属性と不一致';
5554                                 $configImg .= '<span rel="m3help" data-container="body" title="' . $title . '"><img src="' . $rootUrl . self::NOTICE_ICON_FILE . '" alt="' . $title . '" /></span>&nbsp;';
5555                         }
5556                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type']) && $isShared){                                 // メイン型ウィジェットがグローバル属性を持つとき
5557                                 $title = 'メイン型ウィジェットはグローバル属性を設定できません';
5558                                 $configImg .= '<span rel="m3help" data-container="body" title="' . $title . '"><img src="' . $rootUrl . self::ALERT_ICON_FILE . '" alt="' . $title . '" /></span>&nbsp;';
5559                         }
5560                         if ($rows[$i]['wd_has_admin']){
5561                                 $hasAdmin = '1';
5562                                 $title = 'ウィジェット設定';
5563                                 $configImg .= '<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\'' . $widgetId . '\', \'' . $configId . '\', \'' . $serial . '\');return false;" rel="m3help" data-container="body" title="' . $title . '">' .
5564                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" alt="' . $title . '"/></a>&nbsp;';
5565                         }
5566                         // 表示順
5567                         $configImg .= '<span rel="m3help" data-container="body" title="表示順">' . $widgetIndex . '</span>';
5568                         
5569                         $shared = '0';          // 共通属性があるかどうか
5570                         $sharedClassName = '';
5571                         //if (empty($rows[$i]['pd_sub_id'])){
5572                         if ($isShared){                                 // グローバル属性ウィジェットのとき
5573                                 $shared = '1';
5574                                 $sharedClassName = 'm3_widget_shared';                  // 共通ウィジェットのクラス
5575                         }
5576                         $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
5577                         
5578                         // ウィジェット機能マーク
5579                         $widgetMark = '';
5580                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メイン型ウィジェット
5581                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
5582                         
5583                         // 操作メニュー
5584                         $dropdownMenuId = $widgetTag . '_dropdown';
5585                         $operationMenu = '<div class="m3widgetdropdown">';
5586 //                      $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#"><i class="glyphicon glyphicon-list-alt"></i> <b class="caret"></b></a>';
5587                         $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#" data-horizontal-offset="4"><b class="caret"></b></a>';
5588                         $operationMenu .= '<div id="' . $dropdownMenuId . '" class="m3dropdown m3dropdown-tip m3dropdown-relative m3dropdown-anchor-right">';
5589                         $operationMenu .= '<ul class="m3dropdown-menu">';
5590                         if ($hasAdmin) $operationMenu .= '<li class="m3_wconfig"><a href="#"><img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" /> <span>ウィジェットの設定</span></a></li>';
5591                         $operationMenu .= '<li class="m3_wadjust"><a href="#"><img src="' . $rootUrl . self::ADJUST_ICON_FILE . '" /> <span>タイトル・スタイル調整</span></a></li>';
5592                         if ($shared){
5593                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>グローバル属性を解除</span></a></li>';
5594                         } else {
5595                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>グローバル属性を設定</span></a></li>';
5596                         }
5597                         $operationMenu .= '<li class="m3_wdelete"><a href="#"><img src="' . $rootUrl . self::DELETE_ICON_FILE . '" /> <span>このウィジェットを削除</span></a></li>';
5598                         $operationMenu .= '</ul>';
5599                         $operationMenu .= '</div>';
5600                         $operationMenu .= '</div>';
5601                         
5602                         $contents .= '<dl class="m3_widget m3_widget_sortable" id="' . $widgetTag . '" ' . $m3Option . ' >' . M3_NL;
5603                         $contents .= '<dt class="m3_widget_with_check_box ' . $sharedClassName . '"><div class="m3widgettitle">' . $widgetMark . $rows[$i]['wd_name'] . '</div>' . $operationMenu . '</dt>' . M3_NL;
5604                         $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;
5605                         $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;
5606                         $contents .= '</dl>' . M3_NL;
5607                 }
5608                 return $contents;
5609         }
5610         /**
5611          * ウィジェット出力を処理
5612          *
5613          * @param string $position                      HTMLテンプレート上の書き出し位置
5614          * @param int $index                            行番号
5615          * @param array $fetchedRow                     fetch取得した行
5616          * @param string $style                         ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
5617          * @param string $launchWidgetTag       遅延ウィジェット埋め込み用タグ(遅延ウィジェットの場合のみ作成)
5618          * @param string $titleTag              タイトル埋め込み用タグ(遅延ウィジェットの場合のみ作成)
5619          * @param int $widgetHeaderType         ウィジェットタイトルを出力方法(0=出力なし、1=Joomla!v1.0PC用出力、2=Joomla!v1.0携帯用出力)
5620          * @return bool                                         処理を継続するかどうか(true=続行、false=中断)
5621          */
5622         function pageDefLoop($position, $index, $fetchedRow, $style, &$launchWidgetTag, &$titleTag, $widgetHeaderType = 0)
5623         {
5624                 global $gEnvManager;
5625                 global $gErrorManager;
5626                 global $gDesignManager;
5627
5628                 // ページ作成中断またはウィジェット処理中断のときは終了
5629                 if ($this->isAbort || $this->isWidgetAbort) return false;
5630
5631                 // ウィジェット実行停止中のときは空で返す
5632                 // 管理者、運営者どのレベルで制限をかける?
5633                 if (!$fetchedRow['wd_active']) return true;
5634                 
5635                 // グローバル属性ありの場合は現在のページが例外ページにないかチェック
5636                 if (empty($fetchedRow['pd_sub_id'])){
5637                         $exceptPageStr = $fetchedRow['pd_except_sub_id'];
5638                         if (!empty($exceptPageStr)){
5639                                 $exceptPageArray = explode(',', $exceptPageStr);
5640                                 if (in_array($gEnvManager->getCurrentPageSubId(), $exceptPageArray)) return true;               // 例外ページの場合は出力しない
5641                         }
5642                 }
5643                 
5644                 // ウィジェット表示タイプによる表示制御。システム管理者以上の場合は常時表示。
5645                 if (!$gEnvManager->isSystemAdmin()){
5646                         if (!empty($fetchedRow['pd_view_control_type'])){
5647                                 switch ($fetchedRow['pd_view_control_type']){
5648                                         case 1:                 // ログイン時のみ表示
5649                                                 if (!$gEnvManager->isCurrentUserLogined()) return true;         // ログインしていなければ終了
5650                                                 break;
5651                                         case 2:                 // 非ログイン時のみ表示
5652                                                 if ($gEnvManager->isCurrentUserLogined()) return true;          // ログインしていれば終了
5653                                                 break;
5654                                         default:
5655                                                 break;
5656                                 }
5657                         }
5658                         if (!empty($fetchedRow['pd_view_page_state'])){
5659                                 switch ($fetchedRow['pd_view_page_state']){
5660                                         case 1:                 // トップ時のみ表示
5661                                                 if (!$this->isPageTopUrl) return true;          // ページトップ(サブページ内のトップ位置)でなければ終了
5662                                                 break;
5663                                         default:
5664                                                 break;
5665                                 }
5666                         }
5667                 }
5668                 
5669                 // パラメータ初期化
5670                 $launchWidgetTag = '';          // 遅延ウィジェット埋め込み用タグ
5671                 $titleTag = '';
5672                 
5673                 // ウィジェットID取得
5674                 $widgetId = $fetchedRow['wd_id'];               
5675                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
5676
5677                 // その他パラメータ取得
5678                 $configId = $fetchedRow['pd_config_id'];                // ウィジェット定義ID
5679                 if ($configId == 0) $configId = '';
5680                 $prefix = $fetchedRow['wd_suffix'];             // サフィックス文字列
5681                 $title = $fetchedRow['wd_name'];                // デフォルトのウィジェットタイトル
5682                 if (empty($title)) $title = $fetchedRow['wd_id'];
5683                 $widgetHeadTitle = $fetchedRow['pd_title'];             // ウィジェットのヘッドタイトル
5684                 if (empty($widgetHeadTitle)) $widgetHeadTitle = $title;                 // ウィジェットのヘッドタイトルが空の場合はウィジェットタイトルを取得
5685                 $serial = $fetchedRow['pd_serial'];             // シリアル番号
5686                 $cssStyle       = $fetchedRow['pd_style'];              // CSS
5687                 $lateLaunchIndex = $fetchedRow['wd_launch_index'];              // 遅延実行インデックス
5688                 $shared = false;
5689                 if (empty($fetchedRow['pd_sub_id'])) $shared = true;// 共通属性あり
5690                 if ($this->nonSharedWidgetCount == -1) $this->nonSharedWidgetCount = 0;         // 初期化されていない場合は初期化
5691                 if (!$shared) $this->nonSharedWidgetCount++;    // 非共通ウィジェットの数を更新
5692                 
5693                 // ウィジェットが遅延実行に指定されている場合は、ウィジェットのタグのみ埋め込む
5694                 if ($lateLaunchIndex > 0){              // 遅延実行のとき
5695                         // 遅延実行ウィジェットリストに追加
5696                         if (!isset($this->lateLaunchWidgetList[$widgetId])){
5697                                 $this->lateLaunchWidgetList[$widgetId] = (int)$lateLaunchIndex;
5698                         }
5699                         // 実行パラメータ保存
5700                         $maxNo = 0;             // 最大シリアル番号
5701                         $count = count($this->latelaunchWidgetParam);
5702                         for ($i = 0; $i < $count; $i++){
5703                                 list($wId, $maxNo, $tmp1, $tmp2, $tmp3, $tmp4, $tmp5, $tmp6, $tmp7, $tmp8, $tmp9, $tmp10, $tmp11) = $this->latelaunchWidgetParam[$i];
5704                                 if ($wId == $widgetId) $maxNo = $maxNo + 1;
5705                         }
5706                         // Joomla!1.0テンプレートの場合はタイトルを修正
5707                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
5708                                 if (!empty($fetchedRow['pd_title'])) $title = $fetchedRow['pd_title'];
5709                         }
5710                         $this->latelaunchWidgetParam[] = array($widgetId, $maxNo, $configId, $prefix, $serial, $style, $cssStyle, $title, $shared, $exportCss, $position, $index, $fetchedRow);
5711                         
5712                         // 遅延実行用タグを埋め込む
5713                         $launchWidgetTag = self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;                // 遅延ウィジェット埋め込み用タグ
5714                         echo $launchWidgetTag;
5715                         
5716                         // タイトル用タグ作成
5717                         $titleTag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
5718                 } else {
5719                         // ウィジェットが存在する場合は実行
5720                         if (!file_exists($widgetIndexFile)) {
5721                                 if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
5722                         } else {
5723                                 // パラメータ初期化
5724                                 $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
5725                                 $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
5726                                 $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
5727                                 $this->lastHeadTitle = '';                      // ヘッダ部titleにセットした文字列
5728                                 $this->lastHeadDescription = '';        // ヘッダ部descriptionにセットした文字列
5729                                 $this->lastHeadKeywords = '';           // ヘッダ部keywordsにセットした文字列
5730                         
5731                                 // 現在のウィジェットのポジション
5732                                 $this->currentWidgetPosition = $position;                       // 現在のウィジェットのポジション
5733                                 $this->currentWidgetIndex = $index;                     // 現在のウィジェットのポジション番号
5734                                         
5735                                 // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
5736                                 $joomlaTitleVisble = false;
5737                                 if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
5738                                         if ($fetchedRow['pd_title_visible']){
5739                                                 if ($widgetHeaderType == 1){            // PC用出力のとき
5740                                                         $joomlaTitle = $fetchedRow['pd_title'];
5741                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
5742                                                         echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
5743                                                         echo '<tr><th>' . $joomlaTitle . '</th></tr>' . M3_NL;
5744                                                         echo '<tr><td>' . M3_NL;
5745                                                         $joomlaTitleVisble = true;
5746                                                 } else if ($widgetHeaderType == 2){             // 携帯用出力のとき
5747                                                         $joomlaTitle = $fetchedRow['pd_title'];
5748                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
5749                                                         echo '<div>' . $joomlaTitle . '</div>' . M3_NL;
5750                                                         $joomlaTitleVisble = true;
5751                                                 }
5752                                         }
5753                                 }
5754                                 // ウィジェットの外枠タグを設定
5755                                 //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
5756                                 // ウィジェット親のCSS定義があるときは、タグを追加
5757                                 if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
5758                                         
5759                                 // ウィジェットの前出力
5760                                 echo $gDesignManager->getAdditionalWidgetOutput(true);
5761                                 
5762                                 // 作業中のウィジェットIDを設定
5763                                 $gEnvManager->setCurrentWidgetId($widgetId);
5764         
5765                                 // ウィジェット定義IDを設定
5766                                 $gEnvManager->setCurrentWidgetConfigId($configId);
5767                         
5768                                 // ページ定義のシリアル番号を設定
5769                                 $gEnvManager->setCurrentPageDefSerial($fetchedRow['pd_serial']);
5770                                 
5771                                 // ページ定義レコードを設定
5772                                 $gEnvManager->setCurrentPageDefRec($fetchedRow);
5773                                 
5774                                 // パラメータを設定
5775                                 $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
5776                         
5777                                 // ウィジェットのヘッドタイトルを設定
5778                                 $gEnvManager->setCurrentWidgetHeadTitle($widgetHeadTitle);
5779
5780                                 // ウィジェットのタイトルを設定
5781                                 $gEnvManager->setCurrentWidgetTitle($title);
5782                                 
5783                                 // ウィジェットのスタイルを設定
5784                                 $gEnvManager->setCurrentWidgetStyle($style);
5785                                 
5786                                 // ウィジェットのグローバル属性状況を設定
5787                                 $gEnvManager->setIsCurrentWidgetShared($shared);
5788                                         
5789                                 // 実行ログを残す
5790                                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
5791                                 
5792                                 // ウィジェットを実行
5793                                 //require_once($widgetIndexFile);
5794                                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5795                                 $msg = 'widget-start(' . $widgetId . ')';
5796                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5797                                 require($widgetIndexFile);
5798                                 $msg = 'widget-end(' . $widgetId . ')';
5799                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5800
5801                                 // 作業中のウィジェットIDを解除
5802                                 $gEnvManager->setCurrentWidgetId('');
5803                         
5804                                 // ウィジェット定義IDを解除
5805                                 $gEnvManager->setCurrentWidgetConfigId('');
5806                                 
5807                                 // ページ定義のシリアル番号を解除
5808                                 $gEnvManager->setCurrentPageDefSerial(0);
5809                         
5810                                 // ページ定義レコードを解除
5811                                 $gEnvManager->setCurrentPageDefRec();
5812                                 
5813                                 // パラメータを解除
5814                                 $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
5815
5816                                 // ウィジェットのスタイルを解除
5817                                 $gEnvManager->setCurrentWidgetStyle('');
5818                                 
5819                                 // ウィジェットのグローバル属性状況を解除
5820                                 $gEnvManager->setIsCurrentWidgetShared(false);
5821                                 
5822                                 // ウィジェットの後出力
5823                                 echo $gDesignManager->getAdditionalWidgetOutput(false);
5824 //                              echo "<!-- ".time()." -->";
5825
5826                                 // ウィジェット親のCSS定義があるときは、タグを追加
5827                                 if (!empty($cssStyle)) echo '</div>' . M3_NL;
5828                                 // ウィジェットの外枠タグを設定
5829                                 //echo '</div>' . M3_NL;
5830                                 
5831                                 // Joomla!1.0テンプレートのときはタイトルを出力
5832                                 if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用出力のとき
5833                                         echo '</td></tr>' . M3_NL;
5834                                         echo '</table>' . M3_NL;
5835                                 }
5836                         }
5837                 }
5838                 return true;            // 処理継続
5839         }
5840         /**
5841          * 定義IDを指定してウィジェットの出力を取得
5842          *
5843          * @param string $widgetId              ウィジェットID
5844          * @param int $configId                 ウィジェット定義ID
5845          * @return string                               ウィジェットの出力
5846          */
5847         function getWidgetOutput($widgetId, $configId = 0)
5848         {
5849                 global $gEnvManager;
5850                 global $gErrorManager;
5851
5852                 // ウィジェットのアクセス権をチェック
5853                 if (!$this->db->canAccessWidget($widgetId)) return '';
5854
5855                 // ウィジェット情報取得
5856                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
5857
5858                 // 端末タイプをチェック
5859                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
5860                 
5861                 // 必要なJavascriptライブラリを追加
5862                 $scritLib = trim($row['wd_add_script_lib']);
5863                 if (!empty($scritLib)) $this->addScript('', $scritLib);
5864                 
5865                 // バッファ作成
5866                 ob_start();
5867
5868                 // ウィジェット実行ファイル取得
5869                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
5870                                         
5871                 // 作業中のウィジェットIDを設定
5872                 $saveWidgetId = $gEnvManager->getCurrentWidgetId();
5873                 $gEnvManager->setCurrentWidgetId($widgetId);
5874
5875                 // ウィジェット定義IDを設定
5876                 $saveConfigId = $gEnvManager->getCurrentWidgetConfigId();
5877                 $gEnvManager->setCurrentWidgetConfigId($configId);
5878         
5879                 // ページ定義のシリアル番号を設定
5880                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
5881                         
5882                 // パラメータを設定
5883                 //$gEnvManager->setCurrentWidgetPrefix($prefix);                // プレフィックス文字列
5884         
5885                 // ウィジェットのタイトルを設定
5886                 //$gEnvManager->setCurrentWidgetTitle($title);
5887                 
5888                 // ウィジェットのグローバル属性状況を設定
5889                 //$gEnvManager->setIsCurrentWidgetShared($shared);
5890                         
5891                 // 実行ログを残す
5892                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
5893                 
5894                 // ウィジェットを実行
5895                 //require_once($widgetIndexFile);
5896                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5897                 $msg = 'widget-start(' . $widgetId . ')';
5898                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5899                 if (file_exists($widgetIndexFile)){
5900                         require($widgetIndexFile);
5901                 } else {
5902                         if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
5903                 }
5904                 $msg = 'widget-end(' . $widgetId . ')';
5905                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
5906
5907                 // 作業中のウィジェットIDを戻す
5908                 $gEnvManager->setCurrentWidgetId($saveWidgetId);
5909         
5910                 // ウィジェット定義IDを戻す
5911                 $gEnvManager->setCurrentWidgetConfigId($saveConfigId);
5912                 
5913                 // ページ定義のシリアル番号を解除
5914                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
5915         
5916                 // パラメータを解除
5917                 //$gEnvManager->setCurrentWidgetPrefix('');                             // プレフィックス文字列
5918
5919                 // ウィジェットのグローバル属性状況を解除
5920                 //$gEnvManager->setIsCurrentWidgetShared(false);
5921
5922                 // 現在のバッファ内容を取得し、バッファを破棄
5923                 $output = ob_get_contents();
5924                 ob_end_clean();
5925                                         
5926                 return $output;
5927         }
5928         /**
5929          * インナーウィジェットの操作
5930          *
5931          * @param int $cmdNo                            実行コマンド(0=初期化、1=更新、2=計算、10=コンテンツ取得)
5932          * @param string $id                            ウィジェットID+インナーウィジェットID
5933          * @param string $configId                      インナーウィジェット定義ID
5934          * @param object $paramObj                      インナーウィジェットに渡すパラメータオブジェクト
5935          * @param object $optionParamObj        インナーウィジェットに渡すパラメータオブジェクト(オプション)
5936          * @param object $resultObj                     インナーウィジェットから返る結果オブジェクト
5937          * @param string $content                       出力内容
5938          * @param bool $isAdmin                         管理者機能(adminディレクトリ以下)かどうか
5939          * @return bool                                         true=成功、false=失敗
5940          */
5941         function commandIWidget($cmdNo, $id, $configId, &$paramObj, &$optionParamObj, &$resultObj, &$content, $isAdmin = false)
5942         {
5943                 global $gEnvManager;
5944                 
5945                 // ウィジェットIDとインナーウィジェットIDを取り出す
5946                 list($widgetId, $iWidgetId) = explode(M3_WIDGET_ID_SEPARATOR, $id);
5947
5948                 // インナーウィジェットに渡すパラメータを設定
5949                 switch ($cmdNo){
5950                         case 0:
5951                                 $cmd = self::IWIDTET_CMD_INIT;                  // 初期化
5952                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5953                                 break;
5954                         case 1:
5955                                 $cmd = self::IWIDTET_CMD_UPDATE;                // 更新
5956                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
5957                                 break;
5958                         case 2:
5959                                 $cmd = self::IWIDTET_CMD_CALC;                  // 計算
5960                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5961                                 break;
5962                         case 10:
5963                                 $cmd = self::IWIDTET_CMD_CONTENT;                       // コンテンツ取得
5964                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
5965                                 break;
5966                         default:
5967                                 $cmd = '';
5968                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
5969                                 break;
5970                 }
5971
5972                 // インナーウィジェットのエラー出力は呼び出しウィジェット側で受けるため、出力を抑止する
5973                 ob_start();// バッファ作成
5974
5975                 // ウィジェット実行ファイル取得
5976                 if (empty($widgetId)){          // ウィジェットIDが指定されていないときは共通ディレクトリ
5977                 //$gEnvManager->getIWidgetsPath() . '/' . $iWidgetId . '/' . $containerClass . '.php';
5978                 } else {
5979                         if ($isAdmin){
5980                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/' . M3_DIR_NAME_ADMIN . '/index.php';
5981                         } else {
5982                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/index.php';
5983                         }
5984                 }
5985
5986                 // 作業中のインナーウィジェットIDを設定
5987                 $gEnvManager->setCurrentIWidgetId($id);         // インナーウィジェットを設定
5988
5989                 // インナーウィジェット定義IDを設定
5990                 $gEnvManager->setCurrentIWidgetConfigId($configId);
5991                 
5992                 // ウィジェットを実行
5993                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
5994                 if (file_exists($widgetIndexFile)){
5995                         require($widgetIndexFile);
5996                 } else {
5997                         echo 'file not found error: ' . $widgetIndexFile;
5998                 }
5999                 
6000                 // 作業中のウィジェットIDを解除
6001                 $gEnvManager->setCurrentIWidgetId('');
6002         
6003                 // インナーウィジェット定義IDを解除
6004                 $gEnvManager->setCurrentIWidgetConfigId('');
6005                 
6006                 // 現在のバッファ内容を取得し、バッファを破棄
6007                 $content = ob_get_contents();
6008                 ob_end_clean();
6009                 
6010                 // 値を再取得
6011                 if ($this->gInstance->getCmdParamManager()->getParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $obj, $option)){
6012                         $paramObj = $obj;
6013                         $optionParamObj = $option;
6014                 }
6015
6016                 // 結果を取得
6017                 if ($this->gInstance->getCmdParamManager()->getResult($id . M3_WIDGET_ID_SEPARATOR . $configId, $resObj)) $resultObj = $resObj;
6018                 return true;
6019         }
6020         /**
6021          * コールバックメソッドを実行し、出力を返す
6022          *
6023          * @param array $callback               実行するコールバック
6024          * @return string                               出力結果
6025          */
6026         function getOutputByCallbackMethod($callback)
6027         {
6028                 ob_start();// バッファ作成
6029                 
6030                 // コールバック関数を実行
6031                 if (is_callable($callback)) call_user_func($callback);
6032                 
6033                 // 現在のバッファ内容を取得し、バッファを破棄
6034                 $content = ob_get_contents();
6035                 ob_end_clean();
6036                 return $content;
6037         }
6038         /**
6039          * ページ作成処理中断を行った場合のレスポンスヘッダ設定
6040          *
6041          * @param int $responseCode             レスポンスコード
6042          * @return                                              なし
6043          */
6044         function setResponse($responseCode)
6045         {
6046                 switch ($responseCode){
6047                         case 400:                       // リクエストにエラーがあるとき
6048                                 header('HTTP/1.1 400 Bad request');
6049                                 header('Status: 400 Bad request');
6050                                 break;
6051                         case 403:                       // アクセス禁止のとき
6052                                 header('HTTP/1.1 403 Forbidden');
6053                                 header('Status: 403 Forbidden');
6054                                 break;
6055                         case 404:                       // 存在しないページのとき
6056                                 header("HTTP/1.1 404 Not Found");
6057                                 header("Status: 404 Not Found");
6058                                 break;
6059                         case 500:                       // サーバ内部エラー
6060                                 header('HTTP/1.1 500 Internal Server Error');
6061                                 header('Status: 500 Internal Server Error');
6062                                 break;
6063                         case 503:                       // サイト非公開(システムメンテナンス)
6064                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
6065                                 header('Status: 503 Service Temporarily Unavailable');
6066                                 break;
6067                 }
6068         }
6069         /**
6070          * ファイルダウンロード
6071          *
6072          * @param string $filePath                      ダウンロードするファイルのファイルパス
6073          * @param string $downloadFilename      ダウンロード時のファイル名
6074          * @param bool   $deleteFile            実行後ファイルを削除するかどうか(成功失敗に関係なく)
6075          * @return bool                                         true=成功、false=失敗
6076          */
6077         function downloadFile($filePath, $downloadFilename, $deleteFile=false)
6078         {
6079                 // エラーチェック
6080                 if (!file_exists($filePath)) return false;
6081                 
6082                 // ファイルサイズ取得
6083                 $fileSize = filesize($filePath);
6084                 
6085                 // バッファ内容が残っているときは破棄
6086                 if (ob_get_level() > 0) ob_end_clean();
6087                 
6088                 header('Cache-Control: public');                // IE6+SSHでダウンロードエラーが出る問題を回避
6089                 header('Pragma: public');                               // IE6+SSHでダウンロードエラーが出る問題を回避
6090             header('Content-Disposition: attachment; filename=' . $downloadFilename);
6091                 header('Content-Length: ' . $fileSize);
6092             header('Content-Type: application/octet-stream; name=' . $downloadFilename);
6093             $fp = fopen($filePath, "r");
6094             echo fread($fp, $fileSize);
6095             fclose($fp);
6096                 
6097                 ob_end_flush();
6098                 
6099                 // ファイル削除
6100                 if ($deleteFile) unlink($filePath);
6101                 return true;
6102         }
6103         /**
6104          * システム制御ページを表示するかどうかを返す
6105          *
6106          * @return bool         true=システム制御ページを表示、false=システム制御ページを表示しない
6107          */
6108         function isSystemPage()
6109         {
6110                 return $this->isSystemPage;
6111         }
6112         /**
6113          * 指定URLへリダイレクト
6114          *
6115          * @param string $url                   遷移先URL。未指定の場合は現在のスクリプト。URLでないときは、現在のスクリプトに付加。
6116          * @param bool $noMessage               画面を遷移させたとき、ドコモ携帯端末でダイアログ(サイトが移動しました(301))が出ないようにするオプション
6117          * @param int  $responseCode    レスポンスコード
6118          * @param bool $autoSsl                 リダイレクト先のページの状態に合わせてSSLを制御するかどうか
6119          * @return                                              なし
6120          */
6121         function redirect($url = '', $noMessage = false, $responseCode = 0, $autoSsl = true)
6122         {
6123                 global $gEnvManager;
6124
6125                 // すでにリダイレクトが設定されている場合は終了
6126                 if ($this->isRedirect) return;                          // リダイレクトするかどうか
6127                 
6128                 $toUrl = $url;
6129                 if (empty($toUrl)){
6130                         $toUrl = $gEnvManager->getCurrentScriptUrl();
6131                 } else if (strncmp($toUrl, 'http://', 7) != 0 && strncmp($toUrl, 'https://', 8) != 0){  // URL以外のときはクエリー文字列と判断する
6132                         $toUrl = $gEnvManager->getCurrentScriptUrl() . $toUrl;
6133                 }
6134
6135                 // SSL化が必要な場合はhttpsに変更
6136                 if ($autoSsl){
6137                         $isSslPage = false;
6138                         if ($gEnvManager->isAdminUrlAccess($toUrl)){            // 管理画面へのアクセスのとき
6139                                 // ルートURLがSSLの場合は管理画面は常にSSL付き
6140                                 if ($gEnvManager->isRootUrlSsl()) $isSslPage = true;
6141                                 
6142                                 // 管理画面のSSL状態を参照
6143                                 if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
6144                         } else {                // フロント画面へのアクセスのとき
6145                                 // ファイル名を取得
6146                                 $paramArray = array();
6147                                 //list($filename, $query) = explode('?', basename($toUrl));
6148                                 list($url, $query) = explode('?', $toUrl);
6149                                 $baseUrl = dirname($url);
6150                                 $filename = basename($url);
6151                                 if (empty($filename)) $filename = M3_FILENAME_INDEX;
6152                                 if (!empty($query)) parse_str($query, $paramArray);             // クエリーの解析
6153                 
6154                                 // ページIDを取得
6155                                 $pageId = basename($filename, '.php');
6156                                 $pageSubId = $paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID];
6157                         
6158                                 // ページのSSL設定状況を取得
6159                                 $isSslPage = $this->isSslPage($pageId, $pageSubId);
6160                         
6161                                 // 階層化ページの場合はURLを修正
6162                                 if ($this->gSystem->hierarchicalPage() && $filename == M3_FILENAME_INDEX){
6163                                         $toUrl = $baseUrl . '/' . $pageSubId . '/';
6164                                         unset($paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID]);
6165                                         
6166                                         $paramStr = $this->_createUrlParamStr($paramArray);
6167                                         if (!empty($paramStr)) $toUrl .= '?' . $paramStr;
6168                                 }
6169                         }
6170                         if ($isSslPage){
6171                                 //$toUrl = str_replace('http://', 'https://', $toUrl);
6172                                 $toUrl = $gEnvManager->getSslUrl($toUrl);               // SSL用URLに変換
6173                         } else {
6174                                 $toUrl = str_replace('https://', 'http://', $toUrl);
6175                         }
6176                 }
6177
6178                 // バッファ内容が残っているときは破棄
6179                 if (ob_get_level() > 0) ob_end_clean();
6180
6181                 if (empty($responseCode)){
6182                         if ($noMessage){
6183                                 header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
6184                         } else {
6185 //                              header('HTTP/1.1 301 Moved Permanently');
6186                                 header('HTTP/1.1 302 Moved Temporary');                         // ドメインのURLをHTTPからHTTPに変更するとChromeで問題が発生したので301から302リダイレクトに変更(2018/4/30)
6187                         }
6188                 } else {                // レスポンスコードが指定されている場合
6189                         switch ($responseCode){
6190                                 case 301:
6191                                         // ##### 301リダイレクトはChromeではブラウザにキャッシュされてしまうので注意 #####
6192                                         header('HTTP/1.1 301 Moved Permanently');
6193                                         break;
6194                                 case 302:
6195                                         header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
6196                                         break;
6197                                 case 303:
6198                                         header('HTTP/1.1 303 See Other');
6199                                         break;
6200                                 case 500:                       // サーバ内部エラー
6201                                         header('HTTP/1.1 500 Internal Server Error');
6202                                         header('Status: 500 Internal Server Error');
6203                                         break;
6204                                 case 503:                       // サイト非公開(システムメンテナンス)
6205                                         header('HTTP/1.1 503 Service Temporarily Unavailable');
6206                                         header('Status: 503 Service Temporarily Unavailable');
6207                                         break;
6208                                 default:
6209                                         header('HTTP/1.1 ' . (string)$responseCode);
6210                                         break;
6211                         }
6212                 }
6213                 header('Location: ' . $toUrl);
6214                 
6215                 $this->isRedirect = true;                               // リダイレクトするかどうか
6216         }
6217         /**
6218          * リダイレクト処理かどうかを返す
6219          *
6220          * @return bool         true=リダイレクト、false=リダイレクトでない
6221          */
6222         function isRedirect()
6223         {
6224                 return $this->isRedirect;
6225         }
6226         /**
6227          * 指定URLのディレクトリへリダイレクト
6228          *
6229          * @return                                              なし
6230          */
6231         function redirectToDirectory()
6232         {
6233                 global $gEnvManager;
6234
6235                 // ファイル名を削除
6236                 $dirPath = dirname($gEnvManager->getCurrentScriptUrl()) . '/';
6237                 //$this->redirect($dirPath);
6238                 $this->redirect($dirPath, false, 303, false/*SSLは自動制御しない*/);                    // Firefoxでredirect先がキャッシュに残る問題を回避(2012/7/23)
6239         }
6240         /**
6241          * インストール時のリダイレクト処理
6242          *
6243          * @param string $url                   遷移先URL
6244          * @return                                              なし
6245          */
6246         function redirectInInstall($url)
6247         {
6248                 $this->redirect($url, false, 303, false/*SSLは自動制御しない*/);                        // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
6249         }
6250         /**
6251          * インストール用URLへリダイレクト
6252          *
6253          * @return                                              なし
6254          */
6255         function redirectToInstall()
6256         {
6257                 global $gEnvManager;
6258                 
6259                 $sytemRootUrl = $gEnvManager->calcSystemRootUrl();
6260                 //$this->redirect($sytemRootUrl . '/admin/install.php');
6261                 $this->redirect($sytemRootUrl . '/admin/install.php', false, 303, false/*SSLは自動制御しない*/);                        // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
6262         }
6263         /**
6264          * ログイン、ログアウト処理を行った後、リダイレクト
6265          *
6266          * @param RequestManager        $request                HTTPリクエスト処理クラス
6267          * @param bool                          $success                ログインの成否
6268          * @param string                        $redirectUrl    ログイン成功の場合のリダイレクト先
6269          * @return int                                                          0=何も処理しなかった場合、1=ログイン処理、2=ログアウト処理、3=パスワード送信
6270          */
6271         function standardLoginLogoutRedirect($request, &$success, $redirectUrl = '')
6272         {
6273                 global $gEnvManager;
6274                 global $gAccessManager;
6275                 global $gRequestManager;
6276                 
6277                 // ログイン、ログアウト処理、および、コンテナの起動
6278                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
6279                 if ($cmd == M3_REQUEST_CMD_LOGIN){                      // ログインの場合
6280                         $act = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_ACT);
6281                         if ($act == 'sendpwd'){         // パスワード送信の場合
6282                                 $success = $gAccessManager->sendPassword($request);
6283                                 return 3;
6284                         } else {
6285                                 // ユーザ認証
6286                                 $ret = $gAccessManager->userLogin($request);
6287                                 if ($ret){
6288                                         if (empty($redirectUrl)){
6289                                                 // システム運用可能ユーザの場合でリダイレクト先が設定されていない場合はデフォルトの管理画面URLへ遷移
6290                                                 $userInfo = $gEnvManager->getCurrentUserInfo();// ユーザ情報取得
6291                                                 if ($userInfo->userType >= UserInfo::USER_TYPE_MANAGER){
6292                                                         $ret = $this->db->getLoginUserRecordById($userInfo->userId, $userInfoRow);
6293                                                         if ($ret && !empty($userInfoRow['lu_default_admin_url'])){
6294                                                                 $redirectUrl = $gEnvManager->getDefaultAdminUrl() . $userInfoRow['lu_default_admin_url'];
6295                                                         }
6296                                                 }
6297                                         }
6298                                 
6299                                         // リダイレクト処理
6300                                         $this->redirect($redirectUrl);
6301                                         $success = true;                // ログイン成功
6302                                 } else {        // ログイン失敗のとき
6303                                         $success = false;               // ログイン失敗
6304                                 }
6305                                 return 1;
6306                         }
6307                 } else if ($cmd == M3_REQUEST_CMD_LOGOUT){              // ログアウト
6308                         // ログアウト処理
6309                         $gAccessManager->userLogout(true);
6310                         
6311                         // リダイレクト処理
6312                         $this->redirect($redirectUrl);
6313                         return 2;
6314                 } else {
6315                         return 0;
6316                 }
6317         }
6318         /**
6319          * エラー画面を表示
6320          *
6321          * @param int $errStatus                HTTPエラーステータスコード
6322          * @return                                              なし
6323          */
6324         function showError($errStatus)
6325         {
6326                 // レスポンスヘッダ設定
6327                 $this->setResponse($errStatus);
6328                 
6329                 // メッセージ設定
6330                 $msg = 'NOT DEFINED ERROR';
6331                 switch ($errStatus){
6332                         case 403:                       // アクセス禁止のとき
6333                                 $msg = 'Forbidden';
6334                                 break;
6335                         case 404:                       // 存在しないページのとき
6336                                 $msg = 'Not Found';
6337                                 break;
6338                         case 500:                       // サーバ内部エラー
6339                                 $msg = 'Internal Server Error';
6340                                 break;
6341                         case 503:                       // サイト非公開(システムメンテナンス)
6342                                 $msg = 'Service Temporarily Unavailable';
6343                                 break;
6344                 }
6345                 
6346                 echo '<!doctype html>';
6347                 echo '<html>';
6348                 echo '<head>';
6349                 echo '<title>' . $msg . '</title>';
6350                 echo '</head>';
6351                 echo '<body>';
6352                 echo '<h2>' . $msg . '</h2>';
6353                 echo '</body>';
6354                 echo '</html>';
6355         }
6356         /**
6357          * ウィジェットがセットされているページサブIDを取得
6358          *
6359          * @param string $pageId                ページID
6360          * @param string $widgetId              対象ウィジェットID
6361          * @param int $configId                 ウィジェット定義ID
6362          * @return string                               ページサブID
6363          */
6364         function getPageSubIdByWidget($pageId, $widgetId, $configId = 0)
6365         {
6366                 $pageSubId = '';
6367                 
6368                 // 対象のウィジェットのページサブIDを取得
6369                 $ret = $this->db->getSubPageId($widgetId, $pageId, $rows);
6370                 if ($ret){// データが存在する
6371                         for ($i = 0; $i < count($rows); $i++){
6372                                 if (!empty($rows[$i]['pd_sub_id']) && $rows[$i]['pd_config_id'] == $configId){
6373                                         $pageSubId = $rows[$i]['pd_sub_id'];
6374                                         break;
6375                                 }
6376                         }
6377                 }
6378                 return $pageSubId;
6379         }
6380         /**
6381          * その他のGET,POSTパラメータからページサブID取得
6382          *
6383          * @param RequestManager $request               HTTPリクエスト処理クラス
6384          * @param string $redirectUrl                   リダイレクト用URL
6385          * @return string                                               ページサブID
6386          */
6387         function getPageSubIdByParam($request, &$redirectUrl)
6388         {
6389                 global $gEnvManager;
6390                 
6391                 $subId = '';
6392                 $redirectUrl = '';
6393                 $task = $request->trimValueOf('task');
6394                 $option = $request->trimValueOf('option');
6395                 if ($task == 'search' && $option == 'com_search'){              // joomla!の検索結果表示の場合
6396                         $this->contentType = M3_VIEW_TYPE_SEARCH;               // ページのコンテンツタイプ
6397                                 
6398                         $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_SEARCH, $gEnvManager->getCurrentPageId());// ページサブIDを取得
6399                         if (!empty($subId)){
6400                                 // リダイレクト用URLを作成
6401                                 $keyword = $request->trimValueOf('searchword');
6402                                 $redirectUrl = $gEnvManager->createPageUrl();
6403                                 $redirectUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subId;
6404                                 $redirectUrl .= '&' . M3_REQUEST_PARAM_OPERATION_TASK . '=search&' . M3_REQUEST_PARAM_KEYWORD . '=' . urlencode($keyword);
6405                         }
6406                 }
6407                 return $subId;
6408         }
6409         /**
6410          * コンテンツタイプとページIDからページサブID取得
6411          *
6412          * @param string $contentType   コンテンツタイプ
6413          * @param string $pageId                ページID
6414          * @return string                               ページサブID
6415          */
6416         function getPageSubIdByContentType($contentType, $pageId)
6417         {
6418                 $subId = $this->db->getSubPageIdWithContent($contentType, $pageId);// ページサブIDを取得
6419                 return $subId;
6420         }
6421         /**
6422          * 指定のウィジェットがページ上にあるかを取得
6423          *
6424          * @param string $pageId                ページID
6425          * @param string $widgetId              対象ウィジェットID
6426          * @param bool $activePageOnly  公開中のページのウィジェットに制限するかどうか。falseの場合はすべてのページのウィジェットを対象とする。
6427          * @return bool                                 true=ページ上にあり、false=ページ上になし
6428          */
6429         function isWidgetOnPage($pageId, $widgetId, $activePageOnly=true)
6430         {
6431                 $ret = $this->db->isWidgetOnPage($pageId, $widgetId, $activePageOnly, 0/*定義セットID*/);
6432                 return $ret;
6433         }
6434         /**
6435          * URLで示されるページ上のウィジェットをウィジェット種別で取得
6436          *
6437          * @param string $url                   URL
6438          * @param string $widgetType    対象ウィジェットタイプ
6439          * @return string                               ウィジェットID
6440          */
6441         function getWidgetIdByWidgetType($url, $widgetType)
6442         {
6443                 $ret = $this->getPageIdFromUrl($url, $pageId, $pageSubId, $param);
6444                 
6445                 // ウィジェットIDを取得
6446                 if ($ret) $widgetId = $this->db->getWidgetIdByType($pageId, $pageSubId, $widgetType);
6447                 return $widgetId;
6448         }
6449         /**
6450          * ページコンテンツタイプ、コンテンツタイプからウィジェットIDを取得
6451          *
6452          * @param string $pageId                ページID
6453          * @param string $contentType    コンテンツタイプ
6454          * @return string                               ウィジェットID
6455          */
6456         function getWidgetIdWithPageInfoByContentType($pageId, $contentType)
6457         {
6458                 $widgetId = $this->db->getWidgetIdWithPageInfoByContentType($pageId, $contentType);
6459                 return $widgetId;
6460         }
6461         /**
6462          * ジョブタイプからウィジェットIDを取得
6463          *
6464          * @param string $jobType               ジョブタイプ
6465          * @return string                               ウィジェットID
6466          */
6467         function getWidgetIdByJobType($jobType)
6468         {
6469                 global $gEnvManager;
6470                 global $gErrorManager;
6471
6472                 // ジョブ実行用ウィジェット取得
6473                 $widgetId = '';
6474                 $linkInfoObj = $this->gInstance->getObject(self::LINKINFO_OBJ_ID);
6475                 if (isset($linkInfoObj)) $widgetId = $linkInfoObj->getJobWidget($jobType);
6476                 
6477                 // ウィジェットのアクセス権をチェック
6478                 if (!$this->db->canAccessWidget($widgetId)) return '';
6479
6480                 // ウィジェット情報取得
6481                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
6482
6483                 // 端末タイプをチェック
6484                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
6485                 
6486                 return $widgetId;
6487         }
6488         /**
6489          * 現在アクティブなメイン型ウィジェットをウィジェット種別で取得
6490          *
6491          * @param string $widgetType    対象ウィジェットタイプ
6492          * @return string                               ウィジェットID
6493          */
6494         function getActiveMainWidgetIdByWidgetType($widgetType)
6495         {
6496                 // ウィジェットIDを取得
6497                 $widgetId = $this->db->getActiveMainWidgetIdByType($widgetType);
6498                 return $widgetId;
6499         }
6500         /**
6501          * URLを解析して、ページID,サブページIDを取得
6502          *
6503          * @param string $url                   URL
6504          * @param string $pageId                ページID
6505          * @param string $pageSubId             ページサブID
6506          * @param array  $urlParam              URLパラメータ
6507          * @return bool                                 true=成功、false=失敗
6508          */
6509         function getPageIdFromUrl($url, &$pageId, &$pageSubId, &$urlParam)
6510         {
6511                 global $gEnvManager;
6512                         
6513                 // ページID、ページサブIDを求める
6514                 list($page, $other) = explode('?', str_replace($gEnvManager->getRootUrl(), '', $url));
6515                 parse_str($other, $urlParam);
6516                 
6517                 $pageId = str_replace('/', '_', trim($page, '/'));
6518                 $pageId = basename($pageId, '.php');
6519
6520                 // ページサブIDを取得
6521                 $pageSubId = $param[M3_REQUEST_PARAM_PAGE_SUB_ID];
6522                 if (empty($pageSubId)) $pageSubId = $gEnvManager->getDefaultPageSubId();
6523                 return true;
6524         }
6525         /**
6526          * ウィジェットが組み込まれているページのURLを生成
6527          *
6528          * @param string $widgetId      送信元ウィジェットID
6529          * @param string $param         実行パラメータ
6530          * @param string $pageId        ウィジェットが存在するページID
6531          * @return string                       生成したURL
6532          */
6533         function getDefaultPageUrlByWidget($widgetId, $param = '', $pageId = '')
6534         {
6535                 global $gEnvManager;
6536
6537                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6538                 
6539                 // このウィジェットがマップされているページサブIDを取得
6540                 $sub = '';
6541                 $subPageId = $this->getPageSubIdByWidget($pageId, $widgetId);
6542                 if (empty($subPageId)){
6543                         // 見つからないときは互換ウィジェットを探す
6544                         $targetWidgetId = $this->db->getCompatibleWidgetId($widgetId);
6545                         if (!empty($targetWidgetId)){
6546                                 $subPageId = $this->getPageSubIdByWidget($pageId, $targetWidgetId);
6547                         }
6548                 }
6549                 if (!empty($subPageId)) $sub = M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subPageId;
6550                 
6551                 //$url = $gEnvManager->getDefaultUrl();
6552                 $url = $gEnvManager->createPageUrl($pageId);
6553                 if (!empty($sub)) $url .= '?' . $sub;
6554                 if (!empty($param)) $url .= '&' . $param;
6555                 return $url;
6556         }
6557         /**
6558          * 現在のアクセスポイントの指定のページ属性のページURLを生成
6559          *
6560          * @param string $contentType   コンテンツタイプ
6561          * @param string $param                 追加パラメータ
6562          * @param bool $omitPageId              ページID省略形を使用するかどうか
6563          * @return string                               生成したURL
6564          */
6565         function createContentPageUrl($contentType, $param = '', $omitPageId = true)
6566         {
6567                 global $gEnvManager;
6568                 static $urlArray = array();
6569                 
6570                 // 複数回呼ばれるのでコンテンツタイプごとにページまでのURLは保存しておく
6571                 $baseUrl = $urlArray[$contentType];
6572                 if (!isset($baseUrl)){
6573                         // コンテンツタイプからページサブIDを取得
6574                         $pageSubId = $this->getPageSubIdByContentType($contentType, $gEnvManager->getCurrentPageId());          // DBから取得
6575                 
6576                         if (empty($pageSubId)){ // ページサブIDが取得できない場合はデフォルトのページサブIDを取得
6577                                 $pageSubId = $gEnvManager->getDefaultPageSubId();
6578                         } else if ($pageSubId == $gEnvManager->getDefaultPageSubId()){          // デフォルトページの場合
6579                                 if ($omitPageId) $pageSubId = '';       // ページID省略形を使用する場合はページサブIDを省略
6580                         }
6581                         
6582                         // 現在のアクセスポイントのURLを取得
6583                         $baseUrl = $gEnvManager->createPageUrl();
6584                         
6585                         // ページサブIDを付加
6586                         if (!empty($pageSubId)) $baseUrl .= '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId;
6587                         
6588                         // URLを保存
6589                         $urlArray[$contentType] = $baseUrl;
6590                 }
6591                 
6592                 // 追加パラメータ
6593                 $url = $baseUrl;
6594                 if (!empty($param)){
6595                         if (strEndsWith($url, '.php') || strEndsWith($url, '/')){
6596                                 $url .= '?';
6597                         } else {
6598                                 $url .= '&';
6599                         }
6600                         $url .= $param;
6601                 }
6602                 return $url;
6603         }
6604         /**
6605          * ウィジェット指定呼び出し用のURLを生成
6606          *
6607          * @param string $toWidgetId    送信先ウィジェットID
6608          * @param string $fromWidgetId  送信元ウィジェットID
6609          * @param string $todo                  実行パラメータ
6610          * @param string $pageId                ページID(空のときは現在のURL)
6611          * @return string                               生成したURL
6612          */
6613         function createWidgetCmdUrl($toWidgetId, $fromWidgetId, $todo, $pageId = '')
6614         {
6615                 global $gEnvManager;
6616                 
6617                 $url = $gEnvManager->createPageUrl($pageId);
6618                 
6619                 $url .= '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_FIND_WIDGET;
6620                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $toWidgetId;
6621                 if (!empty($fromWidgetId)) $url .= '&' . M3_REQUEST_PARAM_FROM . '=' . $fromWidgetId;           // 送信元
6622                 if (!empty($todo)) $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=' . urlencode($todo);
6623                 return $url;
6624         }
6625         /**
6626          * RSS配信用のURLを生成
6627          *
6628          * @param string $widgetId              実行ウィジェットID
6629          * @param string $optionParam   追加パラメータ
6630          * @param string $pageId                ページID(空のときは現在のURL)
6631          * @param string $pageSubId             ページサブID
6632          * @return string                               生成したURL
6633          */
6634         function createRssCmdUrl($widgetId, $optionParam = '', $pageId = '', $pageSubId = '')
6635         {
6636                 global $gEnvManager;
6637                 
6638                 // 現在のページURLを取得
6639                 $url = $gEnvManager->createPageUrl() . '?';
6640                 
6641                 // ページサブIDを取得
6642                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // グローバル属性ありのときは空
6643                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6644                 
6645                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_RSS;
6646                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
6647                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6648                 return $url;
6649         }
6650         /**
6651          * CSS生成用のURLを生成
6652          *
6653          * @param bool   $isSslPage             SSLが必要なページかどうか
6654          * @param string $optionParam   追加パラメータ
6655          * @return string                               生成したURL
6656          */
6657         function createCssCmdUrl($isSslPage, $optionParam = '')
6658         {
6659                 global $gEnvManager;
6660                 global $gRequestManager;
6661                 
6662                 // 現在のページURLを取得
6663         //      $url = $gEnvManager->createPageUrl() . '?';
6664                 $url = $gEnvManager->createPageUrl(''/*現在のページ*/, $isSslPage) . '?';
6665                 
6666                 // ページサブIDを取得
6667                 $pageSubId = $this->gEnv->getCurrentPageSubId();
6668                 $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6669                 
6670                 // コンテンツ詳細画面の場合はコンテンツパラメータを追加
6671                 if ($this->isContentDetailPage){
6672                         switch ($this->contentType){
6673                                 case M3_VIEW_TYPE_CONTENT:              // 汎用コンテンツ
6674                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_CONTENT_ID);
6675                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_CONTENT_ID_SHORT);
6676                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentsId . '&';
6677                                         break;
6678                                 case M3_VIEW_TYPE_PRODUCT:      // 製品
6679                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PRODUCT_ID);
6680                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PRODUCT_ID_SHORT);
6681                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_PRODUCT_ID . '=' . $contentsId . '&';
6682                                         break;
6683                                 case M3_VIEW_TYPE_BBS:  // BBS
6684                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BBS_THREAD_ID);
6685                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT);
6686                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $contentsId . '&';
6687                                         break;
6688                                 case M3_VIEW_TYPE_BLOG: // ブログ
6689                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BLOG_ENTRY_ID);
6690                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT);
6691                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $contentsId . '&';
6692                                         break;
6693                                 case M3_VIEW_TYPE_WIKI: // Wiki
6694                                         $contentsId = $gRequestManager->getWikiPageFromQuery();         // 「=」なしのパラメータはwikiパラメータとする
6695                                         if (!empty($contentsId)) $url .= $contentsId . '&';
6696                                         break;
6697                                 case M3_VIEW_TYPE_EVENT:        // イベント
6698                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_EVENT_ID);
6699                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_EVENT_ID_SHORT);
6700                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_EVENT_ID . '=' . $contentsId . '&';
6701                                         break;
6702                                 case M3_VIEW_TYPE_PHOTO:        // フォトギャラリー
6703                                         $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID);
6704                                         if (empty($contentsId)) $contentsId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID_SHORT);
6705                                         if (!empty($contentsId)) $url .= M3_REQUEST_PARAM_PHOTO_ID . '=' . $contentsId . '&';
6706                                         break;
6707                         }
6708                 }
6709                 
6710                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_CSS;
6711                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6712                 return $url;
6713         }
6714         /**
6715          * ウィジェット実行用のURLを生成
6716          *
6717          * @param string $widgetId      実行ウィジェットID
6718          * @param string $optionParam   追加パラメータ
6719          * @param bool $byMacro         マクロ変換で返すかどうか
6720          * @param string $pageId                ページID(空のときは現在のURL)
6721          * @param string $pageSubId             ページサブID
6722          * @return string                               生成したURL
6723          */
6724         function createDirectWidgetCmdUrl($widgetId, $optionParam = '', $byMacro = false, $pageId = '', $pageSubId = '')
6725         {
6726                 global $gEnvManager;
6727                 
6728                 // 現在のページURLを取得
6729                 if ($byMacro){
6730                         $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_FILENAME_INDEX . '?';
6731                 } else {
6732                         $url = $gEnvManager->createPageUrl() . '?';
6733                 }
6734                 
6735                 // ページサブIDを取得
6736                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // グローバル属性ありのときは空
6737                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
6738                 
6739                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_DO_WIDGET;
6740                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
6741                 if (!empty($optionParam)) $url .= '&' . $optionParam;
6742                 return $url;
6743         }
6744         /**
6745          * URLパラメータの並び順を取得
6746          *
6747          * @return array                                        パラメータ文字列の配列
6748          */
6749         function getUrlParamOrder()
6750         {
6751                 return $this->urlParamOrder;                                    // URLパラメータの並び順
6752         }
6753         /**
6754          * キャッシュ制御用の付加パラメータを取得
6755          *
6756          * @return string                               パラメータ
6757          */     
6758         function getCacheParam()
6759         {
6760                 $addParam = '?' . date('YmdHis');
6761                 return $addParam;
6762         }
6763         /**
6764          * 現在のURLにアクセス可能かチェック
6765          *
6766          * @param bool $isActivePage    ページが有効かどうか
6767          * @param int  $errCode                 エラーコード
6768          * @return bool                                 true=可能、false=不可
6769          */     
6770         function canAccessUrl(&$isActivePage, &$errCode)
6771         {
6772                 global $gEnvManager;
6773
6774                 $errCode = 0;                   // エラーコード初期化
6775                 
6776                 // 現在設定されているページIDを取得
6777                 $pageId         = $gEnvManager->getCurrentPageId();
6778                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
6779                 $ret = $this->db->canAccessPage($pageId, $pageSubId, $pageVisible, $pageSubVisible, $isAdminMenu);
6780                 if ($ret){              // アクセス可能なときは、ユーザ制限もチェックする
6781                         $isActivePage = true;
6782                         
6783                         // ページが表示可能かチェック
6784                         if (!$pageVisible || !$pageSubVisible) return false;
6785
6786                         if (!$gEnvManager->isCurrentUserLogined() && $this->isUserLimitedPage($pageId, $pageSubId)){                    // ユーザがログインされていない状態でユーザ制限されていればアクセス不可
6787                                 return false;
6788                         } else {
6789                                 $this->isAccessPointWithAdminMenu = $isAdminMenu;                               // 管理メニューを使用するアクセスポイントかどうか
6790                                 return true;
6791                         }
6792                 } else {                        // 無効ページのとき
6793                         $isActivePage = false;
6794                         
6795                         // ページIDの文字のチェック。ページIDは半角英小文字、数字、アンダーバー、ハイフンのみ使用可能。
6796                         if (preg_match("/[^0-9a-z-_]/", $pageSubId)) $errCode = 1;                      // 不正文字検出
6797                 }
6798                 return false;
6799         }
6800         /**
6801          * ウィジェットヘッダ(Joomla!1.0用)を出力タイプを取得
6802          *
6803          * @return int                          0=出力しない、1=Joomla!1.0テンプレートPC用、2=Joomla!1.0テンプレート携帯用
6804          */     
6805         function getTemplateWidgetHeaderType()
6806         {
6807                 global $gEnvManager;
6808                 
6809                 $templateId = $gEnvManager->getCurrentTemplateId();
6810                 if ($templateId == self::ADMIN_TEMPLATE){               // PC管理用テンプレート
6811                         return 0;
6812                 } else if(strncmp($templateId, 'm/', 2) == 0){          // 携帯用テンプレート
6813                         return 2;               // 携帯テンプレート用出力
6814                 } else {
6815                         return 1;               // PCテンプレート用出力
6816                 }
6817         }
6818         /**
6819          * SSLが必要なページかどうかを判断
6820          *
6821          * @param string $pageId        ページID
6822          * @param string $pageSubId     ページサブID
6823          * @return bool                         true=必要、false=不要
6824          */     
6825         function isSslPage($pageId, $pageSubId)
6826         {
6827                 global $gEnvManager;
6828                 
6829                 // パラメータ修正
6830                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6831                 
6832                 // 管理用ページの場合
6833                 if ($pageId == $gEnvManager->getDefaultAdminPageId()){
6834                         if ($gEnvManager->getUseSslAdmin()){            // 管理用ページにSSLを使用するかどうか
6835                                 return true;
6836                         } else {
6837                                 return false;
6838                         }
6839                 }
6840                 
6841                 // ##### フロント画面の場合 #####
6842                 if ($gEnvManager->isRootUrlSsl()) return true;          // ルートURLがSSLの場合はフロント画面のすべてがSSL付き
6843                 
6844                 // 一般用ページにSSLを使用しない場合は不要を返す
6845                 if (!$gEnvManager->getUseSsl()) return false;
6846                                         
6847                 // 一般用ページでSSLを使用する場合は、データベースの設定をチェックする
6848                 $line = $this->getPageInfo($pageId, $pageSubId);
6849                 if (!empty($line)){
6850                         if ($line['pn_use_ssl']){
6851                                 return true;
6852                         } else {
6853                                 return false;
6854                         }
6855                 }
6856                 return false;
6857         }
6858         /**
6859          * ユーザ制限が必要なページかどうかを判断
6860          *
6861          * @param string $pageId        ページID
6862          * @param string $pageSubId     ページサブID
6863          * @return bool                         true=必要、false=不要
6864          */     
6865         function isUserLimitedPage($pageId, $pageSubId)
6866         {
6867                 global $gEnvManager;
6868                 
6869                 // パラメータ修正
6870                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
6871                 
6872                 $line = $this->getPageInfo($pageId, $pageSubId);
6873                 if (!empty($line)){
6874                         if ($line['pn_user_limited']){
6875                                 return true;
6876                         } else {
6877                                 return false;
6878                         }
6879                 }
6880                 return false;
6881         }
6882         /**
6883          * ページ情報を取得
6884          *
6885          * @param string $pageId        ページID
6886          * @param string $pageSubId     ページサブID
6887          * @return array                        ページ情報レコード
6888          */     
6889         function getPageInfo($pageId, $pageSubId)
6890         {
6891                 // ページ情報が空のときはデータをロード
6892                 if (empty($this->pageInfo)){
6893                         $records = $this->db->getPageInfoRecords();
6894                         $count = count($records);
6895                         $this->pageInfo = array();
6896                         for ($i = 0; $i < $count; $i++){
6897                                 $pId = $records[$i]['pn_id'] . self::PAGE_ID_SEPARATOR . $records[$i]['pn_sub_id'];
6898                                 $this->pageInfo[$pId] = $records[$i];
6899                         }
6900                 }
6901                 return $this->pageInfo[$pageId . self::PAGE_ID_SEPARATOR . $pageSubId];
6902         }
6903         /**
6904          * 現在のページのページ情報を取得
6905          *
6906          * @return array                        ページ情報レコード
6907          */     
6908         function getCurrentPageInfo()
6909         {
6910                 return $this->currentPageInfo;
6911         }
6912         /**
6913          * 現在のページ情報からテンプレートIDを取得
6914          *
6915          * @param string $subTemplateId         テンプレートIDが取得できるときはサブページIDが返る
6916          * @return string                                       テンプレートID
6917          */     
6918         function getTemplateIdFromCurrentPageInfo(&$subTemplateId)
6919         {
6920                 $templateId = '';
6921                 if (!empty($this->currentPageInfo)){
6922                         $templateId = $this->currentPageInfo['pn_template_id'];
6923                         $subTemplateId = $this->currentPageInfo['pn_sub_template_id'];                  // サブテンプレートID
6924                 }
6925                 return $templateId;
6926         }
6927         /**
6928          * JavascriptライブラリのIDを取得
6929          *
6930          * @param int $type                     種別(0=すべて、1=jQuery関係すべて、2=jQueryプラグインのみ)
6931          * @return array                        JavascriptライブラリのID
6932          */     
6933         function getScriptLibId($type = 0)
6934         {
6935                 // Javascriptライブラリのすべてのキーを取得
6936                 $keys = array_keys($this->libFiles);
6937                 
6938                 $destKeys = array();
6939                 for ($i = 0; $i < count($keys); $i++){
6940                         switch ($type){
6941                                 case 1:         // jQuery関係すべて
6942                                         if (strStartsWith($keys[$i], 'jquery')) $destKeys[] = $keys[$i];
6943                                         break;
6944                                 case 2:         // jQueryプラグインのみ
6945                                         if (strStartsWith($keys[$i], 'jquery.')) $destKeys[] = $keys[$i];
6946                                         break;
6947                         }
6948                 }
6949                 return $destKeys;
6950         }
6951         /**
6952          * Javascriptライブラリの情報を取得
6953          *
6954          * @param string $id            ライブラリID
6955          * @return array                        ライブラリの情報
6956          */     
6957         function getScriptLibInfo($id)
6958         {
6959                 $libInfo = $this->libFiles[$id];
6960                 if (isset($libInfo)){
6961                         return $libInfo;
6962                 } else {
6963                         return array();
6964                 }
6965         }
6966         /**
6967          * 管理画面用jQueryUIテーマのURLを取得
6968          *
6969          * @return string                       テーマURL
6970          */     
6971         function getAdminDefaultThemeUrl()
6972         {
6973 //              $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
6974                 $themeFile = $this->gEnv->getAdminUrl(true/*「admin」削除*/) . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
6975                 return $themeFile;
6976         }
6977         /**
6978          * フロント画面用jQueryUIテーマのURLを取得
6979          *
6980          * @return string                       テーマURL
6981          */     
6982         function getDefaultThemeUrl()
6983         {
6984                 static $themeFile;
6985                 
6986                 if (!isset($themeFile)){
6987                         $themeFile = '';
6988                         $theme = $this->gSystem->defaultTheme();
6989                         if (!empty($theme)){
6990                                 $path = $this->gEnv->getSystemRootPath() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
6991                                 if (file_exists($path)) $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
6992                         }
6993                 }
6994                 return $themeFile;
6995         }
6996         /**
6997          * URLパラメータ文字列作成
6998          *
6999          * @param array $paramArray                     URL作成用のパス
7000          * @return string                                       作成したURLパラメータ
7001          */
7002         function _createUrlParamStr($paramArray)
7003         {
7004                 $destParam = '';
7005                 if (count($paramArray) == 0) return $destParam;
7006
7007                 $sortParam = array();
7008                 $keys = array_keys($paramArray);
7009                 $keyCount = count($keys);
7010                 for ($i = 0; $i < $keyCount; $i++){
7011                         $key = $keys[$i];
7012                         $value = $paramArray[$key];
7013                         $orderNo = $this->urlParamOrder[$key];
7014                         if (!isset($orderNo)) $orderNo = 100;
7015                         $sortParam[] = array('key' => $key, 'value' => $value, 'no' => $orderNo);
7016                 }
7017 //              usort($sortParam, create_function('$a,$b', 'return $a["no"] - $b["no"];'));
7018                 usort($sortParam, function($a, $b)
7019                 {
7020                         return $a['no'] - $b['no'];
7021                 });
7022                 
7023                 // 文字列を作成
7024                 $sortCount = count($sortParam);
7025                 for ($i = 0; $i < $sortCount; $i++){
7026                         if ($i > 0) $destParam .= '&';
7027                         $destParam .= rawurlencode($sortParam[$i]['key']) . '=' . rawurlencode($sortParam[$i]['value']);
7028                 }
7029                 return $destParam;
7030         }
7031         /**
7032          * DBからCSSファイル(テンプレート独自のCSSまたは外部のCSS)を取得
7033          *
7034          * @param string $templateId    テンプレートID
7035          * @return bool                                 true=取得成功、false=取得失敗
7036          */
7037         function loadCssFiles($templateId = '')
7038         {
7039                 if (empty($templateId)) $templateId = $this->gSystem->defaultTemplateId();              // PC画面デフォルトのテンプレートを取得
7040
7041                 $ret = $this->db->getTemplate($templateId, $row);
7042                 if (!$ret) return false;
7043                 
7044                 // 編集エディタ用パラメータが初期化されていない場合は初期化
7045                 if (empty($row['tm_editor_param'])){
7046                         // テンプレートを解析し、使用しているCSSファイルを取得
7047                         $editorParamObj = $this->parseTemplate($templateId);
7048                         
7049                         // テンプレートの情報を更新
7050                         $updateParam = array();
7051                         $updateParam['tm_editor_param'] = serialize($editorParamObj);
7052                         $ret = $this->db->updateTemplate($templateId, $updateParam);
7053                 } else {
7054                         $editorParamObj = unserialize($row['tm_editor_param']);
7055                 }
7056                 
7057                 if (isset($editorParamObj)){
7058                         $this->ckeditorCssFiles = array();
7059                         $cssFiles = $editorParamObj->cssFiles;
7060                         for ($i = 0; $i < count($cssFiles); $i++){
7061                                 $cssFile = $cssFiles[$i];
7062                                 
7063                                 if (strStartsWith($cssFile, '//')){             // URLが「//」で始まる外部ファイルの場合はそのまま追加
7064                                         $this->ckeditorCssFiles[] = $cssFile;
7065                                 } else if (strStartsWith($cssFile, '/')){               // URLが「/」で始まる相対パスの場合はURLに変換
7066                                         $this->ckeditorCssFiles[] = $this->gEnv->getAdminUrl(true/*adminディレクトリ削除*/) . $cssFile;
7067                                 } else {
7068                                         $this->ckeditorCssFiles[] = $cssFile;
7069                                 }
7070                         }
7071                         return true;
7072                 } else {
7073                         return false;
7074                 }
7075         }
7076         /**
7077          * URLで指定した画面のCSSファイル(テンプレート独自のCSSまたは外部のCSS)を取得
7078          *
7079          * @param string $url   取得画面のURL
7080          * @return                              なし
7081          */
7082         function loadCssFilesByUrl($url)
7083         {
7084                 // ##### cURLを使用する場合はセッションのブロックを解除する #####
7085                 session_write_close();
7086                 
7087                 $ch = curl_init();
7088                 curl_setopt($ch, CURLOPT_URL, $url);
7089                 curl_setopt($ch, CURLOPT_USERAGENT, M3_SYSTEM_NAME . '/' . M3_SYSTEM_VERSION);          // ユーザエージェント
7090                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         // 画面に出力しない
7091                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
7092                 curl_setopt($ch, CURLOPT_TIMEOUT, 3);
7093                 curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());          // セッションを維持
7094                 $content = curl_exec($ch);
7095                 curl_close($ch);
7096
7097                 // HEADタグを取り出す
7098                 $urlArray = array();
7099                 $headContent = '';
7100                 $pattern = '/<head\b[^>]*?>(.*?)<\/head\b[^>]*?>/si';
7101                 if (preg_match($pattern, $content, $matches)) $headContent = $matches[0];
7102
7103                 // CSSファイル取り出し
7104                 $pattern = '/<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
7105                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7106                         foreach ($matches as $match){
7107                                 if (strEndsWith($match[1], '.css')){            // ファイル名の拡張子が「css」の場合
7108                                         $urlArray[] = $match[1];
7109                                 } else {
7110                                         // typeが「text/css」を取得
7111                                         $attrPattern = '/type\s*=\s*[\'"]+(.+?)[\'"]/si';
7112                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7113                                                 if (strcasecmp($attrMatch[1], 'text/css') == 0){
7114                                                         $urlArray[] = $match[1];
7115                                                         continue;
7116                                                 }
7117                                         }
7118                                         // relが「stylesheet」を取得
7119                                         $attrPattern = '/rel\s*=\s*[\'"]+(.+?)[\'"]/si';
7120                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7121                                                 if (strcasecmp($attrMatch[1], 'stylesheet') == 0){
7122                                                         $urlArray[] = $match[1];
7123                                                         continue;
7124                                                 }
7125                                         }
7126                                 }
7127                         }
7128                 }
7129
7130                 // ifで制御されているCSSファイルを除く
7131                 $delUrlArray = array();
7132                 $pattern = '/<!--\[if\b.*?\]>[\s\S]*<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>[\s\S]*<!\[endif\]-->/si';
7133                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7134                         foreach ($matches as $match) $delUrlArray[] = $match[1];
7135                 }
7136
7137                 // ##### テンプレート独自のCSSまたは外部のCSSを取得する #####
7138                 $this->ckeditorCssFiles = array();
7139                 $cssFiles = array_merge(array_diff($urlArray, $delUrlArray));   // CKEditor用のCSSファイル
7140                 for ($i = 0; $i < count($cssFiles); $i++){
7141                         $cssFileUrl = $cssFiles[$i];
7142                         $baseUrl = '';
7143                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7144                                 $baseUrl = $this->gEnv->getRootUrl();
7145                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7146                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7147                         }
7148                         // パスを解析
7149                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7150                         
7151                         if (strStartsWith($relativePath, '//')){                // URLが「//」で始まる外部ファイルの場合
7152                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7153                         } else if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){            // テンプレートディレクトリの場合
7154                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7155                         } else if (strStartsWith($relativePath, '/')){          // テンプレートディレクトリ以外のディレクトリの場合
7156                         } else {                        // 外部URLの場合
7157                                 $this->ckeditorCssFiles[] = $cssFileUrl;
7158                         }
7159                 }
7160
7161                 // テンプレートタイプを取得
7162                 $pattern = '/var\s*M3_TEMPLATE_TYPE\s*=\s*(\d+?)\s*;/si';
7163                 if (preg_match($pattern, $headContent, $matches)) $this->ckeditorTemplateType = $matches[1];                    // CKEditor用のテンプレートタイプ
7164         }
7165         /**
7166          * CKEditor用のテンプレートタイプを取得
7167          *
7168          * @return int                  テンプレートタイプ
7169          */     
7170         function getCkeditorTemplateType()
7171         {
7172                 return $this->ckeditorTemplateType;
7173         }
7174         /**
7175          * POST時のリファラーチェック
7176          *
7177          * @return bool         true=正常、false=不正
7178          */
7179 /*      function _checkReferer()
7180         {
7181                 global $gEnvManager;
7182                 global $gRequestManager;
7183                 
7184                 // リファラーをチェック
7185                 $referer        = $gRequestManager->trimServerValueOf('HTTP_REFERER');
7186                 $uri            = $gEnvManager->getCurrentRequestUri();
7187                 if (empty($referer) || $referer != $uri){
7188                         return false;
7189                 } else {
7190                         return true;
7191                 }
7192         }*/
7193         /**
7194          * テンプレート画面を解析してCSSファイルやポジションの情報を取得
7195          *
7196          * @param string $templateId    テンプレートID
7197          * @return                                              テンプレート情報オブジェクト
7198          */
7199         function parseTemplate($templateId)
7200         {
7201                 // ##### cURLを使用する場合はセッションのブロックを解除する #####
7202                 session_write_close();
7203
7204                 // テンプレートのURL
7205                 $url = $this->gEnv->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_SHOW_POSITION . '&template=' . $templateId;
7206                 
7207                 // テンプレート情報オブジェクト
7208                 $tmplateInfoObj = new stdClass;
7209                 $tmplateInfoObj->cssFiles       = array();              // テンプレートで使用されているCSSファイル
7210                 
7211                 $ch = curl_init();
7212                 curl_setopt($ch, CURLOPT_URL, $url);
7213                 curl_setopt($ch, CURLOPT_USERAGENT, M3_SYSTEM_NAME . '/' . M3_SYSTEM_VERSION);          // ユーザエージェント
7214                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         // 画面に出力しない
7215                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
7216                 curl_setopt($ch, CURLOPT_TIMEOUT, 3);
7217                 curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());          // セッションを維持
7218                 $content = curl_exec($ch);
7219                 curl_close($ch);
7220
7221                 // HEADタグを取り出す
7222                 $urlArray = array();
7223                 $headContent = '';
7224                 $pattern = '/<head\b[^>]*?>(.*?)<\/head\b[^>]*?>/si';
7225                 if (preg_match($pattern, $content, $matches)) $headContent = $matches[0];
7226
7227                 // CSSファイル取り出し
7228                 $pattern = '/<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>/si';
7229                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7230                         foreach ($matches as $match){
7231                                 if (strEndsWith($match[1], '.css')){            // ファイル名の拡張子が「css」の場合
7232                                         $urlArray[] = $match[1];
7233                                 } else {
7234                                         // typeが「text/css」を取得
7235                                         $attrPattern = '/type\s*=\s*[\'"]+(.+?)[\'"]/si';
7236                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7237                                                 if (strcasecmp($attrMatch[1], 'text/css') == 0){
7238                                                         $urlArray[] = $match[1];
7239                                                         continue;
7240                                                 }
7241                                         }
7242                                         // relが「stylesheet」を取得
7243                                         $attrPattern = '/rel\s*=\s*[\'"]+(.+?)[\'"]/si';
7244                                         if (preg_match($attrPattern, $match[0], $attrMatch)){
7245                                                 if (strcasecmp($attrMatch[1], 'stylesheet') == 0){
7246                                                         $urlArray[] = $match[1];
7247                                                         continue;
7248                                                 }
7249                                         }
7250                                 }
7251                         }
7252                 }
7253
7254                 // ifで制御されているCSSファイルを除く
7255                 $delUrlArray = array();
7256                 $pattern = '/<!--\[if\b.*?\]>[\s\S]*<link[^<]*?href\s*=\s*[\'"]+(.+?)[\'"]+[^>]*?>[\s\S]*<!\[endif\]-->/si';
7257                 if (preg_match_all($pattern, $headContent, $matches, PREG_SET_ORDER)){
7258                         foreach ($matches as $match) $delUrlArray[] = $match[1];
7259                 }
7260
7261                 // テンプレート独自のCSSまたは外部のCSSを取得する
7262                 $cssFiles = array_merge(array_diff($urlArray, $delUrlArray));   // CKEditor用のCSSファイル
7263                 for ($i = 0; $i < count($cssFiles); $i++){
7264                         $cssFileUrl = $cssFiles[$i];
7265                         $baseUrl = '';
7266                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7267                                 $baseUrl = $this->gEnv->getRootUrl();
7268                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7269                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7270                         }
7271                         // パスを解析
7272                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7273                         
7274                         if (strStartsWith($relativePath, '//')){                // URLが「//」で始まる外部ファイルの場合
7275                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7276                         } else if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){            // テンプレートディレクトリの場合
7277                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7278                         } else if (strStartsWith($relativePath, '/')){          // テンプレートディレクトリ以外のディレクトリの場合
7279                         } else {                        // 外部URLの場合
7280                                 $tmplateInfoObj->cssFiles[] = $cssFileUrl;
7281                         }
7282                 }
7283                 
7284                 // パスを相対パスに変換
7285                 for ($i = 0; $i < count($tmplateInfoObj->cssFiles); $i++){
7286                         $cssFileUrl = $tmplateInfoObj->cssFiles[$i];
7287                         
7288                         $baseUrl = '';
7289                         if (strncasecmp($cssFileUrl, 'http://', strlen('http://')) == 0){
7290                                 $baseUrl = $this->gEnv->getRootUrl();
7291                         } else if (strncasecmp($cssFileUrl, 'https://', strlen('https://')) == 0){
7292                                 $baseUrl = $this->gEnv->getSslRootUrl();                // SSLの場合
7293                         }
7294                         // パスを解析
7295                         $relativePath = str_replace($baseUrl, '', $cssFileUrl);         // ルートURLからの相対パスを取得
7296                         
7297                         // テンプレート内のCSSの場合は相対パスに変換
7298                         if (strStartsWith($relativePath, '/' . M3_DIR_NAME_TEMPLATES . '/')){// テンプレートディレクトリの場合
7299                                 $tmplateInfoObj->cssFiles[$i] = $relativePath;
7300                         } else {
7301                                 $tmplateInfoObj->cssFiles[$i] = $cssFileUrl;
7302                         }
7303                 }
7304                 
7305                 // テンプレートのポジションを取得
7306                 $tmplateInfoObj->positions = array();
7307                 $pattern = '/var\s*M3_POSITION_DATA\s*=\s*[\'"]+(.+?)[\'"]/si';
7308                 if (preg_match($pattern, $headContent, $matches) && !empty($matches[1])){
7309                         $tmplateInfoObj->positions = explode(',', $matches[1]);
7310                 }
7311                 return $tmplateInfoObj;
7312         }
7313         /**
7314          * デフォルトのテンプレートからレイアウト用テンプレートで使用していないポジションを取得
7315          *
7316          * @return array                                ポジション名の配列
7317          */
7318         function getLayoutTemplatePosition()
7319         {
7320                 $removePositions = array('header', 'extra1', 'extra2', 'brand', 'hmenu', 'user3', 'banner1', 'top1', 'top2', 'top3',
7321                                                                 'left', 'banner2', 'breadcrumb', 'user1', 'user2', 'banner3', 'main-top', 'main', 'main-bottom', 'banner4', 'user4', 'user5', 'banner5', 
7322                                                                 'right','bottom1', 'bottom2', 'bottom3', 'banner6', 'syndicate', 'copyright', 'footer');                // レイアウト用テンプレートに存在するので削除するポジション
7323                 
7324                 // URLパラメータからデフォルトのテンプレートを取得
7325                 $pageId = $this->gRequest->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
7326
7327                 $templateId = '';
7328                 if ($pageId == $this->gEnv->getDefaultPageId()){                // 通常サイトのとき
7329                         $templateId = $this->gSystem->defaultTemplateId();
7330                 } else if ($pageId == $this->gEnv->getDefaultSmartphonePageId()){               // スマートフォン用サイトのとき
7331                         $templateId = $this->gSystem->defaultSmartphoneTemplateId();            // スマートフォン用デフォルトテンプレート
7332                 }
7333
7334                 // テンプレート情報取得
7335                 $ret = $this->db->getTemplate($templateId, $row);
7336                 if (!$ret) return array();
7337                 if (empty($row['tm_editor_param'])) return array();
7338         
7339                 // レイアウト用テンプレートに存在しないポジション名のみ返す
7340                 $editorParamObj = unserialize($row['tm_editor_param']);
7341                 if (isset($editorParamObj)){
7342                         if (isset($editorParamObj->positions)){
7343                                 $srcArray = $editorParamObj->positions;
7344                                 $destArray = array();
7345                                 for ($i = 0; $i < count($srcArray); $i++){
7346                                         $position = $srcArray[$i];
7347                                         if (!in_array($position, $removePositions)) $destArray[] = $position;
7348                                 }
7349                                 return $destArray;
7350                         }
7351                 }
7352                 return array();
7353         }
7354 }
7355 ?>