Beispiel #1
0
 /**
  * move file to the trash bin
  *
  * @param $file_path path to the deleted file/directory relative to the files root directory
  */
 public static function move2trash($file_path)
 {
     $user = \OCP\User::getUser();
     $view = new \OC\Files\View('/' . $user);
     if (!$view->is_dir('files_trashbin')) {
         $view->mkdir('files_trashbin');
         $view->mkdir("files_trashbin/files");
         $view->mkdir("files_trashbin/versions");
         $view->mkdir("files_trashbin/keyfiles");
         $view->mkdir("files_trashbin/share-keys");
     }
     $path_parts = pathinfo($file_path);
     $filename = $path_parts['basename'];
     $location = $path_parts['dirname'];
     $timestamp = time();
     $mime = $view->getMimeType('files' . $file_path);
     if ($view->is_dir('files' . $file_path)) {
         $type = 'dir';
     } else {
         $type = 'file';
     }
     $trashbinSize = self::getTrashbinSize($user);
     if ($trashbinSize === false || $trashbinSize < 0) {
         $trashbinSize = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin'));
     }
     // disable proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $sizeOfAddedFiles = self::copy_recursive($file_path, 'files_trashbin/files/' . $filename . '.d' . $timestamp, $view);
     \OC_FileProxy::$enabled = $proxyStatus;
     if ($view->file_exists('files_trashbin/files/' . $filename . '.d' . $timestamp)) {
         $trashbinSize += $sizeOfAddedFiles;
         $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
         $result = $query->execute(array($filename, $timestamp, $location, $type, $mime, $user));
         if (!$result) {
             // if file couldn't be added to the database than also don't store it in the trash bin.
             $view->deleteAll('files_trashbin/files/' . $filename . '.d' . $timestamp);
             \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
             return;
         }
         \OCP\Util::emitHook('\\OCA\\Files_Trashbin\\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path), 'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
         $trashbinSize += self::retainVersions($view, $file_path, $filename, $timestamp);
         $trashbinSize += self::retainEncryptionKeys($view, $file_path, $filename, $timestamp);
     } else {
         \OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
     }
     $trashbinSize -= self::expire($trashbinSize);
     self::setTrashbinSize($user, $trashbinSize);
 }
* @author Bjoern Schiessle
* @copyright 2013 Bjoern Schiessle schiessle@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
OCP\JSON::checkAppEnabled('files_versions');
//OCP\JSON::callCheck();
$file = $_GET['file'];
$revision = (int) $_GET['revision'];
list($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($file);
$versionName = '/' . $uid . '/files_versions/' . $filename . '.v' . $revision;
$view = new OC\Files\View('/');
$ftype = $view->getMimeType('/' . $uid . '/files/' . $filename);
header('Content-Type:' . $ftype);
OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
OCP\Response::disableCaching();
OCP\Response::setContentLengthHeader($view->filesize($versionName));
OC_Util::obEnd();
$view->readfile($versionName);
Beispiel #3
0
    OCP\JSON::checkUserExists($user);
    OC_Util::tearDownFS();
    OC_Util::setupFS($user);
    OC_User::setIncognitoMode(true);
    $fullPath = \OC\Files\Filesystem::getPath($linkItem['file_source']);
    if ($fullPath === null) {
        exit;
    }
    $img = trim($fullPath . '/' . $img);
} else {
    OCP\JSON::checkLoggedIn();
    $user = OCP\User::getUser();
}
session_write_close();
$ownerView = new \OC\Files\View('/' . $user . '/files');
$mime = $ownerView->getMimeType($img);
list($mimePart, ) = explode('/', $mime);
if ($mimePart === 'image') {
    $fileInfo = $ownerView->getFileInfo($img);
    if ($fileInfo['encrypted'] === true) {
        $local = $ownerView->toTmpFile($img);
    } else {
        $local = $ownerView->getLocalFile($img);
    }
    $rotate = false;
    if (is_callable('exif_read_data')) {
        //don't use OCP\Image here, using OCP\Image will always cause parsing the image file
        $exif = @exif_read_data($local, 'IFD0');
        if (isset($exif['Orientation'])) {
            $rotate = $exif['Orientation'] > 1;
        }
Beispiel #4
0
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
OCP\JSON::checkAppEnabled('files_versions');
OCP\JSON::checkLoggedIn();
$file = $_GET['file'];
$revision = (int) $_GET['revision'];
list($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($file);
$versionName = '/' . $uid . '/files_versions/' . $filename . '.v' . $revision;
$view = new OC\Files\View('/');
$ftype = \OC_Helper::getSecureMimeType($view->getMimeType('/' . $uid . '/files/' . $filename));
header('Content-Type:' . $ftype);
OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
OCP\Response::disableCaching();
OCP\Response::setContentLengthHeader($view->filesize($versionName));
OC_Util::obEnd();
$view->readfile($versionName);
Beispiel #5
0
 /**
  * move file to the trash bin
  *
  * @param $file_path path to the deleted file/directory relative to the files root directory
  */
 public static function move2trash($file_path)
 {
     $user = \OCP\User::getUser();
     $size = 0;
     list($owner, $ownerPath) = self::getUidAndFilename($file_path);
     // file has been deleted in between
     if (empty($ownerPath)) {
         return false;
     }
     self::setUpTrash($user);
     if ($owner !== $user) {
         self::setUpTrash($owner);
     }
     $view = new \OC\Files\View('/' . $user);
     $path_parts = pathinfo($file_path);
     $filename = $path_parts['basename'];
     $location = $path_parts['dirname'];
     $timestamp = time();
     $mime = $view->getMimeType('files' . $file_path);
     if ($view->is_dir('files' . $file_path)) {
         $type = 'dir';
     } else {
         $type = 'file';
     }
     $userTrashSize = self::getTrashbinSize($user);
     if ($userTrashSize === false || $userTrashSize < 0) {
         $userTrashSize = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin'));
     }
     // disable proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
     try {
         $sizeOfAddedFiles = self::copy_recursive('/files/' . $file_path, $trashPath, $view);
     } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
         $sizeOfAddedFiles = false;
         if ($view->file_exists($trashPath)) {
             $view->deleteAll($trashPath);
         }
         \OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
     }
     \OC_FileProxy::$enabled = $proxyStatus;
     if ($sizeOfAddedFiles !== false) {
         $size = $sizeOfAddedFiles;
         $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
         $result = $query->execute(array($filename, $timestamp, $location, $type, $mime, $user));
         if (!$result) {
             // if file couldn't be added to the database than also don't store it in the trash bin.
             $view->deleteAll('files_trashbin/files/' . $filename . '.d' . $timestamp);
             \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
             return;
         }
         \OCP\Util::emitHook('\\OCA\\Files_Trashbin\\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path), 'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
         $size += self::retainVersions($file_path, $filename, $timestamp);
         $size += self::retainEncryptionKeys($file_path, $filename, $timestamp);
         // if owner !== user we need to also add a copy to the owners trash
         if ($user !== $owner) {
             self::copyFilesToOwner($file_path, $owner, $ownerPath, $timestamp, $type, $mime);
         }
     }
     $userTrashSize += $size;
     $userTrashSize -= self::expire($userTrashSize, $user);
     self::setTrashbinSize($user, $userTrashSize);
     // if owner !== user we also need to update the owners trash size
     if ($owner !== $user) {
         $ownerTrashSize = self::getTrashbinSize($owner);
         if ($ownerTrashSize === false || $ownerTrashSize < 0) {
             $ownerTrashSize = self::calculateSize(new \OC\Files\View('/' . $owner . '/files_trashbin'));
         }
         $ownerTrashSize += $size;
         $ownerTrashSize -= self::expire($ownerTrashSize, $owner);
         self::setTrashbinSize($owner, $ownerTrashSize);
     }
 }
Beispiel #6
0
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
OCP\JSON::checkAppEnabled('files_versions');
OCP\JSON::checkLoggedIn();
$file = $_GET['file'];
$revision = (int) $_GET['revision'];
list($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($file);
$versionName = '/' . $uid . '/files_versions/' . $filename . '.v' . $revision;
$view = new OC\Files\View('/');
$ftype = \OC::$server->getMimeTypeDetector()->getSecureMimeType($view->getMimeType('/' . $uid . '/files/' . $filename));
header('Content-Type:' . $ftype);
OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
OCP\Response::disableCaching();
OCP\Response::setContentLengthHeader($view->filesize($versionName));
OC_Util::obEnd();
$view->readfile($versionName);