bulk upload / zip upload betterness
This commit is contained in:
parent
db7708b6e3
commit
0f784f0a8d
@ -33,21 +33,21 @@ class BulkAdd extends SimpleExtension {
|
|||||||
|
|
||||||
|
|
||||||
private function add_image($tmpname, $filename, $tags) {
|
private function add_image($tmpname, $filename, $tags) {
|
||||||
if(file_exists($tmpname)) {
|
assert(file_exists($tmpname));
|
||||||
global $user;
|
|
||||||
$pathinfo = pathinfo($filename);
|
global $user;
|
||||||
if(!array_key_exists('extension', $pathinfo)) return;
|
$pathinfo = pathinfo($filename);
|
||||||
$metadata['filename'] = $pathinfo['basename'];
|
if(!array_key_exists('extension', $pathinfo)) {
|
||||||
$metadata['extension'] = $pathinfo['extension'];
|
throw new UploadException("File has no extension");
|
||||||
$metadata['tags'] = $tags;
|
}
|
||||||
$metadata['source'] = null;
|
$metadata['filename'] = $pathinfo['basename'];
|
||||||
try {
|
$metadata['extension'] = $pathinfo['extension'];
|
||||||
$event = new DataUploadEvent($user, $tmpname, $metadata);
|
$metadata['tags'] = $tags;
|
||||||
send_event($event);
|
$metadata['source'] = null;
|
||||||
}
|
$event = new DataUploadEvent($user, $tmpname, $metadata);
|
||||||
catch(Exception $ex) {
|
send_event($event);
|
||||||
return $ex->getMessage();
|
if($event->image_id == -1) {
|
||||||
}
|
throw new UploadException("File type not recognised");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,30 +61,29 @@ class BulkAdd extends SimpleExtension {
|
|||||||
|
|
||||||
$list = "";
|
$list = "";
|
||||||
|
|
||||||
foreach(glob("$base/$subdir/*") as $filename) {
|
foreach(glob("$base/$subdir/*") as $fullpath) {
|
||||||
$fullpath = "$base/$subdir/$filename";
|
$fullpath = str_replace("//", "/", $fullpath);
|
||||||
|
$shortpath = str_replace($base, "", $fullpath);
|
||||||
|
|
||||||
if(is_link($fullpath)) {
|
if(is_link($fullpath)) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
else if(is_dir($fullpath)) {
|
else if(is_dir($fullpath)) {
|
||||||
if($filename[0] != ".") {
|
$this->add_dir($base, str_replace($base, "", $fullpath));
|
||||||
$this->add_dir($base, "$subdir/$filename");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tmpfile = $fullpath;
|
$pathinfo = pathinfo($fullpath);
|
||||||
$tags = $subdir;
|
$tags = $subdir;
|
||||||
$tags = str_replace("/", " ", $tags);
|
$tags = str_replace("/", " ", $tags);
|
||||||
$tags = str_replace("__", " ", $tags);
|
$tags = str_replace("__", " ", $tags);
|
||||||
$tags = trim($tags);
|
$tags = trim($tags);
|
||||||
$list .= "<br>".html_escape("$subdir/$filename (".str_replace(" ", ", ", $tags).")... ");
|
$list .= "<br>".html_escape("$shortpath (".str_replace(" ", ", ", $tags).")... ");
|
||||||
$error = $this->add_image($tmpfile, $filename, $tags);
|
try{
|
||||||
if(is_null($error)) {
|
$this->add_image($fullpath, $pathinfo["basename"], $tags);
|
||||||
$list .= "ok\n";
|
$list .= "ok\n";
|
||||||
}
|
}
|
||||||
else {
|
catch(Exception $ex) {
|
||||||
$list .= "failed:<br>$error\n";
|
$list .= "failed:<br>". $ex->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,11 @@ class ArchiveFileHandler extends SimpleExtension {
|
|||||||
$tmp = sys_get_temp_dir();
|
$tmp = sys_get_temp_dir();
|
||||||
$tmpdir = "$tmp/shimmie-archive-{$event->hash}";
|
$tmpdir = "$tmp/shimmie-archive-{$event->hash}";
|
||||||
$cmd = $config->get_string('archive_extract_command');
|
$cmd = $config->get_string('archive_extract_command');
|
||||||
$cmd = str_replace('%f', $event->tmpfile);
|
$cmd = str_replace('%f', $event->tmpname, $cmd);
|
||||||
$cmd = str_replace('%d', $tmpdir);
|
$cmd = str_replace('%d', $tmpdir, $cmd);
|
||||||
system($cmd);
|
exec($cmd);
|
||||||
$this->add_dir($tmpdir);
|
$this->add_dir($tmpdir);
|
||||||
unlink($tmpdir);
|
deltree($tmpdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,20 +46,23 @@ class ArchiveFileHandler extends SimpleExtension {
|
|||||||
|
|
||||||
// copied from bulk add extension
|
// copied from bulk add extension
|
||||||
private function add_image($tmpname, $filename, $tags) {
|
private function add_image($tmpname, $filename, $tags) {
|
||||||
if(file_exists($tmpname)) {
|
assert(file_exists($tmpname));
|
||||||
|
|
||||||
|
try {
|
||||||
global $user;
|
global $user;
|
||||||
$pathinfo = pathinfo($filename);
|
$pathinfo = pathinfo($filename);
|
||||||
|
if(!array_key_exists('extension', $pathinfo)) {
|
||||||
|
throw new UploadException("File has no extension");
|
||||||
|
}
|
||||||
$metadata['filename'] = $pathinfo['basename'];
|
$metadata['filename'] = $pathinfo['basename'];
|
||||||
$metadata['extension'] = $pathinfo['extension'];
|
$metadata['extension'] = $pathinfo['extension'];
|
||||||
$metadata['tags'] = $tags;
|
$metadata['tags'] = $tags;
|
||||||
$metadata['source'] = null;
|
$metadata['source'] = null;
|
||||||
try {
|
$event = new DataUploadEvent($user, $tmpname, $metadata);
|
||||||
$event = new DataUploadEvent($user, $tmpname, $metadata);
|
send_event($event);
|
||||||
send_event($event);
|
}
|
||||||
}
|
catch(UploadException $ex) {
|
||||||
catch(UploadException $ex) {
|
return $ex->getMessage();
|
||||||
return $ex->getMessage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user