Esempio n. 1
0
function set_notifier_page_handler($page, $identifier)
{
    // select page based on first URL segment after /set_notifier/
    switch ($page[0]) {
        case 'set':
            gatekeeper();
            $num_users = 1;
            $limit = 100;
            $offset = 0;
            while ($num_users != 0) {
                $users = elgg_get_entities(array('types' => 'user', 'limit' => $limit, 'offset' => $offset));
                if ($users != 0) {
                    foreach ($users as $user) {
                        $prefix = "notification:method:notifier";
                        $user->{$prefix} = true;
                        $user->collections_notifications_preferences_notifier = '-1';
                        $user->save();
                    }
                }
                $num_users = count($users);
                $offset += $limit;
            }
            forward(REFERER);
            break;
        default:
            echo "request for {$identifier} {$page['0']}";
            break;
    }
    // return true to let Elgg know that a page was sent to browser
    return true;
}
Esempio n. 2
0
function hj_forum_get_forum_category_input_options($entity = null, $container = null)
{
    if ((elgg_instanceof($container, 'site') || elgg_instanceof($container, 'group')) && !HYPEFORUM_CATEGORIES_TOP) {
        return false;
    }
    if (elgg_instanceof($container, 'object', 'hjforum') && !HYPEFORUM_CATEGORIES) {
        return false;
    }
    if (!$entity && !$container) {
        return false;
    }
    if (elgg_instanceof($container, 'object', 'hjforum') && !$container->enable_subcategories) {
        return false;
    }
    $dbprefix = elgg_get_config('dbprefix');
    $categories = elgg_get_entities(array('types' => 'object', 'subtypes' => 'hjforumcategory', 'limit' => 0, 'container_guids' => $container->guid, 'joins' => array("JOIN {$dbprefix}objects_entity oe ON oe.guid = e.guid"), 'order_by' => 'oe.title ASC'));
    if ($categories) {
        foreach ($categories as $category) {
            $options_values[$category->guid] = $category->title;
        }
        if ($entity) {
            $categories = $entity->getCategories('hjforumcategory');
            $value = $categories[0]->guid;
        }
        $options = array('input_type' => 'dropdown', 'options_values' => $options_values, 'value' => $value);
    } else {
        if ($container->canWriteToContainer(0, 'object', 'hjforumcategory')) {
            $options = array('input_type' => 'text', 'override_view' => 'output/url', 'text' => elgg_echo('hj:forum:create:category'), 'href' => "forum/create/category/{$container->guid}");
        } else {
            return false;
        }
    }
    return $options;
}
Esempio n. 3
0
 /**
  * Get notification preferences of users who have answered the poll
  *
  * The poll contents have changed so we must notify the people
  * who had answered before the changes took place.
  *
  * @param string $hook          'get'
  * @param string $type          'subscriptions'
  * @param array  $subscriptions Array containing subscriptions in the form
  *                              <user guid> => array('email', 'site', etc.)
  * @param array  $params        Hook parameters
  * @return array
  */
 public static function subscribers($hook,   $type, $subscriptions, $params)
 {
     $poll = $params['event']->getObject();
     if (!$poll instanceof \ElggSchedulingPoll) {
         return $subscriptions;
     }
     $subscriptions = array();
     $voters = array_keys($poll->getVotesByUser());
     if (empty($voters)) {
         // There's no one to notify
         return $subscriptions;
     }
     // Get all available notification methods
     $methods = _elgg_services()->notifications->getMethods();
     // Get all users who have voted
     $users = elgg_get_entities(array('type' => 'user', 'guids' => $voters, 'limit' => 0));
     // Personal notification settings are saved into a metadata
     // called notification:method:{$method}. Go through the users
     // and check which methods have been enabled for each user.
     foreach ($users as $user) {
         foreach ($methods as $method) {
             $meta_name = "notification:method:{$method}";
             if ((bool) $user->{$meta_name}) {
                 $subscriptions[$user->guid][] = $method;
             }
         }
     }
     return $subscriptions;
 }
