aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Webpages.php55
-rw-r--r--include/attach.php47
-rw-r--r--include/text.php4
-rw-r--r--view/tpl/website_portation_tools.tpl16
4 files changed, 113 insertions, 9 deletions
diff --git a/Zotlabs/Module/Webpages.php b/Zotlabs/Module/Webpages.php
index 0fec06c38..028cc5114 100644
--- a/Zotlabs/Module/Webpages.php
+++ b/Zotlabs/Module/Webpages.php
@@ -424,7 +424,18 @@ class Webpages extends \Zotlabs\Web\Controller {
}
break;
+
+ case 'exportcloud':
+ logger('exportcloud', LOGGER_DEBUG);
+ if(isset($_POST['exportcloudpath']) && $_POST['exportcloudpath'] !== '') {
+ $_SESSION['action'] = 'export_select_list';
+ $_SESSION['export'] = 'cloud';
+ $_SESSION['exportcloudpath'] = filter_var($_POST['exportcloudpath'], FILTER_SANITIZE_ENCODED);
+ }
+ break;
+
+ case 'cloud':
case 'zipfile':
$channel = \App::get_channel();
@@ -644,18 +655,46 @@ class Webpages extends \Zotlabs\Web\Controller {
}
}
}
- // Generate the zip file
- \Zotlabs\Lib\ExtendedZip::zipTree($tmp_folderpath, $zip_filepath, \ZipArchive::CREATE);
- // Output the file for download
- header('Content-disposition: attachment; filename="' . $zip_filename . '"');
- header("Content-Type: application/zip");
- readfile($zip_filepath);
- rrmdir($zip_folderpath); // delete temporary files
- rrmdir($tmp_folderpath); // delete temporary files
+ if($action === 'zipfile') {
+ // Generate the zip file
+ \Zotlabs\Lib\ExtendedZip::zipTree($tmp_folderpath, $zip_filepath, \ZipArchive::CREATE);
+ // Output the file for download
+ header('Content-disposition: attachment; filename="' . $zip_filename . '"');
+ header("Content-Type: application/zip");
+ $success = readfile($zip_filepath);
+ } elseif ($action === 'cloud') { // Only zipfile or cloud should be possible values for $action here
+ if(isset($_SESSION['exportcloudpath'])) {
+ require_once('include/attach.php');
+ $cloudpath = urldecode($_SESSION['exportcloudpath']);
+ $channel = \App::get_channel();
+ $dirpath = get_dirpath_by_cloudpath($channel, $cloudpath);
+ if(!$dirpath) {
+ $x = attach_mkdirp($channel, $channel['channel_hash'], array('pathname' => $cloudpath));
+ $folder_hash = (($x['success']) ? $x['data']['hash'] : '');
+
+ if (!$x['success']) {
+ logger('Failed to create cloud file folder', LOGGER_NORMAL);
+ }
+ $dirpath = get_dirpath_by_cloudpath($channel, $cloudpath);
+ if (!is_dir($dirpath)) {
+ logger('Failed to create cloud file folder', LOGGER_NORMAL);
+ }
+ }
+
+ $success = copy_folder_to_cloudfiles($channel, $channel['channel_hash'], $tmp_folderpath, $cloudpath);
+ }
+ }
+ if(!$success) {
+ logger('Error exporting webpage elements', LOGGER_NORMAL);
+ }
+
+ rrmdir($zip_folderpath); rrmdir($tmp_folderpath); // delete temporary files
+
break;
default :
break;
}
+
}
}
diff --git a/include/attach.php b/include/attach.php
index 172840b96..6b17cdca1 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -1994,3 +1994,50 @@ function get_filename_by_cloudname($cloudname, $channel, $storepath) {
}
return null;
}
+
+
+// recursively copy a directory into cloud files
+function copy_folder_to_cloudfiles($channel, $observer_hash, $srcpath, $cloudpath)
+{
+ if (!is_dir($srcpath) || !is_readable($srcpath)) {
+ logger('Error reading source path: ' . $srcpath, LOGGER_NORMAL);
+ return false;
+ }
+ $nodes = array_diff(scandir($srcpath), array('.', '..'));
+ foreach ($nodes as $node) {
+ $clouddir = $cloudpath . '/' . $node; // Sub-folder in cloud files destination
+ $nodepath = $srcpath . '/' . $node; // Sub-folder in source path
+ if(is_dir($nodepath)) {
+ $x = attach_mkdirp($channel, $observer_hash, array('pathname' => $clouddir));
+ if(!$x['success']) {
+ logger('Error creating cloud path: ' . $clouddir, LOGGER_NORMAL);
+ return false;
+ }
+ // Recursively call this function where the source and destination are the subfolders
+ $success = copy_folder_to_cloudfiles($channel, $observer_hash, $nodepath, $clouddir);
+ if(!$success) {
+ logger('Error copying contents of folder: ' . $nodepath, LOGGER_NORMAL);
+ return false;
+ }
+ } elseif (is_file($nodepath) && is_readable($nodepath)) {
+ $x = attach_store($channel, $observer_hash, 'import',
+ array(
+ 'directory' => $cloudpath,
+ 'src' => $nodepath,
+ 'filename' => $node,
+ 'filesize' => @filesize($nodepath),
+ 'preserve_original' => true)
+ );
+ if(!$x['success']) {
+ logger('Error copying file: ' . $nodepath , LOGGER_NORMAL);
+ logger('Return value: ' . json_encode($x), LOGGER_NORMAL);
+ return false;
+ }
+ } else {
+ logger('Error scanning source path', LOGGER_NORMAL);
+ return false;
+ }
+ }
+
+ return true;
+} \ No newline at end of file
diff --git a/include/text.php b/include/text.php
index 1729048e9..99ac59ca7 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2295,6 +2295,10 @@ function website_portation_tools() {
'$file_download_text' => t('Export to a zip file'),
'$filename_desc' => t('website.zip'),
'$filename_hint' => t('Enter a name for the zip file.'),
+ '$cloud_export_text' => t('Export to cloud files'),
+ '$cloud_export_desc' => t('/path/to/export/folder'),
+ '$cloud_export_hint' => t('Enter a path to a cloud files destination.'),
+ '$cloud_export_select' => t('Specify folder'),
));
}
diff --git a/view/tpl/website_portation_tools.tpl b/view/tpl/website_portation_tools.tpl
index 2f68a7393..10468b64e 100644
--- a/view/tpl/website_portation_tools.tpl
+++ b/view/tpl/website_portation_tools.tpl
@@ -35,7 +35,7 @@
</ul>
<ul class="nav nav-pills nav-stacked">
<li>
- <a href="#" onclick="openClose('export-form');
+ <a href="#" onclick="openClose('export-form'); openClose('export-cloud-form');
return false;"><i class="fa fa-share-square-o generic-icons"></i> {{$export_label}}</a>
</li>
<li style="margin-left: 12px;" >
@@ -53,6 +53,20 @@
</div>
</div>
</form>
+ <form id="export-cloud-form" enctype="multipart/form-data" method="post" action="" style="display: none;" class="sub-menu">
+ <input type="hidden" name="action" value="exportcloud">
+ <!-- Or export the website elements to a cloud files folder -->
+ <p style="margin-top: 10px;" class="descriptive-text">{{$cloud_export_text}}</p>
+ <div class="form-group">
+
+ <div class="input-group">
+ <input class="widget-input" type="text" name="exportcloudpath" title="{{$cloud_export_hint}}" placeholder="{{$cloud_export_desc}}" />
+ <div class="input-group-btn">
+ <button class="btn btn-default btn-sm" type="submit" name="exportcloudsubmit" value="{{$cloud_export_select}}"><i class="fa fa-folder-open generic-icons"></i></button>
+ </div>
+ </div>
+ </div>
+ </form>
</li>
</ul>
</div>