Exemplo n.º 1
0
/**
 * Add a user to a group
 *
 * @param ElggGroup $group the group to add the user to
 * @param ElggUser  $user  the user to be added
 * @param string    $text  (optional) extra text for the notification
 *
 * @return boolean 	true if successfull
 */
function group_tools_add_user(ElggGroup $group, ElggUser $user, $text = "")
{
    $result = false;
    $loggedin_user = elgg_get_logged_in_user_entity();
    if (!empty($user) && $user instanceof ElggUser && !empty($group) && $group instanceof ElggGroup && !empty($loggedin_user)) {
        // make sure all goes well
        $ia = elgg_set_ignore_access(true);
        if ($group->join($user)) {
            // Remove any invite or join request flags
            remove_entity_relationship($group->getGUID(), "invited", $user->getGUID());
            remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID());
            // notify user
            $subject = elgg_echo("group_tools:groups:invite:add:subject", array($group->name));
            $msg = elgg_echo("group_tools:groups:invite:add:body", array($user->name, $loggedin_user->name, $group->name, $text, $group->getURL()));
            $params = array("group" => $group, "inviter" => $loggedin_user, "invitee" => $user);
            $msg = elgg_trigger_plugin_hook("invite_notification", "group_tools", $params, $msg);
            if (notify_user($user->getGUID(), $group->getOwnerGUID(), $subject, $msg, null, "email")) {
                $result = true;
            }
        }
        // restore access
        elgg_set_ignore_access($ia);
    }
    return $result;
}
Exemplo n.º 2
0
/**
 * Update notifications when a relationship is deleted
 *
 * @param string $event
 * @param string $object_type
 * @param object $relationship
 */
function notifications_relationship_remove($event, $object_type, $relationship)
{
    global $NOTIFICATION_HANDLERS;
    $user_guid = $relationship->guid_one;
    $object_guid = $relationship->guid_two;
    // loop through all notification types
    foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
        remove_entity_relationship($user_guid, "notify{$method}", $object_guid);
    }
}
Exemplo n.º 3
0
 public function testPreventRemoveRelationship()
 {
     $this->assertTrue(add_entity_relationship($this->entity1->guid, 'test_relationship', $this->entity2->guid));
     $r = check_entity_relationship($this->entity1->guid, 'test_relationship', $this->entity2->guid);
     $this->assertIsA($r, 'ElggRelationship');
     elgg_register_event_handler('delete', 'relationship', 'Elgg\\Values::getFalse');
     $this->assertFalse(remove_entity_relationship($this->entity1->guid, 'test_relationship', $this->entity2->guid));
     elgg_unregister_event_handler('delete', 'relationship', 'Elgg\\Values::getFalse');
     $r = check_entity_relationship($this->entity1->guid, 'test_relationship', $this->entity2->guid);
     $this->assertIsA($r, 'ElggRelationship');
 }
Exemplo n.º 4
0
 public function delete()
 {
     $result = false;
     $event = get_entity($this->event_guid);
     $result = remove_entity_relationship($this->event_guid, ZHAOHU_MANAGER_RELATION_ATTENDING, $this->user_guid);
     if (!$result) {
         elgg_log("ZHError ,coupon:delete, failed to remove_entity_relationship, coupon_id {$this->guid}", "ERROR");
         return false;
     }
     parent::delete();
     return true;
 }
Exemplo n.º 5
0
 /**
  * Remove user from chat
  *
  * - Delete the relationship
  * - Delete annotations from the messages
  * - Delete annotations from the chat
  *
  * @param $user
  */
 public function removeMember($user)
 {
     $success = remove_entity_relationship($user->getGUID(), 'member', $this->getGUID());
     $messages = elgg_get_entities_from_relationship(array('relationship' => 'unread', 'relationship_guid' => $user->getGUID(), 'inverse_relationship' => TRUE, 'container_guid' => $this->getGUID()));
     // Remove annotations from messages
     foreach ($messages as $message) {
         remove_entity_relationship($message->getGUID(), 'unread', $user->getGUID());
     }
     // Remove unread_messages annotation from chat
     $this->resetUnreadMessageCount($user);
     return $success;
 }
Exemplo n.º 6
0
/**
 * Update entity categories
 *
 * @param string $event		Equals 'create' or 'update'
 * @param string $type		Equals 'object', 'user' or 'group'
 * @param ElggEntity $entity
 * @return boolean
 */
