From: Jacob Casper Date: Sat, 25 Jun 2022 22:26:26 +0000 (-0500) Subject: Make RSS feed X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=ac20a7ef113b0e901e15ae674c1394d424327fb2;p=pics.git Make RSS feed RSS feed template, generator, and wiring. Needs to be displayed prominently on the index and automated. --- diff --git a/README.md b/README.md index ab4860e..20c3320 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ Requirements: - php7.3+ - php-imagick +- php-xml - sqlite3 diff --git a/index.php b/index.php index 88310ff..c8f23f5 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ + diff --git a/rss.php b/rss.php new file mode 100644 index 0000000..0312255 --- /dev/null +++ b/rss.php @@ -0,0 +1,45 @@ +createElement('item'); + $description = $dom->createElement('description', $post_body); + $link = $dom->createElement('link', "https://pics.jacobcasper.com/#post-{$post_id}"); + $guid = $dom->createElement('guid', "https://pics.jacobcasper.com/#post-{$post_id}"); + $pub_date = $dom->createElement('pubDate', date(DATE_RSS, $timestamp)); + // TODO write the endpoint for this + //$enclosure = $dom->createElement('enclosure'); + //$enclosure->setAttribute('url', "https://pics.jacobcasper.com/pic/{$post_id}"); + //$enclosure->setAttribute('length', "9999"); + //$enclosure->setAttribute('type', $mime_type); + $item->appendChild($description); + //$item->appendChild($enclosure); + $item->appendChild($link); + $item->appendChild($guid); + $item->appendChild($pub_date); + return $item; +} + +$rss_template = file_get_contents('rss.template.xml'); +$rss_dom = new DOMDocument(); +$rss_dom->formatOutput = true; +$rss_dom->loadXML($rss_template); +$channel_node = $rss_dom->firstChild->childNodes[1]; +$db = get_db(); +$posts = $db->query('SELECT + p.ID, p.TIMESTAMP, pi.MIME_TYPE, c.BODY + FROM posts p + JOIN pics pi on p.id = pi.post_id + JOIN comments c on p.id = c.post_id + ORDER BY p.TIMESTAMP DESC'); +while ($post = $posts->fetchArray()) { + $item = post_to_item($rss_dom, $post); + $channel_node->appendChild($item); +} + +file_put_contents('rss.xml', $rss_dom->saveXML()); diff --git a/rss.template.xml b/rss.template.xml new file mode 100644 index 0000000..7975fe5 --- /dev/null +++ b/rss.template.xml @@ -0,0 +1,11 @@ + + + + Jacob's Not-gram + https://pics.jacobcasper.com + picture of JC + en-US + pics-wm@jacobcasper.com (Jacob Casper) + 1440 + + diff --git a/rss_test.php b/rss_test.php new file mode 100644 index 0000000..4d86918 --- /dev/null +++ b/rss_test.php @@ -0,0 +1,21 @@ + 'image/jpeg', + 'ID' => 'uuid-v4', + 'BODY' => 'lorem ipsum dolor', + 'TIMESTAMP' => '1400000000', + ]; + $dom = new DOMDocument(); + $dom->formatOutput = true; + $item_node = post_to_item($dom, $post); + var_dump($item_node); + $dom->appendChild($item_node); + var_dump($dom->saveXML($dom)); +} + +test_post_to_item_success();