public function getImage($type)
{
global $conf, $injector;
if (!empty($conf['contactsimage']['backends'])) {
switch ($type) {
case self::AVATAR:
$func = 'avatarImg';
$type = 'IMP_Contacts_Avatar_Backend';
break;
case self::FLAG:
$func = 'flagImg';
$type = 'IMP_Contacts_Flag_Backend';
break;
}
$cache = $injector->getInstance('Horde_Cache');
$pack = $injector->getInstance('Horde_Pack');
$cache_id = implode('|', array('imp_avatar_email', $type, $this->_email));
if ($url = $cache->get($cache_id, 0)) {
try {
return $pack->unpack($url);
} catch (Horde_Pack_Exception $e) {
}
}
foreach ($conf['contactsimage']['backends'] as $val) {
if (class_exists($val)) {
$backend = new $val();
if ($backend instanceof $type && ($url = $backend->{$func}($this->_email))) {
$cache->set($cache_id, $pack->pack($url), $this->cache_timeout);
return $url;
}
}
}
}
throw new IMP_Exception('No backend found to generate contact image.');
}