xref: /dokuwiki/lib/exe/mediamanager.php (revision 8108113c244529ec54f11271a6a15e3d1e0a048f)
1<?php
2    if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
3    define('DOKU_MEDIAMANAGER',1);
4
5    // for multi uploader:
6    @ini_set('session.use_only_cookies',0);
7
8    require_once(DOKU_INC.'inc/init.php');
9
10    trigger_event('MEDIAMANAGER_STARTED',$tmp=array());
11    session_write_close();  //close session
12
13    // handle passed message
14    if($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')),1);
15    if($INPUT->str('err')) msg(hsc($INPUT->str('err')),-1);
16
17
18    // get namespace to display (either direct or from deletion order)
19    if($INPUT->str('delete')){
20        $DEL = cleanID($INPUT->str('delete'));
21        $IMG = $DEL;
22        $NS  = getNS($DEL);
23    }elseif($INPUT->str('edit')){
24        $IMG = cleanID($INPUT->str('edit'));
25        $NS  = getNS($IMG);
26    }elseif($INPUT->str('img')){
27        $IMG = cleanID($INPUT->str('img'));
28        $NS  = getNS($IMG);
29    }else{
30        $NS = cleanID($INPUT->str('ns'));
31    }
32
33    // check auth
34    $AUTH = auth_quickaclcheck("$NS:*");
35
36    // do not display the manager if user does not have read access
37    if($AUTH < AUTH_READ && !$fullscreen) {
38        header('HTTP/1.0 403 Forbidden');
39        die($lang['accessdenied']);
40    }
41
42    // create the given namespace (just for beautification)
43    if($AUTH >= AUTH_UPLOAD) { io_createNamespace("$NS:xxx", 'media'); }
44
45    // handle flash upload
46    if(isset($_FILES['Filedata'])){
47        $_FILES['upload'] =& $_FILES['Filedata'];
48        $JUMPTO = media_upload($NS,$AUTH);
49        if($JUMPTO == false){
50            header("HTTP/1.0 400 Bad Request");
51            echo 'Upload failed';
52        }
53        echo 'ok';
54        exit;
55    }
56
57    // give info on PHP catched upload errors
58    if($_FILES['upload']['error']){
59        switch($_FILES['upload']['error']){
60            case 1:
61            case 2:
62                msg(sprintf($lang['uploadsize'],
63                    filesize_h(php_to_byte(ini_get('upload_max_filesize')))),-1);
64                break;
65            default:
66                msg($lang['uploadfail'].' ('.$_FILES['upload']['error'].')',-1);
67        }
68        unset($_FILES['upload']);
69    }
70
71    // handle upload
72    if($_FILES['upload']['tmp_name']){
73        $JUMPTO = media_upload($NS,$AUTH);
74        if($JUMPTO) $NS = getNS($JUMPTO);
75    }
76
77    // handle meta saving
78    if($IMG && @array_key_exists('save', $INPUT->arr('do'))){
79        $JUMPTO = media_metasave($IMG,$AUTH,$INPUT->arr('meta'));
80    }
81
82    if($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) {
83        $JUMPTO = media_metasave($IMG,$AUTH,$INPUT->arr('meta'));
84    }
85
86    if ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev');
87
88    if($INPUT->str('mediado') == 'restore' && $conf['mediarevisions']){
89        $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH);
90    }
91
92    // handle deletion
93    if($DEL) {
94        $res = 0;
95        if(checkSecurityToken()) {
96            $res = media_delete($DEL,$AUTH);
97        }
98        if ($res & DOKU_MEDIA_DELETED) {
99            $msg = sprintf($lang['deletesucc'], noNS($DEL));
100            if ($res & DOKU_MEDIA_EMPTY_NS && !$fullscreen) {
101                // current namespace was removed. redirecting to root ns passing msg along
102                send_redirect(DOKU_URL.'lib/exe/mediamanager.php?msg1='.
103                        rawurlencode($msg).'&edid='.$INPUT->str('edid'));
104            }
105            msg($msg,1);
106        } elseif ($res & DOKU_MEDIA_INUSE) {
107            if(!$conf['refshow']) {
108                msg(sprintf($lang['mediainuse'],noNS($DEL)),0);
109            }
110        } else {
111            msg(sprintf($lang['deletefail'],noNS($DEL)),-1);
112        }
113    }
114    // finished - start output
115
116    if (!$fullscreen) {
117        header('Content-Type: text/html; charset=utf-8');
118        include(template('mediamanager.php'));
119    }
120
121/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
122