aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-01-30 19:24:24 +0100
committerRobin Appelman <icewind@owncloud.com>2013-01-30 19:24:24 +0100
commit207aa22d12931d161f682198996086e74c91bf53 (patch)
tree26f65a42462244fdfc14e15c7788da8b7f8a524e /lib
parent95352fbc1568e0c49be25461a07d53b3d5ad3b45 (diff)
parent2fbf3d40900d29c04b69f0c18e4d833a312fb21c (diff)
downloadnextcloud-server-207aa22d12931d161f682198996086e74c91bf53.tar.gz
nextcloud-server-207aa22d12931d161f682198996086e74c91bf53.zip
merge master into filesystem
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php2
-rw-r--r--lib/group.php29
-rw-r--r--lib/group/backend.php18
-rw-r--r--lib/group/database.php28
-rw-r--r--lib/helper.php7
-rw-r--r--lib/l10n/da.php1
-rw-r--r--lib/l10n/pl.php1
-rw-r--r--lib/l10n/ru_RU.php1
-rw-r--r--lib/l10n/sk_SK.php1
-rw-r--r--lib/public/share.php9
-rw-r--r--lib/public/user.php20
-rw-r--r--lib/user.php76
-rw-r--r--lib/user/backend.php28
-rw-r--r--lib/user/database.php54
-rw-r--r--lib/user/interface.php15
-rwxr-xr-xlib/util.php2
16 files changed, 284 insertions, 8 deletions
diff --git a/lib/base.php b/lib/base.php
index c1fece0c3d9..ea5c939cd80 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -504,7 +504,7 @@ class OC
// write error into log if locale can't be set
if (OC_Util::issetlocaleworking() == false) {
- OC_Log::write('core', 'setting locate to en_US.UTF-8 failed. Support is probably not installed on your system', OC_Log::ERROR);
+ OC_Log::write('core', 'setting locale to en_US.UTF-8 failed. Support is probably not installed on your system', OC_Log::ERROR);
}
if (OC_Config::getValue('installed', false)) {
if (OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
diff --git a/lib/group.php b/lib/group.php
index ed9482418bd..5afef769361 100644
--- a/lib/group.php
+++ b/lib/group.php
@@ -286,4 +286,33 @@ class OC_Group {
}
return $users;
}
+
+ /**
+ * @brief get a list of all display names in a group
+ * @returns array with display names (value) and user ids(key)
+ */
+ public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ $displayNames=array();
+ foreach(self::$_usedBackends as $backend) {
+ $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames);
+ }
+ return $displayNames;
+ }
+
+ /**
+ * @brief get a list of all display names in several groups
+ * @param array $gids
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array with display names (Key) user ids (value)
+ */
+ public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) {
+ $displayNames = array();
+ foreach ($gids as $gid) {
+ // TODO Need to apply limits to groups as total
+ $displayNames = array_merge(array_diff(self::displayNamesInGroup($gid, $search, $limit, $offset), $displayNames), $displayNames);
+ }
+ return $displayNames;
+ }
}
diff --git a/lib/group/backend.php b/lib/group/backend.php
index 9ff432d0663..4f6570c3be3 100644
--- a/lib/group/backend.php
+++ b/lib/group/backend.php
@@ -133,5 +133,23 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
return array();
}
+
+ /**
+ * @brief get a list of all display names in a group
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array with display names (value) and user ids (key)
+ */
+ public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ $displayNames = '';
+ $users = $this->usersInGroup($gid, $search, $limit, $offset);
+ foreach ( $users as $user ) {
+ $DisplayNames[$user] = $user;
+ }
+
+ return $DisplayNames;
+ }
}
diff --git a/lib/group/database.php b/lib/group/database.php
index 6eca98ba019..c5dd402b212 100644
--- a/lib/group/database.php
+++ b/lib/group/database.php
@@ -208,4 +208,32 @@ class OC_Group_Database extends OC_Group_Backend {
}
return $users;
}
+
+ /**
+ * @brief get a list of all display names in a group
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array with display names (value) and user ids (key)
+ */
+ public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ $displayNames = '';
+ /*
+
+ SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
+ FROM Persons
+ INNER JOIN Orders
+ ON Persons.P_Id=Orders.P_Id
+ ORDER BY Persons.LastName
+ */
+ $stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname` FROM `*PREFIX*users` INNER JOIN `*PREFIX*group_user` ON `*PREFIX*group_user`.`uid` = `*PREFIX*users`.`uid` WHERE `gid` = ? AND `*PREFIX*group_user.uid` LIKE ?', $limit, $offset);
+ $result = $stmt->execute(array($gid, $search.'%'));
+ $users = array();
+ while ($row = $result->fetchRow()) {
+ $displayName = trim($row['displayname'], ' ');
+ $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;
+ }
+ return $displayNames;
+ }
}
diff --git a/lib/helper.php b/lib/helper.php
index c2a0d83f6b1..0e549d006a1 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -78,11 +78,8 @@ class OC_Helper {
}
}
- if (!empty($args)) {
- $urlLinkTo .= '?';
- foreach($args as $k => $v) {
- $urlLinkTo .= '&'.$k.'='.urlencode($v);
- }
+ if ($args && $query = http_build_query($args, '', '&')) {
+ $urlLinkTo .= '?'.$query;
}
return $urlLinkTo;
diff --git a/lib/l10n/da.php b/lib/l10n/da.php
index a0ab1f17014..8f22be5e823 100644
--- a/lib/l10n/da.php
+++ b/lib/l10n/da.php
@@ -9,6 +9,7 @@
"Files need to be downloaded one by one." => "Filer skal downloades en for en.",
"Back to Files" => "Tilbage til Filer",
"Selected files too large to generate zip file." => "De markerede filer er for store til at generere en ZIP-fil.",
+"couldn't be determined" => "kunne ikke fastslås",
"Application is not enabled" => "Programmet er ikke aktiveret",
"Authentication error" => "Adgangsfejl",
"Token expired. Please reload page." => "Adgang er udløbet. Genindlæs siden.",
diff --git a/lib/l10n/pl.php b/lib/l10n/pl.php
index 6f84a328ed9..6ec35445bc2 100644
--- a/lib/l10n/pl.php
+++ b/lib/l10n/pl.php
@@ -9,6 +9,7 @@
"Files need to be downloaded one by one." => "Pliki muszą zostać pobrane pojedynczo.",
"Back to Files" => "Wróć do plików",
"Selected files too large to generate zip file." => "Wybrane pliki są zbyt duże, aby wygenerować plik zip.",
+"couldn't be determined" => "nie może zostać znaleziony",
"Application is not enabled" => "Aplikacja nie jest włączona",
"Authentication error" => "Błąd uwierzytelniania",
"Token expired. Please reload page." => "Token wygasł. Proszę ponownie załadować stronę.",
diff --git a/lib/l10n/ru_RU.php b/lib/l10n/ru_RU.php
index ba7d39f9eb0..03da09236ea 100644
--- a/lib/l10n/ru_RU.php
+++ b/lib/l10n/ru_RU.php
@@ -9,6 +9,7 @@
"Files need to be downloaded one by one." => "Файлы должны быть загружены один за другим.",
"Back to Files" => "Обратно к файлам",
"Selected files too large to generate zip file." => "Выбранные файлы слишком велики для генерации zip-архива.",
+"couldn't be determined" => "не может быть определено",
"Application is not enabled" => "Приложение не запущено",
"Authentication error" => "Ошибка аутентификации",
"Token expired. Please reload page." => "Маркер истек. Пожалуйста, перезагрузите страницу.",
diff --git a/lib/l10n/sk_SK.php b/lib/l10n/sk_SK.php
index 98a5b5ca677..81f23ffdc50 100644
--- a/lib/l10n/sk_SK.php
+++ b/lib/l10n/sk_SK.php
@@ -9,6 +9,7 @@
"Files need to be downloaded one by one." => "Súbory musia byť nahrávané jeden za druhým.",
"Back to Files" => "Späť na súbory",
"Selected files too large to generate zip file." => "Zvolené súbory sú príliž veľké na vygenerovanie zip súboru.",
+"couldn't be determined" => "nedá sa zistiť",
"Application is not enabled" => "Aplikácia nie je zapnutá",
"Authentication error" => "Chyba autentifikácie",
"Token expired. Please reload page." => "Token vypršal. Obnovte, prosím, stránku.",
diff --git a/lib/public/share.php b/lib/public/share.php
index f65d272ff17..3c5c2d53782 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -758,6 +758,15 @@ class Share {
continue;
}
}
+
+ // 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)) {
diff --git a/lib/public/user.php b/lib/public/user.php
index 204d8e4c0f1..de52055a4c5 100644
--- a/lib/public/user.php
+++ b/lib/public/user.php
@@ -51,7 +51,25 @@ class User {
public static function getUsers($search = '', $limit = null, $offset = null) {
return \OC_USER::getUsers();
}
-
+
+ /**
+ * @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
diff --git a/lib/user.php b/lib/user.php
index 85240ce6b68..38259bceea5 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -251,6 +251,7 @@ class OC_User {
if($uid && $enabled) {
session_regenerate_id(true);
self::setUserId($uid);
+ self::setDisplayName($uid);
OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password ));
return true;
}
@@ -266,6 +267,48 @@ class OC_User {
}
/**
+ * @brief Sets user display name for session
+ */
+ public static function setDisplayName($uid, $displayName = null) {
+ $result = false;
+ if ($displayName ) {
+ foreach(self::$_usedBackends as $backend) {
+ if($backend->implementsActions(OC_USER_BACKEND_SET_DISPLAYNAME)) {
+ if($backend->userExists($uid)) {
+ $success |= $backend->setDisplayName($uid, $displayName);
+ }
+ }
+ }
+ } else {
+ $displayName = self::determineDisplayName($uid);
+ $result = true;
+ }
+ if (OC_User::getUser() === $uid) {
+ $_SESSION['display_name'] = $displayName;
+ }
+ return $result;
+ }
+
+
+ /**
+ * @brief get display name
+ * @param $uid The username
+ * @returns string display name or uid if no display name is defined
+ *
+ */
+ private static function determineDisplayName( $uid ) {
+ foreach(self::$_usedBackends as $backend) {
+ if($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
+ $result=$backend->getDisplayName( $uid );
+ if($result) {
+ return $result;
+ }
+ }
+ }
+ return $uid;
+ }
+
+ /**
* @brief Logs the current user out and kills all the session data
*
* Logout, destroys session
@@ -321,6 +364,21 @@ class OC_User {
}
/**
+ * @brief get the display name of the user currently logged in.
+ * @return string uid or false
+ */
+ public static function getDisplayName($user=null) {
+ if ( $user ) {
+ return self::determineDisplayName($user);
+ } else if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) {
+ return $_SESSION['display_name'];
+ }
+ else{
+ return false;
+ }
+ }
+
+ /**
* @brief Autogenerate a password
* @returns string
*
@@ -420,6 +478,24 @@ class OC_User {
}
/**
+ * @brief Get a list of all users display name
+ * @returns associative array with all display names (value) and corresponding uids (key)
+ *
+ * Get a list of all display names and user ids.
+ */
+ public static function getDisplayNames($search = '', $limit = null, $offset = null) {
+ $displayNames = array();
+ foreach (self::$_usedBackends as $backend) {
+ $backendDisplayNames = $backend->getDisplayNames($search, $limit, $offset);
+ if (is_array($backendDisplayNames)) {
+ $displayNames = array_merge($displayNames, $backendDisplayNames);
+ }
+ }
+ ksort($displayNames);
+ return $displayNames;
+ }
+
+ /**
* @brief check if a user exists
* @param string $uid the username
* @param string $excludingBackend (default none)
diff --git a/lib/user/backend.php b/lib/user/backend.php
index 2a95db93690..56fa3195978 100644
--- a/lib/user/backend.php
+++ b/lib/user/backend.php
@@ -35,6 +35,8 @@ define('OC_USER_BACKEND_CREATE_USER', 0x000001);
define('OC_USER_BACKEND_SET_PASSWORD', 0x000010);
define('OC_USER_BACKEND_CHECK_PASSWORD', 0x000100);
define('OC_USER_BACKEND_GET_HOME', 0x001000);
+define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x010000);
+define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x010000);
/**
@@ -50,6 +52,8 @@ abstract class OC_User_Backend implements OC_User_Interface {
OC_USER_BACKEND_SET_PASSWORD => 'setPassword',
OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword',
OC_USER_BACKEND_GET_HOME => 'getHome',
+ OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName',
+ OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName',
);
/**
@@ -120,4 +124,28 @@ abstract class OC_User_Backend implements OC_User_Interface {
public function getHome($uid) {
return false;
}
+
+ /**
+ * @brief get display name of the user
+ * @param $uid user ID of the user
+ * @return display name
+ */
+ public function getDisplayName($uid) {
+ return $uid;
+ }
+
+ /**
+ * @brief Get a list of all display names
+ * @returns array with all displayNames (value) and the correspondig uids (key)
+ *
+ * Get a list of all display names and user ids.
+ */
+ public function getDisplayNames($search = '', $limit = null, $offset = null) {
+ $displayNames = array();
+ $users = $this->getUsers($search, $limit, $offset);
+ foreach ( $users as $user) {
+ $displayNames[$user] = $user;
+ }
+ return $displayNames;
+ }
}
diff --git a/lib/user/database.php b/lib/user/database.php
index f33e338e2e4..7deeb0c4697 100644
--- a/lib/user/database.php
+++ b/lib/user/database.php
@@ -110,7 +110,61 @@ class OC_User_Database extends OC_User_Backend {
return false;
}
}
+
+ /**
+ * @brief Set display name
+ * @param $uid The username
+ * @param $displayName The new display name
+ * @returns true/false
+ *
+ * Change the display name of a user
+ */
+ public function setDisplayName( $uid, $displayName ) {
+ if( $this->userExists($uid) ) {
+ $query = OC_DB::prepare( 'UPDATE `*PREFIX*users` SET `displayname` = ? WHERE `uid` = ?' );
+ $query->execute( array( $displayName, $uid ));
+ return true;
+ }else{
+ return false;
+ }
+ }
+ /**
+ * @brief get display name of the user
+ * @param $uid user ID of the user
+ * @return display name
+ */
+ public function getDisplayName($uid) {
+ if( $this->userExists($uid) ) {
+ $query = OC_DB::prepare( 'SELECT displayname FROM `*PREFIX*users` WHERE `uid` = ?' );
+ $result = $query->execute( array( $uid ))->fetchAll();
+ $displayName = trim($result[0]['displayname'], ' ');
+ if ( !empty($displayName) ) {
+ return $displayName;
+ } else {
+ return $uid;
+ }
+ }
+ }
+
+ /**
+ * @brief Get a list of all display names
+ * @returns array with all displayNames (value) and the correspondig uids (key)
+ *
+ * Get a list of all display names and user ids.
+ */
+ public function getDisplayNames($search = '', $limit = null, $offset = null) {
+ $displayNames = array();
+ $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`displayname`) LIKE LOWER(?)', $limit, $offset);
+ $result = $query->execute(array($search.'%'));
+ $users = array();
+ while ($row = $result->fetchRow()) {
+ $displayName = trim($row['displayname'], ' ');
+ $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;
+ }
+ return $displayNames;
+ }
+
/**
* @brief Check if the password is correct
* @param $uid The username
diff --git a/lib/user/interface.php b/lib/user/interface.php
index 3d9f4691f24..b4667633b50 100644
--- a/lib/user/interface.php
+++ b/lib/user/interface.php
@@ -57,4 +57,19 @@ interface OC_User_Interface {
*/
public function userExists($uid);
+ /**
+ * @brief get display name of the user
+ * @param $uid user ID of the user
+ * @return display name
+ */
+ public function getDisplayName($uid);
+
+ /**
+ * @brief Get a list of all display names
+ * @returns array with all displayNames (value) and the correspondig uids (key)
+ *
+ * Get a list of all display names and user ids.
+ */
+ public function getDisplayNames($search = '', $limit = null, $offset = null);
+
} \ No newline at end of file
diff --git a/lib/util.php b/lib/util.php
index f947ed9c178..f2d2e782ffc 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -74,7 +74,7 @@ class OC_Util {
*/
public static function getVersion() {
// hint: We only can count up. So the internal version number of ownCloud 4.5 will be 4.90.0. This is not visible to the user
- return array(4,91,8);
+ return array(4, 91, 8);
}
/**