diff --git a/ext/comment/main.php b/ext/comment/main.php index 96abf62b..b09b30e7 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -154,6 +154,31 @@ class CommentList implements Extension { $sb->add_text_option("comment_wordpress_key", "
Akismet Key "); $event->panel->add_block($sb); } + + if(is_a($event, 'SearchTermParseEvent')) { + $matches = array(); + if(preg_match("/comments(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) { + $cmp = $matches[1]; + $comments = $matches[2]; + $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM comments GROUP BY image_id HAVING count(image_id) $cmp $comments)")); + } + else if(preg_match("/commented_by=(.*)/i", $event->term, $matches)) { + global $database; + $user = User::by_name($matches[1]); + if(!is_null($user)) { + $user_id = $user->id; + } + else { + $user_id = -1; + } + + $event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM comments WHERE owner_id = $user_id)")); + } + else if(preg_match("/commented_by_userid=([0-9]+)/i", $event->term, $matches)) { + $user_id = int_escape($matches[1]); + $event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM comments WHERE owner_id = $user_id)")); + } + } } // }}} // installer {{{ diff --git a/ext/comment/test.php b/ext/comment/test.php index ba4d0413..286f8858 100644 --- a/ext/comment/test.php +++ b/ext/comment/test.php @@ -2,7 +2,7 @@ class CommentListTest extends ShimmieWebTestCase { function testCommentsPage() { $this->log_in_as_user(); - $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot"); + $image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx"); # a good comment $this->get_page("post/view/$image_id"); @@ -28,12 +28,18 @@ class CommentListTest extends ShimmieWebTestCase { $this->click("Post Comment"); $this->assertText("Comments need text..."); - # repetitive (gzip gives 10x improvement) + # repetitive (aka. gzip gives >= 10x improvement) $this->get_page("post/view/$image_id"); $this->setField('comment', str_repeat("U", 5000)); $this->click("Post Comment"); $this->assertText("Comment too repetitive~"); + # test that search by comment metadata works + $this->get_page("post/list/commented_by=test/1"); + $this->assertTitle("Image $image_id: pbx"); + $this->get_page("post/list/comments=1/1"); + $this->assertTitle("Image $image_id: pbx"); + $this->log_out(); $this->get_page('comment/list');