Esempio n. 4
0
function upgrade_20141125()
{
    $version = (int) elgg_get_plugin_setting('version', PLUGIN_ID);
    if ($version == 2011111502) {
        // this didn't happen correctly in the last upgrade
        // due to some legacy setting
        elgg_set_plugin_setting('version', 20141121, PLUGIN_ID);
        $version = 20141121;
    }
    if ($version >= UPGRADE_VERSION) {
        return true;
    }
    $options = array('type' => 'object', 'subtype' => 'plugin_project', 'limit' => false);
    $batch = new ElggBatch('elgg_get_entities', $options);
    foreach ($batch as $plugin) {
        // get most recent release
        $releases = elgg_get_entities(array('type' => 'object', 'subtype' => 'plugin_release', 'container_guid' => $plugin->guid, 'limit' => 1, 'callback' => false));
        if ($releases[0]->time_created) {
            update_entity_last_action($plugin->guid, $releases[0]->time_created);
        } else {
            update_entity_last_action($plugin->guid, $plugin->time_created);
        }
    }
    elgg_set_plugin_setting('version', 20141125, PLUGIN_ID);
}
function batch_find_images()
{
    $log = elgg_get_config('mfp_log');
    $logtime = elgg_get_config('mfp_logtime');
    // only search
    $options = array('type' => 'object', 'subtype' => 'image', 'limit' => 0);
    $images = new ElggBatch('elgg_get_entities', $options);
    $count = 0;
    $bad_images = 0;
    $total = elgg_get_entities(array_merge($options, array('count' => true)));
    file_put_contents($log, "Starting scan of {$total} images" . "\n", FILE_APPEND);
    foreach ($images as $image) {
        $count++;
        // don't use ->exists() because of #5207.
        if (!is_file($image->getFilenameOnFilestore())) {
            $bad_images++;
            $image->mfp_delete_check = $logtime;
        }
        if ($count == 1 || !($count % 25)) {
            $time = date('Y-m-d g:ia');
            $message = "Checked {$count} of {$total} images as of {$time}";
            file_put_contents($log, $message . "\n", FILE_APPEND);
        }
    }
    $message = '<div class="done"><a href="#" id="elgg-tidypics-broken-images-delete" data-time="' . $logtime . '">Delete ' . $bad_images . ' broken images</a></div>';
    file_put_contents($log, $message . "\n", FILE_APPEND);
}
Esempio n. 6
0
function current_dokuwiki_entity($create = true)
{
    $page_owner = elgg_get_page_owner_guid();
    $user = elgg_get_logged_in_user_entity();
    //error_log($page_owner->guid);
    //error_log($user->guid);
    if (!$page_owner) {
        $page_owner = 0;
    }
    $entities = elgg_get_entities(array('types' => 'object', 'subtypes' => 'dokuwiki', 'limit' => 1, 'owner_guid' => $page_owner));
    if ($entities) {
        $doku = $entities[0];
        return $doku;
    } elseif ($user && $create) {
        elgg_set_ignore_access(true);
        $newdoku = new ElggObject();
        $newdoku->access_id = ACCESS_PUBLIC;
        $newdoku->owner_guid = $page_owner;
        $newdoku->subtype = 'dokuwiki';
        $newdoku->container_guid = $page_owner;
        $newdoku->save();
        $acl = array();
        $acl[] = "# acl.auth.php";
        $acl[] = '# <?php exit()?\\>';
        $acl[] = "*               @ALL        0";
        $acl[] = "*               @user        1";
        $acl[] = "*               @member        8";
        $acl[] = "*               @admin        16";
        $acl[] = "*               @root        255";
        $newdoku->wiki_acl = implode("\n", $acl) . "\n";
        elgg_set_ignore_access(false);
        return $newdoku;
    }
}
Esempio n. 7
0
 function show_members_json($context, $limit = 30, $offset = 0, $username)
 {
     if (!$username) {
         $user = elgg_get_logged_in_user_entity();
     } else {
         $user = get_user_by_username($username);
         if (!$user) {
             throw new InvalidParameterException('registration:usernamenotvalid');
         }
     }
     if ($context == "newest") {
         $params = array('types' => 'user', 'limit' => $limit, 'full_view' => FALSE);
         $latest_member = elgg_get_entities($params);
         //return $return;
     }
     if ($context == "online") {
         $latest_member = get_online_users();
     }
     if ($context == "popular") {
         $params = array('types' => 'user', 'relationship' => 'friend', 'inverse_relationship' => false);
         $latest_member = elgg_list_entities_from_relationship_count($params);
     }
     if ($latest_member) {
         foreach ($latest_member as $single) {
             $member['guid'] = $single->guid;
             $member['name'] = $single->name;
             //$member['avatar_url'] = get_entity_icon_url($single,'small');
             $return[] = $member;
         }
     }
     //return $return;
     return json_encode($return, true);
 }
