\n"; echo "
Click your browser's Back button to try again.\n
\n";
page_tail();
exit();
}
// 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)) {
echo "ERROR: $filename does not exist! Cannot create combo box.
Your profile lets you share your opinions and background
with the ".PROJECT." community.
";
}
function show_questions($profile) {
$response1 = "";
$response2 = "";
if (isset($profile->response1)) {
$response1 = stripslashes($profile->response1);
}
if (isset($profile->response2)) {
$response2 = stripslashes($profile->response2);
}
row1(show_profile_heading1());
rowify(show_profile_question1().html_info());
rowify("
To replace it,
click the \"Browse\" button and select a JPEG or PNG file (50KB or less).
To remove it from your profile, check this box:
");
rowify("
Select the language in which your profile is written:
";
if (isset($profile->language)) {
show_combo_box("language", LANGUAGE_FILE, $profile->language);
} else {
show_combo_box("language", LANGUAGE_FILE, "English");
}
echo " ");
}
// If the user with id = $userid has uploaded a picture his/herself,
// delete it and its thumbnail.
//
function delete_user_pictures($userid) {
$filename1 = IMAGE_PATH . $userid . '.jpg';
$filename2 = IMAGE_PATH . $userid . '_sm.jpg';
if (file_exists($filename1)) {
unlink($filename1);
}
if (file_exists($filename2)) {
unlink($filename2);
}
}
// $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) {
$response1 = $_POST['response1'];
$response2 = $_POST['response2'];
$language = $_POST['language'];
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'])
) {
profile_error_page("Your profile submission was empty.");
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 "
Your profile was successfully entered into our database. ");
}
$profile = get_profile($userid);
if (!$profile) {
profile_error_page("No user profile exists for that user ID.");
}
if (!$verify_mode) {
$logged_in_user = get_logged_in_user(false);
if (!$logged_in_user || ($user->id != $logged_in_user->id)) {
$caching = true;
$cache_args = "userid=$userid";
start_cache(USER_PROFILE_TTL,$cache_args);
}
}
$can_edit = isset($logged_in_user) && $logged_in_user && $user->id == $logged_in_user->id;
if (!$verify_mode) {
page_head("Profile: ".$user->name);
}
start_table();
if ($can_edit) {
row1("Edit your profile");
}
// If doing screening, only show picture in certain situations
//
$show_picture = $profile->has_picture;
if (profile_screening()) {
if (!$verify_mode && !$can_edit && $profile->verification!=1) {
$show_picture = false;
}
}
if ($show_picture) {
echo "
";
exit();
}
echo "\n";
fclose($file);
}
function get_profile($userid) {
$result = mysql_query("SELECT * FROM profile WHERE userid = $userid");
if (!$result) {
return NULL;
}
$profile = mysql_fetch_object($result);
mysql_free_result($result);
return $profile;
}
function show_profile_creation_page($user) {
// If the user already has a profile,
// fill in the fields with their current values.
//
$profile = get_profile($user->id);
if (post_str("submit", true)) {
$config = get_config();
$privatekey = parse_config($config, "
".
"(reCAPTCHA said: " . $resp->error . ")");
}
}
process_create_profile($user, $profile);
exit();
}
if ($profile) {
page_head("Edit your profile");
} else {
page_head("Create a profile");
}
echo "
";
page_tail();
}
function show_description() {
echo "
");
show_textarea("response1", $response1);
rowify("
");
row1( show_profile_heading2());
rowify( show_profile_question2().html_info());
rowify("
");
show_textarea("response2", $response2);
rowify("
");
show_language_selection($profile);
rowify("
");
}
function show_textarea($name, $text) {
rowify("");
}
// 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 "
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.
";
} else if ($verify_flag == -1) {
return "
Your profile has been marked as unacceptable.
It is not visible to other people. Please change it.
";
}
return "";
}
function show_picture_option($profile) {
row1("Picture");
$warning = "";
if (profile_screening() && $profile->has_picture) {
$warning = offensive_profile_warning($profile->verification);
}
if (($profile) && ($profile->has_picture)) {
echo "
userid . '.jpg' . "\">userid . '_sm.jpg' . "\">
$warning Your profile picture is shown at left.
";
rowify("
");
end_table();
echo "";
} else {
rowify("
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 50KB or less.
");
}
}
function show_language_selection($profile) {
row1("Language");
echo " \n";
}
function show_submit() {
row1("Submit profile");
echo ""; // White looks better :)
$config = get_config();
$publickey = parse_config($config, "
\n".
recaptcha_get_html($publickey));
}
table_row("
Name: " . $_FILES['picture']['name'];
// echo "
Type: " . $_FILES['picture']['type'];
// echo "
Size: " . $_FILES['picture']['size'];
// echo "
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 = 'UPDATE profile SET '
." response1 = '".mysql_escape_string($response1)."',"
." response2 = '".mysql_escape_string($response2)."',"
." language = '".mysql_escape_string($language)."',"
." has_picture = '$hasPicture',"
." verification = '$profile->verification'"
." WHERE userid = '$user->id'";
$result = mysql_query($query);
if (!$result) {
echo mysql_error();
profile_error_page("Couldn't update profile: database error");
}
} else {
$query = 'INSERT INTO profile SET '
." userid = '$user->id',"
." language = '".mysql_escape_string($language)."',"
." response1 = '".mysql_escape_string($response1)."',"
." response2 = '".mysql_escape_string($response2)."',"
." has_picture = '$hasPicture',"
." verification=0";
$result = mysql_query($query);
if (!$result) {
profile_error_page("Couldn't create profile: database error");
}
mysql_query("update user set has_profile=1 where id=$user->id");
}
show_result_page($user);
}
// 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:
profile_error_page("The format of your uploaded image is not supported by our system.");
}
$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 "
Image type: $size[2]";
echo "
Original width: $width";
echo "
Original height: $height";
echo "
Scalar: $scalar";
echo "
Dest width: " . ($width / $scalar);
echo "
Dest height: " . ($height / $scalar);
echo "
Horizontal offset: $horiz_offset";
echo "
Vertical offset: $vert_offset";
echo "
View result";
*/
return array($image, $smallImage);
}
function scale_image(
$image, $origWidth, $origHeight, $targetWidth, $targetHeight
) {
// If the image is already smaller than the target dimensions,
// just return it.
//
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;
}
$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
);
}
return $newImage;
}
function show_result_page($user) {
page_head("Profile Saved");
echo "
Congratulations!
id>View your profile
";
page_tail();
}
// Builds a summary table of user profiles.
//
// $members is an array of userIDs;
// $offset indicates which entry to begin the table with
// $numToDisplay indicates how many profiles to display in this table
// $cols indicates how many profile summaries should be written per row
// $descriptor is an optional file descriptor to write the table to.
function show_user_table($members, $offset, $numToDisplay, $cols) {
echo "
";
}
// If the user is viewing their own picture, display its status if it's not
// 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.
//
if (profile_screening() && $profile->has_picture && $can_edit && $profile->verification!=1) {
row1(offensive_profile_warning($profile->verification));
}
show_user_summary_public($user);
// Setup text output options based on logged in user forum settings
//
if (!$verify_mode) {
$logged_in_user = get_logged_in_user(false);
$logged_in_user = getForumPreferences($logged_in_user);
$options = get_transform_settings_from_user($logged_in_user);
}
row1(show_profile_heading1());
row1(output_transform($profile->response1,$options), 2, "foobar");
row1(show_profile_heading2());
row1(output_transform($profile->response2,$options), 2, "foobar");
if (!$can_edit and !$verify_mode) {
row1("Your feedback on this profile");
row2(
"Recommend this profile for User of the Day:",
"I like this profile"
);
row2(
"Alert administrators to an offensive profile:",
"I don't like this profile"
);
}
end_table();
if (!$verify_mode) {
page_tail();
} else {
echo "
id.".jpg\">
";
}
if (isset($caching) && $caching) end_cache(USER_PROFILE_TTL,$cache_args);
}
?>