fix checkstyle for files_external app, add whitespace for readability

This commit is contained in:
Jörn Friedrich Dreyer 2012-11-30 16:27:11 +01:00
parent df21ebeaf7
commit 92df70b6e5
22 changed files with 527 additions and 306 deletions

View File

@ -10,4 +10,9 @@ if ($_POST['isPersonal'] == 'true') {
OCP\JSON::checkAdminUser();
$isPersonal = false;
}
OC_Mount_Config::addMountPoint($_POST['mountPoint'], $_POST['class'], $_POST['classOptions'], $_POST['mountType'], $_POST['applicable'], $isPersonal);
OC_Mount_Config::addMountPoint($_POST['mountPoint'],
$_POST['class'],
$_POST['classOptions'],
$_POST['mountType'],
$_POST['applicable'],
$isPersonal);

View File

@ -29,8 +29,10 @@ if ( $isValid ) {
$view->file_put_contents($filename, $data);
OC_Mount_Config::createCertificateBundle();
} else {
OCP\Util::writeLog("files_external", "Couldn't import SSL root certificate ($filename), allowed formats: PEM and DER", OCP\Util::WARN);
OCP\Util::writeLog('files_external',
'Couldn\'t import SSL root certificate ('.$filename.'), allowed formats: PEM and DER',
OCP\Util::WARN);
}
header("Location: settings/personal.php");
header('Location: settings/personal.php');
exit;

View File

@ -16,9 +16,13 @@ if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
$callback = null;
}
$token = $oauth->getRequestToken();
OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback), 'request_token' => $token['token'], 'request_token_secret' => $token['token_secret'])));
OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback),
'request_token' => $token['token'],
'request_token_secret' => $token['token_secret'])));
} catch (Exception $exception) {
OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.')));
OCP\JSON::error(array('data' => array('message' =>
'Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.')
));
}
break;
case 2:
@ -26,9 +30,12 @@ if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
try {
$oauth->setToken($_POST['request_token'], $_POST['request_token_secret']);
$token = $oauth->getAccessToken();
OCP\JSON::success(array('access_token' => $token['token'], 'access_token_secret' => $token['token_secret']));
OCP\JSON::success(array('access_token' => $token['token'],
'access_token_secret' => $token['token_secret']));
} catch (Exception $exception) {
OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.')));
OCP\JSON::error(array('data' => array('message' =>
'Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.')
));
}
}
break;

View File

@ -14,7 +14,9 @@ if (isset($_POST['step'])) {
} else {
$callback = null;
}
$scope = 'https://docs.google.com/feeds/ https://docs.googleusercontent.com/ https://spreadsheets.google.com/feeds/';
$scope = 'https://docs.google.com/feeds/'
.' https://docs.googleusercontent.com/'
.' https://spreadsheets.google.com/feeds/';
$url = 'https://www.google.com/accounts/OAuthGetRequestToken?scope='.urlencode($scope);
$params = array('scope' => $scope, 'oauth_callback' => $callback);
$request = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', $url, $params);
@ -24,24 +26,35 @@ if (isset($_POST['step'])) {
parse_str($response, $token);
if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) {
$authUrl = 'https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token='.$token['oauth_token'];
OCP\JSON::success(array('data' => array('url' => $authUrl, 'request_token' => $token['oauth_token'], 'request_token_secret' => $token['oauth_token_secret'])));
OCP\JSON::success(array('data' => array('url' => $authUrl,
'request_token' => $token['oauth_token'],
'request_token_secret' => $token['oauth_token_secret'])));
} else {
OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Error: '.$response)));
OCP\JSON::error(array('data' => array(
'message' => 'Fetching request tokens failed. Error: '.$response
)));
}
break;
case 2:
if (isset($_POST['oauth_verifier']) && isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
if (isset($_POST['oauth_verifier'])
&& isset($_POST['request_token'])
&& isset($_POST['request_token_secret'])
) {
$token = new OAuthToken($_POST['request_token'], $_POST['request_token_secret']);
$url = 'https://www.google.com/accounts/OAuthGetAccessToken';
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $url, array('oauth_verifier' => $_POST['oauth_verifier']));
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $url,
array('oauth_verifier' => $_POST['oauth_verifier']));
$request->sign_request($sigMethod, $consumer, $token);
$response = send_signed_request('GET', $url, array($request->to_header()), null, false);
$token = array();
parse_str($response, $token);
if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) {
OCP\JSON::success(array('access_token' => $token['oauth_token'], 'access_token_secret' => $token['oauth_token_secret']));
OCP\JSON::success(array('access_token' => $token['oauth_token'],
'access_token_secret' => $token['oauth_token_secret']));
} else {
OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Error: '.$response)));
OCP\JSON::error(array('data' => array(
'message' => 'Fetching access tokens failed. Error: '.$response
)));
}
}
break;

