Skip to content

Commit

Permalink
regression fix (v242) export files/themes broken
Browse files Browse the repository at this point in the history
  • Loading branch information
dleffler committed May 22, 2018
1 parent d08b184 commit 91d7b88
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,10 @@ public function install_extension_confirm() {
rename($_FILES['mod_archive']['tmp_name'], $dest);
}

if ($compression != 'zip') {// If not zip, must be tar
if ($compression !== 'zip') {// If not zip, it must be tar
$tar = new PharData($dest);
if ($compression) {
$tar->decompress(); // creates .tar file
$tar->decompress(); // uncompressed and creates .tar file
$tar = new PharData(BASE . "tmp/extensionuploads/$sessid/archive.tar");
}
$return = $tar->extractTo(dirname($dest));
Expand All @@ -685,7 +685,7 @@ public function install_extension_confirm() {
// header('Location: ' . URL_FULL . 'index.php?module=administrationmodule&action=verify_extension&type=tar');
// self::verify_extension('tar');
}
} else { // must be a zip
} else { // it must be a zip
$unzip = new ZipArchive();

$unzip_error_no = $unzip->open($dest);
Expand Down Expand Up @@ -1204,26 +1204,31 @@ public function update_theme() {
}

public function export_theme() {
include_once(BASE.'external/Tar.php');

$themeclass = $this->params['theme'];
$fname = tempnam(BASE.'/tmp','exporter_files_');
$tar = new Archive_Tar($fname,'gz');
$tar->createModify(BASE.'themes/'.$themeclass,'themes/',BASE.'themes/');

$filename = preg_replace('/[^A-Za-z0-9_.-]/','-',$themeclass.'.tar.gz');
$fname = substr(tempnam(BASE.'/tmp','exporter_files_'), 0, -4);
// include_once(BASE . 'external/Tar.php'); // fixme change to PharData
// $tar = new Archive_Tar($fname,'gz');
// $tar->createModify(BASE.'themes/'.$themeclass,'themes/',BASE.'themes/');
$tar = new PharData($fname . '.tar');
$tar->buildFromDirectory(BASE . 'themes/' . $themeclass);
$tar->compress(Phar::GZ);
unset($tar);
unlink($fname . '.tmp'); // remove intermediary .tmp file
unlink($fname . '.tar'); // remove intermediary .tar file

$filename = preg_replace('/[^A-Za-z0-9_.-]/','-',$themeclass . '.tar.gz');

ob_end_clean();
// This code was lifted from phpMyAdmin, but this is Open Source, right?
// 'application/octet-stream' is the registered IANA type but
// MSIE and Opera seems to prefer 'application/octetstream'
$mime_type = (EXPONENT_USER_BROWSER == 'IE' || EXPONENT_USER_BROWSER == 'OPERA') ? 'application/octetstream' : 'application/octet-stream';
$mime_type = (EXPONENT_USER_BROWSER === 'IE' || EXPONENT_USER_BROWSER === 'OPERA') ? 'application/octetstream' : 'application/octet-stream';

header('Content-Type: ' . $mime_type);
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
// IE need specific headers
if (EXPONENT_USER_BROWSER == 'IE') {
if (EXPONENT_USER_BROWSER === 'IE') {
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
Expand All @@ -1232,12 +1237,13 @@ public function export_theme() {
header('Pragma: no-cache');
}

$fh = fopen($fname,'rb');
$fh = fopen($fname . '.tar.gz','rb');
while (!feof($fh)) {
echo fread($fh,8192);
}
fclose($fh);
unlink($fname);
unlink($fname . '.tar.gz');

exit(''); // Exit, since we are exporting.
}
Expand Down
10 changes: 6 additions & 4 deletions framework/modules/file/controllers/fileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ public function import_files_process() {
// include_once(BASE.'external/Tar.php'); // fixme change to PharData
// $tar = new Archive_Tar($_FILES['file']['tmp_name'],'gz');
$tar = new PharData($_FILES['file']['tmp_name']);
$tar->decompress(); // creates .tar file
$tar->decompress(); // uncompressed and creates .tar file
$dest_dir = BASE.'tmp/extensionuploads/'.uniqid('');
@mkdir($dest_dir, octdec(DIR_DEFAULT_MODE_STR + 0));
if (!file_exists($dest_dir)) {
Expand All @@ -950,7 +950,7 @@ public function import_files_process() {

$dh = opendir($dest_dir . '/files');
while (($file = readdir($dh)) !== false) {
if ($file{0} != '.' && is_dir($dest_dir . '/files/' . $file)) {
if ($file{0} !== '.' && is_dir($dest_dir . '/files/' . $file)) {
$mods[$file] = array(
'',
array_keys(expFile::listFlat($dest_dir . '/files/' . $file,1,null, array(),$dest_dir . '/files/'))
Expand Down Expand Up @@ -1055,17 +1055,19 @@ public function export_files_process() {
}
//}

$fname = tempnam(BASE.'/tmp','exporter_files_');
$fname = substr(tempnam(BASE.'/tmp','exporter_files_'), 0, -4);

// include_once(BASE.'external/Tar.php'); // change to PharData
// $tar = new Archive_Tar($fname,'gz');
// $tar->createModify($files,'',BASE);
$tar = new PharData($fname . '.tar');
foreach($files as $file) {
$tar->addFile($file, str_replace(BASE, "", $file));
if (file_exists($file))
$tar->addFile($file, str_replace(BASE, "", $file));
}
$tar->compress(Phar::GZ);
unset($tar);
unlink($fname . '.tmp'); // remove intermediary .tmp file
unlink($fname . '.tar'); // remove intermediary .tar file

$filename = str_replace(
Expand Down

0 comments on commit 91d7b88

Please sign in to comment.