Completed
Push — develop ( fa4d70...aead11 )
by Michael
01:54
created

admin_plugin_swarmwebhook::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 0
nc 1
nop 0
crap 2
1
<?php
2
3
class admin_plugin_swarmwebhook extends DokuWiki_Admin_Plugin
4
{
5
6
    public function forAdminOnly()
7
    {
8
        return true;
9
    }
10
11
    public function handle()
12
    {
13
    }
14
15
16
    public function html()
17
    {
18
        echo '<h1>Instructions to create the swarm webhook with IFTTT</h1>';
19
        $secret = $this->getConf('hook_secret');
20
        if (empty($secret)) {
21
            $exampleSecret = md5(time());
22
            $settingsID = 'plugin____swarmwebhook____plugin_settings_name';
23
            $configHRef = DOKU_REL . DOKU_SCRIPT . '?do=admin&page=config#' . $settingsID;
24
            $configLink = '<a href="' . $configHRef . '">' . $this->getLang('configuration') . '</a>';
25
            $secretNeededMsg = sprintf(
26
                $this->getLang('secret needed'),
27
                $configLink,
28
                '<code>' . $exampleSecret . '</code>'
29
            );
30
            echo '<p>' . $secretNeededMsg . '</p>';
31
            return;
32
        }
33
        $htmlIFTTT = '<h2>IFTTT</h2>';
34
        $htmlIFTTT .= '<ol>';
35
        $htmlIFTTT .= '<li>';
36
        $iftttFormHref = 'https://ifttt.com/create/if-any-new-check-in-then-make-a-web-request?sid=5';
37
        $htmlIFTTT .= 'Go to <a href="' . $iftttFormHref . '">the relevant IFTTT form</a>';
38
        $htmlIFTTT .= '</li>';
39
        $htmlIFTTT .= '<li>';
40
        $htmlIFTTT .= 'Enter the following Data in the Form:';
41
        $htmlIFTTT .= '<ul>';
42
        $htmlIFTTT .= '<li>';
43
        $webhookURL = DOKU_URL . 'lib/plugins/swarmwebhook/webhook.php';
44
        $htmlIFTTT .= '<strong>URL</strong>: <code>' . $webhookURL . '</code>';
45
        $htmlIFTTT .= '</li>';
46
        $htmlIFTTT .= '<li>';
47
        $htmlIFTTT .= '<strong>Method</strong>: POST';
48
        $htmlIFTTT .= '</li>';
49
        $htmlIFTTT .= '<li>';
50
        $htmlIFTTT .= '<strong>Content Type</strong>: application/json';
51
        $htmlIFTTT .= '</li>';
52
        $iftttBody = '
53
{
54
"ts": "{{CheckinDate}}",
55
"shout": "{{Shout}}",
56
"VenueName": "{{VenueName}}",
57
"VenueUrl": "{{VenueUrl}}",
58
"VenueMapImageUrl": "{{VenueMapImageUrl}}",
59
"secret": "'. $secret . '"
60
}';
61
        $htmlIFTTT .= '<li>';
62
        $htmlIFTTT .= '<strong>Body</strong>: <pre>' . $iftttBody . '</pre>';
63
        $htmlIFTTT .= '</li>';
64
        $htmlIFTTT .= '</ul>';
65
        $htmlIFTTT .= '</li>';
66
        $htmlIFTTT .= '<li>';
67
        $htmlIFTTT .= 'Submit the form';
68
        $htmlIFTTT .= '</li>';
69
        $htmlIFTTT .= '<li>';
70
        $htmlIFTTT .= 'Done ✅';
71
        $htmlIFTTT .= '</li>';
72
        $htmlIFTTT .= '</ol>';
73
74
        echo $htmlIFTTT;
75
    }
76
}
77