61 lines
2.3 KiB
Plaintext
61 lines
2.3 KiB
Plaintext
<?php
|
|
|
|
function rating_conf_options() {
|
|
$period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600));
|
|
$output .= form_select(t("Update interval"), "rating_cron_time" , variable_get("rating_cron_time", 86400), $period, t("The update interval for the user ratings. Requires crontab."));
|
|
return $output;
|
|
}
|
|
|
|
function rating_cron() {
|
|
if (time() - variable_get("rating_cron_last", 0) > variable_get("rating_cron_time", time())) {
|
|
variable_set("rating_cron_last", time());
|
|
|
|
$r1 = db_query("SELECT id FROM users ORDER BY rating DESC");
|
|
while ($account = db_fetch_object($r1)) {
|
|
db_query("UPDATE users SET rating = '". user_gravity($account->id) ."' WHERE id = '$account->id'");
|
|
$rating[$account->id] = ++$i;
|
|
}
|
|
|
|
db_query("DELETE FROM rating");
|
|
|
|
$r2 = db_query("SELECT id FROM users ORDER BY rating DESC");
|
|
while ($account = db_fetch_object($r2)) {
|
|
db_query("INSERT INTO rating (user, new, old) VALUES ('$account->id', '". ++$j ."', '". $rating[$account->id] ."')");
|
|
}
|
|
}
|
|
}
|
|
|
|
function rating_help() {
|
|
?>
|
|
<P>The rating cron will periodically calculate each user's gravity, the overall time-weighted rating of each user's contributions.</P>
|
|
<?
|
|
}
|
|
|
|
function rating_list($limit) {
|
|
$result = db_query("SELECT u.userid, u.rating, r.* FROM users u LEFT JOIN rating r ON u.id = r.user ORDER BY u.rating DESC LIMIT $limit");
|
|
|
|
$output .= "<TABLE CELLPADDING=\"1\" CELLSPACING=\"1\">\n";
|
|
while ($account = db_fetch_object($result)) {
|
|
$ranking = $account->old - $account->new;
|
|
$output .= "<TR><TD ALIGN=\"right\">". ++$i .".</TD><TD>". format_username($account->userid) ."</TD><TD ALIGN=\"right\">". check_output($account->rating) ."</TD><TD>(". ($ranking < 0 ? "" : "+") ."$ranking)</TD></TR>";
|
|
}
|
|
$output .= "</TABLE>\n";
|
|
return $output;
|
|
}
|
|
|
|
function rating_page() {
|
|
global $theme;
|
|
$theme->header();
|
|
$theme->box("Top 100 users", rating_list(100));
|
|
$theme->footer();
|
|
}
|
|
|
|
function rating_block() {
|
|
$block[0][subject] = "Top 10:<BR>users";
|
|
$block[0][content] = rating_list(10);
|
|
$block[0][info] = "Top 10: users";
|
|
return $block;
|
|
}
|
|
|
|
?>
|