Passed
Push — master ( 2613a0...5b1ddc )
by Michael
02:05
created

admin_plugin_swarmwebhook   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 67
ccs 0
cts 62
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forAdminOnly() 0 3 1
A html() 0 59 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 html()
12
    {
13
        echo '<h1>Instructions to create the swarm webhook with IFTTT</h1>';
14
        $secret = $this->getConf('hook_secret');
15
        if (empty($secret)) {
16
            $exampleSecret = md5(time());
17
            $settingsID = 'plugin____swarmwebhook____plugin_settings_name';
18
            $configHRef = DOKU_REL . DOKU_SCRIPT . '?do=admin&page=config#' . $settingsID;
19
            $configLink = '<a href="' . $configHRef . '">' . $this->getLang('configuration') . '</a>';
20
            $secretNeededMsg = sprintf(
21
                $this->getLang('secret needed'),
22
                $configLink,
23
                '<code>' . $exampleSecret . '</code>'
24
            );
25
            echo '<p>' . $secretNeededMsg . '</p>';
26
            return;
27
        }
28
        $htmlIFTTT = '<h2>IFTTT</h2>';
29
        $htmlIFTTT .= '<ol>';
30
        $htmlIFTTT .= '<li>';
31
        $iftttFormHref = 'https://ifttt.com/create/if-any-new-check-in-then-make-a-web-request?sid=5';
32
        $htmlIFTTT .= 'Go to <a href="' . $iftttFormHref . '">the relevant IFTTT form</a>';
33
        $htmlIFTTT .= '</li>';
34
        $htmlIFTTT .= '<li>';
35
        $htmlIFTTT .= 'Enter the following Data in the Form:';
36
        $htmlIFTTT .= '<ul>';
37
        $htmlIFTTT .= '<li>';
38
        $webhookURL = DOKU_URL . 'lib/plugins/swarmwebhook/webhook.php';
39
        $htmlIFTTT .= '<strong>URL</strong>: <code>' . $webhookURL . '</code>';
40
        $htmlIFTTT .= '</li>';
41
        $htmlIFTTT .= '<li>';
42
        $htmlIFTTT .= '<strong>Method</strong>: POST';
43
        $htmlIFTTT .= '</li>';
44
        $htmlIFTTT .= '<li>';
45
        $htmlIFTTT .= '<strong>Content Type</strong>: application/json';
46
        $htmlIFTTT .= '</li>';
47
        $iftttBody = '
48
{
49
"ts": "{{CheckinDate}}",
50
"shout": "{{Shout}}",
51
"VenueName": "{{VenueName}}",
52
"VenueUrl": "{{VenueUrl}}",
53
"VenueMapImageUrl": "{{VenueMapImageUrl}}",
54
"secret": "'. $secret . '"
55
}';
56
        $htmlIFTTT .= '<li>';
57
        $htmlIFTTT .= '<strong>Body</strong>: <pre>' . $iftttBody . '</pre>';
58
        $htmlIFTTT .= '</li>';
59
        $htmlIFTTT .= '</ul>';
60
        $htmlIFTTT .= '</li>';
61
        $htmlIFTTT .= '<li>';
62
        $htmlIFTTT .= 'Submit the form';
63
        $htmlIFTTT .= '</li>';
64
        $htmlIFTTT .= '<li>';
65
        $htmlIFTTT .= 'Done ✅';
66
        $htmlIFTTT .= '</li>';
67
        $htmlIFTTT .= '</ol>';
68
69
        echo $htmlIFTTT;
70
    }
71
}
72