45 lines
958 B
PHP
45 lines
958 B
PHP
<?php
|
|
include('urljoin.php');
|
|
|
|
if (isset($_GET['comic'])) {
|
|
$comic = $_GET['comic'];
|
|
} else {
|
|
$comic = 'nancy';
|
|
}
|
|
|
|
$url = "https://gocomics.com/$comic";
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
|
$html = curl_exec($curl);
|
|
if ($html === false) {
|
|
die("cURL error: " . curl_error($curl));
|
|
}
|
|
|
|
$dom = new DOMDocument;
|
|
@$dom->loadHTML($html);
|
|
|
|
$xpath = new DOMXPath($dom);
|
|
|
|
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
|
<rss version=\"2.0\">
|
|
<channel>
|
|
<title>Feed for $comic on GoComics</title>
|
|
<link>$url</link>";
|
|
|
|
foreach ($xpath->query('//a') as $a) {
|
|
$href = $a->getattribute('href');
|
|
if (str_starts_with($href, "/$comic/")) {
|
|
$href = urljoin($url, $href);
|
|
echo "<item>
|
|
<title>{$a->getattribute('title')}</title>
|
|
<link>$href</link>
|
|
</item>";
|
|
}
|
|
}
|
|
|
|
echo "</channel></rss>";
|
|
|
|
?>
|