summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorGeorg Ehrke <georg@ownCloud.com>2013-04-22 16:19:16 +0200
committerGeorg Ehrke <georg@ownCloud.com>2013-04-22 16:19:16 +0200
commitec3e97f28f96d06434eb1a9f480f5fe1b3e489f8 (patch)
treeb830fd8c7ef58ec752da15ca30fead57b8b30eee /lib/public
parenteb27c0b2a84da44f8e42f7e4aca0102c969eb195 (diff)
parent03c7a52bc595bbc9fe1f155da699994f93b84131 (diff)
downloadnextcloud-server-ec3e97f28f96d06434eb1a9f480f5fe1b3e489f8.tar.gz
nextcloud-server-ec3e97f28f96d06434eb1a9f480f5fe1b3e489f8.zip
Merge branch 'master' into oc_preview
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/api.php45
-rw-r--r--lib/public/app.php7
-rw-r--r--lib/public/config.php3
-rw-r--r--lib/public/constants.php1
-rw-r--r--lib/public/contacts.php187
-rw-r--r--lib/public/db.php27
-rw-r--r--lib/public/files.php21
-rw-r--r--lib/public/iaddressbook.php74
-rw-r--r--lib/public/response.php32
-rw-r--r--lib/public/share.php571
-rw-r--r--lib/public/template.php3
-rw-r--r--lib/public/user.php31
-rw-r--r--lib/public/util.php207
13 files changed, 950 insertions, 259 deletions
diff --git a/lib/public/api.php b/lib/public/api.php
new file mode 100644
index 00000000000..d94b68e908a
--- /dev/null
+++ b/lib/public/api.php
@@ -0,0 +1,45 @@
+<?php
+/**
+* ownCloud
+*
+* @author Tom Needham
+* @copyright 2012 Tom Needham tom@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/>.
+*
+*/
+
+namespace OCP;
+
+/**
+ * This class provides functions to manage apps in ownCloud
+ */
+class API {
+
+ /**
+ * registers an api call
+ * @param string $method the http method
+ * @param string $url the url to match
+ * @param callable $action the function to run
+ * @param string $app the id of the app registering the call
+ * @param int $authLevel the level of authentication required for the call (See OC_API constants)
+ * @param array $defaults
+ * @param array $requirements
+ */
+ public static function register($method, $url, $action, $app, $authLevel = OC_API::USER_AUTH,
+ $defaults = array(), $requirements = array()){
+ \OC_API::register($method, $url, $action, $app, $authLevel, $defaults, $requirements);
+ }
+
+}
diff --git a/lib/public/app.php b/lib/public/app.php
index 809a656f17f..a1ecf524cc8 100644
--- a/lib/public/app.php
+++ b/lib/public/app.php
@@ -89,7 +89,7 @@ class App {
* @param $page string page to be included
*/
public static function registerPersonal( $app, $page ) {
- return \OC_App::registerPersonal( $app, $page );
+ \OC_App::registerPersonal( $app, $page );
}
/**
@@ -98,7 +98,7 @@ class App {
* @param $page string page to be included
*/
public static function registerAdmin( $app, $page ) {
- return \OC_App::registerAdmin( $app, $page );
+ \OC_App::registerAdmin( $app, $page );
}
/**
@@ -125,10 +125,9 @@ class App {
/**
* @brief Check if the app is enabled, redirects to home if not
* @param $app app
- * @returns true/false
*/
public static function checkAppEnabled( $app ) {
- return \OC_Util::checkAppEnabled( $app );
+ \OC_Util::checkAppEnabled( $app );
}
/**
diff --git a/lib/public/config.php b/lib/public/config.php
index 1f163d52617..8076d640b49 100644
--- a/lib/public/config.php
+++ b/lib/public/config.php
@@ -35,7 +35,8 @@
namespace OCP;
/**
- * This class provides functions to read and write configuration data. configuration can be on a system, application or user level
+ * This class provides functions to read and write configuration data.
+ * configuration can be on a system, application or user level
*/
class Config {
/**
diff --git a/lib/public/constants.php b/lib/public/constants.php
index bc979c9031f..1495c620dc9 100644
--- a/lib/public/constants.php
+++ b/lib/public/constants.php
@@ -35,4 +35,3 @@ const PERMISSION_UPDATE = 2;
const PERMISSION_DELETE = 8;
const PERMISSION_SHARE = 16;
const PERMISSION_ALL = 31;
-
diff --git a/lib/public/contacts.php b/lib/public/contacts.php
new file mode 100644
index 00000000000..88d812e735a
--- /dev/null
+++ b/lib/public/contacts.php
@@ -0,0 +1,187 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Thomas Müller
+ * @copyright 2012 Thomas Müller thomas.mueller@tmit.eu
+ *
+ * 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/>.
+ *
+ */
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * Contacts Class
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP {
+
+ /**
+ * This class provides access to the contacts app. Use this class exclusively if you want to access contacts.
+ *
+ * Contacts in general will be expressed as an array of key-value-pairs.
+ * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1
+ *
+ * Proposed workflow for working with contacts:
+ * - search for the contacts
+ * - manipulate the results array
+ * - createOrUpdate will save the given contacts overwriting the existing data
+ *
+ * For updating it is mandatory to keep the id.
+ * Without an id a new contact will be created.
+ *
+ */
+ class Contacts {
+
+ /**
+ * This function is used to search and find contacts within the users address books.
+ * In case $pattern is empty all contacts will be returned.
+ *
+ * Example:
+ * Following function shows how to search for contacts for the name and the email address.
+ *
+ * public static function getMatchingRecipient($term) {
+ * // The API is not active -> nothing to do
+ * if (!\OCP\Contacts::isEnabled()) {
+ * return array();
+ * }
+ *
+ * $result = \OCP\Contacts::search($term, array('FN', 'EMAIL'));
+ * $receivers = array();
+ * foreach ($result as $r) {
+ * $id = $r['id'];
+ * $fn = $r['FN'];
+ * $email = $r['EMAIL'];
+ * if (!is_array($email)) {
+ * $email = array($email);
+ * }
+ *
+ * // loop through all email addresses of this contact
+ * foreach ($email as $e) {
+ * $displayName = $fn . " <$e>";
+ * $receivers[] = array(
+ * 'id' => $id,
+ * 'label' => $displayName,
+ * 'value' => $displayName);
+ * }
+ * }
+ *
+ * return $receivers;
+ * }
+ *
+ *
+ * @param string $pattern which should match within the $searchProperties
+ * @param array $searchProperties defines the properties within the query pattern should match
+ * @param array $options - for future use. One should always have options!
+ * @return array of contacts which are arrays of key-value-pairs
+ */
+ public static function search($pattern, $searchProperties = array(), $options = array()) {
+ $result = array();
+ foreach(self::$address_books as $address_book) {
+ $r = $address_book->search($pattern, $searchProperties, $options);
+ $result = array_merge($result, $r);
+ }
+
+ return $result;
+ }
+
+ /**
+ * This function can be used to delete the contact identified by the given id
+ *
+ * @param object $id the unique identifier to a contact
+ * @param $address_book_key
+ * @return bool successful or not
+ */
+ public static function delete($id, $address_book_key) {
+ if (!array_key_exists($address_book_key, self::$address_books))
+ return null;
+
+ $address_book = self::$address_books[$address_book_key];
+ if ($address_book->getPermissions() & \OCP\PERMISSION_DELETE)
+ return null;
+
+ return $address_book->delete($id);
+ }
+
+ /**
+ * This function is used to create a new contact if 'id' is not given or not present.
+ * Otherwise the contact will be updated by replacing the entire data set.
+ *
+ * @param array $properties this array if key-value-pairs defines a contact
+ * @param $address_book_key string to identify the address book in which the contact shall be created or updated
+ * @return array representing the contact just created or updated
+ */
+ public static function createOrUpdate($properties, $address_book_key) {
+
+ if (!array_key_exists($address_book_key, self::$address_books))
+ return null;
+
+ $address_book = self::$address_books[$address_book_key];
+ if ($address_book->getPermissions() & \OCP\PERMISSION_CREATE)
+ return null;
+
+ return $address_book->createOrUpdate($properties);
+ }
+
+ /**
+ * Check if contacts are available (e.g. contacts app enabled)
+ *
+ * @return bool true if enabled, false if not
+ */
+ public static function isEnabled() {
+ return !empty(self::$address_books);
+ }
+
+ /**
+ * @param \OCP\IAddressBook $address_book
+ */
+ public static function registerAddressBook(\OCP\IAddressBook $address_book) {
+ self::$address_books[$address_book->getKey()] = $address_book;
+ }
+
+ /**
+ * @param \OCP\IAddressBook $address_book
+ */
+ public static function unregisterAddressBook(\OCP\IAddressBook $address_book) {
+ unset(self::$address_books[$address_book->getKey()]);
+ }
+
+ /**
+ * @return array
+ */
+ public static function getAddressBooks() {
+ $result = array();
+ foreach(self::$address_books as $address_book) {
+ $result[$address_book->getKey()] = $address_book->getDisplayName();
+ }
+
+ return $result;
+ }
+
+ /**
+ * removes all registered address book instances
+ */
+ public static function clear() {
+ self::$address_books = array();
+ }
+
+ /**
+ * @var \OCP\IAddressBook[] which holds all registered address books
+ */
+ private static $address_books = array();
+ }
+}
diff --git a/lib/public/db.php b/lib/public/db.php
index d2484b6eb83..932e79d9ef1 100644
--- a/lib/public/db.php
+++ b/lib/public/db.php
@@ -36,8 +36,8 @@ namespace OCP;
class DB {
/**
* @brief Prepare a SQL query
- * @param $query Query string
- * @returns prepared SQL query
+ * @param string $query Query string
+ * @return \MDB2_Statement_Common prepared SQL query
*
* SQL query via MDB2 prepare(), needs to be execute()'d!
*/
@@ -46,9 +46,30 @@ class DB {
}
/**
+ * @brief Insert a row if a matching row doesn't exists.
+ * @param $table string The table name (will replace *PREFIX*) to perform the replace on.
+ * @param $input array
+ *
+ * The input array if in the form:
+ *
+ * array ( 'id' => array ( 'value' => 6,
+ * 'key' => true
+ * ),
+ * 'name' => array ('value' => 'Stoyan'),
+ * 'family' => array ('value' => 'Stefanov'),
+ * 'birth_date' => array ('value' => '1975-06-20')
+ * );
+ * @return bool
+ *
+ */
+ public static function insertIfNotExist($table, $input) {
+ return(\OC_DB::insertIfNotExist($table, $input));
+ }
+
+ /**
* @brief gets last value of autoincrement
* @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix
- * @returns id
+ * @return int
*
* MDB2 lastInsertID()
*
diff --git a/lib/public/files.php b/lib/public/files.php
index 90889c59ad8..4975bbb7dfa 100644
--- a/lib/public/files.php
+++ b/lib/public/files.php
@@ -31,16 +31,18 @@
namespace OCP;
/**
- * This class provides access to the internal filesystem abstraction layer. Use this class exlusively if you want to access files
+ * This class provides access to the internal filesystem abstraction layer. Use
+ * this class exlusively if you want to access files
*/
class Files {
/**
* @brief Recusive deletion of folders
* @param string $dir path to the folder
*
+ * @return bool
*/
static function rmdirr( $dir ) {
- \OC_Helper::rmdirr( $dir );
+ return \OC_Helper::rmdirr( $dir );
}
/**
@@ -54,13 +56,24 @@ class Files {
}
/**
+ * search for files by mimetype
+ *
+ * @param string $query
+ * @return array
+ */
+ public function searchByMime($mimetype) {
+ return(\OC\Files\Filesystem::searchByMime( $mimetype ));
+ }
+
+ /**
* copy the contents of one stream to another
* @param resource source
* @param resource target
* @return int the number of bytes copied
*/
public static function streamCopy( $source, $target ) {
- return(\OC_Helper::streamCopy( $source, $target ));
+ list($count, $result) = \OC_Helper::streamCopy( $source, $target );
+ return $count;
}
/**
@@ -98,7 +111,7 @@ class Files {
/**
* @param string appid
* @param $app app
- * @return OC_FilesystemView
+ * @return \OC\Files\View
*/
public static function getStorage( $app ) {
return \OC_App::getStorage( $app );
diff --git a/lib/public/iaddressbook.php b/lib/public/iaddressbook.php
new file mode 100644
index 00000000000..77e8750d9da
--- /dev/null
+++ b/lib/public/iaddressbook.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Thomas Müller
+ * @copyright 2012 Thomas Müller thomas.mueller@tmit.eu
+ *
+ * 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/>.
+ *
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP {
+ interface IAddressBook {
+
+ /**
+ * @return string defining the technical unique key
+ */
+ public function getKey();
+
+ /**
+ * In comparison to getKey() this function returns a human readable (maybe translated) name
+ * @return mixed
+ */
+ public function getDisplayName();
+
+ /**
+ * @param string $pattern which should match within the $searchProperties
+ * @param array $searchProperties defines the properties within the query pattern should match
+ * @param array $options - for future use. One should always have options!
+ * @return array of contacts which are arrays of key-value-pairs
+ */
+ public function search($pattern, $searchProperties, $options);
+ // // dummy results
+ // return array(
+ // array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', 'GEO' => '37.386013;-122.082932'),
+ // array('id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => array('d@e.f', 'g@h.i')),
+ // );
+
+ /**
+ * @param array $properties this array if key-value-pairs defines a contact
+ * @return array representing the contact just created or updated
+ */
+ public function createOrUpdate($properties);
+ // // dummy
+ // return array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c',
+ // 'PHOTO' => 'VALUE=uri:http://www.abc.com/pub/photos/jqpublic.gif',
+ // 'ADR' => ';;123 Main Street;Any Town;CA;91921-1234'
+ // );
+
+ /**
+ * @return mixed
+ */
+ public function getPermissions();
+
+ /**
+ * @param object $id the unique identifier to a contact
+ * @return bool successful or not
+ */
+ public function delete($id);
+ }
+}
diff --git a/lib/public/response.php b/lib/public/response.php
index 95e67a85720..de0c3f25347 100644
--- a/lib/public/response.php
+++ b/lib/public/response.php
@@ -31,27 +31,27 @@
namespace OCP;
/**
- * This class provides convinient functions to send the correct http response headers
+ * This class provides convenient functions to send the correct http response headers
*/
class Response {
/**
* @brief Enable response caching by sending correct HTTP headers
- * @param $cache_time time to cache the response
+ * @param int $cache_time time to cache the response
* >0 cache time in seconds
* 0 and <0 enable default browser caching
* null cache indefinitly
*/
static public function enableCaching( $cache_time = null ) {
- return(\OC_Response::enableCaching( $cache_time ));
+ \OC_Response::enableCaching( $cache_time );
}
/**
* Checks and set Last-Modified header, when the request matches sends a
* 'not modified' response
- * @param $lastModified time when the reponse was last modified
+ * @param string $lastModified time when the reponse was last modified
*/
static public function setLastModifiedHeader( $lastModified ) {
- return(\OC_Response::setLastModifiedHeader( $lastModified ));
+ \OC_Response::setLastModifiedHeader( $lastModified );
}
/**
@@ -59,41 +59,41 @@ class Response {
* @see enableCaching with cache_time = 0
*/
static public function disableCaching() {
- return(\OC_Response::disableCaching());
+ \OC_Response::disableCaching();
}
/**
* Checks and set ETag header, when the request matches sends a
* 'not modified' response
- * @param $etag token to use for modification check
+ * @param string $etag token to use for modification check
*/
static public function setETagHeader( $etag ) {
- return(\OC_Response::setETagHeader( $etag ));
+ \OC_Response::setETagHeader( $etag );
}
/**
* @brief Send file as response, checking and setting caching headers
- * @param $filepath of file to send
+ * @param string $filepath of file to send
*/
static public function sendFile( $filepath ) {
- return(\OC_Response::sendFile( $filepath ));
+ \OC_Response::sendFile( $filepath );
}
/**
- * @brief Set reponse expire time
- * @param $expires date-time when the response expires
+ * @brief Set response expire time
+ * @param string|\DateTime $expires date-time when the response expires
* string for DateInterval from now
* DateTime object when to expire response
*/
static public function setExpiresHeader( $expires ) {
- return(\OC_Response::setExpiresHeader( $expires ));
+ \OC_Response::setExpiresHeader( $expires );
}
/**
* @brief Send redirect response
- * @param $location to redirect to
+ * @param string $location to redirect to
*/
static public function redirect( $location ) {
- return(\OC_Response::redirect( $location ));
+ \OC_Response::redirect( $location );
}
-} \ No newline at end of file
+}
diff --git a/lib/public/share.php b/lib/public/share.php
index dcb1b5c278e..4b337530be8 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -20,11 +20,6 @@
*/
namespace OCP;
-\OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\Share', 'post_deleteUser');
-\OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\Share', 'post_addToGroup');
-\OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\Share', 'post_removeFromGroup');
-\OC_Hook::connect('OC_User', 'post_deleteGroup', 'OCP\Share', 'post_deleteGroup');
-
/**
* This class provides the ability for apps to share their content between users.
* Apps must create a backend class that implements OCP\Share_Backend and register it with this class.
@@ -42,10 +37,17 @@ class Share {
const SHARE_TYPE_REMOTE = 6;
/** CRUDS permissions (Create, Read, Update, Delete, Share) using a bitmask
- * Construct permissions for share() and setPermissions with Or (|) e.g. Give user read and update permissions: PERMISSION_READ | PERMISSION_UPDATE
- * Check if permission is granted with And (&) e.g. Check if delete is granted: if ($permissions & PERMISSION_DELETE)
- * Remove permissions with And (&) and Not (~) e.g. Remove the update permission: $permissions &= ~PERMISSION_UPDATE
- * Apps are required to handle permissions on their own, this class only stores and manages the permissions of shares
+ * Construct permissions for share() and setPermissions with Or (|) e.g.
+ * Give user read and update permissions: PERMISSION_READ | PERMISSION_UPDATE
+ *
+ * Check if permission is granted with And (&) e.g. Check if delete is
+ * granted: if ($permissions & PERMISSION_DELETE)
+ *
+ * Remove permissions with And (&) and Not (~) e.g. Remove the update
+ * permission: $permissions &= ~PERMISSION_UPDATE
+ *
+ * Apps are required to handle permissions on their own, this class only
+ * stores and manages the permissions of shares
* @see lib/public/constants.php
*/
@@ -53,10 +55,13 @@ class Share {
const FORMAT_STATUSES = -2;
const FORMAT_SOURCES = -3;
+ const TOKEN_LENGTH = 32; // see db_structure.xml
+
private static $shareTypeUserAndGroups = -1;
private static $shareTypeGroupUserUnique = 2;
private static $backends = array();
private static $backendTypes = array();
+ private static $isResharingAllowed;
/**
* @brief Register a sharing backend class that implements OCP\Share_Backend for an item type
@@ -69,14 +74,21 @@ class Share {
public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
if (self::isEnabled()) {
if (!isset(self::$backendTypes[$itemType])) {
- self::$backendTypes[$itemType] = array('class' => $class, 'collectionOf' => $collectionOf, 'supportedFileExtensions' => $supportedFileExtensions);
+ self::$backendTypes[$itemType] = array(
+ 'class' => $class,
+ 'collectionOf' => $collectionOf,
+ 'supportedFileExtensions' => $supportedFileExtensions
+ );
if(count(self::$backendTypes) === 1) {
\OC_Util::addScript('core', 'share');
\OC_Util::addStyle('core', 'share');
}
return true;
}
- \OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN);
+ \OC_Log::write('OCP\Share',
+ 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class']
+ .' is already registered for '.$itemType,
+ \OC_Log::WARN);
}
return false;
}
@@ -102,8 +114,10 @@ class Share {
* @param int Number of items to return (optional) Returns all by default
* @return Return depends on format
*/
- public static function getItemsSharedWith($itemType, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false) {
- return self::getItems($itemType, null, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, $parameters, $limit, $includeCollections);
+ public static function getItemsSharedWith($itemType, $format = self::FORMAT_NONE,
+ $parameters = null, $limit = -1, $includeCollections = false) {
+ return self::getItems($itemType, null, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format,
+ $parameters, $limit, $includeCollections);
}
/**
@@ -113,8 +127,10 @@ class Share {
* @param int Format (optional) Format type must be defined by the backend
* @return Return depends on format
*/
- public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE, $parameters = null, $includeCollections = false) {
- return self::getItems($itemType, $itemTarget, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, $parameters, 1, $includeCollections);
+ public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE,
+ $parameters = null, $includeCollections = false) {
+ return self::getItems($itemType, $itemTarget, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format,
+ $parameters, 1, $includeCollections);
}
/**
@@ -124,8 +140,10 @@ class Share {
* @param int Format (optional) Format type must be defined by the backend
* @return Return depends on format
*/
- public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE, $parameters = null, $includeCollections = false) {
- return self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, $parameters, 1, $includeCollections, true);
+ public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE,
+ $parameters = null, $includeCollections = false) {
+ return self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format,
+ $parameters, 1, $includeCollections, true);
}
/**
@@ -136,7 +154,22 @@ class Share {
* @return Item
*/
public static function getItemSharedWithByLink($itemType, $itemSource, $uidOwner) {
- return self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1);
+ return self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE,
+ null, 1);
+ }
+
+ /**
+ * @brief Get the item shared by a token
+ * @param string token
+ * @return Item
+ */
+ public static function getShareByToken($token) {
+ $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1);
+ $result = $query->execute(array($token));
+ if (\OC_DB::isError($result)) {
+ \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result) . ', token=' . $token, \OC_Log::ERROR);
+ }
+ return $result->fetchRow();
}
/**
@@ -146,8 +179,10 @@ class Share {
* @param int Number of items to return (optional) Returns all by default
* @return Return depends on format
*/
- public static function getItemsShared($itemType, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false) {
- return self::getItems($itemType, null, null, null, \OC_User::getUser(), $format, $parameters, $limit, $includeCollections);
+ public static function getItemsShared($itemType, $format = self::FORMAT_NONE, $parameters = null,
+ $limit = -1, $includeCollections = false) {
+ return self::getItems($itemType, null, null, null, \OC_User::getUser(), $format,
+ $parameters, $limit, $includeCollections);
}
/**
@@ -157,8 +192,33 @@ class Share {
* @param int Format (optional) Format type must be defined by the backend
* @return Return depends on format
*/
- public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE, $parameters = null, $includeCollections = false) {
- return self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), $format, $parameters, -1, $includeCollections);
+ public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE,
+ $parameters = null, $includeCollections = false) {
+ return self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), $format,
+ $parameters, -1, $includeCollections);
+ }
+
+ /**
+ * Get all users an item is shared with
+ * @param string Item type
+ * @param string Item source
+ * @param string Owner
+ * @param bool Include collections
+ * @return Return array of users
+ */
+ public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false) {
+ $users = array();
+ $items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections);
+ if ($items) {
+ foreach ($items as $item) {
+ if ((int)$item['share_type'] === self::SHARE_TYPE_USER) {
+ $users[] = $item['share_with'];
+ } else if ((int)$item['share_type'] === self::SHARE_TYPE_GROUP) {
+ $users = array_merge($users, \OC_Group::usersInGroup($item['share_with']));
+ }
+ }
+ }
+ return $users;
}
/**
@@ -168,7 +228,7 @@ class Share {
* @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param string User or group the item is being shared with
* @param int CRUDS permissions
- * @return bool Returns true on success or false on failure
+ * @return bool|string Returns true on success or false on failure, Returns token on success for links
*/
public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions) {
$uidOwner = \OC_User::getUser();
@@ -188,14 +248,18 @@ class Share {
if ($sharingPolicy == 'groups_only') {
$inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
if (empty($inGroup)) {
- $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of';
+ $message = 'Sharing '.$itemSource.' failed, because the user '
+ .$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of';
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
}
}
// Check if the item source is already shared with the user, either from the same owner or a different user
- if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
- // Only allow the same share to occur again if it is the same owner and is not a user share, this use case is for increasing permissions for a specific user
+ if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups,
+ $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
+ // Only allow the same share to occur again if it is the same
+ // owner and is not a user share, this use case is for increasing
+ // permissions for a specific user
if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
$message = 'Sharing '.$itemSource.' failed, because this item is already shared with '.$shareWith;
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
@@ -209,14 +273,18 @@ class Share {
throw new \Exception($message);
}
if ($sharingPolicy == 'groups_only' && !\OC_Group::inGroup($uidOwner, $shareWith)) {
- $message = 'Sharing '.$itemSource.' failed, because '.$uidOwner.' is not a member of the group '.$shareWith;
+ $message = 'Sharing '.$itemSource.' failed, because '
+ .$uidOwner.' is not a member of the group '.$shareWith;
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
}
// Check if the item source is already shared with the group, either from the same owner or a different user
// The check for each user in the group is done inside the put() function
- if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
- // Only allow the same share to occur again if it is the same owner and is not a group share, this use case is for increasing permissions for a specific user
+ if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith,
+ null, self::FORMAT_NONE, null, 1, true, true)) {
+ // Only allow the same share to occur again if it is the same
+ // owner and is not a group share, this use case is for increasing
+ // permissions for a specific user
if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
$message = 'Sharing '.$itemSource.' failed, because this item is already shared with '.$shareWith;
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
@@ -230,23 +298,35 @@ class Share {
$shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner));
} else if ($shareType === self::SHARE_TYPE_LINK) {
if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') {
- if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) {
- // If password is set delete the old link
- if (isset($shareWith)) {
- self::delete($checkExists['id']);
- } else {
- $message = 'Sharing '.$itemSource.' failed, because this item is already shared with a link';
- \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
- throw new \Exception($message);
- }
+ // when updating a link share
+ if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null,
+ $uidOwner, self::FORMAT_NONE, null, 1)) {
+ // remember old token
+ $oldToken = $checkExists['token'];
+ //delete the old share
+ self::delete($checkExists['id']);
}
+
// Generate hash of password - same method as user passwords
if (isset($shareWith)) {
$forcePortable = (CRYPT_BLOWFISH != 1);
$hasher = new \PasswordHash(8, $forcePortable);
$shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', ''));
}
- return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions);
+
+ // Generate token
+ if (isset($oldToken)) {
+ $token = $oldToken;
+ } else {
+ $token = \OC_Util::generate_random_bytes(self::TOKEN_LENGTH);
+ }
+ $result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions,
+ null, $token);
+ if ($result) {
+ return $token;
+ } else {
+ return false;
+ }
}
$message = 'Sharing '.$itemSource.' failed, because sharing with links is not allowed';
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
@@ -279,34 +359,36 @@ class Share {
throw new \Exception($message);
}
// If the item is a folder, scan through the folder looking for equivalent item types
- if ($itemType == 'folder') {
- $parentFolder = self::put('folder', $itemSource, $shareType, $shareWith, $uidOwner, $permissions, true);
- if ($parentFolder && $files = \OC_Files::getDirectoryContent($itemSource)) {
- for ($i = 0; $i < count($files); $i++) {
- $name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource));
- if ($files[$i]['mimetype'] == 'httpd/unix-directory' && $children = \OC_Files::getDirectoryContent($name, '/')) {
- // Continue scanning into child folders
- array_push($files, $children);
- } else {
- // Check file extension for an equivalent item type to convert to
- $extension = strtolower(substr($itemSource, strrpos($itemSource, '.') + 1));
- foreach (self::$backends as $type => $backend) {
- if (isset($backend->dependsOn) && $backend->dependsOn == 'file' && isset($backend->supportedFileExtensions) && in_array($extension, $backend->supportedFileExtensions)) {
- $itemType = $type;
- break;
- }
- }
- // Pass on to put() to check if this item should be converted, the item won't be inserted into the database unless it can be converted
- self::put($itemType, $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder);
- }
- }
- return true;
- }
- return false;
- } else {
+// if ($itemType == 'folder') {
+// $parentFolder = self::put('folder', $itemSource, $shareType, $shareWith, $uidOwner, $permissions, true);
+// if ($parentFolder && $files = \OC\Files\Filesystem::getDirectoryContent($itemSource)) {
+// for ($i = 0; $i < count($files); $i++) {
+// $name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource));
+// if ($files[$i]['mimetype'] == 'httpd/unix-directory'
+// && $children = \OC\Files\Filesystem::getDirectoryContent($name, '/')
+// ) {
+// // Continue scanning into child folders
+// array_push($files, $children);
+// } else {
+// // Check file extension for an equivalent item type to convert to
+// $extension = strtolower(substr($itemSource, strrpos($itemSource, '.') + 1));
+// foreach (self::$backends as $type => $backend) {
+// if (isset($backend->dependsOn) && $backend->dependsOn == 'file' && isset($backend->supportedFileExtensions) && in_array($extension, $backend->supportedFileExtensions)) {
+// $itemType = $type;
+// break;
+// }
+// }
+// // Pass on to put() to check if this item should be converted, the item won't be inserted into the database unless it can be converted
+// self::put($itemType, $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder);
+// }
+// }
+// return true;
+// }
+// return false;
+// } else {
// Put the item into the database
return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions);
- }
+// }
}
/**
@@ -318,7 +400,16 @@ class Share {
* @return Returns true on success or false on failure
*/
public static function unshare($itemType, $itemSource, $shareType, $shareWith) {
- if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(), self::FORMAT_NONE, null, 1)) {
+ if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(),
+ self::FORMAT_NONE, null, 1)) {
+ // Pass all the vars we have for now, they may be useful
+ \OC_Hook::emit('OCP\Share', 'pre_unshare', array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'fileSource' => $item['file_source'],
+ 'shareType' => $shareType,
+ 'shareWith' => $shareWith,
+ ));
self::delete($item['id']);
return true;
}
@@ -333,6 +424,12 @@ class Share {
*/
public static function unshareAll($itemType, $itemSource) {
if ($shares = self::getItemShared($itemType, $itemSource)) {
+ // Pass all the vars we have for now, they may be useful
+ \OC_Hook::emit('OCP\Share', 'pre_unshareAll', array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'shares' => $shares
+ ));
foreach ($shares as $share) {
self::delete($share['id']);
}
@@ -353,9 +450,16 @@ class Share {
public static function unshareFromSelf($itemType, $itemTarget) {
if ($item = self::getItemSharedWith($itemType, $itemTarget)) {
if ((int)$item['share_type'] === self::SHARE_TYPE_GROUP) {
- // Insert an extra row for the group share and set permission to 0 to prevent it from showing up for the user
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
- $query->execute(array($item['item_type'], $item['item_source'], $item['item_target'], $item['id'], self::$shareTypeGroupUserUnique, \OC_User::getUser(), $item['uid_owner'], 0, $item['stime'], $item['file_source'], $item['file_target']));
+ // Insert an extra row for the group share and set permission
+ // to 0 to prevent it from showing up for the user
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share`'
+ .' (`item_type`, `item_source`, `item_target`, `parent`, `share_type`,'
+ .' `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`)'
+ .' VALUES (?,?,?,?,?,?,?,?,?,?,?)');
+ $query->execute(array($item['item_type'], $item['item_source'], $item['item_target'],
+ $item['id'], self::$shareTypeGroupUserUnique,
+ \OC_User::getUser(), $item['uid_owner'], 0, $item['stime'], $item['file_source'],
+ $item['file_target']));
\OC_DB::insertid('*PREFIX*share');
// Delete all reshares by this user of the group share
self::delete($item['id'], true, \OC_User::getUser());
@@ -382,13 +486,16 @@ class Share {
* @return Returns true on success or false on failure
*/
public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
- if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) {
- // Check if this item is a reshare and verify that the permissions granted don't exceed the parent shared item
+ if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith,
+ \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) {
+ // Check if this item is a reshare and verify that the permissions
+ // granted don't exceed the parent shared item
if (isset($item['parent'])) {
$query = \OC_DB::prepare('SELECT `permissions` FROM `*PREFIX*share` WHERE `id` = ?', 1);
$result = $query->execute(array($item['parent']))->fetchRow();
if (~(int)$result['permissions'] & $permissions) {
- $message = 'Setting permissions for '.$itemSource.' failed, because the permissions exceed permissions granted to '.\OC_User::getUser();
+ $message = 'Setting permissions for '.$itemSource.' failed,'
+ .' because the permissions exceed permissions granted to '.\OC_User::getUser();
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
}
@@ -405,9 +512,11 @@ class Share {
$parents = array($item['id']);
while (!empty($parents)) {
$parents = "'".implode("','", $parents)."'";
- $query = \OC_DB::prepare('SELECT `id`, `permissions` FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.')');
+ $query = \OC_DB::prepare('SELECT `id`, `permissions` FROM `*PREFIX*share`'
+ .' WHERE `parent` IN ('.$parents.')');
$result = $query->execute();
- // Reset parents array, only go through loop again if items are found that need permissions removed
+ // Reset parents array, only go through loop again if
+ // items are found that need permissions removed
$parents = array();
while ($item = $result->fetchRow()) {
// Check if permissions need to be removed
@@ -421,7 +530,8 @@ class Share {
// Remove the permissions for all reshares of this item
if (!empty($ids)) {
$ids = "'".implode("','", $ids)."'";
- $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `permissions` = `permissions` & ? WHERE `id` IN ('.$ids.')');
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `permissions` = `permissions` & ?'
+ .' WHERE `id` IN ('.$ids.')');
$query->execute(array($permissions));
}
}
@@ -434,7 +544,8 @@ class Share {
}
public static function setExpirationDate($itemType, $itemSource, $date) {
- if ($items = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE, null, -1, false)) {
+ if ($items = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(),
+ self::FORMAT_NONE, null, -1, false)) {
if (!empty($items)) {
if ($date == '') {
$date = null;
@@ -482,6 +593,24 @@ class Share {
}
/**
+ * @brief Check if resharing is allowed
+ * @return Returns true if allowed or false
+ *
+ * Resharing is allowed by default if not configured
+ *
+ */
+ private static function isResharingAllowed() {
+ if (!isset(self::$isResharingAllowed)) {
+ if (\OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes') == 'yes') {
+ self::$isResharingAllowed = true;
+ } else {
+ self::$isResharingAllowed = false;
+ }
+ }
+ return self::$isResharingAllowed;
+ }
+
+ /**
* @brief Get a list of collection item types for the specified item type
* @param string Item type
* @return array
@@ -493,10 +622,12 @@ class Share {
$collectionTypes[] = $type;
}
}
- if (!self::getBackend($itemType) instanceof Share_Backend_Collection) {
+ // TODO Add option for collections to be collection of themselves, only 'folder' does it now...
+ if (!self::getBackend($itemType) instanceof Share_Backend_Collection || $itemType != 'folder') {
unset($collectionTypes[0]);
}
- // Return array if collections were found or the item type is a collection itself - collections can be inside collections
+ // Return array if collections were found or the item type is a
+ // collection itself - collections can be inside collections
if (count($collectionTypes) > 0) {
return $collectionTypes;
}
@@ -519,7 +650,9 @@ class Share {
* See public functions getItem(s)... for parameter usage
*
*/
- private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false, $itemShareWithBySource = false) {
+ private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null,
+ $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1,
+ $includeCollections = false, $itemShareWithBySource = false) {
if (!self::isEnabled()) {
if ($limit == 1 || (isset($uidOwner) && isset($item))) {
return false;
@@ -528,10 +661,12 @@ class Share {
}
}
$backend = self::getBackend($itemType);
- // Get filesystem root to add it to the file target and remove from the file source, match file_source with the file cache
+ $collectionTypes = false;
+ // Get filesystem root to add it to the file target and remove from the
+ // file source, match file_source with the file cache
if ($itemType == 'file' || $itemType == 'folder') {
- $root = \OC_Filesystem::getRoot();
- $where = 'INNER JOIN `*PREFIX*fscache` ON `file_source` = `*PREFIX*fscache`.`id`';
+ $root = \OC\Files\Filesystem::getRoot();
+ $where = 'INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid`';
if (!isset($item)) {
$where .= ' WHERE `file_target` IS NOT NULL';
}
@@ -548,7 +683,7 @@ class Share {
$itemTypes = $collectionTypes;
}
$placeholders = join(',', array_fill(0, count($itemTypes), '?'));
- $where .= ' WHERE `item_type` IN ('.$placeholders.'))';
+ $where = ' WHERE `item_type` IN ('.$placeholders.'))';
$queryArgs = $itemTypes;
} else {
$where = ' WHERE `item_type` = ?';
@@ -617,7 +752,7 @@ class Share {
} else {
if ($itemType == 'file' || $itemType == 'folder') {
$where .= ' `file_target` = ?';
- $item = \OC_Filesystem::normalizePath($item);
+ $item = \OC\Files\Filesystem::normalizePath($item);
} else {
$where .= ' `item_target` = ?';
}
@@ -631,7 +766,8 @@ class Share {
}
if ($limit != -1 && !$includeCollections) {
if ($shareType == self::$shareTypeUserAndGroups) {
- // Make sure the unique user target is returned if it exists, unique targets should follow the group share in the database
+ // Make sure the unique user target is returned if it exists,
+ // unique targets should follow the group share in the database
// If the limit is not 1, the filtering can be done later
$where .= ' ORDER BY `*PREFIX*share`.`id` DESC';
}
@@ -647,23 +783,35 @@ class Share {
// TODO Optimize selects
if ($format == self::FORMAT_STATUSES) {
if ($itemType == 'file' || $itemType == 'folder') {
- $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `file_source`, `path`, `expiration`';
+ $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,'
+ .' `share_type`, `file_source`, `path`, `expiration`, `storage`';
} else {
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`';
}
} else {
if (isset($uidOwner)) {
if ($itemType == 'file' || $itemType == 'folder') {
- $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`, `expiration`';
+ $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,'
+ .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,'
+ .' `expiration`, `token`, `storage`';
} else {
- $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`, `stime`, `file_source`, `expiration`';
+ $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,'
+ .' `stime`, `file_source`, `expiration`, `token`';
}
} else {
if ($fileDependent) {
- if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT) {
- $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `expiration`, `name`, `ctime`, `mtime`, `mimetype`, `size`, `encrypted`, `versioned`, `writable`';
+ if (($itemType == 'file' || $itemType == 'folder')
+ && $format == \OC_Share_Backend_File::FORMAT_GET_FOLDER_CONTENTS
+ || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT
+ ) {
+ $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, '
+ .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, '
+ .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, '
+ .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`';
} else {
- $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`';
+ $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`,
+ `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`,
+ `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`';
}
} else {
$select = '*';
@@ -674,10 +822,14 @@ class Share {
$query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit);
$result = $query->execute($queryArgs);
if (\OC_DB::isError($result)) {
- \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result) . ', select=' . $select . ' where=' . $where, \OC_Log::ERROR);
+ \OC_Log::write('OCP\Share',
+ \OC_DB::getErrorMessage($result) . ', select=' . $select . ' where=' . $where,
+ \OC_Log::ERROR);
}
$items = array();
$targets = array();
+ $switchedItems = array();
+ $mounts = array();
while ($row = $result->fetchRow()) {
// Filter out duplicate group shares for users with unique targets
if ($row['share_type'] == self::$shareTypeGroupUserUnique && isset($items[$row['parent']])) {
@@ -691,7 +843,8 @@ class Share {
} else if (!isset($uidOwner)) {
// Check if the same target already exists
if (isset($targets[$row[$column]])) {
- // Check if the same owner shared with the user twice through a group and user share - this is allowed
+ // Check if the same owner shared with the user twice
+ // through a group and user share - this is allowed
$id = $targets[$row[$column]];
if ($items[$id]['uid_owner'] == $row['uid_owner']) {
// Switch to group share type to ensure resharing conditions aren't bypassed
@@ -699,9 +852,12 @@ class Share {
$items[$id]['share_type'] = self::SHARE_TYPE_GROUP;
$items[$id]['share_with'] = $row['share_with'];
}
- // Switch ids if sharing permission is granted on only one share to ensure correct parent is used if resharing
- if (~(int)$items[$id]['permissions'] & PERMISSION_SHARE && (int)$row['permissions'] & PERMISSION_SHARE) {
+ // Switch ids if sharing permission is granted on only
+ // one share to ensure correct parent is used if resharing
+ if (~(int)$items[$id]['permissions'] & PERMISSION_SHARE
+ && (int)$row['permissions'] & PERMISSION_SHARE) {
$items[$row['id']] = $items[$id];
+ $switchedItems[$id] = $row['id'];
unset($items[$id]);
$id = $row['id'];
}
@@ -718,7 +874,13 @@ class Share {
if (isset($row['parent'])) {
$row['path'] = '/Shared/'.basename($row['path']);
} else {
- $row['path'] = substr($row['path'], $root);
+ if (!isset($mounts[$row['storage']])) {
+ $mounts[$row['storage']] = \OC\Files\Mount::findByNumericId($row['storage']);
+ }
+ if ($mounts[$row['storage']]) {
+ $path = $mounts[$row['storage']]->getMountPoint().$row['path'];
+ $row['path'] = substr($path, $root);
+ }
}
}
if (isset($row['expiration'])) {
@@ -728,13 +890,25 @@ class Share {
continue;
}
}
+ // Check if resharing is allowed, if not remove share permission
+ if (isset($row['permissions']) && !self::isResharingAllowed()) {
+ $row['permissions'] &= ~PERMISSION_SHARE;
+ }
+ // Add display names to result
+ if ( isset($row['share_with']) && $row['share_with'] != '') {
+ $row['share_with_displayname'] = \OCP\User::getDisplayName($row['share_with']);
+ }
+ if ( isset($row['uid_owner']) && $row['uid_owner'] != '') {
+ $row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']);
+ }
+
$items[$row['id']] = $row;
}
if (!empty($items)) {
$collectionItems = array();
foreach ($items as &$row) {
// Return only the item instead of a 2-dimensional array
- if ($limit == 1 && $row['item_type'] == $itemType && $row[$column] == $item) {
+ if ($limit == 1 && $row[$column] == $item && ($row['item_type'] == $itemType || $itemType == 'file')) {
if ($format == self::FORMAT_NONE) {
return $row;
} else {
@@ -743,7 +917,8 @@ class Share {
}
// Check if this is a collection of the requested item type
if ($includeCollections && $collectionTypes && in_array($row['item_type'], $collectionTypes)) {
- if (($collectionBackend = self::getBackend($row['item_type'])) && $collectionBackend instanceof Share_Backend_Collection) {
+ if (($collectionBackend = self::getBackend($row['item_type']))
+ && $collectionBackend instanceof Share_Backend_Collection) {
// Collections can be inside collections, check if the item is a collection
if (isset($item) && $row['item_type'] == $itemType && $row[$column] == $item) {
$collectionItems[] = $row;
@@ -767,9 +942,11 @@ class Share {
if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') {
$childItem['file_source'] = $child['source'];
} else {
- $childItem['file_source'] = \OC_FileCache::getId($child['file_path']);
+ $meta = \OC\Files\Filesystem::getFileInfo($child['file_path']);
+ $childItem['file_source'] = $meta['fileid'];
}
- $childItem['file_target'] = \OC_Filesystem::normalizePath($child['file_path']);
+ $childItem['file_target'] =
+ \OC\Files\Filesystem::normalizePath($child['file_path']);
}
if (isset($item)) {
if ($childItem[$column] == $item) {
@@ -794,25 +971,31 @@ class Share {
}
}
// Remove collection item
- unset($items[$row['id']]);
+ $toRemove = $row['id'];
+ if (array_key_exists($toRemove, $switchedItems)) {
+ $toRemove = $switchedItems[$toRemove];
+ }
+ unset($items[$toRemove]);
}
}
if (!empty($collectionItems)) {
$items = array_merge($items, $collectionItems);
}
+ if (empty($items) && $limit == 1) {
+ return false;
+ }
if ($format == self::FORMAT_NONE) {
return $items;
} else if ($format == self::FORMAT_STATUSES) {
$statuses = array();
- // Switch column to path for files and folders, used for determining statuses inside of folders
- if ($itemType == 'file' || $itemType == 'folder') {
- $column = 'path';
- }
foreach ($items as $item) {
if ($item['share_type'] == self::SHARE_TYPE_LINK) {
- $statuses[$item[$column]] = true;
+ $statuses[$item[$column]]['link'] = true;
} else if (!isset($statuses[$item[$column]])) {
- $statuses[$item[$column]] = false;
+ $statuses[$item[$column]]['link'] = false;
+ }
+ if ($itemType == 'file' || $itemType == 'folder') {
+ $statuses[$item[$column]]['path'] = $item['path'];
}
}
return $statuses;
@@ -835,7 +1018,8 @@ class Share {
* @param bool|array Parent folder target (optional)
* @return bool Returns true on success or false on failure
*/
- private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null) {
+ private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
+ $permissions, $parentFolder = null, $token = null) {
$backend = self::getBackend($itemType);
// Check if this is a reshare
if ($checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true)) {
@@ -846,9 +1030,10 @@ class Share {
throw new \Exception($message);
}
// Check if share permissions is granted
- if ((int)$checkReshare['permissions'] & PERMISSION_SHARE) {
+ if (self::isResharingAllowed() && (int)$checkReshare['permissions'] & PERMISSION_SHARE) {
if (~(int)$checkReshare['permissions'] & $permissions) {
- $message = 'Sharing '.$itemSource.' failed, because the permissions exceed permissions granted to '.$uidOwner;
+ $message = 'Sharing '.$itemSource
+ .' failed, because the permissions exceed permissions granted to '.$uidOwner;
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
} else {
@@ -870,7 +1055,8 @@ class Share {
$suggestedItemTarget = null;
$suggestedFileTarget = null;
if (!$backend->isValidSource($itemSource, $uidOwner)) {
- $message = 'Sharing '.$itemSource.' failed, because the sharing backend for '.$itemType.' could not find its source';
+ $message = 'Sharing '.$itemSource.' failed, because the sharing backend for '
+ .$itemType.' could not find its source';
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
}
@@ -880,7 +1066,8 @@ class Share {
if ($itemType == 'file' || $itemType == 'folder') {
$fileSource = $itemSource;
} else {
- $fileSource = \OC_FileCache::getId($filePath);
+ $meta = \OC\Files\Filesystem::getFileInfo($filePath);
+ $fileSource = $meta['fileid'];
}
if ($fileSource == -1) {
$message = 'Sharing '.$itemSource.' failed, because the file could not be found in the file cache';
@@ -892,14 +1079,18 @@ class Share {
$fileSource = null;
}
}
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`,'
+ .' `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,'
+ .' `file_target`, `token`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)');
// Share with a group
if ($shareType == self::SHARE_TYPE_GROUP) {
- $groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget);
+ $groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'],
+ $uidOwner, $suggestedItemTarget);
if (isset($fileSource)) {
if ($parentFolder) {
if ($parentFolder === true) {
- $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner, $suggestedFileTarget);
+ $groupFileTarget = self::generateTarget('file', $filePath, $shareType,
+ $shareWith['group'], $uidOwner, $suggestedFileTarget);
// Set group default file target for future use
$parentFolders[0]['folder'] = $groupFileTarget;
} else {
@@ -908,21 +1099,25 @@ class Share {
$parent = $parentFolder[0]['id'];
}
} else {
- $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner, $suggestedFileTarget);
+ $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'],
+ $uidOwner, $suggestedFileTarget);
}
} else {
$groupFileTarget = null;
}
- $query->execute(array($itemType, $itemSource, $groupItemTarget, $parent, $shareType, $shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget));
+ $query->execute(array($itemType, $itemSource, $groupItemTarget, $parent, $shareType,
+ $shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget, $token));
// Save this id, any extra rows for this group share will need to reference it
$parent = \OC_DB::insertid('*PREFIX*share');
// Loop through all users of this group in case we need to add an extra row
foreach ($shareWith['users'] as $uid) {
- $itemTarget = self::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedItemTarget, $parent);
+ $itemTarget = self::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $uid,
+ $uidOwner, $suggestedItemTarget, $parent);
if (isset($fileSource)) {
if ($parentFolder) {
if ($parentFolder === true) {
- $fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedFileTarget, $parent);
+ $fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid,
+ $uidOwner, $suggestedFileTarget, $parent);
if ($fileTarget != $groupFileTarget) {
$parentFolders[$uid]['folder'] = $fileTarget;
}
@@ -931,52 +1126,60 @@ class Share {
$parent = $parentFolder[$uid]['id'];
}
} else {
- $fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedFileTarget, $parent);
+ $fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER,
+ $uid, $uidOwner, $suggestedFileTarget, $parent);
}
} else {
$fileTarget = null;
}
- \OC_Hook::emit('OCP\Share', 'post_shared', array(
- 'itemType' => $itemType,
- 'itemSource' => $itemSource,
- 'itemTarget' => $itemTarget,
- 'parent' => $parent,
- 'shareType' => self::$shareTypeGroupUserUnique,
- 'shareWith' => $uid,
- 'uidOwner' => $uidOwner,
- 'permissions' => $permissions,
- 'fileSource' => $fileSource,
- 'fileTarget' => $fileTarget,
- 'id' => $parent
- ));
// Insert an extra row for the group share if the item or file target is unique for this user
if ($itemTarget != $groupItemTarget || (isset($fileSource) && $fileTarget != $groupFileTarget)) {
- $query->execute(array($itemType, $itemSource, $itemTarget, $parent, self::$shareTypeGroupUserUnique, $uid, $uidOwner, $permissions, time(), $fileSource, $fileTarget));
+ $query->execute(array($itemType, $itemSource, $itemTarget, $parent,
+ self::$shareTypeGroupUserUnique, $uid, $uidOwner, $permissions, time(),
+ $fileSource, $fileTarget, $token));
$id = \OC_DB::insertid('*PREFIX*share');
}
}
+ \OC_Hook::emit('OCP\Share', 'post_shared', array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'itemTarget' => $groupItemTarget,
+ 'parent' => $parent,
+ 'shareType' => $shareType,
+ 'shareWith' => $shareWith['group'],
+ 'uidOwner' => $uidOwner,
+ 'permissions' => $permissions,
+ 'fileSource' => $fileSource,
+ 'fileTarget' => $groupFileTarget,
+ 'id' => $parent,
+ 'token' => $token
+ ));
if ($parentFolder === true) {
// Return parent folders to preserve file target paths for potential children
return $parentFolders;
}
} else {
- $itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedItemTarget);
+ $itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
+ $suggestedItemTarget);
if (isset($fileSource)) {
if ($parentFolder) {
if ($parentFolder === true) {
- $fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner, $suggestedFileTarget);
+ $fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith,
+ $uidOwner, $suggestedFileTarget);
$parentFolders['folder'] = $fileTarget;
} else {
$fileTarget = $parentFolder['folder'].$itemSource;
$parent = $parentFolder['id'];
}
} else {
- $fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner, $suggestedFileTarget);
+ $fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner,
+ $suggestedFileTarget);
}
} else {
$fileTarget = null;
}
- $query->execute(array($itemType, $itemSource, $itemTarget, $parent, $shareType, $shareWith, $uidOwner, $permissions, time(), $fileSource, $fileTarget));
+ $query->execute(array($itemType, $itemSource, $itemTarget, $parent, $shareType, $shareWith, $uidOwner,
+ $permissions, time(), $fileSource, $fileTarget, $token));
$id = \OC_DB::insertid('*PREFIX*share');
\OC_Hook::emit('OCP\Share', 'post_shared', array(
'itemType' => $itemType,
@@ -989,7 +1192,8 @@ class Share {
'permissions' => $permissions,
'fileSource' => $fileSource,
'fileTarget' => $fileTarget,
- 'id' => $id
+ 'id' => $id,
+ 'token' => $token
));
if ($parentFolder === true) {
$parentFolders['id'] = $id;
@@ -1010,7 +1214,8 @@ class Share {
* @param int The id of the parent group share (optional)
* @return string Item target
*/
- private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null) {
+ private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
+ $suggestedTarget = null, $groupParent = null) {
$backend = self::getBackend($itemType);
if ($shareType == self::SHARE_TYPE_LINK) {
if (isset($suggestedTarget)) {
@@ -1062,7 +1267,8 @@ class Share {
}
if ($item['uid_owner'] == $uidOwner) {
if ($itemType == 'file' || $itemType == 'folder') {
- if ($item['file_source'] == \OC_FileCache::getId($itemSource)) {
+ $meta = \OC\Files\Filesystem::getFileInfo($itemSource);
+ if ($item['file_source'] == $meta['fileid']) {
return $target;
}
} else if ($item['item_source'] == $itemSource) {
@@ -1076,18 +1282,28 @@ class Share {
// Find similar targets to improve backend's chances to generate a unqiue target
if ($userAndGroups) {
if ($column == 'file_target') {
- $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
- $result = $checkTargets->execute(array(self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share`'
+ .' WHERE `item_type` IN (\'file\', \'folder\')'
+ .' AND `share_type` IN (?,?,?)'
+ .' AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
+ $result = $checkTargets->execute(array(self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP,
+ self::$shareTypeGroupUserUnique));
} else {
- $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
- $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share`'
+ .' WHERE `item_type` = ? AND `share_type` IN (?,?,?)'
+ .' AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')');
+ $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER,
+ self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
}
} else {
if ($column == 'file_target') {
- $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` = ? AND `share_with` = ?');
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share`'
+ .' WHERE `item_type` IN (\'file\', \'folder\')'
+ .' AND `share_type` = ? AND `share_with` = ?');
$result = $checkTargets->execute(array(self::SHARE_TYPE_GROUP, $shareWith));
} else {
- $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ?');
+ $checkTargets = \OC_DB::prepare('SELECT `'.$column.'` FROM `*PREFIX*share`'
+ .' WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ?');
$result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith));
}
}
@@ -1115,21 +1331,33 @@ class Share {
$parents = array($parent);
while (!empty($parents)) {
$parents = "'".implode("','", $parents)."'";
- // Check the owner on the first search of reshares, useful for finding and deleting the reshares by a single user of a group share
+ // Check the owner on the first search of reshares, useful for
+ // finding and deleting the reshares by a single user of a group share
if (count($ids) == 1 && isset($uidOwner)) {
- $query = \OC_DB::prepare('SELECT `id`, `uid_owner`, `item_type`, `item_target`, `parent` FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.') AND `uid_owner` = ?');
+ $query = \OC_DB::prepare('SELECT `id`, `uid_owner`, `item_type`, `item_target`, `parent`'
+ .' FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.') AND `uid_owner` = ?');
$result = $query->execute(array($uidOwner));
} else {
- $query = \OC_DB::prepare('SELECT `id`, `item_type`, `item_target`, `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.')');
+ $query = \OC_DB::prepare('SELECT `id`, `item_type`, `item_target`, `parent`, `uid_owner`'
+ .' FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.')');
$result = $query->execute();
}
// Reset parents array, only go through loop again if items are found
$parents = array();
while ($item = $result->fetchRow()) {
- // Search for a duplicate parent share, this occurs when an item is shared to the same user through a group and user or the same item is shared by different users
+ // Search for a duplicate parent share, this occurs when an
+ // item is shared to the same user through a group and user or the
+ // same item is shared by different users
$userAndGroups = array_merge(array($item['uid_owner']), \OC_Group::getUserGroups($item['uid_owner']));
- $query = \OC_DB::prepare('SELECT `id`, `permissions` FROM `*PREFIX*share` WHERE `item_type` = ? AND `item_target` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\') AND `uid_owner` != ? AND `id` != ?');
- $duplicateParent = $query->execute(array($item['item_type'], $item['item_target'], self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, $item['uid_owner'], $item['parent']))->fetchRow();
+ $query = \OC_DB::prepare('SELECT `id`, `permissions` FROM `*PREFIX*share`'
+ .' WHERE `item_type` = ?'
+ .' AND `item_target` = ?'
+ .' AND `share_type` IN (?,?,?)'
+ .' AND `share_with` IN (\''.implode('\',\'', $userAndGroups).'\')'
+ .' AND `uid_owner` != ? AND `id` != ?');
+ $duplicateParent = $query->execute(array($item['item_type'], $item['item_target'],
+ self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique,
+ $item['uid_owner'], $item['parent']))->fetchRow();
if ($duplicateParent) {
// Change the parent to the other item id if share permission is granted
if ($duplicateParent['permissions'] & PERMISSION_SHARE) {
@@ -1158,7 +1386,8 @@ class Share {
public static function post_deleteUser($arguments) {
// Delete any items shared with the deleted user
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `share_with` = ? AND `share_type` = ? OR `share_type` = ?');
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share`'
+ .' WHERE `share_with` = ? AND `share_type` = ? OR `share_type` = ?');
$result = $query->execute(array($arguments['uid'], self::SHARE_TYPE_USER, self::$shareTypeGroupUserUnique));
// Delete any items the deleted user shared
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*share` WHERE `uid_owner` = ?');
@@ -1172,21 +1401,27 @@ class Share {
// Find the group shares and check if the user needs a unique target
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?');
$result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid']));
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`,'
+ .' `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`,'
+ .' `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
while ($item = $result->fetchRow()) {
if ($item['item_type'] == 'file' || $item['item_type'] == 'file') {
$itemTarget = null;
} else {
- $itemTarget = self::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'], $item['uid_owner'], $item['item_target'], $item['id']);
+ $itemTarget = self::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER,
+ $arguments['uid'], $item['uid_owner'], $item['item_target'], $item['id']);
}
if (isset($item['file_source'])) {
- $fileTarget = self::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'], $item['uid_owner'], $item['file_target'], $item['id']);
+ $fileTarget = self::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER,
+ $arguments['uid'], $item['uid_owner'], $item['file_target'], $item['id']);
} else {
$fileTarget = null;
}
// Insert an extra row for the group share if the item or file target is unique for this user
if ($itemTarget != $item['item_target'] || $fileTarget != $item['file_target']) {
- $query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'], self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'], $item['stime'], $item['file_source'], $fileTarget));
+ $query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'],
+ self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'],
+ $item['stime'], $item['file_source'], $fileTarget));
\OC_DB::insertid('*PREFIX*share');
}
}
@@ -1194,8 +1429,10 @@ class Share {
public static function post_removeFromGroup($arguments) {
// TODO Don't call if user deleted?
- $query = \OC_DB::prepare('SELECT `id`, `share_type` FROM `*PREFIX*share` WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)');
- $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'], self::$shareTypeGroupUserUnique, $arguments['uid']));
+ $query = \OC_DB::prepare('SELECT `id`, `share_type` FROM `*PREFIX*share`'
+ .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)');
+ $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'], self::$shareTypeGroupUserUnique,
+ $arguments['uid']));
while ($item = $result->fetchRow()) {
if ($item['share_type'] == self::SHARE_TYPE_GROUP) {
// Delete all reshares by this user of the group share
@@ -1252,10 +1489,18 @@ interface Share_Backend {
* @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 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
+ * 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.
*/
diff --git a/lib/public/template.php b/lib/public/template.php
index 4cda3650866..ccf19cf052c 100644
--- a/lib/public/template.php
+++ b/lib/public/template.php
@@ -99,7 +99,8 @@ function html_select_options($options, $selected, $params=array()) {
/**
- * This class provides the template system for owncloud. You can use it to load specific templates, add data and generate the html code
+ * This class provides the template system for owncloud. You can use it to load
+ * specific templates, add data and generate the html code
*/
class Template extends \OC_Template {
diff --git a/lib/public/user.php b/lib/public/user.php
index b320ce8ea0c..9edebe0e7cf 100644
--- a/lib/public/user.php
+++ b/lib/public/user.php
@@ -31,7 +31,8 @@
namespace OCP;
/**
- * This class provides access to the user management. You can get information about the currently logged in user and the permissions for example
+ * This class provides access to the user management. You can get information
+ * about the currently logged in user and the permissions for example
*/
class User {
/**
@@ -53,6 +54,24 @@ class User {
}
/**
+ * @brief get the user display name of the user currently logged in.
+ * @return string display name
+ */
+ public static function getDisplayName($user=null) {
+ return \OC_USER::getDisplayName($user);
+ }
+
+ /**
+ * @brief Get a list of all display names
+ * @returns array with all display names (value) and the correspondig uids (key)
+ *
+ * Get a list of all display names and user ids.
+ */
+ public static function getDisplayNames($search = '', $limit = null, $offset = null) {
+ return \OC_USER::getDisplayNames($search, $limit, $offset);
+ }
+
+ /**
* @brief Check if the user is logged in
* @returns true/false
*
@@ -65,20 +84,18 @@ class User {
/**
* @brief check if a user exists
* @param string $uid the username
+ * @param string $excludingBackend (default none)
* @return boolean
*/
- public static function userExists( $uid ) {
- return \OC_USER::userExists( $uid );
+ public static function userExists( $uid, $excludingBackend = null ) {
+ return \OC_USER::userExists( $uid, $excludingBackend );
}
-
/**
* @brief Loggs the user out including all the session data
- * @returns true
- *
* Logout, destroys session
*/
public static function logout() {
- return \OC_USER::logout();
+ \OC_USER::logout();
}
/**
diff --git a/lib/public/util.php b/lib/public/util.php
index 7b5b1abbded..6744c2d37bd 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -59,16 +59,18 @@ class Util {
* @param string $fromname
* @param bool $html
*/
- public static function sendMail( $toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, $html=0, $altbody='', $ccaddress='', $ccname='', $bcc='') {
+ public static function sendMail( $toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
+ $html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '') {
// call the internal mail class
- \OC_MAIL::send($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, $html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '');
+ \OC_MAIL::send($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
+ $html, $altbody, $ccaddress, $ccname, $bcc);
}
/**
* @brief write a message in the log
* @param string $app
* @param string $message
- * @param int level
+ * @param int $level
*/
public static function writeLog( $app, $message, $level ) {
// call the internal log class
@@ -77,7 +79,7 @@ class Util {
/**
* @brief add a css file
- * @param url $url
+ * @param string $url
*/
public static function addStyle( $application, $file = null ) {
\OC_Util::addStyle( $application, $file );
@@ -85,8 +87,8 @@ class Util {
/**
* @brief add a javascript file
- * @param appid $application
- * @param filename $file
+ * @param string $application
+ * @param string $file
*/
public static function addScript( $application, $file = null ) {
\OC_Util::addScript( $application, $file );
@@ -94,7 +96,7 @@ class Util {
/**
* @brief Add a custom element to the header
- * @param string tag tag name of the element
+ * @param string $tag tag name of the element
* @param array $attributes array of attributes for the element
* @param string $text the text content for the element
*/
@@ -104,8 +106,8 @@ class Util {
/**
* @brief formats a timestamp in the "right" way
- * @param int timestamp $timestamp
- * @param bool dateOnly option to ommit time from the result
+ * @param int $timestamp $timestamp
+ * @param bool $dateOnly option to omit time from the result
*/
public static function formatDate( $timestamp, $dateOnly=false) {
return(\OC_Util::formatDate( $timestamp, $dateOnly ));
@@ -113,11 +115,11 @@ class Util {
/**
* @brief Creates an absolute url
- * @param $app app
- * @param $file file
- * @param $args array with param=>value, will be appended to the returned url
+ * @param string $app app
+ * @param string $file file
+ * @param array $args array with param=>value, will be appended to the returned url
* The value of $args will be urlencoded
- * @returns the url
+ * @returns string the url
*
* Returns a absolute url to the given app and file.
*/
@@ -127,8 +129,8 @@ class Util {
/**
* @brief Creates an absolute url for remote use
- * @param $service id
- * @returns the url
+ * @param string $service id
+ * @returns string the url
*
* Returns a absolute url to the given app and file.
*/
@@ -138,8 +140,8 @@ class Util {
/**
* @brief Creates an absolute url for public use
- * @param $service id
- * @returns the url
+ * @param string $service id
+ * @returns string the url
*
* Returns a absolute url to the given app and file.
*/
@@ -148,12 +150,26 @@ class Util {
}
/**
+ * @brief Creates an url using a defined route
+ * @param $route
+ * @param array $parameters
+ * @return
+ * @internal param array $args with param=>value, will be appended to the returned url
+ * @returns the url
+ *
+ * Returns a url to the given app and file.
+ */
+ public static function linkToRoute( $route, $parameters = array() ) {
+ return \OC_Helper::linkToRoute($route, $parameters);
+ }
+
+ /**
* @brief Creates an url
- * @param $app app
- * @param $file file
- * @param $args array with param=>value, will be appended to the returned url
+ * @param string $app app
+ * @param string $file file
+ * @param array $args array with param=>value, will be appended to the returned url
* The value of $args will be urlencoded
- * @returns the url
+ * @returns string the url
*
* Returns a url to the given app and file.
*/
@@ -163,7 +179,7 @@ class Util {
/**
* @brief Returns the server host
- * @returns the server host
+ * @returns string the server host
*
* Returns the server host, even if the website uses one or more
* reverse proxies
@@ -173,8 +189,48 @@ class Util {
}
/**
+ * @brief returns the server hostname
+ * @returns string the server hostname
+ *
+ * Returns the server host name without an eventual port number
+ */
+ public static function getServerHostName() {
+ $host_name = self::getServerHost();
+ // strip away port number (if existing)
+ $colon_pos = strpos($host_name, ':');
+ if ($colon_pos != FALSE) {
+ $host_name = substr($host_name, 0, $colon_pos);
+ }
+ return $host_name;
+ }
+
+ /**
+ * @brief Returns the default email address
+ * @param string $user_part the user part of the address
+ * @returns string the default email address
+ *
+ * Assembles a default email address (using the server hostname
+ * and the given user part, and returns it
+ * Example: when given lostpassword-noreply as $user_part param,
+ * and is currently accessed via http(s)://example.com/,
+ * it would return 'lostpassword-noreply@example.com'
+ */
+ public static function getDefaultEmailAddress($user_part) {
+ $host_name = self::getServerHostName();
+ $host_name = \OC_Config::getValue('mail_domain', $host_name);
+ $defaultEmailAddress = $user_part.'@'.$host_name;
+
+ if (\OC_Mail::ValidateAddress($defaultEmailAddress)) {
+ return $defaultEmailAddress;
+ }
+
+ // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
+ return $user_part.'@localhost.localdomain';
+ }
+
+ /**
* @brief Returns the server protocol
- * @returns the server protocol
+ * @returns string the server protocol
*
* Returns the server protocol. It respects reverse proxy servers and load balancers
*/
@@ -183,10 +239,32 @@ class Util {
}
/**
+ * @brief Returns the request uri
+ * @returns the request uri
+ *
+ * Returns the request uri, even if the website uses one or more
+ * reverse proxies
+ */
+ public static function getRequestUri() {
+ return(\OC_Request::requestUri());
+ }
+
+ /**
+ * @brief Returns the script name
+ * @returns the script name
+ *
+ * Returns the script name, even if the website uses one or more
+ * reverse proxies
+ */
+ public static function getScriptName() {
+ return(\OC_Request::scriptName());
+ }
+
+ /**
* @brief Creates path to an image
- * @param $app app
- * @param $image image name
- * @returns the url
+ * @param string $app app
+ * @param string $image image name
+ * @returns string the url
*
* Returns the path to the image.
*/
@@ -196,8 +274,8 @@ class Util {
/**
* @brief Make a human file size
- * @param $bytes file size in bytes
- * @returns a human readable file size
+ * @param int $bytes file size in bytes
+ * @returns string a human readable file size
*
* Makes 2048 to 2 kB.
*/
@@ -207,8 +285,8 @@ class Util {
/**
* @brief Make a computer file size
- * @param $str file size in a fancy format
- * @returns a file size in bytes
+ * @param string $str file size in a fancy format
+ * @returns int a file size in bytes
*
* Makes 2kB to 2048.
*
@@ -220,11 +298,11 @@ class Util {
/**
* @brief connects a function to a hook
- * @param $signalclass class name of emitter
- * @param $signalname name of signal
- * @param $slotclass class name of slot
- * @param $slotname name of slot
- * @returns true/false
+ * @param string $signalclass class name of emitter
+ * @param string $signalname name of signal
+ * @param string $slotclass class name of slot
+ * @param string $slotname name of slot
+ * @returns bool
*
* This function makes it very easy to connect to use hooks.
*
@@ -236,10 +314,10 @@ class Util {
/**
* @brief emitts a signal
- * @param $signalclass class name of emitter
- * @param $signalname name of signal
- * @param $params defautl: array() array with additional data
- * @returns true if slots exists or false if not
+ * @param string $signalclass class name of emitter
+ * @param string $signalname name of signal
+ * @param string $params defautl: array() array with additional data
+ * @returns bool true if slots exists or false if not
*
* Emits a signal. To get data from the slot use references!
*
@@ -262,15 +340,16 @@ class Util {
* Todo: Write howto
*/
public static function callCheck() {
- return(\OC_Util::callCheck());
+ \OC_Util::callCheck();
}
/**
* @brief Used to sanitize HTML
*
- * This function is used to sanitize HTML and should be applied on any string or array of strings before displaying it on a web page.
+ * This function is used to sanitize HTML and should be applied on any
+ * string or array of strings before displaying it on a web page.
*
- * @param string or array of strings
+ * @param string|array of strings
* @return array with sanitized strings or a single sinitized string, depends on the input parameter.
*/
public static function sanitizeHTML( $value ) {
@@ -280,9 +359,9 @@ class Util {
/**
* @brief Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
*
- * @param $input The array to work on
- * @param $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
- * @param $encoding The encoding parameter is the character encoding. Defaults to UTF-8
+ * @param array $input The array to work on
+ * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
+ * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
* @return array
*
*
@@ -294,11 +373,11 @@ class Util {
/**
* @brief replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement.
*
- * @param $input The input string. .Opposite to the PHP build-in function does not accept an array.
- * @param $replacement The replacement string.
- * @param $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string.
- * @param $length Length of the part to be replaced
- * @param $encoding The encoding parameter is the character encoding. Defaults to UTF-8
+ * @param string $input The input string. .Opposite to the PHP build-in function does not accept an array.
+ * @param string $replacement The replacement string.
+ * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string.
+ * @param int $length Length of the part to be replaced
+ * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
* @return string
*
*/
@@ -309,11 +388,11 @@ class Util {
/**
* @brief Replace all occurrences of the search string with the replacement string
*
- * @param $search The value being searched for, otherwise known as the needle. String.
- * @param $replace The replacement string.
- * @param $subject The string or array being searched and replaced on, otherwise known as the haystack.
- * @param $encoding The encoding parameter is the character encoding. Defaults to UTF-8
- * @param $count If passed, this will be set to the number of replacements performed.
+ * @param string $search The value being searched for, otherwise known as the needle. String.
+ * @param string $replace The replacement string.
+ * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack.
+ * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
+ * @param int $count If passed, this will be set to the number of replacements performed.
* @return string
*
*/
@@ -323,12 +402,22 @@ class Util {
/**
* @brief performs a search in a nested array
- * @param haystack the array to be searched
- * @param needle the search string
- * @param $index optional, only search this key name
- * @return the key of the matching field, otherwise false
+ * @param array $haystack the array to be searched
+ * @param string $needle the search string
+ * @param int $index optional, only search this key name
+ * @return mixed the key of the matching field, otherwise false
*/
public static function recursiveArraySearch($haystack, $needle, $index = null) {
return(\OC_Helper::recursiveArraySearch($haystack, $needle, $index));
}
+
+ /**
+ * @brief calculates the maximum upload size respecting system settings, free space and user quota
+ *
+ * @param $dir the current folder where the user currently operates
+ * @return number of bytes representing
+ */
+ public static function maxUploadFilesize($dir) {
+ return \OC_Helper::maxUploadFilesize($dir);
+ }
}