Commit 77ed5310 authored by Dries's avatar Dries

- added new feature for evaluating purpose: user rating (mojo, karma)!
- removed tabs from Jeroen's theme
parent dac719a3
......@@ -159,7 +159,8 @@ CREATE TABLE users (
status tinyint(4) DEFAULT '0' NOT NULL,
history text NOT NULL,
hash varchar(12) DEFAULT '' NOT NULL,
timezone varchar(8),
rating decimal(8,4) DEFAULT '0' NOT NULL,
timezone varchar(8) DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
);
......
<?
$module = array("help" => "account_help",
"cron" => "account_cron",
$module = array("cron" => "account_cron",
"help" => "account_help",
"find" => "account_find",
"block" => "account_block",
"admin" => "account_admin");
function account_help() {
......@@ -9,15 +11,62 @@ function account_help() {
<P>The account-module is responsible for maintaining the user database. It automatically handles tasks like registration, authentication, access rights, password retrieval, user settings and much more.</P>
<P>The required administration can be accomplished through the "account" interface of the administration section. From here administrators can get a quick overview of all registered users and view/edit specific accounts using the links provided. Some useful operations include blocking specific accounts (e.g. a troublesome user) and giving/taking administration permissions. Note that you should only give these permissions to people you trust!</P>
<P>Check the documentation page for detailed information about user management.</P>
<H3>User rating</H3>
<P>The account cron will periodically calculate an overall rating of each user's contributed value that is a time-weighted average of his or her comments ratings with an additional bonus for the stories he or she contributed. The system can be best compared with <A HREF="http://slashcode.com/">SlashCode</A>'s karma and is - in fact - even more similar to <A HREF="http://scoop.kuro5hin.org/">Scoop</A>'s mojo implementation.</P>
<P>I won't elaborate on all the funny math involved and it suffices to say that the actual weighting is done in such a way:</P>
<OL>
<LI>that comments with a lot of votes count more then comments with only one or two votes.</LI>
<LI>that newer comments count for more then older comments.</LI>
</OL>
<P>The idea of (1) is that it favors comments that more people voted on, and thus whose rating is more likely to be accurate or justified.</P>
<P>The latter (2) makes the user rating that comes out of the calulations temporary, based on users' most recent activity and responsive to their current state. This is accomplished by taking each user's last 30 comments, or however many he or she posted in the last 60 days - whatever comes first.</P>
<P>Additionally, users that posted one or more succesful stories in the last 60 days gain extra bonus points which will boost up their overall rating.</P>
<?
}
function account_cron_ratings() {
$period = 5184000; // 60 days
$number = 30; // 30 comments
$r1 = db_query("SELECT id, userid FROM users");
while ($account = db_fetch_object($r1)) {
unset($bonus); unset($votes); unset($score); unset($value); unset($weight);
$r2 = db_query("SELECT COUNT(id) AS number FROM stories WHERE author = $account->id AND (". time() ." - timestamp < $period) AND status = 2");
if ($story = db_fetch_object($r2)) {
$bonus = $story->number;
}
$r3 = db_query("SELECT score, votes FROM comments WHERE author = $account->id AND (". time() ." - timestamp < $period) ORDER BY timestamp LIMIT $number");
while ($comment = db_fetch_object($r3)) {
$weight++;
$score += $weight * $comment->score;
$votes += $weight * $comment->votes;
}
if ($weight > 5 && $votes > 0) {
$value = ($score + $weight) / $votes + $bonus;
db_query("UPDATE users SET rating = '$value' WHERE id = $account->id");
}
}
}
function account_cron() {
// clean-up user database
// update user ratings:
account_cron_ratings();
}
function account_find($keys) {
$find = array();
$result = db_query("SELECT * FROM users WHERE userid LIKE '%". check_input($keys) ."%' LIMIT 20");
while ($account = db_fetch_object($result)) {
array_push($find, array("subject" => $account->userid, "link" => "account.php?op=view&name=$account->userid", "user" => $account->userid));
}
return $find;
}
function account_display($order = "username") {
$sort = array("ID" => "id", "fake e-mail address" => "fake_email", "hostname" => "last_host DESC", "last access date" => "last_access DESC", "real e-mail address" => "real_email", "real name" => "name", "permissions" => "permissions", "status" => "status", "theme" => "theme", "timezone" => "timezone DESC", "username" => "userid");
$sort = array("ID" => "id", "fake e-mail address" => "fake_email", "hostname" => "last_host DESC", "last access date" => "last_access DESC", "real e-mail address" => "real_email", "real name" => "name", "permissions" => "permissions", "rating" => "rating DESC", "status" => "status", "theme" => "theme", "timezone" => "timezone DESC", "username" => "userid");
$show = array("ID" => "id", "username" => "userid", "$order" => "$sort[$order]", "homepage" => "url");
$stat = array(0 => "blocked", 1 => "not confirmed", 2 => "open");
$perm = array(0 => "regular user", 1 => "administrator");
......@@ -179,6 +228,23 @@ function account_view($name) {
}
}
function account_block() {
$result = db_query("SELECT userid, rating FROM users ORDER BY rating DESC LIMIT 10");
$content .= "<TABLE CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$content .= "<TR><TH>Username</TH><TH>Rating</TH></TR>\n";
while ($account = db_fetch_object($result)) {
$content .= "<TR><TD>". format_username($account->userid) ."</TD><TD>". format_data($account->rating) ."</TD></TR>";
}
$content .= "</TABLE>\n";
$block[0]["subject"] = "Top 10:<BR>users";
$block[0]["content"] = $content;
$block[0]["info"] = "Top 10: users";
return $block;
}
function account_admin() {
global $op, $edit, $order, $name;
......
<?
$module = array("admin" => "comment_admin");
$module = array("find" => "comment_find",
"admin" => "comment_admin");
function comment_find($keys) {
$find = array();
$result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.subject LIKE '%". check_input($keys) ."%' OR c.comment LIKE '%". check_input($keys) ."%' ORDER BY c.timestamp DESC LIMIT 20");
while ($comment = db_fetch_object($result)) {
array_push($find, array("subject" => check_output($comment->subject), "link" => "story.php?id=$comment->lid&cid=$comment->cid", "user" => $story->userid, "date" => $comment->timestamp));
}
return $find;
}
function comment_edit($id) {
$result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = $id");
......
<?
$module = array("admin" => "comment_admin");
$module = array("find" => "comment_find",
"admin" => "comment_admin");
function comment_find($keys) {
$find = array();
$result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.subject LIKE '%". check_input($keys) ."%' OR c.comment LIKE '%". check_input($keys) ."%' ORDER BY c.timestamp DESC LIMIT 20");
while ($comment = db_fetch_object($result)) {
array_push($find, array("subject" => check_output($comment->subject), "link" => "story.php?id=$comment->lid&cid=$comment->cid", "user" => $story->userid, "date" => $comment->timestamp));
}
return $find;
}
function comment_edit($id) {
$result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = $id");
......
This diff is collapsed.
......@@ -2,8 +2,9 @@
$module = array("cron" => "story_cron",
"help" => "story_help",
"block" => "story_block",
"admin" => "story_admin");
"find" => "story_find",
"admin" => "story_admin",
"block" => "story_block");
include_once "includes/section.inc";
......@@ -14,6 +15,15 @@ function story_cron() {
}
}
function story_find($keys) {
$find = array();
$result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.status = 2 AND (s.subject LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.article LIKE '%". check_input($keys) ."%') ORDER BY s.timestamp DESC LIMIT 20");
while ($story = db_fetch_object($result)) {
array_push($find, array("subject" => check_output($story->subject), "link" => "story.php?id=$story->id", "user" => $story->userid, "date" => $story->timestamp));
}
return $find;
}
function story_help() {
?>
<P>Scheduled stories: stories that are scheduled to be automatically published at a given date and time. Useful when you have to leave the site alone for a while or when you want to regulate the flow of new content.</P>
......
......@@ -2,8 +2,9 @@
$module = array("cron" => "story_cron",
"help" => "story_help",
"block" => "story_block",
"admin" => "story_admin");
"find" => "story_find",
"admin" => "story_admin",
"block" => "story_block");
include_once "includes/section.inc";
......@@ -14,6 +15,15 @@ function story_cron() {
}
}
function story_find($keys) {
$find = array();
$result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.status = 2 AND (s.subject LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.article LIKE '%". check_input($keys) ."%') ORDER BY s.timestamp DESC LIMIT 20");
while ($story = db_fetch_object($result)) {
array_push($find, array("subject" => check_output($story->subject), "link" => "story.php?id=$story->id", "user" => $story->userid, "date" => $story->timestamp));
}
return $find;
}
function story_help() {
?>
<P>Scheduled stories: stories that are scheduled to be automatically published at a given date and time. Useful when you have to leave the site alone for a while or when you want to regulate the flow of new content.</P>
......
......@@ -6,4 +6,4 @@ password=""
hostname=""
path=""
mysqldump -h $hostname -u $username -p$password $database > $path/backup-`date +"%Y%m%d"`.sql
/usr/bin/mysqldump -h $hostname -u $username -p$password $database > $path/backup-`date +"%Y%m%d"`.sql
......@@ -52,7 +52,7 @@ function header() {
<A HREF=\"account.php\">account</A>
</TD>
</TR>");
?>
?>
</TD>
</TR>
<TR>
......@@ -86,13 +86,13 @@ function abstract($story) {
<FONT COLOR="<? echo $this->fgc2; ?>">
<?
switch (rand(0,13)) {
case 0: $how = "Yelled at us"; break; case 1: $how = "Whispered"; break;
case 2: $how = "Reported"; break; case 3: $how = "Posted"; break;
case 4: $how = "Beamed through"; break; case 5: $how = "Faxed"; break;
case 6: $how = "Tossed at us"; break; case 7: $how = "Morsed"; break;
case 8: $how = "Flagged"; break; case 9: $how = "Written to us"; break;
case 10: $how = "Made up"; break; case 11: $how = "Uploaded"; break;
case 12: $how = "Forged"; break;
case 0: $how = "Yelled at us"; break; case 1: $how = "Whispered"; break;
case 2: $how = "Reported"; break; case 3: $how = "Posted"; break;
case 4: $how = "Beamed through"; break; case 5: $how = "Faxed"; break;
case 6: $how = "Tossed at us"; break; case 7: $how = "Morsed"; break;
case 8: $how = "Flagged"; break; case 9: $how = "Written to us"; break;
case 10: $how = "Made up"; break; case 11: $how = "Uploaded"; break;
case 12: $how = "Forged"; break;
default: $how = "Sneaked through";
}
......@@ -172,14 +172,14 @@ function article($story, $reply) {
<FONT COLOR="<? echo $this->fgc2; ?>">
<?
switch (rand(0,13)) {
case 0: $how = "Yelled at us"; break; case 1: $how = "Whispered"; break;
case 2: $how = "Reported"; break; case 3: $how = "Posted"; break;
case 4: $how = "Beamed through"; break; case 5: $how = "Faxed"; break;
case 6: $how = "Tossed at us"; break; case 7: $how = "Morsed"; break;
case 8: $how = "Flagged"; break; case 9: $how = "Written to us"; break;
case 10: $how = "Made up"; break; case 11: $how = "Uploaded"; break;
case 0: $how = "Yelled at us"; break; case 1: $how = "Whispered"; break;
case 2: $how = "Reported"; break; case 3: $how = "Posted"; break;
case 4: $how = "Beamed through"; break; case 5: $how = "Faxed"; break;
case 6: $how = "Tossed at us"; break; case 7: $how = "Morsed"; break;
case 8: $how = "Flagged"; break; case 9: $how = "Written to us"; break;
case 10: $how = "Made up"; break; case 11: $how = "Uploaded"; break;
case 12: $how = "Forged"; break;
default: $how = "Sneaked through";
default: $how = "Sneaked through";
}
......@@ -194,7 +194,7 @@ function article($story, $reply) {
</TD>
<TD ALIGN=\"center\" WIDTH=\"80\" BGOLOR=\"6C6C6C\" BACKGROUND=\"themes/jeroen/images/menutitle.gif\">
<A HREF=\"search.php?category=$category\"><FONT COLOR=\"<? $this->fgc3; ?>\">$story->category</FONT></A>";
}
}
?>
</FONT>
......@@ -218,7 +218,7 @@ function article($story, $reply) {
else {
echo check_output($story->abstract, 1);
}
if ($story->article)
if ($story->article)
echo "<P>". check_output($story->article, 1) ."</P>";
?>
......@@ -351,9 +351,9 @@ function footer() {
</TD>
<TD VALIGN="top" ALIGN="right">
<?
global $PHP_SELF;
global $PHP_SELF;
theme_account($this);
?>
......
......@@ -10,3 +10,6 @@ alter table stories change category section varchar(64) DEFAULT '' NOT NULL;
# 31/01/2001: block rehashing
alter table blocks add remove tinyint(1) DEFAULT '0' NOT NULL;
# 07/02/2001: value calculation
alter table users add rating decimal(8,4) DEFAULT '0' NOT NULL;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment