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_archive/main.php
Matthew Barbour 63b2601e67 Mime type handling overhaul
Changed mime type map to deal with the reality that certain file types have multiple extensions and/or multiple mime types, as well as constants supporting all of the data. Created new functions using the updated mime type map to resolve mime types and extensions. Updated various items around the project that determine mime/extension to take advantage of the new functions.
2020-06-03 19:47:40 +01:00

59 lines
1.9 KiB
PHP

<?php declare(strict_types=1);
class ArchiveFileHandler extends DataHandlerExtension
{
protected $SUPPORTED_MIME = [MIME_TYPE_ZIP];
public function onInitExt(InitExtEvent $event)
{
global $config;
$config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"');
}
public function onSetupBuilding(SetupBuildingEvent $event)
{
$sb = new SetupBlock("Archive Handler Options");
$sb->add_text_option("archive_tmp_dir", "Temporary folder: ");
$sb->add_text_option("archive_extract_command", "<br>Extraction command: ");
$sb->add_label("<br>%f for archive, %d for temporary directory");
$event->panel->add_block($sb);
}
public function onDataUpload(DataUploadEvent $event)
{
if ($this->supported_ext($event->type)) {
global $config, $page;
$tmp = sys_get_temp_dir();
$tmpdir = "$tmp/shimmie-archive-{$event->hash}";
$cmd = $config->get_string('archive_extract_command');
$cmd = str_replace('%f', $event->tmpname, $cmd);
$cmd = str_replace('%d', $tmpdir, $cmd);
exec($cmd);
$results = add_dir($tmpdir);
if (count($results) > 0) {
$page->flash("Adding files" . implode("\n", $results));
}
deltree($tmpdir);
$event->image_id = -2; // default -1 = upload wasn't handled
}
}
public function onDisplayingImage(DisplayingImageEvent $event)
{
}
// we don't actually do anything, just accept one upload and spawn several
protected function media_check_properties(MediaCheckPropertiesEvent $event): void
{
}
protected function check_contents(string $tmpname): bool
{
return false;
}
protected function create_thumb(string $hash, string $type): bool
{
return false;
}
}