本文整理汇总了PHP中OC_Group::groupExists方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Group::groupExists方法的具体用法?PHP OC_Group::groupExists怎么用?PHP OC_Group::groupExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Group
的用法示例。
在下文中一共展示了OC_Group::groupExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteGroup
public static function deleteGroup($parameters)
{
// Check it exists
if (!OC_Group::groupExists($parameters['groupid'])) {
return 101;
} else {
if ($parameters['groupid'] == 'admin') {
// Cannot delete admin group
return 102;
} else {
if (OC_Group::deleteGroup($parameters['groupid'])) {
return 100;
} else {
return 103;
}
}
}
}
示例2: addToGroup
/**
* @brief Add a user to a group
* @param $uid Name of the user to add to group
* @param $gid Name of the group in which add the user
* @returns true/false
*
* Adds a user to a group.
*/
public static function addToGroup($uid, $gid)
{
// Does the user exist?
if (!OC_User::userExists($uid)) {
return false;
}
// Does the group exist?
if (!OC_Group::groupExists($gid)) {
return false;
}
// Go go go
$run = true;
OC_Hook::emit("OC_Group", "pre_addToGroup", array("run" => &$run, "uid" => $uid, "gid" => $gid));
if ($run && self::$_backend->addToGroup($uid, $gid)) {
OC_Hook::emit("OC_Group", "post_addToGroup", array("uid" => $uid, "gid" => $gid));
return true;
} else {
return false;
}
}
示例3: array
OC_JSON::checkSubAdminUser();
OCP\JSON::callCheck();
$success = true;
$username = $_POST["username"];
$group = $_POST["group"];
if ($username == OC_User::getUser() && $group == "admin" && OC_User::isAdminUser($username)) {
$l = OC_L10N::get('core');
OC_JSON::error(array('data' => array('message' => $l->t('Admins can\'t remove themself from the admin group'))));
exit;
}
if (!OC_User::isAdminUser(OC_User::getUser()) && (!OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username) || !OC_SubAdmin::isGroupAccessible(OC_User::getUser(), $group))) {
$l = OC_L10N::get('core');
OC_JSON::error(array('data' => array('message' => $l->t('Authentication error'))));
exit;
}
if (!OC_Group::groupExists($group)) {
OC_Group::createGroup($group);
}
$l = OC_L10N::get('settings');
$error = $l->t("Unable to add user to group %s", $group);
$action = "add";
// Toggle group
if (OC_Group::inGroup($username, $group)) {
$action = "remove";
$error = $l->t("Unable to remove user from group %s", $group);
$success = OC_Group::removeFromGroup($username, $group);
$usersInGroup = OC_Group::usersInGroup($group);
if (count($usersInGroup) == 0) {
OC_Group::deleteGroup($group);
}
} else {
示例4: _createAltInternalOwnCloudNameForGroups
/**
* creates a unique name for internal ownCloud use for groups. Don't call it directly.
* @param string $name the display name of the object
* @return string with with the name to use in ownCloud or false if unsuccessful.
*
* Instead of using this method directly, call
* createAltInternalOwnCloudName($name, false)
*
* Group names are also used as display names, so we do a sequential
* numbering, e.g. Developers_42 when there are 41 other groups called
* "Developers"
*/
private function _createAltInternalOwnCloudNameForGroups($name)
{
$query = \OCP\DB::prepare('
SELECT `owncloud_name`
FROM `' . $this->getMapTable(false) . '`
WHERE `owncloud_name` LIKE ?
');
$usedNames = array();
$res = $query->execute(array($name . '_%'));
while ($row = $res->fetchRow()) {
$usedNames[] = $row['owncloud_name'];
}
if (!$usedNames || count($usedNames) === 0) {
$lastNo = 1;
//will become name_2
} else {
natsort($usedNames);
$lastName = array_pop($usedNames);
$lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1));
}
$altName = $name . '_' . strval($lastNo + 1);
unset($usedNames);
$attempts = 1;
while ($attempts < 21) {
// Check to be really sure it is unique
// while loop is just a precaution. If a name is not generated within
// 20 attempts, something else is very wrong. Avoids infinite loop.
if (!\OC_Group::groupExists($altName)) {
return $altName;
}
$altName = $name . '_' . ($lastNo + $attempts);
$attempts++;
}
return false;
}
示例5: checkPassword
public function checkPassword($uid, $password)
{
if (!$this->db_conn) {
$this->connectdb();
}
if (!$this->db_conn) {
return false;
}
$query = 'SELECT user_login, user_pass FROM ' . self::$params['wordpress_db_prefix'] . 'users WHERE user_login = "' . str_replace('"', '""', $uid) . '"';
$query .= ' AND user_status = 0';
$result = $this->wp_instance->db->query($query);
if ($result && mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$hash = $row['user_pass'];
$normalize_path = str_replace('\\', '/', OC_APP::getAppPath('user_wordpress'));
$path_array = explode('/', $normalize_path);
array_pop($path_array);
$app_folder = array_pop($path_array);
OC::$CLASSPATH['OC_wordpress'] = $app_folder . '/lib/wordpress.class.php';
require_once $app_folder . '/user_wordpress/class-phpass.php';
$wp_hasher = new WPPasswordHash(8, TRUE);
$check = $wp_hasher->CheckPassword($password, $hash);
if ($check === true) {
// Make sure the user is in the wordpress_global_group
if (self::$params['wordpress_global_group'] != '') {
if (!OC_Group::groupExists(self::$params['wordpress_global_group'])) {
OC_Group::createGroup(self::$params['wordpress_global_group']);
}
$UserblogsIds = $this->wp_instance->getUserblogsIds($uid);
if (empty($UserblogsIds)) {
// remove from group if current user has no access to Wordpress blog/site with the same role name.
OC_Group::removefromGroup($uid, self::$params['wordpress_global_group']);
} else {
OC_Group::addToGroup($uid, self::$params['wordpress_global_group']);
}
}
$this->setUserInfos($uid);
return $row['user_login'];
}
}
return false;
}
示例6: addToGroup
/**
* @brief Add a user to a group
* @param string $uid Name of the user to add to group
* @param string $gid Name of the group in which add the user
* @return bool
*
* Adds a user to a group.
*/
public static function addToGroup($uid, $gid)
{
// Does the group exist?
if (!OC_Group::groupExists($gid)) {
return false;
}
// Go go go
$run = true;
OC_Hook::emit("OC_Group", "pre_addToGroup", array("run" => &$run, "uid" => $uid, "gid" => $gid));
if ($run) {
$success = false;
//add the user to the all backends that have the group
foreach (self::$_usedBackends as $backend) {
if (!$backend->implementsActions(OC_GROUP_BACKEND_ADD_TO_GROUP)) {
continue;
}
if ($backend->groupExists($gid)) {
$success |= $backend->addToGroup($uid, $gid);
}
}
if ($success) {
OC_Hook::emit("OC_User", "post_addToGroup", array("uid" => $uid, "gid" => $gid));
}
return $success;
} else {
return false;
}
}
示例7: update_groups
private static function update_groups($uid, $groups, $protectedGroups = array(), $just_created = false)
{
if (!$just_created) {
$old_groups = OC_Group::getUserGroups($uid);
foreach ($old_groups as $group) {
if (!in_array($group, $protectedGroups) && !in_array($group, $groups)) {
// This does not affect groups from user_group_admin
OC_Group::removeFromGroup($uid, $group);
OC_Log::write('saml', 'Removed "' . $uid . '" from the group "' . $group . '"', OC_Log::DEBUG);
}
}
}
foreach ($groups as $group) {
if (preg_match('/[^a-zA-Z0-9 _\\.@\\-\\/]/', $group)) {
OC_Log::write('saml', 'Invalid group "' . $group . '", allowed chars "a-zA-Z0-9" and "_.@-/" ', OC_Log::DEBUG);
} else {
if (!OC_Group::inGroup($uid, $group)) {
if (!OC_Group::groupExists($group)) {
if (OCP\App::isEnabled('user_group_admin')) {
OC_User_Group_Admin_Util::createHiddenGroup($group);
} else {
OC_Group::createGroup($group);
}
OC_Log::write('saml', 'New group created: ' . $group, OC_Log::DEBUG);
}
if (OCP\App::isEnabled('user_group_admin')) {
OC_User_Group_Admin_Util::addToGroup($uid, $group);
} else {
OC_Group::addToGroup($uid, $group);
}
OC_Log::write('saml', 'Added "' . $uid . '" to the group "' . $group . '"', OC_Log::DEBUG);
}
}
}
}
示例8: groupExists
public function groupExists($group)
{
return OC_Group::groupExists($group);
}
示例9: strip_tags
exit;
}
if ($idtype == 'event' && !OC_Calendar_App::getEventObject($id)) {
OCP\JSON::error(array('message' => 'permission denied'));
exit;
}
$sharewith = $_GET['sharewith'];
$sharetype = strip_tags($_GET['sharetype']);
switch ($sharetype) {
case 'user':
case 'group':
case 'public':
break;
default:
OCP\JSON::error(array('message' => 'unexspected parameter'));
exit;
}
if ($sharetype == 'user' && !OCP\User::userExists($sharewith)) {
OCP\JSON::error(array('message' => 'user not found'));
exit;
} elseif ($sharetype == 'group' && !OC_Group::groupExists($sharewith)) {
OCP\JSON::error(array('message' => 'group not found'));
exit;
}
$success = OC_Calendar_Share::unshare(OCP\USER::getUser(), $sharewith, $sharetype, $id, $idtype == 'calendar' ? OC_Calendar_Share::CALENDAR : OC_Calendar_Share::EVENT);
if ($success) {
OCP\JSON::success();
} else {
OCP\JSON::error(array('message' => 'can not unshare'));
exit;
}
示例10: getUsersAndGroups
/**
* Generate a string to be used for searching for uid_shared_with that handles both users and groups
* @param $uid (Optional) The uid to get the user groups for, a gid to get the users in a group, or if not set the current user
* @return An IN operator as a string
*/
private static function getUsersAndGroups($uid = null)
{
$in = " IN(";
if (isset($uid) && OC_Group::groupExists($uid)) {
$users = OC_Group::usersInGroup($uid);
foreach ($users as $user) {
// Add a comma only if the the current element isn't the last
if ($user !== end($users)) {
$in .= "'" . $user . "@" . $uid . "', ";
} else {
$in .= "'" . $user . "@" . $uid . "'";
}
}
} else {
if (isset($uid)) {
// TODO Check if this is necessary, only constructor needs it as IN. It would be better for other queries to just return =$uid
$in .= "'" . $uid . "'";
$groups = OC_Group::getUserGroups($uid);
foreach ($groups as $group) {
$in .= ", '" . $uid . "@" . $group . "'";
}
} else {
$uid = OC_User::getUser();
$in .= "'" . $uid . "'";
$groups = OC_Group::getUserGroups($uid);
foreach ($groups as $group) {
$in .= ", '" . $uid . "@" . $group . "'";
}
}
}
$in .= ", '" . self::PUBLICLINK . "'";
$in .= ")";
return $in;
}
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:39,代码来源:owncloud_apps_files_sharing_lib_share.php
示例11: OC_l10n
<?php
/**
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
$l = new OC_l10n('collaboration');
OC::$CLASSPATH['OC_Collaboration_Project'] = 'collaboration/lib/projects.php';
OC::$CLASSPATH['OC_Collaboration_Post'] = 'collaboration/lib/posts.php';
OC::$CLASSPATH['OC_Collaboration_Time'] = 'collaboration/lib/time.php';
OC::$CLASSPATH['OC_Collaboration_Comment'] = 'collaboration/lib/comments.php';
OC::$CLASSPATH['OC_Collaboration_Task'] = 'collaboration/lib/tasks.php';
OC::$CLASSPATH['OC_Collaboration_Mail'] = 'collaboration/lib/mail_templates.php';
OC::$CLASSPATH['OC_Collaboration_Hooks'] = 'collaboration/lib/hooks.php';
OC::$CLASSPATH['OC_Collaboration_Skillset'] = 'collaboration/lib/skillset.php';
OC::$CLASSPATH['OC_Collaboration_Report'] = 'collaboration/lib/reports.php';
OC::$CLASSPATH['OC_Collaboration_Calendar'] = 'collaboration/lib/calendar_support.php';
OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_Collaboration_Hooks', 'notifyUserDeletion');
OC_Hook::connect('OCP\\Share', 'post_shared', 'OC_Collaboration_Hooks', 'notifyFileShare');
$gid = "Collaboration Admin";
if (!OC_Group::groupExists($gid)) {
OC_Group::createGroup($gid);
}
\OCP\App::addNavigationEntry(array('id' => 'collaboration', 'order' => 0, 'href' => \OCP\Util::linkToRoute('collaboration_route', array('rel_path' => '')), 'icon' => \OCP\Util::imagePath('collaboration', 'collaboration.svg'), 'name' => $l->t('Collaboration')));
示例12: dn2ocname
/**
* @brief returns an internal ownCloud name for the given LDAP DN
* @param $dn the dn of the user object
* @param $ldapname optional, the display name of the object
* @param $isUser optional, wether it is a user object (otherwise group assumed)
* @returns string with with the name to use in ownCloud
*
* returns the internal ownCloud name for the given LDAP DN of the user, false on DN outside of search DN
*/
public function dn2ocname($dn, $ldapname = null, $isUser = true)
{
$table = $this->getMapTable($isUser);
if ($isUser) {
$fncFindMappedName = 'findMappedUser';
$nameAttribute = $this->connection->ldapUserDisplayName;
} else {
$fncFindMappedName = 'findMappedGroup';
$nameAttribute = $this->connection->ldapGroupDisplayName;
}
//let's try to retrieve the ownCloud name from the mappings table
$ocname = $this->{$fncFindMappedName}($dn);
if ($ocname) {
return $ocname;
}
//second try: get the UUID and check if it is known. Then, update the DN and return the name.
$uuid = $this->getUUID($dn);
if ($uuid) {
$query = \OCP\DB::prepare('
SELECT `owncloud_name`
FROM `' . $table . '`
WHERE `directory_uuid` = ?
');
$component = $query->execute(array($uuid))->fetchOne();
if ($component) {
$query = \OCP\DB::prepare('
UPDATE `' . $table . '`
SET `ldap_dn` = ?
WHERE `directory_uuid` = ?
');
$query->execute(array($dn, $uuid));
return $component;
}
}
if (is_null($ldapname)) {
$ldapname = $this->readAttribute($dn, $nameAttribute);
if (!isset($ldapname[0]) && empty($ldapname[0])) {
\OCP\Util::writeLog('user_ldap', 'No or empty name for ' . $dn . '.', \OCP\Util::INFO);
return false;
}
$ldapname = $ldapname[0];
}
$ldapname = $this->sanitizeUsername($ldapname);
//a new user/group! Then let's try to add it. We're shooting into the blue with the user/group name, assuming that in most cases there will not be a conflict. Otherwise an error will occur and we will continue with our second shot.
if ($isUser && !\OCP\User::userExists($ldapname) || !$isUser && !\OC_Group::groupExists($ldapname)) {
if ($this->mapComponent($dn, $ldapname, $isUser)) {
return $ldapname;
}
}
//doh! There is a conflict. We need to distinguish between users/groups. Adding indexes is an idea, but not much of a help for the user. The DN is ugly, but for now the only reasonable way. But we transform it to a readable format and remove the first part to only give the path where this object is located.
$oc_name = $this->alternateOwnCloudName($ldapname, $dn);
if ($isUser && !\OCP\User::userExists($oc_name) || !$isUser && !\OC_Group::groupExists($oc_name)) {
if ($this->mapComponent($dn, $oc_name, $isUser)) {
return $oc_name;
}
}
//if everything else did not help..
\OCP\Util::writeLog('user_ldap', 'Could not create unique ownCloud name for ' . $dn . '.', \OCP\Util::INFO);
return false;
}
示例13: ldap2ownCloudNames
private static function ldap2ownCloudNames($ldapObjects, $isUsers)
{
if ($isUsers) {
$knownObjects = self::mappedUsers();
$nameAttribute = self::conf('ldapUserDisplayName');
} else {
$knownObjects = self::mappedGroups();
$nameAttribute = self::conf('ldapGroupDisplayName');
}
$ownCloudNames = array();
foreach ($ldapObjects as $ldapObject) {
$key = self::recursiveArraySearch($knownObjects, $ldapObject['dn']);
//everything is fine when we know the group
if ($key !== false) {
$ownCloudNames[] = $knownObjects[$key]['owncloud_name'];
continue;
}
//we do not take empty usernames
if (!isset($ldapObject[$nameAttribute]) || empty($ldapObject[$nameAttribute])) {
OCP\Util::writeLog('user_ldap', 'No or empty name for ' . $ldapObject['dn'] . ', skipping.', OCP\Util::INFO);
continue;
}
//a new group! Then let's try to add it. We're shooting into the blue with the group name, assuming that in most cases there will not be a conflict. But first make sure, that the display name contains only allowed characters.
$ocname = self::sanitizeUsername($ldapObject[$nameAttribute]);
if ($isUsers && !\OCP\User::userExists($ocname) || !$isUsers && !\OC_Group::groupExists($ocname)) {
if (self::mapComponent($ldapObject['dn'], $ocname, $isUsers)) {
$ownCloudNames[] = $ocname;
continue;
}
}
//doh! There is a conflict. We need to distinguish between groups. Adding indexes is an idea, but not much of a help for the user. The DN is ugly, but for now the only reasonable way. But we transform it to a readable format and remove the first part to only give the path where this entry is located.
$ocname = self::alternateOwnCloudName($ocname, $ldapObject['dn']);
if ($isUsers && !\OCP\User::userExists($ocname) || !$isUsers && !\OC_Group::groupExists($ocname)) {
if (self::mapComponent($ldapObject['dn'], $ocname, $isUsers)) {
$ownCloudNames[] = $ocname;
continue;
}
}
//if everything else did not help..
OCP\Util::writeLog('user_ldap', 'Could not create unique ownCloud name for ' . $ldapObject['dn'] . ', skipping.', OCP\Util::INFO);
}
return $ownCloudNames;
}
示例14: testMultiBackend
function testMultiBackend()
{
$backend1 = new OC_Group_Dummy();
$backend2 = new OC_Group_Dummy();
OC_Group::useBackend($backend1);
OC_Group::useBackend($backend2);
$group1 = uniqid();
$group2 = uniqid();
OC_Group::createGroup($group1);
//groups should be added to the first registered backend
$this->assertEqual(array($group1), $backend1->getGroups());
$this->assertEqual(array(), $backend2->getGroups());
$this->assertEqual(array($group1), OC_Group::getGroups());
$this->assertTrue(OC_Group::groupExists($group1));
$this->assertFalse(OC_Group::groupExists($group2));
$backend1->createGroup($group2);
$this->assertEqual(array($group1, $group2), OC_Group::getGroups());
$this->assertTrue(OC_Group::groupExists($group1));
$this->assertTrue(OC_Group::groupExists($group2));
$user1 = uniqid();
$user2 = uniqid();
$this->assertFalse(OC_Group::inGroup($user1, $group1));
$this->assertFalse(OC_Group::inGroup($user2, $group1));
$this->assertTrue(OC_Group::addToGroup($user1, $group1));
$this->assertTrue(OC_Group::inGroup($user1, $group1));
$this->assertFalse(OC_Group::inGroup($user2, $group1));
$this->assertFalse($backend2->inGroup($user1, $group1));
$this->assertFalse(OC_Group::addToGroup($user1, $group1));
$this->assertEqual(array($user1), OC_Group::usersInGroup($group1));
$this->assertEqual(array($group1), OC_Group::getUserGroups($user1));
$this->assertEqual(array(), OC_Group::getUserGroups($user2));
OC_Group::deleteGroup($group1);
$this->assertEqual(array(), OC_Group::getUserGroups($user1));
$this->assertEqual(array(), OC_Group::usersInGroup($group1));
$this->assertFalse(OC_Group::inGroup($user1, $group1));
}
示例15: updateFolder
private static function updateFolder($uid_shared_with)
{
if ($uid_shared_with != self::PUBLICLINK) {
if (OC_Group::groupExists($uid_shared_with)) {
$uid_shared_with = OC_Group::usersInGroup($uid_shared_with);
// Remove the owner from the list of users in the group
$uid_shared_with = array_diff($uid_shared_with, array(OCP\USER::getUser()));
} else {
if ($uid = strstr($uid_shared_with, '@', true)) {
$uid_shared_with = array($uid);
} else {
$uid_shared_with = array($uid_shared_with);
}
}
foreach ($uid_shared_with as $uid) {
$sharedFolder = $uid . '/files/Shared';
// Update mtime of shared folder to invoke a file cache rescan
$rootView = new OC_FilesystemView('/');
$rootView->touch($sharedFolder);
}
}
}