diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2019-01-14 19:24:19 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-01-14 19:24:19 +0100 |
commit | 8130427ec508f1d66553b52052c840c311081061 (patch) | |
tree | 23bab28db0f649618aa6bea024dcee84a9a25308 | |
parent | eb30a63c819ca50ebbc896eb293a0745dcd043be (diff) | |
download | wcms-8130427ec508f1d66553b52052c840c311081061.tar.gz wcms-8130427ec508f1d66553b52052c840c311081061.zip |
fix save art out of session
-rw-r--r-- | app/class/controllerart.php | 76 | ||||
-rw-r--r-- | app/class/controllerconnect.php | 36 | ||||
-rw-r--r-- | app/view/templates/backtopbar.php | 1 | ||||
-rw-r--r-- | app/view/templates/connect.php | 4 | ||||
-rw-r--r-- | app/view/templates/navart.php | 2 | ||||
-rw-r--r-- | assets/css/edit.css | 2 |
6 files changed, 76 insertions, 45 deletions
diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 00b7558..20ef634 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -33,13 +33,19 @@ class Controllerart extends Controller public function importart() { - $art = $this->artmanager->get($this->art); + if (isset($_SESSION['artupdate']) && $_SESSION['artupdate']['id'] == $this->art->id()) { + $art = new Art2($_SESSION['artupdate']); + unset($_SESSION['artupdate']); + } else { + $art = $this->artmanager->get($this->art); + } if ($art !== false) { $this->art = $art; return true; } else { return false; } + } @@ -104,9 +110,9 @@ class Controllerart extends Controller } else { $page = ['head' => $this->art->renderhead(), 'body' => $this->art->renderbody()]; } - if($canread) { + if ($canread) { $this->art->addaffcount(); - if($this->user->level() < 2) { + if ($this->user->level() < 2) { $this->art->addvisitcount(); } } @@ -208,40 +214,56 @@ class Controllerart extends Controller public function update($id) { $this->setart($id, 'artupdate'); - $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); - $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']); - - if (!empty($_POST['fontsize']) && $_POST['fontsize'] !== Config::fontsize()) { - Config::setfontsize($_POST['fontsize']); - Config::savejson(); - } - + $this->movepanels(); + $this->fontsize(); $date = new DateTimeImmutable($_POST['pdate'] . $_POST['ptime'], new DateTimeZone('Europe/Paris')); $date = ['date' => $date]; - if ($this->importart() && $this->canedit()) { + if ($this->importart()) { + if ($this->canedit()) { + + // Check if someone esle edited the page during the editing. + $oldart = clone $this->art; + $this->art->hydrate($_POST); - $oldart = clone $this->art; - $this->art->hydrate($_POST); + if (self::COMBINE && $_POST['thisdatemodif'] === $oldart->datemodif('string')) { - if (self::COMBINE) { - if ($_POST['thisdatemodif'] === $oldart->datemodif('string')) { - $compare = $this->artmanager->combine($this->art, $oldart); - if (!empty($compare['diff'])) { - $this->art->hydrate($compare['mergeart']); - } } - } - $this->art->hydrate($date); - $this->art->updateedited(); - $this->art->addauthor($this->user->id()); - $this->artmanager->update($this->art); - $this->routedirect('artedit', ['art' => $this->art->id()]); - + $this->art->hydrate($date); + $this->art->updateedited(); + $this->art->addauthor($this->user->id()); + + + $this->artmanager->update($this->art); + + $this->routedirect('artedit', ['art' => $this->art->id()]); + //$this->showtemplate('updatemerge', $compare); + } else { + // If the editor session finished during the editing, let's try to reconnect to save the editing + $_SESSION['artupdate'] = $_POST; + $_SESSION['artupdate']['id'] = $this->art->id(); + $this->routedirect('connect'); + } + + } + $this->routedirect('art'); + } + + public function movepanels() + { + $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); + $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']); + } + + public function fontsize() + { + if (!empty($_POST['fontsize']) && $_POST['fontsize'] !== Config::fontsize()) { + Config::setfontsize($_POST['fontsize']); + Config::savejson(); } } diff --git a/app/class/controllerconnect.php b/app/class/controllerconnect.php index 2e3f976..d0e3ee5 100644 --- a/app/class/controllerconnect.php +++ b/app/class/controllerconnect.php @@ -6,31 +6,33 @@ class Controllerconnect extends Controller public function log() { if (isset($_POST['log'])) { - if (isset($_POST['id'])) { - $id = $_POST['id']; - } else { - $id = null; - } + $id = $_POST['id'] ?? null; + $route = $_POST['route'] ?? 'home'; if ($_POST['log'] === 'login') { - $this->login($id); + $this->login($route, $id); } elseif ($_POST['log'] === 'logout') { - $this->logout($id); + $this->logout($route, $id); } } - } public function connect() { - $this->showtemplate('connect', []); + if(isset($_SESSION['artupdate'])) { + $artupdate['route'] = 'artedit'; + $artupdate['id'] = $_SESSION['artupdate']['id']; + } else { + $artupdate = [$route = 'home']; + } + $this->showtemplate('connect', $artupdate); } - public function login($id) + public function login($route, $id = null) { if (isset($_POST['pass'])) { $this->user = $this->usermanager->login($_POST['pass']); @@ -41,21 +43,21 @@ class Controllerconnect extends Controller } } - if (!empty($id)) { - $this->routedirect('artread/', ['art' => $id]); + if ($id !== null) { + $this->routedirect($route, ['art' => $id]); } else { - $this->routedirect('home'); + $this->routedirect($route); } } - public function logout($id) + public function logout($route, $id = null) { $this->user = $this->usermanager->logout(); $this->usermanager->writesession($this->user); - if (!empty($id)) { - $this->routedirect('artread/', ['art' => $id]); + if ($id !== null && $route !== 'home') { + $this->routedirect($route, ['art' => $id]); } else { - $this->routedirect('home'); + $this->routedirect($route); } } diff --git a/app/view/templates/backtopbar.php b/app/view/templates/backtopbar.php index 07b19e8..d6b522e 100644 --- a/app/view/templates/backtopbar.php +++ b/app/view/templates/backtopbar.php @@ -15,6 +15,7 @@ <form action="<?= $this->url('log') ?>" method="post" id="connect"> <input type="password" name="pass" id="loginpass" placeholder="password"> +<input type="hidden" name="route" value="home"> <input type="submit" name="log" value="login"> </form> diff --git a/app/view/templates/connect.php b/app/view/templates/connect.php index 06fe9c8..5d7ee5c 100644 --- a/app/view/templates/connect.php +++ b/app/view/templates/connect.php @@ -11,7 +11,11 @@ <?php if($user->isvisitor()) { ?> +<?= $route === 'artedit' ? '<p>Your edits have been temporary saved. You need to connect and update to store it completly</p>' : '' ?> + <form action="<?= $this->url('log') ?>" method="post"> +<input type="hidden" name="route" value="<?= $route ?>"> +<input type="hidden" name="id" value="<?= $id ?>"> <input type="password" name="pass" id="loginpass" placeholder="password"> <input name="log" type="submit" value="login"> </form> diff --git a/app/view/templates/navart.php b/app/view/templates/navart.php index be3b248..1e6b551 100644 --- a/app/view/templates/navart.php +++ b/app/view/templates/navart.php @@ -72,6 +72,7 @@ <li class="drop"> <form action="<?= $this->url('log') ?>" method="post"> <input type="password" name="pass" id="loginpass" placeholder="password"> + <input type="hidden" name="route" value="artread/"> <input type="hidden" name="id" value="<?= $art->id() ?>"> <input type="submit" name="log" value="login" id="button"> </form> @@ -82,6 +83,7 @@ <li class="drop"> <form action="<?= $this->url('log') ?>" method="post"> <input type="hidden" name="id" value="<?= $art->id() ?>"> + <input type="hidden" name="route" value="artread/"> <input type="submit" name="log" value="logout" id="button"> </form> </li> diff --git a/assets/css/edit.css b/assets/css/edit.css index 7f7553c..5598aa5 100644 --- a/assets/css/edit.css +++ b/assets/css/edit.css @@ -212,7 +212,7 @@ details { } input#fontsize { - width: 36px; + width: 50px; } span#headid {color: white;} |