Wiki source for DescribeUsers


Show raw source

===Advanced Sumary View of UserPages===
This action displays all the users and their pages. Also reveals the percentage they own from the total ""WikiPages"" and ""WikiComments"". The layout can be customised using attributes when calling the function.

==Typical Use==
Use like :
""{{describeusers}}""

If you want to customise the appearance you may use a syntax similar to this :
""{{describeusers cellpadding="5" cellspacing="3" border="1" columns="2"}}""
@@Don't Forget To Read The Notes Within The Code@@
==How to use==

You will need **/wikka/actions/describeusers.php** with the following contents.

%%(php)<?php
/*
@filename: describeusers.php
@author: George Petsagourakis
@email: petsagouris@hotmail.com
@date: 18 Dec 2004
@license: GPL
@todo: Suggestions welcome ...
@description: it displays all the users and lists the WikiPages they own.
also displays the percentages of comments and pages they own in the wiki.
owned pages count and own comments count is also diaplayed.
@usage: insert {{describeusers}} any where in a wakka page.
Example : {{describeusers cellpadding="5" cellspacing="3" border="1" columns="2"}}
You may use the above syntax to customise the layout of the output.
Any of the attributes may be mentioned or not ;)
*/
$row = 1;
$cellpadding = 1;
$cellspacing = 1;
$border = 0;
$columns = 3;

if (is_array($vars)){
foreach ($vars as $att => $v){
if ($att == 'columns') $columns=$v;
if ($att == 'cellpadding') $cellpadding=$v;
if ($att == 'cellspacing') $cellspacing=$v;
if ($att == 'border') $border=$v;
}
// Getting the comments count ...
$total_wikicomments = 0;
$res = $this->LoadAll("SELECT Count(*) FROM ".$this->config['table_prefix']."comments GROUP BY page_tag");
foreach($res as $i => $arr) {
foreach($arr as $t => $c){
$total_wikicomments += $c;
}
}
// Getting the pages count ...
$total_wikipages = 0;
$res = $this->LoadAll("SELECT Count(*) from ".$this->config['table_prefix']."pages WHERE latest ='Y' GROUP BY tag");
foreach($res as $i => $arr) {
foreach($arr as $t => $c){
$total_wikipages += $c;
}
}
//print $total_wikipages." -- \n";
// Lets get all the usernames in an array...
$all_usernames = array();
$res = $this->LoadAll("SELECT name from ".$this->config['table_prefix']."users");
foreach($res as $i => $arr) {
foreach ($arr as $t => $name){
$res_pagenames = $this->LoadAll("SELECT tag,datediff(time, now()) as last_edit FROM ".$this->config['table_prefix']."pages WHERE owner='$name' and latest ='Y' GROUP BY tag");
$temp = array();
foreach($res_pagenames as $i => $page) {
$le = abs($page['last_edit']+0) ;
if ($le > 1) { $le = "$le days ago"; }
else if ($le == 1) { $le = "yesterday"; }
else {$le = "today";}
$temp['pages'][$page['tag']] = "$le";
}
$temp['commentscount'] = count($this->LoadAll("SELECT Count(*) FROM ".$this->config['table_prefix']."comments WHERE user='$name' GROUP BY id"));
}
$all_usernames[$name] = $temp;
}

$the_big_one = array();
foreach($all_usernames as $name => $arr){

$name = $this->Format($name);

$row_one = "$name | Pages: ".count($arr['pages'])." | Comments: ".$arr['commentscount'];

$row_two = "Owns ".round( ( ((count($arr['pages']))*100)/$total_wikipages ), 2)."% of all the pages and <br />".round( ( (($arr['commentscount'])*100)/$total_wikicomments ), 2)."% of all comments in this wiki";

$row_three = '<table width="100%" border="0" cellpadding="1">';
$row_three .= '<tr><td>Page</td><td align=\"left\">| Last Edit</td></tr>';
if (!count($arr['pages'])) {
$row_three .= "<tr><td>none</td><td align=\"left\">| <em>never</em></td></tr>";
}
else {
foreach($arr['pages'] as $p => $l){
//print "$p - $l\n";
$row_three .= "<tr><td align=\"left\">".$this->Format($p)."</td><td align=\"left\">| <em>$l</em></td></tr>";
}
}
$row_three .= "</table>";

$out = "<table border=\"0\" cellpadding=\"3\">";
$out .= "<tr><td>$row_one</td></tr>";
$out .= "<tr><td>$row_two</td></tr>";
$out .= "<tr><td>$row_three</td></tr>";
$out .= "</table>";
// print $out;
$the_big_one[] = $out;
}
$fin = "<hr />";
//var_dump($the_big_one);
foreach($the_big_one as $i => $cell){
if ($row == 1) $fin .= "<table width=\"100%\" border=\"$border\" cellspacing=\"$cellspacing\" cellpadding=\"$cellpadding\">\n <tr>\n";
$fin .= "<td width=\"".(100/$columns)."%\"valign=\"top\" align=\"center\">$cell</td>\n";
$row++;
if ($row > $columns) {
$row = 1;
$fin .= " </tr>\n</table>\n<hr />";
}
}
echo $this->ReturnSafeHTML($fin);
}
?>%%

~& Thanks so much for all of this work!! I've found a couple of errors/problems which I have suggested fixes for below. - CharlotteFischer

For those of us for whom upgrading to mySQL 4.1 is more bother than correcting a few lines of code: make this correction to line 52
%%(php)
$res_pagenames = $this->LoadAll("SELECT tag,TO_DAYS(now())-TO_DAYS(time) AS last_edit FROM ".$this->config['table_prefix']."pages WHERE owner='$name' and latest ='Y' GROUP BY tag");
%%

And for those of us with users who have made no comments or created no pages: replace line 74 with this
%%(php)
// CORRECTION OF DIVISION-BY-ZERO ERROR
if($total_wikipages>0)
$percent_pages = round( ( ((count($arr['pages']))*100)/$total_wikipages ), 2);
else
$percent_pages = 0;
if($total_wikicomments>0)
$percent_comments = round( ( (($arr['commentscount'])*100)/$total_wikicomments ), 2);
else
$percent_comments = 0;
$row_two = "Owns ".$percent_pages."% of all the pages and <br />".$percent_comments."% of all comments in this wiki";
%%
----
CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki