true, "image/pjpeg" => true, "image/gif" => true, "image/png" => true, "image/x-png" => true ); bb_register_activation_hook(__FILE__, 'userphoto_activation'); load_plugin_textdomain('user-photo'); function userphoto_activation() { bb_update_option("userphoto_jpeg_compression", USERPHOTO_JPEG_COMPRESSION); bb_update_option("userphoto_maximum_dimension", USERPHOTO_FULL_SIZE); bb_update_option("userphoto_thumb_dimension", USERPHOTO_THUMBNAIL_SIZE); } bb_register_deactivation_hook(__FILE__, 'userphoto_deactivation'); function userphoto_deactivation() { bb_delete_option("userphoto_jpeg_compression"); bb_delete_option("userphoto_maximum_dimension"); bb_delete_option("userphoto_thumb_dimension"); } function userphoto_profile_update($userID){ global $userphoto_validtypes, $errors; $current_user = bb_current_user(); $userdata = bb_get_user($userID); #Delete photo if (@$_POST['userphoto_delete']) { if ($userdata->userphoto_image_file) { $imagepath = USERPHOTO_PATH . basename($userdata->userphoto_image_file); if(file_exists($imagepath) && !@unlink($imagepath)) $errors->add('userphoto_error', __("Unable to delete photo.", 'user-photo')); else { bb_delete_usermeta($userID, "userphoto_image_file"); // bb_delete_usermeta($userID, "userphoto_image_width"); // bb_delete_usermeta($userID, "userphoto_image_height"); } } if ($userdata->userphoto_thumb_file) { $thumbpath = USERPHOTO_PATH . basename($userdata->userphoto_thumb_file); if (file_exists($thumbpath) && !@unlink($thumbpath)) $errors->add('userphoto_error', __("Unable to delete photo thumbnail.", 'user-photo')); else { bb_delete_usermeta($userID, "userphoto_thumb_file"); // bb_delete_usermeta($userID, "userphoto_thumb_width"); // bb_delete_usermeta($userID, "userphoto_thumb_height"); } } } #Upload photo or change approval status else { #Upload the file if(isset($_FILES['userphoto_image_file']) && @$_FILES['userphoto_image_file']['name']){ #Upload error $error = ''; if($_FILES['userphoto_image_file']['error']){ switch($_FILES['userphoto_image_file']['error']){ case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $error = __("The uploaded file exceeds the max upload size.", 'user-photo'); break; case UPLOAD_ERR_PARTIAL: $error = __("The uploaded file was only partially uploaded.", 'user-photo'); break; case UPLOAD_ERR_NO_FILE: $error = __("No file was uploaded.", 'user-photo'); break; case UPLOAD_ERR_NO_TMP_DIR: $error = __("Missing a temporary folder.", 'user-photo'); break; case UPLOAD_ERR_CANT_WRITE: $error = __("Failed to write file to disk.", 'user-photo'); break; case UPLOAD_ERR_EXTENSION: $error = __("File upload stopped by extension.", 'user-photo'); break; default: $error = __("File upload failed due to unknown error.", 'user-photo'); } } else if(!$_FILES['userphoto_image_file']['size']) $error = sprintf(__("The file “%s” was not uploaded. Did you provide the correct filename?", 'user-photo'), $_FILES['userphoto_image_file']['name']); else if(@!$userphoto_validtypes[$_FILES['userphoto_image_file']['type']]) //!preg_match("/\.(" . join('|', $userphoto_validextensions) . ")$/i", $_FILES['userphoto_image_file']['name'])) || $error = sprintf(__("The uploaded file type “%s” is not allowed.", 'user-photo'), $_FILES['userphoto_image_file']['type']); $tmppath = $_FILES['userphoto_image_file']['tmp_name']; $imageinfo = null; $thumbinfo = null; if (!$error) { $userphoto_maximum_dimension = bb_get_option( 'userphoto_maximum_dimension' ); $imageinfo = getimagesize($tmppath); if (!$imageinfo || !$imageinfo[0] || !$imageinfo[1]) $error = __("Unable to get image dimensions.", 'user-photo'); else if ($imageinfo[0] > $userphoto_maximum_dimension || $imageinfo[1] > $userphoto_maximum_dimension){ if (userphoto_resize_image($tmppath, null, $userphoto_maximum_dimension, $error)) $imageinfo = getimagesize($tmppath); } } if (!$error) { $dir = USERPHOTO_PATH; if (!file_exists($dir) && !mkdir($dir, 0777)) $error = __("The userphoto upload content directory does not exist and could not be created. Please ensure that you have write permissions for the /wp-content/uploads/ directory.", 'user-photo'); if (!$error) { $imagefile = preg_replace('/^.+(?=\.\w+$)/', $userdata->user_nicename, $_FILES['userphoto_image_file']['name']); $imagepath = $dir . '/' . $imagefile; $thumbfile = preg_replace("/(?=\.\w+$)/", '.thumbnail', $imagefile); $thumbpath = $dir . '/' . $thumbfile; if(!move_uploaded_file($tmppath, $imagepath)) $error = __("Unable to move the file to the user photo upload content directory.", 'user-photo'); else { chmod($imagepath, 0666); $userphoto_thumb_dimension = bb_get_option( 'userphoto_thumb_dimension' ); if (!($userphoto_thumb_dimension >= $imageinfo[0] && $userphoto_thumb_dimension >= $imageinfo[1])) userphoto_resize_image($imagepath, $thumbpath, $userphoto_thumb_dimension, $error); else { copy($imagepath, $thumbpath); chmod($thumbpath, 0666); } $thumbinfo = getimagesize($thumbpath); #Update usermeta bb_update_usermeta($userID, "userphoto_image_file", $imagefile); //bb_update_usermeta($userID, "userphoto_image_width", $imageinfo[0]); //bb_update_usermeta($userID, "userphoto_image_height", $imageinfo[1]); bb_update_usermeta($userID, "userphoto_thumb_file", $thumbfile); //bb_update_usermeta($userID, "userphoto_thumb_width", $thumbinfo[0]); //bb_update_usermeta($userID, "userphoto_thumb_height", $thumbinfo[1]); #if($oldFile && $oldFile != $newFile) # @unlink($dir . '/' . $oldFile); } } } } } if ($error) bb_update_usermeta($userID, 'userphoto_error', $error); else bb_delete_usermeta($userID, "userphoto_error"); } add_action('bb_delete_user', 'userphoto_delete_user'); function userphoto_delete_user($userID){ $userdata = bb_get_user($userID); if($userdata->userphoto_image_file) @unlink(USERPHOTO_PATH . basename($userdata->userphoto_image_file)); if($userdata->userphoto_thumb_file) @unlink(USERPHOTO_PATH . basename($userdata->userphoto_thumb_file)); } function userphoto_display_selector_fieldset($userID){ global $userphoto_error; $current_user = bb_current_user(); $profileuser = bb_get_user($userID); $isSelf = ($profileuser->ID == $current_user->ID); if ($isSelf && !bb_current_user_can('write_posts')) return; ?>
$info[1] ) { $image_width = $info[0]; $image_height = $info[1]; $image_new_width = $maxdimension; $image_ratio = $image_width / $image_new_width; $image_new_height = $image_height / $image_ratio; //width is > height } else { $image_width = $info[0]; $image_height = $info[1]; $image_new_height = $maxdimension; $image_ratio = $image_height / $image_new_height; $image_new_width = $image_width / $image_ratio; //height > width } $imageresized = imagecreatetruecolor( $image_new_width, $image_new_height); @ imagecopyresampled( $imageresized, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $info[0], $info[1] ); // move the thumbnail to its final destination if ( $info[2] == IMAGETYPE_GIF ) { if (!imagegif( $imageresized, $newFilename ) ) $error = __( "Thumbnail path invalid", 'user-photo'); } elseif ( $info[2] == IMAGETYPE_JPEG ) { if (!imagejpeg( $imageresized, $newFilename, $userphoto_jpeg_compression ) ) $error = __( "Thumbnail path invalid", 'user-photo'); } elseif ( $info[2] == IMAGETYPE_PNG ) { if (!imagepng( $imageresized, $newFilename ) ) $error = __( "Thumbnail path invalid", 'user-photo'); } } if(!empty($error)) return false; return true; } /// Avatar/Photo display if (USE_GRAVATARS_IF_NO_PHOTO): /// This is the original function. We'll use the original if no photo was found. function original_bb_get_avatar( $id_or_email, $size = 80, $default = '' ) { if ( !bb_get_option('avatars_show') ) return false; if ( !is_numeric($size) ) $size = 80; if ( $email = bb_get_user_email($id_or_email) ) { $class = 'photo '; } else { $class = ''; $email = $id_or_email; } if ( !$email ) $email = ''; if ( empty($default) ) $default = bb_get_option('avatars_default'); switch ($default) { case 'logo': $default = ''; break; case 'monsterid': case 'wavatar': case 'identicon': break; case 'default': default: $default = 'http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com') break; break; } $src = 'http://www.gravatar.com/avatar/'; $class .= 'avatar avatar-' . $size; if ( !empty($email) ) { $src .= md5( strtolower( $email ) ); } else { $src .= 'd41d8cd98f00b204e9800998ecf8427e'; // d41d8cd98f00b204e9800998ecf8427e == md5('') $class .= ' avatar-noemail'; } $src .= '?s=' . $size; $src .= '&d=' . urlencode( $default ); $rating = bb_get_option('avatars_rating'); if ( !empty( $rating ) ) $src .= '&r=' . $rating; $avatar = '