aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/class/Controllerpage.php42
-rw-r--r--app/class/Page.php9
-rw-r--r--app/class/Routes.php2
3 files changed, 53 insertions, 0 deletions
diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php
index 585db0a..92632fc 100644
--- a/app/class/Controllerpage.php
+++ b/app/class/Controllerpage.php
@@ -230,6 +230,16 @@ class Controllerpage extends Controller
}
}
+ public function addascopy(string $id, string $copy)
+ {
+ $id = idclean($id);
+ if($this->copy($copy, $id)) {
+ $this->routedirect('pageedit', ['page' => $this->page->id()]);
+ } else {
+ $this->routedirect('pageread/', ['page' => $id]);
+ }
+ }
+
public function confirmdelete($id)
{
$this->setpage($id, 'pageconfirmdelete');
@@ -304,6 +314,38 @@ class Controllerpage extends Controller
$this->routedirect('home');
}
+ public function duplicate(string $srcid, string $targetid)
+ {
+ $targetid = idclean($targetid);
+ if ($this->copy($srcid, $targetid)) {
+ $this->routedirect('pageread/', ['page' => $targetid]);
+ } else {
+ $this->routedirect('pageread/', ['page' => idclean($srcid)]);
+
+ }
+ }
+
+ /**
+ * Copy a page to a new ID
+ *
+ * @param string $srcid Source page ID
+ * @param string $targetid Target page ID
+ */
+ public function copy(string $srcid, string $targetid)
+ {
+ if ($this->user->iseditor()) {
+ $this->page = $this->pagemanager->get($srcid);
+ if($this->page !== false && $this->canedit() && $this->pagemanager->get($targetid) === false) {
+ $this->page->setid($targetid);
+ $this->page->setdatecreation(true); // Reset date of creation
+ $this->page->addauthor($this->user->id());
+ $this->pagemanager->add($this->page);
+ return true;
+ }
+ }
+ return false;
+ }
+
public function update($id)
{
$this->setpage($id, 'pageupdate');
diff --git a/app/class/Page.php b/app/class/Page.php
index e4692e3..c30352c 100644
--- a/app/class/Page.php
+++ b/app/class/Page.php
@@ -444,10 +444,19 @@ class Page extends Dbitem
}
}
+ /**
+ * DateTimeImmutable : set date
+ * string ISO8601 : set date
+ * true : reset to now
+ *
+ * @param string|DateTimeImmutable|true $datecreation Set or reset date of creation
+ */
public function setdatecreation($datecreation)
{
if ($datecreation instanceof DateTimeImmutable) {
$this->datecreation = $datecreation;
+ } elseif ($datecreation === true) {
+ $this->datecreation = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
} else {
$this->datecreation = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $datecreation, new DateTimeZone('Europe/Paris'));
}
diff --git a/app/class/Routes.php b/app/class/Routes.php
index 277d478..e71bf59 100644
--- a/app/class/Routes.php
+++ b/app/class/Routes.php
@@ -50,6 +50,7 @@ class Routes
['GET', '/[cid:page]/', 'Controllerpage#read', 'pageread/'],
['GET', '/[cid:page]', 'Controllerpage#read', 'pageread'],
['GET', '/[cid:page]/add', 'Controllerpage#add', 'pageadd'],
+ ['GET', '/[cid:page]/add:[cid:copy]', 'Controllerpage#addascopy', 'pageaddascopy'],
['GET', '/[cid:page]/edit', 'Controllerpage#edit', 'pageedit'],
['GET', '/[cid:page]/render', 'Controllerpage#render', 'pagerender'],
['GET', '/[cid:page]/log', 'Controllerpage#log', 'pagelog'],
@@ -59,6 +60,7 @@ class Routes
['POST', '/[cid:page]/removeeditby', 'Controllerpage#removeeditby', 'pageremoveeditby'],
['GET', '/[cid:page]/delete', 'Controllerpage#confirmdelete', 'pageconfirmdelete'],
['POST', '/[cid:page]/delete', 'Controllerpage#delete', 'pagedelete'],
+ ['GET', '/[cid:page]/duplicate:[cid:duplicate]', 'Controllerpage#duplicate', 'pageduplicate'],
['GET', '/[cid:page]/[*]', 'Controllerpage#pagedirect', 'pageread/etoile'],
]);