diff options
author | Arno Richter <oelna@oelna.de> | 2022-12-13 22:27:21 +0100 |
---|---|---|
committer | Arno Richter <oelna@oelna.de> | 2022-12-13 22:27:44 +0100 |
commit | 0b075f3ea2616cfde4d976199a69ba631174a336 (patch) | |
tree | bb1feef58d9c714f6c3fb0b75f1e52b0181cf2af /templates/single.inc.php | |
parent | f0e3ff408db8ee40611f75cdf96892f90034bd60 (diff) | |
download | microblog-0b075f3ea2616cfde4d976199a69ba631174a336.tar.gz microblog-0b075f3ea2616cfde4d976199a69ba631174a336.tar.bz2 microblog-0b075f3ea2616cfde4d976199a69ba631174a336.zip |
gave up and sorted files into a directory structure. made snippets for header, nav and footer. made it easier to add additional css files as themes. prepare a little for addition of a real template engine. added a css reset file to share between themes, if warranted.
Diffstat (limited to 'templates/single.inc.php')
-rw-r--r-- | templates/single.inc.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/templates/single.inc.php b/templates/single.inc.php new file mode 100644 index 0000000..af486d5 --- /dev/null +++ b/templates/single.inc.php @@ -0,0 +1,100 @@ +<?php + if(!defined('ROOT')) die('Don\'t call this directly.'); + header('Content-Type: text/html; charset=utf-8'); + + $id = (!empty(path(0))) ? (int) path(0) : 0; + + $action = 'display'; + if(mb_strtolower(path(1)) == 'delete') $action = 'delete'; + if(mb_strtolower(path(1)) == 'edit') $action = 'edit'; + + $error = false; + if($config['logged_in']) { + + // delete post + if(!empty($_POST['action']) && $_POST['action'] == 'delete') { + $result = db_delete((int) $_POST['id']); + + if(!$result) { + $error = 'Post could not be deleted!'; + } else { + rebuild_feeds(); + + header('Location: '.$config['url']); + die(); + } + } + + // edit post + if(!empty($_POST['action']) && $_POST['action'] == 'edit') { + + $result = db_update((int) $_POST['id'], $_POST['content']); + + if(!$result) { + $error = 'Post could not be updated!'; + } else { + rebuild_feeds(); + + header('Location: '.$config['url'].'/'.$_POST['id']); + die(); + } + } + } + + // load the actual post + $post = db_select_post($id); + + $title_suffix = 'entry #' . $id; + require(ROOT.DS.'snippets'.DS.'header.snippet.php'); + +?><body> + <div class="wrap"> + <?php require(ROOT.DS.'snippets'.DS.'nav.snippet.php'); ?> + <ul class="posts"> + <?php if(!empty($post)): ?> + <li class="single-post" data-post-id="<?= $post['id'] ?>"> + <?php if($action == 'edit'): ?> + <form action="" method="post" class="edit"> + <textarea name="content" maxlength="<?= $config['max_characters'] ?>"><?= $post['post_content'] ?></textarea> + <p id="count"><?= $config['max_characters'] ?></p> + + <input type="hidden" name="action" value="edit" /> + <input type="hidden" name="id" value="<?= $post['id'] ?>" /> + <input type="submit" class="button" value="Update this post" /> + </form> + <?php else: ?> + <?php + $date = date_create(); + date_timestamp_set($date, $post['post_timestamp']); + + $datetime = date_format($date, 'Y-m-d H:i:s'); + $formatted_time = date_format($date, 'M d Y H:i'); + ?> + <span class="post-timestamp"><time datetime="<?= $datetime ?>" data-unix-time="<?= $post['post_timestamp'] ?>"><?= $formatted_time ?></time></span> + <nav class="post-meta"> + <?php if($config['logged_in']): ?><ul> + <li><a href="<?= $config['url'] ?>/<?= $post['id'] ?>/edit">Edit</a></li> + <li><a href="<?= $config['url'] ?>/<?= $post['id'] ?>/delete">Delete</a></li> + </ul><?php endif; ?> + </nav> + <p class="post-content"><?= nl2br(autolink($post['post_content'])) ?></p> + <?php if($action == 'delete'): ?> + <form action="" method="post" class="delete"> + <input type="hidden" name="action" value="delete" /> + <input type="hidden" name="id" value="<?= $post['id'] ?>" /> + <input type="submit" class="button alert" value="Delete this post" /> + </form> + <?php if($error !== false): ?> + <p class="message error"><?= $error ?></p> + <?php endif; ?> + <?php endif; ?> + <?php endif; ?> + </li> + <?php else: ?> + <p>No post with this ID.</p> + <?php endif; ?> + </ul> + </div> + <?php require(ROOT.DS.'snippets'.DS.'footer.snippet.php'); ?> +</body> +</html> |