pull a bunch of small fixes from #659

This commit is contained in:
Shish 2019-06-14 13:16:58 +01:00
parent 5765978afd
commit f078b283bd
13 changed files with 61 additions and 61 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -281,20 +281,20 @@ function manual_include(string $fname): ?string
function path_to_tags(string $path): string
{
$matches = [];
$tags = "";
if(preg_match("/\d+ - (.*)\.([a-zA-Z0-9]+)/", basename($path), $matches)) {
$tags = "";
if (preg_match("/\d+ - (.*)\.([a-zA-Z0-9]+)/", basename($path), $matches)) {
$tags = $matches[1];
}
$dir_tags = dirname($path);
$dir_tags = str_replace("/", " ", $dir_tags);
$dir_tags = str_replace("__", " ", $dir_tags);
$dir_tags = trim($dir_tags);
if ($dir_tags != "") {
$tags = trim($tags)." ".trim($dir_tags);
}
$tags = trim ( $tags );
}
$dir_tags = dirname($path);
$dir_tags = str_replace("/", " ", $dir_tags);
$dir_tags = str_replace("__", " ", $dir_tags);
$dir_tags = trim($dir_tags);
if ($dir_tags != "") {
$tags = trim($tags)." ".trim($dir_tags);
}
$tags = trim($tags);
return $tags;
}

View file

@ -37,9 +37,9 @@ class BulkAdd extends Extension
set_time_limit(0);
$bae = new BulkAddEvent($_POST['dir']);
send_event($bae);
foreach ($bae->results as $result) {
$this->theme->add_status("Adding files", $result);
}
foreach ($bae->results as $result) {
$this->theme->add_status("Adding files", $result);
}
$this->theme->display_upload_results($page);
}
}

View file

@ -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'];
$metadata['extension'] = $pathinfo['extension'];
if (array_key_exists('extension', $pathinfo)) {
$metadata['extension'] = $pathinfo['extension'];
}
$metadata['tags'] = Tag::explode($tags);
$metadata['source'] = $source;
$event = new DataUploadEvent($tmpname, $metadata);

View file

@ -274,7 +274,7 @@ class CronUploader extends Extension
} catch (Exception $e) {
$this->move_uploaded($img[0], $img[1], true);
if (strpos($e->getMessage(), 'SQLSTATE') !== false) {
// Postgres invalidates the transaction if there is an SQL error,
// Postgres invalidates the transaction if there is an SQL error,
// so all subsequence transactions will fail.
break;
}
@ -296,20 +296,20 @@ class CronUploader extends Extension
$relativeDir = dirname(substr($path, strlen($this->root_dir) + 7));
// Determine which dir to move to
if ($corrupt) {
// Move to corrupt dir
$newDir .= "/failed_to_upload/".$relativeDir;
$info = "ERROR: Image was not uploaded.";
}
else {
$newDir .= "/uploaded/".$relativeDir;
$info = "Image successfully uploaded. ";
}
$newDir = str_replace ( "//", "/", $newDir."/" );
// Determine which dir to move to
if ($corrupt) {
// Move to corrupt dir
$newDir .= "/failed_to_upload/".$relativeDir;
$info = "ERROR: Image was not uploaded.";
} else {
$newDir .= "/uploaded/".$relativeDir;
$info = "Image successfully uploaded. ";
}
$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,13 +325,12 @@ 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'];
$metadata ['tags'] = Tag::explode($tags);
if (array_key_exists('extension', $pathinfo)) {
$metadata['extension'] = $pathinfo['extension'];
}
$metadata ['tags'] = Tag::explode($tags);
$metadata ['source'] = null;
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);
@ -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 = [

View file

@ -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) =========");

View file

@ -362,8 +362,8 @@ class PoolsTheme extends Themelet
} elseif ($history['action'] == 0) {
$prefix = "-";
} else {
throw new Exception("history['action'] not in {0, 1}");
}
throw new Exception("history['action'] not in {0, 1}");
}
$images = trim($history['images']);
$images = explode(" ", $images);

View file

@ -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 */

View file

@ -123,8 +123,8 @@ class Rule34 extends Extension
}
}
$page->set_mode("redirect");
$page->set_redirect(make_link("admin"));
$page->set_mode("redirect");
$page->set_redirect(make_link("admin"));
}
}

View file

@ -75,7 +75,7 @@ class TagEditCloud extends Extension
$ignore_tags = Tag::explode($config->get_string("tageditcloud_ignoretags"));
$cat_color = [];
$cat_color = [];
if (ext_is_live("TagCategories")) {
$categories = $database->get_all("SELECT category, color FROM image_tag_categories");
foreach ($categories as $row) {

View file

@ -307,7 +307,9 @@ class Upload extends Extension
$pathinfo = pathinfo($file['name']);
$metadata = [];
$metadata['filename'] = $pathinfo['basename'];
$metadata['extension'] = $pathinfo['extension'];
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(

View file

@ -491,8 +491,8 @@ class Wiki extends Extension
return "--- $value\n";
break;
default:
throw new Exception("stat needs to be =, + or -");
default:
throw new Exception("stat needs to be =, + or -");
}
}
// }}}