xref: /dokuwiki/lib/exe/mediamanager.php (revision 06c886b9a0ca10beb5120bbbb6a1f59435750c8f)
1cf6894dfSAndreas Gohr<?php
2cbb44eabSAndreas Gohr
3cbb44eabSAndreas Gohruse dokuwiki\Extension\Event;
4cbb44eabSAndreas Gohr
5e3c3abf1SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
63df72098SAndreas Gohrdefine('DOKU_MEDIAMANAGER', 1);
7d00ec455SAndreas Gohr
8a5de816fSAndreas Gohr// for multi uploader:
9a5de816fSAndreas Gohr@ini_set('session.use_only_cookies', 0);
10a5de816fSAndreas Gohr
113df72098SAndreas Gohrrequire_once(DOKU_INC . 'inc/init.php');
12a249681dSAndreas Gohr
13361f1762STom N Harrisglobal $INPUT;
14893747daSAndreas Gohrglobal $lang;
154547e69eSlispsglobal $conf;
16d186898bSAndreas Gohr// handle passed message
178108113cSTom N Harrisif ($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')), 1);
188108113cSTom N Harrisif ($INPUT->str('err')) msg(hsc($INPUT->str('err')), -1);
19d186898bSAndreas Gohr
20ca22711eSChristopher Smithglobal $DEL;
213df72098SAndreas Gohr// get namespace to display (either direct or from deletion order)
228108113cSTom N Harrisif ($INPUT->str('delete')) {
238108113cSTom N Harris    $DEL = cleanID($INPUT->str('delete'));
24a05e297aSAndreas Gohr    $IMG = $DEL;
253df72098SAndreas Gohr    $NS = getNS($DEL);
268108113cSTom N Harris} elseif ($INPUT->str('edit')) {
278108113cSTom N Harris    $IMG = cleanID($INPUT->str('edit'));
283df72098SAndreas Gohr    $NS = getNS($IMG);
298108113cSTom N Harris} elseif ($INPUT->str('img')) {
308108113cSTom N Harris    $IMG = cleanID($INPUT->str('img'));
313df72098SAndreas Gohr    $NS = getNS($IMG);
323df72098SAndreas Gohr} else {
338108113cSTom N Harris    $NS = cleanID($INPUT->str('ns'));
341015a57dSChristopher Smith    $IMG = null;
353df72098SAndreas Gohr}
363df72098SAndreas Gohr
37d1e37fb0SMatthias Schulteglobal $INFO, $JSINFO;
38e3c3abf1SAndreas Gohr$INFO = empty($INFO) ? mediainfo() : array_merge($INFO, mediainfo());
39e725e2adSGerrit Uitslag$JSINFO['id'] = '';
40e725e2adSGerrit Uitslag$JSINFO['namespace'] = '';
411015a57dSChristopher Smith$AUTH = $INFO['perm'];    // shortcut for historical reasons
421015a57dSChristopher Smith
432ab59305SBenjamin BERNARD// If this page is directly opened it means we are in popup mode not fullscreen
442ab59305SBenjamin BERNARD// $fullscreen isn't defined by default it might lead to some PHP warnings
45e3c3abf1SAndreas Gohr$fullscreen ??= false;
462ab59305SBenjamin BERNARD
47e3c3abf1SAndreas Gohr$tmp = [];
48cbb44eabSAndreas GohrEvent::createAndTrigger('MEDIAMANAGER_STARTED', $tmp);
491015a57dSChristopher Smithsession_write_close();  //close session
503df72098SAndreas Gohr
510b34c70fSGina Haeussge// do not display the manager if user does not have read access
5288a71175SKate Arzamastsevaif ($AUTH < AUTH_READ && !$fullscreen) {
539d2e1be6SAndreas Gohr    http_status(403);
540b34c70fSGina Haeussge    die($lang['accessdenied']);
550b34c70fSGina Haeussge}
560b34c70fSGina Haeussge
57d00ec455SAndreas Gohr// handle flash upload
5858b091deSAndreas Gohrif (isset($_FILES['Filedata'])) {
59d00ec455SAndreas Gohr    $_FILES['upload'] =& $_FILES['Filedata'];
60d00ec455SAndreas Gohr    $JUMPTO = media_upload($NS, $AUTH);
61d00ec455SAndreas Gohr    if ($JUMPTO == false) {
629d2e1be6SAndreas Gohr        http_status(400);
63d00ec455SAndreas Gohr        echo 'Upload failed';
64d00ec455SAndreas Gohr    }
65d00ec455SAndreas Gohr    echo 'ok';
66d00ec455SAndreas Gohr    exit;
67d00ec455SAndreas Gohr}
68d00ec455SAndreas Gohr
693074e342SChristopher Smith// give info on PHP caught upload errors
700e80bb5eSChristopher Smithif (!empty($_FILES['upload']['error'])) {
7199766eefSAndreas Gohr    switch ($_FILES['upload']['error']) {
72a93e6f85SAndreas Gohr        case 1:
73a93e6f85SAndreas Gohr        case 2:
74ba8f8349SAndreas Gohr            msg(sprintf(
75ba8f8349SAndreas Gohr                $lang['uploadsize'],
76ba8f8349SAndreas Gohr                filesize_h(php_to_byte(ini_get('upload_max_filesize')))
77ba8f8349SAndreas Gohr            ), -1);
78a93e6f85SAndreas Gohr            break;
79a93e6f85SAndreas Gohr        default:
8099766eefSAndreas Gohr            msg($lang['uploadfail'] . ' (' . $_FILES['upload']['error'] . ')', -1);
8199766eefSAndreas Gohr    }
8299766eefSAndreas Gohr    unset($_FILES['upload']);
83a93e6f85SAndreas Gohr}
84d00ec455SAndreas Gohr
853df72098SAndreas Gohr// handle upload
860e80bb5eSChristopher Smithif (!empty($_FILES['upload']['tmp_name'])) {
873df72098SAndreas Gohr    $JUMPTO = media_upload($NS, $AUTH);
887b877f51SAndreas Gohr    if ($JUMPTO) $NS = getNS($JUMPTO);
893df72098SAndreas Gohr}
903df72098SAndreas Gohr
913df72098SAndreas Gohr// handle meta saving
928108113cSTom N Harrisif ($IMG && @array_key_exists('save', $INPUT->arr('do'))) {
938108113cSTom N Harris    $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
94d9162c6cSKate Arzamastseva}
95d9162c6cSKate Arzamastseva
968108113cSTom N Harrisif ($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) {
978108113cSTom N Harris    $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
983df72098SAndreas Gohr}
993df72098SAndreas Gohr
1008108113cSTom N Harrisif ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev');
1019c1bd4bcSKate Arzamastseva
102*06c886b9SAndreas Gohrif ($INPUT->str('mediado') == 'restore' && $conf['mediarevisions'] && checkSecurityToken()) {
1038108113cSTom N Harris    $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH);
1049c1bd4bcSKate Arzamastseva}
1059c1bd4bcSKate Arzamastseva
1063df72098SAndreas Gohr// handle deletion
1073df72098SAndreas Gohrif ($DEL) {
10887229c84SAdrian Lang    $res = 0;
10987229c84SAdrian Lang    if (checkSecurityToken()) {
11087229c84SAdrian Lang        $res = media_delete($DEL, $AUTH);
111666cdec5SMichael Klier    }
11287229c84SAdrian Lang    if ($res & DOKU_MEDIA_DELETED) {
11387229c84SAdrian Lang        $msg = sprintf($lang['deletesucc'], noNS($DEL));
1147d7ab775SKate Arzamastseva        if ($res & DOKU_MEDIA_EMPTY_NS && !$fullscreen) {
11587229c84SAdrian Lang            // current namespace was removed. redirecting to root ns passing msg along
11687229c84SAdrian Lang            send_redirect(DOKU_URL . 'lib/exe/mediamanager.php?msg1=' .
1178108113cSTom N Harris                rawurlencode($msg) . '&edid=' . $INPUT->str('edid'));
11887229c84SAdrian Lang        }
11987229c84SAdrian Lang        msg($msg, 1);
12087229c84SAdrian Lang    } elseif ($res & DOKU_MEDIA_INUSE) {
121d5b31577SChristian Marg        msg(sprintf($lang['mediainuse'], noNS($DEL)), 0);
12287229c84SAdrian Lang    } else {
12387229c84SAdrian Lang        msg(sprintf($lang['deletefail'], noNS($DEL)), -1);
124666cdec5SMichael Klier    }
1253df72098SAndreas Gohr}
1263df72098SAndreas Gohr// finished - start output
127d9162c6cSKate Arzamastseva
12888a71175SKate Arzamastsevaif (!$fullscreen) {
1293df72098SAndreas Gohr    header('Content-Type: text/html; charset=utf-8');
1303df72098SAndreas Gohr    include(template('mediamanager.php'));
131d9162c6cSKate Arzamastseva}
132