1<?php
2/**
3 * DokuWiki Plugin PreserveFilenames / action_adorabelle.php
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author  Kazutaka Miyasaka <kazmiya@gmail.com>
7 */
8
9// must be run within DokuWiki
10if (!defined('DOKU_INC')) {
11    die();
12}
13
14if (!defined('DOKU_PLUGIN')) {
15    define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
16}
17
18require_once(DOKU_PLUGIN . 'preservefilenames/common.php');
19require_once(DOKU_PLUGIN . 'preservefilenames/action_angua.php');
20
21class action_plugin_preservefilenames_adorabelle extends action_plugin_preservefilenames_angua
22{
23    // -------------------------------------------------------
24    // The following methods whose name starts with '_mod' are
25    // slightly modified versions of existing functions.
26    // -------------------------------------------------------
27
28    /**
29     * Formats and prints one file in the list
30     *
31     * @see media_printfile()
32     */
33    function _mod_media_printfile($item,$auth,$jump,$display_namespace=false){
34        global $lang;
35        global $conf;
36
37        // Prepare zebra coloring
38        // I always wanted to use this variable name :-D
39        static $twibble = 1;
40        $twibble *= -1;
41        $zebra = ($twibble == -1) ? 'odd' : 'even';
42
43        // Automatically jump to recent action
44        if($jump == $item['id']) {
45            $jump = ' id="scroll__here" ';
46        }else{
47            $jump = '';
48        }
49
50        // Prepare fileicons
51        list($ext,$mime,$dl) = mimetype($item['file'],false);
52        $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
53        $class = 'select mediafile mf_'.$class;
54
55        // Prepare filename
56        $file = $this->_getOriginalFileName($item['id']);
57
58        if ($file === false) {
59            $file = utf8_decodeFN($item['file']);
60        }
61
62        // build fake media id
63        $ns = getNS($item['id']);
64        $fakeId = $ns === false ? $file : "$ns:$file";
65        $fakeId_escaped = hsc($fakeId);
66
67        // Prepare info
68        $info = '';
69        if($item['isimg']){
70            $info .= (int) $item['meta']->getField('File.Width');
71            $info .= '&#215;';
72            $info .= (int) $item['meta']->getField('File.Height');
73            $info .= ' ';
74        }
75        $info .= '<i>'.dformat($item['mtime']).'</i>';
76        $info .= ' ';
77        $info .= filesize_h($item['size']);
78
79        // output
80        echo '<div class="'.$zebra.'"'.$jump.' title="'.$fakeId_escaped.'">'.NL;
81        if (!$display_namespace) {
82            echo '<a id="h_:'.$item['id'].'" class="'.$class.'">'.hsc($file).'</a> ';
83        } else {
84            echo '<a id="h_:'.$item['id'].'" class="'.$class.'">'.$fakeId_escaped.'</a><br/>';
85        }
86        echo '<span class="info">('.$info.')</span>'.NL;
87
88        // view button
89        $link = ml($fakeId,'',true);
90        echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/magnifier.png" '.
91            'alt="'.$lang['mediaview'].'" title="'.$lang['mediaview'].'" class="btn" /></a>';
92
93        // mediamanager button
94        $link = wl('',array('do'=>'media','image'=>$fakeId,'ns'=>$ns));
95        echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/mediamanager.png" '.
96            'alt="'.$lang['btn_media'].'" title="'.$lang['btn_media'].'" class="btn" /></a>';
97
98        // delete button
99        if($item['writable'] && $auth >= AUTH_DELETE){
100            $link = DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($fakeId).
101                '&amp;sectok='.getSecurityToken();
102            echo ' <a href="'.$link.'" class="btn_media_delete" title="'.$fakeId_escaped.'">'.
103                '<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '.
104                'title="'.$lang['btn_delete'].'" class="btn" /></a>';
105        }
106
107        echo '<div class="example" id="ex_'.str_replace(':','_',$item['id']).'">';
108        echo $lang['mediausage'].' <code>{{:'.str_replace(array('{','}'),array('(',')'),$fakeId_escaped).'}}</code>';
109        echo '</div>';
110        if($item['isimg']) media_printimgdetail($item);
111        echo '<div class="clearer"></div>'.NL;
112        echo '</div>'.NL;
113    }
114
115    /**
116     * Formats and prints one file in the list in the thumbnails view
117     *
118     * @see media_printfile_thumbs()
119     */
120    function _mod_media_printfile_thumbs($item,$auth,$jump=false,$display_namespace=false){
121        global $lang;
122        global $conf;
123
124        // Prepare filename
125        $file = $this->_getOriginalFileName($item['id']);
126
127        if ($file === false) {
128            $file = utf8_decodeFN($item['file']);
129        }
130
131        // build fake media id
132        $ns = getNS($item['id']);
133        $fakeId = $ns === false ? $file : "$ns:$file";
134        $fakeId_escaped = hsc($fakeId);
135
136        // output
137        echo '<li><dl title="'.$fakeId_escaped.'">'.NL;
138
139            echo '<dt>';
140        if($item['isimg']) {
141            media_printimgdetail($item, true);
142
143        } else {
144            echo '<a id="d_:'.$item['id'].'" class="image" title="'.$fakeId_escaped.'" href="'.
145                media_managerURL(array('image' => $fakeId, 'ns' => $ns,
146                'tab_details' => 'view')).'">';
147            echo media_printicon($fakeId_escaped);
148            echo '</a>';
149        }
150        echo '</dt>'.NL;
151        if (!$display_namespace) {
152            $name = hsc($file);
153        } else {
154            $name = $fakeId_escaped;
155        }
156        echo '<dd class="name"><a href="'.media_managerURL(array('image' => $fakeId, 'ns' => $ns,
157            'tab_details' => 'view')).'" id="h_:'.$item['id'].'">'.$name.'</a></dd>'.NL;
158
159        if($item['isimg']){
160            $size = '';
161            $size .= (int) $item['meta']->getField('File.Width');
162            $size .= '&#215;';
163            $size .= (int) $item['meta']->getField('File.Height');
164            echo '<dd class="size">'.$size.'</dd>'.NL;
165        } else {
166            echo '<dd class="size">&#160;</dd>'.NL;
167        }
168        $date = dformat($item['mtime']);
169        echo '<dd class="date">'.$date.'</dd>'.NL;
170        $filesize = filesize_h($item['size']);
171        echo '<dd class="filesize">'.$filesize.'</dd>'.NL;
172        echo '</dl></li>'.NL;
173    }
174}
175