From d9162c6cd87643d7e7af8e37cd93aa48b8aecb96 Mon Sep 17 00:00:00 2001 From: Kate Arzamastseva Date: Thu, 9 Jun 2011 14:04:50 +0300 Subject: fullscreen media manager --- inc/actions.php | 2 +- inc/media.php | 401 ++++++++++++++++++++++++++++++++++++++++++---- inc/template.php | 89 +++++++++- lib/exe/mediamanager.php | 14 +- lib/tpl/default/style.ini | 1 + 5 files changed, 470 insertions(+), 37 deletions(-) diff --git a/inc/actions.php b/inc/actions.php index ecf09036f..1a0ae4028 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -227,7 +227,7 @@ function act_clean($act){ 'preview','search','show','check','index','revisions', 'diff','recent','backlink','admin','subscribe','revert', 'unsubscribe','profile','resendpwd','recover', - 'draftdel','subscribens','unsubscribens','sitemap')) && substr($act,0,7) != 'export_' ) { + 'draftdel','subscribens','unsubscribens','sitemap','media')) && substr($act,0,7) != 'export_' ) { msg('Command unknown: '.htmlspecialchars($act),-1); return 'show'; } diff --git a/inc/media.php b/inc/media.php index be55f8044..d98e225b9 100644 --- a/inc/media.php +++ b/inc/media.php @@ -74,8 +74,9 @@ function media_metasave($id,$auth,$data){ * Display the form to edit image meta data * * @author Andreas Gohr + * @author Kate Arzamastseva */ -function media_metaform($id,$auth){ +function media_metaform($id,$auth,$fullscreen = false){ if($auth < AUTH_UPLOAD) return false; global $lang, $config_cascade; @@ -96,8 +97,13 @@ function media_metaform($id,$auth){ $src = mediaFN($id); // output - echo '

'.hsc(noNS($id)).'

'.NL; - echo '
'.NL; + if (!$fullscreen) { + echo '

'.hsc(noNS($id)).'

'.NL; + echo ''.NL; + } else { + echo ''.NL; + } formSecurityToken(); foreach($fields as $key => $field){ // get current value @@ -132,8 +138,11 @@ function media_metaform($id,$auth){ } echo '
'.NL; echo ''.NL; - echo ''.NL; + if (!$fullscreen) echo ''.NL; echo '
'.NL; @@ -476,7 +485,7 @@ function media_notify($id,$file,$mime){ /** * List all files in a given Media namespace */ -function media_filelist($ns,$auth=null,$jump=''){ +function media_filelist($ns,$auth=null,$jump='',$fullscreenview=false){ global $conf; global $lang; $ns = cleanID($ns); @@ -484,13 +493,13 @@ function media_filelist($ns,$auth=null,$jump=''){ // check auth our self if not given (needed for ajax calls) if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); - echo '

:'.hsc($ns).'

'.NL; + if (!$fullscreenview) echo '

:'.hsc($ns).'

'.NL; if($auth < AUTH_READ){ // FIXME: print permission warning here instead? echo '
'.$lang['nothingfound'].'
'.NL; }else{ - media_uploadform($ns, $auth); + if (!$fullscreenview) media_uploadform($ns, $auth); $dir = utf8_encodeFN(str_replace(':','/',$ns)); $data = array(); @@ -500,10 +509,248 @@ function media_filelist($ns,$auth=null,$jump=''){ if(!count($data)){ echo '
'.$lang['nothingfound'].'
'.NL; }else foreach($data as $item){ - media_printfile($item,$auth,$jump); + if (!$fullscreenview) media_printfile($item,$auth,$jump); + else if ($fullscreenview == 'thumbs') media_printfile_thumbs($item,$auth,$jump); + } + } + if (!$fullscreenview) media_searchform($ns); +} + +/** + * Prints tabs for files list actions + * + * @author Kate Arzamastseva + * @param string $selected - opened tab + */ +function media_tabs_files($selected=false){ + global $lang; + + echo '
'; + $tab = 'Files'; + echo $tab; + + $tab = 'Upload'; + echo $tab; + + $tab = 'Search'; + echo $tab; + + echo '
 
'; + echo '
'; +} + +/** + * Prints tabs for files details actions + * + * @author Kate Arzamastseva + * @param string $selected - opened tab + */ +function media_tabs_details($selected=false){ + global $lang; + + echo '
'; + $tab = 'View'; + echo $tab; + + $tab = 'Edit'; + echo $tab; + + $tab = 'History'; + echo $tab; + + echo '
 
'; + echo '
'; +} + +/** + * Prints options for the tab that displays a list of all files + * + * @author Kate Arzamastseva + */ +function media_tab_files_options(){ + global $lang; + + echo '
'; + echo '
'; + echo ' + Thumbs'; + echo 'List'; + + echo '
'; + echo '
Sort'; + //select + echo '
'; + echo '
 
'; + echo '
'; +} + +/** + * Prints tab that displays a list of all files + * + * @author Kate Arzamastseva + */ +function media_tab_files($ns,$auth=null,$jump='') { + global $lang; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '
'; + media_tab_files_options(); + echo '
'; + + $view = $_REQUEST['view']; + if($auth < AUTH_READ){ + echo '
'.$lang['nothingfound'].'
'.NL; + }else{ + if ($view == 'list') { + echo '
'; + echo '
'; + } else { + echo '
'; + media_filelist($ns,$auth,$jump,'thumbs'); + echo '
'; } } - media_searchform($ns); + echo '
'; + echo '
'; +} + +/** + * Prints tab that displays uploading form + * + * @author Kate Arzamastseva + */ +function media_tab_upload($ns,$auth=null,$jump='') { + global $lang; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '
'; + echo '
'; + echo $lang['mediaupload']; + echo '
'; + + echo '
'; + media_uploadform($ns, $auth, true); + echo '
'; + echo '
'; +} + +/** + * Prints tab that displays search form + * + * @author Kate Arzamastseva + */ +function media_tab_search($ns,$auth=null) { + global $lang; + + $do = $_REQUEST['mediado']; + $query = $_REQUEST['q']; + if (!$query) $query = ''; + + echo ''; +} + +/** + * Prints tab that displays mediafile details + * + * @author Kate Arzamastseva + */ +function media_tab_view($image, $ns, $auth=null) { + global $lang, $conf; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '
'; + echo '
'; + echo 'Preview of image'; + echo '
'; + + echo '
'; + if($auth < AUTH_READ) return false; + + $info = new JpegMeta(mediaFN($image)); + $w = (int) $info->getField('File.Width'); + $src = ml($image); + echo ''; + echo '
'; + echo '
'; +} + +/** + * Prints tab that displays form for editing mediafile metadata + * + * @author Kate Arzamastseva + */ +function media_tab_edit($image, $ns, $auth=null) { + global $lang; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '
'; + echo '
'; + echo 'Edit'; + echo '
'; + + echo '
'; + media_metaform($image,$auth,true); + echo '
'; + echo '
'; +} + +/** + * Prints tab that displays mediafile revisions + * + * @author Kate Arzamastseva + */ +function media_tab_history($image, $ns, $auth=null) { + global $lang; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '
'; + echo '
'; + echo 'History'; + echo '
'; + + echo '
'; + + echo '
'; + echo '
'; } /** @@ -511,9 +758,10 @@ function media_filelist($ns,$auth=null,$jump=''){ * * @author Tobias Sarnowski * @author Andreas Gohr + * @author Kate Arzamastseva * @triggers MEDIA_SEARCH */ -function media_searchlist($query,$ns,$auth=null){ +function media_searchlist($query,$ns,$auth=null,$fullscreen=false){ global $conf; global $lang; $ns = cleanID($ns); @@ -538,13 +786,16 @@ function media_searchlist($query,$ns,$auth=null){ unset($evt); } - echo '

'.sprintf($lang['searchmedia_in'],hsc($ns).':*').'

'.NL; - media_searchform($ns,$query); + if (!$fullscreen) { + echo '

'.sprintf($lang['searchmedia_in'],hsc($ns).':*').'

'.NL; + media_searchform($ns,$query); + } if(!count($evdata['data'])){ echo '
'.$lang['nothingfound'].'
'.NL; }else foreach($evdata['data'] as $item){ - media_printfile($item,$item['perm'],'',true); + if (!$fullscreen) media_printfile($item,$item['perm'],'',true); + else media_printfile_thumbs($item,$item['perm'],'',true); } } @@ -552,7 +803,7 @@ function media_searchlist($query,$ns,$auth=null){ * Print action links for a file depending on filetype * and available permissions */ -function media_fileactions($item,$auth){ +function media_fileactions($item,$auth,$fullscreen=false){ global $lang; // view button @@ -565,15 +816,20 @@ function media_fileactions($item,$auth){ // delete button if($auth >= AUTH_DELETE){ - echo ' '. + if (!$fullscreen) $link = DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']). + '&sectok='.getSecurityToken(); + else $link = media_managerURL(array('delete' => $item['id'], + 'sectok' => getSecurityToken())); + echo ' '. ''.$lang['btn_delete'].''; } // edit button if($auth >= AUTH_UPLOAD && $item['isimg'] && $item['meta']->getField('File.Mime') == 'image/jpeg'){ - echo ' '. + if (!$fullscreen) $link = DOKU_BASE.'lib/exe/mediamanager.php?edit='.rawurlencode($item['id']); + else $link = media_managerURL(array('edit' => $item['id'])); + echo ' '. ''.$lang['metaedit'].''; } @@ -637,15 +893,50 @@ function media_printfile($item,$auth,$jump,$display_namespace=false){ echo ''.NL; } +/** + * Formats and prints one file in the list in the thumbnails view + * + * @author Kate Arzamastseva + */ +function media_printfile_thumbs($item,$auth,$jump){ + global $lang; + global $conf; + + // Prepare filename + $file = utf8_decodeFN($item['file']); + + // Prepare info + $info = ''; + if($item['isimg']){ + $info .= (int) $item['meta']->getField('File.Width'); + $info .= '×'; + $info .= (int) $item['meta']->getField('File.Height'); + $info .= '
'; + } + $info .= ''.dformat($item['mtime']).'
'; + $info .= filesize_h($item['size']); + + // output + echo '
'; + if($item['isimg']) media_printimgdetail($item, true); + echo '
'.hsc($file).'
'; + echo ''.$info.'
'; + media_fileactions($item,$auth,true); + echo '
'.NL; +} + /** * Prints a thumbnail and metainfos */ -function media_printimgdetail($item){ +function media_printimgdetail($item, $fullscreen=false){ // prepare thumbnail + if (!$fullscreen) $size = 120; + else $size = 90; $w = (int) $item['meta']->getField('File.Width'); $h = (int) $item['meta']->getField('File.Height'); - if($w>120 || $h>120){ - $ratio = $item['meta']->getResizeRatio(120); + if($w>$size || $h>$size){ + $ratio = $item['meta']->getResizeRatio($size); $w = floor($w * $ratio); $h = floor($h * $ratio); } @@ -658,6 +949,13 @@ function media_printimgdetail($item){ $att = buildAttributes($p); // output + if ($fullscreen) { + echo ''; + echo ''; + echo ''; + return 1; + } + echo '
'; echo ''; } +/** + * Build link based on the current, adding/rewriting + * parameters + * + * @author Kate Arzamastseva + * @param array $params + * @param string $amp - separator + * @return string - link + */ +function media_managerURL($params=false, $amp='&') { + global $conf; + global $ID; + + $url = $_SERVER['REQUEST_URI']; + + $urlArray = explode('?', $url, 2); + $gets = @$urlArray[1]; + parse_str($gets, $gets); + + if ($gets['edit']) $gets['image'] = $gets['edit']; + unset($gets['edit']); + unset($gets['sectok']); + unset($gets['delete']); + + if ($params) { + foreach ($params as $k => $v) { + $gets[$k] = $v; + } + } + unset($gets['id']); + + return wl($ID,$gets,false,$amp); +} + /** * Print the media upload form if permissions are correct * * @author Andreas Gohr + * @author Kate Arzamastseva */ -function media_uploadform($ns, $auth){ +function media_uploadform($ns, $auth, $fullscreen = false){ global $lang; if($auth < AUTH_UPLOAD) return; //fixme print info on missing permissions? // The default HTML upload form - $form = new Doku_Form(array('id' => 'dw__upload', - 'action' => DOKU_BASE.'lib/exe/mediamanager.php', - 'enctype' => 'multipart/form-data')); - $form->addElement('
' . $lang['mediaupload'] . '
'); + $params = array('id' => 'dw__upload', + 'enctype' => 'multipart/form-data'); + if (!$fullscreen) $params['action'] = DOKU_BASE.'lib/exe/mediamanager.php'; + else $params['action'] = media_managerURL(array('tab_files' => 'files')); + + $form = new Doku_Form($params); + if (!$fullscreen) $form->addElement('
' . $lang['mediaupload'] . '
'); $form->addElement(formSecurityToken()); $form->addHidden('ns', hsc($ns)); $form->addElement(form_makeOpenTag('p')); @@ -757,16 +1093,21 @@ function media_uploadform($ns, $auth){ * Print the search field form * * @author Tobias Sarnowski + * @author Kate Arzamastseva */ -function media_searchform($ns,$query=''){ +function media_searchform($ns,$query='',$fullscreen=false){ global $lang; // The default HTML search form - $form = new Doku_Form(array('id' => 'dw__mediasearch', 'action' => DOKU_BASE.'lib/exe/mediamanager.php')); - $form->addElement('
' . $lang['mediasearch'] . '
'); + $params = array('id' => 'dw__mediasearch'); + if (!$fullscreen) $params['action'] = DOKU_BASE.'lib/exe/mediamanager.php'; + else $params['action'] = media_managerURL(); + $form = new Doku_Form($params); + if (!$fullscreen) $form->addElement('
' . $lang['mediasearch'] . '
'); $form->addElement(formSecurityToken()); $form->addHidden('ns', $ns); - $form->addHidden('do', 'searchlist'); + if (!$fullscreen) $form->addHidden('do', 'searchlist'); + else $form->addHidden('mediado', 'searchlist'); $form->addElement(form_makeOpenTag('p')); $form->addElement(form_makeTextField('q', $query,$lang['searchmedia'],'','',array('title'=>sprintf($lang['searchmedia_in'],hsc($ns).':*')))); $form->addElement(form_makeButton('submit', '', $lang['btn_search'])); @@ -820,7 +1161,9 @@ function media_nstree_item($item){ if(!$item['label']) $item['label'] = $label; $ret = ''; + if (!($_REQUEST['do'] == 'media')) $ret .= '
'; + else $ret .= ''; $ret .= $item['label']; $ret .= ''; return $ret; diff --git a/inc/template.php b/inc/template.php index d2d66220c..4bbb501fc 100644 --- a/inc/template.php +++ b/inc/template.php @@ -123,6 +123,9 @@ function tpl_content_core(){ case 'subscribe': tpl_subscribe(); break; + case 'media': + tpl_media(); + break; default: $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); if ($evt->advise_before()) @@ -1123,6 +1126,56 @@ function tpl_mediaContent($fromajax=false){ } +/** + * Prints the central column in full-screen media manager + * Depending on the opened tab this may be a list of + * files in a namespace, upload form or search form + * + * @author Kate Arzamastseva + */ +function tpl_fileList(){ + global $AUTH; + global $NS; + global $JUMPTO; + + $opened_tab = $_REQUEST['tab_files']; + if (!$opened_tab) $opened_tab = 'files'; + + media_tabs_files($opened_tab); + if ($opened_tab == 'files') media_tab_files($NS,$AUTH,$JUMPTO); + if ($opened_tab == 'upload') media_tab_upload($NS,$AUTH,$JUMPTO); + if ($opened_tab == 'search') media_tab_search($NS,$AUTH); + +} + +/** + * Prints the third column in full-screen media manager + * Depending on the opened tab this may be details of the + * selected file, the meta editing dialog or + * list of file revisions + * + * @author Kate Arzamastseva + */ +function tpl_fileDetails(){ + global $AUTH; + global $NS; + global $IMG; + + $opened_tab = $_REQUEST['tab_details']; + if (!$opened_tab) $opened_tab = 'view'; + if ($_REQUEST['edit']) $opened_tab = 'edit'; + media_tabs_details($opened_tab); + + $image = $_REQUEST['image']; + if (!$image && !$IMG) return false; + if ($opened_tab == 'view') media_tab_view($image, $NS, $AUTH); + if ($opened_tab == 'edit') { + if ($IMG) media_tab_edit($IMG, $NS, $AUTH); + else if ($image) media_tab_edit($image, $NS, $AUTH); + } + if ($opened_tab == 'history') media_tab_history($image,$NS,$AUTH); +} + /** * prints the namespace tree in the mediamanger popup * @@ -1130,10 +1183,10 @@ function tpl_mediaContent($fromajax=false){ * * @author Andreas Gohr */ -function tpl_mediaTree(){ +function tpl_mediaTree($fullscreen = false){ global $NS; - - ptln('
'); + if ($fullscreen) ptln('
'); + else ptln('
'); media_nstree($NS); ptln('
'); } @@ -1359,6 +1412,36 @@ function tpl_getFavicon($abs=false) { return DOKU_TPL.'images/favicon.ico'; } +/** + * Prints full-screen media manager + * + * @author Kate Arzamastseva + */ +function tpl_media() { + // + global $DEL, $NS, $IMG, $AUTH, $JUMPTO; + require_once(DOKU_INC.'lib/exe/mediamanager.php'); + + echo '
'; + echo '
'; + echo '
'; + html_msgarea(); + echo hsc('Namespaces:'); + echo '

'; + echo '
'; + tpl_mediaTree(true); + echo '
'; + echo '
'; + echo '
'; + tpl_fileList(); + echo '
'; + echo '
'; + tpl_fileDetails(); + echo '
'; + echo '
 
'; + echo '
'; + echo '
'; +} //Setup VIM: ex: et ts=4 : diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php index 02fde5a8d..d4ebc2d38 100644 --- a/lib/exe/mediamanager.php +++ b/lib/exe/mediamanager.php @@ -76,7 +76,11 @@ } // handle meta saving - if($IMG && $_REQUEST['do']['save']){ + if($IMG && @array_key_exists('save', $_REQUEST['do'])){ + $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']); + } + + if($IMG && @array_key_exists('save', $_REQUEST['mediado'])){ $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']); } @@ -102,9 +106,11 @@ msg(sprintf($lang['deletefail'],noNS($DEL)),-1); } } - // finished - start output - header('Content-Type: text/html; charset=utf-8'); - include(template('mediamanager.php')); + + if (!($_REQUEST['do'] == 'media')) { + header('Content-Type: text/html; charset=utf-8'); + include(template('mediamanager.php')); + } /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ diff --git a/lib/tpl/default/style.ini b/lib/tpl/default/style.ini index c5b2c31a5..bc28d1bbc 100644 --- a/lib/tpl/default/style.ini +++ b/lib/tpl/default/style.ini @@ -15,6 +15,7 @@ _mediaoptions.css = screen _admin.css = screen _linkwiz.css = screen _subscription.css = screen +mediamanager.css = screen rtl.css = rtl print.css = print -- cgit v1.2.3