View File

@ -108,12 +108,15 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
$stat['atime'] = time();
$stat['mtime'] = $stat['atime'];
$stat['ctime'] = $stat['atime'];
} else if ($object = $this->getObject($path)) {
} else {
$object = $this->getObject($path);
if ($object) {
$stat['size'] = $object['Size'];
$stat['atime'] = time();
$stat['mtime'] = strtotime($object['LastModified']);
$stat['ctime'] = $stat['mtime'];
}
}
if (isset($stat)) {
return $stat;
}
@ -123,7 +126,9 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
public function filetype($path) {
if ($path == '' || $path == '/') {
return 'dir';
} else if ($object = $this->getObject($path)) {
} 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';
@ -131,6 +136,7 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
return 'file';
}
}
}
return false;
}
@ -199,7 +205,9 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_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);
}
@ -209,9 +217,12 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
public function getMimeType($path) {
if ($this->filetype($path) == 'dir') {
return 'httpd/unix-directory';
} else if ($object = $this->getObject($path)) {
} else {
$object = $this->getObject($path);
if ($object) {
return $object['ContentType'];
}
}
return false;
}

View File

@ -39,14 +39,64 @@ class OC_Mount_Config {
*/
public static function getBackends() {
return array(
'OC_Filestorage_Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')),
'OC_Filestorage_AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')),
'OC_Filestorage_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_Filestorage_FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')),
'OC_Filestorage_Google' => array('backend' => 'Google Drive', 'configuration' => array('configured' => '#configured', 'token' => '#token', 'token_secret' => '#token secret'), 'custom' => 'google'),
'OC_Filestorage_SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')),
'OC_Filestorage_SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')),
'OC_Filestorage_DAV' => array('backend' => 'WebDAV', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://'))
'OC_Filestorage_Local' => array(
'backend' => 'Local',
'configuration' => array(
'datadir' => 'Location')),
'OC_Filestorage_AmazonS3' => array(
'backend' => 'Amazon S3',
'configuration' => array(
'key' => 'Key',
'secret' => '*Secret',
'bucket' => 'Bucket')),
'OC_Filestorage_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_Filestorage_FTP' => array(
'backend' => 'FTP',
'configuration' => array(
'host' => 'URL',
'user' => 'Username',
'password' => '*Password',
'root' => '&Root',
'secure' => '!Secure ftps://')),
'OC_Filestorage_Google' => array(
'backend' => 'Google Drive',
'configuration' => array(
'configured' => '#configured',
'token' => '#token',
'token_secret' => '#token secret'),
'custom' => 'google'),
'OC_Filestorage_SWIFT' => array(
'backend' => 'OpenStack Swift',
'configuration' => array(
'host' => 'URL',
'user' => 'Username',
'token' => '*Token',
'root' => '&Root',
'secure' => '!Secure ftps://')),
'OC_Filestorage_SMB' => array(
'backend' => 'SMB',
'configuration' => array(
'host' => 'URL',
'user' => 'Username',
'password' => '*Password',
'share' => 'Share',
'root' => '&Root')),
'OC_Filestorage_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);
}

