===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: %%(sql)ALTER TABLE `users` ADD `lastseen` DATETIME NOT NULL;%% ==Modifications inside wikka.php== ---- Find Run() inside your //wikka.php// and find this line : %%(php)if ((!$this->GetUser() && isset($_COOKIE["name"])) && ($user = $this->LoadUser($_COOKIE["name"], $_COOKIE["password"]))) $this->SetUser($user);%% and change it to this : %%(php)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"] :'')));%% Then find the Maintainance() function and change it to this one: %%(php) // 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"); } } } }%% 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: %%(php) "users_purge_time" => "15", "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) $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 = "There are ".count($res)." users online. (In the last ".$time_int." minutes)"; if ($show_names) { $out .= "
\n Online Users :"; foreach($res as $i => $arr) { $comma = ($i+1 == count($res)) ? "" : ", "; $out .= $this->Format($arr["name"]).$comma; } } $out .= "
"; 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