Dear Mark
这个插件的作者没想到也是你老人家呀^^
我一个地方都没改过,原般抄过来给你看看
<?php
include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/article.class.php" );
/**
* Plugin that offers features to return a recent article comments from the current blog
*/
class PluginRecentComments extends PluginBase
{
function PluginRecentComments()
{
$this->author = "Mark Wu";
$this->desc = "This plugin offers the most recently article comments. Usage as follow:<br /><br />Add the following code to header.template<br /><br /><strong><p><br />{assign var=comments value=\$recentcomments->getRecentComments()}<br />{foreach from=\$comments item=comment}<br />{assign var=postid value=\$comment->getArticleId()}<br />{assign var=post value=\$recentcomments->getCommentArticle(\$postid)}<br />{if \$comment->getUserUrl()}<br /><li><a title="{\$comment->getText()|truncate:150:"..."|escape}" href="{\$comment->getUserUrl()}">{\$comment->getUsername()}</a> &gt;&gt; <a href="{\$url->postPermalink(\$post)}">{\$post->getTopic()}</a></li> <br />{else}<br /><li><a title="{\$comment->getText()|truncate:150:"..."|escape}" href="{\$url->postPermalink(\$post)}">{\$comment->getUsername()}</a> &gt;&gt; <a href="{\$url->postPermalink(\$post)}">{\$post->getTopic()}</a></li><br />{/if}<br />{/foreach}<br /></p></strong><br /><br />You can use <br /><br /><strong>getRecentComments(5)</strong> to get recent 5 comments. The default view is BLOG. <br /><strong>getRecentComments(10, 'SITE')</strong> to get recent 10 comments from SITE view. It is very convenient for pLog Host Provider.<br /><br />";
$this->PluginBase();
}
/**
* Returns the recent comments object of current blog
*/
function getRecentComments($maxComments = 12, $based = 'BLOG')
{
$comments = new ArticleComments();
$config = new Config();
$prefix = $config->getValue('db_prefix');
$blogId = $this->blogInfo->getId();
if ($based == 'BLOG') {
$query = "SELECT ".$prefix."articles_comments.* FROM ".$prefix."articles_comments, ".$prefix."articles";
$query .= " WHERE ".$prefix."articles_comments.article_id = ".$prefix."articles.id AND ".$prefix."articles.blog_id = ".$blogId." AND ".$prefix."articles.status = 'published'";
$query .= " ORDER BY ".$prefix."articles_comments.date DESC";
} elseif ($based == 'SITE') {
$query = "SELECT ".$prefix."articles_comments.* FROM ".$prefix."articles_comments, ".$prefix."articles";
$query .= " WHERE ".$prefix."articles_comments.article_id = ".$prefix."articles.id AND ".$prefix."articles.status = 'published'";
$query .= " ORDER BY ".$prefix."articles_comments.date DESC";
} else {
return false;
}
if( $maxComments > 0 )
$query .= " LIMIT 0,".$maxComments;
$result = $comments->_db->Execute( $query );
if( !$result )
return false;
$recentcomments = Array();
while( $row = $result->FetchRow()) {
array_push( $recentcomments, $comments->_fillCommentInformation($row));
}
return $recentcomments;
}
function getCommentArticle( $artId )
{
$articles = new Articles();
$config = new Config();
$prefix = $config->getValue('db_prefix');
$blogId = $this->blogInfo->getId();
$query = "SELECT * FROM ".$prefix."articles WHERE id = ".$artId;
$query .= " AND blog_id = ".$blogId;
$query .= ";";
// we send the query and then fetch the first array with the result
$result = $articles->_db->Execute( $query );
if( $result == false )
return false;
if ( $result->RecordCount() == 0)
return false;
$row = $result->FetchRow( $result );
$article = $articles->_fillArticleInformation( $row );
return $article;
}
}
PluginManager::registerPlugin( "recentcomments", "PluginRecentComments" );
?>