import aliases from file
git-svn-id: file:///home/shish/svn/shimmie2/trunk@720 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
c828ce5cfe
commit
04fe9ad03a
2 changed files with 32 additions and 0 deletions
|
@ -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());
|
||||
?>
|
||||
|
|
|
@ -49,6 +49,10 @@ class AliasEditorTheme extends Themelet {
|
|||
$add
|
||||
</table>
|
||||
<p><a href='".make_link("alias/export/aliases.csv")."'>Download as CSV</a></p>
|
||||
<form enctype='multipart/form-data' action='".make_link("alias/import")."' method='POST'>
|
||||
<input type='file' name='alias_file'>
|
||||
<input type='submit' value='Upload List'>
|
||||
</form>
|
||||
";
|
||||
|
||||
$page->set_title("Alias List");
|
||||
|
|
Reference in a new issue