Plugin Directory

Changeset 415380


Ignore:
Timestamp:
07/26/2011 01:30:24 PM (15 years ago)
Author:
GabSoftware
Message:

1.0.2: Federation support and Services_Libravatar class usage

Location:
libravatar/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libravatar/trunk/libravatar.php

    r410755 r415380  
    44 Plugin URI: http://www.gabsoftware.com/products/scripts/libravatar/
    55 Description: Libravatar support for Wordpress
    6  Version: 1.0.1
     6 Version: 1.0.2
    77 Author: Gabriel Hautclocq
    88 Author URI: http://www.gabsoftware.com/
     
    2525define( 'LIBRAVATAR_VERSION_MAJ', 1 );
    2626define( 'LIBRAVATAR_VERSION_MIN', 0 );
    27 define( 'LIBRAVATAR_VERSION_REV', 1 );
     27define( 'LIBRAVATAR_VERSION_REV', 2 );
     28
     29include_once( 'Services_Libravatar.php' );
    2830
    2931add_filter( 'get_avatar', 'libravatar_get_avatar_filter_callback', 10, 5 );
    3032add_filter( 'avatar_defaults', 'libravatar_avatar_defaults_filter_callback' );
     33
     34//return true if the connection uses SSL
     35function libravatar_is_ssl()
     36{
     37    if( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' )
     38    {
     39        return true;
     40    }
     41    elseif( $_SERVER['SERVER_PORT'] == 443 )
     42    {
     43        return true;
     44    }
     45    else
     46    {
     47        return false;
     48    }
     49}
    3150
    3251function libravatar_avatar_defaults_filter_callback( $avatar_defaults )
     
    3857function libravatar_get_avatar_filter_callback( $avatar, $id_or_email, $size, $default, $alt )
    3958{
    40     if( ! get_option( 'show_avatars' ) )
     59    if( 'libravatar_default' == $default )
    4160    {
    42         return false;
    43     }
    44 
    45     if( false === $alt)
    46     {
    47         $safe_alt = '';
    48     }
    49     else
    50     {
    51         $safe_alt = esc_attr( $alt );
    52     }
    53 
    54     if( !is_numeric( $size ) )
    55     $size = '96';
    56 
    57     $email = '';
    58     if( is_numeric( $id_or_email ) )
    59     {
    60         $id = (int) $id_or_email;
    61         $user = get_userdata( $id );
    62         if ( $user )
     61        if( false === $alt)
    6362        {
    64             $email = $user->user_email;
     63            $safe_alt = '';
    6564        }
    66     }
    67     elseif( is_object( $id_or_email ) )
    68     {
    69         // No avatar for pingbacks or trackbacks
    70         $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
    71         if( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) )
     65        else
    7266        {
    73             return false;
     67            $safe_alt = esc_attr( $alt );
    7468        }
    7569
    76         if( !empty($id_or_email->user_id) )
     70        $email = '';
     71        if( is_numeric( $id_or_email ) )
    7772        {
    78             $id = (int) $id_or_email->user_id;
     73            $id = (int) $id_or_email;
    7974            $user = get_userdata( $id );
    8075            if( $user )
     
    8378            }
    8479        }
    85         elseif( ! empty( $id_or_email->comment_author_email ) )
     80        elseif( is_object( $id_or_email ) )
    8681        {
    87             $email = $id_or_email->comment_author_email;
    88         }
    89     }
    90     else
    91     {
    92         $email = $id_or_email;
    93     }
     82            // No avatar for pingbacks or trackbacks
     83            $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
    9484
    95     if( empty( $default ) )
    96     {
    97         $avatar_default = get_option( 'avatar_default' );
    98         if( empty( $avatar_default ) )
    99         {
    100             $default = 'mystery';
     85            if( ! empty( $id_or_email->user_id ) )
     86            {
     87                $id = (int) $id_or_email->user_id;
     88                $user = get_userdata( $id );
     89                if( $user)
     90                {
     91                    $email = $user->user_email;
     92                }
     93            }
     94            elseif( ! empty( $id_or_email->comment_author_email ) )
     95            {
     96                $email = $id_or_email->comment_author_email;
     97            }
    10198        }
    10299        else
    103100        {
    104             $default = $avatar_default;
    105         }
    106     }
    107 
    108     if( ! empty( $email ) )
    109     {
    110         $email_hash = md5( strtolower( $email ) );
    111     }
    112 
    113     if( 'libravatar_default' == $default )
    114     {
    115         if( is_ssl() )
    116         {
    117             $host = 'https://seccdn.libravatar.org';
    118         }
    119         else
    120         {
    121             $host = 'http://cdn.libravatar.org';
    122         }
    123     }
    124     else
    125     {
    126         if( is_ssl() )
    127         {
    128             $host = 'https://secure.gravatar.com';
    129         }
    130         else
    131         {
    132             if( ! empty( $email ) )
    133             {
    134                 $host = sprintf( 'http://%d.gravatar.com', ( hexdec( $email_hash[0] ) % 2 ) );
    135             }
    136             else
    137             {
    138                 $host = 'http://0.gravatar.com';
    139             }
    140         }
    141     }
    142 
    143     if( 'mystery' == $default )
    144     {
    145         $default = "{$host}/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
    146     }
    147     elseif( 'blank' == $default )
    148     {
    149         $default = includes_url('images/blank.gif');
    150     }
    151     elseif( ! empty( $email ) && ( 'gravatar_default' == $default || 'libravatar_default' == $default ) )
    152     {
    153         $default = '';
    154     }
    155     elseif( 'gravatar_default' == $default )
    156     {
    157         $default = "{$host}/avatar/?s={$size}";
    158     }
    159     elseif( 'libravatar_default' == $default )
    160     {
    161         $default = "{$host}/avatar/98000a49cdfabb01ab80d1509a17f3dfcc7dec9b27d38c899ebd6c392da1893a?s={$size}"; // 98000a49cdfabb01ab80d1509a17f3dfcc7dec9b27d38c899ebd6c392da1893a == sha256('unknown@libravatar.org')
    162     }
    163     elseif( empty( $email ) )
    164     {
    165         $default = "{$host}/avatar/?d={$default}&s={$size}";
    166     }
    167     elseif( strpos( $default, 'http://' ) === 0 )
    168     {
    169         $default = add_query_arg( 's', $size, $default );
    170     }
    171 
    172     if( ! empty( $email ) )
    173     {
    174         $out = "{$host}/avatar/";
    175         $out .= $email_hash;
    176         $out .= '?s='.$size;
    177         $out .= '&d=' . urlencode( $default );
    178 
    179 
    180         $rating = get_option( 'avatar_rating' );
    181         if( ! empty( $rating ) )
    182         {
    183             $out .= "&r={$rating}";
     101            $email = $id_or_email;
    184102        }
    185103
    186         $avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
    187     }
    188     else
    189     {
    190         $avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
     104        $libravatar = new Services_Libravatar();
     105        $options = array();
     106        $options['s'] = $size;
     107        $options['algorithm'] = 'md5';
     108        $options['https'] = libravatar_is_ssl();
     109        //$options['d'] = ( $options['https'] == true ? 'https://sec' : 'http://' ) . 'cdn.libravatar.org/nobody/60.png';
     110        $url = $libravatar->url( $email, $options );
     111
     112        $avatar = "<img alt='{$safe_alt}' src='{$url}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
    191113    }
    192114
     
    194116}
    195117
     118
     119
     120
    196121?>
  • libravatar/trunk/readme.txt

    r410755 r415380  
    55Requires at least: 3.0.0
    66Tested up to: 3.2
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88
    99Adds Libravatar support to your WordPress installation.
     
    3838== Changelog ==
    3939
     40= 1.0.2 =
     41* Support for federation (self hosted avatars functionnality of Libravatar)
     42* Now uses the Services_Libravatar class from Libravatar
     43
    4044= 1.0.1 =
    4145* Corrected invalid s query arg
Note: See TracChangeset for help on using the changeset viewer.