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

55 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2009-08-20 22:37:17 +00:00
/*
* Name: Handle Archives
* Author: Shish <webmaster@shishnet.org>
* Description: Allow users to upload archives (zip, etc)
2009-01-16 08:18:41 +00:00
* Documentation:
* Note: requires exec() access and an external unzip command
* <p>Any command line unzipper should work, some examples:
* <p>unzip: <code>unzip -d "%d" "%f"</code>
* <br>7-zip: <code>7zr x -o"%d" "%f"</code>
*/
class ArchiveFileHandler extends Extension {
public function onInitExt(InitExtEvent $event) {
2009-05-11 21:09:24 +00:00
global $config;
$config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"');
}
2009-01-04 19:18:37 +00:00
public function onSetupBuilding(SetupBuildingEvent $event) {
2009-05-11 21:09:24 +00:00
$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) {
2009-05-11 21:09:24 +00:00
if($this->supported_ext($event->type)) {
global $config;
$tmp = sys_get_temp_dir();
$tmpdir = "$tmp/shimmie-archive-{$event->hash}";
$cmd = $config->get_string('archive_extract_command');
2009-08-03 09:19:33 +00:00
$cmd = str_replace('%f', $event->tmpname, $cmd);
$cmd = str_replace('%d', $tmpdir, $cmd);
exec($cmd);
2015-08-23 15:09:52 +00:00
$results = add_dir($tmpdir);
if(count($results) > 0) {
// FIXME no theme?
$this->theme->add_status("Adding files", $results);
}
2009-08-03 09:19:33 +00:00
deltree($tmpdir);
$event->image_id = -2; // default -1 = upload wasn't handled
}
}
/**
2015-09-27 11:38:48 +00:00
* @param string $ext
* @return bool
*/
private function supported_ext($ext) {
$exts = array("zip");
2009-06-05 19:53:00 +00:00
return in_array(strtolower($ext), $exts);
}
}