From 5765978afd94b0ee05cdb5bc55e482a6ac0abcd3 Mon Sep 17 00:00:00 2001
From: Matthew Barbour
Date: Sun, 9 Jun 2019 14:18:25 -0500
Subject: [PATCH 1/4] Changed to prevent writing duplicate image tag IDs
---
core/imageboard/image.php | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/core/imageboard/image.php b/core/imageboard/image.php
index 79afc524..b4eeb299 100644
--- a/core/imageboard/image.php
+++ b/core/imageboard/image.php
@@ -593,6 +593,9 @@ class Image
if (Tag::implode($tags) != $this->get_tag_list()) {
// delete old
$this->delete_tags_from_image();
+
+ $written_tags = [];
+
// insert each new tags
foreach ($tags as $tag) {
$id = $database->get_one(
@@ -615,11 +618,17 @@ class Image
["id"=>$this->id, "tag"=>$tag]
);
} else {
- // user of an existing tag
+ // check if tag has already been written
+ if(in_array($id, $written_tags)) {
+ continue;
+ }
+
$database->execute("
- INSERT INTO image_tags(image_id, tag_id)
- VALUES(:iid, :tid)
- ", ["iid"=>$this->id, "tid"=>$id]);
+ INSERT INTO image_tags(image_id, tag_id)
+ VALUES(:iid, :tid)
+ ", ["iid"=>$this->id, "tid"=>$id]);
+
+ array_push($written_tags, $id);
}
$database->execute(
$database->scoreql_to_sql("
From f078b283bd14e7e3d0f65a54b2af4fdfcff6c43c Mon Sep 17 00:00:00 2001
From: Shish
Date: Fri, 14 Jun 2019 13:16:58 +0100
Subject: [PATCH 2/4] pull a bunch of small fixes from #659
---
core/imageboard/image.php | 2 +-
core/polyfills.php | 6 ++++--
core/util.php | 26 ++++++++++++-------------
ext/bulk_add/main.php | 6 +++---
ext/bulk_add_csv/main.php | 7 +++----
ext/cron_uploader/main.php | 40 ++++++++++++++++++--------------------
ext/danbooru_api/main.php | 4 +++-
ext/pools/theme.php | 4 ++--
ext/rotate/main.php | 9 +++------
ext/rule34/main.php | 4 ++--
ext/tag_editcloud/main.php | 2 +-
ext/upload/main.php | 8 +++++---
ext/wiki/main.php | 4 ++--
13 files changed, 61 insertions(+), 61 deletions(-)
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 -");
}
}
// }}}
From 064b24ffc135eb976638659ff5a36c542e534749 Mon Sep 17 00:00:00 2001
From: Shish
Date: Fri, 14 Jun 2019 13:47:50 +0100
Subject: [PATCH 3/4] formatting pass
---
core/exceptions.php | 2 +-
core/extension.php | 6 +-
core/imageboard/misc.php | 72 ++++++++++--------
ext/bulk_actions/main.php | 38 +++++-----
ext/bulk_actions/theme.php | 66 ++++++++--------
ext/cron_uploader/main.php | 32 ++++----
ext/handle_flash/main.php | 2 +-
ext/handle_pixel/main.php | 23 ++++--
ext/handle_svg/main.php | 4 +-
ext/image/main.php | 18 ++---
ext/rating/main.php | 13 ++--
ext/rating/theme.php | 3 +-
ext/regen_thumb/main.php | 54 +++++++-------
ext/regen_thumb/theme.php | 7 +-
ext/rotate/main.php | 14 ++--
ext/transcode/main.php | 149 ++++++++++++++++++-------------------
ext/transcode/theme.php | 7 +-
ext/upload/main.php | 10 ++-
18 files changed, 265 insertions(+), 255 deletions(-)
diff --git a/core/exceptions.php b/core/exceptions.php
index bf923d96..736b029e 100644
--- a/core/exceptions.php
+++ b/core/exceptions.php
@@ -53,4 +53,4 @@ class ImageResizeException extends SCoreException
{
$this->error = $error;
}
-}
\ No newline at end of file
+}
diff --git a/core/extension.php b/core/extension.php
index 7274f868..b7472583 100644
--- a/core/extension.php
+++ b/core/extension.php
@@ -221,17 +221,17 @@ abstract class DataHandlerExtension extends Extension
{
$result = false;
if ($this->supported_ext($event->type)) {
- if($event->force) {
+ if ($event->force) {
$result = $this->create_thumb($event->hash);
} else {
$outname = warehouse_path("thumbs", $event->hash);
- if(file_exists($outname)) {
+ if (file_exists($outname)) {
return;
}
$result = $this->create_thumb($event->hash);
}
}
- if($result) {
+ if ($result) {
$event->generated = true;
}
}
diff --git a/core/imageboard/misc.php b/core/imageboard/misc.php
index eb3c4146..dbdf25f5 100644
--- a/core/imageboard/misc.php
+++ b/core/imageboard/misc.php
@@ -66,15 +66,15 @@ function add_image(string $tmpname, string $filename, string $tags): void
}
-function get_extension_from_mime(String $file_path): ?String
+function get_extension_from_mime(String $file_path): ?String
{
global $config;
$mime = mime_content_type($file_path);
- if(!empty($mime)) {
+ if (!empty($mime)) {
$ext = get_extension($mime);
- if(!empty($ext)) {
+ if (!empty($ext)) {
return $ext;
- }
+ }
throw new UploadException("Could not determine extension for mimetype ".$mime);
}
throw new UploadException("Could not determine file mime type: ".$file_path);
@@ -168,7 +168,7 @@ function get_thumbnail_max_size_scaled(): array
return [$max_width, $max_height];
}
-function create_thumbnail_convert($hash): bool
+function create_thumbnail_convert($hash): bool
{
global $config;
@@ -178,8 +178,7 @@ function create_thumbnail_convert($hash): bool
$q = $config->get_int("thumb_quality");
$convert = $config->get_string("thumb_convert_path");
- if($convert==null||$convert=="")
- {
+ if ($convert==null||$convert=="") {
return false;
}
@@ -202,7 +201,7 @@ function create_thumbnail_convert($hash): bool
}
$bg = "black";
- if($type=="webp") {
+ if ($type=="webp") {
$bg = "none";
}
$format = '"%s" -flatten -strip -thumbnail %ux%u%s -quality %u -background %s "%s[0]" %s:"%s"';
@@ -225,7 +224,7 @@ function create_thumbnail_ffmpeg($hash): bool
global $config;
$ffmpeg = $config->get_string("thumb_ffmpeg_path");
- if($ffmpeg==null||$ffmpeg=="") {
+ if ($ffmpeg==null||$ffmpeg=="") {
return false;
}
@@ -237,12 +236,12 @@ function create_thumbnail_ffmpeg($hash): bool
$codec = "mjpeg";
$quality = $config->get_int("thumb_quality");
- if($config->get_string("thumb_type")=="webp") {
+ if ($config->get_string("thumb_type")=="webp") {
$codec = "libwebp";
} else {
- // mjpeg quality ranges from 2-31, with 2 being the best quality.
+ // mjpeg quality ranges from 2-31, with 2 being the best quality.
$quality = floor(31 - (31 * ($quality/100)));
- if($quality<2) {
+ if ($quality<2) {
$quality = 2;
}
}
@@ -321,13 +320,19 @@ function calc_memory_use(array $info): int
return (int)$memory_use;
}
-function image_resize_gd(String $image_filename, array $info, int $new_width, int $new_height,
- string $output_filename=null, string $output_type=null, int $output_quality = 80)
-{
+function image_resize_gd(
+ String $image_filename,
+ array $info,
+ int $new_width,
+ int $new_height,
+ string $output_filename=null,
+ string $output_type=null,
+ int $output_quality = 80
+) {
$width = $info[0];
$height = $info[1];
- if($output_type==null) {
+ if ($output_type==null) {
/* If not specified, output to the same format as the original image */
switch ($info[2]) {
case IMAGETYPE_GIF: $output_type = "gif"; break;
@@ -337,7 +342,7 @@ function image_resize_gd(String $image_filename, array $info, int $new_width, in
case IMAGETYPE_BMP: $output_type = "bmp"; break;
default: throw new ImageResizeException("Failed to save the new image - Unsupported image type.");
}
- }
+ }
$memory_use = calc_memory_use($info);
$memory_limit = get_memory_limit();
@@ -348,15 +353,15 @@ function image_resize_gd(String $image_filename, array $info, int $new_width, in
$image = imagecreatefromstring(file_get_contents($image_filename));
$image_resized = imagecreatetruecolor($new_width, $new_height);
try {
- if($image===false) {
+ if ($image===false) {
throw new ImageResizeException("Could not load image: ".$image_filename);
}
- if($image_resized===false) {
+ if ($image_resized===false) {
throw new ImageResizeException("Could not create output image with dimensions $new_width c $new_height ");
}
// Handle transparent images
- switch($info[2]) {
+ switch ($info[2]) {
case IMAGETYPE_GIF:
$transparency = imagecolortransparent($image);
$palletsize = imagecolorstotal($image);
@@ -368,12 +373,12 @@ function image_resize_gd(String $image_filename, array $info, int $new_width, in
// Allocate the same color in the new image resource
$transparency = imagecolorallocate($image_resized, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
- if($transparency===false) {
+ if ($transparency===false) {
throw new ImageResizeException("Unable to allocate transparent color");
}
// Completely fill the background of the new image with allocated color.
- if(imagefill($image_resized, 0, 0, $transparency)===false) {
+ if (imagefill($image_resized, 0, 0, $transparency)===false) {
throw new ImageResizeException("Unable to fill new image with transparent color");
}
@@ -386,24 +391,24 @@ function image_resize_gd(String $image_filename, array $info, int $new_width, in
//
// More info here: http://stackoverflow.com/questions/279236/how-do-i-resize-pngs-with-transparency-in-php
//
- if(imagealphablending($image_resized, false)===false) {
+ if (imagealphablending($image_resized, false)===false) {
throw new ImageResizeException("Unable to disable image alpha blending");
}
- if(imagesavealpha($image_resized, true)===false) {
+ if (imagesavealpha($image_resized, true)===false) {
throw new ImageResizeException("Unable to enable image save alpha");
}
$transparent_color = imagecolorallocatealpha($image_resized, 255, 255, 255, 127);
- if($transparent_color===false) {
+ if ($transparent_color===false) {
throw new ImageResizeException("Unable to allocate transparent color");
}
- if(imagefilledrectangle($image_resized, 0, 0, $new_width, $new_height, $transparent_color)===false) {
+ if (imagefilledrectangle($image_resized, 0, 0, $new_width, $new_height, $transparent_color)===false) {
throw new ImageResizeException("Unable to fill new image with transparent color");
}
break;
}
// Actually resize the image.
- if(imagecopyresampled(
+ if (imagecopyresampled(
$image_resized,
$image,
0,
@@ -415,11 +420,11 @@ function image_resize_gd(String $image_filename, array $info, int $new_width, in
$width,
$height
)===false) {
- throw new ImageResizeException("Unable to copy resized image data to new image");
- }
+ throw new ImageResizeException("Unable to copy resized image data to new image");
+ }
$result = false;
- switch($output_type) {
+ switch ($output_type) {
case "bmp":
$result = imagebmp($image_resized, $output_filename, true);
break;
@@ -439,7 +444,7 @@ function image_resize_gd(String $image_filename, array $info, int $new_width, in
default:
throw new ImageResizeException("Failed to save the new image - Unsupported image type: $output_type");
}
- if($result==false) {
+ if ($result==false) {
throw new ImageResizeException("Failed to save the new image, function returned false when saving type: $output_type");
}
} finally {
@@ -448,7 +453,8 @@ function image_resize_gd(String $image_filename, array $info, int $new_width, in
}
}
-function is_animated_gif(String $image_filename) {
+function is_animated_gif(String $image_filename)
+{
$isanigif = 0;
if (($fh = @fopen($image_filename, 'rb'))) {
//check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
@@ -458,4 +464,4 @@ function is_animated_gif(String $image_filename) {
}
}
return ($isanigif == 0);
-}
\ No newline at end of file
+}
diff --git a/ext/bulk_actions/main.php b/ext/bulk_actions/main.php
index 291dd513..2c93de4e 100644
--- a/ext/bulk_actions/main.php
+++ b/ext/bulk_actions/main.php
@@ -12,22 +12,23 @@
class BulkActionBlockBuildingEvent extends Event
{
/** @var array */
- public $actions = array();
+ public $actions = [];
public function add_action(String $action, string $button_text, String $confirmation_message = "", String $block = "", int $position = 40)
{
- if ($block == null)
+ if ($block == null) {
$block = "";
+ }
array_push(
$this->actions,
- array(
+ [
"block" => $block,
"confirmation_message" => $confirmation_message,
"action" => $action,
"button_text" => $button_text,
"position" => $position
- )
+ ]
);
}
}
@@ -41,7 +42,7 @@ class BulkActionEvent extends Event
/** @var PageRequestEvent */
public $page_request;
- function __construct(String $action, PageRequestEvent $pageRequestEvent, array $items)
+ public function __construct(String $action, PageRequestEvent $pageRequestEvent, array $items)
{
$this->action = $action;
$this->page_request = $pageRequestEvent;
@@ -59,10 +60,11 @@ class BulkActions extends Extension
$babbe = new BulkActionBlockBuildingEvent();
send_event($babbe);
- if (sizeof($babbe->actions) == 0)
- return;
+ if (sizeof($babbe->actions) == 0) {
+ return;
+ }
- usort($babbe->actions, array($this, "sort_blocks"));
+ usort($babbe->actions, [$this, "sort_blocks"]);
$this->theme->display_selector($page, $babbe->actions, Tag::implode($event->search_terms));
}
@@ -73,15 +75,15 @@ class BulkActions extends Extension
global $user;
if ($user->can("delete_image")) {
- $event->add_action("bulk_delete","Delete", "Delete selected images?", "", 10);
+ $event->add_action("bulk_delete", "Delete", "Delete selected images?", "", 10);
}
if ($user->can("bulk_edit_image_tag")) {
- $event->add_action("bulk_tag","Tag", "", $this->theme->render_tag_input(), 10);
+ $event->add_action("bulk_tag", "Tag", "", $this->theme->render_tag_input(), 10);
}
if ($user->can("bulk_edit_image_source")) {
- $event->add_action("bulk_source","Set Source", "", $this->theme->render_source_input(), 10);
+ $event->add_action("bulk_source", "Set Source", "", $this->theme->render_source_input(), 10);
}
}
@@ -144,7 +146,7 @@ class BulkActions extends Extension
}
}
}
- } else if (isset($_POST['bulk_query']) && $_POST['bulk_query'] != "") {
+ } elseif (isset($_POST['bulk_query']) && $_POST['bulk_query'] != "") {
$query = $_POST['bulk_query'];
if ($query != null && $query != "") {
$n = 0;
@@ -178,8 +180,8 @@ class BulkActions extends Extension
}
private function sort_blocks($a, $b)
- {
- return $a["position"] - $b["position"];
+ {
+ return $a["position"] - $b["position"];
}
private function delete_items(array $items): int
@@ -188,7 +190,7 @@ class BulkActions extends Extension
foreach ($items as $id) {
try {
$image = Image::by_id($id);
- if($image==null) {
+ if ($image==null) {
continue;
}
@@ -219,7 +221,7 @@ class BulkActions extends Extension
if ($replace) {
foreach ($items as $id) {
$image = Image::by_id($id);
- if($image==null) {
+ if ($image==null) {
continue;
}
@@ -229,7 +231,7 @@ class BulkActions extends Extension
} else {
foreach ($items as $id) {
$image = Image::by_id($id);
- if($image==null) {
+ if ($image==null) {
continue;
}
@@ -254,7 +256,7 @@ class BulkActions extends Extension
foreach ($items as $id) {
try {
$image = Image::by_id($id);
- if($image==null) {
+ if ($image==null) {
continue;
}
diff --git a/ext/bulk_actions/theme.php b/ext/bulk_actions/theme.php
index b0c06856..538c74df 100644
--- a/ext/bulk_actions/theme.php
+++ b/ext/bulk_actions/theme.php
@@ -2,13 +2,11 @@
class BulkActionsTheme extends Themelet
{
+ public function display_selector(Page $page, $actions, $query)
+ {
+ global $user;
-
- public function display_selector(Page $page, $actions, $query)
- {
- global $user;
-
- $body = "
+ $body = "
@@ -26,37 +24,37 @@ class BulkActionsTheme extends Themelet
";
- $hasQuery = ($query != null && $query != "");
+ $hasQuery = ($query != null && $query != "");
- if ($hasQuery) {
- $body .= "
";
- }
+ if ($hasQuery) {
+ $body .= "";
+ }
- foreach ($actions as $action) {
- $body .= "" . make_form(make_link("bulk_action"), "POST", False, "", "return validate_selections(this,'" . html_escape($action["confirmation_message"]) . "');") .
- "" .
- "" .
- "" .
- $action["block"] .
- "" .
- "
";
- }
+ foreach ($actions as $action) {
+ $body .= "" . make_form(make_link("bulk_action"), "POST", false, "", "return validate_selections(this,'" . html_escape($action["confirmation_message"]) . "');") .
+ "" .
+ "" .
+ "" .
+ $action["block"] .
+ "" .
+ "
";
+ }
- if (!$hasQuery) {
- $body .= "";
- }
- $block = new Block("Bulk Actions", $body, "left", 30);
- $page->add_block($block);
- }
+ if (!$hasQuery) {
+ $body .= "";
+ }
+ $block = new Block("Bulk Actions", $body, "left", 30);
+ $page->add_block($block);
+ }
- public function render_tag_input()
- {
- return "" .
- "";
- }
+ public function render_tag_input()
+ {
+ return "" .
+ "";
+ }
- public function render_source_input()
- {
- return "";
- }
+ public function render_source_input()
+ {
+ return "";
+ }
}
diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php
index 05eb0162..f4bd3c51 100644
--- a/ext/cron_uploader/main.php
+++ b/ext/cron_uploader/main.php
@@ -282,7 +282,7 @@ class CronUploader extends Extension
$result = $this->add_image($img[0], $img[1], $img[2]);
$database->commit();
$this->move_uploaded($img[0], $img[1], $output_subdir, false);
- if($result==null) {
+ if ($result==null) {
$merged++;
} else {
$added++;
@@ -290,7 +290,7 @@ class CronUploader extends Extension
} catch (Exception $e) {
$failed++;
$this->move_uploaded($img[0], $img[1], $output_subdir, true);
- $msgNumber = $this->add_upload_info("(".gettype($e).") ".$e->getMessage());
+ $msgNumber = $this->add_upload_info("(".gettype($e).") ".$e->getMessage());
$msgNumber = $this->add_upload_info($e->getTraceAsString());
if (strpos($e->getMessage(), 'SQLSTATE') !== false) {
// Postgres invalidates the transaction if there is an SQL error,
@@ -299,7 +299,8 @@ class CronUploader extends Extension
}
try {
$database->rollback();
- } catch (Exception $e) {}
+ } catch (Exception $e) {
+ }
}
}
@@ -325,17 +326,16 @@ 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/".$output_subdir.$relativeDir;
- $info = "ERROR: Image was not uploaded.";
- }
- else {
- $newDir .= "/uploaded/".$output_subdir.$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/".$output_subdir.$relativeDir;
+ $info = "ERROR: Image was not uploaded.";
+ } else {
+ $newDir .= "/uploaded/".$output_subdir.$relativeDir;
+ $info = "Image successfully uploaded. ";
+ }
+ $newDir = str_replace("//", "/", $newDir."/");
if (!is_dir($newDir)) {
mkdir($newDir, 0775, true);
@@ -360,7 +360,7 @@ class CronUploader extends Extension
if (array_key_exists('extension', $pathinfo)) {
$metadata ['extension'] = $pathinfo ['extension'];
}
- $metadata ['tags'] = Tag::explode($tags);
+ $metadata ['tags'] = Tag::explode($tags);
$metadata ['source'] = null;
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);
@@ -369,7 +369,7 @@ class CronUploader extends Extension
$infomsg = ""; // Will contain info message
if ($event->image_id == -1) {
throw new Exception("File type not recognised. Filename: {$filename}");
- } else if ($event->image_id == null) {
+ } elseif ($event->image_id == null) {
$infomsg = "Image merged. Filename: {$filename}";
} else {
$infomsg = "Image uploaded. ID: {$event->image_id} - Filename: {$filename}";
diff --git a/ext/handle_flash/main.php b/ext/handle_flash/main.php
index cec86d13..8da00583 100644
--- a/ext/handle_flash/main.php
+++ b/ext/handle_flash/main.php
@@ -12,7 +12,7 @@ class FlashFileHandler extends DataHandlerExtension
{
global $config;
- if(!create_thumbnail_ffmpeg($hash)) {
+ if (!create_thumbnail_ffmpeg($hash)) {
copy("ext/handle_flash/thumb.jpg", warehouse_path("thumbs", $hash));
}
return true;
diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php
index 04b26448..e10d8f75 100644
--- a/ext/handle_pixel/main.php
+++ b/ext/handle_pixel/main.php
@@ -97,19 +97,26 @@ class PixelFileHandler extends DataHandlerExtension
try {
$info = getimagesize($inname);
$tsize = get_thumbnail_size_scaled($info[0], $info[1]);
- $image = image_resize_gd($inname, $info, $tsize[0], $tsize[1],
- $outname, $config->get_string('thumb_type'),$config->get_int('thumb_quality'));
- } catch(InsufficientMemoryException $e) {
- $tsize = get_thumbnail_max_size_scaled();
- $thumb = imagecreatetruecolor($tsize[0], min($tsize[1], 64));
+ $image = image_resize_gd(
+ $inname,
+ $info,
+ $tsize[0],
+ $tsize[1],
+ $outname,
+ $config->get_string('thumb_type'),
+ $config->get_int('thumb_quality')
+ );
+ } catch (InsufficientMemoryException $e) {
+ $tsize = get_thumbnail_max_size_scaled();
+ $thumb = imagecreatetruecolor($tsize[0], min($tsize[1], 64));
$white = imagecolorallocate($thumb, 255, 255, 255);
$black = imagecolorallocate($thumb, 0, 0, 0);
imagefill($thumb, 0, 0, $white);
- log_warning("handle_pixel","Insufficient memory while creating thumbnail: ".$e->getMessage());
+ log_warning("handle_pixel", "Insufficient memory while creating thumbnail: ".$e->getMessage());
imagestring($thumb, 5, 10, 24, "Image Too Large :(", $black);
return true;
- } catch(Exception $e) {
- log_error("handle_pixel","Error while creating thumbnail: ".$e->getMessage());
+ } catch (Exception $e) {
+ log_error("handle_pixel", "Error while creating thumbnail: ".$e->getMessage());
return false;
}
diff --git a/ext/handle_svg/main.php b/ext/handle_svg/main.php
index 97127816..5676d24f 100644
--- a/ext/handle_svg/main.php
+++ b/ext/handle_svg/main.php
@@ -3,7 +3,7 @@
* Name: Handle SVG
* Author: Shish
* Link: http://code.shishnet.org/shimmie2/
- * Description: Handle static SVG files.
+ * Description: Handle static SVG files.
*/
use enshrined\svgSanitize\Sanitizer;
@@ -34,7 +34,7 @@ class SVGFileHandler extends DataHandlerExtension
protected function create_thumb(string $hash): bool
{
- if(!create_thumbnail_convert($hash)) {
+ if (!create_thumbnail_convert($hash)) {
copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash));
}
return true;
diff --git a/ext/image/main.php b/ext/image/main.php
index 362cb944..b2fe5722 100644
--- a/ext/image/main.php
+++ b/ext/image/main.php
@@ -253,12 +253,12 @@ class ImageIO extends Extension
if (!is_null($image)) {
$page->set_mode("data");
if ($type == "thumb") {
- $ext = $config->get_string("thumb_type");
- if (array_key_exists($ext, MIME_TYPE_MAP)) {
- $page->set_type(MIME_TYPE_MAP[$ext]);
- } else {
- $page->set_type("image/jpeg");
- }
+ $ext = $config->get_string("thumb_type");
+ if (array_key_exists($ext, MIME_TYPE_MAP)) {
+ $page->set_type(MIME_TYPE_MAP[$ext]);
+ } else {
+ $page->set_type("image/jpeg");
+ }
$file = $image->get_thumb_filename();
} else {
@@ -278,9 +278,9 @@ class ImageIO extends Extension
$page->set_data("");
} else {
$page->add_http_header("Last-Modified: $gmdate_mod");
- if ($type != "thumb") {
- $page->add_http_header("Content-Disposition: inline; filename=".$image->get_nice_image_name());
- }
+ if ($type != "thumb") {
+ $page->add_http_header("Content-Disposition: inline; filename=".$image->get_nice_image_name());
+ }
$page->set_data(file_get_contents($file));
if ($config->get_int("image_expires")) {
diff --git a/ext/rating/main.php b/ext/rating/main.php
index 948e4b1a..18b40823 100644
--- a/ext/rating/main.php
+++ b/ext/rating/main.php
@@ -170,16 +170,15 @@ class Ratings extends Extension
global $user;
if ($user->is_admin()) {
- $event->add_action("bulk_rate","Set Rating","",$this->theme->get_selection_rater_html("bulk_rating"));
+ $event->add_action("bulk_rate", "Set Rating", "", $this->theme->get_selection_rater_html("bulk_rating"));
}
-
}
public function onBulkAction(BulkActionEvent $event)
{
global $user;
- switch($event->action) {
+ switch ($event->action) {
case "bulk_rate":
if (!isset($_POST['bulk_rating'])) {
return;
@@ -189,12 +188,12 @@ class Ratings extends Extension
$total = 0;
foreach ($event->items as $id) {
$image = Image::by_id($id);
- if($image==null) {
+ if ($image==null) {
continue;
}
send_event(new RatingSetEvent($image, $rating));
- $total++;
+ $total++;
}
flash_message("Rating set for $total items");
}
@@ -331,7 +330,7 @@ class Ratings extends Extension
if ($config->get_int("ext_ratings2_version") < 3) {
$database->Execute("UPDATE images SET rating = 'u' WHERE rating is null");
- switch($database->get_driver_name()) {
+ switch ($database->get_driver_name()) {
case "mysql":
$database->Execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT 'u'");
break;
@@ -340,7 +339,7 @@ class Ratings extends Extension
$database->Execute("ALTER TABLE images ALTER COLUMN rating SET NOT NULL");
break;
}
- $config->set_int("ext_ratings2_version", 3);
+ $config->set_int("ext_ratings2_version", 3);
}
}
diff --git a/ext/rating/theme.php b/ext/rating/theme.php
index 67f85831..d414e3f6 100644
--- a/ext/rating/theme.php
+++ b/ext/rating/theme.php
@@ -46,7 +46,8 @@ class RatingsTheme extends Themelet
$page->add_block(new Block("List Controls", $html, "left"));
}
- public function get_selection_rater_html(String $id = "select_rating") {
+ public function get_selection_rater_html(String $id = "select_rating")
+ {
return "
- ".make_form(make_link("admin/delete_thumbs"),"POST",False, "","return confirm('Are you sure you want to delete all thumbnails?')")."
+
".make_form(make_link("admin/delete_thumbs"), "POST", false, "", "return confirm('Are you sure you want to delete all thumbnails?')")."
|
|
---|