diff --git a/public_html/classes/blogcomment.php b/public_html/classes/blogcomment.php index e101c87..242aa9e 100644 --- a/public_html/classes/blogcomment.php +++ b/public_html/classes/blogcomment.php @@ -21,7 +21,6 @@ class BlogComment extends CPHPDatabaseRecordClass public $prototype = array( 'string' => array( - 'Body' => "Body", 'Name' => "Name", 'EmailAddress' => "EmailAddress" ), @@ -37,6 +36,9 @@ class BlogComment extends CPHPDatabaseRecordClass "Visible" => "Visible", "IsGuestPost" => "GuestPost" ), + 'simplehtml' => array( + 'Body' => "Body", + ), 'user' => array( "Author" => "UserId" ), diff --git a/public_html/modules/blog/comment.php b/public_html/modules/blog/comment.php new file mode 100644 index 0000000..109d3a6 --- /dev/null +++ b/public_html/modules/blog/comment.php @@ -0,0 +1,78 @@ + $router->uParameters[1]), 60, true); +} +catch (NotFoundException $e) +{ + throw new RouterException("No such blog post exists."); +} + +$sErrors = array(); + +if(empty($sCurrentUser) && (empty($_POST['name']) && empty($_POST['email']))) +{ + $sErrors[] = "You did not enter a valid name and/or e-mail address."; +} + +if(empty($sCurrentUser) && !User::CheckIfEmailValid($_POST['email'])) +{ + $sErrors[] = "The e-mail address you entered is invalid."; +} + +if(empty($_POST['body'])) +{ + $sErrors[] = "You can't post an empty comment!"; +} + +if(empty($sErrors)) +{ + $sBlogComment = new BlogComment(0); + + $sBlogComment->uPostId = $sBlogPost->sId; + $sBlogComment->uBody = $_POST['body']; + $sBlogComment->uPostedDate = time(); + $sBlogComment->uVisible = true; + + if(!empty($sCurrentUser)) + { + $sBlogComment->uIsGuestPost = false; + $sBlogComment->uName = ""; + $sBlogComment->uEmailAddress = ""; + $sBlogComment->uAuthorId = $sCurrentUser->sId; + } + else + { + $sBlogComment->uIsGuestPost = true; + $sBlogComment->uName = $_POST['name']; + $sBlogComment->uEmailAddress = $_POST['email']; + $sBlogComment->uAuthorId = 0; + } + + $sBlogComment->InsertIntoDatabase(); + + redirect("/blog/{$sBlogPost->sSlug}/#comment_{$sBlogComment->sId}"); +} +else +{ + foreach($sErrors as $sError) + { + flash_error($sError); + } + + redirect("/blog/{$sBlogPost->sSlug}/"); +} diff --git a/public_html/modules/blog/post.php b/public_html/modules/blog/post.php new file mode 100644 index 0000000..13eb9b5 --- /dev/null +++ b/public_html/modules/blog/post.php @@ -0,0 +1,68 @@ + $router->uParameters[1]), 60, true); +} +catch (NotFoundException $e) +{ + throw new RouterException("No such blog post exists."); +} + +try +{ + $result = BlogComment::CreateFromQuery("SELECT * FROM blog_comments WHERE `PostId` = :PostId AND `Visible` = 1 ORDER BY `Posted` ASC", array(":PostId" => $sBlogPost->sId)); +} +catch (NotFoundException $e) +{ + $result = array(); +} + +$sComments = array(); + +foreach($result as $sComment) +{ + if($sComment->sIsGuestPost) + { + $sAuthorName = $sComment->sName; + $sEmailAddress = $sComment->sEmailAddress; + } + else + { + $sAuthorName = $sComment->sAuthor->sUsername; + $sEmailAddress = $sComment->sAuthor->sEmailAddress; + } + + $sComments[] = array( + "author" => $sAuthorName, + "relative-date" => time_ago($sComment->sPostedDate, $locale), + "body" => Markdown($sComment->sBody), + "gravatar" => "https://secure.gravatar.com/avatar/" . md5(strtolower(trim($sEmailAddress))) . ".jpg?d=retro&s=40", + "id" => $sComment->sId + ); +} + +$sPageTitle = $sBlogPost->sTitle; +$sPageContents = NewTemplater::Render("blog/post", $locale->strings, array( + "title" => $sBlogPost->sTitle, + "body" => Markdown($sBlogPost->sBody), + "author" => $sBlogPost->sAuthor->sUsername, + "relative-date" => time_ago($sBlogPost->sPostedDate, $locale), + "thumbnail" => $sBlogPost->sThumbnail, + "tags" => "test1, test2, test3", + "comments" => $sComments, + "slug" => $sBlogPost->sSlug +)); diff --git a/public_html/modules/forums/thread.php b/public_html/modules/forums/thread.php index 4bed0cd..7599c88 100644 --- a/public_html/modules/forums/thread.php +++ b/public_html/modules/forums/thread.php @@ -51,7 +51,7 @@ foreach($result as $sForumPost) "body" => filter_html(Markdown($sForumPost->uBody)), "date" => time_ago($sForumPost->sPostedDate, $locale), "date-full" => local_from_unix($sForumPost->sPostedDate, $locale->datetime_long), - "self" => ($sForumPost->sAuthorId == $sCurrentUser->sId), + "self" => (!empty($sCurrentUser) && $sForumPost->sAuthorId == $sCurrentUser->sId), "gravatar" => "https://secure.gravatar.com/avatar/" . md5(strtolower(trim($sForumPost->sAuthor->sEmailAddress))) . ".jpg?d=retro&s=40", "signature" => filter_html(Markdown($sForumPost->sAuthor->uSignature)), "permalink" => $sForumPost->GetPermalink() diff --git a/public_html/rewrite.php b/public_html/rewrite.php index efe3d32..4a32606 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -14,6 +14,18 @@ $_APP = true; require("include/base.php"); +if(strtolower($_SERVER["REQUEST_METHOD"]) == "post") +{ + try + { + CSRF::VerifyToken(); + } + catch (CsrfException $e) + { + die(); + } +} + $sPageTitle = ""; $sPageContents = ""; @@ -36,6 +48,14 @@ $router->routes = array( "target" => "modules/blog/home.php", "_section" => "Blog" ), + "^/blog/([a-z0-9-]+)$" => array( + "target" => "modules/blog/post.php", + "_section" => "Blog" + ), + "^/blog/([a-z0-9-]+)/comment$" => array( + "target" => "modules/blog/comment.php", + "_section" => "Blog" + ), "^/login$" => array( "target" => "modules/account/login.php", "_section" => "Account" diff --git a/public_html/static/css/style.css b/public_html/static/css/style.css index 7eea492..56f7249 100644 --- a/public_html/static/css/style.css +++ b/public_html/static/css/style.css @@ -424,14 +424,14 @@ a.user .post .body h5 { font-size: 16px; } .post .body h6 { font-size: 14px; } -.post .body blockquote +.post .body blockquote, .comment blockquote { padding: 7px 0px 7px 9px; margin: 9px 0px 9px 6px; border-left: 3px solid #80B380; } -.post .body blockquote p +.post .body blockquote p, .comment blockquote p { margin: 0px; } @@ -558,3 +558,64 @@ button.preview { margin-right: 18px; } + +.comment +{ + border-bottom: 1px solid #D6D6D6; + padding: 7px 6px 7px 65px; +} + +.comment .gravatar +{ + float: left; + border: 1px solid silver; + padding: 1px; + margin: 7px 6px; + margin-left: -57px; +} + +.comment .metadata +{ + padding: 6px 0px 4px 0px; +} + +.comment .metadata .author +{ + font-weight: bold; +} + +.comment .metadata .date +{ + color: #7D7D7D; + margin-left: 10px; + font-size: 15px; +} + +.comment p +{ + margin: 8px 0px; + font-size: 15px; +} + +.comments h2 +{ + margin: 9px 0px 0px 0px; + font-size: 21px; +} + +.comments form +{ + margin-top: 9px; +} + +.comments textarea.body +{ + height: 140px; + margin-top: 2px; +} + +.comments label +{ + font-size: 17px; + margin-top: 8px; +} diff --git a/public_html/templates/blog/post.tpl b/public_html/templates/blog/post.tpl new file mode 100644 index 0000000..8d519b8 --- /dev/null +++ b/public_html/templates/blog/post.tpl @@ -0,0 +1,56 @@ +
+

{%?title}

+ +
+ {%?relative-date}, by + {%?author} + Tags: {%?tags} +
+ {%?body} +
+ +
+

Comments

+ {%if isempty|comments == true} + No comments have been posted yet. + {%else} + {%foreach comment in comments} +
+ + + + {%?comment[body]} +
+ {%/foreach} + {%/if} + +

Post a new comment

+
+
+ {%if logged-in == false} + + + + + + +
+ {%/if} + +
+ +
+ +
+ You can use Markdown. +
+ + + +
+
+
+