Skip to content

Commit

Permalink
keep filters and sorting when doing media actions close #374
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-peugnet committed Sep 30, 2024
1 parent 444e35b commit 6b744d4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
53 changes: 31 additions & 22 deletions app/class/Controllermedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ class Controllermedia extends Controller
public function __construct(AltoRouter $router)
{
parent::__construct($router);
$this->mediamanager = new Modelmedia();

$this->mediaopt = new Mediaopt($_GET);

if ($this->user->isvisitor()) {
http_response_code(401);
$this->showtemplate('connect', ['route' => 'media']);
exit;
}
$this->mediamanager = new Modelmedia();
$this->mediaopt = new Mediaopt($_GET);
}


Expand Down Expand Up @@ -99,15 +97,15 @@ public function upload()
$fontfacer = new Servicefont($this->mediamanager);
$fontfacer->writecss();
}
$this->redirect($this->generate('media') . '?path=/' . $target);
$this->redirect($this->generate('media') . $_POST['route']);
} catch (RuntimeException $e) {
Model::sendflashmessage($e->getMessage(), Model::FLASH_ERROR);
}
}
} else {
Model::sendflashmessage("acces denied", Model::FLASH_ERROR);
http_response_code(403);
$this->showtemplate('forbidden');

Check failure on line 107 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / analyse php 8.1

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.

Check failure on line 107 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / lint php

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.
}
$this->routedirect('media');
}

public function urlupload()
Expand All @@ -121,9 +119,10 @@ public function urlupload()
Model::sendflashmessage('Error while uploading : ' . $e->getMessage(), Model::FLASH_ERROR);
}
}
$this->redirect($this->generate('media') . '?path=/' . $target);
$this->redirect($this->generate('media') . $_POST['route']);
} else {
$this->routedirect('home');
http_response_code(403);
$this->showtemplate('forbidden');

Check failure on line 125 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / analyse php 8.1

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.

Check failure on line 125 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / lint php

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.
}
}

Expand All @@ -136,30 +135,33 @@ public function folderadd()
$name = 'new-folder';
}
$this->mediamanager->adddir($dir, $name);
$this->redirect($this->generate('media') . '?path=/' . $dir . $name);
parse_str(ltrim($_POST['route'], '?'), $route);
$route['path'] = $dir . $name;
$this->routedirect('media', [], $route);
}
$this->routedirect('home');
http_response_code(403);
$this->showtemplate('forbidden');

Check failure on line 143 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / analyse php 8.1

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.

Check failure on line 143 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / lint php

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.
}

public function folderdelete()
{
if (isset($_POST['dir'])) {
if (isset($_POST['deletefolder']) && intval($_POST['deletefolder']) && $this->user->issupereditor()) {
if ($this->user->issupereditor()) {
if (isset($_POST['deletefolder']) && intval($_POST['deletefolder']) && isset($_POST['dir'])) {
try {
if ($this->mediamanager->deletedir($_POST['dir'])) {
Model::sendflashmessage('Deletion successfull', Model::FLASH_SUCCESS);
} else {
Model::sendflashmessage('Deletion failed');
Model::sendflashmessage('Deletion failed', Model::FLASH_ERROR);
}
} catch (Forbiddenexception $e) {
Model::sendflashmessage('Deletion failed: ' . $e->getMessage(), Model::FLASH_ERROR);
}
} else {
$this->redirect($this->generate('media') . '?path=/' . $_POST['dir']);
exit;
}
$this->redirect($this->generate('media') . $_POST['route']);
} else {
http_response_code(403);
$this->showtemplate('forbidden');

Check failure on line 163 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / analyse php 8.1

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.

Check failure on line 163 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / lint php

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.
}
$this->redirect($this->generate('media'));
}

public function edit()
Expand All @@ -183,8 +185,11 @@ public function edit()
Model::sendflashmessage('Error while updating fonts CSS : ' . $e->getMessage());
}
}
$this->redirect($this->generate('media') . $_POST['route']);
} else {
http_response_code(403);
$this->showtemplate('forbidden');

Check failure on line 191 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / analyse php 8.1

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.

Check failure on line 191 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / lint php

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.
}
$this->redirect($this->generate('media') . $_POST['route']);
}

public function rename()
Expand All @@ -207,8 +212,11 @@ public function rename()
} catch (RuntimeException $e) {
Model::sendflashmessage($e->getMessage(), Model::FLASH_ERROR);
}
$this->redirect($this->generate('media') . $_POST['route']);
} else {
http_response_code(403);
$this->showtemplate('forbidden');

Check failure on line 218 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / analyse php 8.1

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.

Check failure on line 218 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / lint php

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.
}
$this->redirect($this->generate('media') . $_POST['route']);
}

