diff --git a/.gitignore b/.gitignore index 4306843d..2f024699 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.swp *.graffle .idea +*.iml # Useful files which should never be committed src/configs/override.ini diff --git a/src/configs/defaults.ini b/src/configs/defaults.ini index e3a8c302..fc324951 100644 --- a/src/configs/defaults.ini +++ b/src/configs/defaults.ini @@ -20,6 +20,7 @@ assetProtocol="" displaySignupLink="" displaySignupUrl="" enableBetaFeatures="0" +useGravatar=1 [secrets] passwordSalt="salt_for_passwords" diff --git a/src/configs/openphoto-vhost.conf b/src/configs/openphoto-vhost.conf index 2f296d36..b6e04989 100644 --- a/src/configs/openphoto-vhost.conf +++ b/src/configs/openphoto-vhost.conf @@ -22,6 +22,7 @@ AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/x-javascript + AddOutputFilterByType DEFLATE text/javascript BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html diff --git a/src/libraries/models/User.php b/src/libraries/models/User.php index 4e0d617f..ecbd2e37 100644 --- a/src/libraries/models/User.php +++ b/src/libraries/models/User.php @@ -101,10 +101,6 @@ class User extends BaseModel if(empty($email)) return; - $user = $this->getUserByEmail($email); - if(isset($user['attrprofilePhoto']) && !empty($user['attrprofilePhoto'])) - return $user['attrprofilePhoto']; - $utilityObj = new Utility; $protocol = $utilityObj->getProtocol(false); if(empty($this->config->site->cdnPrefix)) @@ -117,6 +113,14 @@ class User extends BaseModel $defaultUrl = sprintf('%s%s', $hostAndProtocol, $this->themeObj->asset('image', 'profile-default.png', false)); + $user = $this->getUserByEmail($email); + if(isset($user['attrprofilePhoto']) && !empty($user['attrprofilePhoto'])) + return $user['attrprofilePhoto']; + + // if gravatar support is disabled and no profile photo exists then we immediately return the default url + if ($this->config->site->useGravatar == 0) + return $defaultUrl; + if($protocol === 'https') $gravatarUrl = 'https://secure.gravatar.com/avatar/'; else diff --git a/src/tests/libraries/models/UserTest.php b/src/tests/libraries/models/UserTest.php index b4441ca3..798d00e8 100644 --- a/src/tests/libraries/models/UserTest.php +++ b/src/tests/libraries/models/UserTest.php @@ -19,7 +19,15 @@ class UserTest extends PHPUnit_Framework_TestCase $db->expects($this->any()) ->method('getUser') ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc', 'attrprofilePhoto' => 'http://foo/bar'))); + $themeObj = $this->getMock('ThemeObj', array('asset')); + $themeObj->expects($this->any()) + ->method('asset') + ->will($this->returnValue('/path/to/asset')); $this->user->inject('db', $db); + $this->user->inject('themeObj', $themeObj); + + $_SERVER['HTTP_HOST'] = 'foo'; + $res = $this->user->getAvatarFromEmail(50, 'test@example.com'); $this->assertEquals('http://foo/bar', $res); } @@ -34,8 +42,13 @@ class UserTest extends PHPUnit_Framework_TestCase $themeObj->expects($this->any()) ->method('asset') ->will($this->returnValue('/path/to/asset')); + $config = new stdClass; + $config->site = new stdClass; + $config->site->useGravatar = 1; + $this->user->inject('themeObj', $themeObj); $this->user->inject('db', $db); + $this->user->inject('config', $config); $_SERVER['HTTP_HOST'] = 'foo'; @@ -43,6 +56,30 @@ class UserTest extends PHPUnit_Framework_TestCase $this->assertEquals('http://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=50&d=http%3A%2F%2Ffoo%2Fpath%2Fto%2Fasset', $res); } + public function testGetAvatarFromEmailNoGravatar() + { + $db = $this->getMock('Db', array('getUser', 'postUser', 'putUser')); + $db->expects($this->any()) + ->method('getUser') + ->will($this->returnValue(array('id' => 'test@example.com', 'lastPhotoId' => 'abc'))); + $themeObj = $this->getMock('ThemeObj', array('asset')); + $themeObj->expects($this->any()) + ->method('asset') + ->will($this->returnValue('/path/to/asset')); + $config = new stdClass; + $config->site = new stdClass; + $config->site->useGravatar = 0; + + $this->user->inject('themeObj', $themeObj); + $this->user->inject('db', $db); + $this->user->inject('config', $config); + + $_SERVER['HTTP_HOST'] = 'foo'; + + $res = $this->user->getAvatarFromEmail(50, 'test@example.com'); + $this->assertEquals('http://foo/path/to/asset', $res); + } + public function testGetEmailAddressNonOAuth() { $session = $this->getMock('session', array('get'));