Deploy on 2026-06-05 17:03:37

This commit is contained in:
Hamza-Ayed
2026-06-05 17:03:37 +03:00
parent 89b72a0b42
commit 227fd7c412
3 changed files with 62 additions and 18 deletions

View File

@@ -20,25 +20,50 @@ class RssParser
*/
public function fetchEntries(string $url): array
{
$context = stream_context_create([
'http' => [
'timeout' => 15,
'user_agent' => 'ScoutIQ/1.0 (Crawler)',
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$xml = false;
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'ScoutIQ/1.0 (Crawler)');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$xml = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$xml = @file_get_contents($url, false, $context);
if (!$xml) {
return [];
if ($httpCode !== 200) {
throw new \Exception("HTTP Error {$httpCode}");
}
if ($xml === false) {
throw new \Exception("Connection failed via cURL");
}
} else {
$context = stream_context_create([
'http' => [
'timeout' => 15,
'user_agent' => 'ScoutIQ/1.0 (Crawler)',
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$xml = @file_get_contents($url, false, $context);
if ($xml === false) {
$status = "Connection failed";
if (isset($http_response_header) && isset($http_response_header[0])) {
$status = $http_response_header[0];
}
throw new \Exception($status);
}
}
$feed = @simplexml_load_string($xml);
if (!$feed) {
return [];
throw new \Exception("Invalid XML structure");
}
$entries = [];