歡迎光臨, 訪客. 請先 登入註冊一個帳號.
三月 19, 2024, 02:44:58 下午
19595 文章 在 3865 主題 由 4580 會員
最新註冊會員: aa123aa1
LifeType 中文開發論壇  |  開發  |  核心補強  |  核心補強精華區  |  請問如何在 summary.php實做最新迴響? « 上篇主題 下篇主題 »
頁: [1] 2
作者 主題: 請問如何在 summary.php實做最新迴響?  (閱讀 46637 次)
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 於: 三月 28, 2006, 08:57:37 下午 »

最近想幫實驗室的網誌加上這個功能,我搜尋了論壇,有看到recentcomments 的外掛程式,不過印象中summary.php 摘要這頁似乎是不支援任何的外掛程式的。

我剛剛翻了一下API,似乎沒看到可以用的api,不知道是不是要自己硬code呢?

感謝!
已記錄
lss
我不是被~拉~~出來的,不要叫我大大!
總版主
超級會員
*****
文章: 1511



檢視個人資料 個人網站
« 回覆文章 #1 於: 三月 28, 2006, 09:58:39 下午 »

你可以參考修改 class/summary/action/summarydefaultaction.class.php 這個檔案,再配合修改 summary 的樣版就可以了。

我之前寫的摘要頁面公告核心補強就是這樣改出來的,不難實作,參考看看。

lss
已記錄

沒找過 常見問題集或不知道 如何在 LifeType 中文開發論壇發問的人,恕不回答問題
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 回覆文章 #2 於: 三月 28, 2006, 10:18:15 下午 »

你可以參考修改 class/summary/action/summarydefaultaction.class.php 這個檔案,再配合修改 summary 的樣版就可以了。

我之前寫的摘要頁面公告核心補強就是這樣改出來的,不難實作,參考看看。

lss
也就是說沒有api可以用,要自己硬code囉,那太感謝了,動工去。
已記錄
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 回覆文章 #3 於: 三月 29, 2006, 06:58:43 下午 »

sorry 我今天改了一下, 可是資料撈不出來 傷心,請大家幫我看看。
我把recentComments寫到 summarystats裡面讓他成為summarystats的一個子方法。
再從summarydefaultaction.class.php把資料給挖出來

程式碼如下:
class/summary/dao/summarystats.class.php
程式碼:
function getRecentComments( $maxComments = 10){
             $query = "SELECT * FROM plog_articles_comments WHERE status = 0 ORDER BY date DESC LIMIT 0,".$maxComments;
             
             $result = $this->Execute($query);
             
             if(!$result)
                 return false;
             
             $recentComments = Array();
             $i          = 0;
           
             while( $row = $result->FetchRow()&& ($i<$maxComments)){
                 $comment        = new UserComment( $row["article_id"],$row["parent_id"],$row['topic'],$row["text"],new Timestamp($row["date"]),$row["user_name"],$row["user_email"],$row["user_url"],$row["client_ip"] ,$row["spam_rate"] ,$row["status"] ,$row["id"]   );

                 array_push($recentComments,$comment);
                 $i++;
             }
             $result->Close();
             
             return $recentComments;
         }

class/summary/action/summarydefaultaction.class.php:
引用
$maxRecentComments = 10;
$recentComments = $stats->getRecentComments($maxRecentComments);

   
$this->_view->setValue( "posts", $recentPosts );
$this->_view->setValue( "recentBlogs", $recentBlogs );
$this->_view->setValue( "activeBlogs", $activeBlogs );
$this->_view->setValue( "commentedPosts", $commentedPosts );
$this->_view->setValue( "readestBlogs", $readestBlogs );
$this->_view->setValue( "blogs", $siteBlogs );
 $this->_view->setValue( "recentComments",$recentComments);
       

不過現在的問題是資料撈不出來...,也就是說拿迴響內容的時候是空的。因為我把$row['test topic']改成"test" 就可以在前端顯示。

請問一下,我可能是哪裡搞錯了呢? 謝謝
« 最後編輯時間: 三月 29, 2006, 07:51:24 下午 由 CrazyLion » 已記錄
lss
我不是被~拉~~出來的,不要叫我大大!
總版主
超級會員
*****
文章: 1511



檢視個人資料 個人網站
« 回覆文章 #4 於: 三月 29, 2006, 07:35:44 下午 »

不知道你的 $row['test topic'] 是那個欄位? article_comment 資料表裡面有 topic 欄位,但是沒有 test topic 欄位啊?

你用 $row['test'] 可以在前端顯示,但是應該沒有文章標題可以用吧?!

試試看把 $row['test topic'] 改成 $row['topic'] 應該就可以了。

lss
已記錄

沒找過 常見問題集或不知道 如何在 LifeType 中文開發論壇發問的人,恕不回答問題
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 回覆文章 #5 於: 三月 29, 2006, 07:51:04 下午 »

不知道你的 $row['test topic'] 是那個欄位? article_comment 資料表裡面有 topic 欄位,但是沒有 test topic 欄位啊?

你用 $row['test'] 可以在前端顯示,但是應該沒有文章標題可以用吧?!

