/**
  * Checks if additional select columns are readable as volatile data even if we hit the cache while fetching entity.
  *
  * https://github.com/Elgg/Elgg/issues/5544
  */
 public function testSqlAdditionalSelectsAsVolatileDataWithCache()
 {
     // remove ignore access as it disables entity cache
     $access = elgg_set_ignore_access(false);
     // may not have groups in DB - let's create one
     $group = new ElggGroup();
     $group->name = 'test_group';
     $group->access_id = ACCESS_PUBLIC;
     $this->assertTrue($group->save() !== false);
     foreach (array('site', 'user', 'group', 'object') as $type) {
         $entities = elgg_get_entities(array('type' => $type, 'selects' => array('42 as added_col3'), 'limit' => 1));
         $entity = array_shift($entities);
         $this->assertTrue($entity instanceof ElggEntity);
         $this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity));
         $this->assertEqual($entity->getVolatileData('select:added_col3'), 42);
         // make sure we have cached the entity
         $this->assertNotEqual(false, _elgg_retrieve_cached_entity($entity->guid));
     }
     // run these again but with different value to make sure cache does not interfere
     foreach (array('site', 'user', 'group', 'object') as $type) {
         $entities = elgg_get_entities(array('type' => $type, 'selects' => array('64 as added_col3'), 'limit' => 1));
         $entity = array_shift($entities);
         $this->assertTrue($entity instanceof ElggEntity);
         $this->assertEqual($entity->added_col3, null, "Additional select columns are leaking to attributes for " . get_class($entity));
         $this->assertEqual($entity->getVolatileData('select:added_col3'), 64, "Failed to overwrite volatile data in cached entity");
     }
     elgg_set_ignore_access($access);
     $group->delete();
 }
Exemplo n.º 2
0
 /**
  * Transfer group icons to new filestore location
  * Before 3.0, group icons where owned by the group owner
  * and located in /groups/<guid><size>.jpg
  * relative to group owner's filestore directory
  * In 3.0, we are moving these to default filestore location
  * relative to group's filestore directory
  *
  * @param \ElggGroup           $group  Group entity
  * @param \Elgg\Upgrade\Result $result Upgrade result
  * @return \Elgg\Upgrade\Result
  */
 public function transferIcons(\ElggGroup $group, \Elgg\Upgrade\Result $result)
 {
     $sizes = elgg_get_icon_sizes('group', $group->getSubtype());
     $dataroot = elgg_get_config('dataroot');
     $dir = (new \Elgg\EntityDirLocator($group->owner_guid))->getPath();
     $prefix = 'groups/';
     foreach ($sizes as $size => $opts) {
         $filename = "{$group->guid}{$size}.jpg";
         $filestorename = "{$dataroot}{$dir}{$prefix}{$filename}";
         if (!file_exists($filestorename)) {
             // nothing to move
             continue;
         }
         $icon = $group->getIcon($size);
         // before transferring the file, we need to make sure
         // the directory structure of the new filestore location exists
         $icon->open('write');
         $icon->close();
         if (!rename($filestorename, $icon->getFilenameOnFilestore())) {
             $result->addError("\n\t\t\t\t\tFailed to transfer file from '{$filestorename}'\n\t\t\t\t\tto {$icon->getFilenameOnFilestore()}\n\t\t\t\t");
             $error = true;
         }
     }
     if ($error) {
         $result->addFailures();
     } else {
         $result->addSuccesses();
     }
     return $result;
 }
