summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorParis Liakos2012-10-07 00:32:12 (GMT)
committer Paris Liakos2012-10-07 00:32:12 (GMT)
commit2f5fe4afbf2ba55f4e801fedf9be37cc87a3e22e (patch)
tree7da88e5b38bb505fed0552a3bb2765ef061e4bbe
parente2ffecb737c9908e63b85c20e5cd93de6af08e85 (diff)
Respect file type restrictions in wysiwyg media browser view
-rw-r--r--media.media.inc40
1 files changed, 29 insertions, 11 deletions
diff --git a/media.media.inc b/media.media.inc
index 655bfca..65738f9 100644
--- a/media.media.inc
+++ b/media.media.inc
@@ -54,19 +54,19 @@ function media_query_media_browser_alter($query) {
// I think PDO should protect them, but I'm not 100% certain.
array_walk_recursive($params, 'media_recursive_check_plain');
- $remote_types = !empty($params['types']) ? $params['types'] : NULL;
+ $types = !empty($params['types']) ? $params['types'] : NULL;
$url_include_patterns = !empty($params['url_include_patterns']) ? $params['url_include_patterns'] : NULL;
$url_exclude_patterns = !empty($params['url_exclude_patterns']) ? $params['url_exclude_patterns'] : NULL;
$allowed_schemes = !empty($params['schemes']) ? array_filter($params['schemes']) : array();
+ $extensions = !empty($params['file_extensions']) ? array_filter(explode(' ', $params['file_extensions'])) : array();
- // Add conditions based on remote file type *or* local allowed extensions.
$or_condition = db_or();
- // Include local files with the allowed extensions.
- if (!empty($params['file_extensions'])) {
- $extensions = array_filter(explode(' ', $params['file_extensions']));
+ if (!empty($allowed_schemes)) {
+ // Include local files with the allowed extensions and types.
$local_wrappers = array_intersect_key(media_get_local_stream_wrappers(), $allowed_schemes);
- if (!empty($local_wrappers) && !empty($extensions)) {
+ if (!empty($extensions) && !empty($local_wrappers)) {
+ // Extension filtering.
$local_condition = db_or();
foreach (array_keys($local_wrappers) as $scheme) {
foreach ($extensions as $extension) {
@@ -75,22 +75,40 @@ function media_query_media_browser_alter($query) {
}
$or_condition->condition($local_condition);
}
- }
+ if (!empty($types) && !empty($local_wrappers)) {
+ // Type filtering.
+ $local_condition = db_or();
+ foreach (array_keys($local_wrappers) as $scheme) {
+ $local_condition->condition($alias . '.type', $types, 'IN');
+ }
+ $or_condition->condition($local_condition);
+ }
- // Include remote files with the allowed file types.
- if (!empty($remote_types)) {
+ // Include remote files with the allowed file types.
+ // We cant filter extensions here, because remote file filenames usually
+ // are a url or a parameter of a query.
$remote_wrappers = array_intersect_key(media_get_remote_stream_wrappers(), $allowed_schemes);
- if (!empty($remote_wrappers)) {
+ if (!empty($types) && !empty($remote_wrappers)) {
$remote_condition = db_and();
$wrapper_condition = db_or();
foreach (array_keys($remote_wrappers) as $scheme) {
$wrapper_condition->condition($alias . '.uri', db_like($scheme . '://') . '%', 'LIKE');
}
$remote_condition->condition($wrapper_condition);
- $remote_condition->condition($alias . '.type', $remote_types, 'IN');
+ $remote_condition->condition($alias . '.type', $types, 'IN');
$or_condition->condition($remote_condition);
}
}
+ else {
+ if (!empty($types)) {
+ $query->condition($alias . '.type', $types, 'IN');
+ }
+ if (!empty($extensions)) {
+ foreach ($extensions as $extension) {
+ $or_condition->condition($alias . '.uri', db_like('.' . $extension), 'LIKE');
+ }
+ }
+ }
if ($or_condition->count()) {
$query->condition($or_condition);