diff --git a/core/imageboard/image.php b/core/imageboard/image.php index b4eeb299..b43a0844 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -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; } diff --git a/core/polyfills.php b/core/polyfills.php index 9c6ccac8..97b1e1ec 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -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; diff --git a/core/util.php b/core/util.php index 41fc04d6..299463d8 100644 --- a/core/util.php +++ b/core/util.php @@ -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; } diff --git a/ext/bulk_add/main.php b/ext/bulk_add/main.php index c1379680..0feaa87b 100644 --- a/ext/bulk_add/main.php +++ b/ext/bulk_add/main.php @@ -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); } } diff --git a/ext/bulk_add_csv/main.php b/ext/bulk_add_csv/main.php index 1cb06cec..14db3591 100644 --- a/ext/bulk_add_csv/main.php +++ b/ext/bulk_add_csv/main.php @@ -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); diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index dbcf549c..82ac79b6 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -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 = [ diff --git a/ext/danbooru_api/main.php b/ext/danbooru_api/main.php index 7ee0579c..94a2bc8c 100644 --- a/ext/danbooru_api/main.php +++ b/ext/danbooru_api/main.php @@ -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) ========="); diff --git a/ext/pools/theme.php b/ext/pools/theme.php index 72829d88..a7b5f145 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -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); diff --git a/ext/rotate/main.php b/ext/rotate/main.php index 56c1e2fb..ba5d0e98 100644 --- a/ext/rotate/main.php +++ b/ext/rotate/main.php @@ -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 */ diff --git a/ext/rule34/main.php b/ext/rule34/main.php index 2d321e79..a39b6949 100644 --- a/ext/rule34/main.php +++ b/ext/rule34/main.php @@ -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")); } } diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php index 60f01b6c..24e6d1a3 100644 --- a/ext/tag_editcloud/main.php +++ b/ext/tag_editcloud/main.php @@ -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) { diff --git a/ext/upload/main.php b/ext/upload/main.php index 84279727..434c0092 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -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( diff --git a/ext/wiki/main.php b/ext/wiki/main.php index de048a7a..e3253c9e 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -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 -"); } } // }}}