This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/contrib/autocomplete/main.php
shish a625fcd787 the bulk of theme engine 2.0; it's still rough, but it works
git-svn-id: file:///home/shish/svn/shimmie2/trunk@201 7f39781d-f577-437e-ae19-be835c7a54ca
2007-06-30 01:19:11 +00:00

27 lines
883 B
PHP

<?php
class AutoComplete extends Extension {
// event handling {{{
public function receive_event($event) {
if(is_a($event, 'PageRequestEvent') && ($event->page == "index" || $event->page == "view")) {
global $page;
$page->add_header("<script>autocomplete_url='".html_escape(make_link("autocomplete"))."';</script>");
}
if(is_a($event, 'PageRequestEvent') && ($event->page == "autocomplete")) {
global $page;
$page->set_mode("data");
$page->set_type("text/plain");
$page->set_data($this->get_completions($event->get_arg(0)));
}
}
// }}}
// do things {{{
private function get_completions($start) {
global $database;
$tags = $database->db->GetCol("SELECT tag,count(image_id) AS count FROM tags WHERE tag LIKE ? GROUP BY tag ORDER BY count DESC", array($start.'%'));
return implode("\n", $tags);
}
// }}}
}
add_event_listener(new AutoComplete());
?>