aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
Diffstat (limited to 'app/class')
-rw-r--r--app/class/Controller.php2
-rw-r--r--app/class/Controllerinfo.php18
-rw-r--r--app/class/Controllermedia.php26
-rw-r--r--app/class/Controllerpage.php14
-rw-r--r--app/class/Medialist.php119
-rw-r--r--app/class/Model.php7
-rw-r--r--app/class/Modelmedia.php50
-rw-r--r--app/class/Modelrender.php68
-rw-r--r--app/class/Page.php16
9 files changed, 234 insertions, 86 deletions
diff --git a/app/class/Controller.php b/app/class/Controller.php
index 32ffc13..c3787b2 100644
--- a/app/class/Controller.php
+++ b/app/class/Controller.php
@@ -10,7 +10,7 @@ class Controller
/** @var User */
protected $user;
- /** @var Routes */
+ /** @var \AltoRouter */
protected $router;
/** @var Modeluser */
diff --git a/app/class/Controllerinfo.php b/app/class/Controllerinfo.php
index af81caf..7b27cea 100644
--- a/app/class/Controllerinfo.php
+++ b/app/class/Controllerinfo.php
@@ -1,25 +1,31 @@
<?php
namespace Wcms;
+use Michelf\MarkdownExtra;
class Controllerinfo extends Controller
{
-
- public function __construct($render) {
+ public function __construct($render){
parent::__construct($render);
}
public function desktop()
{
if($this->user->iseditor()) {
- $this->showtemplate('info', ['version' => getversion()]);
- }
- }
+ if(file_exists(Model::MAN_FILE)) {
+ $render = new Modelrender($this->router);
+ $htmlman = file_get_contents(Model::MAN_FILE);
+ $htmlman = $render->rendermanual($htmlman);
-
+ $summary = $render->sumparser(2, 4);
+ $this->showtemplate('info', ['version' => getversion(), 'manual' => $htmlman, 'summary' => $summary]);
+
+ }
+ }
+ }
}
diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php
index 5958289..8423d18 100644
--- a/app/class/Controllermedia.php
+++ b/app/class/Controllermedia.php
@@ -32,26 +32,22 @@ class Controllermedia extends Controller
if (!$this->mediamanager->dircheck(Model::THUMBNAIL_DIR)) {
throw new Exception("Media error : Cant create /media/thumbnail folder");
}
+
+ $mediaopt = new Medialist($_GET);
+ if(empty($mediaopt->path())) {
+ $mediaopt->setpath(DIRECTORY_SEPARATOR . Model::MEDIA_DIR);
+ }
-
- $dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR);
- $sortby = isset($_GET['sortby']) ? $_GET['sortby'] : 'id';
- $order = isset($_GET['order']) ? $_GET['order'] : '1';
- $opt = ['dir' => $dir, 'sortby' => $sortby, 'order' => $order];
-
- if(is_dir($dir)) {
- $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR);
- $faviconlist = $this->mediamanager->getlistermedia(Model::FAVICON_DIR);
+ if(is_dir($mediaopt->dir())) {
+ $medialist = $this->mediamanager->medialistopt($mediaopt);
$dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR);
$pathlist = [];
-
$this->mediamanager->listpath($dirlist, '', $pathlist);
- $this->mediamanager->medialistsort($medialist, $sortby, $order);
- $this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist, 'dirlist' => $dirlist, 'pathlist' =>$pathlist, 'dir' => $dir, 'opt' => $opt]);
+ $this->showtemplate('media', ['medialist' => $medialist, 'dirlist' => $dirlist, 'pathlist' =>$pathlist, 'mediaopt' => $mediaopt]);
} else {
$this->routedirect('media');
}
@@ -68,7 +64,7 @@ class Controllermedia extends Controller
if (!empty($_FILES['file']['name'][0])) {
$this->mediamanager->multiupload('file', $target);
}
- $this->redirect($this->router->generate('media') . '?path=' . $target);
+ $this->redirect($this->router->generate('media') . '?path=/' . $target);
} else {
$this->routedirect('home');
}
@@ -81,7 +77,7 @@ class Controllermedia extends Controller
$name = idclean($_POST['foldername']) ?? 'new-folder';
$this->mediamanager->adddir($dir, $name);
}
- $this->redirect($this->router->generate('media') . '?path=' . $dir . DIRECTORY_SEPARATOR . $name);
+ $this->redirect($this->router->generate('media') . '?path=/' . $dir . DIRECTORY_SEPARATOR . $name);
}
@@ -91,7 +87,7 @@ class Controllermedia extends Controller
if(isset($_POST['deletefolder']) && intval($_POST['deletefolder']) && $this->user->issupereditor()) {
$this->mediamanager->deletedir($_POST['dir']);
} else {
- $this->redirect($this->router->generate('media') . '?path=' . $_POST['dir']);
+ $this->redirect($this->router->generate('media') . '?path=/' . $_POST['dir']);
exit;
}
}
diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php
index e12d76e..75ac6cf 100644
--- a/app/class/Controllerpage.php
+++ b/app/class/Controllerpage.php
@@ -156,6 +156,7 @@ class Controllerpage extends Controller
$filedir = Model::HTML_RENDER_DIR . $id . '.html';
if(file_exists($filedir)) {
$html = file_get_contents($filedir);
+ sleep($this->page->sleep());
echo $html;
} else {
echo 'Please render this page';
@@ -203,9 +204,13 @@ class Controllerpage extends Controller
public function log($id)
{
- $this->setpage($id, 'pagelog');
- $this->importpage();
- var_dump($this->page);
+ if($this->user->issupereditor()) {
+ $this->setpage($id, 'pagelog');
+ $this->importpage();
+ var_dump($this->page);
+ } else {
+ $this->routedirect('pageread/', ['page' => $id]);
+ }
}
public function add($id)
@@ -216,6 +221,7 @@ class Controllerpage extends Controller
if ($this->user->iseditor() && !$this->importpage()) {
$this->page->reset();
+ $this->page->addauthor($this->user->id());
if (!empty(Config::defaultpage())) {
$defaultpage = $this->pagemanager->get(Config::defaultpage());
if ($defaultpage !== false) {
@@ -236,7 +242,7 @@ class Controllerpage extends Controller
public function confirmdelete($id)
{
$this->setpage($id, 'pageconfirmdelete');
- if ($this->user->iseditor() && $this->importpage()) {
+ if ($this->importpage() && ($this->user->issupereditor() || $this->page->authors() === [$this->user->id()] )) {
$this->showtemplate('confirmdelete', ['page' => $this->page, 'pageexist' => true]);
diff --git a/app/class/Medialist.php b/app/class/Medialist.php
index da5ba4f..b208fef 100644
--- a/app/class/Medialist.php
+++ b/app/class/Medialist.php
@@ -7,8 +7,8 @@ class Medialist
/** @var string full regex match */
protected $fullmatch;
- /** @var string options */
- protected $options = '';
+ /** @var string full filter code line */
+ protected $filter = '';
/** @var string directory of media */
protected $path = '';
@@ -19,16 +19,20 @@ class Medialist
/** @var int */
protected $order = 1;
+ /** @var array list of media type to display */
+ protected $type = ['image', 'sound', 'video', 'other'];
+
/** @var int display media contents*/
protected $display = 1;
/** @var int display download links*/
protected $links = 0;
- /** @var string ouput html code generated*/
- protected $content = '';
+ /** @var string display the file name of the file */
+ protected $filename = 0;
- const SORT_BY_OPTIONS = ['id', 'size', 'type'];
+ const SORT_BY_FILTER = ['id', 'size', 'type'];
+ const TYPES = ['image', 'sound', 'video', 'other'];
@@ -39,8 +43,6 @@ class Medialist
public function __construct(array $datas = [])
{
$this->hydrate($datas);
- $this->readoptions();
- $this->generatecontent();
}
public function hydrate($datas)
@@ -54,16 +56,16 @@ class Medialist
}
}
- public function readoptions()
+ public function readfilter()
{
- parse_str($this->options, $datas);
+ parse_str($this->filter, $datas);
$this->hydrate($datas);
}
public function generatecontent()
{
$mediamanager = new Modelmedia();
- $medialist = $mediamanager->getlistermedia(Model::MEDIA_DIR . $this->path . '/');
+ $medialist = $mediamanager->getlistermedia($this->dir(), $this->type);
if (!$medialist) {
$this->content = '<strong>RENDERING ERROR :</strong> path : <code>' . Model::MEDIA_DIR . $this->path . '/</code> does not exist';
return false;
@@ -91,10 +93,50 @@ class Medialist
$div .= '</div>' . PHP_EOL;
- $this->content = $div;
+ return $div;
+ }
+ }
- return true;
+ /**
+ * Generate link adress for table header
+ *
+ * @param string $sortby
+ * @return string link adress
+ */
+ public function getsortbyadress(string $sortby) : string
+ {
+ if(!in_array($sortby, self::SORT_BY_FILTER)) {
+ $sortby = 'id';
}
+ if ($this->sortby === $sortby) {
+ $order = $this->order * -1;
+ } else {
+ $order = $this->order;
+ }
+ $query = ['path' => $this->path, 'sortby' => $sortby, 'order' => $order];
+ if(array_diff( self::TYPES, $this->type) != []) {
+ $query['type'] = $this->type;
+ }
+ return '?' . urldecode(http_build_query($query));
+
+ }
+
+ public function getpathadress(string $path) : string
+ {
+ $query = ['path' => '/' . $path, 'sortby' => $this->sortby, 'order' => $this->order];
+ if(array_diff( self::TYPES, $this->type) != []) {
+ $query['type'] = $this->type;
+ }
+ return '?' . urldecode(http_build_query($query));
+ }
+
+ public function getquery()
+ {
+ $query = ['path' => $this->path, 'sortby' => $this->sortby, 'order' => $this->order];
+ if(array_diff( self::TYPES, $this->type) != []) {
+ $query['type'] = $this->type;
+ }
+ return '%MEDIA?' . urldecode(http_build_query($query)). '%';
}
@@ -106,17 +148,41 @@ class Medialist
return $this->fullmatch;
}
- public function options()
+ public function filter()
{
- return $this->options;
+ return $this->filter;
}
- public function content()
+ /**
+ * @return string formated like `/media/<folder>`
+ */
+ public function path()
{
- return $this->content;
+ return $this->path;
}
+ /**
+ * @return string formated like `media/<folder>/`
+ */
+ public function dir()
+ {
+ return ltrim($this->path, '/') . '/';
+ }
+
+ public function sortby()
+ {
+ return $this->sortby;
+ }
+
+ public function order()
+ {
+ return $this->order;
+ }
+ public function type()
+ {
+ return $this->type;
+ }
// __________________________________________________ S E T ____________________________________________________________
@@ -127,21 +193,25 @@ class Medialist
}
- public function setoptions(string $options)
+ public function setfilter(string $filter)
{
- if (!empty($options)) {
- $this->options = $options;
+ if (!empty($filter)) {
+ $this->filter = $filter;
}
}
public function setpath(string $path)
{
- $this->path = $path;
+ if(preg_match('%^\/' . rtrim(Model::MEDIA_DIR, DIRECTORY_SEPARATOR) . '%', $path)) {
+ $this->path = rtrim($path, DIRECTORY_SEPARATOR);
+ } elseif (!preg_match('%^\/%', $path)) {
+ $this->path = '/' . Model::MEDIA_DIR . rtrim($path, DIRECTORY_SEPARATOR);
+ }
}
public function setsortby(string $sortby)
{
- if (in_array($sortby, self::SORT_BY_OPTIONS)) {
+ if (in_array($sortby, self::SORT_BY_FILTER)) {
$this->sortby = $sortby;
}
}
@@ -152,4 +222,11 @@ class Medialist
$this->order = $order;
}
}
+
+ public function settype($type)
+ {
+ if(is_array($type)) {
+ $this->type = array_intersect(self::TYPES, array_unique($type));
+ }
+ }
}
diff --git a/app/class/Model.php b/app/class/Model.php
index 81ad626..913dc34 100644
--- a/app/class/Model.php
+++ b/app/class/Model.php
@@ -5,14 +5,15 @@ namespace Wcms;
abstract class Model
{
- const CONFIG_FILE = 'config.json';
+ const CONFIG_FILE = 'config.json';
+ const MAN_FILE = 'MANUAL.md';
const CSS_DIR = 'assets' . DIRECTORY_SEPARATOR .'css' . DIRECTORY_SEPARATOR;
const JS_DIR = 'assets' . DIRECTORY_SEPARATOR .'js' . DIRECTORY_SEPARATOR;
const ICONS_DIR = 'assets' . DIRECTORY_SEPARATOR .'icons' . DIRECTORY_SEPARATOR;
const FONT_DIR = 'fonts' . DIRECTORY_SEPARATOR;
const MEDIA_DIR = 'media' . DIRECTORY_SEPARATOR;
- const FAVICON_DIR = 'media' . DIRECTORY_SEPARATOR . 'favicon' . DIRECTORY_SEPARATOR;
- const THUMBNAIL_DIR = 'media' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR;
+ const FAVICON_DIR = self::MEDIA_DIR . 'favicon' . DIRECTORY_SEPARATOR;
+ const THUMBNAIL_DIR = self::MEDIA_DIR . 'thumbnail' . 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 HTML_RENDER_DIR = 'render' . DIRECTORY_SEPARATOR;
diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php
index 6ac647f..d1da829 100644
--- a/app/class/Modelmedia.php
+++ b/app/class/Modelmedia.php
@@ -33,16 +33,23 @@ class Modelmedia extends Model
}
}
+ public function medialistopt(Medialist $mediaopt)
+ {
+ $medialist = $this->getlistermedia($mediaopt->dir(), $mediaopt->type());
+ $this->medialistsort($medialist, $mediaopt->sortby(), $mediaopt->order());
+
+ return $medialist;
+ }
+
/**
* Display a list of media
*
* @param string $path
- * @param string $sortby
- * @param string $order
+ * @param array $type
*
* @return array of Media objects
*/
- public function getlistermedia($dir, $type = "all")
+ public function getlistermedia($dir, $type = Model::MEDIA_TYPES)
{
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
@@ -56,11 +63,7 @@ class Modelmedia extends Model
$media->analyse();
- if (in_array($type, self::MEDIA_TYPES)) {
- if ($media->type() == $type) {
- $list[] = $media;
- }
- } else {
+ if (in_array($media->type(), $type)) {
$list[] = $media;
}
}
@@ -74,22 +77,6 @@ class Modelmedia extends Model
}
-
- public function mediacompare($media1, $media2, $method = 'id', $order = 1)
- {
- $result = ($media1->$method() <=> $media2->$method());
- return $result * $order;
- }
-
- public function buildsorter($sortby, $order)
- {
- return function ($media1, $media2) use ($sortby, $order) {
- $result = $this->mediacompare($media1, $media2, $sortby, $order);
- return $result;
- };
- }
-
-
/**
* Sort an array of media
*
@@ -103,6 +90,21 @@ class Modelmedia extends Model
$order = ($order === 1 || $order === -1) ? $order : 1;
return usort($medialist, $this->buildsorter($sortby, $order));
}
+
+ public function buildsorter($sortby, $order)
+ {
+ return function ($media1, $media2) use ($sortby, $order) {
+ $result = $this->mediacompare($media1, $media2, $sortby, $order);
+ return $result;
+ };
+ }
+
+ public function mediacompare($media1, $media2, $method = 'id', $order = 1)
+ {
+ $result = ($media1->$method() <=> $media2->$method());
+ return $result * $order;
+ }
+
diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php
index 778b327..5a86d0b 100644
--- a/app/class/Modelrender.php
+++ b/app/class/Modelrender.php
@@ -36,6 +36,21 @@ class Modelrender extends Modelpage
}
}
+ /**
+ * Used to convert the markdown user manual to html document
+ *
+ * @param string $text Input text in markdown
+ * @return string html formated text
+ */
+ public function rendermanual(string $text) : string
+ {
+ $text = $this->markdown($text);
+ $text = $this->headerid($text, 5);
+ return $text;
+
+ }
+
+
public function upage($id)
{
return $this->router->generate('pageread/', ['page' => $id]);
@@ -308,7 +323,7 @@ class Modelrender extends Modelpage
$text = $this->headerid($text);
- $text = str_replace(self::SUMMARY, $this->sumparser($text), $text);
+ $text = str_replace(self::SUMMARY, $this->sumparser(), $text);
$text = $this->wurl($text);
$text = $this->wikiurl($text);
@@ -384,11 +399,25 @@ class Modelrender extends Modelpage
return $text;
}
- public function headerid($text)
+ /**
+ * Add Id to hrml header elements and store the titles in the `sum` parameter
+ *
+ * @param string $text Input html document to scan
+ * @param int $maxdeepness Maximum header deepness to look for. Min = 1 Max = 6 Default = 6
+ *
+ * @return string text with id in header
+ */
+
+ public function headerid($text, int $maxdeepness = 6)
{
+ if($maxdeepness > 6 || $maxdeepness < 1) {
+ $maxdeepness = 6;
+ }
+
+
$sum = [];
$text = preg_replace_callback(
- '/<h([1-6])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[1-6]>/mU',
+ '/<h([1-' . $maxdeepness . '])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[1-' . $maxdeepness . ']>/mU',
function ($matches) use (&$sum) {
$cleanid = idclean($matches[4]);
$sum[$cleanid][$matches[1]] = $matches[4];
@@ -437,34 +466,49 @@ class Modelrender extends Modelpage
*/
public function automedialist(string $text)
{
- preg_match_all('~\%MEDIA\?([a-zA-Z0-9\&=\-\/\%]*)\%~', $text, $out);
+ preg_match_all('~\%MEDIA\?([a-zA-Z0-9\[\]\&=\-\/\%]*)\%~', $text, $out);
foreach ($out[0] as $key => $match) {
- $matches[$key] = ['fullmatch' => $match, 'options' => $out[1][$key]];
+ $matches[$key] = ['fullmatch' => $match, 'filter' => $out[1][$key]];
}
if(isset($matches)) {
foreach ($matches as $match) {
$medialist = new Medialist($match);
- $text = str_replace($medialist->fullmatch(), $medialist->content(), $text);
+ $medialist->readfilter();
+ $text = str_replace($medialist->fullmatch(), $medialist->generatecontent(), $text);
}
}
return $text;
}
-
- function sumparser($text)
+ /**
+ * Generate a Summary based on header ids. Need to use `$this->headerid` before to scan text
+ *
+ * @param int $min Minimum header deepness to start the summary : Between 1 and 6.
+ * @param int $max Maximum header deepness to start the summary : Between 1 and 6.
+ *
+ * @return string html list with anchor link
+ */
+ function sumparser(int $min = 1, int $max = 6) : string
{
- preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#iU', $text, $out);
-
+ $min = $min >= 1 && $min <= 6 && $min <= $max ? $min : 1;
+ $end = $max >=1 && $max <= 6 && $max >= $min ? $max : 6;
$sum = $this->sum;
+ $filteredsum = [];
+ foreach ($sum as $key => $menu) {
+ $deepness = array_keys($menu)[0];
+ if($deepness >= $min && $deepness <= $max) {
+ $filteredsum[$key] = $menu;
+ }
+ }
$sumstring = '';
$last = 0;
- foreach ($sum as $title => $list) {
+ foreach ($filteredsum as $title => $list) {
foreach ($list as $h => $link) {
if ($h > $last) {
for ($i = 1; $i <= ($h - $last); $i++) {
@@ -633,7 +677,7 @@ class Modelrender extends Modelpage
$optlist->parsehydrate($match['options']);
$table2 = $modelhome->table2($this->pagelist, $optlist);
- $content = '<ul>' . PHP_EOL ;
+ $content = '<ul class="pagelist">' . PHP_EOL ;
foreach ($table2 as $page ) {
$content .= '<li>' . PHP_EOL;
$content .= '<a href="' . $this->upage($page->id()) . '">' . $page->title() . '</a>' . PHP_EOL;
diff --git a/app/class/Page.php b/app/class/Page.php
index 41cf0ab..170a057 100644
--- a/app/class/Page.php
+++ b/app/class/Page.php
@@ -43,6 +43,7 @@ class Page
protected $visitcount;
protected $editcount;
protected $editby;
+ protected $sleep;
const LEN = 255;
@@ -112,6 +113,7 @@ class Page
$this->setvisitcount(0);
$this->seteditcount(0);
$this->seteditby([]);
+ $this->setsleep(0);
}
public static function classvarlist()
@@ -454,6 +456,11 @@ class Page
return $this->editby;
}
+ public function sleep($type = 'int')
+ {
+ return $this->sleep;
+ }
+
@@ -819,6 +826,15 @@ class Page
return count($this->editby) > 0;
}
+ public function setsleep($sleep)
+ {
+ $sleep = abs(intval($sleep));
+ if($sleep > 180) {
+ $sleep = 180;
+ }
+ $this->sleep = $sleep;
+ }
+
/**
* Merge new tag with actual tags
*