xref: /dokuwiki/lib/exe/mediamanager.php (revision 666cdec516655603e1a83ff884faa9c6e58b7ace)
1cf6894dfSAndreas Gohr<?php
2d0a27cb0SAndreas Gohr    if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
33df72098SAndreas Gohr    define('DOKU_MEDIAMANAGER',1);
4d00ec455SAndreas Gohr
53df72098SAndreas Gohr    require_once(DOKU_INC.'inc/init.php');
63df72098SAndreas Gohr    require_once(DOKU_INC.'inc/lang/en/lang.php');
73df72098SAndreas Gohr    require_once(DOKU_INC.'inc/lang/'.$conf['lang'].'/lang.php');
83df72098SAndreas Gohr    require_once(DOKU_INC.'inc/media.php');
93df72098SAndreas Gohr    require_once(DOKU_INC.'inc/common.php');
103df72098SAndreas Gohr    require_once(DOKU_INC.'inc/search.php');
113df72098SAndreas Gohr    require_once(DOKU_INC.'inc/template.php');
123df72098SAndreas Gohr    require_once(DOKU_INC.'inc/auth.php');
13a249681dSAndreas Gohr
14a249681dSAndreas Gohr    trigger_event('MEDIAMANAGER_STARTED',$tmp=array());
153df72098SAndreas Gohr    session_write_close();  //close session
163df72098SAndreas Gohr
17d186898bSAndreas Gohr    // handle passed message
18d186898bSAndreas Gohr    if($_REQUEST['msg1']) msg(hsc($_REQUEST['msg1']),1);
19d00ec455SAndreas Gohr    if($_REQUEST['err']) msg(hsc($_REQUEST['err']),-1);
20d186898bSAndreas Gohr
213df72098SAndreas Gohr
223df72098SAndreas Gohr    // get namespace to display (either direct or from deletion order)
233df72098SAndreas Gohr    if($_REQUEST['delete']){
243df72098SAndreas Gohr        $DEL = cleanID($_REQUEST['delete']);
25a05e297aSAndreas Gohr        $IMG = $DEL;
263df72098SAndreas Gohr        $NS  = getNS($DEL);
273df72098SAndreas Gohr    }elseif($_REQUEST['edit']){
283df72098SAndreas Gohr        $IMG = cleanID($_REQUEST['edit']);
293df72098SAndreas Gohr        $NS  = getNS($IMG);
303df72098SAndreas Gohr    }elseif($_REQUEST['img']){
313df72098SAndreas Gohr        $IMG = cleanID($_REQUEST['img']);
323df72098SAndreas Gohr        $NS  = getNS($IMG);
333df72098SAndreas Gohr    }else{
343df72098SAndreas Gohr        $NS = $_REQUEST['ns'];
353df72098SAndreas Gohr        $NS = cleanID($NS);
363df72098SAndreas Gohr    }
373df72098SAndreas Gohr
383df72098SAndreas Gohr    // check auth
393df72098SAndreas Gohr    $AUTH = auth_quickaclcheck("$NS:*");
403df72098SAndreas Gohr
413df72098SAndreas Gohr    // create the given namespace (just for beautification)
42cc7d0c94SBen Coburn    if($AUTH >= AUTH_UPLOAD) { io_createNamespace("$NS:xxx", 'media'); }
433df72098SAndreas Gohr
44d00ec455SAndreas Gohr    // handle flash upload
45d00ec455SAndreas Gohr    if($_FILES['Filedata']['tmp_name']){
46d00ec455SAndreas Gohr        $_FILES['upload'] =& $_FILES['Filedata'];
47d00ec455SAndreas Gohr        $JUMPTO = media_upload($NS,$AUTH);
48d00ec455SAndreas Gohr        if($JUMPTO == false){
49d00ec455SAndreas Gohr            header("HTTP/1.0 400 Bad Request");
50d00ec455SAndreas Gohr            echo 'Upload failed';
51d00ec455SAndreas Gohr        }
52d00ec455SAndreas Gohr        echo 'ok';
53d00ec455SAndreas Gohr        exit;
54d00ec455SAndreas Gohr    }
55d00ec455SAndreas Gohr
56a93e6f85SAndreas Gohr    // give info on PHP catched upload errors
57a93e6f85SAndreas Gohr    if($_FILES['upload']['error']) switch($_FILES['upload']['error']){
58a93e6f85SAndreas Gohr        case 1:
59a93e6f85SAndreas Gohr        case 2:
60a93e6f85SAndreas Gohr            msg(sprintf($lang['uploadsize'],
61a93e6f85SAndreas Gohr                filesize_h(php_to_byte(ini_get('upload_max_filesize')))),-1);
62a93e6f85SAndreas Gohr            break;
63a93e6f85SAndreas Gohr        default:
64a93e6f85SAndreas Gohr            msg($lang['uploadfail'],-1);
65a93e6f85SAndreas Gohr    }
66d00ec455SAndreas Gohr
673df72098SAndreas Gohr    // handle upload
683df72098SAndreas Gohr    if($_FILES['upload']['tmp_name']){
693df72098SAndreas Gohr        $JUMPTO = media_upload($NS,$AUTH);
707b877f51SAndreas Gohr        if($JUMPTO) $NS = getNS($JUMPTO);
713df72098SAndreas Gohr    }
723df72098SAndreas Gohr
733df72098SAndreas Gohr    // handle meta saving
743df72098SAndreas Gohr    if($IMG && $_REQUEST['do']['save']){
753df72098SAndreas Gohr        $JUMPTO = media_metasave($IMG,$AUTH,$_REQUEST['meta']);
763df72098SAndreas Gohr    }
773df72098SAndreas Gohr
783df72098SAndreas Gohr    // handle deletion
793df72098SAndreas Gohr    if($DEL) {
80*666cdec5SMichael Klier        $INUSE = media_inuse($DEL);
81*666cdec5SMichael Klier        if(!$INUSE) {
82*666cdec5SMichael Klier            if(media_delete($DEL,$AUTH)) {
83*666cdec5SMichael Klier			    msg(str_replace('%s',noNS($id),$lang['deletesucc']),1);
84*666cdec5SMichael Klier            } else {
85*666cdec5SMichael Klier         	    msg(str_replace('%s',noNS($DEL),$lang['deletefail']),-1);
86*666cdec5SMichael Klier            }
87*666cdec5SMichael Klier		} else {
88*666cdec5SMichael Klier            if(!$conf['refshow']) {
89*666cdec5SMichael Klier                unset($INUSE);
90*666cdec5SMichael Klier                msg(str_replace('%s',noNS($DEL),$lang['mediainuse']),0);
91*666cdec5SMichael Klier            }
92*666cdec5SMichael Klier        }
933df72098SAndreas Gohr    }
943df72098SAndreas Gohr
953df72098SAndreas Gohr    // finished - start output
963df72098SAndreas Gohr    header('Content-Type: text/html; charset=utf-8');
973df72098SAndreas Gohr    include(template('mediamanager.php'));
98