aboutsummaryrefslogtreecommitdiff
path: root/blog/post.php
blob: ff7abf093e7e6d5f89adc7f0ab64225e0aab0813 (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
<?php
/*ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);*/

if($_SERVER['REQUEST_URI'] === "/blog/post.php") {
  header("Location: /blog/");
  die();
}

$root = $_SERVER['DOCUMENT_ROOT'];

$cwd = preg_replace('/^.*\//', '', getcwd());
$feed = simplexml_load_file($_SERVER['DOCUMENT_ROOT']."/blog/blog.atom");
$pdate = "a future date...";
$udate = "";
$title = "";
$descr = "";
$authr = "someone...";
$prevtitle = "";
$prevlink = "";
$nexttitle = "";
$nextlink = "";
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 = htmlspecialchars($entry->summary);
    $authr = $entry->author->name;
  } else if($title) {
    $nextlink = $entry->link["href"];
    $nexttitle = $entry->title;
    break;
  } else {
    $prevlink = $entry->link["href"];
    $prevtitle = $entry->title;
  }
}
if(!$title) {
  $title = "DRAFT: ".preg_replace("/^.*\//","",getcwd());
}
if(!$udate) {
  $udate = date("Y-m-d", filemtime("index.md"));
}
$udates = "";
if($pdate != $udate) { $udates = " Updated&nbsp;on $udate"; }
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <?php include($_SERVER['DOCUMENT_ROOT'] . '/boilerplate.php'); ?>
    <link href="/style.css" rel="stylesheet" type="text/css" media="all">
    <?php
      echo("<title>$title | ".$_SERVER['HTTP_HOST']."</title><meta name='description' content='$descr'>");
      //$bgfile = glob('bg.*')[0];
      //if(!is_null($bgfile)) {
      //  echo("<style> body > h1:first-of-type { background-image: url('$bgfile') } </style>");
      //}
    ?>
    
  </head>
  <body>
    <?php include($root."/header.php"); ?>
    <main>
      <section>
        <h2><?php echo($title); ?></h2>
        <p class='h2caption'>By&nbsp;<?php echo("$authr"); ?><br>Posted&nbsp;on <?php echo($pdate."<br>".$udates); ?></p>
        <p class="backlink"><a href="/blog/"><< blog</a></p>
        <?php
          //echo("<p style='text-align: right;'>I'm testing in prod right now. don't worry about it");

          //Boilerplate for Parsedown
          include_once($root."/Parsedown.php");
          $Parsedown = new Parsedown();

          $posttext = $Parsedown->text(file_get_contents("index.md"));
          $posttext = str_replace("<h3>", "<h5>", $posttext);
          $posttext = str_replace("</h3>", "</h5>", $posttext);
          $posttext = str_replace("<h2>", "<h4>", $posttext);
          $posttext = str_replace("</h2>", "</h4>", $posttext);
          $posttext = str_replace("<h1>", "<h3>", $posttext);
          $posttext = str_replace("</h1>", "</h3>", $posttext);
          echo $posttext;
          $Parsedown->setSafeMode(true);
        ?>
        <hr>
        <nav class="prevnextnav">
          <?php 
          if($prevlink) {
            echo("<a class='prevlink' href='$prevlink'><b>Newer</b>: $prevtitle</a>");
          }
          if($nextlink) {
            echo("<a class='nextlink' href='$nextlink'><b>Older</b>: $nexttitle</a>");
          }
          ?>
        </nav>
        <?php include_once($root."/common.php"); include($root."/guestbook/commentbox.php"); ?>
      </section>
    </main>
    <?php include($root."/footer.php"); ?>
  </body>
</html>