diff --git a/htdocs/lib/view.php b/htdocs/lib/view.php
index 8f4c277a8efa14ef30d2ae648ded204c8ab7760c..6ca16d9fe76105145131944762eaae1a6929fe9b 100644
--- a/htdocs/lib/view.php
+++ b/htdocs/lib/view.php
@@ -4261,6 +4261,14 @@ class View {
if (!empty($results->count)) {
return true;
}
+ // Check if view has a secret url and is also a template
+ if (count_records_sql("SELECT COUNT(*) FROM {view} v
+ JOIN {view_access} va ON va.view = v.id
+ WHERE (va.token IS NOT null AND va.token !='')
+ AND v.template = ?
+ AND v.id = ?", array(self::USER_TEMPLATE, $this->id))) {
+ return true;
+ }
return false;
}
diff --git a/htdocs/theme/raw/templates/view/view.tpl b/htdocs/theme/raw/templates/view/view.tpl
index 45f51c07a5050c7b6af1e486805337be146582a4..87b955b599532acbdd1c1299f8d3172671b7eb38 100644
--- a/htdocs/theme/raw/templates/view/view.tpl
+++ b/htdocs/theme/raw/templates/view/view.tpl
@@ -35,7 +35,11 @@
{/strip}{/if}
{if $copyurl}{strip}
-
+ {if $downloadurl}
+
+ {else}
+
+ {/if}
{str tag=copy section=mahara}
diff --git a/htdocs/view/copy.php b/htdocs/view/copy.php
index 1d679a89de9888e6a844df730a73015d407dddce..fb9c16df9d3239dcf3503cd62a9cecb67e7d7bc3 100644
--- a/htdocs/view/copy.php
+++ b/htdocs/view/copy.php
@@ -24,7 +24,9 @@ $collection = param_integer('collection', null);
$groupid = param_integer('group', null);
$view = new View($viewid);
-
+if (!can_view_view($view)) {
+ throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view'));
+}
if (!$view->is_copyable()) {
throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view'));
}
diff --git a/htdocs/view/download.php b/htdocs/view/download.php
new file mode 100644
index 0000000000000000000000000000000000000000..1d894e763e47bb8df840f0e92652cc8b9249e582
--- /dev/null
+++ b/htdocs/view/download.php
@@ -0,0 +1,64 @@
+is_copyable()) {
+ throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view'));
+}
+
+safe_require('export', 'leap');
+$user = new User();
+$user->find_by_id($view->get('owner'));
+
+if (isset($collection)) {
+ //get all views in collection
+ require_once(get_config('libroot') . 'collection.php');
+ $colltemplate = new Collection($collection);
+ $views = $colltemplate->views();
+ $views = array_column($views['views'], 'view');
+
+ $artefacts = PluginExport::EXPORT_LIST_OF_COLLECTIONS;
+}
+else {
+ $views = array($view->get('id'));
+ $artefacts = PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS;
+}
+
+$exporter = new PluginExportLeap($user, $views, $artefacts);
+
+$exporter->includefeedback = false; // currently only doing leap2a exports and they can't handle feedback
+
+try {
+ $zipfile = $exporter->export();
+}
+catch (SystemException $e) {
+ $errors[] = get_string('exportzipfileerror', 'export', $e->getMessage());
+ log_warn($e->getMessage());
+}
+
+require_once('file.php');
+serve_file($exporter->get('exportdir') . $zipfile, $zipfile, 'application/x-zip', array('lifetime' => 0, 'forcedownload' => true));
diff --git a/htdocs/view/view.php b/htdocs/view/view.php
index 9de75017633f4738dfb036e5b6162b7620570c4e..3cc9291f23c90a57d87e9a5e26e9381e1e77ff8a 100644
--- a/htdocs/view/view.php
+++ b/htdocs/view/view.php
@@ -273,7 +273,7 @@ if (get_config_plugin('blocktype', 'gallery', 'useslimbox2')) {
}
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
-$can_copy = $view->is_copyable($view);
+$can_copy = $view->is_copyable();
$viewgroupform = false;
if ($owner && $owner == $USER->get('id')) {
@@ -386,6 +386,10 @@ if ($can_edit) {
}
if ($can_copy) {
$smarty->assign('copyurl', get_config('wwwroot') . 'view/copy.php?id=' . $viewid . (!empty($collection) ? '&collection=' . $collection->get('id') : ''));
+ if (!$USER->is_logged_in() && $view->get('owner')) {
+ // if no user is loggedin and the personal profile is public, the Copy button should download the portfolio
+ $smarty->assign('downloadurl', get_config('wwwroot') . 'view/download.php?id=' . $viewid . (!empty($collection) ? '&collection=' . $collection->get('id') : ''));
+ }
}
$title = hsc(TITLE);