1: <?php
2: /**
3: * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2013-2014 Horde LLC
10: * @license http://www.fsf.org/copyleft/gpl.html GPL
11: * @package IMP
12: */
13:
14: /**
15: * Generate contact avatar image using the Gravatar service.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2013-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Contacts_Avatar_Gravatar implements IMP_Contacts_Avatar_Backend
24: {
25: /**
26: */
27: public function avatarImg($email)
28: {
29: if (class_exists('Horde_Service_Gravatar')) {
30: $gravatar = new Horde_Service_Gravatar(
31: Horde_Service_Gravatar::STANDARD,
32: $GLOBALS['injector']->getInstance('Horde_Http_Client')
33: );
34:
35: $data = $gravatar->fetchAvatar($email, array(
36: 'default' => 404,
37: 'size' => 80
38: ));
39:
40: if (!is_null($data)) {
41: rewind($data);
42: $img_data = stream_get_contents($data);
43:
44: if (strlen($img_data)) {
45: return array(
46: 'desc' => '',
47: 'url' => Horde_Url_Data::create('image/jpeg', $img_data)
48: );
49: }
50: }
51: }
52:
53: return null;
54: }
55:
56: }
57: