remove some dead code

This commit is contained in:
Shish 2020-10-29 01:28:46 +00:00
parent 0961ad465f
commit 8a58ede5b3
22 changed files with 25 additions and 82 deletions

View File

@ -121,7 +121,7 @@ class Approval extends Extension
const SEARCH_REGEXP = "/^approved:(yes|no)/"; const SEARCH_REGEXP = "/^approved:(yes|no)/";
public function onSearchTermParse(SearchTermParseEvent $event) public function onSearchTermParse(SearchTermParseEvent $event)
{ {
global $user, $database, $config; global $user, $config;
if ($config->get_bool(ApprovalConfig::IMAGES)) { if ($config->get_bool(ApprovalConfig::IMAGES)) {
$matches = []; $matches = [];

View File

@ -314,14 +314,10 @@ class AutoTagger extends Extension
$tags_mixed = array_merge($tags_mixed, $new_tags); $tags_mixed = array_merge($tags_mixed, $new_tags);
} }
$results = array_intersect_key( return array_intersect_key(
$tags_mixed, $tags_mixed,
array_unique(array_map('strtolower', $tags_mixed)) array_unique(array_map('strtolower', $tags_mixed))
); );
return $results;
} }
/** /**

View File

@ -193,14 +193,14 @@ class BulkActions extends Extension
if (is_iterable($items)) { if (is_iterable($items)) {
send_event($bae); send_event($bae);
} }
if ($bae->redirect) {
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(referer_or(make_link()));
}
} catch (BulkActionException $e) { } catch (BulkActionException $e) {
log_error(BulkActionsInfo::KEY, $e->getMessage(), $e->getMessage()); log_error(BulkActionsInfo::KEY, $e->getMessage(), $e->getMessage());
} }
if ($bae->redirect) {
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(referer_or(make_link()));
}
} }
} }

View File

@ -6,7 +6,7 @@ class BulkAddTest extends ShimmiePHPUnitTestCase
{ {
send_event(new UserLoginEvent(User::by_name(self::$admin_name))); send_event(new UserLoginEvent(User::by_name(self::$admin_name)));
$bae = send_event(new BulkAddEvent('asdf')); $bae = send_event(new BulkAddEvent('asdf'));
$this->assertContains( $this->assertContainsEquals(
"Error, asdf is not a readable directory", "Error, asdf is not a readable directory",
$bae->results, $bae->results,
implode("\n", $bae->results) implode("\n", $bae->results)

View File

@ -21,7 +21,7 @@ class BulkDownload extends Extension
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event) public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
{ {
global $user, $config; global $user;
if ($user->can(Permissions::BULK_DOWNLOAD)) { if ($user->can(Permissions::BULK_DOWNLOAD)) {
$event->add_action(BulkDownload::DOWNLOAD_ACTION_NAME, "Download ZIP"); $event->add_action(BulkDownload::DOWNLOAD_ACTION_NAME, "Download ZIP");

View File

@ -7,6 +7,7 @@ class BulkExportEvent extends Event
public function __construct(Image $image) public function __construct(Image $image)
{ {
parent::__construct();
$this->image = $image; $this->image = $image;
} }
} }
@ -19,6 +20,7 @@ class BulkImportEvent extends Event
public function __construct(Image $image, $fields) public function __construct(Image $image, $fields)
{ {
parent::__construct();
$this->image = $image; $this->image = $image;
$this->fields = $fields; $this->fields = $fields;
} }

View File

@ -100,7 +100,7 @@ class BulkImportExport extends DataHandlerExtension
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event) public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
{ {
global $user, $config; global $user;
if ($user->can(Permissions::BULK_EXPORT)) { if ($user->can(Permissions::BULK_EXPORT)) {
$event->add_action(self::EXPORT_ACTION_NAME, "Export"); $event->add_action(self::EXPORT_ACTION_NAME, "Export");
@ -167,7 +167,6 @@ class BulkImportExport extends DataHandlerExtension
private function get_export_data(ZipArchive $zip): ?array private function get_export_data(ZipArchive $zip): ?array
{ {
$info = $zip->getStream(self::EXPORT_INFO_FILE_NAME); $info = $zip->getStream(self::EXPORT_INFO_FILE_NAME);
$json_data = [];
if ($info !== false) { if ($info !== false) {
try { try {
$json_string = stream_get_contents($info); $json_string = stream_get_contents($info);

View File

@ -9,6 +9,7 @@ class ImageDownloadingEvent extends Event
public function __construct(Image $image, String $path, string $mime) public function __construct(Image $image, String $path, string $mime)
{ {
parent::__construct();
$this->image = $image; $this->image = $image;
$this->path = $path; $this->path = $path;
$this->mime = $mime; $this->mime = $mime;

View File

@ -230,14 +230,10 @@ class Media extends Extension
// } // }
} }
const CONTENT_SEARCH_TERM_REGEX = "/^content[=|:]((video)|(audio)|(image)|(unknown))$/i"; const CONTENT_SEARCH_TERM_REGEX = "/^content[=|:]((video)|(audio)|(image)|(unknown))$/i";
public function onSearchTermParse(SearchTermParseEvent $event) public function onSearchTermParse(SearchTermParseEvent $event)
{ {
global $database;
if (is_null($event->term)) { if (is_null($event->term)) {
return; return;
} }
@ -323,10 +319,11 @@ class Media extends Extension
global $config; global $config;
$ffmpeg = $config->get_string(MediaConfig::FFMPEG_PATH); $ffmpeg = $config->get_string(MediaConfig::FFMPEG_PATH);
if ($ffmpeg == null || $ffmpeg == "") { if (empty($ffmpeg)) {
throw new MediaException("ffmpeg command configured"); throw new MediaException("ffmpeg command not configured");
} }
$ok = false;
$inname = warehouse_path(Image::IMAGE_DIR, $hash); $inname = warehouse_path(Image::IMAGE_DIR, $hash);
$tmpname = tempnam(sys_get_temp_dir(), "shimmie_ffmpeg_thumb"); $tmpname = tempnam(sys_get_temp_dir(), "shimmie_ffmpeg_thumb");
try { try {
@ -335,18 +332,6 @@ class Media extends Extension
$orig_size = self::video_size($inname); $orig_size = self::video_size($inname);
$scaled_size = get_thumbnail_size($orig_size[0], $orig_size[1], true); $scaled_size = get_thumbnail_size($orig_size[0], $orig_size[1], true);
$codec = "mjpeg";
$quality = $config->get_int(ImageConfig::THUMB_QUALITY);
if ($config->get_string(ImageConfig::THUMB_MIME) == MimeType::WEBP) {
$codec = "libwebp";
} else {
// mjpeg quality ranges from 2-31, with 2 being the best quality.
$quality = floor(31 - (31 * ($quality / 100)));
if ($quality < 2) {
$quality = 2;
}
}
$args = [ $args = [
escapeshellarg($ffmpeg), escapeshellarg($ffmpeg),
"-y", "-i", escapeshellarg($inname), "-y", "-i", escapeshellarg($inname),
@ -363,18 +348,15 @@ class Media extends Extension
if ((int)$ret === (int)0) { if ((int)$ret === (int)0) {
log_debug('media', "Generating thumbnail with command `$cmd`, returns $ret"); log_debug('media', "Generating thumbnail with command `$cmd`, returns $ret");
create_scaled_image($tmpname, $outname, $scaled_size, MimeType::PNG); create_scaled_image($tmpname, $outname, $scaled_size, MimeType::PNG);
$ok = true;
return true;
} else { } else {
log_error('media', "Generating thumbnail with command `$cmd`, returns $ret"); log_error('media', "Generating thumbnail with command `$cmd`, returns $ret");
return false;
} }
} finally { } finally {
@unlink($tmpname); @unlink($tmpname);
} }
return $ok;
} }

View File

@ -1,11 +1,5 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use function MicroHTML\INPUT; use function MicroHTML\INPUT;
use function MicroHTML\TABLE;
use function MicroHTML\TR;
use function MicroHTML\TH;
use function MicroHTML\TD;
use function MicroHTML\SELECT;
use function MicroHTML\OPTION;
class MediaTheme extends Themelet class MediaTheme extends Themelet
{ {

View File

@ -219,8 +219,6 @@ class MimeType
$output = self::OCTET_STREAM; $output = self::OCTET_STREAM;
$type = false;
$finfo = finfo_open(FILEINFO_MIME_TYPE); $finfo = finfo_open(FILEINFO_MIME_TYPE);
try { try {
$type = finfo_file($finfo, $file); $type = finfo_file($finfo, $file);

View File

@ -124,7 +124,7 @@ class PrivateImage extends Extension
const SEARCH_REGEXP = "/^private:(yes|no|any)/"; const SEARCH_REGEXP = "/^private:(yes|no|any)/";
public function onSearchTermParse(SearchTermParseEvent $event) public function onSearchTermParse(SearchTermParseEvent $event)
{ {
global $user, $database, $user_config; global $user, $user_config;
$show_private = $user_config->get_bool(PrivateImageConfig::USER_VIEW_DEFAULT); $show_private = $user_config->get_bool(PrivateImageConfig::USER_VIEW_DEFAULT);
$matches = []; $matches = [];
@ -200,7 +200,7 @@ class PrivateImage extends Extension
public static function privatize_image($image_id) public static function privatize_image($image_id)
{ {
global $database, $user; global $database;
$database->execute( $database->execute(
"UPDATE images SET private = :true WHERE id = :id AND private = :false", "UPDATE images SET private = :true WHERE id = :id AND private = :false",
@ -220,7 +220,7 @@ class PrivateImage extends Extension
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
{ {
global $user, $config; global $user;
if ($user->can(Permissions::SET_PRIVATE_IMAGE) && $user->id==$event->image->owner_id) { if ($user->can(Permissions::SET_PRIVATE_IMAGE) && $user->id==$event->image->owner_id) {
$event->add_part($this->theme->get_image_admin_html($event->image)); $event->add_part($this->theme->get_image_admin_html($event->image));
} }
@ -236,7 +236,7 @@ class PrivateImage extends Extension
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event) public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
{ {
global $user, $config; global $user;
if ($user->can(Permissions::SET_PRIVATE_IMAGE)) { if ($user->can(Permissions::SET_PRIVATE_IMAGE)) {
$event->add_action("bulk_privatize_image", "Make Private"); $event->add_action("bulk_privatize_image", "Make Private");

View File

@ -1,6 +1,4 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use function MicroHTML\BR;
use function MicroHTML\BUTTON;
use function MicroHTML\INPUT; use function MicroHTML\INPUT;
class PrivateImageTheme extends Themelet class PrivateImageTheme extends Themelet

View File

@ -171,12 +171,6 @@ class ResizeImage extends Extension
if ($config->get_bool(ResizeConfig::GET_ENABLED) && if ($config->get_bool(ResizeConfig::GET_ENABLED) &&
$user->can(Permissions::EDIT_FILES) && $user->can(Permissions::EDIT_FILES) &&
$this->can_resize_mime($event->image->get_mime())) { $this->can_resize_mime($event->image->get_mime())) {
$new_width = $event->image->width;
$new_height = $event->image->height;
$max_height = 0;
$max_width = 0;
if (isset($_GET['max_height'])) { if (isset($_GET['max_height'])) {
$max_height = int_escape($_GET['max_height']); $max_height = int_escape($_GET['max_height']);
} else { } else {

View File

@ -1,14 +1,8 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use function MicroHTML\UL;
use function MicroHTML\LI; use function MicroHTML\LI;
use function MicroHTML\A; use function MicroHTML\A;
use function MicroHTML\INPUT; use function MicroHTML\INPUT;
use function MicroHTML\FORM;
use function MicroHTML\DIV;
use function MicroHTML\LABEL; use function MicroHTML\LABEL;
use function MicroHTML\P;
use function MicroHTML\B;
use function MicroHTML\SPAN;
use function MicroHTML\rawHTML; use function MicroHTML\rawHTML;
class SourceHistoryTheme extends Themelet class SourceHistoryTheme extends Themelet

View File

@ -1,13 +1,8 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use function MicroHTML\UL;
use function MicroHTML\LI; use function MicroHTML\LI;
use function MicroHTML\A; use function MicroHTML\A;
use function MicroHTML\INPUT; use function MicroHTML\INPUT;
use function MicroHTML\FORM;
use function MicroHTML\DIV;
use function MicroHTML\LABEL; use function MicroHTML\LABEL;
use function MicroHTML\P;
use function MicroHTML\B;
use function MicroHTML\SPAN; use function MicroHTML\SPAN;
use function MicroHTML\rawHTML; use function MicroHTML\rawHTML;

View File

@ -92,8 +92,6 @@ class TranscodeImage extends Extension
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event) public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
{ {
global $config;
if ($this->get_version(TranscodeConfig::VERSION) < 1) { if ($this->get_version(TranscodeConfig::VERSION) < 1) {
$old_extensions =[]; $old_extensions =[];
foreach (array_values(self::INPUT_MIMES) as $mime) { foreach (array_values(self::INPUT_MIMES) as $mime) {

View File

@ -42,7 +42,7 @@ class TranscodeVideo extends Extension
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
{ {
global $user, $config; global $user;
if ($event->image->video===true && $user->can(Permissions::EDIT_FILES)) { if ($event->image->video===true && $user->can(Permissions::EDIT_FILES)) {
$options = self::get_output_options($event->image->get_mime(), $event->image->video_codec); $options = self::get_output_options($event->image->get_mime(), $event->image->video_codec);
@ -54,8 +54,6 @@ class TranscodeVideo extends Extension
public function onSetupBuilding(SetupBuildingEvent $event) public function onSetupBuilding(SetupBuildingEvent $event)
{ {
global $config;
$sb = new SetupBlock("Video Transcode"); $sb = new SetupBlock("Video Transcode");
$sb->start_table(); $sb->start_table();
$sb->add_bool_option(TranscodeVideoConfig::ENABLED, "Allow transcoding images: ", true); $sb->add_bool_option(TranscodeVideoConfig::ENABLED, "Allow transcoding images: ", true);
@ -126,10 +124,9 @@ class TranscodeVideo extends Extension
} }
} }
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event) public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
{ {
global $user, $config; global $user;
if ($user->can(Permissions::EDIT_FILES)) { if ($user->can(Permissions::EDIT_FILES)) {
$event->add_action( $event->add_action(

View File

@ -32,7 +32,6 @@ class DataUploadEvent extends Event
public function __construct(string $tmpname, array $metadata) public function __construct(string $tmpname, array $metadata)
{ {
parent::__construct(); parent::__construct();
global $config;
assert(file_exists($tmpname)); assert(file_exists($tmpname));
assert(is_string($metadata["filename"])); assert(is_string($metadata["filename"]));

View File

@ -227,7 +227,6 @@ class UploadTheme extends Themelet
{ {
global $config; global $config;
$upload_count = $config->get_int(UploadConfig::COUNT);
$accept = $this->get_accept(); $accept = $this->get_accept();
$max_size = $config->get_int(UploadConfig::SIZE); $max_size = $config->get_int(UploadConfig::SIZE);

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
/** @var $user_config Config */ /** @var Config */
global $user_config; global $user_config;

View File

@ -1,7 +1,4 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use function MicroHTML\BR;
use function MicroHTML\BUTTON;
use function MicroHTML\INPUT;
class UserConfigTheme extends Themelet class UserConfigTheme extends Themelet
{ {