3 * Name: Gravatar Support
4 * Description: If there is no avatar image for a new user or contact this plugin will look for one at Gravatar.
6 * Author: Klaus Weidenbach <http://friendica.dszdw.net/profile/klaus>
10 * Installs the plugin hook
12 function gravatar_install() {
13 register_hook('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup');
15 logger("installed gravatar");
19 * Removes the plugin hook
21 function gravatar_uninstall() {
22 unregister_hook('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup');
24 logger("uninstalled gravatar");
28 * Looks up the avatar at gravatar.com and returns the URL.
33 function gravatar_lookup($a, &$b) {
34 $default_avatar = get_config('gravatar', 'default_img');
35 $rating = get_config('gravatar', 'rating');
37 // setting default value if nothing configured
39 $default_avatar = 'identicon'; // default image will be a random pattern
41 $rating = 'g'; // suitable for display on all websites with any audience type
43 $hash = md5(trim(strtolower($b['email'])));
45 $url = 'http://www.gravatar.com/avatar/' .$hash .'.jpg';
46 $url .= '?s=' .$b['size'] .'&r=' .$rating;
47 if ($default_avatar != "gravatar")
48 $url .= '&d=' .$default_avatar;
55 * Display admin settings for this addon
57 function gravatar_plugin_admin (&$a, &$o) {
58 $t = file_get_contents( dirname(__file__)."/admin.tpl");
60 $default_avatar = get_config('gravatar', 'default_img');
61 $rating = get_config('gravatar', 'rating');
63 // set default values for first configuration
65 $default_avatar = 'identicon'; // pseudo-random geometric pattern based on email hash
67 $rating = 'g'; // suitable for display on all websites with any audience type
69 // Available options for the select boxes
70 $default_avatars = array(
71 'mm' => t('generic profile image'),
72 'identicon' => t('random geometric pattern'),
73 'monsterid' => t('monster face'),
74 'wavatar' => t('computer generated face'),
75 'retro' => t('retro arcade style face'),
84 $o = '<input type="hidden" name="form_security_token" value="' .get_form_security_token("gravatarsave") .'">';
85 $o .= replace_macros( $t, array(
86 '$submit' => t('Submit'),
87 '$default_avatar' => array('avatar', t('Default avatar image'), $default_avatar, t('Select default avatar image if none was found at Gravatar. See README'), $default_avatars),
88 '$rating' => array('rating', t('Rating of images'), $rating, t('Select the appropriate avatar rating for your site. See README'), $ratings),
95 function gravatar_plugin_admin_post (&$a) {
96 check_form_security_token('gravatarsave');
98 $default_avatar = ((x($_POST, 'avatar')) ? notags(trim($_POST['avatar'])) : 'identicon');
99 $rating = ((x($_POST, 'rating')) ? notags(trim($_POST['rating'])) : 'g');
100 set_config('gravatar', 'default_img', $default_avatar);
101 set_config('gravatar', 'rating', $rating);
102 info( t('Gravatar settings updated.') .EOL);