diff options
Diffstat (limited to 'inc/media.php')
-rw-r--r-- | inc/media.php | 652 |
1 files changed, 617 insertions, 35 deletions
diff --git a/inc/media.php b/inc/media.php index 10da501b0..b2d608860 100644 --- a/inc/media.php +++ b/inc/media.php @@ -40,6 +40,7 @@ function media_filesinuse($data,$id){ * Handles the saving of image meta data * * @author Andreas Gohr <andi@splitbrain.org> + * @author Kate Arzamastseva <pshns@ukr.net> */ function media_metasave($id,$auth,$data){ if($auth < AUTH_UPLOAD) return false; @@ -60,8 +61,19 @@ function media_metasave($id,$auth,$data){ } } + $old = @filemtime($src); + if(!@file_exists(mediaFN($id, $old)) && @file_exists($src)) { + // add old revision to the attic + media_saveOldRevision($id); + } + if($meta->save()){ if($conf['fperm']) chmod($src, $conf['fperm']); + + $new = @filemtime($src); + // add a log entry to the media changelog + addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_EDIT, $lang['media_meta_edited']); + msg($lang['metasaveok'],1); return $id; }else{ @@ -74,11 +86,16 @@ function media_metasave($id,$auth,$data){ * Display the form to edit image meta data * * @author Andreas Gohr <andi@splitbrain.org> + * @author Kate Arzamastseva <pshns@ukr.net> */ -function media_metaform($id,$auth){ - if($auth < AUTH_UPLOAD) return false; +function media_metaform($id,$auth,$fullscreen = false){ global $lang, $config_cascade; + if($auth < AUTH_UPLOAD) { + echo '<div class="nothing">'.$lang['media_perm_upload'].'</div>'.NL; + return false; + } + // load the field descriptions static $fields = null; if(is_null($fields)){ @@ -96,8 +113,13 @@ function media_metaform($id,$auth){ $src = mediaFN($id); // output - echo '<h1>'.hsc(noNS($id)).'</h1>'.NL; - echo '<form action="'.DOKU_BASE.'lib/exe/mediamanager.php" accept-charset="utf-8" method="post" class="meta">'.NL; + if (!$fullscreen) { + echo '<h1>'.hsc(noNS($id)).'</h1>'.NL; + echo '<form action="'.DOKU_BASE.'lib/exe/mediamanager.php" accept-charset="utf-8" method="post" class="meta">'.NL; + } else { + echo '<form action="'.media_managerURL(array('tab_details' => 'view')). + '" accept-charset="utf-8" method="post" class="meta">'.NL; + } formSecurityToken(); foreach($fields as $key => $field){ // get current value @@ -132,8 +154,11 @@ function media_metaform($id,$auth){ } echo '<div class="buttons">'.NL; echo '<input type="hidden" name="img" value="'.hsc($id).'" />'.NL; - echo '<input name="do[save]" type="submit" value="'.$lang['btn_save']. + if (!$fullscreen) $do = 'do'; + else $do = 'mediado'; + echo '<input name="'.$do.'[save]" type="submit" value="'.$lang['btn_save']. '" title="'.$lang['btn_save'].' [S]" accesskey="s" class="button" />'.NL; + if (!$fullscreen) echo '<input name="do[cancel]" type="submit" value="'.$lang['btn_cancel']. '" title="'.$lang['btn_cancel'].' [C]" accesskey="c" class="button" />'.NL; echo '</div>'.NL; @@ -341,15 +366,23 @@ function _media_upload_action($data) { * * @author Andreas Gohr <andi@splitbrain.org> * @author Michael Klier <chi@chimeric.de> + * @author Kate Arzamastseva <pshns@ukr.net> */ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'move_uploaded_file') { global $conf; global $lang; + $old = @filemtime($fn); + if(!@file_exists(mediaFN($id, $old)) && @file_exists($fn)) { + // add old revision to the attic if missing + media_saveOldRevision($id); + } + // prepare directory io_createNamespace($id, 'media'); if($move($fn_tmp, $fn)) { + $new = @filemtime($fn); // Set the correct permission here. // Always chmod media because they may be saved with different permissions than expected from the php umask. // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.) @@ -358,9 +391,9 @@ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'mov media_notify($id,$fn,$imime); // add a log entry to the media changelog if ($overwrite) { - addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_EDIT); + addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_EDIT); } else { - addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_CREATE); + addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_CREATE, $lang['created']); } return $id; }else{ @@ -369,6 +402,30 @@ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'mov } /** + * Moves the current version of media file to the media_attic + * directory + * + * @author Kate Arzamastseva <pshns@ukr.net> + * @param string $id + * @return int - revision date + */ +function media_saveOldRevision($id){ + global $conf; + $oldf = mediaFN($id); + if(!@file_exists($oldf)) return ''; + $date = filemtime($oldf); + $newf = mediaFN($id,$date); + io_makeFileDir($newf); + if(copy($oldf, $newf)) { + // Set the correct permission here. + // Always chmod media because they may be saved with different permissions than expected from the php umask. + // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.) + chmod($newf, $conf['fmode']); + } + return $date; +} + +/** * This function checks if the uploaded content is really what the * mimetype says it is. We also do spam checking for text types here. * @@ -447,7 +504,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); @@ -455,13 +512,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 '<h1 id="media__ns">:'.hsc($ns).'</h1>'.NL; + if (!$fullscreenview) echo '<h1 id="media__ns">:'.hsc($ns).'</h1>'.NL; if($auth < AUTH_READ){ // FIXME: print permission warning here instead? echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL; }else{ - media_uploadform($ns, $auth); + if (!$fullscreenview) media_uploadform($ns, $auth); $dir = utf8_encodeFN(str_replace(':','/',$ns)); $data = array(); @@ -471,10 +528,409 @@ function media_filelist($ns,$auth=null,$jump=''){ if(!count($data)){ echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.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 <pshns@ukr.net> + * @param string $selected - opened tab + */ +function media_tabs_files($selected=false){ + global $lang; + + echo '<div class="mediamanager-tabs" id="id-mediamanager-tabs">'; + $tab = '<a href="'.media_managerURL(array('tab_files' => 'files')). + '" rel=".mediamanager-tab-files"'; + if (!empty($selected) && $selected == 'files') $class = 'files selected'; + else $class = 'files'; + $tab .= ' class="'.$class.'" >'.$lang['mediaselect'].'</a>'; + echo $tab; + + $tab = '<a href="'.media_managerURL(array('tab_files' => 'upload')). + '" rel=".mediamanager-tab-upload"'; + if (!empty($selected) && $selected == 'upload') $class = 'upload selected'; + else $class = 'upload'; + $tab .= ' class="'.$class.'" >'.$lang['media_uploadtab'].'</a>'; + echo $tab; + + $tab = '<a href="'.media_managerURL(array('tab_files' => 'search')). + '" rel=".mediamanager-tab-search"'; + if (!empty($selected) && $selected == 'search') $class = 'search selected'; + else $class = 'search'; + $tab .= ' class="'.$class.'" >'.$lang['media_searchtab'].'</a>'; + echo $tab; + + echo '<div class="clearer"></div>'; + echo '</div>'; +} + +/** + * Prints tabs for files details actions + * + * @author Kate Arzamastseva <pshns@ukr.net> + * @param string $selected - opened tab + */ +function media_tabs_details($selected=false){ + global $lang; + + echo '<div class="mediamanager-tabs" id="id-mediamanager-tabs-detail">'; + $tab = '<a href="'.media_managerURL(array('tab_details' => 'view')). + '" rel=".mediamanager-tab-view"'; + if (!empty($selected) && $selected == 'view') $class = 'view selected'; + else $class = 'view'; + $tab .= ' class="'.$class.'" >'.$lang['media_viewtab'].'</a>'; + echo $tab; + + $tab = '<a href="'.media_managerURL(array('tab_details' => 'edit')). + '" rel=".mediamanager-tab-edit"'; + if (!empty($selected) && $selected == 'edit') $class = 'edit selected'; + else $class = 'edit'; + $tab .= ' class="'.$class.'" >'.$lang['media_edittab'].'</a>'; + echo $tab; + + $tab = '<a href="'.media_managerURL(array('tab_details' => 'history')). + '" rel=".mediamanager-tab-history"'; + if (!empty($selected) && $selected == 'history') $class = 'history selected'; + else $class = 'history'; + $tab .= ' class="'.$class.'" >'.$lang['media_historytab'].'</a>'; + echo $tab; + + echo '<div class="clearer"></div>'; + echo '</div>'; +} + +/** + * Prints options for the tab that displays a list of all files + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_tab_files_options(){ + global $lang; + + echo '<div class="background-container">'; + echo '<div id="id-mediamanager-tabs-files" style="display: inline;">'; + echo '<a href="'.media_managerURL(array('view' => 'thumbs')).'" + rel=".mediamanager-files-thumbnails-tab" class="mediamanager-link-thumbnails">'. + $lang['media_thumbsview'].'</a>'; + echo '<a href="'.media_managerURL(array('view' => 'list')).'" + rel=".mediamanager-files-list-tab" class="mediamanager-link-list" + title="View as list">'.$lang['media_listview'].'</a>'; + + echo '</div>'; + echo '<div class="mediamanager-block-sort">'.$lang['media_sort']; + //select + echo '</div>'; + echo '<div class="clearer"></div>'; + echo '</div>'; +} + +/** + * Prints tab that displays a list of all files + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_tab_files($ns,$auth=null,$jump='') { + global $lang; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '<div class="mediamanager-tab-files">'; + media_tab_files_options(); + echo '<div class="scroll-container">'; + + $view = $_REQUEST['view']; + if($auth < AUTH_READ){ + echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL; + }else{ + if ($view == 'list') { + echo '<ul class="mediamanager-file-list mediamanager-list" id="id-mediamanager-file-list">'; + } else { + echo '<ul class="mediamanager-file-list mediamanager-thumbs" id="id-mediamanager-file-list">'; } + media_filelist($ns,$auth,$jump,'thumbs'); + echo '</ul>'; + } + echo '</div>'; + echo '</div>'; +} + +/** + * Prints tab that displays uploading form + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_tab_upload($ns,$auth=null,$jump='') { + global $lang; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '<div class="mediamanager-tab-upload"">'; + echo '<div class="background-container">'; + echo $lang['mediaupload']; + echo '</div>'; + + echo '<div class="scroll-container">'; + media_uploadform($ns, $auth, true); + echo '</div>'; + echo '</div>'; +} + +/** + * Prints tab that displays search form + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_tab_search($ns,$auth=null) { + global $lang; + + $do = $_REQUEST['mediado']; + $query = $_REQUEST['q']; + if (!$query) $query = ''; + + echo '<div class="mediamanager-tab-search">'; + echo '<div class="background-container">'; + echo $lang['media_search']; + echo'</div>'; + + echo '<div class="scroll-container">'; + media_searchform($ns, $query, true); + + if($do == 'searchlist'){ + media_searchlist($query,$ns,$auth,true); } - media_searchform($ns); + echo '</div>'; + echo '</div>'; +} + +/** + * Prints tab that displays mediafile details + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_tab_view($image, $ns, $auth=null) { + global $lang, $conf; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '<div class="mediamanager-tab-detail-view">'; + echo '<div class="background-container">'; + echo $image; + echo '</div>'; + + echo '<div class="scroll-container">'; + $rev = (int) $_REQUEST['rev']; + media_preview($image, $auth, $rev); + media_details($image, $auth, $rev); + echo '</div>'; + echo '</div>'; +} + +/** + * Prints tab that displays form for editing mediafile metadata + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_tab_edit($image, $ns, $auth=null) { + global $lang; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '<div class="mediamanager-tab-detail-edit">'; + echo '<div class="background-container">'; + echo $lang['media_edit']; + echo '</div>'; + + echo '<div class="scroll-container">'; + if ($image) { + list($ext, $mime) = mimetype($image); + if ($mime == 'image/jpeg') media_metaform($image,$auth,true); + } + echo '</div>'; + echo '</div>'; +} + +/** + * Prints tab that displays mediafile revisions + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_tab_history($image, $ns, $auth=null) { + global $lang; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + $do = $_REQUEST['mediado']; + + echo '<div class="mediamanager-tab-detail-history">'; + echo '<div class="background-container">'; + echo $lang['media_history']; + echo '</div>'; + + echo '<div class="scroll-container">'; + if ($auth >= AUTH_READ && $image) { + if ($do == 'diff'){ + media_diff($image, $ns, $auth); + } else { + $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; + html_revisions($first, $image); + } + } else { + echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL; + } + echo '</div>'; + echo '</div>'; +} + +/** + * Prints mediafile details + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_preview($image, $auth, $rev=false) { + global $lang; + if (!$image) return ''; + if ($auth < AUTH_READ) { + echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL; + return ''; + } + $info = getimagesize(mediaFN($image)); + $w = (int) $info[0]; + + $more = ''; + if ($rev) $more = "rev=$rev"; + $src = ml($image, $more); + echo '<div class="mediamanager-preview">'; + echo '<img src="'.$src.'" alt="" width="99%" style="max-width: '.$w.'px;" /><br /><br />'; + + $link = ml($image,$more,true,'&'); + + $form = new Doku_Form(array('action'=>$link, 'target'=>'_blank')); + $form->addElement(form_makeButton('submit','',$lang['mediaview'])); + $form->printForm(); + + // delete button + if($auth >= AUTH_DELETE && !$rev){ + $form = new Doku_Form(array('action'=>media_managerURL(array('delete' => $image)))); + $form->addElement(form_makeButton('submit','',$lang['btn_delete'])); + $form->printForm(); + + $form = new Doku_Form(array('action'=>media_managerURL())); + $form->addHidden('mediado','update'); + $form->addElement(form_makeButton('submit','',$lang['media_update'])); + $form->printForm(); + } + echo '</div>'; +} + +/** + * Prints mediafile tags + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_details($image, $auth, $rev=false) { + global $lang, $config_cascade;; + + if (!$image) return ''; + if ($auth < AUTH_READ) { + echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL; + return ''; + } + + // load the field descriptions + static $tags = null; + if(is_null($tags)){ + foreach (array('default','local') as $config_group) { + if (empty($config_cascade['mediameta'][$config_group])) continue; + foreach ($config_cascade['mediameta'][$config_group] as $config_file) { + if(@file_exists($config_file)){ + include($config_file); + } + } + } + } + + $src = mediaFN($image, $rev); + $meta = new JpegMeta($src); + echo '<dl class="img_tags">'; + foreach($tags as $key => $tag){ + $t = $tag[0]; + if (!is_array($t)) $t = array($tag[0]); + $value = media_getTag($t, $meta, '-'); + $value = cleanText($value); + echo '<dt>'.$lang[$tag[1]].':</dt><dd>'; + if ($tag[2] == 'text') echo hsc($value); + if ($tag[2] == 'date') echo dformat($value); + echo '</dd>'; + } + echo '</dl>'; +} + +/** + * Returns the requested EXIF/IPTC tag from the image meta + * + * @author Kate Arzamastseva <pshns@ukr.net> + * @param array $tags + * @param JpegMeta $meta + * @param string $alt + * @return string + */ +function media_getTag($tags,$meta,$alt=''){ + if($meta === false) return $alt; + $info = $meta->getField($tags); + if($info == false) return $alt; + return $info; +} + +/** + * Shows difference between two revisions of file + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_diff($image, $ns, $auth) { + global $lang; + global $conf; + + $rev1 = (int) $_REQUEST['rev']; + + if(is_array($_REQUEST['rev2'])){ + $rev1 = (int) $_REQUEST['rev2'][0]; + $rev2 = (int) $_REQUEST['rev2'][1]; + + if(!$rev1){ + $rev1 = $rev2; + unset($rev2); + } + }else{ + $rev2 = (int) $_REQUEST['rev2']; + } + if($rev1 && $rev2){ // two specific revisions wanted + // make sure order is correct (older on the left) + if($rev1 < $rev2){ + $l_rev = $rev1; + $r_rev = $rev2; + }else{ + $l_rev = $rev2; + $r_rev = $rev1; + } + }elseif($rev1){ // single revision given, compare to current + $r_rev = ''; + $l_rev = $rev1; + }else{ // no revision was given, compare previous to current + $r_rev = ''; + $revs = getRevisions($image, 0, 1, 8192, true); + $l_rev = $revs[0]; + } + echo '<ul class="mediamanager-table-50"><li><div>'; + media_preview($image, $auth, $l_rev); + echo '</div></li>'; + echo '<li><div>'; + media_preview($image, $auth, $r_rev); + echo '</div></li><li><div>'; + media_details($image, $auth, $l_rev); + echo '</div></li>'; + echo '<li><div>'; + media_details($image, $auth, $r_rev); + echo '</div></li></ul>'; } /** @@ -482,11 +938,13 @@ function media_filelist($ns,$auth=null,$jump=''){ * * @author Tobias Sarnowski <sarnowski@cosmocode.de> * @author Andreas Gohr <gohr@cosmocode.de> + * @author Kate Arzamastseva <pshns@ukr.net> * @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); if ($query) { @@ -509,13 +967,16 @@ function media_searchlist($query,$ns,$auth=null){ unset($evt); } - echo '<h1 id="media__ns">'.sprintf($lang['searchmedia_in'],hsc($ns).':*').'</h1>'.NL; - media_searchform($ns,$query); + if (!$fullscreen) { + echo '<h1 id="media__ns">'.sprintf($lang['searchmedia_in'],hsc($ns).':*').'</h1>'.NL; + media_searchform($ns,$query); + } if(!count($evdata['data'])){ echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.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); } } @@ -536,15 +997,17 @@ function media_fileactions($item,$auth){ // delete button if($auth >= AUTH_DELETE){ - echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']). - '&sectok='.getSecurityToken().'" class="btn_media_delete" title="'.$item['id'].'">'. + $link = DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']). + '&sectok='.getSecurityToken(); + echo ' <a href="'.$link.'" class="btn_media_delete" title="'.$item['id'].'">'. '<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '. 'title="'.$lang['btn_delete'].'" class="btn" /></a>'; } // edit button if($auth >= AUTH_UPLOAD && $item['isimg'] && $item['meta']->getField('File.Mime') == 'image/jpeg'){ - echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?edit='.rawurlencode($item['id']).'">'. + $link = DOKU_BASE.'lib/exe/mediamanager.php?edit='.rawurlencode($item['id']); + echo ' <a href="'.$link.'">'. '<img src="'.DOKU_BASE.'lib/images/pencil.png" alt="'.$lang['metaedit'].'" '. 'title="'.$lang['metaedit'].'" class="btn" /></a>'; } @@ -609,26 +1072,82 @@ function media_printfile($item,$auth,$jump,$display_namespace=false){ } /** + * Formats and prints one file in the list in the thumbnails view + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_printfile_thumbs($item,$auth,$jump){ + global $lang; + global $conf; + + // Prepare filename + $file = utf8_decodeFN($item['file']); + + // output + echo '<li><div>'; + if($item['isimg']) { + media_printimgdetail($item, true); + } else { + echo '<a name="d_:'.$item['id'].'" class="image" title="'.$item['id'].'" href="'. + media_managerURL(array('image' => hsc($item['id']))).'">'; + echo '<img src="'.DOKU_BASE.'lib/images/icon-file.png" width="90px" />'; + echo '</a>'; + } + //echo '<input type=checkbox />'; + echo '<a href="'.media_managerURL(array('image' => hsc($item['id']))).'" name= + "h_:'.$item['id'].'" class="name">'.hsc($file).'</a>'; + if($item['isimg']){ + $size = ''; + $size .= (int) $item['meta']->getField('File.Width'); + $size .= '×'; + $size .= (int) $item['meta']->getField('File.Height'); + echo '<span class="size">'.$size.'</span>'; + } else { + echo '<span class="size"> </span>'; + } + $date = dformat($item['mtime']); + echo '<span class="date">'.$date.'</span>'; + $filesize = filesize_h($item['size']); + echo '<span class="filesize">'.$filesize.'</span>'; + echo '<div class="clearer"></div>'; + echo '</div></li>'.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){ + if (!$fullscreen) { + $ratio = $item['meta']->getResizeRatio($size); + } else { + $ratio = $item['meta']->getResizeRatio($size,$size); + } $w = floor($w * $ratio); $h = floor($h * $ratio); } $src = ml($item['id'],array('w'=>$w,'h'=>$h)); $p = array(); $p['width'] = $w; - $p['height'] = $h; + if (!$fullscreen) $p['height'] = $h; $p['alt'] = $item['id']; $p['class'] = 'thumb'; $att = buildAttributes($p); // output + if ($fullscreen) { + echo '<a name="d_:'.$item['id'].'" class="image" title="'.$item['id'].'" href="'. + media_managerURL(array('image' => hsc($item['id']))).'">'; + echo '<img src="'.$src.'" '.$att.' />'; + echo '</a>'; + return 1; + } + echo '<div class="detail">'; echo '<div class="thumb">'; echo '<a name="d_:'.$item['id'].'" class="select">'; @@ -656,33 +1175,89 @@ function media_printimgdetail($item){ } /** + * Build link based on the current, adding/rewriting + * parameters + * + * @author Kate Arzamastseva <pshns@ukr.net> + * @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']); + unset($gets['rev']); + unset($gets['mediado']); + + if ($params) { + foreach ($params as $k => $v) { + $gets[$k] = $v; + } + } + unset($gets['id']); + if ($gets['delete']) { + unset($gets['image']); + unset($gets['tab_details']); + } + + return wl($ID,$gets,false,$amp); +} + +/** * Print the media upload form if permissions are correct * * @author Andreas Gohr <andi@splitbrain.org> + * @author Kate Arzamastseva <pshns@ukr.net> */ -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? + if($auth < AUTH_UPLOAD) { + echo '<div class="nothing">'.$lang['media_perm_upload'].'</div>'.NL; + return; + } + + $update = false; + $id = ''; + if ($auth >= AUTH_DELETE && $fullscreen && $_REQUEST['mediado'] == 'update') { + $update = true; + $id = cleanID($_REQUEST['image']); + } // 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('<div class="upload">' . $lang['mediaupload'] . '</div>'); + $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('<div class="upload">' . $lang['mediaupload'] . '</div>'); $form->addElement(formSecurityToken()); $form->addHidden('ns', hsc($ns)); $form->addElement(form_makeOpenTag('p')); $form->addElement(form_makeFileField('upload', $lang['txt_upload'].':', 'upload__file')); $form->addElement(form_makeCloseTag('p')); $form->addElement(form_makeOpenTag('p')); - $form->addElement(form_makeTextField('id', '', $lang['txt_filename'].':', 'upload__name')); + $form->addElement(form_makeTextField('id', $id, $lang['txt_filename'].':', 'upload__name')); $form->addElement(form_makeButton('submit', '', $lang['btn_upload'])); $form->addElement(form_makeCloseTag('p')); if($auth >= AUTH_DELETE){ $form->addElement(form_makeOpenTag('p')); - $form->addElement(form_makeCheckboxField('ow', 1, $lang['txt_overwrt'], 'dw__ow', 'check')); + $attrs = array(); + if ($update) $attrs['checked'] = 'checked'; + $form->addElement(form_makeCheckboxField('ow', 1, $lang['txt_overwrt'], 'dw__ow', 'check', $attrs)); $form->addElement(form_makeCloseTag('p')); } html_form('upload', $form); @@ -728,16 +1303,21 @@ function media_uploadform($ns, $auth){ * Print the search field form * * @author Tobias Sarnowski <sarnowski@cosmocode.de> + * @author Kate Arzamastseva <pshns@ukr.net> */ -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('<div class="upload">' . $lang['mediasearch'] . '</div>'); + $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('<div class="upload">' . $lang['mediasearch'] . '</div>'); $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'])); @@ -791,7 +1371,9 @@ function media_nstree_item($item){ if(!$item['label']) $item['label'] = $label; $ret = ''; + if (!($_REQUEST['do'] == 'media')) $ret .= '<a href="'.DOKU_BASE.'lib/exe/mediamanager.php?ns='.idfilter($item['id']).'" class="idx_dir">'; + else $ret .= '<a href="'.media_managerURL(array('ns' => idfilter($item['id']))).'" class="idx_dir">'; $ret .= $item['label']; $ret .= '</a>'; return $ret; |