Skip to content

Commit cc278f0

Browse files
committed
Social: Use GuzzleHttp to verify URL with open graph
1 parent ed94690 commit cc278f0

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

main/inc/lib/social.lib.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Chamilo\CourseBundle\Entity\CForumPost;
66
use Chamilo\CourseBundle\Entity\CForumThread;
77
use ChamiloSession as Session;
8+
use GuzzleHttp\Client;
89
use Zend\Feed\Reader\Entry\Rss;
910
use Zend\Feed\Reader\Reader;
1011

@@ -2093,21 +2094,25 @@ public static function readContentWithOpenGraph(string $link): string
20932094
*/
20942095
public static function verifyUrl(string $uri): bool
20952096
{
2096-
$curl = curl_init($uri);
2097-
curl_setopt($curl, CURLOPT_FAILONERROR, true);
2098-
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
2099-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
2100-
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
2101-
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
2102-
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
2103-
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
2104-
$response = curl_exec($curl);
2105-
curl_close($curl);
2106-
if (!empty($response)) {
2097+
$client = new Client();
2098+
2099+
try {
2100+
$response = $client->request('GET', $uri, [
2101+
'timeout' => 15,
2102+
'verify' => false,
2103+
'headers' => [
2104+
'User-Agent' => $_SERVER['HTTP_USER_AGENT']
2105+
]
2106+
]);
2107+
2108+
if (200 !== $response->getStatusCode()) {
2109+
return false;
2110+
}
2111+
21072112
return true;
2113+
} catch (Exception $e) {
2114+
return false;
21082115
}
2109-
2110-
return false;
21112116
}
21122117

21132118
/**

0 commit comments

Comments
 (0)