OSDN Git Service

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