Changeset 473

Show
Ignore:
Timestamp:
07/16/07 12:22:59 (1 year ago)
Author:
louisedade
Message:

avatar-upload: committing version 0.6 - added Identicons into trunk (no more branching) and implemented a fix for browser cache problems.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • avatar-upload/trunk/avatar-upload.php

    r462 r473  
    33Plugin Name: Avatar Upload 
    44Plugin URI: http://bbpress.org/plugins/topic/46 
    5 Version: 0.5 
     5Version: 0.6 
    66Description: Allows users to upload an avatar (gif, jpeg/jpg or png) image to bbPress. 
    77Author: Louise Dade 
     
    113113                } 
    114114 
    115                 // Add avatar to database as usermeta data
    116                 $meta_avatar = $user_filename . "|" . $img_w . "|" . $img_h . "|avatar-upload"; 
     115                // Add avatar to database as usermeta data (append unix time to help browser caching probs)
     116                $meta_avatar = $user_filename . "?" . time() . "|" . $img_w . "|" . $img_h . "|avatar-upload"; 
    117117                bb_update_usermeta( $user_id, 'avatar_file', $meta_avatar ); 
    118118                $success_message = "Your avatar has been uploaded."; 
     
    161161                } 
    162162        } 
     163} 
     164 
     165// Has user checked the "Use Identicon" option? 
     166if( $_POST['identicon'] ) 
     167{ 
     168        felapplyidenticon( $user_id ); // create an identicon 
    163169} 
    164170 
  • avatar-upload/trunk/my-plugins/bb-avatar-upload.php

    r462 r473  
    33Plugin Name: Avatar Upload 
    44Plugin URI: http://bbpress.org/plugins/topic/46 
    5 Version: 0.5 
     5Version: 0.6 
    66Description: Allows users to upload an avatar (gif, jpeg/jpg or png) image to bbPress. 
    77Author: Louise Dade 
     
    2323                $this->max_bytes = 1048576; // filesize (1024 bytes = 1 KB / 1048576 bytes = MB) 
    2424 
    25                 // Default avatar - set 'use_default' to '0' to display no image instead of default 
     25                // Default avatar - set 'use_default' to '0' to display Identicon instead of default 
    2626                // The default URI is in the '$this->avatar_dir' folder. 
    2727                $this->default_avatar = array(   
    28                         'use_default' => 1
     28                        'use_default' => 0
    2929                        'uri' =>  bb_get_option('uri') . $this->avatar_dir . 'default.png', 
    3030                        'width' => 80, 
     
    4343 
    4444// Display the avatar image 
    45 function avatarupload_display($id, $status=''
     45function avatarupload_display($id
    4646{ 
    4747        if ($a = avatarupload_get_avatar($id)) 
    4848        { 
    49                 echo '<img src="'.$a[0]; 
    50                 echo ($status == 'new') ? '?'.time() : ''; 
    51                 echo'" width="'.$a[1].'" height="'.$a[2].'" alt="'.$a[4].'" />'; 
     49                echo '<img src="'.$a[0].'" width="'.$a[1].'" height="'.$a[2].'" alt="'.$a[4].'" />'; 
    5250        } else { 
    5351                $config = new avatarupload_config(); 
     
    5553                if ($config->default_avatar['use_default'] == 1) 
    5654                { 
     55                        // Use a "genric" default avatar 
    5756                        echo '<img src="'.$config->default_avatar['uri'].'" width="'.$config->default_avatar['width'] 
    5857                        .'" height="'.$config->default_avatar['height'].'" alt="'.$config->default_avatar['alt'].'" />'; 
     58                } else { 
     59                        // Or use Identicons instead.  New users will have an identicon automatically 
     60                        // created when they join, but this is for existing users with no avatar. 
     61 
     62                        felapplyidenticon($id); // create identicon 
     63 
     64                        // now fetch it from the database 
     65                        if ($a = avatarupload_get_avatar($id)) 
     66                        { 
     67                                echo '<img src="'.$a[0].'" width="'.$a[1].'" height="'.$a[2].'" alt="'.$a[4].'" />'; 
     68                        } 
    5969                } 
    6070        } 
     
    110120add_action( 'bb_profile_menu', 'add_avatar_tab' ); 
    111121 
     122 
     123//  bbPress Identicon function by Fel64 
     124function felapplyidenticon( $felID ) 
     125{ 
     126        $config = new avatarupload_config(); 
     127        $user = bb_get_user( $felID ); 
     128 
     129        $ifilename = strtolower($user->user_login) . "." . 'png'; 
     130        $ifilepath = BBPATH . $config->avatar_dir . $ifilename; 
     131 
     132        if (class_exists("identicon")) { $identicon = new identicon; } 
     133 
     134        if( $identicon ) 
     135        { 
     136                $felidenticon = $identicon->identicon_build( $user->user_login, '', false, '', false ); 
     137 
     138                if( imagepng( $felidenticon, $ifilepath ) ) 
     139                { 
     140                        $ioptions = identicon_get_options(); 
     141                        $meta_avatar = $ifilename."?".time().'|'.$ioptions['size'].'|'.$ioptions['size'].'|identicon'; 
     142                        bb_update_usermeta( $felID, 'avatar_file', $meta_avatar ); 
     143                        $success_message = "Your identicon has been made."; 
     144                } 
     145        } 
     146} 
     147 
     148// Is user using an Identicon? 
     149function usingidenticon($id) 
     150{ 
     151        if ($a = avatarupload_get_avatar($id, 0, 1)) 
     152        { 
     153                return ($a[3] == "identicon") ? true : false; 
     154        } else { 
     155                return false; 
     156        } 
     157} 
     158 
    112159?> 
  • avatar-upload/trunk/my-templates/avatar.php

    r462 r473  
    77<?php 
    88        echo (!empty($error_message)) ? '<div class="infobox"><strong>'.__("OOPS! ".$error_message).'</strong></div>' : ""; 
    9  
    10         if (!empty($success_message)) { 
    11                 echo '<div class="notice">'.__($success_message).'<br /><br />If your avatar does not appear to ' 
    12                 . 'have changed on the forums, it is because your browser has cached (stored a copy of) your old ' 
    13                 . 'avatar - refreshing the page a few times should download the new image.</div>'; 
    14         } 
     9        echo (!empty($success_message)) ? '<div class="notice">'.__($success_message).'</div>' : ""; 
    1510?> 
    1611 
     
    3328 
    3429<h3><?php _e('Current Avatar'); ?></h3> 
    35 <p><?php echo avatarupload_display($user->ID, 'new'); ?></p> 
     30<p><?php echo avatarupload_display($user->ID); ?></p> 
     31 
     32<?php if (!usingidenticon($user->ID)) { ?> 
     33<form method="POST" action="<?php profile_tab_link($user->ID, 'avatar'); ?>"> 
     34<p><label for"useidenticon"><input type="checkbox" name="identicon" value="1" id="useidenticon" /> <?php _e('Use your Identicon instead?'); ?></label></p> 
     35<p><input type="submit" name="submit" id="submit" value="Use Identicon" /></p> 
     36</form> 
     37<?php 
     38} else { 
     39        _e('<p>You are currently using your Identicon.</p>'); 
     40} // end if not using identicon 
     41 
     42if ($config->default_avatar['use_default'] == 0) { 
     43        _e("<p>The forum Admin has selected Identicons for user's default avatar. You can change it by uploading your own avatar image (you can always revert back to your Identicon if you wish).</p>"); 
     44
     45?> 
    3646 
    3747<?php } ?> 
  • avatar-upload/trunk/readme.txt

    r462 r473  
    22Tags: avatars, avatar, uploads, profile 
    33Contributors: LouiseDade 
    4 Requires at least: 0.8 
     4Requires at least: 0.8.2 
    55Tested up to: 0.8.2.1 
    6 Stable Tag: 0.5 
     6Stable Tag: 0.6 
    77 
    8 Allows users to upload an avatar (gif, jpeg/jpg or png) image to bbPress. Admins can configure maximum allowed file size and image dimensions. 
     8Allows users to upload an avatar (gif, jpeg/jpg or png) image to bbPress. Admins can configure maximum allowed file size and image dimensions. Includes fel64's code enabling 'Identicons' - default avatars made of abstract patterns unique to each user. 
    99 
    1010== Description == 
     
    3434* Option to display a default avatar for users who do not upload their own. 
    3535 
    36 * Can be extended with fel64's "Identicons" plugin to give users the option of displaying an identicon instead of uploading an image (becomes their 'default' avatar). Identicons are currently a branch of this plugin.  http://bbpress.org/forums/topic/1027?replies=25#post-6759 
     36* fel64's "Identicons" plugin gives users the option of displaying an identicon instead of uploading an image (becomes their 'default' avatar). http://bbpress.org/forums/topic/1027?replies=25#post-6759 
     37 
     38Credit to fel64 for providing the bbPress interface for Identicons and Scott Sherrill-Mix for writing the Identicon code at http://scott.sherrillmix.com/blog/blogger/wp_identicon/  
    3739 
    3840== Installation == 
     
    4143 
    42441. Open up the `my-plugins/bb-avatar-upload.php` file and configure the "Configuration Settings". At least make sure the `$avatar_dir` variable is correct. 
     45 
     46    IMPORTANT: to use Identicons, you must leave the 'use_default' (avatar) option as '0' so that 
     47    the user's automatically created identicon is displayed and not the generic default image.  
     48    Obviously, to go back to using a generic default set the option to '1' again. 
    4349 
    44502. The avatar upload page should appear as a tab ("Avatar") on the user's Profile menu.  If you'd prefer the link to be elsewhere, insert the following "Upload Avatar" link wherever you wish: 
     
    8086   `my-plugins/bb-avatar-upload.php` - your `my-plugins/` dir (and activated). 
    8187 
     88   `my-plugins/_identicon.php`        - your `my-plugins/` dir (it is automatically activated). 
     89 
    8290That's it, the 'Avatar Upload' plugin should now be working. 
    8391 
     
    100108== Change Log == 
    101109 
     1102007-07-16 Ver. 0.6   Integrated Identicons into the core plugin. Added Unix timestamp to filename 
     111                      in DB (updated when user updates avatar) to combat browser caching problems. 
     112 
    1021132007-07-15 Ver. 0.5   added image resizing function, better mime-type checking and a couple of 
    103114                      performance improvements.