Example #1
0
function group_member_entity_menu_handler($hook, $type, $returnvalue, $params)
{
    $page_owner = elgg_get_page_owner_entity();
    $user = elgg_get_logged_in_user_entity();
    if (!$page_owner instanceof ElggGroup || empty($user) || $page_owner->owner_guid != $user->getGUID()) {
        return $returnvalue;
    }
    $result = $returnvalue;
    if (!empty($params) && is_array($params) && ($user = elgg_get_logged_in_user_entity())) {
        $entity = elgg_extract("entity", $params);
        if (elgg_instanceof($entity, "user") && $entity->getGUID() != $user->getGUID()) {
            if (!empty($result) && !is_array($result)) {
                $result = array($result);
            } elseif (empty($result)) {
                $result = array();
            }
            if (check_entity_relationship($page_owner->getGUID(), "manager", $entity->getGUID())) {
                // pending request
                $result[] = ElggMenuItem::factory(array("name" => "set_group_manager", "text" => elgg_echo("group:setmanager"), "href" => "groups/setmanager/" . $page_owner->getGUID() . "/" . $entity->getGUID(), "is_action" => true, "priority" => 503));
            } else {
                // add as friend
                $result[] = ElggMenuItem::factory(array("name" => "set_group_manager", "text" => elgg_echo("group:removemanager"), "href" => "groups/removemanager/" . $page_owner->getGUID() . "/" . $entity->getGUID(), "is_action" => true, "priority" => 503));
            }
        }
    }
    return $result;
}
Example #2
0
function friend_request_entity_menu_handler($hook, $type, $returnvalue, $params)
{
    $result = $returnvalue;
    if (!empty($params) && is_array($params) && ($user = elgg_get_logged_in_user_entity())) {
        $entity = elgg_extract("entity", $params);
        if (elgg_instanceof($entity, "user") && $entity->getGUID() != $user->getGUID()) {
            if (!empty($result) && !is_array($result)) {
                $result = array($result);
            } elseif (empty($result)) {
                $result = array();
            }
            // are we friends
            if (!$entity->isFriendOf($user->getGUID())) {
                // no, check if pending request
                if (check_entity_relationship($user->getGUID(), "friendrequest", $entity->getGUID())) {
                    // pending request
                    $result[] = ElggMenuItem::factory(array("name" => "friend_request", "text" => elgg_echo("friend_request:friend:add:pending"), "href" => "friend_request/" . $user->username . "#friend_request_sent_listing", "priority" => 500));
                } else {
                    // add as friend
                    $result[] = ElggMenuItem::factory(array("name" => "add_friend", "text" => elgg_echo("friend:add"), "href" => "action/friends/add?friend=" . $entity->getGUID(), "is_action" => true, "priority" => 500));
                }
            } else {
                // is friend, se remove friend link
                $result[] = ElggMenuItem::factory(array("name" => "remove_friend", "text" => elgg_echo("friend:remove"), "href" => "action/friends/remove?friend=" . $entity->getGUID(), "is_action" => true, "priority" => 500));
            }
        }
    }
    return $result;
}
/**
 * Is $blocked_user blocked by $blocking_user?
 *
 * @param ElggUser $blocked_user
 * @param ElggUser $blocking_user
 * @return type bool
 */
function is_blocked(\ElggUser $blocked_user, \ElggUser $blocking_user)
{
    if (!$blocked_user instanceof \ElggUser || !$blocking_user instanceof \ElggUser) {
        return false;
    }
    return (bool) check_entity_relationship($blocking_user->getGUID(), 'blocked', $blocked_user->getGUID());
}
Example #4
0
/**
 * Retrieve ancestry relationships / update if they have changed
 *
 * @param int $guid
 * @param mixed $subtypes
 * @return boolean|array
 */
