This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/handle_flash/main.php
Matthew Barbour b1db833d51 Added additional media properties to the images table, video, audio, length, and lossless.
Added new event to handle fetching media properties like height, width, and the newly added fields, and admin controls to manually scan files for their properties.
Added a search terms content:video and content:audio to search for images that do (or do not) have those flags.
2019-07-08 08:07:09 -05:00

78 lines
1.9 KiB
PHP

<?php
/*
* Name: Handle Flash
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* Description: Handle Flash files.
*/
class FlashFileHandler extends DataHandlerExtension
{
public function onMediaCheckProperties(MediaCheckPropertiesEvent $event)
{
switch ($event->ext) {
case "swf":
$event->lossless = true;
$event->video = true;
$info = getimagesize($event->file_name);
if (!$info) {
return null;
}
$event->width = $info[0];
$event->height = $info[1];
break;
}
}
protected function create_thumb(string $hash, string $type): bool
{
global $config;
if (!Media::create_thumbnail_ffmpeg($hash)) {
copy("ext/handle_flash/thumb.jpg", warehouse_path(Image::THUMBNAIL_DIR, $hash));
}
return true;
}
protected function supported_ext(string $ext): bool
{
$exts = ["swf"];
return in_array(strtolower($ext), $exts);
}
protected function create_image_from_data(string $filename, array $metadata)
{
$image = new Image();
$image->filesize = $metadata['size'];
$image->hash = $metadata['hash'];
$image->filename = $metadata['filename'];
$image->ext = $metadata['extension'];
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
return $image;
}
protected function check_contents(string $tmpname): bool
{
if (!file_exists($tmpname)) {
return false;
}
$fp = fopen($tmpname, "r");
$head = fread($fp, 3);
fclose($fp);
if (!in_array($head, ["CWS", "FWS"])) {
return false;
}
return true;
}
}