]> git.mxchange.org Git - friendica-addons.git/blob - gravatar/gravatar.php
Merge branch 'master', remote-tracking branch 'remotes/upstream/master'
[friendica-addons.git] / gravatar / gravatar.php
1 <?php
2 /**
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.
5  * Version: 1.0
6  * Author: Klaus Weidenbach <http://friendica.dszdw.net/profile/klaus>
7  */
8
9 /**
10  * Installs the plugin hook
11  */
12 function gravatar_install() {
13         register_hook('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup');
14
15         logger("installed gravatar");
16 }
17
18 /**
19  * Removes the plugin hook
20  */
21 function gravatar_uninstall() {
22         unregister_hook('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup');
23
24         logger("uninstalled gravatar");
25 }
26
27 /**
28  * Looks up the avatar at gravatar.com and returns the URL.
29  *
30  * @param $a array
31  * @param &$b array
32  */
33 function gravatar_lookup($a, &$b) {
34         $default_avatar = get_config('gravatar', 'default_img');
35         $rating = get_config('gravatar', 'rating');
36
37         // setting default value if nothing configured
38         if(! $default_avatar)
39                 $default_avatar = 'identicon'; // default image will be a random pattern
40         if(! $rating)
41                 $rating = 'g'; // suitable for display on all websites with any audience type
42
43         $hash = md5(trim(strtolower($b['email'])));
44
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;
49
50         $b['url'] = $url;       
51         $b['success'] = true;
52 }
53
54 /**
55  * Display admin settings for this addon
56  */
57 function gravatar_plugin_admin (&$a, &$o) {
58         $t = file_get_contents( dirname(__file__)."/admin.tpl");
59
60         $default_avatar = get_config('gravatar', 'default_img');
61         $rating = get_config('gravatar', 'rating');
62
63         // set default values for first configuration
64         if(! $default_avatar)
65                 $default_avatar = 'identicon'; // pseudo-random geometric pattern based on email hash
66         if(! $rating)
67                 $rating = 'g'; // suitable for display on all websites with any audience type
68
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'),
76         );
77         $ratings = array(
78                 'g' => 'g',
79                 'pg' => 'pg',
80                 'r' => 'r',
81                 'x' => 'x'
82         );
83
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),
89         ));
90 }
91
92 /**
93  * Save admin settings
94  */
95 function gravatar_plugin_admin_post (&$a) {
96         check_form_security_token('gravatarsave');
97
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);
103 }
104 ?>