From 20c44426207b8f58fd8ef1145b509913371b2901 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 30 Mar 2019 20:44:55 +0100 Subject: new feature : upload json as page --- app/class/controller.php | 3 +++ app/class/controllerart.php | 23 +++++++++++++++++++++++ app/class/modelart.php | 25 +++++++++++++++++++++++++ app/class/modelrender.php | 1 + app/class/routes.php | 1 + app/view/templates/home.php | 23 +++++++++++++++++++++++ assets/css/home.css | 18 +++++++++++------- composer.json | 2 +- 8 files changed, 88 insertions(+), 8 deletions(-) diff --git a/app/class/controller.php b/app/class/controller.php index ce1507a..c4994f8 100644 --- a/app/class/controller.php +++ b/app/class/controller.php @@ -15,11 +15,14 @@ class Controller */ protected $usermanager; protected $plates; + /** @var DateTimeImmutable */ + protected $now; public function __construct($router) { $this->setuser(); $this->router = $router; $this->initplates(); + $this->now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); } public function setuser() diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 4d7b1be..ce742a1 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -241,6 +241,29 @@ class Controllerart extends Controller } } + /** + * Import page and save it into the database + */ + public function upload() + { + $art = $this->artmanager->getfromfile(); + + if(!empty($_POST['id'])) { + $art->setid(idclean($_POST['id'])); + } + + if($_POST['datecreation']) { + $art->setdatecreation($this->now); + } + + if($art !== false) { + if($_POST['erase'] || $this->artmanager->get($art) === false) { + $this->artmanager->add($art); + } + } + $this->routedirect('home'); + } + public function delete($id) { $this->setart($id, 'artdelete'); diff --git a/app/class/modelart.php b/app/class/modelart.php index e9d4b86..f5b4858 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -63,6 +63,31 @@ class Modelart extends Modeldb } } + /** + * Transform File to Art2 Oject + * + * @return false|Art2 + */ + public function getfromfile() + { + if(!isset($_FILES['pagefile']) || $_FILES['pagefile']['error'] > 0 ) return false; + + $ext = substr(strrchr($_FILES['pagefile']['name'],'.'),1); + if($ext !== 'json') return false; + + $files = $_FILES; + + $json = file_get_contents($_FILES['pagefile']['tmp_name']); + $pagedata = json_decode($json, true); + + if($pagedata === false) return false; + + $page = new Art2($pagedata); + + return $page; + + } + public function getartelement($id, $element) { if (in_array($element, Model::TEXT_ELEMENTS)) { diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 8b62cd2..046499f 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -142,6 +142,7 @@ class Modelrender extends Modelart $content = $this->autotaglistupdate($content); $content = $this->date($content); if($element->autolink()) { + $content = str_replace('%LINK%', '' ,$content); $content = $this->everylink($content, $element->autolink()); } else { $content = $this->taglink($content); diff --git a/app/class/routes.php b/app/class/routes.php index f3b9adf..bad6e19 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -16,6 +16,7 @@ class Routes $router->addRoutes([ ['GET', '/', 'Controllerhome#desktop', 'home'], ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], + ['POST', '/upload', 'Controllerart#upload', 'artupload'], ['POST', '/!co', 'Controllerconnect#log', 'log'], ['GET', '/!co', 'Controllerconnect#connect', 'connect'], ['POST', '/!search', 'Controllerhome#search', 'search'], diff --git a/app/view/templates/home.php b/app/view/templates/home.php index fab5146..137e1b3 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -28,6 +28,29 @@

Pages

+
+ Import W JSON page file + Upload page file as json +
+ + + + +
+ + +
+ + +
+ + +
+ +
+
+ +
diff --git a/assets/css/home.css b/assets/css/home.css index 840ac9c..cc86a55 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -16,6 +16,17 @@ main.home { display: flex; } +main.home article#main { + width: 100%; +} + +main.home div#main { + display: flex; + align-items: flex-start; + flex-direction: column; +} + + body { margin: 0; height: 100%; @@ -365,10 +376,3 @@ main.timeline li.event { } -article#main {} - -div#main { - display: flex; - align-items: flex-start; - flex-direction: column; -} \ No newline at end of file diff --git a/composer.json b/composer.json index d369040..64ba744 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "w-cms", "description": "point'n think", - "version": "1.1.3", + "version": "1.2.0", "require": { "michelf/php-markdown": "^1.8", "league/plates": "3.*", -- cgit v1.2.3