Esempio n. 8
0
 /**
  * Migrates old (pre MenuBuilder 2.0) menu entities to json
  *
  * @return void
  */
 public static function migrateEntitiesToJSON()
 {
     $ia = elgg_set_ignore_access(true);
     $menu = new \ColdTrick\MenuBuilder\Menu('site');
     $menu->save();
     $options = ['type' => 'object', 'subtype' => 'menu_builder_menu_item', 'limit' => false];
     $entities = elgg_get_entities($options);
     if (empty($entities)) {
         elgg_set_ignore_access($ia);
         return;
     }
     foreach ($entities as $menu_item) {
         $parent_name = null;
         $parent_guid = $menu_item->parent_guid;
         if ($parent_guid) {
             $parent = get_entity($parent_guid);
             if ($parent) {
                 $parent_name = "menu_name_{$parent_guid}";
             }
         }
         $menu->addMenuItem(['name' => "menu_name_{$menu_item->guid}", 'text' => $menu_item->title, 'href' => $menu_item->url, 'target' => $menu_item->target, 'is_action' => $menu_item->is_action, 'access_id' => $menu_item->access_id, 'priority' => $menu_item->order, 'parent_name' => $parent_name]);
     }
     // delete entities need to do it afterwards as parents are not always available otherwise
     foreach ($entities as $menu_item) {
         $menu_item->delete();
     }
     elgg_set_ignore_access($ia);
 }
Esempio n. 9
0
function bookmark_tools_get_folders($container_guid = 0)
{
    $result = false;
    if (empty($container_guid)) {
        $container_guid = elgg_get_page_owner_guid();
    }
    if (!empty($container_guid)) {
        $options = array("type" => "object", "subtype" => BOOKMARK_TOOLS_SUBTYPE, "container_guid" => $container_guid, "limit" => false);
        if ($folders = elgg_get_entities($options)) {
            $parents = array();
            foreach ($folders as $folder) {
                $parent_guid = (int) $folder->parent_guid;
                if (!empty($parent_guid)) {
                    if ($temp = get_entity($parent_guid)) {
                        if ($temp->getSubtype() != BOOKMARK_TOOLS_SUBTYPE) {
                            $parent_guid = 0;
                        }
                    } else {
                        $parent_guid = 0;
                    }
                } else {
                    $parent_guid = 0;
                }
                if (!array_key_exists($parent_guid, $parents)) {
                    $parents[$parent_guid] = array();
                }
                $parents[$parent_guid][] = $folder;
            }
            $result = bookmark_tools_sort_folders($parents, 0);
        }
    }
    return $result;
}
Esempio n. 10
0
/**
 * Get the folders in a container
 *
 * @param int $container_guid the container to check
 *
 * @return bool|ElggObject[]
 */
function file_tools_get_folders($container_guid = 0)
{
    $container_guid = (int) $container_guid;
    if (empty($container_guid)) {
        $container_guid = elgg_get_page_owner_guid();
    }
    if (empty($container_guid)) {
        return false;
    }
    $folders = elgg_get_entities(['type' => 'object', 'subtype' => FILE_TOOLS_SUBTYPE, 'container_guid' => $container_guid, 'limit' => false]);
    if (empty($folders)) {
        return false;
    }
    $parents = array();
    /* @var $folder ElggObject */
    foreach ($folders as $folder) {
        $parent_guid = (int) $folder->parent_guid;
        if (!empty($parent_guid)) {
            $temp = get_entity($parent_guid);
            if (!elgg_instanceof($temp, 'object', FILE_TOOLS_SUBTYPE)) {
                $parent_guid = 0;
            }
        }
        if (!array_key_exists($parent_guid, $parents)) {
            $parents[$parent_guid] = [];
        }
        $parents[$parent_guid][] = $folder;
    }
    return file_tools_sort_folders($parents, 0);
}
Esempio n. 11
0
/**
 * Returns the object based on the id
 *
 * @param string  $id     id of the object to find
 * @param boolean $create should the object be created if id is missing
 *
 * @return /ElggObject|false
 */
