diff --git a/library/Zend/View/Helper/Gravatar.php b/library/Zend/View/Helper/Gravatar.php index 1de9d90837a..a6f9b8cb81b 100644 --- a/library/Zend/View/Helper/Gravatar.php +++ b/library/Zend/View/Helper/Gravatar.php @@ -56,6 +56,13 @@ class Gravatar extends AbstractHtmlElement */ protected $email; + /** + * True or false if the email address passed is already an MD5 hash + * + * @var bool + */ + protected $emailIsHashed; + /** * Options * @@ -66,7 +73,6 @@ class Gravatar extends AbstractHtmlElement 'default_img' => self::DEFAULT_MM, 'rating' => self::RATING_G, 'secure' => null, - 'skip_email_hash' => false, ); /** @@ -136,7 +142,7 @@ public function setOptions(array $options) protected function getAvatarUrl() { $src = $this->getGravatarUrl() - . '/' . ($this->getSkipEmailHash() ? $this->getEmail() : md5($this->getEmail())) + . '/' . ($this->emailIsHashed ? $this->getEmail() : md5($this->getEmail())) . '?s=' . $this->getImgSize() . '&d=' . $this->getDefaultImg() . '&r=' . $this->getRating(); @@ -232,6 +238,7 @@ public function getDefaultImg() */ public function setEmail($email) { + $this->emailIsHashed = (bool) preg_match('/^[A-Za-z0-9]{32}$/', $email); $this->email = $email; return $this; } @@ -333,33 +340,6 @@ public function getSecure() return $this->options['secure']; } - /** - * Skip email hashing - * - * This is useful if you are using a webservice that provides you the - * gravatar hash (md5sum) of users' email addresses, but not the actual - * email addresses themselves. - * - * @param bool $flag - * @return Gravatar - */ - public function setSkipEmailHash($flag) - { - $this->options['skip_email_hash'] = $flag; - return $this; - } - - /** - * Returns if the helper should pass the email through md5() or not. - * - * @return boolean - */ - public function getSkipEmailHash() - { - return $this->options['skip_email_hash']; - } - - /** * Set src attrib for image. * diff --git a/tests/ZendTest/View/Helper/GravatarTest.php b/tests/ZendTest/View/Helper/GravatarTest.php index 04e3a8892c9..1b39c241405 100644 --- a/tests/ZendTest/View/Helper/GravatarTest.php +++ b/tests/ZendTest/View/Helper/GravatarTest.php @@ -92,7 +92,6 @@ public function testGetAndSetMethods() $this->helper->setDefaultImg('monsterid') ->setImgSize(150) ->setSecure(true) - ->setSkipEmailHash(true) ->setEmail("example@example.com") ->setAttribs($attribs) ->setRating('pg'); @@ -102,7 +101,6 @@ public function testGetAndSetMethods() $this->assertEquals($attribs, $this->helper->getAttribs()); $this->assertEquals(150, $this->helper->getImgSize()); $this->assertTrue($this->helper->getSecure()); - $this->assertTrue($this->helper->getSkipEmailHash()); } public function tesSetDefaultImg() @@ -190,15 +188,15 @@ public function testGravatarOptions() ); } - public function testSkipEmailHashingOptionTogglesMd5Hashing() + public function testPassingAnMd5HashSkipsMd5Hashing() { $this->assertNotContains( - 'b642b4217b34b1e8d3bd915fc65c4452', - $this->helper->__invoke('b642b4217b34b1e8d3bd915fc65c4452')->__toString() + 'test@test.com', + $this->helper->__invoke('test@test.com')->__toString() ); $this->assertContains( 'b642b4217b34b1e8d3bd915fc65c4452', - $this->helper->__invoke('b642b4217b34b1e8d3bd915fc65c4452', array('skip_email_hash' => true))->__toString() + $this->helper->__invoke('b642b4217b34b1e8d3bd915fc65c4452')->__toString() ); }