2003-07-11 22:33:59 +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/>.
2003-07-11 22:33:59 +00:00
2007-12-18 20:28:08 +00:00
// TODO: the following is organized in a funky way. Clean it up
2004-02-03 19:17:52 +00:00
require_once ( " ../inc/profile.inc " );
2008-07-04 20:06:31 +00:00
require_once ( " ../inc/akismet.inc " );
2003-07-11 22:33:59 +00:00
2007-12-18 20:28:08 +00:00
// output a select form item with the given name,
// from a list of newline-delineated items from the text file.
// If $selection is provided, and if it matches one of the entries in the file,
// it will be selected by default.
//
function show_combo_box ( $name , $filename , $selection = null ) {
if ( ! file_exists ( $filename )) {
2008-12-13 18:54:06 +00:00
error_page ( tra ( " ERROR: %1 does not exist! Cannot create combo box.<br> " , htmlentities ( $filename )));
2007-12-18 20:28:08 +00:00
}
echo " <select name= \" $name\ " > \n " ;
$file = fopen ( $filename , " r " );
while ( $line = trim ( fgets ( $file , 1024 ))) {
if ( $line == $selection ) {
echo " <option SELECTED value= \" $line\ " > $line\n " ;
} else {
echo " <option value= \" $line\ " > $line\n " ;
}
}
echo " </select> \n " ;
fclose ( $file );
}
function show_picture_option ( $profile ) {
2008-12-13 18:54:06 +00:00
row1 ( tra ( " Picture " ));
2007-12-18 20:28:08 +00:00
$warning = " " ;
if ( profile_screening () && $profile -> has_picture ) {
$warning = offensive_profile_warning ( $profile -> verification );
}
if (( $profile ) && ( $profile -> has_picture )) {
echo "
< tr >< td colspan = 2 >
< table border = 0 cellpadding = 5
< tr >
< td valign = top >< a href = \ " " . IMAGE_URL . $profile -> userid . '.jpg' . " \" ><img src= \" " . IMAGE_URL . $profile -> userid . '_sm.jpg' . " \" ></a>
</ td >
2008-12-13 18:54:06 +00:00
< td valign = top > " .tra( " % 1 Your profile picture is shown to the left . " , $warning ) . "
< p > " .
tra ( " To replace it, click the \" Browse \" button and select a JPEG or PNG file (%1 or less). " , " 50KB " ) . " <br />
2007-12-18 20:28:08 +00:00
< input name = picture type = file >< br >
2008-12-13 18:54:06 +00:00
< p > " .
tra ( " To remove it from your profile, check this box: " ) . "
2007-12-18 20:28:08 +00:00
< input type = checkbox name = delete_pic >
< p >
</ td ></ tr > " ;
rowify ( " <br> " );
end_table ();
echo " </td></tr> " ;
} else {
2008-12-13 18:54:06 +00:00
rowify ( tra ( " If you would like include a picture with your profile, click the \" Browse \" button and select a JPEG or PNG file. Please select images of %1 or less. " , " 50KB " ) . "
2007-12-18 20:28:08 +00:00
< p >
< input name = picture type = file >
" );
rowify ( " <br> " );
}
}
function show_language_selection ( $profile ) {
2008-12-13 18:54:06 +00:00
row1 ( tra ( " Language " ));
2007-12-18 20:28:08 +00:00
echo " <tr><td>
2008-12-13 18:54:06 +00:00
< p > " .
tra ( " Select the language in which your profile is written: " ) . "
2007-12-18 20:28:08 +00:00
< p >
" ;
if ( isset ( $profile -> language )) {
show_combo_box ( " language " , LANGUAGE_FILE , $profile -> language );
} else {
show_combo_box ( " language " , LANGUAGE_FILE , " English " );
}
echo " </td></tr> \n " ;
}
function show_submit () {
2008-12-13 18:54:06 +00:00
row1 ( tra ( " Submit profile " ));
2008-01-15 22:22:08 +00:00
echo " <script>var RecaptchaOptions = { theme : 'white' };</script> " ;
2007-12-18 20:28:08 +00:00
$config = get_config ();
$publickey = parse_config ( $config , " <recaptcha_public_key> " );
if ( $publickey ) {
2008-12-13 18:54:06 +00:00
table_row ( tra ( " To protect the project's webpages from spam, we kindly ask you to type in the two words shown in the image:<br> \n " ) .
2007-12-18 20:28:08 +00:00
recaptcha_get_html ( $publickey ));
}
2008-12-13 18:54:06 +00:00
table_row ( " <p><input type= \" submit \" value= \" " . tra ( " Create/edit profile " ) . " \" name= \" submit \" > " );
2007-12-18 20:28:08 +00:00
}
// Returns an array containing:
// [0]: The original image refered to by $fileName if its dimensions are
// less than MAX_IMG_WIDTH x MAX_IMG_HEIGHT, or a version scaled to
// those dimensions if it was too large.
// [1]: A scaled version of the above.
function getImages ( $fileName ) {
$size = getImageSize ( $fileName );
// Determine if the filetype uploaded is supported.
// TODO: Change these to constants.
switch ( $size [ 2 ]) {
case '2' : // JPEG
$image = imageCreateFromJPEG ( $fileName );
break ;
case '3' : // PNG
$image = imageCreateFromPNG ( $fileName );
break ;
default :
2008-12-13 18:54:06 +00:00
error_page ( tra ( " The format of your uploaded image is not supported. " ));
2007-12-18 20:28:08 +00:00
}
$width = $size [ 0 ];
$height = $size [ 1 ];
$smallImage = scale_image ( $image , $width , $height , SMALL_IMG_WIDTH , SMALL_IMG_HEIGHT );
if ( $width > MAX_IMG_WIDTH || $height > MAX_IMG_HEIGHT ) {
$image = scale_image ( $image , $width , $height , MAX_IMG_WIDTH , MAX_IMG_HEIGHT );
}
/*
echo " <br><br>Image type: $size[2] " ;
echo " <br>Original width: $width " ;
echo " <br>Original height: $height " ;
echo " <br>Scalar: $scalar " ;
echo " <br>Dest width: " . ( $width / $scalar );
echo " <br>Dest height: " . ( $height / $scalar );
echo " <br>Horizontal offset: $horiz_offset " ;
echo " <br>Vertical offset: $vert_offset " ;
echo " <br><br><a href= \" images/user_profile/test.jpg \" >View result</a> " ;
*/
return array ( $image , $smallImage );
}
function show_description () {
echo "
2008-12-13 18:54:06 +00:00
< p > " .tra( " Your % 1 profile % 2 lets you share your opinions and background with the % 3 community . " , " < b > " , " </ b > " , PROJECT) . "
2007-12-18 20:28:08 +00:00
< p >
" ;
}
function show_questions ( $profile ) {
$response1 = " " ;
$response2 = " " ;
if ( isset ( $profile -> response1 )) {
2008-06-05 20:32:21 +00:00
$response1 = $profile -> response1 ;
2007-12-18 20:28:08 +00:00
}
if ( isset ( $profile -> response2 )) {
2008-06-05 20:32:21 +00:00
$response2 = $profile -> response2 ;
2007-12-18 20:28:08 +00:00
}
row1 ( show_profile_heading1 ());
rowify ( show_profile_question1 () . html_info ());
show_textarea ( " response1 " , $response1 );
row1 ( show_profile_heading2 ());
rowify ( show_profile_question2 () . html_info ());
show_textarea ( " response2 " , $response2 );
show_language_selection ( $profile );
}
function show_textarea ( $name , $text ) {
rowify ( " <textarea name= \" $name\ " cols = 80 rows = 20 > " . $text . " </ textarea > " );
}
// $profile is null if user doesn't already have a profile.
// Don't assign to $profile->x if this is the case.
//
function process_create_profile ( $user , $profile ) {
2008-12-13 18:54:06 +00:00
global $config ;
2008-07-30 02:16:10 +00:00
$response1 = post_str ( 'response1' , true );
$response2 = post_str ( 'response2' , true );
2008-06-12 15:28:06 +00:00
$language = post_str ( 'language' );
2008-07-04 20:06:31 +00:00
2008-10-09 18:28:55 +00:00
$privatekey = parse_config ( $config , " <recaptcha_private_key> " );
if ( $privatekey ) {
$resp = recaptcha_check_answer ( $privatekey , $_SERVER [ " REMOTE_ADDR " ],
$_POST [ " recaptcha_challenge_field " ], $_POST [ " recaptcha_response_field " ]
);
if ( ! $resp -> is_valid ) {
2008-10-13 03:19:34 +00:00
$profile -> response1 = $response1 ;
$profile -> response2 = $response2 ;
2008-10-09 18:28:55 +00:00
show_profile_form ( $profile ,
2008-12-13 18:54:06 +00:00
tra ( " Your ReCaptcha response was not correct. Please try again. " )
2008-10-09 18:28:55 +00:00
);
return ;
}
}
if ( ! akismet_check ( $user , $response1 )) {
2008-10-13 03:19:34 +00:00
$profile -> response1 = $response1 ;
$profile -> response2 = $response2 ;
2008-10-09 18:28:55 +00:00
show_profile_form ( $profile ,
2008-12-13 18:54:06 +00:00
tra ( " Your first response was flagged as spam by the Akismet anti-spam system. Please modify your text and try again. " )
2008-10-09 18:28:55 +00:00
);
return ;
}
if ( ! akismet_check ( $user , $response2 )) {
2008-10-13 03:19:34 +00:00
$profile -> response1 = $response1 ;
$profile -> response2 = $response2 ;
2008-10-09 18:28:55 +00:00
show_profile_form ( $profile ,
2008-12-13 18:54:06 +00:00
tra ( " Your second response was flagged as spam by the Akismet anti-spam system. Please modify your text and try again. " )
2008-10-09 18:28:55 +00:00
);
return ;
}
2008-07-04 20:06:31 +00:00
2007-12-18 20:28:08 +00:00
if ( isset ( $_POST [ 'delete_pic' ])) {
$delete_pic = $_POST [ 'delete_pic' ];
} else {
$delete_pic = " off " ;
}
if ( strlen ( $response1 ) == 0 &&
strlen ( $response2 ) == 0 &&
$delete_pic != " on " &&
! is_uploaded_file ( $_FILES [ 'picture' ][ 'tmp_name' ])
) {
2008-12-13 18:54:06 +00:00
error_page ( tra ( " Your profile submission was empty. " ));
2007-12-18 20:28:08 +00:00
exit ();
}
if ( $delete_pic == " on " ) {
delete_user_pictures ( $profile -> userid );
$profile -> has_picture = false ;
$profile -> verification = 0 ;
}
$profile ? $hasPicture = $profile -> has_picture : $hasPicture = false ;
if ( is_uploaded_file ( $_FILES [ 'picture' ][ 'tmp_name' ])) {
$hasPicture = true ;
if ( $profile ) $profile -> verification = 0 ;
// echo "<br>Name: " . $_FILES['picture']['name'];
// echo "<br>Type: " . $_FILES['picture']['type'];
// echo "<br>Size: " . $_FILES['picture']['size'];
// echo "<br>Temp name: " . $_FILES['picture']['tmp_name'];
$images = getImages ( $_FILES [ 'picture' ][ 'tmp_name' ]);
// Write the original image file to disk.
// TODO: define a constant for image quality.
ImageJPEG ( $images [ 0 ], IMAGE_PATH . $user -> id . '.jpg' );
ImageJPEG ( $images [ 1 ], IMAGE_PATH . $user -> id . '_sm.jpg' );
}
$response1 = sanitize_html ( $response1 );
$response2 = sanitize_html ( $response2 );
if ( $profile ) {
$query = " response1 = ' " . boinc_real_escape_string ( $response1 ) . " ', "
. " response2 = ' " . boinc_real_escape_string ( $response2 ) . " ', "
. " language = ' " . boinc_real_escape_string ( $language ) . " ', "
. " has_picture = ' $hasPicture ', "
. " verification = ' $profile->verification ' "
. " WHERE userid = ' $user->id ' " ;
$result = BoincProfile :: update_aux ( $query );
if ( ! $result ) {
2008-12-13 18:54:06 +00:00
error_page ( tra ( " Could not update the profile: database error " ));
2007-12-18 20:28:08 +00:00
}
} else {
$query = 'SET '
. " userid = ' $user->id ', "
. " language = ' " . boinc_real_escape_string ( $language ) . " ', "
. " response1 = ' " . boinc_real_escape_string ( $response1 ) . " ', "
. " response2 = ' " . boinc_real_escape_string ( $response2 ) . " ', "
. " has_picture = ' $hasPicture ', "
. " verification=0 " ;
$result = BoincProfile :: insert ( $query );
if ( ! $result ) {
2008-12-13 18:54:06 +00:00
error_page ( tra ( " Could not create the profile: database error " ));
2007-12-18 20:28:08 +00:00
}
$user -> update ( " has_profile=1 " );
}
2008-12-13 18:54:06 +00:00
page_head ( tra ( " Profile saved " ));
2007-12-18 20:28:08 +00:00
2008-12-13 18:54:06 +00:00
echo tra ( " Congratulations! Your profile was successfully entered into our database. " ) .
" <br><br> " . tra ( " %1View your profile%2 " , " <a href= \" view_profile.php?userid= " . $user -> id . " \" > " , " </a><br> " );
2007-12-18 20:28:08 +00:00
page_tail ();
}
2008-10-09 18:28:55 +00:00
function show_profile_form ( $profile , $warning = null ) {
2007-12-18 20:28:08 +00:00
if ( $profile ) {
2008-12-13 18:54:06 +00:00
page_head ( tra ( " Edit your profile " ));
2007-12-18 20:28:08 +00:00
} else {
2008-12-13 18:54:06 +00:00
page_head ( tra ( " Create a profile " ));
2007-12-18 20:28:08 +00:00
}
2008-10-09 18:28:55 +00:00
if ( $warning ) {
echo " <span class=error> $warning </span><p>
" ;
}
2007-12-18 20:28:08 +00:00
echo "
< form action = " , $_SERVER['PHP_SELF'] , " method = \ " POST \" , ENCTYPE= \" multipart/form-data \" >
" ;
start_table_noborder ();
show_description ();
show_questions ( $profile );
show_picture_option ( $profile );
show_submit ();
end_table ();
echo " </form> " ;
page_tail ();
2008-10-09 18:28:55 +00:00
2007-12-18 20:28:08 +00:00
}
2003-07-11 22:33:59 +00:00
$user = get_logged_in_user ( true );
2008-10-09 18:28:55 +00:00
$profile = get_profile ( $user -> id );
$config = get_config ();
$min_credit = parse_config ( $config , " <profile_min_credit> " );
if ( $min_credit && $user -> expavg_credit < $min_credit ) {
error_page (
2008-12-13 18:54:06 +00:00
tra ( " To prevent spam, an average credit of %1 or greater is required to create or edit a profile. We apologize for this inconvenience. " , $min_credit )
2008-10-09 18:28:55 +00:00
);
}
if ( post_str ( " submit " , true )) {
process_create_profile ( $user , $profile );
exit ;
}
show_profile_form ( $profile );
2003-07-11 22:33:59 +00:00
2003-07-15 22:29:39 +00:00
?>