7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
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
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_blog_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/blog_mainDb.php');
19 class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetContainer
21 private $serialNo; // 選択中の項目のシリアル番号
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_'; // フィールド名の先頭文字列
45 function __construct()
48 parent::__construct();
50 $this->isMultiLang = $this->gEnv->isMultiLanguageSite(); // 多言語対応画面かどうか
55 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
56 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
58 * @param RequestManager $request HTTPリクエスト処理クラス
59 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
60 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
62 function _setTemplate($request, &$param)
64 $task = $request->trimValueOf('task');
66 if ($task == 'entry_detail'){ // 詳細画面
67 return 'admin_entry_detail.tmpl.html';
69 return 'admin_entry.tmpl.html';
75 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
77 * @param RequestManager $request HTTPリクエスト処理クラス
78 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
81 function _assign($request, &$param)
83 $task = $request->trimValueOf('task');
84 if ($task == 'entry_detail'){ // 詳細画面
85 return $this->createDetail($request);
87 return $this->createList($request);
91 * JavascriptファイルをHTMLヘッダ部に設定
93 * JavascriptファイルをHTMLのheadタグ内に追加出力する。
94 * _assign()よりも後に実行される。
96 * @param RequestManager $request HTTPリクエスト処理クラス
97 * @param object $param 任意使用パラメータ。
98 * @return string Javascriptファイル。出力しない場合は空文字列を設定。
100 function _addScriptFileToHead($request, &$param)
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)); // カレンダーセットアップファイル
109 * CSSファイルをHTMLヘッダ部に設定
111 * CSSファイルをHTMLのheadタグ内に追加出力する。
112 * _assign()よりも後に実行される。
114 * @param RequestManager $request HTTPリクエスト処理クラス
115 * @param object $param 任意使用パラメータ。
116 * @return string CSS文字列。出力しない場合は空文字列を設定。
118 function _addCssFileToHead($request, &$param)
120 return $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_CSS_FILE);
125 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
127 * @param RequestManager $request HTTPリクエスト処理クラス
130 function createList($request)
133 $defaultLangId = $this->gEnv->getDefaultLanguage();
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空)を含むすべてのブログ記事にアクセス可能
141 $this->blogId = $request->trimValueOf(M3_REQUEST_PARAM_BLOG_ID); // 所属ブログ
145 $pageNo = $request->trimValueOf('page'); // ページ番号
146 if (empty($pageNo)) $pageNo = 1;
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; // 会員リスト最大表示数
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'); // 検索キーワード
164 $this->categoryArray = array();
165 if (!empty($search_categoryId)){ // 0以外の値を取得
166 $this->categoryArray[] = $search_categoryId;
169 if ($act == 'delete'){ // 項目削除の場合
170 $listedItem = explode(',', $request->trimValueOf('seriallist'));
172 for ($i = 0; $i < count($listedItem); $i++){
174 $itemName = 'item' . $i . '_selected';
175 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
177 if ($itemValue){ // チェック項目
178 $delItems[] = $listedItem[$i];
181 if (count($delItems) > 0){
183 $delEntryInfo = array();
184 for ($i = 0; $i < count($delItems); $i++){
185 $ret = self::$_mainDb->getEntryBySerial($delItems[$i], $row, $categoryRow);
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;
195 $ret = self::$_mainDb->delEntryItem($delItems);
196 if ($ret){ // データ削除成功のとき
197 $this->setGuidanceMsg('データを削除しました');
199 // ##### サムネールの削除 #####
200 for ($i = 0; $i < count($delEntryInfo); $i++){
201 $infoObj = $delEntryInfo[$i];
202 $ret = blog_mainCommonDef::removeThumbnail($infoObj->entryId);
204 if (!empty($infoObj->thumb)){
205 $oldFiles = explode(';', $infoObj->thumb);
206 $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $oldFiles);
211 for ($i = 0; $i < count($delItems); $i++){
212 $this->clearCacheBySerial($delItems[$i]);
216 $this->gPage->updateParentWindow();
219 for ($i = 0; $i < count($delEntryInfo); $i++){
220 $infoObj = $delEntryInfo[$i];
221 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $infoObj->name, 2100, 'ID=' . $infoObj->entryId);
224 $this->setAppErrorMsg('データ削除に失敗しました');
227 } else if ($act == 'search'){ // 検索のとき
228 if (!empty($search_startDt) && !empty($search_endDt) && $search_startDt > $search_endDt){
229 $this->setUserErrorMsg('期間の指定範囲にエラーがあります。');
231 $pageNo = 1; // ページ番号初期化
232 } else if ($act == 'selpage'){ // ページ選択
234 // ###### 一覧の取得条件を作成 ######
235 if (!empty($search_endDt)) $endDt = $this->getNextDay($search_endDt);
238 $totalCount = self::$_mainDb->getEntryItemCount($search_startDt, $endDt, $this->categoryArray, $search_keyword, $this->langId, $this->blogId);
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; // 先頭番号
248 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
249 for ($i = 1; $i <= $pageCount; $i++){
251 $link = ' ' . $i;
253 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
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');// 投稿記事がないときは、一覧を表示しない
264 self::$_mainDb->getAllCategory($this->langId, $this->categoryListData);
265 $this->createCategoryMenu(1); // メニューは1つだけ表示
268 $this->tmpl->addVar("_widget", "page_link", $pageLink);
269 $this->tmpl->addVar("_widget", "total_count", $totalCount);
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); // 検索キーワード
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); // 一覧表示項目数
284 * @param RequestManager $request HTTPリクエスト処理クラス
287 function createDetail($request)
290 $defaultLangId = $this->gEnv->getDefaultLanguage();
291 $regUserId = $this->gEnv->getCurrentUserId(); // 記事投稿ユーザ
292 //$regDt = date("Y/m/d H:i:s"); // 投稿日時
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;
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);
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タグが送信される)
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'); // 関連コンテンツ
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;
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 = ''; // 日付が空のときは時刻も空に設定する
344 if (empty($start_time)) $start_time = '00:00'; // 日付が入っているときは時間にデフォルト値を設定
346 if (!empty($start_time)) $start_time = $this->convertToProperTime($start_time, 1/*時分フォーマット*/);
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 = ''; // 日付が空のときは時刻も空に設定する
354 if (empty($end_time)) $end_time = '00:00'; // 日付が入っているときは時間にデフォルト値を設定
356 if (!empty($end_time)) $end_time = $this->convertToProperTime($end_time, 1/*時分フォーマット*/);
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;
368 $historyIndex = -1; // 履歴番号
369 $reloadData = false; // データの再ロード
370 if ($act == 'select'){ // 一覧から選択のとき
371 $reloadData = true; // データの再ロード
372 } else if ($act == 'selectlang'){ // 項目選択の場合
374 $this->serialNo = self::$_mainDb->getEntrySerialNoByContentId($this->entryId, $this->langId);
375 if (empty($this->serialNo)){
377 //$name = ''; // タイトル
378 //$html = ''; // HTML
379 $status = 0; // エントリー状況
380 $reg_user = ''; // 投稿者
381 $update_user = '';// 更新者
384 $reloadData = true; // データの再ロード
386 } else if ($act == 'add' || $act == 'addlang'){ // 項目追加の場合
388 $this->checkInput($name, 'タイトル');
389 $this->checkDate($entry_date, '投稿日付');
390 $this->checkTime($entry_time, '投稿時間');
393 if (!empty($start_date) && !empty($end_date)){
394 if (strtotime($start_date . ' ' . $start_time) >= strtotime($end_date . ' ' . $end_time)) $this->setUserErrorMsg('公開期間が不正です');
398 if ($this->getMsgCount() == 0){
400 if (empty($start_date)){
401 $startDt = $this->gEnv->getInitValueOfTimestamp();
403 $startDt = $start_date . ' ' . $start_time;
405 if (empty($end_date)){
406 $endDt = $this->gEnv->getInitValueOfTimestamp();
408 $endDt = $end_date . ' ' . $end_time;
410 $regDt = $this->convertToProperDate($entry_date) . ' ' . $this->convertToProperTime($entry_time); // 投稿日時
414 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){ // // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
416 $nextEntryId = self::$_mainDb->getNextEntryId();
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);
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);
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);
440 $this->setGuidanceMsg('データを追加しました');
443 $this->serialNo = $newSerial;
444 $reloadData = true; // データの再ロード
446 // ##### サムネールの作成 #####
447 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
449 $entryId = $row['be_id']; // 記事ID
450 $html = $row['be_html']; // HTML
451 $updateDt = $row['be_create_dt'];
452 $status = $row['be_status'];
454 if ($status == 2){ // 公開の場合
455 $ret = blog_mainCommonDef::createThumbnail($html, $entryId, $updateDt);
457 $ret = blog_mainCommonDef::removeThumbnail($entryId);
462 $this->clearCacheBySerial($this->serialNo);
465 $this->gPage->updateParentWindow();
469 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
471 $this->entryId = $row['be_id']; // 記事ID
472 $name = $row['be_name']; // コンテンツ名前
475 switch ($row['be_status']){
476 case 1: $statusStr = '編集中'; break;
477 case 2: $statusStr = '公開'; break;
478 case 3: $statusStr = '非公開'; break;
481 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を追加(' . $statusStr . ')しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
483 $this->setAppErrorMsg('データ追加に失敗しました');
486 } else if ($act == 'update'){ // 項目更新の場合
488 $this->checkInput($name, 'タイトル');
489 $this->checkDate($entry_date, '投稿日付');
490 $this->checkTime($entry_time, '投稿時間');
493 if (!empty($start_date) && !empty($end_date)){
494 if (strtotime($start_date . ' ' . $start_time) >= strtotime($end_date . ' ' . $end_time)) $this->setUserErrorMsg('公開期間が不正です');
498 if ($this->getMsgCount() == 0){
500 if (empty($start_date)){
501 $startDt = $this->gEnv->getInitValueOfTimestamp();
503 $startDt = $start_date . ' ' . $start_time;
505 if (empty($end_date)){
506 $endDt = $this->gEnv->getInitValueOfTimestamp();
508 $endDt = $end_date . ' ' . $end_time;
510 $regDt = $this->convertToProperDate($entry_date) . ' ' . $this->convertToProperTime($entry_time); // 投稿日時
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);
524 $otherParams = array( 'be_description' => $desc, // 簡易説明
525 'be_thumb_filename' => $thumbFilename, // サムネールファイル名
526 'be_related_content' => $relatedContent, // 関連コンテンツ
527 'be_option_fields' => $this->serializeArray($this->fieldValueArray)); // ユーザ定義フィールド値
529 $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
530 ''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams);
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);
540 $this->setGuidanceMsg('データを更新しました');
543 $this->serialNo = $newSerial;
544 $reloadData = true; // データの再ロード
546 // ##### サムネールの作成 #####
547 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
549 $entryId = $row['be_id']; // 記事ID
550 $html = $row['be_html']; // HTML
551 $updateDt = $row['be_create_dt'];
552 $status = $row['be_status'];
554 if ($status == 2){ // 公開の場合
555 $ret = blog_mainCommonDef::createThumbnail($html, $entryId, $updateDt);
557 $ret = blog_mainCommonDef::removeThumbnail($entryId);
562 $this->clearCacheBySerial($this->serialNo);
565 $this->gPage->updateParentWindow();
569 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
571 $this->entryId = $row['be_id']; // 記事ID
572 $name = $row['be_name']; // コンテンツ名前
575 switch ($row['be_status']){
576 case 1: $statusStr = '編集中'; break;
577 case 2: $statusStr = '公開'; break;
578 case 3: $statusStr = '非公開'; break;
581 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を更新(' . $statusStr . ')しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
583 $this->setAppErrorMsg('データ更新に失敗しました');
586 } else if ($act == 'delete'){ // 項目削除の場合
587 if (empty($this->serialNo)){
588 $this->setUserErrorMsg('削除項目が選択されていません');
591 if ($this->getMsgCount() == 0){
593 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
595 $this->entryId = $row['be_id']; // 記事ID
596 $name = $row['be_name']; // コンテンツ名前
599 $ret = self::$_mainDb->delEntryItem(array($this->serialNo));
600 if ($ret){ // データ削除成功のとき
601 $this->setGuidanceMsg('データを削除しました');
603 // ##### サムネールの削除 #####
604 $ret = blog_mainCommonDef::removeThumbnail($this->entryId);
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);
613 $this->clearCacheBySerial($this->serialNo);
616 $this->gPage->updateParentWindow();
619 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
621 $this->setAppErrorMsg('データ削除に失敗しました');
624 } else if ($act == 'deleteid'){ // ID項目削除の場合
625 if (empty($this->serialNo)){
626 $this->setUserErrorMsg('削除項目が選択されていません');
629 if ($this->getMsgCount() == 0){
631 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
633 $this->entryId = $row['be_id']; // 記事ID
634 $name = $row['be_name']; // コンテンツ名前
637 $ret = self::$_mainDb->delEntryItemById($this->serialNo);
638 if ($ret){ // データ削除成功のとき
639 $this->setGuidanceMsg('データを削除しました');
641 // ##### サムネールの削除 #####
642 $ret = blog_mainCommonDef::removeThumbnail($this->entryId);
645 $this->clearCacheBySerial($this->serialNo);
648 $this->gPage->updateParentWindow();
651 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
653 $this->setAppErrorMsg('データ削除に失敗しました');
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; // データの再読み込み
666 if ($this->isMultiLang){ // 多言語対応の場合
667 $langId = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_LANG); // lang値を取得
668 if (!empty($langId)) $this->langId = $langId;
672 $ret = self::$_mainDb->getEntryItem($this->entryId, $this->langId, $row);
674 $this->serialNo = $row['be_serial']; // シリアル番号
675 $reloadData = true; // データの再読み込み
680 if (empty($this->serialNo)){
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; // コメントを受け付けるかどうか
692 if ($reloadData){ // データの再ロード
693 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
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']; // 関連コンテンツ
718 $this->categoryArray = $this->getCategory($categoryRow);
721 if ($row['be_deleted']) $historyIndex = $row['be_history_index'];
724 $this->fieldValueArray = $this->unserializeArray($row['be_option_fields']);
728 self::$_mainDb->getAllCategory($this->langId, $this->categoryListData);
729 $this->createCategoryMenu($this->categoryCount);
732 $this->createUserFields($fieldInfoArray);
735 if (empty($useMultiBlog)){
736 $this->tmpl->setAttribute('show_blogid_area', 'visibility', 'visible');
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');
745 $this->createBlogIdMenu();
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(一般画面)
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); // 簡易説明
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;
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); // 公開期間終了時間
776 if ($showComment) $checked = 'checked';
777 $this->tmpl->addVar("_widget", "show_comment", $checked);// コメントを表示するかどうか
779 if ($receiveComment) $checked = 'checked';
780 $this->tmpl->addVar("_widget", "receive_comment", $checked);// コメントを受け付けるかどうか
781 $this->tmpl->addVar("_widget", "related_content", $relatedContent); // 関連コンテンツ
784 $this->tmpl->addVar("_widget", "serial", $this->serialNo); // シリアル番号
786 // 入力フィールドの設定、共通項目のデータ設定
787 if (empty($this->entryId)){ // 記事IDが0のときは、新規追加モードにする
789 $this->tmpl->addVar('_widget', 'id', '新規');
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');// 履歴ボタン使用不可
796 $this->tmpl->addVar("default_lang", "default_lang", $defaultLangName);
797 $this->tmpl->setAttribute('default_lang', 'visibility', 'visible');
800 $itemId = $this->entryId;
801 if ($historyIndex >= 0) $itemId .= '(' . ($historyIndex +1) . ')';// 履歴番号
802 $this->tmpl->addVar('_widget', 'id', $itemId);
804 if ($this->serialNo == 0){ // 未登録データのとき
806 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
809 $this->tmpl->setAttribute('delete_button', 'visibility', 'visible');// デフォルト言語以外はデータ削除
810 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');
813 //if (!empty($this->entryId)){ // コンテンツが選択されているとき
814 // self::$_mainDb->getAllLang(array($this, 'langLoop'));
815 // $this->tmpl->setAttribute('select_lang', 'visibility', 'visible');
820 $this->tmpl->addVar('_widget', 'calendar_img', $this->getUrl($this->gEnv->getRootUrl() . self::CALENDAR_ICON_FILE)); // カレンダーアイコン
823 if ($openBy == 'simple') $this->tmpl->setAttribute('cancel_button', 'visibility', 'hidden'); // 詳細画面のみの表示のときは戻るボタンを隠す
826 * 取得したデータをテンプレートに設定する
828 * @param int $index 行番号(0~)
829 * @param array $fetchedRow フェッチ取得した行
830 * @param object $param 未使用
831 * @return bool true=処理続行の場合、false=処理終了の場合
833 function itemListLoop($index, $fetchedRow, $param)
836 $serial = $fetchedRow['be_serial'];
839 $categoryArray = array();
840 $ret = self::$_mainDb->getEntryBySerial($serial, $row, $categoryRow);
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, '…');
846 $categoryArray[] = substr($categoryRow[$i]['bc_name'], 0, self::CATEGORY_NAME_SIZE) . '...';
850 $category = implode(',', $categoryArray);
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;
859 $totalViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(self::CONTENT_TYPE, $serial);
862 $now = date("Y/m/d H:i:s"); // 現在日時
863 $startDt = $fetchedRow['be_active_start_dt'];
864 $endDt = $fetchedRow['be_active_end_dt'];
866 $isActive = false; // 公開状態
867 if ($fetchedRow['be_status'] == 2) $isActive = $this->isActive($startDt, $endDt, $now);// 表示可能
869 if ($isActive){ // コンテンツが公開状態のとき
870 $iconUrl = $this->gEnv->getRootUrl() . self::ACTIVE_ICON_FILE; // 公開中アイコン
873 $iconUrl = $this->gEnv->getRootUrl() . self::INACTIVE_ICON_FILE; // 非公開アイコン
876 $statusImg = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
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']) // 更新日時
894 $this->tmpl->addVars('itemlist', $row);
895 $this->tmpl->parseTemplate('itemlist', 'a');
898 $this->serialArray[] = $serial;
904 * @param int $index 行番号(0~)
905 * @param array $fetchedRow フェッチ取得した行
906 * @param object $param 未使用
907 * @return bool true=処理続行の場合、false=処理終了の場合
909 function langLoop($index, $fetchedRow, $param)
912 if ($fetchedRow['ln_id'] == $this->langId){
913 $selected = 'selected';
915 if ($this->gEnv->getCurrentLanguage() == 'ja'){ // 日本語表示の場合
916 $name = $this->convertToDispString($fetchedRow['ln_name']);
918 $name = $this->convertToDispString($fetchedRow['ln_name_en']);
922 'value' => $this->convertToDispString($fetchedRow['ln_id']), // 言語ID
923 'name' => $name, // 言語名
924 'selected' => $selected // 選択中かどうか
926 $this->tmpl->addVars('lang_list', $row);
927 $this->tmpl->parseTemplate('lang_list', 'a');
933 * @param array $srcRows 取得行
934 * @return array 取得した行
936 function getCategory($srcRows)
938 $destArray = array();
940 for ($i = 0; $i < count($srcRows); $i++){
941 if (!empty($srcRows[$i]['bw_category_id'])){
942 $destArray[] = $srcRows[$i]['bw_category_id'];
944 if ($itemCount >= $this->categoryCount) break;
952 * @param int $size メニューの表示数
955 function createCategoryMenu($size)
957 for ($j = 0; $j < $size; $j++){
959 $this->tmpl->clearTemplate('category_list');
960 for ($i = 0; $i < count($this->categoryListData); $i++){
961 $categoryId = $this->categoryListData[$i]['bc_id'];
963 if ($j < count($this->categoryArray) && $this->categoryArray[$j] == $categoryId){
964 $selected = 'selected';
967 'value' => $categoryId, // カテゴリーID
968 'name' => $this->categoryListData[$i]['bc_name'], // カテゴリー名
969 'selected' => $selected // 選択中かどうか
971 $this->tmpl->addVars('category_list', $menurow);
972 $this->tmpl->parseTemplate('category_list', 'a');
975 'index' => $j // 項目番号
977 $this->tmpl->addVars('category', $itemRow);
978 $this->tmpl->parseTemplate('category', 'a');
984 * @param string $blogId ブログID
985 * @return string ブログ名
987 function getBlogName($blogId)
989 $ret = self::$_mainDb->getBlogInfoById($blogId, $row);
991 return $row['bl_name'];
993 return self::NO_BLOG_NAME;
1001 function createBlogIdMenu()
1004 if (empty($this->blogId)) $selected ='selected';
1006 'value' => $this->convertToDispString(''), // ブログID
1007 'name' => $this->convertToDispString(self::NO_BLOG_NAME), // ブログ名
1008 'selected' => $selected // 選択中かどうか
1010 $this->tmpl->addVars('blogid_list', $row);
1011 $this->tmpl->parseTemplate('blogid_list', 'a');
1013 $ret = self::$_mainDb->getAllBlogId($rows);
1015 for ($i = 0; $i < count($rows); $i++){
1017 if ($rows[$i]['bl_id'] == $this->blogId) $selected = 'selected';
1019 'value' => $this->convertToDispString($rows[$i]['bl_id']), // ブログID
1020 'name' => $this->convertToDispString($rows[$i]['bl_name']), // ブログ名
1021 'selected' => $selected // 選択中かどうか
1023 $this->tmpl->addVars('blogid_list', $row);
1024 $this->tmpl->parseTemplate('blogid_list', 'a');
1031 * @param timestamp $startDt 公開開始日時
1032 * @param timestamp $endDt 公開終了日時
1033 * @param timestamp $now 基準日時
1034 * @return bool true=公開可能、false=公開不可
1036 function isActive($startDt, $endDt, $now)
1038 $isActive = false; // 公開状態
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; // 公開状態
1047 if (strtotime($startDt) <= strtotime($now) && strtotime($now) < strtotime($endDt)) $isActive = true; // 公開状態
1054 * @param int $serial 削除対象のコンテンツシリアル番号
1057 function clearCacheBySerial($serial)
1059 $ret = self::$_mainDb->getEntryBySerial($serial, $row, $categoryRow);// 記事ID取得
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);
1071 * @param array $fields フィールドID
1072 * @return bool true=成功、false=失敗
1074 function createUserFields($fields)
1076 if (count($fields) == 0) return true;
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'); // 最初の行の場合
1086 $value = $this->fieldValueArray[$key];
1087 if (!isset($value)) $value = '';
1090 'row_count' => $fieldCount,
1091 'field_id' => $this->convertToDispString($key),
1092 'value' => $this->convertToDispString($value)
1094 $this->tmpl->addVars('user_fields', $row);
1095 $this->tmpl->parseTemplate('user_fields', 'a');