diff options
-rw-r--r-- | inc/lang/en/lang.php | 3 | ||||
-rw-r--r-- | inc/media.php | 87 | ||||
-rw-r--r-- | inc/template.php | 7 | ||||
-rw-r--r-- | lib/exe/ajax.php | 12 | ||||
-rw-r--r-- | lib/scripts/media.js | 43 |
5 files changed, 148 insertions, 4 deletions
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index 04ec3170e..121b0fec2 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -94,6 +94,8 @@ $lang['resendpwdsuccess'] = 'Your new password has been sent by email.'; $lang['license'] = 'Except where otherwise noted, content on this wiki is licensed under the following license:'; $lang['licenseok'] = 'Note: By editing this page you agree to license your content under the following license:'; +$lang['txt_searchmediakey'] = 'Search for file'; +$lang['txt_searchrelative'] = 'Only search in namespace :%s'; $lang['txt_upload'] = 'Select file to upload'; $lang['txt_filename'] = 'Upload as (optional)'; $lang['txt_overwrt'] = 'Overwrite existing file'; @@ -121,6 +123,7 @@ $lang['mediainuse'] = 'The file "%s" hasn\'t been deleted - it is still in use. $lang['namespaces'] = 'Namespaces'; $lang['mediafiles'] = 'Available files in'; +$lang['js']['searchmedia'] = 'Search for files'; $lang['js']['keepopen'] = 'Keep window open on selection'; $lang['js']['hidedetails'] = 'Hide Details'; $lang['mediausage'] = 'Use the following syntax to reference this file:'; diff --git a/inc/media.php b/inc/media.php index 1d584db70..84b11b65e 100644 --- a/inc/media.php +++ b/inc/media.php @@ -461,6 +461,56 @@ function media_filelist($ns,$auth=null,$jump=''){ } /** + * List all files found by the search request + */ +function media_searchlist($ns,$auth=null,$jump=''){ + global $conf; + global $lang; + $ns = cleanID($ns); + + // check auth our self if not given (needed for ajax calls) + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '<h1 id="media__ns">Search</h1>'.NL; + + if($auth < AUTH_READ){ + // FIXME: print permission warning here instead? + echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL; + return; + } + + media_searchform($ns, $auth); + + if (isset($_REQUEST['key']) && strlen($_REQUEST['key']) > 2) { + + if (isset($_REQUEST['key_relative'])) { + $dir = utf8_encodeFN(str_replace(':','/',$ns)); + } else { + $dir = ''; + } + + $data = array(); + $evt = new Doku_Event('ACTION_MEDIA_SEARCH', $dir); + if ($evt->advise_before()) { + $pattern = '#'.str_replace('#', '\#', $_REQUEST['key']).'#'; + search($data,$conf['mediadir'],'search_media', array('showmsg'=>true,'pattern'=>$pattern),$dir); + + } + $evt->advise_after(); + unset($evt); + + if(!count($data)){ + echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL; + return; + } + + foreach($data as $item){ + media_printfile($item,$auth,$jump,$display_namespace=true); + } + } +} + +/** * Print action links for a file depending on filetype * and available permissions * @@ -498,7 +548,7 @@ function media_fileactions($item,$auth){ /** * Formats and prints one file in the list */ -function media_printfile($item,$auth,$jump){ +function media_printfile($item,$auth,$jump,$display_namespace=false){ global $lang; global $conf; @@ -537,7 +587,7 @@ function media_printfile($item,$auth,$jump){ // ouput echo '<div class="'.$zebra.'"'.$jump.'>'.NL; - echo '<a name="h_:'.$item['id'].'" class="'.$class.'">'.$file.'</a> '; + echo '<a name="h_'.$item['id'].'" class="'.$class.'">'.$file.'</a> '; echo '<span class="info">('.$info.')</span>'.NL; media_fileactions($item,$auth); echo '<div class="example" id="ex_'.str_replace(':','_',$item['id']).'">'; @@ -663,6 +713,39 @@ function media_uploadform($ns, $auth){ } /** + * Print the search field form + * + * @author Tobias Sarnowski <sarnowski@cosmocode.de> + */ +function media_searchform($ns, $auth){ + global $lang; + + if (!isset($_REQUEST['key'])) { + $default = ''; + } else { + $default = htmlspecialchars($_REQUEST['key']); + } + + // The default HTML search form + $form = new Doku_Form('dw__mediasearch', DOKU_BASE.'lib/exe/mediamanager.php', false); + $form->addElement('<div class="upload">' . $lang['mediasearch'] . '</div>'); + $form->addElement(formSecurityToken()); + $form->addHidden('ns', hsc($ns)); + $form->addHidden('call', 'mediasearchlist'); + $form->addElement(form_makeOpenTag('p')); + $form->addElement(form_makeTextField('key', $default, $lang['txt_searchmediakey'].':', 'searchmedia__key')); + $form->addElement(form_makeButton('submit', '', $lang['btn_search'])); + $form->addElement(form_makeCloseTag('p')); + if ($ns) { + $form->addElement(form_makeOpenTag('p')); + $form->addElement(form_makeCheckboxField('key_relative', true, sprintf($lang['txt_searchrelative'], $ns), 'dw__relative', 'check', isset($_REQUEST['key_relative'])?array('checked' => 'checked'):array())); + $form->addElement(form_makeCloseTag('p')); + } + + html_form('searchmedia', $form); +} + +/** * Build a tree outline of available media namespaces * * @author Andreas Gohr <andi@splitbrain.org> diff --git a/inc/template.php b/inc/template.php index e1b253f96..9564dcef8 100644 --- a/inc/template.php +++ b/inc/template.php @@ -1190,8 +1190,11 @@ function tpl_mediaContent($fromajax=false){ global $NS; global $JUMPTO; - if(is_array($_REQUEST['do'])){ - $do = array_shift(array_keys($_REQUEST['do'])); + ptln('<div id="media__content">'); + if($_REQUEST['edit']){ + media_metaform($IMG,$AUTH); + }elseif(is_array($INUSE)){ + media_filesinuse($INUSE,$IMG); }else{ $do = $_REQUEST['do']; } diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index c10893db7..4d9a8105a 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -216,6 +216,18 @@ function ajax_medialist(){ } /** + * Return list of search result for the Mediamanager + * + * @author Tobias Sarnowski <sarnowski@cosmocode.de> + */ +function ajax_mediasearchlist(){ + global $conf; + require_once(DOKU_INC.'inc/media.php'); + + media_searchlist($_POST['ns']); +} + +/** * Return sub index for index view * * @author Andreas Gohr <andi@splitbrain.org> diff --git a/lib/scripts/media.js b/lib/scripts/media.js index 4ae31a989..7726d0664 100644 --- a/lib/scripts/media.js +++ b/lib/scripts/media.js @@ -94,6 +94,22 @@ media = { attachoptions: function(obj){ if(!obj) return; + // search link + var searcha = document.createElement('a'); + searcha.id = 'media__search'; + searcha.href = '#'; + addEvent(searcha,'click',function(event){ return media.showsearchfield(event,this); }); + + var searchlbl = document.createElement('label'); + searchlbl.htmlFor = 'media__searchmedia'; + searchlbl.innerHTML = LANG['searchmedia']; + + var searchbr = document.createElement('br'); + + searcha.appendChild(searchlbl); + obj.appendChild(searcha); + obj.appendChild(searchbr); + // keep open if(opener){ var kobox = document.createElement('input'); @@ -141,6 +157,33 @@ media = { }, /** + * Opens the searchfield + * + * @author Tobias Sarnowski <sarnowski@cosmocode.de> + */ + showsearchfield: function(event,link){ + // prepare an AJAX call to fetch the search + var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php'); + ajax.AjaxFailedAlert = ''; + ajax.encodeURIString = false; + if(ajax.failed) return true; + + cleanMsgArea(); + + var content = $('media__content'); + content.innerHTML = '<img src="'+DOKU_BASE+'lib/images/loading.gif" alt="..." class="load" />'; + + ajax.elementObj = content; + ajax.afterCompletion = function(){ + media.selectorattach(content); + media.confirmattach(content); + media.updatehide(); + }; + ajax.runAJAX(link.search.substr(1)+'&call=mediasearchlist'); + return false; + }, + + /** * Toggles the keep open state * * @author Andreas Gohr <andi@splitbrain.org> |