You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

132 lines
3.7 KiB

  1. <?php
  2. use dokuwiki\Extension\Event;
  3. if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
  4. define('DOKU_MEDIAMANAGER', 1);
  5. // for multi uploader:
  6. @ini_set('session.use_only_cookies', 0);
  7. require_once(DOKU_INC . 'inc/init.php');
  8. global $INPUT;
  9. global $lang;
  10. global $conf;
  11. // handle passed message
  12. if ($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')), 1);
  13. if ($INPUT->str('err')) msg(hsc($INPUT->str('err')), -1);
  14. global $DEL;
  15. // get namespace to display (either direct or from deletion order)
  16. if ($INPUT->str('delete')) {
  17. $DEL = cleanID($INPUT->str('delete'));
  18. $IMG = $DEL;
  19. $NS = getNS($DEL);
  20. } elseif ($INPUT->str('edit')) {
  21. $IMG = cleanID($INPUT->str('edit'));
  22. $NS = getNS($IMG);
  23. } elseif ($INPUT->str('img')) {
  24. $IMG = cleanID($INPUT->str('img'));
  25. $NS = getNS($IMG);
  26. } else {
  27. $NS = cleanID($INPUT->str('ns'));
  28. $IMG = null;
  29. }
  30. global $INFO, $JSINFO;
  31. $INFO = empty($INFO) ? mediainfo() : array_merge($INFO, mediainfo());
  32. $JSINFO['id'] = '';
  33. $JSINFO['namespace'] = '';
  34. $AUTH = $INFO['perm']; // shortcut for historical reasons
  35. // If this page is directly opened it means we are in popup mode not fullscreen
  36. // $fullscreen isn't defined by default it might lead to some PHP warnings
  37. $fullscreen ??= false;
  38. $tmp = [];
  39. Event::createAndTrigger('MEDIAMANAGER_STARTED', $tmp);
  40. session_write_close(); //close session
  41. // do not display the manager if user does not have read access
  42. if ($AUTH < AUTH_READ && !$fullscreen) {
  43. http_status(403);
  44. die($lang['accessdenied']);
  45. }
  46. // handle flash upload
  47. if (isset($_FILES['Filedata'])) {
  48. $_FILES['upload'] =& $_FILES['Filedata'];
  49. $JUMPTO = media_upload($NS, $AUTH);
  50. if ($JUMPTO == false) {
  51. http_status(400);
  52. echo 'Upload failed';
  53. }
  54. echo 'ok';
  55. exit;
  56. }
  57. // give info on PHP caught upload errors
  58. if (!empty($_FILES['upload']['error'])) {
  59. switch ($_FILES['upload']['error']) {
  60. case 1:
  61. case 2:
  62. msg(sprintf(
  63. $lang['uploadsize'],
  64. filesize_h(php_to_byte(ini_get('upload_max_filesize')))
  65. ), -1);
  66. break;
  67. default:
  68. msg($lang['uploadfail'] . ' (' . $_FILES['upload']['error'] . ')', -1);
  69. }
  70. unset($_FILES['upload']);
  71. }
  72. // handle upload
  73. if (!empty($_FILES['upload']['tmp_name'])) {
  74. $JUMPTO = media_upload($NS, $AUTH);
  75. if ($JUMPTO) $NS = getNS($JUMPTO);
  76. }
  77. // handle meta saving
  78. if ($IMG && @array_key_exists('save', $INPUT->arr('do'))) {
  79. $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
  80. }
  81. if ($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) {
  82. $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
  83. }
  84. if ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev');
  85. if ($INPUT->str('mediado') == 'restore' && $conf['mediarevisions']) {
  86. $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH);
  87. }
  88. // handle deletion
  89. if ($DEL) {
  90. $res = 0;
  91. if (checkSecurityToken()) {
  92. $res = media_delete($DEL, $AUTH);
  93. }
  94. if ($res & DOKU_MEDIA_DELETED) {
  95. $msg = sprintf($lang['deletesucc'], noNS($DEL));
  96. if ($res & DOKU_MEDIA_EMPTY_NS && !$fullscreen) {
  97. // current namespace was removed. redirecting to root ns passing msg along
  98. send_redirect(DOKU_URL . 'lib/exe/mediamanager.php?msg1=' .
  99. rawurlencode($msg) . '&edid=' . $INPUT->str('edid'));
  100. }
  101. msg($msg, 1);
  102. } elseif ($res & DOKU_MEDIA_INUSE) {
  103. msg(sprintf($lang['mediainuse'], noNS($DEL)), 0);
  104. } else {
  105. msg(sprintf($lang['deletefail'], noNS($DEL)), -1);
  106. }
  107. }
  108. // finished - start output
  109. if (!$fullscreen) {
  110. header('Content-Type: text/html; charset=utf-8');
  111. include(template('mediamanager.php'));
  112. }