diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Controller.php | 1 | ||||
-rw-r--r-- | app/class/Controllermedia.php | 30 | ||||
-rw-r--r-- | app/class/Media.php | 6 | ||||
-rw-r--r-- | app/class/Modelmedia.php | 17 | ||||
-rw-r--r-- | app/class/Routes.php | 1 | ||||
-rw-r--r-- | app/fn/fn.php | 3 | ||||
-rw-r--r-- | app/view/templates/media.php | 19 | ||||
-rw-r--r-- | app/view/templates/mediamenu.php | 1 |
8 files changed, 72 insertions, 6 deletions
diff --git a/app/class/Controller.php b/app/class/Controller.php index 56d4dfe..11a2c12 100644 --- a/app/class/Controller.php +++ b/app/class/Controller.php @@ -111,6 +111,7 @@ class Controller public function redirect($url) { header('Location: ' . $url); + exit; } public function routedirect(string $route, array $vars = []) diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php index c6e5d6c..0d75de7 100644 --- a/app/class/Controllermedia.php +++ b/app/class/Controllermedia.php @@ -3,6 +3,7 @@ namespace Wcms; use Exception; +use InvalidArgumentException; use LogicException; class Controllermedia extends Controller @@ -116,6 +117,33 @@ class Controllermedia extends Controller $this->mediamanager->multimovefile($_POST['id'], $_POST['dir']); } } - $this->redirect($this->generate('media') . '?path=/' . $_POST['path']); + $this->redirect($this->generate('media') . $_POST['route']); + } + + public function rename() + { + if ( + $this->user->issupereditor() + && isset($_POST['oldid']) + && isset($_POST['newid']) + && isset($_POST['oldextension']) + && isset($_POST['newextension']) + && isset($_POST['path']) + ) { + $newid = idclean($_POST['newid']); + $newextension = idclean($_POST['newextension']); + if (!empty($newid) && !empty($newextension)) { + $oldname = $_POST['path'] . $_POST['oldid'] . '.' . $_POST['oldextension']; + $newname = $_POST['path'] . $newid . '.' . $newextension; + try { + $this->mediamanager->rename($oldname, $newname); + } catch (InvalidArgumentException $e) { + Model::sendflashmessage($e->getMessage(), 'error'); + } + } else { + Model::sendflashmessage('Invalid name or extension', 'warning'); + } + } + $this->redirect($this->generate('media') . $_POST['route']); } } diff --git a/app/class/Media.php b/app/class/Media.php index 7105830..099d4f8 100644 --- a/app/class/Media.php +++ b/app/class/Media.php @@ -97,14 +97,14 @@ class Media extends Item break; case 'sound': - $code = '<audio controls src="' . $this->getincludepath() . '"></audio>'; + $code = '<audio controls src="' . $this->getincludepath() . '"></audio>'; break; case 'video': $src = $this->getincludepath(); $ext = $this->extension; - $code = '<video controls="">'; - $code .= '<source src="' . $src . '" type="video/' . $ext . '"></video>'; + $code = '<video controls="">'; + $code .= '<source src="' . $src . '" type="video/' . $ext . '"></video>'; break; default: diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php index 0b1d700..4da7707 100644 --- a/app/class/Modelmedia.php +++ b/app/class/Modelmedia.php @@ -2,6 +2,8 @@ namespace Wcms; +use Exception; +use InvalidArgumentException; use phpDocumentor\Reflection\Types\Mixed_; class Modelmedia extends Model @@ -364,4 +366,19 @@ class Modelmedia extends Model return true; } } + + /** + * @param string $oldname + * @param string $newname + * @throws InvalidArgumentException if cant access file + */ + public function rename(string $oldname, string $newname) + { + try { + accessfile($oldname); + } catch (InvalidArgumentException $e) { + throw new InvalidArgumentException($e->getMessage()); + } + return rename($oldname, $newname); + } } diff --git a/app/class/Routes.php b/app/class/Routes.php index 59659ea..13bd2ac 100644 --- a/app/class/Routes.php +++ b/app/class/Routes.php @@ -35,6 +35,7 @@ class Routes ['POST', '/!media/folderadd', 'Controllermedia#folderadd', 'mediafolderadd'], ['POST', '/!media/folderdelete', 'Controllermedia#folderdelete', 'mediafolderdelete'], ['POST', '/!media/edit', 'Controllermedia#edit', 'mediaedit'], + ['POST', '/!media/rename', 'Controllermedia#rename', 'mediarename'], ['GET', '/!font', 'Controllerfont#desktop', 'font'], ['GET', '/!font/render', 'Controllerfont#render', 'fontrender'], ['POST', '/!font/add', 'Controllerfont#add', 'fontadd'], diff --git a/app/fn/fn.php b/app/fn/fn.php index 103062a..461f129 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -425,6 +425,9 @@ function accessfile(string $path, bool $createdir = false): bool if (!is_writable($dir)) { throw new \InvalidArgumentException("Directory '$dir' is not writable."); } + if (!file_exists($path)) { + throw new \InvalidArgumentException("The file '$path' does not exist."); + } if (is_file($path) && !is_writable($path)) { throw new \InvalidArgumentException("The file '$path' is not writable."); } diff --git a/app/view/templates/media.php b/app/view/templates/media.php index 960ff33..d0caaf2 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -95,7 +95,7 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' <input type="checkbox" name="id[]" value="<?= $media->getfulldir() ?>" form="mediaedit" id="media_<?= $media->id() ?>"> <label for="media_<?= $media->id() ?>"><?= $media->id() ?></label> <a href="<?= $media->getfullpath() ?>" target="_blank">⧉</a> - <code><?= $media->getcode() ?></code> + <input readonly class="code select-all" value="<?= $media->getcode() ?>" /> </div> </li> @@ -130,7 +130,22 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' ?> <tr> <td><input type="checkbox" name="id[]" value="<?= $media->getfulldir() ?>" form="mediaedit" id="media_<?= $media->id() ?>"></td> - <td><label for="media_<?= $media->id() ?>"><?= $media->id() ?></label></td> + <td> + <details> + <summary> + <label for="newid"><?= $media->id() ?></label> + </summary> + <form action="<?= $this->url('mediarename') ?>" method="post"> + <input type="hidden" name="route" value="<?= $mediaopt->getadress() ?>"> + <input type="hidden" name="path" value="<?= $media->path() ?>"> + <input type="hidden" name="oldid" value="<?= $media->id() ?>"> + <input type="hidden" name="oldextension" value="<?= $media->extension() ?>"> + <input type="text" name="newid" value="<?= $media->id() ?>" id="newid" maxlength="<?= Wcms\Model::MAX_ID_LENGTH ?>"> + <input type="text" name="newextension" value="<?= $media->extension() ?>" id="" style="width: 30px" maxlength="16"> + <input type="submit" value="rename"> + </form> + </details> + </td> <td><?= $media->extension() ?></td> <td class="nowrap"><a href="<?= $media->getfullpath() ?>" target="_blank"><?= $media->type() == 'image' ? '<span class="thumbnail">' . $media->getsymbol() . '<img src="' . $media->getfullpath() . '"></span>' : $media->getsymbol() ?></a></td> <td class="nowrap"><?= $media->size('hr') ?></td> diff --git a/app/view/templates/mediamenu.php b/app/view/templates/mediamenu.php index b64bd25..f79b2bc 100644 --- a/app/view/templates/mediamenu.php +++ b/app/view/templates/mediamenu.php @@ -39,6 +39,7 @@ <h2>Move</h2> <form action="<?= $this->url('mediaedit') ?>" method="post" id="mediaedit"> + <input type="hidden" name="route" value="<?= $mediaopt->getadress() ?>"> <input type="hidden" name="path" value="<?= $mediaopt->dir() ?>"> <label for="moveto">Move selected medias to a new directory</label> </br> |