function ckeditor_extended_get_inline_object($id, $create = false)
{
    static $cached = [];
    if (empty($id)) {
        return false;
    }
    $prefix = elgg_extract(0, explode('_', $id));
    if (!array_key_exists($prefix, $cached)) {
        $cached[$prefix] = [];
        // preload entities
        $entities = elgg_get_entities(['type' => 'object', 'subtype' => 'ckeditor_inline', 'limit' => false, 'joins' => 'JOIN ' . elgg_get_config('dbprefix') . "objects_entity oe ON oe.guid = e.guid", 'wheres' => "oe.title LIKE '{$prefix}%'"]);
        foreach ($entities as $entity) {
            $cached[$prefix][$entity->title] = $entity;
        }
    }
    if (array_key_exists($id, $cached[$prefix])) {
        return $cached[$prefix][$id];
    }
    if (!$create) {
        return false;
    }
    $object = new \ElggObject();
    $object->subtype = 'ckeditor_inline';
    $object->title = $id;
    $object->owner_guid = elgg_get_site_entity()->guid;
    $object->container_guid = elgg_get_site_entity()->guid;
    $object->access_id = ACCESS_PUBLIC;
    $cached[$prefix][$id] = $object;
    return $object;
}
Esempio n. 12
0
function search_by_proximity_hook($hook, $type, $return, $params)
{
    $query = $params['query'];
    $coords = elgg_geocode_location($query);
    if (!$coords) {
        return $return;
    }
    $registered_entities = elgg_get_config('registered_entities');
    $options = array('types' => array('object', 'user', 'group'), 'subtypes' => array_merge($registered_entities['object'], $registered_entities['user'], $registered_entities['group']), 'limit' => get_input('limit', 20), 'offset' => get_input('proximity_offset', 0), 'offset_key' => 'proximity_offset', 'count' => true);
    $options = add_order_by_proximity_clauses($options, $coords['lat'], $coords['long']);
    $options = add_distance_constraint_clauses($options, $coords['lat'], $coords['long'], SEARCH_RADIUS);
    $count = elgg_get_entities($options);
    if ($count) {
        $options['count'] = false;
        $entities = elgg_get_entities($options);
    }
    if ($entities) {
        foreach ($entities as $entity) {
            $name = search_get_highlighted_relevant_substrings(isset($entity->name) ? $entity->name : $entity->title, $query);
            $entity->setVolatileData('search_matched_title', $name);
            $location = search_get_highlighted_relevant_substrings($entity->getLocation(), $query);
            $entity->setVolatileData('search_matched_location', $location);
            $distance = get_distance($entity->getLatitude(), $entity->getLongitude(), $coords['lat'], $coords['long']);
            // distance in metres
            $distance = round($distance / 1000, 2);
            // distance in km
            $distance_str = elgg_echo('geo:search:proximity', array($query, $distance));
            $entity->setVolatileData('search_proximity', $distance_str);
        }
    }
    return array('entities' => $entities, 'count' => $count);
}
Esempio n. 13
0
/**
 * Register the navigation menu
 * 
 * @param ElggEntity $container Container entity for the pages
 */
function pages_register_navigation_tree($container)
{
    if (!$container) {
        return;
    }
    $top_pages = elgg_get_entities(array('type' => 'object', 'subtype' => 'page_top', 'container_guid' => $container->getGUID(), 'limit' => 0));
    if (!$top_pages) {
        return;
    }
    foreach ($top_pages as $page) {
        elgg_register_menu_item('pages_nav', array('name' => $page->getGUID(), 'text' => $page->title, 'href' => $page->getURL()));
        $stack = array();
        array_push($stack, $page);
        while (count($stack) > 0) {
            $parent = array_pop($stack);
            $children = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'page', 'metadata_name' => 'parent_guid', 'metadata_value' => $parent->getGUID(), 'limit' => 0));
            if ($children) {
                foreach ($children as $child) {
                    elgg_register_menu_item('pages_nav', array('name' => $child->getGUID(), 'text' => $child->title, 'href' => $child->getURL(), 'parent_name' => $parent->getGUID()));
                    array_push($stack, $child);
                }
            }
        }
    }
}
Esempio n. 14
0
/**
 *
 * Returns array of people containing entity, mutuals (friends), groups (shared) and priority
 * @param Int $guid
 * @param Int $friends_limit
 * @param Int $groups_limit
 * @return Array
 */
