Changeset 415380
- Timestamp:
- 07/26/2011 01:30:24 PM (15 years ago)
- Location:
- libravatar/trunk
- Files:
-
- 2 edited
-
libravatar.php (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libravatar/trunk/libravatar.php
r410755 r415380 4 4 Plugin URI: http://www.gabsoftware.com/products/scripts/libravatar/ 5 5 Description: Libravatar support for Wordpress 6 Version: 1.0. 16 Version: 1.0.2 7 7 Author: Gabriel Hautclocq 8 8 Author URI: http://www.gabsoftware.com/ … … 25 25 define( 'LIBRAVATAR_VERSION_MAJ', 1 ); 26 26 define( 'LIBRAVATAR_VERSION_MIN', 0 ); 27 define( 'LIBRAVATAR_VERSION_REV', 1 ); 27 define( 'LIBRAVATAR_VERSION_REV', 2 ); 28 29 include_once( 'Services_Libravatar.php' ); 28 30 29 31 add_filter( 'get_avatar', 'libravatar_get_avatar_filter_callback', 10, 5 ); 30 32 add_filter( 'avatar_defaults', 'libravatar_avatar_defaults_filter_callback' ); 33 34 //return true if the connection uses SSL 35 function 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 } 31 50 32 51 function libravatar_avatar_defaults_filter_callback( $avatar_defaults ) … … 38 57 function libravatar_get_avatar_filter_callback( $avatar, $id_or_email, $size, $default, $alt ) 39 58 { 40 if( ! get_option( 'show_avatars' ))59 if( 'libravatar_default' == $default ) 41 60 { 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) 63 62 { 64 $ email = $user->user_email;63 $safe_alt = ''; 65 64 } 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 72 66 { 73 return false;67 $safe_alt = esc_attr( $alt ); 74 68 } 75 69 76 if( !empty($id_or_email->user_id) ) 70 $email = ''; 71 if( is_numeric( $id_or_email ) ) 77 72 { 78 $id = (int) $id_or_email ->user_id;73 $id = (int) $id_or_email; 79 74 $user = get_userdata( $id ); 80 75 if( $user ) … … 83 78 } 84 79 } 85 elseif( ! empty( $id_or_email->comment_author_email ) )80 elseif( is_object( $id_or_email ) ) 86 81 { 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' ) ); 94 84 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 } 101 98 } 102 99 else 103 100 { 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; 184 102 } 185 103 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}' />"; 191 113 } 192 114 … … 194 116 } 195 117 118 119 120 196 121 ?> -
libravatar/trunk/readme.txt
r410755 r415380 5 5 Requires at least: 3.0.0 6 6 Tested up to: 3.2 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 9 9 Adds Libravatar support to your WordPress installation. … … 38 38 == Changelog == 39 39 40 = 1.0.2 = 41 * Support for federation (self hosted avatars functionnality of Libravatar) 42 * Now uses the Services_Libravatar class from Libravatar 43 40 44 = 1.0.1 = 41 45 * Corrected invalid s query arg
Note: See TracChangeset
for help on using the changeset viewer.