diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-12-17 15:34:20 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-12-17 15:34:20 +0100 |
commit | 1a7a60ea3efde53ac2c3b07ca914483cfc25a827 (patch) | |
tree | ac1f09d4d041c19501dd211df451d8d35ef55c47 | |
parent | 300cf1cc8399d29f61052c0ad09ba1cca2d04d4d (diff) | |
download | wcms-1a7a60ea3efde53ac2c3b07ca914483cfc25a827.tar.gz wcms-1a7a60ea3efde53ac2c3b07ca914483cfc25a827.zip |
media
-rw-r--r-- | app/class/controllermedia.php | 41 | ||||
-rw-r--r-- | app/class/modelart.php | 14 | ||||
-rw-r--r-- | app/class/modelmedia.php | 51 | ||||
-rw-r--r-- | app/class/modelrender.php | 28 | ||||
-rw-r--r-- | app/class/routes.php | 4 | ||||
-rw-r--r-- | app/view/templates/info.php | 2 | ||||
-rw-r--r-- | app/view/templates/media.php | 8 | ||||
-rw-r--r-- | assets/global/global.css | 7 |
8 files changed, 92 insertions, 63 deletions
diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php index f156b35..4421f65 100644 --- a/app/class/controllermedia.php +++ b/app/class/controllermedia.php @@ -2,18 +2,31 @@ class Controllermedia extends Controller { + /** + * @var Modelmedia + */ protected $mediamanager; - public function __construct($render) { + public function __construct($render) + { parent::__construct($render); - + $this->mediamanager = new Modelmedia; } public function desktop() { - if($this->user->iseditor()) { + if ($this->user->iseditor()) { + + if (!$this->mediamanager->basedircheck()) { + throw new Exception("Error : Cant create /media folder"); + } + if (!$this->mediamanager->favicondircheck()) { + throw new Exception("Error : Cant create /media/favicon folder"); + } + + $dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR); $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR); @@ -29,16 +42,28 @@ class Controllermedia extends Controller public function upload() { - if($this->user->iseditor()) { - $target = $_POST['dir'] ?? Model::MEDIA_DIR; - - $this->mediamanager->upload($target); - $this->redirect($this->router->generate('media').'?path='.$target); + if ($this->user->iseditor()) { + $target = $_POST['dir'] ?? Model::MEDIA_DIR; + if (!empty($_FILES['file']['name'][0])) { + $this->mediamanager->upload($target); + } + $this->redirect($this->router->generate('media') . '?path=' . $target); } else { $this->routedirect('home'); } } + public function folder() + { + if ($this->user->iseditor()) { + $dir = $_POST['dir'] ?? Model::MEDIA_DIR; + $name = $_POST['foldername'] ?? 'new folder'; + $this->mediamanager->adddir($dir, $name); + } + $this->redirect($this->router->generate('media') . '?path=' . $dir . DIRECTORY_SEPARATOR . $name); + + } + } diff --git a/app/class/modelart.php b/app/class/modelart.php index e8203e1..ac4f91e 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -12,20 +12,6 @@ class Modelart extends Modeldb parent::__construct(); } - - - public function exist(Art2 $art) - { - $artdata = $this->artstore->get($art->id()); - if ($artdata === false) { - return false; - } else { - return true; - } - - } - - public function add(Art2 $art) { diff --git a/app/class/modelmedia.php b/app/class/modelmedia.php index 5706c26..6fbcece 100644 --- a/app/class/modelmedia.php +++ b/app/class/modelmedia.php @@ -3,38 +3,24 @@ class Modelmedia extends Model { - public function addmedia(array $file, $maxsize = 2 ** 24, $id) - { - $message = 'runing'; - $id = strtolower(strip_tags($id)); - $id = str_replace(' ', '_', $id); - if (isset($file) and $file['media']['error'] == 0 and $file['media']['size'] < $maxsize) { - $infosfichier = pathinfo($file['media']['name']); - $extension_upload = $infosfichier['extension']; - $extensions_autorisees = $this::MEDIA_EXTENSIONS; - if (in_array($extension_upload, $extensions_autorisees)) { - if (!file_exists($this::MEDIA_DIR . $id . '.' . $extension_upload)) { - - $extension_upload = strtolower($extension_upload); - $uploadok = move_uploaded_file($file['media']['tmp_name'], $this::MEDIA_DIR . $id . '.' . $extension_upload); - if ($uploadok) { - $message = 'uploadok'; - } else { - $message = 'uploaderror'; - } - } else { - $message = 'filealreadyexist'; - } - } + public function basedircheck() + { + if(!is_dir(Model::MEDIA_DIR)) { + return mkdir(Model::MEDIA_DIR); } else { - $message = 'filetoobig'; - + return true; } - - return $message; } + public function favicondircheck() + { + if(!is_dir(Model::FAVICON_DIR)) { + return mkdir(Model::FAVICON_DIR); + } else { + return true; + } + } public function getmedia($entry, $dir) { @@ -153,6 +139,17 @@ class Modelmedia extends Model } } + public function adddir($dir, $name) + { + $name = idclean($name); + $newdir = $dir . DIRECTORY_SEPARATOR . $name; + if(!is_dir($newdir)) { + return mkdir($newdir); + } else { + return false; + } + } + } diff --git a/app/class/modelrender.php b/app/class/modelrender.php index dba363b..e24e067 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -99,6 +99,7 @@ class Modelrender extends Modelart $element = $this->article($element); $element = $this->automedialist($element); $element = $this->autotaglistupdate($element); + $element = $this->date($element); $element = $this->markdown($element); return $element; @@ -152,6 +153,13 @@ class Modelrender extends Modelart $head .= '<link href="'.$externalcss.'" rel="stylesheet" />' . PHP_EOL; } + if (!empty($this->art->templatecss() && in_array('externalcss', $this->art->templateoptions()))) { + $templatecss = $this->get($this->art->templatecss()); + foreach ($templatecss->externalcss() as $externalcss) { + $head .= '<link href="'.$externalcss.'" rel="stylesheet" />' . PHP_EOL; + } + } + foreach ($this->art->externalscript() as $externalscript) { $head .= '<script src="'.$externalscript.'"></script>' . PHP_EOL; } @@ -394,7 +402,7 @@ class Modelrender extends Modelart public function autotaglist($text) { - $pattern = "/%%(\w*)%%/"; + $pattern = "/\%TAG:([a-z0-9_-]+)\%/"; preg_match_all($pattern, $text, $out); return $out[1]; @@ -424,7 +432,7 @@ class Modelrender extends Modelart $ul .= '</ul>' . PHP_EOL; - $text = str_replace('%%' . $tag . '%%', $ul, $text); + $text = str_replace('%TAG:' . $tag . '%', $ul, $text); $li = array_map(function ($item) { return $item->id(); @@ -434,6 +442,22 @@ class Modelrender extends Modelart return $text; } + + public function date(string $text) + { + $art = $this->art; + $text = preg_replace_callback('~\%DATE\%~', function($matches) use ($art) { + return '<time datetime='.$art->date('string').'>'.$art->date('dmy').'</time>'; + }, $text); + $text = preg_replace_callback('~\%TIME\%~', function($matches) use ($art) { + return '<time datetime='.$art->date('string').'>'.$art->date('ptime').'</time>'; + }, $text); + + return $text; + } + + + public function linkfrom() { sort($this->linkfrom); diff --git a/app/class/routes.php b/app/class/routes.php index 4763887..c222445 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -19,8 +19,8 @@ class Routes ['GET', '/!co', 'Controllerconnect#connect', 'connect'], ['POST', '/!search', 'Controllerhome#search', 'search'], ['GET', '/!media', 'Controllermedia#desktop', 'media'], - ['POST', '/!media', 'Controllermedia#upload', 'mediaupload'], - ['POST', '/!media', 'Controllermedia#folder', 'mediafolder'], + ['POST', '/!media/upload', 'Controllermedia#upload', 'mediaupload'], + ['POST', '/!media/folder', 'Controllermedia#folder', 'mediafolder'], ['GET', '/!font', 'Controllerfont#desktop', 'font'], ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'], ['GET', '/!admin', 'Controlleradmin#desktop', 'admin'], diff --git a/app/view/templates/info.php b/app/view/templates/info.php index 4da3819..d86bdc1 100644 --- a/app/view/templates/info.php +++ b/app/view/templates/info.php @@ -203,7 +203,7 @@ You can use any of them, only one or all at the same time, as you prefer. <p>You can create a html list of links pointing to all the pages using this tag.</p> <blockquote> - %%<i>tag</i>%% + %TAG:<i>__tag__</i>% </blockquote> <p>Let's suppose we are in page3 and we have page2, page3, page5, using this tag, this will output :</p> diff --git a/app/view/templates/media.php b/app/view/templates/media.php index 706a160..613efd1 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -53,16 +53,18 @@ treecount($dirlist, 'media', 0, 'media', $dir); <h2><?= $dir ?></h2> +Print the whole content of the folder using this code : <span><code>%MEDIA:<?= str_replace('\\', '/', substr($dir, strlen(Model::MEDIA_DIR))) ?>%</code></span> + <form id="addfolder" action="<?= $this->url('mediafolder') ?>" method="post"> <label for="foldername">📂 New folder</label> - <input type="text" name="foldername" id="foldername" placeholder="folder name" > + <input type="text" name="foldername" id="foldername" placeholder="folder name" required> <input type="hidden" name="dir" value="<?= $dir ?>"> <input type="submit" value="create folder"> </form> <form id=addmedia action="<?= $this->url('mediaupload') ?>" method="post" enctype="multipart/form-data"> <label for="file">🚀 Upload file(s)</label> - <input type='file' id="file" name='file[]' multiple> + <input type='file' id="file" name='file[]' multiple required> <input type="hidden" name="dir" value="<?= $dir ?>"> <input type="submit" value="upload"> </form> @@ -91,7 +93,7 @@ foreach ($medialist as $media) { <?php } elseif ($media->type() == 'other') { ?> - [<?= $media->id() ?>.<?= $media->extension() ?>](<?= $media->getincludepath() ?>) + [<?= $media->id() ?>](<?= $media->getincludepath() ?>) <?php } else { echo $media->getincludepath(); diff --git a/assets/global/global.css b/assets/global/global.css index 42b91c5..072a9ed 100644 --- a/assets/global/global.css +++ b/assets/global/global.css @@ -8,12 +8,7 @@ a.external::before { } ul.medialist { - max-width: 400px; - width: 100%; + list-style: none; padding: 0; } - -.medialist img { - width: 100%; -}
\ No newline at end of file |