aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/elgglib.php48
-rw-r--r--engine/lib/entities.php26
-rw-r--r--engine/lib/metadata.php118
-rw-r--r--engine/lib/relationships.php25
-rw-r--r--engine/lib/sites.php22
-rw-r--r--engine/lib/users.php42
-rw-r--r--languages/en.php3
-rw-r--r--search/index.php12
-rw-r--r--views/default/navigation/pagination.php82
9 files changed, 345 insertions, 33 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 3670cd884..dae53daa9 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -239,6 +239,54 @@
}
/**
+ * Returns a view of a list of entities, plus navigation. It is intended that this function
+ * be called from other wrapper functions.
+ *
+ * @see list_entities
+ * @see list_user_objects
+ * @see list_user_friends_objects
+ * @see list_entities_from_metadata
+ * @see list_entities_from_metadata_multi
+ * @see list_entities_from_relationships
+ * @see list_site_members
+ *
+ * @param array $entities List of entities
+ * @param int $count The total number of entities across all pages
+ * @param int $offset The current indexing offset
+ * @param int $limit The number of entities to display per page
+ * @return string The list of entities
+ */
+ function elgg_view_entity_list($entities, $count, $offset, $limit) {
+
+ $count = (int) $count;
+ $offset = (int) $offset;
+ $limit = (int) $limit;
+
+ $html = "";
+
+ $nav = elgg_view('navigation/pagination',array(
+
+ 'baseurl' => $_SERVER['REQUEST_URI'],
+ 'offset' => $offset,
+ 'count' => $count,
+
+ ));
+
+ $html .= $nav;
+
+ if (is_array($entities) && sizeof($entities) > 0) {
+ foreach($entities as $entity) {
+ $html .= elgg_view_entity($entity, "", false);
+ }
+ }
+
+ $html .= $nav;
+
+ return $html;
+
+ }
+
+ /**
* Displays an internal layout for the use of a plugin canvas.
* Takes a variable number of parameters, which are made available
* in the views as $vars['area1'] .. $vars['areaN'].
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index e9f795d11..c57a13d46 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1016,7 +1016,7 @@
* @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
* @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
*/
- function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "time_created desc", $limit = 10, $offset = 0, $count = false, $site_guid = 0)
+ function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0)
{
global $CONFIG;
@@ -1025,7 +1025,8 @@
$type = sanitise_string($type);
$subtype = get_subtype_id($type, $subtype);
-
+
+ if ($order_by == "") $order_by = "time_created desc";
$order_by = sanitise_string($order_by);
$limit = (int)$limit;
$offset = (int)$offset;
@@ -1072,6 +1073,27 @@
return $total->total;
}
}
+
+ /**
+ * Returns a viewable list of entities
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param string $type The type of entity (eg "user", "object" etc)
+ * @param string $subtype The arbitrary subtype of the entity
+ * @param int $owner_guid The GUID of the owning user
+ * @param int $limit The number of entities to display per page (default: 10)
+ * @return string A viewable list of entities
+ */
+ function list_entities($type= "", $subtype = "", $owner_guid = 0, $limit = 10) {
+
+ $offset = (int) get_input('offset');
+ $count = get_entities($type, $subtype, $owner_guid, "", $limit, $offset, true);
+ $entities = get_entities($type, $subtype, $owner_guid, "", $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit);
+
+ }
/**
* Delete a given entity.
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 7923039b1..d01ce0985 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -370,17 +370,18 @@
* @param string $order_by Optional ordering.
* @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
*/
- function find_metadata($meta_name = "", $meta_value = "", $entity_type = "", $entity_subtype = "", $limit = 10, $offset = 0, $order_by = "e.time_created desc", $site_guid = 0)
+ function find_metadata($meta_name = "", $meta_value = "", $entity_type = "", $entity_subtype = "", $limit = 10, $offset = 0, $order_by = "", $site_guid = 0)
{
global $CONFIG;
$meta_n = get_metastring_id($meta_name);
- $meta_v = get_metastring_id($meta_value);
-
+ $meta_v = get_metastring_id($meta_value);
+
$entity_type = sanitise_string($entity_type);
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);
$limit = (int)$limit;
- $offset = (int)$offset;
+ $offset = (int)$offset;
+ if ($order_by == "") $order_by = "e.time_created desc";
$order_by = sanitise_string($order_by);
$site_guid = (int) $site_guid;
if ($site_guid == 0)
@@ -419,9 +420,12 @@
* @param int $limit
* @param int $offset
* @param string $order_by Optional ordering.
- * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ *
+ * @return int|array A list of entities, or a count if $count is set to true
*/
- function get_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "e.time_created desc", $site_guid = 0)
+ function get_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false)
{
global $CONFIG;
@@ -431,7 +435,8 @@
$entity_type = sanitise_string($entity_type);
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);
$limit = (int)$limit;
- $offset = (int)$offset;
+ $offset = (int)$offset;
+ if ($order_by == "") $order_by = "e.time_created desc";
$order_by = sanitise_string($order_by);
$site_guid = (int) $site_guid;
$owner_guid = (int) $owner_guid;
@@ -454,14 +459,50 @@
$where[] = "e.site_guid = {$site_guid}";
if ($owner_guid > 0)
$where[] = "e.owner_guid = {$owner_guid}";
-
- $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid where";
+
+ if (!$count) {
+ $query = "SELECT distinct e.* ";
+ } else {
+ $query = "SELECT count(e.guid) as total ";
+ }
+
+ $query .= "from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid where";
foreach ($where as $w)
$query .= " $w and ";
- $query .= get_access_sql_suffix("e"); // Add access controls
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
-
- return get_data($query, "entity_row_to_elggstar");
+ $query .= get_access_sql_suffix("e"); // Add access controls
+
+ if (!$count) {
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($row = get_data_row($query))
+ return $row->total;
+ }
+ return false;
+ }
+
+ /**
+ * Return a list of entities suitable for display based on the given search criteria.
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param mixed $meta_name Metadata name to search on
+ * @param mixed $meta_value The value to match, optionally
+ * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
+ * @param string $entity_subtype The subtype of the entity
+ * @param int $limit Number of entities to display per page
+ *
+ * @return string A list of entities suitable for display
+ */
+ function list_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10) {
+
+ $offset = (int) get_input('offset');
+ $limit = (int) $limit;
+ $count = get_entities_from_metadata($meta_name, $meta_value, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, true);
+ $entities = get_entities_from_metadata($meta_name, $meta_value, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, false);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit);
+
}
/**
@@ -474,9 +515,10 @@
* @param int $offset
* @param string $order_by Optional ordering.
* @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
- * @return array List of ElggEntities
+ * @param true|false $count If set to true, returns the total number of entities rather than a list. (Default: false)
+ * @return int|array List of ElggEntities, or the total number if count is set to false
*/
- function get_entities_from_metadata_multi($meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "e.time_created desc", $site_guid = 0)
+ function get_entities_from_metadata_multi($meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false)
{
global $CONFIG;
@@ -503,6 +545,7 @@
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);
$limit = (int)$limit;
$offset = (int)$offset;
+ if ($order_by == "") $order_by = "e.time_created desc";
$order_by = sanitise_string($order_by);
$owner_guid = (int) $owner_guid;
@@ -521,13 +564,50 @@
if ($owner_guid > 0)
$where[] = "e.owner_guid = {$owner_guid}";
- $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e {$join} where";
+ if ($count) {
+ $query = "SELECT count(e.guid) as total ";
+ } else {
+ $query = "SELECT distinct e.* ";
+ }
+
+ $query .= " from {$CONFIG->dbprefix}entities e {$join} where";
foreach ($where as $w)
$query .= " $w and ";
$query .= get_access_sql_suffix("e"); // Add access controls
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
-
- return get_data($query, "entity_row_to_elggstar");
+
+ if (!$count) {
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($count = get_data_row($query)) {
+ return $count->total;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns a viewable list of entities based on the given search criteria.
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param array $meta_array Array of 'name' => 'value' pairs
+ * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
+ * @param string $entity_subtype The subtype of the entity.
+ * @param int $limit
+ * @param int $offset
+ * @param string $order_by Optional ordering.
+ * @return string List of ElggEntities suitable for display
+ */
+ function list_entities_from_metadata_multi($meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10) {
+
+ $offset = (int) get_input('offset');
+ $limit = (int) $limit;
+ $count = get_entities_from_metadata_multi($meta_array, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", $site_guid, true);
+ $entities = get_entities_from_metadata_multi($meta_array, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", $site_guid, false);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit);
+
}
/**
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php
index ebcd1ef88..f715f4a58 100644
--- a/engine/lib/relationships.php
+++ b/engine/lib/relationships.php
@@ -485,6 +485,31 @@
}
return false;
+ }
+
+ /**
+ * Returns a viewable list of entities by relationship
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param string $relationship The relationship eg "friends_of"
+ * @param int $relationship_guid The guid of the entity to use query
+ * @param bool $inverse_relationship Reverse the normal function of the query to instead say "give me all entities for whome $relationship_guid is a $relationship of"
+ * @param string $type The type of entity (eg 'object')
+ * @param string $subtype The entity subtype
+ * @param int $owner_guid The owner (default: all)
+ * @param int $limit The number of entities to display on a page
+ * @return string The viewable list of entities
+ */
+ function list_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $limit = 0) {
+
+ $limit = (int) $limit;
+ $offset = (int) get_input('offset');
+ $count = get_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship, $type, $subtype, $owner_guid, "", $limit, 0, true);
+ $entities = get_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship, $type, $subtype, $owner_guid, "", $limit, 0, true);
+
+ return elgg_view_entity_list($entities, $count, $offset, $Limit);
+
}
/**** HELPER FUNCTIONS FOR RELATIONSHIPS OF TYPE 'ATTACHED' ****/
diff --git a/engine/lib/sites.php b/engine/lib/sites.php
index c8636fdc8..9d81c7364 100644
--- a/engine/lib/sites.php
+++ b/engine/lib/sites.php
@@ -367,6 +367,24 @@
$offset = (int)$offset;
return get_entities_from_relationship("member_of_site", $site_guid, true, "user", "", 0, "time_created desc", $limit, $offset);
+ }
+
+ /**
+ * Display a list of site members
+ *
+ * @param int $site_guid The GUID of the site
+ * @param int $limit The number of members to display on a page
+ * @return string A displayable list of members
+ */
+ function list_site_members($site_guid, $limit = 10) {
+
+ $offset = (int) get_input('offset');
+ $limit = (int) $limit;
+ $count = (int) get_entities_from_relationship("member_of_site", $site_guid, true, "user", "", 0, "time_created desc", $limit, $offset, true);
+ $entities = get_site_members($site_guid, $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit);
+
}
/**
@@ -415,8 +433,8 @@
$offset = (int)$offset;
return get_entities_from_relationship("member_of_site", $site_guid, true, "object", $subtype, 0, "time_created desc", $limit, $offset);
- }
-
+ }
+
/**
* Add a collection to a site.
*
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 5065a633a..16e7a2c5f 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -526,6 +526,27 @@
$total = get_entities('object', $subtype, $user_guid, "time_created desc", null, null, true);
return $total;
}
+
+ /**
+ * Displays a list of user objects of a particular subtype, with navigation.
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param int $user_guid The GUID of the user
+ * @param string $subtype The object subtype
+ * @param int $limit The number of entities to display on a page
+ * @return string The list in a form suitable to display
+ */
+ function list_user_objects($user_guid, $subtype = "", $limit = 10) {
+
+ $offset = (int) get_input('offset');
+ $limit = (int) $limit;
+ $count = (int) count_user_objects($user_guid, $subtype);
+ $entities = get_user_objects($user_guid, $subtype, $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit);
+
+ }
/**
* Obtains a list of objects owned by a user's friends
@@ -566,6 +587,27 @@
}
/**
+ * Displays a list of a user's friends' objects of a particular subtype, with navigation.
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param int $user_guid The GUID of the user
+ * @param string $subtype The object subtype
+ * @param int $limit The number of entities to display on a page
+ * @return string The list in a form suitable to display
+ */
+ function list_user_friends_objects($user_guid, $subtype = "", $limit = 10) {
+
+ $offset = (int) get_input('offset');
+ $limit = (int) $limit;
+ $count = (int) count_user_friends_objects($user_guid, $subtype);
+ $entities = get_user_friends_objects($user_guid, $subtype, $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit);
+
+ }
+
+ /**
* Get user objects by an array of metadata
*
* @param int $user_guid The GUID of the owning user
diff --git a/languages/en.php b/languages/en.php
index 1641c206d..4c7e2249a 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -201,6 +201,9 @@
'search' => "Search",
'searchtitle' => "Search: %s",
+ 'notfound' => "No results found.",
+ 'next' => "Next",
+ 'previous' => "Previous",
/**
* Account
diff --git a/search/index.php b/search/index.php
index da94ed493..33a32046f 100644
--- a/search/index.php
+++ b/search/index.php
@@ -17,19 +17,11 @@
// Get input
$tag = get_input('tag');
- $offset = get_input('offset',0);
$subtype = get_input('subtype');
$objecttype = get_input('object');
- $body = "";
-
- if ($entities = get_entities_from_metadata("",$tag,"",$subtype,0,15,$offset)) {
-
- foreach($entities as $entity) {
- $body .= elgg_view_entity($entity);
- }
-
- }
+ $body = list_entities_from_metadata("", $tag, "", $subtype);
+ $body = elgg_view_layout('one_column',$body);
page_draw(sprintf(elgg_echo('searchtitle'),$tag),$body);
diff --git a/views/default/navigation/pagination.php b/views/default/navigation/pagination.php
new file mode 100644
index 000000000..c946544ae
--- /dev/null
+++ b/views/default/navigation/pagination.php
@@ -0,0 +1,82 @@
+<?php
+
+ /**
+ * Elgg pagination
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ */
+
+ if (!isset($vars['offset'])) {
+ $offset = 0;
+ } else {
+ $offset = $vars['offset'];
+ }
+ if (!isset($vars['limit'])) {
+ $limit = 10;
+ } else {
+ $limit = $vars['limit'];
+ }
+ if (!isset($vars['count'])) {
+ $count = 0;
+ } else {
+ $count = $vars['count'];
+ }
+
+ $totalpages = ceil($count / $limit);
+ $currentpage = ceil($offset / $limit) + 1;
+
+ $baseurl = preg_replace('/[\&\?]offset\=[0-9]*/',"",$vars['baseurl']);
+
+?>
+
+<div class="pagination">
+ <p>
+<?php
+
+ if ($count == 0) {
+
+ echo elgg_echo("notfound");
+
+ }
+
+ if ($offset > 0) {
+
+ $prevoffset = $offset - $limit;
+ if ($prevoffset < 0) $prevoffset = 0;
+
+ $prevurl = $baseurl;
+ if (substr_count($baseurl,'?')) {
+ $prevurl .= "&offset=" . $prevoffset;
+ } else {
+ $prevurl .= "?offset=" . $prevoffset;
+ }
+
+ echo "<a href=\"{$prevurl}\">&lt;&lt; ". elgg_echo("previous") ."</a> ";
+
+ }
+
+ if ($offset < ($count - $limit)) {
+
+ $nextoffset = $offset + $limit;
+ if ($nextoffset >= $count) $nextoffset--;
+
+ $nexturl = $baseurl;
+ if (substr_count($baseurl,'?')) {
+ $nexturl .= "&offset=" . $nextoffset;
+ } else {
+ $nexturl .= "?offset=" . $nextoffset;
+ }
+
+ echo " <a href=\"{$nexturl}\">" . elgg_echo("next") . " &gt;&gt;</a>";
+
+ }
+
+?>
+ </p>
+</div> \ No newline at end of file