-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
executable file
·184 lines (170 loc) · 9.3 KB
/
index.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
use Kirby\Cms\App as Kirby;
use Kirby\Cms\Blueprint;
use Kirby\Cms\Response;
use KirbyReporter\Model\FormData;
use KirbyReporter\Report\ReportClient;
use KirbyReporter\Report\ReportMailTemplateParser;
use KirbyReporter\Report\ReportTemplateParser;
use KirbyReporter\Vendor\IssueTracker;
use KirbyReporter\Vendor\Mail;
@include_once __DIR__.'/vendor/autoload.php';
if (empty(option('gearsdigital.reporter-for-kirby.enabled', false)) === true
// this is only neccessary to run tests in CI env
&& !getenv("KIRBY_REPORTER_TEST")
) {
return false;
}
Kirby::plugin('gearsdigital/reporter-for-kirby', [
'areas' => [
'reporter' => function () {
return [
'label' => t('reporter.headline'),
'icon' => 'bolt',
'menu' => true,
'link' => 'reporter',
'views' => [
[
'pattern' => 'reporter',
'action' => function () {
return [
'component' => 'k-reporter-view',
'title' => t('reporter.headline'),
];
},
],
],
];
},
],
'blueprints' => [
'reporter/reporter' => __DIR__.'/blueprints/reporter/reporter.yml',
],
'templates' => [
'reporter' => __DIR__.'/templates/reporter.php',
'emails/report.html' => __DIR__.'/templates/emails/report.html.php',
'emails/report.text' => __DIR__.'/templates/emails/report.text.php',
],
'sections' => [
'reporter' => [],
],
'api' => [
'routes' => [
[
'pattern' => 'reporter/report',
'method' => 'post',
'action' => function () {
try {
// get body from post request
$requestData = kirby()->request()->body()->data();
// create formdata model (to ensure shape of form data)
$formData = new FormData($requestData);
// Issue Tracker Report
if (is_array(option('gearsdigital.reporter-for-kirby.repository'))) {
$url = option('gearsdigital.reporter-for-kirby.repository.url');
$token = option('gearsdigital.reporter-for-kirby.repository.token');
$user = option('gearsdigital.reporter-for-kirby.repository.user');
$tracker = new IssueTracker($url, $token, $user);
$client = new ReportClient($tracker);
return $client->createReport($formData)->toJson();
}
// Mail Report
$from = option('gearsdigital.reporter-for-kirby.mail.from');
$to = option('gearsdigital.reporter-for-kirby.mail.to');
$subject = option('gearsdigital.reporter-for-kirby.mail.subject');
$type = option('gearsdigital.reporter-for-kirby.mail.type');
$mail = new Mail($from, $to, $subject, $type);
$client = new ReportClient($mail);
return $client->createReport($formData)->toJson();
} catch (Exception $e) {
return new Response(json_encode($e->getMessage()), 'application/json', $e->getCode());
}
}
],
[
'pattern' => 'reporter/report/preview',
'method' => 'post',
'action' => function () {
$requestData = kirby()->request()->body()->data();
$formData = new FormData($requestData);
if (is_array(option('gearsdigital.reporter-for-kirby.repository'))) {
$parsedTemplate = (new class {
use ReportTemplateParser;
})->parseTemplate($formData);
return new Response(json_encode(trim($parsedTemplate)), 'application/json');
} elseif ($type = option('gearsdigital.reporter-for-kirby.mail.type')) {
$parsedTemplate = (new class {
use ReportMailTemplateParser;
})->parseTemplate($formData, $type ?? 'text');
return new Response(json_encode(trim($parsedTemplate)), 'application/json');
}
return new Response(null, 'application/json', 204);
}
],
[
'pattern' => 'reporter/fields',
'method' => 'get',
'action' => function () {
$blueprint = Blueprint::load('reporter/reporter');
return json_encode($blueprint['reporter']['fields']);
},
],
],
],
'translations' => [
'en' => [
'reporter.headline' => 'New Issue',
'reporter.description' => 'This is the place to report things that need to be improved or solved. Issues can be bugs, tasks or ideas to be discussed.',
'reporter.tab.write' => 'Write',
'reporter.tab.preview' => 'Preview',
'reporter.tab.preview.empty' => 'Nothing to preview',
'reporter.form.field.title' => 'Title',
'reporter.form.success' => 'Your problem has been reported successfully and is handled under case number: {issueLink}',
'reporter.form.mail.success' => 'Your problem has been reported successfully.',
'reporter.form.issue.link' => '<a href="{issueLink}">#{issueId}</a>',
'reporter.form.button.save' => 'Report Issue',
'reporter.form.error.title' => 'You need to add at least a title.',
'reporter.form.error.authFailed' => 'Authentication failed. Please check your "Personal Access Token".',
'reporter.form.error.repoNotFound' => 'Repository not found.',
'reporter.form.error.optionNotFound.url' => 'Option "kirby-reporter.repository" not defined.',
'reporter.form.error.optionNotFound.token' => 'Option "kirby-reporter.token" not defined.',
'reporter.form.error.platform.unsupported' => 'Your Platform is currently not supported.',
],
'de' => [
'reporter.headline' => 'Fehler Melden',
'reporter.description' => 'Hier können Dinge gemeldet werden die verbessert oder behoben werden müssen. Das können Fehler, Aufgaben oder Ideen sein.',
'reporter.tab.write' => 'Schreiben',
'reporter.tab.preview' => 'Vorschau',
'reporter.form.field.title' => 'Titel',
'reporter.tab.preview.empty' => 'Keine Vorschau verfügbar',
'reporter.form.success' => 'Ihr Bericht wurde erfolgreich übertragen und wird unter der Fallnummer {issueLink} behandelt.',
'reporter.form.mail.success' => 'Ihr Bericht wurde erfolgreich übertragen.',
'reporter.form.issue.link' => '<a href="{issueLink}">{issueId}</a>',
'reporter.form.button.save' => 'Fehler melden',
'reporter.form.error.title' => 'Es muss mindestens ein Titel eingegeben werden.',
'reporter.form.error.authFailed' => 'Anmeldung Fehlgeschlagen. Bitte prüfen Sie den "Personal Access Token".',
'reporter.form.error.repoNotFound' => 'Das Repository wurde nicht gefunden.',
'reporter.form.error.optionNotFound.url' => 'Die Option "kirby-reporter.repository" ist nicht vorhanden',
'reporter.form.error.optionNotFound.token' => 'Option "kirby-reporter.token" ist nicht vorhanden.',
'reporter.form.error.platform.unsupported' => 'Die Platform wird zur Zeit nicht Unterstützt.',
],
'tr' => [
'reporter.headline' => 'Hata Bildir',
'reporter.description' => 'Geliştirilmesi veya çözülmesi gereken şeyleri rapor edebileceğiniz yer burasıdır. Bunlar tartışılması gereken hatalar, görevler veya fikirler olabilir.',
'reporter.tab.write' => 'Yaz',
'reporter.tab.preview' => 'Önizleme',
'reporter.tab.preview.empty' => 'Önizleme yapacak bir şey yok',
'reporter.form.field.title' => 'Başlık',
'reporter.form.success' => 'Hata başarıyla bildirildi ve ilgili konu numarası altında ele alındı: {issueLink}',
'reporter.form.mail.success' => 'Hata başarıyla bildirildi.',
'reporter.form.issue.link' => '<a href="{issueLink}">#{issueId}</a>',
'reporter.form.button.save' => 'Hata Raporla',
'reporter.form.error.title' => 'En azından bir başlık eklemelisin.',
'reporter.form.error.authFailed' => 'Kimlik doğrulama başarısız oldu. Lütfen "Kişisel Erişim Simgenizi" kontrol edin.',
'reporter.form.error.repoNotFound' => 'Depo bulunamadı.',
'reporter.form.error.optionNotFound.url' => 'Seçenek "kirby-reporter.repository" tanımlanmadı.',
'reporter.form.error.optionNotFound.token' => 'Seçenek "kirby-reporter.token" tanımlanmadı.',
'reporter.form.error.platform.unsupported' => 'Platformunuz şu anda desteklenmiyor.',
],
],
]);