. require_once("../inc/credit.inc"); require_once("../inc/email.inc"); require_once("../inc/util.inc"); require_once("../inc/team.inc"); require_once("../inc/friend.inc"); require_once("../inc/forum_db.inc"); require_once("../inc/notify.inc"); require_once("../inc/ldap.inc"); if (!defined('REMOTE_PROJECTS_TTL')) { define('REMOTE_PROJECTS_TTL', 86400); } function get_other_projects($user) { $cpid = md5($user->cross_project_id . $user->email_addr); $url = "http://boinc.netsoft-online.com/get_user.php?cpid=".$cpid; // Check the cache for that URL // $cacheddata = get_cached_data(REMOTE_PROJECTS_TTL, $url); if ($cacheddata){ $remote = unserialize($cacheddata); } else { $xml_object = null; $remote = false; // Fetch the XML, use curl if fopen() is disallowed // if (ini_get('allow_url_fopen')) { $timeout = 3; $old_timeout = ini_set('default_socket_timeout', $timeout); $xml_object = null; $f = @file_get_contents($url); if ($f) { $xml_object = @simplexml_load_string($f); } ini_set('default_socket_timeout', $old_timeout); if (!$xml_object) { return $user; } } else { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 3); $rawxml = @curl_exec($ch); $xml_object = null; if ($rawxml) { $xml_object = @simplexml_load_string($rawxml); } curl_close($ch); if (!xml_object) { return $user; } } // auto-cast the project list to an array of stdClass projects // $remote = @json_decode(json_encode((array)$xml_object))->project; if (!$remote) { return $user; } else { // Cache the results set_cached_data(REMOTE_PROJECTS_TTL, serialize($remote), $url); } } $user->projects = $remote; return $user; } function show_project($project) { if ($project->url == "http://www.worldcommunitygrid.org/") { $x = $project->name; } else { $x = "url"."show_user.php?userid=$project->id\">$project->name"; } echo "
".tra("Click for user page")."
", tra("Total credit"), tra("Average credit"), tra("Since") )); foreach($user->projects as $project) { show_project($project); } end_table(); } function total_posts($user) { return BoincPost::count("user=$user->id"); } function show_credit($user) { row2(tra("Total credit"), format_credit_large($user->total_credit)); row2(tra("Recent average credit"), format_credit($user->expavg_credit)); if (function_exists("project_user_credit")) { project_user_credit($user); } } require_once("../inc/stats_sites.inc"); // show dynamic user info (private) // function show_user_stats_private($user) { global $cpid_stats_sites; row1(tra("Computing and credit")); show_credit($user); $config = get_config(); row2(tra("Computers on this account"), "".tra("View").""); row2(tra("Tasks"), "id\">".tra("View").""); $cpid = md5($user->cross_project_id . $user->email_addr); $x = ""; shuffle($cpid_stats_sites); foreach ($cpid_stats_sites as $site) { $name = $site[0]; $y = sprintf($site[1], $cpid); $x .= "$name".tra("Used in community functions")."
", $user->id); if (!no_computing()) { row2( tra("Account keys"), "".tra("View")."" ); } row1("".tra("Preferences")); if (!no_computing()) { row2( tra("When and how BOINC uses your computer"), "".tra("Computing preferences")."" ); } row2(tra("Message boards and private messages"), "".tra("Community preferences")."" ); if (!no_computing()) { row2(tra("Preferences for this project"), "".tra("%1 preferences", PROJECT)."" ); } } function friend_links($user) { if (is_banished($user)) { return ""; } $x = "";
if ($user->has_profile) {
$profile = BoincProfile::lookup_fields("has_picture", "userid=$user->id");
if ($profile && $profile->has_picture) {
$img_url = profile_thumb_url($user->id);
} else {
$img_url = url_base()."img/head_20.png";
}
$title = tra("View the profile of %1", $user->name);
$alt = tra("Profile");
$x .= ' '; } $x .= " id."\">".$user->name.""; if ($user->donated == 1) { require_once("../project/donations.inc"); $x .= DONATION_LINK; } if ($user->donated == 2) { require_once("../project/donations.inc"); $x .= DONATION_LINK_TWO; } $x .= " |
".tra("(foundership change request pending)")."
"; } row2(tra("Member of team"), $x); } else { row2(tra("Team"), tra("None")." · ".tra("find a team").""); } $teams_founded = BoincTeam::enum("userid=$user->id"); foreach ($teams_founded as $team) { if ($team->id != $user->teamid) { $x = "id\">$team->name"; $x .= " | id."\">".tra("Administer").""; if ($team->ping_user > 0) { $x .= "".tra("(foundership change request pending)")."";
}
row2(tra("Founder but not member of"), $x);
}
}
}
$friends = BoincFriend::enum("user_src=$user->id and reciprocated=1");
$x = "".tra("Find friends")."
\n";
$n = count($friends);
if ($n) {
foreach($friends as $friend) {
$fuser = BoincUser::lookup_id($friend->user_dest);
if (!$fuser) continue;
$x .= friend_links($fuser);
}
row2(tra("Friends")." ($n)", $x);
} else {
row2(tra("Friends"), $x);
}
end_table();
}
// show summary of dynamic and static info (public)
//
function show_user_summary_public($user) {
global $g_logged_in_user;
row2(tra("User ID"), $user->id);
row2(tra("%1 member since", PROJECT), date_str($user->create_time));
row2(tra("Country"), $user->country);
// don't show URL if user has no recent credit (spam suppression)
//
if (strlen($user->url)) {
if (no_computing() || $user->expavg_credit > 1) {
row2(tra("URL"), "url\">http://$user->url");
}
}
if (!no_computing()) {
show_credit($user);
if ($user->show_hosts) {
row2(tra("Computers"), "id\">".tra("View")."");
} else {
row2(tra("Computers"), tra("hidden"));
}
}
if ($user->donated == 1) {
if (file_exists("../project/donations.inc")) {
require_once("../project/donations.inc");
row2(tra("Donor"), DONATION_LINK);
}
}
if ($user->donated == 2) {
if (file_exists("../project/donations.inc")) {
require_once("../project/donations.inc");
row2(tra("Donor"), DONATION_LINK_TWO);
}
}
}
// Returns a cacheable community links data object
// @param user The user to produce a community links object for
function get_community_links_object($user){
$cache_object = new StdClass;
$cache_object->post_count = total_posts($user);
$cache_object->user = $user;
$cache_object->team = BoincTeam::lookup_id($user->teamid);
$cache_object->friends = array();
$friends = BoincFriend::enum("user_src=$user->id and reciprocated=1");
foreach($friends as $friend) {
$fuser = BoincUser::lookup_id($friend->user_dest);
if (!$fuser) continue;
$cache_object->friends[] = $fuser;
}
return $cache_object;
}
function community_links($clo, $logged_in_user){
$user = $clo->user;
$team = $clo->team;
$friends = $clo->friends;
$tot = $clo->post_count;
if (!DISABLE_TEAMS) {
if ($user->teamid && $team) {
row2(tra("Team"), "id\">$team->name");
} else {
row2(tra("Team"), tra("None"));
}
}
if (!DISABLE_FORUMS) {
if ($tot) {
row2(tra("Message boards"), "id\">".tra("%1 posts", $tot)."");
}
}
if ($logged_in_user && $logged_in_user->id != $user->id) {
row2(tra("Contact"), "id."\">".tra("Send private message")."");
$friend = BoincFriend::lookup($logged_in_user->id, $user->id);
if ($friend && $friend->reciprocated) {
row2(tra("This person is a friend"),
"id\">".tra("Cancel friendship").""
);
} else if ($friend) {
row2(tra("Friends"), "id\">".tra("Request pending")."");
} else {
row2(tra("Friends"), "id\">".tra("Add as friend")."");
}
}
if ($friends) {
$x = "";
foreach($friends as $friend) {
$x .= friend_links($friend);
}
row2(tra("Friends")." (".sizeof($friends).")", $x);
}
}
function show_profile_link($user) {
if ($user->has_profile) {
row2(tra("Profile"), "id\">".tra("View")."");
}
}
function show_account_private($user) {
grid(
false,
function() use ($user) {
start_table();
show_user_info_private($user);
if (!no_computing()) {
show_user_stats_private($user);
}
if (file_exists("../project/donations.inc")) {
require_once("../project/donations.inc");
if (function_exists('show_user_donations_private')) {
show_user_donations_private($user);
}
}
end_table();
show_other_projects($user, true);
project_user_page_private($user);
//echo "Delete account\n";
},
function() use ($user) {
show_community_private($user);
}
);
}
function is_banned_email_addr($email_addr) {
global $banned_email_domains;
if (isset($banned_email_domains)) {
foreach($banned_email_domains as $d) {
$x = strstr($email_addr, $d);
if ($x == $d) return true;
}
}
return false;
}
function is_valid_user_name($name, &$reason) {
if (trim($name) !== $name) {
$reason = tra("user name cannot have leading or trailing white space");
return false;
}
if (strlen($name) == 0) {
$reason = tra("user name must be nonempty");
return false;
}
if (sanitize_tags($name) !== $name) {
$reason = tra("user name may not contain HTML tags");
return false;
}
return true;
}
// the following DB-escapes its args
//
function make_user(
$email_addr, $name, $passwd_hash,
$country=null, $postal_code=null, $project_prefs=null, $teamid=0
) {
if (!is_valid_email_addr($email_addr)) return null;
if (is_banned_email_addr($email_addr)) return null;
$authenticator = random_string();
$cross_project_id = random_string();
$now = time();
if (!is_valid_country($country)) return null;
$email_addr = BoincDb::escape_string($email_addr);
$name = sanitize_tags($name);
$name = BoincDb::escape_string($name);
$passwd_hash = BoincDb::escape_string($passwd_hash);
$country = BoincDb::escape_string($country);
$postal_code = sanitize_tags(BoincDb::escape_string($postal_code));
$uid = BoincUser::insert("(create_time, email_addr, name, authenticator, country, postal_code, total_credit, expavg_credit, expavg_time, project_prefs, teamid, venue, send_email, show_hosts, posts, seti_id, seti_nresults, seti_last_result_time, seti_total_cpu, has_profile, cross_project_id, passwd_hash, email_validated, donated) values($now, '$email_addr', '$name', '$authenticator', '$country', '$postal_code', 0, 0, unix_timestamp(), '$project_prefs', $teamid, '', 1, 1, 0, 0, 0, 0, 0, 0, '$cross_project_id', '$passwd_hash', 0, 0)");
if (!$uid) {
return null;
}
$user = BoincUser::lookup_id($uid);
if (defined('RECORD_USER_IP')) {
$ip = $_SERVER['REMOTE_ADDR'];
$ip = BoincDb::escape_string($ip);
$user->update("venue='$ip'");
}
return $user;
}
function make_user_ldap($email_addr, $name) {
$email_addr = BoincDb::escape_string($email_addr);
$name = sanitize_tags($name);
$name = BoincDb::escape_string($name);
$authenticator = random_string();
$cross_project_id = random_string();
$passwd_hash = random_string();
$now = time();
$uid = BoincUser::insert("(create_time, email_addr, name, authenticator, country, postal_code, total_credit, expavg_credit, expavg_time, project_prefs, teamid, send_email, show_hosts, cross_project_id, passwd_hash) values($now, '$email_addr', '$name', '$authenticator', '', '', 0, 0, unix_timestamp(), '', 0, 1, 1, '$cross_project_id', '$passwd_hash')");
if ($uid) {
return BoincUser::lookup_id($uid);
} else {
return null;
}
}
// delete a user and all associated records except
// result
// host
// batch
// team
// user_submit
// user_submit_app
// credited_job
// donation_paypal
// sent_email
//
function delete_user($user) {
delete_profile($user);
forum_delete_user($user);
// deletes post, thread, subscription, forum_preferences, forum_logging
BoincPrivateMessage::delete_aux("userid=$user->id or senderid=$user->id");
BoincNotify::delete_aux("userid=$user->id");
BoincCreditUser::delete_user($user);
BoincBadgeUser::delete("user_id=$user->id");
BoincFriend::delete_aux("user_src=$user->id or user_dest=$user->id");
$user->delete();
}
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?>