aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-12-22 09:01:52 +0000
committerMario <mario@mariovavti.com>2020-12-22 09:01:52 +0000
commit60cbb65d84cdc2854bdcf1613cf67180878c44dd (patch)
treed007f9ee410fd20aebd312d726d55f4666426719
parentd118ab71e6aa4f300ba6e42663d13a63a2323122 (diff)
downloadvolse-hubzilla-60cbb65d84cdc2854bdcf1613cf67180878c44dd.tar.gz
volse-hubzilla-60cbb65d84cdc2854bdcf1613cf67180878c44dd.tar.bz2
volse-hubzilla-60cbb65d84cdc2854bdcf1613cf67180878c44dd.zip
files_ng: omit parent folders of a download
-rw-r--r--Zotlabs/Module/Attach.php45
-rw-r--r--view/js/mod_cloud.js2
2 files changed, 29 insertions, 18 deletions
diff --git a/Zotlabs/Module/Attach.php b/Zotlabs/Module/Attach.php
index 86183056c..e012b1449 100644
--- a/Zotlabs/Module/Attach.php
+++ b/Zotlabs/Module/Attach.php
@@ -12,18 +12,21 @@ class Attach extends Controller {
function post() {
$attach_ids = ((x($_REQUEST, 'attach_ids')) ? $_REQUEST['attach_ids'] : []);
+ $attach_path = ((x($_REQUEST, 'attach_path')) ? $_REQUEST['attach_path'] : '');
- if ($attach_ids) {
+ $channel_id = ((x($_REQUEST, 'channel_id')) ? intval($_REQUEST['channel_id']) : 0);
+ $channel = channelx_by_n($channel_id);
- $ret = ['success' => false];
+ if (! $channel) {
+ notice(t('Channel not found.') . EOL);
+ return;
+ }
- $channel_id = ((x($_REQUEST, 'channel_id')) ? intval($_REQUEST['channel_id']) : 0);
- $channel = channelx_by_n($channel_id);
+ $strip_str = '/cloud/' . $channel['channel_address'] . '/';
+ $count = strlen($strip_str);
+ $attach_path = substr($attach_path, $count);
- if (! $channel) {
- notice(t('Channel not found.') . EOL);
- return;
- }
+ if ($attach_ids) {
$zip_dir = 'store/[data]/' . $channel['channel_address'] . '/tmp';
if (! is_dir($zip_dir))
@@ -38,7 +41,7 @@ class Attach extends Controller {
if ($zip->open($zip_path, ZipArchive::CREATE) === true) {
- $filename = self::zip_archive_handler($zip, $attach_ids);
+ $filename = self::zip_archive_handler($zip, $attach_ids, $attach_path);
$zip->close();
@@ -82,7 +85,6 @@ class Attach extends Controller {
if(! $c)
return;
-
$unsafe_types = array('text/html','text/css','application/javascript');
if(in_array($r['data']['filetype'],$unsafe_types) && (! channel_codeallowed($r['data']['uid']))) {
@@ -112,11 +114,11 @@ class Attach extends Controller {
}
- function zip_archive_handler($zip, $attach_ids, $pass = 1) {
+ public function zip_archive_handler($zip, $attach_ids, $attach_path, $pass = 1) {
$observer_hash = get_observer_hash();
$single = ((count($attach_ids) == 1) ? true : false);
- $filename = 'download.zip';
+ $download_name = 'download.zip';
foreach($attach_ids as $attach_id) {
@@ -127,27 +129,34 @@ class Attach extends Controller {
}
if ($r['data']['is_dir'] && $single && $pass === 1)
- $filename = $r['data']['filename'] . '.zip';
+ $download_name = $r['data']['filename'] . '.zip';
+
+ $zip_path = $r['data']['display_path'];
+
+ if ($attach_path) {
+ $strip_str = $attach_path . '/';
+ $count = strlen($strip_str);
+ $zip_path = substr($r['data']['display_path'], $count);
+ }
if ($r['data']['is_dir']) {
- $zip->addEmptyDir($r['data']['display_path']);
+ $zip->addEmptyDir($zip_path);
$d = q("SELECT id FROM attach WHERE folder = '%s'",
dbesc($r['data']['hash'])
);
$attach_ids = ids_to_array($d);
- self::zip_archive_handler($zip, $attach_ids, $observer_hash, $pass++);
+ self::zip_archive_handler($zip, $attach_ids, $attach_path, $pass++);
}
else {
$file_path = $r['data']['content'];
- $file_name = $r['data']['display_path'];
- $zip->addFile($file_path, $file_name);
+ $zip->addFile($file_path, $zip_path);
}
}
- return $filename;
+ return $download_name;
}
}
diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js
index 736dec471..516284d9b 100644
--- a/view/js/mod_cloud.js
+++ b/view/js/mod_cloud.js
@@ -69,6 +69,7 @@ $(document).ready(function () {
// some trickery to trigger download action via ajax
let form = $('<form></form>').attr('action', 'attach').attr('method', 'post');
+ form.append($("<input></input>").attr('type', 'hidden').attr('name', 'attach_path').attr('value', window.location.pathname));
form.append($("<input></input>").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId));
form.append($("<input></input>").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', id));
form.appendTo('body').submit().remove();
@@ -286,6 +287,7 @@ $(document).ready(function () {
// some trickery to trigger download action via ajax
var form = $('<form></form>').attr('action', 'attach').attr('method', 'post');
+ form.append($("<input></input>").attr('type', 'hidden').attr('name', 'attach_path').attr('value', window.location.pathname));
form.append($("<input></input>").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId));
post_data.each(function () {
form.append($("<input></input>").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', this.value));