xref: /dokuwiki/lib/exe/mediamanager.php (revision 093fe67e98c0cdb4b73fd46938e49b64971483c2)
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'])) {
71*093fe67eSAndreas Gohr    match ($_FILES['upload']['error']) {
72*093fe67eSAndreas Gohr        1, 2 => msg(sprintf(
73ba8f8349SAndreas Gohr            $lang['uploadsize'],
74ba8f8349SAndreas Gohr            filesize_h(php_to_byte(ini_get('upload_max_filesize')))
75*093fe67eSAndreas Gohr        ), -1),
76*093fe67eSAndreas Gohr        default => msg($lang['uploadfail'] . ' (' . $_FILES['upload']['error'] . ')', -1),
77*093fe67eSAndreas Gohr    };
7899766eefSAndreas Gohr    unset($_FILES['upload']);
79a93e6f85SAndreas Gohr}
80d00ec455SAndreas Gohr
813df72098SAndreas Gohr// handle upload
820e80bb5eSChristopher Smithif (!empty($_FILES['upload']['tmp_name'])) {
833df72098SAndreas Gohr    $JUMPTO = media_upload($NS, $AUTH);
847b877f51SAndreas Gohr    if ($JUMPTO) $NS = getNS($JUMPTO);
853df72098SAndreas Gohr}
863df72098SAndreas Gohr
873df72098SAndreas Gohr// handle meta saving
888108113cSTom N Harrisif ($IMG && @array_key_exists('save', $INPUT->arr('do'))) {
898108113cSTom N Harris    $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
90d9162c6cSKate Arzamastseva}
91d9162c6cSKate Arzamastseva
928108113cSTom N Harrisif ($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) {
938108113cSTom N Harris    $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
943df72098SAndreas Gohr}
953df72098SAndreas Gohr
968108113cSTom N Harrisif ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev');
979c1bd4bcSKate Arzamastseva
9806c886b9SAndreas Gohrif ($INPUT->str('mediado') == 'restore' && $conf['mediarevisions'] && checkSecurityToken()) {
998108113cSTom N Harris    $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH);
1009c1bd4bcSKate Arzamastseva}
1019c1bd4bcSKate Arzamastseva
1023df72098SAndreas Gohr// handle deletion
1033df72098SAndreas Gohrif ($DEL) {
10487229c84SAdrian Lang    $res = 0;
10587229c84SAdrian Lang    if (checkSecurityToken()) {
10687229c84SAdrian Lang        $res = media_delete($DEL, $AUTH);
107666cdec5SMichael Klier    }
10887229c84SAdrian Lang    if ($res & DOKU_MEDIA_DELETED) {
10987229c84SAdrian Lang        $msg = sprintf($lang['deletesucc'], noNS($DEL));
1107d7ab775SKate Arzamastseva        if ($res & DOKU_MEDIA_EMPTY_NS && !$fullscreen) {
11187229c84SAdrian Lang            // current namespace was removed. redirecting to root ns passing msg along
11287229c84SAdrian Lang            send_redirect(DOKU_URL . 'lib/exe/mediamanager.php?msg1=' .
1138108113cSTom N Harris                rawurlencode($msg) . '&edid=' . $INPUT->str('edid'));
11487229c84SAdrian Lang        }
11587229c84SAdrian Lang        msg($msg, 1);
11687229c84SAdrian Lang    } elseif ($res & DOKU_MEDIA_INUSE) {
117d5b31577SChristian Marg        msg(sprintf($lang['mediainuse'], noNS($DEL)), 0);
11887229c84SAdrian Lang    } else {
11987229c84SAdrian Lang        msg(sprintf($lang['deletefail'], noNS($DEL)), -1);
120666cdec5SMichael Klier    }
1213df72098SAndreas Gohr}
1223df72098SAndreas Gohr// finished - start output
123d9162c6cSKate Arzamastseva
12488a71175SKate Arzamastsevaif (!$fullscreen) {
1253df72098SAndreas Gohr    header('Content-Type: text/html; charset=utf-8');
1263df72098SAndreas Gohr    include(template('mediamanager.php'));
127d9162c6cSKate Arzamastseva}
128