-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.inc
281 lines (258 loc) · 9.01 KB
/
user.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/email.inc");
require_once("../inc/util.inc");
require_once("../inc/forum.inc");
require_once("../inc/friend.inc");
require_once("../inc/forum_db.inc");
require_once("../inc/notify.inc");
function total_posts($user) {
return BoincPost::count("user=$user->id");
}
function weak_auth($user) {
$x = md5($user->authenticator.$user->passwd_hash);
return "{$user->id}_$x";
}
// originally user URLs were assumed to be http://,
// and this prefix wasn't stored.
// Now the prefix can be http:// or https://.
// This function takes a user URL in any form and converts
// it to a canonical form, with the protocol prefix.
//
function normalize_user_url($url) {
$x = strtolower($url);
if (substr($x, 0, 7) == 'http://') {
return 'http://'.substr($url, 7);
}
if (substr($x, 0, 8) == 'https://') {
return 'https://'.substr($url, 8);
}
return 'http://'.$url;
}
// show static user info (private)
//
function show_user_info_private($user) {
row2(tra("Name"), $user->name);
if (LDAP_HOST && is_ldap_email($user->email_addr)) {
row2("LDAP ID", ldap_email_to_uid($user->email_addr));
} else {
$email_text = $user->email_addr;
if (defined("SHOW_NONVALIDATED_EMAIL_ADDR") && !$user->email_validated) {
$email_text .= " (<a href=validate_email_addr.php>must be validated</a>)";
}
row2(tra("Email address"), $email_text);
}
if (USER_URL) {
if (strlen($user->url)) {
$u = normalize_user_url($user->url);
row2(tra("URL"), sprintf('<a href="%s">%s</a>', $u, $u));
}
}
if (USER_COUNTRY) {
row2(tra("Country"), $user->country);
}
if (POSTAL_CODE) {
row2(tra("Postal code"), $user->postal_code);
}
row2(tra("%1 member since", PROJECT), date_str($user->create_time));
$url_tokens = url_tokens($user->authenticator);
if (LDAP_HOST && is_ldap_email($user->email_addr)) {
// LDAP accounts can't change email or password
//
row2(tra("Change"),
"<a href=\"edit_user_info_form.php?$url_tokens\">Account info</a>"
);
} else {
$delete_account_str = "";
$config = get_config();
if (parse_bool($config, "enable_delete_account")) {
$delete_account_str = " · <a href=\"delete_account_request.php\">".tra("delete account")."</a>";
}
row2(tra("Change"),
"<a href=\"edit_email_form.php\">".tra("email address")."</a>
· <a href=\"".secure_url_base()."/edit_passwd_form.php\">".tra("password")."</a>
· <a href=\"edit_user_info_form.php?$url_tokens\">".tra("other account info")."</a>"
.$delete_account_str
);
}
row2(tra("User ID")."<br/><p class=\"small\">".tra("Used in community functions")."</p>", $user->id);
if (!NO_COMPUTING) {
row2(
tra("Account keys"),
"<a href=\"weak_auth.php\">".tra("View")."</a>"
);
require_once("../inc/account_ownership.inc");
if (file_exists($account_ownership_private_key_file_path)) {
// If the server has keys configured show the account ownership form
row2(
tra("Account Ownership"),
"<a href=\"account_ownership.php?$url_tokens\">Generate ownership proof</a>"
);
}
}
}
// show user name, with links to profile if present.
// if $badge_height is > 0, show badges
// if $name_limit, limit name to N chars
//
function user_links($user, $badge_height=0, $name_limit=0) {
BoincForumPrefs::lookup($user);
if (is_banished($user)) {
return "(banished: ID $user->id)";
}
$x = "";
if ($user->has_profile) {
$img_url = url_base()."img/head_20.png";
$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>';
}
$name = $user->name;
if ($name_limit && strlen($name) > $name_limit) {
$name = substr($name, 0, $name_limit)."...";
}
$x .= " <a href=\"".url_base()."user.php?user_id=".$user->id."\">".$name."</a>";
if (function_exists("project_user_links")){
$x .= project_user_links($user);
}
if ($badge_height) {
$x .= badges_string(true, $user, $badge_height);
}
return $name_limit?"<nobr>$x</nobr>":$x;
}
// 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));
if (USER_COUNTRY) {
row2(tra("Country"), $user->country);
}
if (USER_URL) {
// don't show URL if user has no recent credit (spam suppression)
//
if (strlen($user->url)) {
if (!NO_COMPUTING || $user->expavg_credit > 1) {
$u = normalize_user_url($user->url);
row2(tra("URL"), sprintf('<a href="%s">%s</a>', $u, $u));
}
}
}
if (!NO_COMPUTING) {
show_credit($user);
if ($user->show_hosts) {
row2(tra("Computers"), "<a href=\"".url_base()."hosts_user.php?userid=$user->id\">".tra("View")."</a>");
} else {
row2(tra("Computers"), tra("hidden"));
}
}
if (function_exists("project_user_summary_public")) {
project_user_summary_public($user);
}
}
function user_link($user) {
return sprintf("<a href=user.php?user_id=%d>%s</a>", $user->id, $user->name);
}
function community_links($user, $logged_in_user){
$following = BoincFriend::enum("user_src=$user->id");
$followers = BoincFriend::enum("user_dest=$user->id");
$tot = total_posts($user);
if ($tot) {
row2(tra("Message boards"), "<a href=\"".url_base()."forum_user_posts.php?userid=$user->id\">".tra("%1 posts", $tot)."</a>");
}
if ($logged_in_user->id != $user->id) {
row2("Contact",
mm_button_text(
"pm.php?action=new&userid=$user->id",
"Send private message",
BUTTON_SMALL
)
);
}
$x = [];
$found = false;
foreach ($followers as $f) {
if ($f->user_src == $logged_in_user->id) {
$found = true;
} else {
$u = BoincUser::lookup_id($f->user_src);
if (!$u) continue;
$x[] = user_link($u);
}
}
if (!$x) $x[] = '---';
if ($found) {
$x[] = sprintf("You are following %s. %s",
$user->name,
mm_button_text(
"follow.php?action=unfollow&user_id=$user->id",
"Unfollow", BUTTON_SMALL
)
);
} else if ($user->id != $logged_in_user->id) {
$x[] = mm_button_text(
"follow.php?action=follow&user_id=$user->id",
"Follow $user->name",
BUTTON_SMALL
);
}
row2("Followers", implode('<br>', $x));
$x = [];
foreach ($following as $f) {
$u = BoincUser::lookup_id($f->user_dest);
if (!$u) continue;
$x[] = user_link($u);
}
if ($x) {
row2("$user->name is following", implode('<br>', $x));
}
}
function show_profile_link($user) {
if ($user->has_profile) {
row2(tra("Profile"), "<a href=\"view_profile.php?userid=$user->id\">".tra("View")."</a>");
}
}
function show_account_private($user) {
grid(
false,
function() use ($user) {
start_table();
row1(tra("Account information"), 2, 'heading');
show_user_info_private($user);
show_preference_links();
show_user_stats_private($user);
if (function_exists('show_user_donations_private')) {
show_user_donations_private($user);
}
end_table();
if (!NO_COMPUTING) {
show_other_projects($user, true);
}
if (function_exists("project_user_page_private")) {
project_user_page_private($user);
}
},
function() use ($user) {
start_table();
row1(tra("Community"));
show_community_private($user);
end_table();
}
);
}
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?>