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: blog_mainEntryWidgetContainer.php 5236 2012-09-21 01:38:04Z fishbone $
14 * @link http://www.magic3.org
16 //require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_blog_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/blog_mainBaseWidgetContainer.php');
18 require_once($gEnvManager->getCurrentWidgetDbPath() . '/blog_mainDb.php');
20 // このファイルはadmin_blog_mainEntryWidgetContainer.phpの内容と同じ。クラス名の定義のみ異なる。
21 //class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetContainer
22 class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer
24 private $serialNo; // 選択中の項目のシリアル番号
26 private $blogId; // 所属ブログ
27 private $langId; // 現在の選択言語
28 private $serialArray = array(); // 表示されている項目シリアル番号
29 private $categoryListData; // 全記事カテゴリー
30 private $categoryArray; // 選択中の記事カテゴリー
31 private $categoryCount; // カテゴリ数
32 private $isMultiLang; // 多言語対応画面かどうか
33 private $fieldValueArray; // ユーザ定義フィールド入力値
34 const ICON_SIZE = 16; // アイコンのサイズ
35 const CONTENT_TYPE = 'bg'; // 記事参照数取得用
36 const DEFAULT_LIST_COUNT = 20; // 最大リスト表示数
37 //const CATEGORY_COUNT = 2; // 記事カテゴリーの選択可能数
38 const CATEGORY_NAME_SIZE = 20; // カテゴリー名の最大文字列長
39 const CALENDAR_ICON_FILE = '/images/system/calendar.png'; // カレンダーアイコン
40 const ACTIVE_ICON_FILE = '/images/system/active.png'; // 公開中アイコン
41 const INACTIVE_ICON_FILE = '/images/system/inactive.png'; // 非公開アイコン
42 const NO_BLOG_NAME = '所属なし'; // 所属ブログなし
43 const FIELD_HEAD = 'item_'; // フィールド名の先頭文字列
48 function __construct()
51 parent::__construct();
53 $this->isMultiLang = $this->gEnv->isMultiLanguageSite(); // 多言語対応画面かどうか
58 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
59 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
61 * @param RequestManager $request HTTPリクエスト処理クラス
62 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
63 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
65 function _setTemplate($request, &$param)
67 $task = $request->trimValueOf('task');
69 if ($task == 'entry_detail'){ // 詳細画面
70 return 'admin_entry_detail.tmpl.html';
72 return 'admin_entry.tmpl.html';
78 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
80 * @param RequestManager $request HTTPリクエスト処理クラス
81 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
84 function _assign($request, &$param)
86 $task = $request->trimValueOf('task');
87 if ($task == 'entry_detail'){ // 詳細画面
88 return $this->createDetail($request);
90 return $this->createList($request);
94 * JavascriptファイルをHTMLヘッダ部に設定
96 * JavascriptファイルをHTMLのheadタグ内に追加出力する。
97 * _assign()よりも後に実行される。
99 * @param RequestManager $request HTTPリクエスト処理クラス
100 * @param object $param 任意使用パラメータ。
101 * @return string Javascriptファイル。出力しない場合は空文字列を設定。
103 function _addScriptFileToHead($request, &$param)
105 $scriptArray = array($this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SCRIPT_FILE), // カレンダースクリプトファイル
106 $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_LANG_FILE), // カレンダー言語ファイル
107 $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SETUP_FILE)); // カレンダーセットアップファイル
112 * CSSファイルをHTMLヘッダ部に設定
114 * CSSファイルをHTMLのheadタグ内に追加出力する。
115 * _assign()よりも後に実行される。
117 * @param RequestManager $request HTTPリクエスト処理クラス
118 * @param object $param 任意使用パラメータ。
119 * @return string CSS文字列。出力しない場合は空文字列を設定。
121 function _addCssFileToHead($request, &$param)
123 return $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_CSS_FILE);
128 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
130 * @param RequestManager $request HTTPリクエスト処理クラス
133 function createList($request)
136 $defaultLangId = $this->gEnv->getDefaultLanguage();
138 $act = $request->trimValueOf('act');
139 $this->langId = $request->trimValueOf('item_lang'); // 現在メニューで選択中の言語
140 if (empty($this->langId)) $this->langId = $defaultLangId; // 言語が選択されていないときは、デフォルト言語を設定
141 if ($this->gEnv->isAdminDirAccess()){ // 管理画面へのアクセスの場合
142 $this->blogId = null; // デフォルトブログ(ブログID空)を含むすべてのブログ記事にアクセス可能
144 $this->blogId = $request->trimValueOf(M3_REQUEST_PARAM_BLOG_ID); // 所属ブログ
148 $pageNo = $request->trimValueOf('page'); // ページ番号
149 if (empty($pageNo)) $pageNo = 1;
152 $maxListCount = self::DEFAULT_LIST_COUNT;
153 $serializedParam = $this->_db->getWidgetParam($this->gEnv->getCurrentWidgetId());
154 if (!empty($serializedParam)){
155 $dispInfo = unserialize($serializedParam);
156 $maxListCount = $dispInfo->maxMemberListCountByAdmin; // 会員リスト最大表示数
159 $search_startDt = $request->trimValueOf('search_start'); // 検索範囲開始日付
160 if (!empty($search_startDt)) $search_startDt = $this->convertToProperDate($search_startDt);
161 $search_endDt = $request->trimValueOf('search_end'); // 検索範囲終了日付
162 if (!empty($search_endDt)) $search_endDt = $this->convertToProperDate($search_endDt);
163 $search_categoryId = $request->trimValueOf('search_category0'); // 検索カテゴリー
164 $search_keyword = $request->trimValueOf('search_keyword'); // 検索キーワード
167 $this->categoryArray = array();
168 if (!empty($search_categoryId)){ // 0以外の値を取得
169 $this->categoryArray[] = $search_categoryId;
172 if ($act == 'delete'){ // 項目削除の場合
173 $listedItem = explode(',', $request->trimValueOf('seriallist'));
175 for ($i = 0; $i < count($listedItem); $i++){
177 $itemName = 'item' . $i . '_selected';
178 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
180 if ($itemValue){ // チェック項目
181 $delItems[] = $listedItem[$i];
184 if (count($delItems) > 0){
186 $delEntryInfo = array();
187 for ($i = 0; $i < count($delItems); $i++){
188 $ret = self::$_mainDb->getEntryBySerial($delItems[$i], $row, $categoryRow);
190 $newInfoObj = new stdClass;
191 $newInfoObj->entryId = $row['be_id']; // 記事ID
192 $newInfoObj->name = $row['be_name']; // 記事タイトル
193 $newInfoObj->thumb = $row['be_thumb_filename']; // サムネール
194 $delEntryInfo[] = $newInfoObj;
198 $ret = self::$_mainDb->delEntryItem($delItems);
199 if ($ret){ // データ削除成功のとき
200 $this->setGuidanceMsg('データを削除しました');
202 // ##### サムネールの削除 #####
203 for ($i = 0; $i < count($delEntryInfo); $i++){
204 $infoObj = $delEntryInfo[$i];
205 $ret = blog_mainCommonDef::removeThumbnail($infoObj->entryId);
207 if (!empty($infoObj->thumb)){
208 $oldFiles = explode(';', $infoObj->thumb);
209 $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $oldFiles);
214 for ($i = 0; $i < count($delItems); $i++){
215 $this->clearCacheBySerial($delItems[$i]);
219 $this->gPage->updateParentWindow();
222 for ($i = 0; $i < count($delEntryInfo); $i++){
223 $infoObj = $delEntryInfo[$i];
224 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $infoObj->name, 2100, 'ID=' . $infoObj->entryId);
227 $this->setAppErrorMsg('データ削除に失敗しました');
230 } else if ($act == 'search'){ // 検索のとき
231 if (!empty($search_startDt) && !empty($search_endDt) && $search_startDt > $search_endDt){
232 $this->setUserErrorMsg('期間の指定範囲にエラーがあります。');
234 $pageNo = 1; // ページ番号初期化
235 } else if ($act == 'selpage'){ // ページ選択
237 // ###### 一覧の取得条件を作成 ######
238 if (!empty($search_endDt)) $endDt = $this->getNextDay($search_endDt);
241 $totalCount = self::$_mainDb->getEntryItemCount($search_startDt, $endDt, $this->categoryArray, $search_keyword, $this->langId, $this->blogId);
244 $pageCount = (int)(($totalCount -1) / $maxListCount) + 1; // 総ページ数
245 if ($pageNo < 1) $pageNo = 1;
246 if ($pageNo > $pageCount) $pageNo = $pageCount;
247 $this->firstNo = ($pageNo -1) * $maxListCount + 1; // 先頭番号
251 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
252 for ($i = 1; $i <= $pageCount; $i++){
254 $link = ' ' . $i;
256 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
263 self::$_mainDb->searchEntryItems($maxListCount, $pageNo, $search_startDt, $endDt, $this->categoryArray, $search_keyword, $this->langId, array($this, 'itemListLoop'), $this->blogId);
264 if (count($this->serialArray) <= 0) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');// 投稿記事がないときは、一覧を表示しない
267 self::$_mainDb->getAllCategory($this->langId, $this->categoryListData);
268 $this->createCategoryMenu(1); // メニューは1つだけ表示
271 $this->tmpl->addVar("_widget", "page_link", $pageLink);
272 $this->tmpl->addVar("_widget", "total_count", $totalCount);
275 $this->tmpl->addVar("_widget", "search_start", $search_startDt); // 開始日付
276 $this->tmpl->addVar("_widget", "search_end", $search_endDt); // 終了日付
277 $this->tmpl->addVar("_widget", "search_keyword", $search_keyword); // 検索キーワード
280 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
281 $this->tmpl->addVar("_widget", "page", $pageNo); // ページ番号
282 $this->tmpl->addVar("_widget", "list_count", $maxListCount); // 一覧表示項目数
287 * @param RequestManager $request HTTPリクエスト処理クラス
290 function createDetail($request)
293 $defaultLangId = $this->gEnv->getDefaultLanguage();
294 $regUserId = $this->gEnv->getCurrentUserId(); // 記事投稿ユーザ
295 //$regDt = date("Y/m/d H:i:s"); // 投稿日時
298 $useMultiBlog = $this->_configArray[blog_mainCommonDef::CF_USE_MULTI_BLOG];// マルチブログを使用するかどうか
299 $this->categoryCount = $this->_configArray[blog_mainCommonDef::CF_CATEGORY_COUNT]; // カテゴリ数
300 if (empty($this->categoryCount)) $this->categoryCount = self::DEFAULT_CATEGORY_COUNT;
303 $contentLayout = array(self::$_configArray[blog_mainCommonDef::CF_LAYOUT_ENTRY_SINGLE], self::$_configArray[blog_mainCommonDef::CF_LAYOUT_ENTRY_LIST]);
304 $fieldInfoArray = blog_mainCommonDef::parseUserMacro($contentLayout);
307 $openBy = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY); // ウィンドウオープンタイプ
308 $act = $request->trimValueOf('act');
309 $this->langId = $request->trimValueOf('item_lang'); // 現在メニューで選択中の言語
310 if (empty($this->langId)) $this->langId = $defaultLangId; // 言語が選択されていないときは、デフォルト言語を設定
311 $this->entryId = $request->trimValueOf('entryid'); // 記事エントリーID
312 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
313 // if (empty($this->serialNo)) $this->serialNo = 0;
314 $this->blogId = $request->trimValueOf(M3_REQUEST_PARAM_BLOG_ID); // 所属ブログ
315 $name = $request->trimValueOf('item_name');
316 $entry_date = $request->trimValueOf('item_entry_date'); // 投稿日
317 $entry_time = $request->trimValueOf('item_entry_time'); // 投稿時間
318 $html = $request->valueOf('item_html');
319 $html2 = $request->valueOf('item_html2');
320 if (strlen($html2) <= 10){ // IE6のときFCKEditorのバグの対応(「続き」が空の場合でもpタグが送信される)
323 $desc = $request->trimValueOf('item_desc'); // 簡易説明
324 $status = $request->trimValueOf('item_status'); // エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
325 $category = ''; // カテゴリー
326 $showComment = ($request->trimValueOf('show_comment') == 'on') ? 1 : 0; // コメントを表示するかどうか
327 $receiveComment = ($request->trimValueOf('receive_comment') == 'on') ? 1 : 0; // コメントを受け付けるかどうか
328 $relatedContent = $request->trimValueOf('item_related_content'); // 関連コンテンツ
331 $this->categoryArray = array();
332 for ($i = 0; $i < $this->categoryCount; $i++){
333 $itemName = 'item_category' . $i;
334 $itemValue = $request->trimValueOf($itemName);
335 if (!empty($itemValue)){ // 0以外の値を取得
336 $this->categoryArray[] = $itemValue;
341 $start_date = $request->trimValueOf('item_start_date'); // 公開期間開始日付
342 if (!empty($start_date)) $start_date = $this->convertToProperDate($start_date);
343 $start_time = $request->trimValueOf('item_start_time'); // 公開期間開始時間
344 if (empty($start_date)){
345 $start_time = ''; // 日付が空のときは時刻も空に設定する
347 if (empty($start_time)) $start_time = '00:00'; // 日付が入っているときは時間にデフォルト値を設定
349 if (!empty($start_time)) $start_time = $this->convertToProperTime($start_time, 1/*時分フォーマット*/);
351 $end_date = $request->trimValueOf('item_end_date'); // 公開期間終了日付
352 if (!empty($end_date)) $end_date = $this->convertToProperDate($end_date);
353 $end_time = $request->trimValueOf('item_end_time'); // 公開期間終了時間
354 if (empty($end_date)){
355 $end_time = ''; // 日付が空のときは時刻も空に設定する
357 if (empty($end_time)) $end_time = '00:00'; // 日付が入っているときは時間にデフォルト値を設定
359 if (!empty($end_time)) $end_time = $this->convertToProperTime($end_time, 1/*時分フォーマット*/);
362 $this->fieldValueArray = array(); // ユーザ定義フィールド入力値
363 $fieldKeys = array_keys($fieldInfoArray);
364 for ($i = 0; $i < count($fieldKeys); $i++){
365 $fieldKey = $fieldKeys[$i];
366 $itemName = self::FIELD_HEAD . $fieldKey;
367 $itemValue = $this->cleanMacroValue($request->trimValueOf($itemName));
368 if (!empty($itemValue)) $this->fieldValueArray[$fieldKey] = $itemValue;
371 $historyIndex = -1; // 履歴番号
372 $reloadData = false; // データの再ロード
373 if ($act == 'select'){ // 一覧から選択のとき
374 $reloadData = true; // データの再ロード
375 } else if ($act == 'selectlang'){ // 項目選択の場合
377 $this->serialNo = self::$_mainDb->getEntrySerialNoByContentId($this->entryId, $this->langId);
378 if (empty($this->serialNo)){
380 //$name = ''; // タイトル
381 //$html = ''; // HTML
382 $status = 0; // エントリー状況
383 $reg_user = ''; // 投稿者
384 $update_user = '';// 更新者
387 $reloadData = true; // データの再ロード
389 } else if ($act == 'add' || $act == 'addlang'){ // 項目追加の場合
391 $this->checkInput($name, 'タイトル');
392 $this->checkDate($entry_date, '投稿日付');
393 $this->checkTime($entry_time, '投稿時間');
396 if (!empty($start_date) && !empty($end_date)){
397 if (strtotime($start_date . ' ' . $start_time) >= strtotime($end_date . ' ' . $end_time)) $this->setUserErrorMsg('公開期間が不正です');
401 if ($this->getMsgCount() == 0){
403 if (empty($start_date)){
404 $startDt = $this->gEnv->getInitValueOfTimestamp();
406 $startDt = $start_date . ' ' . $start_time;
408 if (empty($end_date)){
409 $endDt = $this->gEnv->getInitValueOfTimestamp();
411 $endDt = $end_date . ' ' . $end_time;
413 $regDt = $this->convertToProperDate($entry_date) . ' ' . $this->convertToProperTime($entry_time); // 投稿日時
417 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){ // // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
419 $nextEntryId = self::$_mainDb->getNextEntryId();
421 $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html);
422 if (empty($thumbPath) && !empty($html2)) $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html2); // 本文1に画像がないときは本文2を検索
423 if (!empty($thumbPath)){
424 $ret = $this->gInstance->getImageManager()->createSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $nextEntryId, $thumbPath, $destFilename);
425 if ($ret) $thumbFilename = implode(';', $destFilename);
430 $otherParams = array( 'be_description' => $desc, // 簡易説明
431 'be_thumb_filename' => $thumbFilename, // サムネールファイル名
432 'be_related_content' => $relatedContent, // 関連コンテンツ
433 'be_option_fields' => $this->serializeArray($this->fieldValueArray)); // ユーザ定義フィールド値
434 //if ($act == 'add'){
435 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){ // 多言語でデフォルト言語、または単一言語のとき
436 $ret = self::$_mainDb->addEntryItem($nextEntryId * (-1)/*次のコンテンツIDのチェック*/, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
437 $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
439 $ret = self::$_mainDb->addEntryItem($this->entryId, $this->langId, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
440 $regUserId, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $otherParams);
443 $this->setGuidanceMsg('データを追加しました');
446 $this->serialNo = $newSerial;
447 $reloadData = true; // データの再ロード
449 // ##### サムネールの作成 #####
450 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
452 $entryId = $row['be_id']; // 記事ID
453 $html = $row['be_html']; // HTML
454 $updateDt = $row['be_create_dt'];
455 $status = $row['be_status'];
457 if ($status == 2){ // 公開の場合
458 $ret = blog_mainCommonDef::createThumbnail($html, $entryId, $updateDt);
460 $ret = blog_mainCommonDef::removeThumbnail($entryId);
465 $this->clearCacheBySerial($this->serialNo);
468 $this->gPage->updateParentWindow();
472 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
474 $this->entryId = $row['be_id']; // 記事ID
475 $name = $row['be_name']; // コンテンツ名前
478 switch ($row['be_status']){
479 case 1: $statusStr = '編集中'; break;
480 case 2: $statusStr = '公開'; break;
481 case 3: $statusStr = '非公開'; break;
484 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を追加(' . $statusStr . ')しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
486 $this->setAppErrorMsg('データ追加に失敗しました');
489 } else if ($act == 'update'){ // 項目更新の場合
491 $this->checkInput($name, 'タイトル');
492 $this->checkDate($entry_date, '投稿日付');
493 $this->checkTime($entry_time, '投稿時間');
496 if (!empty($start_date) && !empty($end_date)){
497 if (strtotime($start_date . ' ' . $start_time) >= strtotime($end_date . ' ' . $end_time)) $this->setUserErrorMsg('公開期間が不正です');
501 if ($this->getMsgCount() == 0){
503 if (empty($start_date)){
504 $startDt = $this->gEnv->getInitValueOfTimestamp();
506 $startDt = $start_date . ' ' . $start_time;
508 if (empty($end_date)){
509 $endDt = $this->gEnv->getInitValueOfTimestamp();
511 $endDt = $end_date . ' ' . $end_time;
513 $regDt = $this->convertToProperDate($entry_date) . ' ' . $this->convertToProperTime($entry_time); // 投稿日時
517 if (($this->isMultiLang && $this->langId == $this->gEnv->getDefaultLanguage()) || !$this->isMultiLang){ // // 多言語対応の場合はデフォルト言語が選択されている場合のみ処理を行う
518 $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html);
519 if (empty($thumbPath) && !empty($html2)) $thumbPath = $this->gInstance->getImageManager()->getFirstImagePath($html2); // 本文1に画像がないときは本文2を検索
520 if (!empty($thumbPath)){
521 $ret = $this->gInstance->getImageManager()->createSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $this->entryId, $thumbPath, $destFilename);
522 if ($ret) $thumbFilename = implode(';', $destFilename);
527 $otherParams = array( 'be_description' => $desc, // 簡易説明
528 'be_thumb_filename' => $thumbFilename, // サムネールファイル名
529 'be_related_content' => $relatedContent, // 関連コンテンツ
530 'be_option_fields' => $this->serializeArray($this->fieldValueArray)); // ユーザ定義フィールド値
532 $ret = self::$_mainDb->updateEntryItem($this->serialNo, $name, $html, $html2, $status, $this->categoryArray, $this->blogId,
533 ''/*投稿者そのまま*/, $regDt, $startDt, $endDt, $showComment, $receiveComment, $newSerial, $oldRecord, $otherParams);
535 // コンテンツに画像がなくなった場合は、サムネールを削除
536 if (empty($thumbFilename) && !empty($oldRecord['be_thumb_filename'])){
537 $oldFiles = explode(';', $oldRecord['be_thumb_filename']);
538 $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $oldFiles);
543 $this->setGuidanceMsg('データを更新しました');
546 $this->serialNo = $newSerial;
547 $reloadData = true; // データの再ロード
549 // ##### サムネールの作成 #####
550 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
552 $entryId = $row['be_id']; // 記事ID
553 $html = $row['be_html']; // HTML
554 $updateDt = $row['be_create_dt'];
555 $status = $row['be_status'];
557 if ($status == 2){ // 公開の場合
558 $ret = blog_mainCommonDef::createThumbnail($html, $entryId, $updateDt);
560 $ret = blog_mainCommonDef::removeThumbnail($entryId);
565 $this->clearCacheBySerial($this->serialNo);
568 $this->gPage->updateParentWindow();
572 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
574 $this->entryId = $row['be_id']; // 記事ID
575 $name = $row['be_name']; // コンテンツ名前
578 switch ($row['be_status']){
579 case 1: $statusStr = '編集中'; break;
580 case 2: $statusStr = '公開'; break;
581 case 3: $statusStr = '非公開'; break;
584 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を更新(' . $statusStr . ')しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
586 $this->setAppErrorMsg('データ更新に失敗しました');
589 } else if ($act == 'delete'){ // 項目削除の場合
590 if (empty($this->serialNo)){
591 $this->setUserErrorMsg('削除項目が選択されていません');
594 if ($this->getMsgCount() == 0){
596 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
598 $this->entryId = $row['be_id']; // 記事ID
599 $name = $row['be_name']; // コンテンツ名前
602 $ret = self::$_mainDb->delEntryItem(array($this->serialNo));
603 if ($ret){ // データ削除成功のとき
604 $this->setGuidanceMsg('データを削除しました');
606 // ##### サムネールの削除 #####
607 $ret = blog_mainCommonDef::removeThumbnail($this->entryId);
610 if (!empty($row['be_thumb_filename'])){
611 $oldFiles = explode(';', $row['be_thumb_filename']);
612 $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_BLOG, blog_mainCommonDef::$_deviceType, $oldFiles);
616 $this->clearCacheBySerial($this->serialNo);
619 $this->gPage->updateParentWindow();
622 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
624 $this->setAppErrorMsg('データ削除に失敗しました');
627 } else if ($act == 'deleteid'){ // ID項目削除の場合
628 if (empty($this->serialNo)){
629 $this->setUserErrorMsg('削除項目が選択されていません');
632 if ($this->getMsgCount() == 0){
634 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
636 $this->entryId = $row['be_id']; // 記事ID
637 $name = $row['be_name']; // コンテンツ名前
640 $ret = self::$_mainDb->delEntryItemById($this->serialNo);
641 if ($ret){ // データ削除成功のとき
642 $this->setGuidanceMsg('データを削除しました');
644 // ##### サムネールの削除 #####
645 $ret = blog_mainCommonDef::removeThumbnail($this->entryId);
648 $this->clearCacheBySerial($this->serialNo);
651 $this->gPage->updateParentWindow();
654 $this->gOpeLog->writeUserInfo(__METHOD__, 'ブログ記事を削除しました。タイトル: ' . $name, 2100, 'ID=' . $this->entryId);
656 $this->setAppErrorMsg('データ削除に失敗しました');
659 } else if ($act == 'get_history'){ // 履歴データの取得のとき
660 $reloadData = true; // データの再読み込み
661 } else { // 初期画面表示のとき
662 // ##### ブログ記事IDが設定されているとき(他ウィジェットからの表示)は、データを取得 #####
663 if (empty($this->entryId)){
664 if (!empty($this->serialNo)){ // シリアル番号で指定の場合
665 $reloadData = true; // データの再読み込み
669 if ($this->isMultiLang){ // 多言語対応の場合
670 $langId = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_LANG); // lang値を取得
671 if (!empty($langId)) $this->langId = $langId;
675 $ret = self::$_mainDb->getEntryItem($this->entryId, $this->langId, $row);
677 $this->serialNo = $row['be_serial']; // シリアル番号
678 $reloadData = true; // データの再読み込み
683 if (empty($this->serialNo)){
685 // 所属ブログIDは親ウィンドウから引き継ぐ
686 //$this->blogId = ''; // 所属ブログ
687 $entry_date = date("Y/m/d"); // 投稿日
688 $entry_time = date("H:i:s"); // 投稿時間
689 $showComment = 1; // コメントを表示するかどうか
690 $receiveComment = 1; // コメントを受け付けるかどうか
695 if ($reloadData){ // データの再ロード
696 $ret = self::$_mainDb->getEntryBySerial($this->serialNo, $row, $categoryRow);
698 $this->entryId = $row['be_id']; // 記事ID
699 $this->blogId = $row['be_blog_id']; // 所属ブログ
700 $name = $row['be_name']; // タイトル
701 $html = $row['be_html']; // HTML
702 $html = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->getUrl($this->gEnv->getRootUrl()), $html);// アプリケーションルートを変換
703 $html2 = $row['be_html_ext']; // HTML
704 $html2 = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->getUrl($this->gEnv->getRootUrl()), $html2);// アプリケーションルートを変換
705 $desc = $row['be_description']; // 簡易説明
706 $status = $row['be_status']; // エントリー状況
707 $reg_user = $row['reg_user_name']; // 投稿者
708 $entry_date = $this->timestampToDate($row['be_regist_dt']); // 投稿日
709 $entry_time = $this->timestampToTime($row['be_regist_dt']); // 投稿時間
710 $update_user = $this->convertToDispString($row['lu_name']);// 更新者
711 $update_dt = $this->convertToDispDateTime($row['be_create_dt']);
712 $start_date = $this->convertToDispDate($row['be_active_start_dt']); // 公開期間開始日
713 $start_time = $this->convertToDispTime($row['be_active_start_dt'], 1/*時分*/); // 公開期間開始時間
714 $end_date = $this->convertToDispDate($row['be_active_end_dt']); // 公開期間終了日
715 $end_time = $this->convertToDispTime($row['be_active_end_dt'], 1/*時分*/); // 公開期間終了時間
716 $showComment = $row['be_show_comment']; // コメントを表示するかどうか
717 $receiveComment = $row['be_receive_comment']; // コメントを受け付けるかどうか
718 $relatedContent = $row['be_related_content']; // 関連コンテンツ
721 $this->categoryArray = $this->getCategory($categoryRow);
724 if ($row['be_deleted']) $historyIndex = $row['be_history_index'];
727 $this->fieldValueArray = $this->unserializeArray($row['be_option_fields']);
731 self::$_mainDb->getAllCategory($this->langId, $this->categoryListData);
732 $this->createCategoryMenu($this->categoryCount);
735 $this->createUserFields($fieldInfoArray);
738 if (empty($useMultiBlog)){
739 $this->tmpl->setAttribute('show_blogid_area', 'visibility', 'visible');
741 $blogName = $this->getBlogName($this->blogId);
742 $this->tmpl->addVar("show_blogid_area", "blog_id", $this->blogId); // 所属ブログID
743 $this->tmpl->addVar("show_blogid_area", "blog_name", $blogName); // 所属ブログ名
744 } else { // マルチブログを使用するとき
745 $this->tmpl->setAttribute('select_blogid_area', 'visibility', 'visible');
748 $this->createBlogIdMenu();
752 $previewUrl = $this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $this->entryId;
753 if ($historyIndex >= 0) $previewUrl .= '&' . M3_REQUEST_PARAM_HISTORY . '=' . $historyIndex;
754 $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_PREVIEW;
755 if ($this->isMultiLang) $previewUrl .= '&' . M3_REQUEST_PARAM_OPERATION_LANG . '=' . $this->langId; // 多言語対応の場合は言語IDを付加
756 $this->tmpl->addVar('_widget', 'preview_url', $previewUrl);// プレビュー用URL(一般画面)
759 $this->tmpl->addVar('_widget', 'entryid', $this->entryId);
760 $this->tmpl->addVar("_widget", "item_name", $this->convertToDispString($name)); // 名前
761 $this->tmpl->addVar("_widget", "item_html", $html); // HTML
762 $this->tmpl->addVar("_widget", "item_html2", $html2); // HTML(続き)
763 $this->tmpl->addVar("_widget", "desc", $desc); // 簡易説明
765 case 1: $this->tmpl->addVar("_widget", "selected_edit", 'selected'); break;
766 case 2: $this->tmpl->addVar("_widget", "selected_public", 'selected'); break;
767 case 3: $this->tmpl->addVar("_widget", "selected_closed", 'selected'); break;
769 $this->tmpl->addVar("_widget", "entry_user", $reg_user); // 投稿者
770 $this->tmpl->addVar("_widget", "entry_date", $entry_date); // 投稿日
771 $this->tmpl->addVar("_widget", "entry_time", $entry_time); // 投稿時
772 $this->tmpl->addVar("_widget", "update_user", $update_user); // 更新者
773 $this->tmpl->addVar("_widget", "update_dt", $update_dt); // 更新日時
774 $this->tmpl->addVar("_widget", "start_date", $start_date); // 公開期間開始日
775 $this->tmpl->addVar("_widget", "start_time", $start_time); // 公開期間開始時間
776 $this->tmpl->addVar("_widget", "end_date", $end_date); // 公開期間終了日
777 $this->tmpl->addVar("_widget", "end_time", $end_time); // 公開期間終了時間
779 if ($showComment) $checked = 'checked';
780 $this->tmpl->addVar("_widget", "show_comment", $checked);// コメントを表示するかどうか
782 if ($receiveComment) $checked = 'checked';
783 $this->tmpl->addVar("_widget", "receive_comment", $checked);// コメントを受け付けるかどうか
784 $this->tmpl->addVar("_widget", "related_content", $relatedContent); // 関連コンテンツ
787 $this->tmpl->addVar("_widget", "serial", $this->serialNo); // シリアル番号
789 // 入力フィールドの設定、共通項目のデータ設定
790 if (empty($this->entryId)){ // 記事IDが0のときは、新規追加モードにする
792 $this->tmpl->addVar('_widget', 'id', '新規');
794 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
795 $this->tmpl->addVar('_widget', 'preview_btn_disabled', 'disabled');// プレビューボタン使用不可
796 $this->tmpl->addVar('_widget', 'history_btn_disabled', 'disabled');// 履歴ボタン使用不可
799 $this->tmpl->addVar("default_lang", "default_lang", $defaultLangName);
800 $this->tmpl->setAttribute('default_lang', 'visibility', 'visible');
803 $itemId = $this->entryId;
804 if ($historyIndex >= 0) $itemId .= '(' . ($historyIndex +1) . ')';// 履歴番号
805 $this->tmpl->addVar('_widget', 'id', $itemId);
807 if ($this->serialNo == 0){ // 未登録データのとき
809 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
812 $this->tmpl->setAttribute('delete_button', 'visibility', 'visible');// デフォルト言語以外はデータ削除
813 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');
816 //if (!empty($this->entryId)){ // コンテンツが選択されているとき
817 // self::$_mainDb->getAllLang(array($this, 'langLoop'));
818 // $this->tmpl->setAttribute('select_lang', 'visibility', 'visible');
823 $this->tmpl->addVar('_widget', 'calendar_img', $this->getUrl($this->gEnv->getRootUrl() . self::CALENDAR_ICON_FILE)); // カレンダーアイコン
826 if ($openBy == 'simple') $this->tmpl->setAttribute('cancel_button', 'visibility', 'hidden'); // 詳細画面のみの表示のときは戻るボタンを隠す
829 * 取得したデータをテンプレートに設定する
831 * @param int $index 行番号(0~)
832 * @param array $fetchedRow フェッチ取得した行
833 * @param object $param 未使用
834 * @return bool true=処理続行の場合、false=処理終了の場合
836 function itemListLoop($index, $fetchedRow, $param)
839 $serial = $fetchedRow['be_serial'];
842 $categoryArray = array();
843 $ret = self::$_mainDb->getEntryBySerial($serial, $row, $categoryRow);
845 for ($i = 0; $i < count($categoryRow); $i++){
846 if (function_exists('mb_strimwidth')){
847 $categoryArray[] = mb_strimwidth($categoryRow[$i]['bc_name'], 0, self::CATEGORY_NAME_SIZE, '…');
849 $categoryArray[] = substr($categoryRow[$i]['bc_name'], 0, self::CATEGORY_NAME_SIZE) . '...';
853 $category = implode(',', $categoryArray);
856 switch ($fetchedRow['be_status']){
857 case 1: $status = '<font color="orange">編集中</font>'; break;
858 case 2: $status = '<font color="green">公開</font>'; break;
859 case 3: $status = '非公開'; break;
862 $totalViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(self::CONTENT_TYPE, $serial);
865 $now = date("Y/m/d H:i:s"); // 現在日時
866 $startDt = $fetchedRow['be_active_start_dt'];
867 $endDt = $fetchedRow['be_active_end_dt'];
869 $isActive = false; // 公開状態
870 if ($fetchedRow['be_status'] == 2) $isActive = $this->isActive($startDt, $endDt, $now);// 表示可能
872 if ($isActive){ // コンテンツが公開状態のとき
873 $iconUrl = $this->gEnv->getRootUrl() . self::ACTIVE_ICON_FILE; // 公開中アイコン
876 $iconUrl = $this->gEnv->getRootUrl() . self::INACTIVE_ICON_FILE; // 非公開アイコン
879 $statusImg = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
882 'index' => $index, // 項目番号
883 'no' => $index + 1, // 行番号
884 'serial' => $serial, // シリアル番号
885 'id' => $this->convertToDispString($fetchedRow['be_id']), // ID
886 'name' => $this->convertToDispString($fetchedRow['be_name']), // 名前
887 'lang' => $lang, // 対応言語
888 'status_img' => $statusImg, // ユーザからの参照状況
889 'status' => $status, // 公開状況
890 'category' => $category, // 記事カテゴリー
891 'view_count' => $totalViewCount, // 総参照数
892 'reg_user' => $this->convertToDispString($fetchedRow['lu_name']), // 投稿者
893 'reg_date' => $this->convertToDispDateTime($fetchedRow['be_regist_dt']), // 投稿日時
894 'update_user' => $this->convertToDispString($fetchedRow['lu_name']), // 更新者
895 'update_date' => $this->convertToDispDateTime($fetchedRow['be_create_dt']) // 更新日時
897 $this->tmpl->addVars('itemlist', $row);
898 $this->tmpl->parseTemplate('itemlist', 'a');
901 $this->serialArray[] = $serial;
907 * @param int $index 行番号(0~)
908 * @param array $fetchedRow フェッチ取得した行
909 * @param object $param 未使用
910 * @return bool true=処理続行の場合、false=処理終了の場合
912 function langLoop($index, $fetchedRow, $param)
915 if ($fetchedRow['ln_id'] == $this->langId){
916 $selected = 'selected';
918 if ($this->gEnv->getCurrentLanguage() == 'ja'){ // 日本語表示の場合
919 $name = $this->convertToDispString($fetchedRow['ln_name']);
921 $name = $this->convertToDispString($fetchedRow['ln_name_en']);
925 'value' => $this->convertToDispString($fetchedRow['ln_id']), // 言語ID
926 'name' => $name, // 言語名
927 'selected' => $selected // 選択中かどうか
929 $this->tmpl->addVars('lang_list', $row);
930 $this->tmpl->parseTemplate('lang_list', 'a');
936 * @param array $srcRows 取得行
937 * @return array 取得した行
939 function getCategory($srcRows)
941 $destArray = array();
943 for ($i = 0; $i < count($srcRows); $i++){
944 if (!empty($srcRows[$i]['bw_category_id'])){
945 $destArray[] = $srcRows[$i]['bw_category_id'];
947 if ($itemCount >= $this->categoryCount) break;
955 * @param int $size メニューの表示数
958 function createCategoryMenu($size)
960 for ($j = 0; $j < $size; $j++){
962 $this->tmpl->clearTemplate('category_list');
963 for ($i = 0; $i < count($this->categoryListData); $i++){
964 $categoryId = $this->categoryListData[$i]['bc_id'];
966 if ($j < count($this->categoryArray) && $this->categoryArray[$j] == $categoryId){
967 $selected = 'selected';
970 'value' => $categoryId, // カテゴリーID
971 'name' => $this->categoryListData[$i]['bc_name'], // カテゴリー名
972 'selected' => $selected // 選択中かどうか
974 $this->tmpl->addVars('category_list', $menurow);
975 $this->tmpl->parseTemplate('category_list', 'a');
978 'index' => $j // 項目番号
980 $this->tmpl->addVars('category', $itemRow);
981 $this->tmpl->parseTemplate('category', 'a');
987 * @param string $blogId ブログID
988 * @return string ブログ名
990 function getBlogName($blogId)
992 $ret = self::$_mainDb->getBlogInfoById($blogId, $row);
994 return $row['bl_name'];
996 return self::NO_BLOG_NAME;
1004 function createBlogIdMenu()
1007 if (empty($this->blogId)) $selected ='selected';
1009 'value' => $this->convertToDispString(''), // ブログID
1010 'name' => $this->convertToDispString(self::NO_BLOG_NAME), // ブログ名
1011 'selected' => $selected // 選択中かどうか
1013 $this->tmpl->addVars('blogid_list', $row);
1014 $this->tmpl->parseTemplate('blogid_list', 'a');
1016 $ret = self::$_mainDb->getAllBlogId($rows);
1018 for ($i = 0; $i < count($rows); $i++){
1020 if ($rows[$i]['bl_id'] == $this->blogId) $selected = 'selected';
1022 'value' => $this->convertToDispString($rows[$i]['bl_id']), // ブログID
1023 'name' => $this->convertToDispString($rows[$i]['bl_name']), // ブログ名
1024 'selected' => $selected // 選択中かどうか
1026 $this->tmpl->addVars('blogid_list', $row);
1027 $this->tmpl->parseTemplate('blogid_list', 'a');
1034 * @param timestamp $startDt 公開開始日時
1035 * @param timestamp $endDt 公開終了日時
1036 * @param timestamp $now 基準日時
1037 * @return bool true=公開可能、false=公開不可
1039 function isActive($startDt, $endDt, $now)
1041 $isActive = false; // 公開状態
1043 if ($startDt == $this->gEnv->getInitValueOfTimestamp() && $endDt == $this->gEnv->getInitValueOfTimestamp()){
1044 $isActive = true; // 公開状態
1045 } else if ($startDt == $this->gEnv->getInitValueOfTimestamp()){
1046 if (strtotime($now) < strtotime($endDt)) $isActive = true; // 公開状態
1047 } else if ($endDt == $this->gEnv->getInitValueOfTimestamp()){
1048 if (strtotime($now) >= strtotime($startDt)) $isActive = true; // 公開状態
1050 if (strtotime($startDt) <= strtotime($now) && strtotime($now) < strtotime($endDt)) $isActive = true; // 公開状態
1057 * @param int $serial 削除対象のコンテンツシリアル番号
1060 function clearCacheBySerial($serial)
1062 $ret = self::$_mainDb->getEntryBySerial($serial, $row, $categoryRow);// 記事ID取得
1064 $entryId = $row['be_id']; // 記事ID
1065 $urlParam = array();
1066 $urlParam[] = M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $entryId; // 記事ID
1067 $urlParam[] = M3_REQUEST_PARAM_BLOG_ENTRY_ID_SHORT . '=' . $entryId; // 記事ID略式
1068 $this->clearCache($urlParam);
1074 * @param array $fields フィールドID
1075 * @return bool true=成功、false=失敗
1077 function createUserFields($fields)
1079 if (count($fields) == 0) return true;
1081 $this->tmpl->setAttribute('user_fields', 'visibility', 'visible');
1082 $keys = array_keys($fields);
1083 $fieldCount = count($keys);
1084 for ($i = 0; $i < $fieldCount; $i++){
1085 if ($i == 0) $this->tmpl->addVar('user_fields', 'type', 'first'); // 最初の行の場合
1089 $value = $this->fieldValueArray[$key];
1090 if (!isset($value)) $value = '';
1093 'row_count' => $fieldCount,
1094 'field_id' => $this->convertToDispString($key),
1095 'value' => $this->convertToDispString($value)
1097 $this->tmpl->addVars('user_fields', $row);
1098 $this->tmpl->parseTemplate('user_fields', 'a');