function update_entity_categories($event, $type, $entity)
{
    if (!elgg_instanceof($entity)) {
        return true;
    }
    $entity_guid = $entity->getGUID();
    // No need to run this handler on multiple update events for this entity
    global $TAXONOMY_CATCH;
    if (isset($TAXONOMY_CATCH[$entity_guid])) {
        return true;
    }
    $TAXONOMY_CATCH[$entity_guid] = true;
    // Restrict the scope of the handler to entity types/subtypes specified in the plugin settings
    $type = $entity->getType();
    $subtype = $entity->getSubtype();
    if (!$subtype) {
        $subtype = 'default';
    }
    $taxonomy_type_subtype_pairs = elgg_get_config('taxonomy_type_subtype_pairs');
    if (!in_array("{$type}:{$subtype}", $taxonomy_type_subtype_pairs)) {
        return true;
    }
    $input_categories = get_input('categories', false);
    //set_input('categories', false); // prevent this handler from running multiple times in case of nested actions
    // Category form input was not present
    if (!$input_categories) {
        return true;
    }
    // User did not specify any categories
    if ($input_categories && !is_array($input_categories)) {
        $input_categories = array();
    }
    $future_categories = array();
    foreach ($input_categories as $guid) {
        $category = get_entity($guid);
        $universal_categories[] = $category->title;
        $hierarchy = get_hierarchy($category->guid, true, true);
        $future_categories = array_merge($future_categories, $hierarchy);
    }
    // Storing categories metadata for compatibility with categories plugin
    $entity->universal_categories = $universal_categories;
    $current_categories = get_entity_categories($entity_guid, array(), true);
    $to_remove = array_diff($current_categories, $future_categories);
    $to_add = array_diff($future_categories, $current_categories);
    foreach ($to_remove as $guid) {
        remove_entity_relationship($entity_guid, HYPECATEGORIES_RELATIONSHIP, $guid);
    }
    foreach ($to_add as $guid) {
        add_entity_relationship($entity_guid, HYPECATEGORIES_RELATIONSHIP, $guid);
    }
    return true;
}
Exemplo n.º 7
0
 public function testCanInsert()
 {
     $time = time();
     $id1 = insert_data("\n\t\t\tINSERT INTO {$this->prefix}entity_relationships\n\t\t\t       (guid_one, relationship, guid_two, time_created)\n\t\t\tVALUES ({$this->user->guid}, 'test_self1', {$this->user->guid}, {$time})\n\t\t\tON DUPLICATE KEY UPDATE time_created = {$time}\n\t\t");
     $id2 = insert_data("\n\t\t\tINSERT INTO {$this->prefix}entity_relationships\n\t\t\t       (guid_one, relationship, guid_two, time_created)\n\t\t\tVALUES (:guid1,   :rel,         :guid2,   :time)\n\t\t\tON DUPLICATE KEY UPDATE time_created = :time\n\t\t", [':guid1' => $this->user->guid, ':guid2' => $this->user->guid, ':rel' => 'test_self2', ':time' => $time]);
     $rows = get_data("\n\t\t\tSELECT *\n\t\t\tFROM {$this->prefix}entity_relationships\n\t\t\tWHERE guid_one = ?\n\t\t\t  AND guid_two = ?\n\t\t\t  AND time_created = ?\n\t\t\tORDER BY id ASC\n\t\t", null, [$this->user->guid, $this->user->guid, $time]);
     $this->assertIsA($id1, 'int');
     $this->assertIsA($id2, 'int');
     $this->assertEqual($rows[0]->id, $id1);
     $this->assertEqual($rows[1]->id, $id2);
     remove_entity_relationship($this->user->guid, 'test_self1', $this->user->guid);
     remove_entity_relationship($this->user->guid, 'test_self2', $this->user->guid);
 }
Exemplo n.º 8
0
 /**
  * Cleanup group admin status on group leave
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param array  $params supplied params
  *
  * @return void|bool
  */
 public static function groupLeave($event, $type, $params)
 {
     $user = elgg_extract('user', $params);
     $group = elgg_extract('group', $params);
     if (!$user instanceof \ElggUser || !$group instanceof \ElggGroup) {
         return;
     }
     // is the user a group admin
     if (!check_entity_relationship($user->getGUID(), 'group_admin', $group->getGUID())) {
         return;
     }
     return remove_entity_relationship($user->getGUID(), 'group_admin', $group->getGUID());
 }
