~ubuntu-branches/debian/sid/boinc/sid

« back to all changes in this revision

Viewing changes to html/inc/util.inc

  • Committer: Package Import Robot
  • Author(s): Steffen Moeller
  • Date: 2011-08-08 01:36:51 UTC
  • mfrom: (6.1.11 experimental)
  • Revision ID: package-import@ubuntu.com-20110808013651-m1hs3cltiveuteyn
Tags: 6.13.1+dfsg-2
* Bringing notify patch to unstable.
* Adjusted build dependency to libjpeg-dev (Closes: #641093)
* Further improvements on stripchart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
require_once("../inc/translation.inc");
25
25
require_once("../inc/profile.inc");
26
26
 
 
27
// don't allow /... at the end of URL
 
28
 
 
29
if (array_key_exists("PATH_INFO", $_SERVER)) {
 
30
    die("bad URL");
 
31
}
 
32
 
27
33
ini_set("memory_limit", "64M");
28
34
 
29
35
date_default_timezone_set("UTC");
34
40
 
35
41
$generating_xml = false;
36
42
$caching = false;
 
43
$did_page_head = false;
37
44
 
38
45
function send_cookie($name, $value, $permanent, $ops=false) {
39
46
    // the following allows independent login for projects on the same server
66
73
}
67
74
 
68
75
$g_logged_in_user = null;
 
76
$got_logged_in_user = false;
69
77
 
70
78
function get_logged_in_user($must_be_logged_in=true) {
71
 
    global $g_logged_in_user;
72
 
    if ($g_logged_in_user) return $g_logged_in_user;
 
79
    global $g_logged_in_user, $got_logged_in_user;;
 
80
    if ($got_logged_in_user) return $g_logged_in_user;
73
81
 
74
82
    check_web_stopped();
75
83
 
81
89
        $g_logged_in_user = BoincUser::lookup("authenticator='$authenticator'");
82
90
    }
83
91
    if ($must_be_logged_in && !$g_logged_in_user) {
84
 
        $next_url = $_SERVER['REQUEST_URI'];
85
 
        $n = strrpos($next_url, "/");
86
 
        if ($n) {
87
 
            $next_url = substr($next_url, $n+1);
 
92
        $next_url = '';
 
93
        if (array_key_exists('REQUEST_URI', $_SERVER)) {
 
94
            $next_url = $_SERVER['REQUEST_URI'];
 
95
            $n = strrpos($next_url, "/");
 
96
            if ($n) {
 
97
                $next_url = substr($next_url, $n+1);
 
98
            }
88
99
        }
 
100
        $next_url = urlencode($next_url);
89
101
        Header("Location: login_form.php?next_url=$next_url");
 
102
        exit;
90
103
    }
91
104
    return $g_logged_in_user;
92
105
}
93
106
 
94
 
function show_login($user) {
 
107
function show_login_info($prefix="") {
 
108
    $user = get_logged_in_user(false);
 
109
    echo "
 
110
        <table width=100% cellpadding=0 cellspacing=0>
 
111
        <td align=right>
 
112
    ";
95
113
    if ($user) {
96
 
        echo tra("Logged in as %1.", $user->name)."\n";
97
 
        echo "<br><a href=\"login_form.php\">".tra("Log in as someone else.")."</a>\n";
 
114
        $url_tokens = url_tokens($user->authenticator);
 
115
        echo "$user->name | <a href=".$prefix."logout.php?$url_tokens>".tra("log out")."</a>";
98
116
    } else {
99
 
        echo tra("Not logged in.");
 
117
        echo "<a href=".$prefix."login_form.php>".tra("log in")."</a>";
100
118
    }
 
119
    echo "
 
120
        </td>
 
121
        </tr>
 
122
        </table>
 
123
    ";
101
124
}
102
125
 
103
126
$cache_control_extra="";
110
133
function page_head(
111
134
    $title, $java_onload=null, $title_plain=null, $prefix="", $head_extra=null
112
135
) {
113
 
    global $caching;
114
 
    global $cache_control_extra;
 
136
    global $caching, $cache_control_extra, $did_page_head;
115
137
 
 
138
        $did_page_head = true;
116
139
    $stylesheet = URL_BASE.STYLESHEET;
117
140
    $rssname = PROJECT . " RSS 2.0";
118
141
    $rsslink = URL_BASE."rss_main.php";
119
 
    
 
142
 
120
143
    header("Content-type: text/html; charset=utf-8");
121
144
    if (!$caching) {
122
145
        header ("Expires: Mon, 26 Jul 1997 05:00:00 UTC");    // Date in the past
124
147
        header ("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0");  // HTTP/1.1
125
148
        header ("Pragma: no-cache");                          // HTTP/1.0
126
149
    }
127
 
    
 
150
 
128
151
    echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
129
 
 
130
152
    
131
153
    if (!$title_plain) {
132
154
        echo "<html><head><title>".strip_tags($title)."</title>\n";
133
155
    } else {
134
156
        echo "<html><head><title>".strip_tags($title_plain)."</title>\n";
135
157
    }
136
 
    echo "<link rel=stylesheet type=\"text/css\" href=\"main.css\" media=\"all\" />
137
 
                <link rel=stylesheet type=\"text/css\" href=\"$stylesheet\">
 
158
    echo "<link rel=stylesheet type=\"text/css\" href=\"".URL_BASE."main.css\" media=\"all\" />
 
159
        <link rel=stylesheet type=\"text/css\" href=\"$stylesheet\">
138
160
        <link rel=alternate type=\"application/rss+xml\" title=\"$rssname\" href=\"$rsslink\">
139
161
        $head_extra
140
162
        </head>
145
167
        echo "<body>";
146
168
    }
147
169
    display_cvs_versions();
 
170
 
148
171
    project_banner($title, $prefix);
 
172
    switch($title) {    //kludge
 
173
    case tra("Log in"):
 
174
    case tra("Create an account"):
 
175
    case tra("Server status page"):
 
176
        break;
 
177
    default:
 
178
        show_login_info($prefix);
 
179
    }
 
180
 
149
181
}
150
182
}
151
183
 
