OSDN Git Service

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