Skip to content

Commit

Permalink
Update Gravatar
Browse files Browse the repository at this point in the history
  • Loading branch information
HungNA - Technical Manager committed Oct 16, 2024
1 parent 9441051 commit 1bd1426
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jobs:
build:
strategy:
matrix:
operating-system: [ 'ubuntu-latest', 'ubuntu-20.04', 'ubuntu-22.04', 'macos-latest', 'macos-11', 'macos-12' ]
php-versions: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
operating-system: [ 'ubuntu-latest', 'macos-latest' ]
php-versions: [ '5.6', '7.0', 7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
Expand All @@ -15,7 +15,7 @@ jobs:
uses: shivammathur/setup-php@v2 # From https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, curl, json, openssl, iconv, bcmath, xml
extensions: mbstring, intl, curl, json, openssl, iconv, mcrypt, sodium, bcmath, xml
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
Expand All @@ -27,5 +27,5 @@ jobs:
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --no-dev --no-progress --prefer-dist --optimize-autoloader
- name: Test Gravatar with user nguyenanhung
- name: Testing Generated Gravatar
run: php ./test/test.php
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ composer.lock

tmp/*
!tmp/.htaccess
!tmp/.gitkeep
!tmp/.gitkeep
test.php
24 changes: 15 additions & 9 deletions helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* Date: 09/08/2021
* Time: 07:33
*/
if ( ! function_exists('gravatarUrlWithUsername')) {
if (!function_exists('gravatarUrlWithUsername')) {
/**
* Function gravatarUrlWithUsername
*
* @param string $username Username on Gravatar you need Get
* @param int $size Sizing of Gravatar Output
* @param string $cachePath /your/to/path for Save Cache
* @param string $username Username on Gravatar you need Get
* @param int $size Sizing of Gravatar Output
* @param string $cachePath /your/to/path for Save Cache
*
* @return string|null
* @author : 713uk13m <[email protected]>
Expand All @@ -32,12 +32,12 @@ function gravatarUrlWithUsername($username = 'nguyenanhung', $size = 300, $cache
return $gravatar->showAvatar($size);
}
}
if ( ! function_exists('gravatarUrlWithEmail')) {
if (!function_exists('gravatarUrlWithEmail')) {
/**
* Function gravatarUrlWithEmail
*
* @param string $email
* @param int $size
* @param string $email
* @param int $size
*
* @return string
* @author : 713uk13m <[email protected]>
Expand All @@ -46,7 +46,13 @@ function gravatarUrlWithUsername($username = 'nguyenanhung', $size = 300, $cache
*/
function gravatarUrlWithEmail($email = '[email protected]', $size = 300)
{
$email = md5($email);
return 'https://www.gravatar.com/avatar/' . $email . '?s=' . $size;
// Trim leading and trailing whitespace from
// an email address and force all characters
// to lower case
$address = strtolower(trim($email));

// Create an SHA256 hash of the final string
$hash = hash('sha256', $address);
return 'https://www.gravatar.com/avatar/' . $hash . '?s=' . $size;
}
}
11 changes: 3 additions & 8 deletions src/Gravatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class Gravatar
public function getProperties()
{
return array(
'username' => $this->username,
'username' => $this->username,
'cacheStatus' => $this->cacheStatus,
'cachePath' => $this->cachePath,
'jsonLink' => $this->jsonLink
'cachePath' => $this->cachePath,
'jsonLink' => $this->jsonLink
);
}

Expand All @@ -74,7 +74,6 @@ public function getProperties()
public function setUsername($username)
{
$this->username = trim($username);

return $this;
}

Expand All @@ -91,7 +90,6 @@ public function setUsername($username)
public function setCacheStatus($cacheStatus = false)
{
$this->cacheStatus = $cacheStatus;

return $this;
}

Expand All @@ -108,7 +106,6 @@ public function setCacheStatus($cacheStatus = false)
public function setCachePath($cachePath = '')
{
$this->cachePath = $cachePath;

return $this;
}

Expand Down Expand Up @@ -151,7 +148,6 @@ public function getData()
protected function requestToGravatar($url = '')
{
$respond = $this->sendRequest($url);

return json_decode($respond);
}

Expand Down Expand Up @@ -197,7 +193,6 @@ public function showAvatar($size = '300')
if (!empty($this->data)) {
return $this->data->entry[0]->thumbnailUrl . '?' . http_build_query(['size' => $size]);
}

return null;
}
}
6 changes: 3 additions & 3 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ trait Helper
/**
* Function sendRequest
*
* @param string $url
* @param array $params
* @param int $timeout
* @param string $url
* @param array $params
* @param int $timeout
*
* @return bool|string
* @author : 713uk13m <[email protected]>
Expand Down

0 comments on commit 1bd1426

Please sign in to comment.