diff options
author | sarnowski <sarnowski@cosmocode.de> | 2009-08-24 13:22:30 +0200 |
---|---|---|
committer | sarnowski <sarnowski@cosmocode.de> | 2009-08-24 13:22:30 +0200 |
commit | bf1f3ac4f72c26ff386c08c920dda651d91c6898 (patch) | |
tree | 4b720e186993b1f96a0b55641f85d988c7bf5bb9 /inc | |
parent | 8ec12455ec81c8832085594acd6c082b1f9e625a (diff) | |
download | rpg-bf1f3ac4f72c26ff386c08c920dda651d91c6898.tar.gz rpg-bf1f3ac4f72c26ff386c08c920dda651d91c6898.tar.bz2 |
Search capabilities for the media manager added.
darcs-hash:20090824112230-8c5bd-7b8d8ba14e7533c1035b7b732983a0e3de8251a1.gz
Diffstat (limited to 'inc')
-rw-r--r-- | inc/lang/en/lang.php | 3 | ||||
-rw-r--r-- | inc/media.php | 87 | ||||
-rw-r--r-- | inc/template.php | 7 |
3 files changed, 93 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']; } |