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