function get_suggestions($guid, $friends_of_friends_limit = 10, $groups_members_limit = 10)
{
    $dbprefix = elgg_get_config('dbprefix');
    $guid = sanitize_int($guid);
    $suggestions = array();
    if ($friends_of_friends_limit) {
        // get some friends of friends
        $options = array('selects' => array('COUNT(fof.guid_two) as priority'), 'type' => 'user', 'joins' => array("JOIN {$dbprefix}users_entity ue ON ue.guid = e.guid", "JOIN {$dbprefix}entity_relationships fr ON fr.guid_one = {$guid} AND fr.relationship = 'friend'", "JOIN {$dbprefix}entity_relationships fof ON fof.guid_one = fr.guid_two AND fof.relationship = 'friend'"), "wheres" => array("ue.banned = 'no'", "e.guid NOT IN (SELECT f.guid_two FROM {$dbprefix}entity_relationships f WHERE f.guid_one = {$guid} AND f.relationship = 'friend')", "fof.guid_two = e.guid", "e.guid != {$guid}"), 'group_by' => 'e.guid', 'order_by' => 'priority desc, ue.last_action desc', 'limit' => abs((int) $friends_of_friends_limit));
        $fof = elgg_get_entities($options);
        foreach ($fof as $f) {
            $priority = (int) $f->getVolatileData('select:priority');
            $suggestions[$f->guid] = array('entity' => $f, 'mutuals' => $priority, 'groups' => 0, 'priority' => $priority);
        }
    }
    if ($groups_members_limit) {
        // get some mutual group members
        $options = array('selects' => array('COUNT(mog.guid_two) as priority'), 'type' => 'user', 'joins' => array("JOIN {$dbprefix}users_entity ue ON ue.guid = e.guid", "JOIN {$dbprefix}entity_relationships g ON g.guid_one = {$guid} AND g.relationship = 'member'", "JOIN {$dbprefix}groups_entity ge ON ge.guid = g.guid_two", "JOIN {$dbprefix}entity_relationships mog ON mog.guid_two = g.guid_two AND mog.relationship = 'member'"), "wheres" => array("ue.banned = 'no'", "e.guid NOT IN (SELECT f.guid_two FROM {$dbprefix}entity_relationships f WHERE f.guid_one = {$guid} AND f.relationship = 'friend')", "mog.guid_one = e.guid", "e.guid != {$guid}"), 'group_by' => 'e.guid', 'order_by' => 'priority desc, ue.last_action desc', 'limit' => 3);
        // get members of groups
        $mog = elgg_get_entities($options);
        foreach ($mog as $m) {
            if (!isset($suggestions[$m->guid])) {
                $priority = (int) $m->getVolatileData('select:priority');
                $suggestions[$m->guid] = array('entity' => $m, 'mutuals' => 0, 'groups' => $priority, 'priority' => $priority);
            } else {
                $priority = (int) $m->getVolatileData('select:priority');
                $suggestions[$m->guid]['groups'] = $priority;
                $suggestions[$m->guid]['priority'] += $priority;
            }
        }
    }
    // sort by priority
    usort($suggestions, __NAMESPACE__ . '\\suggested_friends_sorter');
    return $suggestions;
}
Esempio n. 15
0
function elggchat_session_cleanup($hook, $entity_type, $returnvalue, $params)
{
    $resulttext = elgg_echo("elggchat:crondone");
    $access = elgg_set_ignore_access(true);
    $access_status = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    $session_count = elgg_get_entities(array('type' => "object", 'subtype' => ELGGCHAT_SESSION_SUBTYPE, 'count' => true));
    if ($session_count < 1) {
        // no sessions to clean up
        access_show_hidden_entities($access_status);
        elgg_set_ignore_access($access);
        return $returnvalue . $resulttext;
    }
    $sessions = elgg_get_entities(array('type' => "object", 'subtype' => ELGGCHAT_SESSION_SUBTYPE, 'limit' => $session_count));
    foreach ($sessions as $session) {
        $member_count = $session->countEntitiesFromRelationship(ELGGCHAT_MEMBER);
        if ($member_count > 0) {
            $max_age = (int) elgg_get_plugin_setting("maxSessionAge", "elggchat");
            $age = time() - $session->time_updated;
            if ($age > $max_age) {
                $session->delete();
            }
        } else {
            $session->delete();
        }
    }
    access_show_hidden_entities($access_status);
    elgg_set_ignore_access($access);
    return $returnvalue . $resulttext;
}
 /**
  * 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();
 }
/**
 * function to replace group profile fields
 * 
 * @param $hook_name
 * @param $entity_type
 * @param $return_value
 * @param $parameters
 * @return unknown_type
 */
function profile_manager_group_override($hook_name, $entity_type, $return_value, $parameters)
{
    global $CONFIG;
    $result = $return_value;
    // Get all custom group fields
    $options = array("type" => "object", "subtype" => CUSTOM_PROFILE_FIELDS_GROUP_SUBTYPE, "limit" => false, "owner_guid" => $CONFIG->site_guid);
    $group_fields = elgg_get_entities($options);
    if ($group_fields) {
        $result = array();
        $ordered = array();
        // Order the group fields and filter some types out
        foreach ($group_fields as $group_field) {
            if ($group_field->admin_only != "yes" || elgg_is_admin_logged_in()) {
                $ordered[$group_field->order] = $group_field;
            }
        }
        ksort($ordered);
        // build the correct list
        $result["name"] = "text";
        foreach ($ordered as $group_field) {
            $result[$group_field->metadata_name] = $group_field->metadata_type;
            // should it be handled as tags? TODO: is this still needed? Yes it is, it handles presentation of these fields in listing mode
            if (elgg_get_context() == "search" && ($group_field->output_as_tags == "yes" || $group_field->metadata_type == "multiselect")) {
                $result[$group_field->metadata_name] = "tags";
            }
        }
    }
    return $result;
}
Esempio n. 18
0
/**
 * Web service to get file list by all users
 *
 * @param string $limit  (optional) default 10
 * @param string $offset (optional) default 0
 *
 * @return array $file Array of files uploaded
 */
