1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Maxence Lange <[email protected]> |
9
|
|
|
* @copyright 2018 |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace OCA\FullTextSearch\Service; |
28
|
|
|
|
29
|
|
|
use OCA\FullTextSearch\AppInfo\Application; |
30
|
|
|
use OCP\ILogger; |
31
|
|
|
use OCP\Util; |
32
|
|
|
|
33
|
|
|
class MiscService { |
34
|
|
|
|
35
|
|
|
/** @var ILogger */ |
36
|
|
|
private $logger; |
37
|
|
|
|
38
|
|
|
public function __construct(ILogger $logger) { |
39
|
|
|
$this->logger = $logger; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function log($message, $level = 2) { |
43
|
|
|
$data = array( |
44
|
|
|
'app' => Application::APP_NAME, |
45
|
|
|
'level' => $level |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->logger->log($level, $message, $data); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param $arr |
53
|
|
|
* @param $k |
54
|
|
|
* |
55
|
|
|
* @param string $default |
56
|
|
|
* |
57
|
|
|
* @return array|string|integer |
58
|
|
|
*/ |
59
|
|
|
public static function get($k, $arr, $default = '') { |
60
|
|
|
if ($arr === null) { |
61
|
|
|
return $default; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (!key_exists($k, $arr)) { |
65
|
|
|
return $default; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $arr[$k]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public static function noEndSlash($path) { |
73
|
|
|
if (substr($path, -1) === '/') { |
74
|
|
|
$path = substr($path, 0, -1); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $path; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $time |
83
|
|
|
* |
84
|
|
|
* @return float |
85
|
|
|
*/ |
86
|
|
|
public static function getMicroTime($time) { |
87
|
|
|
list($usec, $sec) = explode(' ', $time); |
88
|
|
|
|
89
|
|
|
return ((float)$usec + (float)$sec); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
View Code Duplication |
public function addJavascript() { |
|
|
|
|
94
|
|
|
Util::addStyle(Application::APP_NAME, 'fulltextsearch'); |
95
|
|
|
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.api'); |
96
|
|
|
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.settings'); |
97
|
|
|
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.searchbox'); |
98
|
|
|
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.result'); |
99
|
|
|
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.navigation'); |
100
|
|
|
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.