1 | <?php |
|||||||||||
2 | // This file is part of BOINC. |
|||||||||||
3 | // http://boinc.berkeley.edu |
|||||||||||
4 | // Copyright (C) 2008 University of California |
|||||||||||
5 | // |
|||||||||||
6 | // BOINC is free software; you can redistribute it and/or modify it |
|||||||||||
7 | // under the terms of the GNU Lesser General Public License |
|||||||||||
8 | // as published by the Free Software Foundation, |
|||||||||||
9 | // either version 3 of the License, or (at your option) any later version. |
|||||||||||
10 | // |
|||||||||||
11 | // BOINC is distributed in the hope that it will be useful, |
|||||||||||
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||||||||||
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|||||||||||
14 | // See the GNU Lesser General Public License for more details. |
|||||||||||
15 | // |
|||||||||||
16 | // You should have received a copy of the GNU Lesser General Public License |
|||||||||||
17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
|||||||||||
18 | ||||||||||||
19 | require_once("../inc/boinc_db.inc"); |
|||||||||||
20 | require_once("../inc/util.inc"); |
|||||||||||
21 | require_once("../inc/sanitize_html.inc"); |
|||||||||||
22 | require_once("../inc/cache.inc"); |
|||||||||||
23 | require_once("../inc/user.inc"); |
|||||||||||
24 | require_once("../inc/translation.inc"); |
|||||||||||
25 | require_once("../inc/text_transform.inc"); |
|||||||||||
26 | require_once("../inc/forum.inc"); |
|||||||||||
27 | ||||||||||||
28 | define('SMALL_IMG_WIDTH', 64); |
|||||||||||
29 | define('SMALL_IMG_HEIGHT', 64); |
|||||||||||
30 | ||||||||||||
31 | define('MAX_IMG_WIDTH', 640); |
|||||||||||
32 | define('MAX_IMG_HEIGHT', 480); |
|||||||||||
33 | ||||||||||||
34 | define('MAX_DESC_LENGTH', 90); |
|||||||||||
35 | ||||||||||||
36 | define('GALLERY_WIDTH', 7); |
|||||||||||
37 | define('GALLERY_HEIGHT', 4); |
|||||||||||
38 | ||||||||||||
39 | function profile_screening() { |
|||||||||||
40 | static $val; |
|||||||||||
41 | if (!isset($val)) { |
|||||||||||
42 | $config = get_config(); |
|||||||||||
43 | $val = parse_bool($config, "profile_screening"); |
|||||||||||
44 | } |
|||||||||||
45 | return $val; |
|||||||||||
46 | } |
|||||||||||
47 | ||||||||||||
48 | function get_profile($userid) { |
|||||||||||
49 | return BoincProfile::lookup("userid = $userid"); |
|||||||||||
50 | } |
|||||||||||
51 | ||||||||||||
52 | // TODO: use the following functions instead of hardwired crap everywhere |
|||||||||||
0 ignored issues
–
show
Coding Style
Best Practice
introduced
by
![]() |
||||||||||||
53 | ||||||||||||
54 | function profile_image_path($userid) { |
|||||||||||
55 | return IMAGE_PATH.$userid.'.jpg'; |
|||||||||||
56 | } |
|||||||||||
57 | ||||||||||||
58 | function profile_thumb_path($userid) { |
|||||||||||
59 | return IMAGE_PATH.$userid.'_sm.jpg'; |
|||||||||||
60 | } |
|||||||||||
61 | ||||||||||||
62 | function profile_image_url($userid) { |
|||||||||||
63 | return url_base().IMAGE_URL.$userid.'.jpg'; |
|||||||||||
64 | } |
|||||||||||
65 | ||||||||||||
66 | function profile_thumb_url($userid) { |
|||||||||||
67 | return url_base().IMAGE_URL.$userid.'_sm.jpg'; |
|||||||||||
68 | } |
|||||||||||
69 | ||||||||||||
70 | function profile_user_thumb_url($user) { |
|||||||||||
71 | if (!$user->has_profile) return null; |
|||||||||||
72 | $profile = BoincProfile::lookup("userid=$user->id"); |
|||||||||||
73 | if (!$profile->has_picture) return null; |
|||||||||||
74 | if (profile_screening() && $profile->verification!=1) return null; |
|||||||||||
75 | return profile_thumb_url($user->id); |
|||||||||||
76 | } |
|||||||||||
77 | ||||||||||||
78 | // When passed profile->verification, this function is used to tell the |
|||||||||||
79 | // user the verification status of their profile. |
|||||||||||
80 | // |
|||||||||||
81 | function offensive_profile_warning($verify_flag) { |
|||||||||||
82 | if ($verify_flag == 0) { |
|||||||||||
83 | return " |
|||||||||||
84 | <font size='+2' color='#3c3'> |
|||||||||||
85 | ".tra("Your profile will be made visible to other people as soon as it has been approved by the project. This may take up to a few days.")." |
|||||||||||
86 | </font> |
|||||||||||
87 | "; |
|||||||||||
88 | } else if ($verify_flag == -1) { |
|||||||||||
89 | return " |
|||||||||||
90 | <font size='+2' color='#f33'> |
|||||||||||
91 | ".tra("Your profile has been marked as unacceptable. It is not visible to other people. Please change it.")." |
|||||||||||
92 | </font> |
|||||||||||
93 | "; |
|||||||||||
94 | } |
|||||||||||
95 | return ""; |
|||||||||||
96 | } |
|||||||||||
97 | ||||||||||||
98 | // If the user with id = $userid has uploaded a picture his/herself, |
|||||||||||
99 | // delete it and its thumbnail. |
|||||||||||
100 | // |
|||||||||||
101 | function delete_user_pictures($userid) { |
|||||||||||
102 | $path = profile_image_path($userid); |
|||||||||||
103 | if (file_exists($path)) { |
|||||||||||
104 | unlink($path); |
|||||||||||
105 | } |
|||||||||||
106 | $path = profile_thumb_path($userid); |
|||||||||||
107 | if (file_exists($path)) { |
|||||||||||
108 | unlink($path); |
|||||||||||
109 | } |
|||||||||||
110 | } |
|||||||||||
111 | ||||||||||||
112 | function delete_profile($user) { |
|||||||||||
113 | delete_user_pictures($user->id); |
|||||||||||
114 | return BoincProfile::delete_aux("userid=$user->id"); |
|||||||||||
115 | } |
|||||||||||
116 | ||||||||||||
117 | function scale_image( |
|||||||||||
118 | $image, $origWidth, $origHeight, $targetWidth, $targetHeight |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
119 | ) { |
|||||||||||
120 | ||||||||||||
121 | // If the image is already smaller than the target dimensions, |
|||||||||||
122 | // just return it. |
|||||||||||
123 | // |
|||||||||||
124 | if ($origWidth <= $targetWidth && $origHeight <= $targetHeight) { |
|||||||||||
125 | return $image; |
|||||||||||
126 | } |
|||||||||||
127 | ||||||||||||
128 | ($origWidth > $origHeight)? $scalar = ($origWidth / $targetWidth) : $scalar = ($origHeight / $targetHeight); |
|||||||||||
129 | ||||||||||||
130 | if ($scalar != 0) { |
|||||||||||
131 | $destWidth = $origWidth / $scalar; |
|||||||||||
132 | $destHeight = $origHeight / $scalar; |
|||||||||||
133 | } else { |
|||||||||||
134 | $destWidth = $origWidth; |
|||||||||||
135 | $destHeight = $origHeight; |
|||||||||||
136 | } |
|||||||||||
137 | ||||||||||||
138 | $gd_info = gd_info(); |
|||||||||||
139 | $v = $gd_info["GD Version"]; |
|||||||||||
140 | $v = explode('.', $v); |
|||||||||||
141 | $v = (int)$v[0]; // major version |
|||||||||||
142 | if ($v >= 2) { |
|||||||||||
143 | // If you are using a modern PHP/GD installation that does |
|||||||||||
144 | // 'truecolor' images, this is what's needed. |
|||||||||||
145 | $newImage = ImageCreateTrueColor($destWidth, $destHeight); |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
146 | ImageCopyResampled( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
147 | $newImage, $image, 0, 0, 0, 0, $destWidth, |
|||||||||||
148 | $destHeight, $origWidth, $origHeight |
|||||||||||
149 | ); |
|||||||||||
150 | } else { |
|||||||||||
151 | // If not, use this block. |
|||||||||||
152 | // The image quality is lower but it works using older PHP/GD versions. |
|||||||||||
153 | $newImage = ImageCreate($destWidth, $destHeight); |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
154 | ImageCopyResized( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
155 | $newImage, $image, 0, 0, 0, 0, $destWidth, $destHeight, |
|||||||||||
156 | $origWidth, $origHeight |
|||||||||||
157 | ); |
|||||||||||
158 | } |
|||||||||||
159 | ||||||||||||
160 | return $newImage; |
|||||||||||
161 | } |
|||||||||||
162 | ||||||||||||
163 | // Generates a string containing: |
|||||||||||
164 | // 1) the name of the user with ID == $userid, |
|||||||||||
165 | // with a link to a view of their profile |
|||||||||||
166 | // 2) the first MAX_DESC_LENGTH characters from the response1 field |
|||||||||||
167 | // of said user's profile. |
|||||||||||
168 | ||||||||||||
169 | function get_profile_summary($profile) { |
|||||||||||
170 | $user = BoincUser::lookup_id($profile->userid); |
|||||||||||
171 | ||||||||||||
172 | if (!$user || !$profile) { |
|||||||||||
173 | error_page(tra("Database error")); |
|||||||||||
174 | exit(); |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
175 | } |
|||||||||||
176 | ||||||||||||
177 | $description = ""; |
|||||||||||
178 | ||||||||||||
179 | if (strlen($profile->response1) != 0) { |
|||||||||||
180 | $options = new output_options(); |
|||||||||||
181 | $options->htmlitems = false; |
|||||||||||
182 | $temp = output_transform($profile->response1, $options); |
|||||||||||
183 | $temp = sanitize_tags($temp); |
|||||||||||
184 | $description = "(\"" . sub_sentence($temp, ' ', MAX_DESC_LENGTH, true) . "\")"; |
|||||||||||
185 | ||||||||||||
186 | } |
|||||||||||
187 | ||||||||||||
188 | $summary = "<a href=\"".url_base()."view_profile.php?userid=".$profile->userid."\">".$user->name."</a> ".$description; |
|||||||||||
189 | return $summary; |
|||||||||||
190 | } |
|||||||||||
191 | ||||||||||||
192 | function check_whether_to_show_profile($user, $logged_in_user) { |
|||||||||||
193 | $min_credit = parse_config(get_config(), "<profile_min_credit>"); |
|||||||||||
194 | if (!$logged_in_user && $min_credit && $user->expavg_credit < $min_credit ) { |
|||||||||||
195 | error_page( |
|||||||||||
196 | tra("To prevent spam, profiles of users with an average credit of less than %1 are displayed only to logged-in users. We apologize for this inconvenience.", $min_credit) |
|||||||||||
197 | ); |
|||||||||||
198 | } |
|||||||||||
199 | } |
|||||||||||
200 | ||||||||||||
201 | // Displays a user's profile (if they have one); |
|||||||||||
202 | // $screen_mode is set if we're in the administrative profile-screening page, |
|||||||||||
203 | // in which case we show everything |
|||||||||||
204 | // This assumes we're inside a table; it generates table rows |
|||||||||||
205 | // |
|||||||||||
206 | function show_profile($user, $logged_in_user, $screen_mode = false) { |
|||||||||||
207 | BoincForumPrefs::lookup($user); |
|||||||||||
208 | $profile = BoincProfile::lookup("userid = $user->id"); |
|||||||||||
209 | if (!$profile) { |
|||||||||||
210 | row1(tra("No profile exists for that user ID.")); |
|||||||||||
211 | $user->update("has_profile = 0"); |
|||||||||||
212 | return; |
|||||||||||
213 | } |
|||||||||||
214 | ||||||||||||
215 | $can_edit = $logged_in_user && $user->id == $logged_in_user->id; |
|||||||||||
216 | ||||||||||||
217 | if ($can_edit) { |
|||||||||||
218 | echo "<tr><td>"; |
|||||||||||
219 | show_button("create_profile.php", tra("Edit your profile")); |
|||||||||||
220 | echo "</td></tr> |
|||||||||||
221 | "; |
|||||||||||
222 | } |
|||||||||||
223 | ||||||||||||
224 | // If screening is enabled, only show picture in certain situations |
|||||||||||
225 | // |
|||||||||||
226 | $show_picture = $profile->has_picture; |
|||||||||||
227 | if (profile_screening()) { |
|||||||||||
228 | if (!$screen_mode && !$can_edit && $profile->verification!=1) { |
|||||||||||
229 | $show_picture = false; |
|||||||||||
230 | } |
|||||||||||
231 | } |
|||||||||||
232 | if ($show_picture) { |
|||||||||||
233 | echo " |
|||||||||||
234 | <tr><td colspan=\"2\" align=\"center\"> |
|||||||||||
235 | <img vspace=\"6\" hspace=\"9\" src=\"".profile_image_url($user->id)."\"> |
|||||||||||
236 | </td></tr> |
|||||||||||
237 | "; |
|||||||||||
238 | } |
|||||||||||
239 | ||||||||||||
240 | // If the user is viewing their own picture, display its status if it's not |
|||||||||||
241 | // yet verified. This will tell them if other users can't view it yet, or |
|||||||||||
242 | // if there is a problem with it and they need to replace it. |
|||||||||||
243 | // |
|||||||||||
244 | if (profile_screening() && $profile->has_picture && $can_edit && $profile->verification!=1) { |
|||||||||||
245 | row1(offensive_profile_warning($profile->verification)); |
|||||||||||
246 | } |
|||||||||||
247 | ||||||||||||
248 | // Setup text output options based on logged in user forum settings |
|||||||||||
249 | // |
|||||||||||
250 | BoincForumPrefs::lookup($logged_in_user); |
|||||||||||
251 | $options = get_output_options($logged_in_user); |
|||||||||||
252 | $options->htmlitems = false; |
|||||||||||
253 | ||||||||||||
254 | if (!empty($profile->response1)) { |
|||||||||||
255 | row1(show_profile_heading1()); |
|||||||||||
256 | row1(output_transform($profile->response1, $options), 2, "foobar"); |
|||||||||||
257 | } |
|||||||||||
258 | ||||||||||||
259 | if (!empty($profile->response2)) { |
|||||||||||
260 | row1(show_profile_heading2()); |
|||||||||||
261 | row1(output_transform($profile->response2, $options), 2, "foobar"); |
|||||||||||
262 | } |
|||||||||||
263 | ||||||||||||
264 | if (!$can_edit and !$screen_mode) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
265 | row1(tra("Your feedback on this profile")); |
|||||||||||
266 | row2( |
|||||||||||
267 | tra("Recommend this profile for User of the Day:"), |
|||||||||||
268 | tra("I %1 like %2 this profile", "<a href=\"profile_rate.php?userid=".$user->id."&vote=recommend\">", "</a>") |
|||||||||||
269 | ); |
|||||||||||
270 | row2( |
|||||||||||
271 | tra("Alert administrators to an offensive profile:"), |
|||||||||||
272 | tra("I %1 do not like %2 this profile", "<a href=\"profile_rate.php?userid=".$user->id."&vote=reject\">", "</a>") |
|||||||||||
273 | ); |
|||||||||||
274 | } |
|||||||||||
275 | } |
|||||||||||
276 | ||||||||||||
277 | ||||||||||||
278 | ?> |
|||||||||||
279 |