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("registered gravatar in avatar_lookup hook");
19 * Removes the plugin hook
21 function gravatar_uninstall() {
22 unregister_hook('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup');
24 logger("unregistered gravatar in avatar_lookup hook");
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 = 'https://secure.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 = get_markup_template( "admin.tpl", "addon/gravatar/" );
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 // Check if Libravatar is enabled and show warning
85 $r = q("SELECT * FROM `addon` WHERE `name` = '%s' and `installed` = 1",
89 $o = '<h5>' .t('Information') .'</h5><p>' .t('Libravatar addon is installed, too. Please disable Libravatar addon or this Gravatar addon.<br>The Libravatar addon will fall back to Gravatar if nothing was found at Libravatar.') .'</p><br><br>';
92 // output Gravatar settings
93 $o .= '<input type="hidden" name="form_security_token" value="' .get_form_security_token("gravatarsave") .'">';
94 $o .= replace_macros( $t, array(
95 '$submit' => t('Save Settings'),
96 '$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),
97 '$rating' => array('rating', t('Rating of images'), $rating, t('Select the appropriate avatar rating for your site. See README'), $ratings),
102 * Save admin settings
104 function gravatar_plugin_admin_post (&$a) {
105 check_form_security_token('gravatarsave');
107 $default_avatar = ((x($_POST, 'avatar')) ? notags(trim($_POST['avatar'])) : 'identicon');
108 $rating = ((x($_POST, 'rating')) ? notags(trim($_POST['rating'])) : 'g');
109 set_config('gravatar', 'default_img', $default_avatar);
110 set_config('gravatar', 'rating', $rating);
111 info( t('Gravatar settings updated.') .EOL);