xref: /dokuwiki/lib/exe/mediamanager.php (revision f6d35a79a4686ef537d04abbd1705c410beb53ca)
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($_FILES['Filedata']['tmp_name']){
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
57    // handle upload
58    if($_FILES['upload']['tmp_name']){
59        $JUMPTO = media_upload($NS,$AUTH);
60        if($JUMPTO) $NS = getNS($JUMPTO);
61    }
62
63    // handle meta saving
64    if($IMG && $_REQUEST['do']['save']){
65        $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
66    }
67
68    // handle deletion
69    if($DEL) {
70        $INUSE = media_delete($DEL,$AUTH);
71    }
72
73    // finished - start output
74    header('Content-Type: text/html; charset=utf-8');
75    include(template('mediamanager.php'));
76