oldtag = $oldtag; $this->newtag = $newtag; } } class AliasEditor extends Extension { // event handler {{{ public function receive_event($event) { if(is_a($event, 'PageRequestEvent') && ($event->page == "alias")) { global $user; if($user->is_admin()) { if($event->get_arg(0) == "add") { if(isset($_POST['oldtag']) && isset($_POST['newtag'])) { send_event(new AddAliasEvent($_POST['oldtag'], $_POST['newtag'])); } } else if($event->get_arg(0) == "remove") { if(isset($_POST['oldtag'])) { global $database; $database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag'])); global $page; $page->set_mode("redirect"); $page->set_redirect(make_link("admin")); } } else if($event->get_arg(0) == "list") { global $page; $page->set_title("Alias List"); $page->set_heading("Alias List"); $page->add_main_block(new Block("Aliases", $this->build_aliases())); } else if($event->get_arg(0) == "export") { global $page; $page->set_mode("data"); $page->set_type("text/plain"); $page->set_data($this->get_alias_csv()); } } } if(is_a($event, 'AddAliasEvent')) { global $database; $database->Execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", array($event->oldtag, $event->newtag)); global $page; $page->set_mode("redirect"); $page->set_redirect(make_link("admin")); } if(is_a($event, 'UserBlockBuildingEvent')) { if($event->user->is_admin()) { $event->add_link("Alias Editor", make_link("alias/list")); } } } // }}} // admin page HTML {{{ private function build_aliases() { global $database; $h_aliases = ""; $aliases = $database->db->GetAssoc("SELECT oldtag, newtag FROM aliases"); foreach($aliases as $old => $new) { $h_old = html_escape($old); $h_new = html_escape($new); $h_aliases .= " $h_old $h_new
"; } $html = " $h_aliases
FromToAction

Export "; return $html; } private function get_alias_csv() { global $database; $csv = ""; $aliases = $database->db->GetAssoc("SELECT oldtag, newtag FROM aliases"); foreach($aliases as $old => $new) { $csv .= "$old,$new\n"; } return $csv; } // }}} } add_event_listener(new AliasEditor()); ?>