Changeset 796325
- Timestamp:
- 10/31/2013 01:33:17 AM (12 years ago)
- Location:
- libravatar-replace/trunk
- Files:
-
- 4 added
- 1 deleted
- 2 edited
-
Services_Libravatar.php (deleted)
-
classes (added)
-
classes/LibravatarReplace.class.php (added)
-
classes/ServicesLibravatarExt.class.php (added)
-
classes/Services_Libravatar.class.php (added)
-
libravatar-replace.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libravatar-replace/trunk/libravatar-replace.php
r769849 r796325 5 5 * Plugin URI: http://code.sunchaser.info/libravatar 6 6 * Description: Libravatar support for WordPress and BuddyPress 7 * Version: 2.0. 37 * Version: 2.0.4 8 8 * Author: Christian Archer 9 9 * Author URI: https://sunchaser.info/ … … 19 19 } 20 20 21 require_once('Services_Libravatar.php'); 21 // if file exsists, require it. otherwise assume it's autoload 22 // WARNING: do not check class existance instead of file or you will crash WordPress if both Libravatar and Libravatar Replace are active 23 if (is_file(dirname(__FILE__) . '/classes/Services_Libravatar.class.php')) { 24 require_once(dirname(__FILE__) . '/classes/Services_Libravatar.class.php'); 25 } 22 26 23 /** 24 * Class LibravatarReplace 25 * 26 * everything for the plugin to work 27 */ 28 class LibravatarReplace 29 { 30 var $bp_catched_last_email; 31 32 /** 33 * @return bool true if the connection uses SSL 34 */ 35 function isSsl() 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 } 50 51 /** 52 * Change Avatar Defaults 53 * 54 * @param array $avatar_defaults 55 * @return mixed 56 */ 57 function filterAvatarDefaults($avatar_defaults) 58 { 59 $avatar_defaults['gravatar_default'] = __('Libravatar Logo'); // rename accordingly 60 return $avatar_defaults; 61 } 62 63 /** 64 * Update default avatar links so they will show defaults 65 * 66 * Can be removed when Libravatar will support forcedefault 67 * 68 * @param string $avatar_list 69 * @return string 70 */ 71 function filterDefaultAvatarSelect($avatar_list) 72 { 73 return preg_replace('~/[a-f0-9]{32}~', '/'.str_repeat('0', 32), $avatar_list); // fill hash with zeros 74 } 75 76 /** 77 * Create avatar link 78 * 79 * @param string $avatar 80 * @param string|int $id_or_email 81 * @param int $size 82 * @param string $default 83 * @param string $alt 84 * @return string avatar HTML 85 */ 86 function filterGetAvatar($avatar, $id_or_email, $size, $default, $alt) 87 { 88 if (false === $alt) 89 { 90 $safe_alt = ''; 91 } 92 else 93 { 94 $safe_alt = esc_attr($alt); 95 } 96 97 $email = ''; 98 if (is_numeric($id_or_email)) 99 { 100 $id = (int)$id_or_email; 101 $user = get_userdata($id); 102 if ($user) 103 { 104 $email = $user->user_email; 105 } 106 } 107 elseif (is_object($id_or_email)) 108 { 109 if (!empty($id_or_email->user_id)) 110 { 111 $id = (int)$id_or_email->user_id; 112 $user = get_userdata($id); 113 if ($user) 114 { 115 $email = $user->user_email; 116 } 117 } 118 elseif (!empty($id_or_email->comment_author_email)) 119 { 120 $email = $id_or_email->comment_author_email; 121 } 122 } 123 else 124 { 125 $email = $id_or_email; 126 } 127 128 $libravatar = new Services_Libravatar(); 129 $options = array(); 130 $options['s'] = $size; 131 $options['algorithm'] = 'md5'; 132 $options['https'] = $this->isSsl(); 133 if ($default && $default !== 'gravatar_default') 134 { 135 $options['d'] = $default; 136 } 137 $url = $libravatar->getUrl($email, $options); 138 139 $avatar = "<img alt='{$safe_alt}' src='{$url}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />"; 140 141 return $avatar; 142 } 143 144 /** 145 * There's no way to know email on the url composing so just remember the email in the previous filter 146 * 147 * @param $email 148 * @return mixed 149 */ 150 function filterBPCoreGravatarEmail($email) 151 { 152 $this->bp_catched_last_email = $email; 153 154 return $email; 155 } 156 157 /** 158 * Shitcode here :) 159 * 160 * Take the remembered email and get url from it, then extract the host 161 * Unfortunately there's no way to set Libravatar link with federation support more direct 162 * 163 * @param $host 164 * @return string 165 */ 166 function filterBPGravatarUrl($host) 167 { 168 $default_host = $this->isSsl() ? 'https://seccdn.libravatar.org/avatar/' : 'http://cdn.libravatar.org/avatar/'; 169 170 if (empty($this->bp_catched_last_email)) 171 { 172 return $default_host; 173 } 174 175 $libravatar = new Services_Libravatar(); 176 $options = array(); 177 $options['algorithm'] = 'md5'; 178 $options['https'] = $this->isSsl(); 179 $url = $libravatar->getUrl($this->bp_catched_last_email, $options); 180 181 preg_match('~^(.*/avatar/)~', $url, $matches); 182 183 return isset($matches[1]) ? $matches[1] : $default_host; 184 } 185 } 27 require_once dirname(__FILE__) . '/classes/ServicesLibravatarExt.class.php'; // Services_Libravatar custom extensions 28 require_once dirname(__FILE__) . '/classes/LibravatarReplace.class.php'; // main plugin class 186 29 187 30 $libravatar_replace = new LibravatarReplace(); -
libravatar-replace/trunk/readme.txt
r794044 r796325 22 22 <p>Just extract the plugin directory into your wp-content/plugins directory.</p> 23 23 24 = via Composer = =24 = via Composer = 25 25 26 26 (available since 2.0.3.1) … … 59 59 == Changelog == 60 60 61 = 2.0.4 = 62 * Some refactoring (move classes to the separate files) 63 * Now we use vanilla Services_Libravatar, created compatibility class ServicesLibravatarExt 64 61 65 = 2.0.3.1 = 62 66 * Build for WordPress SVN via Composer
Note: See TracChangeset
for help on using the changeset viewer.