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