1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Contacts_Avatar_Addressbook implements IMP_Contacts_Avatar_Backend
24: {
25: 26:
27: public function avatarImg($email)
28: {
29: global $injector, $registry;
30:
31: if ($registry->hasMethod('contacts/search')) {
32: $contacts = $injector->getInstance('IMP_Contacts');
33:
34: try {
35: $res = $registry->call('contacts/search', array(
36: $email,
37: array(
38: 'customStrict' => array('email'),
39: 'fields' => array_fill_keys($contacts->sources, array('email')),
40: 'returnFields' => array('photo', 'phototype'),
41: 'sources' => $contacts->sources
42: )
43: ));
44:
45: if (isset($res[$email][0]['photo'])) {
46: try {
47: $img = $injector->getInstance('Horde_Core_Factory_Image')->create();
48: $img->loadString($res[$email][0]['photo']['load']['data']);
49: $img->resize(80, 80, true);
50:
51: $data = $img->raw(true);
52: $type = $img->getContentType();
53: } catch (Horde_Exception $e) {
54: $data = $res[$email][0]['photo']['load']['data'];
55: $type = $res[$email][0]['phototype'];
56: }
57:
58: return array(
59: 'desc' => '',
60: 'url' => Horde_Url_Data::create($type, $data)
61: );
62: }
63: } catch (Horde_Exception $e) {}
64: }
65:
66: return null;
67: }
68:
69: }
70: