Changeset 44757
- Timestamp:
- 05/07/08 18:56:54 (2 months ago)
- Files:
-
- add-local-avatar/trunk/avatars.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
add-local-avatar/trunk/avatars.php
r40975 r44757 5 5 Description: A plugin to manage public and private avatars. 6 6 Author: Peter Sterling 7 Version: 3.27 Version: 4.1 8 8 Changes: 0.1 - Initial version. 9 9 1.0 - Added pagination of users list. 10 2.0 - Added pagination of the comment ors list too.10 2.0 - Added pagination of the commenters list too. 11 11 2.1 - Added example formatting information. 12 12 3.0 - Added ability to place avatars in written post content (plus other tweaks). 13 13 3.1 - Minor tweaks to usage text and options. 14 14 3.2 - Added check for administration pages to stop user URL wrapping breaking comment editing. 15 3.3 - Spelling fixes! 16 4.0 - Wavatar, Monster ID and Identicon can be used. 17 4.1 - Author credit. 15 18 Author URI: http://www.sterling-adventures.co.uk/ 16 19 */ … … 24 27 'snapshots' => 'off', 25 28 'in_posts' => 'on', 29 'wavatar' => '', 30 'credit' => 'on', 26 31 'default' => '' 27 32 ); 33 update_option('plugin_avatars', $avatar_options); 34 } 35 if(!isset($avatar_options['credit'])) { 36 $avatar_options['credit'] = 'on'; 28 37 update_option('plugin_avatars', $avatar_options); 29 38 } … … 36 45 global $avatar_options; 37 46 38 // Check if avatars are turned on. 39 if(!get_option('show_avatars')) return false; 40 41 // Set (check) default avatar and size options. 42 if(!is_numeric($size) || $size == '') $size = $avatar_options['size']; 43 if(empty($default)) $default = $avatar_options['default']; 44 if(empty($default)) $default = "http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=$size"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com') 45 46 $email = ''; 47 48 // Determine if user ID, object (e.g. comment), or email key... 49 $name = ''; 50 $url = ''; 51 if(is_numeric($id_or_email)) { 47 if(!get_option('show_avatars')) return false; // Check if avatars are turned on. 48 49 if(!is_numeric($size) || $size == '') $size = $avatar_options['size']; // Check default avatar size. 50 if(empty($default)) $default = $avatar_options['default']; // Check default avatar image. 51 52 define('UNKNOWN', 'unknown@gravatar.com'); // Unknown e-mail. 53 define('BLANK', 'blank'); // Blank e-mail. 54 define('FALLBACK', 'http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536'); 55 56 $email = ''; // E-mail key for Gravatar.com 57 $name = ''; // Name for anchor title attribute. 58 $url = ''; // Anchor. 59 $id = ''; // User ID. 60 $src = ''; // Image source; 61 62 if(is_numeric($id_or_email)) { // Numeric - user ID... 52 63 $id = (int) $id_or_email; 53 64 $user = get_userdata($id); … … 58 69 } 59 70 } 60 elseif(is_object($id_or_email)) { 61 if(!empty($id_or_email->user_id)) { 71 elseif(is_object($id_or_email)) { // Comment object... 72 if(!empty($id_or_email->user_id)) { // Object has a user ID, commenter was registered & logged in... 62 73 $id = (int) $id_or_email->user_id; 63 74 $user = get_userdata($id); … … 67 78 $url = $user->user_url; 68 79 } 69 } elseif(!empty($id_or_email->comment_author_email)) { 70 $email = $id_or_email->comment_author_email; 71 $id = $id_or_email->user_id; 72 if(('' == $id_or_email->comment_type) || ('comment' == $id_or_email->comment_type)) { 73 $user = get_user_by_email($email); 74 if($user) $id = $user->ID; 75 $url = $id_or_email->comment_author_url; 76 $name = $id_or_email->comment_author; 77 } elseif(('trackback' == $id_or_email->comment_type) || ('pingback' == $id_or_email->comment_type)) { 80 } 81 else { // Comment object... 82 $name = $id_or_email->comment_author; 83 84 switch($id_or_email->comment_type) { 85 case 'trackback': // Trackback... 86 case 'pingback': 78 87 $url_array = parse_url($id_or_email->comment_author_url); 79 88 $url = "http://" . $url_array['host']; 80 } 81 } 82 } 83 else { 84 $email = $id_or_email; 89 break; 90 91 case 'comment': // Comment... 92 case '': 93 if(!empty($id_or_email->comment_author_email)) $email = $id_or_email->comment_author_email; 94 $user = get_user_by_email($email); 95 if($user) $id = $user->ID; // Set ID if we can to check for local avatar. 96 $url = $id_or_email->comment_author_url; 97 break; 98 } 99 } 100 } 101 else { // Assume we have been passed an e-mail address... 102 if(!empty($id_or_email)) $email = $id_or_email; 85 103 $user = get_user_by_email($email); 86 if($user) $id = $user->ID; 104 if($user) $id = $user->ID; // Set ID if we can to check for local avatar. 87 105 } 88 106 … … 93 111 if($id) { 94 112 $local = get_usermeta($id, 'avatar'); 95 if(!empty($local)) {96 $avatar = "<img alt='' src='{$local}' class='{$class} avatar-{$size}' height='{$size}' width='{$size}' />";97 } 98 }99 100 // No local avatar string set, so build global avatar string...101 if(!$avatar) {102 if(!empty($email)) {103 $out = 'http://www.gravatar.com/avatar/';104 $out .= md5(strtolower($email)); 105 $out .= '?s=' . $size;106 $out .= '&d=' . urlencode($default);107 108 $rating = get_option('avatar_rating');109 if(!empty($rating)) $out .= "&r={$rating}";110 111 $avatar = "<img alt='' src='{$out}' class='{$class} avatar-{$size}' height='{$size}' width='{$size}' />";112 } else {113 $avatar = "<img alt='' src='{$default}' class='{$class} avatar-{$size} avatar-default' height='{$size}' width='{$size}'>";114 } 115 }116 117 // If not in admin pages and there is a URL wrap the avatar markup with an anchor.113 if(!empty($local)) $src = $local; 114 } 115 116 // No local avatar source, so build global avatar source... 117 if(!$src) { 118 $src = 'http://www.gravatar.com/avatar/'; 119 if(empty($email)) $src .= md5(strtolower((empty($default) ? UNKNOWN : BLANK))); 120 else $src .= md5(strtolower($email)); 121 $src .= '?s=' . $size; 122 123 $wavatar = $avatar_options['wavatar']; 124 $src .= '&d='; 125 if(!empty($wavatar) && !empty($email)) $src .= urlencode($wavatar); 126 elseif(!empty($default)) $src .= urlencode($default); 127 else $src .= urlencode(FALLBACK); 128 129 $rating = get_option('avatar_rating'); 130 if(!empty($rating)) $src .= "&r={$rating}"; 131 } 132 133 $avatar = "<img alt='' src='{$src}' class='{$class} avatar-{$size} avatar-default' height='{$size}' width='{$size}' />"; 134 135 // If not in admin pages and there is a URL, wrap the avatar markup with an anchor. 118 136 if(!empty($url) && $url != 'http://' && !is_admin()) $avatar = "<a alt='Avatar' href='" . attribute_escape($url) . "' title='" . (empty($name) ? '' : "Visit $name’s website.") . "' " . ($avatar_options['snapshots'] == 'on' ? '>' : "class='snap_noshots'>") . $avatar . "</a>"; 119 137 … … 127 145 function manage_avatar_cache() 128 146 { 129 global $wpdb ;147 global $wpdb, $avatar_options; 130 148 131 149 $msg = ''; … … 146 164 'snapshots' => $_POST['snapshots'], 147 165 'in_posts' => $_POST['in_posts'], 166 'wavatar' => $_POST['wavatar'], 167 'credit' => $_POST['credit'], 148 168 'default' => $_POST['default'] 149 169 ); … … 172 192 <p> 173 193 Please visit the author's site, <a href='http://www.sterling-adventures.co.uk/' title='Sterling Adventures'>Sterling Adventures</a>, and say "Hi"...<br /> 174 Control the be vaiour of the avatar plugin.<br />194 Control the behaviour of the avatar plug-in.<br /> 175 195 </p> 176 196 <h3>User Avatars</h3> … … 203 223 <table class='widefat'> 204 224 <thead> 205 <tr><th>Username</th><th>Name (Nickname)</th><th>e-Mail</th><th> Private</th><th style="text-align: center;">Avatar</th><th>Type</th><th>Action</th></tr>225 <tr><th>Username</th><th>Name (Nickname)</th><th>e-Mail</th><th>Local</th><th style="text-align: center;">Avatar</th><th>Type</th><th>Action</th></tr> 206 226 </thead> 207 227 <tbody> … … 214 234 echo '<td>', $user->first_name, ' ', $user->last_name, (empty($user->nickname) ? '-' : ' (' . $user->nickname . ')'), '</a></td>'; 215 235 echo '<td><a href="mailto:', $user->user_email, '">', $user->user_email, '</td>'; 216 echo '<td><input type="text" value="', $user->avatar, '" size=" 45" id="avatar-', $i, '" /></td>';236 echo '<td><input type="text" value="', $user->avatar, '" size="35" id="avatar-', $i, '" /></td>'; 217 237 echo '<td style="text-align: center;">', get_avatar($id), '</td>'; 218 echo '<td>', (!isset($user->avatar) ? 'Global' : ' Private'), '</td>';238 echo '<td>', (!isset($user->avatar) ? 'Global' : 'Local'), '</td>'; 219 239 echo '<td><a href="?page=avatars.php&user_id=', $id, '" class="edit" onclick="set_input_values(', $i, ');" id="href-', $i, '">Update</a></td>'; 220 240 echo "</tr>\n"; … … 318 338 <tr> 319 339 <td>Size:</td> 320 <td colspan=2> 321 <select name='size'><?php 322 for ($i = 10; $i <= 80; $i = $i + 10) { 323 echo "<option value='$i'"; 324 if($i == $avatar_options['size']) echo " selected"; 325 echo ">$i</option>"; 326 } 327 ?></select> px 340 <td><select name='size'><?php 341 for ($i = 10; $i <= 80; $i = $i + 10) { 342 echo "<option value='$i'"; 343 if($i == $avatar_options['size']) echo " selected"; 344 echo ">$i</option>"; 345 } 346 ?></select></td> 347 <td>px</td> 348 </tr> 349 <tr> 350 <td>Gravatar default:</td> 351 <td><?php echo get_avatar($avatar_options['wavatar']); ?></td> 352 <td> 353 <select name='wavatar'> 354 <option value="" <?php echo ($avatar_options['wavatar'] == '' ? 'selected' : ''); ?> >- none -</option> 355 <option value="wavatar" <?php echo ($avatar_options['wavatar'] == 'wavatar' ? 'selected' : ''); ?> >Wavatar</option> 356 <option value="monsterid" <?php echo ($avatar_options['wavatar'] == 'monsterid' ? 'selected' : ''); ?> >Monster ID</option> 357 <option value="identicon" <?php echo ($avatar_options['wavatar'] == 'identicon' ? 'selected' : ''); ?> >Identicon</option> 358 </select> 359 <br /> 360 <small>Give users without Global or Local avatars a unique avatar.</small> 328 361 </td> 329 362 </tr> 330 363 <tr> 331 364 <td>Default image:</td> 332 <td><?php echo get_avatar('default'); ?></td> 333 <td><input type='text' name='default' value='<?php echo $avatar_options['default']; ?>' size='70' /></td> 365 <td><?php echo get_avatar('', '', $avatar_options['default']); ?></td> 366 <td> 367 <input type='text' name='default' value='<?php echo $avatar_options['default']; ?>' size='70' /> 368 <br /> 369 <small>The default avatar (a working URI) for users without Global or Local avatars. Used for trackbacks.</small> 370 </td> 334 371 </tr> 335 372 <tr> … … 342 379 <td><input type="checkbox" name="in_posts" <?php echo $avatar_options['in_posts'] == 'on' ? 'checked' : ''; ?> /></td> 343 380 <td><small>Replaces </small><code><!-- avatar <b>e-mail</b> --></code><small> with an avatar for that email address in post content</small></td> 381 </tr> 382 <tr> 383 <td>Credit:</td> 384 <td><input type="checkbox" name="credit" <?php echo $avatar_options['credit'] == 'on' ? 'checked' : ''; ?> /></td> 385 <td><small>Includes an invisible credit to <a href='http://www.sterling-adventures.co.uk/' title='Sterling Adventures'>Sterling Adventures</a></small></td> 344 386 </tr> 345 387 </table> … … 352 394 <p>The function takes the following parameters:<br /> 353 395 <code><ol> 354 <li>Identifier; <code>NULL</code> (the currently logged in user), user ID (a blog user), e-mail address, or a comment object fromWordPress comment loop (for comments).</li>396 <li>Identifier; A blog user ID, an e-mail address, or a comment object from a WordPress comment loop (for comments).</li> 355 397 <li>Size (pixels); defaulted to value set above.</li> 356 <li>Default image if no public (global) or private (local) avatar found; defaulted to value set above.</li>398 <li>Default image if no Global (public) or Local (private) avatar found; defaulted to value set above.</li> 357 399 </ol></code></p> 358 400 <p>Apply format to the avatars with something like the following in your <code>style.css</code> theme file:<br /><ul> … … 369 411 370 412 413 // Add credit. 414 function avatar_footer() 415 { 416 global $avatar_options; 417 if($avatar_options['credit'] == 'on') echo '<div id="avatar_footer" style="display: none;"><a href="http://www.sterling-adventures.co.uk/blog/">Adventures</a></div>'; 418 } 419 420 371 421 // Add sub-menus... 372 422 function avatar_menu() { … … 410 460 add_action('admin_menu', 'avatar_menu'); 411 461 add_filter('the_content', 'generate_avatar_in_posts'); 462 add_action('wp_footer', 'avatar_footer'); 412 463 ?>
