Changeset 39565
- Timestamp:
- 04/10/08 11:34:50 (3 months ago)
- Files:
-
- add-local-avatar/trunk/avatars.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
add-local-avatar/trunk/avatars.php
r39491 r39565 5 5 Description: A plugin to manage public and private avatars. 6 6 Author: Peter Sterling 7 Version: 2.17 Version: 3.0 8 8 Changes: 0.1 - Initial version. 9 9 1.0 - Added pagination of users list. 10 10 2.0 - Added pagination of the commentors list too. 11 11 2.1 - Added example formatting information. 12 3.0 - Added ability to place avatars in written post content (plus other tweaks). 12 13 Author URI: http://www.sterling-adventures.co.uk/ 13 14 */ … … 20 21 'size' => '30', 21 22 'snapshots' => 'off', 23 'in_posts' => 'on', 22 24 'default' => '' 23 25 ); … … 28 30 // Main template tag - outputs the avatar (returns false if avatars are switched off)... 29 31 if(!function_exists('get_avatar')) : 30 function get_avatar($id_or_email, $size = '', $default = '' )32 function get_avatar($id_or_email, $size = '', $default = '', $post = false) 31 33 { 32 34 global $avatar_options; … … 83 85 } 84 86 87 // What class to apply to avatar images? 88 $class = ($post ? 'post_avatar no-rate' : 'avatar'); 89 85 90 // Try to use local avatar. 86 91 if($id) { 87 92 $local = get_usermeta($id, 'avatar'); 88 93 if(!empty($local)) { 89 $avatar = "<img alt='' src='{$local}' class=' avataravatar-{$size}' height='{$size}' width='{$size}' />";94 $avatar = "<img alt='' src='{$local}' class='{$class} avatar-{$size}' height='{$size}' width='{$size}' />"; 90 95 } 91 96 } … … 102 107 if(!empty($rating)) $out .= "&r={$rating}"; 103 108 104 $avatar = "<img alt='' src='{$out}' class=' avataravatar-{$size}' height='{$size}' width='{$size}' />";109 $avatar = "<img alt='' src='{$out}' class='{$class} avatar-{$size}' height='{$size}' width='{$size}' />"; 105 110 } else { 106 $avatar = "<img alt='' src='{$default}' class=' avataravatar-{$size} avatar-default' height='{$size}' width='{$size}'>";111 $avatar = "<img alt='' src='{$default}' class='{$class} avatar-{$size} avatar-default' height='{$size}' width='{$size}'>"; 107 112 } 108 113 } … … 138 143 'size' => $_POST['size'], 139 144 'snapshots' => $_POST['snapshots'], 145 'in_posts' => $_POST['in_posts'], 140 146 'default' => $_POST['default'] 141 147 ); 142 148 update_option('plugin_avatars', $options_update); 149 update_option('show_avatars', $_POST['show_avatars']); 150 update_option('avatar_rating', $_POST['avatar_rating']); 143 151 $msg = 'Options saved.'; 144 152 } … … 288 296 <table class='form-table'> 289 297 <tr> 298 <td><label for="show_avatars">Show avatars:</label><br /><small>Repeated from Settings » Discussion</small></td> 299 <td><input type="checkbox" name="show_avatars" <?php echo (get_option('show_avatars') ? 'checked' : ''); ?> /></td> 300 </tr> 301 <tr> 302 <td>Avatar rating:<br /><small>Repeated from Settings » Discussion</small></td> 303 <td> 304 <label><input type='radio' name='avatar_rating' value='G' <?php echo (get_option('avatar_rating') == 'G' ? 'checked="checked"' : ''); ?>> G — Suitable for all audiences</label><br /> 305 <label><input type='radio' name='avatar_rating' value='PG' <?php echo (get_option('avatar_rating') == 'PG' ? 'checked="checked"' : ''); ?>> PG — Possibly offensive, usually for audiences 13 and above</label><br /> 306 <label><input type='radio' name='avatar_rating' value='R' <?php echo (get_option('avatar_rating') == 'R' ? 'checked="checked"' : ''); ?>> R — Intended for adult audiences above 17</label><br /> 307 <label><input type='radio' name='avatar_rating' value='X' <?php echo (get_option('avatar_rating') == 'X' ? 'checked="checked"' : ''); ?>> X — Even more mature than above</label><br /> 308 </td> 309 </tr> 310 <tr> 290 311 <td><label for='size'>Size:</label></td> 291 312 <td> … … 305 326 <tr> 306 327 <td><label for="snapshots">Use Snapshots:</label></td> 307 <td><input type="checkbox" name="snapshots" <?php echo $avatar_options['snapshots'] == 'on' ? 'checked' : ''; ?> /></td> 328 <td><input type="checkbox" name="snapshots" <?php echo $avatar_options['snapshots'] == 'on' ? 'checked' : ''; ?> /> <small>if you have enabled <a href="http://www.snap.com">snapshots</a>, clearing this will disable them for avatar links</small></td> 329 </tr> 330 <tr> 331 <td><label for="in_posts">Replace <code><!-- avatar <b>e-mail</b> --></code> with avatar in posts:</label></td> 332 <td><input type="checkbox" name="in_posts" <?php echo $avatar_options['in_posts'] == 'on' ? 'checked' : ''; ?> /></td> 308 333 </tr> 309 334 </table> … … 316 341 <p>The function takes the following parameters:<br /> 317 342 <code><ol> 318 <li>Identifier; NULL (the currently logged in user), user ID (a blog user), or e-mail address (for comments etc.).</li>343 <li>Identifier; <code>NULL</code> (the currently logged in user), user ID (a blog user), e-mail address, or a comment object from WordPress comment loop (for comments).</li> 319 344 <li>Size (pixels); defaulted to value set above.</li> 320 345 <li>Default image if no public (global) or private (local) avatar found; defaulted to value set above.</li> 321 346 </ol></code></p> 322 <p>Apply format to the avatars with something like the following in in you <code>style.css</code> theme file:<br /> 323 <ul><code>.avatar { float:left; padding: 2px; margin: 0; border: 1px solid #ddd; background: white; }</code></ul></p> 347 <p>Apply format to the avatars with something like the following in your <code>style.css</code> theme file:<br /><ul> 348 <li>For comment avatars, <code>.avatar { float: left; padding: 2px; margin: 0; border: 1px solid #ddd; background: white; }</code></li> 349 <li>For avatars in post content, <code>.post_avatar { padding: 2px; margin: 0; border: 1px solid #ddd; background: white; }</code></li> 350 </ul></p> 324 351 <p>Examples for your theme's template files:<br /> 325 352 <ul> … … 337 364 338 365 366 // Replace <!-- avatar e-mail --> in post content with an avatar. 367 function generate_avatar_in_posts($content) 368 { 369 global $avatar_options; 370 371 // Is there content to work with? 372 if(!empty($content)) { 373 $matches = array(); 374 $replacement = array(); 375 $counter = 0; 376 377 // Look for all instances of <!-- avatar ??? --> in the content... 378 preg_match_all("/<!-- avatar ([^>]+) -->/", $content, $matches); 379 380 // For each instance, let's try to parse it... 381 foreach($matches['1'] as $email) { 382 // Check if we should replace with an avatar or with 'nothing' (to protect email addresses from prying eyes/robots. 383 if(!get_option('show_avatars') || $avatar_options['in_posts'] != 'on') $replacement[$counter] = ''; 384 else $replacement[$counter] = get_avatar($email, $avatar_options['size'], $avatar_options['default'], true); 385 $counter++; 386 } 387 388 // Replace... 389 for($i = 0; $i <= $counter; $i++) { 390 $content = str_replace($matches[0][$i], $replacement[$i], $content); 391 } 392 } 393 394 return $content; 395 } 396 397 339 398 // Hooks... 340 add_action ('admin_menu', 'avatar_menu');341 399 add_action('admin_menu', 'avatar_menu'); 400 add_filter('the_content', 'generate_avatar_in_posts'); 342 401 ?>
