Issues (1839)

html/ops/team_export.php (1 issue)

1
#!/usr/bin/env php
2
3
<?php
4
// This file is part of BOINC.
5
// http://boinc.berkeley.edu
6
// Copyright (C) 2008 University of California
7
//
8
// BOINC is free software; you can redistribute it and/or modify it
9
// under the terms of the GNU Lesser General Public License
10
// as published by the Free Software Foundation,
11
// either version 3 of the License, or (at your option) any later version.
12
//
13
// BOINC is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
// See the GNU Lesser General Public License for more details.
17
//
18
// You should have received a copy of the GNU Lesser General Public License
19
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
20
21
// This script for use ONLY by the BOINC-teams project.
22
// It generates an XML file with team and user info
23
24
$cli_only = true;
25
require_once("../inc/util_ops.inc");
26
27
function escape2($strin) {
28
    $strout = null;
29
30
    for ($i = 0; $i < strlen($strin); $i++) {
0 ignored issues
show
Coding Style Performance introduced by
The use of strlen() inside a loop condition is not allowed; assign the return value to a variable and use the variable in the loop condition instead
Loading history...
31
        $ord = ord($strin[$i]);
32
33
        if (($ord > 0 && $ord < 32) || ($ord >= 127)) {
34
            $strout .= "&amp;#{$ord};";
35
        } else {
36
            switch ($strin[$i]) {
37
            case '<': $strout .= '&lt;'; break;
38
            case '>': $strout .= '&gt;'; break;
39
            case '&': $strout .= '&amp;'; break;
40
            case '"': $strout .= '&quot;'; break;
41
            default: $strout .= $strin[$i]; }
42
        }
43
    }
44
    return $strout;
45
}
46
47
function escape($strin) {
48
    $dom = new DOMDocument('1.0');
49
    $element = $dom->createElement('Element');
50
    $element->appendChild(
51
        $dom->createTextNode($strin)
52
    );
53
54
    $dom->appendChild($element);
55
    $x = $dom->saveXml();
56
    $x = substr($x, 31);
57
    $x = substr($x, 0, -11);
58
    return $x;
59
}
60
61
function handle_team($team, $f) {
62
    echo "Team: $team->name\n";
63
    $user = BoincUser::lookup_id($team->userid);
64
    if (!$user) {
65
        echo "no user for team $team->id\n";
66
        return;
67
    }
68
    if ($user->teamid != $team->id) {
69
        echo "Founder is not member of $team->name\n";
70
        return;
71
    }
72
    if (!$user->email_validated) {
73
        echo "the founder of $team->name, $user->email_addr, is not validated\n";
74
        return;
75
    }
76
    $user_email_munged = str_rot13($user->email_addr);
77
    fwrite($f,
78
"<team>
79
   <name>".escape($team->name)."</name>
80
   <url>".escape($team->url)."</url>
81
   <type>$team->type</type>
82
   <name_html>".escape($team->name_html)."</name_html>
83
   <description>
84
".escape($team->description)."
85
    </description>
86
   <country>$team->country</country>
87
   <id>$team->id</id>
88
   <user_email_munged>$user_email_munged</user_email_munged>
89
   <user_name>".escape($user->name)."</user_name>
90
   <user_country>".escape($user->country)."</user_country>
91
   <user_postal_code>".escape($user->postal_code)."</user_postal_code>
92
   <user_url>".escape($user->url)."</user_url>
93
</team>
94
"
95
    );
96
}
97
98
function main() {
99
    echo "------------ Starting at ".time_str(time())."-------\n";
100
    $f = fopen("temp.xml", "w");
101
    $teams = BoincTeam::enum(null);
102
    fwrite($f, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<teams>\n");
103
    foreach($teams as $team) {
104
        handle_team($team, $f);
105
    }
106
    fwrite($f, "</teams>\n");
107
    fclose($f);
108
    if (!rename("temp.xml", "/home/boincadm/boinc-site/boinc_teams.xml")) {
109
        echo "Rename failed\n";
110
    }
111
    echo "------------ Finished at ".time_str(time())."-------\n";
112
}
113
114
main();
115
116
?>
117