aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-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
-rw-r--r--app/view/templates/admin.php78
-rw-r--r--app/view/templates/backtopbar.php (renamed from app/view/templates/hometopbar.php)13
-rw-r--r--app/view/templates/font.php6
-rw-r--r--app/view/templates/home.php5
13 files changed, 231 insertions, 29 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/'],
diff --git a/app/view/templates/admin.php b/app/view/templates/admin.php
new file mode 100644
index 0000000..54bbedd
--- /dev/null
+++ b/app/view/templates/admin.php
@@ -0,0 +1,78 @@
+<?php $this->layout('layout', ['title' => 'admin', 'css' => $css . 'home.css']) ?>
+
+
+<?php $this->start('page') ?>
+
+<body>
+
+ <?php $this->insert('backtopbar', ['user' => $user]) ?>
+
+
+<section class="admin">
+
+ <form action="<?= $this->url('adminupdate') ?>" method="post">
+
+ <h2>Passwords</h2>
+ <label for="admin">Admin password</label>
+ <input type="password" name="admin" id="admin" value="<?= Config::admin() ?>">
+ <label for="editor">Editor password</label>
+ <input type="password" name="editor" id="editor" value="<?= Config::editor() ?>">
+
+ <h2>Page creation</h2>
+ <label for="defaultart">Create new page based on an already existing one</label>
+ <select name="defaultart" id="defaultart">
+ <option value="" <?= Config::defaultart() === '' || !$defaultartexist ? 'selected' : '' ?>>--use default BODY element--</option>
+ <?php
+ foreach ($artlist as $art) {
+ ?>
+ <option value="<?= $art ?>" <?= Config::defaultart() === $art ? 'selected' : '' ?>><?= $art ?></option>
+ <?php }
+ ?>
+ </select>
+
+ <?php
+ if(empty(!$defaultartexist || Config::defaultart())) {
+ ?>
+ <label for="defaultbody">Or edit default BODY element</label>
+ <textarea name="defaultbody" id="defaultbody" cols="30" rows="10"><?= Config::defaultbody() ?></textarea>
+ <?php
+ }
+ ?>
+
+
+ <h2>Editing</h2>
+
+ <label for="existnot">Tooltip hover internal link when page does not exist yet</label>
+ <input type="text" name="existnot" id="existnot" value="<?= Config::existnot() ?>">
+
+ <label for="showeditmenu">Show editor menu in top right corner of pages</label>
+ <input type="checkbox" name="showeditmenu" id="showeditmenu" <?= Config::showeditmenu() === true ? 'checked' : '' ?>>
+
+ <?php
+ if(Config::showeditmenu() === true) {
+ ?>
+ <label for="editsymbol">Symbol</label>
+ <select name="editsymbol" id="editsymbol">
+ <?php
+ foreach (Model::EDIT_SYMBOLS as $symbol) {
+ ?>
+ <option value="<?= $symbol ?>" <?= Config::editsymbol() === $symbol ? 'selected' : '' ?>><?= $symbol ?></option>
+ <?php
+ }
+ ?>
+ </select>
+ <?php
+ }
+ ?>
+
+ <input type="submit" value="submit">
+
+ </form>
+
+
+
+
+</section>
+</body>
+
+<?php $this->stop('page') ?> \ No newline at end of file
diff --git a/app/view/templates/hometopbar.php b/app/view/templates/backtopbar.php
index ff0b5f8..1f4a246 100644
--- a/app/view/templates/hometopbar.php
+++ b/app/view/templates/backtopbar.php
@@ -25,12 +25,21 @@ User level : <?= $user->level() ?>
<span>
-| <a href="">media</a>
-| <a href="">admin</a>
+<a href="<?= $this->url('home') ?>">home</a>
+<?php
+if($user->isadmin()) {
+?>
+<a href="<?= $this->url('font') ?>">font</a>
+<a href="<?= $this->url('admin') ?>">admin</a>
+<?php
+}
+?>
</span>
+
+
<?php } ?>
</div> \ No newline at end of file
diff --git a/app/view/templates/font.php b/app/view/templates/font.php
index e294031..1bd64a2 100644
--- a/app/view/templates/font.php
+++ b/app/view/templates/font.php
@@ -1,9 +1,13 @@
-<?php $this->layout('layout', ['title' => 'font', 'css' => $css . 'font.css']) ?>
+<?php $this->layout('layout', ['title' => 'font', 'css' => $css . 'home.css']) ?>
<?php $this->start('page') ?>
<body>
+
+ <?php $this->insert('backtopbar', ['user' => $user]) ?>
+
+
<section class="font">
diff --git a/app/view/templates/home.php b/app/view/templates/home.php
index 0d09238..24e378b 100644
--- a/app/view/templates/home.php
+++ b/app/view/templates/home.php
@@ -8,7 +8,7 @@
<body>
- <?php $this->insert('hometopbar', ['user' => $user]) ?>
+ <?php $this->insert('backtopbar', ['user' => $user]) ?>
<?php if($user->iseditor()) { ?>
@@ -28,7 +28,7 @@
<div id="main">
<h2>Articles</h2>
-<form action="./" method="post">
+<form action="/massedit" method="post">
<div id="massedit">
@@ -40,6 +40,7 @@
<option value="erasetag">erase all tags</option>
<option value="erasetemplate">erase template</option>
<option value="delete">delete</option>
+ <option value="render">render</option>
</select>
<input type="submit" name="massaction" value="do" onclick="confirmSubmit(event, 'Are you sure')" >