From fb0c80db9c929d77bee607ceff580f368a2cd2a6 Mon Sep 17 00:00:00 2001 From: "wlee@mozilla.com" Date: Thu, 3 Dec 2009 21:38:12 +0000 Subject: [PATCH] Fixed random breakage to existing code; refactoring git-svn-id: http://svn.mozilla.org/projects/phonebook/trunk@57212 4eb1ac78-321c-0410-a911-ec516a8615a5 --- config.php | 8 ++++++++ search.php | 10 ---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/config.php b/config.php index f3a815c..31b7636 100644 --- a/config.php +++ b/config.php @@ -127,6 +127,14 @@ class MozillaSearchAdapter extends SearchAdapter { ); public function search_users($search) { + if ($search != "random") { + return $this->_search_users($search); + } + $entries = $this->_search_users('*'); + return array($entries[mt_rand(0, count($entries) - 1)]); + } + + public function _search_users($search) { $filter = ($search == '*') ? 'objectClass=mozComPerson' : "(&(|(cn=*$search*)(mail=*$search*)(im=*$search*))(objectClass=mozComPerson))"; return $this->query_users($filter, 'dc=mozilla', $this->fields); } diff --git a/search.php b/search.php index 4d27421..36ba78b 100644 --- a/search.php +++ b/search.php @@ -6,17 +6,7 @@ require_once("preprocessors-attr.inc"); $auth = new MozillaAuthAdapter(); $search = new MozillaSearchAdapter($ldapconn); $keyword = isset($_GET["query"]) ? $_GET["query"] : '*'; - -if ($keyword == 'random') { - $keyword = '*'; - $random = true; -} - $entries = normalize($search->search_users($keyword)); -$entries = array( -0 => $entries[mt_rand(0, count($entries)-1)] -); - $attr_preps = get_attr_preprocessors(); $preprocess_attr_functions = array();