Exemplo n.º 3
0
function CreateLTIGroup($user, $name, $context_id, $consumer_key)
{
    $group_guid = 0;
    $group = new ElggGroup($group_guid);
    // Set the group properties that we can!
    $group->name = $name;
    $group->context_id = $context_id;
    // This is a unique identifier from the consumer for this context
    $group->consumer_key = $consumer_key;
    // Which consumer is creating this group
    $group->membership = ACCESS_PRIVATE;
    $group->access_id = ACCESS_PUBLIC;
    $group->briefdescription = elgg_echo('LTI:provision:group');
    $consumer_instance = new LTI_Tool_Consumer_Instance($group->consumer_key, elgg_get_config('dbprefix'));
    $context = new LTI_Context($consumer_instance, $group->context_id);
    $group->description = $context->title;
    $group->save();
    $group->join($user);
    // Add images
    $prefix = 'groups/' . $group->guid;
    $filename = GetImage($consumer_key, '.jpg');
    $thumbtiny = get_resized_image_from_existing_file($filename, 25, 25, true);
    $thumbsmall = get_resized_image_from_existing_file($filename, 40, 40, true);
    $thumbmedium = get_resized_image_from_existing_file($filename, 100, 100, true);
    $thumblarge = get_resized_image_from_existing_file($filename, 200, 200, false);
    if ($thumbtiny) {
        $thumb = new ElggFile();
        $thumb->owner_guid = $group->owner_guid;
        $thumb->setMimeType('image/jpeg');
        $thumb->setFilename($prefix . "tiny.jpg");
        $thumb->open("write");
        $thumb->write($thumbtiny);
        $thumb->close();
        $thumb->setFilename($prefix . "small.jpg");
        $thumb->open("write");
        $thumb->write($thumbsmall);
        $thumb->close();
        $thumb->setFilename($prefix . "medium.jpg");
        $thumb->open("write");
        $thumb->write($thumbmedium);
        $thumb->close();
        $thumb->setFilename($prefix . "large.jpg");
        $thumb->open("write");
        $thumb->write($thumblarge);
        $thumb->close();
        $group->icontime = time();
    }
    // return the URL
    return $group;
}
Exemplo n.º 4
0
/**
 * Get the latest activity of this group based on the river
 *
 * @param ElggGroup $entity the group to check
 *
 * @return int the UNIX timestamp of the latest activity
 */
function csv_exporter_get_last_group_activity(ElggGroup $entity)
{
    $result = 0;
    if (!$entity instanceof ElggGroup) {
        return $result;
    }
    $dbprefix = elgg_get_config('dbprefix');
    $query = 'SELECT max(r.posted) as posted';
    $query .= " FROM {$dbprefix}river r";
    $query .= " INNER JOIN {$dbprefix}entities e ON r.object_guid = e.guid";
    $query .= " WHERE (e.container_guid = {$entity->getGUID()})";
    $query .= " OR (r.object_guid = {$entity->getGUID()})";
    $data = get_data($query);
    if (!empty($data)) {
        $result = (int) $data[0]->posted;
    }
    return $result;
}
Exemplo n.º 5
0
function group_tools_invite_email(ElggGroup $group, $email, $text = "", $resend = false)
{
    $result = false;
    if (!empty($group) && $group instanceof ElggGroup && !empty($email) && is_email_address($email) && ($loggedin_user = elgg_get_logged_in_user_entity())) {
        // get site secret
        $site_secret = get_site_secret();
        // generate invite code
        $invite_code = md5($site_secret . $email . $group->getGUID());
        if (!group_tools_check_group_email_invitation($invite_code, $group->getGUID()) || $resend) {
            // make site email
            $site = elgg_get_site_entity();
            if (!empty($site->email)) {
                if (!empty($site->name)) {
                    $site_from = $site->name . " <" . $site->email . ">";
                } else {
                    $site_from = $site->email;
                }
            } else {
                // no site email, so make one up
                if (!empty($site->name)) {
                    $site_from = $site->name . " <noreply@" . get_site_domain($site->getGUID()) . ">";
                } else {
                    $site_from = "noreply@" . get_site_domain($site->getGUID());
                }
            }
            if (!$resend) {
                // register invite with group
                $group->annotate("email_invitation", $invite_code, ACCESS_LOGGED_IN, $group->getGUID());
            }
            // make subject
            $subject = elgg_echo("group_tools:groups:invite:email:subject", array($group->name));
            // make body
            $body = elgg_echo("group_tools:groups:invite:email:body", array($loggedin_user->name, $group->name, $site->name, $text, $site->name, elgg_get_site_url() . "register", elgg_get_site_url() . "groups/invitations/?invitecode=" . $invite_code, $invite_code));
            $result = elgg_send_email($site_from, $email, $subject, $body);
        } else {
            $result = null;
        }
    }
    return $result;
}
 /**
  * Called before each test object.
  */
 public function __construct()
 {
     elgg_set_ignore_access(true);
     $this->entities = array();
     $this->subtypes = array('object' => array(), 'user' => array(), 'group' => array());
     // sites are a bit wonky.  Don't use them just now.
     $this->types = array('object', 'user', 'group');
     // create some fun objects to play with.
     // 5 with random subtypes
     for ($i = 0; $i < 5; $i++) {
         $subtype = 'test_object_subtype_' . rand();
         $e = new ElggObject();
         $e->subtype = $subtype;
         $e->save();
         $this->entities[] = $e;
         $this->subtypes['object'][] = $subtype;
     }
     // and users
     for ($i = 0; $i < 5; $i++) {
         $subtype = "test_user_subtype_" . rand();
         $e = new ElggUser();
         $e->username = "******" . rand();
         $e->subtype = $subtype;
         $e->save();
         $this->entities[] = $e;
         $this->subtypes['user'][] = $subtype;
     }
     // and groups
     for ($i = 0; $i < 5; $i++) {
         $subtype = "test_group_subtype_" . rand();
         $e = new ElggGroup();
         $e->subtype = $subtype;
         $e->save();
         $this->entities[] = $e;
         $this->subtypes['group'][] = $subtype;
     }
     parent::__construct();
 }