View File

@ -31,7 +31,12 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_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->root=isset($params['root'])?$params['root']:'';
$oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']);
$oauth->setToken($params['token'], $params['token_secret']);
@ -95,7 +100,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_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']);
@ -107,7 +113,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_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();
@ -120,13 +127,16 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
public function filetype($path) {
if ($path == '' || $path == '/') {
return 'dir';
} else if ($metaData = $this->getMetaData($path)) {
} else {
$metaData = $this->getMetaData($path);
if ($metaData) {
if ($metaData['is_dir'] == 'true') {
return 'dir';
} else {
return 'file';
}
}
}
return false;
}
@ -241,9 +251,12 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
public function getMimeType($path) {
if ($this->filetype($path) == 'dir') {
return 'httpd/unix-directory';
} else if ($metaData = $this->getMetaData($path)) {
} else {
$metaData = $this->getMetaData($path);
if ($metaData) {
return $metaData['mime_type'];
}
}
return false;
}

View File

@ -32,7 +32,10 @@ class OC_Filestorage_Google extends OC_Filestorage_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->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
@ -44,7 +47,14 @@ class OC_Filestorage_Google extends OC_Filestorage_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();
@ -58,7 +68,11 @@ class OC_Filestorage_Google extends OC_Filestorage_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');
@ -132,6 +146,11 @@ class OC_Filestorage_Google extends OC_Filestorage_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)) {
@ -140,14 +159,14 @@ class OC_Filestorage_Google extends OC_Filestorage_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;
@ -180,20 +199,25 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$collection = dirname($path);
// Check if path parent is root directory
if ($collection == '/' || $collection == '\.' || $collection == '.') {
$uri = 'https://docs.google.com/feeds/default/private/full';
$uri = self::BASE_URI.'/default/private/full';
} else {
// Get parent content link
} else if ($dom = $this->getResource(basename($collection))) {
$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;
}
}
@ -206,9 +230,10 @@ class OC_Filestorage_Google extends OC_Filestorage_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;
@ -251,14 +276,20 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$stat['atime'] = time();
$stat['mtime'] = time();
$stat['ctime'] = time();
} else if ($entry = $this->getResource($path)) {
} 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['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'] = strtotime($entry->getElementsByTagName('published')->item(0)->nodeValue);
}
}
if (isset($stat)) {
return $stat;
}
@ -268,7 +299,9 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
public function filetype($path) {
if ($path == '' || $path == '/') {
return 'dir';
} else if ($entry = $this->getResource($path)) {
} 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') {
@ -281,6 +314,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
}
}
}
}
return false;
}
@ -291,7 +325,9 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
public function isUpdatable($path) {
if ($path == '' || $path == '/') {
return true;
} else if ($entry = $this->getResource($path)) {
} else {
$entry = $this->getResource($path);
if ($entry) {
// Check if edit or edit-media links exist
$links = $entry->getElementsByTagName('link');
foreach ($links as $link) {
@ -302,6 +338,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
}
}
}
}
return false;
}
@ -316,7 +353,8 @@ class OC_Filestorage_Google extends OC_Filestorage_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') {
@ -333,7 +371,8 @@ class OC_Filestorage_Google extends OC_Filestorage_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
@ -348,14 +387,18 @@ class OC_Filestorage_Google extends OC_Filestorage_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"?>';
@ -374,7 +417,8 @@ class OC_Filestorage_Google extends OC_Filestorage_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
@ -422,7 +466,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$entry = $this->getResource($target);
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));
}
@ -466,7 +510,9 @@ class OC_Filestorage_Google extends OC_Filestorage_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') {
@ -484,7 +530,8 @@ class OC_Filestorage_Google extends OC_Filestorage_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';
@ -494,8 +541,10 @@ class OC_Filestorage_Google extends OC_Filestorage_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) {
@ -512,7 +561,8 @@ class OC_Filestorage_Google extends OC_Filestorage_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';
}
}
@ -524,10 +574,13 @@ class OC_Filestorage_Google extends OC_Filestorage_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;

