summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/webdav.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/webdav.php')
-rw-r--r--apps/files_external/lib/webdav.php81
1 files changed, 41 insertions, 40 deletions
diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php
index 25b328ea2d0..68aca228bc5 100644
--- a/apps/files_external/lib/webdav.php
+++ b/apps/files_external/lib/webdav.php
@@ -27,20 +27,20 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
$this->host=$host;
$this->user=$params['user'];
$this->password=$params['password'];
- if(isset($params['secure'])) {
- if(is_string($params['secure'])) {
+ if (isset($params['secure'])) {
+ if (is_string($params['secure'])) {
$this->secure = ($params['secure'] === 'true');
- }else{
+ } else {
$this->secure = (bool)$params['secure'];
}
- }else{
+ } else {
$this->secure = false;
}
$this->root=isset($params['root'])?$params['root']:'/';
- if(!$this->root || $this->root[0]!='/') {
+ if ( ! $this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
- if(substr($this->root, -1, 1)!='/') {
+ if (substr($this->root, -1, 1)!='/') {
$this->root.='/';
}
@@ -52,7 +52,8 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
$this->client = new OC_Connector_Sabre_Client($settings);
- if($caview = \OCP\Files::getStorage('files_external')) {
+ $caview = \OCP\Files::getStorage('files_external');
+ if ($caview) {
$certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt';
if (file_exists($certPath)) {
$this->client->addTrustedCertificates($certPath);
@@ -64,7 +65,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
private function createBaseUri() {
$baseUri='http';
- if($this->secure) {
+ if ($this->secure) {
$baseUri.='s';
}
$baseUri.='://'.$this->host.$this->root;
@@ -83,29 +84,29 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
public function opendir($path) {
$path=$this->cleanPath($path);
- try{
+ try {
$response=$this->client->propfind($path, array(), 1);
$id=md5('webdav'.$this->root.$path);
OC_FakeDirStream::$dirs[$id]=array();
$files=array_keys($response);
array_shift($files);//the first entry is the current directory
- foreach($files as $file) {
+ foreach ($files as $file) {
$file = urldecode(basename($file));
OC_FakeDirStream::$dirs[$id][]=$file;
}
return opendir('fakedir://'.$id);
- }catch(Exception $e) {
+ } catch(Exception $e) {
return false;
}
}
public function filetype($path) {
$path=$this->cleanPath($path);
- try{
+ try {
$response=$this->client->propfind($path, array('{DAV:}resourcetype'));
$responseType=$response["{DAV:}resourcetype"]->resourceType;
return (count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file';
- }catch(Exception $e) {
+ } catch(Exception $e) {
error_log($e->getMessage());
\OCP\Util::writeLog("webdav client", \OCP\Util::sanitizeHTML($e->getMessage()), \OCP\Util::ERROR);
return false;
@@ -122,10 +123,10 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
public function file_exists($path) {
$path=$this->cleanPath($path);
- try{
+ try {
$this->client->propfind($path, array('{DAV:}resourcetype'));
return true;//no 404 exception
- }catch(Exception $e) {
+ } catch(Exception $e) {
return false;
}
}
@@ -139,7 +140,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
switch($mode) {
case 'r':
case 'rb':
- if(!$this->file_exists($path)) {
+ if ( ! $this->file_exists($path)) {
return false;
}
//straight up curl instead of sabredav here, sabredav put's the entire get result in memory
@@ -166,14 +167,14 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
case 'c':
case 'c+':
//emulate these
- if(strrpos($path, '.')!==false) {
+ if (strrpos($path, '.')!==false) {
$ext=substr($path, strrpos($path, '.'));
- }else{
+ } else {
$ext='';
}
$tmpFile=OCP\Files::tmpFile($ext);
OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this, 'writeBack');
- if($this->file_exists($path)) {
+ if ($this->file_exists($path)) {
$this->getFile($path, $tmpFile);
}
self::$tempFiles[$tmpFile]=$path;
@@ -182,7 +183,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
public function writeBack($tmpFile) {
- if(isset(self::$tempFiles[$tmpFile])) {
+ if (isset(self::$tempFiles[$tmpFile])) {
$this->uploadFile($tmpFile, self::$tempFiles[$tmpFile]);
unlink($tmpFile);
}
@@ -190,20 +191,20 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
public function free_space($path) {
$path=$this->cleanPath($path);
- try{
+ try {
$response=$this->client->propfind($path, array('{DAV:}quota-available-bytes'));
- if(isset($response['{DAV:}quota-available-bytes'])) {
+ if (isset($response['{DAV:}quota-available-bytes'])) {
return (int)$response['{DAV:}quota-available-bytes'];
- }else{
+ } else {
return 0;
}
- }catch(Exception $e) {
+ } catch(Exception $e) {
return 0;
}
}
public function touch($path, $mtime=null) {
- if(is_null($mtime)) {
+ if (is_null($mtime)) {
$mtime=time();
}
$path=$this->cleanPath($path);
@@ -232,10 +233,10 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
public function rename($path1, $path2) {
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
- try{
+ try {
$response=$this->client->request('MOVE', $path1, null, array('Destination'=>$path2));
return true;
- }catch(Exception $e) {
+ } catch(Exception $e) {
echo $e;
echo 'fail';
var_dump($response);
@@ -246,10 +247,10 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
public function copy($path1, $path2) {
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
- try{
+ try {
$response=$this->client->request('COPY', $path1, null, array('Destination'=>$path2));
return true;
- }catch(Exception $e) {
+ } catch(Exception $e) {
echo $e;
echo 'fail';
var_dump($response);
@@ -259,50 +260,50 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
public function stat($path) {
$path=$this->cleanPath($path);
- try{
+ try {
$response=$this->client->propfind($path, array('{DAV:}getlastmodified', '{DAV:}getcontentlength'));
return array(
'mtime'=>strtotime($response['{DAV:}getlastmodified']),
'size'=>(int)isset($response['{DAV:}getcontentlength']) ? $response['{DAV:}getcontentlength'] : 0,
'ctime'=>-1,
);
- }catch(Exception $e) {
+ } catch(Exception $e) {
return array();
}
}
public function getMimeType($path) {
$path=$this->cleanPath($path);
- try{
+ try {
$response=$this->client->propfind($path, array('{DAV:}getcontenttype', '{DAV:}resourcetype'));
$responseType=$response["{DAV:}resourcetype"]->resourceType;
$type=(count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file';
- if($type=='dir') {
+ if ($type=='dir') {
return 'httpd/unix-directory';
- }elseif(isset($response['{DAV:}getcontenttype'])) {
+ } elseif (isset($response['{DAV:}getcontenttype'])) {
return $response['{DAV:}getcontenttype'];
- }else{
+ } else {
return false;
}
- }catch(Exception $e) {
+ } catch(Exception $e) {
return false;
}
}
private function cleanPath($path) {
- if(!$path || $path[0]=='/') {
+ if ( ! $path || $path[0]=='/') {
return substr($path, 1);
- }else{
+ } else {
return $path;
}
}
private function simpleResponse($method, $path, $body, $expected) {
$path=$this->cleanPath($path);
- try{
+ try {
$response=$this->client->request($method, $path, $body);
return $response['statusCode']==$expected;
- }catch(Exception $e) {
+ } catch(Exception $e) {
return false;
}
}