Exemplo n.º 9
0
/**
 * When an expert leaves the site, remove the expert role
 *
 * @param string $event the 'delete' event
 * @param string $type for the 'member_of_site' type
 * @param ElggRelationship $relationship the provided params
 *
 * @return void
 */
function questions_leave_site_handler($event, $type, $relationship)
{
    if (!empty($relationship) && $relationship instanceof ElggRelationship) {
        $user = get_user($relationship->guid_one);
        $site = elgg_get_site_entity($relationship->guid_two);
        if (!empty($user) && !empty($site)) {
            // is the user an expert in this site
            if (check_entity_relationship($user->getGUID(), QUESTIONS_EXPERT_ROLE, $site->getGUID())) {
                // remove the expert role
                remove_entity_relationship($user->getGUID(), QUESTIONS_EXPERT_ROLE, $site->getGUID());
            }
        }
    }
}
Exemplo n.º 10
0
function group_tools_multiple_admin_group_leave($event, $type, $params)
{
    if (!empty($params) && is_array($params)) {
        if (array_key_exists("group", $params) && array_key_exists("user", $params)) {
            $entity = $params["group"];
            $user = $params["user"];
            if ($entity instanceof ElggGroup && $user instanceof ElggUser) {
                if (check_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID())) {
                    return remove_entity_relationship($user->getGUID(), "group_admin", $entity->getGUID());
                }
            }
        }
    }
}
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function delete(ParameterBag $params)
 {
     $user = get_entity($params->guid);
     $friend = $params->friend_uid ? $this->graph->get($params->friend_uid) : elgg_get_logged_in_user_entity();
     if (!$user instanceof ElggUser || !$friend instanceof ElggUser) {
         throw new GraphException("User or friend not found", HttpResponse::HTTP_NOT_FOUND);
     }
     if (!$user->canEdit()) {
         throw new GraphException("You are not allowed to modify this user's friends list", HttpResponse::HTTP_FORBIDDEN);
     }
     if (!remove_entity_relationship($user->guid, "friend", $friend->guid)) {
         throw new GraphException("Unable to remove friendship");
     }
     return array('nodes' => array('friend' => check_entity_relationship($user->guid, 'friend', $friend->guid), 'friend_of' => check_entity_relationship($friend->guid, 'friend', $user->guid)));
 }
Exemplo n.º 12
0
function group_tools_add_user(ElggGroup $group, ElggUser $user, $text = "")
{
    $result = false;
    if (!empty($user) && $user instanceof ElggUser && !empty($group) && $group instanceof ElggGroup && ($loggedin_user = elgg_get_logged_in_user_entity())) {
        if ($group->join($user)) {
            // Remove any invite or join request flags
            remove_entity_relationship($group->getGUID(), "invited", $user->getGUID());
            remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID());
            // notify user
            $subject = elgg_echo("group_tools:groups:invite:add:subject", array($group->name));
            $msg = elgg_echo("group_tools:groups:invite:add:body", array($user->name, $loggedin_user->name, $group->name, $text, $group->getURL()));
            if (notify_user($user->getGUID(), $group->getOwnerGUID(), $subject, $msg)) {
                $result = true;
            }
        }
    }
    return $result;
}
Exemplo n.º 13
0
/**
 * Subscribe a user to the updates of an entity
 *
 * @param int $entity_guid the content entity to subscribe to
 * @param int $user_guid   the user to subscribe (defaults to current user)
 *
 * @return bool
 */
