2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2007-12-08 03:10:07 +00:00
|
|
|
|
2020-02-23 19:41:20 +00:00
|
|
|
class ArchiveFileHandler extends DataHandlerExtension
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-06-14 16:05:55 +00:00
|
|
|
protected $SUPPORTED_MIME = [MimeType::ZIP];
|
2020-02-23 19:41:20 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onInitExt(InitExtEvent $event)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"');
|
|
|
|
}
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event)
|
|
|
|
{
|
2020-10-26 15:13:28 +00:00
|
|
|
$sb = $event->panel->create_new_block("Archive Handler Options");
|
2019-05-28 16:59:38 +00:00
|
|
|
$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");
|
|
|
|
}
|
2007-12-08 17:13:15 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onDataUpload(DataUploadEvent $event)
|
|
|
|
{
|
2020-06-14 16:05:55 +00:00
|
|
|
if ($this->supported_mime($event->mime)) {
|
2020-01-26 13:19:35 +00:00
|
|
|
global $config, $page;
|
2019-05-28 16:59:38 +00:00
|
|
|
$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);
|
2020-06-24 16:02:24 +00:00
|
|
|
if (file_exists($tmpdir)) {
|
2020-06-24 14:17:44 +00:00
|
|
|
try {
|
|
|
|
$results = add_dir($tmpdir);
|
|
|
|
if (count($results) > 0) {
|
|
|
|
$page->flash("Adding files" . implode("\n", $results));
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
deltree($tmpdir);
|
|
|
|
}
|
|
|
|
$event->image_id = -2; // default -1 = upload wasn't handled
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-08 03:10:07 +00:00
|
|
|
|
2020-02-25 12:18:47 +00:00
|
|
|
public function onDisplayingImage(DisplayingImageEvent $event)
|
|
|
|
{
|
|
|
|
}
|
2020-02-23 19:41:20 +00:00
|
|
|
|
|
|
|
// we don't actually do anything, just accept one upload and spawn several
|
2020-02-25 12:18:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2007-12-08 03:10:07 +00:00
|
|
|
}
|