This commit is contained in:
Shish 2020-09-19 00:18:51 +01:00
parent 6284f3bcb8
commit 1159ba2fa1
7 changed files with 29 additions and 35 deletions

View File

@ -9,8 +9,9 @@ class CommandBuilder
private $args = [];
public $output;
function __construct(String $executable) {
if(empty($executable)) {
public function __construct(String $executable)
{
if (empty($executable)) {
throw new InvalidArgumentException("executable cannot be empty");
}
@ -30,7 +31,7 @@ class CommandBuilder
public function generate(): string
{
$command = escapeshellarg($this->executable);
if(!empty($this->args)) {
if (!empty($this->args)) {
$command .= " ";
$command .= join(" ", $this->args);
}
@ -40,12 +41,11 @@ class CommandBuilder
public function combineOutput(string $empty_output = ""): string
{
if(empty($this->output)) {
if (empty($this->output)) {
return $empty_output;
} else {
return implode("\r\n", $this->output);
}
}
public function execute(bool $fail_on_non_zero_return = false): int
@ -57,7 +57,7 @@ class CommandBuilder
log_debug('command_builder', "Command `$cmd` returned $ret and outputted $output");
if($fail_on_non_zero_return&&(int)$ret!==(int)0) {
if ($fail_on_non_zero_return&&(int)$ret!==(int)0) {
throw new SCoreException("Command `$cmd` failed, returning $ret and outputting $output");
}
return $ret;

View File

@ -13,7 +13,7 @@ class Eokm extends Extension
$username = $config->get_string("eokm_username");
$password = $config->get_string("eokm_password");
if($username && $password) {
if ($username && $password) {
$ch = curl_init("https://api.eokmhashdb.nl/v1/check/md5");
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
curl_setopt($ch, CURLOPT_HEADER, 0);
@ -21,18 +21,16 @@ class Eokm extends Extension
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $event->image->hash);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);
curl_close($ch);
if($return == "false") {
if ($return == "false") {
// all ok
}
elseif($return == "true") {
} elseif ($return == "true") {
log_warning("eokm", "User tried to upload banned image {$event->image->hash}");
throw new UploadException("Image banned");
}
else {
} else {
log_warning("eokm", "Unexpected return from EOKM: $return");
}
}

View File

@ -97,8 +97,8 @@ class VideoFileHandler extends DataHandlerExtension
$event->image->video = $video;
$event->image->video_codec = $video_codec;
$event->image->audio = $audio;
if($event->image->get_mime()==MimeType::MKV &&
VideoContainers::is_video_codec_supported(VideoContainers::WEBM,$event->image->video_codec)) {
if ($event->image->get_mime()==MimeType::MKV &&
VideoContainers::is_video_codec_supported(VideoContainers::WEBM, $event->image->video_codec)) {
// WEBMs are MKVs with the VP9 or VP8 codec
// For browser-friendliness, we'll just change the mime type
$event->image->set_mime(MimeType::WEBM);

View File

@ -592,8 +592,8 @@ class Media extends Extension
$file_arg = "${input_ext}:\"${input_path}[0]\"";
if($resize_type===Media::RESIZE_TYPE_FIT_BLUR_PORTRAIT) {
if($new_height>$new_width) {
if ($resize_type===Media::RESIZE_TYPE_FIT_BLUR_PORTRAIT) {
if ($new_height>$new_width) {
$resize_type = Media::RESIZE_TYPE_FIT_BLUR;
} else {
$resize_type = Media::RESIZE_TYPE_FILL;

View File

@ -33,8 +33,8 @@ abstract class VideoContainers
public static function is_video_codec_supported(string $container, string $codec): bool
{
return array_key_exists($container,self::VIDEO_CODEC_SUPPORT) &&
in_array($codec,self::VIDEO_CODEC_SUPPORT[$container]);
return array_key_exists($container, self::VIDEO_CODEC_SUPPORT) &&
in_array($codec, self::VIDEO_CODEC_SUPPORT[$container]);
}
}

View File

@ -46,8 +46,8 @@ class TranscodeVideo extends Extension
if ($event->image->video===true && $user->can(Permissions::EDIT_FILES)) {
$options = self::get_output_options($event->image->get_mime(), $event->image->video_codec);
if(!empty($options)&&sizeof($options)>1) {
$event->add_part($this->theme->get_transcode_html($event->image,$options));
if (!empty($options)&&sizeof($options)>1) {
$event->add_part($this->theme->get_transcode_html($event->image, $options));
}
}
}
@ -163,7 +163,7 @@ class TranscodeVideo extends Extension
// transcodes recorded already, otherwise the image entries will be stuck pointing to
// missing image files
$database->commit();
if($output_image!=$image) {
if ($output_image!=$image) {
$total++;
}
} catch (Exception $e) {
@ -187,11 +187,11 @@ class TranscodeVideo extends Extension
foreach (VideoContainers::ALL as $container) {
if($starting_container==$container) {
if ($starting_container==$container) {
continue;
}
if(!empty($starting_codec)&&
!VideoContainers::is_video_codec_supported($container,$starting_codec)) {
if (!empty($starting_codec)&&
!VideoContainers::is_video_codec_supported($container, $starting_codec)) {
continue;
}
$description = MimeMap::get_name_for_mime($container);
@ -202,16 +202,16 @@ class TranscodeVideo extends Extension
private function transcode_and_replace_video(Image $image, String $target_mime): Image
{
if($image->get_mime()==$target_mime) {
if ($image->get_mime()==$target_mime) {
return $image;
}
if($image->video==null||($image->video===true && empty($image->video_codec))) {
if ($image->video==null||($image->video===true && empty($image->video_codec))) {
// If image predates the media system, or the video codec support, run a media check
send_event(new MediaCheckPropertiesEvent($image));
$image->save_to_db();
}
if(empty($image->video_codec)) {
if (empty($image->video_codec)) {
throw new VideoTranscodeException("Cannot transcode item $image->id because its video codec is not known");
}
@ -237,12 +237,10 @@ class TranscodeVideo extends Extension
send_event(new ImageReplaceEvent($image->id, $new_image));
return $new_image;
} finally {
/* Remove temporary file */
@unlink($tmp_filename);
}
}
@ -250,7 +248,7 @@ class TranscodeVideo extends Extension
{
global $config;
if(empty($source_video_codec)) {
if (empty($source_video_codec)) {
throw new VideoTranscodeException("Cannot transcode item because it's video codec is not known");
}
@ -267,7 +265,7 @@ class TranscodeVideo extends Extension
$command->add_flag("-i");
$command->add_escaped_arg($source_file);
if(!VideoContainers::is_video_codec_supported($target_mime, $source_video_codec)) {
if (!VideoContainers::is_video_codec_supported($target_mime, $source_video_codec)) {
throw new VideoTranscodeException("Cannot transcode item to $target_mime because it does not support the video codec $source_video_codec");
}
@ -289,6 +287,4 @@ class TranscodeVideo extends Extension
return $target_file;
}
}

View File

@ -34,7 +34,7 @@ class CustomViewImageTheme extends ViewImageTheme
<br>Filesize: $h_filesize
<br>Type: ".$h_type."
";
if($image->video_codec!=null) {
if ($image->video_codec!=null) {
$html .= "<br/>Video Codec: $image->video_codec";
}
if ($image->length!=null) {