8000 dokuwiki/inc/media.php at linkwizard · alexlehm/dokuwiki · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
2216 lines (1939 loc) · 65.6 KB

media.php

File metadata and controls

2216 lines (1939 loc) · 65.6 KB
<?php
/**
* All output and handler function needed for the media management popup
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) die('meh.');
if(!defined('NL')) define('NL',"\n");
/**
* Lists pages which currently use a media file selected for deletion
*
* References uses the same visual as search results and share
* their CSS tags except pagenames won't be links.
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function media_filesinuse($data,$id){
global $lang;
echo '<h1>'.$lang['reference'].' <code>'.hsc(noNS($id)).'</code></h1>';
echo '<p>'.hsc($lang['ref_inuse']).'</p>';
$hidden=0; //count of hits without read permission
foreach($data as $row){
if(auth_quickaclcheck($row) >= AUTH_READ && isVisiblePage($row)){
echo '<div class="search_result">';
echo '<span class="mediaref_ref">'.hsc($row).'</span>';
echo '</div>';
}else
$hidden++;
}
if ($hidden){
print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
}
}
/**
* 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;
if(!checkSecurityToken()) return false;
global $lang;
global $conf;
$src = mediaFN($id);
$meta = new JpegMeta($src);
$meta->_parseAll();
foreach($data as $key => $val){
$val=trim($val);
if(empty($val)){
$meta->deleteField($key);
}else{
$meta->setField($key,$val);
}
}
$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{
msg($lang['metasaveerr'],-1);
return false;
}
}
/**
* check if a media is external source
*
* @author Gerrit Uitslag <klapinklapin@gmail.com>
* @param string $id the media ID or URL
* @return bool
*/
function media_isexternal($id){
if (preg_match('#^(?:https?|ftp)://#i', $id)) return true;
return false;
}
/**
* Check if a media item is public (eg, external URL or readable by @ALL)
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $id the media ID or URL
* @return bool
*/
function media_ispublic($id){
if(media_isexternal($id)) return true;
$id = cleanID($id);
if(auth_aclcheck(getNS($id).':*', '', array()) >= AUTH_READ) return true;
return false;
}
/**
* 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){
global $lang;
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)){
$config_files = getConfigFiles('mediameta');
foreach ($config_files as $config_file) {
if(@file_exists($config_file)) include($config_file);
}
}
$src = mediaFN($id);
// output
$form = new Doku_Form(array('action' => media_managerURL(array('tab_details' => 'view'), '&'),
'class' => 'meta'));
$form->addHidden('img', $id);
$form->addHidden('mediado', 'save');
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);
$value = cleanText($value);
// prepare attributes
$p = array();
$p['class'] = 'edit';
$p['id'] = 'meta__'.$key;
$p['name'] = 'meta['.$field[0].']';
$p_attrs = array('class' => 'edit');
$form->addElement('<div class="row">');
if($field[2] == 'text'){
$form->addElement(form_makeField('text', $p['name'], $value, ($lang[$field[1]]) ? $lang[$field[1]] : $field[1] . ':', $p['id'], $p['class'], $p_attrs));
}else{
$att = buildAttributes($p);
$form->addElement('<label for="meta__'.$key.'">'.$lang[$field[1]].'</label>');
$form->addElement("<textarea $att rows=\"6\" cols=\"50\">".formText($value).'</textarea>');
}
$form->addElement('</div>'.NL);
}
$form->addElement('<div class="buttons">');
$form->addElement(form_makeButton('submit', '', $lang['btn_save'], array('accesskey' => 's', 'name' => 'mediado[save]')));
$form->addElement('</div>'.NL);
$form->printForm();
return true;
}
/**
* Convenience function to check if a media file is still in use
*
* @author Michael Klier <chi@chimeric.de>
*/
function media_inuse($id) {
global $conf;
if($conf['refcheck']){
$mediareferences = ft_mediause($id,true);
if(!count($mediareferences)) {
return false;
} else {
return $mediareferences;
}
} else {
return false;
}
}
define('DOKU_MEDIA_DELETED', 1);
define('DOKU_MEDIA_NOT_AUTH', 2);
define('DOKU_MEDIA_INUSE', 4);
define('DOKU_MEDIA_EMPTY_NS', 8);
/**
* Handles media file deletions
*
* If configured, checks for media references before deletion
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $id media id
* @param int $auth current auth check result
* @return int One of: 0,
* DOKU_MEDIA_DELETED,
* DOKU_MEDIA_DELETED | DOKU_MEDIA_EMPTY_NS,
* DOKU_MEDIA_NOT_AUTH,
* 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;
$file = mediaFN($id);
// trigger an event - MEDIA_DELETE_FILE
$data['id'] = $id;
$data['name'] = utf8_basename($file);
$data['path'] = $file;
$data['size'] = (@file_exists($file)) ? filesize($file) : 0;
$data['unl'] = false;
$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, $lang['deleted']);
$data['del'] = io_sweepNS($id,'mediadir');
}
}
$evt->advise_after();
unset($evt);
if($data['unl'] && $data['del']){
return DOKU_MEDIA_DELETED | DOKU_MEDIA_EMPTY_NS;
}
return $data['unl'] ? DOKU_MEDIA_DELETED : 0;
}
/**
* Handle file uploads via XMLHttpRequest
*
* @param string $ns target namespace
* @param int $auth current auth check result
* @return mixed false on error, id of the new file on success
*/
function media_upload_xhr($ns,$auth){
if(!checkSecurityToken()) return false;
global $INPUT;
$id = $INPUT->get->str('qqfile');
list($ext,$mime) = mimetype($id);
$input = fopen("php://input", "r");
if (!($tmp = io_mktmpdir())) return false;
$path = $tmp.'/'.md5($id);
$target = fopen($path, "w");
$realSize = stream_copy_to_stream($input, $target);
fclose($target);
fclose($input);
if (isset($_SERVER["CONTENT_LENGTH"]) && ($realSize != (int)$_SERVER["CONTENT_LENGTH"])){
unlink($path);
return false;
}
$res = media_save(
array('name' => $path,
'mime' => $mime,
'ext' => $ext),
$ns.':'.$id,
(($INPUT->get->str('ow') == 'checked') ? true : false),
$auth,
'copy'
);
unlink($path);
if ($tmp) io_rmdir($tmp, true);
if (is_array($res)) {
msg($res[0], $res[1]);
return false;
}
return $res;
}
/**
* Handles media file uploads
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Michael Klier <chi@chimeric.de>
* @param string $ns target namespace
* @param int $auth current auth check result
* @param bool|array $file $_FILES member, $_FILES['upload'] if false
* @return mixed false on error, id of the new file on success
*/
function media_upload($ns,$auth,$file=false){
if(!checkSecurityToken()) return false;
global $lang;
global $INPUT;
// get file and id
$id = $INPUT->post->str('mediaid');
if (!$file) $file = $_FILES['upload'];
if(empty($id)) $id = $file['name'];
// check for errors (messages are done in lib/exe/mediamanager.php)
if($file['error']) return false;
// check extensions
list($fext,$fmime) = mimetype($file['name']);
list($iext,$imime) = mimetype($id);
if($fext && !$iext){
// no extension specified in id - read original one
$id .= '.'.$fext;
$imime = $fmime;
}elseif($fext && $fext != $iext){
// extension was changed, print warning
msg(sprintf($lang['mediaextchange'],$fext,$iext));
}
$res = media_save(array('name' => $file['tmp_name'],
'mime' => $imime,
'ext' => $iext), $ns.':'.$id,
$INPUT->post->bool('ow'), $auth, 'copy_uploaded_file');
if (is_array($res)) {
msg($res[0], $res[1]);
return false;
}
return $res;
}
/**
* An alternative to move_uploaded_file that copies
*
* Using copy, makes sure any setgid bits on the media directory are honored
*
* @see move_uploaded_file()
* @param string $from
* @param string $to
* @return bool
*/
function copy_uploaded_file($from, $to){
if(!is_uploaded_file($from)) return false;
$ok = copy($from, $to);
@unlink($from);
return $ok;
}
/**
* This generates an action event and delegates to _media_upload_action().
* Action plugins are allowed to pre/postprocess the uploaded file.
* (The triggered event is preventable.)
*
* Event data:
* $data[0] fn_tmp: the temporary file name (read from $_FILES)
* $data[1] fn: the file name of the uploaded file
* $data[2] id: the future directory id of the uploaded file
* $data[3] imime: the mimetype of the uploaded file
* $data[4] overwrite: if an existing file is going to be overwritten
*
* @triggers MEDIA_UPLOAD_FINISH
*/
function media_save($file, $id, $ow, $auth, $move) {
if($auth < AUTH_UPLOAD) {
return array("You don't have permissions to upload files.", -1);
}
if (!isset($file['mime']) || !isset($file['ext'])) {
list($ext, $mime) = mimetype($id);
if (!isset($file['mime'])) {
$file['mime'] = $mime;
}
if (!isset($file['ext'])) {
$file['ext'] = $ext;
}
}
global $lang, $conf;
// get filename
$id = cleanID($id);
$fn = mediaFN($id);
// get filetype regexp
$types = array_keys(getMimeTypes());
$types = array_map(create_function('$q','return preg_quote($q,"/");'),$types);
$regex = join('|',$types);
// because a temp file was created already
if(!preg_match('/\.('.$regex.')$/i',$fn)) {
return array($lang['uploadwrong'],-1);
}
//check for overwrite
$overwrite = @file_exists($fn);
$auth_ow = (($conf['mediarevisions']) ? AUTH_UPLOAD : AUTH_DELETE);
if($overwrite && (!$ow || $auth < $auth_ow)) {
return array($lang['uploadexist'], 0);
}
// check for valid content
$ok = media_contentcheck($file['name'], $file['mime']);
if($ok == -1){
return array(sprintf($lang['uploadbadcontent'],'.' . $file['ext']),-1);
}elseif($ok == -2){
return array($lang['uploadspam'],-1);
}elseif($ok == -3){
return array($lang['uploadxss'],-1);
}
// prepare event data
$data[0] = $file['name'];
$data[1] = $fn;
$data[2] = $id;
$data[3] = $file['mime'];
$data[4] = $overwrite;
$data[5] = $move;
// trigger event
return trigger_event('MEDIA_UPLOAD_FINISH', $data, '_media_upload_action', true);
}
/**
* Callback adapter for media_upload_finish()
* @author Michael Klier <chi@chimeric.de>
*/
function _media_upload_action($data) {
// fixme do further sanity tests of given data?
if(is_array($data) && count($data)===6) {
return media_upload_finish($data[0], $data[1], $data[2], $data[3], $data[4], $data[5]);
} else {
return false; //callback error
}
}
/**
* Saves an uploaded media file
*
* @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.)
chmod($fn, $conf['fmode']);
msg($lang['uploadsucc'],1);
media_notify($id,$fn,$imime,$old);
// add a log entry to the media changelog
if ($REV){
addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_REVERT, sprintf($lang['restored'], dformat($REV)), $REV);
} elseif ($overwrite) {
addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_EDIT);
} else {
addMediaLogEntry($new, $id, DOKU_CHANGE_TYPE_CREATE, $lang['created']);
}
return $id;
}else{
return array($lang['uploadfail'],-1);
}
}
/**
* 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, $lang;
$oldf = mediaFN($id);
if(!@file_exists($oldf)) return '';
$date = filemtime($oldf);
if (!$conf['mediarevisions']) return $date;
if (!getRevisionInfo($id, $date, 8192, true)) {
// there was an external edit,
// there is no log entry for current version of file
if (!@file_exists(mediaMetaFN($id,'.changes'))) {
addMediaLogEntry($date, $id, DOKU_CHANGE_TYPE_CREATE, $lang['created']);
} else {
addMediaLogEntry($date, $id, DOKU_CHANGE_TYPE_EDIT);
}
}
$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.
*
* We need to do this stuff because we can not rely on the browser
* to do this check correctly. Yes, IE is broken as usual.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @link http://www.splitbrain.org/blog/2007-02/12-internet_explorer_facilitates_cross_site_scripting
* @fixme check all 26 magic IE filetypes here?
*/
function media_contentcheck($file,$mime){
global $conf;
if($conf['iexssprotect']){
$fh = @fopen($file, 'rb');
if($fh){
$bytes = fread($fh, 256);
fclose($fh);
if(preg_match('/<(script|a|img|html|body|iframe)[\s>]/i',$bytes)){
return -3;
}
}
}
if(substr($mime,0,6) == 'image/'){
$info = @getimagesize($file);
if($mime == 'image/gif' && $info[2] != 1){
return -1;
}elseif($mime == 'image/jpeg' && $info[2] != 2){
return -1;
}elseif($mime == 'image/png' && $info[2] != 3){
return -1;
}
# fixme maybe check other images types as well
}elseif(substr($mime,0,5) == 'text/'){
global $TEXT;
$TEXT = io_readFile($file);
if(checkwordblock()){
return -2;
}
}
return 0;
}
/**
* Send a notify mail on uploads
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function media_notify($id,$file,$mime,$old_rev=false){
global $conf;
if(empty($conf['notify'])) return false; //notify enabled?
$subscription = new Subscription();
return $subscription->send_media_diff($conf['notify'], 'uploadmail', $id, $old_rev);
}
/**
* List all files in a given Media namespace
*/
function media_filelist($ns,$auth=null,$jump='',$fullscreenview=false,$sort=false){
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:*");
if (!$fullscreenview) echo & 10BC8 #039;<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{
if (!$fullscreenview) {
media_uploadform($ns, $auth);
media_searchform($ns);
}
$dir = utf8_encodeFN(str_replace(':','/',$ns));
$data = array();
search($data,$conf['mediadir'],'search_media',
array('showmsg'=>true,'depth'=>1),$dir,1,$sort);
if(!count($data)){
echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL;
}else {
if ($fullscreenview) {
echo '<ul class="' . _media_get_list_type() . '">';
}
foreach($data as $item){
if (!$fullscreenview) {
media_printfile($item,$auth,$jump);
} else {
media_printfile_thumbs($item,$auth,$jump);
}
}
if ($fullscreenview) echo '</ul>'.NL;
}
}
}
/**
* Prints tabs for files list actions
*
* @author Kate Arzamastseva <pshns@ukr.net>
* @author Adrian Lang <mail@adrianlang.de>
*
* @param string $selected_tab - opened tab
*/
function media_tabs_files($selected_tab = ''){
global $lang;
$tabs = array();
foreach(array('files' => 'mediaselect',
'upload' => 'media_uploadtab',
'search' => 'media_searchtab') as $tab => $caption) {
$tabs[$tab] = array('href' => media_managerURL(array('tab_files' => $tab), '&'),
'caption' => $lang[$caption]);
}
html_tabs($tabs, $selected_tab);
}
/**
* Prints tabs for files details actions
*
* @author Kate Arzamastseva <pshns@ukr.net>
* @param string $image filename of the current image
* @param string $selected_tab opened tab
*/
function media_tabs_details($image, $selected_tab = ''){
global $lang, $conf;
$tabs = array();
$tabs['view'] = array('href' => media_managerURL(array('tab_details' => 'view'), '&'),
'caption' => $lang['media_viewtab']);
list(, $mime) = mimetype($image);
if ($mime == 'image/jpeg' && @file_exists(mediaFN($image))) {
$tabs['edit'] = array('href' => media_managerURL(array('tab_details' => 'edit'), '&'),
'caption' => $lang['media_edittab']);
}
if ($conf['mediarevisions']) {
$tabs['history'] = array('href' => media_managerURL(array('tab_details' => 'history'), '&'),
'caption' => $lang['media_historytab']);
}
html_tabs($tabs, $selected_tab);
}
/**
* 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;
global $INPUT;
global $ID;
$form = new Doku_Form(array('class' => 'options', 'method' => 'get',
'action' => wl($ID)));
$media_manager_params = media_managerURL(array(), '', false, true);
foreach($media_manager_params as $pKey => $pVal){
$form->addHidden($pKey, $pVal);
}
$form->addHidden('sectok', null);
if ($INPUT->has('q')) {
$form->addHidden('q', $INPUT->str('q'));
}
$form->addElement('<ul>'.NL);
foreach(array('list' => array('listType', array('thumbs', 'rows')),
'sort' => array('sortBy', array('name', 'date')))
as $group => $content) {
$checked = "_media_get_${group}_type";
$checked = $checked();
$form->addElement('<li class="' . $content[0] . '">');
foreach($content[1] as $option) {
$attrs = array();
if ($checked == $option) {
$attrs['checked'] = 'checked';
}
$form->addElement(form_makeRadioField($group . '_dwmedia', $option,
$lang['media_' . $group . '_' . $option],
$content[0] . '__' . $option,
$option, $attrs));
}
$form->addElement('</li>'.NL);
}
$form->addElement('<li>');
$form->addElement(form_makeButton('submit', '', $lang['btn_apply']));
$form->addElement('</li>'.NL);
$form->addElement('</ul>'.NL);
$form->printForm();
}
/**
* Returns type of sorting for the list of files in media manager
*
* @author Kate Arzamastseva <pshns@ukr.net>
* @return string - sort type
*/
function _media_get_sort_type() {
return _media_get_display_param('sort', array('default' => 'name', 'date'));
}
/**
* Returns type of listing for the list of files in media manager
*
* @author Kate Arzamastseva <pshns@ukr.net>
* @return string - list type
*/
function _media_get_list_type() {
return _media_get_display_param('list', array('default' => 'thumbs', 'rows'));
}
/**
* Get display parameters
*
* @param string $param name of parameter
* @param array $values allowed values, where default value has index key 'default'
* @return string the parameter value
*/
function _media_get_display_param($param, $values) {
global $INPUT;
if (in_array($INPUT->str($param), $values)) {
// FIXME: Set cookie
return $INPUT->str($param);
} else {
$val = get_doku_pref($param, $values['default']);
if (!in_array($val, $values)) {
$val = $values['default'];
}
return $val;
}
}
/**
* 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:*");
if($auth < AUTH_READ){
echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL;
}else{
media_filelist($ns,$auth,$jump,true,_media_get_sort_type());
}
}
/**
* 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="upload">'.NL;
if ($auth >= AUTH_UPLOAD) {
echo '<p>' . $lang['mediaupload'] . '</p>';
}
media_uploadform($ns, $auth, true);
echo '</div>'.NL;
}
/**
* Prints tab that displays search form
*
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_tab_search($ns,$auth=null) {
global $INPUT;
$do = $INPUT->str('mediado');
$query = $INPUT->str('q');
echo '<div class="search">'.NL;
media_searchform($ns, $query, true);
if ($do == 'searchlist' || $query) {
media_searchlist($query,$ns,$auth,true,_media_get_sort_type());
}
echo '</div>'.NL;
}
/**
* Prints tab that displays mediafile details
*
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_tab_view($image, $ns, $auth=null, $rev=false) {
global $lang;
if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*");
if ($image && $auth >= AUTH_READ) {
$meta = new JpegMeta(mediaFN($image, $rev));
media_preview($image, $auth, $rev, $meta);
media_preview_buttons($image, $auth, $rev);
media_details($image, $auth, $rev, $meta);
} else {
echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL;
}
}
/**
* Prints tab that displays form for editing mediafile metadata
*
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_tab_edit($image, $ns, $auth=null) {
if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*");
if ($image) {
list(, $mime) = mimetype($image);
if ($mime == 'image/jpeg') media_metaform($image,$auth);
}
}
/**
* Prints tab that displays mediafile revisions
*
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_tab_history($image, $ns, $auth=null) {
global $lang;
global $INPUT;
if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*");
$do = $INPUT->str('mediado');
if ($auth >= AUTH_READ && $image) {
if ($do == 'diff'){
media_diff($image, $ns, $auth);
} else {
$first = $INPUT->int('first');
html_revisions($first, $image);
}
} else {
echo '<div class="nothing">'.$lang['media_perm_read'].'</div>'.NL;
}
}
/**
* Prints mediafile details
*
* @param string $image media id
* @param $auth
* @param int|bool $rev
* @param JpegMeta|bool $meta
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_preview($image, $auth, $rev=false, $meta=false) {
$size = media_image_preview_size($image, $rev, $meta);
if ($size) {
global $lang;
echo '<div class="image">';
$more = array();
if ($rev) {
$more['rev'] = $rev;
} else {
$t = @filemtime(mediaFN($image));
$more['t'] = $t;
}
$more['w'] = $size[0];
$more['h'] = $size[1];
$src = ml($image, $more);
echo '<a href="'.$src.'" target="_blank" title="'.$lang['mediaview'].'">';
echo '<img src="'.$src.'" alt="" style="max-width: '.$size[0].'px;" />';
echo '</a>';
echo '</div>'.NL;
}
}
/**
* Prints mediafile action buttons
*
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function media_preview_buttons($image, $auth, $rev=false) {
global $lang, $conf;
echo '<ul class="actions">'.NL;
if($auth >= AUTH_DELETE && !$rev && @file_exists(mediaFN($image))){
// delete button
$form = new Doku_Form(array('id' => 'mediamanager__btn_delete',
'action'=>media_managerURL(array('delete' => $image), '&')));
$form->addElement(form_makeButton('submit','',$lang['btn_delete']));
echo '<li>';
$form->printForm();
echo '</li>'.NL;
}
$auth_ow = (($conf['mediarevisions']) ? AUTH_UPLOAD : AUTH_DELETE);
if($auth >= $auth_ow && !$rev){
// upload new version button
$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']));
echo '<li>';
$form->printForm();
echo '</li>'.NL;
}
if($auth >= AUTH_UPLOAD && $rev && $conf['mediarevisions'] && @file_exists(mediaFN($image, $rev))){
// restore button
$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']));
echo '<li>';
$form->printForm();
echo '</li>'.NL;
}
echo '</ul>'.NL;
}
/**
* Returns image width and height for mediamanager preview panel
*
* @author Kate Arzamastseva <pshns@ukr.net>
* @param string $image
* @param int $rev
* @param JpegMeta $meta
* @param int $size
* @return array
*/
function media_image_preview_size($image, $rev, $meta, $size = 500) {
if (!preg_match("/\.(jpe?g|gif|png)$/", $image) || !file_exists(mediaFN($image, $rev))) return false;
$info = getimagesize(mediaFN($image, $rev));
$w = (int) $info[0];
$h = (int) $info[1];
if($meta && ($w > $size || $h > $size)){
$ratio = $meta->getResizeRatio($size, $size);
$w = floor($w * $ratio);
$h = floor($h * $ratio);
}
return array($w, $h);
}
/**
* 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;
}
/**
* Returns mediafile tags
0