試試看把 $row['test topic'] 改成 $row['topic'] 應該就可以了。

lss
XD 實際上我不是這樣寫...po上來的時候弄錯了@@ sorry
不過他還是不能動..真是奇怪
« 最後編輯時間: 三月 30, 2006, 10:15:30 上午 由 CrazyLion » 已記錄
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 回覆文章 #6 於: 三月 30, 2006, 12:56:31 下午 »

找到問題了,等一下把結果po上來
已記錄
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 回覆文章 #7 於: 三月 30, 2006, 06:05:36 下午 »

成功了!
要達到這個功能,依照我的設計需要修改三個檔案,分別是:
class/summary/dao/summarystats.class.php
class/summary/action/summarydefaultaction.class.php
templates/summary/index.template

首先要修改summarystats.class.php 建立一個新的成員函式getRecentComment()
程式碼:
function getRecentComments( $maxComments = 10){       
             $prefix = $this->getPrefix();
             $query = "SELECT * FROM {$prefix}articles_comments WHERE status = 0 ORDER BY date DESC LIMIT 0,".$maxComments;
             
             $result = $this->Execute($query);
             
             if(!$result)
                 return false;
             
             $recentComments = Array();
             while( $row = $result->FetchRow()){
                 $comment        = new UserComment($row['article_id'],$row['parent_id'],$row['topic'],$row['text'],new Timestamp($row['date']),$row['user_name'],$row['user_email'],$row['user_url'],$row['client_ip'],$row['spam_rate'],0 ,$row['id']);
               
                 $query2 =
                             "SELECT a.id as id, a.id,a.date,
                             a.user_id,a.blog_id, a.status, a.properties,
                             a.num_reads, a.slug
                     FROM {$prefix}articles a, {$prefix}blogs b
                             WHERE a.blog_id = b.id
  AND b.status = ".BLOG_STATUS_ACTIVE."
  AND a.status = ".POST_STATUS_PUBLISHED."
  AND a.id=".$row['article_id'];
                  $result2=$this->Execute($query2);
                  if($row2 = $result2->FetchRow()){
                       $comment->setArticle($this->articles->_fillArticleInformation($row2));
                  }
                  $result2->Close;
                                 
                 array_push($recentComments,$comment);
               
             }
             $result->Close();
             
             return $recentComments;
         }

再來是summarydefaultaction.class.php,需要加入兩行(紅色的部份)
引用
$activeBlogs    = $stats->getMostActiveBlogs( $this->_numPosts);
 $commentedPosts = $stats->getMostCommentedArticles( $this->_numPosts, $registerTopic, $registerText );
 $readestBlogs   = $stats->getMostReadArticles( $this->_numPosts, $registerTopic, $registerText );
$recentComments = $stats->getRecentComments();


引用
$this->_view->setValue( "posts", $recentPosts );
$this->_view->setValue( "recentBlogs", $recentBlogs );
$this->_view->setValue( "activeBlogs", $activeBlogs );
$this->_view->setValue( "commentedPosts", $commentedPosts );
$this->_view->setValue( "readestBlogs", $readestBlogs );
$this->_view->setValue( "blogs", $siteBlogs );
$this->_view->setValue("recentComments",$recentComments);

然後你就可以在前端的網頁選擇加入的地方,已我們實驗室為例,我們是加在左邊的功能列,也就是index.template這個頁面。
程式碼:
<ul class="itemList">
    {foreach from=$recentComments item = comment}
         {assign var="commentArticle" value=$comment->getArticle()}
         {assign var="blog" value=$commentArticle->getBlogInfo()}
         {assign var="url" value=$blog->getBlogRequestGenerator()}
         <li class="item">
             {if $comment->getUserUrl()}<a href="{$comment->getUserUrl()}">{/if}{$comment->getUserName()}{if $comment->getUserUrl()}</a>{/if} on<a href="{$url->postPermalink($commentArticle)}#comments">{$commentArticle->getTopic()|strip_tags}</a>
    <!--{$comment->getText()|strip_tags|truncate:50:"..."}-->
    </li>
    {/foreach}
 </ul>

----------------
備註:我知道取出getRecentComment()裡應該可以換成運行一次sql就把資料撈出來,可是剛剛試了一下,底下的_fillArticleInformation似乎無法正常運作,我推測大概是跟select出來的name有關。已經可以動了,所以我就不改了:P

