pull a bunch of small fixes from #659
This commit is contained in:
parent
5765978afd
commit
f078b283bd
@ -619,7 +619,7 @@ class Image
|
||||
);
|
||||
} else {
|
||||
// check if tag has already been written
|
||||
if(in_array($id, $written_tags)) {
|
||||
if (in_array($id, $written_tags)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,9 @@ const MIME_TYPE_MAP = [
|
||||
'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
|
||||
'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
|
||||
'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php',
|
||||
'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm'
|
||||
'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm',
|
||||
'webp' => 'image/webp', 'bmp' =>'image/x-ms-bmp', 'psd' => 'image/vnd.adobe.photoshop',
|
||||
'mkv' => 'video/x-matroska'
|
||||
];
|
||||
|
||||
/**
|
||||
@ -309,7 +311,7 @@ function getMimeType(string $file, string $ext=""): string
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
|
||||
function getExtension(?string $mime_type): ?string
|
||||
function get_extension(?string $mime_type): ?string
|
||||
{
|
||||
if (empty($mime_type)) {
|
||||
return null;
|
||||
|
@ -282,7 +282,7 @@ function path_to_tags(string $path): string
|
||||
{
|
||||
$matches = [];
|
||||
$tags = "";
|
||||
if(preg_match("/\d+ - (.*)\.([a-zA-Z0-9]+)/", basename($path), $matches)) {
|
||||
if (preg_match("/\d+ - (.*)\.([a-zA-Z0-9]+)/", basename($path), $matches)) {
|
||||
$tags = $matches[1];
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ function path_to_tags(string $path): string
|
||||
if ($dir_tags != "") {
|
||||
$tags = trim($tags)." ".trim($dir_tags);
|
||||
}
|
||||
$tags = trim ( $tags );
|
||||
$tags = trim($tags);
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
@ -64,12 +64,11 @@ class BulkAddCSV extends Extension
|
||||
assert(file_exists($tmpname));
|
||||
|
||||
$pathinfo = pathinfo($filename);
|
||||
if (!array_key_exists('extension', $pathinfo)) {
|
||||
throw new UploadException("File has no extension");
|
||||
}
|
||||
$metadata = [];
|
||||
$metadata['filename'] = $pathinfo['basename'];
|
||||
if (array_key_exists('extension', $pathinfo)) {
|
||||
$metadata['extension'] = $pathinfo['extension'];
|
||||
}
|
||||
$metadata['tags'] = Tag::explode($tags);
|
||||
$metadata['source'] = $source;
|
||||
$event = new DataUploadEvent($tmpname, $metadata);
|
||||
|
@ -301,15 +301,15 @@ class CronUploader extends Extension
|
||||
// Move to corrupt dir
|
||||
$newDir .= "/failed_to_upload/".$relativeDir;
|
||||
$info = "ERROR: Image was not uploaded.";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$newDir .= "/uploaded/".$relativeDir;
|
||||
$info = "Image successfully uploaded. ";
|
||||
}
|
||||
$newDir = str_replace ( "//", "/", $newDir."/" );
|
||||
$newDir = str_replace("//", "/", $newDir."/");
|
||||
|
||||
if (!is_dir($newDir))
|
||||
mkdir ( $newDir, 0775, true );
|
||||
if (!is_dir($newDir)) {
|
||||
mkdir($newDir, 0775, true);
|
||||
}
|
||||
|
||||
// move file to correct dir
|
||||
rename($path, $newDir.$filename);
|
||||
@ -325,12 +325,11 @@ class CronUploader extends Extension
|
||||
assert(file_exists($tmpname));
|
||||
|
||||
$pathinfo = pathinfo($filename);
|
||||
if (! array_key_exists('extension', $pathinfo)) {
|
||||
throw new UploadException("File has no extension");
|
||||
}
|
||||
$metadata = [];
|
||||
$metadata ['filename'] = $pathinfo ['basename'];
|
||||
$metadata ['extension'] = $pathinfo ['extension'];
|
||||
if (array_key_exists('extension', $pathinfo)) {
|
||||
$metadata['extension'] = $pathinfo['extension'];
|
||||
}
|
||||
$metadata ['tags'] = Tag::explode($tags);
|
||||
$metadata ['source'] = null;
|
||||
$event = new DataUploadEvent($tmpname, $metadata);
|
||||
@ -344,7 +343,6 @@ class CronUploader extends Extension
|
||||
$infomsg = "Image uploaded. ID: {$event->image_id} - Filename: {$filename} - Tags: {$tags}";
|
||||
}
|
||||
$msgNumber = $this->add_upload_info($infomsg);
|
||||
|
||||
}
|
||||
|
||||
private function generate_image_queue(): void
|
||||
@ -361,7 +359,7 @@ class CronUploader extends Extension
|
||||
if (!is_link($fullpath) && !is_dir($fullpath)) {
|
||||
$pathinfo = pathinfo($fullpath);
|
||||
|
||||
$relativePath = substr($fullpath,strlen($base));
|
||||
$relativePath = substr($fullpath, strlen($base));
|
||||
$tags = path_to_tags($relativePath);
|
||||
|
||||
$img = [
|
||||
|
@ -366,7 +366,9 @@ class DanbooruApi extends Extension
|
||||
$fileinfo = pathinfo($filename);
|
||||
$metadata = [];
|
||||
$metadata['filename'] = $fileinfo['basename'];
|
||||
$metadata['extension'] = $fileinfo['extension'];
|
||||
if (array_key_exists('extension', $pathinfo)) {
|
||||
$metadata['extension'] = $pathinfo['extension'];
|
||||
}
|
||||
$metadata['tags'] = $posttags;
|
||||
$metadata['source'] = $source;
|
||||
//log_debug("danbooru_api","========== NEW($filename) =========");
|
||||
|
@ -155,12 +155,9 @@ class RotateImage extends Extension
|
||||
|
||||
|
||||
/* Attempt to load the image */
|
||||
switch ($info[2]) {
|
||||
case IMAGETYPE_GIF: $image = imagecreatefromgif($image_filename); break;
|
||||
case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($image_filename); break;
|
||||
case IMAGETYPE_PNG: $image = imagecreatefrompng($image_filename); break;
|
||||
default:
|
||||
throw new ImageRotateException("Unsupported image type or ");
|
||||
$image = imagecreatefromstring(file_get_contents($image_filename));
|
||||
if ($image == false) {
|
||||
throw new ImageRotateException("Could not load image: ".$image_filename);
|
||||
}
|
||||
|
||||
/* Rotate and resample the image */
|
||||
|
@ -307,7 +307,9 @@ class Upload extends Extension
|
||||
$pathinfo = pathinfo($file['name']);
|
||||
$metadata = [];
|
||||
$metadata['filename'] = $pathinfo['basename'];
|
||||
if (array_key_exists('extension', $pathinfo)) {
|
||||
$metadata['extension'] = $pathinfo['extension'];
|
||||
}
|
||||
$metadata['tags'] = $tags;
|
||||
$metadata['source'] = $source;
|
||||
|
||||
@ -389,7 +391,7 @@ class Upload extends Extension
|
||||
|
||||
$ext = false;
|
||||
if (is_array($headers)) {
|
||||
$ext = getExtension(findHeader($headers, 'Content-Type'));
|
||||
$ext = get_extension(findHeader($headers, 'Content-Type'));
|
||||
}
|
||||
if ($ext === false) {
|
||||
$ext = $pathinfo['extension'];
|
||||
@ -411,8 +413,8 @@ class Upload extends Extension
|
||||
$metadata['replace'] = $replace;
|
||||
}
|
||||
|
||||
$event = new DataUploadEvent($tmp_filename, $metadata);
|
||||
try {
|
||||
$event = new DataUploadEvent($tmp_filename, $metadata);
|
||||
send_event($event);
|
||||
} catch (UploadException $ex) {
|
||||
$this->theme->display_upload_error(
|
||||
|
Loading…
x
Reference in New Issue
Block a user