<?php
 
/*
  History:
    v1.1 - Initialize version
    v1.2 - uses sql_table, add featuresSupport
 
 */
 
// plugin needs to work on Nucleus versions <=2.0 as well
if (!function_exists('sql_table'))
{
    function sql_table($name) { return 'nucleus_' . $name; }
}
 
 
class NP_MostKarma extends NucleusPlugin {
 
    function getName() {
        return 'Most Karma';
    }
    function getAuthor()  {
        return 'Mikko Saari | mod by Edmond Hui (admun)';
    }
    function getURL()  {
        return 'http://www.melankolia.net/nucleusplugins/';
    }
    function getVersion() {
        return '1.2';
    }
    function getDescription() {
        return 'This plugin displays a list of articles with the '
             . 'biggest karma total. Usage: &lt;%MostKarma(n,sort)%&gt; '
             . 'where n is the number of articles to list (default '
             . 'is five) and sort is the direction (asc = ascending, '
             . 'from bottom to top or desc = descending, from top to '
             . 'bottom; default is desc).';
    }
    function getMinNucleusVersion() {
        // Uses version 2.0 karma
        return 200;
    }
        function supportsFeature($feature) {
                switch($feature) {
                        case 'SqlTablePrefix':
                                return 1;
                        default:
                                return 0;
                }
        }
 
    // skinvar plugin can have a blogname as second parameter
    function doSkinVar($skinType, $param1 = 5, $param2 = 'desc') {
        global $manager, $blog, $CONF;
 
        if ($param1) {
            $articlesToShow = $param1;
        }
        else {
            $articlesToShow = 5;
        }
 
        $sortDirection = $param2;
 
        if ($blog)
            $b =& $blog;
        else {
            $b =& $manager->getBlog($CONF['DefaultBlog']);
        }
 
        $blogId = $b->getID();
 
        $query = ' SELECT inumber as itemid, ititle as title,'
               . ' ikarmapos-ikarmaneg as karma'
               . ' FROM '
               . sql_table('item')
               . ' WHERE iblog='.$blogId
               . ' and idraft=0' // exclude drafts
               . ' and itime<=' . mysqldate($b->getCorrectTime());
 
        // Sort order
        if ($sortDirection == 'desc') {
            $query = $query . ' ORDER BY karma DESC, itime DESC';
        }
        else {
            $query = $query . ' ORDER BY karma ASC, itime DESC';
        }
 
        // Number of articles to show
        $query = $query . " LIMIT $articlesToShow";
 
        $entries = mysql_query($query);
 
        while ($row = mysql_fetch_assoc($entries)) {
            extract($row);
 
            $itemlink = createItemLink($itemid, '');
 
            echo "<a href=\"$itemlink\">";
            if ($title)
                echo "$title</a>";
            else
                echo "Untitled</a>";
 
            echo " ($karma)";
            echo "<br />\n";
        }
    }
}
?>
mostkarmacode.txt · Last modified: 2006/07/05 13:03 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki