зеркало из https://github.com/nextcloud/server.git
Search: Change provider registration to class name, for lazy loading of search providers
This commit is contained in:
Родитель
8c7b13db70
Коммит
d1dcd7893c
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
OC::$CLASSPATH['OC_Bookmarks_Bookmarks'] = 'apps/bookmarks/lib/bookmarks.php';
|
||||
OC::$CLASSPATH['OC_Search_Provider_Bookmarks'] = 'apps/bookmarks/lib/search.php';
|
||||
|
||||
OC_App::register( array( 'order' => 70, 'id' => 'bookmark', 'name' => 'Bookmarks' ));
|
||||
|
||||
|
@ -15,5 +16,5 @@ $l = new OC_l10n('bookmarks');
|
|||
OC_App::addNavigationEntry( array( 'id' => 'bookmarks_index', 'order' => 70, 'href' => OC_Helper::linkTo( 'bookmarks', 'index.php' ), 'icon' => OC_Helper::imagePath( 'bookmarks', 'bookmarks.png' ), 'name' => $l->t('Bookmarks')));
|
||||
|
||||
OC_App::registerPersonal('bookmarks', 'settings');
|
||||
require_once('apps/bookmarks/lib/search.php');
|
||||
OC_Util::addScript('bookmarks','bookmarksearch');
|
||||
OC_Search::registerProvider('OC_Search_Provider_Bookmarks');
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class OC_Search_Provider_Bookmarks extends OC_Search_Provider{
|
||||
function search($query){
|
||||
class OC_Search_Provider_Bookmarks implements OC_Search_Provider{
|
||||
static function search($query){
|
||||
$results=array();
|
||||
|
||||
$offset = 0;
|
||||
|
@ -45,6 +45,3 @@ class OC_Search_Provider_Bookmarks extends OC_Search_Provider{
|
|||
return $results;
|
||||
}
|
||||
}
|
||||
new OC_Search_Provider_Bookmarks();
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,6 +6,7 @@ if(version_compare(PHP_VERSION, '5.3.0', '>=')){
|
|||
OC::$CLASSPATH['OC_Calendar_Object'] = 'apps/calendar/lib/object.php';
|
||||
OC::$CLASSPATH['OC_Calendar_Hooks'] = 'apps/calendar/lib/hooks.php';
|
||||
OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php';
|
||||
OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php';
|
||||
OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser');
|
||||
OC_Util::addScript('calendar','loader');
|
||||
OC_App::register( array(
|
||||
|
@ -19,5 +20,5 @@ if(version_compare(PHP_VERSION, '5.3.0', '>=')){
|
|||
'icon' => OC_Helper::imagePath( 'calendar', 'icon.svg' ),
|
||||
'name' => $l->t('Calendar')));
|
||||
OC_App::registerPersonal('calendar', 'settings');
|
||||
require_once('apps/calendar/lib/search.php');
|
||||
OC_Search::registerProvider('OC_Search_Provider_Calendar');
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
class OC_Search_Provider_Calendar extends OC_Search_Provider{
|
||||
function search($query){
|
||||
class OC_Search_Provider_Calendar implements OC_Search_Provider{
|
||||
static function search($query){
|
||||
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1);
|
||||
if(count($calendars)==0 || !OC_App::isEnabled('calendar')){
|
||||
//return false;
|
||||
|
@ -44,4 +44,3 @@ class OC_Search_Provider_Calendar extends OC_Search_Provider{
|
|||
return $results;
|
||||
}
|
||||
}
|
||||
new OC_Search_Provider_Calendar();
|
||||
|
|
|
@ -4,6 +4,7 @@ OC::$CLASSPATH['OC_Contacts_Addressbook'] = 'apps/contacts/lib/addressbook.php';
|
|||
OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php';
|
||||
OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';
|
||||
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV'] = 'apps/contacts/lib/connector_sabre.php';
|
||||
OC::$CLASSPATH['OC_Search_Provider_Contacts'] = 'apps/contacts/lib/search.php';
|
||||
OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Contacts_Hooks', 'deleteUser');
|
||||
OC_HOOK::connect('OC_Calendar', 'getEvents', 'OC_Contacts_Hooks', 'getBirthdayEvents');
|
||||
OC_HOOK::connect('OC_Calendar', 'getSources', 'OC_Contacts_Hooks', 'getCalenderSources');
|
||||
|
@ -23,4 +24,4 @@ OC_App::addNavigationEntry( array(
|
|||
|
||||
OC_APP::registerPersonal('contacts','settings');
|
||||
OC_UTIL::addScript('contacts', 'loader');
|
||||
require_once('apps/contacts/lib/search.php');
|
||||
OC_Search::registerProvider('OC_Search_Provider_Contacts');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
class OC_Search_Provider_Contacts extends OC_Search_Provider{
|
||||
function search($query){
|
||||
class OC_Search_Provider_Contacts implements OC_Search_Provider{
|
||||
static function search($query){
|
||||
$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser(), 1);
|
||||
// if(count($calendars)==0 || !OC_App::isEnabled('contacts')){
|
||||
// //return false;
|
||||
|
@ -26,4 +26,3 @@ class OC_Search_Provider_Contacts extends OC_Search_Provider{
|
|||
return $results;
|
||||
}
|
||||
}
|
||||
new OC_Search_Provider_Contacts();
|
||||
|
|
|
@ -40,8 +40,8 @@ OC_App::addNavigationEntry( array(
|
|||
'icon' => OC_Helper::imagePath('core', 'places/picture.svg'),
|
||||
'name' => $l->t('Gallery')));
|
||||
|
||||
class OC_GallerySearchProvider extends OC_Search_Provider{
|
||||
function search($query){
|
||||
class OC_GallerySearchProvider implements OC_Search_Provider{
|
||||
static 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();
|
||||
|
@ -52,7 +52,7 @@ OC_App::addNavigationEntry( array(
|
|||
}
|
||||
}
|
||||
|
||||
new OC_GallerySearchProvider();
|
||||
OC_Search::registerProvider('OC_GallerySearchProvider');
|
||||
|
||||
require_once('apps/gallery/lib/hooks_handlers.php');
|
||||
?>
|
||||
|
|
|
@ -30,4 +30,5 @@ OC_APP::registerPersonal('media','settings');
|
|||
OC_App::register( array( 'order' => 3, 'id' => 'media', 'name' => 'Media' ));
|
||||
|
||||
OC_App::addNavigationEntry(array('id' => 'media_index', 'order' => 2, 'href' => OC_Helper::linkTo('media', 'index.php'), 'icon' => OC_Helper::imagePath('core', 'places/music.svg'), 'name' => $l->t('Music')));
|
||||
?>
|
||||
|
||||
OC_Search::registerProvider('OC_MediaSearchProvider');
|
||||
|
|
|
@ -82,8 +82,8 @@ class OC_MEDIA{
|
|||
}
|
||||
}
|
||||
|
||||
class OC_MediaSearchProvider extends OC_Search_Provider{
|
||||
function search($query){
|
||||
class OC_MediaSearchProvider implements OC_Search_Provider{
|
||||
static function search($query){
|
||||
require_once('lib_collection.php');
|
||||
$artists=OC_MEDIA_COLLECTION::getArtists($query);
|
||||
$albums=OC_MEDIA_COLLECTION::getAlbums(0,$query);
|
||||
|
@ -107,5 +107,3 @@ class OC_MediaSearchProvider extends OC_Search_Provider{
|
|||
}
|
||||
}
|
||||
|
||||
new OC_MediaSearchProvider();
|
||||
?>
|
||||
|
|
|
@ -7,4 +7,4 @@ OC_App::register( array( "order" => 2, "id" => "files", "name" => "Files" ));
|
|||
|
||||
OC_App::addNavigationEntry( array( "id" => "files_index", "order" => 1, "href" => OC_Helper::linkTo( "files", "index.php" ), "icon" => OC_Helper::imagePath( "core", "places/home.svg" ), "name" => $l->t("Files") ));
|
||||
|
||||
?>
|
||||
OC_Search::registerProvider('OC_Search_Provider_File');
|
||||
|
|
|
@ -350,6 +350,3 @@ if(!function_exists('get_temp_dir')) {
|
|||
}
|
||||
|
||||
OC::init();
|
||||
|
||||
// FROM search.php
|
||||
new OC_Search_Provider_File();
|
||||
|
|
|
@ -29,7 +29,7 @@ class OC_Search{
|
|||
|
||||
/**
|
||||
* register a new search provider to be used
|
||||
* @param OC_Search_Provider $provider
|
||||
* @param string $provider class name of a OC_Search_Provider
|
||||
*/
|
||||
public static function registerProvider($provider){
|
||||
self::$providers[]=$provider;
|
||||
|
@ -43,7 +43,7 @@ class OC_Search{
|
|||
public static function search($query){
|
||||
$results=array();
|
||||
foreach(self::$providers as $provider){
|
||||
$results=array_merge($results,$provider->search($query));
|
||||
$results=array_merge($results, $provider::search($query));
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
|
|
@ -2,15 +2,11 @@
|
|||
/**
|
||||
* provides search functionalty
|
||||
*/
|
||||
abstract class OC_Search_Provider{
|
||||
public function __construct(){
|
||||
OC_Search::registerProvider($this);
|
||||
}
|
||||
|
||||
interface OC_Search_Provider {
|
||||
/**
|
||||
* search for $query
|
||||
* @param string $query
|
||||
* @return array An array of OC_Search_Result's
|
||||
*/
|
||||
abstract function search($query);
|
||||
static function search($query);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class OC_Search_Provider_File extends OC_Search_Provider{
|
||||
function search($query){
|
||||
class OC_Search_Provider_File implements OC_Search_Provider{
|
||||
static function search($query){
|
||||
$files=OC_FileCache::search($query,true);
|
||||
$results=array();
|
||||
foreach($files as $fileData){
|
||||
|
|
Загрузка…
Ссылка в новой задаче