From: Mikael Nordfeldth Date: Wed, 18 Feb 2015 10:08:11 +0000 (+0100) Subject: Make group search in Directory use PEAR::DB X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b039d960f50dc0307e85604009ba4b10717a1d75;p=quix0rs-gnu-social.git Make group search in Directory use PEAR::DB No more direct SQL queries please. --- diff --git a/plugins/Directory/actions/groupdirectory.php b/plugins/Directory/actions/groupdirectory.php index 5e532fc214..496f035570 100644 --- a/plugins/Directory/actions/groupdirectory.php +++ b/plugins/Directory/actions/groupdirectory.php @@ -27,12 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) -{ - exit(1); -} - -require_once INSTALLDIR . '/lib/publicgroupnav.php'; +if (!defined('GNUSOCIAL')) { exit(1); } /** * Group directory @@ -40,6 +35,7 @@ require_once INSTALLDIR . '/lib/publicgroupnav.php'; * @category Directory * @package StatusNet * @author Zach Copley + * @author Mikael Nordfeldth * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -308,6 +304,14 @@ class GroupdirectoryAction extends Action if (isset($this->q)) { + // Disable this to get global group searches + $group->joinAdd(array('id', 'local_group:group_id')); + + $wheres = array('nickname', 'fullname', 'homepage', 'description', 'location'); + foreach ($wheres as $where) { + $group->whereAdd("LOWER({$group->__table}.{$where}) LIKE LOWER('%".$group->escape($this->q)."%')", 'OR'); + } + $order = 'user_group.created ASC'; if ($this->sort == 'nickname') { @@ -322,17 +326,8 @@ class GroupdirectoryAction extends Action } } - $sql = <<< GROUP_QUERY_END -SELECT user_group.* -FROM user_group -JOIN local_group ON user_group.id = local_group.group_id -ORDER BY %s -LIMIT %d, %d -GROUP_QUERY_END; - - $cnt = 0; - $group->query(sprintf($sql, $order, $limit, $offset)); - $group->find(); + $group->orderBy($order); + $group->limit($offset, $limit); } else { // User is browsing via AlphaNav @@ -371,6 +366,8 @@ GROUP_QUERY_END; $group->query($sql); } + $group->find(); + return $group; }