function hj_framework_set_ancestry($guid)
{
    $entity = get_entity($guid);
    if (!$entity) {
        return false;
    }
    $ia = elgg_set_ignore_access(true);
    // Build an hierarchy from [0]highest to [X]lowest
    $ancestry = array();
    $ancestry_guids = array();
    $container = $entity->getContainerEntity();
    while (elgg_instanceof($container)) {
        array_unshift($ancestry, $container);
        array_unshift($ancestry_guids, $container->guid);
        $container = $container->getContainerEntity();
    }
    // Store as a hash so we don't unnecessarily update the hierarchy every time save() is calleed
    if (!isset($entity->hierarchy_hash) || $entity->hierarchy_hash != sha1(serialize($ancestry_guids))) {
        remove_entity_relationships($entity->guid, 'descendant', false);
        foreach ($ancestry as $ancestor) {
            if (elgg_instanceof($ancestor, 'object')) {
                update_entity_last_action($ancestor->guid, $entity->time_created);
            }
            if (!check_entity_relationship($entity->guid, 'descendant', $ancestor->guid)) {
                add_entity_relationship($entity->guid, 'descendant', $ancestor->guid);
            }
        }
        $entity->hierarchy_hash = sha1(serialize($ancestry_guids));
    }
    elgg_set_ignore_access($ia);
    return $ancestry;
}
Example #5
0
 /**
  * Checks if a given user is waiting for this slot
  *
  * @param string $user_guid guid of the user
  *
  * @return ElggRelationship|false
  */
 public function isUserWaiting($user_guid = null)
 {
     if (empty($user_guid)) {
         $user_guid = elgg_get_logged_in_user_guid();
     }
     return check_entity_relationship($user_guid, EVENT_MANAGER_RELATION_SLOT_REGISTRATION_WAITINGLIST, $this->getGUID());
 }
function au_staff_options($pageowner)
{
    $user = elgg_get_logged_in_user_entity();
    $group = elgg_get_page_owner_entity();
    if (elgg_instanceof($group, 'group')) {
        //check group attributes - ignore if au staff
        if ($group->staff_only_enable == 'yes') {
            elgg_extend_view('group/default', 'groups/sidebar/staff_only', 502);
            //do stuff if this is a staff-only group
            //system_message("AU staff-only group: only AU staff members can join this group");
            if (elgg_is_logged_in()) {
                $invited = check_entity_relationship($group->getGUID(), "invited", $user->getGUID());
                //allow invited users in
                if (is_au_staff_member($user) || elgg_is_admin_logged_in() || $group->canEdit() || $invited) {
                    //do other stuff - welcome here
                } else {
                    //remove buttons for non staff members who are not members of the group and not invited
                    if (!$group->isMember($user)) {
                        elgg_register_plugin_hook_handler('register', 'menu:title', 'au_landing_remove_group_join_button', 9999);
                        //remove the link we added in groups_ux to allow joining from discussion forum
                        elgg_unextend_view('discussion/replies', 'discussion/replies/join');
                    }
                }
            }
        } else {
            //this is a normal group
        }
    } else {
        //not a group, do nothing
    }
}
/**
 * Make sure the user from profile_sync is a member of the site
 *
 * @param string $event  the name of the event
 * @param string $type   the type of the event
 * @param mixed  $object supplied object
 *
 * @return void
 */
function theme_haarlem_intranet_profile_sync_site_membership($event, $type, $object)
{
    if (empty($object) || !is_array($object)) {
        return;
    }
    $user = elgg_extract('entity', $object);
    if (empty($user) || !elgg_instanceof($user, 'user')) {
        return;
    }
    $datasource = elgg_extract('datasource', $object);
    if (empty($datasource) || !elgg_instanceof($datasource, 'object', 'profile_sync_datasource')) {
        return;
    }
    if ($datasource->datasource_type !== 'csv') {
        return;
    }
    $csv_location = $datasource->csv_location;
    $csv_filename = basename($csv_location);
    $site = elgg_get_site_entity();
    $is_member = check_entity_relationship($user->getGUID(), 'member_of_site', $site->getGUID());
    if ($csv_filename === 'pleio_removed.csv') {
        if ($is_member) {
            $site->removeUser($user->getGUID());
        }
        return;
    }
    if (!$is_member) {
        // not a member, so add
        $site->addUser($user->getGUID());
    }
}
/**
 * Has the current user has dugg the plugin project
 * @param $project
 * @return bool
 */
function plugins_is_dugg($project)
{
    if (check_entity_relationship(get_loggedin_userid(), "has_dugg", $project->guid)) {
        return TRUE;
    } else {
        return FALSE;
    }
}
Example #9
0
/**
 * Register user hover menu items
 */
