xref: /dokuwiki/inc/media.php (revision 3df72098bbc205fa4bd4735d52d2626baad93548)
1*3df72098SAndreas Gohr<?php
2*3df72098SAndreas Gohr/**
3*3df72098SAndreas Gohr * All output and handler function needed for the media management popup
4*3df72098SAndreas Gohr *
5*3df72098SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6*3df72098SAndreas Gohr * @author     Andreas Gohr <andi@splitbrain.org>
7*3df72098SAndreas Gohr */
8*3df72098SAndreas Gohr
9*3df72098SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10*3df72098SAndreas Gohrif(!defined('NL')) define('NL',"\n");
11*3df72098SAndreas Gohr
12*3df72098SAndreas Gohrrequire_once(DOKU_INC.'inc/html.php');
13*3df72098SAndreas Gohrrequire_once(DOKU_INC.'inc/search.php');
14*3df72098SAndreas Gohrrequire_once(DOKU_INC.'inc/JpegMeta.php');
15*3df72098SAndreas Gohr
16*3df72098SAndreas Gohr/**
17*3df72098SAndreas Gohr * Lists pages which currently use a media file selected for deletion
18*3df72098SAndreas Gohr *
19*3df72098SAndreas Gohr * References uses the same visual as search results and share
20*3df72098SAndreas Gohr * their CSS tags except pagenames won't be links.
21*3df72098SAndreas Gohr *
22*3df72098SAndreas Gohr * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
23*3df72098SAndreas Gohr */
24*3df72098SAndreas Gohrfunction media_filesinuse($data,$id){
25*3df72098SAndreas Gohr    global $lang;
26*3df72098SAndreas Gohr    echo '<h1>'.$lang['reference'].' <code>'.hsc(noNS($id)).'</code></h1>';
27*3df72098SAndreas Gohr    echo '<p>'.hsc($lang['ref_inuse']).'</p>';
28*3df72098SAndreas Gohr
29*3df72098SAndreas Gohr    $hidden=0; //count of hits without read permission
30*3df72098SAndreas Gohr    usort($data,'sort_search_fulltext');
31*3df72098SAndreas Gohr    foreach($data as $row){
32*3df72098SAndreas Gohr        if(auth_quickaclcheck($row['id']) >= AUTH_READ){
33*3df72098SAndreas Gohr            echo '<div class="search_result">';
34*3df72098SAndreas Gohr            echo '<span class="mediaref_ref">'.$row['id'].'</span>';
35*3df72098SAndreas Gohr            echo ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
36*3df72098SAndreas Gohr            echo '<div class="search_snippet">'.$row['snippet'].'</div>';
37*3df72098SAndreas Gohr            echo '</div>';
38*3df72098SAndreas Gohr        }else
39*3df72098SAndreas Gohr        $hidden++;
40*3df72098SAndreas Gohr    }
41*3df72098SAndreas Gohr    if ($hidden){
42*3df72098SAndreas Gohr      print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
43*3df72098SAndreas Gohr    }
44*3df72098SAndreas Gohr}
45*3df72098SAndreas Gohr
46*3df72098SAndreas Gohr/**
47*3df72098SAndreas Gohr * Handles the saving of image meta data
48*3df72098SAndreas Gohr *
49*3df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
50*3df72098SAndreas Gohr */
51*3df72098SAndreas Gohrfunction media_metasave($id,$auth,$data){
52*3df72098SAndreas Gohr    if($auth < AUTH_UPLOAD) return false;
53*3df72098SAndreas Gohr    global $lang;
54*3df72098SAndreas Gohr    $src = mediaFN($id);
55*3df72098SAndreas Gohr
56*3df72098SAndreas Gohr    $meta = new JpegMeta($src);
57*3df72098SAndreas Gohr    $meta->_parseAll();
58*3df72098SAndreas Gohr
59*3df72098SAndreas Gohr    foreach($data as $key => $val){
60*3df72098SAndreas Gohr        $val=trim($val);
61*3df72098SAndreas Gohr        if(empty($val)){
62*3df72098SAndreas Gohr            $meta->deleteField($key);
63*3df72098SAndreas Gohr        }else{
64*3df72098SAndreas Gohr            $meta->setField($key,$val);
65*3df72098SAndreas Gohr        }
66*3df72098SAndreas Gohr    }
67*3df72098SAndreas Gohr
68*3df72098SAndreas Gohr    if($meta->save()){
69*3df72098SAndreas Gohr        msg($lang['metasaveok'],1);
70*3df72098SAndreas Gohr        return $id;
71*3df72098SAndreas Gohr    }else{
72*3df72098SAndreas Gohr        msg($lang['metasaveerr'],-1);
73*3df72098SAndreas Gohr        return false;
74*3df72098SAndreas Gohr    }
75*3df72098SAndreas Gohr}
76*3df72098SAndreas Gohr
77*3df72098SAndreas Gohr/**
78*3df72098SAndreas Gohr * Display the form to edit image meta data
79*3df72098SAndreas Gohr *
80*3df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
81*3df72098SAndreas Gohr */
82*3df72098SAndreas Gohrfunction media_metaform($id,$auth){
83*3df72098SAndreas Gohr    if($auth < AUTH_UPLOAD) return false;
84*3df72098SAndreas Gohr    global $lang;
85*3df72098SAndreas Gohr
86*3df72098SAndreas Gohr    // load the field descriptions
87*3df72098SAndreas Gohr    static $fields = null;
88*3df72098SAndreas Gohr    if(is_null($fields)){
89*3df72098SAndreas Gohr        include(DOKU_CONF.'mediameta.php');
90*3df72098SAndreas Gohr        if(@file_exists(DOKU_CONF.'mediameta.local.php')){
91*3df72098SAndreas Gohr            include(DOKU_CONF.'mediameta.local.php');
92*3df72098SAndreas Gohr        }
93*3df72098SAndreas Gohr    }
94*3df72098SAndreas Gohr
95*3df72098SAndreas Gohr    $src = mediaFN($id);
96*3df72098SAndreas Gohr
97*3df72098SAndreas Gohr    // output
98*3df72098SAndreas Gohr    echo '<h1>'.hsc(noNS($id)).'</h1>'.NL;
99*3df72098SAndreas Gohr    echo '<form action="'.DOKU_BASE.'lib/exe/mediamanager.php" accept-charset="utf-8" method="post" class="meta">'.NL;
100*3df72098SAndreas Gohr    echo '<input type="hidden" name="img" value="'.hsc($id).'" />'.NL;
101*3df72098SAndreas Gohr    foreach($fields as $key => $field){
102*3df72098SAndreas Gohr        // get current value
103*3df72098SAndreas Gohr        $tags = array($field[0]);
104*3df72098SAndreas Gohr        if(is_array($field[3])) $tags = array_merge($tags,$field[3]);
105*3df72098SAndreas Gohr        $value = tpl_img_getTag($tags,'',$src);
106*3df72098SAndreas Gohr
107*3df72098SAndreas Gohr        // prepare attributes
108*3df72098SAndreas Gohr        $p = array();
109*3df72098SAndreas Gohr        $p['class'] = 'edit';
110*3df72098SAndreas Gohr        $p['id']    = 'meta__'.$key;
111*3df72098SAndreas Gohr        $p['name']  = 'meta['.$field[0].']';
112*3df72098SAndreas Gohr
113*3df72098SAndreas Gohr        // put label
114*3df72098SAndreas Gohr        echo '<div class="metafield">';
115*3df72098SAndreas Gohr        echo '<label for="meta__'.$key.'">';
116*3df72098SAndreas Gohr        echo ($lang[$field[1]]) ? $lang[$field[1]] : $field[1];
117*3df72098SAndreas Gohr        echo '</label>';
118*3df72098SAndreas Gohr
119*3df72098SAndreas Gohr        // put input field
120*3df72098SAndreas Gohr        if($field[2] == 'text'){
121*3df72098SAndreas Gohr            $p['value'] = $value;
122*3df72098SAndreas Gohr            $p['type']  = 'text';
123*3df72098SAndreas Gohr            $att = buildAttributes($p);
124*3df72098SAndreas Gohr            echo "<input $att/>".NL;
125*3df72098SAndreas Gohr        }else{
126*3df72098SAndreas Gohr            $att = buildAttributes($p);
127*3df72098SAndreas Gohr            echo "<textarea $att>".formText($value).'</textarea>'.NL;
128*3df72098SAndreas Gohr        }
129*3df72098SAndreas Gohr        echo '</div>'.NL;
130*3df72098SAndreas Gohr    }
131*3df72098SAndreas Gohr    echo '<div class="buttons">'.NL;
132*3df72098SAndreas Gohr    echo '<input name="do[save]" type="submit" value="'.$lang['btn_save'].
133*3df72098SAndreas Gohr         '" title="ALT+S" accesskey="s" class="button" />'.NL;
134*3df72098SAndreas Gohr    echo '<input name="do[cancel]" type="submit" value="'.$lang['btn_cancel'].
135*3df72098SAndreas Gohr         '" title="ALT+C" accesskey="c" class="button" />'.NL;
136*3df72098SAndreas Gohr    echo '</form>'.NL;
137*3df72098SAndreas Gohr    echo '</div>';
138*3df72098SAndreas Gohr}
139*3df72098SAndreas Gohr
140*3df72098SAndreas Gohr/**
141*3df72098SAndreas Gohr * Handles media file deletions
142*3df72098SAndreas Gohr *
143*3df72098SAndreas Gohr * If configured, checks for media references before deletion
144*3df72098SAndreas Gohr *
145*3df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
146*3df72098SAndreas Gohr * @return mixed false on error, true on delete or array with refs
147*3df72098SAndreas Gohr */
148*3df72098SAndreas Gohrfunction media_delete($id,$auth){
149*3df72098SAndreas Gohr    if($auth < AUTH_DELETE) return false;
150*3df72098SAndreas Gohr    global $conf;
151*3df72098SAndreas Gohr    global $lang;
152*3df72098SAndreas Gohr
153*3df72098SAndreas Gohr    $mediareferences = array();
154*3df72098SAndreas Gohr    if($conf['refcheck']){
155*3df72098SAndreas Gohr        search($mediareferences,$conf['datadir'],'search_reference',array('query' => $id));
156*3df72098SAndreas Gohr    }
157*3df72098SAndreas Gohr
158*3df72098SAndreas Gohr    if(!count($mediareferences)){
159*3df72098SAndreas Gohr        $file = mediaFN($id);
160*3df72098SAndreas Gohr        if(@unlink($file)){
161*3df72098SAndreas Gohr            msg(str_replace('%s',noNS($id),$lang['deletesucc']),1);
162*3df72098SAndreas Gohr            io_sweepNS($id,'mediadir');
163*3df72098SAndreas Gohr            return true;
164*3df72098SAndreas Gohr        }
165*3df72098SAndreas Gohr        //something went wrong
166*3df72098SAndreas Gohr        msg(str_replace('%s',$file,$lang['deletefail']),-1);
167*3df72098SAndreas Gohr        return false;
168*3df72098SAndreas Gohr    }elseif(!$conf['refshow']){
169*3df72098SAndreas Gohr        msg(str_replace('%s',noNS($id),$lang['mediainuse']),0);
170*3df72098SAndreas Gohr        return false;
171*3df72098SAndreas Gohr    }
172*3df72098SAndreas Gohr
173*3df72098SAndreas Gohr    return $mediareferences;
174*3df72098SAndreas Gohr}
175*3df72098SAndreas Gohr
176*3df72098SAndreas Gohr/**
177*3df72098SAndreas Gohr * Handles media file uploads
178*3df72098SAndreas Gohr *
179*3df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
180*3df72098SAndreas Gohr * @return mixed false on error, id of the new file on success
181*3df72098SAndreas Gohr */
182*3df72098SAndreas Gohrfunction media_upload($ns,$auth){
183*3df72098SAndreas Gohr    if($auth < AUTH_UPLOAD) return false;
184*3df72098SAndreas Gohr    require_once(DOKU_INC.'inc/confutils.php');
185*3df72098SAndreas Gohr    global $lang;
186*3df72098SAndreas Gohr    global $conf;
187*3df72098SAndreas Gohr
188*3df72098SAndreas Gohr    // get file
189*3df72098SAndreas Gohr    $id   = $_POST['id'];
190*3df72098SAndreas Gohr    $file = $_FILES['upload'];
191*3df72098SAndreas Gohr    // get id
192*3df72098SAndreas Gohr    if(empty($id)) $id = $file['name'];
193*3df72098SAndreas Gohr    $id   = cleanID($ns.':'.$id);  //FIXME handle relative and absolute names here
194*3df72098SAndreas Gohr    // get filename
195*3df72098SAndreas Gohr    $fn   = mediaFN($id);
196*3df72098SAndreas Gohr
197*3df72098SAndreas Gohr    // get filetype regexp
198*3df72098SAndreas Gohr    $types = array_keys(getMimeTypes());
199*3df72098SAndreas Gohr    $types = array_map(create_function('$q','return preg_quote($q,"/");'),$types);
200*3df72098SAndreas Gohr    $regex = join('|',$types);
201*3df72098SAndreas Gohr
202*3df72098SAndreas Gohr    // because a temp file was created already
203*3df72098SAndreas Gohr    if(preg_match('/\.('.$regex.')$/i',$fn)){
204*3df72098SAndreas Gohr        //check for overwrite
205*3df72098SAndreas Gohr        if(@file_exists($fn) && (!$_POST['ow'] || $auth < AUTH_DELETE)){
206*3df72098SAndreas Gohr            msg($lang['uploadexist'],0);
207*3df72098SAndreas Gohr            return false;
208*3df72098SAndreas Gohr        }
209*3df72098SAndreas Gohr        // prepare directory
210*3df72098SAndreas Gohr        io_makeFileDir($fn);
211*3df72098SAndreas Gohr        if(move_uploaded_file($file['tmp_name'], $fn)) {
212*3df72098SAndreas Gohr            // set the correct permission here
213*3df72098SAndreas Gohr            if($conf['fperm']) chmod($fn, $conf['fperm']);
214*3df72098SAndreas Gohr            msg($lang['uploadsucc'],1);
215*3df72098SAndreas Gohr            return $id;
216*3df72098SAndreas Gohr        }else{
217*3df72098SAndreas Gohr            msg($lang['uploadfail'],-1);
218*3df72098SAndreas Gohr        }
219*3df72098SAndreas Gohr    }else{
220*3df72098SAndreas Gohr        msg($lang['uploadwrong'],-1);
221*3df72098SAndreas Gohr    }
222*3df72098SAndreas Gohr    return false;
223*3df72098SAndreas Gohr}
224*3df72098SAndreas Gohr
225*3df72098SAndreas Gohr
226*3df72098SAndreas Gohr
227*3df72098SAndreas Gohr/**
228*3df72098SAndreas Gohr * List all files in a given Media namespace
229*3df72098SAndreas Gohr */
230*3df72098SAndreas Gohrfunction media_filelist($ns,$auth=null,$jump=''){
231*3df72098SAndreas Gohr    global $conf;
232*3df72098SAndreas Gohr    global $lang;
233*3df72098SAndreas Gohr    $ns = cleanID($ns);
234*3df72098SAndreas Gohr
235*3df72098SAndreas Gohr    // check auth our self if not given (needed for ajax calls)
236*3df72098SAndreas Gohr    if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*");
237*3df72098SAndreas Gohr
238*3df72098SAndreas Gohr    echo '<h1>:'.hsc($ns).'</h1>'.NL;
239*3df72098SAndreas Gohr
240*3df72098SAndreas Gohr    if($auth < AUTH_READ){
241*3df72098SAndreas Gohr        // FIXME: print permission warning here instead?
242*3df72098SAndreas Gohr        echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL;
243*3df72098SAndreas Gohr        return;
244*3df72098SAndreas Gohr    }
245*3df72098SAndreas Gohr
246*3df72098SAndreas Gohr    media_uploadform($ns, $auth);
247*3df72098SAndreas Gohr
248*3df72098SAndreas Gohr    $dir = utf8_encodeFN(str_replace(':','/',$ns));
249*3df72098SAndreas Gohr    $data = array();
250*3df72098SAndreas Gohr    search($data,$conf['mediadir'],'search_media',array(),$dir);
251*3df72098SAndreas Gohr
252*3df72098SAndreas Gohr    if(!count($data)){
253*3df72098SAndreas Gohr        echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL;
254*3df72098SAndreas Gohr        return;
255*3df72098SAndreas Gohr    }
256*3df72098SAndreas Gohr
257*3df72098SAndreas Gohr    foreach($data as $item){
258*3df72098SAndreas Gohr        media_printfile($item,$auth,$jump);
259*3df72098SAndreas Gohr    }
260*3df72098SAndreas Gohr}
261*3df72098SAndreas Gohr
262*3df72098SAndreas Gohr/**
263*3df72098SAndreas Gohr * Print action links for a file depending on filetype
264*3df72098SAndreas Gohr * and available permissions
265*3df72098SAndreas Gohr *
266*3df72098SAndreas Gohr * @todo contains inline javascript
267*3df72098SAndreas Gohr */
268*3df72098SAndreas Gohrfunction media_fileactions($item,$auth){
269*3df72098SAndreas Gohr    global $lang;
270*3df72098SAndreas Gohr
271*3df72098SAndreas Gohr    // no actions if not writable
272*3df72098SAndreas Gohr    if(!$item['writable']) return;
273*3df72098SAndreas Gohr
274*3df72098SAndreas Gohr    // delete button
275*3df72098SAndreas Gohr    if($auth >= AUTH_DELETE){
276*3df72098SAndreas Gohr        $ask  = addslashes($lang['del_confirm']).'\\n';
277*3df72098SAndreas Gohr        $ask .= addslashes($item['id']);
278*3df72098SAndreas Gohr
279*3df72098SAndreas Gohr        echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']).'" '.
280*3df72098SAndreas Gohr             'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'.
281*3df72098SAndreas Gohr             '<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '.
282*3df72098SAndreas Gohr             'title="'.$lang['btn_delete'].'" class="btn" /></a>';
283*3df72098SAndreas Gohr    }
284*3df72098SAndreas Gohr
285*3df72098SAndreas Gohr    // edit button
286*3df72098SAndreas Gohr    if($auth >= AUTH_UPLOAD && $item['isimg'] && $item['meta']->getField('File.Mime') == 'image/jpeg'){
287*3df72098SAndreas Gohr        echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?edit='.rawurlencode($item['id']).'">'.
288*3df72098SAndreas Gohr             '<img src="'.DOKU_BASE.'lib/images/pencil.png" alt="'.$lang['metaedit'].'" '.
289*3df72098SAndreas Gohr             'title="'.$lang['metaedit'].'" class="btn" /></a>';
290*3df72098SAndreas Gohr    }
291*3df72098SAndreas Gohr
292*3df72098SAndreas Gohr}
293*3df72098SAndreas Gohr
294*3df72098SAndreas Gohr/**
295*3df72098SAndreas Gohr * Formats and prints one file in the list
296*3df72098SAndreas Gohr */
297*3df72098SAndreas Gohrfunction media_printfile($item,$auth,$jump){
298*3df72098SAndreas Gohr    // Prepare zebra coloring
299*3df72098SAndreas Gohr    // I always wanted to use this variable name :-D
300*3df72098SAndreas Gohr    static $twibble = 1;
301*3df72098SAndreas Gohr    $twibble *= -1;
302*3df72098SAndreas Gohr    $zebra = ($twibble == -1) ? 'odd' : 'even';
303*3df72098SAndreas Gohr
304*3df72098SAndreas Gohr    // Automatically jump to recent action
305*3df72098SAndreas Gohr    if($jump == $item['id']) {
306*3df72098SAndreas Gohr        $jump = ' id="scroll__here" ';
307*3df72098SAndreas Gohr    }else{
308*3df72098SAndreas Gohr        $jump = '';
309*3df72098SAndreas Gohr    }
310*3df72098SAndreas Gohr
311*3df72098SAndreas Gohr    // Prepare fileicons
312*3df72098SAndreas Gohr    list($ext,$mime) = mimetype($item['file']);
313*3df72098SAndreas Gohr    $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
314*3df72098SAndreas Gohr    $class = 'select mediafile mf_'.$class;
315*3df72098SAndreas Gohr
316*3df72098SAndreas Gohr    // Prepare filename
317*3df72098SAndreas Gohr    $file = utf8_decodeFN($item['file']);
318*3df72098SAndreas Gohr
319*3df72098SAndreas Gohr    // Prepare info
320*3df72098SAndreas Gohr    $info = '';
321*3df72098SAndreas Gohr    if($item['isimg']){
322*3df72098SAndreas Gohr        $info .= (int) $item['meta']->getField('File.Width');
323*3df72098SAndreas Gohr        $info .= '&#215;';
324*3df72098SAndreas Gohr        $info .= (int) $item['meta']->getField('File.Height');
325*3df72098SAndreas Gohr        $info .= ' ';
326*3df72098SAndreas Gohr    }
327*3df72098SAndreas Gohr    $info .= filesize_h($item['size']);
328*3df72098SAndreas Gohr
329*3df72098SAndreas Gohr    // ouput
330*3df72098SAndreas Gohr    echo '<div class="'.$zebra.'"'.$jump.'>'.NL;
331*3df72098SAndreas Gohr    echo '<a name="h_'.$item['id'].'" class="'.$class.'">'.$file.'</a> ';
332*3df72098SAndreas Gohr    echo '<span class="info">('.$info.')</span>'.NL;
333*3df72098SAndreas Gohr    media_fileactions($item,$auth);
334*3df72098SAndreas Gohr    if($item['isimg']) media_printimgdetail($item);
335*3df72098SAndreas Gohr    echo '<div class="clearer"></div>'.NL;
336*3df72098SAndreas Gohr    echo '</div>'.NL;
337*3df72098SAndreas Gohr}
338*3df72098SAndreas Gohr
339*3df72098SAndreas Gohr/**
340*3df72098SAndreas Gohr * Prints a thumbnail and metainfos
341*3df72098SAndreas Gohr */
342*3df72098SAndreas Gohrfunction media_printimgdetail($item){
343*3df72098SAndreas Gohr    // prepare thumbnail
344*3df72098SAndreas Gohr    $w = (int) $item['meta']->getField('File.Width');
345*3df72098SAndreas Gohr    $h = (int) $item['meta']->getField('File.Height');
346*3df72098SAndreas Gohr    if($w>120 || $h>120){
347*3df72098SAndreas Gohr        $ratio = $item['meta']->getResizeRatio(120);
348*3df72098SAndreas Gohr        $w = floor($w * $ratio);
349*3df72098SAndreas Gohr        $h = floor($h * $ratio);
350*3df72098SAndreas Gohr    }
351*3df72098SAndreas Gohr    $src = ml($item['id'],array('w'=>$w,'h'=>$h));
352*3df72098SAndreas Gohr    $p = array();
353*3df72098SAndreas Gohr    $p['width']  = $w;
354*3df72098SAndreas Gohr    $p['height'] = $h;
355*3df72098SAndreas Gohr    $p['alt']    = $item['id'];
356*3df72098SAndreas Gohr    $p['class']  = 'thumb';
357*3df72098SAndreas Gohr    $att = buildAttributes($p);
358*3df72098SAndreas Gohr
359*3df72098SAndreas Gohr    // output
360*3df72098SAndreas Gohr    echo '<div class="detail">';
361*3df72098SAndreas Gohr    echo '<div class="thumb">';
362*3df72098SAndreas Gohr    echo '<a name="d_'.$item['id'].'" class="select">';
363*3df72098SAndreas Gohr    echo '<img src="'.$src.'" '.$att.' />';
364*3df72098SAndreas Gohr    echo '</a>';
365*3df72098SAndreas Gohr    echo '</div>';
366*3df72098SAndreas Gohr
367*3df72098SAndreas Gohr    //read EXIF/IPTC data
368*3df72098SAndreas Gohr    echo '<p>';
369*3df72098SAndreas Gohr    $t = $item['meta']->getField('IPTC.Headline');
370*3df72098SAndreas Gohr    if($t) echo '<strong>'.htmlspecialchars($t).'</strong><br />';
371*3df72098SAndreas Gohr
372*3df72098SAndreas Gohr    $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment',
373*3df72098SAndreas Gohr                                       'EXIF.TIFFImageDescription',
374*3df72098SAndreas Gohr                                       'EXIF.TIFFUserComment'));
375*3df72098SAndreas Gohr    if($t) echo htmlspecialchars($t).'<br />';
376*3df72098SAndreas Gohr
377*3df72098SAndreas Gohr    $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category'));
378*3df72098SAndreas Gohr    if($t) echo '<em>'.htmlspecialchars($t).'</em>';
379*3df72098SAndreas Gohr    echo '</p>';
380*3df72098SAndreas Gohr    echo '</div>';
381*3df72098SAndreas Gohr}
382*3df72098SAndreas Gohr
383*3df72098SAndreas Gohr/**
384*3df72098SAndreas Gohr * Print the media upload form if permissions are correct
385*3df72098SAndreas Gohr *
386*3df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
387*3df72098SAndreas Gohr */
388*3df72098SAndreas Gohrfunction media_uploadform($ns, $auth){
389*3df72098SAndreas Gohr    global $lang;
390*3df72098SAndreas Gohr
391*3df72098SAndreas Gohr    if($auth < AUTH_UPLOAD) return; //fixme print info on missing permissions?
392*3df72098SAndreas Gohr
393*3df72098SAndreas Gohr    ?>
394*3df72098SAndreas Gohr    <form action="<?php echo DOKU_BASE?>lib/exe/mediamanager.php"
395*3df72098SAndreas Gohr          method="post" enctype="multipart/form-data" class="upload">
396*3df72098SAndreas Gohr        <input type="hidden" name="ns" value="<?php echo hsc($ns)?>" />
397*3df72098SAndreas Gohr
398*3df72098SAndreas Gohr        <?php echo $lang['txt_upload']?>:
399*3df72098SAndreas Gohr        <input type="file" name="upload" class="edit" id="upload__file" /><br />
400*3df72098SAndreas Gohr
401*3df72098SAndreas Gohr        <?php echo $lang['txt_filename']?>:
402*3df72098SAndreas Gohr        <input type="text" name="id" class="edit" id="upload__name" />
403*3df72098SAndreas Gohr        <input type="submit" class="button" value="<?php echo $lang['btn_upload']?>" accesskey="s" />
404*3df72098SAndreas Gohr
405*3df72098SAndreas Gohr        <?php if($auth >= AUTH_DELETE){?>
406*3df72098SAndreas Gohr            <br />
407*3df72098SAndreas Gohr            <label for="dw__ow">
408*3df72098SAndreas Gohr            <input type="checkbox" name="ow" value="1" id="dw__ow" /><?php echo $lang['txt_overwrt']?>
409*3df72098SAndreas Gohr            </label>
410*3df72098SAndreas Gohr        <?php }?>
411*3df72098SAndreas Gohr    </form>
412*3df72098SAndreas Gohr    <?php
413*3df72098SAndreas Gohr}
414*3df72098SAndreas Gohr
415*3df72098SAndreas Gohr
416*3df72098SAndreas Gohr
417*3df72098SAndreas Gohr/**
418*3df72098SAndreas Gohr * Build a tree outline of available media namespaces
419*3df72098SAndreas Gohr *
420*3df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
421*3df72098SAndreas Gohr */
422*3df72098SAndreas Gohrfunction media_nstree($ns){
423*3df72098SAndreas Gohr    global $conf;
424*3df72098SAndreas Gohr
425*3df72098SAndreas Gohr    // currently selected namespace
426*3df72098SAndreas Gohr    $ns  = cleanID($ns);
427*3df72098SAndreas Gohr    if(empty($ns)){
428*3df72098SAndreas Gohr        $ns = dirname(str_replace(':','/',$ID));
429*3df72098SAndreas Gohr        if($ns == '.') $ns ='';
430*3df72098SAndreas Gohr    }
431*3df72098SAndreas Gohr    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
432*3df72098SAndreas Gohr
433*3df72098SAndreas Gohr    $data = array();
434*3df72098SAndreas Gohr    search($data,$conf['mediadir'],'search_index',array('ns' => $ns));
435*3df72098SAndreas Gohr
436*3df72098SAndreas Gohr    // wrap a list with the root level around the other namespaces
437*3df72098SAndreas Gohr    $item = array( 'level' => 0, 'id' => '', 'open' =>'true', 'label' => ':*');
438*3df72098SAndreas Gohr
439*3df72098SAndreas Gohr    echo '<ul class="idx">';
440*3df72098SAndreas Gohr    echo media_nstree_li($item);
441*3df72098SAndreas Gohr    echo media_nstree_item($item);
442*3df72098SAndreas Gohr    echo html_buildlist($data,'idx','media_nstree_item','media_nstree_li');
443*3df72098SAndreas Gohr    echo '</li>';
444*3df72098SAndreas Gohr    echo '</ul>';
445*3df72098SAndreas Gohr}
446*3df72098SAndreas Gohr
447*3df72098SAndreas Gohr/**
448*3df72098SAndreas Gohr * Userfunction for html_buildlist
449*3df72098SAndreas Gohr *
450*3df72098SAndreas Gohr * Prints a media namespace tree item
451*3df72098SAndreas Gohr *
452*3df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
453*3df72098SAndreas Gohr */
454*3df72098SAndreas Gohrfunction media_nstree_item($item){
455*3df72098SAndreas Gohr    $pos   = strrpos($item['id'], ':');
456*3df72098SAndreas Gohr    $label = substr($item['id'], $pos > 0 ? $pos + 1 : 0);
457*3df72098SAndreas Gohr    if(!$item['label']) $item['label'] = $label;
458*3df72098SAndreas Gohr
459*3df72098SAndreas Gohr    $ret  = '';
460*3df72098SAndreas Gohr    $ret .= '<a href="'.DOKU_BASE.'lib/exe/mediamanager.php?ns='.idfilter($item['id']).'" class="idx_dir">';
461*3df72098SAndreas Gohr    $ret .= $item['label'];
462*3df72098SAndreas Gohr    $ret .= '</a>';
463*3df72098SAndreas Gohr    return $ret;
464*3df72098SAndreas Gohr}
465*3df72098SAndreas Gohr
466*3df72098SAndreas Gohr/**
467*3df72098SAndreas Gohr * Userfunction for html_buildlist
468*3df72098SAndreas Gohr *
469*3df72098SAndreas Gohr * Prints a media namespace tree item opener
470*3df72098SAndreas Gohr *
471*3df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
472*3df72098SAndreas Gohr */
473*3df72098SAndreas Gohrfunction media_nstree_li($item){
474*3df72098SAndreas Gohr    $class='media level'.$item['level'];
475*3df72098SAndreas Gohr    if($item['open']){
476*3df72098SAndreas Gohr        $class .= ' open';
477*3df72098SAndreas Gohr        $img   = DOKU_BASE.'lib/images/minus.gif';
478*3df72098SAndreas Gohr    }else{
479*3df72098SAndreas Gohr        $class .= ' closed';
480*3df72098SAndreas Gohr        $img   = DOKU_BASE.'lib/images/plus.gif';
481*3df72098SAndreas Gohr    }
482*3df72098SAndreas Gohr    return '<li class="'.$class.'">'.
483*3df72098SAndreas Gohr           '<img src="'.$img.'" alt="*" />';
484*3df72098SAndreas Gohr}
485