aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-12-10 01:40:01 +0100
committervincent-peugnet <v.peugnet@free.fr>2018-12-10 01:40:01 +0100
commit7cafbbb9d9ec14462fe8ce0eda86c42d22367757 (patch)
treec950cf870066817bec50bbacfebaa74f436ed96a
parentc8da7fe9adbf096e7d8131439064e9be2df58ac4 (diff)
downloadwcms-7cafbbb9d9ec14462fe8ce0eda86c42d22367757.tar.gz
wcms-7cafbbb9d9ec14462fe8ce0eda86c42d22367757.zip
media-upload
-rw-r--r--app/class/controllermedia.php33
-rw-r--r--app/class/modelmedia.php25
-rw-r--r--app/class/routes.php2
-rw-r--r--app/view/templates/media.php77
-rw-r--r--assets/css/home.css20
5 files changed, 127 insertions, 30 deletions
diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php
index 1fa564b..26b58ff 100644
--- a/app/class/controllermedia.php
+++ b/app/class/controllermedia.php
@@ -2,7 +2,6 @@
class Controllermedia extends Controller
{
- protected $medialist;
protected $mediamanager;
public function __construct($render) {
@@ -15,9 +14,14 @@ class Controllermedia extends Controller
public function desktop()
{
if($this->user->iseditor()) {
- $medialist = $this->mediamanager->getlistermedia(Model::MEDIA_DIR);
+ $dir = $_GET['path'] ?? Model::MEDIA_DIR;
+
+ $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR);
$faviconlist = $this->mediamanager->getlistermedia(Model::FAVICON_DIR);
- $this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist]);
+
+ $dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR);
+
+ $this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist, 'dirlist' => $dirlist, 'dir' => $dir]);
}
}
@@ -29,6 +33,29 @@ class Controllermedia extends Controller
}
+ public function upload()
+ {
+ $target = $_POST['dir'] ?? Model::MEDIA_DIR;
+ if($target[strlen($target)-1]!='/')
+ $target=$target.'/';
+ $count=0;
+ foreach ($_FILES['file']['name'] as $filename)
+ {
+ $fileinfo = pathinfo($filename);
+ $extension = idclean($fileinfo['extension']);
+ $id = idclean($fileinfo['filename']);
+
+ $temp=$target;
+ $tmp=$_FILES['file']['tmp_name'][$count];
+ $count=$count + 1;
+ $temp .= $id .'.' .$extension;
+ move_uploaded_file($tmp,$temp);
+ $temp='';
+ $tmp='';
+ }
+ $this->redirect($this->router->generate('media').'?path='.$target);
+ }
+
}
diff --git a/app/class/modelmedia.php b/app/class/modelmedia.php
index 3402a04..89c253f 100644
--- a/app/class/modelmedia.php
+++ b/app/class/modelmedia.php
@@ -105,7 +105,32 @@ class Modelmedia extends Model
}
+ public function listdir($dir)
+ {
+
+ $result = array();
+
+ $cdir = scandir($dir);
+ $result['dirfilecount'] = 0;
+ foreach ($cdir as $key => $value)
+ {
+ if (!in_array($value,array(".","..")))
+ {
+ if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
+ {
+ $result[$value] = $this->listdir($dir . DIRECTORY_SEPARATOR . $value);
+ }
+ else
+ {
+ $result['dirfilecount'] ++;
+ }
+ }
+ }
+
+ return $result;
+
+ }
}
diff --git a/app/class/routes.php b/app/class/routes.php
index b324e64..4763887 100644
--- a/app/class/routes.php
+++ b/app/class/routes.php
@@ -19,6 +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'],
['GET', '/!font', 'Controllerfont#desktop', 'font'],
['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'],
['GET', '/!admin', 'Controlleradmin#desktop', 'admin'],
diff --git a/app/view/templates/media.php b/app/view/templates/media.php
index 043000d..6bcba5d 100644
--- a/app/view/templates/media.php
+++ b/app/view/templates/media.php
@@ -10,47 +10,72 @@
<section class="media">
-<h1>Media</h1>
+<h1>Explorer</h1>
-<table id="medialist">
-<tr><th>id</th><th>extension</th><th>path</th><th>type</th><th>size</th><th>width</th><th>height</th><th>lengh</th></tr>
+
+<table id="dirlsit">
+<tr><th>folder</th><th>files</th></tr>
<?php
-foreach ($medialist as $media) {
- ?>
- <tr>
- <td><?= $media->id() ?></td>
- <td><?= $media->extension() ?></td>
- <td><?= $media->path() ?></td>
- <td><?= $media->type() ?></td>
- <td><?= readablesize($media->size()) ?></td>
- <td><?= $media->width() ?></td>
- <td><?= $media->height() ?></td>
- <td><?= $media->length() ?></td>
- </tr>
- <?php
+
+function treecount(array $dir, string $dirname, int $deepness, string $path, string $currentdir) {
+ if($path === $currentdir) {
+ $folder = '├─📂<strong>'. $dirname.'<strong>';
+ } else {
+ $folder = '├─📁'. $dirname;
+ }
+ echo '<tr>';
+ echo '<td><a href="?path='.$path.'">'. str_repeat(' ‎ ‎', $deepness) .$folder.'</a></td>';
+ echo '<td>'.$dir['dirfilecount'].'</td>';
+ echo '</tr>';
+ foreach ($dir as $key => $value) {
+ if(is_array($value)) {
+ treecount($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir);
+ }
+ }
}
+treecount($dirlist, 'media', 0, 'media', $dir);
?>
+
+
</table>
-<h1>Favicon</h1>
+<h2><?= $dir ?></h2>
+
+<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="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 files</label>
+ <input type='file' id="file" name='file[]' multiple>
+ <input type="hidden" name="dir" value="<?= $dir ?>">
+ <input type="submit" value="upload">
+</form>
+
-<table id="faviconlist">
-<tr><th>id</th><th>extension</th><th>path</th><th>size</th><th>width</th><th>height</th></tr>
+
+<table id="medialist">
+<tr><th>id</th><th>ext</th><th>type</th><th>size</th><th>width</th><th>height</th><th>lengh</th></tr>
<?php
-foreach ($faviconlist as $favicon) {
+foreach ($medialist as $media) {
?>
<tr>
- <td><?= $favicon->id() ?></td>
- <td><?= $favicon->extension() ?></td>
- <td><?= $favicon->path() ?></td>
- <td><?= readablesize($favicon->size()) ?></td>
- <td><?= $favicon->width() ?></td>
- <td><?= $favicon->height() ?></td>
+ <td><a href="<?= $media->getfullpath() ?>" target="_blank"><?= $media->id() ?></a></td>
+ <td><?= $media->extension() ?></td>
+
+ <td><?= $media->type() == 'image' ? 'image <span class="thumbnail">👁<img src="'.$media->getfullpath().'"></span>' : $media->type() ?></td>
+ <td><?= readablesize($media->size()) ?></td>
+ <td><?= $media->width() ?></td>
+ <td><?= $media->height() ?></td>
+ <td><?= $media->length() ?></td>
</tr>
<?php
}
diff --git a/assets/css/home.css b/assets/css/home.css
index 61fb100..3c1f31b 100644
--- a/assets/css/home.css
+++ b/assets/css/home.css
@@ -197,6 +197,24 @@ section.info article code i {
}
+section.media table#medialist img {
+ display: none;
+ position: absolute;
+ max-width: 400px;
+ max-height: 200px;
+ margin-left: 80px;
+ background-color: white;
+ padding: 1%;
+}
+
+section.media table#medialist .thumbnail:hover img {
+ display: block;
+}
+
+
+section.media form {
+ margin: 1%;
+}
@media (max-width: 600px) {
section.home .summary, section.home .linkfrom, section.home .linkto, section.home .delete, section.home .datecreation, section.home .date, section.home .log, section.home .secure, section.home .tag {
@@ -207,4 +225,4 @@ section.info article code i {
position: relative;
}
-} \ No newline at end of file
+}