diff options
Diffstat (limited to 'inc/media.php')
-rw-r--r-- | inc/media.php | 769 |
1 files changed, 722 insertions, 47 deletions
diff --git a/inc/media.php b/inc/media.php index 731ba1668..138eb26c2 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,33 +86,40 @@ 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)){ - - 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); - } - } + $config_files = getConfigFiles('mediameta'); + foreach ($config_files as $config_file) { + if(@file_exists($config_file)) include($config_file); } } $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; + $action = DOKU_BASE.'lib/exe/mediamanager.php'; + } else { + $action = media_managerURL(array('tab_details' => 'view'), '&'); + } + echo '<form action="'.$action.'" id="mediamanager__save_meta" accept-charset="utf-8" method="post" class="meta">'.NL; + formSecurityToken(); foreach($fields as $key => $field){ // get current value + if (empty($field[0])) continue; $tags = array($field[0]); if(is_array($field[3])) $tags = array_merge($tags,$field[3]); $value = tpl_img_getTag($tags,'',$src); @@ -132,8 +151,15 @@ 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 { + echo '<input type="hidden" name="mediado" value="save" />'; + $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; @@ -178,6 +204,7 @@ define('DOKU_MEDIA_EMPTY_NS', 8); DOKU_MEDIA_INUSE */ function media_delete($id,$auth){ + global $lang; if($auth < AUTH_DELETE) return DOKU_MEDIA_NOT_AUTH; if(media_inuse($id)) return DOKU_MEDIA_INUSE; @@ -193,9 +220,15 @@ function media_delete($id,$auth){ $data['del'] = false; $evt = new Doku_Event('MEDIA_DELETE_FILE',$data); if ($evt->advise_before()) { + $old = @filemtime($file); + if(!@file_exists(mediaFN($id, $old)) && @file_exists($file)) { + // add old revision to the attic + media_saveOldRevision($id); + } + $data['unl'] = @unlink($file); if($data['unl']){ - addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_DELETE); + addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_DELETE, $lang['deleted']); $data['del'] = io_sweepNS($id,'mediadir'); } } @@ -221,7 +254,7 @@ function media_upload($ns,$auth){ global $lang; // get file and id - $id = $_POST['id']; + $id = $_POST['mediaid']; $file = $_FILES['upload']; if(empty($id)) $id = $file['name']; @@ -341,15 +374,25 @@ 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; + global $REV; + + $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)) { + @clearstatcache(true,$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.) @@ -357,10 +400,12 @@ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'mov msg($lang['uploadsucc'],1); media_notify($id,$fn,$imime); // add a log entry to the media changelog - if ($overwrite) { - addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_EDIT); + if ($REV){ + addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_REVERT, $lang['restored'], $REV); + } elseif ($overwrite) { + 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 +414,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 +516,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 +524,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 +540,477 @@ 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 media_printfile_thumbs($item,$auth,$jump); } } - media_searchform($ns); + 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="mediamanager__tabs_files">'; + + media_tab(media_managerURL(array('tab_files' => 'files')), 'files', $lang['mediaselect'], $selected); + media_tab(media_managerURL(array('tab_files' => 'upload')), 'upload', $lang['media_uploadtab'], $selected); + media_tab(media_managerURL(array('tab_files' => 'search')), 'search', $lang['media_searchtab'], $selected); + + echo '<div class="clearer"></div>'; + echo '</div>'; +} + +/** + * Prints mediamanager tab + * + * @author Kate Arzamastseva <pshns@ukr.net> + * @param string $link + * @param string $class + * @param string $name + * @param string $selected + */ +function media_tab($link, $class, $name, $selected=false) { + if (!empty($selected) && $selected == $class) $class .= ' selected'; + $tab = '<a href="'.$link.'" class="'.$class.'" >'.$name.'</a>'; + echo $tab; +} + +/** + * Prints tabs for files details actions + * + * @author Kate Arzamastseva <pshns@ukr.net> + * @param string $selected - opened tab + */ +function media_tabs_details($image, $selected=false){ + global $lang; + + echo '<div class="mediamanager-tabs" id="mediamanager__tabs_details">'; + + media_tab(media_managerURL(array('tab_details' => 'view')), 'view', $lang['media_viewtab'], $selected); + + list($ext, $mime) = mimetype($image); + if ($mime == 'image/jpeg') { + media_tab(media_managerURL(array('tab_details' => 'edit')), 'edit', $lang['media_edittab'], $selected); + } + media_tab(media_managerURL(array('tab_details' => 'history')), 'history', $lang['media_historytab'], $selected); + + 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($ns){ + global $lang; + + echo '<div class="background-container">'; + echo $ns; + echo '<div id="mediamanager__tabs_list" 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:*"); + + media_tab_files_options($ns); + + 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="mediamanager__file_list">'; + } else { + echo '<ul class="mediamanager-file-list mediamanager-thumbs" id="mediamanager__file_list">'; + } + media_filelist($ns,$auth,$jump,true); + echo '</ul>'; + } + 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="background-container">'; + echo sprintf($lang['media_upload'], $ns); + echo '</div>'; + + echo '<div class="scroll-container">'; + if ($auth >= AUTH_UPLOAD) echo '<div class="upload">' . $lang['mediaupload'] . '</div>'; + media_uploadform($ns, $auth, true); + 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="background-container">'; + echo sprintf($lang['media_search'], $ns); + echo'</div>'; + + echo '<div class="scroll-container">'; + media_searchform($ns, $query, true); + + if($do == 'searchlist'){ + $view = $_REQUEST['view']; + if ($view == 'list') { + echo '<ul class="mediamanager-file-list mediamanager-list" id="mediamanager__file_list">'; + } else { + echo '<ul class="mediamanager-file-list mediamanager-thumbs" id="mediamanager__file_list">'; + } + media_searchlist($query,$ns,$auth,true); + echo '</ul>'; + } + echo '</div>'; +} + +/** + * Prints tab that displays mediafile details + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_tab_view($image, $ns, $auth=null, $rev=false) { + global $lang, $conf; + if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); + + echo '<div class="background-container">'; + list($ext,$mime,$dl) = mimetype($image,false); + $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); + $class = 'select mediafile mf_'.$class; + echo '<a class="'.$class.'" >'.$image.'</a>'; + echo '</div>'; + + echo '<div class="scroll-container">'; + $meta = new JpegMeta(mediaFN($image, $rev)); + media_preview($image, $auth, $rev, $meta); + media_details($image, $auth, $rev, $meta); + 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="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>'; +} + +/** + * 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="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>'; +} + +/** + * Prints mediafile details + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_preview($image, $auth, $rev=false, $meta=false) { + global $lang; + if (!$image) return ''; + if ($auth < AUTH_READ) { + echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL; + return ''; + } + + echo '<div class="mediamanager-preview">'; + + $more = ''; + if ($rev) { + $more = "rev=$rev"; + } else { + $t = @filemtime(mediaFN($image)); + $more = "t=$t"; + } + $link = ml($image,$more,true,'&'); + + if (preg_match("/\.(jpe?g|gif|png)$/", $image)) { + $info = getimagesize(mediaFN($image, $rev)); + $w = (int) $info[0]; + $h = (int) $info[1]; + + $size = 500; + if($meta && ($w > $size || $h > $size)){ + $ratio = $meta->getResizeRatio($size, $size); + $w = floor($w * $ratio); + $h = floor($h * $ratio); + $more .= "&h=$h&w=$w"; + } + + $src = ml($image, $more); + echo '<img src="'.$src.'" alt="" width="99%" style="max-width: '.$w.'px;" /><br /><br />'; + } + + $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('id' => 'mediamanager__btn_delete', + 'action'=>media_managerURL(array('delete' => $image), '&'))); + $form->addElement(form_makeButton('submit','',$lang['btn_delete'])); + $form->printForm(); + + $form = new Doku_Form(array('id' => 'mediamanager__btn_update', + 'action'=>media_managerURL(array('image' => $image, 'mediado' => 'update'), '&'))); + $form->addElement(form_makeButton('submit','',$lang['media_update'])); + $form->printForm(); + } + if($auth >= AUTH_DELETE && $rev){ + $form = new Doku_Form(array('id' => 'mediamanager__btn_restore', + 'action'=>media_managerURL(array('image' => $image), '&'))); + $form->addHidden('mediado','restore'); + $form->addHidden('rev',$rev); + $form->addElement(form_makeButton('submit','',$lang['media_restore'])); + $form->printForm(); + } + echo '</div>'; +} + +/** + * Prints mediafile tags + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_details($image, $auth, $rev=false, $meta=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 $fields = null; + if(is_null($fields)){ + $config_files = getConfigFiles('mediameta'); + foreach ($config_files as $config_file) { + if(@file_exists($config_file)) include($config_file); + } + } + + if (!$meta) $meta = new JpegMeta(mediaFN($image, $rev)); + + echo '<dl class="img_tags">'; + foreach($fields as $key => $tag){ + $t = array(); + if (!empty($tag[0])) $t = array($tag[0]); + if(is_array($tag[3])) $t = array_merge($t,$tag[3]); + $value = media_getTag($t, $meta, '-'); + $value = cleanText($value); + echo '<dt>'.$lang[$tag[1]].':</dt><dd>'; + if ($tag[2] == 'date') echo dformat($value); + else echo hsc($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]; + } + + // prepare event data + $data[0] = $image; + $data[1] = $l_rev; + $data[2] = $r_rev; + $data[3] = $ns; + $data[4] = $auth; + + // trigger event + return trigger_event('MEDIA_DIFF', $data, '_media_image_diff', true); + +} + +function _media_image_diff($data) { + if(is_array($data) && count($data)===5) { + return media_image_diff($data[0], $data[1], $data[2], $data[3], $data[4]); + } else { + return false; + } +} + +/** + * Shows difference between two revisions of image + * + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_image_diff($image, $l_rev, $r_rev, $ns, $auth){ + $l_meta = new JpegMeta(mediaFN($image, $l_rev)); + $r_meta = new JpegMeta(mediaFN($image, $r_rev)); + + echo '<ul class="mediamanager-table-50"><li><div>'; + media_preview($image, $auth, $l_rev, $l_meta); + echo '</div></li>'; + echo '<li><div>'; + media_preview($image, $auth, $r_rev, $r_meta); + echo '</div></li><li><div>'; + media_details($image, $auth, $l_rev, $l_meta); + echo '</div></li>'; + echo '<li><div>'; + media_details($image, $auth, $r_rev, $r_meta); + echo '</div></li></ul>'; +} + +/** + * Restores an old revision of a media file + * + * @param string $image + * @param int $rev + * @param int $auth + * @return string - file's id + * @author Kate Arzamastseva <pshns@ukr.net> + */ +function media_restore($image, $rev, $auth){ + if ($auth < AUTH_DELETE) return false; + if (!$image || !file_exists(mediaFN($image))) return false; + if (!$rev || !file_exists(mediaFN($image, $rev))) return false; + list($iext,$imime,$dl) = mimetype($image); + $res = media_upload_finish(mediaFN($image, $rev), + mediaFN($image), + $image, + $imime, + true, + 'copy'); + if (is_array($res)) { + msg($res[0], $res[1]); + return false; + } + return $res; } /** @@ -482,11 +1018,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 +1047,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']); } } @@ -536,15 +1077,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>'; } @@ -608,27 +1151,98 @@ function media_printfile($item,$auth,$jump,$display_namespace=false){ echo '</div>'.NL; } +function media_printicon($filename){ + list($ext,$mime,$dl) = mimetype(mediaFN($filename),false); + + if (@file_exists(DOKU_INC.'lib/images/fileicons/'.$ext.'.png')) { + $icon = DOKU_BASE.'lib/images/fileicons/'.$ext.'.png'; + } else { + $icon = DOKU_BASE.'lib/images/fileicons/file.png'; + } + + echo '<img src="'.$icon.'" alt="'.$filename.'" class="icon" />'; + +} + +/** + * 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=false){ + 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']))).'"><div>'; + media_printicon($item['id']); + echo '</div></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)); + $src = ml($item['id'],array('w'=>$w,'h'=>$h,'t'=>$item['mtime'])); $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 '<div><img src="'.$src.'" '.$att.' /></div>'; + echo '</a>'; + return 1; + } + echo '<div class="detail">'; echo '<div class="thumb">'; echo '<a name="d_:'.$item['id'].'" class="select">'; @@ -656,33 +1270,86 @@ 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; + + $gets = array('do' => 'media'); + $media_manager_params = array('tab_files', 'tab_details', 'image', 'ns', 'view'); + foreach ($media_manager_params as $x) { + if (isset($_REQUEST[$x])) $gets[$x] = $_REQUEST[$x]; + } + + 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', + 'tab_details' => 'view'), '&'); + } + + $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('mediaid', noNS($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 +1395,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(array(), '&'); + $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'])); @@ -786,7 +1458,10 @@ 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']), 'tab_files' => 'files')) + .'" class="idx_dir">'; $ret .= $item['label']; $ret .= '</a>'; return $ret; |