diff options
-rw-r--r-- | lib/blog/edit.php | 6 | ||||
-rw-r--r-- | lib/blog/post.php | 2 | ||||
-rw-r--r-- | lib/blog/view.php | 3 | ||||
-rw-r--r-- | tpl/blog/drafts.php | 12 | ||||
-rw-r--r-- | tpl/blog/view.php | 54 |
5 files changed, 43 insertions, 34 deletions
diff --git a/lib/blog/edit.php b/lib/blog/edit.php index 854c94f..d76781c 100644 --- a/lib/blog/edit.php +++ b/lib/blog/edit.php @@ -39,11 +39,7 @@ if (isset($_POST['title']) && isset($_POST['tags']) && isset($_POST['text'])) { } sql("INSERT INTO blog_tags(post, tag) VALUES " . implode(',', $v)); } - if ($post['draft']) { - header("Location: drafts-blog"); - } else { - header("Location: blog"); - } + header("Location: view-blog-$postid"); die(); } } diff --git a/lib/blog/post.php b/lib/blog/post.php index 1f1525a..a17ba5b 100644 --- a/lib/blog/post.php +++ b/lib/blog/post.php @@ -28,7 +28,7 @@ if (isset($_POST['title']) && isset($_POST['text'])) { } sql("INSERT INTO blog_tags(post, tag) VALUES " . implode(',', $v)); } - header("Location: drafts-blog"); + header("Location: view-blog-$id"); die(); } } diff --git a/lib/blog/view.php b/lib/blog/view.php index 15c4d6e..fa375d8 100644 --- a/lib/blog/view.php +++ b/lib/blog/view.php @@ -15,7 +15,7 @@ $post = mysql_fetch_assoc(sql( "WHERE blog_posts.id = $postid" )); -assert_error($post && $post['draft'] == 0, +assert_error($post && ($post['draft'] == 0 || $post['owner_id'] == $user['id']), "This post does not exist."); $comments = array(); @@ -34,6 +34,7 @@ $can_post = ($user['priv'] >= $apps['blog']['drafts'] && $user['id'] != 0); $can_edit = ($user['priv'] >= $apps['blog']['edit'] && $user['id'] != 0); $can_delete = ($user['priv'] >= $apps['blog']['delete'] && $user['id'] != 0); $can_comment = ($user['priv'] >= $apps['blog']['comment'] && $user['id'] != 0); +$is_draft = ($post['draft'] != 0); $can_delcom = ($user['priv'] >= $apps['blog']['delcom'] && $user['id'] != 0); require("tpl/blog/view.php"); diff --git a/tpl/blog/drafts.php b/tpl/blog/drafts.php index 5440cbc..510f428 100644 --- a/tpl/blog/drafts.php +++ b/tpl/blog/drafts.php @@ -8,8 +8,9 @@ echo '<a href="post-blog">post a message</a></div>'; echo '<h2>My drafts</h2>'; if (count($drafts) > 0) { + echo '<table><tr><th>Title</th><th>Actions</th></tr>'; foreach ($drafts as $post) { - echo '<div class="blog_post">'; + /*echo '<div class="blog_post">'; echo '<div class="small_right">'; echo '<a href="edit-blog-' . $post['id'] . '">edit</a>'; echo ' | <a href="delete-blog-' . $post['id'] . '">delete</a>'; @@ -17,8 +18,13 @@ if (count($drafts) > 0) { echo '</div>'; echo '<h2>' . $post['title'] . '</h2>'; echo $post['text_html']; - echo '</div>'; + echo '</div>';*/ + echo '<tr><td><a href="view-blog-' . $post['id'] . '">' . $post['title'] . '</a></td>'; + echo '<td><a href="edit-blog-' . $post['id'] . '">edit</a>'; + echo ' | <a href="delete-blog-' . $post['id'] . '">delete</a>'; + echo ' | <a href="publish-blog-' . $post['id'] . '">publish</a></td></tr>'; } + echo '</table>'; } else { echo '<p>No drafts</p>'; } @@ -28,7 +34,7 @@ echo '<h2>My published posts</h2>'; if (count($pub) > 0) { echo '<table><tr><th>Title</th><th>Actions</th></tr>'; foreach ($pub as $post) { - echo '<tr><td>' . $post['title'] . '</td>'; + echo '<tr><td><a href="view-blog-' . $post['id'] . '">' . $post['title'] . '</a></td>'; echo '<td><a href="edit-blog-' . $post['id'] . '">edit</a>'; echo ' | <a href="delete-blog-' . $post['id'] . '">delete</a></td></tr>'; } diff --git a/tpl/blog/view.php b/tpl/blog/view.php index 0f0c89c..32f1073 100644 --- a/tpl/blog/view.php +++ b/tpl/blog/view.php @@ -10,8 +10,10 @@ if ($can_edit && $post['owner_id'] == $user['id']) echo ' | <a href="edit-blog-' . $post['id'] . '">edit</a>'; if ($can_delete && $post['owner_id'] == $user['id']) echo ' | <a href="delete-blog-' . $post['id'] . '">delete</a>'; -if ($can_comment) +if ($can_comment && !$is_draft) echo ' | <a href="comment-blog-' . $post['id'] . '">post comment</a>'; +if ($is_draft) + echo ' | <a href="publish-blog-' . $post['id'] . '">publish</a>'; echo '</div>'; echo '<div class="small_right">published ' . $post['date'] . '</div>'; if ($post['tags'] != '') { @@ -19,31 +21,35 @@ if ($post['tags'] != '') { } echo $post['text_html']; -echo '<h2>Comments</h2>'; - -if (count($comments) == 0) { - echo 'No comments at the moment.'; -} else { - foreach ($comments as $comment) { - echo '<div class="blog_post">'; - $a = array(); - if ($can_delcom) $a[] = '<a href="delcom-blog-' . $comment['id'] . '">delete</a>'; - if ($can_comment && $comment['author_id'] == $user['id']) - $a[] = '<a href="edcom-blog-' . $comment['id'] . '">edit</a>'; - if (count($a) > 0) - echo '<div class="small_right">' . implode(" | ", $a) . '</div>'; - - echo '<h3>' . $comment['date'] . ' by ' . $comment['author'] . '</h3>'; - echo '<div class="inside">' . $comment['text_html'] . '</div>'; - echo '</div>'; +if (!$is_draft) { + + echo '<h2>Comments</h2>'; + + if (count($comments) == 0) { + echo 'No comments at the moment.'; + } else { + foreach ($comments as $comment) { + echo '<div class="blog_post">'; + $a = array(); + if ($can_delcom) $a[] = '<a href="delcom-blog-' . $comment['id'] . '">delete</a>'; + if ($can_comment && $comment['author_id'] == $user['id']) + $a[] = '<a href="edcom-blog-' . $comment['id'] . '">edit</a>'; + if (count($a) > 0) + echo '<div class="small_right">' . implode(" | ", $a) . '</div>'; + + echo '<h3>' . $comment['date'] . ' by ' . $comment['author'] . '</h3>'; + echo '<div class="inside">' . $comment['text_html'] . '</div>'; + echo '</div>'; + } + } + + echo '<h3>Post a comment</h3>'; + if ($can_comment) { + echo '<form class="blog_post" method="POST" action="index.php?p=comment-blog-' . $post['id'] . '"><textarea name="comment" style="height: 200px"></textarea><br /><div class="empty_label"> </div><input type="submit" value="Comment" /></form>'; + } else { + echo 'Please log in or register to post a comment.'; } -} -echo '<h3>Post a comment</h3>'; -if ($can_comment) { - echo '<form class="blog_post" method="POST" action="index.php?p=comment-blog-' . $post['id'] . '"><textarea name="comment" style="height: 200px"></textarea><br /><div class="empty_label"> </div><input type="submit" value="Comment" /></form>'; -} else { - echo 'Please log in or register to post a comment.'; } |