OSDN Git Service

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