-
Notifications
You must be signed in to change notification settings - Fork 7
/
remote.php
100 lines (90 loc) · 2.49 KB
/
remote.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
use dokuwiki\Extension\RemotePlugin;
use dokuwiki\Remote\AccessDeniedException;
class remote_plugin_farmer extends RemotePlugin {
/** @var helper_plugin_farmer hlp */
protected $helper;
/**
* remote_plugin_struct constructor.
*/
public function __construct()
{
parent::__construct();
$this->helper = plugin_load('helper', 'farmer');
}
/**
* Get the configured farm host
*
* @return string
* @throws AccessDeniedException
*/
public function getFarmhost(): string
{
$this->ensureAdmin();
return $this->helper->getConfig()['base']['farmhost'];
}
/**
* Get the configured base domain of the farmer
* This could be an empty string, then farmhost will be used to determine an animal url
*
* @return string
* @throws AccessDeniedException
*/
public function getBaseDomain(): string
{
$this->ensureAdmin();
return $this->helper->getConfig()['base']['basedomain'];
}
/**
* Get a list of all animal names
*
* @return array
* @throws AccessDeniedException
*/
public function listAnimals(): array
{
$this->ensureAdmin();
return $this->helper->getAllAnimals();
}
/**
* Get a list of all animal urls
*
* @return array
* @throws AccessDeniedException
*/
public function listAnimalUrls(): array
{
$this->ensureAdmin();
foreach($this->helper->getAllAnimals() as $animal) {
$animalUrls[] = $this->helper->getAnimalURL($animal);
}
return $animalUrls;
}
/**
* Get configuration details of farmer plugin enriched by list of animals
*
* @return array
* @throws AccessDeniedException
*/
public function getFarmerConfig(): array
{
$this->ensureAdmin();
$farmerConfig = $this->helper->getConfig();
foreach($this->helper->getAllAnimals() as $index=>$animal) {
$farmerConfig['animals'][$index]["name"] =$animal;
$farmerConfig['animals'][$index]["url"] = $this->helper->getAnimalURL($animal);
}
return $farmerConfig;
}
/**
* @throws AccessDeniedException
*/
private function ensureAdmin() {
if (!auth_isadmin()) {
throw new AccessDeniedException(
'You are not allowed to access farmer configuration, superuser permission is required',
114
);
}
}
}