Business needs have dictated that I not pursue the Karma hack for my own purposes.
Instead we are developing a new system that will be used as a form of electronic currency in our forum for our members. As such it is not a user rating related feature anymore. Now SitePoint members will earn points (SitePoints, if you will) for contributing to the community. As time goes on they will be able to turn these points in for added member bonuses and discounts on products.
As such, I won't be persuing a simple "Karma" hack anymore. However here is the code that was used for the previous version of the hack. I converted this to PHP after looking at the PERL version written for UBB.
PHP Code:
<?php
require("global.php");
$permissions=getpermissions($bbuserid,$bbusergroupid);
if ($permissions[canreply]!=1) {
eval("echo dovars(\"".gettemplate("karma_nopermission")."\");");
exit;
}
// ############################### Start Karma ###############################
if ($action=="karma") {
//Make sure a user can't give karma on their own posts.
if ($posterid==$bbuserid) {
$points=$DB_site->query_first("Select karma from user where userid=$bbuserid");
$karmicavg=$DB_site->query_first("SELECT SUM(rank) as netrank from karma where postid=$postid");
$karmicbal=$karmicavg[netrank];
$karma=$points[karma];
if ($karmicbal>0) {
$karmicmsg="Your Karma on this post is positive.";
} elseif ($karmicbal<0) {
$karmicmsg="Your Karma on this post is negative.";
} elseif ($karmicbal==0 || $karmicbal==NULL) {
$karmicmsg="There is no Karma on this post.";
}
eval("echo dovars(\"".gettemplate("karma_show")."\");");
exit;
}
// Make Sure Karma is only given once per post.
$karmaexists=$DB_site->query_first("Select count(*) as count from karma where userid=$bbuserid and postid=$postid");
if ($karmaexists[count]<>0) {
eval("echo dovars(\"".gettemplate("karma_exists")."\");");
exit;
}
$userinfo=$DB_site->query_first("SELECT user.userid,post.userid as posterid,user.username as username
FROM user LEFT JOIN post ON (user.userid = post.userid)
WHERE post.postid=$postid");
$postname=$userinfo[username];
$posterid=$userinfo[posterid];
$userid=$bbuserid;
eval("echo dovars(\"".gettemplate("karma")."\");");
exit;
}
// ############################### Update Karma ###############################
if ($action=="alter") {
if ($comments=="No Comment") {
$comments="";
}
$posterinfo=$DB_site->query_first("SELECT karma from user where userid=$posterid");
$karma=$posterinfo[karma];
$userinfo=$DB_site->query_first("SELECT posts from user where userid=$userid");
$posts=$userinfo[posts];
if ($posts > 1499)
{ $karmaaward=15; }
elseif ($posts > 199)
{ $karmaaward=floor($posts/100); }
else
{ $karmaaward=1; }
$rank=0;
if ($adjust=="praise")
{$karma += $karmaaward;$rank += $karmaaward;}
else
{$karma -= $karmaaward;$rank -= $karmaaward;}
if ($karma > $maxkarma)
{$karma = $maxkarma;}
if ($karma < $minkarma)
{$karma = $minkarma;}
$DB_site->query("UPDATE user SET karma=$karma where userid=$posterid");
$DB_site->query("INSERT INTO karma (postid,userid,rank,comments,posterid) VALUES ($postid,$userid,$rank,'".addslashes($comments)."',$posterid)");
//$DB_site->query("INSERT INTO karma (postid,userid,rank) VALUES ($postid,$userid,$rank)");
eval("echo dovars(\"".gettemplate("karma_close")."\");");
exit;
}
// ############################### Karma Help###############################
if ($action="help") {
eval("echo dovars(\"".gettemplate("karma_help")."\");");
exit;
}
// ############################### View Comments ###############################
if ($action=="comments") {
exit;
}
?>