diff options
-rw-r--r-- | app/class/controllermedia.php | 35 | ||||
-rw-r--r-- | app/class/media.php | 12 | ||||
-rw-r--r-- | app/class/modelmedia.php | 21 | ||||
-rw-r--r-- | app/class/modelrender.php | 12 | ||||
-rw-r--r-- | app/view/templates/info.php | 4 | ||||
-rw-r--r-- | app/view/templates/media.php | 47 | ||||
-rw-r--r-- | assets/css/home.css | 13 |
7 files changed, 99 insertions, 45 deletions
diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php index 26b58ff..f156b35 100644 --- a/app/class/controllermedia.php +++ b/app/class/controllermedia.php @@ -14,7 +14,7 @@ class Controllermedia extends Controller public function desktop() { if($this->user->iseditor()) { - $dir = $_GET['path'] ?? Model::MEDIA_DIR; + $dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR); $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR); $faviconlist = $this->mediamanager->getlistermedia(Model::FAVICON_DIR); @@ -22,38 +22,21 @@ class Controllermedia extends Controller $dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR); $this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist, 'dirlist' => $dirlist, 'dir' => $dir]); + } else { + $this->routedirect('home'); } } - public function addmedia() - { - echo $this->templates->render('media', ['interface' => 'addmedia']); - - //$message = $this->mediamanager->addmedia($_FILES, 2 ** 24, $_POST['id']); - - } - public function upload() { + if($this->user->iseditor()) { $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->mediamanager->upload($target); $this->redirect($this->router->generate('media').'?path='.$target); + } else { + $this->routedirect('home'); + } } diff --git a/app/class/media.php b/app/class/media.php index 0cbbd89..01dfd55 100644 --- a/app/class/media.php +++ b/app/class/media.php @@ -56,7 +56,17 @@ class Media public function getfullpath() { - return '/' . Config::basepath() . '/' . $this->path() . $this->id() . '.' . $this->extension(); + $fullpath = '/' . Config::basepath() . '/'. $this->path() . $this->id() . '.' . $this->extension(); + $fullpath = str_replace('\\', '/', $fullpath); + return $fullpath; + } + + public function getincludepath() + { + $includepath = $this->path() . $this->id() . '.' . $this->extension(); + $includepath = str_replace('\\', '/', $includepath); + $includepath = substr($includepath, 6); + return $includepath; } diff --git a/app/class/modelmedia.php b/app/class/modelmedia.php index 89c253f..5706c26 100644 --- a/app/class/modelmedia.php +++ b/app/class/modelmedia.php @@ -132,6 +132,27 @@ class Modelmedia extends Model } + public function upload(string $target) + { + if($target[strlen($target)-1] != DIRECTORY_SEPARATOR) + $target .= DIRECTORY_SEPARATOR; + $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=''; + } + } + } diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 7ef7e45..c76fa69 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -322,13 +322,13 @@ class Modelrender extends Modelart foreach ($medialist as $media) { $ul .= '<li>'; if($media->type() == 'image') { - $ul .= '<img alt="'.$media->id().'" id="'.$media->id().'" src="'.$media->getfullpath().'" >'; + $ul .= '<img alt="'.$media->id().'" id="'.$media->id().'" src="'.$media->getincludepath().'" >'; } elseif ($media->type() == 'sound') { - $ul .= '<audio id="'.$media->id().'" controls src="'.$media->getfullpath().'" </audio>'; + $ul .= '<audio id="'.$media->id().'" controls src="'.$media->getincludepath().'" </audio>'; } elseif ($media->type() == 'video') { - $ul .= '<video controls><source src="'.$media->getfullpath().'" type="video/'.$media->extension().'"></video>'; + $ul .= '<video controls><source src="'.$media->getincludepath().'" type="video/'.$media->extension().'"></video>'; } elseif ($media->type() == 'other') { - $ul .= '<a href="'.$media->getfullpath().'" target="_blank" class="media" >'.$media->id().'.'.$media->extension().'</a>'; + $ul .= '<a href="'.$media->getincludepath().'" target="_blank" class="media" >'.$media->id().'.'.$media->extension().'</a>'; } $ul .= '</li>' . PHP_EOL; } @@ -337,7 +337,7 @@ class Modelrender extends Modelart return $ul; } else { - return 'directory not founded'; + return 'directory "'.$dir.'" not found'; } }, $text); @@ -402,7 +402,7 @@ class Modelrender extends Modelart } } - $ul = '<ul id="' . $tag . '">' . PHP_EOL; + $ul = '<ul class="taglist" id="' . $tag . '">' . PHP_EOL; $this->artlistsort($li, 'date', -1); foreach ($li as $item) { if ($item->id() === $this->art->id()) { diff --git a/app/view/templates/info.php b/app/view/templates/info.php index f9144ca..4634995 100644 --- a/app/view/templates/info.php +++ b/app/view/templates/info.php @@ -69,9 +69,11 @@ <p>There is'nt a real start of anything when you're using W.</p> +<p>Just type an adress in your web browser, after your W folder. You should see an empty page, not existing yet. You can login to create one at this adress. If you are already logged in, you can juste type <code><i>page_id</i>/add</code>, this will directly create a page at this adress.</p> +<p>This <code><i>page_id</i></code> is the identifier of each page, you cant change it later, this is like a real solid adress, it cant move. It can only contain lowercase letters, numbers, hyphens or underscore charachters.</p> - +<p>No visitor can see the full list of pages you've created. The only way to see the whole map of your project, is to be conected at least as an editor, and go to the "homepage", the root adress where W is instaled.</p> <h3 id="structure">Structure</h3> diff --git a/app/view/templates/media.php b/app/view/templates/media.php index 6bcba5d..2078d79 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -10,6 +10,8 @@ <section class="media"> + +<div id="tree"> <h1>Explorer</h1> @@ -18,18 +20,19 @@ <?php -function treecount(array $dir, string $dirname, int $deepness, string $path, string $currentdir) { - if($path === $currentdir) { - $folder = '├─📂<strong>'. $dirname.'<strong>'; +function treecount(array $dir, string $dirname, int $deepness, string $path, string $currentdir) +{ + if ($path === $currentdir) { + $folder = '├─📂<strong>' . $dirname . '<strong>'; } else { - $folder = '├─📁'. $dirname; + $folder = '├─📁' . $dirname; } echo '<tr>'; - echo '<td><a href="?path='.$path.'">'. str_repeat(' ', $deepness) .$folder.'</a></td>'; - echo '<td>'.$dir['dirfilecount'].'</td>'; + 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)) { + if (is_array($value)) { treecount($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir); } } @@ -42,6 +45,11 @@ treecount($dirlist, 'media', 0, 'media', $dir); </table> +</div> + + +<div id="explorer"> + <h2><?= $dir ?></h2> @@ -53,7 +61,7 @@ treecount($dirlist, 'media', 0, 'media', $dir); </form> <form id=addmedia action="<?= $this->url('mediaupload') ?>" method="post" enctype="multipart/form-data"> - <label for="file">🚀 Upload files</label> + <label for="file">🚀 Upload file(s)</label> <input type='file' id="file" name='file[]' multiple> <input type="hidden" name="dir" value="<?= $dir ?>"> <input type="submit" value="upload"> @@ -62,7 +70,7 @@ treecount($dirlist, 'media', 0, 'media', $dir); <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> +<tr><th>id</th><th>ext</th><th>type</th><th>size</th><th>width</th><th>height</th><th>lengh</th><th>code</th></tr> <?php foreach ($medialist as $media) { @@ -70,14 +78,29 @@ foreach ($medialist as $media) { <tr> <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><?= $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> + <td><code> + <?php + if($media->type() == 'image') { + ?> +  ?>) + <?php + } elseif ($media->type() == 'other') { + ?> + [<?= $media->id() ?>.<?= $media->extension() ?>](<?= $media->getincludepath() ?>) + <?php + } else { + echo $media->getincludepath(); + } + ?> + </code></td> </tr> <?php + } @@ -85,6 +108,8 @@ foreach ($medialist as $media) { </table> +</div> + </section> </body> diff --git a/assets/css/home.css b/assets/css/home.css index 3c1f31b..3ee6a17 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -216,6 +216,17 @@ section.media form { margin: 1%; } +section.media div#tree, section.media div#explorer { + display: inline-grid; +} + +section.media code { + color: #9cbfe8; + background-color: darkslategrey; + font-size: small; + padding: 1px; +} + @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 { display: none; @@ -226,3 +237,5 @@ section.media form { } } + + |