Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
3babb8c2
Commit
3babb8c2
authored
Apr 14, 2012
by
Robin Appelman
Browse files
improve flexibility of search providers a bit
parent
8ed46066
Changes
8
Hide whitespace changes
Inline
Side-by-side
apps/bookmarks/lib/search.php
View file @
3babb8c2
...
...
@@ -20,8 +20,8 @@
*
*/
class
OC_Search_Provider_Bookmarks
implem
en
t
s
OC_Search_Provider
{
static
function
search
(
$query
){
class
OC_Search_Provider_Bookmarks
ext
en
d
s
OC_Search_Provider
{
function
search
(
$query
){
$results
=
array
();
$offset
=
0
;
...
...
apps/calendar/lib/search.php
View file @
3babb8c2
<?php
class
OC_Search_Provider_Calendar
implem
en
t
s
OC_Search_Provider
{
static
function
search
(
$query
){
class
OC_Search_Provider_Calendar
ext
en
d
s
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;
...
...
apps/contacts/lib/search.php
View file @
3babb8c2
<?php
class
OC_Search_Provider_Contacts
implem
en
t
s
OC_Search_Provider
{
static
function
search
(
$query
){
class
OC_Search_Provider_Contacts
ext
en
d
s
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;
...
...
apps/gallery/appinfo/app.php
View file @
3babb8c2
...
...
@@ -41,8 +41,8 @@ OC_App::addNavigationEntry( array(
'icon'
=>
OC_Helper
::
imagePath
(
'core'
,
'places/picture.svg'
),
'name'
=>
$l
->
t
(
'Pictures'
)));
class
OC_GallerySearchProvider
implem
en
t
s
OC_Search_Provider
{
static
function
search
(
$query
){
class
OC_GallerySearchProvider
ext
en
d
s
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
();
...
...
apps/media/lib_media.php
View file @
3babb8c2
...
...
@@ -82,8 +82,8 @@ class OC_MEDIA{
}
}
class
OC_MediaSearchProvider
implem
en
t
s
OC_Search_Provider
{
static
function
search
(
$query
){
class
OC_MediaSearchProvider
ext
en
d
s
OC_Search_Provider
{
function
search
(
$query
){
require_once
(
'lib_collection.php'
);
$artists
=
OC_MEDIA_COLLECTION
::
getArtists
(
$query
);
$albums
=
OC_MEDIA_COLLECTION
::
getAlbums
(
0
,
$query
);
...
...
lib/search.php
View file @
3babb8c2
...
...
@@ -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
);
}
}
}
lib/search/provider.php
View file @
3babb8c2
...
...
@@ -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
*/
stat
ic
function
search
(
$query
)
;
publ
ic
function
search
(
$query
)
{}
}
lib/search/provider/file.php
View file @
3babb8c2
<?php
class
OC_Search_Provider_File
implem
en
t
s
OC_Search_Provider
{
static
function
search
(
$query
){
class
OC_Search_Provider_File
ext
en
d
s
OC_Search_Provider
{
function
search
(
$query
){
$files
=
OC_FileCache
::
search
(
$query
,
true
);
$results
=
array
();
foreach
(
$files
as
$fileData
){
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment