2000-12-14 14:13:37 +00:00
<?
2001-02-07 22:01:57 +00:00
$module = array("cron" => "account_cron",
"help" => "account_help",
"find" => "account_find",
"block" => "account_block",
2000-12-16 08:39:01 +00:00
"admin" => "account_admin");
2001-01-13 16:33:19 +00:00
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>
2001-02-07 22:01:57 +00:00
<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>
2001-01-13 16:33:19 +00:00
<?
}
2001-02-07 22:01:57 +00:00
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");
}
}
}
2000-12-16 08:39:01 +00:00
function account_cron() {
2001-02-07 22:01:57 +00:00
// 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;
2000-12-16 08:39:01 +00:00
}
2000-12-14 14:13:37 +00:00
function account_display($order = "username") {
2001-02-07 22:01:57 +00:00
$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");
2000-12-16 21:42:52 +00:00
$show = array("ID" => "id", "username" => "userid", "$order" => "$sort[$order]", "homepage" => "url");
2000-12-14 14:13:37 +00:00
$stat = array(0 => "blocked", 1 => "not confirmed", 2 => "open");
2000-12-16 21:42:52 +00:00
$perm = array(0 => "regular user", 1 => "administrator");
2000-12-14 14:13:37 +00:00
// Perform query:
2000-12-16 21:42:52 +00:00
$result = db_query("SELECT u.id, u.userid, u.". strtok($sort[$order], " ") .", u.url FROM users u ORDER BY $sort[$order]");
2001-01-26 13:38:46 +00:00
2000-12-14 14:13:37 +00:00
// Generate output:
2000-12-29 11:00:56 +00:00
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2000-12-14 14:13:37 +00:00
$output .= " <TR>\n";
2000-12-16 21:42:52 +00:00
$output .= " <TH ALIGN=\"right\" COLSPAN=\"". (sizeof($show) + 2) ."\">\n";
2000-12-14 14:13:37 +00:00
$output .= " <FORM ACTION=\"admin.php?mod=account\" METHOD=\"post\">\n";
$output .= " <SELECT NAME=\"order\">\n";
foreach ($sort as $key=>$value) {
$output .= " <OPTION VALUE=\"$key\"". ($key == $order ? " SELECTED" : "") .">Sort by $key</OPTION>\n";
}
$output .= " </SELECT>\n";
$output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Update\">\n";
$output .= " </FORM>\n";
$output .= " </TH>\n";
$output .= " </TR>\n";
$output .= " <TR>\n";
2000-12-16 21:42:52 +00:00
2000-12-14 14:13:37 +00:00
foreach ($show as $key=>$value) {
$output .= " <TH>$key</TH>\n";
}
2000-12-16 21:42:52 +00:00
$output .= " <TH COLSPAN=\"2\">operations</TH>\n";
2000-12-14 14:13:37 +00:00
$output .= " </TR>\n";
while ($account = db_fetch_array($result)) {
$output .= " <TR>\n";
foreach ($show as $key=>$value) {
2000-12-16 21:42:52 +00:00
switch($value = strtok($value, " ")) {
2001-02-04 22:09:38 +00:00
case "real_email":
2000-12-14 14:13:37 +00:00
$output .= " <TD>". format_email($account[$value]) ."</TD>\n";
break;
case "last_access":
2000-12-16 21:42:52 +00:00
$output .= " <TD>". format_interval(time() - $account[$value]) ." ago</TD>\n";
2000-12-14 14:13:37 +00:00
break;
2001-02-04 22:09:38 +00:00
case "status":
2000-12-14 14:13:37 +00:00
$output .= " <TD ALIGN=\"center\">". $stat[$account[$value]] ."</TD>\n";
break;
2000-12-16 21:42:52 +00:00
case "permissions":
$output .= " <TD ALIGN=\"center\">". $perm[$account[$value]] ."</TD>\n";
break;
2000-12-14 14:13:37 +00:00
case "timezone":
$output .= " <TD ALIGN=\"center\">". format_data($account[$value] / 3600) ."</TD>\n";
break;
case "url":
$output .= " <TD>". format_url($account[$value]) ."</TD>\n";
break;
2001-02-04 22:09:38 +00:00
case "userid":
2000-12-14 14:13:37 +00:00
$output .= " <TD>". format_username($account[$value], 1) ."</TD>\n";
break;
default:
$output .= " <TD>". format_data($account[$value]) ."</TD>\n";
}
}
2000-12-16 21:42:52 +00:00
$output .= " <TD ALIGN=\"center\"><A HREF=\"admin.php?mod=account&op=view&name=$account[userid]\">view</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=account&op=edit&name=$account[userid]\">edit</A></TD>\n";
2000-12-14 14:13:37 +00:00
$output .= " </TR>\n";
}
$output .= "</TABLE>\n";
print $output;
}
function account_stories($id) {
$result = db_query("SELECT * FROM stories WHERE author = $id ORDER BY timestamp DESC");
while ($story = db_fetch_object($result)) {
2001-01-20 12:20:31 +00:00
$output .= "<LI><A HREF=\"story.php?id=$story->id\">". check_output($story->subject) ."</A></LI>\n";
2000-12-14 14:13:37 +00:00
}
return $output;
}
function account_comments($id) {
2001-01-20 12:20:31 +00:00
$result = db_query("SELECT * FROM comments WHERE link = 'story' AND author = $id ORDER BY timestamp DESC");
2000-12-14 14:13:37 +00:00
while ($comment = db_fetch_object($result)) {
2001-02-08 16:57:26 +00:00
$output .= "<LI><A HREF=\"story.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A></LI>\n";
2000-12-14 14:13:37 +00:00
}
return $output;
}
2001-02-04 22:09:38 +00:00
function account_edit_save($name, $edit) {
2000-12-16 21:42:52 +00:00
foreach ($edit as $key=>$value) {
$query .= "$key = '". addslashes($value) ."', ";
}
db_query("UPDATE users SET $query last_access = '". time() ."' WHERE userid = '$name'");
watchdog("message", "account: modified user '$name'");
}
function account_edit($name) {
$status = array(0 => "blocked", 1 => "not confirmed", 2 => "open");
$permissions = array(0 => "regular user", 1 => "administrator");
$result = db_query("SELECT * FROM users WHERE userid = '$name'");
if ($account = db_fetch_object($result)) {
foreach ($status as $key=>$value) {
2001-01-26 13:38:46 +00:00
$stat .= " <OPTION VALUE=\"$key\"". (($account->status == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
2000-12-16 21:42:52 +00:00
}
$stat = "<SELECT NAME=\"edit[status]\">\n$stat</SELECT>\n";
foreach ($permissions as $key=>$value) {
2001-01-26 13:38:46 +00:00
$perm .= " <OPTION VALUE=\"$key\"". (($account->permissions == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
2000-12-16 21:42:52 +00:00
}
$perm = "<SELECT NAME=\"edit[permissions]\">\n$perm</SELECT>\n";
$output .= "<FORM ACTION=\"admin.php?mod=account\" METHOD=\"post\">\n";
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">\n";
$output .= " <TR><TD ALIGN=\"right\"><B>ID:</B></TD><TD>$account->id</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Status:</B></TD><TD>$stat</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Username:</B></TD><TD>$account->userid</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Real name:</B></TD><TD>". format_data($account->name) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Real e-mail address:</B></TD><TD>". format_email($account->real_email) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Fake e-mail address:</B></TD><TD><INPUT NAME=\"edit[fake_email]\" SIZE=\"55\" VALUE=\"$account->fake_email\"></TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>URL of homepage:</B></TD><TD><INPUT NAME=\"edit[url]\" SIZE=\"55\" VALUE=\"$account->url\"></TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Permissions:</B></TD><TD>$perm</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Last access:</B></TD><TD>". format_date($account->last_access) ." from $account->last_host</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Bio information:</B></TD><TD><TEXTAREA NAME=\"edit[bio]\" COLS=\"35\" ROWS=\"5\" WRAP=\"virtual\">$account->bio</TEXTAREA></TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Signature:</B></TD><TD><TEXTAREA NAME=\"edit[signature]\" COLS=\"35\" ROWS=\"5\" WRAP=\"virtual\">$account->signature</TEXTAREA></TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Theme:</B></TD><TD>". format_data($account->theme) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Timezone:</B></TD><TD>". format_data($account->timezone / 3600) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\" VALIGN=\"top\"><B>Submitted stories:</B></TD><TD>". format_data(account_stories($account->id)) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\" VALIGN=\"top\"><B>Submitted comments:</B></TD><TD>". format_data(account_comments($account->id)) ."</TD></TR>\n";
$output .= "</TABLE>\n";
$output .= "<INPUT NAME=\"name\" TYPE=\"hidden\" VALUE=\"$account->userid\">\n";
$output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Save account\">\n";
$output .= "</FORM>\n";
print "$output";
}
}
2000-12-14 14:13:37 +00:00
function account_view($name) {
$status = array(0 => "blocked", 1 => "not confirmed", 2 => "open");
2000-12-16 21:42:52 +00:00
$permissions = array(0 => "regular user", 1 => "administrator");
2000-12-14 14:13:37 +00:00
$result = db_query("SELECT * FROM users WHERE userid = '$name'");
if ($account = db_fetch_object($result)) {
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">\n";
$output .= " <TR><TD ALIGN=\"right\"><B>ID:</B></TD><TD>$account->id</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Status:</B></TD><TD>". $status[$account->status] ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Username:</B></TD><TD>$account->userid</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Real name:</B></TD><TD>". format_data($account->name) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Real e-mail address:</B></TD><TD>". format_email($account->real_email) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Fake e-mail address:</B></TD><TD>". format_data($account->fake_email) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>URL of homepage:</B></TD><TD>". format_url($account->url) ."</TD></TR>\n";
2000-12-16 21:42:52 +00:00
$output .= " <TR><TD ALIGN=\"right\"><B>Permissions:</B></TD><TD>". $permissions[$account->permissions] ."</TD></TR>\n";
2000-12-14 14:13:37 +00:00
$output .= " <TR><TD ALIGN=\"right\"><B>Last access:</B></TD><TD>". format_date($account->last_access) ." from $account->last_host</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Bio information:</B></TD><TD>". format_data($account->bio) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Signature:</B></TD><TD>". format_data($account->signature) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Theme:</B></TD><TD>". format_data($account->theme) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\"><B>Timezone:</B></TD><TD>". format_data($account->timezone / 3600) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\" VALIGN=\"top\"><B>Submitted stories:</B></TD><TD>". format_data(account_stories($account->id)) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"right\" VALIGN=\"top\"><B>Submitted comments:</B></TD><TD>". format_data(account_comments($account->id)) ."</TD></TR>\n";
$output .= "</TABLE>\n";
print "$output";
}
}
2001-02-07 22:01:57 +00:00
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;
}
2000-12-14 14:13:37 +00:00
function account_admin() {
2000-12-16 21:42:52 +00:00
global $op, $edit, $order, $name;
2000-12-14 14:13:37 +00:00
2001-01-13 16:33:19 +00:00
print "<SMALL><A HREF=\"admin.php?mod=account\">overview</A> | <A HREF=\"admin.php?mod=account&op=help\">help</A></SMALL><HR>\n";
2000-12-14 14:13:37 +00:00
switch ($op) {
2000-12-16 21:42:52 +00:00
case "edit":
account_edit($name);
break;
2001-01-13 16:33:19 +00:00
case "help":
account_help();
break;
2000-12-14 14:13:37 +00:00
case "view":
account_view($name);
break;
2000-12-16 21:42:52 +00:00
case "Save account":
2001-02-04 22:09:38 +00:00
account_edit_save($name, $edit);
2000-12-16 21:42:52 +00:00
account_view($name);
break;
2000-12-14 14:13:37 +00:00
case "Update":
account_display($order);
break;
default:
2001-01-26 13:38:46 +00:00
account_display();
2000-12-14 14:13:37 +00:00
}
}
2000-12-16 08:39:01 +00:00
?>