IMP_Contacts_Image::getImage PHP Méthode

getImage() public méthode

Return the data representing the contact image.
public getImage ( integer $type ) : array
$type integer The image type.
Résultat array Array with the following keys: - desc: (string) Description. - url: (Horde_Url|Horde_Url_Data) URL object.
    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.');
    }

Usage Example

Exemple #1
0
 /**
  * AJAX action: Return the contacts images for a given e-mail address.
  *
  * Variables used:
  *   - addr: (string) The e-mail address.
  *
  * @return object  An object with the following properties:
  *   - avatar: (string) The URL of the avatar image.
  *   - flag: (string) The URL of the sender's country flag image.
  *   - flagname: (string) The name of the country of the sender.
  */
 public function getContactsImage()
 {
     $contacts_img = new IMP_Contacts_Image($this->vars->addr);
     $out = new stdClass();
     try {
         $res = $contacts_img->getImage($contacts_img::AVATAR);
         $out->avatar = strval($res['url']);
     } catch (IMP_Exception $e) {
     }
     try {
         $res = $contacts_img->getImage($contacts_img::FLAG);
         $out->flag = strval($res['url']);
         $out->flagname = $res['desc'];
     } catch (IMP_Exception $e) {
     }
     return $out;
 }
All Usage Examples Of IMP_Contacts_Image::getImage
IMP_Contacts_Image