2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AddAliasEvent extends Event {
|
|
|
|
var $oldtag;
|
|
|
|
var $newtag;
|
|
|
|
|
|
|
|
public function AddAliasEvent($oldtag, $newtag) {
|
|
|
|
$this->oldtag = $oldtag;
|
|
|
|
$this->newtag = $newtag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AliasEditor extends Extension {
|
2007-06-30 01:19:11 +00:00
|
|
|
var $theme;
|
2007-07-05 21:30:37 +00:00
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
public function receive_event($event) {
|
2007-06-30 01:19:11 +00:00
|
|
|
if(is_null($this->theme)) $this->theme = get_theme_object("alias_editor", "AliasEditorTheme");
|
|
|
|
|
2007-07-17 07:45:35 +00:00
|
|
|
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "alias")) {
|
2007-06-04 03:31:52 +00:00
|
|
|
if($event->get_arg(0) == "add") {
|
2007-08-24 22:29:34 +00:00
|
|
|
if($event->user->is_admin()) {
|
2007-04-16 11:58:25 +00:00
|
|
|
if(isset($_POST['oldtag']) && isset($_POST['newtag'])) {
|
|
|
|
send_event(new AddAliasEvent($_POST['oldtag'], $_POST['newtag']));
|
2007-07-17 07:45:35 +00:00
|
|
|
|
|
|
|
$event->page->set_mode("redirect");
|
|
|
|
$event->page->set_redirect(make_link("alias/list"));
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-04 03:31:52 +00:00
|
|
|
}
|
|
|
|
else if($event->get_arg(0) == "remove") {
|
2007-08-24 22:29:34 +00:00
|
|
|
if($event->user->is_admin()) {
|
2007-04-16 11:58:25 +00:00
|
|
|
if(isset($_POST['oldtag'])) {
|
|
|
|
global $database;
|
2007-05-23 22:19:12 +00:00
|
|
|
$database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
|
2007-06-30 01:19:11 +00:00
|
|
|
|
2007-07-17 07:45:35 +00:00
|
|
|
$event->page->set_mode("redirect");
|
|
|
|
$event->page->set_redirect(make_link("alias/list"));
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-04 03:31:52 +00:00
|
|
|
}
|
|
|
|
else if($event->get_arg(0) == "list") {
|
2007-06-30 01:19:11 +00:00
|
|
|
global $database;
|
2007-08-24 22:29:34 +00:00
|
|
|
$this->theme->display_aliases($event->page, $database->db->GetAssoc("SELECT oldtag, newtag FROM aliases"), $event->user->is_admin());
|
2007-06-04 03:31:52 +00:00
|
|
|
}
|
|
|
|
else if($event->get_arg(0) == "export") {
|
2007-10-18 02:35:01 +00:00
|
|
|
global $database;
|
2007-07-17 07:45:35 +00:00
|
|
|
$event->page->set_mode("data");
|
|
|
|
$event->page->set_type("text/plain");
|
2007-10-18 02:35:01 +00:00
|
|
|
$event->page->set_data($this->get_alias_csv($database));
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_a($event, 'AddAliasEvent')) {
|
|
|
|
global $database;
|
2007-05-23 22:19:12 +00:00
|
|
|
$database->Execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", array($event->oldtag, $event->newtag));
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-06-04 02:35:28 +00:00
|
|
|
|
|
|
|
if(is_a($event, 'UserBlockBuildingEvent')) {
|
|
|
|
if($event->user->is_admin()) {
|
|
|
|
$event->add_link("Alias Editor", make_link("alias/list"));
|
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-10-18 02:35:01 +00:00
|
|
|
|
|
|
|
private function get_alias_csv($database) {
|
|
|
|
$csv = "";
|
|
|
|
$aliases = $database->db->GetAssoc("SELECT oldtag, newtag FROM aliases");
|
|
|
|
foreach($aliases as $old => $new) {
|
|
|
|
$csv .= "$old,$new\n";
|
|
|
|
}
|
|
|
|
return $csv;
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
add_event_listener(new AliasEditor());
|
|
|
|
?>
|