aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-11-22 00:09:55 +0100
committervincent-peugnet <v.peugnet@free.fr>2018-11-22 00:09:55 +0100
commitd46c05b12b9dcd65d2d9cd230bf45b5bdf6fa8bd (patch)
treed763a0488fa3055a1a75b2d669744fcb8526ab92 /app
parent47689d1fdfb2c33ee5e00cfe9fe529d6ba3529db (diff)
downloadwcms-d46c05b12b9dcd65d2d9cd230bf45b5bdf6fa8bd.tar.gz
wcms-d46c05b12b9dcd65d2d9cd230bf45b5bdf6fa8bd.zip
linkfrom analyse
Diffstat (limited to 'app')
-rw-r--r--app/class/controller.php13
-rw-r--r--app/class/controllerart.php34
-rw-r--r--app/class/controllermedia.php7
-rw-r--r--app/class/model.php11
-rw-r--r--app/class/modelrender.php23
-rw-r--r--app/class/modeluser.php12
-rw-r--r--app/class/routes.php1
-rw-r--r--app/class/user.php8
-rw-r--r--app/view/templates/home.php2
-rw-r--r--app/view/templates/hometopbar.php2
-rw-r--r--app/view/templates/media.php5
-rw-r--r--app/view/templates/navart.php4
-rw-r--r--app/view/templates/navback.php2
-rw-r--r--app/view/templates/read.php2
14 files changed, 80 insertions, 46 deletions
diff --git a/app/class/controller.php b/app/class/controller.php
index c722b1a..b0681bb 100644
--- a/app/class/controller.php
+++ b/app/class/controller.php
@@ -31,18 +31,6 @@ class Controller
return $router->generate($string, ['art' => $id]);
});
}
-
- public function useriseditor()
- {
- if ($this->user->level() >= $this->usermanager::EDITOR) {
- echo '<h3>Editor access</h3>';
- return true;
- } else {
- echo '<h3>Not enought rights to see more...</h3>';
- return false;
- }
- }
-
public function showtemplate($template, $params)
{
@@ -62,6 +50,7 @@ class Controller
+
public function redirect($url)
{
header('Location: ' . $url);
diff --git a/app/class/controllerart.php b/app/class/controllerart.php
index ab3fec6..7a0ec93 100644
--- a/app/class/controllerart.php
+++ b/app/class/controllerart.php
@@ -39,6 +39,23 @@ class Controllerart extends Controller
}
}
+
+ public function canedit()
+ {
+ if($this->user->iseditor()) {
+ return true;
+ } elseif($this->user->isinvite()) {
+ if($this->user->password() === $this->art->invitepassword()) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+
public function read($id)
{
$this->setart($id, 'artread/');
@@ -47,7 +64,6 @@ class Controllerart extends Controller
$artexist = $this->importart();
$canread = $this->user->level() >= $this->art->secure();
- $cancreate = $this->user->cancreate();
$alerts = ['alertnotexist' => 'This page does not exist yet', 'alertprivate' => 'You cannot see this page'];
$body = '';
$head = '';
@@ -60,7 +76,7 @@ class Controllerart extends Controller
$body = $this->renderengine->renderbody($this->art);
$this->art->setrender($body);
$this->art->setdaterender($now);
- $this->artmanager->update($this->art);
+ $this->art->setlinkfrom($this->renderengine->linkfrom());
} else {
$body = $this->art->render();
}
@@ -73,7 +89,7 @@ class Controllerart extends Controller
}
- $data = array_merge($alerts, ['art' => $this->art, 'artexist' => $artexist, 'canread' => $canread, 'cancreate' => $cancreate, 'readernav' => true, 'body' => $body, 'head' => $head]);
+ $data = array_merge($alerts, ['art' => $this->art, 'artexist' => $artexist, 'canread' => $canread, 'readernav' => true, 'body' => $body, 'head' => $head]);
$this->showtemplate('read', $data);
@@ -87,7 +103,7 @@ class Controllerart extends Controller
$this->setart($id, 'artedit');
- if ($this->importart() && $this->user->canedit()) {
+ if ($this->importart() && $this->canedit()) {
$tablist = ['section' => $this->art->md(), 'css' => $this->art->css(), 'header' => $this->art->header(), 'nav' => $this->art->nav(), 'aside' => $this->art->aside(), 'footer' => $this->art->footer(), 'html' => $this->art->html(), 'javascript' => $this->art->javascript()];
$artlist = $this->artmanager->list();
@@ -118,7 +134,7 @@ class Controllerart extends Controller
public function add($id)
{
$this->setart($id, 'artadd');
- if ($this->user->canedit() && !$this->importart()) {
+ if ($this->user->iseditor() && !$this->importart()) {
$this->art->reset();
$this->artmanager->add($this->art);
$this->routedirect('artedit', ['art' => $this->art->id()]);
@@ -130,7 +146,7 @@ class Controllerart extends Controller
public function confirmdelete($id)
{
$this->setart($id, 'artconfirmdelete');
- if ($this->user->canedit() && $this->importart()) {
+ if ($this->user->iseditor() && $this->importart()) {
$this->showtemplate('confirmdelete', ['art' => $this->art, 'artexist' => true]);
@@ -142,7 +158,7 @@ class Controllerart extends Controller
public function delete($id)
{
$this->setart($id, 'artdelete');
- if ($this->user->canedit() && $this->importart()) {
+ if ($this->user->iseditor() && $this->importart()) {
$this->artmanager->delete($this->art);
}
@@ -158,7 +174,7 @@ class Controllerart extends Controller
$date = new DateTimeImmutable($_POST['pdate'] . $_POST['ptime'], new DateTimeZone('Europe/Paris'));
$date = ['date' => $date];
- if ($this->importart() && $this->user->canedit()) {
+ if ($this->importart() && $this->user->iseditor()) {
$this->art->hydrate($_POST);
$this->art->hydrate($date);
$this->art->updateedited();
@@ -166,7 +182,7 @@ class Controllerart extends Controller
}
- $this->routedirect('artupdate', ['art' => $this->art->id()]);
+ $this->routedirect('artedit', ['art' => $this->art->id()]);
diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php
index 75540e2..48f803b 100644
--- a/app/class/controllermedia.php
+++ b/app/class/controllermedia.php
@@ -14,12 +14,7 @@ class Controllermedia extends Controller
public function desktop()
{
-
- if($this->useriseditor()) {
-
-
-
- }
+
}
public function addmedia()
diff --git a/app/class/model.php b/app/class/model.php
index b6e2ee6..cd0733c 100644
--- a/app/class/model.php
+++ b/app/class/model.php
@@ -5,7 +5,7 @@ abstract class Model
const CONFIG_FILE = 'config.json';
const CSS_DIR = 'assets' . DIRECTORY_SEPARATOR .'css' . DIRECTORY_SEPARATOR;
const FONT_DIR = 'fonts' . DIRECTORY_SEPARATOR;
- const MEDIA_DIR = '.' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR;
+ const MEDIA_DIR = 'media' . DIRECTORY_SEPARATOR;
const TEMPLATES_DIR = '.'. DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
const RENDER_DIR = 'assets'. DIRECTORY_SEPARATOR . 'render' . DIRECTORY_SEPARATOR;
const DATABASE_DIR = '.' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR;
@@ -32,6 +32,15 @@ abstract class Model
return DIRECTORY_SEPARATOR . $basepath . Model::CSS_DIR;
}
+ public static function mediapath()
+ {
+ $basepath = '';
+ if(!empty(Config::basepath())) {
+ $basepath = Config::basepath() . DIRECTORY_SEPARATOR ;
+ }
+ return DIRECTORY_SEPARATOR . $basepath . Model::MEDIA_DIR;
+ }
+
public static function fontpath()
{
$basepath = '';
diff --git a/app/class/modelrender.php b/app/class/modelrender.php
index 82911aa..3fb1f81 100644
--- a/app/class/modelrender.php
+++ b/app/class/modelrender.php
@@ -4,6 +4,7 @@ class Modelrender extends Modelart
{
protected $router;
protected $artlist;
+ protected $linkfrom = [];
const SUMMARY = '%SUMMARY%';
@@ -172,7 +173,8 @@ class Modelrender extends Modelart
$text = $this->wikiurl($text);
$text = str_replace('href="http', ' class="external" target="_blank" href="http', $text);
- $text = str_replace('<img src="/', '<img src="./media/', $text);
+ $text = str_replace('<img src="/', '<img src="'. Model::mediapath(), $text);
+ $text = str_replace('<a href="/', '<a href="'. Model::mediapath(), $text);
$text = $this->autourl($text);
@@ -188,37 +190,43 @@ class Modelrender extends Modelart
public function wurl(string $text)
{
+ $linkfrom = [];
$rend = $this;
$text = preg_replace_callback(
'%href="([\w-]+)"%',
- function ($matches) use ($rend) {
+ function ($matches) use ($rend, &$linkfrom) {
$matchart = $rend->get($matches[1]);
if (!$matchart) {
return 'href="' . $rend->uart($matches[1]) . '"" title="' . Config::existnot() . '" class="internal"';
} else {
+ $linkfrom[] = $matchart->id();
return 'href="' . $rend->uart($matches[1]) . '" title="' . $matchart->description() . '" class="internal"';
}
},
$text
);
+ $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom));
return $text;
}
public function wikiurl(string $text)
{
+ $linkfrom = [];
$rend = $this;
$text = preg_replace_callback(
'%\[([\w-]+)\]%',
- function ($matches) use ($rend) {
+ function ($matches) use ($rend, &$linkfrom) {
$matchart = $rend->get($matches[1]);
if (!$matchart) {
return '<a href="' . $rend->uart($matches[1]) . '"" title="' . Config::existnot() . '" class="internal">' . $matches[1] . '</a>';
} else {
+ $linkfrom[] = $matchart->id();
return '<a href="' . $rend->uart($matches[1]) . '" title="' . $matchart->description() . '" class="internal">' . $matchart->title() . '</a>';
}
},
$text
);
+ $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom));
return $text;
}
@@ -321,10 +329,19 @@ class Modelrender extends Modelart
$text = str_replace('%%'.$tag.'%%', $ul, $text);
+ $this->linkfrom = array_unique(array_merge($this->linkfrom, $li));
}
return $text;
}
+ public function linkfrom()
+ {
+ sort($this->linkfrom);
+ $linkfrom = $this->linkfrom;
+ $this->linkfrom = [];
+ return $linkfrom;
+ }
+
diff --git a/app/class/modeluser.php b/app/class/modeluser.php
index 899d1cc..1644a35 100644
--- a/app/class/modeluser.php
+++ b/app/class/modeluser.php
@@ -39,13 +39,23 @@ class Modeluser extends Model
return $level = self::READ;
} elseif (strip_tags($pass) == Config::editor()) {
return $level = self::EDITOR;
- } elseif (strip_tags($pass) == Config::invite()) {
+ } elseif ($this->invitetest(strip_tags($pass))) {
return $level = self::INVITE;
} else {
return $level = self::FREE;
}
}
+ public function invitetest()
+ {
+ $invitepasslist = [];
+ if(in_array($pass, $invitepasslist)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
public function logout()
{
$user = new User(['level' => self::FREE]);
diff --git a/app/class/routes.php b/app/class/routes.php
index dda30d7..d2658a5 100644
--- a/app/class/routes.php
+++ b/app/class/routes.php
@@ -17,6 +17,7 @@ class Routes
['GET|POST', '/', 'Backrouter#run', 'backrouter'],
['POST', '/!co', 'Controllerconnect#log', 'log'],
['GET', '/!co', 'Controllerconnect#connect', 'connect'],
+ ['GET', '/!m', 'Controllermedia#desktop', 'media'],
['GET', '/[cid:art]/', 'Controllerart#read', 'artread/'],
['GET', '/[cid:art]', 'Controllerart#read', 'artread'],
['GET', '/[cid:art]/add', 'Controllerart#add', 'artadd'],
diff --git a/app/class/user.php b/app/class/user.php
index 77d6ba2..fc5a665 100644
--- a/app/class/user.php
+++ b/app/class/user.php
@@ -3,6 +3,7 @@
class User
{
protected $level = 0;
+ protected $password;
public function __construct($datas = []) {
if(!empty($datas)) {
@@ -36,15 +37,14 @@ class User
return $this->level === Modeluser::FREE;
}
- public function canedit()
+ public function iseditor()
{
- // a modifier en prenant compte du code invitation de l'article
return $this->level >= Modeluser::EDITOR;
}
- public function cancreate()
+ public function isinvite()
{
- return $this->level >=Modeluser::EDITOR;
+ return $this->level >= Modeluser::INVITE;
}
public function isadmin()
diff --git a/app/view/templates/home.php b/app/view/templates/home.php
index b5b9f67..a11f9e3 100644
--- a/app/view/templates/home.php
+++ b/app/view/templates/home.php
@@ -10,7 +10,7 @@
<?php $this->insert('hometopbar', ['user' => $user]) ?>
-<?php if($user->canedit()) { ?>
+<?php if($user->iseditor()) { ?>
<section>
diff --git a/app/view/templates/hometopbar.php b/app/view/templates/hometopbar.php
index 0640119..ff0b5f8 100644
--- a/app/view/templates/hometopbar.php
+++ b/app/view/templates/hometopbar.php
@@ -21,7 +21,7 @@ User level : <?= $user->level() ?>
<?php } ?>
-<?php if($user->canedit()) { ?>
+<?php if($user->iseditor()) { ?>
<span>
diff --git a/app/view/templates/media.php b/app/view/templates/media.php
index 8b189d5..31e3ad0 100644
--- a/app/view/templates/media.php
+++ b/app/view/templates/media.php
@@ -1,4 +1 @@
-<?php $this->layout('base', ['title' => 'Media']) ?>
-
-<h1>Media</h1>
-<p>Hello, <?=$this->e($interface)?></p> \ No newline at end of file
+<?php $this->layout('layout', ['title' => 'Media']) ?>
diff --git a/app/view/templates/navart.php b/app/view/templates/navart.php
index a98eed6..d3baef5 100644
--- a/app/view/templates/navart.php
+++ b/app/view/templates/navart.php
@@ -89,7 +89,7 @@
<?php } ?>
-<?php if($user->canedit() && $artexist) { ?>
+<?php if($user->iseditor() && $artexist) { ?>
<li class="drop">
<a class="button" href="<?= $this->uart('artread/', $art->id()) ?>" target="_blank">display</a>
@@ -101,7 +101,7 @@
<?php } ?>
-<?php if ($user->canedit()) { ?>
+<?php if ($user->iseditor()) { ?>
<li class="drop">
<a class="button" href="?aff=media" >Media</a>
diff --git a/app/view/templates/navback.php b/app/view/templates/navback.php
index c738ae2..8218897 100644
--- a/app/view/templates/navback.php
+++ b/app/view/templates/navback.php
@@ -31,7 +31,7 @@
-<?php if ($user->canedit()) { ?>
+<?php if ($user->iseditor()) { ?>
<li>
<a class="button" href="?aff=media" >Media</a>
diff --git a/app/view/templates/read.php b/app/view/templates/read.php
index 1911cf6..4e18cb3 100644
--- a/app/view/templates/read.php
+++ b/app/view/templates/read.php
@@ -52,7 +52,7 @@ $this->stop();
} else {
echo '<h1>' . $alertnotexist . '</h1>';
- if ($cancreate) {
+ if ($user->iseditor()) {
?>
<a href="<?= $this->uart('artadd', $art->id()) ?>">⭐ Create</a>
<?php