function file_get_files($username, $limit = 10, $offset = 0)
{
    if ($username) {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
        $params = array('types' => 'object', 'subtypes' => 'file', 'owner_guid' => $user->guid, 'limit' => $limit, 'full_view' => FALSE);
    } else {
        $params = array('types' => 'object', 'subtypes' => 'file', 'limit' => $limit, 'full_view' => FALSE);
    }
    $latest_file = elgg_get_entities($params);
    if ($latest_file) {
        foreach ($latest_file as $single) {
            $file[$single->guid]['title'] = $single->title;
            $file[$single->guid]['owner_guid'] = $single->owner_guid;
            $file[$single->guid]['container_guid'] = $single->container_guid;
            $file[$single->guid]['access_id'] = $single->access_id;
            $file[$single->guid]['time_created'] = $single->time_created;
            $file[$single->guid]['time_updated'] = $single->time_updated;
            $file[$single->guid]['last_action'] = $single->last_action;
        }
    } else {
        $file['error']['message'] = elgg_echo('file:none');
    }
    return $file;
}
Esempio n. 19
0
function bulk_user_admin_get_users_by_email_domain($domain, $options = array())
{
    $domain = sanitise_string($domain);
    $db_prefix = elgg_get_config('dbprefix');
    $where = "ue.email LIKE '%@{$domain}'";
    if (!isset($options['wheres'])) {
        $options['wheres'] = array($where);
    } else {
        if (!is_array($options['wheres'])) {
            $options['wheres'] = array($options['wheres']);
        }
        $options['wheres'][] = $where;
    }
    $join = "JOIN {$db_prefix}users_entity ue on e.guid = ue.guid";
    if (!isset($options['joins'])) {
        $options['joins'] = array($join);
    } else {
        if (!is_array($options['joins'])) {
            $options['joins'] = array($options['joins']);
        }
        $options['joins'][] = $join;
    }
    $options['type'] = 'user';
    return elgg_get_entities($options);
}
Esempio n. 20
0
/**
 * External pages page handler
 *
 * @param array  $page    URL segements
 * @param string $handler Handler identifier
 * @return bool
 */
function expages_page_handler($page, $handler)
{
    if ($handler == 'expages') {
        expages_url_forwarder($page[1]);
    }
    $type = strtolower($handler);
    $title = elgg_echo("expages:{$type}");
    $header = elgg_view_title($title);
    $object = elgg_get_entities(array('type' => 'object', 'subtype' => $type, 'limit' => 1));
    if ($object) {
        $content .= elgg_view('output/longtext', array('value' => $object[0]->description));
    } else {
        $content .= elgg_echo("expages:notset");
    }
    $content = elgg_view('expages/wrapper', array('content' => $content));
    if (elgg_is_admin_logged_in()) {
        elgg_register_menu_item('title', array('name' => 'edit', 'text' => elgg_echo('edit'), 'href' => "admin/appearance/expages?type={$type}", 'link_class' => 'elgg-button elgg-button-action'));
    }
    if (elgg_is_logged_in() || !elgg_get_config('walled_garden')) {
        $body = elgg_view_layout('one_column', array('title' => $title, 'content' => $content));
        echo elgg_view_page($title, $body);
    } else {
        elgg_load_css('elgg.walled_garden');
        $body = elgg_view_layout('walled_garden', array('content' => $header . $content));
        echo elgg_view_page($title, $body, 'walled_garden');
    }
    return true;
}
Esempio n. 21
0
/**
 * Produce the navigation tree
 * 
 * @param ElggEntity $container Container entity for the pages
 *
 * @return array
 */
