>>Tested with: WikkaWiki version **1.1.6.4**, in the footer only.
Example: [[www.prepare4descent.net/DescentiaPedia | DescentiaPedia]]>>=====Stats=====
StatsFooter 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 [[www.prepare4descent.net/DescentiaPedia | 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:
%%(php;1;statsft.php)
LoadSingle("SELECT count(*) as num FROM ".$this->config["table_prefix"]."users ");
$users = $userdata["num"];
// stats about user... logged in?
if (($this->IsAdmin() && !empty($username)) ||
($this->GetUser() && $username = $this->GetUserName()))
{
$str = 'SELECT COUNT(*) FROM '.$this->config["table_prefix"].'pages WHERE `owner` ';
$str .= "= '" . $this->GetUserName() . "' AND `latest` = 'Y'";
$countQuery = $this->Query( $str );
// get the total # of pages
$str = 'SELECT COUNT(*) FROM '.$this->config["table_prefix"].'pages WHERE `latest` = \'Y\' ';
$totalQuery = $this->Query( $str );
$count = mysql_result($countQuery, 0);
$totalpages = mysql_result($totalQuery, 0);
$percent = round( ($count/$totalpages )*100, 2 ) ;
//make a string to print... for logged in users
$output = sprintf(STATS_USERS, $users) . ' ' . sprintf(STATS_PAGES_OWNED, $count) . ' ' . sprintf(STATS_PERCENT_OWNED, $percent);
}else{
//output for not logged in user
$output = sprintf(STATS_USERS, $users);
}
$limit = STATS_TOP_QTY;
// query for top contributers
$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;
$total = $this->getCount('pages', "`latest` = 'Y'");
//fetch data
$rank_query = $this->Query($query);
$i = 0;
$str = '';
while($row = mysql_fetch_array($rank_query))
{
$i++;
$str .= ' '.$this->Link($row['name']);
$str .= ':('.round(($row['cnt']/$total)*100, 1).'%)'."\n";
if ($i < $limit)
{$str .= ' | '."\n";
}else{
$str .= '
';
}
}
// print it out...
echo sprintf(STATS_RANK_HEADER, STATS_TOP_QTY);
echo ''. $str .'';
echo '
'. ($this->Format($output)).'';
?>
%%
----
See also:
ActionsInFooter
----
Categories:
CategoryStyle