View File

@ -59,7 +59,8 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
}
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';
}
/**
@ -69,7 +70,8 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
*/
public function hasUpdated($path, $time) {
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 {
$actualTime=$this->filemtime($path);

View File

@ -84,6 +84,4 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
return stat($this->constructUrl($path));
}
}

View File

@ -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);

View File

@ -16,18 +16,22 @@
<?php $_['mounts'] = array_merge($_['mounts'], array('' => array())); ?>
<?php foreach ($_['mounts'] as $mountPoint => $mount): ?>
<tr <?php echo ($mountPoint != '') ? 'class="'.$mount['class'].'"' : 'id="addMountPoint"'; ?>>
<td class="mountPoint"><input type="text" name="mountPoint" value="<?php echo $mountPoint; ?>" placeholder="<?php echo $l->t('Mount point'); ?>" /></td>
<td class="mountPoint"><input type="text" name="mountPoint"
value="<?php echo $mountPoint; ?>"
placeholder="<?php echo $l->t('Mount point'); ?>" /></td>
<?php if ($mountPoint == ''): ?>
<td class="backend">
<select id="selectBackend" data-configurations='<?php echo json_encode($_['backends']); ?>'>
<option value="" disabled selected style="display:none;"><?php echo $l->t('Add mount point'); ?></option>
<option value="" disabled selected
style="display:none;"><?php echo $l->t('Add mount point'); ?></option>
<?php foreach ($_['backends'] as $class => $backend): ?>
<option value="<?php echo $class; ?>"><?php echo $backend['backend']; ?></option>
<?php endforeach; ?>
</select>
</td>
<?php else: ?>
<td class="backend" data-class="<?php echo $mount['class']; ?>"><?php echo $mount['backend']; ?></td>
<td class="backend"
data-class="<?php echo $mount['class']; ?>"><?php echo $mount['backend']; ?></td>
<?php endif; ?>
<td class ="configuration" width="100%">
<?php if (isset($mount['configuration'])): ?>
@ -35,46 +39,75 @@
<?php if (isset($_['backends'][$mount['class']]['configuration'][$parameter])): ?>
<?php $placeholder = $_['backends'][$mount['class']]['configuration'][$parameter]; ?>
<?php if (strpos($placeholder, '*') !== false): ?>
<input type="password" data-parameter="<?php echo $parameter; ?>" value="<?php echo $value; ?>" placeholder="<?php echo substr($placeholder, 1); ?>" />
<input type="password"
data-parameter="<?php echo $parameter; ?>"
value="<?php echo $value; ?>"
placeholder="<?php echo substr($placeholder, 1); ?>" />
<?php elseif (strpos($placeholder, '!') !== false): ?>
<label><input type="checkbox" data-parameter="<?php echo $parameter; ?>" <?php if ($value == 'true') echo ' checked="checked"'; ?> /><?php echo substr($placeholder, 1); ?></label>
<label><input type="checkbox"
data-parameter="<?php echo $parameter; ?>"
<?php if ($value == 'true'): ?> checked="checked"<?php endif; ?>
/><?php echo substr($placeholder, 1); ?></label>
<?php elseif (strpos($placeholder, '&') !== false): ?>
<input type="text" class="optional" data-parameter="<?php echo $parameter; ?>" value="<?php echo $value; ?>" placeholder="<?php echo substr($placeholder, 5); ?>" />
<input type="text"
class="optional"
data-parameter="<?php echo $parameter; ?>"
value="<?php echo $value; ?>"
placeholder="<?php echo substr($placeholder, 5); ?>" />
<?php elseif (strpos($placeholder, '#') !== false): ?>
<input type="hidden" data-parameter="<?php echo $parameter; ?>" value="<?php echo $value; ?>" />
<input type="hidden"
data-parameter="<?php echo $parameter; ?>"
value="<?php echo $value; ?>" />
<?php else: ?>
<input type="text" data-parameter="<?php echo $parameter; ?>" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" />
<input type="text"
data-parameter="<?php echo $parameter; ?>"
value="<?php echo $value; ?>"
placeholder="<?php echo $placeholder; ?>" />
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($_['backends'][$mount['class']]['custom'])) OCP\Util::addScript('files_external', $_['backends'][$mount['class']]['custom']); ?>
<?php if (isset($_['backends'][$mount['class']]['custom'])): ?>
<?php OCP\Util::addScript('files_external',
$_['backends'][$mount['class']]['custom']); ?>
<?php endif; ?>
<?php endif; ?>
</td>
<!--<td class="options">
<select class="selectOptions" title="<?php echo $l->t('None set')?>" multiple="multiple" disabled>
<?php if (OCP\App::isEnabled('files_encryption')) echo '<option value="Encrypt">Encrypt</option>'; ?>
<?php if (OCP\App::isEnabled('files_versions')) echo '<option value="Version control">Version control</option>'; ?>
<?php if (OCP\App::isEnabled('files_sharing')) echo '<option value="Allow sharing">Allow sharing</option>'; ?>
</select>
</td>-->
<?php if ($_['isAdminPage']): ?>
<td class="applicable" align="right" data-applicable-groups='<?php if (isset($mount['applicable']['groups'])) echo json_encode($mount['applicable']['groups']); ?>' data-applicable-users='<?php if (isset($mount['applicable']['users'])) echo json_encode($mount['applicable']['users']); ?>'>
<select class="chzn-select" multiple style="width:20em;" data-placeholder="<?php echo $l->t('None set'); ?>">
<td class="applicable"
align="right"
data-applicable-groups='<?php if (isset($mount['applicable']['groups']))
echo json_encode($mount['applicable']['groups']); ?>'
data-applicable-users='<?php if (isset($mount['applicable']['users']))
echo json_encode($mount['applicable']['users']); ?>'>
<select class="chzn-select"
multiple style="width:20em;"
data-placeholder="<?php echo $l->t('None set'); ?>">
<option value="all"><?php echo $l->t('All Users'); ?></option>
<optgroup label="<?php echo $l->t('Groups'); ?>">
<?php foreach ($_['groups'] as $group): ?>
<option value="<?php echo $group; ?>(group)" <?php if (isset($mount['applicable']['groups']) && in_array($group, $mount['applicable']['groups'])) echo 'selected="selected"'; ?>><?php echo $group; ?></option>
<option value="<?php echo $group; ?>(group)"
<?php if (isset($mount['applicable']['groups']) && in_array($group, $mount['applicable']['groups'])): ?>
selected="selected"
<?php endif; ?>><?php echo $group; ?></option>
<?php endforeach; ?>
</optgroup>
<optgroup label="<?php echo $l->t('Users'); ?>">
<?php foreach ($_['users'] as $user): ?>
<option value="<?php echo $user; ?>" <?php if (isset($mount['applicable']['users']) && in_array($user, $mount['applicable']['users'])) echo 'selected="selected"'; ?>"><?php echo $user; ?></option>
<option value="<?php echo $user; ?>"
<?php if (isset($mount['applicable']['users']) && in_array($user, $mount['applicable']['users'])): ?>
selected="selected"
<?php endif; ?>><?php echo $user; ?></option>
<?php endforeach; ?>
</optgroup>
</select>
</td>
<?php endif; ?>
<td <?php echo ($mountPoint != '') ? 'class="remove"' : 'style="visibility:hidden;"'; ?>><img alt="<?php echo $l->t('Delete'); ?>" title="<?php echo $l->t('Delete'); ?>" class="svg action" src="<?php echo image_path('core', 'actions/delete.svg'); ?>" /></td>
<td <?php if ($mountPoint != ''): ?>class="remove"
<?php else: ?>style="visibility:hidden;"
<?php endif ?>><img alt="<?php echo $l->t('Delete'); ?>"
title="<?php echo $l->t('Delete'); ?>"
class="svg action"
src="<?php echo image_path('core', 'actions/delete.svg'); ?>" /></td>
</tr>
<?php endforeach; ?>
</tbody>
@ -83,14 +116,20 @@
<?php if ($_['isAdminPage']): ?>
<br />
<input type="checkbox" name="allowUserMounting" id="allowUserMounting" value="1" <?php if ($_['allowUserMounting'] == 'yes') echo ' checked="checked"'; ?> />
<input type="checkbox"
name="allowUserMounting"
id="allowUserMounting"
value="1" <?php if ($_['allowUserMounting'] == 'yes') echo ' checked="checked"'; ?> />
<label for="allowUserMounting"><?php echo $l->t('Enable User External Storage'); ?></label><br/>
<em><?php echo $l->t('Allow users to mount their own external storage'); ?></em>
<?php endif; ?>
</fieldset>
</form>
<form id="files_external" method="post" enctype="multipart/form-data" action="<?php echo OCP\Util::linkTo('files_external', 'ajax/addRootCertificate.php'); ?>">
<form id="files_external"
method="post"
enctype="multipart/form-data"
action="<?php echo OCP\Util::linkTo('files_external', 'ajax/addRootCertificate.php'); ?>">
<fieldset class="personalblock">
<?php if ( ! $_['isAdminPage']): ?>
<table id="sslCertificate" data-admin='<?php echo json_encode($_['isAdminPage']); ?>'>
@ -104,7 +143,12 @@
<?php foreach ($_['certs'] as $rootCert): ?>
<tr id="<?php echo $rootCert ?>">
<td class="rootCert"><?php echo $rootCert ?></td>
<td <?php echo ($rootCert != '') ? 'class="remove"' : 'style="visibility:hidden;"'; ?>><img alt="<?php echo $l->t('Delete'); ?>" title="<?php echo $l->t('Delete'); ?>" class="svg action" src="<?php echo image_path('core', 'actions/delete.svg'); ?>" /></td>
<td <?php if ($rootCert != ''): ?>class="remove"
<?php else: ?>style="visibility:hidden;"
<?php endif; ?>><img alt="<?php echo $l->t('Delete'); ?>"
title="<?php echo $l->t('Delete'); ?>"
class="svg action"
src="<?php echo image_path('core', 'actions/delete.svg'); ?>" /></td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@ -37,7 +37,8 @@ class Test_Filestorage_AmazonS3 extends Test_FileStorage {
public function tearDown() {
if ($this->instance) {
$s3 = new AmazonS3(array('key' => $this->config['amazons3']['key'], 'secret' => $this->config['amazons3']['secret']));
$s3 = new AmazonS3(array('key' => $this->config['amazons3']['key'],
'secret' => $this->config['amazons3']['secret']));
if ($s3->delete_all_objects($this->id)) {
$s3->delete_bucket($this->id);
}

View File

@ -26,7 +26,11 @@ class Test_Filestorage_FTP extends Test_FileStorage {
}
public function testConstructUrl(){
$config = array ( 'host' => 'localhost', 'user' => 'ftp', 'password' => 'ftp', 'root' => '/', 'secure' => false );
$config = array ( 'host' => 'localhost',
'user' => 'ftp',
'password' => 'ftp',
'root' => '/',
'secure' => false );
$instance = new OC_Filestorage_FTP($config);
$this->assertEqual('ftp://ftp:ftp@localhost/', $instance->constructUrl(''));