4150 |
4150 |
4151 /** |
4151 /** |
4152 * Generates a URL for the avatar for the given user ID and avatar type. |
4152 * Generates a URL for the avatar for the given user ID and avatar type. |
4153 * @param int User ID |
4153 * @param int User ID |
4154 * @param string Image type - must be one of jpg, png, or gif. |
4154 * @param string Image type - must be one of jpg, png, or gif. |
|
4155 * @param string User's e-mail address, makes Special:Avatar redirect if not specified |
4155 * @return string |
4156 * @return string |
4156 */ |
4157 */ |
4157 |
4158 |
4158 function make_avatar_url($user_id, $avi_type) |
4159 function make_avatar_url($user_id, $avi_type, $user_email = false) |
4159 { |
4160 { |
4160 static $img_types = array( |
4161 static $img_types = array( |
4161 'png' => IMAGE_TYPE_PNG, |
4162 'png' => IMAGE_TYPE_PNG, |
4162 'gif' => IMAGE_TYPE_GIF, |
4163 'gif' => IMAGE_TYPE_GIF, |
4163 'jpg' => IMAGE_TYPE_JPG |
4164 'jpg' => IMAGE_TYPE_JPG, |
|
4165 'grv' => IMAGE_TYPE_GRV |
4164 ); |
4166 ); |
4165 |
4167 |
4166 if ( !is_int($user_id) ) |
4168 if ( !is_int($user_id) ) |
4167 return false; |
4169 return false; |
4168 if ( !isset($img_types[$avi_type]) ) |
4170 if ( !isset($img_types[$avi_type]) ) |
4169 return false; |
4171 return false; |
4170 $avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type; |
4172 |
4171 if ( !file_exists(ENANO_ROOT . $avi_relative_path) ) |
4173 if ( $avi_type == 'grv' ) |
4172 { |
4174 { |
4173 return ''; |
4175 if ( $user_email ) |
|
4176 { |
|
4177 return make_gravatar_url($user_email); |
|
4178 } |
|
4179 } |
|
4180 else |
|
4181 { |
|
4182 $avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type; |
|
4183 if ( !file_exists(ENANO_ROOT . $avi_relative_path) ) |
|
4184 { |
|
4185 return ''; |
|
4186 } |
4174 } |
4187 } |
4175 |
4188 |
4176 $img_type = $img_types[$avi_type]; |
4189 $img_type = $img_types[$avi_type]; |
4177 |
4190 |
4178 $dateline = @filemtime(ENANO_ROOT . $avi_relative_path); |
4191 $dateline = @filemtime(ENANO_ROOT . $avi_relative_path); |
4179 $avi_id = pack('VVv', $dateline, $user_id, $img_type); |
4192 $avi_id = pack('VVv', $dateline, $user_id, $img_type); |
4180 $avi_id = hexencode($avi_id, '', ''); |
4193 $avi_id = hexencode($avi_id, '', ''); |
4181 |
4194 |
4182 // return scriptPath . $avi_relative_path; |
4195 // return scriptPath . $avi_relative_path; |
4183 return makeUrlNS('Special', "Avatar/$avi_id"); |
4196 return makeUrlNS('Special', "Avatar/$avi_id"); |
|
4197 } |
|
4198 |
|
4199 /** |
|
4200 * Generates a URL to the Gravatar for a user based on his/her e-mail address. |
|
4201 * @param string E-mail address |
|
4202 * @param int Size - defaults to site-wide limits |
|
4203 * @return string URL |
|
4204 */ |
|
4205 |
|
4206 function make_gravatar_url($email, $size = false) |
|
4207 { |
|
4208 $email = md5($email); |
|
4209 |
|
4210 // gravatar parameters |
|
4211 if ( $size ) |
|
4212 { |
|
4213 $max_size = intval($size); |
|
4214 } |
|
4215 else |
|
4216 { |
|
4217 $max_x = intval(getConfig('avatar_max_width', '150')); |
|
4218 $max_y = intval(getConfig('avatar_max_height', '150')); |
|
4219 // ?s= |
|
4220 $max_size = ( $max_x > $max_y ) ? $max_y : $max_x; |
|
4221 } |
|
4222 |
|
4223 // ?r= |
|
4224 $rating = getConfig('gravatar_rating', 'g'); |
|
4225 |
|
4226 // final URL |
|
4227 $url = "http://www.gravatar.com/avatar/$email?r=$rating&s=$max_size"; |
|
4228 |
|
4229 return $url; |
4184 } |
4230 } |
4185 |
4231 |
4186 /** |
4232 /** |
4187 * Determines an image's filetype based on its signature. |
4233 * Determines an image's filetype based on its signature. |
4188 * @param string Path to image file |
4234 * @param string Path to image file |