<?
/**
* This plugin can be used to display the most popular posts.
*
* Usage: <%MostPopular%> or <%MostPopular(5)%>
*
* History:
* v0.1: - Initial version
* v0.2: - fix count < numOfPosts error, indentation
* - fixed XHTML warning
* v0.3: - use sql_table(), add supportsFeature
* v0.31: - fixed normal mode URL bug
* v0.4: - re-write for better performance
* - verbose comment count mode
*
*/
// to make this plugin works on Nucleus versions <=2.0 as well
if (!function_exists('sql_table'))
{
function sql_table($name) {
return 'nucleus_' . $name;
}
}
class NP_MostPopular extends NucleusPlugin {
function getEventList() { return array(); }
function getName() { return 'Most Popular Posts'; }
function getAuthor() { return 'anand / admun'; }
function getURL() { return 'http://www.itismylife.com/'; }
function getVersion() { return '0.4'; }
function getDescription() {
return 'This plugin can be used to display the most popular posts.';
}
function supportsFeature($feature) {
switch($feature) {
case 'SqlTablePrefix':
return 1;
default:
return 0;
}
}
function install() {
$this->createOption('commentVerbose', 'Comment count verbose mode? (ie [4] vs [4 comment(s)])', 'yesno', 'yes');
$this->createOption('text1', 'Text in comment count verbose mode', 'text', ' comment(s)');
}
// skinvar plugin can have a blogname as second parameter
function doSkinVar($skinType) {
global $manager, $blog, $CONF;
$params = func_get_args();
$numberOfPosts = 5; //default to 5 most popular posts
if ($params[1]) {
$numberOfPosts = $params[1];
$b =& $blog;
}
else if ($blog)
$b =& $blog;
else
$b =& $manager->getBlog($CONF['DefaultBlog']);
$query = 'CREATE TEMPORARY TABLE ccount (citem int(11), count int(11))';
sql_query($query);
$query = 'INSERT ccount (citem,count) SELECT citem as citem, count(*) as count FROM ' . sql_table('comment') . ' WHERE cblog=' . $b->blogid . ' GROUP BY citem';
sql_query($query);
$query = 'SELECT * FROM ccount ORDER BY count DESC LIMIT 0,'.$numberOfPosts;
$entries = sql_query($query);
$count = 1;
while ($row = mysql_fetch_assoc ($entries)) {
$query = 'SELECT ititle FROM '.sql_table('item').' WHERE inumber='.$row['citem'];
$res = sql_query($query);
$title = mysql_fetch_array($res);
$itemlink = createItemLink($row['citem']);
if ($title[0])
echo "<a href=\"".$itemlink."\">".$title[0]."</a>";
else
echo "<a href=\"".$itemlink."\">"."Untitled"."</a>";
echo " [".$row['count'];
if ($this->getOption('commentVerbose') == 'yes')
echo $this->getOption('text1');;
echo "]<br />";
$count++;
}
$query = 'drop table ccount';
sql_query($query);
}
}
?>