function hj_inbox_user_hover_menu_setup($hook, $type, $return, $params)
{
    $recipient = elgg_extract('entity', $params);
    $sender = elgg_get_logged_in_user_entity();
    if (!$sender || !$recipient) {
        return $return;
    }
    if ($sender->guid == $recipient->guid) {
        return $return;
    }
    $message_types = elgg_get_config('inbox_message_types');
    $user_types = elgg_get_config('inbox_user_types');
    foreach ($message_types as $type => $options) {
        if ($type == HYPEINBOX_NOTIFICATION) {
            continue;
        }
        $valid = false;
        $policies = $options['policy'];
        if (!$policies) {
            $valid = true;
        } else {
            foreach ($policies as $policy) {
                $valid = false;
                $recipient_type = $policy['recipient'];
                $sender_type = $policy['sender'];
                $relationship = $policy['relationship'];
                $inverse_relationship = $policy['inverse_relationship'];
                $group_relationship = $policy['group_relationship'];
                $recipient_validator = $user_types[$recipient_type]['validator'];
                if ($recipient_type == 'all' || $recipient_validator && is_callable($recipient_validator) && call_user_func($recipient_validator, $recipient, $recipient_type)) {
                    $sender_validator = $user_types[$sender_type]['validator'];
                    if ($sender_type == 'all' || $sender_validator && is_callable($sender_validator) && call_user_func($sender_validator, $sender, $sender_type)) {
                        $valid = true;
                        if ($relationship && $relationship != 'all') {
                            if ($inverse_relationship) {
                                $valid = check_entity_relationship($recipient->guid, $relationship, $sender->guid);
                            } else {
                                $valid = check_entity_relationship($sender->guid, $relationship, $recipient->guid);
                            }
                        }
                        if ($valid && $group_relationship && $group_relationship != 'all') {
                            $dbprefix = elgg_get_config('dbprefix');
                            $valid = elgg_get_entities_from_relationship(array('types' => 'group', 'relationship' => 'member', 'relationship_guid' => $recipient->guid, 'count' => true, 'wheres' => array("EXISTS (SELECT * FROM {$dbprefix}entity_relationships WHERE guid_one = {$sender->guid} AND relationship = '{$group_relationship}' AND guid_two = r.guid_two)")));
                        }
                    }
                }
                if ($valid) {
                    break;
                }
            }
        }
        if ($valid) {
            $return[] = ElggMenuItem::factory(array('name' => "messages:{$type}", 'text' => elgg_echo("hj:inbox:send", array(strtolower(elgg_echo("item:object:message:{$type}:singular")))), 'href' => elgg_http_add_url_query_elements("messages/compose", array('message_type' => $type, 'send_to' => $recipient->guid)), 'section' => 'action'));
        }
    }
    return $return;
}
 public function testGroupSubscriptionRemovedWhenMemberRelationshipRemoved()
 {
     $this->group->join($this->user1);
     $this->assertTrue($this->group->isMember($this->user1));
     elgg_add_subscription($this->user1->guid, 'test', $this->group->guid);
     $this->assertIsA(check_entity_relationship($this->user1->guid, 'notifytest', $this->group->guid), ElggRelationship::class);
     $this->group->leave($this->user1);
     $this->assertFalse($this->group->isMember($this->user1));
     $this->assertFalse(check_entity_relationship($this->user1->guid, 'notifytest', $this->user2->guid));
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function post(ParameterBag $params)
 {
     $user = get_entity($params->guid);
     $site = elgg_get_site_entity();
     if (!$user || !$site || !check_entity_relationship($user->guid, 'member_of_site', $site->guid)) {
         throw new GraphException("User is not a member of this site", 403);
     }
     $token = hypeGraph()->tokens->create($user, $site);
     if (!$token) {
         throw new GraphException("Unable to generate a new user token", 500);
     }
     return array('token' => $token->token, 'expires' => date(DATE_ATOM, $token->expires), 'user' => $user, 'site_uid' => "se{$token->site_guid}");
 }
Example #12
0
 /**
  * Change the name/function of the group join button
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value current return value
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function groupMembership($hook, $type, $return_value, $params)
 {
     if (!elgg_in_context('groups')) {
         return;
     }
     $page_owner = elgg_get_page_owner_entity();
     $user = elgg_get_logged_in_user_entity();
     if (!$page_owner instanceof \ElggGroup || !$user instanceof \ElggUser) {
         return;
     }
     if (empty($return_value) || !is_array($return_value)) {
         return;
     }
     foreach ($return_value as $menu_item) {
         // group join button?
         if ($menu_item->getName() !== 'groups:joinrequest') {
             continue;
         }
         if (check_entity_relationship($user->getGUID(), 'membership_request', $page_owner->getGUID())) {
             // user already requested to join this group
             $menu_item->setText(elgg_echo('group_tools:joinrequest:already'));
             $menu_item->setTooltip(elgg_echo('group_tools:joinrequest:already:tooltip'));
             $menu_item->setHref("action/groups/killrequest?user_guid={$user->getGUID()}&group_guid={$page_owner->getGUID()}");
             $menu_item->is_action = true;
         } elseif (check_entity_relationship($page_owner->getGUID(), 'invited', $user->getGUID())) {
             // the user was invited, so let him/her join
             $menu_item->setName('groups:join');
             $menu_item->setText(elgg_echo('groups:join'));
             $menu_item->setTooltip(elgg_echo('group_tools:join:already:tooltip'));
             $menu_item->setHref("action/groups/join?user_guid={$user->getGUID()}&group_guid={$page_owner->getGUID()}");
             $menu_item->is_action = true;
         } elseif (group_tools_check_domain_based_group($page_owner, $user)) {
             // user has a matching email domain
             $menu_item->setName('groups:join');
             $menu_item->setText(elgg_echo('groups:join'));
             $menu_item->setTooltip(elgg_echo('group_tools:join:domain_based:tooltip'));
             $menu_item->setHref("action/groups/join?user_guid={$user->getGUID()}&group_guid={$page_owner->getGUID()}");
             $menu_item->is_action = true;
         } elseif (group_tools_join_motivation_required($page_owner)) {
             // a join motivation is required
             elgg_load_js('lightbox');
             elgg_load_css('lightbox');
             $menu_item->setHref("ajax/view/group_tools/forms/motivation?guid={$page_owner->getGUID()}");
             $menu_item->addLinkClass('elgg-lightbox');
             $opts = 'data-colorbox-opts';
             $menu_item->{$opts} = json_encode(['width' => '500px']);
         }
         break;
     }
     return $return_value;
 }
Example #13
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());
                }
            }
        }
    }
}
Example #14
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());
            }
        }
    }
}
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $relationship = check_entity_relationship($this->user->guid, 'tagged_in', $this->entity->guid);
     if ($relationship instanceof \ElggRelationship) {
         if ($relationship->delete()) {
             elgg_delete_river(array('subject_guids' => $this->user->guid, 'object_guids' => $this->entity->guid, 'action_types' => 'tagged'));
             /**
              * @todo: remove from access collection?
              */
             $this->result->addMessage(elgg_echo('wall:remove_tag:success'));
             return;
         }
     }
     $this->result->addError(elgg_echo('wall:remove_tag:error'));
 }
