WordPress.org

Plugin Directory

Changeset 482003


Ignore:
Timestamp:
12/29/11 21:36:33 (2 years ago)
Author:
jakemgold
Message:
  • Brazilian Portuguese and Belarusian translations
  • Bug fixes (most notably correct naming of image files based on user display name)
  • Optimization for WordPress 3.2 / 3.3 (substitutes deprecated function)
Location:
simple-local-avatars/trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • simple-local-avatars/trunk/readme.txt

    r442320 r482003  
    33Donate link: http://get10up.com/plugins/simple-local-avatars-wordpress/ 
    44Tags: avatar, gravatar, user photos, users, profile 
    5 Requires at least: 3.0 
    6 Tested up to: 3.2.1 
    7 Stable tag: 1.3 
     5Requires at least: 3.2 
     6Tested up to: 3.3 
     7Stable tag: 1.3.1 
    88 
    99Adds an avatar upload field to user profiles if the current user has media permissions. Generates requested sizes on demand just like Gravatar! 
     10 
    1011 
    1112== Description == 
     
    23241. Let's you decide whether lower privilege users (subscribers, contributors) can upload their own avatar 
    2425 
     26 
    2527== Installation == 
    2628 
     
    30321. Start uploading avatars by editing user profiles! 
    3133 
     34Use avatars in your theme using WordPress' built in `get_avatar()` function: [http://codex.wordpress.org/Function_Reference/get_avatar](http://codex.wordpress.org/Function_Reference/get_avatar "get_avatar function") 
     35 
     36You can also use `get_simple_local_avatar()` (with the same arguments) to retreive local avatars a bit faster, but this will make your theme dependent on this plug-in. 
     37 
     38 
    3239== Screenshots == 
    3340 
    34411. Avatar upload field on a user profile page 
    3542 
     43 
    3644== Changelog == 
     45 
     46= 1.3.1 = 
     47* Brazilian Portuguese and Belarusian translations 
     48* Bug fixes (most notably correct naming of image files based on user display name) 
     49* Optimization for WordPress 3.2 / 3.3 (substitutes deprecated function) 
    3750 
    3851= 1.3 = 
     
    7386* All users (regardless of capabilities) can upload avatars by default. To limit avatar uploading to users with upload files capabilities (Authors and above), check the applicable option under Settings > Discussion. This was the default behavior in 1.0. 
    7487* Localization support; German included 
     88 
     89 
     90== Upgrade Notice == 
     91 
     92= 1.3.1 = 
     93Like WordPress 3.2, now *REQUIRES* PHP 5.2 or newer. 
  • simple-local-avatars/trunk/simple-local-avatars.php

    r442320 r482003  
    44 Plugin URI: http://get10up.com/plugins/simple-local-avatars-wordpress/ 
    55 Description: Adds an avatar upload field to user profiles if the current user has media permissions. Generates requested sizes on demand just like Gravatar! Simple and lightweight. 
    6  Version: 1.3 
     6 Version: 1.3.1 
    77 Author: Jake Goldman (10up LLC), Oomph Inc 
    88 Author URI: http://get10up.com 
    99 
    10     Plugin: Copyright 2011 10up LLC (email : jake@get10up.com) 
     10    Plugin: Copyright 2011 Jake Goldman (email : jake@get10up.com) 
    1111 
    1212    This program is free software; you can redistribute it and/or modify 
     
    2323    along with this program; if not, write to the Free Software 
    2424    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
     25     
     26    NOTE: Previous versions may have accidentally and incorrectly attributed the  
     27    copyright to employers of Mr. Goldman. While credit is given to all contributors 
     28    to the current version, including Mr. Goldman's employers, the copyright belongs 
     29    - and has always belonged - to Mr. Goldman, personally. 
    2530*/ 
    2631 
     
    2934 */ 
    3035  
    31 class simple_local_avatars  
    32 { 
    33     function simple_local_avatars() { 
     36class Simple_Local_Avatars { 
     37    private $user_id_being_edited; 
     38     
     39    public function __construct() { 
    3440        add_filter( 'get_avatar', array( $this, 'get_avatar' ), 10, 5 ); 
    3541         
     
    4551    } 
    4652     
    47     function get_avatar( $avatar = '', $id_or_email, $size = '96', $default = '', $alt = false ) { 
     53    public function get_avatar( $avatar = '', $id_or_email, $size = 96, $default = '', $alt = false ) { 
    4854         
    4955        if ( is_numeric($id_or_email) ) 
    5056            $user_id = (int) $id_or_email; 
    51         elseif ( is_string( $id_or_email ) && ( $user = get_user_by_email( $id_or_email ) ) ) 
     57        elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) ) 
    5258            $user_id = $user->ID; 
    5359        elseif ( is_object( $id_or_email ) && ! empty( $id_or_email->user_id ) ) 
     
    7177            $upload_path = wp_upload_dir(); 
    7278            $avatar_full_path = str_replace( $upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full'] ); 
    73             $image_sized = image_resize( $avatar_full_path, $size, $size, true ); 
    74                  
     79            $image_sized = image_resize( $avatar_full_path, $size, $size, true );        
    7580            // deal with original being >= to original image (or lack of sizing ability) 
    7681            $local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace( $upload_path['basedir'], $upload_path['baseurl'], $image_sized );  
    77              
     82            // save updated avatar sizes 
    7883            update_user_meta( $user_id, 'simple_local_avatar', $local_avatars ); 
    7984        } elseif ( substr( $local_avatars[$size], 0, 4 ) != 'http' ) { 
    80             $local_avatars[$size] = site_url( $local_avatars[$size] ); 
     85            $local_avatars[$size] = home_url( $local_avatars[$size] ); 
    8186        } 
    8287         
    8388        $author_class = is_author( $user_id ) ? ' current-author' : '' ; 
    84         $avatar = "<img alt='" . esc_attr($alt) . "' src='" . $local_avatars[$size] . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />"; 
     89        $avatar = "<img alt='" . esc_attr( $alt ) . "' src='" . $local_avatars[$size] . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />"; 
    8590         
    8691        return apply_filters( 'simple_local_avatar', $avatar ); 
    8792    } 
    8893     
    89     function admin_init() { 
     94    public function admin_init() { 
    9095        load_plugin_textdomain( 'simple-local-avatars', false, dirname( plugin_basename( __FILE__ ) ) . '/localization/' ); 
    9196         
     
    9499    } 
    95100     
    96     function sanitize_options( $input ) { 
     101    public function sanitize_options( $input ) { 
    97102        $new_input['simple_local_avatars_caps'] = empty( $input['simple_local_avatars_caps'] ) ? 0 : 1; 
    98103        return $new_input; 
    99104    } 
    100105     
    101     function avatar_settings_field( $args ) {        
     106    public function avatar_settings_field( $args ) {         
    102107        $options = get_option('simple_local_avatars_caps'); 
    103108         
     
    110115    } 
    111116     
    112     function edit_user_profile( $profileuser ) { 
     117    public function edit_user_profile( $profileuser ) { 
    113118    ?> 
    114119    <h3><?php _e( 'Avatar','simple-local-avatars' ); ?></h3> 
     
    151156    } 
    152157     
    153     function edit_user_profile_update( $user_id ) { 
     158    public function edit_user_profile_update( $user_id ) { 
    154159        if ( ! isset( $_POST['_simple_local_avatar_nonce'] ) || ! wp_verify_nonce( $_POST['_simple_local_avatar_nonce'], 'simple_local_avatar_nonce' ) )            //security 
    155160            return; 
     
    170175            $this->avatar_delete( $user_id );   // delete old images if successful 
    171176             
     177            // need to be more secure since low privelege users can upload 
     178            if ( strstr( $_FILES['simple-local-avatar']['name'], '.php' ) ) 
     179                wp_die('For security reasons, the extension ".php" cannot be in your file name.'); 
     180             
     181            $this->user_id_being_edited = $user_id; // make user_id known to unique_filename_callback function 
    172182            $avatar = wp_handle_upload( $_FILES['simple-local-avatar'], array( 'mimes' => $mimes, 'test_form' => false, 'unique_filename_callback' => array( $this, 'unique_filename_callback' ) ) ); 
    173183             
     
    193203     * remove the custom get_avatar hook for the default avatar list output on options-discussion.php 
    194204     */ 
    195     function avatar_defaults( $avatar_defaults ) { 
     205    public function avatar_defaults( $avatar_defaults ) { 
    196206        remove_action( 'get_avatar', array( $this, 'get_avatar' ) ); 
    197207        return $avatar_defaults; 
     
    201211     * delete avatars based on user_id 
    202212     */ 
    203     function avatar_delete( $user_id ) { 
     213    public function avatar_delete( $user_id ) { 
    204214        $old_avatars = get_user_meta( $user_id, 'simple_local_avatar', true ); 
    205215        $upload_path = wp_upload_dir(); 
     
    215225    } 
    216226     
    217     function unique_filename_callback( $dir, $name, $ext ) { 
    218         $user = wp_get_current_user(); 
    219         $name = sanitize_file_name( $user->display_name . '_avatar' ); 
    220          
     227    public function unique_filename_callback( $dir, $name, $ext ) { 
     228        $user = get_user_by( 'id', (int) $this->user_id_being_edited );  
     229        $name = $base_name = sanitize_file_name( $user->display_name . '_avatar' ); 
    221230        $number = 1; 
    222231         
    223232        while ( file_exists( $dir . "/$name$ext" ) ) { 
    224             $name = $name . '_' . $number; 
     233            $name = $base_name . '_' . $number; 
    225234            $number++; 
    226235        } 
     
    230239} 
    231240 
    232 $simple_local_avatars = new simple_local_avatars; 
     241$simple_local_avatars = new Simple_Local_Avatars; 
    233242 
    234243/** 
     
    258267 
    259268function simple_local_avatars_uninstall() { 
    260     $simple_local_avatars = new simple_local_avatars; 
     269    $simple_local_avatars = new Simple_Local_Avatars; 
    261270    $users = get_users_of_blog(); 
    262271     
Note: See TracChangeset for help on using the changeset viewer.