aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-12-03 18:02:22 +0100
committerRobin Appelman <icewind@owncloud.com>2012-12-03 18:02:22 +0100
commitbe30b1a8de2c7858be3f1dfa792504478af70eb4 (patch)
treeeb3f69b006041c1a586479bb59dbf557df48eec0 /apps/files_external/lib
parent18663100d9f68400fba1fc344874aacb62bb4659 (diff)
parent4cb760a92402ab3eb8550fb05b05eae800030680 (diff)
downloadnextcloud-server-be30b1a8de2c7858be3f1dfa792504478af70eb4.tar.gz
nextcloud-server-be30b1a8de2c7858be3f1dfa792504478af70eb4.zip
merge master into filesystem
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r--apps/files_external/lib/amazons3.php28
-rwxr-xr-xapps/files_external/lib/config.php103
-rwxr-xr-xapps/files_external/lib/dropbox.php35
-rw-r--r--apps/files_external/lib/ftp.php32
-rw-r--r--apps/files_external/lib/google.php160
-rw-r--r--apps/files_external/lib/smb.php24
-rw-r--r--apps/files_external/lib/streamwrapper.php10
-rw-r--r--apps/files_external/lib/swift.php154
-rw-r--r--apps/files_external/lib/webdav.php89
9 files changed, 390 insertions, 245 deletions
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php
index c3fa4651f64..a209f0d0507 100644
--- a/apps/files_external/lib/amazons3.php
+++ b/apps/files_external/lib/amazons3.php
@@ -49,7 +49,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
if ($response) {
$this->objects[$path] = $response;
return $response;
- // This object could be a folder, a '/' must be at the end of the path
+ // This object could be a folder, a '/' must be at the end of the path
} else if (substr($path, -1) != '/') {
$response = $this->s3->get_object_metadata($this->bucket, $path.'/');
if ($response) {
@@ -129,12 +129,15 @@ class AmazonS3 extends \OC\Files\Storage\Common {
public function filetype($path) {
if ($path == '' || $path == '/') {
return 'dir';
- } else if ($object = $this->getObject($path)) {
- // Amazon S3 doesn't have typical folders, this is an alternative method to detect a folder
- if (substr($object['Key'], -1) == '/' && $object['Size'] == 0) {
- return 'dir';
- } else {
- return 'file';
+ } else {
+ $object = $this->getObject($path);
+ if ($object) {
+ // Amazon S3 doesn't have typical folders, this is an alternative method to detect a folder
+ if (substr($object['Key'], -1) == '/' && $object['Size'] == 0) {
+ return 'dir';
+ } else {
+ return 'file';
+ }
}
}
return false;
@@ -205,7 +208,9 @@ class AmazonS3 extends \OC\Files\Storage\Common {
public function writeBack($tmpFile) {
if (isset(self::$tempFiles[$tmpFile])) {
$handle = fopen($tmpFile, 'r');
- $response = $this->s3->create_object($this->bucket, self::$tempFiles[$tmpFile], array('fileUpload' => $handle));
+ $response = $this->s3->create_object($this->bucket,
+ self::$tempFiles[$tmpFile],
+ array('fileUpload' => $handle));
if ($response->isOK()) {
unlink($tmpFile);
}
@@ -215,8 +220,11 @@ class AmazonS3 extends \OC\Files\Storage\Common {
public function getMimeType($path) {
if ($this->filetype($path) == 'dir') {
return 'httpd/unix-directory';
- } else if ($object = $this->getObject($path)) {
- return $object['ContentType'];
+ } else {
+ $object = $this->getObject($path);
+ if ($object) {
+ return $object['ContentType'];
+ }
}
return false;
}
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 81225586326..6ec95f63266 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -39,14 +39,64 @@ class OC_Mount_Config {
*/
public static function getBackends() {
return array(
- '\OC\Files\Storage\Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')),
- '\OC\Files\Storage\AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')),
- '\OC\Files\Storage\Dropbox' => array('backend' => 'Dropbox', 'configuration' => array('configured' => '#configured','app_key' => 'App key', 'app_secret' => 'App secret', 'token' => '#token', 'token_secret' => '#token_secret'), 'custom' => 'dropbox'),
- '\OC\Files\Storage\FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')),
- '\OC\Files\Storage\Google' => array('backend' => 'Google Drive', 'configuration' => array('configured' => '#configured', 'token' => '#token', 'token_secret' => '#token secret'), 'custom' => 'google'),
- '\OC\Files\Storage\SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')),
- '\OC\Files\Storage\SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')),
- '\OC\Files\Storage\DAV' => array('backend' => 'WebDAV', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://'))
+ '\OC\Files\Storage\Local' => array(
+ 'backend' => 'Local',
+ 'configuration' => array(
+ 'datadir' => 'Location')),
+ '\OC\Files\Storage\AmazonS3' => array(
+ 'backend' => 'Amazon S3',
+ 'configuration' => array(
+ 'key' => 'Key',
+ 'secret' => '*Secret',
+ 'bucket' => 'Bucket')),
+ '\OC\Files\Storage\Dropbox' => array(
+ 'backend' => 'Dropbox',
+ 'configuration' => array(
+ 'configured' => '#configured',
+ 'app_key' => 'App key',
+ 'app_secret' => 'App secret',
+ 'token' => '#token',
+ 'token_secret' => '#token_secret'),
+ 'custom' => 'dropbox'),
+ '\OC\Files\Storage\FTP' => array(
+ 'backend' => 'FTP',
+ 'configuration' => array(
+ 'host' => 'URL',
+ 'user' => 'Username',
+ 'password' => '*Password',
+ 'root' => '&Root',
+ 'secure' => '!Secure ftps://')),
+ '\OC\Files\Storage\Google' => array(
+ 'backend' => 'Google Drive',
+ 'configuration' => array(
+ 'configured' => '#configured',
+ 'token' => '#token',
+ 'token_secret' => '#token secret'),
+ 'custom' => 'google'),
+ '\OC\Files\Storage\SWIFT' => array(
+ 'backend' => 'OpenStack Swift',
+ 'configuration' => array(
+ 'host' => 'URL',
+ 'user' => 'Username',
+ 'token' => '*Token',
+ 'root' => '&Root',
+ 'secure' => '!Secure ftps://')),
+ '\OC\Files\Storage\SMB' => array(
+ 'backend' => 'SMB',
+ 'configuration' => array(
+ 'host' => 'URL',
+ 'user' => 'Username',
+ 'password' => '*Password',
+ 'share' => 'Share',
+ 'root' => '&Root')),
+ '\OC\Files\Storage\DAV' => array(
+ 'backend' => 'WebDAV',
+ 'configuration' => array(
+ 'host' => 'URL',
+ 'user' => 'Username',
+ 'password' => '*Password',
+ 'root' => '&Root',
+ 'secure' => '!Secure https://'))
);
}
@@ -66,9 +116,14 @@ class OC_Mount_Config {
$mountPoint = substr($mountPoint, 13);
// Merge the mount point into the current mount points
if (isset($system[$mountPoint]) && $system[$mountPoint]['configuration'] == $mount['options']) {
- $system[$mountPoint]['applicable']['groups'] = array_merge($system[$mountPoint]['applicable']['groups'], array($group));
+ $system[$mountPoint]['applicable']['groups']
+ = array_merge($system[$mountPoint]['applicable']['groups'], array($group));
} else {
- $system[$mountPoint] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options'], 'applicable' => array('groups' => array($group), 'users' => array()));
+ $system[$mountPoint] = array(
+ 'class' => $mount['class'],
+ 'backend' => $backends[$mount['class']]['backend'],
+ 'configuration' => $mount['options'],
+ 'applicable' => array('groups' => array($group), 'users' => array()));
}
}
}
@@ -80,9 +135,13 @@ class OC_Mount_Config {
$mountPoint = substr($mountPoint, 13);
// Merge the mount point into the current mount points
if (isset($system[$mountPoint]) && $system[$mountPoint]['configuration'] == $mount['options']) {
- $system[$mountPoint]['applicable']['users'] = array_merge($system[$mountPoint]['applicable']['users'], array($user));
+ $system[$mountPoint]['applicable']['users']
+ = array_merge($system[$mountPoint]['applicable']['users'], array($user));
} else {
- $system[$mountPoint] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options'], 'applicable' => array('groups' => array(), 'users' => array($user)));
+ $system[$mountPoint] = array('class' => $mount['class'],
+ 'backend' => $backends[$mount['class']]['backend'],
+ 'configuration' => $mount['options'],
+ 'applicable' => array('groups' => array(), 'users' => array($user)));
}
}
}
@@ -103,7 +162,9 @@ class OC_Mount_Config {
if (isset($mountPoints[self::MOUNT_TYPE_USER][$uid])) {
foreach ($mountPoints[self::MOUNT_TYPE_USER][$uid] as $mountPoint => $mount) {
// Remove '/uid/files/' from mount point
- $personal[substr($mountPoint, strlen($uid) + 8)] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options']);
+ $personal[substr($mountPoint, strlen($uid) + 8)] = array('class' => $mount['class'],
+ 'backend' => $backends[$mount['class']]['backend'],
+ 'configuration' => $mount['options']);
}
}
return $personal;
@@ -135,7 +196,12 @@ class OC_Mount_Config {
* @param bool Personal or system mount point i.e. is this being called from the personal or admin page
* @return bool
*/
- public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false) {
+ public static function addMountPoint($mountPoint,
+ $class,
+ $classOptions,
+ $mountType,
+ $applicable,
+ $isPersonal = false) {
if ($isPersonal) {
// Verify that the mount point applies for the current user
// Prevent non-admin users from mounting local storage
@@ -176,7 +242,8 @@ class OC_Mount_Config {
// Merge the new mount point into the current mount points
if (isset($mountPoints[$mountType])) {
if (isset($mountPoints[$mountType][$applicable])) {
- $mountPoints[$mountType][$applicable] = array_merge($mountPoints[$mountType][$applicable], $mount[$applicable]);
+ $mountPoints[$mountType][$applicable]
+ = array_merge($mountPoints[$mountType][$applicable], $mount[$applicable]);
} else {
$mountPoints[$mountType] = array_merge($mountPoints[$mountType], $mount);
}
@@ -286,18 +353,18 @@ class OC_Mount_Config {
$view = \OCP\Files::getStorage('files_external');
$path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
\OCP\Util::writeLog('files_external', 'checking path '.$path, \OCP\Util::INFO);
- if(!is_dir($path)) {
+ if ( ! is_dir($path)) {
//path might not exist (e.g. non-standard OC_User::getHome() value)
//in this case create full path using 3rd (recursive=true) parameter.
mkdir($path, 0777, true);
}
$result = array();
$handle = opendir($path);
- if (!$handle) {
+ if ( ! $handle) {
return array();
}
while (false !== ($file = readdir($handle))) {
- if($file != '.' && $file != '..') $result[] = $file;
+ if ($file != '.' && $file != '..') $result[] = $file;
}
return $result;
}
diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php
index 0e82f80668f..9223b4ca87b 100755
--- a/apps/files_external/lib/dropbox.php
+++ b/apps/files_external/lib/dropbox.php
@@ -34,7 +34,12 @@ class Dropbox extends \OC\Files\Storage\Common {
private static $tempFiles = array();
public function __construct($params) {
- if (isset($params['configured']) && $params['configured'] == 'true' && isset($params['app_key']) && isset($params['app_secret']) && isset($params['token']) && isset($params['token_secret'])) {
+ if (isset($params['configured']) && $params['configured'] == 'true'
+ && isset($params['app_key'])
+ && isset($params['app_secret'])
+ && isset($params['token'])
+ && isset($params['token_secret'])
+ ) {
$this->id = 'dropbox::'.$params['app_key'] . $params['token']. '/' . $params['root'];
$this->root=isset($params['root'])?$params['root']:'';
$oauth = new \Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']);
@@ -48,7 +53,7 @@ class Dropbox extends \OC\Files\Storage\Common {
private function getMetaData($path, $list = false) {
$path = $this->root.$path;
- if (!$list && isset($this->metaData[$path])) {
+ if ( ! $list && isset($this->metaData[$path])) {
return $this->metaData[$path];
} else {
if ($list) {
@@ -103,7 +108,8 @@ class Dropbox extends \OC\Files\Storage\Common {
}
public function opendir($path) {
- if ($contents = $this->getMetaData($path, true)) {
+ $contents = $this->getMetaData($path, true);
+ if ($contents) {
$files = array();
foreach ($contents as $file) {
$files[] = basename($file['path']);
@@ -115,7 +121,8 @@ class Dropbox extends \OC\Files\Storage\Common {
}
public function stat($path) {
- if ($metaData = $this->getMetaData($path)) {
+ $metaData = $this->getMetaData($path);
+ if ($metaData) {
$stat['size'] = $metaData['bytes'];
$stat['atime'] = time();
$stat['mtime'] = (isset($metaData['modified'])) ? strtotime($metaData['modified']) : time();
@@ -127,11 +134,14 @@ class Dropbox extends \OC\Files\Storage\Common {
public function filetype($path) {
if ($path == '' || $path == '/') {
return 'dir';
- } else if ($metaData = $this->getMetaData($path)) {
- if ($metaData['is_dir'] == 'true') {
- return 'dir';
- } else {
- return 'file';
+ } else {
+ $metaData = $this->getMetaData($path);
+ if ($metaData) {
+ if ($metaData['is_dir'] == 'true') {
+ return 'dir';
+ } else {
+ return 'file';
+ }
}
}
return false;
@@ -248,8 +258,11 @@ class Dropbox extends \OC\Files\Storage\Common {
public function getMimeType($path) {
if ($this->filetype($path) == 'dir') {
return 'httpd/unix-directory';
- } else if ($metaData = $this->getMetaData($path)) {
- return $metaData['mime_type'];
+ } else {
+ $metaData = $this->getMetaData($path);
+ if ($metaData) {
+ return $metaData['mime_type'];
+ }
}
return false;
}
diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php
index 951dfd7f3cc..973b33fbfd7 100644
--- a/apps/files_external/lib/ftp.php
+++ b/apps/files_external/lib/ftp.php
@@ -21,21 +21,21 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
$this->host=$params['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;
}
- //create the root folder if necessary
- if (!$this->is_dir('')) {
+ //create the root folder if necesary
+ if ( ! $this->is_dir('')) {
$this->mkdir('');
}
}
@@ -51,7 +51,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
*/
public function constructUrl($path) {
$url='ftp';
- if($this->secure) {
+ if ($this->secure) {
$url.='s';
}
$url.='://'.$this->user.':'.$this->password.'@'.$this->host.$this->root.$path;
@@ -78,15 +78,15 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
case 'c':
case 'c+':
//emulate these
- if(strrpos($path,'.')!==false) {
- $ext=substr($path, strrpos($path,'.'));
- }else{
+ if (strrpos($path, '.')!==false) {
+ $ext=substr($path, strrpos($path, '.'));
+ } else {
$ext='';
}
- $tmpFile=\OCP\Files::tmpFile($ext);
- \OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
- if($this->file_exists($path)) {
- $this->getFile($path,$tmpFile);
+ $tmpFile=OCP\Files::tmpFile($ext);
+ OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this, 'writeBack');
+ if ($this->file_exists($path)) {
+ $this->getFile($path, $tmpFile);
}
self::$tempFiles[$tmpFile]=$path;
return fopen('close://'.$tmpFile,$mode);
@@ -96,7 +96,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
public function writeBack($tmpFile) {
$this->init();
- if(isset(self::$tempFiles[$tmpFile])) {
+ if (isset(self::$tempFiles[$tmpFile])) {
$this->uploadFile($tmpFile, self::$tempFiles[$tmpFile]);
unlink($tmpFile);
}
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php
index 12f3e975071..bbb315c4910 100644
--- a/apps/files_external/lib/google.php
+++ b/apps/files_external/lib/google.php
@@ -35,7 +35,10 @@ class Google extends \OC\Files\Storage\Common {
private static $tempFiles = array();
public function __construct($params) {
- if (isset($params['configured']) && $params['configured'] == 'true' && isset($params['token']) && isset($params['token_secret'])) {
+ if (isset($params['configured']) && $params['configured'] == 'true'
+ && isset($params['token'])
+ && isset($params['token_secret'])
+ ) {
$consumer_key = isset($params['consumer_key']) ? $params['consumer_key'] : 'anonymous';
$consumer_secret = isset($params['consumer_secret']) ? $params['consumer_secret'] : 'anonymous';
$this->id = 'google::' . $consumer_key . $consumer_secret;
@@ -48,7 +51,14 @@ class Google extends \OC\Files\Storage\Common {
}
}
- private function sendRequest($uri, $httpMethod, $postData = null, $extraHeaders = null, $isDownload = false, $returnHeaders = false, $isContentXML = true, $returnHTTPCode = false) {
+ private function sendRequest($uri,
+ $httpMethod,
+ $postData = null,
+ $extraHeaders = null,
+ $isDownload = false,
+ $returnHeaders = false,
+ $isContentXML = true,
+ $returnHTTPCode = false) {
$uri = trim($uri);
// create an associative array from each key/value url query param pair.
$params = array();
@@ -62,7 +72,11 @@ class Google extends \OC\Files\Storage\Common {
$tempStr .= '&' . urlencode($key) . '=' . urlencode($value);
}
$uri = preg_replace('/&/', '?', $tempStr, 1);
- $request = \OAuthRequest::from_consumer_and_token($this->consumer, $this->oauth_token, $httpMethod, $uri, $params);
+ $request = \OAuthRequest::from_consumer_and_token($this->consumer,
+ $this->oauth_token,
+ $httpMethod,
+ $uri,
+ $params);
$request->sign_request($this->sig_method, $this->consumer, $this->oauth_token);
$auth_header = $request->to_header();
$headers = array($auth_header, 'GData-Version: 3.0');
@@ -136,6 +150,11 @@ class Google extends \OC\Files\Storage\Common {
return false;
}
+ /**
+ * Base url for google docs feeds
+ */
+ const BASE_URI='https://docs.google.com/feeds';
+
private function getResource($path) {
$file = basename($path);
if (array_key_exists($file, $this->entries)) {
@@ -144,14 +163,14 @@ class Google extends \OC\Files\Storage\Common {
// Strip the file extension; file could be a native Google Docs resource
if ($pos = strpos($file, '.')) {
$title = substr($file, 0, $pos);
- $dom = $this->getFeed('https://docs.google.com/feeds/default/private/full?showfolders=true&title='.$title, 'GET');
+ $dom = $this->getFeed(self::BASE_URI.'/default/private/full?showfolders=true&title='.$title, 'GET');
// Check if request was successful and entry exists
if ($dom && $entry = $dom->getElementsByTagName('entry')->item(0)) {
$this->entries[$file] = $entry;
return $entry;
}
}
- $dom = $this->getFeed('https://docs.google.com/feeds/default/private/full?showfolders=true&title='.$file, 'GET');
+ $dom = $this->getFeed(self::BASE_URI.'/default/private/full?showfolders=true&title='.$file, 'GET');
// Check if request was successful and entry exists
if ($dom && $entry = $dom->getElementsByTagName('entry')->item(0)) {
$this->entries[$file] = $entry;
@@ -187,20 +206,25 @@ class Google extends \OC\Files\Storage\Common {
$collection = dirname($path);
// Check if path parent is root directory
if ($collection == '/' || $collection == '\.' || $collection == '.') {
- $uri = 'https://docs.google.com/feeds/default/private/full';
- // Get parent content link
- } else if ($dom = $this->getResource(basename($collection))) {
- $uri = $dom->getElementsByTagName('content')->item(0)->getAttribute('src');
+ $uri = self::BASE_URI.'/default/private/full';
+ } else {
+ // Get parent content link
+ $dom = $this->getResource(basename($collection));
+ if ($dom) {
+ $uri = $dom->getElementsByTagName('content')->item(0)->getAttribute('src');
+ }
}
if (isset($uri)) {
$title = basename($path);
// Construct post data
$postData = '<?xml version="1.0" encoding="UTF-8"?>';
$postData .= '<entry xmlns="http://www.w3.org/2005/Atom">';
- $postData .= '<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/docs/2007#folder"/>';
+ $postData .= '<category scheme="http://schemas.google.com/g/2005#kind"';
+ $postData .= ' term="http://schemas.google.com/docs/2007#folder"/>';
$postData .= '<title>'.$title.'</title>';
$postData .= '</entry>';
- if ($dom = $this->sendRequest($uri, 'POST', $postData)) {
+ $dom = $this->sendRequest($uri, 'POST', $postData);
+ if ($dom) {
return true;
}
}
@@ -213,9 +237,10 @@ class Google extends \OC\Files\Storage\Common {
public function opendir($path) {
if ($path == '' || $path == '/') {
- $next = 'https://docs.google.com/feeds/default/private/full/folder%3Aroot/contents';
+ $next = self::BASE_URI.'/default/private/full/folder%3Aroot/contents';
} else {
- if ($entry = $this->getResource($path)) {
+ $entry = $this->getResource($path);
+ if ($entry) {
$next = $entry->getElementsByTagName('content')->item(0)->getAttribute('src');
} else {
return false;
@@ -237,7 +262,7 @@ class Google extends \OC\Files\Storage\Common {
foreach ($entries as $entry) {
$name = $entry->getElementsByTagName('title')->item(0)->nodeValue;
// Google Docs resources don't always include extensions in title
- if (!strpos($name, '.')) {
+ if ( ! strpos($name, '.')) {
$extension = $this->getExtension($entry);
if ($extension != '') {
$name .= '.'.$extension;
@@ -257,12 +282,19 @@ class Google extends \OC\Files\Storage\Common {
$stat['size'] = $this->free_space($path);
$stat['atime'] = time();
$stat['mtime'] = time();
- } else if ($entry = $this->getResource($path)) {
- // NOTE: Native resources don't have a file size
- $stat['size'] = $entry->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'quotaBytesUsed')->item(0)->nodeValue;
-// if (isset($atime = $entry->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'lastViewed')->item(0)->nodeValue))
-// $stat['atime'] = strtotime($entry->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'lastViewed')->item(0)->nodeValue);
- $stat['mtime'] = strtotime($entry->getElementsByTagName('updated')->item(0)->nodeValue);
+ $stat['ctime'] = time();
+ } else {
+ $entry = $this->getResource($path);
+ if ($entry) {
+ // NOTE: Native resources don't have a file size
+ $stat['size'] = $entry->getElementsByTagNameNS('http://schemas.google.com/g/2005',
+ 'quotaBytesUsed')->item(0)->nodeValue;
+ //if (isset($atime = $entry->getElementsByTagNameNS('http://schemas.google.com/g/2005',
+ // 'lastViewed')->item(0)->nodeValue))
+ //$stat['atime'] = strtotime($entry->getElementsByTagNameNS('http://schemas.google.com/g/2005',
+ // 'lastViewed')->item(0)->nodeValue);
+ $stat['mtime'] = strtotime($entry->getElementsByTagName('updated')->item(0)->nodeValue);
+ }
}
if (isset($stat)) {
return $stat;
@@ -273,15 +305,18 @@ class Google extends \OC\Files\Storage\Common {
public function filetype($path) {
if ($path == '' || $path == '/') {
return 'dir';
- } else if ($entry = $this->getResource($path)) {
- $categories = $entry->getElementsByTagName('category');
- foreach ($categories as $category) {
- if ($category->getAttribute('scheme') == 'http://schemas.google.com/g/2005#kind') {
- $type = $category->getAttribute('label');
- if (strlen(strstr($type, 'folder')) > 0) {
- return 'dir';
- } else {
- return 'file';
+ } else {
+ $entry = $this->getResource($path);
+ if ($entry) {
+ $categories = $entry->getElementsByTagName('category');
+ foreach ($categories as $category) {
+ if ($category->getAttribute('scheme') == 'http://schemas.google.com/g/2005#kind') {
+ $type = $category->getAttribute('label');
+ if (strlen(strstr($type, 'folder')) > 0) {
+ return 'dir';
+ } else {
+ return 'file';
+ }
}
}
}
@@ -296,14 +331,17 @@ class Google extends \OC\Files\Storage\Common {
public function isUpdatable($path) {
if ($path == '' || $path == '/') {
return true;
- } else if ($entry = $this->getResource($path)) {
- // Check if edit or edit-media links exist
- $links = $entry->getElementsByTagName('link');
- foreach ($links as $link) {
- if ($link->getAttribute('rel') == 'edit') {
- return true;
- } else if ($link->getAttribute('rel') == 'edit-media') {
- return true;
+ } else {
+ $entry = $this->getResource($path);
+ if ($entry) {
+ // Check if edit or edit-media links exist
+ $links = $entry->getElementsByTagName('link');
+ foreach ($links as $link) {
+ if ($link->getAttribute('rel') == 'edit') {
+ return true;
+ } else if ($link->getAttribute('rel') == 'edit-media') {
+ return true;
+ }
}
}
}
@@ -321,7 +359,8 @@ class Google extends \OC\Files\Storage\Common {
public function unlink($path) {
// Get resource self link to trash resource
- if ($entry = $this->getResource($path)) {
+ $entry = $this->getResource($path);
+ if ($entry) {
$links = $entry->getElementsByTagName('link');
foreach ($links as $link) {
if ($link->getAttribute('rel') == 'self') {
@@ -338,7 +377,8 @@ class Google extends \OC\Files\Storage\Common {
}
public function rename($path1, $path2) {
- if ($entry = $this->getResource($path1)) {
+ $entry = $this->getResource($path1);
+ if ($entry) {
$collection = dirname($path2);
if (dirname($path1) == $collection) {
// Get resource edit link to rename resource
@@ -353,14 +393,18 @@ class Google extends \OC\Files\Storage\Common {
$title = basename($path2);
// Construct post data
$postData = '<?xml version="1.0" encoding="UTF-8"?>';
- $postData .= '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007" xmlns:gd="http://schemas.google.com/g/2005" gd:etag='.$etag.'>';
+ $postData .= '<entry xmlns="http://www.w3.org/2005/Atom"';
+ $postData .= ' xmlns:docs="http://schemas.google.com/docs/2007"';
+ $postData .= ' xmlns:gd="http://schemas.google.com/g/2005"';
+ $postData .= ' gd:etag='.$etag.'>';
$postData .= '<title>'.$title.'</title>';
$postData .= '</entry>';
$this->sendRequest($uri, 'PUT', $postData);
return true;
} else {
// Move to different collection
- if ($collectionEntry = $this->getResource($collection)) {
+ $collectionEntry = $this->getResource($collection);
+ if ($collectionEntry) {
$feedUri = $collectionEntry->getElementsByTagName('content')->item(0)->getAttribute('src');
// Construct post data
$postData = '<?xml version="1.0" encoding="UTF-8"?>';
@@ -379,7 +423,8 @@ class Google extends \OC\Files\Storage\Common {
switch ($mode) {
case 'r':
case 'rb':
- if ($entry = $this->getResource($path)) {
+ $entry = $this->getResource($path);
+ if ($entry) {
$extension = $this->getExtension($entry);
$downloadUri = $entry->getElementsByTagName('content')->item(0)->getAttribute('src');
// TODO Non-native documents don't need these additional parameters
@@ -425,14 +470,14 @@ class Google extends \OC\Files\Storage\Common {
private function uploadFile($path, $target) {
$entry = $this->getResource($target);
- if (!$entry) {
+ if ( ! $entry) {
if (dirname($target) == '.' || dirname($target) == '/') {
- $uploadUri = 'https://docs.google.com/feeds/upload/create-session/default/private/full/folder%3Aroot/contents';
+ $uploadUri = self::BASE_URI.'/upload/create-session/default/private/full/folder%3Aroot/contents';
} else {
$entry = $this->getResource(dirname($target));
}
}
- if (!isset($uploadUri) && $entry) {
+ if ( ! isset($uploadUri) && $entry) {
$links = $entry->getElementsByTagName('link');
foreach ($links as $link) {
if ($link->getAttribute('rel') == 'http://schemas.google.com/g/2005#resumable-create-media') {
@@ -471,7 +516,9 @@ class Google extends \OC\Files\Storage\Common {
}
}
$end = $i + $chunkSize - 1;
- $headers = array('Content-Length: '.$chunkSize, 'Content-Type: '.$mimetype, 'Content-Range: bytes '.$i.'-'.$end.'/'.$size);
+ $headers = array('Content-Length: '.$chunkSize,
+ 'Content-Type: '.$mimetype,
+ 'Content-Range: bytes '.$i.'-'.$end.'/'.$size);
$postData = fread($handle, $chunkSize);
$result = $this->sendRequest($uploadUri, 'PUT', $postData, $headers, false, true, false, true);
if ($result['code'] == '308') {
@@ -489,7 +536,8 @@ class Google extends \OC\Files\Storage\Common {
}
public function getMimeType($path, $entry = null) {
- // Entry can be passed, because extension is required for opendir and the entry can't be cached without the extension
+ // Entry can be passed, because extension is required for opendir
+ // and the entry can't be cached without the extension
if ($entry == null) {
if ($path == '' || $path == '/') {
return 'httpd/unix-directory';
@@ -499,8 +547,10 @@ class Google extends \OC\Files\Storage\Common {
}
if ($entry) {
$mimetype = $entry->getElementsByTagName('content')->item(0)->getAttribute('type');
- // Native Google Docs resources often default to text/html, but it may be more useful to default to a corresponding ODF mimetype
- // Collections get reported as application/atom+xml, make sure it actually is a folder and fix the mimetype
+ // Native Google Docs resources often default to text/html,
+ // but it may be more useful to default to a corresponding ODF mimetype
+ // Collections get reported as application/atom+xml,
+ // make sure it actually is a folder and fix the mimetype
if ($mimetype == 'text/html' || $mimetype == 'application/atom+xml;type=feed') {
$categories = $entry->getElementsByTagName('category');
foreach ($categories as $category) {
@@ -517,7 +567,8 @@ class Google extends \OC\Files\Storage\Common {
} else if (strlen(strstr($type, 'drawing')) > 0) {
return 'application/vnd.oasis.opendocument.graphics';
} else {
- // If nothing matches return text/html, all native Google Docs resources can be exported as text/html
+ // If nothing matches return text/html,
+ // all native Google Docs resources can be exported as text/html
return 'text/html';
}
}
@@ -529,10 +580,13 @@ class Google extends \OC\Files\Storage\Common {
}
public function free_space($path) {
- if ($dom = $this->getFeed('https://docs.google.com/feeds/metadata/default', 'GET')) {
+ $dom = $this->getFeed(self::BASE_URI.'/metadata/default', 'GET');
+ if ($dom) {
// NOTE: Native Google Docs resources don't count towards quota
- $total = $dom->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'quotaBytesTotal')->item(0)->nodeValue;
- $used = $dom->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'quotaBytesUsed')->item(0)->nodeValue;
+ $total = $dom->getElementsByTagNameNS('http://schemas.google.com/g/2005',
+ 'quotaBytesTotal')->item(0)->nodeValue;
+ $used = $dom->getElementsByTagNameNS('http://schemas.google.com/g/2005',
+ 'quotaBytesUsed')->item(0)->nodeValue;
return $total - $used;
}
return false;
diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php
index a4b2338e3b2..96778b0b2e1 100644
--- a/apps/files_external/lib/smb.php
+++ b/apps/files_external/lib/smb.php
@@ -23,13 +23,13 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
$this->password=$params['password'];
$this->share=$params['share'];
$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.='/';
}
- if(!$this->share || $this->share[0]!='/') {
+ if ( ! $this->share || $this->share[0]!='/') {
$this->share='/'.$this->share;
}
if(substr($this->share, -1, 1)=='/') {
@@ -42,25 +42,26 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
}
public function constructUrl($path) {
- if(substr($path, -1)=='/') {
+ if (substr($path, -1)=='/') {
$path=substr($path, 0, -1);
}
return 'smb://'.$this->user.':'.$this->password.'@'.$this->host.$this->share.$this->root.$path;
}
public function stat($path) {
- if(!$path and $this->root=='/') {//mtime doesn't work for shares
+ if ( ! $path and $this->root=='/') {//mtime doesn't work for shares
$mtime=$this->shareMTime();
$stat=stat($this->constructUrl($path));
$stat['mtime']=$mtime;
return $stat;
- }else{
+ } else {
return stat($this->constructUrl($path));
}
}
public function filetype($path) {
- return (bool)@$this->opendir($path) ? 'dir' : 'file';//using opendir causes the same amount of requests and caches the content of the folder in one go
+ // using opendir causes the same amount of requests and caches the content of the folder in one go
+ return (bool)@$this->opendir($path) ? 'dir' : 'file';
}
/**
@@ -72,9 +73,10 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
public function hasUpdated($path,$time) {
$this->init();
if(!$path and $this->root=='/') {
- //mtime doesn't work for shares, but giving the nature of the backend, doing a full update is still just fast enough
+ // mtime doesn't work for shares, but giving the nature of the backend,
+ // doing a full update is still just fast enough
return true;
- }else{
+ } else {
$actualTime=$this->filemtime($path);
return $actualTime>$time;
}
@@ -87,9 +89,9 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
$dh=$this->opendir('');
$lastCtime=0;
while($file=readdir($dh)) {
- if($file!='.' and $file!='..') {
+ if ($file!='.' and $file!='..') {
$ctime=$this->filemtime($file);
- if($ctime>$lastCtime) {
+ if ($ctime>$lastCtime) {
$lastCtime=$ctime;
}
}
diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php
index bc1c95c5e8f..7c3ddcf8a2c 100644
--- a/apps/files_external/lib/streamwrapper.php
+++ b/apps/files_external/lib/streamwrapper.php
@@ -33,10 +33,10 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common{
public function rmdir($path) {
$this->init();
if($this->file_exists($path)) {
- $succes=rmdir($this->constructUrl($path));
+ $succes = rmdir($this->constructUrl($path));
clearstatcache();
return $succes;
- }else{
+ } else {
return false;
}
}
@@ -66,7 +66,7 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common{
public function unlink($path) {
$this->init();
- $succes=unlink($this->constructUrl($path));
+ $succes = unlink($this->constructUrl($path));
clearstatcache();
return $succes;
}
@@ -83,10 +83,10 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common{
public function touch($path,$mtime=null) {
$this->init();
if(is_null($mtime)) {
- $fh=$this->fopen($path,'a');
+ $fh = $this->fopen($path,'a');
fwrite($fh,'');
fclose($fh);
- }else{
+ } else {
return false;//not supported
}
}
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index d7ab38fbe2a..bd1f4c572a6 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -43,8 +43,8 @@ class SWIFT extends \OC\Files\Storage\Common{
* @return string
*/
private function getContainerName($path) {
- $path=trim(trim($this->root,'/')."/".$path,'/.');
- return str_replace('/','\\',$path);
+ $path=trim(trim($this->root, '/') . "/".$path, '/.');
+ return str_replace('/', '\\', $path);
}
/**
@@ -53,17 +53,17 @@ class SWIFT extends \OC\Files\Storage\Common{
* @return \CF_Container
*/
private function getContainer($path) {
- if($path=='' or $path=='/') {
+ if ($path=='' or $path=='/') {
return $this->rootContainer;
}
- if(isset($this->containers[$path])) {
+ if (isset($this->containers[$path])) {
return $this->containers[$path];
}
- try{
+ try {
$container=$this->conn->get_container($this->getContainerName($path));
$this->containers[$path]=$container;
return $container;
- }catch(\NoSuchContainerException $e) {
+ } catch(\NoSuchContainerException $e) {
return null;
}
}
@@ -74,16 +74,16 @@ class SWIFT extends \OC\Files\Storage\Common{
* @return \CF_Container
*/
private function createContainer($path) {
- if($path=='' or $path=='/' or $path=='.') {
+ if ($path=='' or $path=='/' or $path=='.') {
return $this->conn->create_container($this->getContainerName($path));
}
$parent=dirname($path);
- if($parent=='' or $parent=='/' or $parent=='.') {
+ if ($parent=='' or $parent=='/' or $parent=='.') {
$parentContainer=$this->rootContainer;
- }else{
- if(!$this->containerExists($parent)) {
+ } else {
+ if ( ! $this->containerExists($parent)) {
$parentContainer=$this->createContainer($parent);
- }else{
+ } else {
$parentContainer=$this->getContainer($parent);
}
}
@@ -97,21 +97,21 @@ class SWIFT extends \OC\Files\Storage\Common{
* @return \CF_Object
*/
private function getObject($path) {
- if(isset($this->objects[$path])) {
+ if (isset($this->objects[$path])) {
return $this->objects[$path];
}
$container=$this->getContainer(dirname($path));
- if(is_null($container)) {
+ if (is_null($container)) {
return null;
- }else{
+ } else {
if ($path=="/" or $path=='') {
return null;
}
- try{
+ try {
$obj=$container->get_object(basename($path));
$this->objects[$path]=$obj;
return $obj;
- }catch(\NoSuchObjectException $e) {
+ } catch(\NoSuchObjectException $e) {
return null;
}
}
@@ -123,11 +123,11 @@ class SWIFT extends \OC\Files\Storage\Common{
* @return array
*/
private function getObjects($container) {
- if(is_null($container)) {
+ if (is_null($container)) {
return array();
- }else{
+ } else {
$files=$container->get_objects();
- foreach($files as &$file) {
+ foreach ($files as &$file) {
$file=$file->name;
}
return $files;
@@ -141,7 +141,7 @@ class SWIFT extends \OC\Files\Storage\Common{
*/
private function createObject($path) {
$container=$this->getContainer(dirname($path));
- if(!is_null($container)) {
+ if ( ! is_null($container)) {
$container=$this->createContainer(dirname($path));
}
return $container->create_object(basename($path));
@@ -173,15 +173,15 @@ class SWIFT extends \OC\Files\Storage\Common{
private function getSubContainers($container) {
$tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
- try{
+ try {
$obj->save_to_filename($tmpFile);
- }catch(\Exception $e) {
+ } catch(\Exception $e) {
return array();
}
$obj->save_to_filename($tmpFile);
$containers=file($tmpFile);
unlink($tmpFile);
- foreach($containers as &$sub) {
+ foreach ($containers as &$sub) {
$sub=trim($sub);
}
return $containers;
@@ -193,26 +193,26 @@ class SWIFT extends \OC\Files\Storage\Common{
* @param string $name
* @return bool
*/
- private function addSubContainer($container,$name) {
- if(!$name) {
+ private function addSubContainer($container, $name) {
+ if ( ! $name) {
return false;
}
$tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
- try{
+ try {
$obj->save_to_filename($tmpFile);
$containers=file($tmpFile);
- foreach($containers as &$sub) {
+ foreach ($containers as &$sub) {
$sub=trim($sub);
}
if(array_search($name, $containers) !== false) {
unlink($tmpFile);
return false;
- }else{
+ } else {
$fh=fopen($tmpFile, 'a');
fwrite($fh,$name . "\n");
}
- }catch(\Exception $e) {
+ } catch(\Exception $e) {
file_put_contents($tmpFile, $name . "\n");
}
@@ -228,25 +228,25 @@ class SWIFT extends \OC\Files\Storage\Common{
* @return bool
*/
private function removeSubContainer($container, $name) {
- if(!$name) {
+ if ( ! $name) {
return false;
}
$tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
- try{
+ try {
$obj->save_to_filename($tmpFile);
$containers=file($tmpFile);
- }catch(\Exception $e) {
+ } catch (\Exception $e) {
return false;
}
- foreach($containers as &$sub) {
+ foreach ($containers as &$sub) {
$sub=trim($sub);
}
$i=array_search($name, $containers);
- if($i===false) {
+ if ($i===false) {
unlink($tmpFile);
return false;
- }else{
+ } else {
unset($containers[$i]);
file_put_contents($tmpFile, implode("\n", $containers)."\n");
}
@@ -262,9 +262,9 @@ class SWIFT extends \OC\Files\Storage\Common{
* @return \CF_Object
*/
private function getSubContainerFile($container) {
- try{
+ try {
return $container->get_object(self::SUBCONTAINER_FILE);
- }catch(NoSuchObjectException $e) {
+ } catch(NoSuchObjectException $e) {
return $container->create_object(self::SUBCONTAINER_FILE);
}
}
@@ -274,16 +274,16 @@ class SWIFT extends \OC\Files\Storage\Common{
$this->host=$params['host'];
$this->user=$params['user'];
$this->root=isset($params['root'])?$params['root']:'/';
- 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;
}
- if(!$this->root || $this->root[0]!='/') {
+ if ( ! $this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
@@ -300,9 +300,9 @@ class SWIFT extends \OC\Files\Storage\Common{
$this->conn = new \CF_Connection($this->auth);
- if(!$this->containerExists('/')) {
+ if ( ! $this->containerExists('/')) {
$this->rootContainer=$this->createContainer('/');
- }else{
+ } else {
$this->rootContainer=$this->getContainer('/');
}
}
@@ -314,9 +314,9 @@ class SWIFT extends \OC\Files\Storage\Common{
public function mkdir($path) {
$this->init();
- if($this->containerExists($path)) {
+ if ($this->containerExists($path)) {
return false;
- }else{
+ } else {
$this->createContainer($path);
return true;
}
@@ -324,11 +324,11 @@ class SWIFT extends \OC\Files\Storage\Common{
public function rmdir($path) {
$this->init();
- if(!$this->containerExists($path)) {
+ if (!$this->containerExists($path)) {
return false;
- }else{
+ } else {
$this->emptyContainer($path);
- if($path!='' and $path!='/') {
+ if ($path!='' and $path!='/') {
$parentContainer=$this->getContainer(dirname($path));
$this->removeSubContainer($parentContainer, basename($path));
}
@@ -341,12 +341,12 @@ class SWIFT extends \OC\Files\Storage\Common{
private function emptyContainer($path) {
$container=$this->getContainer($path);
- if(is_null($container)) {
+ if (is_null($container)) {
return;
}
$subContainers=$this->getSubContainers($container);
- foreach($subContainers as $sub) {
- if($sub) {
+ foreach ($subContainers as $sub) {
+ if ($sub) {
$this->emptyContainer($path.'/'.$sub);
$this->conn->delete_container($this->getContainerName($path.'/'.$sub));
unset($this->containers[$path.'/'.$sub]);
@@ -354,7 +354,7 @@ class SWIFT extends \OC\Files\Storage\Common{
}
$objects=$this->getObjects($container);
- foreach($objects as $object) {
+ foreach ($objects as $object) {
$container->delete_object($object);
unset($this->objects[$path.'/'.$object]);
}
@@ -365,7 +365,7 @@ class SWIFT extends \OC\Files\Storage\Common{
$container=$this->getContainer($path);
$files=$this->getObjects($container);
$i=array_search(self::SUBCONTAINER_FILE, $files);
- if($i!==false) {
+ if ($i!==false) {
unset($files[$i]);
}
$subContainers=$this->getSubContainers($container);
@@ -377,9 +377,9 @@ class SWIFT extends \OC\Files\Storage\Common{
public function filetype($path) {
$this->init();
- if($this->containerExists($path)) {
+ if ($this->containerExists($path)) {
return 'dir';
- }else{
+ } else {
return 'file';
}
}
@@ -394,9 +394,9 @@ class SWIFT extends \OC\Files\Storage\Common{
public function file_exists($path) {
$this->init();
- if($this->is_dir($path)) {
+ if ($this->is_dir($path)) {
return true;
- }else{
+ } else {
return $this->objectExists($path);
}
}
@@ -404,7 +404,7 @@ class SWIFT extends \OC\Files\Storage\Common{
public function file_get_contents($path) {
$this->init();
$obj=$this->getObject($path);
- if(is_null($obj)) {
+ if (is_null($obj)) {
return false;
}
return $obj->read();
@@ -413,9 +413,9 @@ class SWIFT extends \OC\Files\Storage\Common{
public function file_put_contents($path, $content) {
$this->init();
$obj=$this->getObject($path);
- if(is_null($obj)) {
+ if (is_null($obj)) {
$container=$this->getContainer(dirname($path));
- if(is_null($container)) {
+ if (is_null($container)) {
return false;
}
$obj=$container->create_object(basename($path));
@@ -426,14 +426,14 @@ class SWIFT extends \OC\Files\Storage\Common{
public function unlink($path) {
$this->init();
- if($this->containerExists($path)) {
+ if ($this->containerExists($path)) {
return $this->rmdir($path);
}
- if($this->objectExists($path)) {
+ if ($this->objectExists($path)) {
$container=$this->getContainer(dirname($path));
$container->delete_object(basename($path));
unset($this->objects[$path]);
- }else{
+ } else {
return false;
}
}
@@ -472,7 +472,7 @@ class SWIFT extends \OC\Files\Storage\Common{
}
public function writeBack($tmpFile) {
- if(isset(self::$tempFiles[$tmpFile])) {
+ if (isset(self::$tempFiles[$tmpFile])) {
$this->fromTmpFile($tmpFile, self::$tempFiles[$tmpFile]);
unlink($tmpFile);
}
@@ -485,10 +485,10 @@ class SWIFT extends \OC\Files\Storage\Common{
public function touch($path, $mtime=null) {
$this->init();
$obj=$this->getObject($path);
- if(is_null($obj)) {
+ if (is_null($obj)) {
return false;
}
- if(is_null($mtime)) {
+ if (is_null($mtime)) {
$mtime=time();
}
@@ -503,7 +503,7 @@ class SWIFT extends \OC\Files\Storage\Common{
$targetContainer=$this->getContainer(dirname($path2));
$result=$sourceContainer->move_object_to(basename($path1), $targetContainer, basename($path2));
unset($this->objects[$path1]);
- if($result) {
+ if ($result) {
$targetObj=$this->getObject($path2);
$this->resetMTime($targetObj);
}
@@ -515,7 +515,7 @@ class SWIFT extends \OC\Files\Storage\Common{
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
$result=$sourceContainer->copy_object_to(basename($path1), $targetContainer, basename($path2));
- if($result) {
+ if ($result) {
$targetObj=$this->getObject($path2);
$this->resetMTime($targetObj);
}
@@ -525,7 +525,7 @@ class SWIFT extends \OC\Files\Storage\Common{
public function stat($path) {
$this->init();
$container=$this->getContainer($path);
- if (!is_null($container)) {
+ if ( ! is_null($container)) {
return array(
'mtime'=>-1,
'size'=>$container->bytes_used,
@@ -535,13 +535,13 @@ class SWIFT extends \OC\Files\Storage\Common{
$obj=$this->getObject($path);
- if(is_null($obj)) {
+ if (is_null($obj)) {
return false;
}
- if(isset($obj->metadata['Mtime']) and $obj->metadata['Mtime']>-1) {
+ if (isset($obj->metadata['Mtime']) and $obj->metadata['Mtime']>-1) {
$mtime=$obj->metadata['Mtime'];
- }else{
+ } else {
$mtime=strtotime($obj->last_modified);
}
return array(
@@ -554,11 +554,11 @@ class SWIFT extends \OC\Files\Storage\Common{
private function getTmpFile($path) {
$this->init();
$obj=$this->getObject($path);
- if(!is_null($obj)) {
+ if ( ! is_null($obj)) {
$tmpFile=\OCP\Files::tmpFile();
$obj->save_to_filename($tmpFile);
return $tmpFile;
- }else{
+ } else {
return \OCP\Files::tmpFile();
}
}
@@ -566,7 +566,7 @@ class SWIFT extends \OC\Files\Storage\Common{
private function fromTmpFile($tmpFile, $path) {
$this->init();
$obj=$this->getObject($path);
- if(is_null($obj)) {
+ if (is_null($obj)) {
$obj=$this->createObject($path);
}
$obj->load_from_filename($tmpFile);
@@ -578,7 +578,7 @@ class SWIFT extends \OC\Files\Storage\Common{
* @param \CF_Object $obj
*/
private function resetMTime($obj) {
- if(isset($obj->metadata['Mtime'])) {
+ if (isset($obj->metadata['Mtime'])) {
$obj->metadata['Mtime']=-1;
$obj->sync_metadata();
}
diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php
index 973c95fe58b..19b6ec2fd2c 100644
--- a/apps/files_external/lib/webdav.php
+++ b/apps/files_external/lib/webdav.php
@@ -30,20 +30,20 @@ class DAV extends \OC\Files\Storage\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.='/';
}
}
@@ -62,7 +62,8 @@ class DAV extends \OC\Files\Storage\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);
@@ -78,7 +79,7 @@ class DAV extends \OC\Files\Storage\Common{
private function createBaseUri() {
$baseUri='http';
- if($this->secure) {
+ if ($this->secure) {
$baseUri.='s';
}
$baseUri.='://'.$this->host.$this->root;
@@ -100,18 +101,18 @@ class DAV extends \OC\Files\Storage\Common{
public function opendir($path) {
$this->init();
$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;
}
}
@@ -119,11 +120,11 @@ class DAV extends \OC\Files\Storage\Common{
public function filetype($path) {
$this->init();
$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;
@@ -141,10 +142,10 @@ class DAV extends \OC\Files\Storage\Common{
public function file_exists($path) {
$this->init();
$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;
}
}
@@ -160,7 +161,7 @@ class DAV extends \OC\Files\Storage\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
@@ -187,9 +188,9 @@ class DAV extends \OC\Files\Storage\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);
@@ -203,7 +204,7 @@ class DAV extends \OC\Files\Storage\Common{
}
public function writeBack($tmpFile) {
- if(isset(self::$tempFiles[$tmpFile])) {
+ if (isset(self::$tempFiles[$tmpFile])) {
$this->uploadFile($tmpFile, self::$tempFiles[$tmpFile]);
unlink($tmpFile);
}
@@ -212,21 +213,21 @@ class DAV extends \OC\Files\Storage\Common{
public function free_space($path) {
$this->init();
$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) {
+ public function touch($path, $mtime=null) {
$this->init();
- if(is_null($mtime)) {
+ if (is_null($mtime)) {
$mtime=time();
}
$path=$this->cleanPath($path);
@@ -258,10 +259,10 @@ class DAV extends \OC\Files\Storage\Common{
$this->init();
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
- try{
- $this->client->request('MOVE', $path1, null, array('Destination' => $path2));
+ try {
+ $this->client->request('MOVE', $path1, null, array('Destination'=>$path2));
return true;
- }catch(\Exception $e) {
+ } catch(\Exception $e) {
return false;
}
}
@@ -270,10 +271,10 @@ class DAV extends \OC\Files\Storage\Common{
$this->init();
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
- try{
- $this->client->request('COPY', $path1, null, array('Destination' => $path2));
+ try {
+ $this->client->request('COPY', $path1, null, array('Destination'=>$path2));
return true;
- }catch(\Exception $e) {
+ } catch(\Exception $e) {
return false;
}
}
@@ -281,13 +282,13 @@ class DAV extends \OC\Files\Storage\Common{
public function stat($path) {
$this->init();
$path=$this->cleanPath($path);
- try{
- $response=$this->client->propfind($path, array('{DAV:}getlastmodified','{DAV:}getcontentlength'));
+ 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,
);
- }catch(\Exception $e) {
+ } catch(\Exception $e) {
return array();
}
}
@@ -295,36 +296,36 @@ class DAV extends \OC\Files\Storage\Common{
public function getMimeType($path) {
$this->init();
$path=$this->cleanPath($path);
- try{
- $response=$this->client->propfind($path, array('{DAV:}getcontenttype','{DAV:}resourcetype'));
+ 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;
}
}