From ea15c17149227373045dd6a5d08cf8e83c8a374b Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 28 Feb 2012 20:38:51 +0100 Subject: [PATCH 01/12] typo in function call --- apps/user_ldap/user_ldap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index fb42cc81337..fbc87f158a1 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -189,7 +189,7 @@ class OC_USER_LDAP extends OC_User_Backend { if(!$this->configured){ return false; } - $dn = $this->getDn($uid); + $dn = $this->getDc($uid); return !empty($dn); } From 2754cac21ffaba199b05526e0a8df5bcd4a25768 Mon Sep 17 00:00:00 2001 From: Bartek Przybylski Date: Tue, 28 Feb 2012 23:02:02 +0100 Subject: [PATCH 02/12] dialogs library for apps --- apps/gallery/templates/index.php | 1 - core/js/js.js | 3 +- core/js/oc-dialogs.js | 145 +++++++++++++++++++++++++++++++ lib/base.php | 1 + 4 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 core/js/oc-dialogs.js diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index 7cc7dad3ac6..1b8d53e82d4 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -5,7 +5,6 @@ OC_Util::addScript('gallery', 'album_cover'); $l = new OC_L10N('gallery'); ?> -
diff --git a/core/js/js.js b/core/js/js.js index 61588f7a0f2..df1b5c6ce76 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -125,7 +125,8 @@ OC={ OC.search.showResults(results); }); } - } + }, + dialogs:OCdialogs }; OC.search.customResults={}; OC.search.currentResult=-1; diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js new file mode 100644 index 00000000000..de67c342a71 --- /dev/null +++ b/core/js/oc-dialogs.js @@ -0,0 +1,145 @@ +/** + * ownCloud + * + * @author Bartek Przybylski + * @copyright 2012 Bartek Przybylski bart.p.pl@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + * + * todo(bartek): add select option in form + */ + +/** + * this class ease usage of jquery dialogs + */ +OCdialogs = { + /** + * displays alert dialog + * @param text content of dialog + * @param title dialog title + * @param callback which will be triggered when user press OK + */ + alert:function(text, title, callback) { + var content = '

'+text+'

'; + OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback); + }, + /** + * displays info dialog + * @param text content of dialog + * @param title dialog title + * @param callback which will be triggered when user press OK + */ + info:function(text, title, callback) { + var content = '

'+text+'

'; + OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback); + }, + /** + * displays confirmation dialog + * @param text content of dialog + * @param title dialog title + * @param callback which will be triggered when user press YES or NO (true or false would be passed to callback respectively) + */ + confirm:function(text, title, callback) { + var content = '

'+text+'

'; + OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.YES_NO_BUTTON, callback); + }, + /** + * prompt for user input + * @param text content of dialog + * @param title dialog title + * @param callback which will be triggered when user press OK (input text will be passed to callback) + */ + prompt:function(text, title, callback) { + var content = '

'+text+':

'; + OCdialogs.message(content, title, OCdialogs.PROMPT_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback); + }, + /** + * prompt user for input with custom form + * fields should be passed in following format: [{text:'prompt text', name:'return name', type:'input type'},...] + * @param fields to display + * @param title dialog title + * @param callback which will be triggered when user press OK (user answers will be passed to callback in following format: [{name:'return name', value: 'user value'},...]) + */ + form:function(fields, title, callback) { + var content = ''; + for (var a in fields) { + content += '" + } + content += "
'+fields[a].text+''; + var type=fields[a].type; + if (type == 'text' || type == 'checkbox' || type == 'password') + content += ''; + content += "
"; + OCdialogs.message(content, title, OCdialogs.FORM_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback); + }, + message:function(content, title, dialog_type, buttons, callback) { + var c_name = 'oc-dialog-'+OCdialogs.dialogs_counter+'-content'; + var c_id = '#'+c_name; + var d = '
'+content+'
'; + $('body').append(d); + var b = []; + switch (buttons) { + case OCdialogs.YES_NO_BUTTONS: + b[1] = {text: t('dialogs', 'No'), click: function(){ if (callback != undefined) callback(false); $(c_id).dialog('close'); }}; + b[0] = {text: t('dialogs', 'Yes'), click: function(){ if (callback != undefined) callback(true); $(c_id).dialog('close');}}; + break; + case OCdialogs.OK_CANCEL_BUTTONS: + b[1] = {text: t('dialogs', 'Cancel'), click: function(){$(c_id).dialog('close'); }}; + case OCdialogs.OK_BUTTON: // fallthrough + var f; + switch(dialog_type) { + case OCdialogs.ALERT_DIALOG: + f = function(){$(c_id).dialog('close'); }; + break; + case OCdialogs.PROMPT_DIALOG: + f = function(){OCdialogs.prompt_ok_handler(callback, c_id)}; + break; + case OCdialogs.FORM_DIALOG: + f = function(){OCdialogs.form_ok_handler(callback, c_id)}; + break; + } + b[0] = {text: t('dialogs', 'Ok'), click: f}; + break; + } + $(c_id).dialog({width: 4*$(document).width()/9, height: $(d).height() + 150, modal: false, buttons: b}); + OCdialogs.dialogs_counter++; + }, + // dialogs buttons types + YES_NO_BUTTONS: 70, + OK_BUTTONS: 71, + OK_CANCEL_BUTTONS: 72, + // dialogs types + ALERT_DIALOG: 80, + INFO_DIALOG: 81, + PROMPT_DIALOG: 82, + FORM_DIALOG: 83, + dialogs_counter: 0, + determineValue: function(element) { + switch ($(element).attr('type')) { + case 'checkbox': return $(element).attr('checked') != undefined; + } + return $(element).val(); + }, + prompt_ok_handler: function(callback, c_id){callback(true, $(c_id + " input#oc-dialog-prompt-input").val()); $(c_id).dialog('close');}, + form_ok_handler: function(callback, c_id) { + var r = []; + var c = 0; + $(c_id + ' input').each(function(i, elem) { + r[c] = {name: $(elem).attr('name'), value: OCdialogs.determineValue(elem)}; + c++; + }); + $(c_id).dialog('close'); + callback(r); + } +}; diff --git a/lib/base.php b/lib/base.php index d4dbdcde9b6..c98477ce15c 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" ); From 02f15e9a037a63ab6795927231015f366d47846e Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 28 Feb 2012 19:15:49 -0500 Subject: [PATCH 03/12] More work on Google Docs storage backend --- lib/filestorage/google.php | 279 +++++++++++++++++++++++-------------- 1 file changed, 175 insertions(+), 104 deletions(-) diff --git a/lib/filestorage/google.php b/lib/filestorage/google.php index dd898b7955d..0c562941d41 100644 --- a/lib/filestorage/google.php +++ b/lib/filestorage/google.php @@ -20,12 +20,15 @@ * License along with this library. If not, see . */ -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 = ''; - $postData .= ''; - $postData .= ''; - $postData .= ''.$title.''; - $postData .= ''; - if ($dom = $this->sendRequest($feedUri, 'POST', $postData)) { - return true; + if (isset($feedUri)) { + $title = basename($path); + // Construct post data + $postData = ''; + $postData .= ''; + $postData .= ''; + $postData .= ''.$title.''; + $postData .= ''; + if ($dom = $this->sendRequest($feedUri, 'POST', $postData)) { + return true; + } } return false; } @@ -102,106 +133,87 @@ 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)) { + $collectionId = $entry->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'resourceId')->item(0)->nodeValue; + $next = 'https://docs.google.com/feeds/default/private/full/folder%3A'.$collectionId.'/contents'; + } 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 +227,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 +252,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 = ''; + $postData .= ''; + $postData .= ''.$title.''; + $postData .= ''; + $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 +335,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 From 3c72a7c934ed4ec036f1b82d95053dde10463ade Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 29 Feb 2012 12:57:11 +0100 Subject: [PATCH 04/12] make ldap settings a little bit less ugly --- apps/user_ldap/templates/settings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index 99af275525d..69b9c171816 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -6,9 +6,9 @@

t('Leave both empty for anonymous bind for search, then bind with users credentials.');?>

-

- - t('For example "objectClass=person".');?>

+

+

t('use %%uid placeholder, e.g. uid=%%uid');?>

+

t('without any placeholder, e.g. "objectClass=person".');?>

t('Currently the display name field needs to be the same you matched %%uid against in the filter above, because ownCloud doesn\'t distinguish between user id and user name.');?>

>

From f040ce044c20a80e03a76b0aa92292839122f929 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 29 Feb 2012 13:03:44 +0100 Subject: [PATCH 05/12] consider changed/new setting variables for user_ldap --- apps/user_ldap/settings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 1f2d8ed9af3..01c5b1749e9 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -20,7 +20,7 @@ * License along with this library. If not, see . * */ -$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_filter', 'ldap_display_name', 'ldap_tls', 'ldap_nocase'); +$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_userlist_filter', 'ldap_login_filter', 'ldap_display_name', 'ldap_tls', 'ldap_nocase'); if ($_POST) { foreach($params as $param){ @@ -29,12 +29,12 @@ if ($_POST) { } elseif('ldap_tls' == $param) { // unchecked checkboxes are not included in the post paramters - OC_Appconfig::setValue('user_ldap', $param, 0); + OC_Appconfig::setValue('user_ldap', $param, 0); } elseif('ldap_nocase' == $param) { OC_Appconfig::setValue('user_ldap', $param, 0); } - + } } From baffa03fa59430312e9c625451c633b54a3a51ce Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 29 Feb 2012 13:18:19 -0500 Subject: [PATCH 06/12] Fix opendir for folders aka Google Docs collections --- lib/filestorage/google.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/filestorage/google.php b/lib/filestorage/google.php index 0c562941d41..49985548382 100644 --- a/lib/filestorage/google.php +++ b/lib/filestorage/google.php @@ -136,8 +136,7 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { $next = 'https://docs.google.com/feeds/default/private/full/folder%3Aroot/contents'; } else { if ($entry = $this->getResource($path)) { - $collectionId = $entry->getElementsByTagNameNS('http://schemas.google.com/g/2005', 'resourceId')->item(0)->nodeValue; - $next = 'https://docs.google.com/feeds/default/private/full/folder%3A'.$collectionId.'/contents'; + $next = $entry->getElementsByTagName('content')->item(0)->getAttribute('src'); } else { return false; } From b23b5aae7fba9467fd0e6b6137268c894ea6f8e8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 29 Feb 2012 23:17:49 +0100 Subject: [PATCH 07/12] remove debug output --- lib/helper.php | 2 -- 1 file changed, 2 deletions(-) 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); } } From e76e4e75407cc672bf342f13bbd77392a93c1623 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 29 Feb 2012 23:42:40 +0100 Subject: [PATCH 08/12] add touch() to all storage backands, and make parameter optional --- apps/files_sharing/sharedstorage.php | 8 +++++++- lib/filestorage.php | 1 + lib/filestorage/common.php | 1 + lib/filestorage/commontest.php | 3 +++ lib/filestorage/local.php | 11 ++++++++--- lib/filesystem.php | 2 +- lib/filesystemview.php | 2 +- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 3067d4d34c0..845659588ef 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -505,7 +505,13 @@ class OC_Filestorage_Shared extends OC_Filestorage { return $storage->getLocalFile($this->getInternalPath($source)); } } - + public function touch($path, $mtime=null){ + $source = $this->getSource($path); + if ($source) { + $storage = OC_Filesystem::getStorage($source); + return $storage->touch($this->getInternalPath($source),$time); + } + } } ?> 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/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){ From f193e474c1f499458f6d18ba6d7fa7f83c2098c8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 29 Feb 2012 23:47:53 +0100 Subject: [PATCH 09/12] add test cases for stat and touch --- tests/lib/filestorage.php | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/lib/filestorage.php b/tests/lib/filestorage.php index fb050868ee3..6296d7abf99 100644 --- a/tests/lib/filestorage.php +++ b/tests/lib/filestorage.php @@ -126,4 +126,49 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertTrue(file_exists($localFile)); $this->assertEqual(file_get_contents($localFile),file_get_contents($textFile)); } + + public function testStat(){ + $textFile=OC::$SERVERROOT.'/tests/data/lorem.txt'; + $ctimeStart=time(); + $this->instance->file_put_contents('/lorem.txt',file_get_contents($textFile)); + $this->assertTrue($this->instance->is_readable('/lorem.txt')); + $ctimeEnd=time(); + $cTime=$this->instance->filectime('/lorem.txt'); + $mTime=$this->instance->filemtime('/lorem.txt'); + $this->assertTrue($ctimeStart<=$cTime); + $this->assertTrue($cTime<=$ctimeEnd); + $this->assertEqual($cTime,$mTime); + $this->assertEqual(filesize($textFile),$this->instance->filesize('/lorem.txt')); + + $stat=$this->instance->stat('/lorem.txt'); + //only size, mtime and ctime are requered in the result + $this->assertEqual($stat['size'],$this->instance->filesize('/lorem.txt')); + $this->assertEqual($stat['mtime'],$mTime); + $this->assertEqual($stat['ctime'],$cTime); + + $mtimeStart=time(); + $this->instance->touch('/lorem.txt'); + $mtimeEnd=time(); + $originalCTime=$cTime; + $cTime=$this->instance->filectime('/lorem.txt'); + $mTime=$this->instance->filemtime('/lorem.txt'); + $this->assertTrue($mtimeStart<=$mTime); + $this->assertTrue($mTime<=$mtimeEnd); + $this->assertEqual($cTime,$originalCTime); + + $this->instance->touch('/lorem.txt',100); + $mTime=$this->instance->filemtime('/lorem.txt'); + $this->assertEqual($mTime,100); + + $mtimeStart=time(); + $fh=$this->instance->fopen('/lorem.txt','a'); + fwrite($fh,' '); + fclose($fh); + clearstatcache(); + $mtimeEnd=time(); + $originalCTime=$cTime; + $mTime=$this->instance->filemtime('/lorem.txt'); + $this->assertTrue($mtimeStart<=$mTime); + $this->assertTrue($mTime<=$mtimeEnd); + } } From eb8ffd9315273ce7990f95d1ea7a94d05d2dd33d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 1 Mar 2012 14:18:28 +0100 Subject: [PATCH 10/12] LDAP fix: set user quota, if attribute is provided --- apps/user_ldap/user_ldap.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index fbc87f158a1..3de5ebacd36 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -81,9 +81,9 @@ class OC_USER_LDAP extends OC_User_Backend { if( !$this->ldap_dc ) return false; - $quota = $this->ldap_dc[$this->ldap_quota_attr][0]; + $quota = $this->ldap_dc[strtolower($this->ldap_quota_attr)][0]; $quota = $quota != -1 ? $quota : $this->ldap_quota_def; - OC_Preferences::setValue($uid, 'files', 'quota', $quota); + OC_Preferences::setValue($uid, 'files', 'quota', OC_Helper::computerFileSize($quota)); } private function setEmail( $uid ) { @@ -154,7 +154,7 @@ class OC_USER_LDAP extends OC_User_Backend { return false; } - if(!empty($this->ldap_quota) && !empty($this->ldap_quota_def)) { + if(!empty($this->ldap_quota_attr) && !empty($this->ldap_quota_def)) { $this->setQuota($uid); } From b192f86d84866fab1d7c440d9dad35798f352353 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 1 Mar 2012 14:21:38 +0100 Subject: [PATCH 11/12] LDPA: fix setting variables and add missing ones to the array --- apps/user_ldap/settings.php | 2 +- apps/user_ldap/templates/settings.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 01c5b1749e9..ad44fe95f9e 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -20,7 +20,7 @@ * License along with this library. If not, see . * */ -$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_userlist_filter', 'ldap_login_filter', 'ldap_display_name', 'ldap_tls', 'ldap_nocase'); +$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_userlist_filter', 'ldap_login_filter', 'ldap_display_name', 'ldap_tls', 'ldap_nocase'. 'ldap_quota_def', 'ldap_quota_attr', 'ldap_email_attr'); if ($_POST) { foreach($params as $param){ diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index 69b9c171816..828c72cba97 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -13,9 +13,9 @@ t('Currently the display name field needs to be the same you matched %%uid against in the filter above, because ownCloud doesn\'t distinguish between user id and user name.');?>

>

>

-

+

bytes

-

+

From fa6ad6ba68ac671375b50971a92a61dc43e250c7 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 1 Mar 2012 14:31:06 +0100 Subject: [PATCH 12/12] LDAP: set also quota, when there is no explicit default value --- apps/user_ldap/user_ldap.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index 3de5ebacd36..3521a9d90cf 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -81,7 +81,11 @@ class OC_USER_LDAP extends OC_User_Backend { if( !$this->ldap_dc ) return false; - $quota = $this->ldap_dc[strtolower($this->ldap_quota_attr)][0]; + if(!empty($this->ldap_quota_attr)) { + $quota = $this->ldap_dc[strtolower($this->ldap_quota_attr)][0]; + } else { + $quota = false; + } $quota = $quota != -1 ? $quota : $this->ldap_quota_def; OC_Preferences::setValue($uid, 'files', 'quota', OC_Helper::computerFileSize($quota)); } @@ -154,7 +158,7 @@ class OC_USER_LDAP extends OC_User_Backend { return false; } - if(!empty($this->ldap_quota_attr) && !empty($this->ldap_quota_def)) { + if(!empty($this->ldap_quota_attr) || !empty($this->ldap_quota_def)) { $this->setQuota($uid); }