2004-02-02 23:34:39 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// 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/>.
2004-02-02 23:34:39 +00:00
2007-10-29 04:02:41 +00:00
require_once ( " ../inc/boinc_db.inc " );
2004-02-02 23:34:39 +00:00
require_once ( " ../inc/util.inc " );
require_once ( " ../inc/sanitize_html.inc " );
2004-07-22 23:42:50 +00:00
require_once ( " ../inc/cache.inc " );
2005-04-08 00:06:52 +00:00
require_once ( " ../inc/user.inc " );
2005-10-01 01:39:32 +00:00
require_once ( " ../inc/translation.inc " );
2005-10-14 00:05:41 +00:00
require_once ( " ../inc/text_transform.inc " );
2007-12-18 20:28:08 +00:00
require_once ( " ../inc/forum.inc " );
2007-10-25 10:43:16 +00:00
require_once ( " ../inc/recaptchalib.php " );
2004-02-02 23:34:39 +00:00
define ( 'SMALL_IMG_WIDTH' , 64 );
define ( 'SMALL_IMG_HEIGHT' , 64 );
2008-01-15 22:22:08 +00:00
define ( 'MAX_IMG_WIDTH' , 640 );
define ( 'MAX_IMG_HEIGHT' , 480 );
2004-02-02 23:34:39 +00:00
define ( 'MAX_DESC_LENGTH' , 90 );
define ( 'GALLERY_WIDTH' , 7 );
define ( 'GALLERY_HEIGHT' , 4 );
2005-09-26 20:01:01 +00:00
function profile_screening () {
2008-01-03 17:24:28 +00:00
static $val ;
if ( ! isset ( $val )) {
$config = get_config ();
$val = parse_bool ( $config , " profile_screening " );
}
return $val ;
2005-09-26 20:01:01 +00:00
}
2004-05-30 21:47:11 +00:00
function get_profile ( $userid ) {
2007-10-29 04:02:41 +00:00
return BoincProfile :: lookup ( " userid = $userid " );
2004-05-30 21:47:11 +00:00
}
2004-02-02 23:34:39 +00:00
2007-12-18 20:28:08 +00:00
// TODO: use the following functions instead of hardwired crap everywhere
2004-05-30 21:47:11 +00:00
2007-12-18 20:28:08 +00:00
function profile_image_path ( $userid ) {
return IMAGE_PATH . $userid . '.jpg' ;
2004-02-02 23:34:39 +00:00
}
2007-12-18 20:28:08 +00:00
function profile_thumb_path ( $userid ) {
return IMAGE_PATH . $userid . '_sm.jpg' ;
2004-02-02 23:34:39 +00:00
}
2007-12-18 20:28:08 +00:00
function profile_image_url ( $userid ) {
return URL_BASE . IMAGE_URL . $userid . '.jpg' ;
}
2007-10-25 10:43:16 +00:00
2007-12-18 20:28:08 +00:00
function profile_thumb_url ( $userid ) {
return URL_BASE . IMAGE_URL . $userid . '_sm.jpg' ;
2004-02-02 23:34:39 +00:00
}
2007-12-18 20:28:08 +00:00
function profile_user_thumb_url ( $user ) {
if ( ! $user -> has_profile ) return null ;
$profile = BoincProfile :: lookup ( " userid= $user->id " );
if ( ! $profile -> has_picture ) return null ;
if ( profile_screening () && $profile -> verification != 1 ) return null ;
return profile_thumb_url ( $user -> id );
2004-02-02 23:34:39 +00:00
}
2005-09-11 07:31:42 +00:00
// When passed profile->verification, this function is used to tell the
// user the verification status of their profile.
//
function offensive_profile_warning ( $verify_flag ) {
if ( $verify_flag == 0 ) {
return "
2007-10-26 22:07:39 +00:00
< font size = '+2' color = '#33cc33' >
2005-09-11 07:31:42 +00:00
Your profile will be made visible to other people < br >
as soon as it has been approved by the project .< br >
This may take up to a few days .< br >
2005-09-26 20:01:01 +00:00
</ font >
" ;
2005-09-11 07:31:42 +00:00
} else if ( $verify_flag == - 1 ) {
return "
2007-10-26 22:07:39 +00:00
< font size = '+2' color = '#ff3333' >
2005-09-11 07:31:42 +00:00
Your profile has been marked as unacceptable .< br >
It is not visible to other people . Please change it .< br >
2005-09-26 20:01:01 +00:00
</ font >
" ;
2005-09-11 07:31:42 +00:00
}
return " " ;
}
2004-02-02 23:34:39 +00:00
// If the user with id = $userid has uploaded a picture his/herself,
// delete it and its thumbnail.
//
function delete_user_pictures ( $userid ) {
2007-12-18 20:28:08 +00:00
$path = profile_image_path ( $userid );
if ( file_exists ( $path )) {
unlink ( $path );
2004-02-02 23:34:39 +00:00
}
2007-12-18 20:28:08 +00:00
$path = profile_thumb_path ( $userid );
if ( file_exists ( $path )) {
unlink ( $path );
2004-02-02 23:34:39 +00:00
}
}
2005-09-26 20:01:01 +00:00
function scale_image (
$image , $origWidth , $origHeight , $targetWidth , $targetHeight
) {
2004-02-02 23:34:39 +00:00
2005-09-26 20:01:01 +00:00
// If the image is already smaller than the target dimensions,
// just return it.
//
2004-02-02 23:34:39 +00:00
if ( $origWidth <= $targetWidth && $origHeight <= $targetHeight ) {
return $image ;
}
( $origWidth > $origHeight ) ? $scalar = ( $origWidth / $targetWidth ) : $scalar = ( $origHeight / $targetHeight );
if ( $scalar != 0 ) {
$destWidth = $origWidth / $scalar ;
$destHeight = $origHeight / $scalar ;
} else {
$destWidth = $origWidth ;
$destHeight = $origHeight ;
}
2005-09-26 20:01:01 +00:00
$gd_info = gd_info ();
$newGD = ( strstr ( $gd_info [ " GD Version " ], " 2.0 " ) != " " );
if ( $newGD ) {
// If you are using a modern PHP/GD installation that does
// 'truecolor' images, this is what's needed.
$newImage = ImageCreateTrueColor ( $destWidth , $destHeight );
ImageCopyResampled (
$newImage , $image , 0 , 0 , 0 , 0 , $destWidth ,
$destHeight , $origWidth , $origHeight
);
} else {
// If not, use this block.
// The image quality is lower but it works using older PHP/GD versions.
$newImage = ImageCreate ( $destWidth , $destHeight );
ImageCopyResized (
$newImage , $image , 0 , 0 , 0 , 0 , $destWidth , $destHeight ,
$origWidth , $origHeight
);
}
2004-02-02 23:34:39 +00:00
return $newImage ;
}
// Generates a string containing:
2005-09-26 20:01:01 +00:00
// 1) the name of the user with ID == $userid,
// with a link to a view of their profile
// 2) the first MAX_DESC_LENGTH characters from the response1 field
// of said user's profile.
2004-02-02 23:34:39 +00:00
function get_profile_summary ( $profile ) {
2004-05-30 21:47:11 +00:00
$user = get_user_from_id ( $profile -> userid );
2004-02-02 23:34:39 +00:00
2004-05-30 21:47:11 +00:00
if ( ! $user || ! $profile ) {
2004-02-02 23:34:39 +00:00
echo " Database error! " ; // Change this to a standard error page.
exit ();
}
$description = " " ;
2004-05-30 21:47:11 +00:00
if ( strlen ( $profile -> response1 ) != 0 ) {
$temp = $profile -> response1 ;
2004-02-02 23:34:39 +00:00
$description = " ( \" " . sub_sentence ( strip_tags ( $temp ), ' ' , MAX_DESC_LENGTH , true ) . " \" ) " ;
}
2007-11-18 22:42:47 +00:00
$summary = " <a href= \" " . URL_BASE . " view_profile.php?userid= " . $profile -> userid . " \" > " . $user -> name . " </a> " . $description ;
2004-02-02 23:34:39 +00:00
return $summary ;
}
2008-12-19 18:14:02 +00:00
function check_whether_to_show_profile ( $user , $logged_in_user ) {
$min_credit = parse_config ( get_config (), " <profile_min_credit> " );
if ( ! $logged_in_user && $min_credit && $user -> expavg_credit < $min_credit ) {
error_page (
" To prevent spam, profiles of users with an average credit of less than $min_credit are displayed only to logged-in users. We apologize for this inconvenience. "
);
}
if ( is_banished ( $user )) {
error_page ( " User is banished " );
}
}
2004-02-02 23:34:39 +00:00
// Displays a user's profile (if they have one);
2007-12-18 20:28:08 +00:00
// $screen_mode is set if we're in the administrative profile-screening page,
// in which case we show everything
2008-03-07 04:38:06 +00:00
// This assumes we're inside a table; it generates table rows
//
2008-01-01 22:29:10 +00:00
function show_profile ( $user , $logged_in_user , $screen_mode = false ) {
2007-12-02 21:11:17 +00:00
BoincForumPrefs :: lookup ( $user );
2008-10-28 21:59:25 +00:00
$profile = BoincProfile :: lookup ( " userid = $user->id " );
if ( ! $profile ) {
2008-12-19 18:14:02 +00:00
row1 ( " No profile exists for that user ID. " );
2008-10-28 21:59:25 +00:00
$user -> update ( " has_profile = 0 " );
2008-12-19 18:14:02 +00:00
return ;
2008-10-28 21:59:25 +00:00
}
2008-09-16 22:03:43 +00:00
2008-12-19 18:14:02 +00:00
$can_edit = $logged_in_user && $user -> id == $logged_in_user -> id ;
2004-02-02 23:34:39 +00:00
2005-01-18 19:56:18 +00:00
if ( $can_edit ) {
row1 ( " <a href=create_profile.php>Edit your profile</a> " );
2004-02-02 23:34:39 +00:00
}
2008-03-07 04:38:06 +00:00
2007-12-18 20:28:08 +00:00
// If screening is enabled, only show picture in certain situations
2005-09-11 07:31:42 +00:00
//
2005-09-26 20:01:01 +00:00
$show_picture = $profile -> has_picture ;
if ( profile_screening ()) {
2007-12-18 20:28:08 +00:00
if ( ! $screen_mode && ! $can_edit && $profile -> verification != 1 ) {
2005-09-26 20:01:01 +00:00
$show_picture = false ;
}
}
if ( $show_picture ) {
2005-01-18 19:56:18 +00:00
echo "
2007-07-05 19:37:33 +00:00
< tr >< td colspan = \ " 2 \" align= \" center \" >
2007-12-18 20:28:08 +00:00
< img vspace = \ " 6 \" hspace= \" 9 \" src= \" " . profile_image_url ( $user -> id ) . " \" >
2005-01-18 19:56:18 +00:00
</ td ></ tr >
" ;
2004-02-02 23:34:39 +00:00
}
2005-09-26 20:01:01 +00:00
// If the user is viewing their own picture, display its status if it's not
2005-09-11 07:31:42 +00:00
// yet verified. This will tell them if other users can't view it yet, or
// if there is a problem with it and they need to replace it.
//
2005-10-01 16:00:31 +00:00
if ( profile_screening () && $profile -> has_picture && $can_edit && $profile -> verification != 1 ) {
2005-09-26 20:01:01 +00:00
row1 ( offensive_profile_warning ( $profile -> verification ));
}
2005-09-11 07:31:42 +00:00
2007-09-12 12:13:33 +00:00
// Setup text output options based on logged in user forum settings
//
2008-03-07 04:38:06 +00:00
BoincForumPrefs :: lookup ( $logged_in_user );
$options = get_output_options ( $logged_in_user );
2005-01-18 19:56:18 +00:00
row1 ( show_profile_heading1 ());
2008-07-04 20:06:31 +00:00
row1 ( output_transform ( $profile -> response1 , $options ), 2 , " foobar " );
2005-01-18 19:56:18 +00:00
row1 ( show_profile_heading2 ());
2008-07-04 20:06:31 +00:00
row1 ( output_transform ( $profile -> response2 , $options ), 2 , " foobar " );
2005-08-30 09:41:47 +00:00
2007-12-18 20:28:08 +00:00
if ( ! $can_edit and ! $screen_mode ) {
2005-01-18 19:56:18 +00:00
row1 ( " Your feedback on this profile " );
row2 (
" Recommend this profile for User of the Day: " ,
2008-01-03 17:37:38 +00:00
" I <a href=profile_rate.php?userid= $user->id &vote=recommend>like</a> this profile "
2005-01-18 19:56:18 +00:00
);
row2 (
" Alert administrators to an offensive profile: " ,
2008-01-03 17:37:38 +00:00
" I <a href=profile_rate.php?userid= $user->id &vote=reject>don't like</a> this profile "
2005-01-18 19:56:18 +00:00
);
2004-02-02 23:34:39 +00:00
}
}
2007-11-14 16:03:47 +00:00
$cvs_version_tracker [] = " \$ Id $ " ; //Generated automatically - do not edit
2004-02-02 23:34:39 +00:00
?>