Exemple #1
0
/**
 * File deleter
 *
 * @param array $attr
 * @param array $item
 *
 * @return bool
 */
function deleter_file(array $attr, array &$item) : bool
{
    if (!empty($item[$attr['id']]) && !media_delete($item[$attr['id']])) {
        $item['_error'][$attr['id']] = _('Could not delete old file %s', $item[$attr['id']]);
        return false;
    }
    return true;
}
Exemple #2
0
/**
 * File saver
 *
 * @param array $attr
 * @param array $item
 *
 * @return bool
 */
function saver_file(array $attr, array &$item) : bool
{
    $item[$attr['id']] = null;
    $file = http_files('data')[$item['_id']][$attr['id']] ?? null;
    // Delete old file
    if (!empty($item['_old'][$attr['id']]) && ($file || !empty($item['_delete'][$attr['id']])) && !media_delete($item['_old'][$attr['id']])) {
        $item['_error'][$attr['id']] = _('Could not delete old file %s', $item['_old'][$attr['id']]);
        return false;
    }
    // No upload
    if (!$file) {
        return true;
    }
    $value = generator_file($file['name'], project_path('media'));
    // Upload failed
    if (!file_upload($file['tmp_name'], project_path('media', $value))) {
        $item['_error'][$attr['id']] = _('File upload failed');
        return false;
    }
    $item[$attr['id']] = $value;
    return true;
}
 /**
  * Deletes a file from the wiki.
  *
  * @author Gina Haeussge <*****@*****.**>
  */
 function deleteAttachment($id)
 {
     $id = cleanID($id);
     $auth = auth_quickaclcheck(getNS($id) . ':*');
     $res = media_delete($id, $auth);
     if ($res & DOKU_MEDIA_DELETED) {
         return 0;
     } elseif ($res & DOKU_MEDIA_NOT_AUTH) {
         throw new RemoteAccessDeniedException('You don\'t have permissions to delete files.', 212);
     } elseif ($res & DOKU_MEDIA_INUSE) {
         throw new RemoteException('File is still referenced', 232);
     } else {
         throw new RemoteException('Could not delete file', 233);
     }
 }
Exemple #4
0
// handle upload
if ($_FILES['upload']['tmp_name']) {
    $JUMPTO = media_upload($NS, $AUTH);
    if ($JUMPTO) {
        $NS = getNS($JUMPTO);
    }
}
// handle meta saving
if ($IMG && $_REQUEST['do']['save']) {
    $JUMPTO = media_metasave($IMG, $AUTH, $_REQUEST['meta']);
}
// handle deletion
if ($DEL) {
    $INUSE = media_inuse($DEL);
    if (!$INUSE) {
        if (media_delete($DEL, $AUTH)) {
            msg(sprintf($lang['deletesucc'], noNS($DEL)), 1);
        } else {
            msg(sprintf($lang['deletefail'], noNS($DEL)), -1);
        }
    } else {
        if (!$conf['refshow']) {
            unset($INUSE);
            msg(sprintf($lang['mediainuse'], noNS($DEL)), 0);
        }
    }
}
// finished - start output
header('Content-Type: text/html; charset=utf-8');
include template('mediamanager.php');
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
Exemple #5
0
 /**
  * Deletes a file from the wiki.
  *
  * @author Gina Haeussge <*****@*****.**>
  */
 function deleteAttachment($id)
 {
     $id = cleanID($id);
     $auth = auth_quickaclcheck(getNS($id) . ':*');
     $res = media_delete($id, $auth);
     if ($res & DOKU_MEDIA_DELETED) {
         return 0;
     } elseif ($res & DOKU_MEDIA_NOT_AUTH) {
         return new IXR_ERROR(1, "You don't have permissions to delete files.");
     } elseif ($res & DOKU_MEDIA_INUSE) {
         return new IXR_ERROR(1, 'File is still referenced');
     } else {
         return new IXR_ERROR(1, 'Could not delete file');
     }
 }
    $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
}
if ($IMG && ($INPUT->str('mediado') == 'save' || @array_key_exists('save', $INPUT->arr('mediado')))) {
    $JUMPTO = media_metasave($IMG, $AUTH, $INPUT->arr('meta'));
}
if ($INPUT->int('rev') && $conf['mediarevisions']) {
    $REV = $INPUT->int('rev');
}
if ($INPUT->str('mediado') == 'restore' && $conf['mediarevisions']) {
    $JUMPTO = media_restore($INPUT->str('image'), $REV, $AUTH);
}
// handle deletion
if ($DEL) {
    $res = 0;
    if (checkSecurityToken()) {
        $res = media_delete($DEL, $AUTH);
    }
    if ($res & DOKU_MEDIA_DELETED) {
        $msg = sprintf($lang['deletesucc'], noNS($DEL));
        if ($res & DOKU_MEDIA_EMPTY_NS && !$fullscreen) {
            // current namespace was removed. redirecting to root ns passing msg along
            send_redirect(DOKU_URL . 'lib/exe/mediamanager.php?msg1=' . rawurlencode($msg) . '&edid=' . $INPUT->str('edid'));
        }
        msg($msg, 1);
    } elseif ($res & DOKU_MEDIA_INUSE) {
        if (!$conf['refshow']) {
            msg(sprintf($lang['mediainuse'], noNS($DEL)), 0);
        }
    } else {
        msg(sprintf($lang['deletefail'], noNS($DEL)), -1);
    }
Exemple #7
0
 /**
  * remove an old zip file
  **/
 function __removeOldZip($FILENAMEID = null, $checkForMore = true)
 {
     global $INFO;
     global $conf;
     $returnValue = true;
     if (empty($FILENAMEID)) {
         $FILENAMEID = $this->functions->settings->origZipFile;
     }
     if (!$this->functions->settings->isCLI) {
         $INFO = pageinfo();
         if ($INFO['perm'] < AUTH_DELETE && !$this->functions->settings->isAuthed) {
             list($USER, $PASS) = $this->functions->basic_authentication();
             $this->functions->settings->isAuthed = auth_login($USER, $PASS);
             $this->functions->debug->message("Login With:", array('User' => $USER, 'Password' => '*****', 'isAuthed' => $this->functions->settings->isAuthed));
             $INFO = pageinfo();
         }
     }
     if (!file_exists(mediaFN($FILENAMEID))) {
         $returnValue = true;
     } else {
         require_once DOKU_INC . 'inc/media.php';
         if (!media_delete($FILENAMEID, $INFO['perm'])) {
             $returnValue = false;
         }
     }
     if ($checkForMore) {
         // Try to remove more files.
         $ns = getNS($FILENAMEID);
         $fn = $this->functions->getSpecialExportFileName(noNS($FILENAMEID), '.+');
         $data = array();
         search($data, $conf['mediadir'], 'search_media', array('pattern' => "/{$fn}\$/i"), $ns);
         if (count($data > 0)) {
             // 30 Minuten Cache Zeit
             $cache = $this->functions->settings->cachetime;
             foreach ($data as $media) {
                 //decide if has to be deleted needed:
                 if ($media['mtime'] < time() - $cache) {
                     $this->__removeOldZip($media['id'], false);
                 }
             }
         }
     }
     return $returnValue;
 }