xref: /dokuwiki/lib/exe/mediamanager.php (revision 357e220245cc608a5421bebf402bd083991714ab)
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']) switch($_FILES['upload']['error']){
58        case 1:
59        case 2:
60            msg(sprintf($lang['uploadsize'],
61                filesize_h(php_to_byte(ini_get('upload_max_filesize')))),-1);
62            break;
63        default:
64            msg($lang['uploadfail'],-1);
65    }
66
67    // handle upload
68    if($_FILES['upload']['tmp_name']){
69        $JUMPTO = media_upload($NS,$AUTH);
70        if($JUMPTO) $NS = getNS($JUMPTO);
71    }
72
73    // handle meta saving
74    if($IMG && $_REQUEST['do']['save']){
75        $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
76    }
77
78    // handle deletion
79    if($DEL) {
80        $INUSE = media_inuse($DEL);
81        if(!$INUSE) {
82            if(media_delete($DEL,$AUTH)) {
83                msg(sprintf($lang['deletesucc'],noNS($id)),1);
84            } else {
85                msg(sprintf($lang['deletefail'],noNS($DEL)),-1);
86            }
87        } else {
88            if(!$conf['refshow']) {
89                unset($INUSE);
90                msg(sprintf($lang['mediainuse'],noNS($DEL)),0);
91            }
92        }
93    }
94
95    // finished - start output
96    header('Content-Type: text/html; charset=utf-8');
97    include(template('mediamanager.php'));
98
99/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
100