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: * Generates a contact image to use for a given e-mail address.
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_Image
24: {
25: /* Image types. */
26: const AVATAR = 1;
27: const FLAG = 2;
28:
29: /**
30: * The e-mail address.
31: *
32: * @var string
33: */
34: protected $_email;
35:
36: /**
37: * Constructor.
38: *
39: * @param string $email The e-mail address.
40: */
41: public function __construct($email)
42: {
43: $this->_email = $email;
44: }
45:
46: /**
47: * Return the data representing the contact image.
48: *
49: * @param integer $type The image type.
50: *
51: * @return array Array with the following keys:
52: * - desc: (string) Description.
53: * - url: (Horde_Url|Horde_Url_Data) URL object.
54: *
55: * @throws IMP_Exception
56: */
57: public function getImage($type)
58: {
59: global $conf;
60:
61: if (!empty($conf['contactsimage']['backends'])) {
62: switch ($type) {
63: case self::AVATAR:
64: $func = 'avatarImg';
65: $type = 'IMP_Contacts_Avatar_Backend';
66: break;
67:
68: case self::FLAG:
69: $func = 'flagImg';
70: $type = 'IMP_Contacts_Flag_Backend';
71: break;
72: }
73:
74: foreach ($conf['contactsimage']['backends'] as $val) {
75: if (class_exists($val)) {
76: $backend = new $val();
77: if (($backend instanceof $type) &&
78: ($url = $backend->$func($this->_email))) {
79: return $url;
80: }
81: }
82: }
83: }
84:
85: throw new IMP_Exception('No backend found to generate contact image.');
86: }
87:
88: }
89: