aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/calendar/appinfo/app.php4
-rw-r--r--apps/calendar/js/loader.js2
-rw-r--r--apps/calendar/lib/share.php21
-rw-r--r--apps/calendar/lib/share/calendar.php111
-rw-r--r--apps/calendar/lib/share/event.php40
-rw-r--r--apps/calendar/lib/share_backend.php44
-rw-r--r--apps/calendar/templates/part.choosecalendar.rowfields.php2
-rw-r--r--apps/contacts/appinfo/app.php5
-rw-r--r--apps/contacts/css/contacts.css3
-rw-r--r--apps/contacts/js/loader.js4
-rw-r--r--apps/contacts/js/settings.js1
-rw-r--r--apps/contacts/lib/addressbook.php16
-rw-r--r--apps/contacts/lib/app.php29
-rw-r--r--apps/contacts/lib/share/addressbook.php93
-rw-r--r--apps/contacts/lib/share/contact.php53
-rw-r--r--apps/contacts/lib/vcard.php87
-rw-r--r--apps/contacts/templates/settings.php3
-rw-r--r--apps/files/index.php2
-rw-r--r--apps/files/js/fileactions.js54
-rw-r--r--apps/files/js/files.js35
-rwxr-xr-xapps/files/share.php38
-rw-r--r--apps/files/templates/index.php10
-rw-r--r--apps/files/templates/part.list.php3
-rw-r--r--apps/files_archive/js/archive.js4
-rw-r--r--apps/files_archive/lib/storage.php4
-rw-r--r--apps/files_external/lib/amazons3.php4
-rwxr-xr-xapps/files_external/lib/dropbox.php4
-rw-r--r--apps/files_external/lib/dropboxtest.php71
-rw-r--r--apps/files_external/lib/google.php4
-rw-r--r--apps/files_external/lib/googletest.php8
-rw-r--r--apps/files_external/lib/streamwrapper.php4
-rw-r--r--apps/files_external/lib/swift.php4
-rw-r--r--apps/files_external/lib/webdav.php4
-rw-r--r--apps/files_external/tests/test.php7
-rw-r--r--apps/files_imageviewer/js/lightbox.js2
-rw-r--r--apps/files_pdfviewer/js/viewer.js2
-rw-r--r--apps/files_sharing/appinfo/app.php6
-rw-r--r--apps/files_sharing/css/sharing.css16
-rw-r--r--apps/files_sharing/lib/share/file.php91
-rw-r--r--apps/files_sharing/lib/share/folder.php61
-rw-r--r--apps/files_sharing/sharedstorage.php509
-rwxr-xr-xapps/files_sharing/templates/get.php11
-rw-r--r--apps/files_texteditor/js/editor.js16
-rw-r--r--apps/files_versions/appinfo/api.php36
-rw-r--r--apps/files_versions/js/versions.js2
-rw-r--r--apps/gallery/appinfo/app.php3
-rw-r--r--apps/gallery/lib/share.php42
-rw-r--r--apps/media/js/loader.js4
-rw-r--r--apps/media/lib/share/album.php0
-rw-r--r--apps/media/lib/share/artist.php65
-rw-r--r--apps/media/lib/share/song.php65
51 files changed, 1308 insertions, 401 deletions
diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php
index 5c05c57bcad..9ae255853d5 100644
--- a/apps/calendar/appinfo/app.php
+++ b/apps/calendar/appinfo/app.php
@@ -10,6 +10,8 @@ OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php';
OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php';
OC::$CLASSPATH['OC_Calendar_Export'] = 'apps/calendar/lib/export.php';
OC::$CLASSPATH['OC_Calendar_Import'] = 'apps/calendar/lib/import.php';
+OC::$CLASSPATH['OC_Share_Backend_Calendar'] = 'apps/calendar/lib/share/calendar.php';
+OC::$CLASSPATH['OC_Share_Backend_Event'] = 'apps/calendar/lib/share/event.php';
//General Hooks
OCP\Util::connectHook('OC_User', 'post_createUser', 'OC_Calendar_Hooks', 'createUser');
OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser');
@@ -34,3 +36,5 @@ OCP\App::addNavigationEntry( array(
'icon' => OCP\Util::imagePath( 'calendar', 'icon.svg' ),
'name' => $l->t('Calendar')));
OC_Search::registerProvider('OC_Search_Provider_Calendar');
+OCP\Share::registerBackend('calendar', 'OC_Share_Backend_Calendar');
+OCP\Share::registerBackend('event', 'OC_Share_Backend_Event');
diff --git a/apps/calendar/js/loader.js b/apps/calendar/js/loader.js
index b28d19ab00e..253abafc427 100644
--- a/apps/calendar/js/loader.js
+++ b/apps/calendar/js/loader.js
@@ -173,7 +173,7 @@ Calendar_Import={
}
$(document).ready(function(){
if(typeof FileActions !== 'undefined'){
- FileActions.register('text/calendar','importCalendar', '', Calendar_Import.Dialog.open);
+ FileActions.register('text/calendar','importCalendar', FileActions.PERMISSION_READ, '', Calendar_Import.Dialog.open);
FileActions.setDefault('text/calendar','importCalendar');
};
});
diff --git a/apps/calendar/lib/share.php b/apps/calendar/lib/share.php
index 4fe88171403..e5ffc04143a 100644
--- a/apps/calendar/lib/share.php
+++ b/apps/calendar/lib/share.php
@@ -18,19 +18,16 @@ class OC_Calendar_Share{
* @return: array $return - information about calendars
*/
public static function allSharedwithuser($userid, $type, $active=null, $permission=null){
- $group_where = self::group_sql(OC_Group::getUserGroups($userid));
- $permission_where = self::permission_sql($permission);
- if($type == self::CALENDAR){
- $active_where = self::active_sql($active);
- }else{
- $active_where = '';
- }
- $stmt = OCP\DB::prepare("SELECT * FROM *PREFIX*calendar_share_" . $type . " WHERE ((share = ? AND sharetype = 'user') " . $group_where . ") AND owner <> ? " . $permission_where . " " . $active_where);
- $result = $stmt->execute(array($userid, $userid));
- $return = array();
- while( $row = $result->fetchRow()){
- $return[] = $row;
+ $format = OC_Share_Backend_Calendar::FORMAT_CALENDAR;
+ if ($type == self::EVENT) {
+ $format = OC_Share_Backend_Event::FORMAT_EVENT;
}
+ $return = OCP\Share::getItemsSharedWith($type,
+ $format,
+ array(
+ 'active' => $active,
+ 'permissions' => $permission,
+ ));
return $return;
}
/**
diff --git a/apps/calendar/lib/share/calendar.php b/apps/calendar/lib/share/calendar.php
new file mode 100644
index 00000000000..7f498292419
--- /dev/null
+++ b/apps/calendar/lib/share/calendar.php
@@ -0,0 +1,111 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+*
+* 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 <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Calendar implements OCP\Share_Backend_Collection {
+ const FORMAT_CALENDAR = 1;
+
+ /**
+ * @brief Get the source of the item to be stored in the database
+ * @param string Item
+ * @param string Owner of the item
+ * @return mixed|array|false Source
+ *
+ * Return an array if the item is file dependent, the array needs two keys: 'item' and 'file'
+ * Return false if the item does not exist for the user
+ *
+ * The formatItems() function will translate the source returned back into the item
+ */
+ public function isValidSource($itemSource, $uidOwner) {
+ $calendar = OC_Calendar_App::getCalendar( $itemSource );
+ if ($calendar || $calendar['userid'] != $uidOwner) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @brief Get a unique name of the item for the specified user
+ * @param string Item
+ * @param string|false User the item is being shared with
+ * @param array|null List of similar item names already existing as shared items
+ * @return string Target name
+ *
+ * This function needs to verify that the user does not already have an item with this name.
+ * If it does generate a new name e.g. name_#
+ */
+ public function generateTarget($itemSource, $shareWith, $exclude = null) {
+ $calendar = OC_Calendar_App::getCalendar( $itemSource );
+ $user_calendars = array();
+ foreach(OC_Contacts_Addressbook::all($uid) as $user_calendar) {
+ $user_calendars[] = $user_calendar['displayname'];
+ }
+ $name = $calendar['userid']."'s ".$calendar['displayname'];
+ $suffix = '';
+ while (in_array($name.$suffix, $user_calendars)) {
+ $suffix++;
+ }
+
+ return $name.$suffix;
+ }
+
+ /**
+ * @brief Converts the shared item sources back into the item in the specified format
+ * @param array Shared items
+ * @param int Format
+ * @return ?
+ *
+ * The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info.
+ * The key/value pairs included in the share info depend on the function originally called:
+ * If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source
+ * If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target
+ * This function allows the backend to control the output of shared items with custom formats.
+ * It is only called through calls to the public getItem(s)Shared(With) functions.
+ */
+ public function formatItems($items, $format, $parameters = null) {
+ $calendars = array();
+ if ($format == self::FORMAT_CALENDAR) {
+ foreach ($items as $item) {
+ $calendar = OC_Calendar_App::getCalendar($item['item_source'], false);
+ // TODO: really check $parameters['permissions'] == 'rw'/'r'
+ if ($parameters['permissions'] == 'rw') {
+ continue; // TODO
+ }
+ $calendar['displaynamename'] = $item['item_target'];
+ $calendar['calendarid'] = $calendar['id'];
+ $calendar['owner'] = $calendar['userid'];
+ $calendars[] = $calendar;
+ }
+ }
+ return $calendars;
+ }
+
+ public function getChildren($itemSource) {
+ $query = OCP\DB::prepare('SELECT id FROM *PREFIX*calendar_objects WHERE calendarid = ?');
+ $result = $query->execute(array($itemSource));
+ $sources = array();
+ while ($object = $result->fetchRow()) {
+ $sources[] = $object['id'];
+ }
+ return $sources;
+ }
+
+} \ No newline at end of file
diff --git a/apps/calendar/lib/share/event.php b/apps/calendar/lib/share/event.php
new file mode 100644
index 00000000000..5bb72ee6c98
--- /dev/null
+++ b/apps/calendar/lib/share/event.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class OC_Share_Backend_Event implements OCP\Share_Backend {
+
+ const FORMAT_EVENT = 0;
+
+ private static $event;
+
+ public function isValidSource($itemSource, $uidOwner) {
+ self::$event = OC_Calendar_Object::find($itemSource);
+ if (self::$event) {
+ return true;
+ }
+ return false;
+ }
+
+ public function generateTarget($itemSource, $shareWith, $exclude = null) {
+ // TODO Get default calendar and check for conflicts
+ return self::$event['summary'];
+ }
+
+ public function formatItems($items, $format, $parameters = null) {
+ $events = array();
+ if ($format == self::FORMAT_EVENT) {
+ foreach ($items as $item) {
+ $event = OC_Calendar_Object::find($item['item_source']);
+ $event['summary'] = $item['item_target'];
+ $events[] = $event;
+ }
+ }
+ return $events;
+ }
+
+}
diff --git a/apps/calendar/lib/share_backend.php b/apps/calendar/lib/share_backend.php
new file mode 100644
index 00000000000..f937c0d1c34
--- /dev/null
+++ b/apps/calendar/lib/share_backend.php
@@ -0,0 +1,44 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Calendar extends OCP\Share_Backend {
+
+ public function getSource($item, $uid) {
+ $query = OCP\DB::prepare('SELECT id FROM *PREFIX*calendar_calendars WHERE userid = ? AND displayname = ? LIMIT 1');
+ return $query->execute(array($uid, $item))->fetchAll();
+ }
+
+ public function generateTarget($item, $uid) {
+
+ }
+
+ public function getItems($sources) {
+
+ }
+
+}
+
+class OC_Share_Backend_Event extends OCP\Share_Backend {
+
+}
+
+
+?> \ No newline at end of file
diff --git a/apps/calendar/templates/part.choosecalendar.rowfields.php b/apps/calendar/templates/part.choosecalendar.rowfields.php
index d29113c9a61..64aaa797197 100644
--- a/apps/calendar/templates/part.choosecalendar.rowfields.php
+++ b/apps/calendar/templates/part.choosecalendar.rowfields.php
@@ -5,7 +5,7 @@
<label for="active_<?php echo $_['calendar']['id'] ?>"><?php echo $_['calendar']['displayname'] ?></label>
</td>
<td width="20px">
- <a href="#" onclick="Calendar.UI.Share.dropdown('<?php echo OCP\USER::getUser() ?>', <?php echo $_['calendar']['id'] ?>);" title="<?php echo $l->t('Share Calendar') ?>" class="action"><img class="svg action" src="<?php echo (!$_['shared']) ? OCP\Util::imagePath('core', 'actions/share.svg') : OCP\Util::imagePath('core', 'actions/shared.svg') ?>"></a>
+ <a href="#" class="share" data-item-type="calendar" data-item="<?php echo $_['calendar']['id']; ?>" title="<?php echo $l->t('Share Calendar') ?>" class="action"><img class="svg action" src="<?php echo (!$_['shared']) ? OCP\Util::imagePath('core', 'actions/share.svg') : OCP\Util::imagePath('core', 'actions/shared.svg') ?>"></a>
</td>
<td width="20px">
<a href="#" onclick="Calendar.UI.showCalDAVUrl('<?php echo OCP\USER::getUser() ?>', '<?php echo rawurlencode(html_entity_decode($_['calendar']['uri'], ENT_QUOTES, 'UTF-8')) ?>');" title="<?php echo $l->t('CalDav Link') ?>" class="action"><img class="svg action" src="<?php echo OCP\Util::imagePath('core', 'actions/public.svg') ?>"></a>
diff --git a/apps/contacts/appinfo/app.php b/apps/contacts/appinfo/app.php
index 7e73f315dd0..68163430186 100644
--- a/apps/contacts/appinfo/app.php
+++ b/apps/contacts/appinfo/app.php
@@ -3,6 +3,8 @@ OC::$CLASSPATH['OC_Contacts_App'] = 'apps/contacts/lib/app.php';
OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php';
OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php';
OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';
+OC::$CLASSPATH['OC_Share_Backend_Contact'] = 'apps/contacts/lib/share/contact.php';
+OC::$CLASSPATH['OC_Share_Backend_Addressbook'] = 'apps/contacts/lib/share/addressbook.php';
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV'] = 'apps/contacts/lib/connector_sabre.php';
OC::$CLASSPATH['Sabre_CardDAV_VCFExportPlugin'] = 'apps/contacts/lib/VCFExportPlugin.php';
OC::$CLASSPATH['OC_Search_Provider_Contacts'] = 'apps/contacts/lib/search.php';
@@ -20,3 +22,6 @@ OCP\App::addNavigationEntry( array(
OCP\Util::addscript('contacts', 'loader');
OC_Search::registerProvider('OC_Search_Provider_Contacts');
+OCP\Share::registerBackend('contact', 'OC_Share_Backend_Contact');
+OCP\Share::registerBackend('addressbook', 'OC_Share_Backend_Addressbook', 'contact');
+
diff --git a/apps/contacts/css/contacts.css b/apps/contacts/css/contacts.css
index c5308c4d25a..ad8762167b5 100644
--- a/apps/contacts/css/contacts.css
+++ b/apps/contacts/css/contacts.css
@@ -50,11 +50,12 @@ label:hover, dt:hover { color: #333; }
.float { float: left; }
.svg { border: inherit; background: inherit; }
.listactions { height: 1em; width:60px; float: left; clear: right; }
-.add,.edit,.delete,.mail, .globe, .upload, .download, .cloud { cursor: pointer; width: 20px; height: 20px; margin: 0; float: left; position:relative; opacity: 0.1; }
+.add,.edit,.delete,.mail, .globe, .upload, .download, .cloud, .share { cursor: pointer; width: 20px; height: 20px; margin: 0; float: left; position:relative; opacity: 0.1; }
.add:hover,.edit:hover,.delete:hover,.mail:hover, .globe:hover, .upload:hover, .download:hover .cloud:hover { opacity: 1.0 }
.add { background:url('%webroot%/core/img/actions/add.svg') no-repeat center; clear: both; }
.delete { background:url('%webroot%/core/img/actions/delete.svg') no-repeat center; }
.edit { background:url('%webroot%/core/img/actions/rename.svg') no-repeat center; }
+.share { background:url('%webroot%/core/img/actions/share.svg') no-repeat center; }
.mail { background:url('%webroot%/core/img/actions/mail.svg') no-repeat center; }
.upload { background:url('%webroot%/core/img/actions/upload.svg') no-repeat center; }
.download { background:url('%webroot%/core/img/actions/download.svg') no-repeat center; }
diff --git a/apps/contacts/js/loader.js b/apps/contacts/js/loader.js
index 5bca0ab7237..3b1f4070485 100644
--- a/apps/contacts/js/loader.js
+++ b/apps/contacts/js/loader.js
@@ -78,9 +78,9 @@ Contacts_Import={
}
$(document).ready(function(){
if(typeof FileActions !== 'undefined'){
- FileActions.register('text/vcard','importaddressbook', '', Contacts_Import.importdialog);
+ FileActions.register('text/vcard','importaddressbook', FileActions.PERMISSION_READ, '', Contacts_Import.importdialog);
FileActions.setDefault('text/vcard','importaddressbook');
- FileActions.register('text/x-vcard','importaddressbook', '', Contacts_Import.importdialog);
+ FileActions.register('text/x-vcard','importaddressbook', FileActions.PERMISSION_READ, '', Contacts_Import.importdialog);
FileActions.setDefault('text/x-vcard','importaddressbook');
};
}); \ No newline at end of file
diff --git a/apps/contacts/js/settings.js b/apps/contacts/js/settings.js
index 67aaa5b5f88..69cf473e06a 100644
--- a/apps/contacts/js/settings.js
+++ b/apps/contacts/js/settings.js
@@ -4,6 +4,7 @@ OC.Contacts.Settings = OC.Contacts.Settings || {
this.Addressbook.adrsettings = $('.addressbooks-settings').first();
this.Addressbook.adractions = $('#contacts-settings').find('div.actions');
console.log('actions: ' + this.Addressbook.adractions.length);
+ OC.Share.loadIcons('addressbook');
},
Addressbook:{
showActions:function(act) {
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
index eb61b6dbced..92c5f4da3a7 100644
--- a/apps/contacts/lib/addressbook.php
+++ b/apps/contacts/lib/addressbook.php
@@ -64,10 +64,10 @@ class OC_Contacts_Addressbook {
while( $row = $result->fetchRow()) {
$addressbooks[] = $row;
}
+ $addressbooks = array_merge($addressbooks, OCP\Share::getItemsSharedWith('addressbook', OC_Share_Backend_Addressbook::FORMAT_ADDRESSBOOKS));
if(!$active && !count($addressbooks)) {
self::addDefault($uid);
}
-
return $addressbooks;
}
@@ -208,7 +208,12 @@ class OC_Contacts_Addressbook {
public static function edit($id,$name,$description) {
// Need these ones for checking uri
$addressbook = self::find($id);
-
+ if ($addressbook['userid'] != OCP\User::getUser()) {
+ $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id);
+ if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_UPDATE)) {
+ return false;
+ }
+ }
if(is_null($name)) {
$name = $addressbook['name'];
}
@@ -270,6 +275,13 @@ class OC_Contacts_Addressbook {
* @return boolean
*/
public static function delete($id) {
+ $addressbook = self::find($id);
+ if ($addressbook['userid'] != OCP\User::getUser()) {
+ $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id);
+ if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_DELETE)) {
+ return false;
+ }
+ }
self::setActive($id, false);
try {
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' );
diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php
index b59a8372b74..f6ce213c49b 100644
--- a/apps/contacts/lib/app.php
+++ b/apps/contacts/lib/app.php
@@ -37,21 +37,24 @@ class OC_Contacts_App {
)
)
);
- }
- else {
- OCP\Util::writeLog('contacts',
- 'Addressbook('.$id.') is not from '.OCP\USER::getUser(),
- OCP\Util::ERROR);
- //throw new Exception('This is not your addressbook.');
- OCP\JSON::error(
- array(
- 'data' => array(
- 'message' => self::$l10n->t('This is not your addressbook.')
+ } else {
+ $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $id, OC_Share_Backend_Addressbook::FORMAT_ADDRESSBOOKS);
+ if ($sharedAddressbook) {
+ return $sharedAddressbook;
+ } else {
+ OCP\Util::writeLog('contacts',
+ 'Addressbook('.$id.') is not from '.OCP\USER::getUser(),
+ OCP\Util::ERROR);
+ //throw new Exception('This is not your addressbook.');
+ OCP\JSON::error(
+ array(
+ 'data' => array(
+ 'message' => self::$l10n->t('This is not your addressbook.')
+ )
)
- )
- );
+ );
+ }
}
- exit();
}
return $addressbook;
}
diff --git a/apps/contacts/lib/share/addressbook.php b/apps/contacts/lib/share/addressbook.php
new file mode 100644
index 00000000000..62799696d95
--- /dev/null
+++ b/apps/contacts/lib/share/addressbook.php
@@ -0,0 +1,93 @@
+<?php
+/**
+ * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class OC_Share_Backend_Addressbook implements OCP\Share_Backend_Collection {
+ const FORMAT_ADDRESSBOOKS = 1;
+
+ /**
+ * @brief Get the source of the item to be stored in the database
+ * @param string Item
+ * @param string Owner of the item
+ * @return mixed|array|false Source
+ *
+ * Return an array if the item is file dependent, the array needs two keys: 'item' and 'file'
+ * Return false if the item does not exist for the user
+ *
+ * The formatItems() function will translate the source returned back into the item
+ */
+ public function isValidSource($itemSource, $uidOwner) {
+ $addressbook = OC_Contacts_Addressbook::find( $itemSource );
+ if( $addressbook === false || $addressbook['userid'] != $uidOwner) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @brief Get a unique name of the item for the specified user
+ * @param string Item
+ * @param string|false User the item is being shared with
+ * @param array|null List of similar item names already existing as shared items
+ * @return string Target name
+ *
+ * This function needs to verify that the user does not already have an item with this name.
+ * If it does generate a new name e.g. name_#
+ */
+ public function generateTarget($itemSource, $shareWith, $exclude = null) {
+ $addressbook = OC_Contacts_Addressbook::find( $itemSource );
+ $user_addressbooks = array();
+ foreach(OC_Contacts_Addressbook::all($uid) as $user_addressbook) {
+ $user_addressbooks[] = $user_addressbook['displayname'];
+ }
+ $name = $addressbook['userid']."'s ".$addressbook['displayname'];
+ $suffix = '';
+ while (in_array($name.$suffix, $user_addressbooks)) {
+ $suffix++;
+ }
+
+ return $name.$suffix;
+ }
+
+ /**
+ * @brief Converts the shared item sources back into the item in the specified format
+ * @param array Shared items
+ * @param int Format
+ * @return ?
+ *
+ * The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info.
+ * The key/value pairs included in the share info depend on the function originally called:
+ * If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source
+ * If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target
+ * This function allows the backend to control the output of shared items with custom formats.
+ * It is only called through calls to the public getItem(s)Shared(With) functions.
+ */
+ public function formatItems($items, $format, $parameters = null) {
+ $addressbooks = array();
+ if ($format == self::FORMAT_ADDRESSBOOKS) {
+ foreach ($items as $item) {
+ $addressbook = OC_Contacts_Addressbook::find($item['item_source']);
+ if ($addressbook) {
+ $addressbook['displayname'] = $item['item_target'];
+ $addressbooks[] = $addressbook;
+ }
+ }
+ }
+ return $addressbooks;
+ }
+
+ public function getChildren($itemSource) {
+ $query = OCP\DB::prepare('SELECT id FROM *PREFIX*contacts_cards WHERE addressbookid = ?');
+ $result = $query->execute(array($itemSource));
+ $sources = array();
+ while ($contact = $result->fetchRow()) {
+ $sources[] = $contact['id'];
+ }
+ return $sources;
+ }
+
+}
diff --git a/apps/contacts/lib/share/contact.php b/apps/contacts/lib/share/contact.php
new file mode 100644
index 00000000000..718c8f9025f
--- /dev/null
+++ b/apps/contacts/lib/share/contact.php
@@ -0,0 +1,53 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Contact implements OCP\Share_Backend {
+
+ const FORMAT_CONTACT = 0;
+
+ private static $contact;
+
+ public function isValidSource($itemSource, $uidOwner) {
+ self::$contact = OC_Contacts_VCard::find($itemSource);
+ if (self::$contact) {
+ return true;
+ }
+ return false;
+ }
+
+ public function generateTarget($itemSource, $shareWith, $exclude = null) {
+ // TODO Get default addressbook and check for conflicts
+ return self::$contact['fullname'];
+ }
+
+ public function formatItems($items, $format, $parameters = null) {
+ $contacts = array();
+ if ($format == self::FORMAT_CONTACT) {
+ foreach ($items as $item) {
+ $contact = OC_Contacts_VCard::find($item['item_source']);
+ $contact['fullname'] = $item['item_target'];
+ $contacts[] = $contact;
+ }
+ }
+ return $contacts;
+ }
+
+} \ No newline at end of file
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index 81ae689d9a2..8c38f1ba15d 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -293,12 +293,17 @@ class OC_Contacts_VCard{
OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::add. No vCard supplied', OCP\Util::ERROR);
return null;
};
-
+ $addressbook = OC_Contacts_Addressbook::find($aid);
+ if ($addressbook['userid'] != OCP\User::getUser()) {
+ $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid);
+ if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) {
+ return false;
+ }
+ }
if(!$isChecked) {
OC_Contacts_App::loadCategoriesFromVCard($card);
self::updateValuesFromAdd($aid, $card);
}
-
$card->setString('VERSION', '3.0');
// Add product ID is missing.
$prodid = trim($card->getAsString('PRODID'));
@@ -357,6 +362,17 @@ class OC_Contacts_VCard{
foreach($objects as $object) {
$vcard = OC_VObject::parse($object[1]);
if(!is_null($vcard)) {
+ $oldcard = self::find($object[0]);
+ if (!$oldcard) {
+ return false;
+ }
+ $addressbook = OC_Contacts_Addressbook::find($oldcard['addressbookid']);
+ if ($addressbook['userid'] != OCP\User::getUser()) {
+ $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $object[0], OCP\Share::FORMAT_NONE, null, true);
+ if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_UPDATE)) {
+ return false;
+ }
+ }
$vcard->setString('REV', $now->format(DateTime::W3C));
$data = $vcard->serialize();
try {
@@ -378,11 +394,20 @@ class OC_Contacts_VCard{
*/
public static function edit($id, OC_VObject $card){
$oldcard = self::find($id);
-
+ if (!$oldcard) {
+ return false;
+ }
if(is_null($card)) {
return false;
}
-
+ // NOTE: Owner checks are being made in the ajax files, which should be done inside the lib files to prevent any redundancies with sharing checks
+ $addressbook = OC_Contacts_Addressbook::find($oldcard['addressbookid']);
+ if ($addressbook['userid'] != OCP\User::getUser()) {
+ $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
+ if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_UPDATE)) {
+ return false;
+ }
+ }
OC_Contacts_App::loadCategoriesFromVCard($card);
$fn = $card->getAsString('FN');
@@ -431,6 +456,17 @@ class OC_Contacts_VCard{
* @return boolean
*/
public static function delete($id){
+ $card = self::find($id);
+ if (!$card) {
+ return false;
+ }
+ $addressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
+ if ($addressbook['userid'] != OCP\User::getUser()) {
+ $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
+ if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
+ return false;
+ }
+ }
OC_Hook::emit('OC_Contacts_VCard', 'pre_deleteVCard', array('aid' => null, 'id' => $id, 'uri' => null));
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE id = ?' );
try {
@@ -451,6 +487,18 @@ class OC_Contacts_VCard{
* @return boolean
*/
public static function deleteFromDAVData($aid,$uri){
+ $addressbook = OC_Contacts_Addressbook::find($aid);
+ if ($addressbook['userid'] != OCP\User::getUser()) {
+ $query = OCP\DB::prepare( 'SELECT id FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri = ?' );
+ $id = $query->execute(array($aid, $uri))->fetchOne();
+ if (!$id) {
+ return false;
+ }
+ $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
+ if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
+ return false;
+ }
+ }
OC_Hook::emit('OC_Contacts_VCard', 'pre_deleteVCard', array('aid' => $aid, 'id' => null, 'uri' => $uri));
$stmt = OCP\DB::prepare( 'DELETE FROM *PREFIX*contacts_cards WHERE addressbookid = ? AND uri=?' );
try {
@@ -594,7 +642,27 @@ class OC_Contacts_VCard{
*/
public static function moveToAddressBook($aid, $id, $isAddressbook = false) {
OC_Contacts_App::getAddressbook($aid); // check for user ownership.
+ $addressbook = OC_Contacts_Addressbook::find($aid);
+ if ($addressbook['userid'] != OCP\User::getUser()) {
+ $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid);
+ if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) {
+ return false;
+ }
+ }
if(is_array($id)) {
+ foreach ($id as $index => $cardId) {
+ $card = self::find($cardId);
+ if (!$card) {
+ unset($id[$index]);
+ }
+ $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
+ if ($oldAddressbook['userid'] != OCP\User::getUser()) {
+ $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $cardId, OCP\Share::FORMAT_NONE, null, true);
+ if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
+ unset($id[$index]);
+ }
+ }
+ }
$id_sql = join(',', array_fill(0, count($id), '?'));
$prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN ('.$id_sql.')';
try {
@@ -613,6 +681,17 @@ class OC_Contacts_VCard{
if($isAddressbook) {
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE addressbookid = ?' );
} else {
+ $card = self::find($id);
+ if (!$card) {
+ return false;
+ }
+ $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
+ if ($oldAddressbook['userid'] != OCP\User::getUser()) {
+ $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
+ if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
+ return false;
+ }
+ }
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' );
}
try {
diff --git a/apps/contacts/templates/settings.php b/apps/contacts/templates/settings.php
index 3fddc59588a..e3536c7b461 100644
--- a/apps/contacts/templates/settings.php
+++ b/apps/contacts/templates/settings.php
@@ -23,6 +23,9 @@
<a class="svg action cloud" title="<?php echo $l->t('Show read-only VCF link'); ?>"></a>
</td>
<td class="action">
+ <a class="svg action share" data-item-type="addressbook" data-item="<?php echo $addressbook['id'] ?>" title="<?php echo $l->t("Share"); ?>"></a>
+ </td>
+ <td class="action">
<a class="svg action download" title="<?php echo $l->t('Download'); ?>"
href="<?php echo OCP\Util::linkToAbsolute('contacts', 'export.php'); ?>?bookid=<?php echo $addressbook['id'] ?>"></a>
</td>
diff --git a/apps/files/index.php b/apps/files/index.php
index d65aa6cabb8..6d53527025a 100644
--- a/apps/files/index.php
+++ b/apps/files/index.php
@@ -93,7 +93,7 @@ $tmpl = new OCP\Template( 'files', 'index', 'user' );
$tmpl->assign( 'fileList', $list->fetchPage(), false );
$tmpl->assign( 'breadcrumb', $breadcrumbNav->fetchPage(), false );
$tmpl->assign( 'dir', OC_Filesystem::normalizePath($dir));
-$tmpl->assign( 'readonly', !OC_Filesystem::is_writable($dir.'/'));
+$tmpl->assign( 'isCreatable', OC_Filesystem::isCreatable($dir.'/'));
$tmpl->assign( 'files', $files );
$tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign( 'uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index b6f4d0b0896..39e848cec80 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -1,19 +1,28 @@
FileActions={
+ PERMISSION_CREATE:4,
+ PERMISSION_READ:1,
+ PERMISSION_UPDATE:2,
+ PERMISSION_DELETE:8,
+ PERMISSION_SHARE:16,
actions:{},
defaults:{},
icons:{},
currentFile:null,
- register:function(mime,name,icon,action){
+ register:function(mime,name,permissions,icon,action){
if(!FileActions.actions[mime]){
FileActions.actions[mime]={};
}
- FileActions.actions[mime][name]=action;
+ if (!FileActions.actions[mime][name]) {
+ FileActions.actions[mime][name] = {};
+ }
+ FileActions.actions[mime][name]['action'] = action;
+ FileActions.actions[mime][name]['permissions'] = permissions;
FileActions.icons[name]=icon;
},
setDefault:function(mime,name){
FileActions.defaults[mime]=name;
},
- get:function(mime,type){
+ get:function(mime,type,permissions){
var actions={};
if(FileActions.actions.all){
actions=$.extend( actions, FileActions.actions.all )
@@ -32,9 +41,15 @@ FileActions={
actions=$.extend( actions, FileActions.actions[type] )
}
}
- return actions;
+ var filteredActions = {};
+ $.each(actions, function(name, action) {
+ if (action.permissions & permissions) {
+ filteredActions[name] = action.action;
+ }
+ });
+ return filteredActions;
},
- getDefault:function(mime,type){
+ getDefault:function(mime,type,permissions){
if(mime){
var mimePart=mime.substr(0,mime.indexOf('/'));
}
@@ -48,22 +63,20 @@ FileActions={
}else{
name=FileActions.defaults.all;
}
- var actions=this.get(mime,type);
+ var actions=this.get(mime,type,permissions);
return actions[name];
},
- display:function(parent, filename, type){
+ display:function(parent){
FileActions.currentFile=parent;
$('#fileList span.fileactions, #fileList td.date a.action').remove();
- var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType());
+ var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions());
var file=FileActions.getCurrentFile();
if($('tr').filterAttr('data-file',file).data('renaming')){
return;
}
parent.children('a.name').append('<span class="fileactions" />');
- var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType());
+ var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions());
for(name in actions){
- // no rename and share action for the 'Shared' dir
- if((name=='Rename' || name =='Share') && type=='dir' && filename=='Shared') { continue; }
if((name=='Download' || actions[name]!=defaultAction) && name!='Delete'){
var img=FileActions.icons[name];
if(img.call){
@@ -86,16 +99,12 @@ FileActions={
parent.find('a.name>span.fileactions').append(element);
}
}
- if(actions['Delete'] && (type!='dir' || filename != 'Shared')){ // no delete action for the 'Shared' dir
+ if(actions['Delete']){
var img=FileActions.icons['Delete'];
if(img.call){
img=img(file);
}
- if ($('#dir').val().indexOf('Shared') != -1) {
- var html='<a href="#" original-title="' + t('files', 'Unshare') + '" class="action delete" style="display:none" />';
- } else {
- var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />';
- }
+ var html='<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" style="display:none" />';
var element=$(html);
if(img){
element.append($('<img src="'+img+'"/>'));
@@ -131,6 +140,9 @@ FileActions={
},
getCurrentType:function(){
return FileActions.currentFile.parent().attr('data-type');
+ },
+ getCurrentPermissions:function() {
+ return FileActions.currentFile.parent().data('permissions');
}
}
@@ -140,12 +152,12 @@ $(document).ready(function(){
} else {
var downloadScope = 'file';
}
- FileActions.register(downloadScope,'Download',function(){return OC.imagePath('core','actions/download')},function(filename){
+ FileActions.register(downloadScope,'Download', FileActions.PERMISSION_READ, function(){return OC.imagePath('core','actions/download')},function(filename){
window.location=OC.filePath('files', 'ajax', 'download.php') + encodeURIComponent('?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val()));
});
});
-FileActions.register('all','Delete',function(){return OC.imagePath('core','actions/delete')},function(filename){
+FileActions.register('all','Delete', FileActions.PERMISSION_DELETE, function(){return OC.imagePath('core','actions/delete')},function(filename){
if(Files.cancelUpload(filename)) {
if(filename.substr){
filename=[filename];
@@ -163,11 +175,11 @@ FileActions.register('all','Delete',function(){return OC.imagePath('core','actio
$('.tipsy').remove();
});
-FileActions.register('all','Rename',function(){return OC.imagePath('core','actions/rename')},function(filename){
+FileActions.register('all','Rename', FileActions.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/rename')},function(filename){
FileList.rename(filename);
});
-FileActions.register('dir','Open','',function(filename){
+FileActions.register('dir','Open', FileActions.PERMISSION_READ, '', function(filename){
window.location=OC.linkTo('files', 'index.php') + '&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
});
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 935101e86e2..049afea4f61 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -56,7 +56,7 @@ $(document).ready(function() {
// Sets the file-action buttons behaviour :
$('tr').live('mouseenter',function(event) {
- FileActions.display($(this).children('td.filename'), $(this).attr('data-file'), $(this).attr('data-type'));
+ FileActions.display($(this).children('td.filename'));
});
$('tr').live('mouseleave',function(event) {
FileActions.hide();
@@ -106,7 +106,8 @@ $(document).ready(function() {
if(!renaming && !FileList.isLoading(filename)){
var mime=$(this).parent().parent().data('mime');
var type=$(this).parent().parent().data('type');
- var action=FileActions.getDefault(mime,type);
+ var permissions = $(this).parent().parent().data('permissions');
+ var action=FileActions.getDefault(mime,type, permissions);
if(action){
action(filename);
}
@@ -462,14 +463,18 @@ $(document).ready(function() {
$.post(
OC.filePath('files','ajax','newfile.php'),
{dir:$('#dir').val(),filename:name,content:" \n"},
- function(data){
- var date=new Date();
- FileList.addFile(name,0,date);
- var tr=$('tr').filterAttr('data-file',name);
- tr.data('mime','text/plain');
- getMimeIcon('text/plain',function(path){
- tr.find('td.filename').attr('style','background-image:url('+path+')');
- });
+ function(result){
+ if (result.status == 'success') {
+ var date=new Date();
+ FileList.addFile(name,0,date);
+ var tr=$('tr').filterAttr('data-file',name);
+ tr.data('mime','text/plain');
+ getMimeIcon('text/plain',function(path){
+ tr.find('td.filename').attr('style','background-image:url('+path+')');
+ });
+ } else {
+ OC.dialogs.alert(result.data.message, 'Error');
+ }
}
);
break;
@@ -477,9 +482,13 @@ $(document).ready(function() {
$.post(
OC.filePath('files','ajax','newfolder.php'),
{dir:$('#dir').val(),foldername:name},
- function(data){
- var date=new Date();
- FileList.addDir(name,0,date);
+ function(result){
+ if (result.status == 'success') {
+ var date=new Date();
+ FileList.addDir(name,0,date);
+ } else {
+ OC.dialogs.alert(result.data.message, 'Error');
+ }
}
);
break;
diff --git a/apps/files/share.php b/apps/files/share.php
new file mode 100755
index 00000000000..4f7c1f55fcf
--- /dev/null
+++ b/apps/files/share.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Files extends OCP\Share_Backend {
+
+ public function getSource($item, $uid) {
+ return $item;
+ }
+}
+
+class OC_Share_Backend_Folders extends OC_Share_Backend_Files {
+
+ public function share($
+ public function getDirectoryContent($folder) {
+
+ }
+}
+
+?> \ No newline at end of file
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php
index 44000171a17..bcf683ae4a8 100644
--- a/apps/files/templates/index.php
+++ b/apps/files/templates/index.php
@@ -1,8 +1,8 @@
<!--[if IE 8]><style>input[type="checkbox"]{padding:0;}table td{position:static !important;}</style><![endif]-->
<div id="controls">
<?php echo($_['breadcrumb']); ?>
- <?php if (!isset($_['readonly']) || !$_['readonly']):?>
- <div class="actions <?php if (isset($_['files']) and ! $_['readonly'] and count($_['files'])==0):?>emptyfolder<?php endif; ?>">
+ <?php if ($_['isCreatable']):?>
+ <div class="actions <?php if (isset($_['files']) and count($_['files'])==0):?>emptyfolder<?php endif; ?>">
<div id='new' class='button'>
<a><?php echo $l->t('New');?></a>
<ul class="popup popupTop">
@@ -35,7 +35,7 @@
</div>
<div id='notification'></div>
-<?php if (isset($_['files']) and ! $_['readonly'] and count($_['files'])==0):?>
+<?php if (isset($_['files']) and $_['isCreatable'] and count($_['files'])==0):?>
<div id="emptyfolder"><?php echo $l->t('Nothing in here. Upload something!')?></div>
<?php endif; ?>
@@ -43,7 +43,7 @@
<thead>
<tr>
<th id='headerName'>
- <?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" id="select_all" /><?php } ?>
+ <input type="checkbox" id="select_all" />
<span class='name'><?php echo $l->t( 'Name' ); ?></span>
<span class='selectedActions'>
<!-- <a href="" class="share"><img class='svg' alt="Share" src="<?php echo OCP\image_path("core", "actions/share.svg"); ?>" /> <?php echo $l->t('Share')?></a> -->
@@ -56,7 +56,7 @@
<th id="headerDate"><span id="modified"><?php echo $l->t( 'Modified' ); ?></span><span class="selectedActions"><a href="" class="delete"><?php echo $l->t('Delete')?> <img class="svg" alt="<?php echo $l->t('Delete')?>" src="<?php echo OCP\image_path("core", "actions/delete.svg"); ?>" /></a></span></th>
</tr>
</thead>
- <tbody id="fileList" data-readonly="<?php echo $_['readonly'];?>">
+ <tbody id="fileList">
<?php echo($_['fileList']); ?>
</tbody>
</table>
diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php
index 4506630c16d..6667b5488af 100644
--- a/apps/files/templates/part.list.php
+++ b/apps/files/templates/part.list.php
@@ -1,5 +1,4 @@
<?php foreach($_['files'] as $file):
- $write = ($file['writable']) ? 'true' : 'false';
$simple_file_size = OCP\simple_file_size($file['size']);
$simple_size_color = intval(200-$file['size']/(1024*1024)*2); // the bigger the file, the darker the shade of grey; megabytes*2
if($simple_size_color<0) $simple_size_color = 0;
@@ -10,7 +9,7 @@
$name = str_replace('%2F','/', $name);
$directory = str_replace('+','%20',urlencode($file['directory']));
$directory = str_replace('%2F','/', $directory); ?>
- <tr data-file="<?php echo $name;?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>' data-write='<?php echo $write;?>'>
+ <tr data-file="<?php echo $name;?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mimetype']?>" data-size='<?php echo $file['size'];?>' data-permissions='<?php echo $file['permissions']; ?>'>
<td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo OCP\mimetype_icon('dir'); else echo OCP\mimetype_icon($file['mimetype']); ?>)">
<?php if(!isset($_['readonly']) || !$_['readonly']) { ?><input type="checkbox" /><?php } ?>
<a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseURL'].$directory.'/'.$name; else echo $_['downloadURL'].$directory.'/'.$name; ?>" title="">
diff --git a/apps/files_archive/js/archive.js b/apps/files_archive/js/archive.js
index 9fb9853e299..6bcbe092662 100644
--- a/apps/files_archive/js/archive.js
+++ b/apps/files_archive/js/archive.js
@@ -7,11 +7,11 @@
$(document).ready(function() {
if(typeof FileActions!=='undefined'){
- FileActions.register('application/zip','Open','',function(filename){
+ FileActions.register('application/zip','Open', FileActions.PERMISSION_READ, '',function(filename){
window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
});
FileActions.setDefault('application/zip','Open');
- FileActions.register('application/x-gzip','Open','',function(filename){
+ FileActions.register('application/x-gzip','Open', FileActions.PERMISSION_READ, '',function(filename){
window.location=OC.linkTo('files', 'index.php')+'&dir='+encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+encodeURIComponent(filename);
});
FileActions.setDefault('application/x-gzip','Open');
diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php
index ca36e76b48a..3c14c3e1fdf 100644
--- a/apps/files_archive/lib/storage.php
+++ b/apps/files_archive/lib/storage.php
@@ -89,10 +89,10 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
return $this->archive->fileExists($path.'/')?'dir':'file';
}
}
- public function is_readable($path){
+ public function isReadable($path){
return is_readable($this->path);
}
- public function is_writable($path){
+ public function isUpdatable($path){
return is_writable($this->path);
}
public function file_exists($path){
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php
index 9feb490dac0..3c2e3330175 100644
--- a/apps/files_external/lib/amazons3.php
+++ b/apps/files_external/lib/amazons3.php
@@ -134,12 +134,12 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common {
return false;
}
- public function is_readable($path) {
+ public function isReadable($path) {
// TODO Check acl and determine who grantee is
return true;
}
- public function is_writable($path) {
+ public function isUpdatable($path) {
// TODO Check acl and determine who grantee is
return true;
}
diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php
index a27d9d7c368..b90563a5065 100755
--- a/apps/files_external/lib/dropbox.php
+++ b/apps/files_external/lib/dropbox.php
@@ -125,11 +125,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
return false;
}
- public function is_readable($path) {
+ public function isReadable($path) {
return $this->file_exists($path);
}
- public function is_writable($path) {
+ public function isUpdatable($path) {
return $this->file_exists($path);
}
diff --git a/apps/files_external/lib/dropboxtest.php b/apps/files_external/lib/dropboxtest.php
new file mode 100644
index 00000000000..686549e16b8
--- /dev/null
+++ b/apps/files_external/lib/dropboxtest.php
@@ -0,0 +1,71 @@
+<?php
+
+require_once 'dropbox.php';
+// $oauth = new Dropbox_OAuth_Curl('526ar3qlrtzmv65', '3bbn0wo5lzgpjty');
+$dropbox = new OC_Filestorage_Dropbox(array('app_key' => '526ar3qlrtzmv65', 'app_secret' => '3bbn0wo5lzgpjty', 'token' => 'a3ben02jb1y538a', 'token_secret' => 'x60h3fsky21r1b0'));
+$dropbox->rename('/652072main_2012-2897_full (1).jpg', '/test.jpg');
+// $dropbox->test();
+// print_r($dropbox->mkdir('Again'));
+
+// GET&https%3A%2F%2Fapi.dropbox.com%2F1%2Fmetadata%2Fdropbox%2FownCloud&list%3D0%26
+
+// uzpi8oo2rbax1po
+// th9uoso3xxny3ca
+//Step 3: Acquiring access tokens Array ( [token] => 37my637p88ng967 [token_secret] => t49fmgp3omucnnr )
+//The user is authenticated You should really save the oauth tokens somewhere, so the first steps will no longer be needed Array ( [token] => 37my637p88ng967 [token_secret] => t49fmgp3omucnnr )
+
+// For convenience, definitely not required
+// header('Content-Type: text/plain');
+
+// // We need to start a session
+// session_start();
+
+// There are multiple steps in this workflow, we keep a 'state number' here
+// if (isset($_SESSION['state'])) {
+// $state = 2;
+// } else {
+// $state = 1;
+// }
+//
+// switch($state) {
+//
+// /* In this phase we grab the initial request tokens
+// and redirect the user to the 'authorize' page hosted
+// on dropbox */
+// case 1 :
+// echo "Step 1: Acquire request tokens\n";
+// $tokens = $oauth->getRequestToken();
+// print_r($tokens);
+//
+// // Note that if you want the user to automatically redirect back, you can
+// // add the 'callback' argument to getAuthorizeUrl.
+// echo "Step 2: You must now redirect the user to:\n";
+// echo $oauth->getAuthorizeUrl() . "\n";
+// $_SESSION['state'] = 2;
+// $_SESSION['oauth_tokens'] = $tokens;
+// die();
+//
+// /* In this phase, the user just came back from authorizing
+// and we're going to fetch the real access tokens */
+// case 2 :
+// echo "Step 3: Acquiring access tokens\n";
+// $oauth->setToken($_SESSION['oauth_tokens']);
+// $tokens = $oauth->getAccessToken();
+// print_r($tokens);
+// $_SESSION['state'] = 3;
+// $_SESSION['oauth_tokens'] = $tokens;
+// // There is no break here, intentional
+//
+// /* This part gets called if the authentication process
+// already succeeded. We can use our stored tokens and the api
+// should work. Store these tokens somewhere, like a database */
+// case 3 :
+// echo "The user is authenticated\n";
+// echo "You should really save the oauth tokens somewhere, so the first steps will no longer be needed\n";
+// print_r($_SESSION['oauth_tokens']);
+// $oauth->setToken($_SESSION['oauth_tokens']);
+// break;
+//
+// }
+
+?> \ No newline at end of file
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php
index 2b387f0c833..73317bbf714 100644
--- a/apps/files_external/lib/google.php
+++ b/apps/files_external/lib/google.php
@@ -284,11 +284,11 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
return false;
}
- public function is_readable($path) {
+ public function isReadable($path) {
return true;
}
- public function is_writable($path) {
+ public function isUpdatable($path) {
if ($path == '' || $path == '/') {
return true;
} else if ($entry = $this->getResource($path)) {
diff --git a/apps/files_external/lib/googletest.php b/apps/files_external/lib/googletest.php
new file mode 100644
index 00000000000..a80af6a0978
--- /dev/null
+++ b/apps/files_external/lib/googletest.php
@@ -0,0 +1,8 @@
+<?php
+
+require_once 'google.php';
+
+// $drive = new OC_Filestorage_Google(array('token' => '4/7nZMlRLlAEeXdY0AeH-eHNCL0YaK', 'token_secret' => 'NqO5VMGUVkwFtOYqHsex4257'));
+// $drive = new OC_Filestorage_Google(array('token' => '1/4Xo84YtTxL2MkQst-Ti3nqF1Isy70NUHDRk-BwsLMf4', 'token_secret' => 'jYnyJ_4-ITNxlX9f9RDNoRW-'));
+// var_export($drive->getFeed('https://docs.google.com/feeds/metadata/default', 'GET'));
+
diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php
index 7d56445361e..467c5a5b845 100644
--- a/apps/files_external/lib/streamwrapper.php
+++ b/apps/files_external/lib/streamwrapper.php
@@ -32,11 +32,11 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
return filetype($this->constructUrl($path));
}
- public function is_readable($path){
+ public function isReadable($path){
return true;//not properly supported
}
- public function is_writable($path){
+ public function isUpdatable($path){
return true;//not properly supported
}
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index 58b95a6ae01..94ccde1ff8f 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -353,11 +353,11 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
}
- public function is_readable($path){
+ public function isReadable($path){
return true;
}
- public function is_writable($path){
+ public function isUpdatable($path){
return true;
}
diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php
index 84d64b65193..e3f73c5c0a7 100644
--- a/apps/files_external/lib/webdav.php
+++ b/apps/files_external/lib/webdav.php
@@ -104,11 +104,11 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
}
- public function is_readable($path){
+ public function isReadable($path){
return true;//not properly supported
}
- public function is_writable($path){
+ public function isUpdatable($path){
return true;//not properly supported
}
diff --git a/apps/files_external/tests/test.php b/apps/files_external/tests/test.php
new file mode 100644
index 00000000000..bd24404f3b9
--- /dev/null
+++ b/apps/files_external/tests/test.php
@@ -0,0 +1,7 @@
+<?php
+require_once 'files_external/lib/config.php';
+echo "<pre>";
+print_r(OC_Mount_Config::getSystemMountPoints());
+echo "</pre>";
+// OC_Mount_Config::addMountPoint('Photos', 'OC_Filestorage_SWIFT', array('host' => 'gapinthecloud.com', 'user' => 'Gap', 'token' => '23423afdasFJEW22', 'secure' => 'true', 'root' => ''), OC_Mount_Config::MOUNT_TYPE_GROUP, 'admin', false);
+?>
diff --git a/apps/files_imageviewer/js/lightbox.js b/apps/files_imageviewer/js/lightbox.js
index 31f08456d22..ff12d808bc8 100644
--- a/apps/files_imageviewer/js/lightbox.js
+++ b/apps/files_imageviewer/js/lightbox.js
@@ -1,6 +1,6 @@
$(document).ready(function() {
if(typeof FileActions!=='undefined'){
- FileActions.register('image','View','',function(filename){
+ FileActions.register('image','View', FileActions.PERMISSION_READ, '',function(filename){
viewImage($('#dir').val(),filename);
});
FileActions.setDefault('image','View');
diff --git a/apps/files_pdfviewer/js/viewer.js b/apps/files_pdfviewer/js/viewer.js
index 2c9cbb9b431..29db2ea7f24 100644
--- a/apps/files_pdfviewer/js/viewer.js
+++ b/apps/files_pdfviewer/js/viewer.js
@@ -40,7 +40,7 @@ $(document).ready(function(){
if(location.href.indexOf("files")!=-1) {
PDFJS.workerSrc = OC.filePath('files_pdfviewer','js','pdfjs/build/pdf.js');
if(typeof FileActions!=='undefined'){
- FileActions.register('application/pdf','Edit','',function(filename){
+ FileActions.register('application/pdf','Edit', FileActions.PERMISSION_READ, '',function(filename){
showPDFviewer($('#dir').val(),filename);
});
FileActions.setDefault('application/pdf','Edit');
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index bbb753d5e69..7495a5bbe6c 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -1,6 +1,8 @@
<?php
OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php";
+OC::$CLASSPATH['OC_Share_Backend_File'] = "apps/files_sharing/lib/share/file.php";
+OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'apps/files_sharing/lib/share/folder.php';
OC::$CLASSPATH['OC_Filestorage_Shared'] = "apps/files_sharing/sharedstorage.php";
OCP\App::registerAdmin('files_sharing', 'settings');
@@ -17,8 +19,10 @@ OCP\Util::connectHook('OC_User', 'post_removeFromGroup', 'OC_Share', 'removeFrom
$dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
if ($dir != '/Shared' || OCP\Config::getAppValue('files_sharing', 'resharing', 'yes') == 'yes') {
- OCP\Util::addscript("files_sharing", "share");
+ OCP\Util::addScript('core', 'share');
}
OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");
OCP\Util::addStyle( 'files_sharing', 'sharing' );
OCP\Util::addStyle("3rdparty", "chosen/chosen");
+OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
+OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
diff --git a/apps/files_sharing/css/sharing.css b/apps/files_sharing/css/sharing.css
index d4fcf79ee98..a683a24a116 100644
--- a/apps/files_sharing/css/sharing.css
+++ b/apps/files_sharing/css/sharing.css
@@ -2,14 +2,16 @@
This file is licensed under the Affero General Public License version 3 or later.
See the COPYING-README file. */
-#dropdown { display:block; position:absolute; z-index:100; width:16em; right:0; margin-right:7em; background:#eee; padding:1em;
+#dropdown { display:block; position:absolute; z-index:500; width:16em; right:0; margin-right:7em; background:#eee; padding:1em;
-moz-box-shadow:0 1px 1px #777; -webkit-box-shadow:0 1px 1px #777; box-shadow:0 1px 1px #777;
-moz-border-radius-bottomleft:1em; -webkit-border-bottom-left-radius:1em; border-bottom-left-radius:1em;
-moz-border-radius-bottomright:1em; -webkit-border-bottom-right-radius:1em; border-bottom-right-radius:1em; }
-#sharedWithList { padding:0.5em; list-style-type: none; }
-#privateLink { border-top:1px solid #ddd; padding-top:0.5em; }
-a.unshare { float:right; display:inline; margin:0 .5em; padding:.3em .3em 0 .3em !important; opacity:.5; }
+#shareWithList { padding:0.5em; list-style-type: none; }
+#shareWithList li { padding-top:0.1em; }
+#dropdown label { font-weight:normal; }
+#dropdown input[type="checkbox"] { margin:0 0.2em 0 0.5em; }
+a.showCruds { display:inline; opacity:.5; }
+a.showCruds:hover { opacity:1; }
+a.unshare { float:right; display:inline; padding:.3em 0 0 .3em !important; opacity:.5; }
a.unshare:hover { opacity:1; }
-#share_with { width: 16em; }
-#privateLink label, .edit { font-weight:normal; }
-#share_with_chzn { display: block; }
+#privateLink { border-top:1px solid #ddd; padding-top:0.5em; } \ No newline at end of file
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
new file mode 100644
index 00000000000..ae6315600f8
--- /dev/null
+++ b/apps/files_sharing/lib/share/file.php
@@ -0,0 +1,91 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
+
+ const FORMAT_SHARED_STORAGE = 0;
+ const FORMAT_FILE_APP = 1;
+ const FORMAT_FILE_APP_ROOT = 2;
+ const FORMAT_OPENDIR = 3;
+
+ public function isValidSource($item, $uid) {
+ if (OC_Filesystem::file_exists($item)) {
+ return true;
+ }
+ return false;
+ }
+
+ public function getFilePath($item, $uid) {
+ return $item;
+ }
+
+ public function generateTarget($item, $uid, $exclude = null) {
+ // TODO Make sure target path doesn't exist already
+ return $item;
+ }
+
+ public function formatItems($items, $format, $parameters = null) {
+ if ($format == self::FORMAT_SHARED_STORAGE) {
+ // Only 1 item should come through for this format call
+ return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']);
+ } else if ($format == self::FORMAT_FILE_APP) {
+ $files = array();
+ foreach ($items as $item) {
+ $file = array();
+ $file['path'] = $item['file_target'];
+ $file['name'] = basename($item['file_target']);
+ $file['ctime'] = $item['ctime'];
+ $file['mtime'] = $item['mtime'];
+ $file['mimetype'] = $item['mimetype'];
+ $file['size'] = $item['size'];
+ $file['encrypted'] = $item['encrypted'];
+ $file['versioned'] = $item['versioned'];
+ $file['directory'] = $parameters['folder'];
+ $file['type'] = ($item['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
+ $file['permissions'] = $item['permissions'];
+ if ($file['type'] == 'file') {
+ // Remove Create permission if type is file
+ $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE;
+ }
+ $files[] = $file;
+ }
+ return $files;
+ } else if ($format == self::FORMAT_FILE_APP_ROOT) {
+ $mtime = 0;
+ $size = 0;
+ foreach ($items as $item) {
+ if ($item['mtime'] > $mtime) {
+ $mtime = $item['mtime'];
+ }
+ $size += $item['size'];
+ }
+ return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\Share::PERMISSION_READ));
+ } else if ($format == self::FORMAT_OPENDIR) {
+ $files = array();
+ foreach ($items as $item) {
+ $files[] = basename($item['file_target']);
+ }
+ return $files;
+ }
+ return array();
+ }
+
+} \ No newline at end of file
diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php
new file mode 100644
index 00000000000..b6db96614fd
--- /dev/null
+++ b/apps/files_sharing/lib/share/folder.php
@@ -0,0 +1,61 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Folder extends OC_Share_Backend_File {
+
+ public function formatItems($items, $format, $parameters = null) {
+ if ($format == self::FORMAT_SHARED_STORAGE) {
+ // Only 1 item should come through for this format call
+ return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']);
+ } else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) {
+ // Only 1 item should come through for this format call
+ $folder = $items[key($items)];
+ if (isset($parameters['mimetype_filter'])) {
+ $mimetype_filter = $parameters['mimetype_filter'];
+ } else {
+ $mimetype_filter = '';
+ }
+ $path = $folder['file_source'].substr($parameters['folder'], 7 + strlen($folder['file_target']));
+ $files = OC_FileCache::getFolderContent($path, '', $mimetype_filter);
+ foreach ($files as &$file) {
+ $file['directory'] = $parameters['folder'];
+ $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
+ $file['permissions'] = $folder['permissions'];
+ if ($file['type'] == 'file') {
+ // Remove Create permission if type is file
+ $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE;
+ }
+ }
+ return $files;
+ }
+ return array();
+ }
+
+ public function getChildren($itemSource) {
+ $files = OC_FileCache::getFolderContent($itemSource);
+ $sources = array();
+ foreach ($files as $file) {
+ $sources[] = $file['path'];
+ }
+ return $sources;
+ }
+
+} \ No newline at end of file
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index 05df275ca9f..582c9c66172 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -3,7 +3,7 @@
* ownCloud
*
* @author Michael Gapczynski
- * @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com
+ * @copyright 2011 Michael Gapczynski mtgap@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -20,213 +20,217 @@
*
*/
-require_once( 'lib_share.php' );
-
/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
class OC_Filestorage_Shared extends OC_Filestorage_Common {
- private $datadir;
- private $sourcePaths = array();
+ private $sharedFolder;
+ private $files = array();
public function __construct($arguments) {
- $this->datadir = $arguments['datadir'];
- $this->datadir .= "/";
+ $this->sharedFolder = $arguments['sharedFolder'];
}
-
- public function getInternalPath($path) {
+
+ /**
+ * @brief Get the source file path and the permissions granted for a shared file
+ * @param string Shared target file path
+ * @return Returns array with the keys path and permissions or false if not found
+ */
+ private function getFile($target) {
+ $target = '/'.$target;
+ $target = rtrim($target, '/');
+ if (isset($this->files[$target])) {
+ return $this->files[$target];
+ } else {
+ $pos = strpos($target, '/', 1);
+ // Get shared folder name
+ if ($pos !== false) {
+ $folder = substr($target, 0, $pos);
+ if (isset($this->files[$folder])) {
+ $file = $this->files[$folder];
+ } else {
+ $file = OCP\Share::getItemSharedWith('folder', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ }
+ if ($file) {
+ $this->files[$target]['path'] = $file['path'].substr($target, strlen($folder));
+ $this->files[$target]['permissions'] = $file['permissions'];
+ return $this->files[$target];
+ }
+ } else {
+ $file = OCP\Share::getItemSharedWith('file', $target, OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
+ if ($file) {
+ $this->files[$target] = $file;
+ return $this->files[$target];
+ }
+ }
+ OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, OCP\Util::ERROR);
+ return false;
+ }
+ }
+
+ /**
+ * @brief Get the source file path for a shared file
+ * @param string Shared target file path
+ * @return Returns source file path or false if not found
+ */
+ private function getSourcePath($target) {
+ $file = $this->getFile($target);
+ if (isset($file['path'])) {
+ return $file['path'];
+ }
+ return false;
+ }
+
+ /**
+ * @brief Get the permissions granted for a shared file
+ * @param string Shared target file path
+ * @return Returns CRUDS permissions granted or false if not found
+ */
+ private function getPermissions($target) {
+ $file = $this->getFile($target);
+ if (isset($file['permissions'])) {
+ return $file['permissions'];
+ }
+ return false;
+ }
+
+ /**
+ * @brief Get the internal path to pass to the storage filesystem call
+ * @param string Source file path
+ * @return Source file path with mount point stripped out
+ */
+ private function getInternalPath($path) {
$mountPoint = OC_Filesystem::getMountPoint($path);
$internalPath = substr($path, strlen($mountPoint));
return $internalPath;
}
- public function getSource($target) {
- $target = $this->datadir.$target;
- if (array_key_exists($target, $this->sourcePaths)) {
- return $this->sourcePaths[$target];
- } else {
- $source = OC_Share::getSource($target);
- $this->sourcePaths[$target] = $source;
- return $source;
- }
- }
-
public function mkdir($path) {
- if ($path == "" || $path == "/" || !$this->is_writable($path)) {
+ if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) {
return false;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->mkdir($this->getInternalPath($source));
- }
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->mkdir($this->getInternalPath($source));
}
+ return false;
}
public function rmdir($path) {
- // The folder will be removed from the database, but won't be deleted from the owner's filesystem
- OC_Share::unshareFromMySelf($this->datadir.$path);
+ if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->rmdir($this->getInternalPath($source));
+ }
+ return false;
}
public function opendir($path) {
- if ($path == "" || $path == "/") {
- $path = $this->datadir.$path;
- $sharedItems = OC_Share::getItemsInFolder($path);
- $files = array();
- foreach ($sharedItems as $item) {
- // If item is in the root of the shared storage provider and the item exists add it to the fakedirs
- if (dirname($item['target'])."/" == $path && $this->file_exists(basename($item['target']))) {
- $files[] = basename($item['target']);
- }
- }
- OC_FakeDirStream::$dirs['shared'.$path] = $files;
- return opendir('fakedir://shared'.$path);
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- $dh = $storage->opendir($this->getInternalPath($source));
- $modifiedItems = OC_Share::getItemsInFolder($source);
- if ($modifiedItems && $dh) {
- $sources = array();
- $targets = array();
- // Remove any duplicate or trailing '/'
- $path = preg_replace('{(/)\1+}', "/", $path);
- $targetFolder = rtrim($this->datadir.$path, "/");
- foreach ($modifiedItems as $item) {
- // If the item is in the current directory and the item exists add it to the arrays
- if (dirname($item['target']) == $targetFolder && $this->file_exists($path."/".basename($item['target']))) {
- // If the item was unshared from self, add it it to the arrays
- if ($item['permissions'] == OC_Share::UNSHARED) {
- $sources[] = basename($item['source']);
- $targets[] = "";
- } else {
- $sources[] = basename($item['source']);
- $targets[] = basename($item['target']);
- }
- }
- }
- // Don't waste time if there aren't any modified items in the current directory
- if (empty($sources)) {
- return $dh;
- } else {
- global $FAKEDIRS;
- $files = array();
- while (($filename = readdir($dh)) !== false) {
- if ($filename != "." && $filename != "..") {
- // If the file isn't in the sources array it isn't modified and can be added as is
- if (!in_array($filename, $sources)) {
- $files[] = $filename;
- // The file has a different name than the source and is added to the fakedirs
- } else {
- $target = $targets[array_search($filename, $sources)];
- // Don't add the file if it was unshared from self by the user
- if ($target != "") {
- $files[] = $target;
- }
- }
- }
- }
- $FAKEDIRS['shared'] = $files;
- return opendir('fakedir://shared');
- }
- } else {
- return $dh;
- }
- }
+ if ($path == '' || $path == '/') {
+ $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_Folder::FORMAT_OPENDIR);
+ OC_FakeDirStream::$dirs['shared'] = $files;
+ return opendir('fakedir://shared');
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->opendir($this->getInternalPath($source));
}
+ return false;
}
-
+
public function is_dir($path) {
- if ($path == "" || $path == "/") {
+ if ($path == '' || $path == '/') {
return true;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->is_dir($this->getInternalPath($source));
- }
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->is_dir($this->getInternalPath($source));
}
+ return false;
}
-
+
public function is_file($path) {
- $source = $this->getSource($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->is_file($this->getInternalPath($source));
}
+ return false;
}
-
- // TODO fill in other components of array
+
public function stat($path) {
- if ($path == "" || $path == "/") {
- $stat["size"] = $this->filesize($path);
- $stat["mtime"] = $this->filemtime($path);
- $stat["ctime"] = $this->filectime($path);
+ if ($path == '' || $path == '/') {
+ $stat['size'] = $this->filesize($path);
+ $stat['mtime'] = $this->filemtime($path);
+ $stat['ctime'] = $this->filectime($path);
return $stat;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->stat($this->getInternalPath($source));
- }
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->stat($this->getInternalPath($source));
}
+ return false;
}
-
+
public function filetype($path) {
- if ($path == "" || $path == "/") {
- return "dir";
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filetype($this->getInternalPath($source));
- }
+ if ($path == '' || $path == '/') {
+ return 'dir';
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->filetype($this->getInternalPath($source));
}
-
+ return false;
}
-
+
public function filesize($path) {
- if ($path == "" || $path == "/" || $this->is_dir($path)) {
+ if ($path == '' || $path == '/' || $this->is_dir($path)) {
return 0;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->filesize($this->getInternalPath($source));
- }
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->filesize($this->getInternalPath($source));
}
+ return false;
}
- public function is_readable($path) {
- return true;
+ public function isCreatable($path) {
+ if ($path == '') {
+ return false;
+ }
+ return ($this->getPermissions($path) & OCP\Share::PERMISSION_CREATE);
}
-
- public function is_writable($path) {
- if($path == "" || $path == "/"){
+
+ public function isReadable($path) {
+ return $this->file_exists($path);
+ }
+
+ public function isUpdatable($path) {
+ if ($path == '') {
return false;
- }elseif (OC_Share::getPermissions($this->datadir.$path) & OC_Share::WRITE) {
- return true;
- } else {
+ }
+ return ($this->getPermissions($path) & OCP\Share::PERMISSION_UPDATE);
+ }
+
+ public function isDeletable($path) {
+ if ($path == '') {
return false;
}
+ return ($this->getPermissions($path) & OCP\Share::PERMISSION_DELETE);
}
-
+
+ public function isSharable($path) {
+ if ($path == '') {
+ return false;
+ }
+ return ($this->getPermissions($path) & OCP\Share::PERMISSION_SHARE);
+ }
+
public function file_exists($path) {
- if ($path == "" || $path == "/") {
+ if ($path == '' || $path == '/') {
return true;
- } else {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->file_exists($this->getInternalPath($source));
- }
+ } else if ($source = $this->getSourcePath($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->file_exists($this->getInternalPath($source));
}
+ return false;
}
public function filectime($path) {
- if ($path == "" || $path == "/") {
+ if ($path == '' || $path == '/') {
$ctime = 0;
if ($dh = $this->opendir($path)) {
while (($filename = readdir($dh)) !== false) {
@@ -238,7 +242,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
return $ctime;
} else {
- $source = $this->getSource($path);
+ $source = $this->getSourcePath($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->filectime($this->getInternalPath($source));
@@ -247,7 +251,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
public function filemtime($path) {
- if ($path == "" || $path == "/") {
+ if ($path == '' || $path == '/') {
$mtime = 0;
if ($dh = $this->opendir($path)) {
while (($filename = readdir($dh)) !== false) {
@@ -259,7 +263,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
return $mtime;
} else {
- $source = $this->getSource($path);
+ $source = $this->getSourcePath($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->filemtime($this->getInternalPath($source));
@@ -268,10 +272,10 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
public function file_get_contents($path) {
- $source = $this->getSource($path);
+ $source = $this->getSourcePath($path);
if ($source) {
$info = array(
- 'target' => $this->datadir.$path,
+ 'target' => $this->sharedFolder.$path,
'source' => $source,
);
OCP\Util::emitHook('OC_Filestorage_Shared', 'file_get_contents', $info);
@@ -281,92 +285,66 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
}
public function file_put_contents($path, $data) {
- if ($this->is_writable($path)) {
- $source = $this->getSource($path);
- if ($source) {
- $info = array(
- 'target' => $this->datadir.$path,
- 'source' => $source,
- );
- OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
- $storage = OC_Filesystem::getStorage($source);
- $result = $storage->file_put_contents($this->getInternalPath($source), $data);
- return $result;
+ if ($source = $this->getSourcePath($path)) {
+ // Check if permission is granted
+ if (($this->file_exists($path) && !$this->isUpdatable($path)) || ($this->is_dir($path) && !$this->isCreatable($path))) {
+ return false;
}
+ $info = array(
+ 'target' => $this->sharedFolder.$path,
+ 'source' => $source,
+ );
+ OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info);
+ $storage = OC_Filesystem::getStorage($source);
+ $result = $storage->file_put_contents($this->getInternalPath($source), $data);
+ return $result;
}
+ return false;
}
public function unlink($path) {
- // The item will be removed from the database, but won't be touched on the owner's filesystem
- $target = $this->datadir.$path;
- // Check if the item is inside a shared folder
- if (OC_Share::getParentFolders($target)) {
- // If entry for item already exists
- if (OC_Share::getItem($target)) {
- OC_Share::unshareFromMySelf($target, false);
- } else {
- OC_Share::pullOutOfFolder($target, $target);
- OC_Share::unshareFromMySelf($target, false);
- }
- // Delete the database entry
- } else {
- OC_Share::unshareFromMySelf($target);
+ // Delete the file if DELETE permission is granted
+ if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) {
+ $storage = OC_Filesystem::getStorage($source);
+ return $storage->unlink($this->getInternalPath($source));
}
- return true;
+ return false;
}
public function rename($path1, $path2) {
- $oldTarget = $this->datadir.$path1;
- $newTarget = $this->datadir.$path2;
- // Check if the item is inside a shared folder
- if ($folders = OC_Share::getParentFolders($oldTarget)) {
- $root1 = substr($path1, 0, strpos($path1, "/"));
- $root2 = substr($path1, 0, strpos($path2, "/"));
- // Prevent items from being moved into different shared folders until versioning (cut and paste) and prevent items going into 'Shared'
- if ($root1 !== $root2) {
- return false;
- // Check if both paths have write permission
- } else if ($this->is_writable($path1) && $this->is_writable($path2)) {
- $oldSource = $this->getSource($path1);
- $newSource = $folders['source'].substr($newTarget, strlen($folders['target']));
- if ($oldSource) {
- $storage = OC_Filesystem::getStorage($oldSource);
+ if ($oldSource = $this->getSourcePath($path1)) {
+ $root1 = substr($path1, 0, strpos($path1, '/'));
+ $root2 = substr($path2, 0, strpos($path2, '/'));
+ // Moving/renaming is only allowed within the same shared folder
+ if ($root1 == $root2) {
+ $storage = OC_Filesystem::getStorage($oldSource);
+ $newSource = substr($oldSource, 0, strpos($oldSource, $root1)).$path2;
+ if (dirname($path1) == dirname($path2)) {
+ // Rename the file if UPDATE permission is granted
+ if ($this->isUpdatable($path1)) {
+ return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
+ }
+ // Move the file if DELETE and CREATE permissions are granted
+ } else if ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) {
return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
}
- // If the user doesn't have write permission, items can only be renamed and not moved
- } else if (dirname($path1) !== dirname($path2)) {
- return false;
- // The item will be renamed in the database, but won't be touched on the owner's filesystem
- } else {
- OC_Share::pullOutOfFolder($oldTarget, $newTarget);
- // If this is a folder being renamed, call setTarget in case there are any database entries inside the folder
- if (self::is_dir($path1)) {
- OC_Share::setTarget($oldTarget, $newTarget);
- }
}
- } else {
- OC_Share::setTarget($oldTarget, $newTarget);
}
- return true;
+ return false;
}
public function copy($path1, $path2) {
- if ($path2 == "" || $path2 == "/") {
- // TODO Construct new shared item or should this not be allowed?
- } else {
- if ($this->is_writable($path2)) {
- $tmpFile = $this->toTmpFile($path1);
- $result = $this->fromTmpFile($tmpFile, $path2);
- return $result;
- } else {
- return false;
- }
+ // Copy the file if CREATE permission is granted
+ if (($source = $this->getSourcePath($path1)) && $this->isCreatable(dirname($path2))) {
+ $source = $this->fopen($path1, 'r');
+ $target = $this->fopen($path2, 'w');
+ return OC_Helper::streamCopy($source, $target);
}
+ return true;
}
-
+
public function fopen($path, $mode) {
- $source = $this->getSource($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
switch ($mode) {
case 'r+':
case 'rb+':
@@ -382,12 +360,12 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
case 'xb':
case 'a':
case 'ab':
- if (!$this->is_writable($path)) {
+ if (!$this->isUpdatable($path)) {
return false;
}
}
$info = array(
- 'target' => $this->datadir.$path,
+ 'target' => $this->sharedFolder.$path,
'source' => $source,
'mode' => $mode,
);
@@ -395,95 +373,46 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
$storage = OC_Filesystem::getStorage($source);
return $storage->fopen($this->getInternalPath($source), $mode);
}
+ return false;
}
-
- public function toTmpFile($path) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->toTmpFile($this->getInternalPath($source));
- }
- }
-
- public function fromTmpFile($tmpFile, $path) {
- if ($this->is_writable($path)) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- $result = $storage->fromTmpFile($tmpFile, $this->getInternalPath($source));
- return $result;
- }
- } else {
- return false;
- }
- }
-
+
public function getMimeType($path) {
- if ($path == "" || $path == "/") {
+ if ($path == '' || $path == '/') {
return 'httpd/unix-directory';
}
- $source = $this->getSource($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->getMimeType($this->getInternalPath($source));
}
+ return false;
}
-
- public function hash($type, $path, $raw = false) {
- $source = $this->getSource($path);
- if ($source) {
- $storage = OC_Filesystem::getStorage($source);
- return $storage->hash($type, $this->getInternalPath($source), $raw);
- }
- }
-
+
public function free_space($path) {
- $source = $this->getSource($path);
+ $source = $this->getSourcePath($path);
if ($source) {
$storage = OC_Filesystem::getStorage($source);
return $storage->free_space($this->getInternalPath($source));
}
}
-
- public function search($query) {
- return $this->searchInDir($query);
- }
-
- protected function searchInDir($query, $path = "") {
- $files = array();
- if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- if ($filename != "." && $filename != "..") {
- if (strstr(strtolower($filename), strtolower($query))) {
- $files[] = $path."/".$filename;
- }
- if ($this->is_dir($path."/".$filename)) {
- $files = array_merge($files, $this->searchInDir($query, $path."/".$filename));
- }
- }
- }
- }
- return $files;
- }
public function getLocalFile($path) {
- $source = $this->getSource($path);
- if ($source) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
return $storage->getLocalFile($this->getInternalPath($source));
}
+ return false;
}
- public function touch($path, $mtime=null){
- $source = $this->getSource($path);
- if ($source) {
+ public function touch($path, $mtime = null) {
+ if ($source = $this->getSourcePath($path)) {
$storage = OC_Filesystem::getStorage($source);
- return $storage->touch($this->getInternalPath($source),$mtime);
+ return $storage->touch($this->getInternalPath($source), $mtime);
}
+ return false;
}
public static function setup($options) {
$user_dir = $options['user_dir'];
- OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => $user_dir.'/Shared'), $user_dir.'/Shared/');
+ OC_Filesystem::mount('OC_Filestorage_Shared', array('sharedFolder' => '/Shared'), $user_dir.'/Shared/');
}
/**
@@ -493,6 +422,6 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common {
*/
public function hasUpdated($path,$time){
//TODO
- return $this->filemtime($path)>$time;
+ return false;
}
}
diff --git a/apps/files_sharing/templates/get.php b/apps/files_sharing/templates/get.php
new file mode 100755
index 00000000000..57275f07a3d
--- /dev/null
+++ b/apps/files_sharing/templates/get.php
@@ -0,0 +1,11 @@
+<table>
+ <thead>
+ <tr>
+ <th id="headerSize"><?php echo $l->t( 'Size' ); ?></th>
+ <th id="headerDate"><span id="modified"><?php echo $l->t( 'Modified' ); ?></span><span class="selectedActions"><a href="" class="delete"><?php echo $l->t('Delete all')?> <img class="svg" alt="<?php echo $l->t('Delete')?>" src="<?php echo OCP\image_path("core", "actions/delete.svg"); ?>" /></a></span></th>
+ </tr>
+ </thead>
+ <tbody id="fileList" data-readonly="<?php echo $_['readonly'];?>">
+ <?php echo($_['fileList']); ?>
+ </tbody>
+</table> \ No newline at end of file
diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js
index 70bb74a9101..3784ea1032f 100644
--- a/apps/files_texteditor/js/editor.js
+++ b/apps/files_texteditor/js/editor.js
@@ -222,9 +222,17 @@ function showFileEditor(dir,filename){
}
});
// Add the ctrl+s event
- window.aceEditor.commands.addCommand({ name: "save", bindKey: { win: "Ctrl-S", mac: "Command-S", sender: "editor" }, exec: function(){
+ window.aceEditor.commands.addCommand({
+ name: "save",
+ bindKey: {
+ win: "Ctrl-S",
+ mac: "Command-S",
+ sender: "editor"
+ },
+ exec: function(){
doFileSave();
- } });
+ }
+ });
});
} else {
// Failed to get the file.
@@ -297,11 +305,11 @@ $(window).resize(function() {
var is_editor_shown = false;
$(document).ready(function(){
if(typeof FileActions!=='undefined'){
- FileActions.register('text','Edit','',function(filename){
+ FileActions.register('text','Edit', FileActions.PERMISSION_READ, '',function(filename){
showFileEditor($('#dir').val(),filename);
});
FileActions.setDefault('text','Edit');
- FileActions.register('application/xml','Edit','',function(filename){
+ FileActions.register('application/xml','Edit', FileActions.PERMISSION_READ, '',function(filename){
showFileEditor($('#dir').val(),filename);
});
FileActions.setDefault('application/xml','Edit');
diff --git a/apps/files_versions/appinfo/api.php b/apps/files_versions/appinfo/api.php
new file mode 100644
index 00000000000..a7386bc2c9f
--- /dev/null
+++ b/apps/files_versions/appinfo/api.php
@@ -0,0 +1,36 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+return array(
+ 'list' => array('method' => 'GET', 'class' => 'Storage', 'function' => 'getVersions',
+ 'parameters' => array(
+ 'file' => array('required' => true, 'type' => 'string')
+ )
+ ),
+ 'revert' => array('method' => 'POST', 'class' => 'Storage', 'function' => 'rollback',
+ 'parameters' => array(
+ 'file' => array('required' => true, 'type' => 'string'),
+ 'time' => array('required' => true, 'type' => 'int')
+ )
+ )
+);
+
+?> \ No newline at end of file
diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js
index a090fde446e..c5c1553f1a8 100644
--- a/apps/files_versions/js/versions.js
+++ b/apps/files_versions/js/versions.js
@@ -11,7 +11,7 @@ $(document).ready(function() {
$(document).ready(function(){
if (typeof FileActions !== 'undefined') {
// Add history button to files/index.php
- FileActions.register('file','History',function(){return OC.imagePath('core','actions/history')},function(filename){
+ FileActions.register('file','History', FileActions.PERMISSION_UPDATE, function(){return OC.imagePath('core','actions/history')},function(filename){
if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback
diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php
index df3b68ef736..9103f66441d 100644
--- a/apps/gallery/appinfo/app.php
+++ b/apps/gallery/appinfo/app.php
@@ -28,6 +28,9 @@ OC::$CLASSPATH['OC_Gallery_Sharing'] = 'gallery/lib/sharing.php';
OC::$CLASSPATH['OC_Gallery_Hooks_Handlers'] = 'gallery/lib/hooks_handlers.php';
OC::$CLASSPATH['Pictures_Managers'] = 'gallery/lib/managers.php';
OC::$CLASSPATH['Pictures_Tiles'] = 'gallery/lib/tiles.php';
+OC::$CLASSPATH['OC_Share_Backend_Photo'] = 'gallery/lib/share.php';
+
+// OCP\Share::registerBackend('photo', new OC_Share_Backend_Photo());
$l = OC_L10N::get('gallery');
diff --git a/apps/gallery/lib/share.php b/apps/gallery/lib/share.php
new file mode 100644
index 00000000000..d6c5f40d492
--- /dev/null
+++ b/apps/gallery/lib/share.php
@@ -0,0 +1,42 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+abstract class OC_Share_Photo_Backend implements OCP\Share_Backend {
+
+ public $dependsOn = 'file';
+ public $supportedFileExtensions = array('jpg', 'png', 'gif');
+
+ public function getSource($item, $uid) {
+ return array('item' => 'blah.jpg', 'file' => $item);
+ }
+
+ public function generateTarget($item, $uid, $exclude = null) {
+ // TODO Make sure target path doesn't exist already
+ return $item;
+ }
+
+ public function formatItems($items, $format, $parameters = null) {
+
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/apps/media/js/loader.js b/apps/media/js/loader.js
index 393f8ba914e..ffe9c1cdd61 100644
--- a/apps/media/js/loader.js
+++ b/apps/media/js/loader.js
@@ -45,8 +45,8 @@ $(document).ready(function() {
// FileActions.register('application/ogg','Add to playlist','',addAudio);
if(typeof FileActions!=='undefined'){
- FileActions.register('audio','Play','',playAudio);
- FileActions.register('application/ogg','','Play',playAudio);
+ FileActions.register('audio','Play', FileActions.PERMISSION_READ, '',playAudio);
+ FileActions.register('application/ogg', FileActions.PERMISSION_READ, '','Play',playAudio);
FileActions.setDefault('audio','Play');
FileActions.setDefault('application/ogg','Play');
}
diff --git a/apps/media/lib/share/album.php b/apps/media/lib/share/album.php
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/apps/media/lib/share/album.php
diff --git a/apps/media/lib/share/artist.php b/apps/media/lib/share/artist.php
new file mode 100644
index 00000000000..7218fa1a279
--- /dev/null
+++ b/apps/media/lib/share/artist.php
@@ -0,0 +1,65 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Artist extends OCP\Share_Backend {
+
+ public function getSource($item, $uid) {
+ $query = OCP\DB::prepare('SELECT artist_id FROM *PREFIX*media_artists WHERE artist_id = ? AND song_user = ?');
+ $result = $query->execute(array($item, $uid))->fetchRow();
+ if (is_array($result)) {
+ return array('item' => $item, 'file' => $result['song_path']);
+ }
+ return false;
+ }
+
+ public function generateTarget($item, $uid, $exclude = null) {
+ // TODO Make sure target path doesn't exist already
+ return '/Shared'.$item;
+ }
+
+ public function formatItems($items, $format) {
+ $ids = array();
+ foreach ($items as $id => $info) {
+ $ids[] = $id;
+ }
+ $ids = "'".implode("','", $ids)."'";
+ switch ($format) {
+ case self::FORMAT_SOURCE_PATH:
+ $query = OCP\DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
+ return $query->execute()->fetchAll();
+ case self::FORMAT_FILE_APP:
+ $query = OCP\DB::prepare('SELECT id, path, name, ctime, mtime, mimetype, size, encrypted, versioned, writable FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
+ $result = $query->execute();
+ $files = array();
+ while ($file = $result->fetchRow()) {
+ // Set target path
+ $file['path'] = $items[$file['id']]['item_target'];
+ $file['name'] = basename($file['path']);
+ // TODO Set permissions: $file['writable']
+ $files[] = $file;
+ }
+ return $files;
+ }
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/apps/media/lib/share/song.php b/apps/media/lib/share/song.php
new file mode 100644
index 00000000000..fc69975f353
--- /dev/null
+++ b/apps/media/lib/share/song.php
@@ -0,0 +1,65 @@
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.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 <http://www.gnu.org/licenses/>.
+*/
+
+class OC_Share_Backend_Song extends OCP\Share_Backend {
+
+ public function getSource($item, $uid) {
+ $query = OCP\DB::prepare('SELECT song_path FROM *PREFIX*media_songs WHERE song_id = ? AND song_user = ?');
+ $result = $query->execute(array($item, $uid))->fetchRow();
+ if (is_array($result)) {
+ return array('item' => $item, 'file' => $result['song_path']);
+ }
+ return false;
+ }
+
+ public function generateTarget($item, $uid, $exclude = null) {
+ // TODO Make sure target path doesn't exist already
+ return '/Shared'.$item;
+ }
+
+ public function formatItems($items, $format) {
+ $ids = array();
+ foreach ($items as $id => $info) {
+ $ids[] = $id;
+ }
+ $ids = "'".implode("','", $ids)."'";
+ switch ($format) {
+ case self::FORMAT_SOURCE_PATH:
+ $query = OCP\DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
+ return $query->execute()->fetchAll();
+ case self::FORMAT_FILE_APP:
+ $query = OCP\DB::prepare('SELECT id, path, name, ctime, mtime, mimetype, size, encrypted, versioned, writable FROM *PREFIX*fscache WHERE id IN ('.$ids.')');
+ $result = $query->execute();
+ $files = array();
+ while ($file = $result->fetchRow()) {
+ // Set target path
+ $file['path'] = $items[$file['id']]['item_target'];
+ $file['name'] = basename($file['path']);
+ // TODO Set permissions: $file['writable']
+ $files[] = $file;
+ }
+ return $files;
+ }
+ }
+
+}
+
+?> \ No newline at end of file