13df72098SAndreas Gohr<?php 23df72098SAndreas Gohr/** 33df72098SAndreas Gohr * All output and handler function needed for the media management popup 43df72098SAndreas Gohr * 53df72098SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 63df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 73df72098SAndreas Gohr */ 83df72098SAndreas Gohr 93df72098SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 103df72098SAndreas Gohrif(!defined('NL')) define('NL',"\n"); 113df72098SAndreas Gohr 123df72098SAndreas Gohrrequire_once(DOKU_INC.'inc/html.php'); 133df72098SAndreas Gohrrequire_once(DOKU_INC.'inc/search.php'); 143df72098SAndreas Gohrrequire_once(DOKU_INC.'inc/JpegMeta.php'); 153df72098SAndreas Gohr 163df72098SAndreas Gohr/** 173df72098SAndreas Gohr * Lists pages which currently use a media file selected for deletion 183df72098SAndreas Gohr * 193df72098SAndreas Gohr * References uses the same visual as search results and share 203df72098SAndreas Gohr * their CSS tags except pagenames won't be links. 213df72098SAndreas Gohr * 223df72098SAndreas Gohr * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 233df72098SAndreas Gohr */ 243df72098SAndreas Gohrfunction media_filesinuse($data,$id){ 253df72098SAndreas Gohr global $lang; 263df72098SAndreas Gohr echo '<h1>'.$lang['reference'].' <code>'.hsc(noNS($id)).'</code></h1>'; 273df72098SAndreas Gohr echo '<p>'.hsc($lang['ref_inuse']).'</p>'; 283df72098SAndreas Gohr 293df72098SAndreas Gohr $hidden=0; //count of hits without read permission 303df72098SAndreas Gohr usort($data,'sort_search_fulltext'); 313df72098SAndreas Gohr foreach($data as $row){ 323df72098SAndreas Gohr if(auth_quickaclcheck($row['id']) >= AUTH_READ){ 333df72098SAndreas Gohr echo '<div class="search_result">'; 343df72098SAndreas Gohr echo '<span class="mediaref_ref">'.$row['id'].'</span>'; 353df72098SAndreas Gohr echo ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />'; 363df72098SAndreas Gohr echo '<div class="search_snippet">'.$row['snippet'].'</div>'; 373df72098SAndreas Gohr echo '</div>'; 383df72098SAndreas Gohr }else 393df72098SAndreas Gohr $hidden++; 403df72098SAndreas Gohr } 413df72098SAndreas Gohr if ($hidden){ 423df72098SAndreas Gohr print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>'; 433df72098SAndreas Gohr } 443df72098SAndreas Gohr} 453df72098SAndreas Gohr 463df72098SAndreas Gohr/** 473df72098SAndreas Gohr * Handles the saving of image meta data 483df72098SAndreas Gohr * 493df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 503df72098SAndreas Gohr */ 513df72098SAndreas Gohrfunction media_metasave($id,$auth,$data){ 523df72098SAndreas Gohr if($auth < AUTH_UPLOAD) return false; 533df72098SAndreas Gohr global $lang; 543df72098SAndreas Gohr $src = mediaFN($id); 553df72098SAndreas Gohr 563df72098SAndreas Gohr $meta = new JpegMeta($src); 573df72098SAndreas Gohr $meta->_parseAll(); 583df72098SAndreas Gohr 593df72098SAndreas Gohr foreach($data as $key => $val){ 603df72098SAndreas Gohr $val=trim($val); 613df72098SAndreas Gohr if(empty($val)){ 623df72098SAndreas Gohr $meta->deleteField($key); 633df72098SAndreas Gohr }else{ 643df72098SAndreas Gohr $meta->setField($key,$val); 653df72098SAndreas Gohr } 663df72098SAndreas Gohr } 673df72098SAndreas Gohr 683df72098SAndreas Gohr if($meta->save()){ 693df72098SAndreas Gohr msg($lang['metasaveok'],1); 703df72098SAndreas Gohr return $id; 713df72098SAndreas Gohr }else{ 723df72098SAndreas Gohr msg($lang['metasaveerr'],-1); 733df72098SAndreas Gohr return false; 743df72098SAndreas Gohr } 753df72098SAndreas Gohr} 763df72098SAndreas Gohr 773df72098SAndreas Gohr/** 783df72098SAndreas Gohr * Display the form to edit image meta data 793df72098SAndreas Gohr * 803df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 813df72098SAndreas Gohr */ 823df72098SAndreas Gohrfunction media_metaform($id,$auth){ 833df72098SAndreas Gohr if($auth < AUTH_UPLOAD) return false; 843df72098SAndreas Gohr global $lang; 853df72098SAndreas Gohr 863df72098SAndreas Gohr // load the field descriptions 873df72098SAndreas Gohr static $fields = null; 883df72098SAndreas Gohr if(is_null($fields)){ 893df72098SAndreas Gohr include(DOKU_CONF.'mediameta.php'); 903df72098SAndreas Gohr if(@file_exists(DOKU_CONF.'mediameta.local.php')){ 913df72098SAndreas Gohr include(DOKU_CONF.'mediameta.local.php'); 923df72098SAndreas Gohr } 933df72098SAndreas Gohr } 943df72098SAndreas Gohr 953df72098SAndreas Gohr $src = mediaFN($id); 963df72098SAndreas Gohr 973df72098SAndreas Gohr // output 983df72098SAndreas Gohr echo '<h1>'.hsc(noNS($id)).'</h1>'.NL; 993df72098SAndreas Gohr echo '<form action="'.DOKU_BASE.'lib/exe/mediamanager.php" accept-charset="utf-8" method="post" class="meta">'.NL; 1003df72098SAndreas Gohr echo '<input type="hidden" name="img" value="'.hsc($id).'" />'.NL; 1013df72098SAndreas Gohr foreach($fields as $key => $field){ 1023df72098SAndreas Gohr // get current value 1033df72098SAndreas Gohr $tags = array($field[0]); 1043df72098SAndreas Gohr if(is_array($field[3])) $tags = array_merge($tags,$field[3]); 1053df72098SAndreas Gohr $value = tpl_img_getTag($tags,'',$src); 1063df72098SAndreas Gohr 1073df72098SAndreas Gohr // prepare attributes 1083df72098SAndreas Gohr $p = array(); 1093df72098SAndreas Gohr $p['class'] = 'edit'; 1103df72098SAndreas Gohr $p['id'] = 'meta__'.$key; 1113df72098SAndreas Gohr $p['name'] = 'meta['.$field[0].']'; 1123df72098SAndreas Gohr 1133df72098SAndreas Gohr // put label 1143df72098SAndreas Gohr echo '<div class="metafield">'; 1153df72098SAndreas Gohr echo '<label for="meta__'.$key.'">'; 1163df72098SAndreas Gohr echo ($lang[$field[1]]) ? $lang[$field[1]] : $field[1]; 117*cf6894dfSAndreas Gohr echo ':</label>'; 1183df72098SAndreas Gohr 1193df72098SAndreas Gohr // put input field 1203df72098SAndreas Gohr if($field[2] == 'text'){ 1213df72098SAndreas Gohr $p['value'] = $value; 1223df72098SAndreas Gohr $p['type'] = 'text'; 1233df72098SAndreas Gohr $att = buildAttributes($p); 1243df72098SAndreas Gohr echo "<input $att/>".NL; 1253df72098SAndreas Gohr }else{ 1263df72098SAndreas Gohr $att = buildAttributes($p); 1273df72098SAndreas Gohr echo "<textarea $att>".formText($value).'</textarea>'.NL; 1283df72098SAndreas Gohr } 1293df72098SAndreas Gohr echo '</div>'.NL; 1303df72098SAndreas Gohr } 1313df72098SAndreas Gohr echo '<div class="buttons">'.NL; 1323df72098SAndreas Gohr echo '<input name="do[save]" type="submit" value="'.$lang['btn_save']. 1333df72098SAndreas Gohr '" title="ALT+S" accesskey="s" class="button" />'.NL; 1343df72098SAndreas Gohr echo '<input name="do[cancel]" type="submit" value="'.$lang['btn_cancel']. 1353df72098SAndreas Gohr '" title="ALT+C" accesskey="c" class="button" />'.NL; 1363df72098SAndreas Gohr echo '</form>'.NL; 1373df72098SAndreas Gohr echo '</div>'; 1383df72098SAndreas Gohr} 1393df72098SAndreas Gohr 1403df72098SAndreas Gohr/** 1413df72098SAndreas Gohr * Handles media file deletions 1423df72098SAndreas Gohr * 1433df72098SAndreas Gohr * If configured, checks for media references before deletion 1443df72098SAndreas Gohr * 1453df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1463df72098SAndreas Gohr * @return mixed false on error, true on delete or array with refs 1473df72098SAndreas Gohr */ 1483df72098SAndreas Gohrfunction media_delete($id,$auth){ 1493df72098SAndreas Gohr if($auth < AUTH_DELETE) return false; 1503df72098SAndreas Gohr global $conf; 1513df72098SAndreas Gohr global $lang; 1523df72098SAndreas Gohr 1533df72098SAndreas Gohr $mediareferences = array(); 1543df72098SAndreas Gohr if($conf['refcheck']){ 1553df72098SAndreas Gohr search($mediareferences,$conf['datadir'],'search_reference',array('query' => $id)); 1563df72098SAndreas Gohr } 1573df72098SAndreas Gohr 1583df72098SAndreas Gohr if(!count($mediareferences)){ 1593df72098SAndreas Gohr $file = mediaFN($id); 1603df72098SAndreas Gohr if(@unlink($file)){ 1613df72098SAndreas Gohr msg(str_replace('%s',noNS($id),$lang['deletesucc']),1); 1623df72098SAndreas Gohr io_sweepNS($id,'mediadir'); 1633df72098SAndreas Gohr return true; 1643df72098SAndreas Gohr } 1653df72098SAndreas Gohr //something went wrong 1663df72098SAndreas Gohr msg(str_replace('%s',$file,$lang['deletefail']),-1); 1673df72098SAndreas Gohr return false; 1683df72098SAndreas Gohr }elseif(!$conf['refshow']){ 1693df72098SAndreas Gohr msg(str_replace('%s',noNS($id),$lang['mediainuse']),0); 1703df72098SAndreas Gohr return false; 1713df72098SAndreas Gohr } 1723df72098SAndreas Gohr 1733df72098SAndreas Gohr return $mediareferences; 1743df72098SAndreas Gohr} 1753df72098SAndreas Gohr 1763df72098SAndreas Gohr/** 1773df72098SAndreas Gohr * Handles media file uploads 1783df72098SAndreas Gohr * 1793df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1803df72098SAndreas Gohr * @return mixed false on error, id of the new file on success 1813df72098SAndreas Gohr */ 1823df72098SAndreas Gohrfunction media_upload($ns,$auth){ 1833df72098SAndreas Gohr if($auth < AUTH_UPLOAD) return false; 1843df72098SAndreas Gohr require_once(DOKU_INC.'inc/confutils.php'); 1853df72098SAndreas Gohr global $lang; 1863df72098SAndreas Gohr global $conf; 1873df72098SAndreas Gohr 1883df72098SAndreas Gohr // get file 1893df72098SAndreas Gohr $id = $_POST['id']; 1903df72098SAndreas Gohr $file = $_FILES['upload']; 1913df72098SAndreas Gohr // get id 1923df72098SAndreas Gohr if(empty($id)) $id = $file['name']; 1933df72098SAndreas Gohr $id = cleanID($ns.':'.$id); //FIXME handle relative and absolute names here 1943df72098SAndreas Gohr // get filename 1953df72098SAndreas Gohr $fn = mediaFN($id); 1963df72098SAndreas Gohr 1973df72098SAndreas Gohr // get filetype regexp 1983df72098SAndreas Gohr $types = array_keys(getMimeTypes()); 1993df72098SAndreas Gohr $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types); 2003df72098SAndreas Gohr $regex = join('|',$types); 2013df72098SAndreas Gohr 2023df72098SAndreas Gohr // because a temp file was created already 2033df72098SAndreas Gohr if(preg_match('/\.('.$regex.')$/i',$fn)){ 2043df72098SAndreas Gohr //check for overwrite 2053df72098SAndreas Gohr if(@file_exists($fn) && (!$_POST['ow'] || $auth < AUTH_DELETE)){ 2063df72098SAndreas Gohr msg($lang['uploadexist'],0); 2073df72098SAndreas Gohr return false; 2083df72098SAndreas Gohr } 2093df72098SAndreas Gohr // prepare directory 2103df72098SAndreas Gohr io_makeFileDir($fn); 2113df72098SAndreas Gohr if(move_uploaded_file($file['tmp_name'], $fn)) { 2123df72098SAndreas Gohr // set the correct permission here 2133df72098SAndreas Gohr if($conf['fperm']) chmod($fn, $conf['fperm']); 2143df72098SAndreas Gohr msg($lang['uploadsucc'],1); 2153df72098SAndreas Gohr return $id; 2163df72098SAndreas Gohr }else{ 2173df72098SAndreas Gohr msg($lang['uploadfail'],-1); 2183df72098SAndreas Gohr } 2193df72098SAndreas Gohr }else{ 2203df72098SAndreas Gohr msg($lang['uploadwrong'],-1); 2213df72098SAndreas Gohr } 2223df72098SAndreas Gohr return false; 2233df72098SAndreas Gohr} 2243df72098SAndreas Gohr 2253df72098SAndreas Gohr 2263df72098SAndreas Gohr 2273df72098SAndreas Gohr/** 2283df72098SAndreas Gohr * List all files in a given Media namespace 2293df72098SAndreas Gohr */ 2303df72098SAndreas Gohrfunction media_filelist($ns,$auth=null,$jump=''){ 2313df72098SAndreas Gohr global $conf; 2323df72098SAndreas Gohr global $lang; 2333df72098SAndreas Gohr $ns = cleanID($ns); 2343df72098SAndreas Gohr 2353df72098SAndreas Gohr // check auth our self if not given (needed for ajax calls) 2363df72098SAndreas Gohr if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*"); 2373df72098SAndreas Gohr 2383df72098SAndreas Gohr echo '<h1>:'.hsc($ns).'</h1>'.NL; 2393df72098SAndreas Gohr 2403df72098SAndreas Gohr if($auth < AUTH_READ){ 2413df72098SAndreas Gohr // FIXME: print permission warning here instead? 2423df72098SAndreas Gohr echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL; 2433df72098SAndreas Gohr return; 2443df72098SAndreas Gohr } 2453df72098SAndreas Gohr 2463df72098SAndreas Gohr media_uploadform($ns, $auth); 2473df72098SAndreas Gohr 2483df72098SAndreas Gohr $dir = utf8_encodeFN(str_replace(':','/',$ns)); 2493df72098SAndreas Gohr $data = array(); 2503df72098SAndreas Gohr search($data,$conf['mediadir'],'search_media',array(),$dir); 2513df72098SAndreas Gohr 2523df72098SAndreas Gohr if(!count($data)){ 2533df72098SAndreas Gohr echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL; 2543df72098SAndreas Gohr return; 2553df72098SAndreas Gohr } 2563df72098SAndreas Gohr 2573df72098SAndreas Gohr foreach($data as $item){ 2583df72098SAndreas Gohr media_printfile($item,$auth,$jump); 2593df72098SAndreas Gohr } 2603df72098SAndreas Gohr} 2613df72098SAndreas Gohr 2623df72098SAndreas Gohr/** 2633df72098SAndreas Gohr * Print action links for a file depending on filetype 2643df72098SAndreas Gohr * and available permissions 2653df72098SAndreas Gohr * 2663df72098SAndreas Gohr * @todo contains inline javascript 2673df72098SAndreas Gohr */ 2683df72098SAndreas Gohrfunction media_fileactions($item,$auth){ 2693df72098SAndreas Gohr global $lang; 2703df72098SAndreas Gohr 271*cf6894dfSAndreas Gohr // view button 272*cf6894dfSAndreas Gohr $link = ml($item['id'],'',true); 273*cf6894dfSAndreas Gohr echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/magnifier.png" '. 274*cf6894dfSAndreas Gohr 'alt="'.$lang['mediaview'].'" title="'.$lang['mediaview'].'" class="btn" /></a>'; 275*cf6894dfSAndreas Gohr 276*cf6894dfSAndreas Gohr 277*cf6894dfSAndreas Gohr // no further actions if not writable 2783df72098SAndreas Gohr if(!$item['writable']) return; 2793df72098SAndreas Gohr 2803df72098SAndreas Gohr // delete button 2813df72098SAndreas Gohr if($auth >= AUTH_DELETE){ 2823df72098SAndreas Gohr $ask = addslashes($lang['del_confirm']).'\\n'; 2833df72098SAndreas Gohr $ask .= addslashes($item['id']); 2843df72098SAndreas Gohr 2853df72098SAndreas Gohr echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']).'" '. 2863df72098SAndreas Gohr 'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'. 2873df72098SAndreas Gohr '<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '. 2883df72098SAndreas Gohr 'title="'.$lang['btn_delete'].'" class="btn" /></a>'; 2893df72098SAndreas Gohr } 2903df72098SAndreas Gohr 2913df72098SAndreas Gohr // edit button 2923df72098SAndreas Gohr if($auth >= AUTH_UPLOAD && $item['isimg'] && $item['meta']->getField('File.Mime') == 'image/jpeg'){ 2933df72098SAndreas Gohr echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?edit='.rawurlencode($item['id']).'">'. 2943df72098SAndreas Gohr '<img src="'.DOKU_BASE.'lib/images/pencil.png" alt="'.$lang['metaedit'].'" '. 2953df72098SAndreas Gohr 'title="'.$lang['metaedit'].'" class="btn" /></a>'; 2963df72098SAndreas Gohr } 2973df72098SAndreas Gohr 2983df72098SAndreas Gohr} 2993df72098SAndreas Gohr 3003df72098SAndreas Gohr/** 3013df72098SAndreas Gohr * Formats and prints one file in the list 3023df72098SAndreas Gohr */ 3033df72098SAndreas Gohrfunction media_printfile($item,$auth,$jump){ 30464c9cfd5SAndreas Gohr global $lang; 30564c9cfd5SAndreas Gohr 3063df72098SAndreas Gohr // Prepare zebra coloring 3073df72098SAndreas Gohr // I always wanted to use this variable name :-D 3083df72098SAndreas Gohr static $twibble = 1; 3093df72098SAndreas Gohr $twibble *= -1; 3103df72098SAndreas Gohr $zebra = ($twibble == -1) ? 'odd' : 'even'; 3113df72098SAndreas Gohr 3123df72098SAndreas Gohr // Automatically jump to recent action 3133df72098SAndreas Gohr if($jump == $item['id']) { 3143df72098SAndreas Gohr $jump = ' id="scroll__here" '; 3153df72098SAndreas Gohr }else{ 3163df72098SAndreas Gohr $jump = ''; 3173df72098SAndreas Gohr } 3183df72098SAndreas Gohr 3193df72098SAndreas Gohr // Prepare fileicons 3203df72098SAndreas Gohr list($ext,$mime) = mimetype($item['file']); 3213df72098SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 3223df72098SAndreas Gohr $class = 'select mediafile mf_'.$class; 3233df72098SAndreas Gohr 3243df72098SAndreas Gohr // Prepare filename 3253df72098SAndreas Gohr $file = utf8_decodeFN($item['file']); 3263df72098SAndreas Gohr 3273df72098SAndreas Gohr // Prepare info 3283df72098SAndreas Gohr $info = ''; 3293df72098SAndreas Gohr if($item['isimg']){ 3303df72098SAndreas Gohr $info .= (int) $item['meta']->getField('File.Width'); 3313df72098SAndreas Gohr $info .= '×'; 3323df72098SAndreas Gohr $info .= (int) $item['meta']->getField('File.Height'); 3333df72098SAndreas Gohr $info .= ' '; 3343df72098SAndreas Gohr } 3353df72098SAndreas Gohr $info .= filesize_h($item['size']); 3363df72098SAndreas Gohr 3373df72098SAndreas Gohr // ouput 3383df72098SAndreas Gohr echo '<div class="'.$zebra.'"'.$jump.'>'.NL; 3393df72098SAndreas Gohr echo '<a name="h_'.$item['id'].'" class="'.$class.'">'.$file.'</a> '; 3403df72098SAndreas Gohr echo '<span class="info">('.$info.')</span>'.NL; 3413df72098SAndreas Gohr media_fileactions($item,$auth); 34264c9cfd5SAndreas Gohr echo '<div class="example" id="ex_'.$item['id'].'">'; 34364c9cfd5SAndreas Gohr echo $lang['mediausage'].' <code>{{:'.$item['id'].'}}<code>'; 34464c9cfd5SAndreas Gohr echo '</div>'; 3453df72098SAndreas Gohr if($item['isimg']) media_printimgdetail($item); 3463df72098SAndreas Gohr echo '<div class="clearer"></div>'.NL; 3473df72098SAndreas Gohr echo '</div>'.NL; 3483df72098SAndreas Gohr} 3493df72098SAndreas Gohr 3503df72098SAndreas Gohr/** 3513df72098SAndreas Gohr * Prints a thumbnail and metainfos 3523df72098SAndreas Gohr */ 3533df72098SAndreas Gohrfunction media_printimgdetail($item){ 3543df72098SAndreas Gohr // prepare thumbnail 3553df72098SAndreas Gohr $w = (int) $item['meta']->getField('File.Width'); 3563df72098SAndreas Gohr $h = (int) $item['meta']->getField('File.Height'); 3573df72098SAndreas Gohr if($w>120 || $h>120){ 3583df72098SAndreas Gohr $ratio = $item['meta']->getResizeRatio(120); 3593df72098SAndreas Gohr $w = floor($w * $ratio); 3603df72098SAndreas Gohr $h = floor($h * $ratio); 3613df72098SAndreas Gohr } 3623df72098SAndreas Gohr $src = ml($item['id'],array('w'=>$w,'h'=>$h)); 3633df72098SAndreas Gohr $p = array(); 3643df72098SAndreas Gohr $p['width'] = $w; 3653df72098SAndreas Gohr $p['height'] = $h; 3663df72098SAndreas Gohr $p['alt'] = $item['id']; 3673df72098SAndreas Gohr $p['class'] = 'thumb'; 3683df72098SAndreas Gohr $att = buildAttributes($p); 3693df72098SAndreas Gohr 3703df72098SAndreas Gohr // output 3713df72098SAndreas Gohr echo '<div class="detail">'; 3723df72098SAndreas Gohr echo '<div class="thumb">'; 3733df72098SAndreas Gohr echo '<a name="d_'.$item['id'].'" class="select">'; 3743df72098SAndreas Gohr echo '<img src="'.$src.'" '.$att.' />'; 3753df72098SAndreas Gohr echo '</a>'; 3763df72098SAndreas Gohr echo '</div>'; 3773df72098SAndreas Gohr 3783df72098SAndreas Gohr //read EXIF/IPTC data 3793df72098SAndreas Gohr echo '<p>'; 3803df72098SAndreas Gohr $t = $item['meta']->getField('IPTC.Headline'); 3813df72098SAndreas Gohr if($t) echo '<strong>'.htmlspecialchars($t).'</strong><br />'; 3823df72098SAndreas Gohr 3833df72098SAndreas Gohr $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment', 3843df72098SAndreas Gohr 'EXIF.TIFFImageDescription', 3853df72098SAndreas Gohr 'EXIF.TIFFUserComment')); 386*cf6894dfSAndreas Gohr if(utf8_strlen($t) > 250) $t = utf8_substr($t,0,250).'...'; 3873df72098SAndreas Gohr if($t) echo htmlspecialchars($t).'<br />'; 3883df72098SAndreas Gohr 3893df72098SAndreas Gohr $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category')); 3903df72098SAndreas Gohr if($t) echo '<em>'.htmlspecialchars($t).'</em>'; 3913df72098SAndreas Gohr echo '</p>'; 3923df72098SAndreas Gohr echo '</div>'; 3933df72098SAndreas Gohr} 3943df72098SAndreas Gohr 3953df72098SAndreas Gohr/** 3963df72098SAndreas Gohr * Print the media upload form if permissions are correct 3973df72098SAndreas Gohr * 3983df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 3993df72098SAndreas Gohr */ 4003df72098SAndreas Gohrfunction media_uploadform($ns, $auth){ 4013df72098SAndreas Gohr global $lang; 4023df72098SAndreas Gohr 4033df72098SAndreas Gohr if($auth < AUTH_UPLOAD) return; //fixme print info on missing permissions? 4043df72098SAndreas Gohr 4053df72098SAndreas Gohr ?> 406*cf6894dfSAndreas Gohr <div class="upload"><?php echo $lang['mediaupload']?></div> 4073df72098SAndreas Gohr <form action="<?php echo DOKU_BASE?>lib/exe/mediamanager.php" 4083df72098SAndreas Gohr method="post" enctype="multipart/form-data" class="upload"> 4093df72098SAndreas Gohr <input type="hidden" name="ns" value="<?php echo hsc($ns)?>" /> 4103df72098SAndreas Gohr 411*cf6894dfSAndreas Gohr 4123df72098SAndreas Gohr <?php echo $lang['txt_upload']?>: 4133df72098SAndreas Gohr <input type="file" name="upload" class="edit" id="upload__file" /><br /> 4143df72098SAndreas Gohr 4153df72098SAndreas Gohr <?php echo $lang['txt_filename']?>: 4163df72098SAndreas Gohr <input type="text" name="id" class="edit" id="upload__name" /> 4173df72098SAndreas Gohr <input type="submit" class="button" value="<?php echo $lang['btn_upload']?>" accesskey="s" /> 4183df72098SAndreas Gohr 4193df72098SAndreas Gohr <?php if($auth >= AUTH_DELETE){?> 4203df72098SAndreas Gohr <br /> 4213df72098SAndreas Gohr <label for="dw__ow"> 4223df72098SAndreas Gohr <input type="checkbox" name="ow" value="1" id="dw__ow" /><?php echo $lang['txt_overwrt']?> 4233df72098SAndreas Gohr </label> 4243df72098SAndreas Gohr <?php }?> 4253df72098SAndreas Gohr </form> 4263df72098SAndreas Gohr <?php 4273df72098SAndreas Gohr} 4283df72098SAndreas Gohr 4293df72098SAndreas Gohr 4303df72098SAndreas Gohr 4313df72098SAndreas Gohr/** 4323df72098SAndreas Gohr * Build a tree outline of available media namespaces 4333df72098SAndreas Gohr * 4343df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4353df72098SAndreas Gohr */ 4363df72098SAndreas Gohrfunction media_nstree($ns){ 4373df72098SAndreas Gohr global $conf; 4383df72098SAndreas Gohr 4393df72098SAndreas Gohr // currently selected namespace 4403df72098SAndreas Gohr $ns = cleanID($ns); 4413df72098SAndreas Gohr if(empty($ns)){ 4423df72098SAndreas Gohr $ns = dirname(str_replace(':','/',$ID)); 4433df72098SAndreas Gohr if($ns == '.') $ns =''; 4443df72098SAndreas Gohr } 4453df72098SAndreas Gohr $ns = utf8_encodeFN(str_replace(':','/',$ns)); 4463df72098SAndreas Gohr 4473df72098SAndreas Gohr $data = array(); 4483df72098SAndreas Gohr search($data,$conf['mediadir'],'search_index',array('ns' => $ns)); 4493df72098SAndreas Gohr 4503df72098SAndreas Gohr // wrap a list with the root level around the other namespaces 4513df72098SAndreas Gohr $item = array( 'level' => 0, 'id' => '', 'open' =>'true', 'label' => ':*'); 4523df72098SAndreas Gohr 4533df72098SAndreas Gohr echo '<ul class="idx">'; 4543df72098SAndreas Gohr echo media_nstree_li($item); 4553df72098SAndreas Gohr echo media_nstree_item($item); 4563df72098SAndreas Gohr echo html_buildlist($data,'idx','media_nstree_item','media_nstree_li'); 4573df72098SAndreas Gohr echo '</li>'; 4583df72098SAndreas Gohr echo '</ul>'; 4593df72098SAndreas Gohr} 4603df72098SAndreas Gohr 4613df72098SAndreas Gohr/** 4623df72098SAndreas Gohr * Userfunction for html_buildlist 4633df72098SAndreas Gohr * 4643df72098SAndreas Gohr * Prints a media namespace tree item 4653df72098SAndreas Gohr * 4663df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4673df72098SAndreas Gohr */ 4683df72098SAndreas Gohrfunction media_nstree_item($item){ 4693df72098SAndreas Gohr $pos = strrpos($item['id'], ':'); 4703df72098SAndreas Gohr $label = substr($item['id'], $pos > 0 ? $pos + 1 : 0); 4713df72098SAndreas Gohr if(!$item['label']) $item['label'] = $label; 4723df72098SAndreas Gohr 4733df72098SAndreas Gohr $ret = ''; 4743df72098SAndreas Gohr $ret .= '<a href="'.DOKU_BASE.'lib/exe/mediamanager.php?ns='.idfilter($item['id']).'" class="idx_dir">'; 4753df72098SAndreas Gohr $ret .= $item['label']; 4763df72098SAndreas Gohr $ret .= '</a>'; 4773df72098SAndreas Gohr return $ret; 4783df72098SAndreas Gohr} 4793df72098SAndreas Gohr 4803df72098SAndreas Gohr/** 4813df72098SAndreas Gohr * Userfunction for html_buildlist 4823df72098SAndreas Gohr * 4833df72098SAndreas Gohr * Prints a media namespace tree item opener 4843df72098SAndreas Gohr * 4853df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4863df72098SAndreas Gohr */ 4873df72098SAndreas Gohrfunction media_nstree_li($item){ 4883df72098SAndreas Gohr $class='media level'.$item['level']; 4893df72098SAndreas Gohr if($item['open']){ 4903df72098SAndreas Gohr $class .= ' open'; 4913df72098SAndreas Gohr $img = DOKU_BASE.'lib/images/minus.gif'; 4923df72098SAndreas Gohr }else{ 4933df72098SAndreas Gohr $class .= ' closed'; 4943df72098SAndreas Gohr $img = DOKU_BASE.'lib/images/plus.gif'; 4953df72098SAndreas Gohr } 4963df72098SAndreas Gohr return '<li class="'.$class.'">'. 4973df72098SAndreas Gohr '<img src="'.$img.'" alt="*" />'; 4983df72098SAndreas Gohr} 499