Example #16
0
function entity_admins_permission_check($hook, $entity_type, $returnvalue, $params)
{
    if ($returnvalue) {
        return $returnvalue;
    }
    $e = $params['entity'];
    if ($e) {
        $user_guid = elgg_get_logged_in_user_guid();
        $guid = $e->guid;
        if ($user_guid && $guid && check_entity_relationship($user_guid, 'entity_admin_for', $guid)) {
            return true;
        }
    }
    return false;
}
Example #17
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)));
 }
Example #18
0
/**
 * Web service for joining a group
 *
 * @param string $username username of author
 * @param string $groupid  GUID of the group
 *
 * @return bool
 */
function group_join($username, $groupid)
{
    $user = get_user_by_username($username);
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $group = get_entity($groupid);
    $return['success'] = false;
    if ($user instanceof ElggUser && $group instanceof ElggGroup) {
        // join or request
        $join = false;
        if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
            // anyone can join public groups and admins can join any group
            $join = true;
        } else {
            if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
                // user has invite to closed group
                $join = true;
            }
        }
        if ($join) {
            if (groups_join_group($group, $user)) {
                $return['success'] = true;
                $return['message'] = elgg_echo("groups:joined");
            } else {
                $return['message'] = elgg_echo("groups:cantjoin");
            }
        } else {
            add_entity_relationship($user->guid, 'membership_request', $group->guid);
            // Notify group owner
            $url = "{$CONFIG->url}mod/groups/membershipreq.php?group_guid={$group->guid}";
            $subject = elgg_echo('groups:request:subject', array($user->name, $group->name));
            $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url));
            if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) {
                $return['success'] = true;
                $return['message'] = elgg_echo("groups:joinrequestmade");
            } else {
                $return['message'] = elgg_echo("groups:joinrequestnotmade");
            }
        }
    } else {
        $return['message'] = elgg_echo("groups:cantjoin");
    }
    return $return;
}
Example #19
0
/**
 * Get page components to list a user's or all news.
 *
 * @param int $container_guid The GUID of the page owner or null for all news
 * @return array
 */
