Skip to content

Commit

Permalink
[mms] Change second parameter to getAvatarUrl() and fetchAvatar() to …
Browse files Browse the repository at this point in the history
…an array so that additional options can be provided.
  • Loading branch information
slusarz committed Oct 4, 2013
1 parent 9c74bb2 commit 8129a59
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 20 additions & 11 deletions framework/Service_Gravatar/lib/Horde/Service/Gravatar.php
Expand Up @@ -93,21 +93,30 @@ public function getId($mail)
* returned URL can be directly used with an IMG tag e.g.:
* <img src="http://www.gravatar.com/avatar/hash" />
*
* @param string $mail The mail address.
* @param integer $size An optional size parameter. Valid values are
* between 1 and 512.
* @param string $mail The mail address.
* @param mixed $opts Additional options. If an integer, treated as the
* 'size' option. If an array, the following options
* are available:
* <pre>
* - size: (integer) Image size. Valid values are between 1 and 512.
* </pre>
*
* @return Horde_Url The image URL.
*/
public function getAvatarUrl($mail, $size = null)
public function getAvatarUrl($mail, $opts = array())
{
if (!empty($size) && ($size < 1 || $size > 512)) {
if (is_integer($opts)) {
$opts = array('size' => $opts);
}

if (!empty($opts['size']) &&
(($opts['size'] < 1) || ($opts['size'] > 512))) {
throw InvalidArgumentException('The size parameter is out of bounds');
}

$url = new Horde_Url($this->_base . '/avatar/' . $this->getId($mail));
if ($size) {
$url->add('s', $size);
if (!empty($opts['size'])) {
$url->add('s', $opts['size']);
}

return $url;
Expand Down Expand Up @@ -153,14 +162,14 @@ public function getProfile($mail)
/**
* Fetch the avatar image.
*
* @param string $mail The mail address.
* @param integer $size An optional size parameter.
* @param string $mail The mail address.
* @param mixed $opts Additional options. See getAvatarUrl().
*
* @return resource The image as stream resource.
*/
public function fetchAvatar($mail, $size = null)
public function fetchAvatar($mail, $opts = array())
{
return $this->_client->get($this->getAvatarUrl($mail, $size))->getStream();
return $this->_client->get($this->getAvatarUrl($mail, $opts))->getStream();
}

}
2 changes: 2 additions & 0 deletions framework/Service_Gravatar/package.xml
Expand Up @@ -22,6 +22,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Change second parameter to getAvatarUrl() and fetchAvatar() to an array so that additional options can be provided.
* [mms] getAvatarUrl() now returns a Horde_Url object.
* Initial release.
</notes>
Expand Down Expand Up @@ -125,6 +126,7 @@
<date>2012-11-19</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Change second parameter to getAvatarUrl() and fetchAvatar() to an array so that additional options can be provided.
* [mms] getAvatarUrl() now returns a Horde_Url object.
* Initial release.
</notes>
Expand Down

0 comments on commit 8129a59

Please sign in to comment.