[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/exe/ -> mediamanager.php (source)

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