From a535a9e7e017629178b45acc2e96e1d674a0d6fc Mon Sep 17 00:00:00 2001 From: Nicolas BERNSTEIN Date: Fri, 13 Apr 2012 19:17:17 +0200 Subject: Added : ATOM feed for blog ; abilty to comment posts. --- design/style.css | 8 ++++++++ lib/blog/comment.php | 38 ++++++++++++++++++++++++++++++++++++++ lib/blog/delcom.php | 12 ++++++++++++ lib/blog/delete.php | 3 ++- lib/blog/edcom.php | 35 +++++++++++++++++++++++++++++++++++ lib/blog/index.php | 15 ++++++++++++--- lib/blog/view.php | 39 +++++++++++++++++++++++++++++++++++++++ lib/conf/apps.php | 4 ++++ lib/conf/blog.php | 8 ++++++++ schema.sql | 24 +++++++++++++++++++++--- tpl/blog/atom_feed.php | 37 +++++++++++++++++++++++++++++++++++++ tpl/blog/index.php | 15 +++++++++++++++ tpl/blog/view.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 281 insertions(+), 7 deletions(-) create mode 100644 lib/blog/comment.php create mode 100644 lib/blog/delcom.php create mode 100644 lib/blog/edcom.php create mode 100644 lib/blog/view.php create mode 100644 lib/conf/blog.php create mode 100644 tpl/blog/atom_feed.php create mode 100644 tpl/blog/view.php diff --git a/design/style.css b/design/style.css index c3a5314..2a537f6 100644 --- a/design/style.css +++ b/design/style.css @@ -295,3 +295,11 @@ hr { margin-left: 16px; font-size: 1.2em; } + +.blog_post h3 { + margin: 0px; + padding: 0px; + margin-left: 16px; + margin-bottom: 10px; + font-size: 1.0em; +} diff --git a/lib/blog/comment.php b/lib/blog/comment.php new file mode 100644 index 0000000..4bda912 --- /dev/null +++ b/lib/blog/comment.php @@ -0,0 +1,38 @@ + "Comment : ", "name" => "comment", "type" => "textarea", "value" => $comment), + ); +$validate = "Comment"; +require("tpl/general/form.php"); diff --git a/lib/blog/delcom.php b/lib/blog/delcom.php new file mode 100644 index 0000000..eaf93ec --- /dev/null +++ b/lib/blog/delcom.php @@ -0,0 +1,12 @@ += 3, 'blog'); +$comid = intval($args[2]); + +$com = mysql_fetch_assoc(sql("SELECT post FROM blog_comments WHERE id = $comid")); +assert_error($com, + "This comment does not exist."); + +token_validate("Do you really want to delete this comment ?", "view-blog-" . $com['post']); +sql("DELETE FROM blog_comments WHERE id = $comid"); +header("Location: view-blog-" . $com['post']); diff --git a/lib/blog/delete.php b/lib/blog/delete.php index a57b5ac..bfc428b 100644 --- a/lib/blog/delete.php +++ b/lib/blog/delete.php @@ -5,9 +5,10 @@ $postid = intval($args[2]); $post = mysql_fetch_assoc(sql("SELECT owner FROM blog_posts WHERE id = $postid")); assert_error($post && $post['owner'] == $user['id'], - "This note does not exist, or you are not allowed to delete it."); + "This post does not exist, or you are not allowed to delete it."); token_validate("Do you really want to delete this post ?", "blog"); sql("DELETE FROM blog_posts WHERE id = $postid"); sql("DELETE FROM blog_tags WHERE post = $postid"); +sql("DELETE FROM blog_comments WHERE post = $postid"); header("Location: drafts-blog"); diff --git a/lib/blog/edcom.php b/lib/blog/edcom.php new file mode 100644 index 0000000..2b96ff9 --- /dev/null +++ b/lib/blog/edcom.php @@ -0,0 +1,35 @@ + "Comment : ", "name" => "text", "value" => $com_text, "type" => "textarea"), + ); +$validate = "Edit comment"; + +require("tpl/general/form.php"); diff --git a/lib/blog/index.php b/lib/blog/index.php index aaeb969..dd353d3 100644 --- a/lib/blog/index.php +++ b/lib/blog/index.php @@ -1,6 +1,7 @@ array ( @@ -39,10 +40,13 @@ function count_in($fat, $v, $d) { $q = "SELECT blog_posts.id AS id, blog_posts.title AS title, blog_posts.date AS date, ". + "UNIX_TIMESTAMP(blog_posts.date) AS date_ts, ". "DATE_FORMAT(blog_posts.date, '%Y-%m') AS month, ". - "blog_posts.text_html AS text_html, GROUP_CONCAT(ba.tag SEPARATOR ', ') AS tags, ". + "blog_posts.text_html AS text_html, GROUP_CONCAT(DISTINCT ba.tag SEPARATOR ', ') AS tags, ". + "COUNT(DISTINCT blog_comments.id) AS comments, ". "account.login AS owner, account.id AS owner_id ". "FROM blog_posts LEFT JOIN account ON blog_posts.owner = account.id ". + "LEFT JOIN blog_comments ON blog_comments.post = blog_posts.id ". "LEFT JOIN blog_tags ba ON ba.post = blog_posts.id ". (isset($fvalues['tag']) ? "LEFT JOIN blog_tags bb ON bb.post = blog_posts.id AND bb.tag = '" . escs($fvalues['tag'])."' " : ""). "WHERE blog_posts.draft = 0 ". @@ -69,4 +73,9 @@ $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); -require("tpl/blog/index.php"); + +if (isset($fvalues['feed']) && $fvalues['feed'] == "atom") { + require("tpl/blog/atom_feed.php"); +} else { + require("tpl/blog/index.php"); +} diff --git a/lib/blog/view.php b/lib/blog/view.php new file mode 100644 index 0000000..15c4d6e --- /dev/null +++ b/lib/blog/view.php @@ -0,0 +1,39 @@ += $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); +$can_delcom = ($user['priv'] >= $apps['blog']['delcom'] && $user['id'] != 0); + +require("tpl/blog/view.php"); diff --git a/lib/conf/apps.php b/lib/conf/apps.php index b7f3c9d..8afeb2d 100644 --- a/lib/conf/apps.php +++ b/lib/conf/apps.php @@ -37,11 +37,15 @@ $apps = array( // Blogging application "blog" => array( "index" => 0, + "view" => 0, "drafts" => 1, "publish" => 1, "post" => 1, "edit" => 1, "delete" => 1, + "comment" => 1, + "edcom" => 1, + "delcom" => 2, ), // Studies application diff --git a/lib/conf/blog.php b/lib/conf/blog.php new file mode 100644 index 0000000..bb2ef09 --- /dev/null +++ b/lib/conf/blog.php @@ -0,0 +1,8 @@ +'."\n"; +echo ''."\n"; +echo '' . $blog_title . ''."\n"; +echo '' . $blog_base_url . "blog". "\n"; +echo '' . "\n"; + + +function beginning($text, $len = 500) { + $text = preg_replace('#<.+>#isU', ' ', $text); + if (strlen($text) > $len) { + $text = substr($text, 0, $len)."..."; + } + return $text; +} + +foreach ($posts as $post) { + echo "\n\n"; + echo '' . $post['title'] . "\n"; + echo '' . @date("c", $post['date_ts']) . "\n"; + echo '' . $blog_base_url . "view-blog-" . $post['id'] . "\n"; + foreach (explode(', ', $post['tags']) as $tag) { + echo '' . "\n"; + } + echo '' . "\n"; + echo '' . "\n"; + echo '\n"; + echo "".$post['owner']."\n"; + echo "\n"; +} + +echo ''; + +die(); + diff --git a/tpl/blog/index.php b/tpl/blog/index.php index 07e3388..6d07efa 100644 --- a/tpl/blog/index.php +++ b/tpl/blog/index.php @@ -17,6 +17,7 @@ foreach ($posts as $post) { echo ' | edit'; if ($can_delete && $post['owner_id'] == $user['id']) echo ' | delete'; + echo ' | read & comment (' . $post['comments'] . ')'; echo ''; echo '
published ' . $post['date'] . '
'; if ($post['tags'] != '') { @@ -50,4 +51,18 @@ foreach ($fa as $kname => $kdata) { } } +echo "

...

"; +$ze = array(); +foreach ($fvalues as $k => $v) { $ze[] = "$k-$v"; } +$ze[] = "feed-atom"; +$zd = implode("-", $ze); +echo ''; + require("tpl/general/bottom.php"); diff --git a/tpl/blog/view.php b/tpl/blog/view.php new file mode 100644 index 0000000..0f0c89c --- /dev/null +++ b/tpl/blog/view.php @@ -0,0 +1,50 @@ +'; +echo 'Written by ' . $post['owner']; +if ($can_edit && $post['owner_id'] == $user['id']) + echo ' | edit'; +if ($can_delete && $post['owner_id'] == $user['id']) + echo ' | delete'; +if ($can_comment) + echo ' | post comment'; +echo ''; +echo '
published ' . $post['date'] . '
'; +if ($post['tags'] != '') { + echo '
tags: ' . $post['tags'] . '
'; +} +echo $post['text_html']; + +echo '

Comments

'; + +if (count($comments) == 0) { + echo 'No comments at the moment.'; +} else { + foreach ($comments as $comment) { + echo '
'; + $a = array(); + if ($can_delcom) $a[] = 'delete'; + if ($can_comment && $comment['author_id'] == $user['id']) + $a[] = 'edit'; + if (count($a) > 0) + echo '
' . implode(" | ", $a) . '
'; + + echo '

' . $comment['date'] . ' by ' . $comment['author'] . '

'; + echo '
' . $comment['text_html'] . '
'; + echo '
'; + } +} + +echo '

Post a comment

'; +if ($can_comment) { + echo '

 
'; +} else { + echo 'Please log in or register to post a comment.'; +} + + +require("tpl/general/bottom.php"); -- cgit v1.2.3