Permalink
Browse files

Merge branch 'disable_comments'

  • Loading branch information...
2 parents 8818e8e + 5d962dc commit aeb4d47c63934056684751457d0b2846a5dd57c4 @makeusabrew committed Apr 5, 2012
@@ -72,6 +72,7 @@ public function edit_post() {
"tags" => $this->request->getVar('tags'),
"head_block" => $this->request->getVar('head_block'),
"script_block" => $this->request->getVar('script_block'),
+ "comments_enabled" => $this->request->getVar('comments_enabled'),
);
if ($this->post->updateValues($data)) {
$this->post->save();
@@ -97,6 +98,7 @@ public function add_post() {
"user_id" => $this->adminUser->getId(),
"head_block" => $this->request->getVar('head_block'),
"script_block" => $this->request->getVar('script_block'),
+ "comments_enabled" => $this->request->getVar('comments_enabled'),
);
$post = Table::factory('Posts')->newObject();
if ($post->setValues($data)) {
@@ -10,6 +10,7 @@
{include file='default/views/helpers/field.tpl' field='tags'}
{include file='default/views/helpers/field.tpl' field='head_block'}
{include file='default/views/helpers/field.tpl' field='script_block'}
+ {include file='default/views/helpers/field.tpl' field='comments_enabled'}
<div class="actions">
<input type="submit" id="save-button" value="Save" class="btn primary" />
<a href="/admin" class="btn danger">Go Back</a>
@@ -46,6 +46,9 @@ public function view_post() {
}
public function add_comment() {
+ if (!$this->post->commentsEnabled()) {
+ return $this->redirect("/".$this->post->getUrl());
+ }
// very basic honeypot stuff
if ($this->request->getVar("details")) {
$this->setErrors(array(
@@ -32,6 +32,10 @@ public function getUnapprovedCommentsCount() {
));
}
+ public function commentsEnabled() {
+ return !!$this->comments_enabled;
+ }
+
public function getPublishedRelatedPostsCount() {
return count(
$this->getPublishedRelatedPosts()
@@ -149,6 +153,10 @@ class Posts extends Table {
'required' => false,
'title' => 'Script Block',
),
+ 'comments_enabled' => array(
+ 'type' => 'bool',
+ 'title' => 'Comments Enabled?',
+ ),
),
);
@@ -43,7 +43,7 @@ public function testCommentFormWithValidData() {
$this->assertRedirect(true);
$this->assertRedirectUrl("/2011/09/another-test-post/comment/thanks#comments");
$this->request->reset();
- // @todo fix the dispatch stuff? - it chokes on anchor tags. poss not required
+
$this->request->dispatch("/2011/09/another-test-post/comment/thanks");
$this->assertBodyHasContents("<strong>Thanks!</strong> Your comment has been submitted and will be reviewed shortly.");
}
@@ -264,4 +264,36 @@ public function testRelatedArticlesOnlyShowPublished() {
$this->assertBodyHasContentsInOrder("This Is A Test Post");
$this->assertBodyDoesNotHaveContents("This post hasn't been published");
}
+
+ public function testCommentsFormShownOnEnabledPost() {
+ $this->request->dispatch("/2011/07/just-a-test");
+
+ $this->assertBodyHasContentsInOrder("Comments");
+ $this->assertBodyHasContentsInOrder("Add Your Own");
+ $this->assertBodyDoesNotHaveContents("Comments are now closed.");
+ }
+
+ public function testCommentsFormNotShownOnDisabledPost() {
+ $this->request->dispatch("/2011/03/test-post-for-comments");
+
+ $this->assertBodyHasContentsInOrder("Comments");
+ $this->assertBodyHasContentsInOrder("Comments are now closed.");
+ $this->assertBodyDoesNotHaveContents("Add Your Own");
+ }
+
+ public function testCommentSubmissionOnDisabledPost() {
+ TestEmailHandler::resetSentEmails();
+
+ $this->request->setMethod("POST")->setParams(array(
+ "name" => "Valid Comment",
+ "email" => "test@example.com",
+ "content" => "This is a valid message, but comments are disabled",
+ ))->dispatch("/2011/03/test-post-for-comments/comment");
+
+ $emails = TestEmailHandler::getSentEmails();
+ $this->assertEquals(0, count($emails));
+
+ $this->assertRedirect(true);
+ $this->assertRedirectUrl("/2011/03/test-post-for-comments");
+ }
}
@@ -64,4 +64,9 @@ public function testGetUnpublishedRelatedPostsCount() {
$this->assertEquals(0, Table::factory('Posts')->read(6)->getUnpublishedRelatedPostsCount());
$this->assertEquals(1, Table::factory('Posts')->read(7)->getUnpublishedRelatedPostsCount());
}
+
+ public function testCommentsEnabled() {
+ $this->assertTrue(Table::factory('Posts')->read(1)->commentsEnabled());
+ $this->assertFalse(Table::factory('Posts')->read(8)->commentsEnabled());
+ }
}
@@ -14,7 +14,7 @@ public function setUp() {
}
public function testFindRecentIgnoresNonPublishedAndFuturePublishedPosts() {
- $this->assertEquals(4, count($this->table->findRecent()));
+ $this->assertEquals(5, count($this->table->findRecent()));
}
public function testFindByUrlIgnoresFuturePosts() {
@@ -40,12 +40,14 @@ public function testFindMonthsWithPublishedPostsDoesNotReturnDuplicates() {
$this->assertEquals(array(
"2011-09-01",
"2011-07-01",
+ "2011-03-01",
), $this->table->findMonthsWithPublishedPosts());
}
public function testFindAllTagsReturnsNaturallySortedArray() {
$this->assertEquals(array(
"apache",
+ "comments",
"music",
"node.js",
"php",
@@ -36,7 +36,7 @@
</div>
{foreachelse}
{if !isset($comment_submitted)}
- <p class='no-comments'>There are currently no comments - feel free to add one!</p>
+ <p class='no-comments'>There are currently no comments{if $post->commentsEnabled()} - feel free to add one!{else}.{/if}</p>
{/if}
{/foreach}
{if isset($comment_submitted)}
@@ -46,34 +46,38 @@
{/if}
</div>
{if !isset($comment_submitted)}
- <div id='add-comment'>
- <div class='page-header'>
- <h3>Add Your Own</h3>
- </div>
- <div class='form-wrapper'>
- <div class='small'>
- <p>We don't publish your email address and won't send you any spam.
- We do capture your IP address for auditing purposes and your comment
- may be moderated before it appears.</p>
+ {if $post->commentsEnabled()}
+ <div id='add-comment'>
+ <div class='page-header'>
+ <h3>Add Your Own</h3>
</div>
- <form class="form-horizontal" action="/{$post->getUrl()}/comment#comments" method="post">
- {include file='default/views/helpers/field.tpl' field='name' placeholder='Anonymous' required=false icon="icon-user"}
- {include file='default/views/helpers/field.tpl' field='email' icon="icon-envelope"}
- {include file='default/views/helpers/field.tpl' field='content'}
- {include file='default/views/helpers/field.tpl' field='notifications'}
- <div class="comment-details">
- {if isset($_errors) && isset($_errors.details)}
- <p>{$_errors.details}</p>
- {/if}
- <label for="details">Please&mdash;don&rsquo;t fill this field in! <span class='required'>*</span></label>
- <input type="text" name="details" id="details" value="{if isset($smarty.post.details)}{$smarty.post.details|htmlentities8}{/if}" />
- </div>
- <div class="form-actions">
- <input type="submit" value="Send" class="btn btn-primary" />
+ <div class='form-wrapper'>
+ <div class='small'>
+ <p>We don't publish your email address and won't send you any spam.
+ We do capture your IP address for auditing purposes and your comment
+ may be moderated before it appears.</p>
</div>
- </form>
+ <form class="form-horizontal" action="/{$post->getUrl()}/comment#comments" method="post">
+ {include file='default/views/helpers/field.tpl' field='name' placeholder='Anonymous' required=false icon="icon-user"}
+ {include file='default/views/helpers/field.tpl' field='email' icon="icon-envelope"}
+ {include file='default/views/helpers/field.tpl' field='content'}
+ {include file='default/views/helpers/field.tpl' field='notifications'}
+ <div class="comment-details">
+ {if isset($_errors) && isset($_errors.details)}
+ <p>{$_errors.details}</p>
+ {/if}
+ <label for="details">Please&mdash;don&rsquo;t fill this field in! <span class='required'>*</span></label>
+ <input type="text" name="details" id="details" value="{if isset($smarty.post.details)}{$smarty.post.details|htmlentities8}{/if}" />
+ </div>
+ <div class="form-actions">
+ <input type="submit" value="Send" class="btn btn-primary" />
+ </div>
+ </form>
+ </div>
</div>
- </div>
+ {else}
+ <p>Comments are now closed.</p>
+ {/if}
{/if}
</div>
{/block}
@@ -37,7 +37,7 @@ public function testLogoutSetsUserAsNotAuthed() {
public function testGetAllPostsCountIsCorrect() {
$user = Table::factory('Users')->read(1);
- $this->assertEquals(4, count($user->getAllPosts()));
+ $this->assertEquals(5, count($user->getAllPosts()));
}
public function testToArrayRemovesSensitiveInformation() {
@@ -1,8 +1,8 @@
--- MySQL dump 10.13 Distrib 5.1.58, for debian-linux-gnu (x86_64)
+-- MySQL dump 10.13 Distrib 5.5.20, for debian-linux-gnu (i686)
--
-- Host: localhost Database: paynedigital_test
-- ------------------------------------------------------
--- Server version 5.1.58-1ubuntu1
+-- Server version 5.5.20-0~ppa1~oneiric-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -99,13 +99,14 @@ CREATE TABLE `posts` (
`tags` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`head_block` text COLLATE utf8_unicode_ci NOT NULL,
`script_block` text COLLATE utf8_unicode_ci NOT NULL,
+ `comments_enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `url` (`url`),
KEY `user_id` (`user_id`),
KEY `published` (`published`),
KEY `status` (`status`),
KEY `tags` (`tags`)
-) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -114,7 +115,7 @@ CREATE TABLE `posts` (
LOCK TABLES `posts` WRITE;
/*!40000 ALTER TABLE `posts` DISABLE KEYS */;
-INSERT INTO `posts` VALUES (1,1,'This Is A Test Post','this-is-a-test-post','<p>This is simply a test post.</p>\r\n<p>It doesn\'t do <strong>much</strong> <em>at</em> <small>all</small>.','<p>This is simply a test post.</p>\r\n<p>It doesn\'t do <strong>much</strong> <em>at</em> <small>all</small>.','2011-09-14 17:34:41','PUBLISHED','2011-09-14 17:34:41','2011-09-14 17:34:41','|web|apache|music|test|','<link rel=\"stylesheet\" type=\"text/css\" href=\"/foo/bar.css\" />','<script type=\"text/javascript\" src=\"/foo/bar.js\"></script>'),(2,1,'This post hasn\'t been published','not-published-yet','<p>This post hasn\'t been published yet.</p>','<p>This post hasn\'t been published yet.</p>','2010-01-01 12:00:00','DRAFT','2011-09-14 17:34:41','2011-09-14 17:34:41','|apache|test|','',''),(3,2,'Another Test Post','another-test-post','<p>This test post doesn\'t do much either - it\'s only here to test that posts appear in the correct order.</p>','<p>This test post doesn\'t do much either - it\'s only here to test that posts appear in the correct order.</p>','2011-09-14 18:13:47','PUBLISHED','2011-09-14 18:13:47','2011-09-14 18:13:47','|test|php|apache|','',''),(4,1,'This Post Has Been Deleted','this-post-has-been-deleted','<p>Oh well. Nevermind.</p>','<p>Oh well. Nevermind.</p>','2011-09-15 14:43:11','DELETED','2011-09-15 14:43:11','2011-09-15 14:43:11','|test|','',''),(5,1,'This post will be published in the future','this-post-will-be-published-in-future','<p>This is a test post to check that posts marked with a status of \'published\' don\'t appear until their published date.</p>','<p>This is a test post to check that posts marked with a status of \'published\' don\'t appear until their published date.</p>','2021-01-01 00:00:00','PUBLISHED','2011-09-17 11:40:16','2011-09-17 11:40:16','|test|published|','',''),(6,2,'Testing Tags','testing-tags','<p>This post just tests tags with spaces.</p>','<p>This post just tests tags with spaces.</p>','2011-09-11 12:32:08','PUBLISHED','2011-09-11 12:32:08','2011-09-11 12:32:08','|test|Server Administration|node.js|','',''),(7,2,'Just A Test','just-a-test','<p>This is just a test post. It has no tags.</p>','<p>This is just a test post. It has no tags.</p>','2011-07-01 00:00:00','PUBLISHED','2011-07-01 00:00:00','2011-07-01 00:00:00','','','');
+INSERT INTO `posts` VALUES (1,1,'This Is A Test Post','this-is-a-test-post','<p>This is simply a test post.</p>\r\n<p>It doesn\'t do <strong>much</strong> <em>at</em> <small>all</small>.','<p>This is simply a test post.</p>\r\n<p>It doesn\'t do <strong>much</strong> <em>at</em> <small>all</small>.','2011-09-14 17:34:41','PUBLISHED','2011-09-14 17:34:41','2011-09-14 17:34:41','|web|apache|music|test|','<link rel=\"stylesheet\" type=\"text/css\" href=\"/foo/bar.css\" />','<script type=\"text/javascript\" src=\"/foo/bar.js\"></script>',1),(2,1,'This post hasn\'t been published','not-published-yet','<p>This post hasn\'t been published yet.</p>','<p>This post hasn\'t been published yet.</p>','2010-01-01 12:00:00','DRAFT','2011-09-14 17:34:41','2011-09-14 17:34:41','|apache|test|','','',1),(3,2,'Another Test Post','another-test-post','<p>This test post doesn\'t do much either - it\'s only here to test that posts appear in the correct order.</p>','<p>This test post doesn\'t do much either - it\'s only here to test that posts appear in the correct order.</p>','2011-09-14 18:13:47','PUBLISHED','2011-09-14 18:13:47','2011-09-14 18:13:47','|test|php|apache|','','',1),(4,1,'This Post Has Been Deleted','this-post-has-been-deleted','<p>Oh well. Nevermind.</p>','<p>Oh well. Nevermind.</p>','2011-09-15 14:43:11','DELETED','2011-09-15 14:43:11','2011-09-15 14:43:11','|test|','','',1),(5,1,'This post will be published in the future','this-post-will-be-published-in-future','<p>This is a test post to check that posts marked with a status of \'published\' don\'t appear until their published date.</p>','<p>This is a test post to check that posts marked with a status of \'published\' don\'t appear until their published date.</p>','2021-01-01 00:00:00','PUBLISHED','2011-09-17 11:40:16','2011-09-17 11:40:16','|test|published|','','',1),(6,2,'Testing Tags','testing-tags','<p>This post just tests tags with spaces.</p>','<p>This post just tests tags with spaces.</p>','2011-09-11 12:32:08','PUBLISHED','2011-09-11 12:32:08','2011-09-11 12:32:08','|test|Server Administration|node.js|','','',1),(7,2,'Just A Test','just-a-test','<p>This is just a test post. It has no tags.</p>','<p>This is just a test post. It has no tags.</p>','2011-07-01 00:00:00','PUBLISHED','2011-07-01 00:00:00','2011-07-01 00:00:00','','','',1),(8,1,'A test post for comments','test-post-for-comments','<p>This is simply a test post.</p>\r\n<p>It doesn\'t do <strong>much</strong> <em>at</em> <small>all</small>.','<p>This is simply a test post.</p>\r\n<p>It doesn\'t do <strong>much</strong> <em>at</em> <small>all</small>.','2011-03-11 17:34:41','PUBLISHED','2011-03-11 17:34:41','2011-03-11 17:34:41','|comments|','','',0);
/*!40000 ALTER TABLE `posts` ENABLE KEYS */;
UNLOCK TABLES;
@@ -279,4 +280,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2012-01-25 21:22:17
+-- Dump completed on 2012-04-05 8:39:33

0 comments on commit aeb4d47

Please sign in to comment.