WillyP's WikkaStyle : StaTs

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Revision [102]

The oldest known version of this page was edited on 2008-05-10 11:14:27 by WillyPs [new page]
Tested with: WikkaWiki version 1.1.6.4
Demo: DescentiaPedia

Stats

Stats is an action I cobbled together from existing actions, (highscores.php, ownedpages.php, countusers.php) it is intended to be used in the footer, as seen at DescentiaPedia. I have not tested this to see if it can be used in a page. Nor have I tested this in any version of wikka other than 1.1.6.4. Here is the code:
stats.php (line 1)
  1. <?php
  2. /**
  3.  * Displays a list of top contributors, ranked by number of pages owned, edits or comments.
  4.  * Displays number/ percent of pages owned by current user, total pages of wiki.
  5.  * Displays number of registered users.
  6.  *
  7.  * @package     Actions
  8.  * @version     $Id: highscores.php 820 2007-11-23 09:21:08Z DotMG $
  9.  * @license     http://www.gnu.org/copyleft/gpl.html GNU General Public License
  10.  * @filesource
  11.  *
  12.  * @author  Chris Tessmer ... highscores.php, ownedpages.php (original code)
  13.  * @author  {@link http://wikkawiki.org/DarTar Dario Taraborelli} (adding action parameters, styling, accessibility)
  14.  * @author   {@link http://wikkawiki.org/WillyPs W. P. Sullivan} Hacked together code from several actions, removed  unneeded code, and format for use in the footer.
  15. */
  16. //define:
  17. if(!defined('STATS_TOP_QTY')) define('STATS_TOP_QTY', 5); // number of high scores to show
  18. if(!defined('STATS_RANK_BY')) define('STATS_RANK_BY', 'pages');// rank by: 'edits', 'pages', 'comments'
  19. //i18n   USE WIKI FORMATING... %s will be replaced by the appropriate numerical value.
  20. if(!defined('STATS_USERS')) define('STATS_USERS', 'There are %s registered members.');
  21. if(!defined('STATS_PAGES_OWNED')) define('STATS_PAGES_OWNED', 'You own %s pages,');
  22. if(!defined('STATS_PERCENT_OWNED')) define('STATS_PERCENT_OWNED', '%s percent of the total pages.');
  23. if(!defined('STATS_RANK_HEADER')) define('STATS_RANK_HEADER', 'Top %s contributers, by number of pages owned: ');
  24.  
  25.     // count the number of users
  26.     $userdata = $this->LoadSingle("SELECT count(*) as num FROM ".$this->config["table_prefix"]."users ");
  27.     $users = $userdata["num"];
  28.    
  29.     // stats about user... logged in?
  30.     if (($this->IsAdmin() && !empty($username)) ||
  31.     ($this->GetUser() &&  $username = $this->GetUserName()))
  32.         {
  33.             $str = 'SELECT COUNT(*) FROM '.$this->config["table_prefix"].'pages WHERE `owner` ';
  34.             $str .= "= '" . $this->GetUserName() . "' AND `latest` = 'Y'";
  35.             $countQuery = $this->Query( $str );
  36.    
  37.             // get the total # of pages
  38.             $str = 'SELECT COUNT(*) FROM '.$this->config["table_prefix"].'pages WHERE `latest` = \'Y\' ';
  39.             $totalQuery = $this->Query( $str );    
  40.    
  41.             $count  = mysql_result($countQuery, 0);
  42.             $totalpages  = mysql_result($totalQuery, 0);
  43.    
  44.             $percent = round( ($count/$totalpages )*100, 2 ) ;
  45.             //make a string to print... for logged in users
  46.             $output = sprintf(STATS_USERS, $users) . ' ' . sprintf(STATS_PAGES_OWNED, $count) . ' ' . sprintf(STATS_PERCENT_OWNED, $percent);
  47.         }else{
  48.             //output for not logged in user
  49.             $output = sprintf(STATS_USERS, $users);
  50.             }
  51.        
  52.     $limit = STATS_TOP_QTY;
  53.  
  54. //  query for top contributers
  55.     $query = 'SELECT COUNT(*) AS cnt, `name`  FROM '.$this->GetConfigValue('table_prefix').'users, '.$this->GetConfigValue('table_prefix').'pages WHERE `name` = `owner` AND `latest` = "Y" GROUP BY name ORDER BY cnt DESC LIMIT '.$limit
  56.     $total = $this->getCount('pages', "`latest` = 'Y'");
  57.  
  58.  
  59. //fetch data
  60. $rank_query = $this->Query($query);
  61.  
  62. $i = 0;
  63. $str = '';
  64. while($row = mysql_fetch_array($rank_query))
  65. {
  66.     $i++;
  67.     $str .= ' '.$this->Link($row['name']);
  68.     $str .= ':('.round(($row['cnt']/$total)*100, 1).'%)'."\n";
  69.     if ($i < $limit)
  70.         {$str .= ' | '."\n";
  71.         }else{
  72.             $str .= '<br />';
  73.             }
  74. }
  75. // print it out...
  76. echo sprintf(STATS_RANK_HEADER, STATS_TOP_QTY);
  77. echo '<span class="clip">'. $str .'</span>';
  78. echo '<br /><span class="clip">'. ($this->Format($output)).'</span>';
  79. ?>
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.2840 seconds