diff --git a/classes/controller.php b/classes/controller.php
index 5f6a0ecf..2f72d7fe 100644
--- a/classes/controller.php
+++ b/classes/controller.php
@@ -11,6 +11,8 @@ use Grav\Common\Data;
use Grav\Common\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Collection;
+use Grav\Common\Plugin;
+use Grav\Common\Theme;
use Grav\Common\User\User;
use Grav\Common\Utils;
use Grav\Common\Backup\ZipBackup;
@@ -1402,6 +1404,84 @@ class AdminController
return true;
}
+ /**
+ * Determine if the user can edit media
+ *
+ * @return bool True if the media action is allowed
+ */
+ protected function canEditMedia()
+ {
+ $type = 'media';
+ if (!$this->authorizeTask('edit media', ['admin.' . $type, 'admin.super'])) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Handles removing a media file
+ *
+ * @return bool True if the action was performed
+ */
+ public function taskRemoveMedia()
+ {
+ if (!$this->canEditMedia()) {
+ return false;
+ }
+
+ $filename = base64_decode($this->route);
+ $file = File::instance($filename);
+ $resultRemoveMedia = false;
+ $resultRemoveMediaMeta = true;
+
+ if ($file->exists()) {
+ $resultRemoveMedia = $file->delete();
+
+ $metaFilePath = $filename . '.meta.yaml';
+ $metaFilePath = str_replace('@3x', '', $metaFilePath);
+ $metaFilePath = str_replace('@2x', '', $metaFilePath);
+
+ if (is_file($metaFilePath)) {
+ $metaFile = File::instance($metaFilePath);
+ $resultRemoveMediaMeta = $metaFile->delete();
+ }
+ }
+
+ if ($resultRemoveMedia && $resultRemoveMediaMeta) {
+ $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL'), 'info');
+ } else {
+ $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REMOVE_FAILED'), 'error');
+ }
+
+ $this->post = array('_redirect' => 'media');
+ return true;
+ }
+
+ /**
+ * Handle deleting a file from a blueprint
+ *
+ * @return bool True if the action was performed.
+ */
+ protected function taskRemoveFileFromBlueprint()
+ {
+ $uri = $this->grav['uri'];
+ $this->taskRemoveMedia();
+
+ $field = $uri->param('field');
+ $blueprint = $uri->param('blueprint');
+ $this->grav['config']->set($blueprint . '.' . $field, '');
+ if (substr($blueprint, 0, 7) == 'plugins') {
+ Plugin::saveConfig(substr($blueprint, 8));
+ }
+ if (substr($blueprint, 0, 6) == 'themes') {
+ Theme::saveConfig(substr($blueprint, 7));
+ }
+
+ $redirect = base64_decode($uri->param('redirect'));
+ $this->post = array('_redirect' => $redirect);
+ return true;
+ }
+
/**
* Prepare and return POST data.
*
diff --git a/languages/en.yaml b/languages/en.yaml
index 5561a4f3..ed3bb969 100644
--- a/languages/en.yaml
+++ b/languages/en.yaml
@@ -461,4 +461,6 @@ PLUGIN_ADMIN:
TWIG_UMASK_FIX: "Umask Fix"
TWIG_UMASK_FIX_HELP: "By default Twig creates cached files as 0755, fix switches this to 0775"
CACHE_PERMS: "Cache Permissions"
- CACHE_PERMS_HELP: "Default cache folder perms. Usually 0755 or 0775 depending on setup"
\ No newline at end of file
+ CACHE_PERMS_HELP: "Default cache folder perms. Usually 0755 or 0775 depending on setup"
+ REMOVE_SUCCESSFUL: "Remove Successful"
+ REMOVE_FAILED: "Remove Failed"
\ No newline at end of file
diff --git a/themes/grav/templates/forms/fields/file/file.html.twig b/themes/grav/templates/forms/fields/file/file.html.twig
index 5984c3d2..ecedbfcb 100644
--- a/themes/grav/templates/forms/fields/file/file.html.twig
+++ b/themes/grav/templates/forms/fields/file/file.html.twig
@@ -9,28 +9,18 @@
Use the "pagemediaselect" type instead.
{% else %}
{% if value %}
- {% if files.showuploaded == true %}
- {% if files.showuploadedpreview %}
-
- {% else %}
- {{ value|replace({(files.destination ~ '/'): ''}) }}
- {% endif %}
-
- {% if files.ispluginconfig %}
-
-
-
- {% endif %}
- {% endif %}
+
+
+
+
{% endif %}