之前資料拿不出來的原因很奇怪,我原本的程式是:
while( $row = $result->FetchRow() &&  ($i<$maxComments)){
}
可是這樣$row['topic'].之類的資料會拿不出來,改成
while( $row = $result->FetchRow()){
這樣就好了,..我知道原本這樣寫有點無謂 XD
只是為什麼這會影響到資料的取出呢?真奇怪?
已記錄
lss
我不是被~拉~~出來的,不要叫我大大!
總版主
超級會員
*****
文章: 1511



檢視個人資料 個人網站
« 回覆文章 #8 於: 三月 30, 2006, 07:10:36 下午 »

....
之前資料拿不出來的原因很奇怪,我原本的程式是:
while( $row = $result->FetchRow() &&  ($i<$maxComments)){
}
可是這樣$row['topic'].之類的資料會拿不出來,改成
while( $row = $result->FetchRow()){
這樣就好了,..我知道原本這樣寫有點無謂 XD
只是為什麼這會影響到資料的取出呢?真奇怪?
這應該跟運算的優先順序有關。你要的應該是這樣:
引用
while( ($row = $result->FetchRow()) &&  ($i<$maxComments)){
}
可是你的寫法大概會變成這樣的運算順序:
引用
while( $row = ($result->FetchRow() &&  ($i<$maxComments))){
}
這大概就是問題所在吧  微笑

無論如何,恭喜你 hack 成功  微笑

這篇我搬到核心補強版,放進精華區囉!

lss
已記錄

沒找過 常見問題集或不知道 如何在 LifeType 中文開發論壇發問的人,恕不回答問題
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 回覆文章 #9 於: 三月 30, 2006, 07:25:02 下午 »

阿 !!!真的!!!
你不說我還真沒發現到括號這個問題....
真是見笑了 害羞
下次會更注意的@@
感謝!
已記錄
lss
我不是被~拉~~出來的,不要叫我大大!
總版主
超級會員
*****
文章: 1511



檢視個人資料 個人網站
« 回覆文章 #10 於: 三月 30, 2006, 08:10:49 下午 »

hi CrazyLion:

我也嘗過這種苦頭,刻骨銘心啊。

別客氣了,有空多交流啊!  微笑

lss
已記錄

沒找過 常見問題集或不知道 如何在 LifeType 中文開發論壇發問的人,恕不回答問題
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 回覆文章 #11 於: 十月 15, 2006, 08:16:57 下午 »

for 1.1的版本:

class/summary/dao/summarystats.class.php裡的
function getRecentComments( $maxComments = 20) 裡面的所有程式碼換成
換成
引用
include_once( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );
            include_once( PLOG_CLASS_PATH.'class/dao/usercomment.class.php' );   
            include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
             $articleComments = new ArticleComments();
              $articles = new Articles();
               $prefix = $this->getPrefix();
               $query = "SELECT * FROM {$prefix}articles_comments WHERE status = 0 ORDER BY date DESC LIMIT 0,".$maxComments;
                $result = $this->Execute($query);
               if(!$result)
                 return false;
               $recentComments = Array();
               while( $row = $result->FetchRow()){
                 $comment = $articleComments->getComment($row['id']);
                  $comment->setArticle($articles->getArticle[$row['article_id']]);
                  array_push($recentComments,$comment);
              }
              $result->Close();
              return $recentComments;



這次簡潔多了阿!!! 1.1真不賴 :D
已記錄
php
新手見習
*
文章: 23


檢視個人資料
« 回覆文章 #12 於: 十一月 17, 2006, 07:40:31 下午 »

for 1.1的版本:

class/summary/dao/summarystats.class.php裡的
function getRecentComments( $maxComments = 20) 裡面的所有程式碼換成
換成
引用
include_once( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );
            include_once( PLOG_CLASS_PATH.'class/dao/usercomment.class.php' );   
            include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
             $articleComments = new ArticleComments();
              $articles = new Articles();
               $prefix = $this->getPrefix();
               $query = "SELECT * FROM {$prefix}articles_comments WHERE status = 0 ORDER BY date DESC LIMIT 0,".$maxComments;
                $result = $this->Execute($query);
               if(!$result)
                 return false;
               $recentComments = Array();
               while( $row = $result->FetchRow()){
                 $comment = $articleComments->getComment($row['id']);
                  $comment->setArticle($articles->getArticle[$row['article_id']]);
                  array_push($recentComments,$comment);
              }
              $result->Close();
              return $recentComments;



這次簡潔多了阿!!! 1.1真不賴 :D
帮帮我啊!我照这个做了(我现在的版本是1.1.2),并在summarydefaultaction.class.php中加入了:$this->_view->setValue("recentComments",$recentComments);
另外几句,照你原来的,找不到了。现在这样子,在index.template中却不能显示出最新评论,麻烦看看是怎么回事?哪位大哥帮帮我?
谢谢了。
已記錄
CrazyLion
初級會員
**
文章: 53



檢視個人資料 個人網站
« 回覆文章 #13 於: 十一月 17, 2006, 08:49:11 下午 »


帮帮我啊!我照这个做了(我现在的版本是1.1.2),并在summarydefaultaction.class.php中加入了:$this->_view->setValue("recentComments",$recentComments);
另外几句,照你原来的,找不到了。现在这样子,在index.template中却不能显示出最新评论,麻烦看看是怎么回事?哪位大哥帮帮我?
谢谢了。

1.1.2我還沒試耶 我晚點幫你測看看 :P
已記錄
php
新手見習
*
文章: 23


檢視個人資料
« 回覆文章 #14 於: 十一月 18, 2006, 11:25:42 上午 »

真是好大哥,非常感谢!!
已記錄
頁: [1] 2
LifeType 中文開發論壇  |  開發  |  核心補強  |  核心補強精華區  |  請問如何在 summary.php實做最新迴響? « 上篇主題 下篇主題 »
    前往: