php-llm-agent/lib/ResolveActions.function.php
Frederico @ VilaRosa02 2e01e34278 init
2025-09-09 10:06:07 +00:00

48 lines
1.6 KiB
PHP

<?php
function ResolveActions(string $text) {
if (preg_match("/@rss_reader ([\w:\/\.]+)/",$text,$matches)) {
$url = $matches[1];
// Initialize cURL
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_USERAGENT => "PHP cURL RSS Reader"
]);
$response = curl_exec($ch);
if (curl_errno($ch)) die("cURL error: " . curl_error($ch));
curl_close($ch);
// Parse as XML
$xml = @simplexml_load_string($response);
if (!$xml) die("Failed to parse XML.");
// Find first <title>
$firstTitle = '';
if (isset($xml->channel->item[0]->title)) {
// RSS 2.0 style
$firstTitle = (string)$xml->channel->item[0]->title;
} elseif (isset($xml->entry[0]->title)) {
// Atom style
$firstTitle = (string)$xml->entry[0]->title;
} elseif (isset($xml->title)) {
// fallback
$firstTitle = (string)$xml->title;
}
$text = str_replace($matches[0],$firstTitle,$text);
}
return $text;
}