OSDN Git Service

ブログメインウィジェットの管理画面、記事詳細にオンザフライプレビュー機能追加。
authornaoki hirata <naoki@magic3.org>
Thu, 9 Jun 2016 13:34:41 +0000 (22:34 +0900)
committernaoki hirata <naoki@magic3.org>
Thu, 9 Jun 2016 13:34:41 +0000 (22:34 +0900)
widgets/blog_main/include/container/admin_blog_mainEntryWidgetContainer.php
widgets/blog_main/include/container/blog_mainEntryWidgetContainer.php
widgets/blog_main/include/container/blog_mainTopWidgetContainer.php
widgets/blog_main/include/db/blog_mainDb.php

index fe01a7d..d726b09 100644 (file)
@@ -993,7 +993,7 @@ class admin_blog_mainEntryWidgetContainer extends admin_blog_mainBaseWidgetConta
                        $this->tmpl->addVar('_widget', 'id', '新規');
                        
                        $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
-                       $this->tmpl->addVar('_widget', 'preview_btn_disabled', 'disabled');// プレビューボタン使用不可
+//                     $this->tmpl->addVar('_widget', 'preview_btn_disabled', 'disabled');// プレビューボタン使用不可
                        $this->tmpl->addVar('_widget', 'history_btn_disabled', 'disabled');// 履歴ボタン使用不可
                        $this->tmpl->addVar('_widget', 'image_btn_disabled', 'disabled');// 画像ボタン使用不可
                        $this->tmpl->addVar('_widget', 'schedule_btn_disabled', 'disabled');// 記事予約ボタン使用不可
index 6e9bcf7..fc0ccb1 100644 (file)
@@ -995,7 +995,7 @@ class blog_mainEntryWidgetContainer extends blog_mainBaseWidgetContainer
                        $this->tmpl->addVar('_widget', 'id', '新規');
                        
                        $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
-                       $this->tmpl->addVar('_widget', 'preview_btn_disabled', 'disabled');// プレビューボタン使用不可
+//                     $this->tmpl->addVar('_widget', 'preview_btn_disabled', 'disabled');// プレビューボタン使用不可
                        $this->tmpl->addVar('_widget', 'history_btn_disabled', 'disabled');// 履歴ボタン使用不可
                        $this->tmpl->addVar('_widget', 'image_btn_disabled', 'disabled');// 画像ボタン使用不可
                        $this->tmpl->addVar('_widget', 'schedule_btn_disabled', 'disabled');// 記事予約ボタン使用不可
