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