diff options
Diffstat (limited to 'templates')
-rw-r--r-- | templates/loginform.inc.php | 39 | ||||
-rw-r--r-- | templates/postform.inc.php | 54 | ||||
-rw-r--r-- | templates/single.inc.php | 100 | ||||
-rw-r--r-- | templates/timeline.inc.php | 57 |
4 files changed, 250 insertions, 0 deletions
diff --git a/templates/loginform.inc.php b/templates/loginform.inc.php new file mode 100644 index 0000000..b852de7 --- /dev/null +++ b/templates/loginform.inc.php @@ -0,0 +1,39 @@ +<?php + if(!defined('ROOT')) die('Don\'t call this directly.'); + + // handle login + if(isset($_POST['user']) && isset($_POST['pass'])) { + if($_POST['user'] === $config['admin_user'] && $_POST['pass'] === $config['admin_pass']) { + $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; + setcookie('microblog_login', sha1($config['url'].$config['admin_pass']), NOW+$config['cookie_life'], '/', $domain, false); + + header('Location: '.$config['url']); + die(); + } else { + header('HTTP/1.0 401 Unauthorized'); + $message = array( + 'status' => 'error', + 'message' => 'You entered wrong user credentials. Please try again.' + ); + } + } + + $title_suffix = 'login'; + require(ROOT.DS.'snippets'.DS.'header.snippet.php'); + +?><body> + <div class="wrap"> + <?php require(ROOT.DS.'snippets'.DS.'nav.snippet.php'); ?> + <p>Please enter your login information.</p> + <?php if(isset($message['status']) && isset($message['message'])): ?> + <p class="message <?= $message['status'] ?>"><?= $message['message'] ?></p> + <?php endif; ?> + <form action="" method="post"> + <input type="text" name="user" placeholder="username" /><br /> + <input type="password" name="pass" placeholder="password" /><br /> + <input type="submit" name="" value="Login" /> + </form> + </div> + <?php require(ROOT.DS.'snippets'.DS.'footer.snippet.php'); ?> +</body> +</html> diff --git a/templates/postform.inc.php b/templates/postform.inc.php new file mode 100644 index 0000000..149028b --- /dev/null +++ b/templates/postform.inc.php @@ -0,0 +1,54 @@ +<?php + if(!defined('ROOT')) die('Don\'t call this directly.'); + + if(!$config['logged_in']) { + // wrong data, kick user to login page + header('HTTP/1.0 401 Unauthorized'); + header('Location: '.$config['url'].'/login'); + die(); + } + + $message = array(); + if(!empty($_POST['content'])) { + + $id = db_insert($_POST['content'], NOW); + + if($id > 0) { + $message = array( + 'status' => 'success', + 'message' => 'Successfully posted status #'.$id + ); + + rebuild_feeds(); + if($config['ping'] == true) ping_microblog(); + if($config['crosspost_to_twitter'] == true) { + $twitter_response = json_decode(twitter_post_status($_POST['content']), true); + + if(!empty($twitter_response['errors'])) { + $message['message'] .= ' (But crossposting to twitter failed!)'; + } + } + + header('Location: '.$config['url']); + die(); + } + } + + $title_suffix = 'new post'; + require(ROOT.DS.'snippets'.DS.'header.snippet.php'); + +?><body> + <div class="wrap"> + <?php require(ROOT.DS.'snippets'.DS.'nav.snippet.php'); ?> + <?php if(isset($message['status']) && isset($message['message'])): ?> + <p class="message <?= $message['status'] ?>"><?= $message['message'] ?></p> + <?php endif; ?> + <form action="" method="post"> + <textarea name="content" maxlength="<?= $config['max_characters'] ?>"></textarea> + <p id="count"><?= $config['max_characters'] ?></p> + <input type="submit" name="" value="Post" /> + </form> + </div> + <?php require(ROOT.DS.'snippets'.DS.'footer.snippet.php'); ?> +</body> +</html> 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> diff --git a/templates/timeline.inc.php b/templates/timeline.inc.php new file mode 100644 index 0000000..234ea83 --- /dev/null +++ b/templates/timeline.inc.php @@ -0,0 +1,57 @@ +<?php + if(!defined('ROOT')) die('Don\'t call this directly.'); + + // never cache the timeline (?) + header('Expires: Sun, 01 Jan 2014 00:00:00 GMT'); + header('Cache-Control: no-store, no-cache, must-revalidate'); + header('Cache-Control: post-check=0, pre-check=0', FALSE); + header('Pragma: no-cache'); + + // pagination + $current_page = (path(0) == 'page' && is_numeric(path(1))) ? (int) path(1) : 1; + $posts_count = db_posts_count(); + $total_pages = ceil($posts_count / $config['posts_per_page']); + $offset = ($current_page-1)*$config['posts_per_page']; + + // get posts + $posts = db_select_posts(NOW, $config['posts_per_page'], 'desc', $offset); + + $title_suffix = ''; + 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($posts)): ?> + <?php foreach($posts as $post): ?> + <li data-post-id="<?= $post['id'] ?>"> + <?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'); + ?> + <a class="post-timestamp" href="<?= $config['url'] ?>/<?= $post['id'] ?>"><time datetime="<?= $datetime ?>" data-unix-time="<?= $post['post_timestamp'] ?>"><?= $formatted_time ?></time></a> + <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> + <div class="post-content"><?= nl2br(autolink($post['post_content'])) ?></div> + </li> + <?php endforeach; ?> + </ul> + <?php else: ?> + <p>No posts found.</p> + <?php endif; ?> + <div class="pagination"> + <?php if ($current_page > 1): ?><a href="<?= $config['url'] ?>/page/<?= $current_page - 1 ?>" class="previous">newer updates</a><?php endif; ?> + <?php if ($current_page < $total_pages): ?><a href="<?= $config['url'] ?>/page/<?= $current_page + 1 ?>" class="next">older updates</a><?php endif; ?> + </div> + </div> + <?php require(ROOT.DS.'snippets'.DS.'footer.snippet.php'); ?> +</body> +</html> |