function news_get_page_content_list($container_guid = null)
{
    $return = array();
    $return['filter_context'] = $container_guid ? 'mine' : 'all';
    $return['filter'] = '';
    $options = array('type' => 'object', 'subtype' => 'news', 'full_view' => false, 'no_results' => elgg_echo('news:none'), 'preload_owners' => true, 'distinct' => false);
    $current_user = elgg_get_logged_in_user_entity();
    if ($container_guid) {
        // access check for closed groups
        elgg_group_gatekeeper();
        $container = get_entity($container_guid);
        if ($container instanceof ElggGroup) {
            $options['container_guid'] = $container_guid;
        } else {
            $options['owner_guid'] = $container_guid;
        }
        $return['title'] = elgg_echo('news:title:user_news', array($container->name));
        $crumbs_title = $container->name;
        elgg_push_breadcrumb($crumbs_title);
        if ($current_user && $container_guid == $current_user->guid) {
            $return['filter_context'] = 'mine';
        } else {
            if (elgg_instanceof($container, 'group')) {
                $return['filter'] = false;
            } else {
                // do not show button or select a tab when viewing someone else's posts
                $return['filter_context'] = 'none';
            }
        }
    } else {
        $options['preload_containers'] = true;
        $return['filter_context'] = 'all';
        $return['title'] = elgg_echo('news:title:all_news');
        elgg_pop_breadcrumb();
        elgg_push_breadcrumb(elgg_echo('news:news'));
    }
    if (elgg_is_admin_logged_in() || $container_guid && elgg_instanceof($container, 'group') && ($container->owner_guid == $current_user->guid || check_entity_relationship($current_user->guid, "group_admin", $container->guid))) {
        elgg_register_title_button();
    }
    $return['content'] = elgg_list_entities($options);
    return $return;
}
Example #20
0
 /**
  * Change the join status menu item
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value current return value
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function registerJoinStatus($hook, $type, $return_value, $params)
 {
     $entity = elgg_extract('entity', $params);
     if (!$entity instanceof \ElggGroup) {
         return;
     }
     $user = elgg_get_logged_in_user_entity();
     if (empty($user)) {
         return;
     }
     foreach ($return_value as $menu_item) {
         if ($menu_item->getName() !== 'membership_status') {
             continue;
         }
         if ($menu_item->getText() !== elgg_echo('groups:join')) {
             // @todo this should be nicer, but Elgg give the same name to 3 use cases??!!!
             continue;
         }
         if (check_entity_relationship($user->getGUID(), 'membership_request', $entity->getGUID())) {
             // user already requested to join this group
             $menu_item->setText(elgg_echo('group_tools:joinrequest:already'));
             $menu_item->setTooltip(elgg_echo('group_tools:joinrequest:already:tooltip'));
             $menu_item->setHref("action/groups/killrequest?user_guid={$user->getGUID()}&group_guid={$entity->getGUID()}");
             $menu_item->is_action = true;
         } elseif (check_entity_relationship($entity->getGUID(), 'invited', $user->getGUID())) {
             // the user was invited, so let him/her join
             $menu_item->setTooltip(elgg_echo('group_tools:join:already:tooltip'));
         } elseif (group_tools_check_domain_based_group($entity, $user)) {
             // user has a matching email domain
             $menu_item->setTooltip(elgg_echo('group_tools:join:domain_based:tooltip'));
         } elseif (group_tools_join_motivation_required($entity)) {
             // a join motivation is required
             elgg_load_js('lightbox');
             elgg_load_css('lightbox');
             $menu_item->setHref("ajax/view/group_tools/forms/motivation?guid={$entity->getGUID()}");
             $menu_item->addLinkClass('elgg-lightbox');
             $opts = 'data-colorbox-opts';
             $menu_item->{$opts} = json_encode(['width' => '500px']);
         }
     }
 }
Example #21
0
 /**
  * Add menu items to the hover menu
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value the current return value
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function registerUserHoverMenu($hook, $type, $return_value, $params)
 {
     if (empty($params) || !is_array($params)) {
         return;
     }
     $user = elgg_get_logged_in_user_entity();
     if (empty($user)) {
         return;
     }
     $entity = elgg_extract('entity', $params);
     if (!$entity instanceof \ElggUser) {
         return;
     }
     if ($entity->getGUID() === $user->getGUID()) {
         // looking at yourself
         return;
     }
     $requested = check_entity_relationship($user->getGUID(), 'friendrequest', $entity->getGUID());
     $is_friend = $entity->isFriend($user->getGUID());
     foreach ($return_value as $index => $item) {
         // change the text of the button to tell you already requested a friendship
         switch ($item->getName()) {
             case 'add_friend':
                 if ($requested) {
                     $item->setItemClass('hidden');
                 }
                 break;
             case 'remove_friend':
                 if (!$requested && !$is_friend) {
                     unset($return_value[$index]);
                 }
                 break;
         }
     }
     if ($requested) {
         $return_value[] = \ElggMenuItem::factory(['name' => 'friend_request', 'text' => elgg_echo('friend_request:friend:add:pending'), 'href' => "friend_request/{$user->username}#friend_request_sent_listing", 'section' => 'action']);
     }
     return $return_value;
 }
Example #22
0
/**
 * Adds group events to the default calendar of interested members
 * 
 * @param int $event_guid GUID of the event
 * @param int $group_guid GUID of the group
 * @return void
 */
