';
} else {
$ud = get_userdata($user);
$grav_option = get_site_option('user-avatar-default');
if ( $grav_option == '' ) {
$default_grav = 'wavatar';
} else if ( $grav_option == 'mystery' ) {
$default_grav = site_url( MUPLUGINDIR . '/bp-core/images/mystery-man.jpg');
} else {
$default_grav = $grav_option;
}
$gravatar = 'http://www.gravatar.com/avatar/' . md5( $ud->user_email ) . '?d=' . $default_grav . '&s=';
if ( $no_tag )
return $gravatar . constant('CORE_AVATAR_V' . $version . '_W');
else
return '';
}
}
// Override internal "get_avatar()" function to use our own where possible
// WARNING: Does NOT apply size restrictions
function bp_core_get_avatar_filter( $avatar, $id_or_email, $size, $default ) {
$str = '';
$ver = ( $size == 1 || $size == 2 ) ? $size : 1;
if ( CORE_AVATAR_V2_W == false && CORE_AVATAR_V2_H == false )
$ver = 1;
if ( is_numeric($id_or_email) ) {
$str = bp_core_get_avatar( $id_or_email, $ver );
} elseif ( is_object($id_or_email) ) {
if ( !empty($id_or_email->user_id) ) {
$str = bp_core_get_avatar( $id_or_email->user_id, $ver );
}
}
return empty($str) ? $avatar : $str;
}
add_filter( 'get_avatar', 'bp_core_get_avatar_filter', 10, 4 );
// Main UI Rendering
function bp_core_avatar_admin( $message = null, $action, $delete_action) {
global $wp_upload_error;
?>
' . __('Your new avatar was successfully created!', 'buddypress') . '
'; bp_core_avatar_save($result); echo '' . bp_core_get_avatar( get_current_user_id(), 1 ) . ''; if ( CORE_AVATAR_V2_W !== false && CORE_AVATAR_V2_H !== false ) { echo '' . bp_core_get_avatar( get_current_user_id(), 2 ) . ''; } } else if ( isset($_GET['slick_avatars_action']) && $_GET['slick_avatars_action'] == 'delete' ) { // Delete an avatar bp_core_delete_avatar(); unset($_GET['slick_avatars_action']); $message = __('Avatar successfully removed.', 'buddypress'); bp_core_avatar_admin($message); } ?> CORE_MAX_FILE_SIZE ) return false; return true; } function bp_core_check_avatar_type($file) { if ( ( strlen($file['file']['type']) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) && !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) ) return false; return true; } function bp_core_handle_avatar_upload($file) { global $wp_upload_error; // Change the upload file location to /avatars/user_id add_filter( 'upload_dir', 'bp_core_avatar_upload_dir' ); $res = wp_handle_upload( $file['file'], array('action'=>'slick_avatars') ); if ( !in_array('error', array_keys($res) ) ) { return $res['file']; } else { $wp_upload_error = $res['error']; return false; } } function bp_core_avatar_upload_dir( $upload, $user_id = false ) { global $bp; if ( !$user_id ) $user_id = $bp['loggedin_userid']; // Switch to the root blog, so all avatars are stored in the root blog upload dir. switch_to_blog(1); $path = get_option('upload_path'); $newdir = path_join( ABSPATH, $path ); $newdir .= '/avatars/' . $user_id . '/'; $newbdir = $newdir; @wp_mkdir_p( $newdir ); $newurl = trailingslashit( get_option('siteurl') ) . '/avatars/' . $user_id . '/'; $newburl = $newurl; $newsubdir = '/avatars/' . $user_id . '/'; // Switch back to the current blog restore_current_blog(); return array( 'path' => $newdir, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ); } function bp_core_check_avatar_dimensions($file) { $size = getimagesize($file); if ( $size[0] < (int)CORE_AVATAR_V2_W || $size[1] < (int)CORE_CROPPING_CANVAS_MAX ) return false; return true; } function bp_core_resize_avatar( $file, $size = false ) { if ( !$size ) $size = CORE_CROPPING_CANVAS_MAX; $canvas = wp_create_thumbnail( $file, $size ); if ( $canvas->errors ) return false; return $canvas = str_replace( '//', '/', $canvas ); } function bp_core_render_avatar_cropper($original, $new, $action, $user_id = null, $no_form_tag = false, $url = false) { global $bp; $size = getimagesize($new); if ( !$user_id ) $user_id = $bp['loggedin_userid']; $src = str_replace( array(ABSPATH), array(site_url() . '/'), $new ); // Load cropper details // V1 UI if ( !$no_form_tag ) echo ''; ?> = 2 && stristr($dir, ABSPATH) ); return array('v1_out' => $v1_out, 'v2_out' => $v2_out); } function bp_core_avatar_save( $vars, $user_id = false ) { if ( !$user_id ) $user_id = get_current_user_id(); $old = get_usermeta( $user_id, 'bp_core_avatar_v1_path' ); $v1_href = str_replace( array(ABSPATH), array($src), $vars['v1_out'] ); update_usermeta( $user_id, 'bp_core_avatar_v1', $v1_href ); update_usermeta( $user_id, 'bp_core_avatar_v1_path', $vars['v1_out'] ); @unlink($old); // Removing old avatar if ( CORE_AVATAR_V2_W !== false && CORE_AVATAR_V2_H !== false ) { $old = get_usermeta( $user_id, 'bp_core_avatar_v2_path' ); $v2_href = str_replace( array(ABSPATH), array($src), $vars['v2_out'] ); update_usermeta( $user_id, 'bp_core_avatar_v2', $v2_href ); update_usermeta( $user_id, 'bp_core_avatar_v2_path', $vars['v2_out'] ); @unlink($old); // Removing old avatar } } function bp_core_render_avatar_upload_form($action, $no_form_tag = false) { if ( !$no_form_tag ) { ?> ' . $msg . ''; echo ''; echo ''; exit; } function bp_core_thumb_error( $str ) { if ( !is_string($str) ) { return false; } else { return preg_match( '/(filetype|invalid|not found)/is', $str ); } } ?>