summaryrefslogtreecommitdiff
path: root/index.php
blob: 9fab2d8d9036a558b53d0801d45d3b026025f3d2 (plain)
    1 <?php
    2 //print(file_get_contents('res/header.html'));
    3 include('res/header.php');
    4 
    5 // Support multiple page query styles (this implements partial support for
    6 // links used by other sofwares)
    7 if($_GET['p'] != '') {
    8   $post = $_GET['p'];
    9 } else if($_GET['title'] != '') {
   10   $post = $_GET['title'];
   11 } else if($_GET['q'] != '') {
   12   $post = $_GET['q'];
   13 }
   14 
   15 // For security, strip all leading characters off the filename (things like ./
   16 // and ../) to prevent people from abusing the query string.
   17 $post = basename($post);
   18 
   19 // If post is not specified, default to 'index'
   20 if($post == '') { $post = "index"; }
   21 
   22 if($post[0] == '.' || $post[0] == '/') {
   23   // Prevent access to any pages starting with '.' or '/'
   24   print("<p>Error: the page you have requested does not exist.</p>");
   25 } elseif(file_exists('html/' . $post . '.html')) {
   26   // Get the first line
   27   $f = fopen('posts/' . $post . '.adoc', 'r');
   28   $firstline = fgets($f);
   29   fclose($f);
   30   // Print the first line (title)
   31   print('<h1>' . $firstline . '</h1>');
   32 
   33   // Get and print post body
   34   print(file_get_contents('html/' . $post . '.html'));
   35 } else {
   36   print("<p>Error: the page you have requested does not exist.</p>");
   37 }
   38 
   39 print(file_get_contents('res/footer.html'));
   40 ?>

Generated by cgit