aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-12-04 13:55:04 +0100
committervincent-peugnet <v.peugnet@free.fr>2018-12-04 13:55:04 +0100
commit13acdbd444b0ae26e83ab8cf62d60a7f59268545 (patch)
tree9186bda4bffa9751c5e93da2d09d762f40cc0adc /app/class
parentd0ef17169701f90a9dab5f50e3eb61954653cae2 (diff)
downloadwcms-13acdbd444b0ae26e83ab8cf62d60a7f59268545.tar.gz
wcms-13acdbd444b0ae26e83ab8cf62d60a7f59268545.zip
admin panel
Diffstat (limited to 'app/class')
-rw-r--r--app/class/config.php57
-rw-r--r--app/class/controlleradmin.php28
-rw-r--r--app/class/controllerart.php14
-rw-r--r--app/class/controllerfont.php8
-rw-r--r--app/class/model.php17
-rw-r--r--app/class/modelart.php20
-rw-r--r--app/class/modelfont.php2
-rw-r--r--app/class/modelrender.php8
-rw-r--r--app/class/routes.php4
9 files changed, 134 insertions, 24 deletions
diff --git a/app/class/config.php b/app/class/config.php
index 3b05c1a..38ccf5f 100644
--- a/app/class/config.php
+++ b/app/class/config.php
@@ -15,6 +15,10 @@ abstract class Config
protected static $basepath = '';
protected static $route404;
protected static $existnot = 'This page does not exist yet';
+ protected static $defaultbody = '';
+ protected static $defaultart = 'cul';
+ protected static $showeditmenu = true;
+ protected static $editsymbol = 'pen';
@@ -127,6 +131,26 @@ abstract class Config
return self::$existnot;
}
+ public static function defaultbody()
+ {
+ return self::$defaultbody;
+ }
+
+ public static function defaultart()
+ {
+ return self::$defaultart;
+ }
+
+ public static function showeditmenu()
+ {
+ return self::$showeditmenu;
+ }
+
+ public static function editsymbol()
+ {
+ return self::$editsymbol;
+ }
+
// __________________________________________ S E T ______________________________________
@@ -197,6 +221,39 @@ abstract class Config
}
}
+ public static function setdefaultbody($defaultbody)
+ {
+ if(is_string($defaultbody)) {
+ self::$defaultbody = $defaultbody;
+ }
+ }
+
+ public static function setdefaultart($defaultart)
+ {
+ if(is_string($defaultart)) {
+ self::$defaultart = idclean($defaultart);
+ }
+ }
+
+ public static function setshoweditmenu($showeditmenu)
+ {
+ if(is_bool($showeditmenu)) {
+ self::$showeditmenu = $showeditmenu;
+ } elseif (is_string($showeditmenu)) {
+ if($showeditmenu === 'on') {
+ self::$showeditmenu = true;
+ }
+ }
+ }
+
+ public static function seteditsymbol($editsymbol)
+ {
+ if(is_string($editsymbol))
+ {
+ self::$editsymbol = $editsymbol;
+ }
+ }
+
diff --git a/app/class/controlleradmin.php b/app/class/controlleradmin.php
index 62c8fba..0829916 100644
--- a/app/class/controlleradmin.php
+++ b/app/class/controlleradmin.php
@@ -3,18 +3,40 @@
class Controlleradmin extends Controller
{
+ protected $artmanager;
+
public function desktop()
{
- echo '<h1>Admin</h1>';
+ if($this->user->isadmin()) {
+ $this->artmanager = new Modelart();
+ $artlist = $this->artmanager->list();
+ if(in_array(Config::defaultart(), $artlist)) {
+ $defaultartexist = true;
+ } else {
+ $defaultartexist = true;
+ }
+ $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist];
+ $this->showtemplate('admin', $admin);
+ }
}
- public function addtable()
+ public function update()
{
-
+ if(!isset($_POST['showeditmenu'])) {
+ $_POST['showeditmenu'] = false;
+ }
+ Config::hydrate($_POST);
+ if(Config::savejson() !== false) {
+ $this->routedirect('admin');
+ } else {
+ echo 'Can\'t write config file';
+ }
}
+
+
}
diff --git a/app/class/controllerart.php b/app/class/controllerart.php
index 67ec280..0dee8e7 100644
--- a/app/class/controllerart.php
+++ b/app/class/controllerart.php
@@ -90,14 +90,14 @@ class Controllerart extends Controller
$artexist = $this->importart();
$canread = $this->user->level() >= $this->art->secure();
$alerts = ['alertnotexist' => 'This page does not exist yet', 'alertprivate' => 'You cannot see this page'];
- $page = ['head' => '', 'body' => ''];
+ $page = ['head' => '', 'body' => ''];
if ($artexist) {
if ($this->art->daterender() < $this->art->datemodif()) {
$page = $this->renderart();
} else {
- $page = ['head' => $this->art->renderhead(), 'body' => $this->art->renderbody()];
+ $page = ['head' => $this->art->renderhead(), 'body' => $this->art->renderbody()];
}
$this->art->addaffcount();
$this->artmanager->update($this->art);
@@ -148,6 +148,16 @@ class Controllerart extends Controller
$this->setart($id, 'artadd');
if ($this->user->iseditor() && !$this->importart()) {
$this->art->reset();
+ if (!empty(Config::defaultart())) {
+ $defaultart = $this->artmanager->get(Config::defaultart());
+ if ($defaultart !== false) {
+ $defaultbody = $defaultart->body();
+ }
+ }
+ if(empty(Config::defaultart()) || $defaultart === false) {
+ $defaultbody = Config::defaultbody();
+ }
+ $this->art->setbody($defaultbody);
$this->artmanager->add($this->art);
$this->routedirect('artedit', ['art' => $this->art->id()]);
} else {
diff --git a/app/class/controllerfont.php b/app/class/controllerfont.php
index d85e60e..b1cd0d9 100644
--- a/app/class/controllerfont.php
+++ b/app/class/controllerfont.php
@@ -32,13 +32,17 @@ class Controllerfont extends Controller
public function add()
{
- var_dump($_FILES);
if(isset($_POST['fontname'])) {
$fontname = $_POST['fontname'];
} else {
$fontname = '';
}
- var_dump($this->fontmanager->upload($_FILES, 2 ** 16, $fontname));
+ $message = $this->fontmanager->upload($_FILES, 2 ** 16, $fontname);
+ if($message !== true) {
+ echo $message;
+ } else {
+ $this->render();
+ }
}
}
diff --git a/app/class/model.php b/app/class/model.php
index 600e930..4024f62 100644
--- a/app/class/model.php
+++ b/app/class/model.php
@@ -14,41 +14,42 @@ abstract class Model
const MEDIA_TYPES = ['image', 'video', 'sound', 'other'];
const TEXT_ELEMENTS = ['header', 'nav', 'section', 'aside', 'footer'];
+ const EDIT_SYMBOLS = ['pen', 'tool', 'none'];
public static function renderpath()
{
$basepath = '';
if(!empty(Config::basepath())) {
- $basepath = Config::basepath() . DIRECTORY_SEPARATOR ;
+ $basepath = Config::basepath() . '/' ;
}
- return DIRECTORY_SEPARATOR . $basepath . Model::RENDER_DIR;
+ return '/' . $basepath . Model::RENDER_DIR;
}
public static function globalpath()
{
$basepath = '';
if(!empty(Config::basepath())) {
- $basepath = Config::basepath() . DIRECTORY_SEPARATOR ;
+ $basepath = Config::basepath() . '/' ;
}
- return DIRECTORY_SEPARATOR . $basepath . Model::GLOBAL_DIR;
+ return '/' . $basepath . Model::GLOBAL_DIR;
}
public static function csspath()
{
$basepath = '';
if(!empty(Config::basepath())) {
- $basepath = Config::basepath() . DIRECTORY_SEPARATOR ;
+ $basepath = Config::basepath() . '/' ;
}
- return DIRECTORY_SEPARATOR . $basepath . Model::CSS_DIR;
+ return '/' . $basepath . Model::CSS_DIR;
}
public static function mediapath()
{
$basepath = '';
if(!empty(Config::basepath())) {
- $basepath = Config::basepath() . DIRECTORY_SEPARATOR ;
+ $basepath = Config::basepath() . '/' ;
}
- return DIRECTORY_SEPARATOR . $basepath . Model::MEDIA_DIR;
+ return '/' . $basepath . Model::MEDIA_DIR;
}
public static function fontpath()
diff --git a/app/class/modelart.php b/app/class/modelart.php
index 8117284..3fa2d48 100644
--- a/app/class/modelart.php
+++ b/app/class/modelart.php
@@ -17,12 +17,12 @@ class Modelart extends Modeldb
public function exist(Art2 $art)
{
$artdata = $this->artstore->get($art->id());
- if($artdata === false) {
+ if ($artdata === false) {
return false;
} else {
return true;
}
-
+
}
@@ -34,14 +34,15 @@ class Modelart extends Modeldb
$this->artstore->store($artdata);
}
+
public function get($id)
{
- if($id instanceof Art2) {
+ if ($id instanceof Art2) {
$id = $id->id();
}
- if(is_string($id)) {
+ if (is_string($id)) {
$artdata = $this->artstore->findById($id);
- if($artdata !== false) {
+ if ($artdata !== false) {
return new Art2($artdata);
} else {
return false;
@@ -54,6 +55,15 @@ class Modelart extends Modeldb
public function delete(Art2 $art)
{
$this->artstore->delete($art->id());
+ $this->unlink($art->id());
+ }
+
+
+ public function unlink(string $artid)
+ {
+ unlink(Model::RENDER_DIR . $artid . '.css');
+ unlink(Model::RENDER_DIR . $artid . '.quick.css');
+ unlink(Model::RENDER_DIR . $artid . '.js');
}
public function update(Art2 $art)
diff --git a/app/class/modelfont.php b/app/class/modelfont.php
index 4059096..213da11 100644
--- a/app/class/modelfont.php
+++ b/app/class/modelfont.php
@@ -95,7 +95,7 @@ class Modelfont extends Model
$extension_upload = strtolower($extension_upload);
$uploadok = move_uploaded_file($file['font']['tmp_name'], $this::FONT_DIR . $id . '.' . $extension_upload);
if ($uploadok) {
- $message = 'uploadok';
+ $message = true;
} else {
$message = 'uploaderror';
}
diff --git a/app/class/modelrender.php b/app/class/modelrender.php
index 4eab655..829c132 100644
--- a/app/class/modelrender.php
+++ b/app/class/modelrender.php
@@ -89,6 +89,8 @@ class Modelrender extends Modelart
return $body;
}
+
+
public function write()
{
file_put_contents(Model::RENDER_DIR . $this->art->id() . '.css', $this->art->css());
@@ -96,6 +98,8 @@ class Modelrender extends Modelart
file_put_contents(Model::RENDER_DIR . $this->art->id() . '.js', $this->art->javascript());
}
+
+
public function writetemplates()
{
if (array_key_exists('css', $this->art->template('array'))) {
@@ -158,6 +162,8 @@ class Modelrender extends Modelart
public function parser(string $text)
{
+ $text = str_replace('<a href="/', '<a class="media" target="_blank" href="'. Model::mediapath(), $text);
+ $text = str_replace('<img src="/', '<img class="local" src="'. Model::mediapath(), $text);
$text = $this->headerid($text);
@@ -170,8 +176,6 @@ class Modelrender extends Modelart
$text = str_replace('href="http', ' class="external" target="_blank" href="http', $text);
- $text = str_replace('<img src="/', '<img class="local" src="'. Model::mediapath(), $text);
- $text = str_replace('<a href="/', '<a class="media" target="_blank" href="'. Model::mediapath(), $text);
$text = $this->autourl($text);
diff --git a/app/class/routes.php b/app/class/routes.php
index 5edfa81..6eb992b 100644
--- a/app/class/routes.php
+++ b/app/class/routes.php
@@ -10,7 +10,7 @@ class Routes
{
$router = new AltoRouter();
if(!empty(Config::basepath())) {
- $router->setBasePath(DIRECTORY_SEPARATOR . Config::basepath());
+ $router->setBasePath('/' . Config::basepath());
}
$router->addMatchTypes(array('cid' => '[a-zA-Z0-9-_+,\'!%@&.$€=\(\|\)]+'));
$router->addRoutes([
@@ -19,6 +19,8 @@ class Routes
['GET', '/!co', 'Controllerconnect#connect', 'connect'],
['GET', '/!m', 'Controllermedia#desktop', 'media'],
['GET', '/!font', 'Controllerfont#desktop', 'font'],
+ ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'],
+ ['GET', '/!admin', 'Controlleradmin#desktop', 'admin'],
['GET', '/!font/render', 'Controllerfont#render', 'fontrender'],
['POST', '/!font/add', 'Controllerfont#add', 'fontadd'],
['GET', '/[cid:art]/', 'Controllerart#read', 'artread/'],