diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-04-14 11:29:44 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-04-14 11:29:54 +0200 |
commit | 3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472 (patch) | |
tree | a1e466f4875a4766124427f91a5db35c57e0fffd | |
parent | 8ed4606685f93f5fea002aecaf5279f482e78115 (diff) | |
download | nextcloud-server-3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472.tar.gz nextcloud-server-3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472.zip |
improve flexibility of search providers a bit
-rw-r--r-- | apps/bookmarks/lib/search.php | 4 | ||||
-rw-r--r-- | apps/calendar/lib/search.php | 4 | ||||
-rw-r--r-- | apps/contacts/lib/search.php | 4 | ||||
-rw-r--r-- | apps/gallery/appinfo/app.php | 4 | ||||
-rw-r--r-- | apps/media/lib_media.php | 4 | ||||
-rw-r--r-- | lib/search.php | 30 | ||||
-rw-r--r-- | lib/search/provider.php | 6 | ||||
-rw-r--r-- | lib/search/provider/file.php | 4 |
8 files changed, 43 insertions, 17 deletions
diff --git a/apps/bookmarks/lib/search.php b/apps/bookmarks/lib/search.php index 235587855d9..d7e32558617 100644 --- a/apps/bookmarks/lib/search.php +++ b/apps/bookmarks/lib/search.php @@ -20,8 +20,8 @@ * */ -class OC_Search_Provider_Bookmarks implements OC_Search_Provider{ - static function search($query){ +class OC_Search_Provider_Bookmarks extends OC_Search_Provider{ + function search($query){ $results=array(); $offset = 0; diff --git a/apps/calendar/lib/search.php b/apps/calendar/lib/search.php index 8405866392d..da5fa35bc21 100644 --- a/apps/calendar/lib/search.php +++ b/apps/calendar/lib/search.php @@ -1,6 +1,6 @@ <?php -class OC_Search_Provider_Calendar implements OC_Search_Provider{ - static function search($query){ +class OC_Search_Provider_Calendar extends OC_Search_Provider{ + function search($query){ $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); if(count($calendars)==0 || !OC_App::isEnabled('calendar')){ //return false; diff --git a/apps/contacts/lib/search.php b/apps/contacts/lib/search.php index cf0a5fe6997..31d8542091e 100644 --- a/apps/contacts/lib/search.php +++ b/apps/contacts/lib/search.php @@ -1,6 +1,6 @@ <?php -class OC_Search_Provider_Contacts implements OC_Search_Provider{ - static function search($query){ +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; diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php index f7e0651275e..325c2acf249 100644 --- a/apps/gallery/appinfo/app.php +++ b/apps/gallery/appinfo/app.php @@ -41,8 +41,8 @@ OC_App::addNavigationEntry( array( 'icon' => OC_Helper::imagePath('core', 'places/picture.svg'), 'name' => $l->t('Pictures'))); - class OC_GallerySearchProvider implements OC_Search_Provider{ - static function search($query){ +class OC_GallerySearchProvider extends OC_Search_Provider{ + function search($query){ $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ? AND album_name LIKE ?'); $result = $stmt->execute(array(OC_User::getUser(),'%'.$query.'%')); $results=array(); diff --git a/apps/media/lib_media.php b/apps/media/lib_media.php index 9de291e8da2..a4e5a5dfebc 100644 --- a/apps/media/lib_media.php +++ b/apps/media/lib_media.php @@ -82,8 +82,8 @@ class OC_MEDIA{ } } -class OC_MediaSearchProvider implements OC_Search_Provider{ - static function search($query){ +class OC_MediaSearchProvider extends OC_Search_Provider{ + function search($query){ require_once('lib_collection.php'); $artists=OC_MEDIA_COLLECTION::getArtists($query); $albums=OC_MEDIA_COLLECTION::getAlbums(0,$query); diff --git a/lib/search.php b/lib/search.php index 6b33fa38140..12055418687 100644 --- a/lib/search.php +++ b/lib/search.php @@ -26,13 +26,22 @@ */ class OC_Search{ static private $providers=array(); + static private $registeredProviders=array(); + + /** + * remove all registered search providers + */ + public static function clearProviders(){ + self::$providers=array(); + self::$registeredProviders=array(); + } /** * register a new search provider to be used * @param string $provider class name of a OC_Search_Provider */ - public static function registerProvider($provider){ - self::$providers[]=$provider; + public static function registerProvider($class,$options=array()){ + self::$registeredProviders[]=array('class'=>$class,'options'=>$options); } /** @@ -41,10 +50,25 @@ class OC_Search{ * @return array An array of OC_Search_Result's */ public static function search($query){ + self::initProviders(); $results=array(); foreach(self::$providers as $provider){ - $results=array_merge($results, $provider::search($query)); + $results=array_merge($results, $provider->search($query)); } return $results; } + + /** + * create instances of all the registered search providers + */ + private static function initProviders(){ + if(count(self::$providers)>0){ + return; + } + foreach(self::$registeredProviders as $provider){ + $class=$provider['class']; + $options=$provider['options']; + self::$providers[]=new $class($options); + } + } } diff --git a/lib/search/provider.php b/lib/search/provider.php index 9487ca51f2b..838ab696d04 100644 --- a/lib/search/provider.php +++ b/lib/search/provider.php @@ -2,11 +2,13 @@ /** * provides search functionalty */ -interface OC_Search_Provider { +class OC_Search_Provider { + public function __construct($options){} + /** * search for $query * @param string $query * @return array An array of OC_Search_Result's */ - static function search($query); + public function search($query){} } diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php index 3bdb3bcd2af..a37af495599 100644 --- a/lib/search/provider/file.php +++ b/lib/search/provider/file.php @@ -1,7 +1,7 @@ <?php -class OC_Search_Provider_File implements OC_Search_Provider{ - static function search($query){ +class OC_Search_Provider_File extends OC_Search_Provider{ + function search($query){ $files=OC_FileCache::search($query,true); $results=array(); foreach($files as $fileData){ |