summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFrank Karlitschek <karlitschek@kde.org>2012-03-01 15:21:12 +0100
committerFrank Karlitschek <karlitschek@kde.org>2012-03-01 15:21:12 +0100
commit0b4607321fec626b3eec8455a0b0ded8a2b6222f (patch)
tree9ce9028b12c1f764f436604fa3ca796fd5ba2441 /lib
parentd29a02a65a4cc6c7adda17260327e2fe8547e88f (diff)
parentfa6ad6ba68ac671375b50971a92a61dc43e250c7 (diff)
downloadnextcloud-server-0b4607321fec626b3eec8455a0b0ded8a2b6222f.tar.gz
nextcloud-server-0b4607321fec626b3eec8455a0b0ded8a2b6222f.zip
Merge branch 'master' of gitorious.org:owncloud/owncloud
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php1
-rw-r--r--lib/filestorage.php1
-rw-r--r--lib/filestorage/common.php1
-rw-r--r--lib/filestorage/commontest.php3
-rw-r--r--lib/filestorage/google.php278
-rw-r--r--lib/filestorage/local.php11
-rw-r--r--lib/filesystem.php2
-rw-r--r--lib/filesystemview.php2
-rw-r--r--lib/helper.php2
9 files changed, 190 insertions, 111 deletions
diff --git a/lib/base.php b/lib/base.php
index 67d30f8780a..af999d45fa5 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -268,6 +268,7 @@ class OC{
OC_Util::addScript( "jquery-showpassword" );
OC_Util::addScript( "jquery.infieldlabel.min" );
OC_Util::addScript( "jquery-tipsy" );
+ OC_Util::addScript( "oc-dialogs" );
OC_Util::addScript( "js" );
OC_Util::addScript( "eventsource" );
OC_Util::addScript( "config" );
diff --git a/lib/filestorage.php b/lib/filestorage.php
index 6b679eab899..fd6497b9478 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -48,5 +48,6 @@ abstract class OC_Filestorage{
abstract public function hash($type,$path,$raw);
abstract public function free_space($path);
abstract public function search($query);
+ abstract public function touch($path, $mtime=null);
abstract public function getLocalFile($path);// get a path to a local version of the file, whether the original file is local or remote
}
diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php
index 40a9cff5d06..fa14d7e99fd 100644
--- a/lib/filestorage/common.php
+++ b/lib/filestorage/common.php
@@ -121,4 +121,5 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
$count=OC_Helper::streamCopy($source,$target);
return $tmpFile;
}
+// abstract public function touch($path, $mtime=null);
}
diff --git a/lib/filestorage/commontest.php b/lib/filestorage/commontest.php
index dd552c6865b..512e7c1b66d 100644
--- a/lib/filestorage/commontest.php
+++ b/lib/filestorage/commontest.php
@@ -72,4 +72,7 @@ class OC_Filestorage_CommonTest extends OC_Filestorage_Common{
public function search($query){
return $this->storage->search($query);
}
+ public function touch($path, $mtime=null){
+ return $this->storage->touch($path,$mtime);
+ }
} \ No newline at end of file
diff --git a/lib/filestorage/google.php b/lib/filestorage/google.php
index dd898b7955d..49985548382 100644
--- a/lib/filestorage/google.php
+++ b/lib/filestorage/google.php
@@ -20,12 +20,15 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-class OC_Filestorage_Google {
+require_once 'common.inc.php';
+
+class OC_Filestorage_Google extends OC_Filestorage_Common {
private $datadir;
private $consumer;
private $oauth_token;
private $sig_method;
+ private $entries;
public function __construct($arguments) {
$this->datadir = $arguments['datadir'];
@@ -34,6 +37,7 @@ class OC_Filestorage_Google {
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
$this->oauth_token = new OAuthToken($arguments['token'], $arguments['token_secret']);
$this->sig_method = new OAuthSignatureMethod_HMAC_SHA1();
+ $this->entries = array();
}
private function sendRequest($feedUri, $http_method, $postData = null) {
@@ -66,32 +70,59 @@ class OC_Filestorage_Google {
}
private function getResource($path) {
- // TODO Look up google docs query caching/only send back if changes occured
- // TODO Look inside of collections for specific file
- // TODO Strip extension
- $title = basename($path);
- return $this->sendRequest('https://docs.google.com/feeds/default/private/full?showfolders=true&title='.$title.'&title-exact=true', 'GET');
+ if (array_key_exists($path, $this->entries)) {
+ return $this->entries[$path];
+ } else {
+ $title = basename($path);
+ $dom = $this->sendRequest('https://docs.google.com/feeds/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[$path] = $entry;
+ return $entry;
+ }
+ return false;
+ }
}
+ private function getExtension($entry) {
+ $mimetype = $this->getMimeType('', $entry);
+ switch($mimetype) {
+ case 'httpd/unix-directory':
+ return '';
+ case 'application/vnd.oasis.opendocument.text':
+ return 'odt';
+ case 'application/vnd.oasis.opendocument.spreadsheet':
+ return 'ods';
+ case 'application/vnd.oasis.opendocument.presentation':
+ return 'pptx';
+ case 'text/html':
+ return 'html';
+ default:
+ return 'html';
+ }
+ }
+
+
public function mkdir($path) {
$dir = dirname($path);
// Check if path parent is root directory
if ($dir == '/' || $dir == '\.' || $dir == '.') {
$feedUri = 'https://docs.google.com/feeds/default/private/full';
// Get parent content link
- } else {
- $dom = $this->getResource(basename($dir));
+ } else if ($dom = $this->getResource(basename($dir))) {
$feedUri = $dom->getElementsByTagName('content')->item(0)->getAttribute('src');
}
- $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 .= '<title>'.$title.'</title>';
- $postData .= '</entry>';
- if ($dom = $this->sendRequest($feedUri, 'POST', $postData)) {
- return true;
+ if (isset($feedUri)) {
+ $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 .= '<title>'.$title.'</title>';
+ $postData .= '</entry>';
+ if ($dom = $this->sendRequest($feedUri, 'POST', $postData)) {
+ return true;
+ }
}
return false;
}
@@ -102,106 +133,86 @@ class OC_Filestorage_Google {
public function opendir($path) {
if ($path == '' || $path == '/') {
- $resource = 'https://docs.google.com/feeds/default/private/full/folder%3Aroot/contents';
- $dom = $this->sendRequest('https://docs.google.com/feeds/default/private/full/folder%3Aroot/contents', 'GET');
+ $next = 'https://docs.google.com/feeds/default/private/full/folder%3Aroot/contents';
} else {
- $dom = $this->getResource($path);
+ if ($entry = $this->getResource($path)) {
+ $next = $entry->getElementsByTagName('content')->item(0)->getAttribute('src');
+ } else {
+ return false;
+ }
}
- global $FAKEDIRS;
$files = array();
-// while ($next) {
-// // send request $next link
-// $links = $dom->getElementsByTagName('link');
-// foreach ($links as $link) {
-// if ($link->getAttribute('rel') == 'next') {
-// $next = $link->getAttribute('src');
-// break;
-// } else {
-// $next = false;
-// }
-// }
+ while ($next) {
+ $dom = $this->sendRequest($next, 'GET');
+ $links = $dom->getElementsByTagName('link');
+ foreach ($links as $link) {
+ if ($link->getAttribute('rel') == 'next') {
+ $next = $link->getAttribute('src');
+ break;
+ } else {
+ $next = false;
+ }
+ }
$entries = $dom->getElementsByTagName('entry');
- foreach($entries as $entry) {
+ foreach ($entries as $entry) {
$name = $entry->getElementsByTagName('title')->item(0)->nodeValue;
- // Native Google resources don't include extensions in title
+ // Google Docs resources don't always include extensions in title
if (!strpos($name, '.')) {
- if ($ext = $this->filetype('', $entry)) {
- $name .= '.'.$ext;
- }
+ $name .= '.'.$this->getExtension($entry);
}
$files[] = $name;
+ // Cache entry for future use
+ $this->entries[$name] = $entry;
}
-// }
- $FAKEDIRS['google'] = $files;
+ }
+ OC_FakeDirStream::$dirs['google'] = $files;
return opendir('fakedir://google');
}
- public function is_dir($path) {
- if ($entry = $this->getResource($path)) {
+ public function stat($path) {
+ if ($path == '' || $path == '/') {
+ $stat['size'] = $this->free_space($path);
+ $stat['atime'] = time();
+ $stat['mtime'] = time();
+ $stat['ctime'] = 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;
+ $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);
+ }
+ return $stat;
+ }
+
+ 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') {
- // Check if label is equal to folder
$type = $category->getAttribute('label');
if (strlen(strstr($type, 'folder')) > 0) {
- return true;
+ return 'dir';
+ } else {
+ return 'file';
}
}
}
}
- return false;
- }
-
- public function is_file($path) {
- if ($this->getResource($path)) {
- return true;
- }
return false;
}
- public function stat($path) {
- if ($dom = $this->getResource($path)) {
- // TODO Native resources don't have a file size
- $stat['size'] = $dom->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'quotaBytesUsed')->item(0)->nodeValue;
- $stat['mtime'] = strtotime($dom->getElementsByTagName('updated')->item(1)->nodeValue);
- $stat['ctime'] = strtotime($dom->getElementsByTagName('published')->item(0)->nodeValue);
- return $stat;
- }
- return false;
-
- }
-
- public function filetype($path, $entry = null) {
- if ($entry == null) {
- $entry = $this->getResource($path);
- }
- $categories = $entry->getElementsByTagName('category');
- foreach ($categories as $category) {
- if ($category->getAttribute('scheme') == 'http://schemas.google.com/g/2005#kind') {
- // Guess extension from label, default to ODF extensions
- $type = $category->getAttribute('label');
- if (strlen(strstr($type, 'folder')) > 0) {
- return '';
- } else if (strlen(strstr($type, 'document')) > 0) {
- return 'odt';
- } else if (strlen(strstr($type, 'presentation')) > 0) {
- return 'odp';
- } else if (strlen(strstr($type, 'spreadsheet')) > 0) {
- return 'ods';
- } else {
- return $type;
- }
- }
- }
- }
-
public function is_readable($path) {
return true;
}
public function is_writable($path) {
- // Check if edit or edit-media links exist
- if ($entry = $this->getResource($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') {
@@ -215,7 +226,9 @@ class OC_Filestorage_Google {
}
public function file_exists($path) {
- if ($this->getResource($path)) {
+ if ($path == '' || $path == '/') {
+ return true;
+ } else if ($this->getResource($path)) {
return true;
}
return false;
@@ -238,24 +251,82 @@ class OC_Filestorage_Google {
return false;
}
- public function rename($path1,$path2) {
-
+ public function rename($path1, $path2) {
+ // TODO Add support for moving to different collections
+ // Get resource edit link to rename resource
+ if ($entry = $this->getResource($path1)) {
+ $etag = $entry->getElementsByTagName('entry')->item(0)->getAttribute('gd:etag');
+ $links = $entry->getElementsByTagName('link');
+ foreach ($links as $link) {
+ if ($link->getAttribute('rel') == 'edit') {
+ $feedUri = $link->getAttribute('href');
+ }
+ }
+ }
+ if (isset($etag) && isset($feedUri)) {
+ $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 .= '<title>'.$title.'</title>';
+ $postData .= '</entry>';
+ $this->sendRequest($feedUri, 'PUT', $postData);
+ return true;
+ }
+ return false;
}
- public function fopen($path,$mode){}
-
- public function toTmpFile($path) {
- $dom = $this->getResource($path);
- $url = $dom->getElementsByTagName('content')->getAttribute('src');
+ public function fopen($path, $mode) {
+ if ($entry = $this->getResource($path)) {
+ $extension = $this->getExtension($path);
+ $downloadUri = $entry->getElementsByTagName('content')->item(0)->getAttribute('src');
+ // TODO Non-native documents don't need these additional parameters
+ $downloadUri .= '&exportFormat='.$extension.'&format='.$extension;
+ }
}
- public function fromTmpFile($tmpPath,$path){}
- public function fromUploadedFile($tmpPath,$path){}
- public function getMimeType($path){}
- public function hash($type,$path,$raw){}
+ public function getMimeType($path, $entry = null) {
+ if ($entry == null) {
+ if ($path == '' || $path == '/') {
+ return 'httpd/unix-directory';
+ } else {
+ $entry = $this->getResource($path);
+ }
+ }
+ 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
+ if ($mimetype == 'text/html' || $mimetype == 'application/atom+xml') {
+ $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 'httpd/unix-directory';
+ } else if (strlen(strstr($type, 'document')) > 0) {
+ return 'application/vnd.oasis.opendocument.text';
+ } else if (strlen(strstr($type, 'spreadsheet')) > 0) {
+ return 'application/vnd.oasis.opendocument.spreadsheet';
+ } else if (strlen(strstr($type, 'presentation')) > 0) {
+ return 'application/vnd.oasis.opendocument.presentation';
+ } 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
+ return 'text/html';
+ }
+ }
+ }
+ }
+ return $mimetype;
+ }
+ return false;
+ }
public function free_space($path) {
if ($dom = $this->sendRequest('https://docs.google.com/feeds/metadata/default', 'GET')) {
+ // 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;
return $total - $used;
@@ -263,9 +334,8 @@ class OC_Filestorage_Google {
return false;
}
- public function search($query){}
-
- public function getLocalFile($path) {
- return false;
+ public function search($query) {
+
}
+
} \ No newline at end of file
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 8acfe504cb2..8e07ce6025b 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -58,15 +58,20 @@ class OC_Filestorage_Local extends OC_Filestorage{
public function filemtime($path){
return filemtime($this->datadir.$path);
}
- public function touch($path, $mtime){
+ public function touch($path, $mtime=null){
// sets the modification time of the file to the given value.
// If mtime is nil the current time is set.
// note that the access time of the file always changes to the current time.
- if( touch( $this->datadir.$path, $mtime ) ) {
+ if(!is_null($mtime)){
+ $result=touch( $this->datadir.$path, $mtime );
+ }else{
+ $result=touch( $this->datadir.$path);
+ }
+ if( $result ) {
clearstatcache( true, $this->datadir.$path );
}
- return touch($this->datadir.$path, $mtime);
+ return $result;
}
public function file_get_contents($path){
return file_get_contents($this->datadir.$path);
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 90195bc2130..5013b3968c5 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -345,7 +345,7 @@ class OC_Filesystem{
static public function filemtime($path){
return self::$defaultInstance->filemtime($path);
}
- static public function touch($path, $mtime){
+ static public function touch($path, $mtime=null){
return self::$defaultInstance->touch($path, $mtime);
}
static public function file_get_contents($path){
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index 5996a5f60fb..2d54a676c8c 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -163,7 +163,7 @@ class OC_FilesystemView {
public function filemtime($path){
return $this->basicOperation('filemtime',$path);
}
- public function touch($path, $mtime){
+ public function touch($path, $mtime=null){
return $this->basicOperation('touch', $path, array('write'), $mtime);
}
public function file_get_contents($path){
diff --git a/lib/helper.php b/lib/helper.php
index 5b1efd749ae..0c6c73aa76b 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -432,7 +432,6 @@ class OC_Helper {
$fh=fopen($file,'w');
fclose($fh);
self::$tmpFiles[]=$file;
- error_log($file);
return $file;
}
@@ -442,7 +441,6 @@ class OC_Helper {
public static function cleanTmp(){
foreach(self::$tmpFiles as $file){
if(file_exists($file)){
- error_log("clean $file");
unlink($file);
}
}