Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mms] Add support for showing a contact image in the contacts popup b…
…ox in dynamic view.
- Loading branch information
Showing
13 changed files
with
391 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Copyright 2013 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (GPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/gpl. | ||
* | ||
* @category Horde | ||
* @copyright 2013 Horde LLC | ||
* @license http://www.fsf.org/copyleft/gpl.html GPL | ||
* @package IMP | ||
*/ | ||
|
||
/** | ||
* Generates a contact image to use for a given e-mail address. | ||
* | ||
* @author Michael Slusarz <slusarz@horde.org> | ||
* @category Horde | ||
* @copyright 2013 Horde LLC | ||
* @license http://www.horde.org/licenses/gpl GPL | ||
* @package IMP | ||
*/ | ||
class IMP_Contacts_Image | ||
{ | ||
/** | ||
* The e-mail address. | ||
* | ||
* @var string | ||
*/ | ||
protected $_email; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $email The e-mail address. | ||
*/ | ||
public function __construct($email) | ||
{ | ||
$this->_email = $email; | ||
} | ||
|
||
/** | ||
* URL. | ||
* | ||
* @return string URL. | ||
*/ | ||
public function __toString() | ||
{ | ||
return strval($this->getUrlOb()); | ||
} | ||
|
||
/** | ||
* Return a URL object representing the contact image. | ||
* | ||
* @return Horde_Url|Horde_Url_Data URL object | ||
* | ||
* @throws IMP_Exception | ||
*/ | ||
public function getUrlOb() | ||
{ | ||
global $conf; | ||
|
||
if (!empty($conf['contactsimage']['backends'])) { | ||
foreach ($conf['contactsimage']['backends'] as $val) { | ||
if (class_exists($val)) { | ||
$backend = new $val(); | ||
if (($url = $backend->rawImage($this->_email)) || | ||
($url = $backend->urlImage($this->_email))) { | ||
return $url; | ||
} | ||
} | ||
} | ||
} | ||
|
||
throw new IMP_Exception('No backend found to generate contact image.'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright 2013 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (GPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/gpl. | ||
* | ||
* @category Horde | ||
* @copyright 2013 Horde LLC | ||
* @license http://www.fsf.org/copyleft/gpl.html GPL | ||
* @package IMP | ||
*/ | ||
|
||
/** | ||
* Generate contact image by using local addressbook. | ||
* | ||
* @author Michael Slusarz <slusarz@horde.org> | ||
* @category Horde | ||
* @copyright 2013 Horde LLC | ||
* @license http://www.horde.org/licenses/gpl GPL | ||
* @package IMP | ||
*/ | ||
class IMP_Contacts_Image_Addressbook implements IMP_Contacts_Image_Backend | ||
{ | ||
/** | ||
*/ | ||
public function rawImage($email) | ||
{ | ||
global $injector, $registry; | ||
|
||
return null; | ||
|
||
if ($registry->hasMethod('contacts/search')) { | ||
$sparams = $injector->getInstance('IMP_Contacts')->getAddressbookSearchParams(); | ||
|
||
try { | ||
$res = $registry->call('contacts/search', array( | ||
$email, | ||
array( | ||
'customStrict' => array('email'), | ||
'fields' => array_fill_keys($sparams['sources'], array('email')), | ||
'returnFields' => array('photo', 'phototype'), | ||
'sources' => $sparams['sources'] | ||
) | ||
)); | ||
|
||
if (isset($res[$email][0]['photo'])) { | ||
return Horde_Url_Data::create( | ||
$res[$email][0]['photo'], | ||
$res[$email][0]['phototype'] | ||
); | ||
} | ||
} catch (Horde_Exception $e) {} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
*/ | ||
public function urlImage($email) | ||
{ | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Copyright 2013 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (GPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/gpl. | ||
* | ||
* @category Horde | ||
* @copyright 2013 Horde LLC | ||
* @license http://www.fsf.org/copyleft/gpl.html GPL | ||
* @package IMP | ||
*/ | ||
|
||
/** | ||
* Interface for a profile image backend. | ||
* | ||
* @author Michael Slusarz <slusarz@horde.org> | ||
* @category Horde | ||
* @copyright 2013 Horde LLC | ||
* @license http://www.horde.org/licenses/gpl GPL | ||
* @package IMP | ||
*/ | ||
interface IMP_Contacts_Image_Backend | ||
{ | ||
/** | ||
* Raw image data of a contact image. | ||
* | ||
* @param string $email An email address. | ||
* | ||
* @return array Null if image can't be generated. Otherwise, an array | ||
* with these keys: | ||
* <pre> | ||
* - data: (string) Image data. | ||
* - type: (string) MIME type of the image data. | ||
* </pre> | ||
*/ | ||
public function rawImage($email); | ||
|
||
/** | ||
* URL of the contact image. | ||
* | ||
* @param string $email An email address. | ||
* | ||
* @return Horde_Url Null if image can't be generated. Otherwise, the URL | ||
* of the contact image. | ||
*/ | ||
public function urlImage($email); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Copyright 2013 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (GPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/gpl. | ||
* | ||
* @category Horde | ||
* @copyright 2013 Horde LLC | ||
* @license http://www.fsf.org/copyleft/gpl.html GPL | ||
* @package IMP | ||
*/ | ||
|
||
/** | ||
* Generate contact image using the Gravatar service. | ||
* | ||
* @author Michael Slusarz <slusarz@horde.org> | ||
* @category Horde | ||
* @copyright 2013 Horde LLC | ||
* @license http://www.horde.org/licenses/gpl GPL | ||
* @package IMP | ||
*/ | ||
class IMP_Contacts_Image_Gravatar implements IMP_Contacts_Image_Backend | ||
{ | ||
/** | ||
*/ | ||
public function rawImage($email) | ||
{ | ||
if (class_exists('Horde_Service_Gravatar')) { | ||
$gravatar = new Horde_Service_Gravatar(); | ||
$data = $gravatar->fetchAvatar($email, array( | ||
'default' => 404, | ||
'size' => 80 | ||
)); | ||
rewind($data); | ||
$img_data = stream_get_contents($data); | ||
|
||
if (strlen($img_data)) { | ||
return Horde_Url_Data::create( | ||
'image/jpeg', | ||
$img_data | ||
); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
*/ | ||
public function urlImage($email) | ||
{ | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.