index a2891b2..169f0a2 100644 (file)
@@ -307,19 +307,35 @@ class blog_mainTopWidgetContainer extends blog_mainBaseWidgetContainer
        {
                $sendButtonLabel = 'コメントを投稿';             // 送信ボタンラベル
                $sendStatus = 0;                // 送信状況
+               $showPreviewEntry = false;              // プレビュー用の記事を表示するかどうか
                
-               // 記事ID指定のときは記事を取得
-               $entryRow = array();
-               if (!empty($this->entryId)){
-                       $ret = self::$_mainDb->getEntryItem($this->entryId, $this->_langId, $entryRow);
-                       if ($ret){
-                               // ### ウィジェットタイトルは表示しない ###
-                               // ページのタイトル設定
-                       //      $this->title = $entryRow['be_name'];            // ウィジェットタイトル
-                               $this->pageTitle = $entryRow['be_name'];                        // 画面タイトル
+               // プレビューモードの場合はプレビュー用の記事があるかどうか確認
+               if ($this->preview){            // プレビューモードの場合
+                       // 記事IDを解析
+                       list($entryId, $userId) = explode(M3_CONTENT_PREVIEW_ID_SEPARATOR, $this->entryId);
+                       
+                       // ユーザIDのチェック
+                       if ($userId == $this->_userId){
+                               $this->entryId = intval($entryId);
+                               
+                               // プレビュー記事を取得
+                               $ret = self::$_mainDb->getEntryPreviewItem($this->entryId, $this->_langId, $entryRow);
+                               if ($ret) $showPreviewEntry = true;                     // プレビュー用の記事を表示
+                       }
+               }
+               
+               // 単体記事を取得
+               if (!$showPreviewEntry){
+                       // 記事ID指定のときは記事を取得
+                       if (!empty($this->entryId)){
+                               $ret = self::$_mainDb->getEntryItem($this->entryId, $this->_langId, $entryRow);
                        }
                }
                
+               if (!empty($entryRow)){         // 記事レコードがあるとき
+                       $this->pageTitle = $entryRow['be_name'];                        // 画面タイトル
+               }
+               
                // 入力値取得
                $act = $request->trimValueOf('act');
                $commentTitle = $request->trimValueOf('title');
@@ -435,13 +451,19 @@ class blog_mainTopWidgetContainer extends blog_mainBaseWidgetContainer
                        }
                }
 
-               // 記事の取得
-               if ($this->isSystemManageUser){         // システム管理ユーザの場合
-                       self::$_mainDb->getEntryItems($this->entryViewCount, $this->pageNo, $this->now, $this->entryId, $this->startDt/*期間開始*/, $this->endDt/*期間終了*/,
-                                                                               ''/*検索キーワード*/, $this->_langId, $this->entryViewOrder, array($this, 'itemsLoop'), null/*ブログ指定なし*/, null/*ユーザ指定なし*/, $this->preview);
+               // ##### 記事の出力 #####
+               // ***** 記事の出力は直接itemsLoop()を呼び出す方法に変更すべき *****
+               // $this->itemsLoop($index, $fetchedRow)
+               if ($showPreviewEntry){         // プレビュー記事を表示の場合
+                       $this->itemsLoop(0, $entryRow);
                } else {
-                       self::$_mainDb->getEntryItems($this->entryViewCount, $this->pageNo, $this->now, $this->entryId, $this->startDt/*期間開始*/, $this->endDt/*期間終了*/,
-                                                                               ''/*検索キーワード*/, $this->_langId, $this->entryViewOrder, array($this, 'itemsLoop'), null/*ブログ指定なし*/, $this->_userId, $this->preview);
+                       if ($this->isSystemManageUser){         // システム管理ユーザの場合
+                               self::$_mainDb->getEntryItems($this->entryViewCount, $this->pageNo, $this->now, $this->entryId, $this->startDt/*期間開始*/, $this->endDt/*期間終了*/,
+                                                                                       ''/*検索キーワード*/, $this->_langId, $this->entryViewOrder, array($this, 'itemsLoop'), null/*ブログ指定なし*/, null/*ユーザ指定なし*/, $this->preview);
+                       } else {
+                               self::$_mainDb->getEntryItems($this->entryViewCount, $this->pageNo, $this->now, $this->entryId, $this->startDt/*期間開始*/, $this->endDt/*期間終了*/,
+                                                                                       ''/*検索キーワード*/, $this->_langId, $this->entryViewOrder, array($this, 'itemsLoop'), null/*ブログ指定なし*/, $this->_userId, $this->preview);
+                       }
                }
                
                // マルチブログのときはパンくずリストにブログ名を追加
index 9bd03da..ee022cc 100644 (file)
@@ -2021,5 +2021,31 @@ class blog_mainDb extends BaseDb
                $ret = $this->endTransaction();
                return $ret;
        }
+       /**
+        * プレビュー用記事を取得
+        *
+        * @param int,array             $id                             エントリーID
+        * @param string        $langId                         言語
+        * @param array     $row                                レコード
+        * @return bool                                                 取得 = true, 取得なし= false
+        */
+       function getEntryPreviewItem($id, $langId, &$row)
+       {
+               // パラメータエラーチェック
+               if ($id < 0) return false;
+               
+               $now = date("Y/m/d H:i:s");     // 現在日時
+               $userId = $this->gEnv->getCurrentUserId();      // 現在のユーザ
+               $entryId = intval($id) * (-1);                                          // 記事IDを負の値に変換
+               $historyIndex = $userId * (-1);                         // ユーザIDを負の値に変換
+               
+               $queryStr  = 'SELECT * FROM blog_entry LEFT JOIN blog_id ON be_blog_id = bl_id AND bl_deleted = false ';
+               $queryStr .=   'WHERE be_id = ? ';
+               $queryStr .=     'AND be_language_id = ? ';
+               $queryStr .=     'AND be_history_index = ? ';
+               $ret = $this->selectRecord($queryStr, array($entryId, $langId, $historyIndex), $row);
+
+               return $ret;
+       }
 }
 ?>