xref: /dokuwiki/lib/exe/mediamanager.php (revision 620404a5dcfbccb29cd939932ecaead95b6e24cd)
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    require_once(DOKU_INC.'inc/lang/en/lang.php');
10    require_once(DOKU_INC.'inc/lang/'.$conf['lang'].'/lang.php');
11    require_once(DOKU_INC.'inc/media.php');
12    require_once(DOKU_INC.'inc/common.php');
13    require_once(DOKU_INC.'inc/search.php');
14    require_once(DOKU_INC.'inc/template.php');
15    require_once(DOKU_INC.'inc/auth.php');
16
17    trigger_event('MEDIAMANAGER_STARTED',$tmp=array());
18    session_write_close();  //close session
19
20    // handle passed message
21    if($_REQUEST['msg1']) msg(hsc($_REQUEST['msg1']),1);
22    if($_REQUEST['err']) msg(hsc($_REQUEST['err']),-1);
23
24
25    // get namespace to display (either direct or from deletion order)
26    if($_REQUEST['delete']){
27        $DEL = cleanID($_REQUEST['delete']);
28        $IMG = $DEL;
29        $NS  = getNS($DEL);
30    }elseif($_REQUEST['edit']){
31        $IMG = cleanID($_REQUEST['edit']);
32        $NS  = getNS($IMG);
33    }elseif($_REQUEST['img']){
34        $IMG = cleanID($_REQUEST['img']);
35        $NS  = getNS($IMG);
36    }else{
37        $NS = $_REQUEST['ns'];
38        $NS = cleanID($NS);
39    }
40
41    // check auth
42    $AUTH = auth_quickaclcheck("$NS:*");
43
44    // create the given namespace (just for beautification)
45    if($AUTH >= AUTH_UPLOAD) { io_createNamespace("$NS:xxx", 'media'); }
46
47    // handle flash upload
48    if(isset($_FILES['Filedata'])){
49        $_FILES['upload'] =& $_FILES['Filedata'];
50        $JUMPTO = media_upload($NS,$AUTH);
51        if($JUMPTO == false){
52            header("HTTP/1.0 400 Bad Request");
53            echo 'Upload failed';
54        }
55        echo 'ok';
56        exit;
57    }
58
59    // give info on PHP catched upload errors
60    if($_FILES['upload']['error']){
61        switch($_FILES['upload']['error']){
62            case 1:
63            case 2:
64                msg(sprintf($lang['uploadsize'],
65                    filesize_h(php_to_byte(ini_get('upload_max_filesize')))),-1);
66                break;
67            default:
68                msg($lang['uploadfail'].' ('.$_FILES['upload']['error'].')',-1);
69        }
70        unset($_FILES['upload']);
71    }
72
73    // handle upload
74    if($_FILES['upload']['tmp_name']){
75        $JUMPTO = media_upload($NS,$AUTH);
76        if($JUMPTO) $NS = getNS($JUMPTO);
77    }
78
79    // handle meta saving
80    if($IMG && $_REQUEST['do']['save']){
81        $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
82    }
83
84    // handle deletion
85    if($DEL) {
86        $INUSE = media_inuse($DEL);
87        if(!$INUSE) {
88            if(media_delete($DEL,$AUTH)) {
89                msg(sprintf($lang['deletesucc'],noNS($DEL)),1);
90            } else {
91                msg(sprintf($lang['deletefail'],noNS($DEL)),-1);
92            }
93        } else {
94            if(!$conf['refshow']) {
95                unset($INUSE);
96                msg(sprintf($lang['mediainuse'],noNS($DEL)),0);
97            }
98        }
99    }
100
101    // finished - start output
102    header('Content-Type: text/html; charset=utf-8');
103    include(template('mediamanager.php'));
104
105/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
106