Exemplo n.º 7
0
 /**
  * Get an access token for signing API requests
  */
 public function getAccessToken()
 {
     if (!elgg_instanceof($this->entity)) {
         return false;
     }
     switch ($this->entity->getType()) {
         case 'site':
             return StripeClientFactory::getSecretKey();
             break;
         default:
             return $this->entity->getPrivateSetting('stripe_access_token');
             break;
     }
 }
Exemplo n.º 8
0
/**
 * Registers the buttons for title area of the group profile page
 *
 * @param ElggGroup $group
 */
function groups_register_profile_buttons($group)
{
    $actions = array();
    // group owners
    if ($group->canEdit()) {
        // edit and invite
        $url = elgg_get_site_url() . "groups/edit/{$group->getGUID()}";
        $actions[$url] = 'groups:edit';
        $url = elgg_get_site_url() . "groups/invite/{$group->getGUID()}";
        $actions[$url] = 'groups:invite';
    }
    // group members
    if ($group->isMember(elgg_get_logged_in_user_entity())) {
        if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
            // leave
            $url = elgg_get_site_url() . "action/groups/leave?group_guid={$group->getGUID()}";
            $url = elgg_add_action_tokens_to_url($url);
            $actions[$url] = 'groups:leave';
        }
    } elseif (elgg_is_logged_in()) {
        // join - admins can always join.
        $url = elgg_get_site_url() . "action/groups/join?group_guid={$group->getGUID()}";
        $url = elgg_add_action_tokens_to_url($url);
        if ($group->isPublicMembership() || $group->canEdit()) {
            $actions[$url] = 'groups:join';
        } else {
            // request membership
            $actions[$url] = 'groups:joinrequest';
        }
    }
    if ($actions) {
        foreach ($actions as $url => $text) {
            elgg_register_menu_item('title', array('name' => $text, 'href' => $url, 'text' => elgg_echo($text), 'link_class' => 'elgg-button elgg-button-action'));
        }
    }
}
Exemplo n.º 9
0
/**
 * Dispatches subgroups pages.
 * URLs take the form of
 *  
 *  Group view subgroups:      subgroups/owner/<group_guid>
 *  Group manage subgroups:    subgroups/manage/<group_guid>
 *
 * @param array $page
 * @return NULL
 */
