<?php
                                                                             
/**
  * BLOG:CMS: PHP/MySQL Personal Content Management System (CMS)
  * http://blogcms.com/
  * ----------------------------------------------------------------
  *
  * Copyright (C) 2003-2005 Radek HULÁN
  * http://hulan.cz/contact/
  *
  * ----------------------------------------------------------------
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
**/

class NP_MostPopular extends NucleusPlugin {
                                                                             
    function getEventList() { return array(); }
    function getName() { return 'MostPopular'; }
    function getAuthor()  { return 'Radek HULAN'; }
    function getURL()  { return 'http://hulan.cz/blog'; }
    function getVersion() { return '0.1'; }
    function getDescription() {
      return 'This plugin can be used to display the most commented articles.';
    }
                                                                             
	function supportsFeature($feature) {
		switch($feature) {
			case 'SqlTablePrefix':
				return 1;
			default:
				return 0;
		}
	}

    function doSkinVar($skinType, $numberOfPosts = '5') {
      $blogid = strval(getCurrentBlogId());
	  global $catid;
	  if (intval($catid)>0) $s=" AND i.icat=$catid "; else $s='';
      $query =  sql_query('SELECT count(*) as itemtotal, max(c.citem) as xitemid FROM '.sql_table('comment').' as c, '.sql_table('item').' as i WHERE c.citem=i.inumber AND i.iblog='.$blogid.$s.' GROUP BY c.citem ORDER BY itemtotal DESC LIMIT 0,5');
      $num = 0;
      echo "<ul>\n";
      while ($msg = sql_fetch_array($query)) {
        $detail = sql_query('SELECT ititle, iurltitle, UNIX_TIMESTAMP(itime) as itime FROM '.sql_table('item').' WHERE inumber='.$msg['xitemid']);
        if ($xdetail = sql_fetch_array($detail)) {
          $itemlink = fancyTitle($msg['xitemid'],$xdetail['iurltitle'],$xdetail['itime']);
          $num++;
          echo "<li><a href='".$itemlink."'>".strip_tags($xdetail['ititle'])."</a>";
          echo " [".strval($msg['itemtotal'])."]";
          echo "</li>\n";
        }
      }
      echo "</ul>\n";
    } 
                                                                          
}
?>