Issues (1839)

html/inc/profile.inc (1 issue)

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
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
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
    $newGD = (strstr($gd_info["GD Version"], "2.0")!="");
140
    if ($newGD) {
141
        // If you are using a modern PHP/GD installation that does
142
        // 'truecolor' images, this is what's needed.
143
        $newImage = ImageCreateTrueColor($destWidth, $destHeight);
144
        ImageCopyResampled(
145
            $newImage, $image, 0, 0, 0, 0, $destWidth,
146
            $destHeight, $origWidth, $origHeight
147
        );
148
    } else {
149
        // If not, use this block.
150
        // The image quality is lower but it works using older PHP/GD versions.
151
        $newImage = ImageCreate($destWidth, $destHeight);
152
        ImageCopyResized(
153
            $newImage, $image, 0, 0, 0, 0, $destWidth, $destHeight,
154
            $origWidth, $origHeight
155
        );
156
    }
157
158
    return $newImage;
159
}
160
161
// Generates a string containing:
162
//   1) the name of the user with ID == $userid,
163
//      with a link to a view of their profile
164
//   2) the first MAX_DESC_LENGTH characters from the response1 field
165
//      of said user's profile.
166
167
function get_profile_summary($profile) {
168
    $user = BoincUser::lookup_id($profile->userid);
169
170
    if (!$user || !$profile) {
171
        error_page(tra("Database error"));
172
        exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
173
    }
174
175
    $description = "";
176
177
    if (strlen($profile->response1) != 0) {
178
        $options = new output_options();
179
        $options->htmlitems = false;
180
        $temp = output_transform($profile->response1, $options);
181
        $temp = sanitize_tags($temp);
182
        $description = "(\"" . sub_sentence($temp, ' ', MAX_DESC_LENGTH, true) . "\")";
183
184
    }
185
186
    $summary = "<a href=\"".url_base()."view_profile.php?userid=".$profile->userid."\">".$user->name."</a> ".$description;
187
    return $summary;
188
}
189
190
function check_whether_to_show_profile($user, $logged_in_user) {
191
    $min_credit = parse_config(get_config(), "<profile_min_credit>");
192
    if (!$logged_in_user && $min_credit && $user->expavg_credit < $min_credit ) {
193
        error_page(
194
           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)
195
        );
196
    }
197
    if (is_banished($user)) {
198
        error_page(tra("User is banished"));
199
    }
200
201
}
202
203
// Displays a user's profile (if they have one);
204
// $screen_mode is set if we're in the administrative profile-screening page,
205
// in which case we show everything
206
// This assumes we're inside a table; it generates table rows
207
//
208
function show_profile($user, $logged_in_user, $screen_mode = false) {
209
    BoincForumPrefs::lookup($user);
210
    $profile = BoincProfile::lookup("userid = $user->id");
211
    if (!$profile) {
212
        row1(tra("No profile exists for that user ID."));
213
        $user->update("has_profile = 0");
214
        return;
215
    }
216
217
    $can_edit = $logged_in_user && $user->id == $logged_in_user->id;
218
219
    if ($can_edit) {
220
        echo "<tr><td>";
221
        show_button("create_profile.php", tra("Edit your profile"));
222
        echo "</td></tr>
223
        ";
224
    }
225
226
    // If screening is enabled, only show picture in certain situations
227
    //
228
    $show_picture = $profile->has_picture;
229
    if (profile_screening()) {
230
        if (!$screen_mode && !$can_edit && $profile->verification!=1) {
231
            $show_picture = false;
232
        }
233
    }
234
    if ($show_picture) {
235
        echo "
236
            <tr><td colspan=\"2\" align=\"center\">
237
            <img vspace=\"6\" hspace=\"9\" src=\"".profile_image_url($user->id)."\">
238
            </td></tr>
239
        ";
240
    }
241
242
    // If the user is viewing their own picture, display its status if it's not
243
    // yet verified.  This will tell them if other users can't view it yet, or
244
    // if there is a problem with it and they need to replace it.
245
    //
246
    if (profile_screening() && $profile->has_picture && $can_edit && $profile->verification!=1) {
247
        row1(offensive_profile_warning($profile->verification));
248
    }
249
250
    // Setup text output options based on logged in user forum settings
251
    //
252
    BoincForumPrefs::lookup($logged_in_user);
253
    $options = get_output_options($logged_in_user);
254
    $options->htmlitems = false;
255
256
    if (!empty($profile->response1)) {
257
        row1(show_profile_heading1());
258
        row1(output_transform($profile->response1, $options), 2, "foobar");
259
    }
260
261
    if (!empty($profile->response2)) {
262
        row1(show_profile_heading2());
263
        row1(output_transform($profile->response2, $options), 2, "foobar");
264
    }
265
266
    if (!$can_edit and !$screen_mode) {
267
        row1(tra("Your feedback on this profile"));
268
        row2(
269
            tra("Recommend this profile for User of the Day:"),
270
            tra("I %1 like %2 this profile", "<a href=\"profile_rate.php?userid=".$user->id."&vote=recommend\">", "</a>")
271
        );
272
        row2(
273
            tra("Alert administrators to an offensive profile:"),
274
            tra("I %1 do not like %2 this profile", "<a href=\"profile_rate.php?userid=".$user->id."&vote=reject\">", "</a>")
275
        );
276
    }
277
}
278
279
$cvs_version_tracker[]="\$Id$";  //Generated automatically - do not edit
280
281
?>
282