aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhubzilla <git@macgirvin.com>2016-07-27 14:54:51 +1000
committerGitHub <noreply@github.com>2016-07-27 14:54:51 +1000
commite286b510f1488b0fd529258a0d6159111fc4a2ef (patch)
treeff4ed6ac277adcd1ec3d6f6dbb4d8fe4eb1ded9a
parent315dafbe122829aedd80ede1db99d3e4e380dbf8 (diff)
parent7126fd4b313d60062e111c55fafbae47b9e53a68 (diff)
downloadvolse-hubzilla-e286b510f1488b0fd529258a0d6159111fc4a2ef.tar.gz
volse-hubzilla-e286b510f1488b0fd529258a0d6159111fc4a2ef.tar.bz2
volse-hubzilla-e286b510f1488b0fd529258a0d6159111fc4a2ef.zip
Merge pull request #463 from git-marijus/dev
allow multiple-file cloud upload
-rw-r--r--Zotlabs/Storage/Browser.php75
-rw-r--r--view/js/mod_cloud.js2
-rw-r--r--view/tpl/cloud_actionspanel.tpl2
3 files changed, 77 insertions, 2 deletions
diff --git a/Zotlabs/Storage/Browser.php b/Zotlabs/Storage/Browser.php
index 93c55bd4c..0d1d4e791 100644
--- a/Zotlabs/Storage/Browser.php
+++ b/Zotlabs/Storage/Browser.php
@@ -70,6 +70,81 @@ class Browser extends DAV\Browser\Plugin {
}
/**
+ * Extend from parent to add our own listeners
+ */
+ function initialize(DAV\Server $server) {
+ parent::initialize($server);
+ if ($this->enablePost) {
+ $this->server->on('onBrowserPostAction', [$this, 'cloudPostAction']);
+ }
+ }
+
+ /**
+ * Handles POST requests for tree operations.
+ *
+ * @param string $uri
+ * @param string $action
+ * @param array $postVars
+ * @return boolean false will stop other events in the beforeMethod chain to execute
+ */
+ function cloudPostAction($uri, $action, $postVars) {
+ switch ($postVars['sabreAction']) {
+ case 'mkcol' :
+ if (isset($postVars['name']) && trim($postVars['name'])) {
+ // Using basename() because we won't allow slashes
+ list(, $folderName) = \Sabre\HTTP\URLUtil::splitPath(trim($postVars['name']));
+
+ if (isset($postVars['resourceType'])) {
+ $resourceType = explode(',', $postVars['resourceType']);
+ } else {
+ $resourceType = ['{DAV:}collection'];
+ }
+
+ $properties = [];
+ foreach ($postVars as $varName => $varValue) {
+ // Any _POST variable in clark notation is treated
+ // like a property.
+ if ($varName[0] === '{') {
+ // PHP will convert any dots to underscores.
+ // This leaves us with no way to differentiate
+ // the two.
+ // Therefore we replace the string *DOT* with a
+ // real dot. * is not allowed in uris so we
+ // should be good.
+ $varName = str_replace('*DOT*', '.', $varName);
+ $properties[$varName] = $varValue;
+ }
+ }
+
+ $mkCol = new DAV\MkCol(
+ $resourceType,
+ $properties
+ );
+ $this->server->createCollection($uri . '/' . $folderName, $mkCol);
+ }
+ break;
+
+ case 'put' :
+
+ if ($_FILES)
+ $file = current($_FILES);
+ else
+ break;
+
+ for ($i = 0; $i < count($file['name']); $i++) {
+ list(, $newName) = \Sabre\HTTP\URLUtil::splitPath(trim($file['name'][$i]));
+
+ if (is_uploaded_file($file['tmp_name'][$i])) {
+ $this->server->createFile($uri . '/' . $newName, fopen($file['tmp_name'][$i], 'r'));
+ }
+ }
+ break;
+
+ }
+ return false;
+ }
+
+ /**
* @brief Creates the directory listing for the given path.
*
* @param string $path which should be displayed
diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js
index 71e916446..0584cec53 100644
--- a/view/js/mod_cloud.js
+++ b/view/js/mod_cloud.js
@@ -93,6 +93,6 @@ function DragDropUploadFile(file, idx) {
xhr.open('post', window.location.pathname, true);
var data = new FormData(document.getElementById("ajax-upload-files"));
- data.append('file', file);
+ data.append('file[]', file);
xhr.send(data);
}
diff --git a/view/tpl/cloud_actionspanel.tpl b/view/tpl/cloud_actionspanel.tpl
index acba965f2..9cdd73b31 100644
--- a/view/tpl/cloud_actionspanel.tpl
+++ b/view/tpl/cloud_actionspanel.tpl
@@ -18,7 +18,7 @@
<div class="clear"></div>
<label for="files-upload">{{$upload_header}}</label>
<div class="clear"></div>
- <input class="form-group pull-left" id="files-upload" type="file" name="file">
+ <input class="form-group pull-left" id="files-upload" type="file" name="file[]" multiple>
<button class="btn btn-primary btn-sm pull-right" type="submit" value="{{$upload_submit}}">{{$upload_submit}}</button>
</form>
<div class="clear"></div>