User Cleaner and Online Users
This modification involves adding some lines inside wikka.php and wikka.config.php files of your wikka installation. You will be keeping a clean user registry and be able to display an "online users" message using an action in any page of your wikka.Database Entry
You have to add a column inside your wikka_users table of your database.assuming your table is named users you'll execute this query:
ALTER TABLE `users` ADD `lastseen` DATETIME NOT NULL;
Modifications inside wikka.php
Find Run() inside your wikka.php and find this line :
if ((!$this->GetUser() && isset($_COOKIE["name"])) && ($user = $this->LoadUser($_COOKIE["name"], $_COOKIE["password"]))) $this->SetUser($user);
and change it to this :
if ((!$this->GetUser() && isset($_COOKIE["name"])) && ($user = $this->LoadUser($_COOKIE["name"], $_COOKIE["password"]))) $this->SetUser($user);
//usercleaner stamp
$this->SetPage($this->LoadPage($tag, (isset($_REQUEST["time"]) ? $_REQUEST["time"] :'')));
//usercleaner stamp
$this->SetPage($this->LoadPage($tag, (isset($_REQUEST["time"]) ? $_REQUEST["time"] :'')));
Then find the Maintainance() function and change it to this one:
// MAINTENANCE
function Maintenance()
{
// purge referrers
if ($days = $this->GetConfigValue("referrers_purge_time")) {
$this->Query("DELETE FROM ".$this->config["table_prefix"]."referrers WHERE time < date_sub(now(), interval '".mysql_real_escape_string($days)."' day)");
}
// purge old page revisions
if ($days = $this->GetConfigValue("pages_purge_time")) {
$this->Query("delete from ".$this->config["table_prefix"]."pages where time < date_sub(now(), interval '".mysql_real_escape_string($days)."' day) and latest = 'N'");
}
//purge old users
if ($days = $this->GetConfigValue("users_purge_time")) {
$overdues = $this->LoadAll("SELECT name FROM ".$this->config["table_prefix"]."users WHERE lastseen < date_sub(now(), INTERVAL '".mysql_real_escape_string($days)."' DAY)");
$this->Query("DELETE FROM ".$this->config["table_prefix"]."users WHERE lastseen < date_sub(now(), INTERVAL '".mysql_real_escape_string($days)."' DAY)");
foreach ($overdues as $i => $arr){
$name = $arr["name"];
//take care of comments
if ($this->GetConfigValue("purge_deleted_users_comments") == 1)
$this->Query("DELETE FROM ".$this->config["table_prefix"]."comments WHERE user='".$arr["name"]."' limit 1");
//take care of pages
if ($this->GetConfigValue("purge_deleted_users_pages") == 1)
{
//get the users pages
// if we delete the pages then we need to delete it from the links table too
$over_pages = $this->LoadAll("SELECT tag FROM ".$this->config["table_prefix"]."pages WHERE owner='".$name."'");
foreach($over_pages as $idx => $s_arr)
{
$p = $s_arr["tag"];
// pages table...
$this->Query("DELETE FROM ".$this->config["table_prefix"]."pages WHERE owner='".$arr["name"]."' and tag='".$p."'");
//links table ...
$this->Query("DELETE FROM ".$this->config["table_prefix"]."links WHERE from_tag='".$arr["name"]."'");
$this->Query("DELETE FROM ".$this->config["table_prefix"]."links WHERE to_tag='".$arr["name"]."'");
//acls table...
$this->Query("DELETE FROM ".$this->config["table_prefix"]."acls WHERE page_tag='".$p."'");
}
}
else
{
// otherwise just make the owned pages a free
$this->Query("UPDATE pages SET owner='' WHERE owner='".$name);
}
//take care of acls
$test_acls = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."acls");
foreach($test_acls as $idx => $s_arr)
{
$page = $s_arr["page_tag"];
$read = $s_arr["read_acl"];
$write = $s_arr["write_acl"];
$comment = $s_arr["comment_acl"];
$this->Query("UPDATE acls SET read_acls='".str_replace($name."\n", "", $read)."', write_acls='".str_replace($name."\n", "", $write)."', comment_acls='".str_replace($name."\n", "", $comment)."' WHERE page_tag='".$page."' LIMIT 1");
}
}
}
}
function Maintenance()
{
// purge referrers
if ($days = $this->GetConfigValue("referrers_purge_time")) {
$this->Query("DELETE FROM ".$this->config["table_prefix"]."referrers WHERE time < date_sub(now(), interval '".mysql_real_escape_string($days)."' day)");
}
// purge old page revisions
if ($days = $this->GetConfigValue("pages_purge_time")) {
$this->Query("delete from ".$this->config["table_prefix"]."pages where time < date_sub(now(), interval '".mysql_real_escape_string($days)."' day) and latest = 'N'");
}
//purge old users
if ($days = $this->GetConfigValue("users_purge_time")) {
$overdues = $this->LoadAll("SELECT name FROM ".$this->config["table_prefix"]."users WHERE lastseen < date_sub(now(), INTERVAL '".mysql_real_escape_string($days)."' DAY)");
$this->Query("DELETE FROM ".$this->config["table_prefix"]."users WHERE lastseen < date_sub(now(), INTERVAL '".mysql_real_escape_string($days)."' DAY)");
foreach ($overdues as $i => $arr){
$name = $arr["name"];
//take care of comments
if ($this->GetConfigValue("purge_deleted_users_comments") == 1)
$this->Query("DELETE FROM ".$this->config["table_prefix"]."comments WHERE user='".$arr["name"]."' limit 1");
//take care of pages
if ($this->GetConfigValue("purge_deleted_users_pages") == 1)
{
//get the users pages
// if we delete the pages then we need to delete it from the links table too
$over_pages = $this->LoadAll("SELECT tag FROM ".$this->config["table_prefix"]."pages WHERE owner='".$name."'");
foreach($over_pages as $idx => $s_arr)
{
$p = $s_arr["tag"];
// pages table...
$this->Query("DELETE FROM ".$this->config["table_prefix"]."pages WHERE owner='".$arr["name"]."' and tag='".$p."'");
//links table ...
$this->Query("DELETE FROM ".$this->config["table_prefix"]."links WHERE from_tag='".$arr["name"]."'");
$this->Query("DELETE FROM ".$this->config["table_prefix"]."links WHERE to_tag='".$arr["name"]."'");
//acls table...
$this->Query("DELETE FROM ".$this->config["table_prefix"]."acls WHERE page_tag='".$p."'");
}
}
else
{
// otherwise just make the owned pages a free
$this->Query("UPDATE pages SET owner='' WHERE owner='".$name);
}
//take care of acls
$test_acls = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."acls");
foreach($test_acls as $idx => $s_arr)
{
$page = $s_arr["page_tag"];
$read = $s_arr["read_acl"];
$write = $s_arr["write_acl"];
$comment = $s_arr["comment_acl"];
$this->Query("UPDATE acls SET read_acls='".str_replace($name."\n", "", $read)."', write_acls='".str_replace($name."\n", "", $write)."', comment_acls='".str_replace($name."\n", "", $comment)."' WHERE page_tag='".$page."' LIMIT 1");
}
}
}
}
Now you will need to edit your wikka.config.php. Just follow the next part ...
Modification of the wikka.config.php
You will need to add the following line inside your wikka.config.php:
"users_purge_time" => "15",
"purge_deleted_users_comments" => "1",
"purge_deleted_users_pages" => "1",
"purge_deleted_users_comments" => "1",
"purge_deleted_users_pages" => "1",
These settings are vital to handle the user cleaner... you may customise the behaviour of the cleaner as you will.
Online Users Action
Installing this action requires that you create /actions/usersonline.php with the following contents :
<?php
/*
@filename: onlineusers.php
@author: George Petsagourakis
@email: petsagouris@hotmail.com
@date: 24 Dec 2004
@license: GPL
@description: You'll need a lastseen column inside your wikka_users table.
And a few modification inside your wikka.php... see the Wikka site for details.
// config vars //
$limit : how many users are going to be displayed
$show_names : decide whether to show the usernames of the online users in the outputted message.
$time_int : an integer that represents the minutes before to take account of. :/ (need a better explanation)
@usage: insert {{onlineusers}} any where in a wakka page.
for a customised output you may want to play along these lines : {{onlineusers limit="5" names="1" time="15"}}
*/
$limit = 5; // How many to show ?
$show_names = true; // show just the names or just the number ?
$time_int = 5; // in minutes
if ($vars) {
foreach($vars as $k => $v)
{
if ($k == "limit") $limit =$v+0;
if ($k == "names") $show_names = ($v == "1") ? true : false;
if ($k == "time") $time_int = $v;
}
}
$limit = " LIMIT $limit";
$res = $this->LoadAll("SELECT name FROM ".$this->config["table_prefix"]."users where now() > DATE_SUB(lastseen, INTERVAL '5' MINUTE)".$limit);
$out = "<small>There are ".count($res)." users online. (In the last ".$time_int." minutes)";
if ($show_names)
{
$out .= "<br />\n Online Users :";
foreach($res as $i => $arr)
{
$comma = ($i+1 == count($res)) ? "" : ", ";
$out .= $this->Format($arr["name"]).$comma;
}
}
$out .= "</small>";
echo $this->ReturnSafeHTML($out);
?>
/*
@filename: onlineusers.php
@author: George Petsagourakis
@email: petsagouris@hotmail.com
@date: 24 Dec 2004
@license: GPL
@description: You'll need a lastseen column inside your wikka_users table.
And a few modification inside your wikka.php... see the Wikka site for details.
// config vars //
$limit : how many users are going to be displayed
$show_names : decide whether to show the usernames of the online users in the outputted message.
$time_int : an integer that represents the minutes before to take account of. :/ (need a better explanation)
@usage: insert {{onlineusers}} any where in a wakka page.
for a customised output you may want to play along these lines : {{onlineusers limit="5" names="1" time="15"}}
*/
$limit = 5; // How many to show ?
$show_names = true; // show just the names or just the number ?
$time_int = 5; // in minutes
if ($vars) {
foreach($vars as $k => $v)
{
if ($k == "limit") $limit =$v+0;
if ($k == "names") $show_names = ($v == "1") ? true : false;
if ($k == "time") $time_int = $v;
}
}
$limit = " LIMIT $limit";
$res = $this->LoadAll("SELECT name FROM ".$this->config["table_prefix"]."users where now() > DATE_SUB(lastseen, INTERVAL '5' MINUTE)".$limit);
$out = "<small>There are ".count($res)." users online. (In the last ".$time_int." minutes)";
if ($show_names)
{
$out .= "<br />\n Online Users :";
foreach($res as $i => $arr)
{
$comma = ($i+1 == count($res)) ? "" : ", ";
$out .= $this->Format($arr["name"]).$comma;
}
}
$out .= "</small>";
echo $this->ReturnSafeHTML($out);
?>
after you have this file sorted and saved you may use the action by inserting {{onlineusers}} inside any wiki page.
Furthermore you can customise the way the output message is printed.
Just play along these lines : {{onlineusers limit="5" time="15" names="0"}}.
NOTE: This modification has not been tested under all situations. You are advised to backup your database entry before running it. I carry no responsibility for any loss of data or any consiquent result of this.
If you have a recomendation, modification or a sipmle comment please post it here ;)
CategoryUserContributions