richdocuments/lib/view.php

68 lines
1.7 KiB
PHP
Raw Normal View History

2013-08-07 21:14:36 +03:00
<?php
2013-08-08 00:22:21 +03:00
/**
2013-08-28 12:02:27 +02:00
* ownCloud - Documents App
2013-08-08 00:22:21 +03:00
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
2013-08-07 21:14:36 +03:00
2013-08-28 12:02:27 +02:00
namespace OCA\Documents;
2013-08-07 21:14:36 +03:00
class View extends \OC\Files\View{
2013-08-28 12:02:27 +02:00
const DOCUMENTS_DIRNAME='/documents';
protected static $documentsView;
2013-08-07 21:14:36 +03:00
2013-11-08 15:46:30 +00:00
public function initDocumentsView($owner){
$ownerView = new View('/' . $owner);
if (!$ownerView->is_dir(self::DOCUMENTS_DIRNAME)) {
$ownerView->mkdir(self::DOCUMENTS_DIRNAME);
2013-08-07 21:14:36 +03:00
}
2013-11-08 15:46:30 +00:00
return $ownerView;
2013-08-07 21:14:36 +03:00
}
public function getFilePermissions($path){
2013-09-23 22:56:27 +03:00
$permissions = 0;
if ($this->isReadable($path)) {
2013-09-23 22:56:27 +03:00
$permissions |= \OCP\PERMISSION_READ;
}
if ($this->isSharable($path)) {
2013-09-23 22:56:27 +03:00
$permissions |= \OCP\PERMISSION_SHARE;
}
return $permissions;
}
2013-11-06 20:49:48 +03:00
public function storeDocument($owner, $filePath){
2013-08-07 21:14:36 +03:00
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
2013-08-08 00:08:20 +03:00
2013-11-06 20:49:48 +03:00
$ownerView = new View('/' . $owner);
$filePath = '/files' . $filePath;
if (!$ownerView->file_exists($filePath)){
throw new \Exception($filePath . ' doesn\'t exist');
2013-08-17 19:42:50 +03:00
}
if (!$ownerView->is_file($filePath)){
throw new \Exception('Object ' . $filePath . ' is not a file.');
}
$newName = '/' . sha1($ownerView->file_get_contents($filePath)) . '.odt';
2013-08-08 14:02:54 +03:00
$ownerView->copy($filePath, self::DOCUMENTS_DIRNAME . $newName);
if (!$ownerView->file_exists(self::DOCUMENTS_DIRNAME . $newName)){
throw new \Exception('Failed to copy genesis');
}
2013-08-07 21:14:36 +03:00
\OC_FileProxy::$enabled = $proxyStatus;
2013-08-08 00:08:20 +03:00
return $newName;
}
2013-11-06 20:49:48 +03:00
public function getHashByGenesis($owner, $genesisPath){
$ownerView = new View('/' . $owner);
return sha1($ownerView->file_get_contents(self::DOCUMENTS_DIRNAME . $genesisPath));
2013-08-07 21:14:36 +03:00
}
}