aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/sites.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/sites.php')
-rw-r--r--engine/lib/sites.php44
1 files changed, 43 insertions, 1 deletions
diff --git a/engine/lib/sites.php b/engine/lib/sites.php
index 9d81c7364..fe8a23cf1 100644
--- a/engine/lib/sites.php
+++ b/engine/lib/sites.php
@@ -500,7 +500,49 @@
return false;
}
-
+ /**
+ * Searches for a site based on a complete or partial name or description or url using full text searching.
+ *
+ * IMPORTANT NOTE: With MySQL's default setup:
+ * 1) $criteria must be 4 or more characters long
+ * 2) If $criteria matches greater than 50% of results NO RESULTS ARE RETURNED!
+ *
+ * @param string $criteria The partial or full name or username.
+ * @param int $limit Limit of the search.
+ * @param int $offset Offset.
+ * @param string $order_by The order.
+ * @param boolean $count Whether to return the count of results or just the results.
+ */
+ function search_for_site($criteria, $limit = 10, $offset = 0, $order_by = "", $count = false)
+ {
+ global $CONFIG;
+
+ $criteria = sanitise_string($criteria);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $order_by = sanitise_string($order_by);
+
+ $access = get_access_sql_suffix("e");
+
+ if ($order_by == "") $order_by = "e.time_created desc";
+
+ if ($count) {
+ $query = "SELECT count(e.guid) as total ";
+ } else {
+ $query = "SELECT e.* ";
+ }
+ $query .= "from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}sites_entity s on e.guid=s.guid where match(s.name,s.description,s.url) against ('$criteria') and $access";
+
+ 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;
+ }
/**