OSDN Git Service

「ブログメイン」ウィジェット更新。
[magic3/magic3.git] / widgets / blog_main / include / container / blog_mainEntryWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
9  * @package    Magic3 Framework
10  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11  * @copyright  Copyright 2006-2015 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id$
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() .    '/admin_blog_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() .   '/blog_mainDb.php');
18 require_once($gEnvManager->getCommonPath() . '/valueCheck.php');
19
20 // このファイルはadmin_blog_mainEntryWidgetContainer.phpの内容と同じ。クラス名の定義のみ異なる。
21 //class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetContainer
22 class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer
23 {
24         private $serialNo;              // 選択中の項目のシリアル番号
25         private $entryId;
26         private $blogId;                // 所属ブログ
27         private $langId;                // 現在の選択言語
28         private $serialArray = array();         // 表示されている項目シリアル番号
29         private $categoryListData;              // 全記事カテゴリー
30         private $categoryArray;                 // 選択中の記事カテゴリー
31         private $categoryCount;                 // カテゴリ数
32         private $isMultiLang;                   // 多言語対応画面かどうか
33         private $fieldValueArray;               // ユーザ定義フィールド入力値
34         const ICON_SIZE = 32;           // アイコンのサイズ
35         const CONTENT_TYPE = 'bg';              // 記事参照数取得用
36         const DEFAULT_LIST_COUNT = 20;                  // 最大リスト表示数
37         const LINK_PAGE_COUNT           = 20;                   // リンクページ数
38         const CATEGORY_NAME_SIZE = 20;                  // カテゴリー名の最大文字列長
39         const CALENDAR_ICON_FILE = '/images/system/calendar.png';               // カレンダーアイコン
40         const ACTIVE_ICON_FILE = '/images/system/active32.png';                 // 公開中アイコン
41         const INACTIVE_ICON_FILE = '/images/system/inactive32.png';             // 非公開アイコン
42         const SEARCH_ICON_FILE = '/images/system/search16.png';         // 検索用アイコン
43         const NO_BLOG_NAME = '所属なし';            // 所属ブログなし
44         const FIELD_HEAD = 'item_';                     // フィールド名の先頭文字列
45         
46         /**
47          * コンストラクタ
48          */
49         function __construct()
50         {
51                 // 親クラスを呼び出す
52                 parent::__construct();
53                 
54                 $this->isMultiLang = $this->gEnv->isMultiLanguageSite();                        // 多言語対応画面かどうか
55         }
56         /**
57          * テンプレートファイルを設定
58          *
59          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
60          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
61          *
62          * @param RequestManager $request               HTTPリクエスト処理クラス
63          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
64          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
65          */
66         function _setTemplate($request, &$param)
67         {
68                 $task = $request->trimValueOf('task');
69                 
70                 if ($task == 'entry_detail'){           // 詳細画面
71                         return 'admin_entry_detail.tmpl.html';
72                 } else {                        // 一覧画面
73                         return 'admin_entry.tmpl.html';
74                 }
75         }
76         /**
77          * テンプレートにデータ埋め込む
78          *
79          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
80          *
81          * @param RequestManager $request               HTTPリクエスト処理クラス
82          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
83          * @param                                                               なし
84          */
85         function _assign($request, &$param)
86         {
87                 $task = $request->trimValueOf('task');
88                 if ($task == 'entry_detail'){   // 詳細画面
89                         return $this->createDetail($request);
90                 } else {                        // 一覧画面
91                         return $this->createList($request);
92                 }
93         }
94         /**
95          * JavascriptファイルをHTMLヘッダ部に設定
96          *
97          * JavascriptファイルをHTMLのheadタグ内に追加出力する。
98          * _assign()よりも後に実行される。
99          *
100          * @param RequestManager $request               HTTPリクエスト処理クラス
101          * @param object         $param                 任意使用パラメータ。
102          * @return string                                               Javascriptファイル。出力しない場合は空文字列を設定。
103          */
104         function _addScriptFileToHead($request, &$param)
105         {
106                 $scriptArray = array($this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SCRIPT_FILE),          // カレンダースクリプトファイル
107                                                         $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_LANG_FILE), // カレンダー言語ファイル
108                                                         $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SETUP_FILE));       // カレンダーセットアップファイル
109                 return $scriptArray;
110
111         }
112         /**
113          * CSSファイルをHTMLヘッダ部に設定
114          *
115          * CSSファイルをHTMLのheadタグ内に追加出力する。
116          * _assign()よりも後に実行される。
117          *
118          * @param RequestManager $request               HTTPリクエスト処理クラス
119          * @param object         $param                 任意使用パラメータ。
120          * @return string                                               CSS文字列。出力しない場合は空文字列を設定。
121          */
122         function _addCssFileToHead($request, &$param)
123         {
124                 return $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_CSS_FILE);
125         }
126         /**
127          * 一覧画面作成
128          *
129          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
130          *
131          * @param RequestManager $request               HTTPリクエスト処理クラス
132          * @param                                                               なし
133          */
134         function createList($request)
135         {
136                 // ユーザ情報、表示言語
137                 $defaultLangId = $this->gEnv->getDefaultLanguage();
138                 
139                 $act = $request->trimValueOf('act');
140                 $this->langId = $request->trimValueOf('item_lang');                             // 現在メニューで選択中の言語
141                 if (empty($this->langId)) $this->langId = $defaultLangId;                       // 言語が選択されていないときは、デフォルト言語を設定
142                 if ($this->gEnv->isAdminDirAccess()){           // 管理画面へのアクセスの場合
143                         $this->blogId = null;   // デフォルトブログ(ブログID空)を含むすべてのブログ記事にアクセス可能
144                 } else {
145                         $this->blogId = $request->trimValueOf(M3_REQUEST_PARAM_BLOG_ID);                // 所属ブログ
146                 }
147                 
148                 // ##### 検索条件 #####
149                 $pageNo = $request->trimIntValueOf(M3_REQUEST_PARAM_PAGE_NO, '1');                              // ページ番号
150                 
151                 // DBの保存設定値を取得
152                 $maxListCount = self::DEFAULT_LIST_COUNT;
153                 $serializedParam = $this->_db->getWidgetParam($this->gEnv->getCurrentWidgetId());
154                 if (!empty($serializedParam)){
155                         $dispInfo = unserialize($serializedParam);
156                         $maxListCount = $dispInfo->maxMemberListCountByAdmin;           // 会員リスト最大表示数
157                 }
158
159                 $search_startDt = $request->trimValueOf('search_start');                // 検索範囲開始日付
160                 if (!empty($search_startDt)) $search_startDt = $this->convertToProperDate($search_startDt);
161                 $search_endDt = $request->trimValueOf('search_end');                    // 検索範囲終了日付
162                 if (!empty($search_endDt)) $search_endDt = $this->convertToProperDate($search_endDt);
163                 $search_categoryId = $request->trimValueOf('search_category0');                 // 検索カテゴリー
164                 $search_keyword = $request->trimValueOf('search_keyword');                      // 検索キーワード
165                 
166                 // カテゴリーを格納
167                 $this->categoryArray = array();
168                 if (!empty($search_categoryId)){                // 0以外の値を取得
169                         $this->categoryArray[] = $search_categoryId;
170                 }
171
172                 if ($act == 'delete'){          // 項目削除の場合
173                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
174                         $delItems = array();
175                         for ($i = 0; $i < count($listedItem); $i++){
176                                 // 項目がチェックされているかを取得
177                                 $itemName = 'item' . $i . '_selected';
178                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
179                                 
180                                 if ($itemValue){                // チェック項目
181                                         $delItems[] = $listedItem[$i];
182                                 }
183                         }
184                         if (count($delItems) > 0){
185                                 // 削除するブログ記事の情報を取得
186                                 $delEntryInfo = array();
187                                 for ($i = 0; $i < count($delItems); $i++){
188                                         $ret = self::$_mainDb->getEntryBySerial($delItems[$i], $row, $categoryRow);
189                                         if ($ret){
190                                                 $newInfoObj = new stdClass;
191                                                 $newInfoObj->entryId = $row['be_id'];           // 記事ID
192                                                 $newInfoObj->name = $row['be_name'];            // 記事タイトル
193                                                 $newInfoObj->thumb = $row['be_thumb_filename'];         // サムネール
194                                                 $delEntryInfo[] = $newInfoObj;
195                                         }
196                                 }
197                                 
198                                 $ret = self::$_mainDb->delEntryItem($delItems);
199                                 if ($ret){              // データ削除成功のとき
200                                         $this->setGuidanceMsg('データを削除しました');
201                                         
202                                         // ##### サムネールの削除 #####
203                                         for ($i = 0; $i < count($delEntryInfo); $i++){
204                                                 $infoObj = $delEntryInfo[$i];
205 //                                              $ret = blog_mainCommonDef::removeThumbnail($infoObj->entryId);
206                                                 
207                                                 if (!empty($infoObj->thumb)){
208                                                         //$oldFiles = explode(';', $infoObj->thumb);
209                                                         //$this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $oldFiles);
210                                                         
211                                                         // アイキャッチ画像削除
212                                                         blog_mainCommonDef::removerEyecatchImage($infoObj->entryId);
213                                                 }
214                                         }
215
216                                         // キャッシュデータのクリア
217                                         for ($i = 0; $i < count($delItems); $i++){
218                                                 $this->clearCacheBySerial($delItems[$i]);
219                                         }
220                                         
221                                         // 親ウィンドウを更新
222                                         $this->gPage->updateParentWindow();
223                                         
224                                         // 運用ログを残す
225                                         for ($i = 0; $i < count($delEntryInfo); $i++){
226                                                 $infoObj = $delEntryInfo[$i];
227                                                 //$this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $infoObj->name, 2100, 'ID=' . $infoObj->entryId);
228                                                 $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_BLOG,
229                                                                                                 M3_EVENT_HOOK_PARAM_CONTENT_ID          => $infoObj->entryId,
230                                                                                                 M3_EVENT_HOOK_PARAM_UPDATE_DT           => date("Y/m/d H:i:s"));
231                                                 $this->writeUserInfoEvent(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $infoObj->name, 2402, 'ID=' . $infoObj->entryId, $eventParam);
232                                         }
233                                 } else {
234                                         $this->setAppErrorMsg('データ削除に失敗しました');
235                                 }
236                         }
237                 } else if ($act == 'search'){           // 検索のとき
238                         if (!empty($search_startDt) && !empty($search_endDt) && $search_startDt > $search_endDt){
239                                 $this->setUserErrorMsg('期間の指定範囲にエラーがあります。');
240                         }
241                         $pageNo = 1;            // ページ番号初期化
242                 } else if ($act == 'selpage'){                  // ページ選択
243                 }
244                 // ###### 一覧の取得条件を作成 ######
245                 if (!empty($search_endDt)) $endDt = $this->getNextDay($search_endDt);
246                 
247                 // 総数を取得
248                 $totalCount = self::$_mainDb->getEntryItemCount($search_startDt, $endDt, $this->categoryArray, $search_keyword, $this->langId, $this->blogId);
249
250                 // ページング計算
251                 $this->calcPageLink($pageNo, $totalCount, $maxListCount);
252                 
253                 // ページングリンク作成
254                 $pageLink = $this->createPageLink($pageNo, self::LINK_PAGE_COUNT, ''/*リンク作成用(未使用)*/, 'selpage($1);return false;');
255                 
256                 // 記事項目リストを取得
257                 self::$_mainDb->searchEntryItems($maxListCount, $pageNo, $search_startDt, $endDt, $this->categoryArray, $search_keyword, $this->langId, array($this, 'itemListLoop'), $this->blogId);
258                 if (count($this->serialArray) <= 0) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');// 投稿記事がないときは、一覧を表示しない
259                 
260                 // カテゴリーメニューを作成
261                 self::$_mainDb->getAllCategory($this->langId, $this->categoryListData);
262                 $this->createCategoryMenu(1);           // メニューは1つだけ表示
263                 
264                 // プレビュー用URL
265                 $previewUrl = $this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_PAGE_SUB_ID . '=' . $this->gEnv->getPageSubIdByContentType($this->gEnv->getDefaultPageId(), M3_VIEW_TYPE_BLOG);
266                 $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_PREVIEW;
267 //              if ($this->isMultiLang) $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_LANG . '=' . $this->langId;             // 多言語対応の場合は言語IDを付加
268                 $this->tmpl->addVar('_widget', 'preview_url', $previewUrl);// プレビュー用URL(一般画面)
269                 
270                 // 検索結果
271                 $this->tmpl->addVar("_widget", "page_link", $pageLink);
272                 $this->tmpl->addVar("_widget", "total_count", $totalCount);
273                 
274                 // 検索条件
275                 $this->tmpl->addVar("_widget", "search_start", $search_startDt);        // 開始日付
276                 $this->tmpl->addVar("_widget", "search_end", $search_endDt);    // 終了日付
277                 $this->tmpl->addVar("_widget", "search_keyword", $search_keyword);      // 検索キーワード
278
279                 // 非表示項目を設定
280                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
281                 $this->tmpl->addVar("_widget", "page", $pageNo);        // ページ番号
282                 $this->tmpl->addVar("_widget", "list_count", $maxListCount);    // 一覧表示項目数
283         }
284         /**
285          * 詳細画面作成
286          *
287          * @param RequestManager $request               HTTPリクエスト処理クラス
288          * @param                                                               なし
289          */
290         function createDetail($request)
291         {
292                 // デフォルト値
293                 $defaultLangId  = $this->gEnv->getDefaultLanguage();
294                 $regUserId              = $this->gEnv->getCurrentUserId();                      // 記事投稿ユーザ
295                 //$regDt                        = date("Y/m/d H:i:s");                                          // 投稿日時
296                 
297                 // ブログ定義値
298                 $useMultiBlog = self::$_configArray[blog_mainCommonDef::CF_USE_MULTI_BLOG];// マルチブログを使用するかどうか
299                 $useComment = self::$_configArray[blog_mainCommonDef::CF_RECEIVE_COMMENT];// コメント機能を使用するかどうか
300                 $this->categoryCount = self::$_configArray[blog_mainCommonDef::CF_CATEGORY_COUNT];                      // カテゴリ数
301                 if (empty($this->categoryCount)) $this->categoryCount = self::DEFAULT_CATEGORY_COUNT;
302                 
303                 // コンテンツレイアウトを取得
304                 $contentLayout = array(self::$_configArray[blog_mainCommonDef::CF_LAYOUT_ENTRY_SINGLE], self::$_configArray[blog_mainCommonDef::CF_LAYOUT_ENTRY_LIST]);
305                 $fieldInfoArray = blog_mainCommonDef::parseUserMacro($contentLayout);
306                 
307                 // 入力値を取得
308                 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);              // ウィンドウオープンタイプ
309                 $act = $request->trimValueOf('act');
310                 $this->langId = $request->trimValueOf('item_lang');                             // 現在メニューで選択中の言語
311                 if (empty($this->langId)) $this->langId = $defaultLangId;                       // 言語が選択されていないときは、デフォルト言語を設定  
312                 $this->entryId = $request->trimValueOf('entryid');              // 記事エントリーID
313                 $this->serialNo = $request->trimValueOf('serial');              // 選択項目のシリアル番号
314 //              if (empty($this->serialNo)) $this->serialNo = 0;
315                 $this->blogId = $request->trimValueOf(M3_REQUEST_PARAM_BLOG_ID);                // 所属ブログ
316                 $name = $request->trimValueOf('item_name');
317                 $entry_date = $request->trimValueOf('item_entry_date');         // 投稿日
318                 $entry_time = $request->trimValueOf('item_entry_time');         // 投稿時間
319                 $html = $request->valueOf('item_html');
320                 $html2 = $request->valueOf('item_html2');
321                 if (strlen($html2) <= 10){ // IE6のときFCKEditorのバグの対応(「続き」が空の場合でもpタグが送信される)
322                         $html2 = '';
323                 }
324                 $desc = $request->trimValueOf('item_desc');             // 簡易説明
325                 $status = $request->trimValueOf('item_status');         // エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
326                 $category = '';                                                                 // カテゴリー
327                 $showComment = ($request->trimValueOf('show_comment') == 'on') ? 1 : 0;                         // コメントを表示するかどうか
328                 $receiveComment = ($request->trimValueOf('receive_comment') == 'on') ? 1 : 0;           // コメントを受け付けるかどうか
329                 $relatedContent = $request->trimValueOf('item_related_content');        // 関連コンテンツ
330                 if (!$useComment){              // コメント機能を使用しない場合のデフォルト値
331                         $showComment = 1;                               // コメントを表示するかどうか
332                         $receiveComment = 1;            // コメントを受け付けるかどうか
333                 }
334                 
335                 // カテゴリーを取得
336                 $this->categoryArray = array();
337                 for ($i = 0; $i < $this->categoryCount; $i++){
338                         $itemName = 'item_category' . $i;
339                         $itemValue = $request->trimValueOf($itemName);
340                         if (!empty($itemValue)){                // 0以外の値を取得
341                                 $this->categoryArray[] = $itemValue;
342                         }
343                 }
344
345                 // 公開期間を取得
346                 $start_date = $request->trimValueOf('item_start_date');         // 公開期間開始日付
347                 if (!empty($start_date)) $start_date = $this->convertToProperDate($start_date);
348                 $start_time = $request->trimValueOf('item_start_time');         // 公開期間開始時間
349                 if (empty($start_date)){
350                         $start_time = '';                                       // 日付が空のときは時刻も空に設定する
351                 } else {
352                         if (empty($start_time)) $start_time = '00:00';          // 日付が入っているときは時間にデフォルト値を設定
353                 }
354                 if (!empty($start_time)) $start_time = $this->convertToProperTime($start_time, 1/*時分フォーマット*/);
355                 
356                 $end_date = $request->trimValueOf('item_end_date');             // 公開期間終了日付
357                 if (!empty($end_date)) $end_date = $this->convertToProperDate($end_date);
358                 $end_time = $request->trimValueOf('item_end_time');             // 公開期間終了時間
359                 if (empty($end_date)){
360                         $end_time = '';                                 // 日付が空のときは時刻も空に設定する
361                 } else {
362                         if (empty($end_time)) $end_time = '00:00';              // 日付が入っているときは時間にデフォルト値を設定
363                 }
364                 if (!empty($end_time)) $end_time = $this->convertToProperTime($end_time, 1/*時分フォーマット*/);
365                 
366                 // ユーザ定義フィールド入力値取得
367                 $this->fieldValueArray = array();               // ユーザ定義フィールド入力値
368                 $fieldKeys = array_keys($fieldInfoArray);
369                 for ($i = 0; $i < count($fieldKeys); $i++){
370                         $fieldKey = $fieldKeys[$i];
371                         $itemName = self::FIELD_HEAD . $fieldKey;
372                         $itemValue = $this->cleanMacroValue($request->trimValueOf($itemName));
373                         if (!empty($itemValue)) $this->fieldValueArray[$fieldKey] = $itemValue;
374                 }
375                 
376                 $historyIndex = -1;     // 履歴番号初期化(旧データの場合のみ有効)
377                 $reloadData = false;            // データの再ロード
378                 if ($act == 'select'){          // 一覧から選択のとき
379                         $reloadData = true;             // データの再ロード
380                 } else if ($act == 'new'){
381                         $this->serialNo = 0;
382                         $reloadData = true;             // データの再読み込み
383                 } else if ($act == 'selectlang'){               // 項目選択の場合
384                         // 登録済みのコンテンツデータを取得
385                         $this->serialNo = self::$_mainDb->getEntrySerialNoByContentId($this->entryId, $this->langId);
386                         if (empty($this->serialNo)){
387                                 // 取得できないときは一部初期化
388                                 //$name = '';                           // タイトル
389                                 //$html = '';                           // HTML
390                                 $status = 0;                            // エントリー状況
391                                 $reg_user = '';                         // 投稿者
392                                 $update_user = '';// 更新者
393                                 $update_dt = '';                                                        
394                         } else {
395                                 $reloadData = true;             // データの再ロード
396                         }
397                 } else if ($act == 'add' || $act == 'addlang'){         // 項目追加の場合
398                         // 入力チェック
399                         $this->checkInput($name, 'タイトル');
400                         $this->checkDate($entry_date, '投稿日付');
401                         $this->checkTime($entry_time, '投稿時間');
402                                         
403                         // 期間範囲のチェック
404                         if (!empty($start_date) && !empty($end_date)){
405                                 if (strtotime($start_date . ' ' . $start_time) >= strtotime($end_date . ' ' . $end_time)) $this->setUserErrorMsg('公開期間が不正です');
406                         }
407                         
408                         // 関連コンテンツのチェック
409                         if (!empty($relatedContent)){
410                                 $contentIdArray = explode(',', $relatedContent);
411                                 if (!ValueCheck::isNumeric($contentIdArray)) $this->setUserErrorMsg('関連コンテンツにエラー値があります');// すべて数値であるかチェック
412                         }
413                                         
414                         // エラーなしの場合は、データを登録
415                         if ($this->getMsgCount() == 0){
416                                 // 保存データ作成
417                                 if (empty($start_date)){
418                                         $startDt = $this->gEnv->getInitValueOfTimestamp();
419                                 } else {
420                                         $startDt = $start_date . ' ' . $start_time;
421                                 }
422                                 if (empty($end_date)){
423                                         $endDt = $this->gEnv->getInitValueOfTimestamp();
424                                 } else {
425                                         $endDt = $end_date . ' ' . $end_time;
426                                 }
427                                 $regDt = $this->convertToProperDate($entry_date) . ' ' . $this->convertToProperTime($entry_time);               // 投稿日時
428                                 
429                                 // サムネール画像を取得
430                                 $thumbFilename = '';
431                                 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){         // // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
432                                         // 次の記事IDを取得
433                                         $nextEntryId = self::$_mainDb->getNextEntryId();
434                                 
435                                         if ($status == 2){              // 記事公開の場合のみアイキャッチ画像を作成
436                                                 $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html);
437                                                 if (empty($thumbPath) && !empty($html2)) $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html2);           // 本文1に画像がないときは本文2を検索
438                                                 if (!empty($thumbPath)){
439                                                         $ret = $this->gInstance->getImageManager()->createSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $nextEntryId, $thumbPath, $destFilename);
440                                                         if ($ret) $thumbFilename = implode(';', $destFilename);
441                                                 }
442                                         }
443                                 }
444                                 
445                                 // 追加パラメータ
446                                 $otherParams = array(   'be_description'                => $desc,               // 簡易説明
447                                                                                 'be_thumb_filename'             => $thumbFilename,              // サムネールファイル名
448                                                                                 'be_related_content'    => $relatedContent,             // 関連コンテンツ
449                                                                                 'be_option_fields'              => $this->serializeArray($this->fieldValueArray));                              // ユーザ定義フィールド値
450                                 //if ($act == 'add'){
451                                 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){         // 多言語でデフォルト言語、または単一言語のとき
452                                         $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, 
453                                                                                                         $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
454                                 } else {
455                                         $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, 
456                                                                                                         $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
457                                 }
458                                 if ($ret){
459                                         $this->setGuidanceMsg('データを追加しました');
460                                         
461                                         // シリアル番号更新
462                                         $this->serialNo = $newSerial;
463                                         $reloadData = true;             // データの再ロード
464                                         
465                                         // ##### サムネールの作成 #####
466 /*                                      $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
467                                         if ($ret){
468                                                 $entryId        = $row['be_id'];                // 記事ID
469                                                 $html           = $row['be_html'];                              // HTML
470                                                 $updateDt       = $row['be_create_dt'];
471                                                 $status         = $row['be_status'];
472                                 
473                                                 if ($status == 2){              // 公開の場合
474                                                         $ret = blog_mainCommonDef::createThumbnail($html, $entryId, $updateDt);
475                                                 } else {
476                                                         $ret = blog_mainCommonDef::removeThumbnail($entryId);
477                                                 }
478                                         }*/
479                                         
480                                         // キャッシュデータのクリア
481                                         $this->clearCacheBySerial($this->serialNo);
482                                         
483                                         // 親ウィンドウを更新
484                                         $this->gPage->updateParentWindow();
485                                         
486                                         // 運用ログを残す
487                                         $statusStr = '';
488                                         $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
489                                         if ($ret){
490                                                 $this->entryId = $row['be_id'];         // 記事ID
491                                                 $name = $row['be_name'];                // コンテンツ名前
492                                                 $updateDt = $row['be_create_dt'];               // 作成日時
493                                                 
494                                                 // 公開状態
495                                                 switch ($row['be_status']){
496                                                         case 1: $statusStr = '編集中';       break;
497                                                         case 2: $statusStr = '公開';  break;
498                                                         case 3: $statusStr = '非公開';       break;
499                                                 }
500                                         }
501                                         //$this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を追加(' . $statusStr . ')しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
502                                         $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_BLOG,
503                                                                                         M3_EVENT_HOOK_PARAM_CONTENT_ID          => $this->entryId,
504                                                                                         M3_EVENT_HOOK_PARAM_UPDATE_DT           => $updateDt);
505                                         $this->writeUserInfoEvent(__METHOD__, 'ブログ記事を追加(' . $statusStr . ')しました。タイトル: ' . $name, 2400, 'ID=' . $this->entryId, $eventParam);
506                                 } else {
507                                         $this->setAppErrorMsg('データ追加に失敗しました');
508                                 }
509                         }
510                 } else if ($act == 'update'){           // 項目更新の場合
511                         // 入力チェック
512                         $this->checkInput($name, 'タイトル');
513                         $this->checkDate($entry_date, '投稿日付');
514                         $this->checkTime($entry_time, '投稿時間');
515                         
516                         // 期間範囲のチェック
517                         if (!empty($start_date) && !empty($end_date)){
518                                 if (strtotime($start_date . ' ' . $start_time) >= strtotime($end_date . ' ' . $end_time)) $this->setUserErrorMsg('公開期間が不正です');
519                         }
520                         
521                         // 関連コンテンツのチェック
522                         if (!empty($relatedContent)){
523                                 $contentIdArray = explode(',', $relatedContent);
524                                 if (!ValueCheck::isNumeric($contentIdArray)) $this->setUserErrorMsg('関連コンテンツにエラー値があります');// すべて数値であるかチェック
525                         }
526                         
527                         // エラーなしの場合は、データを更新
528                         if ($this->getMsgCount() == 0){
529                                 // 保存データ作成
530                                 if (empty($start_date)){
531                                         $startDt = $this->gEnv->getInitValueOfTimestamp();
532                                 } else {
533                                         $startDt = $start_date . ' ' . $start_time;
534                                 }
535                                 if (empty($end_date)){
536                                         $endDt = $this->gEnv->getInitValueOfTimestamp();
537                                 } else {
538                                         $endDt = $end_date . ' ' . $end_time;
539                                 }
540                                 $regDt = $this->convertToProperDate($entry_date) . ' ' . $this->convertToProperTime($entry_time);               // 投稿日時
541                                 
542                                 // サムネール画像を取得
543                                 $thumbFilename = '';
544                                 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){         // // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
545                                         if ($status == 2){              // 記事公開の場合のみアイキャッチ画像を作成
546                                                 // コンテンツからアイキャッチ画像を作成
547                                                 $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html);
548                                                 if (empty($thumbPath) && !empty($html2)) $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html2);           // 本文1に画像がないときは本文2を検索
549                                                 if (!empty($thumbPath)){
550                                                         $ret = $this->gInstance->getImageManager()->createSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $this->entryId, $thumbPath, $destFilename);
551                                                         if ($ret) $thumbFilename = implode(';', $destFilename);
552                                                 }
553                                         
554                                                 // 非公開ディレクトリのアイキャッチ画像をコピー
555                                                 $ret = blog_mainCommonDef::copyEyecatchImageToPublicDir($this->entryId);
556                                                 if ($ret){                      // アイキャッチ画像をコピーした場合は、ファイル名を取得
557                                                         // 画像ファイル名、フォーマット取得
558                                                         list($destFilename, $formats) = $this->gInstance->getImageManager()->getSystemDefaultThumbFilename($this->entryId, 1/*クロップ画像のみ*/);
559                                                         $thumbFilename = implode(';', $destFilename);
560                                                 }
561                                         } else {                // 記事非公開の場合
562                                                 // 公開ディレクトリのアイキャッチ画像を削除
563                                                 blog_mainCommonDef::removerEyecatchImageInPublicDir($this->entryId);
564                                         }
565                                 }
566
567                                 // 追加パラメータ
568                                 $otherParams = array(   'be_description'                => $desc,               // 簡易説明
569                                                                                 'be_thumb_filename'             => $thumbFilename,              // サムネールファイル名
570                                                                                 'be_related_content'    => $relatedContent,             // 関連コンテンツ
571                                                                                 'be_option_fields'              => $this->serializeArray($this->fieldValueArray));                              // ユーザ定義フィールド値
572
573                                 // 履歴からのデータ取得の場合はシリアル番号を最新に変更
574                                 $mode = $request->trimValueOf('mode');                  // データ更新モード
575                                 if ($mode == 'history'){                // 履歴データ表示モード
576                                         $this->serialNo = self::$_mainDb->getEntrySerialNoByContentId($this->entryId, $this->langId);           // 最新のシリアル番号を取得
577                                         
578                                         // ### 履歴データを再取得すべき? ###
579                                 }
580                         
581                                 $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $this->blogId, 
582                                                                                                         ''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams);
583 /*                              if ($ret){
584                                         // コンテンツに画像がなくなった場合は、サムネールを削除
585                                         if (empty($thumbFilename) && !empty($oldRecord['be_thumb_filename'])){
586                                                 $oldFiles = explode(';', $oldRecord['be_thumb_filename']);
587                                                 $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $oldFiles);
588                                         }
589                                 }*/
590                                 
591                                 if ($ret){
592                                         $this->setGuidanceMsg('データを更新しました');
593                                         
594                                         // シリアル番号更新
595                                         $this->serialNo = $newSerial;
596                                         $reloadData = true;             // データの再ロード
597                                         
598 /*                                      // ##### サムネールの作成 #####
599                                         $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
600                                         if ($ret){
601                                                 $entryId        = $row['be_id'];                // 記事ID
602                                                 $html           = $row['be_html'];                              // HTML
603                                                 $updateDt       = $row['be_create_dt'];
604                                                 $status         = $row['be_status'];
605                                 
606                                                 if ($status == 2){              // 公開の場合
607                                                         $ret = blog_mainCommonDef::createThumbnail($html, $entryId, $updateDt);
608                                                 } else {
609                                                         $ret = blog_mainCommonDef::removeThumbnail($entryId);
610                                                 }
611                                         }*/
612                                         
613                                         // キャッシュデータのクリア
614                                         $this->clearCacheBySerial($this->serialNo);
615                                         
616                                         // 親ウィンドウを更新
617                                         $this->gPage->updateParentWindow();
618                                         
619                                         // 運用ログを残す
620                                         $statusStr = '';
621                                         $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
622                                         if ($ret){
623                                                 $this->entryId = $row['be_id'];         // 記事ID
624                                                 $name = $row['be_name'];                // コンテンツ名前
625                                                 $updateDt = $row['be_create_dt'];               // 作成日時
626                                                 
627                                                 // 公開状態
628                                                 switch ($row['be_status']){
629                                                         case 1: $statusStr = '編集中';       break;
630                                                         case 2: $statusStr = '公開';  break;
631                                                         case 3: $statusStr = '非公開';       break;
632                                                 }
633                                         }
634                                         //$this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を更新(' . $statusStr . ')しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
635                                         $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_BLOG,
636                                                                                         M3_EVENT_HOOK_PARAM_CONTENT_ID          => $this->entryId,
637                                                                                         M3_EVENT_HOOK_PARAM_UPDATE_DT           => $updateDt);
638                                         $this->writeUserInfoEvent(__METHOD__, 'ブログ記事を更新(' . $statusStr . ')しました。タイトル: ' . $name, 2401, 'ID=' . $this->entryId, $eventParam);
639                                 } else {
640                                         $this->setAppErrorMsg('データ更新に失敗しました');
641                                 }
642                         }                               
643                 } else if ($act == 'delete'){           // 項目削除の場合
644                         if (empty($this->serialNo)){
645                                 $this->setUserErrorMsg('削除項目が選択されていません');
646                         }
647                         // エラーなしの場合は、データを削除
648                         if ($this->getMsgCount() == 0){
649                                 // 削除するブログ記事の情報を取得
650                                 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
651                                 if ($ret){
652                                         $this->entryId = $row['be_id'];         // 記事ID
653                                         $name = $row['be_name'];                // コンテンツ名前
654                                 }
655                                         
656                                 $ret = self::$_mainDb->delEntryItem(array($this->serialNo));
657                                 if ($ret){              // データ削除成功のとき
658                                         $this->setGuidanceMsg('データを削除しました');
659                                         
660                                         // ##### サムネールの削除 #####
661 //                                      $ret = blog_mainCommonDef::removeThumbnail($this->entryId);
662                                         
663                                         // サムネールを削除
664                                         if (!empty($row['be_thumb_filename'])){
665 //                                              $oldFiles = explode(';', $row['be_thumb_filename']);
666 //                                              $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $oldFiles);
667                                                 
668                                                 // アイキャッチ画像削除
669                                                 blog_mainCommonDef::removerEyecatchImage($this->entryId);
670                                         }
671                                                 
672                                         // キャッシュデータのクリア
673                                         $this->clearCacheBySerial($this->serialNo);
674                                         
675                                         // 親ウィンドウを更新
676                                         $this->gPage->updateParentWindow();
677                                         
678                                         // 運用ログを残す
679                                         //$this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
680                                         $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_BLOG,
681                                                                                         M3_EVENT_HOOK_PARAM_CONTENT_ID          => $this->entryId,
682                                                                                         M3_EVENT_HOOK_PARAM_UPDATE_DT           => date("Y/m/d H:i:s"));
683                                         $this->writeUserInfoEvent(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $name, 2402, 'ID=' . $this->entryId, $eventParam);
684                                 } else {
685                                         $this->setAppErrorMsg('データ削除に失敗しました');
686                                 }
687                         }
688                 } else if ($act == 'deleteid'){         // ID項目削除の場合
689                         if (empty($this->serialNo)){
690                                 $this->setUserErrorMsg('削除項目が選択されていません');
691                         }
692                         // エラーなしの場合は、データを削除
693                         if ($this->getMsgCount() == 0){
694                                 // 削除するブログ記事の情報を取得
695                                 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
696                                 if ($ret){
697                                         $this->entryId = $row['be_id'];         // 記事ID
698                                         $name = $row['be_name'];                // コンテンツ名前
699                                 }
700                                 
701                                 $ret = self::$_mainDb->delEntryItemById($this->serialNo);
702                                 if ($ret){              // データ削除成功のとき
703                                         $this->setGuidanceMsg('データを削除しました');
704                                         
705                                         // ##### サムネールの削除 #####
706 //                                      $ret = blog_mainCommonDef::removeThumbnail($this->entryId);
707                                         
708                                         // アイキャッチ画像削除
709                                         blog_mainCommonDef::removerEyecatchImage($this->entryId);
710                                                 
711                                         // キャッシュデータのクリア
712                                         $this->clearCacheBySerial($this->serialNo);
713                                         
714                                         // 親ウィンドウを更新
715                                         $this->gPage->updateParentWindow();
716                                         
717                                         // 運用ログを残す
718                                         //$this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
719                                         $eventParam = array(    M3_EVENT_HOOK_PARAM_CONTENT_TYPE        => M3_VIEW_TYPE_BLOG,
720                                                                                         M3_EVENT_HOOK_PARAM_CONTENT_ID          => $this->entryId,
721                                                                                         M3_EVENT_HOOK_PARAM_UPDATE_DT           => date("Y/m/d H:i:s"));
722                                         $this->writeUserInfoEvent(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $name, 2402, 'ID=' . $this->entryId, $eventParam);
723                                 } else {
724                                         $this->setAppErrorMsg('データ削除に失敗しました');
725                                 }
726                         }
727                 } else if ($act == 'get_history'){              // 履歴データの取得のとき
728                         $reloadData = true;             // データの再読み込み
729                 } else {        // 初期画面表示のとき
730                         // ##### ブログ記事IDが設定されているとき(他ウィジェットからの表示)は、データを取得 #####
731                         if (empty($this->entryId)){
732                                 if (!empty($this->serialNo)){           // シリアル番号で指定の場合
733                                         $reloadData = true;             // データの再読み込み
734                                 }
735                         } else {
736                                 // 多言語対応の場合は、言語を取得
737                                 if ($this->isMultiLang){                // 多言語対応の場合
738                                         $langId = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_LANG);               // lang値を取得
739                                         if (!empty($langId)) $this->langId = $langId;
740                                 }
741                 
742                                 // ブログ記事を取得
743                                 $ret = self::$_mainDb->getEntryItem($this->entryId, $this->langId, $row);
744                                 if ($ret){
745                                         $this->serialNo = $row['be_serial'];            // シリアル番号
746                                         $reloadData = true;             // データの再読み込み
747                                 } else {
748                                         $this->serialNo = 0;
749                                 }
750                         }
751                         if (empty($this->serialNo)){
752                                 // 初期値設定
753                                 // 所属ブログIDは親ウィンドウから引き継ぐ
754                                 //$this->blogId = '';           // 所属ブログ
755                                 $entry_date = date("Y/m/d");            // 投稿日
756                                 $entry_time = date("H:i:s");            // 投稿時間
757                                 $showComment = 1;                               // コメントを表示するかどうか
758                                 $receiveComment = 1;            // コメントを受け付けるかどうか
759                         }
760                 }
761                 
762                 // 設定データを再取得
763                 if ($reloadData){               // データの再ロード
764                         $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
765                         if ($ret){
766                                 $this->entryId = $row['be_id'];         // 記事ID
767                                 $this->blogId = $row['be_blog_id'];             // 所属ブログ
768                                 $name = $row['be_name'];                                // タイトル
769                                 $html = $row['be_html'];                                // HTML
770                                 $html = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->getUrl($this->gEnv->getRootUrl()), $html);// アプリケーションルートを変換
771                                 $html2 = $row['be_html_ext'];                           // HTML
772                                 $html2 = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->getUrl($this->gEnv->getRootUrl()), $html2);// アプリケーションルートを変換
773                                 $desc = $row['be_description'];         // 簡易説明
774                                 $status = $row['be_status'];                            // エントリー状況
775                                 $reg_user = $row['reg_user_name'];                              // 投稿者
776                                 $entry_date = $this->timestampToDate($row['be_regist_dt']);             // 投稿日
777                                 $entry_time = $this->timestampToTime($row['be_regist_dt']);             // 投稿時間
778                                 $update_user = $this->convertToDispString($row['lu_name']);// 更新者
779                                 $update_dt = $this->convertToDispDateTime($row['be_create_dt']);
780                                 $start_date = $this->convertToDispDate($row['be_active_start_dt']);     // 公開期間開始日
781                                 $start_time = $this->convertToDispTime($row['be_active_start_dt'], 1/*時分*/);        // 公開期間開始時間
782                                 $end_date = $this->convertToDispDate($row['be_active_end_dt']); // 公開期間終了日
783                                 $end_time = $this->convertToDispTime($row['be_active_end_dt'], 1/*時分*/);    // 公開期間終了時間
784                                 $showComment = $row['be_show_comment'];                         // コメントを表示するかどうか
785                                 $receiveComment = $row['be_receive_comment'];           // コメントを受け付けるかどうか
786                                 $relatedContent = $row['be_related_content'];           // 関連コンテンツ
787                                 
788                                 // 記事カテゴリー取得
789                                 $this->categoryArray = $this->getCategory($categoryRow);
790                                 
791                                 // 履歴番号
792                                 if ($row['be_deleted']) $historyIndex = $row['be_history_index'];               // 旧データの場合のみ有効
793                                 
794                                 // ユーザ定義フィールド
795                                 $this->fieldValueArray = $this->unserializeArray($row['be_option_fields']);
796                                 
797                                 // 前後のエントリーのシリアル番号を取得
798                                 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){         // // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
799                                         if ($this->gEnv->isAdminDirAccess()){           // 管理画面へのアクセスの場合
800                                                 $blogId = null; // デフォルトブログ(ブログID空)を含むすべてのブログ記事にアクセス可能
801                                         } else {
802                                                 $blogId = $this->blogId;                // 所属ブログ
803                                         }
804                                         $ret = self::$_mainDb->getPrevNextEntryByDate($row['be_regist_dt'], $prevRow, $nextRow, $blogId);
805                                         if ($ret){
806                                                 if (!empty($prevRow)) $prevSerial = $prevRow['be_serial'];
807                                                 if (!empty($nextRow)) $nextSerial = $nextRow['be_serial'];
808                                         }
809                                 }
810                         } else {                // データがないとき
811                                 $this->serialNo = 0;
812                                 $this->entryId = '0';           // 記事ID
813                                 $this->blogId = '';             // 所属ブログ
814                                 $name = '';                             // タイトル
815                                 $html = '';                             // HTML
816                                 $html2 = '';                            // HTML
817                                 $desc = '';             // 簡易説明
818                                 $status = 0;                            // エントリー状況
819                                 $reg_user = '';                         // 投稿者
820                                 $entry_date = date("Y/m/d");            // 投稿日
821                                 $entry_time = date("H:i:s");            // 投稿時間
822                                 $update_user = '';// 更新者
823                                 $update_dt = '';
824                                 $start_date = '';       // 公開期間開始日
825                                 $start_time = '';       // 公開期間開始時間
826                                 $end_date = ''; // 公開期間終了日
827                                 $end_time = ''; // 公開期間終了時間
828                                 $showComment = 1;                               // コメントを表示するかどうか
829                                 $receiveComment = 1;            // コメントを受け付けるかどうか
830                                 $relatedContent = '';           // 関連コンテンツ
831                                 
832                                 // 記事カテゴリー取得
833                                 $this->categoryArray = array();
834                                 
835                                 // 履歴番号
836                                 $historyIndex = -1;
837                                 
838                                 // ユーザ定義フィールド
839                                 $this->fieldValueArray = array();
840                         }
841                 }
842                 // カテゴリーメニューを作成
843                 self::$_mainDb->getAllCategory($this->langId, $this->categoryListData);
844                 $this->createCategoryMenu($this->categoryCount);
845                 
846                 // ユーザ定義フィールドを作成
847                 $this->createUserFields($fieldInfoArray);
848                 
849                 // 所属ブログ
850                 if (empty($useMultiBlog)){
851 /*                      $this->tmpl->setAttribute('show_blogid_area', 'visibility', 'visible');
852                         
853                         $blogName = $this->getBlogName($this->blogId);
854                         $this->tmpl->addVar("show_blogid_area", "blog_id", $this->blogId);      // 所属ブログID
855                         $this->tmpl->addVar("show_blogid_area", "blog_name", $blogName);        // 所属ブログ名
856                         */
857                 } else {                // マルチブログを使用するとき
858                         $this->tmpl->setAttribute('select_blogid_area', 'visibility', 'visible');
859                         
860                         // ブログ選択メニュー作成
861                         $this->createBlogIdMenu();
862                 }
863                 
864                 // コメント機能の設定
865                 if ($useComment){
866                         $this->tmpl->setAttribute('show_comment_area', 'visibility', 'visible');
867                         
868                         $this->tmpl->addVar("show_comment_area", "show_comment", $this->convertToCheckedString($showComment));// コメントを表示するかどうか
869                         $this->tmpl->addVar("show_comment_area", "receive_comment", $this->convertToCheckedString($receiveComment));// コメントを受け付けるかどうか
870                 }
871                 
872                 // プレビュー用URL
873                 $previewUrl = $this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $this->entryId;
874                 if ($historyIndex >= 0) $previewUrl .= '&' . M3_REQUEST_PARAM_HISTORY . '=' . $historyIndex;            // 履歴番号(旧データの場合のみ有効)
875                 $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_PREVIEW;
876                 if ($this->isMultiLang) $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_LANG . '=' . $this->langId;             // 多言語対応の場合は言語IDを付加
877                 $this->tmpl->addVar('_widget', 'preview_url', $previewUrl);// プレビュー用URL(一般画面)
878                 
879                 // CKEditor用のCSSファイルを読み込む
880                 $this->loadCKEditorCssFiles($previewUrl);
881                 
882                 // ### 入力値を再設定 ###
883                 $this->tmpl->addVar('_widget', 'entryid', $this->entryId);
884                 $this->tmpl->addVar("_widget", "item_name", $this->convertToDispString($name));         // 名前
885                 $this->tmpl->addVar("_widget", "item_html", $html);             // HTML
886                 $this->tmpl->addVar("_widget", "item_html2", $html2);           // HTML(続き)
887                 $this->tmpl->addVar("_widget", "desc", $desc);          // 簡易説明
888                 switch ($status){
889                         case 1: $this->tmpl->addVar("_widget", "selected_edit", 'selected');    break;
890                         case 2: $this->tmpl->addVar("_widget", "selected_public", 'selected');  break;
891                         case 3: $this->tmpl->addVar("_widget", "selected_closed", 'selected');  break;
892                 }       
893                 $this->tmpl->addVar("_widget", "entry_user", $reg_user);        // 投稿者
894                 $this->tmpl->addVar("_widget", "entry_date", $entry_date);      // 投稿日
895                 $this->tmpl->addVar("_widget", "entry_time", $entry_time);      // 投稿時
896                 $this->tmpl->addVar("_widget", "update_user", $update_user);    // 更新者
897                 $this->tmpl->addVar("_widget", "update_dt", $update_dt);        // 更新日時
898                 $this->tmpl->addVar("_widget", "start_date", $start_date);      // 公開期間開始日
899                 $this->tmpl->addVar("_widget", "start_time", $start_time);      // 公開期間開始時間
900                 $this->tmpl->addVar("_widget", "end_date", $end_date);  // 公開期間終了日
901                 $this->tmpl->addVar("_widget", "end_time", $end_time);  // 公開期間終了時間
902                 $this->tmpl->addVar("_widget", "related_content", $relatedContent);     // 関連コンテンツ
903                 
904                 // 前後エントリー移動ボタン
905                 if (!empty($prevSerial)){
906                         $this->tmpl->setAttribute('show_prev_button', 'visibility', 'visible');
907                         $this->tmpl->addVar('show_prev_button', 'serial', $prevSerial);
908                 }
909                 if (!empty($nextSerial)){
910                         $this->tmpl->setAttribute('show_next_button', 'visibility', 'visible');
911                         $this->tmpl->addVar('show_next_button', 'serial', $nextSerial);
912                 }
913                                                 
914                 // 非表示項目を設定
915                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);      // シリアル番号
916
917                 // 入力フィールドの設定、共通項目のデータ設定
918                 if (empty($this->entryId)){             // 記事IDが0のときは、新規追加モードにする
919                         // 記事ID
920                         $this->tmpl->addVar('_widget', 'id', '新規');
921                         
922                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
923                         $this->tmpl->addVar('_widget', 'preview_btn_disabled', 'disabled');// プレビューボタン使用不可
924                         $this->tmpl->addVar('_widget', 'history_btn_disabled', 'disabled');// 履歴ボタン使用不可
925                         $this->tmpl->addVar('_widget', 'image_btn_disabled', 'disabled');// 画像ボタン使用不可
926                         $this->tmpl->addVar('cancel_button', 'new_btn_disabled', 'disabled');   // 「新規」ボタン使用不可
927                         
928                         // デフォルト言語を最初に登録
929                         //$this->tmpl->addVar("default_lang", "default_lang", $defaultLangName);
930                         //$this->tmpl->setAttribute('default_lang', 'visibility', 'visible');
931                 } else {
932                         // 記事ID
933                         $itemId = $this->entryId;
934                         if ($historyIndex >= 0) $itemId .= '(' . ($historyIndex +1) . ')';// 履歴番号(旧データの場合のみ有効)
935                         $this->tmpl->addVar('_widget', 'id', $itemId);
936                         
937                         // ボタンの表示制御
938                         if ($this->serialNo == 0){              // 未登録データのとき
939                                 // データ追加ボタン表示
940                                 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
941                         } else {
942                                 if ($historyIndex >= 0){                // 履歴データの場合
943                                         $this->tmpl->setAttribute('update_history_button', 'visibility', 'visible');            // 「履歴データで更新」ボタン
944                                 } else {
945                                         // データ更新、削除ボタン表示
946                                         $this->tmpl->setAttribute('delete_button', 'visibility', 'visible');// デフォルト言語以外はデータ削除
947                                         $this->tmpl->setAttribute('update_button', 'visibility', 'visible');
948                                 }
949                         }
950                         // 言語選択メニュー作成
951                         //if (!empty($this->entryId)){  // コンテンツが選択されているとき
952                         //      self::$_mainDb->getAllLang(array($this, 'langLoop'));
953                         //      $this->tmpl->setAttribute('select_lang', 'visibility', 'visible');
954                         //}
955                 }
956
957                 // パス等を設定
958                 $this->tmpl->addVar('_widget', 'calendar_img', $this->getUrl($this->gEnv->getRootUrl() . self::CALENDAR_ICON_FILE));    // カレンダーアイコン
959                 
960                 // 閉じるボタンの表示制御
961                 if ($openBy == 'simple') $this->tmpl->setAttribute('cancel_button', 'visibility', 'hidden');            // 詳細画面のみの表示のときは戻るボタンを隠す
962         }
963         /**
964          * 取得したデータをテンプレートに設定する
965          *
966          * @param int $index                    行番号(0~)
967          * @param array $fetchedRow             フェッチ取得した行
968          * @param object $param                 未使用
969          * @return bool                                 true=処理続行の場合、false=処理終了の場合
970          */
971         function itemListLoop($index, $fetchedRow, $param)
972         {
973                 // シリアル番号
974                 $serial = $fetchedRow['be_serial'];
975
976                 // カテゴリーを取得
977                 $categoryArray = array();
978                 $ret = self::$_mainDb->getEntryBySerial($serial, $row, $categoryRow);
979                 if ($ret){
980                         for ($i = 0; $i < count($categoryRow); $i++){
981                                 if (function_exists('mb_strimwidth')){
982                                         $categoryArray[] = mb_strimwidth($categoryRow[$i]['bc_name'], 0, self::CATEGORY_NAME_SIZE, '…');
983                                 } else {
984                                         $categoryArray[] = substr($categoryRow[$i]['bc_name'], 0, self::CATEGORY_NAME_SIZE) . '...';
985                                 }
986                         }
987                 }
988                 $category = implode(',', $categoryArray);
989                 
990                 // 公開状態
991                 switch ($fetchedRow['be_status']){
992                         case 1: $status = '<font color="orange">編集中</font>';      break;
993                         case 2: $status = '<font color="green">公開</font>';  break;
994                         case 3: $status = '非公開';  break;
995                 }
996                 // 総参照数
997                 $totalViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(self::CONTENT_TYPE, $serial);
998                 
999                 // ユーザからの参照状況
1000                 $now = date("Y/m/d H:i:s");     // 現在日時
1001                 $startDt = $fetchedRow['be_active_start_dt'];
1002                 $endDt = $fetchedRow['be_active_end_dt'];
1003                 
1004                 $isActive = false;              // 公開状態
1005                 if ($fetchedRow['be_status'] == 2) $isActive = $this->isActive($startDt, $endDt, $now);// 表示可能
1006                 
1007                 if ($isActive){         // コンテンツが公開状態のとき
1008                         $iconUrl = $this->gEnv->getRootUrl() . self::ACTIVE_ICON_FILE;                  // 公開中アイコン
1009                         $iconTitle = '公開中';
1010                 } else {
1011                         $iconUrl = $this->gEnv->getRootUrl() . self::INACTIVE_ICON_FILE;                // 非公開アイコン
1012                         $iconTitle = '非公開';
1013                 }
1014                 $statusImg = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" rel="m3help" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
1015                 
1016                 $row = array(
1017                         'index' => $index,              // 項目番号
1018                         'no' => $index + 1,                                                                                                     // 行番号
1019                         'serial' => $serial,                    // シリアル番号
1020                         'id' => $this->convertToDispString($fetchedRow['be_id']),                       // ID
1021                         'name' => $this->convertToDispString($fetchedRow['be_name']),           // 名前
1022                         'lang' => $lang,                                                                                                        // 対応言語
1023                         'status_img' => $statusImg,                                                                                             // ユーザからの参照状況
1024                         'status' => $status,                                                                                                    // 公開状況
1025                         'category' => $category,                                                                                        // 記事カテゴリー
1026                         'view_count' => $totalViewCount,                                                                        // 総参照数
1027                         'reg_user' => $this->convertToDispString($fetchedRow['lu_name']),       // 投稿者
1028                         'reg_date' => $this->convertToDispDateTime($fetchedRow['be_regist_dt']),        // 投稿日時
1029                         'update_user' => $this->convertToDispString($fetchedRow['lu_name']),    // 更新者
1030                         'update_date' => $this->convertToDispDateTime($fetchedRow['be_create_dt'])      // 更新日時
1031                 );
1032                 $this->tmpl->addVars('itemlist', $row);
1033                 $this->tmpl->parseTemplate('itemlist', 'a');
1034                 
1035                 // 表示中項目のシリアル番号を保存
1036                 $this->serialArray[] = $serial;
1037                 return true;
1038         }
1039         /**
1040          * 取得した言語をテンプレートに設定する
1041          *
1042          * @param int $index                    行番号(0~)
1043          * @param array $fetchedRow             フェッチ取得した行
1044          * @param object $param                 未使用
1045          * @return bool                                 true=処理続行の場合、false=処理終了の場合
1046          */
1047         function langLoop($index, $fetchedRow, $param)
1048         {
1049                 $selected = '';
1050                 if ($fetchedRow['ln_id'] == $this->langId){
1051                         $selected = 'selected';
1052                 }
1053                 if ($this->gEnv->getCurrentLanguage() == 'ja'){         // 日本語表示の場合
1054                         $name = $this->convertToDispString($fetchedRow['ln_name']);
1055                 } else {
1056                         $name = $this->convertToDispString($fetchedRow['ln_name_en']);
1057                 }
1058
1059                 $row = array(
1060                         'value'    => $this->convertToDispString($fetchedRow['ln_id']),                 // 言語ID
1061                         'name'     => $name,                    // 言語名
1062                         'selected' => $selected                                                                                                         // 選択中かどうか
1063                 );
1064                 $this->tmpl->addVars('lang_list', $row);
1065                 $this->tmpl->parseTemplate('lang_list', 'a');
1066                 return true;
1067         }
1068         /**
1069          * 記事カテゴリー取得
1070          *
1071          * @param array         $srcRows                        取得行
1072          * @return array                                                取得した行
1073          */
1074         function getCategory($srcRows)
1075         {
1076                 $destArray = array();
1077                 $itemCount = 0;
1078                 for ($i = 0; $i < count($srcRows); $i++){
1079                         if (!empty($srcRows[$i]['bw_category_id'])){
1080                                 $destArray[] = $srcRows[$i]['bw_category_id'];
1081                                 $itemCount++;
1082                                 if ($itemCount >= $this->categoryCount) break;
1083                         }
1084                 }
1085                 return $destArray;
1086         }
1087         /**
1088          * 記事カテゴリーメニューを作成
1089          *
1090          * @param int   $size                   メニューの表示数
1091          * @return なし                                               
1092          */
1093         function createCategoryMenu($size)
1094         {
1095                 for ($j = 0; $j < $size; $j++){
1096                         // selectメニューの作成
1097                         $this->tmpl->clearTemplate('category_list');
1098                         for ($i = 0; $i < count($this->categoryListData); $i++){
1099                                 $categoryId = $this->categoryListData[$i]['bc_id'];
1100                                 $selected = '';
1101                                 if ($j < count($this->categoryArray) && $this->categoryArray[$j] == $categoryId){
1102                                         $selected = 'selected';
1103                                 }
1104                                 $menurow = array(
1105                                         'value'         => $categoryId,                 // カテゴリーID
1106                                         'name'          => $this->categoryListData[$i]['bc_name'],                      // カテゴリー名
1107                                         'selected'      => $selected                                                                                                            // 選択中かどうか
1108                                 );
1109                                 $this->tmpl->addVars('category_list', $menurow);
1110                                 $this->tmpl->parseTemplate('category_list', 'a');
1111                         }
1112                         $itemRow = array(               
1113                                         'index'         => $j                   // 項目番号                                                                                 
1114                         );
1115                         $this->tmpl->addVars('category', $itemRow);
1116                         $this->tmpl->parseTemplate('category', 'a');
1117                 }
1118         }
1119         /**
1120          * ブログ名を取得
1121          *
1122          * @param string $blogId                ブログID
1123          * @return string                               ブログ名
1124          */
1125         function getBlogName($blogId)
1126         {
1127                 $ret = self::$_mainDb->getBlogInfoById($blogId, $row);
1128                 if ($ret){
1129                         return $row['bl_name'];
1130                 } else {
1131                         return self::NO_BLOG_NAME;
1132                 }
1133         }
1134         /**
1135          * ブログ選択メニューを作成
1136          *
1137          * @return なし                                               
1138          */
1139         function createBlogIdMenu()
1140         {
1141                 if ($this->gEnv->isSystemManageUser()){         // システム運用ユーザのみ「ブログ選択なし」が利用可能
1142                         $selected = '';
1143                         if (empty($this->blogId)) $selected ='selected';
1144                         $row = array(
1145                                 'value'    => $this->convertToDispString(''),                   // ブログID
1146                                 'name'     => $this->convertToDispString(self::NO_BLOG_NAME),                   // ブログ選択なし
1147                                 'selected' => $selected                                                                                                 // 選択中かどうか
1148                         );
1149                         $this->tmpl->addVars('blogid_list', $row);
1150                         $this->tmpl->parseTemplate('blogid_list', 'a');
1151                 }
1152                                 
1153                 $ret = self::$_mainDb->getAvailableBlogId($rows);
1154                 if ($ret){
1155                         for ($i = 0; $i < count($rows); $i++){
1156                                 $selected = '';
1157                                 if ($rows[$i]['bl_id'] == $this->blogId) $selected = 'selected';
1158                                 $row = array(
1159                                         'value'    => $this->convertToDispString($rows[$i]['bl_id']),                   // ブログID
1160                                         'name'     => $this->convertToDispString($rows[$i]['bl_name']),                 // ブログ名
1161                                         'selected' => $selected                                                                                                         // 選択中かどうか
1162                                 );
1163                                 $this->tmpl->addVars('blogid_list', $row);
1164                                 $this->tmpl->parseTemplate('blogid_list', 'a');
1165                         }
1166                 }
1167         }
1168         /**
1169          * 期間から公開可能かチェック
1170          *
1171          * @param timestamp     $startDt                公開開始日時
1172          * @param timestamp     $endDt                  公開終了日時
1173          * @param timestamp     $now                    基準日時
1174          * @return bool                                         true=公開可能、false=公開不可
1175          */
1176         function isActive($startDt, $endDt, $now)
1177         {
1178                 $isActive = false;              // 公開状態
1179
1180                 if ($startDt == $this->gEnv->getInitValueOfTimestamp() && $endDt == $this->gEnv->getInitValueOfTimestamp()){
1181                         $isActive = true;               // 公開状態
1182                 } else if ($startDt == $this->gEnv->getInitValueOfTimestamp()){
1183                         if (strtotime($now) < strtotime($endDt)) $isActive = true;              // 公開状態
1184                 } else if ($endDt == $this->gEnv->getInitValueOfTimestamp()){
1185                         if (strtotime($now) >= strtotime($startDt)) $isActive = true;           // 公開状態
1186                 } else {
1187                         if (strtotime($startDt) <= strtotime($now) && strtotime($now) < strtotime($endDt)) $isActive = true;            // 公開状態
1188                 }
1189                 return $isActive;
1190         }
1191         /**
1192          * キャッシュデータをクリア
1193          *
1194          * @param int $serial           削除対象のコンテンツシリアル番号
1195          * @return                                      なし
1196          */
1197         function clearCacheBySerial($serial)
1198         {
1199                 $ret = self::$_mainDb->getEntryBySerial($serial, $row, $categoryRow);// 記事ID取得
1200                 if ($ret){
1201                         $entryId = $row['be_id'];               // 記事ID
1202                         $urlParam = array();
1203                         $urlParam[] = M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $entryId;          // 記事ID
1204                         $urlParam[] = M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT . '=' . $entryId;            // 記事ID略式
1205                         $this->clearCache($urlParam);
1206                 }
1207         }
1208         /**
1209          * ユーザ定義フィールドを作成
1210          *
1211          * @param array $fields                 フィールドID
1212          * @return bool                                 true=成功、false=失敗
1213          */
1214         function createUserFields($fields)
1215         {
1216                 if (count($fields) == 0) return true;
1217                 
1218                 $this->tmpl->setAttribute('user_fields', 'visibility', 'visible');
1219                 $keys = array_keys($fields);
1220                 $fieldCount = count($keys);
1221                 for ($i = 0; $i < $fieldCount; $i++){
1222                         if ($i == 0) $this->tmpl->addVar('user_fields', 'type', 'first');               // 最初の行の場合
1223                         
1224                         // 入力値を取得
1225                         $key = $keys[$i];
1226                         $value = $this->fieldValueArray[$key];
1227                         if (!isset($value)) $value = '';
1228                         
1229                         $row = array(
1230                                 'row_count'     => $fieldCount,
1231                                 'field_id'      => $this->convertToDispString($key),
1232                                 'value'         => $this->convertToDispString($value)
1233                         );
1234                         $this->tmpl->addVars('user_fields', $row);
1235                         $this->tmpl->parseTemplate('user_fields', 'a');
1236                 }
1237                 return true;
1238         }
1239 }
1240 ?>