From 04fe9ad03a583b523290aa70cd97ff73f76567a5 Mon Sep 17 00:00:00 2001 From: shish Date: Sat, 16 Feb 2008 03:58:05 +0000 Subject: [PATCH] import aliases from file git-svn-id: file:///home/shish/svn/shimmie2/trunk@720 7f39781d-f577-437e-ae19-be835c7a54ca --- ext/alias_editor/main.php | 28 ++++++++++++++++++++++++++++ ext/alias_editor/theme.php | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index ad86957e..7e4c1138 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -48,6 +48,25 @@ class AliasEditor extends Extension { $event->page->set_type("text/plain"); $event->page->set_data($this->get_alias_csv($database)); } + else if($event->get_arg(0) == "import") { + if($event->user->is_admin()) { + print_r($_FILES); + if(count($_FILES) > 0) { + global $database; + $tmp = $_FILES['alias_file']['tmp_name']; + $contents = file_get_contents($tmp); + $this->add_alias_csv($database, $contents); + $event->page->set_mode("redirect"); + $event->page->set_redirect(make_link("alias/list")); + } + else { + $this->theme->display_error($event->page, "No File Specified", "You have to upload a file"); + } + } + else { + $this->theme->display_error($event->page, "Admins Only", "Only admins can edit the alias list"); + } + } } if(is_a($event, 'AddAliasEvent')) { @@ -70,6 +89,15 @@ class AliasEditor extends Extension { } return $csv; } + + private function add_alias_csv($database, $csv) { + foreach(explode("\n", $csv) as $line) { + $parts = explode(",", $line); + if(count($parts) == 2) { + $database->execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", $parts); + } + } + } } add_event_listener(new AliasEditor()); ?> diff --git a/ext/alias_editor/theme.php b/ext/alias_editor/theme.php index b5cd3e07..cfe24c0a 100644 --- a/ext/alias_editor/theme.php +++ b/ext/alias_editor/theme.php @@ -49,6 +49,10 @@ class AliasEditorTheme extends Themelet { $add

Download as CSV

+
+ + +
"; $page->set_title("Alias List");