<?
 
/*
  History:
    v1.0 - initial version
    v1.1 - fix deleted entries bug 
         - included enhancement from xiffy on making the entries
           clickable
    v1.2 - add user defined num# of posts (Edmond Hui)
           (Edmond Hui)
    V1.4 - Use sql_table()
         - Add supportsFeature
    V1.4
	 - Fixed paramlink for FancyURL
    v1.5
         - performance improvement
         - add title display option
    v1.5a
         - fix globally itemid
    v1.6
         - add plugin dep check
 
  TODO:
    - this instead of $res2
         $item =& $manager->getItem($itemid,'','');
         $item['title'] = strip_tags($item['title']);
    - show only post from the same blog
 
  Note: This plugin has dependency on NP_Views
 */
 
class NP_MostViewed extends NucleusPlugin {
 
   function getName() {   return 'Most Viewed';    }
   function getAuthor()  { return 'Rodrigo Moraes / Edmond Hui (admun)';    }
   function getURL() {      return 'http://www.tipos.com.br'; }
   function getVersion() {   return '1.6'; }
   function getDescription() {
      return 'This plugin displays the most viewed items.';
   }
 
   function install() {
      $this->createOption('showHeader', 'Display header?', 'yesno', 'yes');
      $this->createOption('header', 'Text for Header', 'text', '<b>Most viewed posts:</b><br />');
   }
 
   function supportsFeature($what) {
      switch($what) {
	 case 'SqlTablePrefix':
	    return 1;
	 default:
	    return 0;
      }
   }
 
   function getPluginDep() {
     return array('NP_Views');
   }
 
   function doSkinVar($skinType, $numOfPosts) {
      $itemid;
 
      if ($numOfPosts == 0) {
	 $numOfPosts = 5; // set default if no user input
      }
 
      $query = "SELECT id, views FROM " . sql_table('plugin_views') . " ORDER by views DESC LIMIT 0,".$numOfPosts;
      $res = mysql_query($query);
 
      if ($this->getOption('showHeader') == 'yes')
	 echo $this->getOption('header');
 
      $num = 1;
      while($row = mysql_fetch_object($res)) {
	 $itemid = $row->id;
	 $views = $row->views;
	 $query = "SELECT ititle FROM " . sql_table('item') . " WHERE inumber = $itemid";
	 $res2 = mysql_query($query);
 
	 if (mysql_affected_rows() <= 0) {
	    $query = "DELETE FROM " . sql_table('plugin_views') . " WHERE id = $itemid";
	    $res3 = mysql_query($query);
	    // eheck result??
	    continue;
	 }
 
         $row = mysql_fetch_object($res2);
         $title = $row->ititle;
         echo $num.". <a href=\"". $IndexURL. createItemLink($itemid). "\">".strip_tags($title)." [".$views."x]</a><br />";
         $num++;
      }
   }
}
?>
mostviewedcode.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