search images by comment metadata
This commit is contained in:
parent
f57e67e6e9
commit
db7708b6e3
@ -154,6 +154,31 @@ class CommentList implements Extension {
|
|||||||
$sb->add_text_option("comment_wordpress_key", "<br>Akismet Key ");
|
$sb->add_text_option("comment_wordpress_key", "<br>Akismet Key ");
|
||||||
$event->panel->add_block($sb);
|
$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 {{{
|
// installer {{{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
class CommentListTest extends ShimmieWebTestCase {
|
class CommentListTest extends ShimmieWebTestCase {
|
||||||
function testCommentsPage() {
|
function testCommentsPage() {
|
||||||
$this->log_in_as_user();
|
$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
|
# a good comment
|
||||||
$this->get_page("post/view/$image_id");
|
$this->get_page("post/view/$image_id");
|
||||||
@ -28,12 +28,18 @@ class CommentListTest extends ShimmieWebTestCase {
|
|||||||
$this->click("Post Comment");
|
$this->click("Post Comment");
|
||||||
$this->assertText("Comments need text...");
|
$this->assertText("Comments need text...");
|
||||||
|
|
||||||
# repetitive (gzip gives 10x improvement)
|
# repetitive (aka. gzip gives >= 10x improvement)
|
||||||
$this->get_page("post/view/$image_id");
|
$this->get_page("post/view/$image_id");
|
||||||
$this->setField('comment', str_repeat("U", 5000));
|
$this->setField('comment', str_repeat("U", 5000));
|
||||||
$this->click("Post Comment");
|
$this->click("Post Comment");
|
||||||
$this->assertText("Comment too repetitive~");
|
$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->log_out();
|
||||||
|
|
||||||
$this->get_page('comment/list');
|
$this->get_page('comment/list');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user