Add wiki download button to export the selected wiki repo to a zip file
This commit is contained in:
parent
6bf92979a2
commit
02cf7274d2
@ -91,6 +91,35 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
$channel_acl = $x = array();
|
||||
}
|
||||
|
||||
// Download a wiki
|
||||
if ((argc() > 3) && (argv(2) === 'download') && (argv(3) === 'wiki')) {
|
||||
$resource_id = argv(4);
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
notice('Error retrieving wiki' . EOL);
|
||||
}
|
||||
$zip_folder_name = random_string(10);
|
||||
$zip_folderpath = '/tmp/' . $zip_folder_name;
|
||||
if (!mkdir($zip_folderpath, 0770, false)) {
|
||||
logger('Error creating zip file export folder: ' . $zip_folderpath, LOGGER_NORMAL);
|
||||
notice('Error creating zip file export folder' . EOL);
|
||||
}
|
||||
$zip_filename = $w['urlName'];
|
||||
$zip_filepath = '/tmp/' . $zip_folder_name . '/' . $zip_filename;
|
||||
// Generate the zip file
|
||||
\Zotlabs\Lib\ExtendedZip::zipTree($w['path'], $zip_filepath, \ZipArchive::CREATE);
|
||||
// Output the file for download
|
||||
header('Content-disposition: attachment; filename="' . $zip_filename . '.zip"');
|
||||
header("Content-Type: application/zip");
|
||||
$success = readfile($zip_filepath);
|
||||
if ($success) {
|
||||
rrmdir($zip_folderpath); // delete temporary files
|
||||
} else {
|
||||
rrmdir($zip_folderpath); // delete temporary files
|
||||
logger('Error downloading wiki: ' . $resource_id);
|
||||
}
|
||||
}
|
||||
|
||||
switch (argc()) {
|
||||
case 2:
|
||||
// Configure page template
|
||||
@ -297,6 +326,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create a page
|
||||
if ((argc() === 4) && (argv(2) === 'create') && (argv(3) === 'page')) {
|
||||
$nick = argv(1);
|
||||
|
@ -240,6 +240,10 @@ function wiki_delete_wiki(wikiHtmlName, resource_id) {
|
||||
}
|
||||
|
||||
|
||||
function wiki_download_wiki(resource_id) {
|
||||
window.location = "wiki/{{$channel}}/download/wiki/" + resource_id;
|
||||
}
|
||||
|
||||
$('#new-page-submit').click(function (ev) {
|
||||
if (window.wiki_resource_id === '') {
|
||||
window.console.log('You must have a wiki open in order to create pages.');
|
||||
|
@ -8,6 +8,7 @@
|
||||
</a>
|
||||
<ul class="dropdown-menu pull-right">
|
||||
<li><a href="/wiki/{{$channel}}/{{$wiki.urlName}}/Home" title="View {{$wiki.title}}">View</a></li>
|
||||
<li><a href="#" onclick="wiki_download_wiki('{{$wiki.resource_id}}'); return false;" title="Download {{$wiki.title}}">Download</a></li>
|
||||
{{if $showControls}}
|
||||
<li class="divider"></li>
|
||||
<li><a href="#" onclick="wiki_delete_wiki('{{$wiki.title}}','{{$wiki.resource_id}}'); return false;" title="Delete {{$wiki.title}}">Delete wiki</a></li>
|
||||
|
Reference in New Issue
Block a user