aboutsummaryrefslogtreecommitdiff
path: root/blog/posts/post.php
blob: e6b13b6f99a46b75e6695a8b4c2ad28e01b85220 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
$cwd = preg_replace('/^.*\//', '', getcwd());
$feed = simplexml_load_file($_SERVER['DOCUMENT_ROOT']."/blog/blog.atom");
$pdate = "";
$udate = "";
$title = "";
$descr = "";
foreach($feed->entry as $entry) {
  if($entry->id == $cwd) {
    $pdate = preg_replace('/T.*$/', ' ', $entry->published);
    $udate = preg_replace('/T.*$/', ' ', $entry->updated);
    $title = $entry->title;
    $descr = $entry->summary;
    break;
  }
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/style.css" rel="stylesheet" type="text/css" media="all">
    <link href="/blog/comment/comments.css" rel="stylesheet" type="text/css" media="all">
    <?php
      echo("<title>$title</title><meta name='description' content='$descr'>");
      $bgfile = glob('bg.*')[0];
      if(!is_null($bgfile)) {
        echo("<style> h1 { background-image: url('$bgfile') } </style>");
      }
    ?>
    <style>
      td {
        display: table-cell;
      }
    </style>
    <?php include($_SERVER['DOCUMENT_ROOT'] . '/seasonal.php'); ?>
  </head>
  <body>
    <?php 
      include($_SERVER['DOCUMENT_ROOT'] . '/nav.php');
      $udates = "";
      if($pdate != $udate) { $udates = " | Updated&nbsp;on&nbsp;$udate"; }
      echo("<h1>isoblog</h1><h2 id='caption'>$title</h2><p style='text-align: center;'><em>Posted&nbsp;on&nbsp;$pdate$udates</em></p>");
      include("../../../Parsedown.php");
      $Parsedown = new Parsedown();
      echo $Parsedown->text(file_get_contents("index.md"));
      $Parsedown->setSafeMode(true);
      $return = $_GET["return"];
    ?>
    <hr>
    <h2>Comments</h2>
    <form action="/blog/comment/submit.php" method="post" autocomplete="off">
      <?php echo "<input type='text' name='entry' value='".preg_replace("/^.*\//","",getcwd())."' style='display: none;' readonly>"; ?>
      <table>
        <tr>
          <td><input type="text" name="name" placeholder="Name"></td>
          <td><input type="text" name="botcheck" placeholder="Bot test (type &quot;isopod&quot;)"></td>
        </tr>
        <tr>
          <td colspan="2"><textarea name="message" placeholder="Comment (Now supports Markdown!)"></textarea></td>
        </tr>

        <tr>
          <?php
              switch ($return) {
                case 'noname':
                  echo "<td><span class='error'>Name required!</span></td>"; 
                  break;
                case 'nomessage':
                  echo "<td><span class='error'>Message required!</span></td>";
                  break;
                case 'botcheckfailed':
                  echo "<td><span class='error'>You failed the bot check!</span></td>";
                  break;
                case 'success':
                  echo "<td><span class='success'>Successfully posted!</span></td>";
                  break;
                default:
                  echo "<td></td>";
                  break;
              }
          ?>
          <td style="text-align: right;"><input type="submit" value="Post"></td>
        </tr>
      </table>
    </form>
    <?php

      $totaloutput = "";
      $postlist = json_decode(file_get_contents("../../comment/posts.json"));
      foreach($postlist as $post) {
        if ($post->entry == preg_replace("/^.*\//","",getcwd())) {
          $output = "";
          $date = date("Y-m-d h:iA", $post->date);
          $name = $post->name;
          $message = $Parsedown->text(html_entity_decode($post->message));

          $output = $output."<hr><article><table><tr><td style='text-align: left;'>".$name."</td><td style='text-align: right;'>".$date."</td></tr><tr><td colspan='2'>".$message."</td></tr></table></article>";
          $totaloutput = $output.$totaloutput;
        }
      }
      echo $totaloutput; ?>
  </body>
</html>