2004-06-09 21:42:23 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-15 23:02:52 +00:00
|
|
|
require_once('../inc/profile.inc');
|
|
|
|
|
2004-06-09 21:42:23 +00:00
|
|
|
define('UOTD_THRESHOLD', 7);
|
2004-05-11 22:49:23 +00:00
|
|
|
|
|
|
|
function uotd_thumbnail($profile, $user) {
|
2004-07-21 22:19:21 +00:00
|
|
|
if ($profile->has_picture) {
|
2005-01-19 19:08:46 +00:00
|
|
|
return "<a href=view_profile.php?userid=$user->id><img border=0 vspace=4 hspace=8 align=left src=" . IMAGE_URL . $user->id . "_sm.jpg></a>";
|
2004-07-21 22:19:21 +00:00
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function generate_uotd_page($profile, $user) {
|
|
|
|
$filename = PROFILE_PATH."uotd.html";
|
|
|
|
$descriptor = fopen($filename, "w");
|
|
|
|
|
|
|
|
if ($profile->has_picture) {
|
|
|
|
fwrite($descriptor, uotd_thumbnail($profile, $user));
|
|
|
|
}
|
|
|
|
$x = user_links($user);
|
|
|
|
fwrite($descriptor, "The " . PROJECT . " User of the Day is $x");
|
|
|
|
fclose($descriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the last UOTD profile, or null
|
|
|
|
//
|
|
|
|
function get_current_uotd() {
|
|
|
|
$result = mysql_query("SELECT * FROM profile ORDER BY uotd_time DESC LIMIT 1");
|
|
|
|
$p = null;
|
|
|
|
if (mysql_num_rows($result) > 0) {
|
|
|
|
$p = mysql_fetch_object($result);
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
2006-08-14 22:11:53 +00:00
|
|
|
// Generate the UOTD page;
|
2004-05-11 22:49:23 +00:00
|
|
|
// see if it's time to pick a new UOTD.
|
|
|
|
//
|
|
|
|
function build_uotd_page() {
|
2004-12-27 21:53:38 +00:00
|
|
|
echo date("F d Y", time())."\n";
|
2004-05-11 22:49:23 +00:00
|
|
|
$current_uotd = get_current_uotd();
|
|
|
|
if ($current_uotd) {
|
|
|
|
$assigned = getdate($current_uotd->uotd_time);
|
|
|
|
$now = getdate(time());
|
|
|
|
if ($assigned['mday'] == $now['mday']) {
|
|
|
|
$user = lookup_user_id($current_uotd->userid);
|
|
|
|
generate_uotd_page($current_uotd, $user);
|
2004-12-27 21:53:38 +00:00
|
|
|
echo "Already have UOTD for today\n";
|
2004-05-11 22:49:23 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
2006-08-14 22:11:53 +00:00
|
|
|
|
|
|
|
// get a list of profiles that have been 'approved' for UOTD,
|
|
|
|
// using a project-specific query if supplied in project.inc
|
|
|
|
//
|
2006-08-14 22:50:51 +00:00
|
|
|
if (function_exists('uotd_candidates_query')) {
|
|
|
|
$query = uotd_candidates_query();
|
2006-08-14 22:11:53 +00:00
|
|
|
} else {
|
2006-11-16 19:03:07 +00:00
|
|
|
$query = default_uotd_candidates_query();
|
2006-08-14 22:11:53 +00:00
|
|
|
}
|
|
|
|
$result = mysql_query($query);
|
2004-05-11 22:49:23 +00:00
|
|
|
|
|
|
|
// If the number of approved profiles dips below a threshold,
|
|
|
|
// email the sys admin every time we pick a new one.
|
|
|
|
//
|
|
|
|
if ($result && mysql_num_rows($result) < UOTD_THRESHOLD) {
|
2007-01-03 19:12:53 +00:00
|
|
|
mail(UOTD_ADMIN_EMAIL,
|
2004-05-11 22:49:23 +00:00
|
|
|
PROJECT . ": User of the Day pool is running low!",
|
|
|
|
"The pool of approved candidates for User of the Day has".
|
2004-06-11 18:50:15 +00:00
|
|
|
" reached your assigned threshold: there are now only " . mysql_num_rows($result) . " approved users.\n\n".
|
2004-05-11 22:49:23 +00:00
|
|
|
"To approve more candidates for User of the Day,".
|
2004-06-11 18:50:15 +00:00
|
|
|
" go to the " . PROJECT . " administration page and click \"Unrated profile\""
|
2004-05-11 22:49:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result && mysql_num_rows($result) == 0) {
|
2004-12-27 21:53:38 +00:00
|
|
|
// If all verified profiles have been selected as UOTD,
|
|
|
|
// reshow the one that was shown least recently.
|
|
|
|
//
|
2006-08-14 22:11:53 +00:00
|
|
|
$result = mysql_query("SELECT * FROM profile,user WHERE profile.userid=user.id AND verification=1 ORDER BY uotd_time ASC LIMIT 1");
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$result || mysql_num_rows($result) == 0) {
|
|
|
|
// No valid users of the day - do something.
|
2004-12-27 21:53:38 +00:00
|
|
|
echo "No screened users found\n";
|
2004-05-11 22:49:23 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$profile = mysql_fetch_object($result);
|
|
|
|
$user = lookup_user_id($profile->userid);
|
|
|
|
generate_uotd_page($profile, $user);
|
|
|
|
|
2006-08-14 22:11:53 +00:00
|
|
|
$sql = "UPDATE profile SET uotd_time = ".time()." WHERE userid=$user->id";
|
2004-05-11 22:49:23 +00:00
|
|
|
mysql_query($sql);
|
|
|
|
|
|
|
|
mail($user->email_addr,
|
|
|
|
"You're the " . PROJECT . " user of the day!",
|
|
|
|
"Congratulations!\n\nYou've been chosen as the "
|
|
|
|
. PROJECT . " user of the day!
|
|
|
|
Your profile will be featured on the " . PROJECT . " website for the next 24 hours."
|
|
|
|
);
|
2004-12-27 21:53:38 +00:00
|
|
|
echo "Chose user $user->id as UOTD\n";
|
2004-05-11 22:49:23 +00:00
|
|
|
}
|
|
|
|
|
2006-11-16 19:03:07 +00:00
|
|
|
// This is the default policy for choosing the UOTD on any BOINC project.
|
|
|
|
// To override this with your own policy, create a similar function in
|
|
|
|
// your own project.inc called uotd_candidates_query()
|
|
|
|
function default_uotd_candidates_query(){
|
|
|
|
if (profile_screening()) {
|
|
|
|
$query = "SELECT * FROM profile,user WHERE profile.userid=user.id ";
|
|
|
|
$query .= " AND verification=1 ";
|
|
|
|
$query .= " AND expavg_credit>1 ";
|
|
|
|
$query .= " AND uotd_time IS NULL ";
|
|
|
|
$query .= "ORDER BY RAND()";
|
|
|
|
} else {
|
|
|
|
$query = "SELECT * FROM profile,user WHERE profile.userid=user.id ";
|
|
|
|
$query .= " AND verification=1 ";
|
|
|
|
$query .= " AND uotd_time IS NULL ";
|
|
|
|
$query .= "ORDER BY RAND()";
|
|
|
|
}
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get a list of profiles that have been 'approved' for UOTD,
|
|
|
|
// using a project-specific query if supplied in project.inc
|
|
|
|
function count_uotd_candidates(){
|
|
|
|
$n = -1; // negative value returned on error
|
|
|
|
if (function_exists('uotd_candidates_query')) {
|
|
|
|
$query = uotd_candidates_query();
|
|
|
|
} else {
|
|
|
|
$query = default_uotd_candidates_query();
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = mysql_query($query);
|
|
|
|
if($result) {
|
|
|
|
$n = mysql_num_rows($result);
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
|
|
|
|
return $n;
|
|
|
|
}
|
|
|
|
|
2004-05-11 22:49:23 +00:00
|
|
|
?>
|