From 22356533a0529197d8a4c383307b566f94ed6fc4 Mon Sep 17 00:00:00 2001
From: Thomas Tanghus <thomas@tanghus.net>
Date: Thu, 12 Jan 2012 16:06:27 +0100
Subject: [PATCH] Added search. Thanks to icewind it was mostly copy/paste :-)

---
 apps/contacts/appinfo/app.php |  4 +++-
 apps/contacts/lib/search.php  | 29 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 apps/contacts/lib/search.php

diff --git a/apps/contacts/appinfo/app.php b/apps/contacts/appinfo/app.php
index 524cc640bc..1e9f881172 100644
--- a/apps/contacts/appinfo/app.php
+++ b/apps/contacts/appinfo/app.php
@@ -1,4 +1,5 @@
 <?php
+$l=new OC_L10N('calendar');
 
 OC::$CLASSPATH['OC_Contacts_App'] = 'apps/contacts/lib/app.php';
 OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php';
@@ -17,7 +18,8 @@ OC_App::addNavigationEntry( array(
   'order' => 10,
   'href' => OC_Helper::linkTo( 'contacts', 'index.php' ),
   'icon' => OC_Helper::imagePath( 'settings', 'users.svg' ),
-  'name' => 'Contacts' ));
+  'name' => $l->t('Contacts') ));
 
 
 OC_APP::registerPersonal('contacts','settings');
+require_once('apps/contacts/lib/search.php');
\ No newline at end of file
diff --git a/apps/contacts/lib/search.php b/apps/contacts/lib/search.php
new file mode 100644
index 0000000000..9763882100
--- /dev/null
+++ b/apps/contacts/lib/search.php
@@ -0,0 +1,29 @@
+<?php
+class OC_Search_Provider_Contacts extends OC_Search_Provider{
+	function search($query){
+		$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser(), 1);
+// 		if(count($calendars)==0 || !OC_App::isEnabled('contacts')){
+// 			//return false;
+// 		}
+		// NOTE: Does the following do anything
+		$results=array();
+		$searchquery=array();
+		if(substr_count($query, ' ') > 0){
+			$searchquery = explode(' ', $query);
+		}else{
+			$searchquery[] = $query;
+		}
+		$l = new OC_l10n('contacts');
+		foreach($addressbooks as $addressbook){
+			$vcards = OC_Contacts_VCard::all($addressbook['id']);
+			foreach($vcards as $vcard){
+				if(substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0){
+					$link = OC_Helper::linkTo('apps/contacts', 'index.php?id='.urlencode($vcard['id']));
+					$results[]=new OC_Search_Result($vcard['fullname'],'', $link,$l->t('Contact'));//$name,$text,$link,$type
+				}
+			}
+		}
+		return $results;
+	}
+}
+new OC_Search_Provider_Contacts();
-- 
GitLab