function pages_get_navigation_tree($container)
{
    if (!$container) {
        return;
    }
    $top_pages = elgg_get_entities(array('type' => 'object', 'subtype' => 'page_top', 'container_guid' => $container->getGUID(), 'limit' => 0));
    if (!$top_pages) {
        return;
    }
    /* @var ElggObject[] $top_pages */
    $tree = array();
    $depths = array();
    foreach ($top_pages as $page) {
        $tree[] = array('guid' => $page->getGUID(), 'title' => $page->title, 'url' => $page->getURL(), 'depth' => 0);
        $depths[$page->guid] = 0;
        $stack = array();
        array_push($stack, $page);
        while (count($stack) > 0) {
            $parent = array_pop($stack);
            $children = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'page', 'metadata_name' => 'parent_guid', 'metadata_value' => $parent->getGUID(), 'limit' => 0));
            if ($children) {
                foreach ($children as $child) {
                    $tree[] = array('guid' => $child->getGUID(), 'title' => $child->title, 'url' => $child->getURL(), 'parent_guid' => $parent->getGUID(), 'depth' => $depths[$parent->guid] + 1);
                    $depths[$child->guid] = $depths[$parent->guid] + 1;
                    array_push($stack, $child);
                }
            }
        }
    }
    return $tree;
}
Esempio n. 22
0
function homepaage_cms_action_hook($hook, $type, $returnvalue, $params)
{
    $hpc_params = array("type" => "object", "subtype" => "hpcroles");
    $allRoles = elgg_get_entities($hpc_params);
    if ($params["hpc_role_check"] == true) {
        if (!$allRoles) {
            $hpcRoleTitles = array("all" => array("title" => "all", "subtype" => $hpc_params["subtype"], "desc" => "Basic home page cms role to refer page this[all]"), "learner" => array("title" => "learner", "subtype" => $hpc_params["subtype"], "desc" => "Basic home page cms role to refer page this[learner]"), "instructor" => array("title" => "instructor", "subtype" => $hpc_params["subtype"], "desc" => "Basic home page cms role to refer page this[instructor]"), "developer" => array("title" => "learner", "subtype" => $hpc_params["subtype"], "desc" => "Basic home page cms role to refer page this[developer]"));
            foreach ($hpcRoleTitles as $roleTitle) {
                $tmpHpcRole = new ElggObject();
                $tmpHpcRole->title = $roleTitle["title"];
                $tmpHpcRole->subtype = $roleTitle["subtype"];
                $tmpHpcRole->description = $roleTitle["desc"];
                $tmpHpcRole->pagecontent = '';
                $allRoles[$roleTitle] = $tmpHpcRole->save();
            }
            //system_message('Created roles: '.count($allRoles));
        } else {
            //please uncomment out the following foreach loop to delete all the roles with subtype "hpcroles" in elgg database
            foreach ($allRoles as $role) {
                $role->delete();
                //system_message((string)$role->guid);
            }
            system_message('Available roles: ' . count($allRoles));
        }
    }
}
Esempio n. 23
0
/**
 * Returns entities based upon private settings.  Also accepts all
 * options available to elgg_get_entities().  Supports
 * the singular option shortcut.
 *
 * @see elgg_get_entities
 *
 * @param array $options Array in format:
 *
 * 	private_setting_names => NULL|ARR private setting names
 *
 * 	private_setting_values => NULL|ARR metadata values
 *
 * 	private_setting_name_value_pairs => NULL|ARR (
 *                                         name => 'name',
 *                                         value => 'value',
 *                                         'operand' => '=',
 *                                        )
 * 	                             Currently if multiple values are sent via
 *                               an array (value => array('value1', 'value2')
 *                               the pair's operand will be forced to "IN".
 *
 * 	private_setting_name_value_pairs_operator => NULL|STR The operator to use for combining
 *                                        (name = value) OPERATOR (name = value); default AND
 *
 *  private_setting_name_prefix => STR A prefix to apply to all private settings. Used to
 *                                     namespace plugin user settings or by plugins to namespace
 *                                     their own settings.
 *
 *
 * @return mixed int If count, int. If not count, array. false on errors.
 * @since 1.8.0
 */