function autosync_group_event($event_guid, $group_guid)
{
    $ia = elgg_set_ignore_access(true);
    // note that this function can be called after shutdown with vroom
    // using guids for params so that we're not performing operations on potentially stale entities
    $event = get_entity($event_guid);
    $group = get_entity($group_guid);
    if (!$event instanceof Event || !$group instanceof ElggGroup) {
        return false;
    }
    // get group members
    $options = array('type' => 'user', 'relationship' => 'member', 'relationship_guid' => $group->guid, 'inverse_relationship' => true, 'limit' => false);
    $users = new ElggBatch('elgg_get_entities_from_relationship', $options);
    foreach ($users as $u) {
        // only add to the calendar if they have not opted out
        if (!check_entity_relationship($u->guid, 'calendar_nosync', $group->guid)) {
            // they have not opted out, we should add it to their calendars
            $calendar = Calendar::getPublicCalendar($u);
            $calendar->addEvent($event);
        }
    }
    elgg_set_ignore_access($ia);
}
Example #23
0
/**
 * Check if a user is an expert
 *
 * @param ElggEntity $container the container where a question was asked, leave empty for any relationship
 * @param ElggUser   $user      the user to check (defaults to current user)
 *
 * @return bool
 */
function questions_is_expert(ElggEntity $container = null, ElggUser $user = null)
{
    $result = false;
    // make sure we have a user
    if (!$user instanceof ElggUser) {
        $user = elgg_get_logged_in_user_entity();
    }
    if (empty($user)) {
        return false;
    }
    if ($container instanceof ElggEntity) {
        if ($container instanceof ElggUser) {
            $container = elgg_get_site_entity();
        }
        if ($container instanceof ElggSite || $container instanceof ElggGroup) {
            if (check_entity_relationship($user->getGUID(), QUESTIONS_EXPERT_ROLE, $container->getGUID())) {
                // user has the expert role
                $result = true;
            }
        }
    } else {
        $expert_options = ['count' => true, 'relationship' => QUESTIONS_EXPERT_ROLE, 'relationship_guid' => $user->getGUID()];
        if (elgg_get_entities_from_relationship($expert_options)) {
            // check if user has any expert relationship with entity on this site
            $result = true;
        }
        if (!$result) {
            // added specific check for Subsite Manager plugin where site has no current site entity set as entity_guid
            if (check_entity_relationship($user->getGUID(), QUESTIONS_EXPERT_ROLE, elgg_get_site_entity()->getGUID())) {
                // user has the expert role for this site
                $result = true;
            }
        }
    }
    return $result;
}
Example #24
0
  * data structure
  * data[0] => displayname
  * data[1] => e-mail address
  */
 $email = "";
 if (isset($data[1])) {
     $email = trim($data[1]);
 }
 if (!empty($email) && is_email_address($email)) {
     $users = get_user_by_email($email);
     if (!empty($users)) {
         // found a user with this email on the site, so invite (or add)
         $user = $users[0];
         if (!$group->isMember($user)) {
             if (!$adding) {
                 if (!check_entity_relationship($group->getGUID(), "invited", $user->getGUID()) || $resend) {
                     // invite user
                     if (group_tools_invite_user($group, $user, $text, $resend)) {
                         $invited++;
                     }
                 } else {
                     // user was already invited
                     $already_invited++;
                 }
             } else {
                 if (group_tools_add_user($group, $user, $text)) {
                     $join++;
                 }
             }
         } else {
             $member++;
Example #25
0
 */
// Load configuration
global $CONFIG;
gatekeeper();
$user_guid = get_input('user_guid');
if (!is_array($user_guid)) {
    $user_guid = array($user_guid);
}
$dgroup_guid = get_input('dgroup_guid');
if (sizeof($user_guid)) {
    foreach ($user_guid as $u_id) {
        $user = get_entity($u_id);
        $dgroup = get_entity($dgroup_guid);
        if ($user && $dgroup) {
            if (get_loggedin_userid() == $dgroup->owner_guid) {
                if (!check_entity_relationship($dgroup->guid, 'invited', $user->guid)) {
                    if ($user->isFriend()) {
                        // Create relationship
                        add_entity_relationship($dgroup->guid, 'invited', $user->guid);
                        // Send email
                        if (notify_user($user->getGUID(), $dgroup->owner_guid, sprintf(elgg_echo('dgroups:invite:subject'), $user->name, $dgroup->name), sprintf(elgg_echo('dgroups:invite:body'), $user->name, $dgroup->name, "{$CONFIG->url}action/dgroups/join?user_guid={$user->guid}&dgroup_guid={$dgroup->guid}"), NULL)) {
                            system_message(elgg_echo("dgroups:userinvited"));
                        } else {
                            register_error(elgg_echo("dgroups:usernotinvited"));
                        }
                    } else {
                        register_error(elgg_echo("dgroups:usernotinvited"));
                    }
                } else {
                    register_error(elgg_echo("dgroups:useralreadyinvited"));
                }
Example #26
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);
Example #27
0
/**
 * Convert an email subscription on the newsletters to a user setting
 *
 * @param NewsletterSubscription $subscription The found email subscription
 * @param ElggUser               $user         The user to save the new settings to
 *
 * @return bool	true on success or false on failure
 */
function newsletter_convert_subscription_to_user_setting(NewsletterSubscription $subscription, ElggUser $user)
{
    $result = false;
    if (!empty($subscription) && elgg_instanceof($subscription, "object", NewsletterSubscription::SUBTYPE) && !empty($user) && elgg_instanceof($user, "user")) {
        // check global block list
        $site = elgg_get_site_entity();
        if (check_entity_relationship($subscription->getGUID(), NewsletterSubscription::GENERAL_BLACKLIST, $site->getGUID())) {
            // copy the block all
            add_entity_relationship($user->getGUID(), NewsletterSubscription::GENERAL_BLACKLIST, $site->getGUID());
        } else {
            // check for subscriptions
            $subscriptions = $subscription->getEntitiesFromRelationship(NewsletterSubscription::SUBSCRIPTION, false, false);
            if (!empty($subscriptions)) {
                foreach ($subscriptions as $entity) {
                    newsletter_subscribe_user($user, $entity);
                }
            }
            // check for blocks
            $blocked = $subscription->getEntitiesFromRelationship(NewsletterSubscription::BLACKLIST, false, false);
            if (!empty($blocked)) {
                foreach ($blocked as $entity) {
                    newsletter_unsubscribe_user($user, $entity);
                }
            }
        }
        // remove email subscription
        $result = (bool) $subscription->delete();
    }
    return $result;
}
function sched_conf_entity_menu_setup($hook, $type, $return, $params)
{
    if (elgg_in_context('widgets')) {
        return $return;
    }
    elgg_load_library('elgg:sched_conf');
    $entity = $params['entity'];
    $entity = sched_conf_get_event_for_conference($entity->guid);
    $handler = elgg_extract('handler', $params, false);
    if ($handler != 'sched_conf') {
        return $return;
    }
    $user_guid = elgg_get_logged_in_user_guid();
    if (event_calendar_personal_can_manage($entity, $user_guid)) {
        if (event_calendar_has_personal_event($entity->guid, $user_guid)) {
            $options = array('name' => 'personal_calendar', 'text' => elgg_echo('event_calendar:remove_from_the_calendar_menu_text'), 'title' => elgg_echo('event_calendar:remove_from_my_calendar'), 'href' => elgg_add_action_tokens_to_url("action/event_calendar/remove_personal?guid={$entity->guid}"), 'priority' => 150);
            $return[] = ElggMenuItem::factory($options);
        } else {
            if (!event_calendar_is_full($entity->guid) && !event_calendar_has_collision($entity->guid, $user_guid)) {
                $options = array('name' => 'personal_calendar', 'text' => elgg_echo('event_calendar:add_to_the_calendar_menu_text'), 'title' => elgg_echo('event_calendar:add_to_my_calendar'), 'href' => elgg_add_action_tokens_to_url("action/event_calendar/add_personal?guid={$entity->guid}"), 'priority' => 150);
                $return[] = ElggMenuItem::factory($options);
            }
        }
    } else {
        if (!event_calendar_has_personal_event($entity->guid, $user_guid) && !check_entity_relationship($user_guid, 'event_calendar_request', $entity->guid)) {
            $options = array('name' => 'personal_calendar', 'text' => elgg_echo('event_calendar:make_request_title'), 'title' => elgg_echo('event_calendar:make_request_title'), 'href' => elgg_add_action_tokens_to_url("action/event_calendar/request_personal_calendar?guid={$entity->guid}"), 'priority' => 150);
            $return[] = ElggMenuItem::factory($options);
        }
    }
    $count = event_calendar_get_users_for_event($entity->guid, 0, 0, true);
    if ($count == 1) {
        $calendar_text = elgg_echo('event_calendar:personal_event_calendars_link_one');
    } else {
        $calendar_text = elgg_echo('event_calendar:personal_event_calendars_link', array($count));
    }
    $options = array('name' => 'calendar_listing', 'text' => $calendar_text, 'title' => elgg_echo('event_calendar:users_for_event_menu_title'), 'href' => "event_calendar/display_users/{$entity->guid}", 'priority' => 150);
    $return[] = ElggMenuItem::factory($options);
    /*if (elgg_is_admin_logged_in() && (elgg_get_plugin_setting('allow_featured', 'event_calendar') == 'yes')) {
    		if ($event->featured) {
    			add_submenu_item(elgg_echo('event_calendar:unfeature'), $CONFIG->url . "action/event_calendar/unfeature?event_id=".$event_id.'&'.event_calendar_security_fields(), 'eventcalendaractions');
    		} else {
    			add_submenu_item(elgg_echo('event_calendar:feature'), $CONFIG->url . "action/event_calendar/feature?event_id=".$event_id.'&'.event_calendar_security_fields(), 'eventcalendaractions');
    		}
    	}*/
    return $return;
}
 * 
 * @package ElggProfile
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Curverider Ltd <*****@*****.**>
 * @copyright Curverider Ltd 2008-2010
 * @link http://elgg.com/
 * 
 * @uses $vars['entity'] The user entity
 */
$icon = elgg_view("profile/icon", array('entity' => $vars['entity'], 'size' => 'medium'));
$banned = $vars['entity']->isBanned();
$rel = "";
if (page_owner() == $vars['entity']->guid) {
    $rel = 'me';
} else {
    if (check_entity_relationship(page_owner(), 'friend', $vars['entity']->guid)) {
        $rel = 'friend';
    }
}
if (!$banned) {
    $info .= "<p><b><a href=\"" . $vars['entity']->getUrl() . "\" rel=\"{$rel}\">" . $vars['entity']->name . "</a></b></p>";
} else {
    $info .= "<p><b><strike>" . $vars['entity']->name . "</b></strike><br />" . elgg_echo('profile:banned') . "</p>";
}
// TODO: look into a way to pass $authorised and $event_id in $vars
$authorised = FALSE;
$event_id = get_input('event_id', 0);
if ($event_id) {
    if (isadminloggedin()) {
        $authorised = TRUE;
    } else {
Example #30
0
 /**
  * Is this plugin active?
  *
  * @param int $site_guid Optional site guid.
  * @return bool
  */
 public function isActive($site_guid = null)
 {
     if (!$this->guid) {
         return false;
     }
     if ($site_guid) {
         $site = get_entity($site_guid);
     } else {
         $site = _elgg_services()->configTable->get('site');
     }
     if (!$site instanceof \ElggSite) {
         return false;
     }
     return check_entity_relationship($this->guid, 'active_plugin', $site->guid);
 }