From 96c99125da5fe74d4a8fa329869cca7f775805cf Mon Sep 17 00:00:00 2001 From: Bartek Przybylski Date: Thu, 5 Apr 2012 23:18:44 +0200 Subject: [PATCH] mimetype filter for filepicker --- core/js/oc-dialogs.js | 8 ++++---- files/ajax/rawlist.php | 3 ++- lib/filecache.php | 6 +++--- lib/files.php | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index e027ffb5103..a3aa1e8c149 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -107,8 +107,8 @@ OCdialogs = { $(c_id + ' #dirtree').focus(function() { var t = $(this); t.data('oldval', t.val())}) .change({dcid: c_id}, OC.dialogs.handleTreeListSelect); $(c_id).ready(function(){ - $.getJSON(OC.webroot+'/files/ajax/rawlist.php', function(r){OC.dialogs.fillFilePicker(r, c_id, callback)}); - }).data('multiselect', multiselect); + $.getJSON(OC.webroot+'/files/ajax/rawlist.php', {mimetype: mimetype_filter} ,function(r){OC.dialogs.fillFilePicker(r, c_id, callback)}); + }).data('multiselect', multiselect).data('mimetype',mimetype_filter); // build buttons var b = [ {text: t('dialogs', 'Choose'), click: function(){ @@ -222,7 +222,7 @@ OCdialogs = { $(this).children().each(function(i, element) { if (skip_first) {skip_first = false; return; }path += '/'+$(element).text(); }); $(event.data.dcid).data('path', path); $(event.data.dcid + ' .filepicker_loader').css('visibility', 'visible'); - $.getJSON(OC.webroot+'/files/ajax/rawlist.php', {dir: path}, function(r){OC.dialogs.fillFilePicker(r, event.data.dcid)}); + $.getJSON(OC.webroot+'/files/ajax/rawlist.php', {dir: path, mimetype: $(event.data.dcid).data('mimetype')}, function(r){OC.dialogs.fillFilePicker(r, event.data.dcid)}); }, // this function is in early development state, please dont use it unlsess you know what you are doing handlePickerClick:function(element, name, dcid) { @@ -240,6 +240,6 @@ OCdialogs = { var newval = parseInt($(dcid + ' #dirtree option:last').val())+1; $(dcid + ' #dirtree').append(''); $(dcid + ' .filepicker_loader').css('visibility', 'visible'); - $.getJSON(OC.webroot+'/files/ajax/rawlist.php', {dir: p}, function(r){OC.dialogs.fillFilePicker(r, dcid)}); + $.getJSON(OC.webroot+'/files/ajax/rawlist.php', {dir: p, mimetype: $(dcid).data('mimetype')}, function(r){OC.dialogs.fillFilePicker(r, dcid)}); } }; diff --git a/files/ajax/rawlist.php b/files/ajax/rawlist.php index 88ba48a6c48..e02c5b62733 100644 --- a/files/ajax/rawlist.php +++ b/files/ajax/rawlist.php @@ -11,10 +11,11 @@ OC_JSON::checkLoggedIn(); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; +$mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : ''; // make filelist $files = array(); -foreach( OC_Files::getdirectorycontent( $dir ) as $i ){ +foreach( OC_Files::getdirectorycontent( $dir, $mimetype ) as $i ){ $i["date"] = OC_Util::formatDate($i["mtime"] ); $i['mimetype_icon'] = $i['type'] == 'dir' ? mimetype_icon('dir'): mimetype_icon($i['mimetype']); $files[] = $i; diff --git a/lib/filecache.php b/lib/filecache.php index 4a4183cbdb5..cdd91dcbfa4 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -240,7 +240,7 @@ class OC_FileCache{ * - encrypted * - versioned */ - public static function getFolderContent($path,$root=''){ + public static function getFolderContent($path,$root='',$mimetype_filter=''){ if(self::isUpdated($path,$root)){ self::updateFolder($path,$root); } @@ -252,8 +252,8 @@ class OC_FileCache{ } $path=$root.$path; $parent=self::getFileId($path); - $query=OC_DB::prepare('SELECT name,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE parent=?'); - $result=$query->execute(array($parent))->fetchAll(); + $query=OC_DB::prepare('SELECT name,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE parent=? AND (mimetype LIKE ? OR mimetype = ?)'); + $result=$query->execute(array($parent, $mimetype_filter.'%', 'httpd/unix-directory'))->fetchAll(); if(is_array($result)){ return $result; }else{ diff --git a/lib/files.php b/lib/files.php index e7bfbbc19bb..a68c29ad989 100644 --- a/lib/files.php +++ b/lib/files.php @@ -32,11 +32,11 @@ class OC_Files { * get the content of a directory * @param dir $directory */ - public static function getDirectoryContent($directory){ + public static function getDirectoryContent($directory, $mimetype_filter = ''){ if(strpos($directory,OC::$CONFIG_DATADIRECTORY)===0){ $directory=substr($directory,strlen(OC::$CONFIG_DATADIRECTORY)); } - $files=OC_FileCache::getFolderContent($directory); + $files=OC_FileCache::getFolderContent($directory, '', $mimetype_filter); foreach($files as &$file){ $file['directory']=$directory; $file['type']=($file['mimetype']=='httpd/unix-directory')?'dir':'file'; -- 2.39.5