OSDN Git Service

a6a4cd5a725e69e133332c2fb12db1e94de3278b
[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-2014 Magic3 Project.
14  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
15  * @version    SVN: $Id$
16  * @link       http://www.magic3.org
17  */
18 require_once(M3_SYSTEM_INCLUDE_PATH . '/common/core.php');
19 require_once(M3_SYSTEM_INCLUDE_PATH . '/common/scriptLibInfo.php');
20
21 class PageManager extends Core
22 {
23         private $popupMsg;                              // ポップアップダイアログメッセージ
24         private $showPositionMode;                      // ポジション表示モード
25         private $showWidget;                    // ウィジェットの単体表示
26         private $systemHandleMode;                      // システム制御遷移モード(1=サイト非公開時)
27         private $isPageEditable;                // 一般画面ページ編集可能モード
28         private $isTransparentMode;             // 画面透過モード
29         private $isEditMode;                    // 一般画面編集モード
30         private $isLayout;                              // 画面レイアウト中かどうか
31         private $tmpData;                               // データ作成用
32         private $db;                                    // DBオブジェクト
33         private $defaultScriptFiles;    // デフォルトで読み込むスクリプトファイル
34         private $defaultCssFiles;               // デフォルトで読み込むCSSファイル
35         private $defaultAdminScriptFiles;       // デフォルトで読み込むスクリプトファイル(管理用)
36         private $defaultAdminCssFiles;          // デフォルトで読み込むCSSファイル(管理用)
37         private $defaultAdminDirScriptFiles;    // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
38         private $defaultAdminDirCssFiles;       // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
39         private $headScriptFiles = array();             // ウィジェットからの追加で読み込むスクリプトファイル
40         private $headPreMobileScriptFiles = array();// ウィジェットからの追加で読み込むスクリプトファイル(jQueryMobile用挿入ファイル)
41         private $headCssFiles = array();                // ウィジェットからの追加で読み込むCSSファイル
42         private $headRssFiles = array();                // HTMLヘッダに出力するRSS配信情報
43         private $pageDefPosition;               // 現在取得しているページ定義のポジション
44         private $pageDefRows;                   // ページ定義レコード
45         private $nonSharedWidgetCount = -1;     // 非共通ウィジェットの数(-1=ページ作成でないとき)
46         private $replaceHeadDone;                       // ヘッダマクロ変換処理が完了したかどうか
47         private $useHelp = false;               // 標準ヘルプ機能を使用するかどうか
48         private $hasScriptCache = false;        // JavaScriptファイルをブラウザにキャッシュさせるかどうか
49         private $isAccessPointWithAdminMenu;                            // 管理メニューを使用するアクセスポイントかどうか
50         private $lateLaunchWidgetList;  // 遅延実行ウィジェットのリスト
51         private $latelaunchWidgetParam;         // 遅延実行ウィジェットのパラメータ
52         private $viewPositions = array();       // テンプレート上のポジション
53         private $viewPosId = array();           // テンプレート上のポジションのタグID
54         private $updateParentWindow;            // 親ウィンドウを再描画するかどうか
55         private $updateDefSerial;                       // 更新する項目のページ定義シリアル番号
56         private $headDescription;                               // HTMLヘッダ「description」に出力する文字列
57         private $headKeywords;                          // HTMLヘッダ「keywords」に出力する文字列
58         private $headOthers;                            // HTMLヘッダに出力するタグ文字列
59         private $lastHeadTitle;                         // 最後にヘッダ部titleにセットした文字列
60         private $lastHeadDescription;           // 最後にヘッダ部descriptionにセットした文字列
61         private $lastHeadKeywords;                      // 最後にヘッダ部keywordsにセットした文字列
62         private $headCss = array();                     // HTMLヘッダにCSS出力する文字列
63         private $headScript = array();          // HTMLヘッダにJavascript出力する文字列
64         private $headPreMobileScript = array();         // HTMLヘッダにJavascript出力する文字列(jQueryMobile用挿入スクリプト)
65         private $headString = array();          // HTMLヘッダに出力する任意文字列
66         private $lastHeadCss;                           // 最後に設定したHTMLヘッダにCSS出力する文字列
67         private $lastHeadScript;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
68         private $lastHeadString;                        // 最後に設定したHTMLヘッダに出力する任意文字列
69         private $initScript = '';                               // ウィンドウ初期化時に実行されるスクリプト
70         private $outputByHtml = true;                           // HTMLフォーマットで出力するかどうか
71         private $outputHead;                            // HTMLヘッダ出力を行ったかどうか
72         private $outputTheme;                           // jQueryUIテーマ出力を行ったかどうか
73         private $isAbort;                                       // ページ作成処理を中断するかどうか
74         private $isRedirect;                            // リダイレクトするかどうか
75         private $libFiles;                                      // javascript追加用ライブラリ
76         private $pageDefRev = 234;                              // 画面定義のリビジョン番号
77         private $headSubTitle = array();                                // ヘッダタグサブタイトル
78         private $headSubTitleUrl = array();                             // ヘッダサブタイトルのリンク先
79         private $pageInfo;                                      // すべてのページ情報
80         private $currentPageInfo;                       // 現在のページのページ情報
81         private $configWidgetInfo;                      // ウィジェット設定画面のウィジェットの情報
82         private $contentType = '';                              // ページのコンテンツタイプ
83         private $mainContentType;                               // 一般画面で使用する主要コンテンツタイプ
84         private $mainFeatureType;                               // 一般画面で使用する主要機能タイプ
85         private $rssVersion;                                    // RSSバージョン
86         private $rssChannel;                            // RSSチャンネルデータ
87         private $selectedJQueryFilename;                // 使用対象のjQueryファイル
88         private $selectedJQueryUiFilename;              // 使用対象のjQuery UIファイル
89         private $selectedJQueryMobileFilename;          // 使用対象のjQueryMobileファイル
90         private $urlParamOrder;                                 // URLパラメータの並び順
91         private $wysiwygEditor;                         // 管理画面用WYSIWYGエディター
92         private $optionTemplateId;                      // 追加設定するテンプレートID
93         private $isContentGooglemaps;           // コンテンツにGoogleマップが含むかどうか
94         private $useGooglemaps;                         // Googleマップを使用するかどうか
95         private $useBootstrap;                          // Bootstrapを使用するかどうか
96         private $isHtml5;                                       // HTML5で出力するかどうか
97         const CONFIG_KEY_HEAD_TITLE_FORMAT = 'head_title_format';               // ヘッダ作成用フォーマット
98         const ADMIN_WIDGET_ID = 'admin_main';           // 管理用ウィジェットのウィジェットID
99         //const CONTENT_TYPE_WIKI = 'wiki';             // ページのコンテンツタイプ(Wiki)
100         const WIDGET_ID_TAG_START = '{{WIDGETID:';              // 遅延実行用タグ
101         const WIDGET_ID_TAG_END = '}}';         // 遅延実行用タグ
102         const WIDGET_ID_TITLE_TAG_START = '{{WIDGETID_TITLE:';          // 遅延実行用タグ(タイトル埋め込み用)
103         const WIDGET_ID_TITLE_TAG_END = '}}';                                           // 遅延実行用タグ(タイトル埋め込み用)
104         const WIDGET_ID_SEPARATOR = ',';
105         const HEAD_TAGS                         = '{{HEAD_TAGS}}';                              // HTMLヘッダ出力用タグ
106         const WIDGET_ICON_IMG_SIZE = 32;                        // ウィジェットアイコンサイズ
107         const WIDGET_OUTER_CLASS = 'm3_widget_outer';                   // ウィジェット外枠クラスクラス
108         const WIDGET_OUTER_CLASS_HEAD_POSITION = 'm3_pos_';                     // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
109         const WIDGET_OUTER_CLASS_WIDGET_TAG = 'm3_';                            // ウィジェットの外枠クラス用ヘッダ(ポジション表示用)
110         const WIDGET_INNER_CLASS = 'm3_widget_inner';                   // ウィジェットの内側クラス
111         const POSITION_TAG_HEAD = 'm3pos_';                     // ポジションの識別用タグIDヘッダ
112         const WIDGET_TAG_HEAD = 'm3widget_';                    // ウィジェットの識別用タグIDヘッダ
113 //      const WIDGET_TAG_HEAD_SHORT = 'm3_';                    // ウィジェットの識別用タグIDヘッダ
114         const WIDGET_TYPE_TAG_HEAD = 'm3widgettype_';                   // ウィジェット種別の識別用タグIDヘッダ
115         const WIDTET_CLASS_NAME = 'm3widget';                   // ウィジェットオブジェクトのタグクラス名
116         const WIDTET_CLASS_TYPE_0 = 'm3widget_type0';                   // ウィジェットオブジェクトのタグクラス(ページ共通でない)
117         const WIDTET_CLASS_TYPE_1 = 'm3widget_type1';                   // ウィジェットオブジェクトのタグクラス(ページ共通)
118         const POSITION_CLASS_NAME = 'm3position';               // ポジションオブジェクトのタグクラス名
119         const JOOMLA10_DEFAULT_WIDGET_MENU_PARAM = 'class="moduletable"';       // Joomla!1.0用デフォルトメニューパラメータ値
120         const ADMIN_TEMPLATE = '_admin';                // PC管理用テンプレートID
121         const M_ADMIN_TEMPLATE = 'm/_admin';    // 携帯用管理画面テンプレートID
122         const SCRIPT_LIB_SEPARATOR = ';';                       // JavaScriptライブラリ読み込み設定のライブラリの区切り
123         const PAGE_ID_SEPARATOR = ',';                          // ページIDとページサブID連結用
124         const DEFAULT_ADMIN_FAVICON_FILE = '/images/system/favicon.ico';                        // デフォルトの管理画面用faviconファイル
125         const DEFAULT_FAVICON_FILE = '/favicon.ico';                    // デフォルトのfaviconファイル
126 //      const DEFAULT_SITE_NAME = 'サイト名未設定';              // 管理画面用のデフォルトサイト名
127         const DEFAULT_ADMIN_TITLE = '管理画面';                     // デフォルトの管理画面名
128         const WIDGET_TITLE_START = '[';                                 // ウィジェットのタイトルの括弧
129         const WIDGET_TITLE_END = ']';                                   // ウィジェットのタイトルの括弧
130         const DEFAULT_RSS_VERSION = '1.0';                              // デフォルトのRSSのバージョン
131         const CF_ACCESS_IN_INTRANET = 'access_in_intranet';             // イントラネット運用かどうか
132         const CF_USE_LATEST_SCRIPT_LIB = 'dev_use_latest_script_lib';           // 最新のJavaScriptライブラリを使用するかどうか
133         const CF_GOOGLE_MAPS_KEY = 'google_maps_key';                           // Googleマップ利用キー
134         const CF_CONFIG_WINDOW_OPEN_TYPE = 'config_window_open_type';           // ウィジェット設定画面のウィンドウ表示タイプ(0=別ウィンドウ、1=タブ)
135         const CF_JQUERY_VERSION = 'jquery_version';                     // jQueryバージョン
136         const CF_WYSIWYG_EDITOR = 'wysiwyg_editor';             // 管理画面用WYSIWYGエディター
137         const CF_ADMIN_JQUERY_VERSION = 'admin_jquery_version';                 // 管理画面用jQueryバージョン
138         const CF_USE_JQUERY = 'use_jquery';                             // jQueryを常に使用するかどうか
139         const CF_SMARTPHONE_USE_JQUERY_MOBILE = 'smartphone_use_jquery_mobile';         // スマートフォン画面でjQuery Mobileを使用
140         const SD_HEAD_OTHERS    = 'head_others';                // ヘッダその他タグ
141         const DEFAULT_THEME_DIR = '/ui/themes/';                                // jQueryUIテーマ格納ディレクトリ
142         const THEME_CSS_FILE = 'jquery-ui.custom.css';          // テーマファイル
143         const CONFIG_ICON_FILE = '/images/system/config.png';                   // ウィジェット定義画面アイコン
144         const ADJUST_ICON_FILE = '/images/system/adjust_widget.png';    // 位置調整アイコン
145         const SHARED_ICON_FILE = '/images/system/shared.png';   // ページ共通属性
146         const DELETE_ICON_FILE = '/images/system/delete.png';   // ウィジェット削除
147         const CONFIG_ICON32_FILE = '/images/system/config32.png';                       // ウィジェット定義画面アイコン(ツールチップ用)
148         const ADJUST_ICON32_FILE = '/images/system/adjust_widget32.png';        // 位置調整アイコン(ツールチップ用)
149         const CLOSE_BOX_ICON32_FILE = '/images/system/close_box.png';           // ウィンドウ閉じるアイコン(ツールチップ用)
150         const NOTICE_ICON_FILE = '/images/system/notice16.png';         // ウィジェット配置注意アイコン
151 //      const ADMIN_ICON_FILE = '/images/system/admin64.png';           // パネルメニュー管理画面遷移用アイコン
152 //      const LOGOUT_ICON_FILE = '/images/system/logout64.png';         // パネルメニューログアウト用アイコン
153 //      const EDIT_PAGE_ICON_FILE = '/images/system/create_page64.png';         // パネルメニュー編集用アイコン   
154         const ADMIN_ICON_FILE = '/images/system/home32.png';            // パネルメニュー管理画面遷移用アイコン
155         const LOGOUT_ICON_FILE = '/images/system/logout32.png';         // パネルメニューログアウト用アイコン
156         const EDIT_PAGE_ICON_FILE = '/images/system/create_page32.png';         // パネルメニュー編集用アイコン   
157 //      const EDIT_END_ICON_FILE = '/images/system/close32.png';                // パネルメニュー編集終了用アイコン
158         const EDIT_END_ICON_FILE = '/images/system/back32.png';         // パネルメニュー編集終了用アイコン
159         const CLOSE_ICON_FILE = '/images/system/close32.png';           // ウィンドウ閉じるアイコン
160         const PREV_ICON_FILE = '/images/system/prev48.png';             // ウィンドウ「前へ」アイコン
161         const NEXT_ICON_FILE = '/images/system/next48.png';             // ウィンドウ「次へ」アイコン
162         const DEFAULT_READMORE_TITLE = 'もっと読む';                       // もっと読むボタンのデフォルトタイトル
163         const POS_HEAD_NAV_MENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー"></i> ';             // 特殊ポジションブロック(ナビゲーションメニュー)
164         const WIDGET_MARK_MAIN = '<i class="glyphicon glyphicon-tower" rel="m3help" title="メインウィジェット"></i> ';         // ウィジェットの機能マーク(メインウィジェット)
165         const WIDGET_MARK_NAVMENU = '<i class="glyphicon glyphicon-th" rel="m3help" title="ナビゲーションメニュー"></i> ';           // ウィジェットの機能マーク(ナビゲーションメニュー)
166         const WIDGET_FUNCTION_MARK_BOOTSTRAP = ' <span class="label label-warning" rel="m3help" title="Bootstrap型">B</span>';                 // ウィジェット機能マーク(Boostrap型テンプレート
167         const WIDGET_STYLE_NAVMENU = '_navmenu';                // ウィジェットの表示スタイル(ナビゲーションメニュー)
168                         
169         // アドオンオブジェクト用
170         const CONTENT_OBJ_ID    = 'contentlib'; // 汎用コンテンツオブジェクトID
171         const BLOG_OBJ_ID               = 'bloglib';            // ブログオブジェクトID
172         
173         // インナーウィジェット用
174         const IWIDTET_CMD_CONTENT = 'content';          // コンテンツ取得
175         const IWIDTET_CMD_INIT = 'init';                        // 初期化
176         const IWIDTET_CMD_UPDATE = 'update';            // 更新
177         const IWIDTET_CMD_CALC = 'calc';                        // 計算
178         
179         // Magic3用スクリプト
180         const M3_ADMIN_SCRIPT_FILENAME                  = 'm3admin1.7.4.js';                            // 管理機能用スクリプト(FCKEditor2.6.6、CKEditor4.0.1対応)
181         const M3_ADMIN_WIDGET_SCRIPT_FILENAME   = 'm3admin_widget2.0.3.js';     // 管理機能(ウィジェット操作)用スクリプト(Magic3 v1.15.0以降)
182         const M3_ADMIN_WIDGET_CSS_FILE                  = '/m3/widget.css';                     // 管理機能(ウィジェット操作)用CSSファイル
183         const M3_STD_SCRIPT_FILENAME                    = 'm3std1.4.5.js';                      // 一般、管理機能共通スクリプト
184         const M3_PLUS_SCRIPT_FILENAME                   = 'm3plus1.6.1.js';                     // 一般画面追加用スクリプト(FCKEditor2.6.6対応、CKEditor4.0.1対応)
185         const M3_OPTION_SCRIPT_FILENAME                 = 'm3opt1.1.0.js';                      // AJAXを含んだオプションライブラリファイル(jQuery必須)
186         const M3_ADMIN_CSS_FILE                                 = 'm3/admin.css';                       // 管理機能用のCSS
187         const M3_EDIT_CSS_FILE                                  = 'm3/edit.css';                        // 一般画面編集用のCSS
188         const M3_DEFAULT_CSS_FILE                               = 'm3/default.css';                     // 一般画面共通のデフォルトCSS
189 //      const M3_NO_BOOTSTRAP_CSS_FILE                  = 'm3/nobootstrap/style.css';           // 管理画面でBootstrapの読み込みなしの場合のCSS
190         
191         // 読み込み制御
192         const USE_BOOTSTRAP_ADMIN       = false;                        // 管理画面でBootstrapを使用するかどうか(デフォルト値)
193         const BOOTSTRAP_BUTTON_CLASS = 'btn btn-default';
194         
195         /**
196          * コンストラクタ
197          */
198         function __construct()
199         {
200                 global $gInstanceManager;
201                 global $gEnvManager;
202                 global $gSystemManager;
203                 global $gRequestManager;
204                                 
205                 // 親クラスを呼び出す
206                 parent::__construct();
207                 
208                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
209                 $widgetId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
210                 
211                 // システムDBオブジェクト取得
212                 $this->db = $gInstanceManager->getSytemDbObject();
213                 
214                 // 運用方法
215                 $value = $gSystemManager->getSystemConfig(self::CF_ACCESS_IN_INTRANET);         // イントラネット運用かどうか
216                 if (empty($value)){             // インターネット運用
217                         $this->useGooglemaps = true;                            // Googleマップを使用するかどうか
218                 }
219                         
220                 // 共通スクリプトファイル
221                 // 「ルート/scripts」ディレクトリからの相対パスで指定する
222                 $this->defaultScriptFiles = array(self::M3_STD_SCRIPT_FILENAME);
223                 $this->defaultCssFiles = array(self::M3_DEFAULT_CSS_FILE);                      // 一般画面共通のデフォルトCSS
224                 
225                 $this->wysiwygEditor = $gSystemManager->getSystemConfig(self::CF_WYSIWYG_EDITOR);                               // 管理画面用WYSIWYGエディター
226                 
227                 // アクセスする画面に応じてjQueryのバージョンを設定
228                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
229                         $value = $gSystemManager->getSystemConfig(self::CF_ADMIN_JQUERY_VERSION);// 管理画面用jQueryバージョン
230                         
231                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET && strStartsWith($widgetId, 'm/')){// 携帯用アクセスポイント用の管理画面の場合はWYSIWYGエディターはFCKEditorに固定
232                                 $this->wysiwygEditor = ScriptLibInfo::LIB_FCKEDITOR;                            // FCKEditorに固定
233                         }
234                         
235                         // 管理画面にBOOTSTRAPを使用するかどうか(初期値)
236                         $this->useBootstrap = self::USE_BOOTSTRAP_ADMIN;
237                 } else {
238                         $value = $gSystemManager->getSystemConfig(self::CF_JQUERY_VERSION);// jQueryバージョン
239                 }
240                 ScriptLibInfo::setJQueryVer($value);
241                 
242                 // WYSISIGエディターのタイプを設定。ScriptLibInfo::getLib()を実行する前に設定。
243                 ScriptLibInfo::setWysiwygEditorType($this->wysiwygEditor);
244                 
245                 // Javascriptライブラリ
246                 $this->libFiles = ScriptLibInfo::getLib();                      // ライブラリ取得
247                 
248                 // jQueryファイル名取得
249                 $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(0);                    // 使用対象のjQueryファイル
250                 $this->selectedJQueryUiFilename = ScriptLibInfo::getJQueryFilename(1);          // 使用対象のjQuery UIファイル
251
252                 // 管理機能用Javascript取得
253                 if (defined('M3_STATE_IN_INSTALL')){            // インストーラの場合のスクリプト
254                         $this->defaultAdminScriptFiles = array($this->selectedJQueryFilename);                  // jQuery
255                                                                                         //      self::M3_STD_SCRIPT_FILENAME,
256                                                                                         //      self::M3_ADMIN_SCRIPT_FILENAME,
257                                                                                         //      self::M3_OPTION_SCRIPT_FILENAME);
258                         
259                         $this->defaultAdminCssFiles = array();  // 管理機能用のCSS
260                 } else {
261                         $this->defaultAdminScriptFiles = array($this->selectedJQueryFilename,                   // jQuery
262                                                                                                 $this->selectedJQueryUiFilename,                                // jQuery UI Core
263                                                                                                 ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME,             // jQuery Contextmenu Lib
264                                                                                                 self::M3_STD_SCRIPT_FILENAME,
265                                                                                                 self::M3_ADMIN_SCRIPT_FILENAME,
266                                                                                                 self::M3_OPTION_SCRIPT_FILENAME);
267                                                                 
268                         $this->defaultAdminCssFiles = array(self::M3_ADMIN_CSS_FILE);// 管理機能用のCSS   
269 //                      if (!$this->useBootstrap) $this->defaultAdminCssFiles[] = self::M3_NO_BOOTSTRAP_CSS_FILE;       // Bootstrapを読み込まない場合は代替CSSを読み込む
270                         
271                         // Javascriptライブラリ
272                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);     // 管理パネル用スクリプト追加
273                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_EASING);            // 管理パネル用スクリプト追加
274                 }
275                 
276                 // 管理権限なしで管理ディレクトリアクセスで読み込むスクリプトファイル
277                 $this->defaultAdminDirScriptFiles = array($this->selectedJQueryFilename);                       // jQuery
278                 
279                 // 遅延ウィジェットリスト                                                                    
280                 $this->lateLaunchWidgetList = array();
281                 $this->latelaunchWidgetParam = array();
282                 
283                 // DB接続可能なときは設定値を取得
284                 if ($gEnvManager->canUseDb()){
285                         $value = $this->gSystem->getSystemConfig('script_cache_in_browser');    // ブラウザにJavaScriptファイルのキャッシュを保持するかどうか
286                         if ($value != '') $this->hasScriptCache = $value;
287                 }
288                 
289                 $this->rssVersion = self::DEFAULT_RSS_VERSION;                                  // RSSバージョン
290                 
291                 // 一般画面で使用する主要コンテンツタイプ
292                 $this->mainContentType   = array(       array(  'name' => '汎用コンテンツ',                              'value' => M3_VIEW_TYPE_CONTENT),
293                                                                                         array(  'name' => '製品',                                             'value' => M3_VIEW_TYPE_PRODUCT),
294                                                                                         array(  'name' => 'BBS',                                                'value' => M3_VIEW_TYPE_BBS),
295                                                                                         array(  'name' => 'ブログ',                                          'value' => M3_VIEW_TYPE_BLOG),
296                                                                                         array(  'name' => 'Wiki',                                               'value' => M3_VIEW_TYPE_WIKI),
297                                                                                         array(  'name' => 'ユーザ作成コンテンツ',             'value' => M3_VIEW_TYPE_USER),
298                                                                                         array(  'name' => 'イベント',                                       'value' => M3_VIEW_TYPE_EVENT),
299                                                                                         array(  'name' => 'フォトギャラリー',                   'value' => M3_VIEW_TYPE_PHOTO));
300                 // 一般画面で使用する主要機能タイプ
301                 $this->mainFeatureType   = array(       array(  'name' => '検索',                                             'value' => M3_VIEW_TYPE_SEARCH),
302                                                                                         array(  'name' => 'Eコマース',                                      'value' => M3_VIEW_TYPE_COMMERCE));
303                                                                                         
304                 // URLパラメータ並び順
305                 $this->urlParamOrder = array(
306                         // コンテンツID
307                         M3_REQUEST_PARAM_CONTENT_ID                             => -20,         // 汎用コンテンツID
308                         M3_REQUEST_PARAM_CONTENT_ID_SHORT               => -19,         // 汎用コンテンツID(略式)
309                         M3_REQUEST_PARAM_PRODUCT_ID                             => -18,         // 製品ID
310                         M3_REQUEST_PARAM_PRODUCT_ID_SHORT               => -17,         // 製品ID(略式)
311                         M3_REQUEST_PARAM_BLOG_ID                                => -16,         // ブログID
312                         M3_REQUEST_PARAM_BLOG_ID_SHORT                  => -15,         // ブログID(略式)
313                         M3_REQUEST_PARAM_BLOG_ENTRY_ID                  => -14,         // ブログ記事ID
314                         M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT    => -13,         // ブログ記事ID(略式)
315                         M3_REQUEST_PARAM_BBS_ID                                 => -12,         // 掲示板投稿記事ID
316                         M3_REQUEST_PARAM_BBS_ID_SHORT                   => -11,         // 掲示板投稿記事ID(略式)
317                         M3_REQUEST_PARAM_BBS_THREAD_ID                  => -10,         // 掲示板投稿スレッドID
318                         M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT    => -9,          // 掲示板投稿スレッドID(略式)
319                         M3_REQUEST_PARAM_USER_ID                                => -8,          // ユーザ作成コンテンツID
320                         M3_REQUEST_PARAM_USER_ID_SHORT                  => -7,          // ユーザ作成コンテンツID(略式)
321                         M3_REQUEST_PARAM_ROOM_ID                                => -6,          // ユーザ作成コンテンツ区画ID
322                         M3_REQUEST_PARAM_ROOM_ID_SHORT                  => -5,          // ユーザ作成コンテンツ区画ID(略式)
323                         M3_REQUEST_PARAM_EVENT_ID                               => -4,          // イベントID
324                         M3_REQUEST_PARAM_EVENT_ID_SHORT                 => -3,          // イベントID(略式)
325                         M3_REQUEST_PARAM_PHOTO_ID                               => -2,          // 画像ID
326                         M3_REQUEST_PARAM_PHOTO_ID_SHORT                 => -1,          // 画像ID(略式)
327                         // URLパラメータ
328                         M3_REQUEST_PARAM_PAGE_SUB_ID                    => 1,           // ページサブID
329                         M3_REQUEST_PARAM_PAGE_CONTENT_ID                => 2,           // ページコンテンツID
330                         M3_REQUEST_PARAM_WIDGET_ID                              => 3,           // ウィジェットID
331                         M3_REQUEST_PARAM_TEMPLATE_ID                    => 4,           // テンプレートID
332                         M3_REQUEST_PARAM_URL                                    => 5,           // リンク先等のURL
333                         M3_REQUEST_PARAM_STAMP                                  => 6,           // 公開発行ID
334                         M3_REQUEST_PARAM_OPTION                                 => 7,           // 通信オプション
335                         M3_REQUEST_PARAM_OPERATION_COMMAND              => 8,           // 実行処理
336                         M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND => 9,           // Wikiコマンド実行
337                         M3_REQUEST_PARAM_OPERATION_TASK                 => 10,          // ウィジェット間共通処理
338                         M3_REQUEST_PARAM_OPERATION_ACT                  => 11,          // クライアントからの実行処理
339                         M3_REQUEST_PARAM_OPERATION_LANG                 => 12,          // 言語指定表示
340                         M3_REQUEST_PARAM_SERIAL_NO                              => 13,          // シリアル番号
341                         M3_REQUEST_PARAM_PAGE_NO                        => 14,          // ページ番号
342                         M3_REQUEST_PARAM_LIST_NO                                => 15,          // 一覧番号
343                         M3_REQUEST_PARAM_ITEM_NO                        => 16,          // 項目番号
344                         M3_REQUEST_PARAM_OPERATION_TODO                 => 17,          // 指定ウィジェットに実行させる処理
345                         M3_REQUEST_PARAM_FROM                                   => 18,          // メッセージの送信元ウィジェットID
346                         M3_REQUEST_PARAM_VIEW_STYLE                             => 19,          // 表示スタイル
347                         M3_REQUEST_PARAM_FORWARD                                => 20,          // 画面遷移用パラメータ
348                         M3_REQUEST_PARAM_ADMIN_KEY                              => 21,          // 管理者一時キー
349                         M3_REQUEST_PARAM_OPEN_BY                                => 22,          // ウィンドウの開き方
350                         M3_REQUEST_PARAM_SHOW_HEADER                    => 23,          // ヘッダ部表示制御
351                         M3_REQUEST_PARAM_SHOW_FOOTER                    => 24,          // フッタ部表示制御
352                         M3_REQUEST_PARAM_SHOW_MENU                              => 25,          // メニュー部表示制御
353                         M3_REQUEST_PARAM_KEYWORD                                => 26,          // 検索キーワード
354                         M3_REQUEST_PARAM_HISTORY                                => 27,          // 履歴インデックスNo
355                         M3_REQUEST_PARAM_DEF_PAGE_ID                    => 28,          // ページID(画面編集用)
356                         M3_REQUEST_PARAM_DEF_PAGE_SUB_ID                => 29,          // ページサブID(画面編集用)
357                         M3_REQUEST_PARAM_PAGE_DEF_SERIAL                => 30,          // ページ定義のレコードシリアル番号(設定画面起動時)
358                         M3_REQUEST_PARAM_PAGE_DEF_CONFIG_ID             => 31,          // ページ定義のウィジェット定義ID(設定画面起動時)
359                         M3_REQUEST_PARAM_BACK_URL                               => 32,          // 戻り先URL
360                         M3_REQUEST_PARAM_BACKUP_URL                             => 33,          // URL退避用(画面編集時)
361                         M3_REQUEST_PARAM_SERVER                                 => 34,          // サーバ指定
362                         M3_REQUEST_PARAM_CATEGORY_ID                    => 35);         // カテゴリID(共通)
363         }
364         /**
365          * メインコンテンツタイプを取得
366          *
367          * @return array        コンテンツタイプ
368          */
369         public function _getAllContentType()
370         {
371                 $contentType = array(   M3_VIEW_TYPE_CONTENT,                           // 汎用コンテンツ
372                                                                 M3_VIEW_TYPE_PRODUCT,                           // 製品
373                                                                 M3_VIEW_TYPE_BBS,                                       // BBS
374                                                                 M3_VIEW_TYPE_BLOG,                              // ブログ
375                                                                 M3_VIEW_TYPE_WIKI,                              // wiki
376                                                                 M3_VIEW_TYPE_USER,                              // ユーザ作成コンテンツ
377                                                                 M3_VIEW_TYPE_EVENT,                             // イベント
378                                                                 M3_VIEW_TYPE_PHOTO);                            // フォトギャラリー
379                 return $contentType;
380         }
381         /**
382          * 機能タイプを取得
383          *
384          * @return array        機能タイプ
385          */
386         public function _getAllFeatureType()
387         {
388                 $featureType = array(   M3_VIEW_TYPE_DASHBOARD,                 // ダッシュボード
389                                                                 M3_VIEW_TYPE_SEARCH,                    // 検索結果
390                                                                 M3_VIEW_TYPE_COMMERCE);                 // Eコマース
391                 return $featureType;
392         }
393         /**
394          * タイムアウトを停止
395          *
396          * @return なし
397          */
398         function setNoTimeout()
399         {
400                 if (ini_get('safe_mode') == '0') set_time_limit(0);
401         }
402         /**
403          * ポップアップメッセージを設定
404          *
405          * @param string $msg   メッセージ
406          */
407         function setPopupMsg($msg)
408         {
409                 $this->popupMsg = $msg;
410         }
411         /**
412          * HTMLヘッダ「description」に出力する文字列を設定
413          *
414          * @param string $str   出力文字列
415          */
416         function setHeadDescription($str)
417         {
418                 if (is_string($str) && !empty($str)){
419                         $this->headDescription = $str;
420                         $this->lastHeadDescription = $str;      // 最後に設定した値を退避
421                 }
422         }
423         /**
424          * HTMLヘッダ「description」に出力する文字列を取得
425          *
426          * @return string $str   出力文字列
427          */
428         function getHeadDescription()
429         {
430                 return $this->headDescription;
431         }
432         /**
433          * HTMLヘッダ「keywords」に出力する文字列を設定
434          *
435          * @param string $str   出力文字列
436          */
437         function setHeadKeywords($str)
438         {
439                 if (is_string($str) && !empty($str)){
440                         $this->headKeywords = $str;
441                         $this->lastHeadKeywords = $str;         // 最後に設定した値を退避
442                 }
443         }
444         /**
445          * HTMLヘッダ「keywords」に出力する文字列を取得
446          *
447          * @return string $str   出力文字列
448          */
449         function getHeadKeywords()
450         {
451                 return $this->headKeywords;
452         }
453         /**
454          * HTMLヘッダに出力するタグ文字列を設定
455          *
456          * @param string $str   出力文字列
457          * @return なし
458          */
459         function setHeadOthers($str)
460         {
461                 if (is_string($str) && !empty($str)){
462                         $this->headOthers = $str;
463                 }
464         }
465         /**
466          * HTMLヘッダに出力するタグ文字列を取得
467          *
468          * @return string $str   出力文字列
469          */
470 /*      function getHeadOthers()
471         {
472                 return $this->headOthers;
473         }*/
474         /**
475          * HTMLヘッダ「title」のサブタイトル出力する文字列を設定
476          *
477          * @param string $str   出力文字列
478          * @param string $url   リンク先
479          */
480         function setHeadSubTitle($str, $url='')
481         {
482                 if (is_string($str) && !empty($str)){
483                         $this->headSubTitle[] = $str;
484                         $this->headSubTitleUrl[] = $url;
485                         $this->lastHeadTitle = $str;    // 最後に設定した値を退避
486                 }
487         }
488         /**
489          * HTMLヘッダ「title」のサブタイトル出力する文字列を取得
490          *
491          * @return $array   サブタイトルに設定されている文字列を連想配列(title=タイトル、url=リンク先URL)の配列で返す
492          */
493         function getHeadSubTitle()
494         {
495                 $titleArray = array();
496                 $titleCount = count($this->headSubTitle);
497                 for ($i = 0; $i < $titleCount; $i++){
498                         $line = array('title' => $this->headSubTitle[$i], 'url' => $this->headSubTitleUrl[$i]);
499                         $titleArray[] = $line;
500                 }
501                 return $titleArray;
502         }
503         /**
504          * HTMLヘッダに出力するCSSの文字列を設定
505          *
506          * @param string $css   追加するCSS内容
507          * @return                              なし
508          */
509         function addHeadCss($css)
510         {
511                 $destCss = trim($css);
512                 if (!empty($destCss)){
513                         if (!in_array($css, $this->headCss)) $this->headCss[] = $css;
514                         
515                         $this->lastHeadCss = $css;                      // 最後に設定したHTMLヘッダにCSS出力する文字列
516                 }
517         }
518         /**
519          * HTMLヘッダに出力するJavascriptの文字列を設定
520          *
521          * @param string $script        追加するJavascript内容
522          * @return                                      なし
523          */
524         function addHeadScript($script)
525         {
526                 $destScript = trim($script);
527                 if (!empty($destScript)){
528                         if (!in_array($script, $this->headScript)) $this->headScript[] = $script;
529                         
530                         $this->lastHeadScript = $script;                        // 最後に設定したHTMLヘッダにJavascript出力する文字列
531                 }
532         }
533         /**
534          * HTMLヘッダに出力するJavascriptの文字列(jQueryMobile用挿入スクリプト)を設定
535          *
536          * @param string $script        追加するJavascript内容
537          * @return                                      なし
538          */
539         function addHeadPreMobileScript($script)
540         {
541                 $destScript = trim($script);
542                 if (!empty($destScript)){
543                         if (!in_array($script, $this->headPreMobileScript)) $this->headPreMobileScript[] = $script;
544                 }
545         }
546         /**
547          * HTMLヘッダに出力する任意文字列を設定
548          *
549          * @param string $str   追加する任意文字列
550          * @return                              なし
551          */
552         function addHeadString($str)
553         {
554                 $destScript = trim($str);
555                 if (!empty($destScript)){
556                         if (!in_array($str, $this->headString)) $this->headString[] = $str;
557                         
558                         $this->lastHeadString = $str;                   // 最後に設定したHTMLヘッダに出力する任意文字列
559                 }
560         }
561         /**
562          * HTMLヘッダに出力するCSSファイルを追加
563          *
564          * @param string,array $cssFile CSSファイルURLパス
565          * @return                              なし
566          */
567         function addHeadCssFile($cssFile)
568         {
569                 if (is_array($cssFile)){        // 配列の場合
570                         for ($i = 0; $i < count($cssFile); $i++){
571                                 $destCss = trim($cssFile[$i]);
572                                 if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
573                         }
574                 } else {                // 文字列の場合
575                         $destCss = trim($cssFile);
576                         if (!empty($destCss) && !in_array($destCss, $this->headCssFiles)) $this->headCssFiles[] = $destCss;
577                 }
578         }
579         /**
580          * HTMLヘッダに出力するJavascriptライブラリを追加
581          *
582          * @param string,array $scriptLib       JavascriptライブラリID
583          * @return                                      なし
584          */
585         function addHeadAdminScriptLib($scriptLib)
586         {
587                 if (is_array($scriptLib)){      // 配列の場合
588                         for ($i = 0; $i < count($scriptLib); $i++){
589                                 $destScript = trim($scriptLib[$i]);
590                                 if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
591                         }
592                 } else {                // 文字列の場合
593                         $destScript = trim($scriptLib);
594                         if (!empty($destScript)) $this->addAdminScript('', $destScript);// スクリプト追加
595                 }
596         }
597         /**
598          * HTMLヘッダに出力するJavascriptライブラリを追加
599          *
600          * @param string,array $scriptLib       JavascriptライブラリID
601          * @return                                      なし
602          */
603         function addHeadScriptLib($scriptLib)
604         {
605                 if (is_array($scriptLib)){      // 配列の場合
606                         for ($i = 0; $i < count($scriptLib); $i++){
607                                 $destScript = trim($scriptLib[$i]);
608                                 if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
609                         }
610                 } else {                // 文字列の場合
611                         $destScript = trim($scriptLib);
612                         if (!empty($destScript)) $this->addScript('', $destScript);// スクリプト追加
613                 }
614         }
615         /**
616          * HTMLヘッダに出力するJavascriptファイルを追加
617          *
618          * @param string,array $scriptFile      JavascriptファイルURLパス
619          * @return                                      なし
620          */
621         function addHeadScriptFile($scriptFile)
622         {
623                 if (is_array($scriptFile)){     // 配列の場合
624                         for ($i = 0; $i < count($scriptFile); $i++){
625                                 $destScript = trim($scriptFile[$i]);
626                                 if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
627                         }
628                 } else {                // 文字列の場合
629                         $destScript = trim($scriptFile);
630                         if (!empty($destScript) && !in_array($destScript, $this->headScriptFiles)) $this->headScriptFiles[] = $destScript;
631                 }
632         }
633         /**
634          * HTMLヘッダに出力するJavascriptファイル(jQueryMobile用挿入ファイル)を追加
635          *
636          * @param string,array $scriptFile      JavascriptファイルURLパス
637          * @return                                      なし
638          */
639         function addHeadPreMobileScriptFile($scriptFile)
640         {
641                 if (is_array($scriptFile)){     // 配列の場合
642                         for ($i = 0; $i < count($scriptFile); $i++){
643                                 $destScript = trim($scriptFile[$i]);
644                                 if (!empty($destScript) && !in_array($destScript, $this->headPreMobileScriptFiles)) $this->headPreMobileScriptFiles[] = $destScript;
645                         }
646                 } else {                // 文字列の場合
647                         $destScript = trim($scriptFile);
648                         if (!empty($destScript) && !in_array($destScript, $this->headPreMobileScriptFiles)) $this->headPreMobileScriptFiles[] = $destScript;
649                 }
650         }
651         /**
652          * HTMLヘッダに出力するRSSファイルを追加
653          *
654          * @param array $rssFile        タイトル(title)、配信用URL(href)の連想配列。複数の場合は連想配列の配列。
655          * @return                                      なし
656          */
657         function addHeadRssFile($rssFile)
658         {
659                 // パラメータエラーチェック
660                 if (!is_array($rssFile)) return;
661                 
662                 $line = $rssFile[0];
663                 if (is_array($line)){   // 複数追加の場合
664                         for ($i = 0; $i < count($line); $i++){
665                                 // すでに追加済みかどうかチェック
666                                 $url = trim($line[$i]['href']);
667                                 if (!empty($url)){
668                                         for ($j = 0; $j < count($this->headRssFiles); $j++){
669                                                 $storedUrl = $this->headRssFiles[$j]['href'];
670                                                 if ($url == $storedUrl) break;
671                                         }
672                                         if ($j == count($this->headRssFiles)){          // 見つからないときは追加
673                                                 $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
674                                                                                                                 'title' => $line[$i]['title']);         // タイトル
675                                         }
676                                 }
677                         }
678                 } else {                // 単数追加のとき
679                         // すでに追加済みかどうかチェック
680                         $url = trim($rssFile['href']);
681                         if (!empty($url)){
682                                 for ($i = 0; $i < count($this->headRssFiles); $i++){
683                                         $storedUrl = $this->headRssFiles[$i]['href'];
684                                         if ($url == $storedUrl) break;
685                                 }
686                                 if ($i == count($this->headRssFiles)){          // 見つからないときは追加
687                                         $this->headRssFiles[] = array(  'href' => $url,         // リンク先URL
688                                                                                                         'title' => $rssFile['title']);          // タイトル
689                                 }
690                         }
691                 }
692         }
693         /**
694          * RSSチャンネル部に出力するデータを設定
695          *
696          * @param array $rssData        RSSチャンネル部データ
697          * @return                                      なし
698          */
699         function setRssChannel($rssData)
700         {
701                 if (!empty($rssData)) $this->rssChannel = $rssData;                             // RSSチャンネルデータ
702         }
703         /**
704          * 表示ポジションを表示するかどうか
705          *
706          * @param int $mode   0=ポジション表示しない(通常画面)、1=ポジション表示、2=ウィジェット込みポジション表示
707          */
708         function showPosition($mode)
709         {
710                 $this->showPositionMode = $mode;
711         }
712         /**
713          * 画面レイアウト中かどうか
714          *
715          * @return bool         true=レイアウト中、false=レイアウト中でない
716          */
717         function isLayout()
718         {
719                 return $this->isLayout;                         // 画面レイアウト中かどうか
720         }
721         /**
722          * ウィジェットの単体表示を設定
723          */
724         function showWidget()
725         {
726                 $this->showWidget = true;
727         }
728         /**
729          * ウィジェットの単体表示を取得
730          *
731          * @param bool          true=単体表示、false=単体表示でない
732          */
733         function getShowWidget()
734         {
735                 return $this->showWidget;
736         }
737         /**
738          * システム制御遷移モードを設定
739          *
740          * @param int $mode   0=設定なし、1=ログイン画面、10=サイト非公開、11=アクセス不可、12=存在しないページ
741          */
742         function setSystemHandleMode($mode)
743         {
744                 $this->systemHandleMode = $mode;
745         }
746         /**
747          * システム制御遷移モード取得
748          */
749         function getSystemHandleMode()
750         {
751                 return $this->systemHandleMode;
752         }
753         /**
754          * 一般画面編集モードを設定
755          *
756          * @return                              なし
757          */
758         function setEditMode()
759         {
760                 $this->isEditMode = true;
761         }
762         /**
763          * 出力フォーマットがHTMLであるかを設定
764          *
765          * @param bool $isHtml  HTMLフォーマットかどうか
766          * @return                              なし
767          */
768         function setOutputByHtml($isHtml)
769         {
770                 $this->outputByHtml = $isHtml;
771         }
772         /**
773          * ヘルプ機能の使用可否を設定
774          *
775          * @param bool $status  ヘルプ機能を使用するかどうか
776          * @return                              なし
777          */
778         function setUseHelp($status)
779         {
780                 $this->useHelp = $status;
781         }
782         /**
783          * ヘルプ機能の使用可否を取得
784          *
785          * @return bool ヘルプ機能を使用するかどうか
786          */
787         function getUseHelp()
788         {
789                 return $this->useHelp;
790         }
791         /**
792          * 表示するコンテンツにGoogleマップが含まれているかを設定
793          *
794          * @param bool $status  Googleマップを含むかどうか
795          * @return                              なし
796          */
797         function setIsContentGooglemaps($status)
798         {
799                 $this->isContentGooglemaps = $status;           // コンテンツにGoogleマップが含むかどうか
800         }
801         /**
802          * 表示するコンテンツにGoogleマップが含まれているかを取得
803          *
804          * @return bool ヘルプ機能を使用するかどうか
805          */
806         function isContentGooglemaps()
807         {
808                 return $this->isContentGooglemaps;
809         }
810         /**
811          * JavaScriptのブラウザキャッシュの使用可否を設定
812          *
813          * @param bool $status  ブラウザキャッシュを使用するかどうか
814          * @return                              なし
815          */
816         function setHasScriptCache($status)
817         {
818                 $this->hasScriptCache = $status;
819         }
820         /**
821          * Bootstrapを使用に設定
822          *
823          * @return                              なし
824          */
825         function useBootstrap()
826         {
827                 $this->useBootstrap = true;                             // Bootstrapを使用するかどうか
828         }
829         /**
830          * Bootstrapを強制的に未使用に設定
831          *
832          * @return                              なし
833          */
834         function cancelBootstrap()
835         {
836                 $this->useBootstrap = false;                            // Bootstrapを使用するかどうか
837         }
838         /**
839          * Bootstrap使用状況を取得
840          *
841          * @return bool                 true=使用、false=使用しない
842          */
843         function getUseBootstrap()
844         {
845                 return $this->useBootstrap;                             // Bootstrapを使用するかどうか
846         }
847         /**
848          * HTML5を使用に設定
849          *
850          * @return                              なし
851          */
852         function setHtml5()
853         {
854                 $this->isHtml5 = true;                                  // HTML5で出力するかどうか
855         }
856         /**
857          * ページ作成処理を中断するかどうかを取得
858          *
859          * @return bool         true=中断、false=継続
860          */
861         function isPageAbort()
862         {
863                 return $this->isAbort;
864         }
865         /**
866          * 親ウィンドウを再描画
867          *
868          * @param int $defSerial        ページ定義シリアル番号
869          * @return                                      なし
870          */
871         function updateParentWindow($defSerial = 0)
872         {
873                 $this->updateParentWindow = true;
874                 $this->updateDefSerial = $defSerial;                    // 更新する項目のページ定義シリアル番号
875         }
876         /**
877          * CSSファイルの追加
878          *
879          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
880          * @return                              なし
881          */
882         function addCssFile($path)
883         {
884                 $destPath = trim($path, '/');
885                 if (!in_array($destPath, $this->defaultCssFiles)) $this->defaultCssFiles[] = $destPath;
886         }
887         /**
888          * CSSファイルの追加
889          *
890          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスまたは絶対パス(scriptディレクトリ以外の場合)で指定する)
891          * @return                              なし
892          */
893         function addAdminCssFile($path)
894         {
895                 $destPath = trim($path, '/');
896                 if (!in_array($destPath, $this->defaultAdminCssFiles)) $this->defaultAdminCssFiles[] = $destPath;
897         }
898         /**
899          * JavaScriptファイルの追加
900          *
901          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
902          * @return                              なし
903          */
904         function addScriptFile($path)
905         {
906                 $destPath = trim($path, '/');
907                 if (!empty($destPath) && !in_array($destPath, $this->defaultScriptFiles)) $this->defaultScriptFiles[] = $destPath;
908         }
909         /**
910          * JavaScriptファイルの追加
911          *
912          * @param string $path  追加するファイルのパス(「ルート/scripts」ディレクトリからの相対パスで指定する)
913          * @return                              なし
914          */
915         function addAdminScriptFile($path)
916         {
917                 $destPath = trim($path, '/');
918                 if (!in_array($destPath, $this->defaultAdminScriptFiles)) $this->defaultAdminScriptFiles[] = $destPath;
919         }
920         /**
921          * 追加設定するテンプレートIDを返す
922          *
923          * @return string                                               テンプレートID
924          */
925         function getOptionTemplateId()
926         {
927                 global $gEnvManager;
928                 
929                 // ページ情報取得
930                 $pageId = $gEnvManager->getCurrentPageId();
931
932                 switch ($this->contentType){
933                         case M3_VIEW_TYPE_CONTENT:              // ページのコンテンツタイプ                         
934                                 // コンテンツ単位のテンプレート設定
935                                 $contentLibObj = $this->gInstance->getObject(self::CONTENT_OBJ_ID);
936                                 if (isset($contentLibObj)) $this->optionTemplateId = $contentLibObj->getTemplate();
937                                 break;
938                         case M3_VIEW_TYPE_BLOG:         // ページがブログタイプのとき
939                                 if ($pageId == $this->gEnv->getDefaultPageId()){                // PCサイトのとき
940                                         // ブログライブラリオブジェクトからテンプレートを取得
941                                         $blogLibObj = $this->gInstance->getObject(self::BLOG_OBJ_ID);
942                                         if (isset($blogLibObj)) $this->optionTemplateId = $blogLibObj->getOptionTemplate();
943                                 }
944                                 break;
945                 }
946                 return $this->optionTemplateId;
947         }
948         /**
949          * 使用した非共通ウィジェットの数を取得
950          *
951          * @return int                          ウィジェット数
952          */
953         function getNonSharedWidgetCount()
954         {
955                 return $this->nonSharedWidgetCount;
956         }
957         /**
958          * ページのコンテンツタイプを取得
959          *
960          * @return string                       コンテンツタイプ
961          */
962         function getContentType()
963         {
964                 return $this->contentType;
965         }
966         /**
967          * 一般画面で使用する主要コンテンツタイプを取得
968          *
969          * @return array                        コンテンツタイプの配列
970          */
971         function getMainContentType()
972         {
973                 return $this->mainContentType;                          // 主要コンテンツタイプ
974         }
975         /**
976          * 一般画面で使用する主要機能タイプを取得
977          *
978          * @return array                        機能タイプの配列
979          */
980         function getMainFeatureType()
981         {
982                 return $this->mainFeatureType;                          // 主要機能タイプ
983         }
984         /**
985          * ページ作成開始
986          *
987          * HTTPヘッダを設定する。セッションを取得する。サブページIDを設定する。
988          *
989          * @param RequestManager $request               HTTPリクエスト処理クラス
990          * @return                                                              なし
991          */
992         function startPage($request)
993         {
994                 global $gEnvManager;
995                 global $gRequestManager;
996                 global $gInstanceManager;
997                 global $gAccessManager;
998                 global $gSystemManager;
999                 global $gDispManager;
1000                 
1001                 // 実行コマンドを取得
1002                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
1003                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
1004                 $pageId = $gEnvManager->getCurrentPageId();
1005                 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
1006
1007                 // クライアントIDの読み込み、再設定
1008                 $clientId = $request->getCookieValue(M3_COOKIE_CLIENT_ID);
1009                 if (empty($clientId)){  // クライアントIDが設定されていないとき
1010                         // クライアントIDを生成
1011                         $clientId = $this->gAccess->createClientId();
1012                 } else {
1013                         $this->gAccess->setClientId($clientId); // クライアントIDを設定
1014                         
1015                         // クッキーの使用可否を設定
1016                         $this->gEnv->setCanUseCookie(true);
1017                 }
1018                 $request->setCookieValue(M3_COOKIE_CLIENT_ID, $clientId, M3_COOKIE_EXPIRE_CLIENT_ID);
1019                         
1020                 // 管理者キーがあればGETまたはPOST値のセッションIDを使用する
1021                 if ($gEnvManager->isAdminDirAccess()){
1022                         if ($gAccessManager->isValidAdminKey()) session_id($gRequestManager->trimValueOf(session_name()));
1023                 }
1024
1025                 // インストール時の管理画面用ライブラリを追加(フレームコンテナでの設定を反映)
1026                 if (defined('M3_STATE_IN_INSTALL')){
1027                         // Bootstrapライブラリ追加
1028                         if ($this->useBootstrap){
1029                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
1030                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
1031                         }
1032                 }
1033
1034                 // セッション変数を取得可能にする
1035                 session_start();
1036
1037                 // ##### インストール時はここで終了 #####
1038                 if (defined('M3_STATE_IN_INSTALL')) return;             // インストール時は実行しない
1039                 
1040                 // セッションを再生成する(セキュリティ対策)
1041                 if ($gSystemManager->regenerateSessionId()){
1042                         $gAccessManager->setOldSessionId(session_id());         // 古いセッションIDを保存
1043                         session_regenerate_id(true);
1044                 }
1045
1046                 // セッションからユーザ情報を取得
1047                 $userInfo = $gRequestManager->getSessionValueWithSerialize(M3_SESSION_USER_INFO);
1048                 $gInstanceManager->setUserInfo($userInfo);
1049
1050                 // ##### 自動ログイン #####
1051                 // ログイン中でない場合は自動ログインでユーザ情報を取得
1052                 $gAccessManager->startAutoLogin();
1053                 
1054                 // デバッグモードの表示
1055                 if (M3_SYSTEM_DEBUG) echo 'Debug mode<br />';
1056                 
1057                 // ##### サブページIDの設定 #####
1058                 if ($gEnvManager->isAdminDirAccess() &&         // 管理画面へのアクセスのとき
1059                         ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT)){                               // ログイン、ログアウト場合は管理画面のページサブIDを指定
1060                         $subId = $gEnvManager->getAdminDefaultPageSubId();              // 管理画面用のデフォルトページサブID
1061                 } else {                                
1062                         $subId = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_SUB_ID);// ページサブIDを取得
1063                         if (empty($subId)){                     // サブページIDが設定されていないとき
1064                                 // URLパラメータからコンテンツ形式を取得し、ページを選択
1065                                 $params = $gRequestManager->getQueryArray();
1066                                 $paramCount = count($params);
1067
1068                                 // コマンド以外のパラメータ数が1つだけのときはパラメータからページ属性を判断する
1069                                 // 値が空でもキーがあれば属性を持つとする
1070                                 if ($paramCount == 0 && $gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemAdmin() && empty($task)){
1071                                         // ダッシュボード機能は、パラメータなし、管理者ディレクトリ、システム管理者の条件で使用可能
1072                                         // POST値にタスクがある場合はダッシュボードとしない
1073                                         $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_DASHBOARD, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1074                                         
1075                                         // ##### ダッシュボードはページの位置を示すので、ページのコンテンツ属性としない #####
1076                                         //$this->contentType = M3_VIEW_TYPE_DASHBOARD;          // ページのコンテンツタイプ
1077                                 //if ($paramCount == 1 || !empty($params[M3_REQUEST_PARAM_OPERATION_COMMAND])){
1078                                 //} else if ($paramCount > 0 || !empty($params[M3_REQUEST_PARAM_OPERATION_COMMAND])){           // コマンド(プレビュー等)のとき、または複数パラメータでも可(2011/9/20)
1079                                 } else if ($paramCount > 0 && !$gEnvManager->isAdminDirAccess()){               // パラメータ付きの場合(2013/3/23)
1080                                         // ##### ページ属性から画面を選択(管理画面は対応しない) ###
1081                                         // 最初のURLパラメータでコンテンツを判断
1082                                         // プレビュー(cmd=preview)等のパターンで複数パラメータがある
1083                                         reset($params);
1084                                         $firstKey = key($params);
1085                                         $firstValue = $params[$firstKey];
1086
1087                                         if (!empty($firstValue)){               // 「key=value」の形式であること
1088                                                 switch ($firstKey){
1089                                                         case M3_REQUEST_PARAM_CONTENT_ID:               // コンテンツIDのとき
1090                                                         case M3_REQUEST_PARAM_CONTENT_ID_SHORT:
1091                                                                 // ローカルメニューのURLからページを特定。ページが特定できないときはページ属性で取得。
1092                                                                 $url = $gEnvManager->getMacroPath($gEnvManager->getCurrentRequestUri());
1093                                                                 $ret = $this->db->getSubPageIdByMenuItemUrl($url, $gEnvManager->getCurrentPageId(), M3_VIEW_TYPE_CONTENT, $rows);
1094                                                                 if ($ret){
1095                                                                         $rowCount = count($rows);
1096                                                                         for ($i = 0; $i < $rowCount; $i++){
1097                                                                                 // コンテンツを表示するウィジェットがあるときはページサブIDを確定
1098                                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);
1099                                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);// コンテンツタイプでの取得に変更(2012/6/20)
1100                                                                                 if (!empty($widgetId)){
1101                                                                                         $subId = $rows[$i]['pd_sub_id'];
1102                                                                                         break;
1103                                                                                 }
1104                                                                         }
1105                                                                 }
1106                                                                 if (empty($subId)) $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_CONTENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1107                                                                 $this->contentType = M3_VIEW_TYPE_CONTENT;              // ページのコンテンツタイプ
1108                                                                 break;
1109                                                         case M3_REQUEST_PARAM_PRODUCT_ID:       // 製品IDのとき
1110                                                         case M3_REQUEST_PARAM_PRODUCT_ID_SHORT:
1111                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PRODUCT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1112                                                                 $this->contentType = M3_VIEW_TYPE_PRODUCT;              // ページのコンテンツタイプ
1113                                                                 break;
1114                                                         case M3_REQUEST_PARAM_BBS_ID:           // 掲示板投稿記事のとき
1115                                                         case M3_REQUEST_PARAM_BBS_ID_SHORT:
1116                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID:
1117                                                         case M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT:
1118                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BBS, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1119                                                                 $this->contentType = M3_VIEW_TYPE_BBS;          // ページのコンテンツタイプ
1120                                                                 break;
1121                                                         case M3_REQUEST_PARAM_EVENT_ID:         // イベント記事のとき
1122                                                         case M3_REQUEST_PARAM_EVENT_ID_SHORT:
1123                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_EVENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1124                                                                 $this->contentType = M3_VIEW_TYPE_EVENT;                // ページのコンテンツタイプ
1125                                                                 break;
1126                                                         case M3_REQUEST_PARAM_PHOTO_ID:         // フォトギャラリー写真のとき
1127                                                         case M3_REQUEST_PARAM_PHOTO_ID_SHORT:
1128                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PHOTO, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1129                                                                 $this->contentType = M3_VIEW_TYPE_PHOTO;                // ページのコンテンツタイプ
1130                                                                 break;
1131                                                         case M3_REQUEST_PARAM_BLOG_ID:          // ブログIDのとき
1132                                                         case M3_REQUEST_PARAM_BLOG_ID_SHORT:
1133                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID:
1134                                                         case M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT:
1135                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BLOG, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1136                                                                 $this->contentType = M3_VIEW_TYPE_BLOG;         // ページのコンテンツタイプ
1137                                                                 break;
1138                                                         case M3_REQUEST_PARAM_ROOM_ID:          // ユーザ作成コンテンツのとき
1139                                                         case M3_REQUEST_PARAM_ROOM_ID_SHORT:
1140                                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_USER, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1141                                                                 $this->contentType = M3_VIEW_TYPE_USER;         // ページのコンテンツタイプ
1142                                                 
1143                                                                 // コンテンツを表示するウィジェットを取得
1144                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);
1145                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);// コンテンツタイプでの取得に変更(2012/6/20)
1146                                                                 if (!empty($widgetId)){
1147                                                                         // ルーム用の定義ID(所属グループID)を取得
1148                                                                         $roomId = isset($params[M3_REQUEST_PARAM_ROOM_ID]) ? $params[M3_REQUEST_PARAM_ROOM_ID] : $params[M3_REQUEST_PARAM_ROOM_ID_SHORT];
1149                                                                         $configId = $this->db->getWidgetConfigIdForRoom($roomId);
1150
1151                                                                         // グループIDを定義IDとするページのページサブIDを取得
1152                                                                         $subPageId = $this->getPageSubIdByWidget($gEnvManager->getCurrentPageId(), $widgetId, $configId);
1153                                                                         if (!empty($subPageId)) $subId = $subPageId;
1154                                                                 }
1155                                                                 break;
1156                                                         default:                // オプションのURLコンテンツパラメータからサブページIDを取得
1157                                                                 $ret = $this->db->getSubPageIdByUrlContentParam($gEnvManager->getCurrentPageId(), $firstKey, $row);
1158                                                                 if ($ret) $subId = $row['pd_sub_id'];
1159                                                                 break;
1160                                                 }
1161                                         }
1162                                         /*
1163                                         if (isset($params[M3_REQUEST_PARAM_CONTENT_ID]) || isset($params[M3_REQUEST_PARAM_CONTENT_ID_SHORT])){          // コンテンツIDのとき
1164                                                 // ローカルメニューのURLからページを特定。ページが特定できないときはページ属性で取得。
1165                                                 $url = $gEnvManager->getMacroPath($gEnvManager->getCurrentRequestUri());
1166                                                 $ret = $this->db->getSubPageIdByMenuItemUrl($url, $gEnvManager->getCurrentPageId(), $rows);
1167                                                 if ($ret){
1168                                                         $rowCount = count($rows);
1169                                                         for ($i = 0; $i < $rowCount; $i++){
1170                                                                 // コンテンツを表示するウィジェットがあるときはページサブIDを確定
1171                                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);
1172                                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $rows[$i]['pd_sub_id'], M3_VIEW_TYPE_CONTENT);// コンテンツタイプでの取得に変更(2012/6/20)
1173                                                                 if (!empty($widgetId)){
1174                                                                         $subId = $rows[$i]['pd_sub_id'];
1175                                                                         break;
1176                                                                 }
1177                                                         }
1178                                                 }
1179                                                 if (empty($subId)) $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_CONTENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1180                                                 $this->contentType = M3_VIEW_TYPE_CONTENT;              // ページのコンテンツタイプ
1181                                         } else if (isset($params[M3_REQUEST_PARAM_PRODUCT_ID]) || isset($params[M3_REQUEST_PARAM_PRODUCT_ID_SHORT])){   // 製品IDのとき
1182                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PRODUCT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1183                                                 $this->contentType = M3_VIEW_TYPE_PRODUCT;              // ページのコンテンツタイプ
1184                                         } else if ((isset($params[M3_REQUEST_PARAM_BBS_ID]) || isset($params[M3_REQUEST_PARAM_BBS_ID_SHORT])) ||
1185                                                                 (isset($params[M3_REQUEST_PARAM_BBS_THREAD_ID]) || isset($params[M3_REQUEST_PARAM_BBS_THREAD_ID_SHORT]))){      // 掲示板投稿記事のとき
1186                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BBS, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1187                                                 $this->contentType = M3_VIEW_TYPE_BBS;          // ページのコンテンツタイプ
1188                                         } else if (isset($params[M3_REQUEST_PARAM_EVENT_ID]) || isset($params[M3_REQUEST_PARAM_EVENT_ID_SHORT])){       // イベント記事のとき
1189                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_EVENT, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1190                                                 $this->contentType = M3_VIEW_TYPE_EVENT;                // ページのコンテンツタイプ
1191                                         } else if (isset($params[M3_REQUEST_PARAM_PHOTO_ID]) || isset($params[M3_REQUEST_PARAM_PHOTO_ID_SHORT])){       // フォトギャラリー写真のとき
1192                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_PHOTO, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1193                                                 $this->contentType = M3_VIEW_TYPE_PHOTO;                // ページのコンテンツタイプ
1194                                         } else if ((isset($params[M3_REQUEST_PARAM_BLOG_ID]) || isset($params[M3_REQUEST_PARAM_BLOG_ID_SHORT])) ||                              // ブログIDのとき
1195                                                                 (isset($params[M3_REQUEST_PARAM_BLOG_ENTRY_ID]) || isset($params[M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT]))){      // ブログ記事のとき
1196                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_BLOG, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1197                                                 $this->contentType = M3_VIEW_TYPE_BLOG;         // ページのコンテンツタイプ
1198                                         } else if (isset($params[M3_REQUEST_PARAM_ROOM_ID]) || isset($params[M3_REQUEST_PARAM_ROOM_ID_SHORT])){ // ユーザ作成コンテンツのとき
1199                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_USER, $gEnvManager->getCurrentPageId());// ページサブIDを取得
1200                                                 $this->contentType = M3_VIEW_TYPE_USER;         // ページのコンテンツタイプ
1201                                                 
1202                                                 // コンテンツを表示するウィジェットを取得
1203                                                 //$widgetId = $this->db->getWidgetIdByType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);
1204                                                 $widgetId = $this->db->getWidgetIdByContentType($gEnvManager->getCurrentPageId(), $subId, M3_VIEW_TYPE_USER);// コンテンツタイプでの取得に変更(2012/6/20)
1205                                                 if (!empty($widgetId)){
1206                                                         // ルーム用の定義ID(所属グループID)を取得
1207                                                         $roomId = isset($params[M3_REQUEST_PARAM_ROOM_ID]) ? $params[M3_REQUEST_PARAM_ROOM_ID] : $params[M3_REQUEST_PARAM_ROOM_ID_SHORT];
1208                                                         $configId = $this->db->getWidgetConfigIdForRoom($roomId);
1209
1210                                                         // グループIDを定義IDとするページのページサブIDを取得
1211                                                         $subPageId = $this->getPageSubIdByWidget($gEnvManager->getCurrentPageId(), $widgetId, $configId);
1212                                                         if (!empty($subPageId)) $subId = $subPageId;
1213                                                 }
1214                                         }*/
1215                                 }
1216
1217                                 // wiki用パラメータの取得
1218                                 if (empty($subId)){
1219                                         // 「http://www.example.com?ページ名」「wcmd」の場合はwikiコンテンツページを選択
1220                                         $wikiCmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_WIKI_COMMAND);
1221                                         $pageName = $gRequestManager->getWikiPageFromQuery();           // 「=」なしのパラメータはwikiパラメータとする
1222                         
1223                                         if (!empty($wikiCmd) || !empty($pageName)){                     // Wikiコンテンツページを指定のとき
1224                                                 // ページサブIDを取得
1225                                                 $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_WIKI, $gEnvManager->getCurrentPageId());
1226                                                 $this->contentType = M3_VIEW_TYPE_WIKI;         // ページのコンテンツタイプ
1227                                         }
1228                                 }
1229                                 // その他のGET,POSTパラメータからページサブID取得
1230                                 if (empty($subId)) $subId = $this->getPageSubIdByParam($request, $gEnvManager->getCurrentPageId());
1231                                 
1232                                 // ページサブIDが取得できない場合はデフォルトを使用
1233                                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
1234                         }
1235                 }
1236                 $gEnvManager->setCurrentPageSubId($subId);// サブページIDを設定
1237
1238                 // SSL通信機能がオンの場合は、アクセスされたURLのSSLをチェックし不正の場合は正しいURLにリダイレクト
1239                 // 設定に間違いがある場合、管理画面にアクセスできなくなるので、一般画面のみ制御
1240                 if ($gEnvManager->getUseSsl() || $gEnvManager->getUseSslAdmin()){
1241                         if (!$gEnvManager->isAdminDirAccess()){         // 管理画面以外へのアクセスのとき
1242                                 $isSsl = $gEnvManager->isSslByCurrentPage();
1243                                 $currentUrl = $gEnvManager->getCurrentRequestUri();
1244                                 if ($isSsl){
1245                                         $correctUrl = str_replace('http://', 'https://', $currentUrl);
1246                                 } else {
1247                                         $correctUrl = str_replace('https://', 'http://', $currentUrl);
1248                                 }
1249                                 if ($currentUrl != $correctUrl) $this->redirect($correctUrl);
1250                         }
1251                 }
1252                 // マルチドメイン用設定初期化
1253                 $gEnvManager->initMultiDomain();
1254                 
1255                 // 画面設定取得
1256                 $gDispManager->load();
1257                         
1258                 // ##### 画面に必要なスクリプトを追加 #####
1259                 // スマートフォン用URLのときはスマートフォン用のjQueryを使用
1260                 if ($gEnvManager->getIsSmartphoneSite()){
1261                         $this->selectedJQueryFilename = ScriptLibInfo::getJQueryFilename(10);                   // スマートフォン用jQueryファイル
1262                         
1263                         if (isset($this->libFiles[ScriptLibInfo::LIB_JQUERYS_MOBILE]['script'])){
1264                                 $scriptFiles = $this->libFiles[ScriptLibInfo::LIB_JQUERYS_MOBILE]['script'];
1265                                 if (count($scriptFiles) > 0) $this->selectedJQueryMobileFilename = $scriptFiles[0];             // 使用対象のjQueryMobileファイル
1266                         }
1267                 }
1268                 
1269                 // Magic3管理用のスクリプトを追加
1270                 if (!$gEnvManager->getIsMobileSite()){          // 携帯用URL以外のとき
1271                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
1272                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
1273                                         $this->isEditMode = true;                       // 一般画面編集モード
1274                                         $this->isPageEditable = true;           // 一般画面ページ編集可能モードに設定(コンテキストメニュー表示)
1275                                                 
1276                                         // 管理画面用ライブラリを追加
1277                                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1278                                                 $this->addAdminScript('', ScriptLibInfo::getWysiwygEditorLibId());      // WYSIWYGエディターを追加
1279                                                 
1280                                                 // Googleマップライブラリの読み込み
1281                                                 if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1282                                                         $this->defaultAdminScriptFiles[] = ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS);
1283                                                 }
1284                                         } else if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){           // 管理画面(ウィジェット付きポジション表示)のとき
1285                                                 $this->isLayout = true;         // 画面レイアウト中かどうか
1286                                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_IDTABS);                    // 管理パネル用スクリプト追加(ポジション表示追加分)
1287                                                 $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_M3_DROPDOWN);               // 管理パネル用スクリプト追加(ドロップダウンメニュー)
1288                                                 //$this->useBootstrap = true;           // Bootstrapを使用
1289                                                 //$this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);             // パネルメニュー(一般画面と管理画面の切り替え等)用
1290                                         }
1291                                         $this->addAdminScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1292                                 
1293                                         // スクリプトが必要なウィジェットをすべて取得
1294                                         $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
1295                                         for ($i = 0; $i < count($rows); $i++){
1296                                                 $this->addAdminScript($task, trim($rows[$i]['wd_add_script_lib']));
1297                                         }
1298                                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){      // ウィジェット詳細設定画面のとき
1299                                                 // ウィジェット情報取得
1300                                                 $widgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
1301                                                 $ret = $this->db->getWidgetInfo($widgetId, $this->configWidgetInfo);
1302                                                 if ($ret) $this->addAdminScript($task, trim($this->configWidgetInfo['wd_add_script_lib_a']));           // 管理機能用スクリプト
1303                                         }
1304                                 }
1305                         } else {                // 一般画面へのアクセスのとき
1306                                 // 一般画面用スクリプトファイル追加
1307                                 $value = $gSystemManager->getSystemConfig(self::CF_USE_JQUERY);// 常にjQueryを使用するかどうか
1308                                 if ($value) $this->addScriptFile($this->selectedJQueryFilename);
1309                 
1310                                 if ($cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                 // ウィジェット単体実行でない
1311                                         $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
1312                                         if ($gEnvManager->isSystemManageUser()){
1313                                                 $this->isEditMode = true;                       // 一般画面編集モード
1314                                                 $this->isPageEditable = true;           // 一般画面ページ編集可能モードに設定
1315                                         
1316                                                 // システム運用権限がある場合は管理用スクリプトを追加
1317                                                 // 一般画面と管理画面の切り替え用のスライドメニューバーには管理用スクリプト,CSSが必要
1318                                                 $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1319                                                 $this->addScriptFile(ScriptLibInfo::JQUERY_CONTEXTMENU_FILENAME);               // jQuery Contextmenu Lib
1320                                                 $this->addScriptFile(self::M3_ADMIN_SCRIPT_FILENAME);           // 管理スクリプトライブラリ追加
1321                                                 //$this->addScript('', ScriptLibInfo::LIB_JQUERY_JQEASYPANEL);          // パネルメニュー(一般画面と管理画面の切り替え等)用
1322                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_M3_SLIDEPANEL);  // 管理パネル用スクリプト追加
1323                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_EASING);                 // 管理パネル用スクリプト追加
1324                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1325                                         
1326                                                 $this->addCssFile(self::M3_ADMIN_CSS_FILE);             // 管理機能用CSS
1327 //                                              if (!$this->useBootstrap) $this->addCssFile(self::M3_NO_BOOTSTRAP_CSS_FILE);    // Bootstrapを読み込まない場合は代替CSSを読み込む
1328                                         }
1329                                 } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET && !empty($openBy)){                                                // ウィジェット単体実行でウィンドウを持つ場合の追加スクリプト
1330                                         if ($gEnvManager->isContentEditableUser()){             // コンテンツ編集可能ユーザの場合
1331                                                 $this->isEditMode = true;                       // 一般画面編集モード
1332                                         
1333                                                 //$this->addScript('', ScriptLibInfo::LIB_FCKEDITOR);// FCKEditorスクリプト追加
1334                                                 $this->addScript('', ScriptLibInfo::getWysiwygEditorLibId());   // WYSIWYGエディターを追加
1335                                                 $this->addScriptFile(self::M3_PLUS_SCRIPT_FILENAME);            // 一般画面追加用スクリプト追加(PLUSライブラリを追加する場合はFCKEditorも使用可能にする)
1336                                                 $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
1337                                                 $this->addScript('', ScriptLibInfo::LIB_JQUERY_CLUETIP);// HELP用スクリプト追加
1338                                                 
1339                                                 // Googleマップライブラリの読み込み
1340                                                 if ($this->useGooglemaps && $this->wysiwygEditor == ScriptLibInfo::LIB_CKEDITOR){                       // CKEditorの場合はGoogleマップライブラリを読み込む
1341                                                         $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));
1342                                                 }
1343                                         }
1344                                 }
1345                         }
1346                 }
1347
1348                 // デフォルトのページ情報を取得
1349                 $row = $this->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
1350                 if (!empty($row)){
1351                         // ショートURLで取得できない場合は、ページコンテンツタイプを取得
1352                         if (empty($this->contentType)) $this->contentType = $row['pn_content_type'];
1353                         
1354                         // 現在のページ情報を設定
1355                         $this->currentPageInfo = $row;                  // 現在のページのページ情報
1356                 }
1357                 
1358                 // 画面透過モードを設定
1359                 if ($openBy == 'tabs') $this->isTransparentMode = true;         // 画面透過モード
1360         }
1361         /**
1362          * 言語に依存する情報を取り込む
1363          *
1364          * @return                                                      なし
1365          */
1366         function loadLang()
1367         {
1368                 global $gEnvManager;
1369                 global $gSystemManager;
1370                 
1371                 $lang = $gEnvManager->getCurrentLanguage();
1372                 
1373                 // デフォルト言語とカレント言語が異なる場合のみ実行
1374                 if ($lang != $gEnvManager->getDefaultLanguage()){
1375                         // 指定言語のサイト定義取得
1376                         $gSystemManager->roadSiteDefByLang($lang);
1377                 }
1378                 
1379                 // 現在の言語でヘッダ初期化
1380                 $this->headDescription  = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_DESCRIPTION);    // HTMLヘッダ「description」に出力する文字列
1381                 $this->headKeywords             = $gSystemManager->getSiteDef(M3_TB_FIELD_SITE_KEYWORDS);               // HTMLヘッダ「keywords」に出力する文字列
1382                 $this->headOthers               = $gSystemManager->getSiteDef(self::SD_HEAD_OTHERS);                    // HTMLヘッダに出力するタグ文字列
1383
1384                 // デフォルトのページ情報でヘッダを更新
1385                 if (!empty($this->currentPageInfo)){
1386                         $title          = $this->currentPageInfo['pn_meta_title'];              // 画面タイトル
1387                         $desc           = $this->currentPageInfo['pn_meta_description'];                // ページ要約
1388                         $keyword        = $this->currentPageInfo['pn_meta_keywords'];           // ページキーワード
1389                         $headOthers     = $this->currentPageInfo['pn_head_others'];             // ヘッダその他タグ
1390                         
1391                         if (!empty($title)) $this->setHeadSubTitle($title);
1392                         if (!empty($desc)) $this->setHeadDescription($desc);
1393                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1394                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1395                 }
1396
1397                 // 現在の言語のページ情報でヘッダを更新
1398                 $ret = $this->db->getPageInfo($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $lang, $row);
1399                 if ($ret){
1400                         $title          = $row['pn_meta_title'];                // 画面タイトル
1401                         $desc           = $row['pn_meta_description'];          // ページ要約
1402                         $keyword        = $row['pn_meta_keywords'];             // ページキーワード
1403                         $headOthers = $row['pn_head_others'];           // ヘッダその他タグ
1404                         
1405                         if (!empty($title)) $this->setHeadSubTitle($title);
1406                         if (!empty($desc)) $this->setHeadDescription($desc);
1407                         if (!empty($keyword)) $this->setHeadKeywords($keyword);
1408                         if (!empty($headOthers)) $this->setHeadOthers($headOthers);
1409                         
1410                         // 現在のページ情報を設定
1411 //                      $this->currentPageInfo = $row;                  // 現在のページのページ情報
1412                 }
1413         }
1414         /**
1415          * スクリプト追加情報から、管理機能用のJavascriptファイル、CSSを追加する
1416          *
1417          * @param string $task                          指定タスク
1418          * @param string $scriptInfo            スクリプト追加情報
1419          * @return                                                      なし
1420          */
1421         function addAdminScript($task, $scriptInfo)
1422         {
1423                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1424                 for ($i = 0; $i < count($itemArray); $i++){
1425                         $pos = strpos($itemArray[$i], '=');
1426                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1427                                 $libs = trim($itemArray[$i]);
1428                         } else {                // タスク指定のとき
1429                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1430                                 $libTask = trim($libTask);
1431                                 $libs = trim($libs);
1432                                 
1433                                 if (strEndsWith($libTask, '_')){                // 「task_subtask」形式のタスクのとき
1434                                         if (!strStartsWith($task, $libTask)) $libs = '';                        // タスクIDの先頭部が異なるときは追加しない
1435                                 } else {
1436                                         if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1437                                 }
1438                         }
1439                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1440                                 $libsArray = explode(',', $libs);
1441                                 for ($j = 0; $j < count($libsArray); $j++){
1442                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1443                                         
1444                                         // ライブラリセットを展開
1445                                         $setLibArray = ScriptLibInfo::getLibSet($lib);
1446                                         $setLibCount = count($setLibArray);
1447                                         if ($setLibCount > 0){                  // ライブラリセットの場合
1448                                                 for ($k = 0; $k < $setLibCount; $k++){
1449                                                         $this->_addAdminScript($setLibArray[$k]);
1450                                                 }
1451                                         } else {
1452                                                 $this->_addAdminScript($lib);
1453                                         }
1454                                 }
1455                         }
1456                 }
1457         }
1458         /**
1459          * ライブラリIDに対応するJavascriptファイル、CSSを追加する
1460          *
1461          * @param string $lib                           ライブラリID
1462          * @return                                                      なし
1463          */
1464         function _addAdminScript($lib)
1465         {
1466                 // ライブラリが存在しないときは終了
1467                 if (!isset($this->libFiles[$lib])) return;
1468                 
1469                 // 依存ライブラリを取得
1470                 if (strcmp($lib, ScriptLibInfo::LIB_ELFINDER) == 0 || strcmp($lib, ScriptLibInfo::LIB_JQUERY_TIMEPICKER) == 0){         // elFinder、timepickerを使用する場合
1471                         // jQuery UIライブラリを追加
1472                         $dependentLib = ScriptLibInfo::getDependentLib($lib);
1473                         for ($i = 0; $i < count($dependentLib); $i++){
1474                                 $addLib = $dependentLib[$i];
1475
1476                                 // ライブラリのファイルを追加
1477                                 if (isset($this->libFiles[$addLib]['script'])){
1478                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1479                                         for ($m = 0; $m < count($scriptFiles); $m++){
1480                                                 $this->addAdminScriptFile($scriptFiles[$m]);            // 通常機能用のスクリプト追加
1481                                         }
1482                                 }
1483                                 if (isset($this->libFiles[$addLib]['css'])){
1484                                         $cssFiles = $this->libFiles[$addLib]['css'];
1485                                         for ($m = 0; $m < count($cssFiles); $m++){
1486                                                 $this->addAdminCssFile($cssFiles[$m]);          // 通常機能用のCSS追加
1487                                         }
1488                                 }
1489                         }
1490                         // jQueryUIテーマを追加
1491                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1492                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1493                                 $this->outputTheme = true;
1494                         }
1495                 }
1496                 // Javascript追加
1497                 if (isset($this->libFiles[$lib]['script'])){
1498                         $scriptFiles = $this->libFiles[$lib]['script'];
1499                         for ($i = 0; $i < count($scriptFiles); $i++){
1500                                 $this->addAdminScriptFile($scriptFiles[$i]);            // 管理機能用のスクリプト追加
1501                         }
1502                 }
1503                 // CSS追加
1504                 if (isset($this->libFiles[$lib]['css'])){
1505                         $cssFiles = $this->libFiles[$lib]['css'];
1506                         for ($i = 0; $i < count($cssFiles); $i++){
1507                                 $this->addAdminCssFile($cssFiles[$i]);          // 管理機能用のCSS追加
1508                         }
1509                 }
1510                 // その他
1511                 if (strncmp($lib, 'jquery-ui.', 10) == 0){              // jQuery UIのwidgetsまたはeffectsのとき。jQuery UI Coreはデフォルトで読み込まれている。
1512                         // jQueryUIテーマを追加
1513                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1514                                 $this->addAdminCssFile($this->getAdminDefaultThemeUrl());               // CSS追加(絶対パス)
1515                                 $this->outputTheme = true;
1516                         }
1517                 }
1518         }
1519         /**
1520          * スクリプト追加情報から、通常機能用のJavascriptファイル、CSSを追加する
1521          *
1522          * @param string $task                          指定タスク
1523          * @param string $scriptInfo            スクリプト追加情報
1524          * @return                                                      なし
1525          */
1526         function addScript($task, $scriptInfo)
1527         {
1528                 // ライブラリ情報取得
1529                 $jQueryUiInfo = ScriptLibInfo::getJQueryUiInfo();
1530                 
1531                 $itemArray = explode(self::SCRIPT_LIB_SEPARATOR, strtolower(trim($scriptInfo)));// 小文字に変換したものを解析
1532                 for ($i = 0; $i < count($itemArray); $i++){
1533                         $pos = strpos($itemArray[$i], '=');
1534                         if ($pos === false){// 見つからないときは、タスクが指定されないとき
1535                                 $libs = trim($itemArray[$i]);
1536                         } else {                // タスク指定のとき
1537                                 list($libTask, $libs) = explode('=', trim($itemArray[$i]));
1538                                 $libTask = trim($libTask);
1539                                 $libs = trim($libs);
1540                                 if (empty($libTask) || $libTask != $task) $libs = '';                   // タスクが異なるときは追加しない
1541                         }
1542                         if (!empty($libs)){             // // スクリプト、CSSの追加を行うとき
1543                                 $libsArray = explode(',', $libs);
1544                                 for ($j = 0; $j < count($libsArray); $j++){
1545                                         $lib = strtolower(trim($libsArray[$j]));// 小文字に変換
1546                                         
1547                                         // jQueryライブラリ等、デフォルトでは追加されないライブラリを追加
1548                                         if (strcmp($lib, 'jquery') == 0){// jQuery本体のとき
1549                                                 $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1550                                         } else if (isset($this->libFiles[$lib])){               // ライブラリが存在するとき
1551                                                 // ライブラリの依存ライブラリファイルを追加
1552                                                 if (strncmp($lib, 'jquery.', 7) == 0){          // jQueryプラグインのとき
1553                                                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1554                                                         if (strcmp($lib, 'jquery.mobile') == 0){        // jQueryMobileファイルのとき
1555                                                                 // ##### jQueryMobileが読み込まれる前に読み込む必要があるスクリプトを設定 #####
1556                                                                 if (!empty($this->headPreMobileScriptFiles)){           // jQueryMobileファイルの前に出力
1557                                                                         for ($l = 0; $l < count($this->headPreMobileScriptFiles); $l++){
1558                                                                                 $this->addScriptFile($this->headPreMobileScriptFiles[$l]);              // 通常機能用のスクリプト追加
1559                                                                         }
1560                                                                 }
1561                                                         }
1562                                                 } else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI) == 0){    // jQuery UI
1563                                                         $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1564                                                 //} else if (strcmp($lib, ScriptLibInfo::LIB_JQUERY_UI_PLUS) == 0){     // jQuery UI plus
1565                                                 //      $this->addScriptFile($this->selectedJQueryFilename);            // JQueryスクリプト追加
1566                                                 //      $this->addScriptFile($this->selectedJQueryUiFilename);          // jQuery Coreスクリプト追加
1567                                                 } else if (strncmp($lib, 'jquery-ui.', 10) == 0){               // jQuery UIのwidgetsまたはeffectsのとき
1568                                                         // 依存ライブラリ追加
1569                                                         $parentLib = $jQueryUiInfo[$lib];               // 依存ライブラリ取得
1570                                                         for ($l = 0; $l < count($parentLib); $l++){
1571                                                                 $addLib = $parentLib[$l];
1572                                                                 
1573                                                                 // ライブラリのファイルを追加
1574                                                                 if (isset($this->libFiles[$addLib]['script'])){
1575                                                                         $scriptFiles = $this->libFiles[$addLib]['script'];
1576                                                                         for ($m = 0; $m < count($scriptFiles); $m++){
1577                                                                                 $this->addScriptFile($scriptFiles[$m]);         // 通常機能用のスクリプト追加
1578                                                                         }
1579                                                                 }
1580                                                                 if (isset($this->libFiles[$addLib]['css'])){
1581                                                                         $cssFiles = $this->libFiles[$addLib]['css'];
1582                                                                         for ($m = 0; $m < count($cssFiles); $m++){
1583                                                                                 $this->addCssFile($cssFiles[$m]);               // 通常機能用のCSS追加
1584                                                                         }
1585                                                                 }
1586                                                         }
1587                                                         // jQueryUIテーマを追加
1588                                                         if (!$this->outputTheme){                               // jQueryUIテーマ出力を行ったかどうか
1589                                                                 //$this->addHeadCssFile($this->getAdminDefaultThemeUrl());              // CSS追加
1590                                                                 $this->addHeadCssFile($this->getDefaultThemeUrl());             // CSS追加
1591                                                                 $this->outputTheme = true;
1592                                                         }
1593                                                 }
1594                                                 
1595                                                 // ライブラリ自体のファイルを追加
1596                                                 if (isset($this->libFiles[$lib]['script'])){
1597                                                         $scriptFiles = $this->libFiles[$lib]['script'];
1598                                                         for ($l = 0; $l < count($scriptFiles); $l++){
1599                                                                 $this->addScriptFile($scriptFiles[$l]);         // 通常機能用のスクリプト追加
1600                                                         }
1601                                                 }
1602                                                 if (isset($this->libFiles[$lib]['css'])){
1603                                                         $cssFiles = $this->libFiles[$lib]['css'];
1604                                                         for ($l = 0; $l < count($cssFiles); $l++){
1605                                                                 $this->addCssFile($cssFiles[$l]);               // 通常機能用のCSS追加
1606                                                         }
1607                                                 }
1608                                         }
1609                                 }
1610                         }
1611                 }
1612         }
1613         /**
1614          * 非ログイン時の管理機能用のJavascriptファイル、CSSを追加する
1615          *
1616          * @param string $libId         追加ライブラリID
1617          * @return                                      なし
1618          */
1619         function addDefaultAdminScript($libId)
1620         {
1621                 // Javascript追加
1622                 if (isset($this->libFiles[$libId]['script'])){
1623                         $scriptFiles = $this->libFiles[$libId]['script'];
1624                         for ($i = 0; $i < count($scriptFiles); $i++){
1625                                 $this->defaultAdminDirScriptFiles[] = $scriptFiles[$i];         // デフォルトで読み込むスクリプトファイル(管理ディレクトリ用)
1626                         }
1627                 }
1628                 // CSS追加
1629                 if (isset($this->libFiles[$libId]['css'])){
1630                         $cssFiles = $this->libFiles[$libId]['css'];
1631                         for ($i = 0; $i < count($cssFiles); $i++){
1632                                 $this->defaultAdminDirCssFiles[] = $cssFiles[$i];               // デフォルトで読み込むCSSファイル(管理ディレクトリ用)
1633                         }
1634                 }
1635         }
1636         /**
1637          * ページ作成終了
1638          *
1639          * ・最終HTML出力
1640          * ・セッション情報の保存
1641          * ・ウィジェットで生成されたHTTPヘッダを設定する
1642          *
1643          * @param RequestManager $request               HTTPリクエスト処理クラス
1644          * @param bool $getOutput                               出力を取得するかどうか
1645          * @return string                                       最終出力HTML
1646          */
1647         function endPage($request, $getOutput = false)
1648         {
1649                 global $gRequestManager;
1650                 global $gInstanceManager;
1651                 global $gEnvManager;
1652                 global $gDispManager;
1653                 global $gAccessManager;
1654                 
1655                 // ページ作成処理を中断するかどうか
1656                 if ($this->isAbort) return '';
1657                 
1658                 $contents = '';
1659                 
1660                 // 実行コマンドを取得
1661                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
1662                 
1663                 // 最終HTML(ページ全体で使用するHTML)の出力
1664                 if ($cmd != M3_REQUEST_CMD_DO_WIDGET){          // ウィジェット単体オペレーションのときは出力しない
1665                         if ($getOutput){
1666                                 $contents = $this->getLastContents($request);
1667                         } else {
1668                                 echo $this->getLastContents($request);
1669                         }
1670                 }
1671                 
1672                 // セッションへユーザ情報を保存
1673                 $userInfo = $gInstanceManager->getUserInfo();
1674                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
1675                 
1676                 // 画面設定保存
1677                 $gDispManager->save();
1678                         
1679                 // キャッシュリミッタは、各リクエスト毎に(アウトプットバッファー が無効な場合は、
1680                 // session_start()がコールされる 前に) session_cache_limiter()をコールする必要がある。
1681                 // キャッシュを残す設定
1682 //              session_cache_limiter('private');
1683 //              session_cache_expire(5);
1684                 if ($this->isRedirect) return '';                       // リダイレクトの場合は終了
1685
1686                 // ########## HTTPヘッダ出力処理 ########
1687                 if (headers_sent($filename, $linenum)){         // HTTPヘッダが既に送信されているとき
1688                         echo "$filename の $linenum 行目でヘッダがすでに送信されています。";
1689                 } else {
1690                         if ($gEnvManager->isMobile()){          // 携帯の場合
1691                                 // ドコモ端末の場合はリクエストヘッダにXHTMLを指定しないとXHTMLを処理しない
1692                                 $agent = $gInstanceManager->getMobileAgent();
1693                                 if ($agent->isDoCoMo()){        // ドコモ端末のとき
1694                                         header('Content-Type: application/xhtml+xml;');
1695                                 }
1696                         } else {
1697                                 // キャッシュを無効にする場合
1698                                 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');// 過去の日付
1699                                 header('Cache-Control: no-store, no-cache, must-revalidate');// HTTP/1.1
1700                                 header('Cache-Control: post-check=0, pre-check=0', false);
1701                                 header('Pragma: no-cache');
1702                 
1703                                 // 更新日時
1704                                 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
1705                 
1706                                 // Ajax用JSON型データをHTTPヘッダに格納
1707                                 $gInstanceManager->getAjaxManager()->header();
1708                         }
1709                         // システム制御画面が設定されている場合はステータスコードを変更
1710                         //if ($this->gEnv->getIsMaintenance()){
1711                         if (!$this->isRedirect){                        // リダイレクトがセットされていない場合
1712                                 switch ($this->systemHandleMode){
1713                                         case 10:                        // サイト非公開(システムメンテナンス)
1714                                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
1715                                                 header('Status: 503 Service Temporarily Unavailable');
1716                                                 break;
1717                                         case 11:                        // アクセス禁止のとき
1718                                                 header('HTTP/1.1 403 Forbidden');
1719                                                 header('Status: 403 Forbidden');
1720                                                 break;
1721                                         case 12:                        // 存在しないページのとき
1722                                                 header("HTTP/1.1 404 Not Found");
1723                                                 header("Status: 404 Not Found");
1724                                                 break;
1725                                 }
1726                         }
1727                 }
1728                 // ##### 自動ログイン #####
1729                 $gAccessManager->endAutoLogin();
1730                 
1731                 return $contents;
1732         }
1733         /**
1734          * ページ作成処理中断
1735          *
1736          * @return                                                      なし
1737          */
1738         function abortPage()
1739         {
1740                 global $gInstanceManager;
1741                 global $gRequestManager;
1742                 
1743                 // HTTPヘッダを削除(PHP 5.3以上で有効)
1744                 if (version_compare(PHP_VERSION, '5.3.0') >= 0) header_remove();
1745
1746                 // exit()等でabortPage()が最後の処理になってしまう可能性があるのでなるべく必要な処理を行う
1747                 //if (ob_get_level() > 0) ob_end_clean();// バッファ内容が残っているときは破棄
1748                 while (ob_get_level()) ob_end_clean();  // バッファ削除方法変更(2009/12/2)
1749                 
1750                 // セッションへユーザ情報を保存
1751                 $userInfo = $gInstanceManager->getUserInfo();
1752                 $gRequestManager->setSessionValueWithSerialize(M3_SESSION_USER_INFO, $userInfo);
1753                 
1754                 $this->isAbort = true;                                  // ページ作成処理を中断するかどうか
1755         }
1756         /**
1757          * 強制終了を実行
1758          *
1759          * @return              なし
1760          */
1761         function exitSystem()
1762         {
1763                 global $gEnvManager;
1764                 global $gAccessManager;
1765                 
1766                 // DBが使用可能であれば、アクセスログのユーザを登録
1767                 if ($gEnvManager->canUseDb()) $gAccessManager->accessLogUser();
1768                 
1769                 exit();         // システム終了
1770         }
1771         /**
1772          * Joomla!v1.5タグを読み込んでウィジェット実行
1773          *
1774          * @param string        $srcBuf                 バッファデータ
1775          * @param int           $templateVer    テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
1776          * @return string                                       変換後文字列
1777          */
1778         function launchWidgetByJoomlaTag($srcBuf, $templateVer)
1779         {
1780                 $replace = array();
1781                 $matches = array();
1782                 $destBuf = $srcBuf;
1783                 
1784                 if (preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $srcBuf, $matches)){
1785                         $count = count($matches[1]);
1786                         for ($i = 0; $i < $count; $i++)
1787                         {
1788                                 $contents = '';
1789                                 $type  = $matches[1][$i];
1790                                 $attr = array();
1791                                 if (strcasecmp($type, 'head') == 0){            // ヘッダ埋め込みタグの場合
1792                                         ob_clean();
1793                                         $this->getHeader();
1794                                         $contents = ob_get_contents();
1795                                 } else if (strcasecmp($type, 'modules') == 0 || 
1796                                                         strcasecmp($type, 'module') == 0){              // ポジションタグの場合
1797                                         $name = '';                     // ポジション名
1798                                         $style = '';            // 表示スタイル
1799                                         $params = explode(' ', $matches[2][$i]);
1800                                         for ($j = 0; $j < count($params); $j++){
1801                                                 list($key, $value) = explode('=', $params[$j]);
1802                                                 if (strcasecmp($key, 'name') == 0){
1803                                                         $name = strtolower(trim($value, "\"'"));
1804                                                         $attr['name'] = $name;
1805                                                 } else if (strcasecmp($key, 'style') == 0){
1806                                                         // スタイルは大文字小文字の区別あり
1807                                                         $style = trim($value, "\"'");
1808                                                 } else if (strcasecmp($key, 'artstyle') == 0){          // 表示スタイル
1809                                                         $attr['artstyle'] = trim($value, "\"'");
1810                                                 }
1811                                         }
1812                                         if (!empty($name)){             // ポジション名が取得できたとき
1813                                                 // Joomla!では、テンプレートの「jdoc:include」タグの属性styleが空のときは「none」で処理される
1814                                                 // Joomla!デフォルトで設定可能なのは「none,table,horz,xhtml,rounded,outline」
1815                                                 if (empty($style)){
1816                                                         if (strStartsWith($name, 'user') ||             // ナビゲーションメニュー位置の場合
1817                                                                 strcasecmp($name, 'position-1') == 0){                          // Joomla!v2.5テンプレート対応
1818                                                                 $style = self::WIDGET_STYLE_NAVMENU;            // デフォルトはナビゲーション型
1819                                                         } else {
1820                                                                 $style = 'none';
1821                                                         }
1822                                                 }
1823                                                 // ウィジェットの出力を取得
1824                                                 $contents = $this->getContents($name, $style, $templateVer, $attr);
1825                                         }
1826                                 } else if (strcasecmp($type, 'component') == 0){        // メインポジションタグの場合
1827                                         // スタイルを取得
1828                                         $style = '';            // 表示スタイル
1829                                         $params = explode(' ', $matches[2][$i]);
1830                                         for ($j = 0; $j < count($params); $j++){
1831                                                 list($key, $value) = explode('=', $params[$j]);
1832                                                 if (strcasecmp($key, 'style') == 0){
1833                                                         // スタイルは大文字小文字の区別あり
1834                                                         $style = trim($value, "\"'");
1835                                                         break;
1836                                                 }
1837                                         }
1838                                         if ($style != 'none') $style = 'xhtml';
1839                                         $contents = $this->getContents('main', $style, $templateVer, $attr);
1840                                 } else if (strcasecmp($type, 'message') == 0){  // メッセージタグの場合
1841                                 }
1842                                 $replace[$i] = $contents;
1843                         }
1844                         ob_clean();
1845                         $destBuf = str_replace($matches[0], $replace, $srcBuf);
1846                 }
1847                 return $destBuf;
1848         }
1849         /**
1850          * 遅延ウィジェット実行
1851          *
1852          * 遅延実行インデックスのついているウィジェットをインデックス順に実行し、出力バッファデータ内のタグの位置に出力を埋め込む
1853          *
1854          * @param RequestManager $request               HTTPリクエスト処理クラス
1855          * @param string         $srcBuf                バッファデータ
1856          * @return string                                               変換後文字列
1857          */
1858         function lateLaunchWidget($request, $srcBuf)
1859         {
1860                 global $gEnvManager;
1861                 global $gErrorManager;
1862                 global $gDesignManager;
1863                 
1864                 // ウィジェットヘッダ(Joomla!1.0用)を出力のタイプを取得
1865                 $widgetHeaderType = $this->getTemplateWidgetHeaderType();
1866                                         
1867                 // 遅延実行ウィジェットをインデックス順にソート
1868                 asort($this->lateLaunchWidgetList, SORT_NUMERIC);
1869                 
1870                 // タグを置換
1871                 $destBuf = $srcBuf;
1872                 foreach ($this->lateLaunchWidgetList as $widgetId => $value){
1873                         // 実行パラメータ取得
1874                         $count = count($this->latelaunchWidgetParam);
1875                         for ($i = 0; $i < $count; $i++){
1876                                 list($wId, $index, $confId, $preId, $serial, $style, $cssStyle, $title, $shared) = $this->latelaunchWidgetParam[$i];
1877                                 if ($wId == $widgetId){
1878                                         // パラメータ初期化
1879                                         $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
1880                                         $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
1881                                         $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
1882                                         
1883                                         // バッファ作成
1884                                         ob_start();
1885
1886                                         // ウィジェット実行ファイル取得
1887                                         $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
1888
1889                                         // その他パラメータ取得
1890                                         $configId = $confId;            // ウィジェット定義ID
1891                                         if ($configId == 0) $configId = '';
1892                                         $prefix = $preId;               // サフィックス文字列
1893                         
1894                                         // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
1895                                         $joomlaTitleVisble = false;
1896                                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
1897                                                 if (!empty($title)){
1898                                                         if ($widgetHeaderType == 1){            // PC用ウィジェットヘッダ出力
1899                                                                 echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
1900                                                                 echo '<tr><th>' . $title . '</th></tr>' . M3_NL;
1901                                                                 echo '<tr><td>' . M3_NL;
1902                                                                 $joomlaTitleVisble = true;
1903                                                         } else if ($widgetHeaderType == 2){                     // 携帯用ウィジェットヘッダ出力
1904                                                                 echo '<div>' . $title . '</div>' . M3_NL;
1905                                                                 $joomlaTitleVisble = true;
1906                                                         }
1907                                                 }
1908                                         }
1909                                         // ウィジェットの外枠タグを設定
1910                                         //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
1911                                         // ウィジェット親のCSS定義があるときは、タグを追加
1912                                         if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
1913                                         
1914                                         // ウィジェットの前出力
1915                                         echo $gDesignManager->getAdditionalWidgetOutput(true);
1916                                 
1917                                         // 作業中のウィジェットIDを設定
1918                                         $gEnvManager->setCurrentWidgetId($widgetId);
1919
1920                                         // ウィジェット定義IDを設定
1921                                         $gEnvManager->setCurrentWidgetConfigId($configId);
1922                                         
1923                                         // ページ定義のシリアル番号を設定
1924                                         $gEnvManager->setCurrentPageDefSerial($serial);
1925                 
1926                                         // パラメータを設定
1927                                         $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
1928                 
1929                                         // ウィジェットのタイトルを設定
1930                                         $gEnvManager->setCurrentWidgetTitle('');
1931                                         
1932                                         // ウィジェットのスタイルを設定
1933                                         $gEnvManager->setCurrentWidgetStyle($style);
1934                                 
1935                                         // ウィジェットのページ共通状況を設定
1936                                         $gEnvManager->setIsCurrentWidgetShared($shared);
1937                                 
1938                                         // 実行ログを残す
1939                                         $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
1940                                         
1941                                         // ウィジェットを実行
1942                                         // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
1943                                         $msg = 'widget-start(' . $widgetId . ')';
1944                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
1945                                         require($widgetIndexFile);
1946                                         $msg = 'widget-end(' . $widgetId . ')';
1947                                         $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
1948
1949                                         // 作業中のウィジェットIDを解除
1950                                         $gEnvManager->setCurrentWidgetId('');
1951                 
1952                                         // ウィジェット定義IDを解除
1953                                         $gEnvManager->setCurrentWidgetConfigId('');
1954                                         
1955                                         // ページ定義のシリアル番号を解除
1956                                         $gEnvManager->setCurrentPageDefSerial(0);
1957                 
1958                                         // パラメータを解除
1959                                         $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
1960                                         
1961                                         // ウィジェットのスタイルを解除
1962                                         $gEnvManager->setCurrentWidgetStyle('');
1963                                         
1964                                         // ウィジェットのページ共通状況を解除
1965                                         $gEnvManager->setIsCurrentWidgetShared(false);
1966                                         
1967                                         // ウィジェットのタイトルを取得
1968                                         $newTitle = $gEnvManager->getCurrentWidgetTitle();
1969
1970                                         // ウィジェットの後出力
1971                                         echo $gDesignManager->getAdditionalWidgetOutput(false);
1972                                 
1973                                         // ウィジェット親のCSS定義があるときは、タグを追加
1974                                         if (!empty($cssStyle)) echo '</div>' . M3_NL;
1975                                         // ウィジェットの外枠タグを設定
1976                                         //echo '</div>' . M3_NL;
1977                                         
1978                                         // Joomla!1.0テンプレートのときはタイトルを出力
1979                                         if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用ウィジェットヘッダ出力
1980                                                 echo '</td></tr>' . M3_NL;
1981                                                 echo '</table>' . M3_NL;
1982                                         }
1983                                         
1984                                         // 現在のバッファ内容を取得し、バッファを破棄
1985                                         $srcContents = ob_get_contents();
1986                                         ob_end_clean();
1987                                         
1988                                         // ウィジェットの出力を取得
1989                                         $tag = self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $index . self::WIDGET_ID_TAG_END;
1990                                         $destBuf = str_replace($tag, $srcContents, $destBuf);
1991                                         
1992                                         // タイトルの出力
1993                                         if (!empty($newTitle)) $title = $newTitle;
1994                                         $tag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $index . self::WIDGET_ID_TITLE_TAG_END;
1995                                         $destBuf = str_replace($tag, $title, $destBuf);
1996                                 }
1997                         }
1998                 }
1999                 $destBuf = $this->replaceHead($destBuf);
2000                 return $destBuf;
2001         }
2002         /**
2003          * ヘッダ部マクロ変換処理
2004          *
2005          * @param string         $srcBuf                変換元
2006          * @return string                                               変換後文字列
2007          */
2008         function replaceHead($srcBuf)
2009         {
2010                 $destBuf = $srcBuf;
2011
2012                 // ##### ヘッダ部分の置換 #####
2013                 if ($this->outputHead){                         // HTMLヘッダ出力を行っているとき
2014                         // タグ変換用文字列の取得
2015                         $replaceStr = $this->getHeaderOutput();
2016                         
2017                         // HTMLヘッダのデータ埋め込み
2018                         $destBuf = str_replace(self::HEAD_TAGS, $replaceStr, $destBuf);
2019                 }
2020                 $this->replaceHeadDone = true;                  // ヘッダマクロ変換処理が完了したかどうか
2021                 return $destBuf;
2022         }
2023         /**
2024          * ウィジェット検索モードの場合のページサブIDの設定
2025          *
2026          * @param RequestManager $request               HTTPリクエスト処理クラス
2027          */
2028         function redirectToUpdatedPageSubId($request)
2029         {
2030                 global $gEnvManager;
2031                 
2032                 // 現在設定されているページIDを取得
2033                 $pageId         = $gEnvManager->getCurrentPageId();
2034                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2035                 
2036                 // 送信元のウィジェットIDを取得
2037                 $fromWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_FROM);
2038                 
2039                 // 対象のウィジェットIDを取得
2040                 $targetWidgetId = $request->trimValueOf(M3_REQUEST_PARAM_WIDGET_ID);
2041                 
2042                 // 対象のウィジェットのページサブIDを取得
2043                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2044                 if ($ret){// データが存在する
2045                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2046                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2047                                 if ($ret){// データが存在する
2048                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2049                                         } else {
2050                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2051                                         }
2052                                 }
2053                         } else {
2054                                 // 送信元があるか順にチェック
2055                                 for ($i = 0; $i < count($rows); $i++){
2056                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2057                                         if ($ret){      
2058                                                 break;
2059                                         }
2060                                 }
2061                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2062                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2063                                 } else {
2064                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2065                                 }
2066                         }
2067                 } else {                // 対象のウィジェットが見つからない場合は、互換ウィジェットを探す
2068                         $widgetId = $this->db->getCompatibleWidgetId($targetWidgetId);
2069                         if (!empty($widgetId)){
2070                                 $targetWidgetId = $widgetId;
2071                                 
2072                                 // 対象のウィジェットのページサブIDを取得
2073                                 $ret = $this->db->getSubPageId($targetWidgetId, $pageId, $rows);
2074                                 if ($ret){// データが存在する
2075                                         if (empty($rows[0]['pd_sub_id'])){              // 共通ウィジェットのときは、送信元にあわせる
2076                                                 $ret = $this->db->getSubPageId($fromWidgetId, $pageId, $rows2);
2077                                                 if ($ret){// データが存在する
2078                                                         if (empty($rows2[0]['pd_sub_id'])){             // 送信元が共通ウィジェットのときは、既に設定されているページサブIDを使用
2079                                                         } else {
2080                                                                 $gEnvManager->setCurrentPageSubId($rows2[0]['pd_sub_id']);
2081                                                         }
2082                                                 }
2083                                         } else {
2084                                                 // 送信元があるか順にチェック
2085                                                 for ($i = 0; $i < count($rows); $i++){
2086                                                         $ret = $this->db->isExistsWidgetOnPage($pageId, $rows[$i]['pd_sub_id'], $fromWidgetId);
2087                                                         if ($ret){      
2088                                                                 break;
2089                                                         }
2090                                                 }
2091                                                 if ($i == count($rows)){                // 送信元が見つからない場合は1番目のページサブIDを使用
2092                                                         $gEnvManager->setCurrentPageSubId($rows[0]['pd_sub_id']);
2093                                                 } else {
2094                                                         $gEnvManager->setCurrentPageSubId($rows[$i]['pd_sub_id']);// 存在するときは見つかったページサブIDで更新
2095                                                 }
2096                                         }
2097                                 }
2098                         }
2099                 }
2100                 // ページサブIDが見つからないときは、既に設定されている値を使用
2101                 // 既に設定されている値は、URL「sub」パラメータで指定されている値か
2102                 // 設定されていない場合はデフォルトのサブページID
2103                 // ********** 指定ページへリダイレクト ***********
2104                 // 実行パラメータ取得
2105                 $todo = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TODO);
2106                 $todo = str_replace(M3_TODO_SEPARATOR, '&', $todo);             // セパレータを変換
2107                 $redirectUrl = '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
2108                 if (!empty($todo)) $redirectUrl .= '&' . $todo;
2109                 if ($gEnvManager->getIsMobileSite()){           // 携帯用アクセスポイントの場合
2110                         $this->redirect($redirectUrl, true/*遷移時のダイアログ表示を抑止*/);
2111                 } else {
2112                         $this->redirect($redirectUrl);
2113                 }
2114         }
2115         /**
2116          * 最終HTML出力処理
2117          *
2118          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2119          * 追加するHTMLは主にウィンドウ管理用のスクリプト
2120          *
2121          * @param RequestManager $request               HTTPリクエスト処理クラス
2122          * @return string                                       最終HTML
2123          */
2124         function getLastContents($request)
2125         {
2126                 global $gEnvManager;
2127
2128                 $contents = '';
2129                 $initScript = '';               // 初期化用スクリプト
2130                 $pageId         = $gEnvManager->getCurrentPageId();
2131                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
2132                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2133                 
2134                 // RSS配信のときは終了
2135                 if ($cmd == M3_REQUEST_CMD_RSS) return '';
2136                 
2137                 if ($gEnvManager->getIsMobileSite()){           // 携帯用URLのとき
2138                 } else {                        // PC用URLのとき
2139                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2140                                 //if ($gEnvManager->isSystemAdmin()){           // 管理者権限がある場合のみ有効
2141                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
2142                                         // ウィジェットレイアウト用カーソル
2143                                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
2144                                                 //$contents .= '<div class="clear"></div>' . M3_NL;
2145                                                 /*
2146                                                 $contents .= '<div id="m3_overlay">' . M3_NL;           // ロード中表示
2147                                                 $contents .= '<div id="preloader"><img src="' . $gEnvManager->getImagesUrl() . '/system/loader.gif" alt="" /></div>' . M3_NL;
2148                                                 $contents .= '</div>' . M3_NL;*/
2149
2150                                                 // テンプレート上のポジション名
2151                                                 if (count($this->viewPosId) > 0){
2152                                                         $posArrayStr = '[';
2153                                                         for ($i = 0; $i < count($this->viewPosId); $i++){
2154                                                                 $posArrayStr .= '\'#' . $this->viewPosId[$i] . '\'';
2155                                                                 //$posArrayStr .= '\'' . $this->viewPosId[$i] . '\'';
2156                                                                 if ($i < count($this->viewPosId) - 1) $posArrayStr .= ',';
2157                                                         }
2158                                                         $posArrayStr .= ']';
2159                                                         $contents .= 'var M3_POSITIONS=' . $posArrayStr . ';' . M3_NL;
2160                                                 }
2161                                                 // 画面定義のリビジョン番号
2162                                                 $contents .= 'var M3_REVISION=' . $this->pageDefRev . ';' . M3_NL;
2163                                 
2164                                                 // 更新用関数追加
2165                                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2166                                                 $contents .= M3_INDENT_SPACE . 'window.m3.m3UpdateByConfig(serial);' . M3_NL;
2167                                                 $contents .= '}' . M3_NL;
2168                                         
2169                                                 // 携帯用テンプレートのときは、プレビューウィンドウの更新を通知する
2170                                                 /*if ($gEnvManager->getCurrentTemplateType() == 1){
2171                                                         $contents .= 'if (window.parent.m3UpdateByChildWindow) window.parent.m3UpdateByChildWindow();' . M3_NL;
2172                                                 }*/
2173                                         } else if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){                       // ウィジェット設定画面
2174                                                 // 画面更新用関数追加
2175                                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2176                                                 $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2177                                                 $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2178                                                 $contents .= M3_INDENT_SPACE . 'm3UpdateParentWindow();' . M3_NL;               // 親ウィンドウ更新
2179                                                 $contents .= '}' . M3_NL;
2180                                                 
2181                                                 // IEエラーメッセージ出力抑止
2182                                                 $contents .= 'function hideIEErrors(){' . M3_NL;
2183                                                 $contents .= M3_INDENT_SPACE . 'return true;' . M3_NL;
2184                                                 $contents .= '}' . M3_NL;
2185                                                 $contents .= 'window.onerror = hideIEErrors;' . M3_NL;
2186                                         } else {                // ダッシュボード画面、メイン管理画面
2187                                                 // 画面更新用関数追加
2188                                                 $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2189                                                 $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2190                                                 $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2191                                                 $contents .= '}' . M3_NL;
2192                                         }
2193                                         
2194                                         // ウィジェット単体実行以外のときの処理
2195                                         if (!$this->showWidget){
2196                                                 if ($this->updateParentWindow){                 // 管理画面からの親画面の更新
2197                                                         $initScript .= M3_INDENT_SPACE . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
2198                                                 }
2199                                         }
2200                                         
2201                                         // ##### ヘルプシステムの組み込み #####
2202                                         // ヘルプシステムはすべての初期処理完了後に実行する
2203                                         // ヘルプシステムは、「span」タグで埋め込み、「title」属性を使用する
2204                                         if ($this->useHelp){                    // ヘルプ表示のとき
2205                                                 $initScript .= M3_INDENT_SPACE . '$(\'span.m3help\').cluetip({splitTitle: \'|\', cluezIndex: 2000});' . M3_NL;
2206                                                 //if ($cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){                // ウィジェット付きポジション表示以外のとき
2207                                                         $initScript .= M3_INDENT_SPACE . 'if (jQuery().tooltip) $(\'[rel=m3help]\').tooltip({ placement: \'top\'});' . M3_NL;           // Bootstrapツールチップ。タイトルのみ表示。
2208                                                 //}
2209                                         } else {                        // ヘルプ非表示のときは、title属性をクリアする
2210                                                 $initScript .= M3_INDENT_SPACE . '$(\'span.m3help\').attr(\'title\', \'\');' . M3_NL;
2211                                         }
2212                                 }
2213                         } else {                // 通常画面のとき
2214                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
2215                                         // 画面更新用関数追加
2216                                         $contents .= 'function m3UpdateByConfig(serial){' . M3_NL;
2217                                         $contents .= M3_INDENT_SPACE . 'var href = window.location.href.split("#");' . M3_NL;
2218                                         $contents .= M3_INDENT_SPACE . 'window.location.href = href[0];' . M3_NL;
2219                                         $contents .= '}' . M3_NL;
2220                                 }
2221                         }
2222                 }
2223                 $destContents = '';
2224                 if (!empty($contents) || !empty($initScript)){
2225                         $destContents .= '<script type="text/javascript">' . M3_NL;
2226                         $destContents .= '//<![CDATA[' . M3_NL;
2227                         $destContents .= $contents;
2228                         if (!empty($initScript)){               // 初期化用スクリプト
2229                                 $destContents .= '$(function(){' . M3_NL;
2230                                 $destContents .= $initScript;
2231                                 $destContents .= '});' . M3_NL;
2232                         }
2233                         $destContents .= '//]]>' . M3_NL;
2234                         $destContents .= '</script>' . M3_NL;
2235                 }
2236                 return $destContents;
2237         }
2238         /**
2239          * オプションHTML出力処理
2240          *
2241          * テンプレートの出力が完了した後、HTMLとして出力する最後の出力を行う
2242          *
2243          * @param RequestManager $request               HTTPリクエスト処理クラス
2244          * @return string                                       最終HTML
2245          */
2246         function getOptionContents($request)
2247         {
2248                 global $gEnvManager;
2249                 
2250                 $contents = '';
2251                 
2252                 // Magic3出力コメント
2253                 if (!$gEnvManager->isMobile() && $this->outputByHtml){          // 携帯以外で、HTML出力のとき
2254                         $contents .= '<!-- created by ' . M3_SYSTEM_NAME . ' v' . M3_SYSTEM_VERSION . ' - http://www.magic3.org -->' . M3_NL;
2255                         $contents .= '<!-- convert time: ' . sprintf('%01.03f', microtime(true) - M3_MTIME) . ' -->' . M3_NL;
2256                 }
2257                 return $contents;
2258         }
2259         /**
2260          * Widget単体起動用のHTMLのヘッダ部(headタグ)出力
2261          *
2262          * Widgetの出力方法は、以下のパターンがある
2263          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
2264          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
2265          *
2266          * @param string $cmd           起動コマンド
2267          */
2268         function startWidget($cmd)
2269         {
2270                 global $gEnvManager;
2271                 global $gRequestManager;
2272                                 
2273                 // ウィジェット単体表示のときのみ出力
2274                 if (!$this->showWidget) return;
2275                 
2276                 // パラメータ取得
2277                 $openBy = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
2278                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
2279
2280 //              $isHtml5 = false;               // HTML5で出力するかどうか
2281                 $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
2282                 if (intval($tempVer) >= 2) $this->isHtml5 = true;               // HTML5で出力するかどうか                             
2283                 
2284                 // DOCTYPEの設定
2285                 if ($this->isHtml5){
2286                         echo '<!DOCTYPE html>' . M3_NL;
2287                         echo '<html dir="ltr" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
2288                         echo '<head>' . M3_NL;
2289                 } else {
2290                         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . M3_NL;
2291                         echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $gEnvManager->getCurrentLanguage() . '" lang="' . $gEnvManager->getCurrentLanguage() . '">' . M3_NL;
2292                         echo '<head>' . M3_NL;
2293 //                      echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . M3_NL;
2294                 }
2295
2296                 // HTMLのヘッダ部(headタグ内)出力
2297                 $this->getHeader();
2298
2299                 // 現在のウィジェットを取得
2300                 $widgetId = $gEnvManager->getCurrentWidgetId();         // カレントのウィジェットID
2301                 
2302                 // URLを作成
2303                 if ($gEnvManager->getUseSslAdmin()){
2304                         $rootUrl = $gEnvManager->getSslRootUrl();
2305                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
2306                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
2307                 } else {
2308                         $rootUrl = $gEnvManager->getRootUrl();
2309                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
2310                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
2311                 }
2312                 
2313                 // ##### テンプレートのCSSの読み込み #####
2314                 // テンプレートは管理用テンプレートに固定されている
2315                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット設定のとき
2316                         $curTemplateUrl = $templatesUrl . '/' . $gEnvManager->getCurrentTemplateId();
2317                         if ($this->isHtml5){
2318                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/style.css" media="screen">' . M3_NL;
2319                                 echo '<link rel="stylesheet" href="' . $curTemplateUrl . '/css/widget.css" media="screen">' . M3_NL;            // ウィジェット設定画面用CSS
2320                         echo '<!--[if IE]><link rel="stylesheet" href="' . $curTemplateUrl . '/css/iestyles.css" media="screen"><![endif]-->' . M3_NL;
2321                                 echo '<!--[if lt IE 9]><script src="' . $curTemplateUrl . '/html5shiv.js"></script><![endif]-->' . M3_NL;
2322                         } else {
2323                                 echo '<link href="' . $curTemplateUrl . '/css/style.css" rel="stylesheet" type="text/css" />' . M3_NL;
2324                                 echo '<!--[if IE]><link rel="stylesheet" type="text/css" media="screen" href="' . $curTemplateUrl . '/css/iestyles.css" /><![endif]-->' . M3_NL;
2325                         }
2326                 }
2327                 // ウィジェット情報取得
2328                 $ret = $this->db->getWidgetInfo($widgetId, $row);
2329
2330                 // ##### 共通ライブラリ読み込み設定 #####
2331                 if ($cmd == M3_REQUEST_CMD_DO_WIDGET){          // ウィジェット単体実行のとき
2332                         $scritLib = trim($row['wd_add_script_lib']);
2333                         if (!empty($scritLib)) $this->addScript($task, $scritLib);
2334                 }
2335                                 
2336                 // CSS読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
2337                 if ($row['wd_read_css']){
2338                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_CSS;
2339                         if (is_dir($searchPath)){
2340                                 $dir = dir($searchPath);
2341                                 while (($file = $dir->read()) !== false){
2342                                         $filePath = $searchPath . '/' . $file;
2343                                         if ($file != '.' && $file != '..' && is_file($filePath)
2344                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
2345                                                 
2346                                                 // CSSへのURLを作成
2347                                                 $cssURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_CSS . '/' . $file;
2348                                                 echo '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
2349                                         }
2350                                 }
2351                                 $dir->close();
2352                         }
2353                 }
2354                 
2355                 // スクリプト読み込みが指定されていて、ディレクトリがあるときはディレクトリ内読み込み
2356                 if ($row['wd_read_scripts']){
2357                         $searchPath = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS;
2358                         if (is_dir($searchPath)){
2359                                 $dir = dir($searchPath);
2360                                 while (($file = $dir->read()) !== false){
2361                                         $filePath = $searchPath . '/' . $file;
2362                                         if ($file != '.' && $file != '..' && is_file($filePath)
2363                                                 && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
2364                                                 
2365                                                 // スクリプトへのURLを作成
2366                                                 $scriptURL = $widgetsUrl . '/' . $widgetId . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
2367                                                 
2368                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
2369                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
2370                                                 echo '<script type="text/javascript" src="' . $scriptURL . '"></script>' . M3_NL;
2371                                         }
2372                                 }
2373                                 $dir->close();
2374                         }
2375                 }
2376                 
2377                 // ウィジェットのタイトルを設定
2378                 $title = $row['wd_name'];
2379                 if (empty($title)) $title = $row['wd_id'];
2380                 echo '<title>' . self::WIDGET_TITLE_START . htmlspecialchars($title) . self::WIDGET_TITLE_END . '</title>' . M3_NL;
2381                 echo '</head>' . M3_NL;
2382                 // タブでウィンドウを開く場合は背景を透過モードにする
2383                 if ($this->isTransparentMode){
2384                         echo '<body style="background-color:transparent;">' . M3_NL;
2385                 } else {
2386                         echo '<body>' . M3_NL;
2387                 }
2388                 // Bootstrap用のタグ出力
2389                 if ($this->useBootstrap) echo '<div class="container">' . M3_NL;
2390                 
2391                 // 別ウィンドウで表示のときは、「閉じる」ボタンを表示
2392                 if ($cmd == M3_REQUEST_CMD_SHOW_WIDGET ||               // ウィジェットの単体表示のとき
2393                         $cmd == M3_REQUEST_CMD_CONFIG_WIDGET || // ウィジェット詳細設定画面のとき
2394                         $cmd == M3_REQUEST_CMD_DO_WIDGET){              // ウィジェット単体実行のとき
2395
2396                         if ($this->isEditMode){// 一般画面編集モードのとき
2397                                 if (!empty($openBy)){
2398                                         // サーバ指定されている場合はサーバ情報を取得
2399                                         $serverName = '';
2400                                         $server = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_SERVER);
2401                                         if (!empty($server)){
2402                                                 // 設定データを取得
2403                                                 $ret = $this->db->getServerById($server, $row);
2404                                                 if ($ret){
2405                                                         $serverName = 'サーバ名:' . $row['ts_name'];// サーバ名
2406                                                         echo '<div align="left" style="float:left;padding-left:30px;"><label>' . convertToHtmlEntity($serverName) . '</label></div>';
2407                                                 }
2408                                         }
2409                                         // タブ形式以外のときは「閉じる」ボタンを表示
2410                                         if ($openBy != 'tabs'){
2411                                                 if ($openBy == 'logout'){
2412                                                         $titleStr = 'ログアウト';
2413                                                         echo '<div class="m3configclose"><a href="#" onclick="location.href=\'?cmd=logout\';"><img src="' . $rootUrl . self::CLOSE_ICON_FILE . 
2414                                                                                 '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></div>' . M3_NL;
2415                                                 } else {
2416                                                         $titleStr = '閉じる';
2417                                                         echo '<div class="m3configclose"><a href="#" onclick="window.close();"><img src="' . $rootUrl . self::CLOSE_ICON_FILE . 
2418                                                                                 '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></div>' . M3_NL;
2419                                                 }
2420                                         }
2421                                 }
2422                                 // 「前へ」「次へ」ボタン
2423                                 $titleStr = '前へ';
2424                                 echo '<div class="m3configprev" style="display:none;"><a id="m3configprev" href="#"><img src="' . $rootUrl . self::PREV_ICON_FILE . 
2425                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></div>' . M3_NL;
2426                                 $titleStr = '次へ';
2427                                 echo '<div class="m3confignext" style="display:none;"><a id="m3confignext" href="#"><img src="' . $rootUrl . self::NEXT_ICON_FILE . 
2428                                                         '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></div>' . M3_NL;
2429                         }
2430                 }
2431                 echo '<div class="row">' . M3_NL;
2432                 echo '<!-- Widget Start -->' . M3_NL;
2433         }
2434         /**
2435          * Widget単体起動用のタグを閉じる
2436          *
2437          * @param string $cmd           起動コマンド
2438          */
2439         function endWidget($cmd)
2440         {
2441                 // ウィジェット単体表示のときのみ出力
2442                 if (!$this->showWidget) return;
2443                 
2444                 echo '</div>' . M3_NL;
2445                 echo '<!-- Widget End -->' . M3_NL;
2446                 
2447                 // ##### ウィジェットからの指定による処理 #####
2448                 if ($this->updateParentWindow){                 // 親ウィンドウ再描画のとき
2449                         echo '<script type="text/javascript">' . M3_NL;
2450                         echo '//<![CDATA[' . M3_NL;
2451                         echo '$(function(){' . M3_NL;
2452                         if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){              // ウィジェット詳細設定画面のとき
2453                                 echo str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindowByConfig(' . $this->updateDefSerial . ');' . M3_NL;// 更新する項目のページ定義シリアル番号
2454                         } else if ($cmd == M3_REQUEST_CMD_DO_WIDGET){                   // ウィジェット単体実行のとき
2455                                 echo str_repeat(M3_INDENT_SPACE, 1) . 'm3UpdateParentWindow();' . M3_NL;
2456                         }
2457                         echo '});' . M3_NL;
2458                         echo '//]]>' . M3_NL;
2459                         echo '</script>' . M3_NL;
2460                 }
2461                 
2462                 // Bootstrap用のタグ出力
2463                 if ($this->useBootstrap) echo '</div>' . M3_NL;
2464                 
2465                 echo '</body>' . M3_NL;
2466                 echo '</html>' . M3_NL;
2467         }
2468         /**
2469          * Widget単体RSS出力用のHTMLのヘッダ部(headタグ)出力
2470          *
2471          * Widgetの出力方法は、以下のパターンがある
2472          *  ・HTMLヘッダ付加 - Widget単体で画面出力するためにHTMLヘッダを付加するパターン
2473          *  ・HTMLヘッダなし - Wiget単体のタグ出力のみのパターン
2474          *
2475          * @param string $cmd           起動コマンド
2476          */
2477         function startWidgetRss($cmd)
2478         {
2479         }
2480         /**
2481          * Widget単体RSS出力用のタグを閉じる
2482          *
2483          * @param string $cmd                   起動コマンド
2484          * @param string $rssContent    RSS配信内容
2485          */
2486         function endWidgetRss($cmd, $rssContent)
2487         {
2488                 global $gEnvManager;
2489                 
2490                 // ページ作成中断のときは終了
2491                 if ($this->isAbort) return;
2492                 
2493                 echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
2494                 
2495                 // RSSチャンネルデータ取得
2496                 $lang   = $gEnvManager->getCurrentLanguage();
2497                 $date   = getW3CDate();         // RSS1.0用日付
2498                 $copyright = $gEnvManager->getSiteCopyRight();          // 著作権
2499                 $title  = $this->rssChannel['title'];                           // タイトル
2500                 $link   = $this->rssChannel['link'];                            // RSS取得用URL
2501                 $desc   = $this->rssChannel['description'];                     // 説明
2502                 $seq    = $this->rssChannel['seq'];                                     // 項目の並び順(URL)
2503                 
2504                 switch ($this->rssVersion){                                     // RSSバージョン
2505                         case '1.0':
2506                         default:
2507                                 echo '<rdf:RDF xmlns="http://purl.org/rss/1.0/" ';
2508                                 echo 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ';
2509                                 echo 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
2510                                 echo 'xml:lang="' . $lang . '">' . M3_NL;
2511                                 echo '<channel rdf:about="' . convertUrlToHtmlEntity($link) . '">' . M3_NL;
2512                                 echo '<title>' . convertToHtmlEntity($title) . '</title>' . M3_NL;
2513                                 echo '<link>' . convertUrlToHtmlEntity($link) . '</link>' . M3_NL;              // 「convertUrlToHtmlEntity」が必要
2514                                 echo '<description>' . convertToHtmlEntity($desc) . '</description>' . M3_NL;
2515                                 echo '<dc:language>' . $lang . '</dc:language>' . M3_NL;
2516                                 if (!empty($copyright)) echo '<dc:rights>' . convertToHtmlEntity($copyright) . '</dc:rights>' . M3_NL;
2517                                 echo '<dc:date>' . $date . '</dc:date>' . M3_NL;
2518                                 echo '<items>' . M3_NL;
2519                                 if (count($seq) > 0){
2520                                         echo str_repeat(M3_INDENT_SPACE, 1) . '<rdf:Seq>' . M3_NL;
2521                                         for ($i = 0; $i < count($seq); $i++){
2522                                                 echo str_repeat(M3_INDENT_SPACE, 2) . '<rdf:li rdf:resource="' . convertUrlToHtmlEntity($seq[$i]) . '" />' . M3_NL;
2523                                         }
2524                                         echo str_repeat(M3_INDENT_SPACE, 1) . '</rdf:Seq>' . M3_NL;
2525                                 }
2526                                 echo '</items>' . M3_NL;
2527                                 echo '</channel>' . M3_NL;
2528                                 echo $rssContent;
2529                                 echo '</rdf:RDF>' . M3_NL;
2530                                 break;
2531                         case '2.0':
2532                                 break;
2533                 }
2534                 
2535                 // HTTPレスポンスヘッダ設定
2536                 header("Content-type: text/xml; charset=utf-8");
2537         }
2538         /**
2539          * 直サーバ接続時のXML出力用のHTMLのヘッダ部(headタグ)出力
2540          *
2541          * @param string $cmd           起動コマンド
2542          * @return                                      なし
2543          */
2544         function startWidgetXml($cmd)
2545         {
2546                 // HTTPレスポンスヘッダ
2547                 //header("Content-type: text/xml; charset=utf-8");
2548         }
2549         /**
2550          * 直サーバ接続時のXML出力終了
2551          *
2552          * @param string $cmd           起動コマンド
2553          * @return                                      なし
2554          */
2555         function endWidgetXml()
2556         {
2557         }
2558         /**
2559          * 携帯用ドキュメントタイプ出力
2560          *
2561          * @return string                               ドキュメントタイプ出力
2562          */
2563         function getMobileDocType()
2564         {
2565                 global $gEnvManager;
2566                 global $gInstanceManager;
2567                 global $gRequestManager;
2568                 
2569                 $docTypeStr = '';               // 出力するDocType
2570                 $agent = $gInstanceManager->getMobileAgent();
2571                 if ($agent->isDoCoMo()){        // ドコモ端末のとき
2572                         $htmlVer = $agent->getHTMLVersion();
2573                         switch ($htmlVer){
2574                                 case '4.0':
2575                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/1.0) 1.0//EN" "i-xhtml_4ja_10.dtd">';
2576                                         break;
2577                                 case '5.0':
2578                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/1.1) 1.0//EN" "i-xhtml_4ja_10.dtd">';
2579                                         break;
2580                                 case '6.0':
2581                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.0) 1.0//EN" "i-xhtml_4ja_10.dtd">';
2582                                         break;
2583                                 case '7.0':
2584                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.1) 1.0//EN" "i-xhtml_4ja_10.dtd">';
2585                                         break;
2586                                 case '7.1':
2587                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.2) 1.0//EN" "i-xhtml_4ja_10.dtd">';
2588                                         break;
2589                                 case '7.2':
2590                                         $docTypeStr = '<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN" "i-xhtml_4ja_10.dtd">';
2591                                         break;
2592                                 default:
2593                                         if (preg_match("/^DoCoMo\/1\.0/i", $gRequestManager->trimServerValueOf('HTTP_USER_AGENT'))){            // mova端末のとき
2594                                                 // mova端末のときはドキュメントタイプなしにすると画面表示可能
2595                                                 return '';
2596                                         }
2597                                         break;
2598                         }
2599                 } else if ($agent->isEZweb()){  // au端末のとき
2600                         if ($agent->isWAP2()){
2601                                 $docTypeStr = '<!DOCTYPE html PUBLIC "-//OPENWAVE//DTD XHTML 1.0//EN" "http://www.openwave.com/DTD/xhtml-basic.dtd">';
2602                         }
2603                 } else if ($agent->isSoftBank()){       // ソフトバンク端末のとき
2604                         if ($agent->isTypeW() || $agent->isType3GC()){
2605                                 $docTypeStr = '<!DOCTYPE html PUBLIC "-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN" "xhtml-basic10-plus.dtd">';
2606                         }
2607                 }
2608                 if ($gEnvManager->getIsMobileSite()){           // 携帯用サイトへのアクセスの場合
2609                         echo '<?xml version="1.0" encoding="' . $gEnvManager->getMobileCharset() . '" ?>' . M3_NL;
2610                 } else {
2611                         echo '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>' . M3_NL;
2612                 }
2613                 if (empty($docTypeStr)) $docTypeStr = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
2614                 echo $docTypeStr . M3_NL;
2615         }
2616         /**
2617          * デフォルトのXML宣言取得
2618          *
2619          * @return string       XML宣言
2620          */
2621         function getDefaultXmlDeclaration()
2622         {
2623                 return '<?xml version="1.0" encoding="' . M3_HTML_CHARSET . '" ?>';
2624         }
2625         /**
2626          * HTMLのヘッダ部(headタグ内)出力
2627          *
2628          * システムに共通な定義をHTMLのheadタグ内に出力する
2629          * mosFunc.phpからも実行されるので、このメソッドは引数なしに固定。
2630          * この関数は、以下の「形式1」または「形式2」でheadタグ内に記述する
2631          *
2632          * 形式1:            <!-- m3:HTMLHeader -->
2633          * 形式2(old style): <?php mosShowHead(); ?>
2634          */
2635         function getHeader()
2636         {
2637                 global $gEnvManager;
2638                 global $gRequestManager;
2639
2640                 $this->outputHead = true;                               // HTMLヘッダ出力を行ったかどうか
2641                 
2642                 // 実行コマンドを取得
2643                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2644                 
2645                 // ######### 携帯用サイトの場合は別にヘッダを作成する #########
2646                 if ($gEnvManager->getIsMobileSite()){
2647                         // キャラクターセット
2648                         echo '<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=' . $gEnvManager->getMobileCharset() . '" />' . M3_NL;
2649
2650                         // キャッシュを保存させない
2651                         echo '<meta http-equiv="Pragma" content="no-cache" />' . M3_NL;
2652                         echo '<meta http-equiv="Cache-Control" content="no-cache" />' . M3_NL;
2653                         echo '<meta http-equiv="Expires" content="-1" />' . M3_NL;
2654                 
2655                         // サイト構築エンジン
2656                         echo '<meta name="generator" content="' . M3_SYSTEM_NAME . ' ver.' . M3_SYSTEM_VERSION . ' - ' . M3_SYSTEM_DESCRIPTION . '" />' . M3_NL;
2657                 } else {                // PC用サイト、管理用サイト、スマートフォン用サイトのとき
2658 //                      $isHtml5 = false;               // HTML5で出力するかどうか
2659                         if ($gEnvManager->getIsSmartphoneSite()){               // スマートフォン用サイトのときはHTML5で設定
2660                                 $this->isHtml5 = true;
2661                         } else {
2662                                 $tempVer = $gEnvManager->getCurrentTemplateType();              // テンプレートタイプを取得(0=デフォルト(Joomla!v1.0),1=Joomla!v1.5,2=Joomla!v2.5)
2663                                 if (intval($tempVer) >= 2) $this->isHtml5 = true;
2664                         }
2665                         
2666                         // ********** メタタグの設定 **********
2667         
2668                         // キャラクターセット
2669                         //if ($gEnvManager->getIsSmartphoneSite()){             // スマートフォン用サイトのときはHTML5で設定
2670                         if ($this->isHtml5){
2671                                 //echo '<meta http-equiv="content-type" content="text/html; charset=' . M3_HTML_CHARSET .'" />' . M3_NL;
2672                                 echo '<meta charset="' . M3_HTML_CHARSET . '">' . M3_NL;
2673                         } else {
2674                                 echo '<meta http-equiv="content-script-type" content="text/javascript" />' . M3_NL;
2675                                 echo '<meta http-equiv="content-style-type" content="text/css" />' . M3_NL;
2676                                 echo '<meta http-equiv="content-type" content="application/xhtml+xml; charset=' . M3_HTML_CHARSET .'" />' . M3_NL;
2677                         }
2678                 
2679                         // 基準ディレクトリの指定
2680                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION ||                             // 表示位置を表示するとき
2681                                 $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){      // 表示位置を表示するとき(ウィジェット付き)
2682                         
2683                                 if ($gEnvManager->getUseSslAdmin()){
2684                                         $rootUrl = $gEnvManager->getSslRootUrl();
2685                                 } else {
2686                                         $rootUrl = $gEnvManager->getRootUrl();
2687                                 }
2688                                 echo '<base href="' . $rootUrl . '/" />' . M3_NL;
2689                         }
2690                 }
2691                 echo self::HEAD_TAGS;                   // HTMLヘッダの埋め込みデータ
2692         }
2693         /**
2694          * HTMLヘッダ出力文字列の取得
2695          *
2696          * @return string               HTMLヘッダ出力文字列
2697          */
2698         function getHeaderOutput()
2699         {
2700                 global $gEnvManager;
2701                 global $gRequestManager;
2702                 global $gInstanceManager;
2703                 global $gSystemManager;
2704
2705                 $replaceStr = '';               // 変換文字列
2706                 
2707                 // 実行コマンドを取得
2708                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
2709                 $task = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
2710                 
2711                 // ********************************************************
2712                 //               ヘッダ文字列作成の前処理
2713                 // ********************************************************
2714                 // ##### テンプレートの設定、フレームの設定から必要なライブラリを取得 #####
2715                 // Bootstrapライブラリ
2716 //              if (!$this->useBootstrap) $this->useBootstrap = $gEnvManager->getCurrentTemplateUseBootstrap();
2717                 if ($this->useBootstrap){
2718                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2719                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
2720                                         $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP);                // 管理画面でBootstrapを使用するかどうか
2721                                         if ($cmd != M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // 管理画面(ウィジェット付きポジション表示)以外のとき
2722                                                 $this->addAdminScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);  // Bootstrap管理画面オプション
2723                                         }
2724                                 } else {                // ログインしていない場合(ログイン画面等)
2725                                         $this->addDefaultAdminScript(ScriptLibInfo::LIB_BOOTSTRAP);
2726                                         $this->addDefaultAdminScript(ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);// Bootstrap管理画面オプション
2727                                 }
2728                         } else {                // 一般画面へのアクセスの場合
2729                                 $this->addScript('', ScriptLibInfo::LIB_BOOTSTRAP);             // 一般画面でBootstrapを使用するかどうか
2730                                 if ($cmd == M3_REQUEST_CMD_LOGIN || $cmd == M3_REQUEST_CMD_LOGOUT || $cmd == M3_REQUEST_CMD_PREVIEW){                           // ログイン、ログアウト場合
2731                                         $this->addScript('', ScriptLibInfo::LIB_BOOTSTRAP_ADMIN);               // Bootstrap管理画面オプション
2732                                 }
2733                         }
2734                 } else {
2735                         if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効(ログイン中の場合)
2736                                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2737                                         //$this->addAdminCssFile(self::M3_NO_BOOTSTRAP_CSS_FILE);       // Bootstrapを読み込まない場合は代替CSSを読み込む
2738                                         $this->addAdminScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);              // Bootstrapを使用しない場合の管理機能用スクリプト
2739                                 } else {
2740                                         //$this->addCssFile(self::M3_NO_BOOTSTRAP_CSS_FILE);    // Bootstrapを読み込まない場合は代替CSSを読み込む
2741                                         $this->addScript('', ScriptLibInfo::LIB_NOBOOTSTRAP);           // Bootstrapを使用しない場合の管理機能用スクリプト
2742                                 }
2743                         }
2744                 }
2745                 
2746                 // ********************************************************
2747                 //               ヘッダ文字列作成処理
2748                 // ********************************************************
2749                 // ##### インストール時のヘッダ出力 #####
2750                 if (defined('M3_STATE_IN_INSTALL')){
2751                         // タイトルの作成
2752                         $title = '';
2753                         if (count($this->headSubTitle) > 0) $title = htmlspecialchars(trim($this->headSubTitle[0]));
2754                         
2755                         // ********** メタタグの設定 **********
2756                         $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
2757                         
2758                         // ##### インストーラ用のファイルの読み込み #####
2759                         $scriptsUrl = '../scripts';
2760                         
2761                         // 管理機能用共通ライブラリのCSSの読み込み
2762                         $count = count($this->defaultAdminCssFiles);
2763                         for ($i = 0; $i < $count; $i++){
2764                                 // CSSへのURLを作成
2765                                 $cssFilename = $this->defaultAdminCssFiles[$i];
2766                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
2767                                         $cssURL = $cssFilename;
2768                                 } else {
2769                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
2770                                 }
2771                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
2772                         }
2773                         
2774                         // 管理画面用の共通スクリプトを読み込む
2775                         $count = count($this->defaultAdminScriptFiles);
2776                         for ($i = 0; $i < $count; $i++){
2777                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
2778
2779                                 // スクリプトのURLを修正
2780                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
2781                                         $scriptURL = $scriptFilename;
2782                                         
2783                                         // SSLをページの状態に合わせる
2784                                         if ($isSslPage){
2785                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
2786                                         } else {
2787                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
2788                                         }
2789                                 } else {
2790                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
2791                                 }
2792                         
2793                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
2794                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
2795                                 $replaceStr .=  '<script type="text/javascript" src="' . $scriptURL . '"></script>' . M3_NL;
2796                         }
2797                         return $replaceStr;
2798                 }
2799                 
2800                 // テンプレートの情報を取得
2801                 $cleanType = $gEnvManager->getCurrentTemplateCleanType();               // テンプレートクリーンタイプ
2802 /*              if ($this->db->getTemplate($gEnvManager->getCurrentTemplateId(), $templateRow)){
2803                         $cleanType = $templateRow['tm_clean_type'];
2804                 }*/
2805                 
2806                 // URLの作成
2807                 $isSslPage = false;
2808                 if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2809                         // 管理画面のSSL状態を参照
2810                         if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
2811                 } else {
2812                         $isSslPage = $this->isSslPage($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId());
2813                 }
2814                 if ($isSslPage){
2815                         $rootUrl = $gEnvManager->getSslRootUrl();
2816                         $scriptsUrl = $gEnvManager->getSslScriptsUrl();         // スクリプト読み込み用パス
2817                         $widgetsUrl = $gEnvManager->getSslWidgetsUrl();         // ウィジェット格納パス
2818                         $templatesUrl = $gEnvManager->getSslTemplatesUrl();     // テンプレート読み込み用パス
2819                 } else {
2820                         $rootUrl = $gEnvManager->getRootUrl();
2821                         $scriptsUrl = $gEnvManager->getScriptsUrl();            // スクリプト読み込み用パス
2822                         $widgetsUrl = $gEnvManager->getWidgetsUrl();            // ウィジェット格納パス
2823                         $templatesUrl = $gEnvManager->getTemplatesUrl();        // テンプレート読み込み用パス
2824                 }
2825                         
2826                 // タイトルの設定
2827                 if (!$this->showWidget){// 単体実行以外のとき
2828                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスの場合
2829                                 // 管理画面のタイトル
2830                                 // メイン画面は「サイト名 - 管理画面」、サブ画面は個別画面名
2831                                 $siteName = $gEnvManager->getSiteName();
2832 //                              if (empty($siteName)) $siteName = self::DEFAULT_SITE_NAME;
2833                                 $title = $siteName . ' - ' . self::DEFAULT_ADMIN_TITLE;
2834                                 $titleCount = count($this->headSubTitle);
2835                                 if ($titleCount > 0) $title = $this->headSubTitle[$titleCount -1];              // サブタイトルが設定されている場合は変更
2836                                 $replaceStr .= '<title>' . htmlspecialchars($title) . '</title>' . M3_NL;
2837                         } else {                        // 管理画面以外の画面へのアクセスの場合
2838                                 // 画面タイトル
2839                                 $titleItemCount = 0;            // タイトル項目数
2840                                 $defaultTitle = trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_TITLE));
2841                                 if (!empty($defaultTitle)) $titleItemCount++;
2842                                 if (!empty($this->headSubTitle)){               // サブタイトルが設定されているとき
2843                                         $titleItemCount += count($this->headSubTitle);
2844                                 }
2845                                 // タイトルフォーマットを取得
2846                                 $title = '';
2847                                 if ($titleItemCount > 0){
2848                                         $format = $this->gSystem->getSystemConfig(self::CONFIG_KEY_HEAD_TITLE_FORMAT);
2849                                         if (empty($format)){
2850                                                 $title = htmlspecialchars($defaultTitle);
2851                                         } else {
2852                                                 $formats = explode(';', $format);
2853                                                 $titleItemCount = ($titleItemCount > count($formats)) ? count($formats) : $titleItemCount;
2854                                                 $title = $formats[$titleItemCount -1];
2855                                                 $number = 1;
2856                                                 if (!empty($defaultTitle)){
2857                                                         $title = str_replace('$1', htmlspecialchars($defaultTitle), $title);
2858                                                         $number++;
2859                                                 }
2860                                                 for ($i = 0; $i < count($this->headSubTitle); $i++){
2861                                                         $key = '$' . $number;
2862                                                         $value = htmlspecialchars(trim($this->headSubTitle[$i]));
2863                                                         $title = str_replace($key, $value, $title);
2864                                                         $number++;
2865                                                 }
2866                                         }
2867                                 }
2868                                 if (!empty($title)) $replaceStr .= '<title>' . $title . '</title>' . M3_NL;
2869
2870                                 // サイトの説明
2871                                 if (!empty($this->headDescription)) $replaceStr .= '<meta name="description" content="' . htmlspecialchars($this->headDescription) . '" />' . M3_NL;
2872                 
2873                                 // 検索エンジン用キーワード
2874                                 if (!empty($this->headKeywords)) $replaceStr .= '<meta name="keywords" content="' . htmlspecialchars($this->headKeywords) . '" />' . M3_NL;
2875                                 
2876                                 // その他HTMLヘッダに出力するタグ文字列
2877                                 if (!empty($this->headOthers)){
2878                                         // マクロを変換
2879                                         $this->headOthers = $gInstanceManager->getTextConvManager()->convContentMacro($this->headOthers, false/*改行コードをbrタグに変換しない*/, array(), true/*変換後の値はHTMLエスケープ処理する*/);
2880                                         $replaceStr .= $this->headOthers . M3_NL;
2881                                 }
2882                         }
2883                 }
2884                 
2885                 // ##### PC用URLと携帯用URLのアクセス別に処理 #####
2886                 if ($gEnvManager->getIsMobileSite()){           // 携帯用URLのとき
2887                 } else {                        // PC用URLまたはスマートフォン用URLのとき
2888                         // ##### テンプレート情報に応じた処理 #####
2889                         // テンプレートクリーンが必要な場合はJQueryを追加
2890                         if ($cleanType != 0) $this->addScriptFile($this->selectedJQueryFilename);               // JQueryスクリプト追加
2891                         
2892                         // 検索ロボットへの指示
2893                         $robots = htmlspecialchars(trim($this->gSystem->getSiteDef(M3_TB_FIELD_SITE_ROBOTS)));
2894                         if (!empty($robots)){
2895                                 $replaceStr .= '<meta name="robots" content="' . $robots . '" />' . M3_NL;
2896                         }
2897                 
2898                         // サイト構築エンジン
2899                         $replaceStr .= '<meta name="generator" content="' . M3_SYSTEM_NAME . ' ver.' . M3_SYSTEM_VERSION . ' - ' . M3_SYSTEM_DESCRIPTION . '" />' . M3_NL;              
2900
2901                         // Faviconの読み込み
2902                         $templateId = $gEnvManager->getCurrentTemplateId();
2903                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2904                                 // テンプレートのFaviconがない場合はシステムのデフォルトのFaviconを使用
2905                                 $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
2906                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
2907                                         $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
2908                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
2909                                 } else {
2910                                         // 管理画面のアイコンを設定
2911                                         $faviconPath = $gEnvManager->getSystemRootPath() . self::DEFAULT_ADMIN_FAVICON_FILE;
2912                                         if (file_exists($faviconPath)){         // ファイルが存在しているとき
2913                                                 $faviconFile = $rootUrl . self::DEFAULT_ADMIN_FAVICON_FILE;
2914                                                 $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
2915                                         }
2916                                 }
2917                         } else {
2918                                 $faviconPath = $gEnvManager->getTemplatesPath() . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
2919                                 if (file_exists($faviconPath)){         // ファイルが存在しているとき
2920                                         $faviconFile = $templatesUrl . '/' . $templateId . self::DEFAULT_FAVICON_FILE;
2921                                         $replaceStr .= '<link rel="shortcut icon" href="' . $faviconFile .'" />' . M3_NL;
2922                                 }
2923                         }
2924                         // ##### 追加ライブラリの読み込み #####
2925                         if ($gEnvManager->getIsSmartphoneSite()){                       // スマートフォン用URLのとき
2926                                 $value = $gSystemManager->getSystemConfig(self::CF_SMARTPHONE_USE_JQUERY_MOBILE);// スマートフォン画面で常にjQuery Mobileを使用
2927                                 if ($value){
2928                                         // ##### jQueryMobileが読み込まれる前に読み込む必要があるスクリプトを設定 #####
2929                                         if (!empty($this->headPreMobileScriptFiles)){           // jQueryMobileファイルの前に出力
2930                                                 for ($l = 0; $l < count($this->headPreMobileScriptFiles); $l++){
2931                                                         $this->addScriptFile($this->headPreMobileScriptFiles[$l]);              // 通常機能用のスクリプト追加
2932                                                 }
2933                                         }
2934                                         $this->addScriptFile($this->selectedJQueryMobileFilename);
2935                                 }
2936                         }
2937                         
2938                         // ##### Ajaxライブラリの読み込み #####
2939                         if (!$gEnvManager->isAdminDirAccess()){         // 通常画面へのアクセスのとき
2940                                 if ($this->db->isExistsWidgetWithAjax($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId())){// Ajaxライブラリを使用しているウィジェットがあるときは追加
2941                                         $this->addScriptFile($this->selectedJQueryFilename);            // デフォルトAjaxライブラリ追加
2942                                         $this->addScriptFile(self::M3_OPTION_SCRIPT_FILENAME);  // Magic3のオプションライブラリ追加
2943                                 }
2944                         }
2945                                 
2946                         // ##### 共通ライブラリの読み込み #####
2947                         if (!$this->showWidget){// 単体実行以外のとき
2948                                 $this->db->getWidgetsIdWithLib($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
2949                                 for ($i = 0; $i < count($rows); $i++){
2950                                         $this->addScript($task, trim($rows[$i]['wd_add_script_lib']));
2951                                 }
2952                         }
2953
2954                         // ##### 共通CSS読み込み #####
2955                         if ($this->isEditMode){                 // 一般画面編集モード
2956                                 $cssURL = $scriptsUrl . '/' . self::M3_EDIT_CSS_FILE;
2957                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
2958                         }
2959                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
2960                                 //if ($gEnvManager->isSystemAdmin()){           // 管理者権限がある場合のみ有効
2961                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
2962                                         // 管理機能用共通ライブラリのCSSの読み込み
2963                                         $count = count($this->defaultAdminCssFiles);
2964                                         for ($i = 0; $i < $count; $i++){
2965                                                 // CSSへのURLを作成
2966                                                 //$cssURL = $scriptsUrl . '/' . $this->defaultAdminCssFiles[$i];
2967                                                 $cssFilename = $this->defaultAdminCssFiles[$i];
2968                                                 if (strncasecmp($cssFilename, 'http://', 7) == 0 || strncasecmp($cssFilename, 'https://', 8) == 0){
2969                                                         $cssURL = $cssFilename;
2970                                                 } else {
2971                                                         $cssURL = $scriptsUrl . '/' . $cssFilename;
2972                                                 }
2973                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
2974                                         }
2975                                 } else {
2976                                         // 管理権限なしで管理ディレクトリアクセスで必要なCSSファイルを読み込む
2977                                         $count = count($this->defaultAdminDirCssFiles);
2978                                         for ($i = 0; $i < $count; $i++){
2979                                                 // CSSへのURLを作成
2980                                                 $cssURL = $scriptsUrl . '/' . $this->defaultAdminDirCssFiles[$i];
2981                                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
2982                                         }
2983                                 }
2984                         } else {
2985                                 // 共通ライブラリのCSSの読み込み
2986                                 $count = count($this->defaultCssFiles);
2987                                 for ($i = 0; $i < $count; $i++){
2988                                         // CSSへのURLを作成
2989                                         $cssURL = $scriptsUrl . '/' . $this->defaultCssFiles[$i];
2990                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
2991                                 }
2992                         }
2993                         
2994                         // ##### 表示モードによるCSS読み込み #####
2995                         // ウィジェット付きポジション画面は管理画面のアクセスではない
2996                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
2997                                 // ウィジェット操作用CSS
2998                                 $cssURL = $scriptsUrl . self::M3_ADMIN_WIDGET_CSS_FILE;
2999                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3000                         }
3001                         
3002                         // ##### ウィジェットごとのCSS読み込み #####
3003                         // CSSがあるウィジェットを取得
3004                         $this->db->getWidgetsIdWithCss($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3005                         for ($i = 0; $i < count($rows); $i++){
3006                                 $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS;
3007                                 // ディレクトリがあるときはディレクトリ内読み込み
3008                                 if (is_dir($searchPath)){
3009                                         $dir = dir($searchPath);
3010                                         while (($file = $dir->read()) !== false){
3011                                                 $filePath = $searchPath . '/' . $file;
3012                                                 if ($file != '.' && $file != '..' && is_file($filePath)
3013                                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3014                                         
3015                                                         // CSSへのURLを作成
3016                                                         $cssURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_CSS . '/' . $file;
3017                                                         $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssURL . '" />' . M3_NL;
3018                                                 }
3019                                         }
3020                                         $dir->close();
3021                                 }
3022                         }
3023                         // ウィジェットからの追加のCSS読み込み
3024                         $count = count($this->headCssFiles);
3025                         for ($i = 0; $i < $count; $i++){
3026                                 $cssUrl = $this->headCssFiles[$i];
3027                                 if ($isSslPage) $cssUrl = str_replace('http://', 'https://', $cssUrl);                  // SSL化が必要なときは変換
3028                                 $replaceStr .=  '<link rel="stylesheet" type="text/css" href="' . $cssUrl . '" />' . M3_NL;
3029                         }
3030
3031                         // ##### RSS配信情報の読み込み #####
3032                         $count = count($this->headRssFiles);
3033                         for ($i = 0; $i < $count; $i++){
3034                                 $rssUrl = $this->headRssFiles[$i]['href'];// リンク先URL
3035                                 $rssTitle = $this->headRssFiles[$i]['title'];// タイトル
3036                                 $replaceStr .=  '<link rel="alternate" type="application/rss+xml" title="' . $rssTitle . '" href="' . convertUrlToHtmlEntity($rssUrl) . '" />' . M3_NL;
3037                         }
3038                                                                         
3039                         // ##### 共通Javascriptの読み込み #####
3040                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面へのアクセスのとき
3041                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限がある場合のみ有効
3042                                         // 管理画面用の共通スクリプトを読み込む
3043                                         $count = count($this->defaultAdminScriptFiles);
3044                                         for ($i = 0; $i < $count; $i++){
3045                                                 $scriptFilename = $this->defaultAdminScriptFiles[$i];
3046
3047                                                 // スクリプトのURLを修正
3048                                                 if (strncasecmp($scriptFilename, 'http://', 7) == 0 || strncasecmp($scriptFilename, 'https://', 8) == 0){
3049                                                         $scriptURL = $scriptFilename;
3050                                                         
3051                                                         // SSLをページの状態に合わせる
3052                                                         if ($isSslPage){
3053                                                                 $scriptURL = str_replace('http://', 'https://', $scriptURL);
3054                                                         } else {
3055                                                                 $scriptURL = str_replace('https://', 'http://', $scriptURL);
3056                                                         }
3057                                                 } else {
3058                                                         $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3059                                                 }
3060                                         
3061                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3062                                                 //$scriptURL = $scriptsUrl . '/' . $scriptFilename;
3063                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3064                                                 $replaceStr .=  '<script type="text/javascript" src="' . $scriptURL . '"></script>' . M3_NL;
3065                                         }
3066                                         if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示のときは、ウィジェット操作ライブラリを読み込む
3067                                                 // wigetのドラッグドロップ用
3068                                                 $scriptURL = $scriptsUrl . '/' . self::M3_ADMIN_WIDGET_SCRIPT_FILENAME;
3069                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();// スクリプトをキャッシュ保存しない場合は、パラメータを付加
3070                                                 $replaceStr .=  '<script type="text/javascript" src="' . $scriptURL . '"></script>' . M3_NL;
3071                                         }
3072                                 } else {                // システム運用権限がない場合
3073                                         // 管理権限なしで管理ディレクトリアクセスで必要なスクリプトを読み込む
3074                                         $count = count($this->defaultAdminDirScriptFiles);
3075                                         for ($i = 0; $i < $count; $i++){
3076                                                 $scriptFilename = $this->defaultAdminDirScriptFiles[$i];
3077
3078                                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3079                                                 $scriptURL = $scriptsUrl . '/' . $scriptFilename;
3080                                                 if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3081                                                 $replaceStr .=  '<script type="text/javascript" src="' . $scriptURL . '"></script>' . M3_NL;
3082                                         }
3083                                 }
3084                         } else {                        // 通常画面
3085                                 // Googleマップライブラリの読み込み
3086                                 if ($this->useGooglemaps && $this->isContentGooglemaps) $this->addScriptFile(ScriptLibInfo::getScript(ScriptLibInfo::LIB_GOOGLEMAPS));  // コンテンツにGoogleマップが含むかどうか
3087
3088                                 $count = count($this->defaultScriptFiles);
3089                                 for ($i = 0; $i < $count; $i++){
3090                                         $defaultScriptFile = $this->defaultScriptFiles[$i];
3091                                         
3092                                         // ##### jQueryMobileスクリプトを追加する場合は直前に初期化スクリプトを追加 #####
3093                                         if ($defaultScriptFile == $this->selectedJQueryMobileFilename){
3094                                                 if (count($this->headPreMobileScript) > 0){
3095                                                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3096                                                         $replaceStr .= '//<![CDATA[' . M3_NL;
3097                                                         for ($j = 0; $j < count($this->headPreMobileScript); $j++){
3098                                                                 $replaceStr .= $this->headPreMobileScript[$j];
3099                                                         }
3100                                                         $replaceStr .= M3_NL;
3101                                                         $replaceStr .= '//]]>' . M3_NL;
3102                                                         $replaceStr .= '</script>' . M3_NL;
3103                                                 }
3104                                         }
3105                                         
3106                                         // スクリプトのURLを修正
3107                                         if (strncasecmp($defaultScriptFile, 'http://', 7) == 0 || strncasecmp($defaultScriptFile, 'https://', 8) == 0){
3108                                                 $scriptURL = $defaultScriptFile;
3109                                                 
3110                                                 // SSLをページの状態に合わせる
3111                                                 if ($isSslPage){
3112                                                         $scriptURL = str_replace('http://', 'https://', $scriptURL);
3113                                                 } else {
3114                                                         $scriptURL = str_replace('https://', 'http://', $scriptURL);
3115                                                 }
3116                                         } else {
3117                                                 $scriptURL = $scriptsUrl . '/' . $defaultScriptFile;
3118                                         }
3119
3120                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3121                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3122                                         $replaceStr .=  '<script type="text/javascript" src="' . $scriptURL . '"></script>' . M3_NL;
3123                                 }
3124                         }
3125                         // ##### ウィジェットごとのJavaScript読み込み #####
3126                         // スクリプトがあるウィジェットを取得
3127                         $this->db->getWidgetsIdWithScript($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $rows);
3128                         for ($i = 0; $i < count($rows); $i++){
3129                                 $searchPath = $gEnvManager->getWidgetsPath() . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS;
3130                         
3131                                 // ディレクトリがあるときはディレクトリ内読み込み
3132                                 if (is_dir($searchPath)){
3133                                         $dir = dir($searchPath);
3134                                         while (($file = $dir->read()) !== false){
3135                                                 $filePath = $searchPath . '/' . $file;
3136                                                 if ($file != '.' && $file != '..' && is_file($filePath)
3137                                                         && strncmp($file, '_', 1) != 0){                // 「_」で始まる名前のファイルは読み込まない
3138                                                 
3139                                                         // スクリプトへのURLを作成
3140                                                         $scriptURL = $widgetsUrl . '/' . $rows[$i]['wd_id'] . '/' . M3_DIR_NAME_SCRIPTS . '/' . $file;
3141                                                         // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3142                                                         if (!$this->hasScriptCache) $scriptURL .= $this->getCacheParam();
3143                                                         $replaceStr .=  '<script type="text/javascript" src="' . $scriptURL . '"></script>' . M3_NL;
3144                                                 }
3145                                         }
3146                                         $dir->close();
3147                                 }
3148                         }
3149                         // ウィジェットからの追加のCSS読み込み
3150                         $count = count($this->headScriptFiles);
3151                         for ($i = 0; $i < $count; $i++){
3152                                 $scriptUrl = $this->headScriptFiles[$i];
3153                                 if ($isSslPage) $scriptUrl = str_replace('http://', 'https://', $scriptUrl);                    // SSL化が必要なときは変換
3154                 
3155                                 // スクリプトをキャッシュ保存しない場合は、パラメータを付加
3156                                 if (!$this->hasScriptCache) $scriptUrl .= $this->getCacheParam();
3157                                 $replaceStr .=  '<script type="text/javascript" src="' . $scriptUrl . '"></script>' . M3_NL;
3158                         }
3159                         
3160                         // 設定値取得
3161                         $openType = $this->gSystem->getSystemConfig(self::CF_CONFIG_WINDOW_OPEN_TYPE);// ウィジェット設定画面のウィンドウ表示タイプ(0=別ウィンドウ、1=タブ)
3162                         
3163                         // ##### ページへJavascriptの埋め込む #####
3164                         // JavaScriptグローバル変数の設定
3165                         //$replaceStr .= '<script type="text/javascript">' . M3_NL;
3166                         //$replaceStr .= '<!--' . M3_NL;
3167                         $replaceStr .= '<script type="text/javascript">' . M3_NL;
3168                         $replaceStr .= '//<![CDATA[' . M3_NL;
3169                         $replaceStr .= '// Magic3 Global values' . M3_NL;
3170                         $replaceStr .= 'var M3_ROOT_URL = "' . $rootUrl . '";' . M3_NL;         // システムルートURL
3171                         
3172                         if ($gEnvManager->isAdminDirAccess() && $gEnvManager->isSystemManageUser()){            // 管理画面へのアクセス、システム運用権限があり
3173                                 $pageId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);          // ページID
3174                                 $pageSubId = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);// ページサブID
3175                                         
3176                                 // 管理画面のオープン設定
3177                                 $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
3178                                 if ($openType != '') $replaceStr .= 'var M3_CONFIG_WINDOW_OPEN_TYPE = ' . $openType . ';' . M3_NL;
3179                                 
3180                                 // ページID、ページサブID
3181                                 $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
3182                                 $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
3183                                 // WYSIWYGエディター
3184                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
3185                                 
3186                                 // Googleマップライブラリの読み込み
3187                                 if ($this->useGooglemaps){
3188                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = true;' . M3_NL;
3189                                 } else {
3190                                         $replaceStr .= 'var M3_USE_GOOGLEMAPS = false;' . M3_NL;
3191                                 }
3192
3193                                 // ウィジェット詳細設定画面専用のJavaScriptグローバル変数
3194                                 if ($cmd == M3_REQUEST_CMD_CONFIG_WIDGET){
3195                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $this->configWidgetInfo['wd_device_type'] . ';' . M3_NL;                 // ウィジェット設定画面のウィジェットの端末タイプ
3196                                 } else if (!empty($pageId)){
3197                                         $accessPoint = $this->gEnv->getAllDefaultPageId();
3198                                         for ($i = 0; $i < count($accessPoint); $i++){
3199                                                 if ($pageId == $accessPoint[$i]){
3200                                                         $replaceStr .= 'var M3_CONFIG_WIDGET_DEVICE_TYPE = ' . $i . ';' . M3_NL;                        // ウィジェット設定画面のウィジェットの端末タイプ
3201                                                         break;
3202                                                 }
3203                                         }
3204                                 }
3205                                                 
3206                                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
3207                                         if (!empty($task)){             // 戻りタスクが設定されているときのみ最大化可能
3208                                                 $replaceStr .= 'function gobackPagedef(){' . M3_NL;
3209                                                 $replaceStr .= '    window.location.href = "' . $gEnvManager->getDefaultAdminUrl() . '?pageid=' . $pageId . '&pagesubid=' . $pageSubId . '&task=' . $task . '";' . M3_NL;
3210                                                 $replaceStr .= '}' . M3_NL;
3211                                                 $replaceStr .= '$(function(){' . M3_NL;
3212                                                 $replaceStr .= '    $(document).keyup(function(e){' . M3_NL;
3213                                                 $replaceStr .= '        if (e.which == 36) gobackPagedef();' . M3_NL;
3214                                                 $replaceStr .= '    });' . M3_NL;
3215                                                 $replaceStr .= '});' . M3_NL;
3216                                         }
3217                                 } else {
3218                                         // ##### 管理用テンプレートを使用している場合の処理 #####
3219                                         // Bootstrap用のスクリプト処理
3220                                         if ($this->useBootstrap){
3221                                                 $replaceStr .= '$(function(){' . M3_NL;
3222                                                 $replaceStr .= '    $(\'.button\').addClass(\'' . self::BOOTSTRAP_BUTTON_CLASS . '\');' . M3_NL;
3223                                                 $replaceStr .= '});' . M3_NL;
3224                                         }
3225                                 }
3226                         } else if ($this->isPageEditable){              // 一般画面ページ編集可能モードのとき
3227                                 $replaceStr .= 'var M3_DEFAULT_ADMIN_URL="' . $gEnvManager->getDefaultAdminUrl() . '";' . M3_NL;                // 管理機能URL
3228                                 if ($openType != '') $replaceStr .= 'var M3_CONFIG_WINDOW_OPEN_TYPE = ' . $openType . ';' . M3_NL;
3229                                 
3230                                 // ページID、ページサブID
3231                                 $replaceStr .= 'var M3_PAGE_ID = "' . $gEnvManager->getCurrentPageId() . '";' . M3_NL;
3232                                 $replaceStr .= 'var M3_PAGE_SUB_ID = "' . $gEnvManager->getCurrentPageSubId() . '";' . M3_NL;
3233                                 // WYSIWYGエディター
3234                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
3235                         } else if ($this->isEditMode){                  // 一般画面編集モード
3236                                 // WYSIWYGエディター
3237                                 $replaceStr .= 'var M3_WYSIWYG_EDITOR = "' . $this->wysiwygEditor . '";' . M3_NL;
3238                         }
3239                         
3240                         // ##### パネルメニュー(一般画面と管理画面の切り替え等)の表示 #####
3241                         // PC用、携帯用、スマートフォン用画面とウィジェット付きポジションの管理画面時に表示
3242                         if (($gEnvManager->isAdminDirAccess() && $cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET) ||           // 管理画面(ウィジェット付きポジション表示)のとき
3243                                 (!$gEnvManager->isAdminDirAccess() &&                                                   // 一般用画面のとき
3244                                         $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
3245                                         $cmd != M3_REQUEST_CMD_RSS)){                                                           // RSS配信でない
3246                                 //if ($gEnvManager->isSystemAdmin()){                           // 管理者権限がある場合のみ有効
3247                                 if ($gEnvManager->isSystemManageUser()){                // システム運用権限ありの場合
3248                                         // トップメニュー項目作成
3249                                         $linkStr = '';
3250                                         $adminTag = '';         // 管理画面ボタン
3251                                         $editTag = '';          // 編集ボタン
3252                                         $logoutTag = '';                // ログアウトボタン
3253                                         
3254                                         if ($gEnvManager->isAdminDirAccess()){          // 管理画面(ウィジェット付きポジション表示)の場合
3255                                                 // 編集ボタン
3256 /*                                              $titleStr = '編集終了';
3257                                                 $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
3258                                                 if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
3259                                                 $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
3260                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></li>';
3261                                                 */
3262                                                 $titleStr = '編集終了';
3263                                                 $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
3264                                                 if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
3265                                                 $editTag = '<div class="m3editend"><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
3266                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_END_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></div>';
3267                                                 $linkStr .= $editTag;
3268                                                 
3269                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
3270                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").prepend(\'' . $linkStr . '\');' . M3_NL;               // appendでうまく表示できないのでprependで表示
3271                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
3272                                         } else if ($this->isAccessPointWithAdminMenu){          // 通常画面は、管理メニューを使用するアクセスポイントの場合のみ表示
3273                                                 // 管理画面ボタン
3274                                                 $titleStr = '管理画面';
3275                                                 $linkUrl = $gEnvManager->getDefaultAdminUrl();
3276                                                 $adminTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
3277                                                 $adminTag .= '<img src="' . $rootUrl . self::ADMIN_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></li>';
3278                                         
3279                                                 // 編集ボタン
3280                                                 $titleStr = '編集';
3281                                                 $linkUrl  = $gEnvManager->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' .M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET;
3282                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_ID . '=' . $gEnvManager->getCurrentPageId();
3283                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_DEF_PAGE_SUB_ID . '=' . $gEnvManager->getCurrentPageSubId();
3284                                                 $linkUrl .= '&' . M3_REQUEST_PARAM_BACKUP_URL . '=' . urlencode($gEnvManager->getCurrentRequestUri());                  // URL退避用
3285                                                 $editTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
3286                                                 $editTag .= '<img src="' . $rootUrl . self::EDIT_PAGE_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></li>';
3287                                                 
3288                                                 // ログアウトボタン
3289                                                 $titleStr = 'ログアウト';
3290 //                                              if ($gEnvManager->isAdminDirAccess()){          // 管理画面の場合
3291 //                                                      $linkUrl = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_BACKUP_URL);          // 退避していたURLを取得
3292 //                                                      if (empty($linkUrl)) $linkUrl = $gEnvManager->getDefaultUrl();
3293 //                                              } else {
3294                                                         $linkUrl = $gEnvManager->getCurrentRequestUri();
3295 //                                              }
3296                                                 $linkUrl = createUrl($linkUrl, M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_LOGOUT);
3297                                                 $logoutTag = '<li><a href="' . convertUrlToHtmlEntity($linkUrl) . '">';
3298                                                 $logoutTag .= '<img src="' . $rootUrl . self::LOGOUT_ICON_FILE . '" alt="' . $titleStr . '" title="' . $titleStr . '" /></a></li>';
3299                                         
3300                                                 $linkStr .= '<div id="m3slidepanel">';
3301                                                 $linkStr .= '<div class="m3panelopener m3topleft"><a href="#"><i class="glyphicon glyphicon-align-justify"></i></a></div>';
3302                                                 $linkStr .= '<div style="top:-60px; visibility: visible;" class="m3panel_top m3-navbar-default">';
3303                                                 $linkStr .= '<div tabindex="0" class="m3panel_wrap">';
3304                                                 $linkStr .= '<ul class="m3-nav m3-navbar-nav">';
3305                                                 if ($gEnvManager->isSystemAdmin()){                             // 管理画面、編集モードは、管理者権限がある場合のみ有効
3306                                                         $linkStr .= $adminTag;
3307                                                         $linkStr .= $editTag;
3308                                                 }
3309                                                 $linkStr .= $logoutTag;
3310                                                 $linkStr .= '</ul>';
3311                                                 $linkStr .= '</div>';
3312                                                 $linkStr .= '</div>';
3313                                                 $linkStr .= '</div>';
3314
3315                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . 'if (window.parent && window.parent.frames.length == 0){' . M3_NL;// インラインフレームでないときパネルメニューを表示
3316                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").append(\'' . $linkStr . '\');' . M3_NL;
3317                                                 //$this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("#m3slidemenubarpanel").m3SlideMenubar();' . M3_NL;
3318                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(".m3panel_top").m3slidepanel({ "position": "top", "type": "push" });' . M3_NL;
3319                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$("body").css("position", "relative");' . M3_NL;
3320                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 1) . '}' . M3_NL;
3321                                         }
3322                                 }
3323                         }
3324                         // 一般画面からのウィジェット操作用ツールバー
3325                         if (!$gEnvManager->isAdminDirAccess() && 
3326                                 $cmd != M3_REQUEST_CMD_DO_WIDGET &&                                                     // ウィジェット単体実行でない
3327                                 $cmd != M3_REQUEST_CMD_RSS){                                                            // RSS配信でない
3328                                 if ($gEnvManager->isSystemManageUser()){                // 一般用画面で管理者権限がある場合のみ有効
3329                                         // 管理用ツールバー
3330                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').each(function(){' . M3_NL;
3331                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var attrs = m3_splitAttr($(this).attr(\'m3\'));' . M3_NL;
3332                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var widgetId = attrs[\'widgetid\'];' . M3_NL;
3333                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var serialNo = attrs[\'serial\'];' . M3_NL;
3334                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var configId = attrs[\'configid\'];' . M3_NL;
3335                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var useconfig = attrs[\'useconfig\'];' . M3_NL;
3336                                         
3337                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var html = \'\';' . M3_NL;
3338                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (useconfig == 1){' . M3_NL;
3339                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
3340                                                                                 'html += \'<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\\\'\' + widgetId + \'\\\', \' + configId + \', \' + serialNo + \');return false;" >' .
3341                                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON32_FILE . '" alt="ウィジェット設定" title="ウィジェット設定" width="32" height="32" /></a>\';' . M3_NL;
3342                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
3343                                         if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
3344                                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 
3345                                                                                         'html += \'<a href="javascript:void(0);" onclick="m3ShowAdjustWindow(\' + configId + \', \' + serialNo + \', M3_PAGE_ID, M3_PAGE_SUB_ID);return false;" >' .
3346                                                                                         '<img src="' . $rootUrl . self::ADJUST_ICON32_FILE . '" alt="タイトル・位置調整" title="タイトル・位置調整" width="32" height="32" /></a>\';' . M3_NL;
3347                                         }
3348                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'if (html != \'\'){' . M3_NL;
3349                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 
3350                                                                                         'html = \'<div class="m3tooltip" style="display:none;">\' + html + \'<a class="m3closebox" href="javascript:void(0);">' . 
3351                                                                                         '<img src="' . $rootUrl . self::CLOSE_BOX_ICON32_FILE . '" alt="閉じる" title="閉じる" width="11" height="11" /></a></div>\';' . M3_NL;
3352                                                                                         
3353                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).append(html);' . M3_NL;
3354                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
3355                                         // クリックイベントの設定
3356                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).click(function(){' . M3_NL;
3357                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
3358                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (tooltipObj.css(\'display\') == \'none\'){' . M3_NL;
3359                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.show();' . M3_NL;
3360                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '} else {' . M3_NL;
3361                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'tooltipObj.hide();' . M3_NL;
3362                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
3363                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
3364                                         // ウィジェットボーダーハイライト、ツールチップ表示
3365                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).hover(function(){' . M3_NL;
3366                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).addClass(\'m3_widget_highlight\');' . M3_NL;
3367                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
3368                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var pos = $(this).position();' . M3_NL;
3369                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var width = $(this).outerWidth();' . M3_NL;
3370                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipWidth = tooltipObj.outerWidth(true);' . M3_NL;
3371                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var x = pos.left + width - tooltipWidth;' . M3_NL;
3372                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var y = pos.top;' . M3_NL;
3373                                 $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'tooltipObj.css({position: "absolute",top: y + "px", left: x + "px"}).show();' . M3_NL;
3374                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}, function(){' . M3_NL;
3375                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).removeClass(\'m3_widget_highlight\');' . M3_NL;
3376                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var tooltipObj = $(this).children(\'.m3tooltip\');' . M3_NL;
3377                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'tooltipObj.hide();' . M3_NL;
3378                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
3379                                         // 閉じるボタン処理
3380                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3closebox\').click(function(event){' . M3_NL;
3381                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).children(\'.m3tooltip\').hide();' . M3_NL;
3382                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
3383                                         // コンテンツ編集ボタンの位置修正
3384                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var pos = $(this).position();' . M3_NL;
3385                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var offset = $(this).offset();' . M3_NL;
3386                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'var width = $(this).outerWidth();' . M3_NL;
3387                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '$(this).find(\'.m3edittool\').each(function(){' . M3_NL;
3388                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).offset({left: offset.left});' . M3_NL;
3389                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '$(this).width(width);' . M3_NL;
3390                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '});' . M3_NL;
3391                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
3392                                         
3393                                         // コンテキストメニューを作成
3394                                         $this->initScript .= M3_INDENT_SPACE . 'var widgetWindow = \'<div class="m3_contextmenu" id="m3_widgetmenu" style="visibility:hidden;">\';' . M3_NL;
3395                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'<ul>\';' . M3_NL;
3396                                         if ($gEnvManager->isSystemAdmin()){             // 位置調整は管理者権限がある場合のみ有効(管理ウィジェットの機能のため)
3397                                                 $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;
3398                                         }
3399                                         $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;
3400                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</ul>\';' . M3_NL;
3401                                         $this->initScript .= M3_INDENT_SPACE . 'widgetWindow += \'</div>\';' . M3_NL;
3402                                         $this->initScript .= M3_INDENT_SPACE . '$("body").append(widgetWindow);' . M3_NL;
3403                                         $this->initScript .= M3_INDENT_SPACE . '$(\'div.m3_widget\').contextMenu(\'m3_widgetmenu\', {' . M3_NL;
3404                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'menuStyle: {' . M3_NL;
3405                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// border : "2px solid green",' . M3_NL;
3406                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'backgroundColor: \'#FFFFFF\',' . M3_NL;
3407                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'width: "150px",' . M3_NL;
3408                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'textAlign: \'left\',' . M3_NL;
3409                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'font: \'12px/1.5 Arial, sans-serif\'' . M3_NL;
3410                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
3411                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'itemStyle: {' . M3_NL;
3412                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'padding: \'3px 3px\'' . M3_NL;
3413                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
3414                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'bindings: {' . M3_NL;
3415                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wconfig\': function(t){' . M3_NL;
3416                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
3417                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
3418                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'alert("このウィジェットには設定画面がありません");' . M3_NL;
3419                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 5) . 'return;' . M3_NL;
3420                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '}' . M3_NL;
3421                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowConfigWindow(attrs[\'widgetid\'], attrs[\'configid\'], attrs[\'serial\']);' . M3_NL;
3422                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '},' . M3_NL;
3423                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '\'m3_wadjust\': function(t){' . M3_NL;
3424                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'var attrs = m3_splitAttr($(\'#\' + t.id).attr(\'m3\'));' . M3_NL;
3425                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . 'm3ShowAdjustWindow(attrs[\'configid\'], attrs[\'serial\'], M3_PAGE_ID, M3_PAGE_SUB_ID);' . M3_NL;
3426                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
3427                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
3428                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onContextMenu: function(e){' . M3_NL;
3429                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'return true;' . M3_NL;
3430                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '},' . M3_NL;
3431                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . 'onShowMenu: function(e, menu){' . M3_NL;
3432                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '// メニュー項目の変更' . M3_NL;
3433                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'var attrs = m3_splitAttr($(e.target).parents(\'dl\').attr(\'m3\'));' . M3_NL;
3434                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'if (attrs[\'useconfig\'] == \'0\'){' . M3_NL;
3435                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 4) . '$(\'#m3_wconfig\', menu).remove();' . M3_NL;
3436                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . '}' . M3_NL;
3437                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 3) . 'return menu;' . M3_NL;
3438                                         $this->initScript .= str_repeat(M3_INDENT_SPACE, 2) . '}' . M3_NL;
3439                                         $this->initScript .= M3_INDENT_SPACE . '});' . M3_NL;
3440                                 }
3441                         }
3442                         // ポップアップメッセージがある場合は表示
3443                         if (!empty($this->popupMsg)){
3444                                 $replaceStr .=  'alert("' . $this->popupMsg . '");' . M3_NL;
3445                         }
3446                         // テンプレートに応じた処理
3447                         if ($cleanType == 1){
3448                                 // HTMLのクリーン処理が必要なときはコードを埋め込む
3449                                 $this->initScript .= '    $(\'.PostHeaderIcons\').remove();' . M3_NL;// 不要なアイコン表示タグの削除
3450                                 $this->initScript .= '    $(\'.PostMetadataHeader\').each(function(i){' . M3_NL;
3451                                 $this->initScript .= '        if ($(this).text().trim() == \'\') $(this).remove();' . M3_NL;
3452                                 $this->initScript .= '    });' . M3_NL;
3453                         }
3454                         // 初期処理用スクリプト埋め込み
3455                         if (!empty($this->initScript)){
3456                                 $replaceStr .= '$(function(){' . M3_NL;
3457                                 $replaceStr .= $this->initScript;
3458                                 $replaceStr .= '});' . M3_NL;
3459                         }
3460                         
3461                         //$replaceStr .= '// -->' . M3_NL;
3462                         //$replaceStr .= '</script>' . M3_NL;
3463                         $replaceStr .= '//]]>' . M3_NL;
3464                         $replaceStr .= '</script>' . M3_NL;
3465
3466                         // HEADタグに埋め込むCSS,JavaScript,任意文字列
3467                         if (count($this->headCss) > 0){
3468                                 // CSSの場合は全体をstyleタグで囲む
3469                                 $replaceStr .= '<style type="text/css">' . M3_NL;
3470                                 $replaceStr .= '<!--' . M3_NL;
3471                                 for ($i = 0; $i < count($this->headCss); $i++){
3472                                         $replaceStr .= $this->headCss[$i];
3473                                 }
3474                                 $replaceStr .= M3_NL . '//-->' . M3_NL;
3475                                 $replaceStr .= '</style>' . M3_NL;
3476                         }
3477                         if (count($this->headScript) > 0){
3478                                 // JavaScriptの場合は全体をscriptタグで囲む
3479                                 //$replaceStr .= '<script type="text/javascript">' . M3_NL;
3480                                 //$replaceStr .= '<!--' . M3_NL;
3481                                 $replaceStr .= '<script type="text/javascript">' . M3_NL;
3482                                 $replaceStr .= '//<![CDATA[' . M3_NL;
3483                                 for ($i = 0; $i < count($this->headScript); $i++){
3484                                         $replaceStr .= $this->headScript[$i];
3485                                 }
3486                                 //$replaceStr .= M3_NL . '//-->' . M3_NL;
3487                                 //$replaceStr .= '</script>' . M3_NL;
3488                                 $replaceStr .= M3_NL;
3489                                 $replaceStr .= '//]]>' . M3_NL;
3490                                 $replaceStr .= '</script>' . M3_NL;
3491                         }
3492                         if (count($this->headString) > 0){
3493                                 // 任意文字列の場合はそのまま追加
3494                                 for ($i = 0; $i < count($this->headString); $i++){
3495                                         $replaceStr .= $this->headString[$i];
3496                                 }
3497                         }
3498                 }
3499                 return $replaceStr;
3500         }
3501         /**
3502          * 各部品のHTML出力
3503          *
3504          * @param string $position                      HTMLテンプレート上の書き出し位置
3505          * @param string $style                         ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
3506          * @param int    $templateVer           テンプレートバージョン(0=デフォルト(Joomla!v1.0)、-1=携帯用、1=Joomla!v1.5、2=Joomla!v2.5)
3507          * @param array  $attr                          その他属性
3508          * @return string                                       出力コンテンツ
3509          */
3510         function getContents($position, $style = '', $templateVer = 0, $attr = array())
3511         {
3512                 static $render;         // Joomla!v1.5テンプレート用
3513                 global $gRequestManager;
3514                 global $gEnvManager;
3515                 
3516                 // ファイル名、ページ名を取得
3517                 $filename       = $gEnvManager->getCurrentPageId();
3518                 $subId          = $gEnvManager->getCurrentPageSubId();
3519                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
3520
3521                 // ポジション名表示モードに応じて出力を作成
3522                 $contents = '';         // 出力コンテンツ
3523                 switch ($this->showPositionMode){
3524                         case 0:         // 通常画面
3525                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
3526                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
3527                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
3528                                         if ($ret){      // 1行以上データが取得できたとき
3529                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
3530                                                 $this->pageDefPosition = $position;
3531                                         } else {
3532                                                 $this->pageDefRows = array();
3533                                                 $this->pageDefPosition = '';
3534                                         }
3535                                 }
3536                                 // ウィジェットを実行
3537                                 $count = count($this->pageDefRows);
3538                                 
3539                                 if ($templateVer == 0){                 // echo出力のとき(Joomla!v1.0テンプレートの場合)
3540                                         ob_start();// バッファ作成
3541
3542                                         // ウィジェットヘッダ(Joomla!1.0用)を出力するテンプレートかどうかチェック
3543                                         $widgetHeaderType = $this->getTemplateWidgetHeaderType();
3544                                         for ($i = 0; $i < $count; $i++){
3545                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
3546                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
3547                                                 
3548                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
3549                                                 // キャッシュデータがあるときはキャッシュデータを使用
3550                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
3551
3552                                                 if (empty($cacheData)){         // キャッシュデータがないとき
3553                                                         ob_clean();
3554                                                         $ret = $this->pageDefLoop($i, $this->pageDefRows[$i], $style, $titleTag, $widgetHeaderType);
3555                                                         if (!$ret) break;
3556                                                         $widgetContent = ob_get_contents();
3557                                                         
3558                                                         // ウィジェット共通のコンテンツ処理
3559                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
3560
3561                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
3562                                                         $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
3563                                                                                 
3564                                                         // キャッシュデータを設定
3565                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
3566                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
3567                                                                                                                         
3568                                                         // ウィジェットの外枠タグを設定
3569                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
3570                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
3571                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
3572                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;          // ポジションブロッククラス
3573                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
3574                                                         if ($this->isPageEditable){             // 一般画面ページ編集可能モードのとき
3575                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
3576                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
3577                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
3578                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
3579                                                                 $shared = '0';          // 共通属性があるかどうか
3580                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
3581                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
3582                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
3583                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget" rel="#m3editwidget" ' . $m3Option . '>' . $widgetContent . '</div>';
3584                                                         }
3585                                                 } else {                // キャッシュデータがあるとき
3586                                                         $widgetContent = $cacheData;
3587                                                         
3588                                                         // HTMLのメタタグを設定
3589                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
3590                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
3591                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
3592                                                 }
3593                                                 $contents .= $widgetContent;
3594                                         }
3595                                         ob_end_clean();         // バッファ破棄
3596                                         
3597                                         if ($i < $count) return '';// 処理中断のときは終了
3598                                 } else {                        // Joomla!v1.5テンプレートの場合
3599                                         for ($i = 0; $i < $count; $i++){
3600                                                 $pageDefParam = $this->pageDefRows[$i];                 // 画面定義パラメータ
3601                                                 $widgetId = $this->pageDefRows[$i]['wd_id'];
3602                                                                                                                 
3603                                                 // ### 遅延実行ウィジェットはキャッシュしない ###
3604                                                 // キャッシュデータがあるときはキャッシュデータを使用
3605                                                 $cacheData = $this->gCache->getWidgetCache($request, $this->pageDefRows[$i], $metaTitle, $metaDesc, $metaKeyword);
3606                                                         
3607                                                 if (empty($cacheData)){         // キャッシュデータがないとき
3608                                                         // ウィジェットのタイトルを初期化
3609                                                         $gEnvManager->setCurrentWidgetTitle('');
3610                                                 
3611                                                         // Joomla用のパラメータを初期化
3612                                                         $gEnvManager->setCurrentWidgetJoomlaParam(array());
3613                                                         
3614                                                         ob_clean();
3615                                                         $ret = $this->pageDefLoop($i, $this->pageDefRows[$i], $style, $titleTag, false);
3616                                                         $widgetContent = ob_get_contents();
3617
3618                                                         $trimContent = trim($widgetContent);
3619                                                         if (!empty($trimContent)){              // 出力が空でない場合
3620                                                                 $isRendered = false;            // Joomla!の描画処理を行ったかどうか
3621                                                                 if (!empty($this->pageDefRows[$i]['pd_use_render'])){                   // Joomla!の描画処理を使用する場合
3622                                                                         // Joomla!ウィジェットの出力に埋め込む
3623                                                                         if (strcasecmp($style, 'none') != 0){
3624                                                                                 // オブジェクト作成
3625                                                                                 if (!isset($render)) $render = new JRender();
3626                                                                 
3627                                                                                 // デフォルトのウィジェットタイトル取得
3628                                                                                 $defaultTitle = $gEnvManager->getCurrentWidgetTitle();
3629                                                                 
3630                                                                                 // Joomla用のパラメータを取得
3631                                                                                 $joomlaParam = $gEnvManager->getCurrentWidgetJoomlaParam();
3632
3633                                                                                 // 遅延ウィジェットのときはタイトルタグを埋め込む
3634                                                                                 if (!empty($titleTag)) $defaultTitle = $titleTag;
3635                                                                 
3636                                                                                 // タイトルが空でタイトル表示を行う場合は、デフォルトタイトルを使用
3637                                                                                 $title = $this->pageDefRows[$i]['pd_title'];
3638                                                                                 if ($this->pageDefRows[$i]['pd_title_visible']){                // タイトル表示のとき
3639                                                                                         if (empty($title)) $title = $defaultTitle;
3640                                                                                 } else {
3641                                                                                         $title = '';                    // タイトルは非表示
3642                                                                                 }
3643                                                                         
3644                                                                                 // Joomla用パラメータ作成
3645                                                                                 $params = array();                              // ウィジェットごとの属性
3646                                                                                 $widgetType = $this->pageDefRows[$i]['wd_type'];                // ウィジェットタイプ
3647                                                                                 
3648                                                                                 // オプションのJoomlaクラス(縦型メニュー(art-vmenu)等)
3649                                                                                 $joomlaClass = $this->pageDefRows[$i]['wd_joomla_class'];               // 「wd_joomla_class」は使っていない?
3650                                                                                 if (!empty($joomlaClass)) $params['moduleclass_sfx'] = $joomlaClass;
3651                                                                                 if (isset($joomlaParam['moduleclass_sfx'])) $params['moduleclass_sfx'] = $joomlaParam['moduleclass_sfx'];// ウィジェットでjoomla用パラメータの設定があるとき
3652                                                                 
3653                                                                                 if (strcmp($position, 'main') == 0){// メイン部のとき
3654                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
3655                                                                                         // ウィジェットの内枠はレンダーで設定
3656                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
3657                                                                 
3658                                                                                         $widgetContent = $render->getComponentContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
3659                                                                                 } else if (strStartsWith($position, 'user') ||                          // ナビゲーションメニュー位置の場合
3660                                                                                                 strcasecmp($position, 'position-1') == 0){                              // Joomla!v2.5テンプレート対応
3661                                                                                         $moduleContent = '';
3662                                                                                         if ($style == self::WIDGET_STYLE_NAVMENU){              // ナビゲーションバーメニューはメニュータイプのウィジェットのみ実行
3663                                                                                                 if ($widgetType == 'menu') $moduleContent = $render->getNavMenuContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
3664                                                                         
3665                                                                                                 // ナビゲーションバータイプで作成できないときはデフォルトの出力を取得
3666                                                                                                 if (empty($moduleContent)) $moduleContent = $render->getModuleContents('xhtml', $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
3667                                                                                         } else {
3668                                                                                                 $moduleContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
3669                                                                                         }
3670                                                                                         $widgetContent = $moduleContent;
3671                                                                                         
3672                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定。メニュー処理後に付加。
3673                                                                                         // ウィジェットの内枠はレンダーで設定
3674                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
3675                                                                                 } else {                // その他の位置のとき
3676                                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
3677                                                                                         // ウィジェットの内枠はレンダーで設定
3678                                                                                         //$widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
3679                                                                                         
3680                                                                                         $widgetContent = $render->getModuleContents($style, $widgetContent, $title, $attr, $params, $pageDefParam, $templateVer);
3681                                                                                 }
3682                                                                                 $isRendered = true;             // Joomla!の描画処理を行ったかどうか
3683                                                                         }
3684                                                                 }
3685                                                                 if (!$isRendered){              // Joomla!の描画処理を行っていない場合
3686                                                                         // ウィジェット共通のコンテンツ処理
3687                                                                         $widgetContent = $this->_addOptionContent($widgetContent, $pageDefParam);
3688                                                                         
3689                                                                         // ウィジェットの内枠(コンテンツ外枠)を設定
3690                                                                         $widgetContent = '<div class="' . self::WIDGET_INNER_CLASS . '">' . $widgetContent . '</div>';
3691                                                                 }
3692                                                         }
3693                                                         if (!$ret) return '';           // 処理中断のときは終了
3694                                                         
3695                                                         // キャッシュデータを設定
3696                                                         $this->gCache->setWidgetCache($gRequestManager, $this->pageDefRows[$i], $widgetContent,
3697                                                                                                                         $this->lastHeadTitle, $this->lastHeadDescription, $this->lastHeadKeywords);
3698                                                                                                                         
3699                                                         // ウィジェットの外枠タグを設定
3700                                                         $widgetClassSuffix = $this->pageDefRows[$i]['pd_suffix'];               // 追加CSSクラスサフィックス
3701                                                         $widgetOuterClass = self::WIDGET_OUTER_CLASS . ' ' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . str_replace('/', '_', $widgetId);// ウィジェットの外枠のクラス
3702                                                         if (!empty($widgetClassSuffix)) $widgetOuterClass .= ' ' . $widgetOuterClass . '_' . $widgetClassSuffix;        // 追加CSSクラス
3703                                                         $widgetOuterClass .= ' ' . self::WIDGET_OUTER_CLASS_HEAD_POSITION . $position;  // ポジションブロッククラス
3704                                                         $widgetContent = '<div class="' . $widgetOuterClass . '">' . $widgetContent . '</div>';
3705                                                         if ($this->isPageEditable){             // 一般画面ページ編集可能モードのとき
3706                                                                 //$editInfo = 'widgetid:' . $this->pageDefRows[$i]['wd_id'];
3707                                                                 $configId = $this->pageDefRows[$i]['pd_config_id'];             // 定義ID
3708                                                                 $serial = $this->pageDefRows[$i]['pd_serial'];          // シリアル番号
3709                                                                 $hasAdmin = '0';                // 管理画面があるかどうか
3710                                                                 if ($this->pageDefRows[$i]['wd_has_admin']) $hasAdmin = '1';
3711                                                                 $shared = '0';          // 共通属性があるかどうか
3712                                                                 if (empty($this->pageDefRows[$i]['pd_sub_id'])) $shared = '1';  // 共通ウィジェットのとき
3713                                                                 $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
3714                                                                 $widgetTag = self::WIDGET_TAG_HEAD . $position . '_' . $i;                              // ウィジェット識別用ユニークタグ
3715                                                                 $widgetContent = '<div id="' . $widgetTag . '" class="m3_widget" rel="#m3editwidget" ' . $m3Option . '>' . $widgetContent . '</div>';
3716                                                         }
3717                                                 } else {                // キャッシュデータがあるとき
3718                                                         $widgetContent = $cacheData;
3719                                                         
3720                                                         // HTMLのメタタグを設定
3721                                                         if (!empty($metaTitle)) $this->setHeadSubTitle($metaTitle);
3722                                                         if (!empty($metaDesc)) $this->setHeadDescription($metaDesc);
3723                                                         if (!empty($metaKeyword)) $this->setHeadKeywords($metaKeyword);
3724                                                 }
3725                                                 $contents .= $widgetContent;
3726                                         }
3727                                 }
3728                         
3729                                 if ($position == 'main'){               // メイン部のときは、メッセージを出力
3730                                         /*if (strlen($this->popupMsg) > 0){
3731                                                 echo "\n<script language=\"javascript\">alert('" . addslashes($this->popupMsg) . "');</script>";
3732                                         }*/
3733                                 } else if ($position == 'debug'){               // デバッグ文出力
3734                                 } else {
3735
3736                                 }
3737                                 break;
3738                         case 1:         // ポジション表示
3739                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:3px solid #f00;color:#700;">ポジション名: ';
3740                                 $contents .= '<b>' . $position . '</b>';
3741                                 $contents .= '</div>';
3742                                 break;
3743                         case 2:         // ポジション表示(ウィジェット付き)
3744                                 $rev = '555';                   // データのリビジョン番号
3745                                 // ポジションのHTMLタグIDを作成
3746                                 $num = 0;
3747                                 $posId = '';
3748                                 for ($i = 0; $i < 100; $i++){
3749                                         $posId = $position . '_' . $num;
3750                                         $viewPosId = self::POSITION_TAG_HEAD . $posId;
3751                                         if (!in_array($viewPosId, $this->viewPosId)) break;
3752                                         $num++;
3753                                 }
3754                                 $this->viewPosId[] = $viewPosId;// IDを保存
3755                                 
3756                                 // ページ定義を取得。同じポジションが続く場合は最初の一度だけ定義を取得
3757                                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // ポジションが異なる場合
3758                                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows);
3759                                         if ($ret){      // 1行以上データが取得できたとき
3760                                                 $this->pageDefRows = $rows;                     // ページ定義レコード
3761                                                 $this->pageDefPosition = $position;
3762                                         } else {
3763                                                 $this->pageDefRows = array();
3764                                                 $this->pageDefPosition = '';
3765                                         }
3766                                 }
3767                                 $posHead = '';
3768                                 if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;                // 特殊ポジションブロックのアイコン付加
3769                                 $contents .= '<div id="' . $viewPosId . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;             // リビジョン番号を付加
3770                                 $contents .= '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
3771                                 
3772                                 // ウィジェットイメージを表示
3773                                 $widgetTagHead = self::WIDGET_TAG_HEAD . $posId;
3774                                 $contents .= $this->getWidgetList($gEnvManager->getCurrentPageId(), $gEnvManager->getCurrentPageSubId(), $widgetTagHead, $this->pageDefRows);
3775
3776                                 $contents .= '</div>' . M3_NL;
3777                                 break;
3778                         default:
3779                                 $contents .= '<div style="background-color:#eee;margin:2px;padding:10px;border:1px solid #f00;color:#700;">param error</div>';
3780                                 break;
3781                 }
3782                 // ポジションを保存
3783                 $this->viewPositions[] = $position;
3784                 
3785                 return $contents;
3786         }
3787         /**
3788          * ウィジェット共通のコンテンツ追加処理
3789          *
3790          * @param string $src                           ウィジェット出力
3791          * @param array $pageDefParam           画面定義レコード
3792          * @return string                                       コンテンツを付加したウィジェット出力
3793          */
3794         function _addOptionContent($src, $pageDefParam)
3795         {
3796                 // 前後コンテンツ追加
3797                 $dest = $pageDefParam['pd_top_content'] . $src . $pageDefParam['pd_bottom_content'];
3798                 
3799                 // 「もっと読む」ボタンを追加
3800                 if ($pageDefParam['pd_show_readmore']){
3801                         $title = $pageDefParam['pd_readmore_title'];
3802                         if (empty($title)) $title = self::DEFAULT_READMORE_TITLE;
3803                         $dest .= '<div><a href="' . convertUrlToHtmlEntity($pageDefParam['pd_readmore_url']) . '">' . convertToHtmlEntity($title) . '</a></div>';
3804                 }
3805                 return $dest;
3806         }
3807         /**
3808          * BODYタグに付加するスタイルを取得(管理画面用)
3809          *
3810          * @param string                CSS文字列
3811          */
3812         function getBodyStyle()
3813         {
3814                 // 画面透過モードのときスタイルを追加
3815                 $transCss = '';
3816                 if ($this->isTransparentMode) $transCss = ' style="background-color:transparent;"';
3817                 return $transCss;
3818         }
3819         /**
3820          * 各部品のHTML出力
3821          *
3822          * @param string $position              HTMLテンプレート上の書き出し位置
3823          * @return int                                  コンテンツの数
3824          */
3825         function getWidgetsCount($position)
3826         {
3827                 global $gRequestManager;
3828                 global $gEnvManager;
3829
3830                 // 実行コマンドを取得
3831                 $cmd = $gRequestManager->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
3832                 if ($cmd == M3_REQUEST_CMD_SHOW_POSITION_WITH_WIDGET){          // ウィジェット付きポジション表示
3833                         return 1;               // ウィジェットが設定されていないポジション名を表示するために固定で値を返す
3834                 }
3835                 
3836                 // 単一ポジション以外の設定のときは固定で返す(or等)
3837                 $pos = strpos($position, ' ');
3838                 if ($pos !== false) return 1;
3839                 
3840                 // ファイル名、ページ名を取得
3841                 $filename       = $gEnvManager->getCurrentPageId();
3842                 $subId          = $gEnvManager->getCurrentPageSubId();
3843                 if (empty($subId)) $subId = $gEnvManager->getDefaultPageSubId();
3844
3845                 // 取得しようとするページ定義のポジションが既に取得しているポジションと異なるときはデータを取得
3846                 if (empty($this->pageDefPosition) || $position != $this->pageDefPosition){              // 現在取得しているページ定義のポジション
3847                         $ret = $this->db->getPageDef($filename, $subId, $position, $rows, 0/*定義セットIdデフォルト*/, true/*表示ウィジェットのみ*/);
3848                         if ($ret){      // 1行以上データが取得できたとき
3849                                 $this->pageDefRows = $rows;                     // ページ定義レコード
3850                                 $this->pageDefPosition = $position;
3851                         } else {
3852                                 $this->pageDefRows = array();
3853                                 $this->pageDefPosition = '';
3854                         }
3855                 }
3856                 return count($this->pageDefRows);
3857         }
3858         /**
3859          * ウィジェット情報取得
3860          *
3861          * 画面作成機能でウィジェット情報を取得するためのAjaxインターフェイス
3862          *
3863          * @param RequestManager $request               HTTPリクエスト処理クラス
3864          */
3865         function getWidgetInfoByAjax($request)
3866         {
3867                 global $gEnvManager;
3868                 global $gDesignManager;
3869                 global $gCacheManager;
3870                 
3871                 // アクセスするページIDからPC用、携帯用、スマートフォン用かを判断
3872                 $widgetDeviceType = 0;          // 端末タイプをPC用に初期化
3873                 $pageId         = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_ID);
3874                 $pageSubId      = $request->trimValueOf(M3_REQUEST_PARAM_DEF_PAGE_SUB_ID);
3875                 $mobilePageIdPrefix = M3_DIR_NAME_MOBILE . '_';
3876                 $smartphonePageIdPrefix = M3_DIR_NAME_SMARTPHONE . '_';
3877                 if (strncmp($pageId, $mobilePageIdPrefix, strlen($mobilePageIdPrefix)) == 0){
3878                         $widgetDeviceType = 1;          // 携帯用
3879                 } else if (strncmp($pageId, $smartphonePageIdPrefix, strlen($smartphonePageIdPrefix)) == 0){
3880                         $widgetDeviceType = 2;          // スマートフォン用
3881                 }
3882
3883                 $task = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_TASK);
3884                 if ($task == 'list'){
3885                         // ウィジェット一覧を取得
3886                         $ret = $this->db->getAvailableWidgetList($widgetDeviceType, $rows);
3887                         if ($ret){
3888                                 $currentCategoryId = '_none';           // 現在のウィジェットカテゴリー初期化
3889                                 for ($i = 0; $i < count($rows); $i++){
3890                                         $widgetId = $rows[$i]['wd_id'];
3891                                         $desc = $rows[$i]['wd_description'];
3892                                         $widgetTag = self::WIDGET_TYPE_TAG_HEAD . $widgetId;
3893                                         $categoryId = $rows[$i]['wd_category_id'];
3894                                         
3895                                         // カテゴリーの開始タグを追加
3896                                         if ($categoryId != $currentCategoryId){
3897                                                 if ($i > 0){
3898                                                         echo '</dd>' . M3_NL;
3899                                                         echo '</dl>' . M3_NL;
3900                                                 }
3901                                                 echo '<dl class="m3accordion">' . M3_NL;
3902                                                 echo '<dt>' . $rows[$i]['wt_name'] . '</dt>' . M3_NL;
3903                                                 echo '<dd>' . M3_NL;
3904                                                 
3905                                                 // 現在のカテゴリー更新
3906                                                 $currentCategoryId = $categoryId;
3907                                         }
3908                                         
3909                                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
3910                                         if ($gEnvManager->getUseSslAdmin()){
3911                                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
3912                                                 $image = $gEnvManager->getSslUrl($image);
3913                                         }
3914                                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
3915                                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
3916                                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
3917                                         $imageTag .= ' />';
3918                                         
3919                                         // ウィジェット機能マーク
3920                                         $widgetMark = '';
3921                                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メインウィジェット
3922                                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
3923
3924                                         // ウィジェット機能一覧
3925                                         $functionMark = '';
3926                                         if (!empty($rows[$i]['wd_template_type'])){             // 対応テンプレートタイプ
3927                                                 $templateTypeArray = explode(',', $rows[$i]['wd_template_type']);
3928                                                 if (in_array('bootstrap', $templateTypeArray)) $functionMark .= self::WIDGET_FUNCTION_MARK_BOOTSTRAP;           // Bootstrap型テンプレート対応
3929                                         }
3930                         
3931                                         echo '<dl class="m3_widgetlist_item" id="' . $widgetTag . '">' . M3_NL;
3932                                         echo '<dt>' . $widgetMark . $rows[$i]['wd_name'] . '</dt>' . M3_NL;                     // ウィジェット名
3933                                         echo '<dd><table width="100%"><tr valign="top"><td width="35">' . $imageTag . '</td><td>' . $desc . '</td></tr></table>';
3934                                         echo $functionMark . '</dd>' . M3_NL;
3935                                         echo '</dl>' . M3_NL;
3936                                         
3937                                         // カテゴリーの終了タグを追加
3938                                         if ($i == count($rows) - 1){
3939                                                 echo '</dd>' . M3_NL;
3940                                                 echo '</dl>' . M3_NL;
3941                                         }
3942                                 }
3943                         }
3944                 } else if ($task == 'wget' || $task == 'wdelete' || $task == 'wtoggle' || $task == 'wadd' || $task == 'wmove'){ // ウィジェット再取得、ウィジェット削除,ウィジェット共通属性変更、ウィジェット追加、ウィジェット移動のとき
3945                         $rev    = $request->trimValueOf('rev');                 // リビジョン
3946                         $serial = $request->trimValueOf('serial');
3947                         $position = $request->trimValueOf('pos');
3948                         $widgetsStr = $request->trimValueOf('widgets');
3949                         if (empty($widgetsStr)){
3950                                 $widgets = array();
3951                         } else {
3952                                 $widgets = explode(',', $widgetsStr);
3953                         }
3954                         $shared = $request->trimValueOf('shared');
3955                         $updatepos = explode(',', $request->trimValueOf('updatepos'));
3956                         $index = $request->trimValueOf('index');
3957                         
3958                         // 処理ごとのパラメータ
3959                         if ($task == 'wmove'){
3960                                 $positions = explode(',', $position);
3961                                 if (count($positions) >= 2){
3962                                         $position = $positions[0];
3963                                         $position2 = $positions[1];
3964                                 } else {
3965                                         $position = $positions[0];
3966                                         $position2 = '';
3967                                 }
3968                         }
3969                         // ##### エラーチェック #####
3970                         $isErr = false;
3971                         // リビジョンのエラーチェック
3972                         $rev = '111';                   // データのリビジョン番号
3973
3974                         // 変更前データ取得
3975                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);    // 0レコードでも正常とする
3976                         
3977                         // 変更前のウィジェットのシリアル番号をチェック
3978                         if (count($widgets) == count($rows)){
3979                                 if (!($task == 'wmove' && empty($position2))){                  // 同一ブロック内の移動の場合はチェックなし
3980                                         for ($i = 0; $i < count($rows); $i++){
3981                                                 if ($widgets[$i] != $rows[$i]['pd_serial']){// シリアル番号
3982                                                         $isErr = true;
3983                                                         break;
3984                                                 }
3985                                         }
3986                                 }
3987                         } else {
3988                                 $isErr = true;
3989                         }
3990
3991                         // データの更新
3992                         if (!$isErr){           // エラーなしのとき
3993                                 if ($task == 'wdelete'){
3994                                         $ret = $this->db->deleteWidget($serial);
3995                                 } else if ($task == 'wtoggle'){
3996                                         $newShared = 0;
3997                                         if (empty($shared)) $newShared = 1;
3998                                         $ret = $this->db->toggleSharedWidget($pageId, $pageSubId, $serial, $newShared);
3999                                 } else if ($task == 'wadd'){    // ウィジェットの追加
4000                                         $widget = $request->trimValueOf('widget');
4001                                         
4002                                         // エラーチェック
4003                                         if (empty($widget)) $isErr = true;
4004                                         
4005                                         // ウィジェットを追加
4006                                         if (!$isErr) $this->db->addWidget($pageId, $pageSubId, $position, $widget, $index);
4007                                 } else if ($task == 'wmove'){
4008                                         // ウィジェットを移動
4009                                         if (!$isErr) $this->db->moveWidget($pageId, $pageSubId, $position, $serial, $index);
4010                                 }
4011                         }
4012                         // 再表示データ取得
4013                         $ret = $this->db->getPageDef($pageId, $pageSubId, $position, $rows);// 0レコードでも正常とする
4014                         
4015                         // 移動のときは、移動元と移動先の再表示データを取得
4016                         if ($task == 'wmove' && !empty($position2)){
4017                                 $ret = $this->db->getPageDef($pageId, $pageSubId, $position2, $rows2);// 0レコードでも正常とする
4018                         }
4019
4020                         // 更新データを作成
4021                         // 更新対象のポジションブロック
4022                         echo '<div>' . M3_NL;
4023                         for ($i = 0; $i < count($updatepos); $i++){
4024                                 // ウィジェットIDヘッダ作成
4025                                 $widgetTagHead = str_replace(self::POSITION_TAG_HEAD, self::WIDGET_TAG_HEAD, $updatepos[$i]);
4026                                         
4027                                 // ポジション名取得
4028                                 $posName = str_replace(self::POSITION_TAG_HEAD, '', substr($updatepos[$i], 0, strlen($updatepos[$i]) - strlen(strrchr($updatepos[$i], "_"))));
4029                                 if ($task == 'wmove' && $posName == $position2){
4030                                         // ウィジェット一覧外枠
4031                                         $posHead = '';
4032                                         if (strcasecmp($position2, 'user3') == 0 || strcasecmp($position2, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;              // 特殊ポジションブロックのアイコン付加
4033                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position2 . ';rev:' . $rev . ';">' . M3_NL;                // リビジョン番号を付加
4034                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position2 . '</h2>' . M3_NL;
4035                                 
4036                                         // ウィジェット一覧出力
4037                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows2);
4038                                 } else {
4039                                         // ウィジェット一覧外枠
4040                                         $posHead = '';
4041                                         if (strcasecmp($position, 'user3') == 0 || strcasecmp($position, 'position-1') == 0) $posHead = self::POS_HEAD_NAV_MENU;                // 特殊ポジションブロックのアイコン付加
4042                                         echo '<div id="' . $updatepos[$i] . '" class="m3_widgetpos_box" m3="pos:' . $position . ';rev:' . $rev . ';">' . M3_NL;         // リビジョン番号を付加
4043                                         echo '<h2 class="m3_widgetpos_box_title">' . $posHead . $position . '</h2>' . M3_NL;
4044                                 
4045                                         // ウィジェット一覧出力
4046                                         echo $this->getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows);
4047                                 }
4048                                 // ウィジェット一覧外枠
4049                                 echo '</div>' . M3_NL;
4050                         }
4051                         echo '</div>' . M3_NL;
4052                         
4053                         // キャッシュデータをクリア
4054                         $gCacheManager->clearAllCache();
4055                 }
4056         }
4057         /**
4058          * 画面作成用ウィジェット一覧データ出力
4059          *
4060          * @param string $pageId                        ページID
4061          * @param string $pageSubId                     ページサブID
4062          * @param string $widgetTagHead         HTMLウィジェットID用のヘッダ
4063          * @param array $rows                           ウィジェット一覧データ
4064          * @return string                                       ウィジェット一覧出力
4065          */
4066         function getWidgetList($pageId, $pageSubId, $widgetTagHead, $rows)
4067         {
4068                 global $gEnvManager;
4069                 global $gDesignManager;
4070                 global $gSystemManager;
4071                 
4072                 if ($gEnvManager->getUseSslAdmin()){
4073                         $rootUrl = $gEnvManager->getSslRootUrl();
4074                 } else {
4075                         $rootUrl = $gEnvManager->getRootUrl();
4076                 }
4077
4078                 // ページのコンテンツタイプを取得
4079                 $line = $this->getPageInfo($pageId, $pageSubId);
4080                 if (!empty($line)) $pageContentType = $line['pn_content_type'];
4081                         
4082                 $contents = '';         // ウィジェット一覧出力コンテンツ
4083                 for ($i = 0; $i < count($rows); $i++){
4084                         $widgetId = $rows[$i]['wd_id'];
4085                         $desc = $rows[$i]['wd_description'];
4086                         $widgetIndex = $rows[$i]['pd_index'];           // 表示順
4087                         $configId = $rows[$i]['pd_config_id'];          // 定義ID
4088                         $serial = $rows[$i]['pd_serial'];               // シリアル番号
4089                         $widgetTag = $widgetTagHead . '_' . $i;                         // ウィジェット識別用ユニークタグ
4090                         $image = $gDesignManager->getWidgetIconUrl($widgetId, self::WIDGET_ICON_IMG_SIZE);
4091                         if ($gEnvManager->getUseSslAdmin()){
4092                                 //$image = str_replace('http://', 'https://', $image);          // SSL通信の場合はSSL用に変換
4093                                 $image = $gEnvManager->getSslUrl($image);
4094                         }
4095                         $imageTag = '<img class="' . self::WIDTET_CLASS_NAME . '" src="' . $image . '" ';
4096                         $imageTag .= 'width="' . self::WIDGET_ICON_IMG_SIZE . '"';
4097                         $imageTag .= ' height="' . self::WIDGET_ICON_IMG_SIZE . '"';
4098                         $imageTag .= ' />';
4099                         // 定義名
4100                         if (empty($rows[$i]['pd_config_name'])){
4101                                 if ($rows[$i]['wd_use_instance_def'] && $configId == 0){                // インスタンス定義が必要で未定義のとき
4102                                         $configName = '<span style="color:red;">[未設定]</span>';
4103                                 } else {
4104                                         $configName = '';
4105                                 }
4106                         } else {
4107                                 $configName = '[' . $rows[$i]['pd_config_name'] . ']';
4108                         }
4109                         $hasAdmin = '0';                // 管理画面があるかどうか
4110                         $configImg = '';        // 設定アイコンの表示
4111                         
4112                         // ウィジェットの配置位置に問題があるかどうかを表示
4113                         // メインコンテンツとページ属性が一致するかどうかチェック
4114                         $widgetContentType = $rows[$i]['wd_content_type'];
4115                         if (!empty($widgetContentType) && $widgetContentType != $pageContentType && 
4116                                                 (in_array($widgetContentType, $this->_getAllContentType()) || in_array($widgetContentType, $this->_getAllFeatureType()))){
4117                                 //$title = 'ウィジェット配置注意';
4118                                 $title = 'ページ属性と不一致';
4119                                 $configImg .= '<img src="' . $rootUrl . self::NOTICE_ICON_FILE . '" alt="' . $title . '" title="' . $title . '" />&nbsp;';
4120                         }
4121                         if ($rows[$i]['wd_has_admin']){
4122                                 $hasAdmin = '1';
4123                                 $title = 'ウィジェット設定';
4124                                 $configImg .= '<a href="javascript:void(0);" onclick="m3ShowConfigWindow(\'' . $widgetId . '\', \'' . $configId . '\', \'' . $serial . '\');return false;" >' .
4125                                                                 '<img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" alt="' . $title . '" title="' . $title . '" /></a>&nbsp;';
4126                         }
4127                         $shared = '0';          // 共通属性があるかどうか
4128                         $sharedClassName = '';
4129                         if (empty($rows[$i]['pd_sub_id'])){
4130                                 $shared = '1';  // 共通ウィジェットのとき
4131                                 $sharedClassName = 'm3_widget_shared';                  // 共通ウィジェットのクラス
4132                         }
4133                         $m3Option = 'm3="widgetid:' . $widgetId . '; serial:' . $serial . '; configid:' . $configId . '; useconfig:' . $hasAdmin . '; shared:' . $shared . '"';
4134                         
4135                         // ウィジェット機能マーク
4136                         $widgetMark = '';
4137                         if ($rows[$i]['wd_edit_content'] && !empty($rows[$i]['wd_type'])) $widgetMark = self::WIDGET_MARK_MAIN;                                 // メインウィジェット
4138                         if ($rows[$i]['wd_type'] == 'menu' && $rows[$i]['wd_type_option'] == 'nav') $widgetMark = self::WIDGET_MARK_NAVMENU;            // ナビゲーションメニュー
4139                         
4140                         // 操作メニュー
4141                         $dropdownMenuId = $widgetTag . '_dropdown';
4142                         $operationMenu = '<div class="m3widgetdropdown">';
4143 //                      $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#"><i class="glyphicon glyphicon-list-alt"></i> <b class="caret"></b></a>';
4144                         $operationMenu .= '<a class="m3widgetdropdownbutton" data-dropdown="#' . $dropdownMenuId . '" href="#" data-horizontal-offset="4"><b class="caret"></b></a>';
4145                         $operationMenu .= '<div id="' . $dropdownMenuId . '" class="m3dropdown m3dropdown-tip m3dropdown-relative m3dropdown-anchor-right">';
4146                         $operationMenu .= '<ul class="m3dropdown-menu">';
4147                         $operationMenu .= '<li class="m3_wadjust"><a href="#"><img src="' . $rootUrl . self::ADJUST_ICON_FILE . '" /> <span>タイトル・位置調整</span></a></li>';
4148                         if ($hasAdmin) $operationMenu .= '<li class="m3_wconfig"><a href="#"><img src="' . $rootUrl . self::CONFIG_ICON_FILE . '" /> <span>ウィジェットの設定</span></a></li>';
4149                         if ($shared){
4150                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>ページ共通属性を解除</span></a></li>';
4151                         } else {
4152                                 $operationMenu .= '<li class="m3_wshared"><a href="#"><img src="' . $rootUrl . self::SHARED_ICON_FILE . '" /> <span>ページ共通属性を設定</span></a></li>';
4153                         }
4154                         $operationMenu .= '<li class="m3_wdelete"><a href="#"><img src="' . $rootUrl . self::DELETE_ICON_FILE . '" /> <span>このウィジェットを削除</span></a></li>';
4155                         $operationMenu .= '</ul>';
4156                         $operationMenu .= '</div>';
4157                         $operationMenu .= '</div>';
4158                         
4159                         $contents .= '<dl class="m3_widget m3_widget_sortable" id="' . $widgetTag . '" ' . $m3Option . ' >' . M3_NL;
4160                         $contents .= '<dt class="m3_widget_with_check_box ' . $sharedClassName . '"><div class="m3widgettitle">' . $widgetMark . $rows[$i]['wd_name'] . '</div>' . $operationMenu . '</dt>' . M3_NL;
4161                         $contents .= '<dd><table width="100%"><tr valign="top"><td width="35">' . $imageTag . '</td><td>' . $desc . '</td></tr></table>' . M3_NL;
4162                         $contents .= '<table width="100%"><tr><td>' . $configName . '</td><td align="right">' . $configImg . $widgetIndex . '</td></tr></table></dd>' . M3_NL;
4163                         $contents .= '</dl>' . M3_NL;
4164                 }
4165                 return $contents;
4166         }
4167         /**
4168          * ウィジェット出力を処理
4169          *
4170          * @param int $index                    行番号
4171          * @param array $fetchedRow             fetch取得した行
4172          * @param string $style                 ウィジェットの表示スタイル(空の場合=Joomla!v1.0テンプレート用、空以外=Joomla!v1.5テンプレート用)
4173          * @param string $titleTag      タイトル埋め込み用タグ(遅延ウィジェットの場合のみ作成)
4174          * @param int $widgetHeaderType ウィジェットタイトルを出力方法(0=出力なし、1=Joomla!v1.0PC用出力、2=Joomla!v1.0携帯用出力)
4175          * @return bool                                 処理を継続するかどうか(true=続行、false=中断)
4176          */
4177         function pageDefLoop($index, $fetchedRow, $style, &$titleTag, $widgetHeaderType = 0)
4178         {
4179                 global $gEnvManager;
4180                 global $gErrorManager;
4181                 global $gDesignManager;
4182
4183                 // ページ作成中断のときは終了
4184                 if ($this->isAbort) return false;
4185                 
4186                 // ウィジェット実行停止中のときは空で返す
4187                 // 管理者、運営者どのレベルで制限をかける?
4188                 if (!$fetchedRow['wd_active']) return true;
4189                 
4190                 // ページ共通属性ありの場合は現在のページが例外ページにないかチェック
4191                 if (empty($fetchedRow['pd_sub_id'])){
4192                         $exceptPageStr = $fetchedRow['pd_except_sub_id'];
4193                         if (!empty($exceptPageStr)){
4194                                 $exceptPageArray = explode(',', $exceptPageStr);
4195                                 if (in_array($gEnvManager->getCurrentPageSubId(), $exceptPageArray)) return true;               // 例外ページの場合は出力しない
4196                         }
4197                 }
4198                 
4199                 // ウィジェット表示タイプによる表示制御。システム管理者以上の場合は常時表示。
4200                 if (!$gEnvManager->isSystemAdmin() && $fetchedRow['pd_view_control_type'] != 0){
4201                         switch ($fetchedRow['pd_view_control_type']){
4202                                 case 1:                 // ログイン時のみ表示
4203                                         if (!$gEnvManager->isCurrentUserLogined()) return true;         // ログインしていなければ終了
4204                                         break;
4205                                 case 2:                 // 非ログイン時のみ表示
4206                                         if ($gEnvManager->isCurrentUserLogined()) return true;          // ログインしていれば終了
4207                                         break;
4208                                 default:
4209                                         break;
4210                         }
4211                 }
4212                 
4213                 // パラメータ初期化
4214                 $titleTag = '';
4215                 
4216                 // ウィジェットID取得
4217                 $widgetId = $fetchedRow['wd_id'];               
4218                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
4219
4220                 // その他パラメータ取得
4221                 $configId = $fetchedRow['pd_config_id'];                // ウィジェット定義ID
4222                 if ($configId == 0) $configId = '';
4223                 $prefix = $fetchedRow['wd_suffix'];             // サフィックス文字列
4224                 $title = $fetchedRow['wd_name'];                // デフォルトのウィジェットタイトル
4225                 if (empty($title)) $title = $fetchedRow['wd_id'];
4226                 $serial = $fetchedRow['pd_serial'];             // シリアル番号
4227                 $cssStyle       = $fetchedRow['pd_style'];              // CSS
4228                 $lateLaunchIndex = $fetchedRow['wd_launch_index'];              // 遅延実行インデックス
4229                 $shared = false;
4230                 if (empty($fetchedRow['pd_sub_id'])) $shared = true;// 共通属性あり
4231                 if ($this->nonSharedWidgetCount == -1) $this->nonSharedWidgetCount = 0;         // 初期化されていない場合は初期化
4232                 if (!$shared) $this->nonSharedWidgetCount++;    // 非共通ウィジェットの数を更新
4233                 
4234                 // ウィジェットが遅延実行に指定されている場合は、ウィジェットのタグのみ埋め込む
4235                 if ($lateLaunchIndex > 0){              // 遅延実行のとき
4236                         // 遅延実行ウィジェットリストに追加
4237                         if (!isset($this->lateLaunchWidgetList[$widgetId])){
4238                                 $this->lateLaunchWidgetList[$widgetId] = (int)$lateLaunchIndex;
4239                         }
4240                         // 実行パラメータ保存
4241                         $maxNo = 0;             // 最大シリアル番号
4242                         $count = count($this->latelaunchWidgetParam);
4243                         for ($i = 0; $i < $count; $i++){
4244                                 list($wId, $index, $tmp1, $tmp2, $tmp3, $tmp4, $tmp5, $tmp6, $tmp7) = $this->latelaunchWidgetParam[$i];
4245                                 if ($wId == $widgetId) $maxNo = $index + 1;
4246                         }
4247                         // Joomla!1.0テンプレートの場合はタイトルを修正
4248                         if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
4249                                 if (!empty($fetchedRow['pd_title'])) $title = $fetchedRow['pd_title'];
4250                         }
4251                         $this->latelaunchWidgetParam[] = array($widgetId, $maxNo, $configId, $prefix, $serial, $style, $cssStyle, $title, $shared);
4252                         
4253                         // 遅延実行用タグを埋め込む
4254                         echo self::WIDGET_ID_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TAG_END;
4255                         
4256                         // タイトル用タグ作成
4257                         $titleTag = self::WIDGET_ID_TITLE_TAG_START . $widgetId . self::WIDGET_ID_SEPARATOR . $maxNo . self::WIDGET_ID_TITLE_TAG_END;
4258                 } else {
4259                         // ウィジェットが存在する場合は実行
4260                         if (!file_exists($widgetIndexFile)) {
4261                                 if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
4262                         } else {
4263                                 // パラメータ初期化
4264                                 $this->lastHeadCss = '';                        // 最後に設定したHTMLヘッダにCSS出力する文字列
4265                                 $this->lastHeadScript = '';                     // 最後に設定したHTMLヘッダにJavascript出力する文字列
4266                                 $this->lastHeadString = '';                     // 最後に設定したHTMLヘッダに出力する任意文字列
4267                                 $this->lastHeadTitle = '';                      // ヘッダ部titleにセットした文字列
4268                                 $this->lastHeadDescription = '';        // ヘッダ部descriptionにセットした文字列
4269                                 $this->lastHeadKeywords = '';           // ヘッダ部keywordsにセットした文字列
4270                         
4271                                 // Joomla!1.0テンプレートのときはウィジェットタイトルを出力
4272                                 $joomlaTitleVisble = false;
4273                                 if ($widgetHeaderType > 0 && empty($style)){                    // Joomla!1.0テンプレートのとき
4274                                         if ($fetchedRow['pd_title_visible']){
4275                                                 if ($widgetHeaderType == 1){            // PC用出力のとき
4276                                                         $joomlaTitle = $fetchedRow['pd_title'];
4277                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
4278                                                         echo '<table ' . self::JOOMLA10_DEFAULT_WIDGET_MENU_PARAM . '>' . M3_NL;
4279                                                         echo '<tr><th>' . $joomlaTitle . '</th></tr>' . M3_NL;
4280                                                         echo '<tr><td>' . M3_NL;
4281                                                         $joomlaTitleVisble = true;
4282                                                 } else if ($widgetHeaderType == 2){             // 携帯用出力のとき
4283                                                         $joomlaTitle = $fetchedRow['pd_title'];
4284                                                         if (empty($joomlaTitle)) $joomlaTitle = $title;
4285                                                         echo '<div>' . $joomlaTitle . '</div>' . M3_NL;
4286                                                         $joomlaTitleVisble = true;
4287                                                 }
4288                                         }
4289                                 }
4290                                 // ウィジェットの外枠タグを設定
4291                                 //echo '<div class="' . self::WIDGET_OUTER_CLASS_WIDGET_TAG . $widgetId . '">' . M3_NL;
4292                                 // ウィジェット親のCSS定義があるときは、タグを追加
4293                                 if (!empty($cssStyle)) echo '<div style="' . $cssStyle . '">' . M3_NL;
4294                                         
4295                                 // ウィジェットの前出力
4296                                 echo $gDesignManager->getAdditionalWidgetOutput(true);
4297                                 
4298                                 // 作業中のウィジェットIDを設定
4299                                 $gEnvManager->setCurrentWidgetId($widgetId);
4300         
4301                                 // ウィジェット定義IDを設定
4302                                 $gEnvManager->setCurrentWidgetConfigId($configId);
4303                         
4304                                 // ページ定義のシリアル番号を設定
4305                                 $gEnvManager->setCurrentPageDefSerial($fetchedRow['pd_serial']);
4306                                         
4307                                 // パラメータを設定
4308                                 $gEnvManager->setCurrentWidgetPrefix($prefix);          // プレフィックス文字列
4309                         
4310                                 // ウィジェットのタイトルを設定
4311                                 $gEnvManager->setCurrentWidgetTitle($title);
4312                                 
4313                                 // ウィジェットのスタイルを設定
4314                                 $gEnvManager->setCurrentWidgetStyle($style);
4315                                 
4316                                 // ウィジェットのページ共通状況を設定
4317                                 $gEnvManager->setIsCurrentWidgetShared($shared);
4318                                         
4319                                 // 実行ログを残す
4320                                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
4321                                 
4322                                 // ウィジェットを実行
4323                                 //require_once($widgetIndexFile);
4324                                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
4325                                 $msg = 'widget-start(' . $widgetId . ')';
4326                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
4327                                 require($widgetIndexFile);
4328                                 $msg = 'widget-end(' . $widgetId . ')';
4329                                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
4330
4331                                 // 作業中のウィジェットIDを解除
4332                                 $gEnvManager->setCurrentWidgetId('');
4333                         
4334                                 // ウィジェット定義IDを解除
4335                                 $gEnvManager->setCurrentWidgetConfigId('');
4336                                 
4337                                 // ページ定義のシリアル番号を解除
4338                                 $gEnvManager->setCurrentPageDefSerial(0);
4339                         
4340                                 // パラメータを解除
4341                                 $gEnvManager->setCurrentWidgetPrefix('');                               // プレフィックス文字列
4342
4343                                 // ウィジェットのスタイルを解除
4344                                 $gEnvManager->setCurrentWidgetStyle('');
4345                                 
4346                                 // ウィジェットのページ共通状況を解除
4347                                 $gEnvManager->setIsCurrentWidgetShared(false);
4348                                 
4349                                 // ウィジェットの後出力
4350                                 echo $gDesignManager->getAdditionalWidgetOutput(false);
4351 //                              echo "<!-- ".time()." -->";
4352
4353                                 // ウィジェット親のCSS定義があるときは、タグを追加
4354                                 if (!empty($cssStyle)) echo '</div>' . M3_NL;
4355                                 // ウィジェットの外枠タグを設定
4356                                 //echo '</div>' . M3_NL;
4357                                 
4358                                 // Joomla!1.0テンプレートのときはタイトルを出力
4359                                 if ($joomlaTitleVisble && $widgetHeaderType == 1){              // PC用出力のとき
4360                                         echo '</td></tr>' . M3_NL;
4361                                         echo '</table>' . M3_NL;
4362                                 }
4363                         }
4364                 }
4365                 return true;            // 処理継続
4366         }
4367         /**
4368          * 定義IDを指定してウィジェットの出力を取得
4369          *
4370          * @param string $widgetId              ウィジェットID
4371          * @param int $configId                 ウィジェット定義ID
4372          * @return string                               ウィジェットの出力
4373          */
4374         function getWidgetOutput($widgetId, $configId)
4375         {
4376                 global $gEnvManager;
4377                 global $gErrorManager;
4378
4379                 // ウィジェットのアクセス権をチェック
4380                 if (!$this->db->canAccessWidget($widgetId)) return '';
4381
4382                 // ウィジェット情報取得
4383                 if (!$this->db->getWidgetInfo($widgetId, $row)) return '';
4384
4385                 // 端末タイプをチェック
4386                 if (intval($row['wd_device_type']) != intval($gEnvManager->getCurrentPageDeviceType())) return '';
4387                 
4388                 // 必要なJavascriptライブラリを追加
4389                 $scritLib = trim($row['wd_add_script_lib']);
4390                 if (!empty($scritLib)) $this->addScript('', $scritLib);
4391                 
4392                 // バッファ作成
4393                 ob_start();
4394
4395                 // ウィジェット実行ファイル取得
4396                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/index.php';
4397                                         
4398                 // 作業中のウィジェットIDを設定
4399                 $saveWidgetId = $gEnvManager->getCurrentWidgetId();
4400                 $gEnvManager->setCurrentWidgetId($widgetId);
4401
4402                 // ウィジェット定義IDを設定
4403                 $saveConfigId = $gEnvManager->getCurrentWidgetConfigId();
4404                 $gEnvManager->setCurrentWidgetConfigId($configId);
4405         
4406                 // ページ定義のシリアル番号を設定
4407                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
4408                         
4409                 // パラメータを設定
4410                 //$gEnvManager->setCurrentWidgetPrefix($prefix);                // プレフィックス文字列
4411         
4412                 // ウィジェットのタイトルを設定
4413                 //$gEnvManager->setCurrentWidgetTitle($title);
4414                 
4415                 // ウィジェットのページ共通状況を設定
4416                 //$gEnvManager->setIsCurrentWidgetShared($shared);
4417                         
4418                 // 実行ログを残す
4419                 $this->db->writeWidgetLog($widgetId, 0/*ページ実行*/);
4420                 
4421                 // ウィジェットを実行
4422                 //require_once($widgetIndexFile);
4423                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
4424                 $msg = 'widget-start(' . $widgetId . ')';
4425                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
4426                 if (file_exists($widgetIndexFile)){
4427                         require($widgetIndexFile);
4428                 } else {
4429                         if ($gEnvManager->isSystemManageUser()) echo '<span class="error">widget not found error: ' . $widgetId . '</span>';            // システム運用者の場合はエラーメッセージ表示
4430                 }
4431                 $msg = 'widget-end(' . $widgetId . ')';
4432                 $gErrorManager->writeDebug(__METHOD__, $msg);           // 時間計測用
4433
4434                 // 作業中のウィジェットIDを戻す
4435                 $gEnvManager->setCurrentWidgetId($saveWidgetId);
4436         
4437                 // ウィジェット定義IDを戻す
4438                 $gEnvManager->setCurrentWidgetConfigId($saveConfigId);
4439                 
4440                 // ページ定義のシリアル番号を解除
4441                 //$gEnvManager->setCurrentPageDefSerial(0);             // 未使用?
4442         
4443                 // パラメータを解除
4444                 //$gEnvManager->setCurrentWidgetPrefix('');                             // プレフィックス文字列
4445
4446                 // ウィジェットのページ共通状況を解除
4447                 //$gEnvManager->setIsCurrentWidgetShared(false);
4448
4449                 // 現在のバッファ内容を取得し、バッファを破棄
4450                 $output = ob_get_contents();
4451                 ob_end_clean();
4452                                         
4453                 return $output;
4454         }
4455         /**
4456          * インナーウィジェットの操作
4457          *
4458          * @param int $cmdNo                            実行コマンド(0=初期化、1=更新、2=計算、10=コンテンツ取得)
4459          * @param string $id                            ウィジェットID+インナーウィジェットID
4460          * @param string $configId                      インナーウィジェット定義ID
4461          * @param object $paramObj                      インナーウィジェットに渡すパラメータオブジェクト
4462          * @param object $optionParamObj        インナーウィジェットに渡すパラメータオブジェクト(オプション)
4463          * @param object $resultObj                     インナーウィジェットから返る結果オブジェクト
4464          * @param string $content                       出力内容
4465          * @param bool $isAdmin                         管理者機能(adminディレクトリ以下)かどうか
4466          * @return bool                                         true=成功、false=失敗
4467          */
4468         function commandIWidget($cmdNo, $id, $configId, &$paramObj, &$optionParamObj, &$resultObj, &$content, $isAdmin = false)
4469         {
4470                 global $gEnvManager;
4471                 
4472                 // ウィジェットIDとインナーウィジェットIDを取り出す
4473                 list($widgetId, $iWidgetId) = explode(M3_WIDGET_ID_SEPARATOR, $id);
4474
4475                 // インナーウィジェットに渡すパラメータを設定
4476                 switch ($cmdNo){
4477                         case 0:
4478                                 $cmd = self::IWIDTET_CMD_INIT;                  // 初期化
4479                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
4480                                 break;
4481                         case 1:
4482                                 $cmd = self::IWIDTET_CMD_UPDATE;                // 更新
4483                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
4484                                 break;
4485                         case 2:
4486                                 $cmd = self::IWIDTET_CMD_CALC;                  // 計算
4487                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
4488                                 break;
4489                         case 10:
4490                                 $cmd = self::IWIDTET_CMD_CONTENT;                       // コンテンツ取得
4491                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd);               // 設定されているパラメータの更新は行わない
4492                                 break;
4493                         default:
4494                                 $cmd = '';
4495                                 $this->gInstance->getCmdParamManager()->setParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $paramObj, $optionParamObj);
4496                                 break;
4497                 }
4498
4499                 // インナーウィジェットのエラー出力は呼び出しウィジェット側で受けるため、出力を抑止する
4500                 ob_start();// バッファ作成
4501
4502                 // ウィジェット実行ファイル取得
4503                 if (empty($widgetId)){          // ウィジェットIDが指定されていないときは共通ディレクトリ
4504                 //$gEnvManager->getIWidgetsPath() . '/' . $iWidgetId . '/' . $containerClass . '.php';
4505                 } else {
4506                         if ($isAdmin){
4507                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/' . M3_DIR_NAME_ADMIN . '/index.php';
4508                         } else {
4509                                 $widgetIndexFile = $gEnvManager->getWidgetsPath() . '/' . $widgetId . '/include/iwidgets/' . $iWidgetId . '/index.php';
4510                         }
4511                 }
4512
4513                 // 作業中のインナーウィジェットIDを設定
4514                 $gEnvManager->setCurrentIWidgetId($id);         // インナーウィジェットを設定
4515
4516                 // インナーウィジェット定義IDを設定
4517                 $gEnvManager->setCurrentIWidgetConfigId($configId);
4518                 
4519                 // ウィジェットを実行
4520                 // ウィジェットの呼び出しは、複数回存在する可能性があるのでrequire_once()で呼び出さない
4521                 if (file_exists($widgetIndexFile)){
4522                         require($widgetIndexFile);
4523                 } else {
4524                         echo 'file not found error: ' . $widgetIndexFile;
4525                 }
4526                 
4527                 // 作業中のウィジェットIDを解除
4528                 $gEnvManager->setCurrentIWidgetId('');
4529         
4530                 // インナーウィジェット定義IDを解除
4531                 $gEnvManager->setCurrentIWidgetConfigId('');
4532                 
4533                 // 現在のバッファ内容を取得し、バッファを破棄
4534                 $content = ob_get_contents();
4535                 ob_end_clean();
4536                 
4537                 // 値を再取得
4538                 if ($this->gInstance->getCmdParamManager()->getParam($id . M3_WIDGET_ID_SEPARATOR . $configId, $cmd, $obj, $option)){
4539                         $paramObj = $obj;
4540                         $optionParamObj = $option;
4541                 }
4542
4543                 // 結果を取得
4544                 if ($this->gInstance->getCmdParamManager()->getResult($id . M3_WIDGET_ID_SEPARATOR . $configId, $resObj)) $resultObj = $resObj;
4545                 return true;
4546         }
4547         /**
4548          * コールバックメソッドを実行し、出力を返す
4549          *
4550          * @param array $callback               実行するコールバック
4551          * @return string                               出力結果
4552          */
4553         function getOutputByCallbackMethod($callback)
4554         {
4555                 ob_start();// バッファ作成
4556                 
4557                 // コールバック関数を実行
4558                 if (is_callable($callback)) call_user_func($callback);
4559                 
4560                 // 現在のバッファ内容を取得し、バッファを破棄
4561                 $content = ob_get_contents();
4562                 ob_end_clean();
4563                 return $content;
4564         }
4565         /**
4566          * ページ作成処理中断を行った場合のレスポンスヘッダ設定
4567          *
4568          * @param int $responseCode             レスポンスコード
4569          * @return                                              なし
4570          */
4571         function setResponse($responseCode)
4572         {
4573                 switch ($responseCode){
4574                         case 503:                       // サイト非公開(システムメンテナンス)
4575                                 header('HTTP/1.1 503 Service Temporarily Unavailable');
4576                                 header('Status: 503 Service Temporarily Unavailable');
4577                                 break;
4578                         case 403:                       // アクセス禁止のとき
4579                                 header('HTTP/1.1 403 Forbidden');
4580                                 header('Status: 403 Forbidden');
4581                                 break;
4582                         case 404:                       // 存在しないページのとき
4583                                 header("HTTP/1.1 404 Not Found");
4584                                 header("Status: 404 Not Found");
4585                                 break;
4586                 }
4587         }
4588         /**
4589          * ファイルダウンロード
4590          *
4591          * @param string $filePath                      ダウンロードするファイルのファイルパス
4592          * @param string $downloadFilename      ダウンロード時のファイル名
4593          * @param bool   $deleteFile            実行後ファイルを削除するかどうか(成功失敗に関係なく)
4594          * @return bool                                         true=成功、false=失敗
4595          */
4596         function downloadFile($filePath, $downloadFilename, $deleteFile=false)
4597         {
4598                 // エラーチェック
4599                 if (!file_exists($filePath)) return false;
4600                 
4601                 // ファイルサイズ取得
4602                 $fileSize = filesize($filePath);
4603                 
4604                 // バッファ内容が残っているときは破棄
4605                 if (ob_get_level() > 0) ob_end_clean();
4606                 
4607                 header('Cache-Control: public');                // IE6+SSHでダウンロードエラーが出る問題を回避
4608                 header('Pragma: public');                               // IE6+SSHでダウンロードエラーが出る問題を回避
4609             header('Content-Disposition: attachment; filename=' . $downloadFilename);
4610                 header('Content-Length: ' . $fileSize);
4611             header('Content-Type: application/octet-stream; name=' . $downloadFilename);
4612             $fp = fopen($filePath, "r");
4613             echo fread($fp, $fileSize);
4614             fclose($fp);
4615                 
4616                 ob_end_flush();
4617                 
4618                 // ファイル削除
4619                 if ($deleteFile) unlink($filePath);
4620                 return true;
4621         }
4622         /**
4623          * 指定URLへリダイレクト
4624          *
4625          * @param string $url                   遷移先URL。未指定の場合は現在のスクリプト。URLでないときは、現在のスクリプトに付加。
4626          * @param bool $noMessage               画面を遷移させたとき、ドコモ携帯端末でダイアログ(サイトが移動しました(301))が出ないようにするオプション
4627          * @param int  $responseCode    レスポンスコード
4628          * @return                                              なし
4629          */
4630         function redirect($url = '', $noMessage = false, $responseCode = 0)
4631         {
4632                 global $gEnvManager;
4633
4634                 // すでにリダイレクトが設定されている場合は終了
4635                 if ($this->isRedirect) return;                          // リダイレクトするかどうか
4636                 
4637                 $toUrl = $url;
4638                 if (empty($toUrl)){
4639                         $toUrl = $gEnvManager->getCurrentScriptUrl();
4640                 } else if (strncmp($toUrl, 'http://', 7) != 0 && strncmp($toUrl, 'https://', 8) != 0){  // URL以外のときはクエリー文字列と判断する
4641                         $toUrl = $gEnvManager->getCurrentScriptUrl() . $toUrl;
4642                 }
4643
4644                 // SSL化が必要な場合はhttpsに変更
4645                 $isSslPage = false;
4646                 if ($gEnvManager->isAdminUrlAccess($toUrl)){            // 管理画面へのアクセスのとき
4647                         // 管理画面のSSL状態を参照
4648                         if ($gEnvManager->getUseSslAdmin()) $isSslPage = true;          // 管理画面でSSLを使用するとき
4649                 } else {
4650                         // ファイル名を取得
4651                         $paramArray = array();
4652                         //list($filename, $query) = explode('?', basename($toUrl));
4653                         list($url, $query) = explode('?', $toUrl);
4654                         $baseUrl = dirname($url);
4655                         $filename = basename($url);
4656                         if (empty($filename)) $filename = M3_FILENAME_INDEX;
4657                         if (!empty($query)) parse_str($query, $paramArray);             // クエリーの解析
4658                 
4659                         // ページIDを取得
4660                         $pageId = basename($filename, '.php');
4661                         $pageSubId = $paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID];
4662                         
4663                         // ページのSSL設定状況を取得
4664                         $isSslPage = $this->isSslPage($pageId, $pageSubId);
4665                         
4666                         // 階層化ページの場合はURLを修正
4667                         if ($this->gSystem->hierarchicalPage() && $filename == M3_FILENAME_INDEX){
4668                                 $toUrl = $baseUrl . '/' . $pageSubId . '/';
4669                                 unset($paramArray[M3_REQUEST_PARAM_PAGE_SUB_ID]);
4670                                         
4671                                 $paramStr = $this->_createUrlParamStr($paramArray);
4672                                 if (!empty($paramStr)) $toUrl .= '?' . $paramStr;
4673                         }
4674                 }
4675                 if ($isSslPage){
4676                         //$toUrl = str_replace('http://', 'https://', $toUrl);
4677                         $toUrl = $gEnvManager->getSslUrl($toUrl);               // SSL用URLに変換
4678                 } else {
4679                         $toUrl = str_replace('https://', 'http://', $toUrl);
4680                 }
4681
4682                 // バッファ内容が残っているときは破棄
4683                 if (ob_get_level() > 0) ob_end_clean();
4684
4685                 if (empty($responseCode)){
4686                         if ($noMessage){
4687                                 header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
4688                         } else {
4689                                 header('HTTP/1.1 301 Moved Permanently');
4690                         }
4691                 } else {                // レスポンスコードが指定されている場合
4692                         switch ($responseCode){
4693                                 case 301:
4694                                         header('HTTP/1.1 301 Moved Permanently');
4695                                         break;
4696                                 case 302:
4697                                         header('HTTP/1.1 302 Found(Moved Temporary)');          // ダイアログメッセージを抑止(ドコモ携帯端末用)
4698                                         break;
4699                                 case 303:
4700                                         header('HTTP/1.1 303 See Other');
4701                                         break;
4702                                 default:
4703                                         header('HTTP/1.1 ' . (string)$responseCode);
4704                                         break;
4705                         }
4706                 }
4707                 header('Location: ' . $toUrl);
4708                 
4709                 $this->isRedirect = true;                               // リダイレクトするかどうか
4710 //              exit();
4711         }
4712         /**
4713          * リダイレクト処理かどうかを返す
4714          *
4715          * @return bool         true=リダイレクト、false=リダイレクトでない
4716          */
4717         function isRedirect()
4718         {
4719                 return $this->isRedirect;
4720         }
4721         /**
4722          * 指定URLのディレクトリへリダイレクト
4723          *
4724          * @return                                              なし
4725          */
4726         function redirectToDirectory()
4727         {
4728                 global $gEnvManager;
4729
4730                 // ファイル名を削除
4731                 $dirPath = dirname($gEnvManager->getCurrentScriptUrl()) . '/';
4732                 //$this->redirect($dirPath);
4733                 $this->redirect($dirPath, false, 303);                  // Firefoxでredirect先がキャッシュに残る問題を回避(2012/7/23)
4734         }
4735         /**
4736          * インストール用URLへリダイレクト
4737          *
4738          * @return                                              なし
4739          */
4740         function redirectToInstall()
4741         {
4742                 global $gEnvManager;
4743                 
4744                 $sytemRootUrl = $gEnvManager->calcSystemRootUrl();
4745                 //$this->redirect($sytemRootUrl . '/admin/install.php');
4746                 $this->redirect($sytemRootUrl . '/admin/install.php', false, 303);                      // Firefoxでredirect先がキャッシュに残る問題を回避(2012/8/1)
4747         }
4748         /**
4749          * ログイン、ログアウト処理を行った後、リダイレクト
4750          *
4751          * @param RequestManager        $request                HTTPリクエスト処理クラス
4752          * @param bool                          $success                ログインの成否
4753          * @param string                        $redirectUrl    ログイン成功の場合のリダイレクト先
4754          * @return int                                                          0=何も処理しなかった場合、1=ログイン処理、2=ログアウト処理、3=パスワード送信
4755          */
4756         function standardLoginLogoutRedirect($request, &$success, $redirectUrl = '')
4757         {
4758                 global $gEnvManager;
4759                 global $gAccessManager;
4760                 global $gRequestManager;
4761                 
4762                 // ログイン、ログアウト処理、および、コンテナの起動
4763                 $cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND);
4764                 if ($cmd == M3_REQUEST_CMD_LOGIN){                      // ログインの場合
4765                         $act = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_ACT);
4766                         if ($act == 'sendpwd'){         // パスワード送信の場合
4767                                 $success = $gAccessManager->sendPassword($request);
4768                                 return 3;
4769                         } else {
4770                                 // ユーザ認証
4771                                 $ret = $gAccessManager->userLogin($request);
4772                                 if ($ret){
4773                                         if (empty($redirectUrl)){
4774                                                 // システム運用可能ユーザの場合でリダイレクト先が設定されていない場合はデフォルトの管理画面URLへ遷移
4775                                                 $userInfo = $gEnvManager->getCurrentUserInfo();// ユーザ情報取得
4776                                                 if ($userInfo->userType >= UserInfo::USER_TYPE_MANAGER){
4777                                                         $ret = $this->db->getLoginUserRecordById($userInfo->userId, $userInfoRow);
4778                                                         if ($ret && !empty($userInfoRow['lu_default_admin_url'])){
4779                                                                 $redirectUrl = $gEnvManager->getDefaultAdminUrl() . $userInfoRow['lu_default_admin_url'];
4780                                                         }
4781                                                 }
4782                                         }
4783                                         
4784                                         // リダイレクト処理
4785                                         $this->redirect($redirectUrl);
4786                                         $success = true;                // ログイン成功
4787                                 } else {        // ログイン失敗のとき
4788                                         $success = false;               // ログイン失敗
4789                                 }
4790                                 return 1;
4791                         }
4792                 } else if ($cmd == M3_REQUEST_CMD_LOGOUT){              // ログアウト
4793                         // ログアウト処理
4794                         $gAccessManager->userLogout(true);
4795                         
4796                         // リダイレクト処理
4797                         $this->redirect($redirectUrl);
4798                         return 2;
4799                 } else {
4800                         return 0;
4801                 }
4802         }
4803         /**
4804          * ウィジェットがセットされているページサブIDを取得
4805          *
4806          * @param string $pageId                ページID
4807          * @param string $widgetId              対象ウィジェットID
4808          * @param int $configId                 ウィジェット定義ID
4809          * @return string                               ページサブID
4810          */
4811         function getPageSubIdByWidget($pageId, $widgetId, $configId = 0)
4812         {
4813                 $pageSubId = '';
4814                 
4815                 // 対象のウィジェットのページサブIDを取得
4816                 $ret = $this->db->getSubPageId($widgetId, $pageId, $rows);
4817                 if ($ret){// データが存在する
4818                         for ($i = 0; $i < count($rows); $i++){
4819                                 if (!empty($rows[$i]['pd_sub_id']) && $rows[$i]['pd_config_id'] == $configId){
4820                                         $pageSubId = $rows[$i]['pd_sub_id'];
4821                                         break;
4822                                 }
4823                         }
4824                 }
4825                 return $pageSubId;
4826         }
4827         /**
4828          * その他のGET,POSTパラメータからページサブID取得
4829          *
4830          * @param RequestManager $request               HTTPリクエスト処理クラス
4831          * @param string $pageId                ページID
4832          * @return string                               ページサブID
4833          */
4834         function getPageSubIdByParam($request, $pageId)
4835         {
4836                 $subId = '';
4837                 $task = $request->trimValueOf('task');
4838                 $option = $request->trimValueOf('option');
4839                 if ($task == 'search' && $option == 'com_search'){              // joomla!の検索結果表示の場合
4840                         $subId = $this->db->getSubPageIdWithContent(M3_VIEW_TYPE_SEARCH, $pageId);// ページサブIDを取得
4841                         $this->contentType = M3_VIEW_TYPE_SEARCH;               // ページのコンテンツタイプ
4842                 }
4843                 return $subId;
4844         }
4845         /**
4846          * コンテンツタイプとページIDからページサブID取得
4847          *
4848          * @param string $contentType   コンテンツタイプ
4849          * @param string $pageId                ページID
4850          * @return string                               ページサブID
4851          */
4852         function getPageSubIdByContentType($contentType, $pageId)
4853         {
4854                 $subId = $this->db->getSubPageIdWithContent($contentType, $pageId);// ページサブIDを取得
4855                 return $subId;
4856         }
4857         /**
4858          * 指定のウィジェットがページ上にあるかを取得
4859          *
4860          * @param string $pageId                ページID
4861          * @param string $widgetId              対象ウィジェットID
4862          * @param bool $activePageOnly  公開中のページのウィジェットに制限するかどうか。falseの場合はすべてのページのウィジェットを対象とする。
4863          * @return bool                                 true=ページ上にあり、false=ページ上になし
4864          */
4865         function isWidgetOnPage($pageId, $widgetId, $activePageOnly=true)
4866         {
4867                 $ret = $this->db->isWidgetOnPage($pageId, $widgetId, $activePageOnly, 0/*定義セットID*/);
4868                 return $ret;
4869         }
4870         /**
4871          * URLで示されるページ上のウィジェットをウィジェット種別で取得
4872          *
4873          * @param string $url                   URL
4874          * @param string $widgetType    対象ウィジェットタイプ
4875          * @return string                               ウィジェットID
4876          */
4877         function getWidgetIdByWidgetType($url, $widgetType)
4878         {
4879                 $ret = $this->getPageIdFromUrl($url, $pageId, $pageSubId, $param);
4880                 
4881                 // ウィジェットIDを取得
4882                 if ($ret) $widgetId = $this->db->getWidgetIdByType($pageId, $pageSubId, $widgetType);
4883                 return $widgetId;
4884         }
4885         /**
4886          * 現在アクティブなメインウィジェットをウィジェット種別で取得
4887          *
4888          * @param string $widgetType    対象ウィジェットタイプ
4889          * @return string                               ウィジェットID
4890          */
4891         function getActiveMainWidgetIdByWidgetType($widgetType)
4892         {
4893                 // ウィジェットIDを取得
4894                 $widgetId = $this->db->getActiveMainWidgetIdByType($widgetType);
4895                 return $widgetId;
4896         }
4897         /**
4898          * URLを解析して、ページID,サブページIDを取得
4899          *
4900          * @param string $url                   URL
4901          * @param string $pageId                ページID
4902          * @param string $pageSubId             ページサブID
4903          * @param array  $urlParam              URLパラメータ
4904          * @return bool                                 true=成功、false=失敗
4905          */
4906         function getPageIdFromUrl($url, &$pageId, &$pageSubId, &$urlParam)
4907         {
4908                 global $gEnvManager;
4909                         
4910                 // ページID、ページサブIDを求める
4911                 list($page, $other) = explode('?', str_replace($gEnvManager->getRootUrl(), '', $url));
4912                 parse_str($other, $urlParam);
4913                 
4914                 $pageId = str_replace('/', '_', trim($page, '/'));
4915                 $pageId = basename($pageId, '.php');
4916
4917                 // ページサブIDを取得
4918                 $pageSubId = $param[M3_REQUEST_PARAM_PAGE_SUB_ID];
4919                 if (empty($pageSubId)) $pageSubId = $gEnvManager->getDefaultPageSubId();
4920                 return true;
4921         }
4922         /**
4923          * ウィジェットが組み込まれているページのURLを生成
4924          *
4925          * @param string $widgetId      送信元ウィジェットID
4926          * @param string $param         実行パラメータ
4927          * @param string $pageId        ウィジェットが存在するページID
4928          * @return string                       生成したURL
4929          */
4930         function getDefaultPageUrlByWidget($widgetId, $param = '', $pageId = '')
4931         {
4932                 global $gEnvManager;
4933
4934                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
4935                 
4936                 // このウィジェットがマップされているページサブIDを取得
4937                 $sub = '';
4938                 $subPageId = $this->getPageSubIdByWidget($pageId, $widgetId);
4939                 if (empty($subPageId)){
4940                         // 見つからないときは互換ウィジェットを探す
4941                         $targetWidgetId = $this->db->getCompatibleWidgetId($widgetId);
4942                         if (!empty($targetWidgetId)){
4943                                 $subPageId = $this->getPageSubIdByWidget($pageId, $targetWidgetId);
4944                         }
4945                 }
4946                 if (!empty($subPageId)) $sub = M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $subPageId;
4947                 
4948                 //$url = $gEnvManager->getDefaultUrl();
4949                 $url = $gEnvManager->createPageUrl($pageId);
4950                 if (!empty($sub)) $url .= '?' . $sub;
4951                 if (!empty($param)) $url .= '&' . $param;
4952                 return $url;
4953         }
4954         /**
4955          * ウィジェット指定呼び出し用のURLを生成
4956          *
4957          * @param string $toWidgetId    送信先ウィジェットID
4958          * @param string $fromWidgetId  送信元ウィジェットID
4959          * @param string $todo                  実行パラメータ
4960          * @param string $pageId                ページID(空のときは現在のURL)
4961          * @return string                               生成したURL
4962          */
4963         function createWidgetCmdUrl($toWidgetId, $fromWidgetId, $todo, $pageId = '')
4964         {
4965                 global $gEnvManager;
4966                 
4967                 $url = $gEnvManager->createPageUrl($pageId);
4968                 
4969                 $url .= '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_FIND_WIDGET;
4970                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $toWidgetId;
4971                 if (!empty($fromWidgetId)) $url .= '&' . M3_REQUEST_PARAM_FROM . '=' . $fromWidgetId;           // 送信元
4972                 if (!empty($todo)) $url .= '&' . M3_REQUEST_PARAM_OPERATION_TODO . '=' . urlencode($todo);
4973                 return $url;
4974         }
4975         /**
4976          * RSS配信用のURLを生成
4977          *
4978          * @param string $widgetId              実行ウィジェットID
4979          * @param string $optionParam   追加パラメータ
4980          * @param string $pageId                ページID(空のときは現在のURL)
4981          * @param string $pageSubId             ページサブID
4982          * @return string                               生成したURL
4983          */
4984         function createRssCmdUrl($widgetId, $optionParam = '', $pageId = '', $pageSubId = '')
4985         {
4986                 global $gEnvManager;
4987                 
4988                 // 現在のページURLを取得
4989                 $url = $gEnvManager->createPageUrl() . '?';
4990                 
4991                 // ページサブIDを取得
4992                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // ページ共通属性ありのときは空
4993                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
4994                 
4995                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_RSS;
4996                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
4997                 if (!empty($optionParam)) $url .= '&' . $optionParam;
4998                 return $url;
4999         }
5000         /**
5001          * ウィジェット実行用のURLを生成
5002          *
5003          * @param string $widgetId      実行ウィジェットID
5004          * @param string $optionParam   追加パラメータ
5005          * @param bool $byMacro         マクロ変換で返すかどうか
5006          * @param string $pageId                ページID(空のときは現在のURL)
5007          * @param string $pageSubId             ページサブID
5008          * @return string                               生成したURL
5009          */
5010         //function createDirectWidgetCmdUrl($widgetId, $optionParam = '', $pageId = '', $pageSubId = '')
5011         function createDirectWidgetCmdUrl($widgetId, $optionParam = '', $byMacro = false, $pageId = '', $pageSubId = '')
5012         {
5013                 global $gEnvManager;
5014                 
5015                 // 現在のページURLを取得
5016                 if ($byMacro){
5017                         $url = M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END . '/' . M3_FILENAME_INDEX . '?';
5018                 } else {
5019                         $url = $gEnvManager->createPageUrl() . '?';
5020                 }
5021                 
5022                 // ページサブIDを取得
5023                 if (empty($pageSubId)) $pageSubId = $this->gEnv->getCurrentWidgetPageSubId();   // ページ共通属性ありのときは空
5024                 if (!empty($pageSubId)) $url .= M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $pageSubId . '&';
5025                 
5026                 $url .= M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_DO_WIDGET;
5027                 $url .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $widgetId;
5028                 if (!empty($optionParam)) $url .= '&' . $optionParam;
5029                 return $url;
5030         }
5031         /**
5032          * キャッシュ制御用の付加パラメータを取得
5033          *
5034          * @return string                               パラメータ
5035          */     
5036         function getCacheParam()
5037         {
5038                 $addParam = '?' . date('YmdHis');
5039                 return $addParam;
5040         }
5041         /**
5042          * 現在のURLにアクセス可能かチェック
5043          *
5044          * @param bool $isActivePage    ページが有効かどうか
5045          * @return bool                                 true=可能、false=不可
5046          */     
5047         function canAccessUrl(&$isActivePage)
5048         {
5049                 global $gEnvManager;
5050
5051                 // 現在設定されているページIDを取得
5052                 $pageId         = $gEnvManager->getCurrentPageId();
5053                 $pageSubId      = $gEnvManager->getCurrentPageSubId();
5054                 $ret = $this->db->canAccessPage($pageId, $pageSubId, $pageVisible, $pageSubVisible, $isAdminMenu);
5055                 if ($ret){              // アクセス可能なときは、ユーザ制限もチェックする
5056                         $isActivePage = true;
5057                         
5058                         // ページが表示可能かチェック
5059                         if (!$pageVisible || !$pageSubVisible) return false;
5060                         
5061                         if (!$gEnvManager->isCurrentUserLogined() && $this->isUserLimitedPage($pageId, $pageSubId)){                    // ユーザがログインされていない状態でユーザ制限されていればアクセス不可
5062                                 return false;
5063                         } else {
5064                                 $this->isAccessPointWithAdminMenu = $isAdminMenu;                               // 管理メニューを使用するアクセスポイントかどうか
5065                                 return true;
5066                         }
5067                 } else {                        // 無効ページのとき
5068                         $isActivePage = false;
5069                 }
5070                 return false;
5071         }
5072         /**
5073          * ウィジェットヘッダ(Joomla!1.0用)を出力タイプを取得
5074          *
5075          * @return int                          0=出力しない、1=Joomla!1.0テンプレートPC用、2=Joomla!1.0テンプレート携帯用
5076          */     
5077         function getTemplateWidgetHeaderType()
5078         {
5079                 global $gEnvManager;
5080                 
5081                 $templateId = $gEnvManager->getCurrentTemplateId();
5082                 if ($templateId == self::ADMIN_TEMPLATE ||              // PC管理用テンプレート
5083                         $templateId == self::M_ADMIN_TEMPLATE){         // 携帯管理用テンプレート
5084                         return 0;
5085                 } else if(strncmp($templateId, 'm/', 2) == 0){          // 携帯用テンプレート
5086                         return 2;               // 携帯テンプレート用出力
5087                 } else {
5088                         return 1;               // PCテンプレート用出力
5089                 }
5090         }
5091         /**
5092          * SSLが必要なページかどうかを判断
5093          *
5094          * @param string $pageId        ページID
5095          * @param string $pageSubId     ページサブID
5096          * @return bool                         true=必要、false=不要
5097          */     
5098         function isSslPage($pageId, $pageSubId)
5099         {
5100                 global $gEnvManager;
5101                 
5102                 // パラメータ修正
5103                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
5104                 
5105                 // 管理用ページの場合
5106                 if ($pageId == $gEnvManager->getDefaultAdminPageId()){
5107                         if ($gEnvManager->getUseSslAdmin()){            // 管理用ページにSSLを使用するかどうか
5108                                 return true;
5109                         } else {
5110                                 return false;
5111                         }
5112                 } else {                // その他のページのとき
5113                         // 一般用ページにSSLを使用しない場合は不要を返す
5114                         if (!$gEnvManager->getUseSsl()) return false;
5115                 }
5116                 
5117                 // 一般用ページでSSLを使用する場合は、データベースの設定をチェックする
5118                 $line = $this->getPageInfo($pageId, $pageSubId);
5119                 if (!empty($line)){
5120                         if ($line['pn_use_ssl']){
5121                                 return true;
5122                         } else {
5123                                 return false;
5124                         }
5125                 }
5126                 return false;
5127         }
5128         /**
5129          * ユーザ制限が必要なページかどうかを判断
5130          *
5131          * @param string $pageId        ページID
5132          * @param string $pageSubId     ページサブID
5133          * @return bool                         true=必要、false=不要
5134          */     
5135         function isUserLimitedPage($pageId, $pageSubId)
5136         {
5137                 global $gEnvManager;
5138                 
5139                 // パラメータ修正
5140                 if (empty($pageId)) $pageId = $gEnvManager->getDefaultPageId();
5141                 
5142                 $line = $this->getPageInfo($pageId, $pageSubId);
5143                 if (!empty($line)){
5144                         if ($line['pn_user_limited']){
5145                                 return true;
5146                         } else {
5147                                 return false;
5148                         }
5149                 }
5150                 return false;
5151         }
5152         /**
5153          * ページ情報を取得
5154          *
5155          * @param string $pageId        ページID
5156          * @param string $pageSubId     ページサブID
5157          * @return array                        ページ情報レコード
5158          */     
5159         function getPageInfo($pageId, $pageSubId)
5160         {
5161                 // ページ情報が空のときはデータをロード
5162                 if (empty($this->pageInfo)){
5163                         $records = $this->db->getPageInfoRecords();
5164                         $count = count($records);
5165                         $this->pageInfo = array();
5166                         for ($i = 0; $i < $count; $i++){
5167                                 $pId = $records[$i]['pn_id'] . self::PAGE_ID_SEPARATOR . $records[$i]['pn_sub_id'];
5168                                 $this->pageInfo[$pId] = $records[$i];
5169                         }
5170                 }
5171                 return $this->pageInfo[$pageId . self::PAGE_ID_SEPARATOR . $pageSubId];
5172         }
5173         /**
5174          * 現在のページ情報からテンプレートIDを取得
5175          *
5176          * @return string               テンプレートID
5177          */     
5178         function getTemplateIdFromCurrentPageInfo()
5179         {
5180                 $templateId = '';
5181                 if (!empty($this->currentPageInfo)) $templateId = $this->currentPageInfo['pn_template_id'];
5182                 return $templateId;
5183         }
5184         /**
5185          * JavascriptライブラリのIDを取得
5186          *
5187          * @param int $type                     種別(0=すべて、1=jQuery関係すべて、2=jQueryプラグインのみ)
5188          * @return array                        JavascriptライブラリのID
5189          */     
5190         function getScriptLibId($type = 0)
5191         {
5192                 // Javascriptライブラリのすべてのキーを取得
5193                 $keys = array_keys($this->libFiles);
5194                 
5195                 $destKeys = array();
5196                 for ($i = 0; $i < count($keys); $i++){
5197                         switch ($type){
5198                                 case 1:         // jQuery関係すべて
5199                                         if (strStartsWith($keys[$i], 'jquery')) $destKeys[] = $keys[$i];
5200                                         break;
5201                                 case 2:         // jQueryプラグインのみ
5202                                         if (strStartsWith($keys[$i], 'jquery.')) $destKeys[] = $keys[$i];
5203                                         break;
5204                         }
5205                 }
5206                 return $destKeys;
5207         }
5208         /**
5209          * Javascriptライブラリの情報を取得
5210          *
5211          * @param string $id            ライブラリID
5212          * @return array                        ライブラリの情報
5213          */     
5214         function getScriptLibInfo($id)
5215         {
5216                 $libInfo = $this->libFiles[$id];
5217                 if (isset($libInfo)){
5218                         return $libInfo;
5219                 } else {
5220                         return array();
5221                 }
5222         }
5223         /**
5224          * 管理画面用jQueryUIテーマのURLを取得
5225          *
5226          * @return string                       テーマURL
5227          */     
5228         function getAdminDefaultThemeUrl()
5229         {
5230 //              $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
5231                 $themeFile = $this->gEnv->getAdminUrl(true/*「admin」削除*/) . self::DEFAULT_THEME_DIR . $this->gSystem->adminDefaultTheme() . '/'. self::THEME_CSS_FILE;
5232                 return $themeFile;
5233         }
5234         /**
5235          * 一般画面用jQueryUIテーマのURLを取得
5236          *
5237          * @return string                       テーマURL
5238          */     
5239         function getDefaultThemeUrl()
5240         {
5241                 static $themeFile;
5242                 
5243                 if (!isset($themeFile)){
5244                         $themeFile = '';
5245                         $theme = $this->gSystem->defaultTheme();
5246                         if (!empty($theme)){
5247                                 $path = $this->gEnv->getSystemRootPath() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
5248                                 if (file_exists($path)) $themeFile = $this->gEnv->getRootUrl() . self::DEFAULT_THEME_DIR . $theme . '/'. self::THEME_CSS_FILE;
5249                         }
5250                 }
5251                 return $themeFile;
5252         }
5253         /**
5254          * URLパラメータ文字列作成
5255          *
5256          * @param array $paramArray                     URL作成用のパス
5257          * @return string                                       作成したURLパラメータ
5258          */
5259         function _createUrlParamStr($paramArray)
5260         {
5261                 $destParam = '';
5262                 if (count($paramArray) == 0) return $destParam;
5263
5264                 $sortParam = array();
5265                 $keys = array_keys($paramArray);
5266                 $keyCount = count($keys);
5267                 for ($i = 0; $i < $keyCount; $i++){
5268                         $key = $keys[$i];
5269                         $value = $paramArray[$key];
5270                         $orderNo = $this->urlParamOrder[$key];
5271                         if (!isset($orderNo)) $orderNo = 100;
5272                         $sortParam[] = array('key' => $key, 'value' => $value, 'no' => $orderNo);
5273                 }
5274                 usort($sortParam, create_function('$a,$b', 'return $a["no"] - $b["no"];'));
5275                 
5276                 // 文字列を作成
5277                 $sortCount = count($sortParam);
5278                 for ($i = 0; $i < $sortCount; $i++){
5279                         if ($i > 0) $destParam .= '&';
5280                         $destParam .= rawurlencode($sortParam[$i]['key']) . '=' . rawurlencode($sortParam[$i]['value']);
5281                 }
5282                 return $destParam;
5283         }
5284 }
5285 ?>