function elgg_get_entities_from_private_settings(array $options = array())
{
    $defaults = array('private_setting_names' => ELGG_ENTITIES_ANY_VALUE, 'private_setting_values' => ELGG_ENTITIES_ANY_VALUE, 'private_setting_name_value_pairs' => ELGG_ENTITIES_ANY_VALUE, 'private_setting_name_value_pairs_operator' => 'AND', 'private_setting_name_prefix' => '');
    $options = array_merge($defaults, $options);
    $singulars = array('private_setting_name', 'private_setting_value', 'private_setting_name_value_pair');
    $options = elgg_normalise_plural_options_array($options, $singulars);
    $clauses = elgg_get_entity_private_settings_where_sql('e', $options['private_setting_names'], $options['private_setting_values'], $options['private_setting_name_value_pairs'], $options['private_setting_name_value_pairs_operator'], $options['private_setting_name_prefix']);
    if ($clauses) {
        // merge wheres to pass to get_entities()
        if (isset($options['wheres']) && !is_array($options['wheres'])) {
            $options['wheres'] = array($options['wheres']);
        } elseif (!isset($options['wheres'])) {
            $options['wheres'] = array();
        }
        $options['wheres'] = array_merge($options['wheres'], $clauses['wheres']);
        // merge joins to pass to get_entities()
        if (isset($options['joins']) && !is_array($options['joins'])) {
            $options['joins'] = array($options['joins']);
        } elseif (!isset($options['joins'])) {
            $options['joins'] = array();
        }
        $options['joins'] = array_merge($options['joins'], $clauses['joins']);
    }
    return elgg_get_entities($options);
}
Esempio n. 24
0
 /**
  * Get the answers on this question
  *
  * @param array $options accepts all elgg_get_entities options
  *
  * @return false|int|ElggAnswer[]
  */
 public function getAnswers(array $options = array())
 {
     $defaults = ['order_by' => 'time_created asc'];
     $overrides = ['type' => 'object', 'subtype' => 'answer', 'container_guid' => $this->getGUID()];
     $options = array_merge($defaults, $options, $overrides);
     return elgg_get_entities($options);
 }
Esempio n. 25
0
/**
 * External pages page handler
 *
 * @param array  $page    URL segements
 * @param string $handler Handler identifier
 * @return bool
 */
function expages_page_handler($page, $handler)
{
    if ($handler == 'expages') {
        expages_url_forwarder($page[1]);
    }
    $type = strtolower($handler);
    $title = elgg_echo("expages:{$type}");
    $header = elgg_view_title($title);
    $object = elgg_get_entities(array('type' => 'object', 'subtype' => $type, 'limit' => 1));
    if ($object) {
        $content .= elgg_view('output/longtext', array('value' => $object[0]->description));
    } else {
        $content .= elgg_echo("expages:notset");
    }
    $content = elgg_view('expages/wrapper', array('content' => $content));
    if (elgg_is_logged_in() || !elgg_get_config('walled_garden')) {
        $body = elgg_view_layout('one_column', array('title' => $title, 'content' => $content));
        echo elgg_view_page($title, $body);
    } else {
        elgg_load_css('elgg.walled_garden');
        $body = elgg_view_layout('walled_garden', array('content' => $header . $content));
        echo elgg_view_page($title, $body, 'walled_garden');
    }
    return true;
}
Esempio n. 26
0
 /**
  * {@inheritdoc}
  */
 public function run(\Elgg\Upgrade\Result $result, $offset)
 {
     $groups = elgg_get_entities(['types' => 'group', 'offset' => $offset, 'limit' => 10]);
     foreach ($groups as $group) {
         $result = $this->transferIcons($group, $result);
     }
     return $result;
 }
Esempio n. 27
0
 public function getInactiveUsers()
 {
     //current date converted to time for math comparison
     $currentDate = strtotime(date('Ymd'));
     //define range end point (60 days in the past)
     $sixtyDaysAgo = $currentDate - 24 * 60 * 60 * 60;
     $users = elgg_get_entities(array('type' => 'user', 'limit' => 0, 'joins' => array("join elgg_users_entity u on e.guid = u.guid"), 'wheres' => array("u.last_action < {$sixtyDaysAgo}")));
     $this->users = $users;
 }
 public function testEGECanUsePreloader()
 {
     $options = array('limit' => 3);
     elgg_get_entities($options);
     $this->assertNull($this->mockPreloader->preloaded);
     $options['preload_owners'] = true;
     elgg_get_entities($options);
     $this->assertEqual(3, count($this->mockPreloader->preloaded));
 }
Esempio n. 29
0
/**
 * Return the current following tags
 *
 */
function follow_tags_get_current_tags($guid)
{
    $options = array('type' => 'object', 'subtype' => 'FollowTags', 'owner_guid' => $guid);
    $tags = elgg_get_entities($options);
    foreach ($tags as $tag) {
        $value = $tag->description;
    }
    return $value;
}
Esempio n. 30
0
 public function lastComment()
 {
     $result = elgg_get_entities(array('type' => 'object', 'subtype' => 'comment', 'container_guid' => $this->guid, 'limit' => '1'));
     if ($result) {
         return $result[0];
     } else {
         return false;
     }
 }