'avatars/', 'max_width' => 150, 'max_height' => 150, 'max_bytes' => 1048576, 'use_default' => 1, 'identicon_size' => 100, 'file_extns' => array("gif", "jpg", "jpeg", "png") ); // Get database options $db_options = bb_get_option('avatar_upload_options'); // If there are options in the database if ($db_options) { // The database options override the defaults $options = array_merge($options, $db_options); } // If there is no trailing slash on the directory then add it if (substr($options['avatar_dir'], -1) != '/') { $options['avatar_dir'] .= '/'; } // Avatar folder location (default is 'avatars' in the bbPress root folder) // You must create the folder before you install this plugin. $this->avatar_dir = $options['avatar_dir']; // Define maximum values allowed $this->max_width = $options['max_width']; // pixels $this->max_height = $options['max_height']; // pixels $this->max_bytes = $options['max_bytes']; // filesize (1024 bytes = 1 KB / 1048576 bytes = MB) // Use Unsharp Mask on resized truecolor images 1=yes (hidden option for now) $this->use_unsharpmask = 1; // Use a thumbnail image (hidden feature for now). 1 = yes / 0 = no (default) $this->use_thumbnail = 0; $this->thumb_width = 25; $this->thumb_height = 25; // Default avatar - set 'use_default' to '0' to display Identicon instead of default // The default URI is in the '$this->avatar_dir' folder. $this->default_avatar = array( 'use_default' => $options['use_default'], 'uri' => bb_get_option('uri') . $this->avatar_dir . 'default.png', 'width' => 80, 'height' => 80, 'alt' => "User has not uploaded an avatar" ); // Identicon dimensions (width/height are equal): $this->identicon_size = $options['identicon_size']; // pixels // Allowed file extensions $this->file_extns = $options['file_extns']; // Just pretty values (Kilobytes/megabytes) for output use $this->max_kbytes = round($this->max_bytes / 1024, 2); $this->max_mbytes = round($this->max_bytes / 1048576, 2); } } // Display the avatar image function avatarupload_display($id, $force_db=0, $class='avatar') { if ($a = avatarupload_get_avatar($id,1,$force_db)) { echo ''.$a[4].''; } else { $config = new avatarupload_config(); if ($config->default_avatar['use_default'] == 1) { // Use a "genric" default avatar echo ''.$config->default_avatar['alt'].''; } else { // Or use Identicons instead. New users will have an identicon automatically // created when they join, but this is for existing users with no avatar. felapplyidenticon($id); // create identicon // now fetch it from the database if ($a = avatarupload_get_avatar($id,1,$force_db)) { echo ''.$a[4].''; } } } } // Display the avatar image function avatarupload_displaythumb($id, $force_db=0, $class='avatar_thumb') { $config = new avatarupload_config(); if ($a = avatarupload_get_avatar($id,1,$force_db, 1)) { echo ''.$a[4].''; } } // Get the avatar URI ($id = user->ID, $fulluri = full url to image, // $force_db = get avatar from database where 'usermeta' not already available) function avatarupload_get_avatar($id, $fulluri=1, $force_db=0, $is_thumb=0) { global $bbdb, $user; $cached = bb_get_user($id); // if $user-avatar-file and $cached->avatar_file are both empty, // or we want to force the db query. if ((empty($user->avatar_file) && empty($cached->avatar_file)) || $force_db == 1) { $bb_query = "SELECT meta_value FROM $bbdb->usermeta WHERE meta_key='avatar_file' AND user_id='$id' LIMIT 1"; if ( $avatar = $bbdb->get_results($bb_query) ) { $a = explode("|", $avatar[0]->meta_value); $a[] = substr($a[0], 0, strrpos($a[0], ".")); // for 'alt' attribute (extract from filename) } else { return false; } } else { if (!empty($user->avatar_file)) { $a = explode("|", $user->avatar_file); $a[] = $user->user_login; // for 'alt' attribute } elseif (!empty($cached->avatar_file)) { $a = explode("|", $cached->avatar_file); $a[] = $cached->user_login; // for 'alt' attribute } else { return false; } } if ($is_thumb == 1) { $a[0] = "thumb.".$a[0]; } // do we want the full uri? if ($fulluri == 1) { $config = new avatarupload_config(); $a[0] = bb_get_option('uri') . $config->avatar_dir . $a[0]; } return $a; } // Add an "Upload Avatar" tab to the Profile menu function add_avatar_tab() { global $self; if ($self != 'avatar-upload.php') { add_profile_tab(__('Avatar'), 'edit_profile', 'moderate', 'avatar-upload.php'); } } add_action( 'bb_profile_menu', 'add_avatar_tab' ); // bbPress Identicon function by Fel64 function felapplyidenticon( $felID ) { $config = new avatarupload_config(); $user = bb_get_user( $felID ); $ifilename = strtolower($user->user_login) . "." . 'png'; $ifilepath = BBPATH . $config->avatar_dir . $ifilename; // include the Identicon class. require_once("identicon.php"); if (class_exists("identicon")) { $identicon = new identicon; } if( $identicon ) { $felidenticon = $identicon->identicon_build( $user->user_login, '', false, '', false ); if( imagepng( $felidenticon, $ifilepath ) ) { $meta_avatar = $ifilename."?".time().'|'.$config->identicon_size.'|'.$config->identicon_size.'|identicon'; bb_update_usermeta( $felID, 'avatar_file', $meta_avatar ); $success_message = "Your identicon has been made."; } } } // Is user using an Identicon? function usingidenticon($id) { if ($a = avatarupload_get_avatar($id, 0, 1)) { return ($a[3] == "identicon") ? true : false; } else { return false; } } // Unsharp Mask on image resize (truecolor images only) function do_unsharp_mask($img, $use_unsharpmask=0) { if ($use_unsharpmask == 1) { require_once("unsharpmask.php"); return UnsharpMask($img, 80, 0.5, 3); } else { return $img; } } /** * The admin pages below are handled outside of the class due to constraints * in the architecture of the admin menu generation routine in bbPress */ // Add filters for the admin area add_action('bb_admin_menu_generator', 'avatar_upload_admin_page_add'); add_action('bb_admin-header.php', 'avatar_upload_admin_page_process'); /** * Adds in an item to the $bb_admin_submenu array * * @return void * @author Sam Bauers **/ function avatar_upload_admin_page_add() { if (function_exists('bb_admin_add_submenu')) { // Build 794+ bb_admin_add_submenu(__('Avatar Upload'), 'use_keys', 'avatar_upload_admin_page'); } else { global $bb_submenu; $submenu = array(__('Avatar Upload'), 'use_keys', 'avatar_upload_admin_page'); if (isset($bb_submenu['plugins.php'])) { // Build 740-793 $bb_submenu['plugins.php'][] = $submenu; } else { // Build 277-739 $bb_submenu['site.php'][] = $submenu; } } } /** * Writes an admin page for the plugin * * @return string * @author Sam Bauers * @modified Louise Dade **/ function avatar_upload_admin_page() { $config = new avatarupload_config(); $gif_checked = (in_array('gif', $config->file_extns)) ? "checked=\"checked\" " : ""; $jpg_checked = (in_array('jpg', $config->file_extns)) ? "checked=\"checked\" " : ""; $png_checked = (in_array('png', $config->file_extns)) ? "checked=\"checked\" " : ""; $use_default_checked = ($config->default_avatar['use_default']) ? "checked=\"checked\" " : ""; $identicons_checked = ($config->default_avatar['use_default']) ? "" : "checked=\"checked\" "; ?>

Avatar Upload Settings

bbPressRootDirectory/ (location must be writable by the web server)
pixels
pixels
bytes (n.b. 1 KB = 1024 bytes)
Allow the following image types to be uploaded:

Action to take when a user has no avatar present: (view).
pixels

Don't Forget!

If you haven't already done so: upload the files in the "additional-files" directory to the following locations.

Read the readme.txt file that came with this plugin for more detailed instructions.