diff options
| author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-13 12:32:43 +0000 | 
|---|---|---|
| committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-12-13 12:32:43 +0000 | 
| commit | d611e9c962ce825eb7f4600f27f74c3dc477000f (patch) | |
| tree | f5b600ce1ef7e27536548b514b3144ae138f1c7c /engine/lib | |
| parent | f03c3bd5bfa8d8425121c769b27c4382147dec65 (diff) | |
| download | elgg-d611e9c962ce825eb7f4600f27f74c3dc477000f.tar.gz elgg-d611e9c962ce825eb7f4600f27f74c3dc477000f.tar.bz2 | |
Refs #2226 moving riverdashboard into core - need to clean up riverdashboard plugin and move to plugins repository and update plugins with new river views
git-svn-id: http://code.elgg.org/elgg/trunk@7610 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
| -rw-r--r-- | engine/lib/annotations.php | 7 | ||||
| -rw-r--r-- | engine/lib/river.php | 772 | ||||
| -rw-r--r-- | engine/lib/views.php | 31 | 
3 files changed, 444 insertions, 366 deletions
| diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index f858fa8d1..a0665f744 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -595,7 +595,12 @@ function list_annotations($entity_guid, $name = "", $limit = 25, $asc = true) {  	$offset = (int) get_input("annoff", 0);  	$annotations = get_annotations($entity_guid, "", "", $name, "", "", $limit, $offset, $asc); -	return elgg_view_annotation_list($annotations, $count, $offset, $limit); +	$params = array( +		'count'  => $count, +		'offset' => $offset, +		'limit'  => $count, +	); +	return elgg_view_annotation_list($annotations, $params);  }  /** diff --git a/engine/lib/river.php b/engine/lib/river.php index ad069d5cf..46f11da46 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -1,7 +1,7 @@  <?php  /** - * Elgg river 2.0. - * Functions for listening for and generating the river separately from the system log. + * Elgg river. + * Activity stream functions.   *   * @package Elgg.Core   * @subpackage SocialModel.River @@ -142,148 +142,373 @@ function remove_from_river_by_id($id) {  }  /** - * Sets the access ID on river items for a particular object + * Get river items   * - * @param int $object_guid The GUID of the entity - * @param int $access_id   The access ID + * @param array $options + *   subject_guids        => INT|ARR Subject guid(s) + *   object_guids         => INT|ARR Object guid(s) + *   annotation_ids       => INT|ARR The identifier of the annotation(s) + *   action_types         => STR|ARR The river action type(s) identifier + *   posted_time_lower    => INT     The lower bound on the time posted + *   posted_time_upper    => INT     The upper bound on the time posted   * - * @return bool Depending on success + *   types                => STR|ARR Entity type string(s) + *   subtypes             => STR|ARR Entity subtype string(s) + *   type_subtype_pairs   => ARR     Array of type => subtype pairs where subtype + *                                   can be an array of subtype strings + * + *   relationship         => STR     Relationship identifier + *   relationship_guid    => INT|ARR Entity guid(s) + *   inverse_relationship => BOOL    Subject or object of the relationship (false) + * + * 	 limit                => INT     Number to show per page (20) + *   offset               => INT     Offset in list (0) + *   count                => BOOL    Count the river items? (false) + *   order_by             => STR     Order by clause (rv.posted desc) + *   group_by             => STR     Group by clause + * + * @return array|int + * @since 1.8.0   */ -function update_river_access_by_object($object_guid, $access_id) { -	// Sanitise -	$object_guid = (int) $object_guid; -	$access_id = (int) $access_id; - -	// Load config +function elgg_get_river(array $options = array()) {  	global $CONFIG; -	// Remove -	$query = "update {$CONFIG->dbprefix}river -		set access_id = {$access_id} -		where object_guid = {$object_guid}"; -	return update_data($query); -} +	$defaults = array( +		'subject_guids'	       => ELGG_ENTITIES_ANY_VALUE, +		'object_guids'         => ELGG_ENTITIES_ANY_VALUE, +		'annotation_ids'       => ELGG_ENTITIES_ANY_VALUE, +		'action_types'         => ELGG_ENTITIES_ANY_VALUE, -/** - * 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 - */ -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) { +		'relationship'         => NULL, +		'relationship_guid'    => NULL, +		'inverse_relationship' => FALSE, -	// Get config -	global $CONFIG; +		'types'	               => ELGG_ENTITIES_ANY_VALUE, +		'subtypes'             => ELGG_ENTITIES_ANY_VALUE, +		'type_subtype_pairs'   => ELGG_ENTITIES_ANY_VALUE, -	// Sanitise variables -	if (!is_array($subject_guid)) { -		$subject_guid = (int) $subject_guid; -	} else { -		foreach ($subject_guid as $key => $temp) { -			$subject_guid[$key] = (int) $temp; +		'posted_time_lower'	   => ELGG_ENTITIES_ANY_VALUE, +		'posted_time_upper'	   => ELGG_ENTITIES_ANY_VALUE, + +		'limit'                => 20, +		'offset'               => 0, +		'count'                => FALSE, + +		'order_by'             => 'rv.posted desc', +		'group_by'             => ELGG_ENTITIES_ANY_VALUE, + +		'wheres'               => array(), +		'joins'                => array(), +	); + +	$options = array_merge($defaults, $options); + +	$singulars = array('subject_guid', 'object_guid', 'annotation_id', 'action_type', 'type', 'subtype'); +	$options = elgg_normalise_plural_options_array($options, $singulars); + +	$wheres = $options['wheres']; + +	$wheres[] = elgg_get_guid_based_where_sql('rv.subject_guid', $options['subject_guids']); +	$wheres[] = elgg_get_guid_based_where_sql('rv.object_guid', $options['object_guids']); +	$wheres[] = elgg_get_guid_based_where_sql('rv.annotation_id', $options['annotation_ids']); +	$wheres[] = elgg_river_get_action_where_sql($options['action_types']); +	$wheres[] = elgg_get_river_type_subtype_where_sql('rv', $options['types'], +		$options['subtypes'], $options['type_subtype_pairs']); + +	if ($options['posted_time_lower'] && is_int($options['posted_time_lower'])) { +		$wheres[] = "rv.posted >= {$options['posted_time_lower']}"; +	} + +	if ($options['posted_time_upper'] && is_int($options['posted_time_upper'])) { +		$wheres[] = "rv.posted <= {$options['posted_time_upper']}"; +	} + +	$joins = $options['joins']; + +	if ($options['relationship_guid']) { +		$clauses = elgg_get_entity_relationship_where_sql( +				'rv.subject_guid', +				$options['relationship'], +				$options['relationship_guid'], +				$options['inverse_relationship']); +		if ($clauses) { +			$wheres = array_merge($wheres, $clauses['wheres']); +			$joins = array_merge($joins, $clauses['joins']);  		}  	} -	if (!is_array($object_guid)) { -		$object_guid = (int) $object_guid; -	} else { -		foreach ($object_guid as $key => $temp) { -			$object_guid[$key] = (int) $temp; + +	// remove identical where clauses +	$wheres = array_unique($wheres); + +	// see if any functions failed +	// remove empty strings on successful functions +	foreach ($wheres as $i => $where) { +		if ($where === FALSE) { +			return FALSE; +		} elseif (empty($where)) { +			unset($wheres[$i]);  		}  	} -	if (!empty($type)) { -		$type = sanitise_string($type); + +	if (!$options['count']) { +		$query = "SELECT DISTINCT rv.* FROM {$CONFIG->dbprefix}river rv "; +	} else { +		$query = "SELECT count(DISTINCT rv.id) as total FROM {$CONFIG->dbprefix}river rv ";  	} -	if (!empty($subtype)) { -		$subtype = sanitise_string($subtype); + +	// add joins +	foreach ($joins as $j) { +		$query .= " $j ";  	} -	if (!empty($action_type)) { -		$action_type = sanitise_string($action_type); + +	// add wheres +	$query .= ' WHERE '; + +	foreach ($wheres as $w) { +		$query .= " $w AND ";  	} -	$limit = (int) $limit; -	$offset = (int) $offset; -	$posted_min = (int) $posted_min; -	$posted_max = (int) $posted_max; -	// Construct 'where' clauses for the river -	$where = array(); -	// river table does not have columns expected by get_access_sql_suffix so we modify its output -	$where[] = str_replace("and enabled='yes'", '', +	$query .= elgg_river_get_access_sql(); + +	if (!$options['count']) { +		$options['group_by'] = sanitise_string($options['group_by']); +		if ($options['group_by']) { +			$query .= " GROUP BY {$options['group_by']}"; +		} + +		$options['order_by'] = sanitise_string($options['order_by']); +		$query .= " ORDER BY {$options['order_by']}"; + +		if ($options['limit']) { +			$limit = sanitise_int($options['limit']); +			$offset = sanitise_int($options['offset']); +			$query .= " LIMIT $offset, $limit"; +		} + +		$river_items = get_data($query, 'elgg_row_to_elgg_river_item'); + +		return $river_items; +	} else { +		$total = get_data_row($query); +		return (int)$total->total; +	} +} + +/** + * 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()) { + +	$defaults = array( +		'offset'     => (int) max(get_input('offset', 0), 0), +		'limit'      => (int) max(get_input('limit', 20), 0), +		'pagination' => TRUE, +		'list_class' => '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('layout/objects/list', $options); +} + +/** + * Convert a database row to a new ElggRiverItem + * + * @param stdClass $row Database row from the river table + * + * @return ElggRiverItem + * @since 1.8.0 + * @access private + */ +function elgg_row_to_elgg_river_item($row) { +	if (!($row instanceof stdClass)) { +		return NULL; +	} + +	return new ElggRiverItem($row); +} + +/** + * Get the river's access where clause + * + * @return string + * @since 1.8.0 + * @access private + */ +function elgg_river_get_access_sql() { +	// rewrite default access where clause to work with river table +	return str_replace("and enabled='yes'", '',  		str_replace('owner_guid', 'subject_guid', get_access_sql_suffix())); +} -	if (empty($subject_relationship)) { -		if (!empty($subject_guid)) { -			if (!is_array($subject_guid)) { -				$where[] = " subject_guid = {$subject_guid} "; -			} else { -				$where[] = " subject_guid in (" . implode(',', $subject_guid) . ") "; +/** + * Returns SQL where clause for type and subtype on river table + * + * @internal This is a simplified version of elgg_get_entity_type_subtype_where_sql() + * which could be used for all queries once the subtypes have been denormalized. + * FYI: It allows types and subtypes to not be paired. + * + * @param string     $table    'rv' + * @param NULL|array $types    Array of types or NULL if none. + * @param NULL|array $subtypes Array of subtypes or NULL if none + * @param NULL|array $pairs    Array of pairs of types and subtypes + * + * @return string + * @since 1.8.0 + * @access private + */ +function elgg_get_river_type_subtype_where_sql($table, $types, $subtypes, $pairs) { +	// short circuit if nothing is requested +	if (!$types && !$subtypes && !$pairs) { +		return ''; +	} + +	$wheres = array(); + +	// if no pairs, use types and subtypes +	if (!is_array($pairs)) { +		if ($types) { +			if (!is_array($types)) { +				$types = array($types); +			} +			foreach ($types as $type) { +				$type = sanitise_string($type); +				$wheres[] = "({$table}.type = '$type')";  			}  		} + +		if ($subtypes) { +			if (!is_array($subtypes)) { +				$subtypes = array($subtypes); +			} +			foreach ($subtypes as $subtype) { +				$subtype = sanitise_string($subtype); +				$wheres[] = "({$table}.subtype = '$subtype')"; +			} +		} + +		if (is_array($wheres) && count($wheres)) { +			$wheres = array(implode(' AND ', $wheres)); +		}  	} else { -		if (!is_array($subject_guid)) { -			if ($entities = elgg_get_entities_from_relationship(array ( -				'relationship' => $subject_relationship, -				'relationship_guid' => $subject_guid, -				'limit' => 9999)) -			) { -				$guids = array(); -				foreach ($entities as $entity) { -					$guids[] = (int) $entity->guid; +		// using type/subtype pairs +		foreach ($pairs as $paired_type => $paired_subtypes) { +			$paired_type = sanitise_string($paired_type); +			if (is_array($paired_subtypes)) { +				$paired_subtypes = array_map('sanitise_string', $paired_subtypes); +				$paired_subtype_str = implode("','", $paired_subtypes); +				if ($paired_subtype_str) { +					$wheres[] = "({$table}.type = '$paired_type'" +						. " AND {$table}.subtype IN ('$paired_subtype_str'))";  				} -				$where[] = " subject_guid in (" . implode(',', $guids) . ") ";  			} else { -				return array(); +				$paired_subtype = sanitise_string($paired_subtypes); +				$wheres[] = "({$table}.type = '$paired_type'" +					. " AND {$table}.subtype = '$paired_subtype')";  			}  		}  	} -	if (!empty($object_guid)) { -		if (!is_array($object_guid)) { -			$where[] = " object_guid = {$object_guid} "; -		} else { -			$where[] = " object_guid in (" . implode(',', $object_guid) . ") "; -		} + +	if (is_array($wheres) && count($wheres)) { +		$where = implode(' OR ', $wheres); +		return "($where)";  	} -	if (!empty($type)) { -		$where[] = " type = '{$type}' "; + +	return ''; +} + +/** + * Get the where clause based on river action type strings + * + * @param array $types Array of action type strings + * + * @return string + * @since 1.8.0 + * @access private + */ +function elgg_river_get_action_where_sql($types) { +	if (!$types) { +		return '';  	} -	if (!empty($subtype)) { -		$where[] = " subtype = '{$subtype}' "; + +	if (!is_array($types)) { +		$types = sanitise_string($types); +		return "'(rv.action_type = '$types')";  	} -	if (!empty($action_type)) { -		$where[] = " action_type = '{$action_type}' "; + +	// sanitize types array +	$types_sanitized = array(); +	foreach ($types as $type) { +		$types_sanitized[] = sanitise_string($type);  	} -	if (!empty($posted_min)) { -		$where[] = " posted > {$posted_min} "; + +	$type_str = implode("','", $types_sanitized); +	return "(rv.action_type IN ('$type_str'))"; +} + +/** + * Returns a human-readable representation of a river item + * + * @param ElggRiverItem $item A river item object + * + * @return string|false Depending on success + */ +function elgg_view_river_item($item) { +	if (!$item || !$item->getView() || !elgg_view_exists($item->getView())) { +		return '';  	} -	if (!empty($posted_max)) { -		$where[] = " posted < {$posted_max} "; + +	$subject = $item->getSubjectEntity(); +	$object = $item->getObjectEntity(); +	if (!$subject || !$object) { +		// subject is disabled or subject/object deleted +		return '';  	} -	$whereclause = implode(' and ', $where); +	$vars = array( +		'pict' => elgg_view('core/river/image', array('item' => $item)), +		'body' => elgg_view('core/river/body', array('item' => $item)), +		'pict_alt' => elgg_view('core/river/controls', array('item' => $item)), +		'class' => 'elgg-river-item', +	); +	return elgg_view('layout/objects/media', $vars); +} -	// Construct main SQL -	$sql = "select id, type, subtype, action_type, access_id, view, -			subject_guid, object_guid, annotation_id, posted -		from {$CONFIG->dbprefix}river -		where {$whereclause} order by posted desc limit {$offset}, {$limit}"; +/** + * Sets the access ID on river items for a particular object + * + * @param int $object_guid The GUID of the entity + * @param int $access_id   The access ID + * + * @return bool Depending on success + */ +function update_river_access_by_object($object_guid, $access_id) { +	// Sanitise +	$object_guid = (int) $object_guid; +	$access_id = (int) $access_id; -	// Get data -	return get_data($sql); +	// Load config +	global $CONFIG; + +	// Remove +	$query = "update {$CONFIG->dbprefix}river +		set access_id = {$access_id} +		where object_guid = {$object_guid}"; +	return update_data($query);  }  /** @@ -293,8 +518,9 @@ $posted_max = 0) {   * @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 + *                                        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 @@ -304,140 +530,53 @@ $posted_max = 0) {   * @param int       $posted_max           The maximum time period to look at. Default: none   *   * @return array|false Depending on success + * @deprecated 1.8   */ -function elgg_get_river_items($subject_guid = 0, $object_guid = 0, $subject_relationship = '', -$type = '', $subtype = '', $action_type = '', $limit = 10, $offset = 0, $posted_min = 0, +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); -	// Get config -	global $CONFIG; +	$options = array(); -	// Sanitise variables -	if (!is_array($subject_guid)) { -		$subject_guid = (int) $subject_guid; -	} else { -		foreach ($subject_guid as $key => $temp) { -			$subject_guid[$key] = (int) $temp; -		} -	} -	if (!is_array($object_guid)) { -		$object_guid = (int) $object_guid; -	} else { -		foreach ($object_guid as $key => $temp) { -			$object_guid[$key] = (int) $temp; -		} -	} -	if (!empty($type)) { -		$type = sanitise_string($type); -	} -	if (!empty($subtype)) { -		$subtype = sanitise_string($subtype); +	if ($subject_guid) { +		$options['subject_guid'] = $subject_guid;  	} -	if (!empty($action_type)) { -		$action_type = sanitise_string($action_type); -	} -	$limit = (int) $limit; -	$offset = (int) $offset; -	$posted_min = (int) $posted_min; -	$posted_max = (int) $posted_max; - -	// Construct 'where' clauses for the river -	$where = array(); -	// river table does not have columns expected by get_access_sql_suffix so we modify its output -	$where[] = str_replace("and enabled='yes'", '', -		str_replace('owner_guid', 'subject_guid', get_access_sql_suffix_new('er', 'e'))); -	if (empty($subject_relationship)) { -		if (!empty($subject_guid)) { -			if (!is_array($subject_guid)) { -				$where[] = " subject_guid = {$subject_guid} "; -			} else { -				$where[] = " subject_guid in (" . implode(',', $subject_guid) . ") "; -			} -		} -	} else { -		if (!is_array($subject_guid)) { -			$entities = elgg_get_entities_from_relationship(array( -				'relationship' => $subject_relationship, -				'relationship_guid' => $subject_guid, -				'limit' => 9999, -			)); -			if (is_array($entities) && !empty($entities)) { -				$guids = array(); -				foreach ($entities as $entity) { -					$guids[] = (int) $entity->guid; -				} -				// $guids[] = $subject_guid; -				$where[] = " subject_guid in (" . implode(',', $guids) . ") "; -			} else { -				return array(); -			} -		} -	} -	if (!empty($object_guid)) { -		if (!is_array($object_guid)) { -			$where[] = " object_guid = {$object_guid} "; -		} else { -			$where[] = " object_guid in (" . implode(',', $object_guid) . ") "; -		} +	if ($object_guid) { +		$options['object_guid'] = $object_guid;  	} -	if (!empty($type)) { -		$where[] = " er.type = '{$type}' "; -	} -	if (!empty($subtype)) { -		$where[] = " er.subtype = '{$subtype}' "; -	} -	if (!empty($action_type)) { -		$where[] = " action_type = '{$action_type}' "; + +	if ($subject_relationship) { +		$options['relationship'] = $subject_relationship; +		unset($options['subject_guid']); +		$options['relationship_guid'] = $subject_guid;  	} -	if (!empty($posted_min)) { -		$where[] = " posted > {$posted_min} "; + +	if ($type) { +		$options['type'] = $type;  	} -	if (!empty($posted_max)) { -		$where[] = " posted < {$posted_max} "; + +	if ($subtype) { +		$options['subtype'] = $subtype;  	} -	$whereclause = implode(' and ', $where); +	if ($action_type) { +		$options['action_type'] = $action_type; +	} -	// Construct main SQL -	$sql = "select er.*" . -			" from {$CONFIG->dbprefix}river er, {$CONFIG->dbprefix}entities e " . -			" where {$whereclause} AND er.object_guid = e.guid GROUP BY object_guid " . -			" ORDER BY e.last_action desc LIMIT {$offset}, {$limit}"; +	$options['limit'] = $limit; +	$options['offset'] = $offset; -	// Get data -	return get_data($sql); -} +	if ($posted_min) { +		$options['posted_time_lower'] = $posted_min; +	} -/** - * Returns a human-readable representation of a river item - * - * @see get_river_items - * - * @param stdClass $item A river item object as returned from get_river_items - * - * @return string|false Depending on success - */ -function elgg_view_river_item($item) { -	if (isset($item->view)) { -		$object = get_entity($item->object_guid); -		$subject = get_entity($item->subject_guid); -		if (!$object || !$subject) { -			// probably means an entity is disabled -			return false; -		} else { -			if (elgg_view_exists($item->view)) { -				$body = elgg_view($item->view, array( -					'item' => $item -				)); -			} -		} -		return elgg_view('river/item/wrapper', array( -			'item' => $item, -			'body' => $body -		)); +	if ($posted_max) { +		$options['posted_time_upper'] = $posted_max;  	} -	return false; + +	return elgg_get_river($options);  }  /** @@ -456,147 +595,42 @@ function elgg_view_river_item($item) {   * @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   * @param bool      $pagination           Show pagination? - * @param $bool     $chronological        Show in chronological order?   *   * @return string Human-readable river. + * @deprecated 1.8   */  function elgg_view_river_items($subject_guid = 0, $object_guid = 0, $subject_relationship = '',  $type = '', $subtype = '', $action_type = '', $limit = 20, $posted_min = 0, -$posted_max = 0, $pagination = true, $chronological = false) { +$posted_max = 0, $pagination = true) { +	elgg_deprecated_notice("elgg_view_river_items deprecated for elgg_list_river", 1.8); + +	$river_items = get_river_items($subject_guid, $object_guid, $subject_relationship, +			$type, $subtype, $action_type, $limit + 1, $posted_min, $posted_max);  	// Get input from outside world and sanitise it  	$offset = (int) get_input('offset', 0); -	// Get the correct function -	if ($chronological == true) { -		$riveritems = get_river_items($subject_guid, $object_guid, $subject_relationship, $type, -			$subtype, $action_type, ($limit + 1), $offset, $posted_min, $posted_max); -	} else { -		$riveritems = elgg_get_river_items($subject_guid, $object_guid, $subject_relationship, $type, -			$subtype, $action_type, ($limit + 1), $offset, $posted_min, $posted_max); -	} - -	// Get river items, if they exist -	if ($riveritems) { - -		return elgg_view('river/item/list', array( -			'limit' => $limit, -			'offset' => $offset, -			'items' => $riveritems, -			'pagination' => $pagination -		)); - -	} - -	return ''; -} - -/** - * This function has been added here until we decide if it is going to roll into core or not - * Add access restriction sql code to a given query. - * Note that if this code is executed in privileged mode it will return blank. - * - * @TODO: DELETE once Query classes are fully integrated - * - * @param string $table_prefix_one Optional table. prefix for the access code. - * @param string $table_prefix_two Another optiona table prefix? - * @param int    $owner            Owner GUID - * - * @return string - */ -function get_access_sql_suffix_new($table_prefix_one = '', $table_prefix_two = '', $owner = null) { -	global $ENTITY_SHOW_HIDDEN_OVERRIDE, $CONFIG; - -	$sql = ""; -	$friends_bit = ""; -	$enemies_bit = ""; - -	if ($table_prefix_one) { -			$table_prefix_one = sanitise_string($table_prefix_one) . "."; -	} - -	if ($table_prefix_two) { -			$table_prefix_two = sanitise_string($table_prefix_two) . "."; -	} - -	if (!isset($owner)) { -		$owner = get_loggedin_userid(); -	} - -	if (!$owner) { -		$owner = -1; -	} - -	$ignore_access = elgg_check_access_overrides($owner); -	$access = get_access_list($owner); - -	if ($ignore_access) { -		$sql = " (1 = 1) "; -	} else if ($owner != -1) { -		$friends_bit = "{$table_prefix_one}access_id = " . ACCESS_FRIENDS . " -			AND {$table_prefix_one}owner_guid IN ( -				SELECT guid_one FROM {$CONFIG->dbprefix}entity_relationships -				WHERE relationship='friend' AND guid_two=$owner -			)"; - -		$friends_bit = '(' . $friends_bit . ') OR '; - -		if ((isset($CONFIG->user_block_and_filter_enabled)) && ($CONFIG->user_block_and_filter_enabled)) { -			// check to see if the user is in the entity owner's block list -			// or if the entity owner is in the user's filter list -			// if so, disallow access -			$enemies_bit = get_annotation_sql('elgg_block_list', "{$table_prefix_one}owner_guid", -				$owner, false); - -			$enemies_bit = '(' -				. $enemies_bit -				. '	AND ' . get_annotation_sql('elgg_filter_list', $owner, "{$table_prefix_one}owner_guid", -					false) -			. ')'; -		} -	} - -	if (empty($sql)) { -		$sql = " $friends_bit ({$table_prefix_one}access_id IN {$access} -			OR ({$table_prefix_one}owner_guid = {$owner}) -			OR ( -				{$table_prefix_one}access_id = " . ACCESS_PRIVATE . " -				AND {$table_prefix_one}owner_guid = $owner -			) -		)"; -	} - -	if ($enemies_bit) { -		$sql = "$enemies_bit AND ($sql)"; -	} - -	if (!$ENTITY_SHOW_HIDDEN_OVERRIDE) { -		$sql .= " and {$table_prefix_two}enabled='yes'"; -	} - -	return '(' . $sql . ')'; +	// view them +	$params = array( +		'items' => $river_items, +		'count' => count($river_items), +		'offset' => $offset, +		'limit' => $limit, +		'pagination' => $pagination, +		'list-class' => 'elgg-river-list', +	); + +	return elgg_view('layout/objects/list', $params);  }  /**   * Construct and execute the query required for the activity stream.   *   * @deprecated 1.8 - * - * @param int    $limit              Limit the query. - * @param int    $offset             Execute from the given object - * @param mixed  $type               A type, or array of types to look for. - *                                   Note: This is how they appear in the SYSTEM LOG. - * @param mixed  $subtype            A subtype, or array of types to look for. - *                                   Note: This is how they appear in the SYSTEM LOG. - * @param mixed  $owner_guid         The guid or a collection of GUIDs - * @param string $owner_relationship If defined, the relationship between $owner_guid and - *                                   the entity owner_guid - so "is $owner_guid $owner_relationship - *                                   with $entity->owner_guid" - * - * @return array An array of system log entries.   */  function get_activity_stream_data($limit = 10, $offset = 0, $type = "", $subtype = "",  $owner_guid = "", $owner_relationship = "") { +	elgg_deprecated_notice("get_activity_stream_data was deprecated", 1.8);  	global $CONFIG; @@ -744,3 +778,35 @@ $owner_guid = "", $owner_relationship = "") {  		ORDER BY sl.time_created desc limit $offset, $limit";  	return get_data($query);  } + +/** + * Page handler for activiy + * + * @param array $page + */ +function elgg_river_page_handler($page) { +	global $CONFIG; + +	elgg_set_page_owner_guid(get_loggedin_userid()); + +	$page_type = elgg_get_array_value(0, $page, 'all'); +	if ($page_type == 'owner') { +		$page_type = 'mine'; +	} + +	// content filter code here +	$entity_type = ''; +	$entity_subtype = ''; + +	require_once("{$CONFIG->path}pages/river.php"); +} + +/** + * Initialize river library + */ +function elgg_river_init() { +	register_page_handler('activity', 'elgg_river_page_handler'); +	add_menu(elgg_echo('activity'), "pg/activity/"); +} + +elgg_register_event_handler('init', 'system', 'elgg_river_init'); diff --git a/engine/lib/views.php b/engine/lib/views.php index 7c542b289..fa65bcae8 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -835,18 +835,17 @@ $list_type_toggle = true, $pagination = true) {   * @return string The list of annotations   * @access private   */ -function elgg_view_annotation_list($annotations, $count, $offset, $limit) { -	$params = array( +function elgg_view_annotation_list($annotations, array $vars = array()) { +	$defaults = array(  		'items' => $annotations, -		'count' => (int) $count, -		'offset' => (int) $offset, -		'limit' => (int) $limit, -		'list-class' => 'elgg-annotation-list', +		'list_class' => 'elgg-annotation-list',  		'full_view' => true,  		'offset_key' => 'annoff',  	); -	return elgg_view('layout/objects/list', $params); +	$vars = array_merge($defaults, $vars); + +	return elgg_view('layout/objects/list', $vars);  }  /** @@ -1062,11 +1061,19 @@ function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {   * @since 1.8.0   * @access private   */ -function elgg_view_list_item($item, $full_view, $vars) { -	if (elgg_instanceof($item)) { -		return elgg_view_entity($item, $full_view); -	} else { -		return elgg_view_annotation($item, $full_view); +function elgg_view_list_item($item, $full_view, array $vars = array()) { +	switch ($item->getType()) { +		case 'user': +		case 'object': +		case 'group': +		case 'site': +			return elgg_view_entity($item, $full_view); +		case 'annotation': +			return elgg_view_annotation($item, $full_view); +		case 'river': +			return elgg_view_river_item($item); +		default: +			break;  	}  } | 
