#!/usr/bin/env php . // This script for use ONLY by the BOINC-teams project. // It generates an XML file with team and user info $cli_only = true; require_once("../inc/util_ops.inc"); function escape2($strin) { $strout = null; for ($i = 0; $i < strlen($strin); $i++) { $ord = ord($strin[$i]); if (($ord > 0 && $ord < 32) || ($ord >= 127)) { $strout .= "&#{$ord};"; } else { switch ($strin[$i]) { case '<': $strout .= '<'; break; case '>': $strout .= '>'; break; case '&': $strout .= '&'; break; case '"': $strout .= '"'; break; default: $strout .= $strin[$i]; } } } return $strout; } function escape($strin) { $dom = new DOMDocument('1.0'); $element = $dom->createElement('Element'); $element->appendChild( $dom->createTextNode($strin) ); $dom->appendChild($element); $x = $dom->saveXml(); $x = substr($x, 31); $x = substr($x, 0, -11); return $x; } function handle_team($team, $f) { echo "Team: $team->name\n"; $user = BoincUser::lookup_id($team->userid); if (!$user) { echo "no user for team $team->id\n"; return; } if ($user->teamid != $team->id) { echo "Founder is not member of $team->name\n"; return; } if (!$user->email_validated) { echo "the founder of $team->name, $user->email_addr, is not validated\n"; return; } $user_email_munged = str_rot13($user->email_addr); fwrite($f, " ".escape($team->name)." ".escape($team->url)." $team->type ".escape($team->name_html)." ".escape($team->description)." $team->country $team->id $user_email_munged ".escape($user->name)." ".escape($user->country)." ".escape($user->postal_code)." ".escape($user->url)." " ); } function main() { echo "------------ Starting at ".time_str(time())."-------\n"; $f = fopen("temp.xml", "w"); $teams = BoincTeam::enum(null); fwrite($f, "\n\n"); foreach($teams as $team) { handle_team($team, $f); } fwrite($f, "\n"); fclose($f); if (!rename("temp.xml", "/home/boincadm/boinc-site/boinc_teams.xml")) { echo "Rename failed\n"; } echo "------------ Finished at ".time_str(time())."-------\n"; } main(); ?>