richdocuments/lib/view.php

60 lines
1.5 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
public function initDocumentsView(){
if (!$this->is_dir(self::DOCUMENTS_DIRNAME)) {
$this->mkdir(self::DOCUMENTS_DIRNAME);
2013-08-07 21:14:36 +03:00
}
return new \OC\Files\View( $this->getRoot() . self::DOCUMENTS_DIRNAME);
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;
}
public function storeDocument($ownerView, $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
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);
2013-08-07 21:14:36 +03:00
\OC_FileProxy::$enabled = $proxyStatus;
2013-08-08 00:08:20 +03:00
return $newName;
}
public function getHashByGenesis($genesisPath){
return sha1($this->file_get_contents(self::DOCUMENTS_DIRNAME . $genesisPath));
2013-08-07 21:14:36 +03:00
}
}