1<?php
2/**
3 * DokuWiki Plugin prettyphoto (Renderer Component)
4 *
5 * @license Public Domain
6 * @author  Marcus von Appen <marcus@sysfault.org>
7 */
8
9class renderer_plugin_prettyphoto extends Doku_Renderer_xhtml {
10
11    /**
12     * Make available as XHTML replacement renderer
13     */
14    public function canRender($format){
15        if ($format === 'xhtml') {
16            return true;
17        }
18        return false;
19    }
20
21    public function internalmedia($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL,
22                                  $cache=NULL, $linking=NULL, $return=false) {
23        global $ID;
24        list($src,$hash) = explode('#',$src,2);
25        resolve_mediaid(getNS($ID),$src, $exists);
26
27        $noLink = false;
28        $render = ($linking === 'linkonly') ? false : true;
29        $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
30
31        list($ext,$mime,$dl) = mimetype($src,false);
32        if (substr($mime,0,5) === 'image' && $render) {
33            if ($linking === NULL || $linking === '' || $linking === 'details') {
34                $linking = 'direct';
35            }
36            $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), ($linking === 'direct'));
37        } else if ($mime === 'application/x-shockwave-flash' && $render) {
38            // don't link flash movies
39            $noLink = true;
40        } else {
41            // add file icons
42            $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
43            $link['class'] .= ' mediafile mf_'.$class;
44            $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), true);
45            if ($exists) {
46                $link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))).')';
47            }
48        }
49
50        if($hash) $link['url'] .= '#'.$hash;
51        //markup non existing files
52        if (!$exists) {
53            $link['class'] .= ' wikilink2';
54        }
55
56        //output formatted
57        if ($linking == 'nolink' || $noLink) {
58            $this->doc .= $link['name'];
59        } else {
60            $this->doc .= $this->_formatLink($link);
61        }
62    }
63
64    // FIXME override any methods of Doku_Renderer_xhtml here
65}
66