/**
Expand All @@ -227,9 +235,10 @@ public function fontface()
Model::FLASH_ERROR
);
}
$this->redirect($this->generate("media", [], $this->mediaopt->getpathadress()));
} else {
Model::sendflashmessage("Access denied", Model::FLASH_ERROR);
http_response_code(403);
$this->showtemplate('forbidden');

Check failure on line 241 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / analyse php 8.1

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.

Check failure on line 241 in app/class/Controllermedia.php

View workflow job for this annotation

GitHub Actions / lint php

Method Wcms\Controller::showtemplate() invoked with 1 parameter, 2 required.
}
$this->redirect($this->generate("media", [], $this->mediaopt->getpathadress()));
}
}
6 changes: 6 additions & 0 deletions app/class/Mediaopt.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public function getsortbyadress(string $sortby): string
return '?' . urldecode(http_build_query($query));
}

/**
* Give the GET params to be used for redirection. Using hidden input under the `route` name.
*
* @param string $path Media path to display. Default is the current path.
* @return string URL-encoded path, filter and sort parameters, startiting with a `?`
*/
public function getpathadress(string $path = null): string
{
$path = is_null($path) ? $this->path : "/$path";
Expand Down
2 changes: 2 additions & 0 deletions app/class/Modelmedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ public function adddir($dir, $name)
* @return bool depending on operation success
*
* @throws Forbiddenexception If the directory is not inside `/media` folder
*
* @todo return void and throw exception in case of failure
*/
public function deletedir(string $dir): bool
{
Expand Down
6 changes: 3 additions & 3 deletions app/view/templates/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
<h2>
/<?= $mediaopt->dir() ?>
<span class="right">
<a href="<?= $mediaopt->getaddress() ?>&display=list" <?= $workspace->mediadisplay() === Wcms\Workspace::LIST ? 'class="selected"' : '' ?> >
<a href="<?= $mediaopt->getpathadress() ?>&display=list" <?= $workspace->mediadisplay() === Wcms\Workspace::LIST ? 'class="selected"' : '' ?> >
<i class="fa fa-th-list"></i>
</a>
<a href="<?= $mediaopt->getaddress() ?>&display=gallery" <?= $workspace->mediadisplay() === Wcms\Workspace::GALLERY ? 'class="selected"' : '' ?> >
<a href="<?= $mediaopt->getpathadress() ?>&display=gallery" <?= $workspace->mediadisplay() === Wcms\Workspace::GALLERY ? 'class="selected"' : '' ?> >
<i class="fa fa-th-large"></i>
</a>
</span>
Expand Down Expand Up @@ -171,7 +171,7 @@
<i class="fa fa-pencil"></i>
</summary>
<form action="<?= $this->url('mediarename') ?>" method="post">
<input type="hidden" name="route" value="<?= $mediaopt->getaddress() ?>">
<input type="hidden" name="route" value="<?= $mediaopt->getpathadress() ?>">
<input type="hidden" name="dir" value="<?= $media->dir() ?>">
<input type="hidden" name="oldfilename" value="<?= $media->filename() ?>">
<input type="text" name="newfilename" value="<?= $media->filename() ?>" id="newid-<?= $media->filename() ?>" maxlength="<?= Wcms\Model::MAX_ID_LENGTH ?>" minlength="1" required>
Expand Down
6 changes: 5 additions & 1 deletion app/view/templates/mediamenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</h3>
<p>max upload file size : <?= $maxuploadsize ?></p>
<form id=addmedia action="<?= $this->url('mediaupload') ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="route" value="<?= $mediaopt->getpathadress() ?>">
<input type='file' id="file" name='file[]' multiple required>

<div>
Expand All @@ -24,12 +25,14 @@
<label for="url"><i class="fa fa-cloud-upload"></i> Upload from URL</label>
</h3>
<form id="addurlmedia" action="<?= $this->url('mediaurlupload') ?>" method="post">
<input type="hidden" name="route" value="<?= $mediaopt->getpathadress() ?>">
<input type="text" name="url" id="url" placeholder="paste url here">
<input type="hidden" name="dir" value="<?= $mediaopt->dir() ?>">
<input type="submit" value="upload">
</form>
<h2>New folder</h2>
<form id="folderadd" action="<?= $this->url('mediafolderadd') ?>" method="post">
<input type="hidden" name="route" value="<?= $mediaopt->getpathadress() ?>">
<label for="foldername"><i class="fa fa-folder"></i> New folder</label>
<input type="text" name="foldername" id="foldername" placeholder="folder name" required>
<input type="hidden" name="dir" value="<?= $mediaopt->dir() ?>">
Expand All @@ -40,6 +43,7 @@
<?php if($user->issupereditor()) { ?>
<h2>Delete folder</h2>
<form action="<?= $this->url('mediafolderdelete') ?>" id="deletefolder" method="post">
<input type="hidden" name="route" value="<?= $mediaopt->getpathadress('media') ?>">
<input type="hidden" name="dir" value="<?= $mediaopt->dir() ?>/">
<input type="checkbox" name="deletefolder" id="confirmdeletefolder" value="1">
<label for="confirmdeletefolder">Delete current folder and all it's content</label>
Expand All @@ -65,7 +69,7 @@

<h2>Move</h2>
<form action="<?= $this->url('mediaedit') ?>" method="post" id="mediaedit">
<input type="hidden" name="route" value="<?= $mediaopt->getaddress() ?>">
<input type="hidden" name="route" value="<?= $mediaopt->getpathadress() ?>">
<input type="hidden" name="path" value="<?= $mediaopt->dir() ?>">
<label for="moveto">Move selected medias to a new directory</label>
<br>
Expand Down

0 comments on commit 6b744d4

Please sign in to comment.