function content_subscriptions_subscribe($entity_guid, $user_guid = 0)
{
    $entity_guid = sanitise_int($entity_guid, false);
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    // remove autosubscription block
    remove_entity_relationship($user_guid, CONTENT_SUBSCRIPTIONS_BLOCK, $entity_guid);
    $notification_services = _elgg_services()->notifications->getMethods();
    if (empty($notification_services)) {
        return false;
    }
    foreach ($notification_services as $service) {
        elgg_add_subscription($user_guid, $service, $entity_guid);
    }
    return true;
}
Exemplo n.º 14
0
 /**
  * Sets the plugin to active or inactive for $site_guid.
  *
  * @param bool  $active    Set to active or inactive
  * @param mixed $site_guid Int for specific site, null for current site.
  *
  * @return bool
  */
 private function setStatus($active, $site_guid = null)
 {
     if (!$this->guid) {
         return false;
     }
     if ($site_guid) {
         $site = get_entity($site_guid);
         if (!$site instanceof \ElggSite) {
             return false;
         }
     } else {
         $site = _elgg_services()->configTable->get('site');
     }
     if ($active) {
         $result = add_entity_relationship($this->guid, 'active_plugin', $site->guid);
     } else {
         $result = remove_entity_relationship($this->guid, 'active_plugin', $site->guid);
     }
     _elgg_invalidate_plugins_provides_cache();
     return $result;
 }
Exemplo n.º 15
0
/**
 * Helper function to transfer the ownership of a group to a new user
 *
 * @param ElggGroup $group     the group to transfer
 * @param ElggUser  $new_owner the new owner
 *
 * @return boolean
 */
