1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ownCloud - bookmarks plugin |
5
|
|
|
* |
6
|
|
|
* @author David Iwanowitsch |
7
|
|
|
* @copyright 2012 David Iwanowitsch <david at unclouded dot de> |
8
|
|
|
* |
9
|
|
|
* This library is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
11
|
|
|
* License as published by the Free Software Foundation; either |
12
|
|
|
* version 3 of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* This library is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public |
20
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Bookmarks\Controller\Lib; |
25
|
|
|
|
26
|
|
|
use \OCA\Bookmarks\Controller\Lib\Bookmarks; |
27
|
|
|
|
28
|
|
|
class Search extends \OCP\Search\Provider{ |
29
|
|
|
|
30
|
|
|
function search($query) { |
|
|
|
|
31
|
|
|
$results = array(); |
32
|
|
|
|
33
|
|
|
if (substr_count($query, ' ') > 0) { |
34
|
|
|
$search_words = explode(' ', $query); |
35
|
|
|
} else { |
36
|
|
|
$search_words = $query; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$db = \OC::$server->getDb(); |
40
|
|
|
$user = \OCP\User::getUser(); |
41
|
|
|
|
42
|
|
|
$bookmarks = Bookmarks::findBookmarks($user, $db, 0, 'id', $search_words, false); |
43
|
|
|
$l = new \OC_l10n('bookmarks'); //resulttype can't be localized, javascript relies on that type |
44
|
|
|
foreach ($bookmarks as $bookmark) { |
45
|
|
|
$results[] = new \OC_Search_Result($bookmark['title'], $bookmark['title'], $bookmark['url'], (string) $l->t('Bookm.')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $results; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.