function subgroups_page_handler($page)
{
    $pages_path = elgg_get_plugins_path() . "subgroups/pages";
    switch ($page[0]) {
        case 'add':
        case 'edit':
            elgg_set_page_owner_guid($page[1]);
            include $pages_path . "/subgroups/edit.php";
            break;
        case 'owner':
            elgg_set_page_owner_guid($page[1]);
            include $pages_path . "/subgroups/owner.php";
            break;
        case 'new':
            $group = new ElggGroup((int) $page[1]);
            if (!$group->guid) {
                register_error(elgg_echo('error:default'));
                return false;
            }
            elgg_load_library('elgg:groups');
            $title = elgg_echo('subgroups:new:of', array($group->name));
            elgg_push_breadcrumb(elgg_echo('groups'), "groups/all");
            elgg_push_breadcrumb($group->name, $group->getURL());
            elgg_push_breadcrumb(elgg_echo('subgroups:new'));
            set_input('container_guid', $group->guid);
            $body = elgg_view_layout('content', array('content' => elgg_view('groups/edit'), 'title' => $title, 'filter' => ''));
            echo elgg_view_page($title, $body);
            break;
        default:
            return false;
    }
    return true;
}
Exemplo n.º 10
0
            break;
    }
}
set_time_limit(0);
$success = $error = 0;
$count = (int) get_input('count');
$featured_count = (int) get_input('featured_count');
$locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
$faker = Factory::create($locale);
foreach (array(ACCESS_PRIVATE, ACCESS_LOGGED_IN, ACCESS_PUBLIC) as $visibility) {
    foreach (array(hypefaker_get_group_content_access_mode('members_only'), hypefaker_get_group_content_access_mode('unrestricted')) as $content_access_mode) {
        foreach (array(ACCESS_PRIVATE, ACCESS_PUBLIC) as $membership) {
            for ($i = 0; $i < $count; $i++) {
                $users = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => 1, 'order_by' => 'RAND()', 'metadata_names' => '__faker'));
                $owner = $users[0];
                $group = new ElggGroup();
                $group->name = $faker->sentence(5);
                $group->owner_guid = $owner->guid;
                $group->container_guid = $owner->guid;
                $group->description = $faker->text(500);
                $group->briefdescription = $faker->bs;
                $group->interests = $faker->words(10);
                $group->access_id = ACCESS_PUBLIC;
                $group->membership = $membership;
                $group->content_access_mode = $content_access_mode;
                $guid = $group->save();
                if (!$guid) {
                    $errors++;
                    continue;
                }
                if ($visibility != ACCESS_PUBLIC && $visibility != ACCESS_LOGGED_IN) {
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
 protected function initializeAttributes()
 {
     parent::initializeAttributes();
     $this->attributes['subtype'] = self::SUBTYPE;
 }
Exemplo n.º 13
0
    } else {
        $input[$shortname] = _elgg_html_decode($input[$shortname]);
    }
    if ($valuetype == 'tags') {
        $input[$shortname] = string_to_tag_array($input[$shortname]);
    }
}
$input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8');
$user = elgg_get_logged_in_user_entity();
$group_guid = (int) get_input('group_guid');
$is_new_group = $group_guid == 0;
if ($is_new_group && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) {
    register_error(elgg_echo("groups:cantcreate"));
    forward(REFERER);
}
$group = new ElggGroup($group_guid);
// load if present, if not create a new group
if ($group_guid && !$group->canEdit()) {
    register_error(elgg_echo("groups:cantedit"));
    forward(REFERER);
}
// Assume we can edit or this is a new group
if (sizeof($input) > 0) {
    foreach ($input as $shortname => $value) {
        // update access collection name if group name changes
        if (!$is_new_group && $shortname == 'name' && $value != $group->name) {
            $group_name = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
            $ac_name = sanitize_string(elgg_echo('groups:group') . ": " . $group_name);
            $acl = get_access_collection($group->group_acl);
            if ($acl) {
                // @todo Elgg api does not support updating access collection name
Exemplo n.º 14
0
 function test_can_write_to_container()
 {
     $user = new ElggUser();
     $user->username = '******' . rand();
     $user->name = 'test_user_name_' . rand();
     $user->email = '*****@*****.**';
     $user->container_guid = 0;
     $user->owner_guid = 0;
     $user->save();
     $object = new ElggObject();
     $object->save();
     $group = new ElggGroup();
     $group->save();
     // disable access overrides because we're admin.
     $ia = elgg_set_ignore_access(false);
     $this->assertFalse(can_write_to_container($user->guid, $object->guid));
     global $elgg_test_user;
     $elgg_test_user = $user;
     // register hook to allow access
     function can_write_to_container_test_hook($hook, $type, $value, $params)
     {
         global $elgg_test_user;
         if ($params['user']->getGUID() == $elgg_test_user->getGUID()) {
             return true;
         }
     }
     elgg_register_plugin_hook_handler('container_permissions_check', 'all', 'can_write_to_container_test_hook');
     $this->assertTrue(can_write_to_container($user->guid, $object->guid));
     elgg_unregister_plugin_hook_handler('container_permissions_check', 'all', 'can_write_to_container_test_hook');
     $this->assertFalse(can_write_to_container($user->guid, $group->guid));
     $group->join($user);
     $this->assertTrue(can_write_to_container($user->guid, $group->guid));
     elgg_set_ignore_access($ia);
     $user->delete();
     $object->delete();
     $group->delete();
 }
Exemplo n.º 15
0
$input = array();
foreach ($CONFIG->dgroup as $shortname => $valuetype) {
    $input[$shortname] = get_input($shortname);
    if ($valuetype == 'tags') {
        $input[$shortname] = string_to_tag_array($input[$shortname]);
    }
}
$user_guid = get_input('user_guid');
$user = NULL;
if (!$user_guid) {
    $user = $_SESSION['user'];
} else {
    $user = get_entity($user_guid);
}
$dgroup_guid = get_input('dgroup_guid');
$dgroup = new ElggGroup($dgroup_guid);
// load if present, if not create a new dgroup
$dgroup->subtype = 'dgroup';
if ($dgroup_guid && !$dgroup->canEdit() && !isadminloggedin()) {
    register_error(elgg_echo("dgroups:cantedit"));
    forward($_SERVER['HTTP_REFERER']);
    exit;
}
// Assume we can edit or this is a new dgroup
if (sizeof($input) > 0) {
    foreach ($input as $shortname => $value) {
        $dgroup->{$shortname} = $value;
    }
}
// Validate create
if (!$dgroup->name) {
Exemplo n.º 16
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 zhgroups_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("zhgroups:groups:invite:add:subject", array($group->name));
            $msg = elgg_echo("zhgroups:groups:invite:add:body", array($user->name, $loggedin_user->name, $group->name, $text, $group->getURL()));
            $params = array("group" => $group, "inviter" => $loggedin_user, "invitee" => $user);
            //to do?
            $msg = elgg_trigger_plugin_hook("invite_notification", "zhgroups", $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.º 17
0
 /**
  * Make sure entity is loaded from cache during save operations
  * See #10612
  */
 public function testNewGroupLoadedFromCacheDuringSaveOperations()
 {
     $group = new \ElggGroup();
     $group->subtype = 'test_group_subtype';
     // Add temporary metadata, annotation and private settings
     // to extend the scope of tests and catch issues with save operations
     $group->test_metadata = 'bar';
     $group->annotate('test_annotation', 'baz');
     $group->setPrivateSetting('test_setting', 'foo');
     $metadata_called = false;
     $metadata_event_handler = function ($event, $type, $metadata) use(&$metadata_called) {
         /* @var $metadata \ElggMetadata */
         $entity = get_entity($metadata->entity_guid);
         $this->assertEqual($metadata->entity_guid, $entity->guid);
         $metadata_called = true;
     };
     $annotation_called = false;
     $annotation_event_handler = function ($event, $type, $annotation) use(&$annotation_called) {
         /* @var $metadata \ElggAnnotation */
         $entity = get_entity($annotation->entity_guid);
         $this->assertEqual($annotation->entity_guid, $entity->guid);
         $annotation_called = true;
     };
     elgg_register_event_handler('create', 'metadata', $metadata_event_handler);
     elgg_register_event_handler('create', 'annotation', $annotation_event_handler);
     $group->save();
     elgg_unregister_event_handler('create', 'metadata', $metadata_event_handler);
     elgg_unregister_event_handler('create', 'annotation', $annotation_event_handler);
     $group->delete();
     $this->assertTrue($metadata_called);
     $this->assertTrue($annotation_called);
 }
Exemplo n.º 18
0
/**
 * Checks if a certain user can create group events
 *
 * @param $group Group to check rights for
 * @param $user  User to check rights for
 *
 * @return bool
 */
function event_manager_can_create_group_events(\ElggGroup $group, $user = null)
{
    if (empty($user)) {
        $user = elgg_get_logged_in_user_entity();
    }
    if (!$group instanceof \ElggGroup || !$user instanceof \ElggUser) {
        return false;
    }
    $who_create_group_events = elgg_get_plugin_setting('who_create_group_events', 'event_manager');
    // group_admin, members
    switch ($who_create_group_events) {
        case 'group_admin':
            return $group->canEdit($user->guid);
        case 'members':
            if ($group->isMember($user)) {
                return true;
            } else {
                return $group->canEdit($user->guid);
            }
    }
    return false;
}
Exemplo n.º 19
0
 public function testJoinLeaveGroupACL()
 {
     if (!elgg_is_active_plugin('groups')) {
         return;
     }
     $group = new ElggGroup();
     $group->name = 'Test group';
     $group->save();
     $result = $group->join($this->user);
     $this->assertTrue($result);
     // disable security since we run as admin
     $ia = elgg_set_ignore_access(false);
     // need to set the page owner to emulate being in a group context.
     // this is kinda hacky.
     elgg_set_page_owner_guid($group->getGUID());
     if ($result) {
         $can_edit = can_edit_access_collection($group->group_acl, $this->user->guid);
         $this->assertTrue($can_edit);
     }
     $result = $group->leave($this->user);
     $this->assertTrue($result);
     if ($result) {
         $can_edit = can_edit_access_collection($group->group_acl, $this->user->guid);
         $this->assertFalse($can_edit);
     }
     elgg_set_ignore_access($ia);
     $group->delete();
 }
Exemplo n.º 20
0
/**
 * Registers the buttons for title area of the group profile page
 *
 * @param ElggGroup $group
 */
function groups_register_profile_buttons($group)
{
    $user = elgg_get_logged_in_user_entity();
    $actions = array();
    // group owners
    if ($group->canEdit()) {
        // local groups except town groups cannot be edited (except by admins)
        if ($group->grouptype != 'local' || $group->grouptype == 'local' && $group->localtype == 'town' || $user->isAdmin()) {
            $url = elgg_get_site_url() . "groups/edit/{$group->getGUID()}";
            $actions[$url] = 'groups:edit';
        }
        // local groups except town groups cannot use invitation system
        if ($group->grouptype != 'local' || $group->grouptype == 'local' && $group->localtype == 'town') {
            $url = elgg_get_site_url() . "groups/invite/{$group->getGUID()}";
            $actions[$url] = 'groups:invite';
        }
    }
    // add a button to allow adding town groups (only for group members)
    if ($group->grouptype == 'local' && $group->localtype == 'departemental' && $group->isMember(elgg_get_logged_in_user_entity())) {
        $url = elgg_get_site_url() . "groups/local/add/{$group->getGUID()}";
        $actions[$url] = 'localgroups:addtown';
    }
    // group members (not for local groups except town group)
    if ($group->grouptype == 'local' && $group->localtype == 'town' || $group->grouptype != 'local') {
        if ($group->isMember(elgg_get_logged_in_user_entity())) {
            if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
                // leave
                $url = elgg_get_site_url() . "action/groups/leave?group_guid={$group->getGUID()}";
                $url = elgg_add_action_tokens_to_url($url);
                $actions[$url] = 'groups:leave';
            }
        } elseif (elgg_is_logged_in()) {
            // join - admins can always join.
            $url = elgg_get_site_url() . "action/groups/join?group_guid={$group->getGUID()}";
            $url = elgg_add_action_tokens_to_url($url);
            if ($group->isPublicMembership() || $group->canEdit()) {
                $actions[$url] = 'groups:join';
            } else {
                // request membership
                $actions[$url] = 'groups:joinrequest';
            }
        }
    }
    if ($actions) {
        foreach ($actions as $url => $text) {
            elgg_register_menu_item('title', array('name' => $text, 'href' => $url, 'text' => elgg_echo($text), 'link_class' => 'elgg-button elgg-button-action'));
        }
    }
}
Exemplo n.º 21
0
 /**
  * Check if the user is receiving notifications from the group
  *
  * @param \ElggUser  $user  the user to check
  * @param \ElggGroup $group the group to check for
  *
  * @return bool
  */
 public static function notificationsEnabledForGroup(\ElggUser $user, \ElggGroup $group)
 {
     if (!$user instanceof \ElggUser || !$group instanceof \ElggGroup) {
         return false;
     }
     $subscriptions = elgg_get_subscriptions_for_container($group->getGUID());
     if (!is_array($subscriptions)) {
         return false;
     }
     if (!empty($subscriptions[$user->getGUID()])) {
         return true;
     }
     return false;
 }
 public function testElggObjectContainer()
 {
     $this->assertEqual($this->entity->getContainer(), get_loggedin_userid());
     // fals when container not a group
     $this->assertFalse($this->entity->getContainerEntity());
     // create and save to group
     $group = new ElggGroup();
     $guid = $group->save();
     $this->assertTrue($this->entity->setContainer($guid));
     // check container
     $this->assertEqual($this->entity->getContainer(), $guid);
     $this->assertIdentical($group, $this->entity->getContainerEntity());
     // clean up
     $group->delete();
 }
Exemplo n.º 23
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.º 24
0
 public function testElggObjectContainer()
 {
     $this->assertEqual($this->entity->getContainerGUID(), elgg_get_logged_in_user_guid());
     // create and save to group
     $group = new \ElggGroup();
     $guid = $group->save();
     $this->assertTrue($this->entity->setContainerGUID($guid));
     // check container
     $this->assertEqual($this->entity->getContainerGUID(), $guid);
     $this->assertIdenticalEntities($group, $this->entity->getContainerEntity());
     // clean up
     $group->delete();
 }
Exemplo n.º 25
0
    } else {
        $input[$shortname] = _elgg_html_decode($input[$shortname]);
    }
    if ($valuetype == 'tags') {
        $input[$shortname] = string_to_tag_array($input[$shortname]);
    }
}
$input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8');
$user = elgg_get_logged_in_user_entity();
$group_guid = (int) get_input('group_guid');
$is_new_group = $group_guid == 0;
if ($is_new_group && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) {
    register_error(elgg_echo("groups:cantcreate"));
    forward(REFERER);
}
$group = new ElggGroup($group_guid);
// load if present, if not create a new group
if ($group_guid && !$group->canEdit()) {
    register_error(elgg_echo("groups:cantedit"));
    forward(REFERER);
}
// Assume we can edit or this is a new group
if (sizeof($input) > 0) {
    foreach ($input as $shortname => $value) {
        // update access collection name if group name changes
        if (!$is_new_group && $shortname == 'name' && $value != $group->name) {
            $group_name = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
            $ac_name = sanitize_string(elgg_echo('groups:group') . ": " . $group_name);
            $acl = get_access_collection($group->group_acl);
            if ($acl) {
                // @todo Elgg api does not support updating access collection name
Exemplo n.º 26
0
    } else {
        $input[$shortname] = _elgg_html_decode($input[$shortname]);
    }
    if ($valuetype == 'tags') {
        $input[$shortname] = string_to_tag_array($input[$shortname]);
    }
}
$input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8');
$user = elgg_get_logged_in_user_entity();
$group_guid = (int) get_input('group_guid');
$is_new_group = $group_guid == 0;
if ($is_new_group && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) {
    register_error(elgg_echo("groups:cantcreate"));
    forward(REFERER);
}
$group = new ElggGroup($group_guid);
// load if present, if not create a new group
if ($group_guid && !$group->canEdit()) {
    register_error(elgg_echo("groups:cantedit"));
    forward(REFERER);
}
// Assume we can edit or this is a new group
if (sizeof($input) > 0) {
    foreach ($input as $shortname => $value) {
        // update access collection name if group name changes
        if (!$is_new_group && $shortname == 'name' && $value != $group->name) {
            $group_name = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
            $ac_name = sanitize_string(elgg_echo('groups:group') . ": " . $group_name);
            $acl = get_access_collection($group->group_acl);
            if ($acl) {
                // @todo Elgg api does not support updating access collection name
Exemplo n.º 27
0
/**
 * Get the time_created from the group membership relation
 *
 * @param ElggUser  $user  the user to check
 * @param ElggGroup $group the group to check
 *
 * @return int
 */
function group_tools_get_membership_information(ElggUser $user, ElggGroup $group)
{
    $result = 0;
    if (!empty($user) && !empty($group)) {
        $query = "SELECT *";
        $query .= " FROM " . elgg_get_config("dbprefix") . "entity_relationships";
        $query .= " WHERE guid_one = " . $user->getGUID();
        $query .= " AND guid_two = " . $group->getGUID();
        $query .= " AND relationship = 'member'";
        $row = get_data_row($query);
        if (!empty($row)) {
            $result = $row->time_created;
        }
    }
    return $result;
}
Exemplo n.º 28
0
Arquivo: edit.php Projeto: remy40/gvrs
    if (is_array($input[$shortname])) {
        array_walk_recursive($input[$shortname], 'profile_array_decoder');
    } else {
        $input[$shortname] = html_entity_decode($input[$shortname], ENT_COMPAT, 'UTF-8');
    }
    if ($valuetype == 'tags') {
        $input[$shortname] = string_to_tag_array($input[$shortname]);
    }
}
$input['name'] = get_input('name');
$input['name'] = html_entity_decode($input['name'], ENT_COMPAT, 'UTF-8');
$user = elgg_get_logged_in_user_entity();
$group_guid = (int) get_input('group_guid');
$parent_guid = (int) get_input('parent_guid');
$new_group_flag = $group_guid == 0;
$group = new ElggGroup($group_guid);
// load if present, if not create a new group
if ($group_guid && !$group->canEdit()) {
    register_error(elgg_echo("groups:cantedit"));
    forward(REFERER);
}
// check if it's a local group or a working group
$grouptype_set_by_admin = get_input(grouptype_set_by_admin);
// admin can modify group type for an existing group
if (!$new_group_flag && $grouptype_set_by_admin) {
    $group->grouptype = $grouptype_set_by_admin;
} else {
    // new group
    if (!isset($group->grouptype)) {
        $group->grouptype = get_input('group_type');
        // we can only create local town groups
Exemplo n.º 29
0
 /**
  * Ensure that \ElggBatch doesn't go into infinite loop when disabling annotations recursively when show hidden is enabled.
  *
  * https://github.com/Elgg/Elgg/issues/5952
  */
 public function test_disabling_annotations_infinite_loop()
 {
     //let's have some entity
     $group = new \ElggGroup();
     $group->name = 'test_group';
     $group->access_id = ACCESS_PUBLIC;
     $this->assertTrue($group->save() !== false);
     $total = 51;
     //add some annotations
     for ($cnt = 0; $cnt < $total; $cnt++) {
         $group->annotate('test_annotation', 'value_' . $total);
     }
     //disable them
     $show_hidden = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $options = array('guid' => $group->guid, 'limit' => $total);
     elgg_disable_annotations($options);
     access_show_hidden_entities($show_hidden);
     //confirm all being disabled
     $annotations = $group->getAnnotations(array('limit' => $total));
     foreach ($annotations as $annotation) {
         $this->assertTrue($annotation->enabled == 'no');
     }
     //delete group and annotations
     $group->delete();
 }
Exemplo n.º 30
0
/**
 * Get the activity count since last action of the previous login of the user
 *
 * @param ElggGroup $group the group to check for
 *
 * @return false|int
 */
function theme_eersel_get_group_activity_count(ElggGroup $group)
{
    if (!$group instanceof ElggGroup) {
        return false;
    }
    if (!elgg_is_logged_in() || empty($_SESSION['theme_eersel_activity_last_action'])) {
        return false;
    }
    if (!is_array($_SESSION['theme_eersel_group_activity_counter'])) {
        $_SESSION['theme_eersel_group_activity_counter'] = [];
    }
    if (isset($_SESSION['theme_eersel_group_activity_counter'][$group->getGUID()])) {
        return $_SESSION['theme_eersel_group_activity_counter'][$group->getGUID()];
    }
    // get river activity since last action of user
    $dbprefix = elgg_get_config('dbprefix');
    $options = ['count' => true, 'joins' => ["JOIN {$dbprefix}entities oe ON rv.object_guid = oe.guid"], 'wheres' => ["(rv.object_guid = {$group->getGUID()} || oe.container_guid = {$group->getGUID()})"], 'posted_time_lower' => (int) $_SESSION['theme_eersel_activity_last_action']];
    $_SESSION['theme_eersel_group_activity_counter'][$group->getGUID()] = elgg_get_river($options);
    return $_SESSION['theme_eersel_group_activity_counter'][$group->getGUID()];
}