aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/class/controller.php3
-rw-r--r--app/class/controllerart.php23
-rw-r--r--app/class/modelart.php25
-rw-r--r--app/class/modelrender.php1
-rw-r--r--app/class/routes.php1
-rw-r--r--app/view/templates/home.php23
-rw-r--r--assets/css/home.css18
-rw-r--r--composer.json2
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 @@
<h2>Pages</h2>
+<details id="import">
+ <summary>Import W JSON page file</summary>
+ <i>Upload page file as json</i>
+ <form action="<?=$this->url('artupload') ?>" method="post" enctype="multipart/form-data">
+ <input type="file" name="pagefile" id="pagefile" accept=".json">
+ <label for="pagefile">JSON Page file</label>
+ <input type="hidden" name="erase" value="0">
+ <input type="hidden" name="datecreation" value="0">
+ </br>
+ <input type="text" name="id" id="id" placeholder="new id (optionnal)">
+ <label for="id">change ID</label>
+ </br>
+ <input type="checkbox" name="datecreation" id="datecreation" value="1">
+ <label for="datecreation">Reset date creation as now</label>
+ </br>
+ <input type="checkbox" name="erase" id="erase" value="1">
+ <label for="erase">Replace if already existing</label>
+ </br>
+ <input type="submit" value="upload">
+ </form>
+</details>
+
+
<form action="/massedit" method="post">
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.*",