aboutsummaryrefslogtreecommitdiff
path: root/guestbook/comments.php
blob: 92505e3f2817c0fa6b01e5936de49b765ef48f07 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
function echo_comments($page, $Parsedown = null) {
  include($_SERVER['DOCUMENT_ROOT'] . '/common.php');
  if(!$Parsedown) {
    include($_SERVER['DOCUMENT_ROOT']."/Parsedown.php");
    $Parsedown = new Parsedown();
    $Parsedown->setSafeMode(true);
  }

  $totaloutput = "";
  $postlist = json_decode(file_get_contents($datadir."posts.json"));
  $index = 1;
  foreach($postlist as $post) {
    if($post->entry === $page and $post->modstatus > 0) {
      $output = "";
      $date = date("Y-m-d", $post->date);
      $name = htmlentities($post->name);
      $message = $Parsedown->text($post->message);
      $found = htmlentities($post->found);
      $website = $post->website;
      $button = $post->button;
      $cool = $post->cool;
      $coolsanitized = htmlentities(preg_replace("/https?:\/\//i", "", $cool));
      $reply = $Parsedown->text($post->reply);

      $nice = "";
      switch($index) {
        case 42:
          $nice = "scifi reference ayo???";
          break;
        case 67:
          $nice = "six sevennn";
          break;
        case 69:
          $nice = "nice";
          break;
        case 420:
          $nice = "blaze it";
          break;
        case 911:
          $nice = "ohhhh nine eleven";
          break;
        default:
          $nice = "#$index";
      }

      $output = $output."<article class='comment'><div class='gb-head'><p class='gb-name'>";
      if($website) { 
        if($button) {
          $output = $output."<a href='$website'><img src='$button' alt='$name'/></a>";
        } else {
          $output = $output."<a href='$website'>$name</a>";
        }
      } else { $output = $output.$name; }
      $output = $output."</p><p class='gb-date'>$date</p><p class='gb-index'>$nice</p></div>";
      if($cool) {
        $output = $output."<div class='gb-cool'><p><b>cool thing</b>: <a href='$cool'>$coolsanitized</a></p></div>";
      }
      if($found) {
        $output = $output."<div class='gb-found'><p><b>How did you find me?</b></p><p>$found</p></div>";
      }
      $output = $output."<div class='gb-message'>$message</div>";
      if($reply) {
        $output = $output."<div class='gb-reply'><p><b>Reply</b>:</p><div>$reply</div></div>";
      }
      $output = $output."</article>";
      $index++;
      $totaloutput = $output.$totaloutput;
    }
  }
  echo $totaloutput;
}