-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de90161
commit 8990e27
Showing
6 changed files
with
86 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
{ | ||
"name": "bear8421/gravatar", | ||
"type": "library", | ||
"description": "Simple Gravatar", | ||
"keywords": [ | ||
"gravatar", | ||
"bear", | ||
"helper", | ||
"php" | ||
], | ||
"homepage": "https://github.com/bear8421/gravatar", | ||
"license": "MIT", | ||
"minimum-stability": "stable", | ||
"authors": [ | ||
{ | ||
"name": "Nguyen An Hung", | ||
"email": "[email protected]", | ||
"homepage": "https://nguyenanhung.com", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.6", | ||
"ext-curl": "*", | ||
"ext-json": "*", | ||
"nguyenanhung/php-file-cache": "^1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Bear8421\\Helper\\Gravatar\\": "src/" | ||
}, | ||
"files": [ | ||
"helpers/helpers.php" | ||
] | ||
"name": "bear8421/gravatar", | ||
"type": "library", | ||
"description": "Simple Gravatar", | ||
"keywords": [ | ||
"gravatar", | ||
"bear", | ||
"helper", | ||
"php" | ||
], | ||
"homepage": "https://github.com/bear8421/gravatar", | ||
"license": "MIT", | ||
"minimum-stability": "stable", | ||
"authors": [ | ||
{ | ||
"name": "Nguyen An Hung", | ||
"email": "[email protected]", | ||
"homepage": "https://nguyenanhung.com", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.6", | ||
"ext-curl": "*", | ||
"ext-json": "*", | ||
"nguyenanhung/php-file-cache": "^1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Bear8421\\Helper\\Gravatar\\": "src/" | ||
}, | ||
"files": [ | ||
"helpers/helpers.php" | ||
] | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* Project my-gravatar | ||
* Created by PhpStorm | ||
|
@@ -7,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]> | ||
|
@@ -28,16 +29,15 @@ function gravatarUrlWithUsername($username = 'nguyenanhung', $size = 300, $cache | |
$gravatar->setCacheStatus(true)->setCachePath($cachePath); | ||
} | ||
$gravatar->init(); | ||
|
||
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]> | ||
|
@@ -47,7 +47,6 @@ 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; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -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]> | ||
|
@@ -34,23 +34,22 @@ trait Helper | |
protected function sendRequest($url = '', $params = array(), $timeout = 30) | ||
{ | ||
$endpoint = $url . '?' . http_build_query($params); | ||
$curl = curl_init(); | ||
$curl = curl_init(); | ||
curl_setopt_array($curl, array( | ||
CURLOPT_URL => $endpoint, | ||
CURLOPT_URL => $endpoint, | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => $timeout, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => $timeout, | ||
CURLOPT_FOLLOWLOCATION => true, | ||
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2, | ||
CURLOPT_CUSTOMREQUEST => "GET", | ||
CURLOPT_HTTPHEADER => array( | ||
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2, | ||
CURLOPT_CUSTOMREQUEST => "GET", | ||
CURLOPT_HTTPHEADER => array( | ||
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15' | ||
), | ||
)); | ||
$result = curl_exec($curl); | ||
curl_close($curl); | ||
|
||
return $result; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
|
||
/** | ||
* Project spreadsheets-basic | ||
* Project gravatar | ||
* Created by PhpStorm | ||
* User: 713uk13m <[email protected]> | ||
* Copyright: 713uk13m <[email protected]> | ||
|
@@ -12,9 +13,11 @@ | |
use Bear8421\Helper\Gravatar\Gravatar; | ||
|
||
$gravatar = new Gravatar(); | ||
$gravatar->setUsername('nguyenanhung')->setCacheStatus(true)->setCachePath(__DIR__ . '/../tmp')->init(); | ||
$gravatar->setUsername('nguyenanhung') | ||
->setCacheStatus(true) | ||
->setCachePath(__DIR__ . '/../tmp')->init(); | ||
|
||
echo "Avatar URL: " . $gravatar->showAvatar(300) . PHP_EOL; | ||
echo "Avatar Data: " . json_encode($gravatar->getData()) . PHP_EOL; | ||
echo "Avatar Data: " . json_encode($gravatar->getData(), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; | ||
echo "Avatar Properties: " . json_encode($gravatar->getProperties()) . PHP_EOL; | ||
echo "Get Gravatar with Email: " . gravatarUrlWithEmail() . PHP_EOL; |