-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
89 lines (76 loc) · 2.38 KB
/
Module.php
File metadata and controls
89 lines (76 loc) · 2.38 KB
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
<?php
namespace humhub\modules\bazaar;
use Yii;
use yii\helpers\Url;
use humhub\components\Module as BaseModule;
use humhub\modules\admin\permissions\ManageSettings;
/**
* Bazaar Module
*
* Provides a storefront inside the HumHub admin panel for browsing and
* purchasing Green Meteor modules. Paid modules are processed via Stripe
* Checkout hosted on greenmeteor.net.
*/
class Module extends BaseModule
{
/**
* @var string Green Meteor modules API endpoint
*/
public string $apiBaseUrl = 'https://greenmeteor.net/api/modules.php';
/**
* @var string Optional API key (not required for the public module list)
*/
public string $apiKey = '';
/**
* @var int How long (in seconds) to cache the module catalogue. Default 1 hour.
*/
public int $cacheTimeout = 3600;
/**
* @var bool Allow admins to initiate purchases from this interface.
*/
public bool $enablePurchasing = true;
/**
* @var bool Route all requests through the Green Meteor API domain.
*/
public bool $useGreenMeteorApi = true;
/**
* @inheritdoc
*/
public function getConfigUrl(): string
{
return Url::to(['/bazaar/admin/config']);
}
/**
* @inheritdoc
*/
public function getPermissions($contentContainer = null): array
{
if ($contentContainer !== null) {
return [];
}
return [
new ManageSettings(),
];
}
/**
* Returns a configured ApiService instance.
*
* Settings are read from the HumHub settings manager (persisted via
* ConfigureForm) and override the module-level defaults.
*
* @return \humhub\modules\bazaar\services\ApiService
*/
public function getApiService(): \humhub\modules\bazaar\services\ApiService
{
$settings = $this->settings;
$baseUrl = $settings->get('apiBaseUrl', $this->apiBaseUrl);
$apiKey = $settings->get('apiKey', $this->apiKey);
$cacheTimeout = (int)$settings->get('cacheTimeout', $this->cacheTimeout);
return Yii::createObject([
'class' => 'humhub\modules\bazaar\services\ApiService',
'baseUrl' => $baseUrl,
'apiKey' => $apiKey,
'useGreenMeteorApi' => $this->useGreenMeteorApi,
]);
}
}