OSDN Git Service

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