diff -N -a --unified -r mantisbt/account_page.php mantisbt-file_avatar/account_page.php --- mantisbt/account_page.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/account_page.php 2008-12-01 11:43:10.032455300 -0500 @@ -50,6 +50,9 @@ $t_core_path = config_get( 'core_path' ); require_once( $t_core_path.'current_user_api.php' ); + require_once( $t_core_path.'avatar_api.php' ); + + $t_use_gravatar = config_get( 'use_gravatar', false, auth_get_current_user_id(), ALL_PROJECTS ); #============ Parameters ============ # (none) @@ -94,7 +97,7 @@
-
+ @@ -209,6 +212,40 @@ + + > + + : + + + /> + + + > + + : + + + + + + + + + + > + + + (' . lang_get( 'max_file_size' ) . ': ' . number_format( $t_max_file_size/1000 ) . 'k)'?> + + + + name="avatar_file" type="file" size="60" /> + + + > diff -N -a --unified -r mantisbt/account_update.php mantisbt-file_avatar/account_update.php --- mantisbt/account_update.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/account_update.php 2008-12-01 11:44:17.262957600 -0500 @@ -32,6 +32,7 @@ $t_core_path = config_get( 'core_path' ); require_once( $t_core_path.'email_api.php' ); + require_once( $t_core_path.'avatar_api.php' ); form_security_validate('account_update'); @@ -43,6 +44,7 @@ $f_realname = gpc_get_string( 'realname', '' ); $f_password = gpc_get_string( 'password', '' ); $f_password_confirm = gpc_get_string( 'password_confirm', '' ); + $f_use_gravatar = gpc_get_bool( 'use_gravatar' ); $f_email = email_append_domain( $f_email ); @@ -57,6 +59,7 @@ $t_email_updated = false; $t_password_updated = false; $t_realname_updated = false; + $t_avatar_updated = false; # @@@ Listing what fields were updated is not standard behaviour of Mantis # it also complicates the code. @@ -88,6 +91,24 @@ } } + # avatar + $t_username = user_get_field( $t_user_id, 'username' ); + # store use_avatar in config + if( config_get('use_gravatar', false) != $f_use_gravatar ) + $t_avatar_updated = true; + + config_set('use_gravatar', $f_use_gravatar, $t_user_id, ALL_PROJECTS); + + $f_delete_avatar = gpc_get_string( 'delete_avatar', '' ); + if( is_blank( $f_delete_avatar ) ) { + if( isset( $_FILES['avatar_file'] ) && !is_blank($_FILES['avatar_file']['name']) ) { + avatar_upload( $t_username, $_FILES['avatar_file']['name'], $_FILES['avatar_file']['tmp_name'] ); + $t_avatar_updated = true; + } + } else { + avatar_delete( $t_username ); + } + form_security_purge('account_update'); html_page_top1(); @@ -107,6 +128,10 @@ if ( $t_realname_updated ) { echo lang_get( 'realname_updated' ) . '
'; } + + if ( $t_avatar_updated ) { + echo lang_get( 'avatar_updated' ) . '
'; + } echo lang_get( 'operation_successful' ) . '
'; print_bracket_link( $t_redirect, lang_get( 'proceed' ) ); diff -N -a --unified -r mantisbt/bugnote_view_inc.php mantisbt-file_avatar/bugnote_view_inc.php --- mantisbt/bugnote_view_inc.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/bugnote_view_inc.php 2008-12-01 11:45:55.851028600 -0500 @@ -30,6 +30,7 @@ * Requires bugnote API */ require_once( $t_core_path.'current_user_api.php' ); +require_once( $t_core_path.'avatar_api.php' ); # grab the user id currently logged in $t_user_id = auth_get_current_user_id(); @@ -113,7 +114,7 @@ ?> - reporter_id ); ?> + reporter_id ); ?> ()
reporter_id ); @@ -121,7 +122,11 @@ reporter_id ) ) { $t_access_level = access_get_project_level( null, (int)$t_bugnote->reporter_id ); - echo '(', get_enum_element( 'access_levels', $t_access_level ), ')'; + if( $t_access_level == ANYBODY ) { + echo '(no access)'; + } else { + echo '(', get_enum_element( 'access_levels', $t_access_level ), ')'; + } } ?> view_state ) { ?> diff -N -a --unified -r mantisbt/config_defaults_inc.php mantisbt-file_avatar/config_defaults_inc.php --- mantisbt/config_defaults_inc.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/config_defaults_inc.php 2008-12-01 12:00:05.739572200 -0500 @@ -635,8 +635,19 @@ # Only users above this threshold will have their avatar shown $g_show_avatar_threshold = DEVELOPER; - # Default avatar for users without a gravatar account - $g_default_avatar = "%path%images/no_avatar.png"; + # local directory to store avatar + $g_directory_avatar = 'avatar'; + + # Default avatar for users without a gravatar account + $g_default_avatar = "images/no_avatar.png"; + + $g_avatar_max_width = 96; + $g_avatar_max_height = 96; + + $g_max_avatar_file_size = 1048576; // 1 MB, will be resized anyway. + + # Show avatar in manage_user_list + $g_show_avatar_in_manage_user_list = OFF; # Show release dates on roadmap/changelog $g_show_changelog_dates = ON; diff -N -a --unified -r mantisbt/core/avatar_api.php mantisbt-file_avatar/core/avatar_api.php --- mantisbt/core/avatar_api.php 1969-12-31 19:00:00.000000000 -0500 +++ mantisbt-file_avatar/core/avatar_api.php 2008-12-01 12:02:45.355377800 -0500 @@ -0,0 +1,115 @@ +thumbnailImage( $g_avatar_max_width, 0 ); // 0 to keep aspect ratio. + $t_avatar_image->borderImage( new ImagickPixel("black"), 1, 1 ); + $t_avatar_image->setImageFormat("png"); + $t_avatar_image->writeImage( $target_file ); + } + else if( get_gd_version() != 0 ) + { + $ext = end(explode('.', $p_name)); + $t_image = gd_open_image($p_filename, '.' . $ext); + if( $t_image === false ) { + trigger_error( "Bad image file." ); + } + + // Get original width and height + $t_width = imagesx($t_image); + $t_height = imagesy($t_image); + + // New width and height + $t_new_width = $g_avatar_max_width; + $t_new_height = $g_avatar_max_height; + + // Resample + if( $t_width > $t_height ) { + $t_new_height = $t_height * ($t_new_width/$t_width); + } else { + $t_new_width = $t_width * ($t_new_height/$t_height); + } + + $image_resized = imagecreatetruecolor($t_new_width, $t_new_height); + imagecopyresampled($image_resized, $t_image, 0, 0, 0, 0, $t_new_width, $t_new_height, $t_width, $t_height); + + imagepng( $image_resized, $target_file ); + } else + move_uploaded_file($p_filename, $target_file); + } + + function avatar_delete( $p_username ) + { + $target_path = config_get('directory_avatar') . '/'; + + # delete avatar + $avatar_file = $target_path . '/' . $p_username . '.gif'; + $fh = fopen($avatar_file, 'w') or die("can't open file"); + fclose($fh); + + unlink($avatar_file); + + $avatar_file = $target_path . '/' . $p_username . '.jpg'; + $fh = fopen($avatar_file, 'w') or die("can't open file"); + fclose($fh); + + unlink($avatar_file); + + $avatar_file = $target_path . '/' . $p_username . '.png'; + $fh = fopen($avatar_file, 'w') or die("can't open file"); + fclose($fh); + + unlink($avatar_file); + } + + # Print avatar image for the given user ID + function avatar_print( $p_user_id, $p_size = 80, $t_class = "avatar" ) { + global $g_default_avatar; + + $t_avatar_exist = false; + if ( !user_exists( $p_user_id ) ) { + return false; + } + + if ( access_has_project_level( config_get( 'show_avatar_threshold' ), null ) ) { + $t_use_gravatar = config_get( 'use_gravatar', false, $p_user_id, ALL_PROJECTS ); + if ($t_use_gravatar) { + $t_avatar = user_get_avatar( $p_user_id, $p_size ); + if ( false !== $t_avatar ) { + $t_avatar_url = $t_avatar[0]; + $t_width = $t_avatar[1]; + $t_height = $t_avatar[2]; + echo '' . + 'User avatar'; + } + } else { + $t_avatar = user_get_local_avatar( $p_user_id ); + $t_avatar_url = $t_avatar[0]; + $t_width = $t_avatar[1]; + $t_height = $t_avatar[2]; + + $t_avatar_exist = $t_avatar[3]; + + if ($t_avatar_exist) { + echo 'User avatar'; + } + else { + if( $t_class == "avatar" ) { + echo 'User avatar'; + } + } + } + } + return $t_avatar_exist; + } diff -N -a --unified -r mantisbt/core/custom_field_api.php mantisbt-file_avatar/core/custom_field_api.php --- mantisbt/core/custom_field_api.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/core/custom_field_api.php 2008-12-01 11:51:50.205616600 -0500 @@ -716,7 +716,6 @@ db_query_bound( $query, Array( $c_field_id ) ); $t_custom_field_table = db_get_table( 'mantis_custom_field_table' ); - # delete the definition $query = "DELETE FROM $t_custom_field_table WHERE id="; diff -N -a --unified -r mantisbt/core/user_api.php mantisbt-file_avatar/core/user_api.php --- mantisbt/core/user_api.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/core/user_api.php 2008-12-01 11:53:45.558346900 -0500 @@ -769,13 +769,15 @@ * in this first implementation, only gravatar.com avatars are supported * @return array|bool an array( URL, width, height ) or false when the given user has no avatar */ -function user_get_avatar( $p_user_id, $p_size = 80 ) { +function user_get_avatar( $p_user_id ) { + global $g_avatar_max_width, $g_avatar_max_height; + $t_email = strtolower( user_get_email( $p_user_id ) ); if( is_blank( $t_email ) ) { $t_result = false; } else { $t_default_image = config_get( 'default_avatar' ); - $t_size = $p_size; + $t_size = $g_avatar_max_width; $t_use_ssl = false; if( isset( $_SERVER['HTTPS'] ) && ( strtolower( $_SERVER['HTTPS'] ) != 'off' ) ) { @@ -799,6 +801,46 @@ return $t_result; } +/** + * return the local stored user avatar image URL + * @return array|bool an array( URL, width, height ) or false when the given user has no avatar + */ +function user_get_local_avatar( $p_user_id ) { + $t_avatar_exist = true; + $avatar_dir = config_get('directory_avatar'); + + # default imagesize + $t_height = config_get('avatar_max_height'); + $t_width = config_get('avatar_max_width'); + + $t_username = user_get_field($p_user_id, 'username'); + + $t_avatar_url = $avatar_dir . '/' . $t_username . '.png'; // mthibeault: Using DIRECTORY_SEPARATOR was not accepted by Firefox + if (!file_exists($t_avatar_url)) { + $t_avatar_url = $avatar_dir . '/' . $t_username . '.gif'; + if (!file_exists($t_avatar_url)) { + $t_avatar_url = $avatar_dir . '/' . $t_username . '.jpg'; + if (!file_exists($t_avatar_url)) { + $t_avatar_exist = false; + } + } + } + + if ($t_avatar_exist) { + # get image dimensions + list($width_orig, $height_orig) = getimagesize($t_avatar_url); + $ratio_orig = $width_orig/$height_orig; + + if ($t_width/$t_height > $ratio_orig) { + $t_width = $t_height*$ratio_orig; + } else { + $t_height = $t_width/$ratio_orig; + } + } + + return array( $t_avatar_url, $t_width, $t_height, $t_avatar_exist ); +} + # -------------------- # return the user's access level # account for private project and the project user lists diff -N -a --unified -r mantisbt/core/utility_api.php mantisbt-file_avatar/core/utility_api.php --- mantisbt/core/utility_api.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/core/utility_api.php 2008-12-01 11:54:06.275903500 -0500 @@ -236,6 +236,46 @@ } } +function gd_open_image ($file, $extension='') { + // Get extension + if( is_blank( $extension ) ) { + $extension = strrchr($file, '.'); + } + $extension = strtolower($extension); + switch($extension) { + case '.jpg': + case '.jpeg': + $im = @imagecreatefromjpeg($file); + break; + case '.gif': + $im = @imagecreatefromgif($file); + break; + case '.png': + $im = @imagecreatefrompng($file); + break; + + // ... etc + + default: + $im = false; + break; + } + + return $im; +} + + +# Return Imagick version +function get_imagick_version() +{ + $t_ImagickfuncList = get_extension_funcs('imagick'); + if( ! is_array( $t_ImagickfuncList ) ) { + return 0; + } else { + return 1; + } +} + /** * return true or false if string matches current page name * @param string $p_string page name diff -N -a --unified -r mantisbt/css/default.css mantisbt-file_avatar/css/default.css --- mantisbt/css/default.css 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/css/default.css 2008-12-01 11:54:30.821364600 -0500 @@ -175,5 +175,11 @@ border: 0; } +.manage_avatar +{ + float: left; + border: 2; +} + .progress400 { position: relative; width: 400px; border: 1px solid #d7d7d7; margin-top: 1em; margin-bottom: 1em; padding: 1px; } .progress400 .bar { display: block; position: relative; background: #6bba70; text-align: center; font-weight: normal; color: #333; height: 2em; line-height: 2em; } diff -N -a --unified -r mantisbt/lang/strings_english.txt mantisbt-file_avatar/lang/strings_english.txt --- mantisbt/lang/strings_english.txt 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/lang/strings_english.txt 2008-12-01 11:55:07.506751400 -0500 @@ -532,6 +532,7 @@ $s_realname_duplicated = 'Real name is used by another user'; $s_realname_updated = 'Real name successfully updated'; $s_password_updated = 'Password successfully updated'; +$s_avatar_updated = 'Avatar successfully updated. You may need to refresh the next page to see the new avatar.'; # adm_permission_report.php @@ -1558,4 +1559,9 @@ $s_view_account_title = 'User Information'; # view_user_page.php -$s_manage_user = 'Manage User'; \ No newline at end of file +$s_manage_user = 'Manage User'; + +$s_avatar = 'Avatar'; +$s_use_gravatar = 'Use Gravatar for Avatar'; +$s_upload_avatar = 'Upload Avatar'; +$s_delete_avatar = 'Delete Avatar'; diff -N -a --unified -r mantisbt/manage_user_edit_page.php mantisbt-file_avatar/manage_user_edit_page.php --- mantisbt/manage_user_edit_page.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/manage_user_edit_page.php 2008-12-01 11:48:13.905576200 -0500 @@ -24,7 +24,8 @@ * Mantis Core API's */ require_once( 'core.php' ); - + require_once( $t_core_path.'avatar_api.php' ); + auth_reauthenticate(); access_ensure_global_level( config_get( 'manage_user_threshold' ) ); @@ -44,6 +45,8 @@ $t_user = user_get_row( $t_user_id ); + $t_use_gravatar = config_get( 'use_gravatar', false, $f_user_id, ALL_PROJECTS ); + html_page_top1(); html_page_top2(); @@ -55,7 +58,7 @@
- + @@ -127,6 +130,39 @@ /> + +> + + + +> + + + + +> + + + diff -N -a --unified -r mantisbt/manage_user_page.php mantisbt-file_avatar/manage_user_page.php --- mantisbt/manage_user_page.php 2008-11-30 14:16:41.000000000 -0500 +++ mantisbt-file_avatar/manage_user_page.php 2008-12-01 11:49:27.463839000 -0500 @@ -28,6 +28,7 @@ $t_core_path = config_get( 'core_path' ); require_once( $t_core_path . 'icon_api.php' ); + require_once( $t_core_path . 'avatar_api.php' ); auth_reauthenticate(); @@ -277,6 +278,10 @@ + > +
+ : + + /> +
+ : + +   + + + +
+ + (' . lang_get( 'max_file_size' ) . ': ' . number_format( $t_max_file_size/1000 ) . 'k)'?> + + + name="avatar_file" type="file" size="60" /> +
+ + +
@@ -312,6 +321,14 @@ +