/** * {@inheritdoc} */ public function post(ParameterBag $params) { $user = get_entity($params->guid); $friend = $params->friend_uid ? $this->graph->get($params->friend_uid) : null; 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 ($user->guid == $friend->guid) { throw new GraphException("You are trying to friend yourself", HttpResponse::HTTP_BAD_REQUEST); } if (check_entity_relationship($user->guid, 'friend', $friend->guid)) { throw new GraphException("Already a friend", HttpResponse::HTTP_BAD_REQUEST); } if (!add_entity_relationship($user->guid, 'friend', $friend->guid)) { throw new GraphException("Unable to create friendship"); } $river_id = elgg_create_river_item(array('view' => 'river/relationship/friend/create', 'action_type' => 'friend', 'subject_guid' => $user->guid, 'object_guid' => $friend->guid)); $return = array('nodes' => array('friend' => check_entity_relationship($user->guid, 'friend', $friend->guid), 'friend_of' => check_entity_relationship($friend->guid, 'friend', $user->guid))); if (!empty($river_id)) { $river = elgg_get_river(array('ids' => $river_id)); $return['nodes']['activity'] = $river ? $river[0] : $river_id; } return $return; }
/** * @SWG\Get( * path="/api/groups/{guid}/activities", * security={{"oauth2": {"all"}}}, * tags={"activities"}, * summary="Find activities in a specific group.", * description="Find the most recent activities from a specific group.", * produces={"application/json"}, * @SWG\Parameter( * name="guid", * in="path", * description="The guid of the specific group", * required=true, * type="integer", * @SWG\Items(type="integer") * ), * @SWG\Parameter( * name="offset", * in="query", * description="Offset the results by", * default=0, * required=false, * type="integer", * @SWG\Items(type="integer") * ), * @SWG\Parameter( * name="limit", * in="query", * description="Limit the results by", * default=20, * required=false, * type="integer", * @SWG\Items(type="integer") * ), * @SWG\Response( * response=200, * description="Succesful operation.", * @SWG\Schema( * type="array", * @SWG\Items(ref="#/definitions/Activity") * ), * ), * @SWG\Response( * response="404", * description="Could not find the requested group.", * ) * ) */ public function getGroup($request, $response, $args) { $currentUser = elgg_get_logged_in_user_entity(); $guid = (int) $args['guid']; $group = get_entity($guid); if (!$group | !$group instanceof \ElggGroup) { return $response->withStatus(404); } $params = $request->getQueryParams(); $limit = (int) $params['limit']; $offset = (int) $params['offset']; if (!$limit | $limit < 0 | $limit > 50) { $limit = 20; } $dbprefix = elgg_get_config("dbprefix"); $options = array('offset' => $offset, 'limit' => $limit, 'joins' => array("JOIN {$dbprefix}entities e1 ON e1.guid = rv.object_guid"), 'wheres' => array("(e1.container_guid = {$group->guid})")); $entities = array(); foreach (elgg_get_river($options) as $entity) { $entities[] = $this->parseActivity($entity); } $options['count'] = true; $total = elgg_get_river($options); $handler = new \PleioRest\Services\PushNotificationHandler(); $response = $response->withHeader('Content-type', 'application/json'); return $response->write(json_encode(array('total' => $total, 'number_unread' => $handler->getContainerUnreadCount($currentUser, $group), 'entities' => $entities), JSON_PRETTY_PRINT)); }
function addTaggedWirePost($hook, $type, $params) { global $CONFIG; $id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '" . $params['type'] . "', " . " subtype = '" . $params['subtype'] . "', " . " action_type = '" . $params['action_type'] . "', " . " access_id = '" . $params['access_id'] . "', " . " view = '" . $params['view'] . "', " . " subject_guid = '" . $params['subject_guid'] . "', " . " object_guid = '" . $params['object_guid'] . "', " . " annotation_id = '" . $params['annotation_id'] . "', " . " posted = '" . $params['posted'] . "';"); $tags = ""; if (isset($_SESSION['role'])) { switch ($_SESSION['role']) { case "learner": $tags = "Learner-Apprenant"; break; case "instructor": $tags = "Instructor-Instructeur"; break; case "developer": $tags = "Developer-Développeur"; break; case "trainingmgr": $tags = "trainingmgr"; break; } $roleTags = $_SESSION['role']; } if ($roleTags) { $metaID = create_metadata($params['object_guid'], "tags", "{$tags}", "text", elgg_get_logged_in_user_guid(), 2, true); } if ($id) { update_entity_last_action($object_guid, $posted); $river_items = elgg_get_river(array('id' => $id)); if ($river_items) { elgg_trigger_event('created', 'river', $river_items[0]); } } return false; }
/** * {@inheritdoc} */ public function post(ParameterBag $params) { $user = elgg_get_logged_in_user_entity(); $object = get_entity($params->guid); if (!$object || !$object->canWriteToContainer(0, 'object', 'comment')) { throw new GraphException("You are not allowed to comment on this object", 403); } $comment_text = $params->comment; $comment = new ElggComment(); $comment->owner_guid = $user->guid; $comment->container_guid = $object->guid; $comment->description = $comment_text; $comment->access_id = $object->access_id; if (!$comment->save()) { throw new GraphException(elgg_echo("generic_comment:failure")); } // Notify if poster wasn't owner if ($object->owner_guid != $user->guid) { $owner = $object->getOwnerEntity(); notify_user($owner->guid, $user->guid, elgg_echo('generic_comment:email:subject', array(), $owner->language), elgg_echo('generic_comment:email:body', array($object->title, $user->name, $comment->description, $comment->getURL(), $user->name, $user->getURL()), $owner->language), array('object' => $comment, 'action' => 'create')); } $return = array('nodes' => array('comment' => $comment)); // Add to river $river_id = elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $user->guid, 'object_guid' => $comment->guid, 'target_guid' => $object->guid)); if ($river_id) { $river = elgg_get_river(array('ids' => $river_id)); $return['nodes']['activity'] = $river ? $river[0] : $river_id; } return $return; }
function getActivityGuidPosition($guid, $context, $loginUser) { $notFound = true; $offset = 0; while ($notFound) { if ($context == 'mine') { $options = array('distinct' => false, 'subject_guids' => $loginUser->guid, 'offset' => $offset, 'limit' => 1); $activity = elgg_get_river($options); } else { if ($context == 'friends') { $options = array('distinct' => false, 'relationship' => 'friend', 'relationship_guid' => $loginUser->guid, 'offset' => $offset, 'limit' => 1); $activity = elgg_get_river($options); } } if (sizeof($activity) > 0) { if ($activity[0]->object_guid == $guid) { $notFound = false; } else { $offset = $offset + 1; } } else { $notFound = false; } } return $offset; }
function pleio_rest_created_river_async($river_id) { $ia = elgg_set_ignore_access(true); $river = elgg_get_river(array('id' => $river_id, 'site_guid' => null)); if (count($river) === 1) { $river = $river[0]; $notHandler = new \PleioRest\Services\PushNotificationHandler(); $notHandler->fanOutNotifications($river); } elgg_set_ignore_access($ia); }
/** * {@inheritdoc} */ public function get($uid = '') { switch ($uid) { case 'me': $uid = "ue" . elgg_get_logged_in_user_guid(); break; case 'site': $uid = "se" . elgg_get_site_entity()->guid; break; } $abbr = substr($uid, 0, 2); switch ($abbr) { case 'an': $id = (int) substr($uid, 2); $object = elgg_get_annotation_from_id($id); break; case 'md': $id = (int) substr($uid, 2); $object = elgg_get_metadata_from_id($id); break; case 'rl': $id = (int) substr($uid, 2); $object = get_relationship($id); break; case 'rv': $id = (int) substr($uid, 2); $river = elgg_get_river(array('ids' => sanitize_int($id))); $object = $river ? $river[0] : false; break; case 'ue': case 'se': case 'oe': case 'ge': $id = (int) substr($uid, 2); $object = get_entity($id); break; default: $object = get_user_by_username($uid); if (!$object && is_numeric($uid)) { $object = get_entity($uid); } } if (!$this->isExportable($object)) { return false; } return $object; }
/** * Returns river data * * @param string $filter filter name * @param array $guids guids of groups * @param int $offset offset * @param int $limit limit * @param int $posted_time_lower lower time stamp to limit results * * @return array|ErrorResult */ function ws_pack_river_get($filter, $guids = array(), $offset = 0, $limit = 25, $posted_time_lower = 0) { $result = false; $dbprefix = elgg_get_config("dbprefix"); // default options $options = array("offset" => $offset, "limit" => $limit, "posted_time_lower" => $posted_time_lower, "joins" => array("JOIN " . $dbprefix . "entities sue ON rv.subject_guid = sue.guid", "JOIN " . $dbprefix . "entities obe ON rv.object_guid = obe.guid"), "wheres" => array("(sue.enabled = 'yes' AND obe.enabled = 'yes')")); // what to return switch ($filter) { case "mine": $options["subject_guid"] = elgg_get_logged_in_user_guid(); break; case "friends": $options["relationship_guid"] = elgg_get_logged_in_user_guid(); $options["relationship"] = "friend"; break; case "groups": if (empty($guids)) { // get group guids $group_options = array("type" => "group", "relationship" => "member", "relationship_guid" => elgg_get_logged_in_user_guid(), "limit" => false, "callback" => "ws_pack_row_to_guid"); $guids = elgg_get_entities_from_relationship($group_options); } // check if there are groups if (!empty($guids)) { $options["joins"] = array("JOIN " . $dbprefix . "entities e ON rv.object_guid = e.guid"); $options["wheres"] = array("(rv.object_guid IN (" . implode(",", $guids) . ") OR e.container_guid IN (" . implode(",", $guids) . "))"); } else { // no groups found, so make sure not to return anything $options = false; } break; case "all": default: // list everything break; } // get river items if ($options && ($items = elgg_get_river($options))) { $result = ws_pack_export_river_items($items); } // did we get river items if ($result === false) { $result = new ErrorResult(elgg_echo("river:none"), WS_PACK_API_NO_RESULTS); } return $result; }
function newsfeed_list_river(array $options = array()) { global $autofeed; $autofeed = true; $defaults = array('offset' => (int) max(get_input('offset', 0), 0), 'limit' => (int) max(get_input('limit', max(20, elgg_get_config('default_limit'))), 0), 'pagination' => true, 'list_class' => 'elgg-list-river', 'no_results' => ''); $options = array_merge($defaults, $options); if (!$options["limit"] && !$options["offset"]) { // no need for pagination if listing is unlimited $options["pagination"] = false; } // get the river items $options['count'] = false; $items = elgg_get_river($options); // get the river items count only if we need it for pagination if (!is_null(get_input('offset', null))) { $options['count'] = true; $count = elgg_get_river($options); $options['count'] = $count; } $options['items'] = $items; return elgg_view('page/components/list', $options); }
/** * Downloads the thumbnail and saves into data folder * * @param ElggObject $item * @return bool */ function videolist_2012022501($item) { require_once elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php'; // get thumbnail image $thumbnail = file_get_contents($item->thumbnail); if (!$thumbnail) { return false; } $prefix = "videolist/" . $item->guid; $filehandler = new ElggFile(); $filehandler->owner_guid = $item->owner_guid; $filehandler->setFilename($prefix . ".jpg"); $filehandler->open("write"); $filehandler->write($thumbnail); $filehandler->close(); // update properties if ($item->url) { $item->video_url = $item->url; $item->deleteMetadata('url'); } if ($item->desc) { $item->description = $item->desc; $item->deleteMetadata('desc'); $item->save(); } if ($item->embedurl) { $item->deleteMetadata('embedurl'); } upgrade_change_subtype($item, 'videolist_item'); // update river $options = array('object_guid' => $item->guid); $river_items = elgg_get_river($options); foreach ($river_items as $river_item) { if ($river_item->action_type == 'create') { upgrade_update_river($river_item->id, 'river/object/videolist_item/create', $item->guid, 0); } } return true; }
function tasks_2012100501($task) { require_once elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php'; if ($task->long_description) { $task->description = $task->long_description; $task->deleteMetadata('long_description'); $task->save(); } if ($task->parent_guid) { $task->list_guid = $task->parent_guid; $task->deleteMetadata('parent_guid'); } else { $task->list_guid = 0; } /* Active was set as default, so it is not indicative of which tasks are really active */ $task->deleteMetadata('active'); if ($task->done) { $task->status = 'done'; $task->deleteMetadata('done'); } else { $task->status = 'new'; } // reset priority since old system was a mess $task->priority = 2; upgrade_change_subtype($task, 'task'); // update river $options = array('object_guid' => $task->guid); $items = elgg_get_river($options); foreach ($items as $item) { if ($item->action_type == 'create') { upgrade_update_river($item->id, 'river/object/task/create', $task->guid, 0); } elseif (in_array($item->action_type, array('done', 'undone', 'subscribe', 'unsubscribe'))) { elgg_delete_river(array('id' => $item->id)); } } return true; }
/** * @param $guid * @param int $limit * @param int $offset * @param $username * @param $from_guid * @return array * @throws InvalidParameterException */ function group_get_activity($guid, $limit = 20, $offset = 0, $username, $from_guid) { if (!$username) { $user = elgg_get_logged_in_user_entity(); throw new InvalidParameterException('registration:usernamenotvalid'); } else { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } } $login_user = elgg_get_logged_in_user_entity(); $group = get_entity($guid); if (!elgg_instanceof($group, 'group')) { $return['message'] = elgg_echo('grups:error:group_not_found'); return $return; } $db_prefix = elgg_get_config('dbprefix'); $activities = elgg_get_river(array('limit' => $limit, 'offset' => $offset, 'joins' => array("JOIN {$db_prefix}entities e1 ON e1.guid = rv.object_guid", "LEFT JOIN {$db_prefix}entities e2 ON e2.guid = rv.target_guid"), 'wheres' => array("(e1.container_guid = {$group->guid} OR e2.container_guid = {$group->guid})"), 'no_results' => elgg_echo('groups:activity:none'))); $handle = getRiverActivity($activities, $user, $login_user); return $handle; }
$page_filter = 'mine'; $options['subject_guid'] = elgg_get_logged_in_user_guid(); break; case 'friends': $title = elgg_echo('river:friends'); $page_filter = 'friends'; $options['relationship_guid'] = elgg_get_logged_in_user_guid(); $options['relationship'] = 'friend'; break; default: $title = elgg_echo('river:all'); $page_filter = 'all'; break; } $options['count'] = true; $count = elgg_get_river($options); $options['count'] = false; $options['pagination'] = false; $options['offset'] = 0; if (elgg_get_config('default_limit')) { $options['limit'] = elgg_get_config('default_limit'); } else { $options['limit'] = 5; } $script_text = '<script type="text/javascript"> var options = ' . json_encode($options) . '; var numactivities = ' . $count . '; </script>'; $activity = '<div id="river_auto_update_activity">'; $activity .= elgg_list_river($options); if (!$activity) {
/** * List river items * * @param array $options Any options from elgg_get_river() plus: * pagination => BOOL Display pagination links (true) * no_results => STR Message to display if no items * * @return string * @since 1.8.0 */ function elgg_list_river(array $options = array()) { global $autofeed; $autofeed = true; $defaults = array('offset' => (int) max(get_input('offset', 0), 0), 'limit' => (int) max(get_input('limit', 20), 0), 'pagination' => true, 'list_class' => 'elgg-list-river', 'no_results' => ''); $options = array_merge($defaults, $options); if (!$options["limit"] && !$options["offset"]) { // no need for pagination if listing is unlimited $options["pagination"] = false; } $options['count'] = true; $count = elgg_get_river($options); if ($count > 0) { $options['count'] = false; $items = elgg_get_river($options); } else { $items = array(); } $options['count'] = $count; $options['items'] = $items; return elgg_view('page/components/list', $options); }
} // End of Update PART 2/4 // Begin of Update PART 3/4: // Check for album comments without a river entry and delete them (for each comment made on the activity page // on an image upload a second comment annotation was created with Tidypics 1.8.1betaXX that showed up on the // corresponding album page while the first comment annotation was only visible below the river entry on the // activity page. This second comment annotation is now no longer necessary and should be removed to avoid // comments appearing twice on album pages) // ATTENTION: this part of the upgrade script will remove ALL album comment annotations that don't a corresponding // river entry. If you removed the river entries by any means or prevented them from getting created in the first // place you might not want this part of the upgrade to be executed. Then you should comment out part 3 of the upgrade // But you will most likely end with double comments on album pages then. $batch = new ElggBatch('elgg_get_annotations', array('annotation_name' => 'generic_comment', 'joins' => array("JOIN {$db_prefix}entities te ON te.guid = n_table.entity_guid"), 'wheres' => array("te.subtype = {$tidypics_album_subtype_id}"), 'limit' => false)); $batch->setIncrementOffset(false); foreach ($batch as $album_comment) { $river_entry_count = elgg_get_river(array('type' => 'object', 'subtype' => 'album', 'action_type' => 'comment', 'annotation_id' => $album_comment->id, 'count' => true)); if ($river_entry_count < 1) { elgg_delete_annotation_by_id($album_comment->id); } } // End of Update Part 3/4 // Begin of Update Part 4/4 // Update likes made to Tidypics batches and assign them either to the image uploaded (if only one) or the album $batch = new ElggBatch('elgg_get_annotations', array('annotation_name' => 'likes', 'joins' => array("JOIN {$db_prefix}entities te ON te.guid = n_table.entity_guid"), 'wheres' => array("te.subtype = {$tidypics_batch_subtype_id}"), 'limit' => false)); $batch->setIncrementOffset(false); foreach ($batch as $like_entry) { // Get the batch entity $tidypics_batch = get_entity($like_entry->entity_guid); // Get images related to this batch $images = elgg_get_entities_from_relationship(array('relationship' => 'belongs_to_batch', 'relationship_guid' => $tidypics_batch->getGUID(), 'inverse_relationship' => true, 'type' => 'object', 'subtype' => 'image', 'limit' => false)); // move the like to the album if more than a single image was uploaded in this batch
/** * {@inheritdoc} */ public function get(ParameterBag $params) { $river = elgg_get_river(array('ids' => sanitize_int($params->id))); return array('nodes' => array($river[0])); }
/** * {@inheritdoc} */ public function put(ParameterBag $params) { hypeGraph()->logger->vardump('params', $params); $user = isset($params->owner_guid) && $params->owner_guid ? get_entity($params->owner_guid) : elgg_get_logged_in_user_entity(); $group_guid = isset($params->guid) ? $params->guid : 0; // allows us to recycle this method from SiteGroups controller $is_new_group = $group_guid == 0; if ($is_new_group && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) { throw new GraphException(elgg_echo("groups:cantcreate"), 403); } $group = $group_guid ? get_entity($group_guid) : new ElggGroup(); if (elgg_instanceof($group, "group") && !$group->canEdit()) { throw new GraphException(elgg_echo("groups:cantedit"), 403); } if (!$is_new_group) { foreach ($params as $key => $value) { if ($value === null) { $params->{$key} = $group->{$key}; } } } $input = array(); foreach (elgg_get_config('group') as $shortname => $valuetype) { $input[$shortname] = $params->{$shortname}; if (is_array($input[$shortname])) { array_walk_recursive($input[$shortname], function (&$v) { $v = _elgg_html_decode($v); }); } else { $input[$shortname] = _elgg_html_decode($input[$shortname]); } if ($valuetype == 'tags') { $input[$shortname] = string_to_tag_array($input[$shortname]); } } $input = array_filter($input); $input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8'); // 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 $db_prefix = elgg_get_config('dbprefix'); $query = "UPDATE {$db_prefix}access_collections SET name = '{$ac_name}'\n\t\t\t\t\tWHERE id = {$group->group_acl}"; update_data($query); } } if ($value === '') { // The group profile displays all profile fields that have a value. // We don't want to display fields with empty string value, so we // remove the metadata completely. $group->deleteMetadata($shortname); continue; } $group->{$shortname} = $value; } } // Validate create if (!$group->name) { throw new GraphException(elgg_echo("groups:notitle"), 400); } // Set group tool options $tool_options = elgg_get_config('group_tool_options'); if ($tool_options) { foreach ($tool_options as $group_option) { $option_toggle_name = $group_option->name . "_enable"; $option_default = $group->{$option_toggle_name} ?: $group_option->default_on ? 'yes' : 'no'; $group->{$option_toggle_name} = $params->{$option_toggle_name} ?: $option_default; } } // Group membership - should these be treated with same constants as access permissions? $is_public_membership = (int) $params->membership == ACCESS_PUBLIC; $group->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE; $group->setContentAccessMode($params->content_access_mode); if ($is_new_group) { $group->owner_guid = $user->guid; $group->access_id = ACCESS_PUBLIC; } if ($is_new_group) { // if new group, we need to save so group acl gets set in event handler if (!$group->save()) { throw new GraphException(elgg_echo("groups:save_error")); } } if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') { $visibility = (int) $params->vis; if ($visibility == ACCESS_PRIVATE) { // Make this group visible only to group members. We need to use // ACCESS_PRIVATE on the form and convert it to group_acl here // because new groups do not have acl until they have been saved once. $visibility = $group->group_acl; // Force all new group content to be available only to members $group->setContentAccessMode(ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY); } $group->access_id = $visibility; } if (!$group->save()) { throw new GraphException(elgg_echo("groups:save_error")); } $river_id = false; if ($is_new_group) { elgg_set_page_owner_guid($group->guid); $group->join($user); $river_id = elgg_create_river_item(array('view' => 'river/group/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $group->guid)); } $return = array('nodes' => array('group' => $group)); if ($river_id) { $river = elgg_get_river(array('ids' => $river_id)); $return['nodes']['activity'] = $river ? $river[0] : $river_id; } return $return; }
/** * List river items * * @param array $options Any options from elgg_get_river() plus: * pagination => BOOL Display pagination links (true) * @return string * @since 1.8.0 */ function elgg_list_river(array $options = array()) { global $autofeed; $autofeed = true; $defaults = array('offset' => (int) max(get_input('offset', 0), 0), 'limit' => (int) max(get_input('limit', 20), 0), 'pagination' => TRUE, 'list_class' => 'elgg-list-river elgg-river'); $options = array_merge($defaults, $options); $options['count'] = TRUE; $count = elgg_get_river($options); $options['count'] = FALSE; $items = elgg_get_river($options); $options['count'] = $count; $options['items'] = $items; return elgg_view('page/components/list', $options); }
function pleio_api_get_activity($group_id = 0, $offset = 0) { $offset = intval($offset); $group_id = intval($group_id); $joins = array(); $wheres = array(); if ($group_id) { $joins[] = sprintf(" JOIN %sentities e ON e.guid = rv.object_guid ", get_config("dbprefix")); } if ($group_id) { $wheres[] = " (e.container_guid = {$group_id} OR e.guid = {$group_id}) "; } $total = elgg_get_river(array("count" => true, "joins" => $joins, "wheres" => $wheres)); $rivers = elgg_get_river(array("offset" => $offset, "joins" => $joins, "wheres" => $wheres)); $list = array(); foreach ($rivers as $item) { $river = pleio_api_format_activity($item); if ($river) { $list[] = $river; } } return array("total" => $total, "list" => $list, "offset" => $offset); }
/** * Get river item * @return ElggRiverItem|false */ public function getRiverItem() { $id = $this->river_id; $items = elgg_get_river(array('ids' => $id, 'limit' => 1)); return is_array($items) && count($items) ? $items[0] : false; }
<?php /** * Shows the activity of your friends in the Digest * */ $user = elgg_extract("user", $vars, elgg_get_logged_in_user_entity()); $ts_lower = (int) elgg_extract("ts_lower", $vars); $ts_upper = (int) elgg_extract("ts_upper", $vars); $river_options = array("relationship" => "friend", "relationship_guid" => $user->getGUID(), "limit" => 5, "posted_time_lower" => $ts_lower, "posted_time_upper" => $ts_upper, "pagination" => false, "href" => 'none'); if ($vars['email']) { if ($river_items = elgg_get_river($river_options)) { $title = "<h2 class='email'>" . elgg_echo("river:friends") . "</h2>"; $title .= "<h5 class='email'>To view your colleagues activity visit " . elgg_get_site_url() . "activity/friends/" . $user->username . "</h5>"; echo $title; $summary = "<div class='email-section'>"; foreach ($river_items as $item) { $summary .= "<p>" . get_river_item_summary($item) . "</p>"; } $summary .= "</div>"; echo $summary; } } else { if ($river_items = elgg_list_river($river_options)) { $title = elgg_view("output/url", array("text" => elgg_echo("river:friends"))); $title .= "<h5>To view your colleagues activity visit " . elgg_get_site_url() . "activity/friends/" . $user->username . "</h5>"; echo elgg_view_module("digest", $title, $river_items); } }
/** * Returns a node from it's uid * * @param string $uid UID of the resource * @return mixed */ public function get($uid = '') { switch ($uid) { case 'me': $uid = "ue" . elgg_get_logged_in_user_guid(); break; case 'site': $uid = "se" . elgg_get_site_entity()->guid; break; } if (substr($uid, 0, 2) == 'an') { $id = (int) substr($uid, 2); $node = elgg_get_annotation_from_id($id); } else { if (substr($uid, 0, 2) == 'md') { $id = (int) substr($uid, 2); $node = elgg_get_metadata_from_id($id); } else { if (substr($uid, 0, 2) == 'rl') { $id = (int) substr($uid, 2); $node = get_relationship($id); } else { if (substr($uid, 0, 2) == 'rv') { $id = (int) substr($uid, 2); $river = elgg_get_river(array('ids' => sanitize_int($id))); $node = $river ? $river[0] : false; } else { if (in_array(substr($uid, 0, 2), array('ue', 'se', 'oe', 'ge'))) { $id = (int) substr($uid, 2); $node = get_entity($id); } else { if (is_numeric($uid)) { $node = get_entity($uid); } else { $node = get_user_by_username($uid); } } } } } } if (!$this->isExportable($node)) { return false; } return $node; }
<?php /** * Elgg ajax edit comment form * * @package Elgg * @subpackage Core */ $river_guid = get_input('guid'); $guid_string = get_input('guid_string'); if ($guid_string) { $river_guids = explode('_', $guid_string); $river_guid = ''; foreach ($river_guids as $river_guid_tmp) { $river_guid = empty($river_guid) ? $river_guid_tmp : $river_guid . ',' . $river_guid_tmp; $river_items = elgg_get_river(array('id' => $river_guid_tmp)); $thewire = $river_items[0]->getObjectEntity(); $guid = empty($guid) ? $thewire->getGuid() : $guid . ',' . $thewire->getGuid(); $container_guid = empty($container_guid) ? $thewire->getContainerGuid() : $container_guid . ',' . $thewire->getContainerGuid(); } } else { $river_items = elgg_get_river(array('id' => $river_guid)); $thewire = $river_items[0]->getObjectEntity(); $guid = $thewire->getGuid(); $container_guid = $thewire->getContainerGUID(); } $form_vars = array('class' => 'hidden mvl', 'id' => "elgg-form-gc_wire-save-{$river_guid}"); $body_vars = array('guid' => $guid, 'container_guid' => $container_guid, 'river_guid' => $river_guid, 'thewire' => $thewire); echo '<div>' . elgg_view_form('compound/add', $form_vars, $body_vars) . '</div>';
public function testElggRiverDisableEnable() { $user = new \ElggUser(); $user->save(); $entity = new \ElggObject(); $entity->save(); $params = array('view' => 'river/relationship/friend/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $entity->guid); $id = elgg_create_river_item($params); $river = elgg_get_river(array('ids' => array($id))); $this->assertIdentical($river[0]->enabled, 'yes'); $user->disable(); // should no longer be able to get the river $river = elgg_get_river(array('ids' => array($id))); $this->assertIdentical($river, array()); // renabling the user should re-enable the river access_show_hidden_entities(true); $user->enable(); access_show_hidden_entities(false); $river = elgg_get_river(array('ids' => array($id))); $this->assertIdentical($river[0]->enabled, 'yes'); $user->delete(); $entity->delete(); }
/** * Ajaxmodule page handler * * @param array $page From the page_handler function * @return true|false Depending on success * */ function ajaxmodule_page_handler($page) { switch ($page[0]) { case 'load_activity_ping': // check for last checked time if (!($seconds_passed = get_input('seconds_passed', 0))) { echo ''; exit; } $last_reload = time() - $seconds_passed; // Get current count of entries $current_count = elgg_get_river(array('count' => TRUE)); // Get the count at the last reload $last_count = elgg_get_river(array('count' => TRUE, 'posted_time_upper' => $last_reload)); if ($current_count > $last_count) { $count = $current_count - $last_count; $s = $count == 1 ? '' : 's'; $link = "<a id='refresh-river-module' href='#' class='update_link'>{$count} update{$s}!</a>"; $page_title = "[{$count} update{$s}] "; echo json_encode(array('count' => $count, 'link' => $link)); exit; } break; case 'loadriver': // River options $options['ids'] = get_input('ids'); $options['subject_guids'] = json_decode(get_input('subject_guids')); $options['object_guids'] = json_decode(get_input('object_guids')); $options['annotation_ids'] = json_decode(get_input('annotation_ids')); $options['action_types'] = json_decode(get_input('action_types')); $options['posted_time_lower'] = get_input('posted_time_lower'); $options['posted_time_upper'] = get_input('posted_time_upper'); $options['types'] = get_input('types'); $options['subtypes'] = get_input('subtypes'); $options['type_subtype_pairs'] = json_decode(get_input('type_subtype_pairs')); $options['relationship'] = get_input('relationship'); $options['relationship_guid'] = get_input('relationship_guid'); $options['inverse_relationship'] = get_input('inverse_relationship'); $options['limit'] = get_input('limit', 15); $options['offset'] = get_input('offset', 0); $options['count'] = get_input('count'); $options['order_by'] = get_input('order_by'); $options['group_by'] = get_input('group_by'); // Remove empty options foreach ($options as $key => $option) { if ($option === NULL || empty($options)) { unset($options[$key]); } } $options = elgg_trigger_plugin_hook('get_options', 'river', '', $options); // Display river $river = elgg_list_river($options); if (!$river) { echo "<div style='font-weight: bold; margin-top: 10px; margin-bottom: 10px; border-top: 1px solid #aaa; width: 100%; text-align: center;'>" . elgg_echo('river:none') . "</div>"; } else { //echo $river; echo elgg_trigger_plugin_hook('output', 'page', array(), $river); } break; case 'loadentities': // Entity options $options['container_guid'] = get_input('container_guid'); $options['tag'] = get_input('tag', false); $options['tags'] = json_decode(get_input('tags', false)); $options['types'] = json_decode(get_input('types')); $options['subtypes'] = json_decode(get_input('subtypes')); $options['limit'] = get_input('limit', 10); $options['offset'] = get_input('offset', 0); $options['owner_guids'] = json_decode(get_input('owner_guids')); $options['created_time_upper'] = get_input('created_time_upper'); $options['created_time_lower'] = get_input('created_time_lower'); $options['count'] = get_input('count', FALSE); // Store access status $access_status = access_get_show_hidden_status(); // Check if bypassing hidden entities if (get_input('access_show_hidden_entities')) { // Override access_show_hidden_entities(true); } // Set 'listing type' for new simple listing if supplied if ($listing_type = get_input('listing_type', FALSE)) { set_input('ajaxmodule_listing_type', $listing_type); } // Make sure container guid isn't empty $options['container_guid'] = !empty($options['container_guid']) ? $options['container_guid'] : ELGG_ENTITIES_ANY_VALUE; if (get_input('restrict_tag')) { // Grab content with supplied tags ONLY elgg_set_context('search'); $options['type'] = 'object'; $options['full_view'] = FALSE; // Multiple tags if ($options['tags']) { foreach ($options['tags'] as $tag) { $options['metadata_name_value_pairs'][] = array('name' => 'tags', 'value' => $tag, 'operand' => '=', 'case_sensitive' => FALSE); } } else { // Just one $options['metadata_name_value_pairs'] = array(array('name' => 'tags', 'value' => $options['tag'], 'operand' => '=', 'case_sensitive' => FALSE)); unset($options['tag']); } unset($options['tags']); // Let plugins decide if we want to check the container of the container as well (ie photos) if ($options['container_guid'] && elgg_trigger_plugin_hook('check_parent_container', 'modules', $options['subtypes'], FALSE)) { $dbprefix = elgg_get_config('dbprefix'); $cont = sanitise_int($options['container_guid']); $options['joins'][] = "JOIN {$dbprefix}entities container_e on e.container_guid = container_e.guid"; $options['wheres'][] = "(e.container_guid in ({$cont}) OR container_e.container_guid in ({$cont}))"; unset($options['container_guid']); } if ($options['count']) { $entities = elgg_get_entities_from_metadata($options); echo $entities; break; } else { $content = elgg_list_entities_from_metadata($options); } } else { if (get_input('albums_images')) { // Grab photos with tag, including photos in albums with tag $options['full_view'] = FALSE; $options['list_type'] = 'gallery'; $content = elgg_list_entities($options, 'am_get_entities_from_tag_and_container_tag'); } else { if (!get_input('restrict_tag') && $options['container_guid'] != ELGG_ENTITIES_ANY_VALUE) { // Container supplied, and not restricting tags $options['full_view'] = FALSE; $content = elgg_list_entities($options); } else { // Default to container or tag $content = am_list_entities_by_container_or_tag($options); } } } // Display friendly message if there is no content if (!$content) { echo "<div style='width: 100%; text-align: center; margin: 10px;'><strong>No results</strong></div>"; } else { echo $content; } break; default: access_show_hidden_entities($access_status); return FALSE; } access_show_hidden_entities($access_status); return TRUE; }
/** * 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()]; }
function threads_groupforumpost_2012100501($post) { require_once elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php'; global $MIGRATED; $MIGRATED += 1; if ($MIGRATED % 100 == 0) { error_log("post {$post->guid}"); } // get content from annotations and copy into description $annotations = $post->getAnnotations('group_topic_post'); foreach ($annotations as $annotation) { if ($annotation->value) { $post->description = $annotation->value; } $annotation->delete(); } // fix relationships $topic = current($post->getEntitiesFromRelationship('group_discussion_top_level_post', true)); if ($topic) { // top level post $topic->removeRelationship($post->guid, 'group_discussion_top_level_post'); $parent = $topic; } else { // reply $topic = current($post->getEntitiesFromRelationship('group_discussion_topic_link', true)); $parent = current($post->getEntitiesFromRelationship('group_discussion_reply_post', true)); if ($topic) { $topic->removeRelationship($post->guid, 'group_discussion_topic_link'); } if ($parent) { $parent->removeRelationship($post->guid, 'group_discussion_reply_post'); } } if ($parent) { $post->addRelationship($parent->guid, 'parent'); } if ($topic) { $post->addRelationship($topic->guid, 'top'); } $post->save(); upgrade_change_subtype($post, 'topicreply'); // update river $options = array('object_guid' => $post->guid); $items = elgg_get_river($options); foreach ($items as $item) { upgrade_update_river($item->id, 'river/forum/create', $topic->guid, $post->guid); } return true; }
function getRiverGuidPosition($guid) { $notFound = true; $offset = 0; while ($notFound) { $options = array('distinct' => false, 'offset' => $offset, 'limit' => 1); $activity = elgg_get_river($options); if (sizeof($activity) > 0) { if ($activity[0]->object_guid == $guid) { $notFound = false; } else { $offset = $offset + 1; } } else { $notFound = false; } } return $offset; }
/** * Retrieves items from the river. All parameters are optional. * * @param int|array $subject_guid Acting entity to restrict to. Default: all * @param int|array $object_guid Entity being acted on to restrict to. Default: all * @param string $subject_relationship If set to a relationship type, this will use * $subject_guid as the starting point and set the * subjects to be all users this * entity has this relationship with (eg 'friend'). * Default: blank * @param string $type The type of entity to restrict to. Default: all * @param string $subtype The subtype of entity to restrict to. Default: all * @param string $action_type The type of river action to restrict to. Default: all * @param int $limit The number of items to retrieve. Default: 20 * @param int $offset The page offset. Default: 0 * @param int $posted_min The minimum time period to look at. Default: none * @param int $posted_max The maximum time period to look at. Default: none * * @return array|false Depending on success * @deprecated 1.8 Use elgg_get_river() */ function get_river_items($subject_guid = 0, $object_guid = 0, $subject_relationship = '', $type = '', $subtype = '', $action_type = '', $limit = 20, $offset = 0, $posted_min = 0, $posted_max = 0) { elgg_deprecated_notice("get_river_items deprecated by elgg_get_river", 1.8); $options = array(); if ($subject_guid) { $options['subject_guid'] = $subject_guid; } if ($object_guid) { $options['object_guid'] = $object_guid; } if ($subject_relationship) { $options['relationship'] = $subject_relationship; unset($options['subject_guid']); $options['relationship_guid'] = $subject_guid; } if ($type) { $options['type'] = $type; } if ($subtype) { $options['subtype'] = $subtype; } if ($action_type) { $options['action_type'] = $action_type; } $options['limit'] = $limit; $options['offset'] = $offset; if ($posted_min) { $options['posted_time_lower'] = $posted_min; } if ($posted_max) { $options['posted_time_upper'] = $posted_max; } return elgg_get_river($options); }
} } // End of Update PART 3/5 // Begin of Update PART 4/5: // Check for album comments without a river entry and delete them (for each comment made on the activity page // on an image upload a second comment annotation (on Elgg 1.9 it has been converted to an entity) was created // with Tidypics 1.8.1betaXX that showed up on the corresponding album page while the first comment annotation // was only visible below the river entry on the activity page. This second comment annotation is now no longer // necessary and should be removed to avoid comments appearing twice on album pages) // ATTENTION: this part of the upgrade script will remove ALL album comment entities (formerly annotations on Elgg 1.9) // that don't a corresponding river entry. If you removed the river entries by any means or prevented them from getting // created in the first place you might not want this part of the upgrade to be executed. Then you should comment out part 4 // of the upgrade. But you will most likely end with double comments on album pages then. $batch = new ElggBatch('elgg_get_entities', array('type' => 'object', 'subtype' => 'comment', 'joins' => array("JOIN {$db_prefix}entities al ON al.guid = e.container_guid"), 'wheres' => array("al.subtype = {$album_subtype_id}"), 'limit' => false)); foreach ($batch as $album_comment) { $river_entry_count = elgg_get_river(array('type' => 'object', 'subtype' => 'comment', 'action_type' => 'comment', 'object_guid' => $album_comment->guid, 'target_guid' => $album_comment->container_guid, 'count' => true)); if ($river_entry_count < 1) { $album_comment->delete(); } } // End of Update Part 4/5 // Begin of Update Part 5/5 // Update likes made to Tidypics batches and assign them either to the image uploaded (if only one) or the album $batch = new ElggBatch('elgg_get_annotations', array('annotation_name' => 'likes', 'joins' => array("JOIN {$db_prefix}entities li ON li.guid = n_table.entity_guid"), 'wheres' => array("li.subtype = {$tidypics_batch_subtype_id}"), 'limit' => false)); foreach ($batch as $like_entry) { // Get the batch entity $tidypics_batch = get_entity($like_entry->entity_guid); // Get images related to this batch $images = elgg_get_entities_from_relationship(array('relationship' => 'belongs_to_batch', 'relationship_guid' => $tidypics_batch->getGUID(), 'inverse_relationship' => true, 'type' => 'object', 'subtype' => 'image', 'limit' => false)); // move the like to the album if more than a single image was uploaded in this batch if (count($images) > 1) {