aboutsummaryrefslogtreecommitdiff
path: root/guestbook/feed.php
blob: 7cdb62e56407e205235c1152a5a0abdcf04f2b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

header('Content-Type: text/xml');

echo '<rss version="2.0"><channel>';
echo '<title>isopod.cool guestbook</title>';
echo '<description>The guestbook on isopod.cool</description>';
echo '<language>en-us</language>';
echo '<link>https://isopod.cool/guestbook/</link>';
echo '<generator>My crappy PHP code</generator>';

$postlist = json_decode(file_get_contents("posts.json"));
$index = 1;
$totaloutput = "";
foreach($postlist as $post) {
  $output = "";
  $date = date("D, d M Y H:m:s", $post->date) . " GMT";
  $name = $post->name;
  $message = $post->message;
  $found = $post->found;
  $website = $post->website;
  $cool = $post->cool;
  $coolsanitized = htmlentities(preg_replace("/https?:\/\//i", "", $cool));
  $reply = htmlentities($post->reply);

  if($website) { $output = $output."<a href='$website'>$name</a>:<br><br>"; }
  else { $output = $output.$name.":<br><br>"; }

  if($cool) {
    $output = $output."<b>cool thing</b>: <a href='$cool'>$coolsanitized</a><br><br>";
  }

  if($found) {
    $output = $output."<b>How did you find me?</b><br>$found<br><br>";
  }

  $output = $output.$message."<br><br>";

  if($reply) {
    $output = $output."<hr><b>Reply:</b><br>$reply";
  }
  $totaloutput = "<item><title>Entry #" . $index . " - " . $name . "</title><link>https://isopod.cool/guestbook/</link><pubDate>" . $date . "</pubDate><description>".htmlentities($output)."</description><guid isPermaLink='false'>" . $index . $post->date . $name . "</guid></item>".$totaloutput;
  $index++;
}

echo $totaloutput;
echo "</channel></rss>";