function group_tools_transfer_group_ownership(ElggGroup $group, ElggUser $new_owner)
{
    $result = false;
    if (empty($group) || !elgg_instanceof($group, "group") || !$group->canEdit()) {
        return $result;
    }
    if (empty($new_owner) || !elgg_instanceof($new_owner, "user")) {
        return $result;
    }
    $loggedin_user = elgg_get_logged_in_user_entity();
    // register plugin hook to make sure transfer can complete
    elgg_register_plugin_hook_handler("permissions_check", "group", "group_tools_admin_transfer_permissions_hook");
    $old_owner = $group->getOwnerEntity();
    // transfer ownership
    $group->owner_guid = $new_owner->getGUID();
    $group->container_guid = $new_owner->getGUID();
    // make sure user is added to the group
    $group->join($new_owner);
    if ($group->save()) {
        // remove existing group administrator role for new owner
        remove_entity_relationship($new_owner->getGUID(), "group_admin", $group->getGUID());
        // check for group icon
        if (!empty($group->icontime)) {
            $prefix = "groups/" . $group->getGUID();
            $sizes = array("", "tiny", "small", "medium", "large");
            $ofh = new ElggFile();
            $ofh->owner_guid = $old_owner->getGUID();
            $nfh = new ElggFile();
            $nfh->owner_guid = $group->getOwnerGUID();
            foreach ($sizes as $size) {
                // set correct file to handle
                $ofh->setFilename($prefix . $size . ".jpg");
                $nfh->setFilename($prefix . $size . ".jpg");
                // open files
                $ofh->open("read");
                $nfh->open("write");
                // copy file
                $nfh->write($ofh->grabFile());
                // close file
                $ofh->close();
                $nfh->close();
                // cleanup old file
                $ofh->delete();
            }
            $group->icontime = time();
        }
        // move metadata of the group to the new owner
        $options = array("guid" => $group->getGUID(), "limit" => false);
        $metadata = elgg_get_metadata($options);
        if (!empty($metadata)) {
            foreach ($metadata as $md) {
                if ($md->owner_guid == $old_owner->getGUID()) {
                    $md->owner_guid = $new_owner->getGUID();
                    $md->save();
                }
            }
        }
        // notify new owner
        if ($new_owner->getGUID() != $loggedin_user->getGUID()) {
            $subject = elgg_echo("group_tools:notify:transfer:subject", array($group->name));
            $message = elgg_echo("group_tools:notify:transfer:message", array($new_owner->name, $loggedin_user->name, $group->name, $group->getURL()));
            notify_user($new_owner->getGUID(), $group->getGUID(), $subject, $message);
        }
        $result = true;
    }
    // unregister plugin hook to make sure transfer can complete
    elgg_unregister_plugin_hook_handler("permissions_check", "group", "group_tools_admin_transfer_permissions_hook");
    return $result;
}
Exemplo n.º 16
0
if (!empty($group_guid) && !empty($owner_guid)) {
    if (($group = get_entity($group_guid)) && $group instanceof ElggGroup && ($new_owner = get_user($owner_guid))) {
        if ($group->getOwnerGUID() == $loggedin_user->getGUID() || $loggedin_user->isAdmin()) {
            if ($group->getOwnerGUID() != $new_owner->getGUID()) {
                // register plugin hook to make sure transfer can complete
                elgg_register_plugin_hook_handler("permissions_check", "group", "group_tools_admin_transfer_permissions_hook");
                $old_owner = $group->getOwnerEntity();
                // transfer ownership
                $group->owner_guid = $new_owner->getGUID();
                $group->container_guid = $new_owner->getGUID();
                // make sure user is added to the group
                $group->join($new_owner);
                if ($group->save()) {
                    $forward_url = $group->getURL();
                    // remove existing group administrator role for new owner
                    remove_entity_relationship($new_owner->getGUID(), "group_admin", $group->getGUID());
                    // check for group icon
                    if (!empty($group->icontime)) {
                        $prefix = "groups/" . $group->getGUID();
                        $sizes = array("tiny", "small", "medium", "large");
                        $ofh = new ElggFile();
                        $ofh->owner_guid = $old_owner->getGUID();
                        $nfh = new ElggFile();
                        $nfh->owner_guid = $group->getOwnerGUID();
                        foreach ($sizes as $size) {
                            // set correct file to handle
                            $ofh->setFilename($prefix . $size . ".jpg");
                            $nfh->setFilename($prefix . $size . ".jpg");
                            // open files
                            $ofh->open("read");
                            $nfh->open("write");
Exemplo n.º 17
0
/**
 * Remove an object from a site.
 *
 * @param int $site_guid   Site GUID
 * @param int $object_guid Object GUID
 *
 * @return bool
 */
function remove_site_object($site_guid, $object_guid)
{
    $site_guid = (int) $site_guid;
    $object_guid = (int) $object_guid;
    return remove_entity_relationship($object_guid, "member_of_site", $site_guid);
}
/**
 * Function to remove a particular attachment between two objects
 *
 * @param int $guid_one This is the target object
 * @param int $guid_two This is the object to remove from $guid_one
 *
 * @return void
 * @access private
 */
function remove_attachment($guid_one, $guid_two)
{
    if (already_attached($guid_one, $guid_two)) {
        remove_entity_relationship($guid_one, "attached", $guid_two);
    }
}
Exemplo n.º 19
0
<?php

/**
 * Remove photo tag action
 */
$annotation = elgg_get_annotation_from_id(get_input('annotation_id'));
if (!$annotation instanceof ElggAnnotation || $annotation->name != 'phototag') {
    register_error(elgg_echo("tidypics:phototagging:delete:error"));
    forward(REFERER);
}
if (!$annotation->canEdit()) {
    register_error(elgg_echo("tidypics:phototagging:delete:error"));
    forward(REFERER);
}
$entity_guid = $annotation->entity_guid;
$tag = unserialize($annotation->value);
if ($annotation->delete()) {
    if ($tag->type == 'user') {
        remove_entity_relationship($tag->value, 'phototag', $entity_guid);
    }
    system_message(elgg_echo("tidypics:phototagging:delete:success"));
} else {
    system_message(elgg_echo("tidypics:phototagging:delete:error"));
}
forward(REFERER);
Exemplo n.º 20
0
<?php

/**
 * View for chat message objects
 *
 * @package Chat
 */
$entity = elgg_extract('entity', $vars);
$owner = $entity->getOwnerEntity();
$owner_name = $owner->name;
$date = elgg_view_friendly_time($entity->time_created);
$user = elgg_get_logged_in_user_entity();
$time_created = "<span id=\"timestamp\" class=\"hidden\">{$entity->time_created}</span>";
$subtitle = "{$owner_name} {$date} {$time_created}";
$params = array('entity' => $entity, 'metadata' => $metadata, 'subtitle' => $subtitle, 'content' => $entity->description);
$params = $params + $vars;
$list_body = elgg_view('object/elements/summary', $params);
$owner_icon = elgg_view_entity_icon($owner, 'small', array('use_hover' => false));
$not_read = check_entity_relationship($entity->getGUID(), 'unread', $user->getGUID());
if ($not_read) {
    // Additional class to notify that message hasn't been read before.
    $vars['class'] = 'elgg-chat-unread';
    // Mark message read
    remove_entity_relationship($entity->getGUID(), 'unread', $user->getGUID());
}
echo elgg_view_image_block($owner_icon, $list_body, $vars);
Exemplo n.º 21
0
function au_subgroups_remove_parent_group($group_guid)
{
    $group = get_entity($group_guid);
    $parent = au_subgroups_get_parent_group($group);
    if ($parent) {
        remove_entity_relationship($group_guid, AU_SUBGROUPS_RELATIONSHIP, $parent->guid);
    }
}
Exemplo n.º 22
0
/**
 * Remove a collection from a site.
 *
 * @param int $site_guid       Site GUID
 * @param int $collection_guid Collection GUID
 *
 * @return mixed
 * @deprecated 1.8 Don't use this.
 */
function remove_site_collection($site_guid, $collection_guid)
{
    elgg_deprecated_notice("remove_site_collection has been deprecated", 1.8);
    $site_guid = (int) $site_guid;
    $collection_guid = (int) $collection_guid;
    return remove_entity_relationship($collection_guid, "member_of_site", $site_guid);
}
Exemplo n.º 23
0
<?php

$group_guid = get_input('group');
$othergroup_guid = get_input('othergroup');
$group = get_entity($group_guid);
$othergroup = get_entity($othergroup_guid);
if ($group instanceof ElggGroup && $group->canEdit()) {
    if (check_entity_relationship($group_guid, 'related', $othergroup_guid)) {
        remove_entity_relationship($group_guid, 'related', $othergroup_guid);
    }
}
forward(REFERER);
Exemplo n.º 24
0
 /**
  * Enable the entity
  *
  * @warning Disabled entities can't be loaded unless
  * {@link access_show_hidden_entities(true)} has been called.
  *
  * @param bool $recursive Recursively enable all entities disabled with the entity?
  * @see access_show_hiden_entities()
  * @return bool
  */
 public function enable($recursive = true)
 {
     $guid = (int) $this->guid;
     if (!$guid) {
         return false;
     }
     if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
         return false;
     }
     if (!$this->canEdit()) {
         return false;
     }
     global $CONFIG;
     // Override access only visible entities
     $old_access_status = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $result = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities\n\t\t\tSET enabled = 'yes'\n\t\t\tWHERE guid = {$guid}");
     $this->deleteMetadata('disable_reason');
     $this->enableMetadata();
     $this->enableAnnotations();
     if ($recursive) {
         $disabled_with_it = elgg_get_entities_from_relationship(array('relationship' => 'disabled_with', 'relationship_guid' => $guid, 'inverse_relationship' => true, 'limit' => 0));
         foreach ($disabled_with_it as $e) {
             $e->enable();
             remove_entity_relationship($e->guid, 'disabled_with', $guid);
         }
     }
     access_show_hidden_entities($old_access_status);
     if ($result) {
         $this->attributes['enabled'] = 'yes';
         _elgg_services()->events->trigger('enable:after', $this->type, $this);
     }
     return $result;
 }
Exemplo n.º 25
0
/**
 * Block an user from all newsletters
 *
 * @param ElggUser $user The user to block
 *
 * @return boolean True on success, false on failure
 */
function newsletter_unsubscribe_all_user(ElggUser $user)
{
    $result = false;
    if (!empty($user) && elgg_instanceof($user, "user")) {
        $site = elgg_get_site_entity();
        // remove site subscription
        remove_entity_relationship($user->getGUID(), NewsletterSubscription::SUBSCRIPTION, $site->getGUID());
        // remove all subscriptions
        $options = array("type" => "group", "limit" => false, "relationship" => NewsletterSubscription::SUBSCRIPTION, "relationship_guid" => $user->getGUID(), "callback" => "newsletter_row_to_guid");
        $entities = elgg_get_entities_from_relationship($options);
        if (!empty($entities)) {
            foreach ($entities as $entity_guid) {
                remove_entity_relationship($user->getGUID(), NewsletterSubscription::SUBSCRIPTION, $entity_guid);
            }
        }
        // add to general blacklist
        $result = (bool) add_entity_relationship($user->getGUID(), NewsletterSubscription::GENERAL_BLACKLIST, $site->getGUID());
        // remove email subscriptions (if any)
        $subscription = newsletter_get_subscription($user->email);
        if (!empty($subscription)) {
            $subscription->delete();
        }
    }
    return $result;
}
Exemplo n.º 26
0
/**
 * Removes a user from another user's friends list.
 *
 * @param int $user_guid The GUID of the friending user
 * @param int $friend_guid The GUID of the user on the friends list
 * @return true|false Depending on success
 */
function user_remove_friend($user_guid, $friend_guid)
{
    global $CONFIG;
    $user_guid = (int) $user_guid;
    $friend_guid = (int) $friend_guid;
    // perform cleanup for access lists.
    $collections = get_user_access_collections($user_guid);
    foreach ($collections as $collection) {
        remove_user_from_access_collection($friend_guid, $collection->id);
    }
    return remove_entity_relationship($user_guid, "friend", $friend_guid);
}
Exemplo n.º 27
0
            if (!$trip->isMember($user)) {
                if (mytrips_join_trip($trip, $user)) {
                    $subject = elgg_echo('mytrips:welcome:subject', array($trip->name), $user->language);
                    $body = elgg_echo('mytrips:welcome:body', array($user->name, $trip->name, $trip->getURL()), $user->language);
                    $params = ['action' => 'add_membership', 'object' => $trip];
                    // Send welcome notification to user
                    notify_user($user->getGUID(), $trip->owner_guid, $subject, $body, $params);
                    system_message(elgg_echo('mytrips:addedtotrip'));
                    //copio en variable local
                    $follower = $trip->follower;
                    //añado al usuario
                    array_push($follower, $user->getGUID());
                    //vuelvo a copiar el array
                    $trip->follower = $follower;
                } else {
                    $errors[] = elgg_echo('mytrips:error:addedtotrip', array($user->name));
                }
            } else {
                $errors[] = elgg_echo('mytrips:add:alreadymember', array($user->name));
                // if an invitation is still pending clear it up, we don't need it
                remove_entity_relationship($trip->guid, 'invited', $user->guid);
            }
        }
    }
}
if ($errors) {
    foreach ($errors as $error) {
        register_error($error);
    }
}
forward(REFERER);
Exemplo n.º 28
0
/**
 * Join a user to a group, add river event, clean-up invitations
 *
 * @param ElggGroup $group
 * @param ElggUser  $user
 * @return bool
 */
function groups_join_group($group, $user)
{
    global $NOTIFICATION_HANDLERS;
    // access ignore so user can be added to access collection of invisible group
    $ia = elgg_set_ignore_access(TRUE);
    $result = $group->join($user);
    elgg_set_ignore_access($ia);
    if ($result) {
        // flush user's access info so the collection is added
        get_access_list($user->guid, 0, true);
        // Remove any invite or join request flags
        remove_entity_relationship($group->guid, 'invited', $user->guid);
        remove_entity_relationship($user->guid, 'membership_request', $group->guid);
        //check if notifications are turned off for the group
        if ($group->notifications == "false") {
            //turn users notifications off
            foreach ($NOTIFICATION_HANDLERS as $method => $dummy) {
                error_log("group" . $method);
                remove_entity_relationship($user->getGUID(), "notify" . $method, $group->getGUID());
            }
        }
        add_to_river('river/relationship/member/create', 'join', $user->guid, $group->guid);
        return true;
    }
    return false;
}
Exemplo n.º 29
0
/**
 * Join a user to a group, add river event, clean-up invitations
 *
 * @param ElggGroup $group
 * @param ElggUser  $user
 * @return bool
 */
function groups_join_group($group, $user)
{
    // access ignore so user can be added to access collection of invisible group
    $ia = elgg_set_ignore_access(TRUE);
    $result = $group->join($user);
    elgg_set_ignore_access($ia);
    if ($result) {
        // flush user's access info so the collection is added
        get_access_list($user->guid, 0, true);
        // Remove any invite or join request flags
        remove_entity_relationship($group->guid, 'invited', $user->guid);
        remove_entity_relationship($user->guid, 'membership_request', $group->guid);
        elgg_create_river_item(array('view' => 'river/relationship/member/create', 'action_type' => 'join', 'subject_guid' => $user->guid, 'object_guid' => $group->guid));
        return true;
    }
    return false;
}
/**
 * Remove a 'notify' relationship between the user and a content author
 *
 * @param int $user_guid   The GUID of the user who is following a user's content
 * @param int $author_guid The GUID of the user whose content the user wants to unfollow
 *
 * @return true|false Depending on success
 */
function remove_notification_interest($user_guid, $author_guid)
{
    return remove_entity_relationship($user_guid, 'notify', $author_guid);
}