From fc930cad0c953f79234090c667335e5467077756 Mon Sep 17 00:00:00 2001
From: Skylar Ittner
Date: Mon, 7 May 2018 01:33:28 -0600
Subject: [PATCH] Add mimetype filtering to file picker
---
lib/filepicker.php | 24 +++++++++++++++++++++++-
static/js/editorparent.js | 18 ++++++++++++++----
2 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/lib/filepicker.php b/lib/filepicker.php
index 5377058..7bcbaff 100644
--- a/lib/filepicker.php
+++ b/lib/filepicker.php
@@ -16,6 +16,13 @@ if (isset($VARS['path']) && file_exists($base . $VARS['path']) && strpos(realpat
$folder = $VARS['path'];
}
+// Compared to the start of the file mimetype, if it doesn't match the file is
+// skipped. A type of "image" will match "image/png", "image/jpeg", etc.
+$type = [];
+if (isset($VARS['type']) && $VARS['type'] != "") {
+ $type = explode("|", $VARS['type']);
+}
+
if ($folder == "/") {
$folder = "";
}
@@ -75,6 +82,21 @@ $fullpath = $base . $folder;
if (array_key_exists($extension, $EXT2MIME)) {
$mimetype = $EXT2MIME[$extension];
}
+
+ $found = true;
+ if (count($type) > 0) {
+ $found = false;
+ foreach ($type as $t) {
+ if (strpos($mimetype, $t) === 0) {
+ $found = true;
+ break;
+ }
+ }
+ }
+ if (!$found) {
+ continue;
+ }
+
// Lookup icon from mimetype
if (array_key_exists($mimetype, $MIMEICONS)) {
$icon = $MIMEICONS[$mimetype];
@@ -103,7 +125,7 @@ $fullpath = $base . $folder;
-
+