xref: /dokuwiki/lib/exe/mediamanager.php (revision a5de816f2f76e45512c89769be63ed8b9bbbfd0d)
1cf6894dfSAndreas Gohr<?php
2d0a27cb0SAndreas Gohr    if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
33df72098SAndreas Gohr    define('DOKU_MEDIAMANAGER',1);
4d00ec455SAndreas Gohr
5*a5de816fSAndreas Gohr    // for multi uploader:
6*a5de816fSAndreas Gohr    @ini_set('session.use_only_cookies',0);
7*a5de816fSAndreas Gohr
83df72098SAndreas Gohr    require_once(DOKU_INC.'inc/init.php');
93df72098SAndreas Gohr    require_once(DOKU_INC.'inc/lang/en/lang.php');
103df72098SAndreas Gohr    require_once(DOKU_INC.'inc/lang/'.$conf['lang'].'/lang.php');
113df72098SAndreas Gohr    require_once(DOKU_INC.'inc/media.php');
123df72098SAndreas Gohr    require_once(DOKU_INC.'inc/common.php');
133df72098SAndreas Gohr    require_once(DOKU_INC.'inc/search.php');
143df72098SAndreas Gohr    require_once(DOKU_INC.'inc/template.php');
153df72098SAndreas Gohr    require_once(DOKU_INC.'inc/auth.php');
16a249681dSAndreas Gohr
17a249681dSAndreas Gohr    trigger_event('MEDIAMANAGER_STARTED',$tmp=array());
183df72098SAndreas Gohr    session_write_close();  //close session
193df72098SAndreas Gohr
20d186898bSAndreas Gohr    // handle passed message
21d186898bSAndreas Gohr    if($_REQUEST['msg1']) msg(hsc($_REQUEST['msg1']),1);
22d00ec455SAndreas Gohr    if($_REQUEST['err']) msg(hsc($_REQUEST['err']),-1);
23d186898bSAndreas Gohr
243df72098SAndreas Gohr
253df72098SAndreas Gohr    // get namespace to display (either direct or from deletion order)
263df72098SAndreas Gohr    if($_REQUEST['delete']){
273df72098SAndreas Gohr        $DEL = cleanID($_REQUEST['delete']);
28a05e297aSAndreas Gohr        $IMG = $DEL;
293df72098SAndreas Gohr        $NS  = getNS($DEL);
303df72098SAndreas Gohr    }elseif($_REQUEST['edit']){
313df72098SAndreas Gohr        $IMG = cleanID($_REQUEST['edit']);
323df72098SAndreas Gohr        $NS  = getNS($IMG);
333df72098SAndreas Gohr    }elseif($_REQUEST['img']){
343df72098SAndreas Gohr        $IMG = cleanID($_REQUEST['img']);
353df72098SAndreas Gohr        $NS  = getNS($IMG);
363df72098SAndreas Gohr    }else{
373df72098SAndreas Gohr        $NS = $_REQUEST['ns'];
383df72098SAndreas Gohr        $NS = cleanID($NS);
393df72098SAndreas Gohr    }
403df72098SAndreas Gohr
413df72098SAndreas Gohr    // check auth
423df72098SAndreas Gohr    $AUTH = auth_quickaclcheck("$NS:*");
433df72098SAndreas Gohr
443df72098SAndreas Gohr    // create the given namespace (just for beautification)
45cc7d0c94SBen Coburn    if($AUTH >= AUTH_UPLOAD) { io_createNamespace("$NS:xxx", 'media'); }
463df72098SAndreas Gohr
47d00ec455SAndreas Gohr    // handle flash upload
4858b091deSAndreas Gohr    if(isset($_FILES['Filedata'])){
49d00ec455SAndreas Gohr        $_FILES['upload'] =& $_FILES['Filedata'];
50d00ec455SAndreas Gohr        $JUMPTO = media_upload($NS,$AUTH);
51d00ec455SAndreas Gohr        if($JUMPTO == false){
52d00ec455SAndreas Gohr            header("HTTP/1.0 400 Bad Request");
53d00ec455SAndreas Gohr            echo 'Upload failed';
54d00ec455SAndreas Gohr        }
55d00ec455SAndreas Gohr        echo 'ok';
56d00ec455SAndreas Gohr        exit;
57d00ec455SAndreas Gohr    }
58d00ec455SAndreas Gohr
59a93e6f85SAndreas Gohr    // give info on PHP catched upload errors
6099766eefSAndreas Gohr    if($_FILES['upload']['error']){
6199766eefSAndreas Gohr        switch($_FILES['upload']['error']){
62a93e6f85SAndreas Gohr            case 1:
63a93e6f85SAndreas Gohr            case 2:
64a93e6f85SAndreas Gohr                msg(sprintf($lang['uploadsize'],
65a93e6f85SAndreas Gohr                    filesize_h(php_to_byte(ini_get('upload_max_filesize')))),-1);
66a93e6f85SAndreas Gohr                break;
67a93e6f85SAndreas Gohr            default:
6899766eefSAndreas Gohr                msg($lang['uploadfail'].' ('.$_FILES['upload']['error'].')',-1);
6999766eefSAndreas Gohr        }
7099766eefSAndreas Gohr        unset($_FILES['upload']);
71a93e6f85SAndreas Gohr    }
72d00ec455SAndreas Gohr
733df72098SAndreas Gohr    // handle upload
743df72098SAndreas Gohr    if($_FILES['upload']['tmp_name']){
753df72098SAndreas Gohr        $JUMPTO = media_upload($NS,$AUTH);
767b877f51SAndreas Gohr        if($JUMPTO) $NS = getNS($JUMPTO);
773df72098SAndreas Gohr    }
783df72098SAndreas Gohr
793df72098SAndreas Gohr    // handle meta saving
803df72098SAndreas Gohr    if($IMG && $_REQUEST['do']['save']){
813df72098SAndreas Gohr        $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
823df72098SAndreas Gohr    }
833df72098SAndreas Gohr
843df72098SAndreas Gohr    // handle deletion
853df72098SAndreas Gohr    if($DEL) {
86666cdec5SMichael Klier        $INUSE = media_inuse($DEL);
87666cdec5SMichael Klier        if(!$INUSE) {
88666cdec5SMichael Klier            if(media_delete($DEL,$AUTH)) {
8907ae50bfSAndreas Gohr                msg(sprintf($lang['deletesucc'],noNS($DEL)),1);
90666cdec5SMichael Klier            } else {
91d5b31577SChristian Marg                msg(sprintf($lang['deletefail'],noNS($DEL)),-1);
92666cdec5SMichael Klier            }
93666cdec5SMichael Klier        } else {
94666cdec5SMichael Klier            if(!$conf['refshow']) {
95666cdec5SMichael Klier                unset($INUSE);
96d5b31577SChristian Marg                msg(sprintf($lang['mediainuse'],noNS($DEL)),0);
97666cdec5SMichael Klier            }
98666cdec5SMichael Klier        }
993df72098SAndreas Gohr    }
1003df72098SAndreas Gohr
1013df72098SAndreas Gohr    // finished - start output
1023df72098SAndreas Gohr    header('Content-Type: text/html; charset=utf-8');
1033df72098SAndreas Gohr    include(template('mediamanager.php'));
104365be586SAndreas Gohr
105365be586SAndreas Gohr/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
106