mediamanager.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. use dokuwiki\Extension\Event;
  3. if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
  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) ? array_merge($INFO, mediainfo()) : 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 = isset($fullscreen) ? $fullscreen : false;
  38. $tmp = array();
  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($lang['uploadsize'],
  63. filesize_h(php_to_byte(ini_get('upload_max_filesize')))),-1);
  64. break;
  65. default:
  66. msg($lang['uploadfail'].' ('.$_FILES['upload']['error'].')',-1);
  67. }
  68. unset($_FILES['upload']);
  69. }
  70. // handle upload
  71. if(!empty($_FILES['upload']['tmp_name'])){
  72. $JUMPTO = media_upload($NS,$AUTH);
  73. if($JUMPTO) $NS = getNS($JUMPTO);
  74. }
  75. // handle meta saving
  76. if($IMG && @array_key_exists('save', $INPUT->arr('do'))){
  77. $JUMPTO = media_metasave($IMG,$AUTH,$INPUT->arr('meta'));
  78. }
  79. if($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) {
  80. $JUMPTO = media_metasave($IMG,$AUTH,$INPUT->arr('meta'));
  81. }
  82. if ($INPUT->int('rev') && $conf['mediarevisions']) $REV = $INPUT->int('rev');
  83. if($INPUT->str('mediado') == 'restore' && $conf['mediarevisions']){
  84. $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH);
  85. }
  86. // handle deletion
  87. if($DEL) {
  88. $res = 0;
  89. if(checkSecurityToken()) {
  90. $res = media_delete($DEL,$AUTH);
  91. }
  92. if ($res & DOKU_MEDIA_DELETED) {
  93. $msg = sprintf($lang['deletesucc'], noNS($DEL));
  94. if ($res & DOKU_MEDIA_EMPTY_NS && !$fullscreen) {
  95. // current namespace was removed. redirecting to root ns passing msg along
  96. send_redirect(DOKU_URL.'lib/exe/mediamanager.php?msg1='.
  97. rawurlencode($msg).'&edid='.$INPUT->str('edid'));
  98. }
  99. msg($msg,1);
  100. } elseif ($res & DOKU_MEDIA_INUSE) {
  101. msg(sprintf($lang['mediainuse'],noNS($DEL)),0);
  102. } else {
  103. msg(sprintf($lang['deletefail'],noNS($DEL)),-1);
  104. }
  105. }
  106. // finished - start output
  107. if (!$fullscreen) {
  108. header('Content-Type: text/html; charset=utf-8');
  109. include(template('mediamanager.php'));
  110. }
  111. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */