Changeset 44757

Show
Ignore:
Timestamp:
05/07/08 18:56:54 (2 months ago)
Author:
peterwsterling
Message:

wavatar & credit

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • add-local-avatar/trunk/avatars.php

    r40975 r44757  
    55      Description:      A plugin to manage public and private avatars. 
    66      Author:                 Peter Sterling 
    7       Version:          3.2 
     7      Version:          4.1 
    88      Changes:          0.1 - Initial version. 
    99                              1.0 - Added pagination of users list. 
    10                               2.0 - Added pagination of the commentors list too. 
     10                              2.0 - Added pagination of the commenters list too. 
    1111                              2.1 - Added example formatting information. 
    1212                              3.0 - Added ability to place avatars in written post content (plus other tweaks). 
    1313                              3.1 - Minor tweaks to usage text and options. 
    1414                              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. 
    1518      Author URI:       http://www.sterling-adventures.co.uk/ 
    1619*/ 
     
    2427            'snapshots' => 'off', 
    2528            'in_posts' => 'on', 
     29            'wavatar' => '', 
     30            'credit' => 'on', 
    2631            'default' => '' 
    2732      ); 
     33      update_option('plugin_avatars', $avatar_options); 
     34} 
     35if(!isset($avatar_options['credit'])) { 
     36      $avatar_options['credit'] = 'on'; 
    2837      update_option('plugin_avatars', $avatar_options); 
    2938} 
     
    3645      global $avatar_options; 
    3746 
    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... 
    5263            $id = (int) $id_or_email; 
    5364            $user = get_userdata($id); 
     
    5869            } 
    5970      } 
    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... 
    6273                  $id = (int) $id_or_email->user_id; 
    6374                  $user = get_userdata($id); 
     
    6778                        $url = $user->user_url; 
    6879                  } 
    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': 
    7887                        $url_array = parse_url($id_or_email->comment_author_url); 
    7988                        $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; 
    85103            $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. 
    87105      } 
    88106 
     
    93111      if($id) { 
    94112            $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 .= '&amp;d=' . urlencode($default)
    107        
    108                  $rating = get_option('avatar_rating'); 
    109                  if(!empty($rating)) $out .= "&amp;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 .= '&amp;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 .= "&amp;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. 
    118136      if(!empty($url) && $url != 'http://' && !is_admin()) $avatar = "<a alt='Avatar' href='" . attribute_escape($url) . "' title='" . (empty($name) ? '' : "Visit $name&rsquo;s website.") . "' " . ($avatar_options['snapshots'] == 'on' ? '>' : "class='snap_noshots'>") . $avatar . "</a>"; 
    119137 
     
    127145function manage_avatar_cache() 
    128146{ 
    129       global $wpdb
     147      global $wpdb, $avatar_options
    130148 
    131149      $msg = ''; 
     
    146164                  'snapshots' => $_POST['snapshots'], 
    147165                  'in_posts' => $_POST['in_posts'], 
     166                  'wavatar' => $_POST['wavatar'], 
     167                  'credit' => $_POST['credit'], 
    148168                  'default' => $_POST['default'] 
    149169            ); 
     
    172192            <p> 
    173193                  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 bevaiour of the avatar plugin.<br /> 
     194                  Control the behaviour of the avatar plug-in.<br /> 
    175195            </p> 
    176196            <h3>User Avatars</h3> 
     
    203223            <table class='widefat'> 
    204224                  <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> 
    206226                  </thead> 
    207227                  <tbody> 
     
    214234                              echo '<td>', $user->first_name, ' ', $user->last_name, (empty($user->nickname) ? '-' : ' (' . $user->nickname . ')'), '</a></td>'; 
    215235                              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>'; 
    217237                              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>'; 
    219239                              echo '<td><a href="?page=avatars.php&user_id=', $id, '" class="edit" onclick="set_input_values(', $i, ');" id="href-', $i, '">Update</a></td>'; 
    220240                              echo "</tr>\n"; 
     
    318338                        <tr> 
    319339                              <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> 
    328361                              </td> 
    329362                        </tr> 
    330363                        <tr> 
    331364                              <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> 
    334371                        </tr> 
    335372                        <tr> 
     
    342379                              <td><input type="checkbox" name="in_posts" <?php echo $avatar_options['in_posts'] == 'on' ? 'checked' : ''; ?> /></td> 
    343380                              <td><small>Replaces </small><code>&lt;!-- avatar <b>e-mail</b> --&gt;</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> 
    344386                        </tr> 
    345387                  </table> 
     
    352394            <p>The function takes the following parameters:<br /> 
    353395            <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 from WordPress 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> 
    355397                  <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> 
    357399            </ol></code></p> 
    358400            <p>Apply format to the avatars with something like the following in your <code>style.css</code> theme file:<br /><ul> 
     
    369411 
    370412 
     413// Add credit. 
     414function 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 
    371421// Add sub-menus... 
    372422function avatar_menu() { 
     
    410460add_action('admin_menu', 'avatar_menu'); 
    411461add_filter('the_content', 'generate_avatar_in_posts'); 
     462add_action('wp_footer', 'avatar_footer'); 
    412463?>