226
258
 
227
259
function time_str($x) {
228
260
    if ($x == 0) return "---";
229
 
    return gmdate('j M Y G:i:s', $x) . " UTC";
 
261
    return gmdate('j M Y | G:i:s', $x) . " UTC";
230
262
}
231
263
 
232
264
function pretty_time_str($x) {
439
471
        }
440
472
        $title = tra("View the profile of %1", $user->name);
441
473
        $alt = tra("Profile");
442
 
        $x .= ' <a href="'.URL_BASE.'view_profile.php?userid='.$user->id.'"><img class="userimg" title="'.$title.'" src="'.$img_url.'" alt="'.$alt.'"></a><br>';
 
474
        $x .= ' <a href="'.URL_BASE.'view_profile.php?userid='.$user->id.'"><img title="'.$title.'" src="'.$img_url.'" alt="'.$alt.'"></a><br>';
443
475
    }
444
476
    $x .= " <a href=\"".URL_BASE."show_user.php?userid=".$user->id."\">".$user->name."</a>";
445
 
    if ($user->donated == 1) { 
 
477
    if ($user->donated == 1) {
446
478
        require_once("../project/donations.inc");
447
479
        $x .= DONATION_LINK;
448
480
    }
458
490
    $x = "";
459
491
    if ($user->has_profile) {
460
492
        $img_url = URL_BASE."img/head_20.png";
461
 
        $x .= ' <a href="'.URL_BASE.'view_profile.php?userid='.$user->id.'"><img class="userimg" title="View the profile of '.$user->name.'" src="'.$img_url.'" alt="Profile"></a>';
 
493
        $x .= ' <a href="'.URL_BASE.'view_profile.php?userid='.$user->id.'"><img title="View the profile of '.$user->name.'" src="'.$img_url.'" alt="Profile"></a>';
462
494
    }
463
495
    $x .= " <a href=\"".URL_BASE."show_user.php?userid=".$user->id."\">".$user->name."</a>";
464
 
    if ($user->donated == 1) { 
 
496
    if ($user->donated == 1) {
465
497
        require_once("../project/donations.inc");
466
498
        $x .= DONATION_LINK;
467
499
    }
504
536
    return $x;
505
537
}
506
538
 
 
539
// check for bogus GET args
 
540
//
 
541
function check_get_args($args) {
 
542
    foreach ($_GET as $key => $val) {
 
543
        if (!in_array($key, $args)) {
 
544
            Header("Location: extra_arg_$key.html");
 
545
            die;
 
546
        }
 
547
    }
 
548
}
 
549
 
507
550
function get_int($name, $optional=false) {
508
551
    $x=null;
509
552
    if (isset($_GET[$name])) $x = $_GET[$name];
510
553
    if (!is_numeric($x)) {
511
554
        if ($optional) {
 
555
            if ($x) {
 
556
                Header("Location: non_num_arg.html");
 
557
                die;
 
558
            }
512
559
            return null;
513
560
        } else {
514
 
            error_page("missing or bad parameter: $name; supplied: ".htmlspecialchars($x));
 
561
            Header("Location: missing_arg_$name.html");
 
562
            die;
515
563
        }
516
564
    }
517
565
    return (int)$x;
542
590
    return undo_magic_quotes($x);
543
591
}
544
592
 
545
 
function get_venue($name) {
546
 
    $x = $_GET[$name];
547
 
    if ($x == "") return $x;
548
 
    if ($x == "home") return $x;
549
 
    if ($x == "work") return $x;
550
 
    if ($x == "school") return $x;
551
 
    error_page("no such venue: $x");
552
 
}
553
 
 
554
593
function post_str($name, $optional=false) {
555
594
    $x = null;
556
595
    if (isset($_POST[$name])) $x = $_POST[$name];
620
659
    return $out;
621
660
}
622
661
 
623
 
// Convert to entities, while preserving already-encoded entities. 
 
662
// Convert to entities, while preserving already-encoded entities.
624
663
// Do NOT use if $str contains valid HTML tags.
625
664
//
626
 
function boinc_htmlentities($str) { 
627
 
    $str = html_entity_decode($str, ENT_COMPAT, "UTF-8"); 
628
 
    $str = htmlentities($str, ENT_COMPAT, "UTF-8"); 
629
 
    return $str; 
630
 
 
665
function boinc_htmlentities($str) {
 
666
    $str = html_entity_decode($str, ENT_COMPAT, "UTF-8");
 
667
    $str = htmlentities($str, ENT_COMPAT, "UTF-8");
 
668
    return $str;
 
669
}
631
670
 
632
671
function strip_bbcode($string){
633
672
    return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/","",$string);
656
695
// @param text The text to display on the button
657
696
// @param desc The title of the destination - typically used as a popup
658
697
// @param class The optional CSS class of the button. Defaults to a standard button
659
 
// 
 
698
//
660
699
function show_button($url, $text, $desc, $class="button") {
661
 
    echo "<a href=\"".$url."\" title=\"".addslashes($desc)."\" class=\"".$class."\">".$text."</a>";
 
700
    echo "<a href=\"".$url."\" title=\"".addslashes($desc)."\" class=\"".$class."\">".$text."</a>\n";
662
701
}
663
702
 
664
703
// When multiple buttons (or actions) are presented in a list you can
683
722
}
684
723
 
685
724
function check_web_stopped() {
686
 
    global $generating_xml;
 
725
    global $generating_xml, $did_page_head;
687
726
    if (web_stopped()) {
688
727
        if ($generating_xml) {
689
728
            xml_error(-183);
690
729
        } else {
691
 
            page_head(tra("Project down for maintenance"));
692
 
            echo tra("This page requires database access.  Our database server is temporarily shut down for maintenance.  Please try again later.");
 
730
                        if (!$did_page_head) {
 
731
                                page_head(tra("Project down for maintenance"));
 
732
                        }
 
733
            echo tra(
 
734
                                "%1 is temporarily shut down for maintenance.  Please try again later.",
 
735
                                PROJECT
 
736
                        );
693
737
            page_tail();
694
738
            exit();
695
739
        }
780
824
}
781
825
 
782
826
 
783
 
$cvs_version_tracker[]="\$Id: util.inc 22445 2010-10-04 23:48:01Z davea $";  //Generated automatically - do not edit
 
827
$cvs_version_tracker[]="\$Id: util.inc 23624 2011-06-01 04:29:43Z boincadm $";  //Generated automatically - do not edit
784
828
 
785
829
?>