1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Nicolas Mora |
4
|
|
|
* @copyright 2014 Nicolas Mora ([email protected]) |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. |
7
|
|
|
* See the COPYING-README file. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace OCA\Contacts\Controller; |
11
|
|
|
|
12
|
|
|
use OCA\Contacts\App, |
13
|
|
|
OCA\Contacts\JSONResponse, |
14
|
|
|
OCA\Contacts\Utils\JSONSerializer, |
15
|
|
|
OCA\Contacts\Controller, |
16
|
|
|
OCP\AppFramework\Http; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Controller class For Address Books |
20
|
|
|
*/ |
21
|
|
|
class BackendController extends Controller { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @NoAdminRequired |
25
|
|
|
* @NoCSRFRequired |
26
|
|
|
*/ |
27
|
|
|
public function getConnectors() { |
28
|
|
|
$response = new JSONResponse(); |
29
|
|
|
$prefix = "backend_ldap_"; |
30
|
|
|
$suffix = "_connector.xml"; |
31
|
|
|
$path = __DIR__ . "/../../formats/"; |
32
|
|
|
$files = scandir($path); |
33
|
|
|
$formats = array(); |
34
|
|
|
foreach ($files as $file) { |
35
|
|
|
if (!strncmp($file, $prefix, strlen($prefix)) && substr($file, - strlen($suffix)) === $suffix) { |
36
|
|
|
if (file_exists($path.$file)) { |
37
|
|
|
$format = simplexml_load_file ( $path.$file ); |
38
|
|
|
if ($format) { |
39
|
|
|
if (isset($format['name'])) { |
40
|
|
|
$formatId = substr($file, strlen($prefix), - strlen($suffix)); |
41
|
|
|
$formats[] = array('id' => $formatId, 'name' => (string)$format['name'], 'xml' => $format->asXML()); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
return $response->setData($formats); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @NoAdminRequired |
52
|
|
|
* @NoCSRFRequired |
53
|
|
|
*/ |
54
|
|
View Code Duplication |
public function enableBackend() { |
|
|
|
|
55
|
|
|
$response = new JSONResponse(); |
56
|
|
|
$params = $this->request->urlParams; |
57
|
|
|
$backend = $params['backend']; |
58
|
|
|
$enable = $params['enable']; |
59
|
|
|
return $response->setData(\OCP\Config::setAppValue('contacts', 'backend_'.$backend, $enable)); |
60
|
|
|
} |
61
|
|
|
/** |
62
|
|
|
* @NoAdminRequired |
63
|
|
|
* @NoCSRFRequired |
64
|
|
|
*/ |
65
|
|
View Code Duplication |
public function backendStatus() { |
|
|
|
|
66
|
|
|
$response = new JSONResponse(); |
67
|
|
|
$params = $this->request->urlParams; |
68
|
|
|
$backend = $params['backend']; |
69
|
|
|
$enabled = \OCP\Config::getAppValue('contacts', 'backend_'.$backend, "false"); |
70
|
|
|
return $response->setData($enabled); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
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.