search images by comment metadata

This commit is contained in:
Shish
2009-08-03 10:18:40 +01:00
parent f57e67e6e9
commit db7708b6e3
2 changed files with 33 additions and 2 deletions

View File

@@ -154,6 +154,31 @@ class CommentList implements Extension {
$sb->add_text_option("comment_wordpress_key", "<br>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 {{{