aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/Notificator/Linkback.php
blob: 4c1abfb73908f21e351a051450812031a0ab3c14 (plain)
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
<?php
namespace phorkie;

/**
 * Send out linkbacks for the remote paste URL when it gets forked here
 */
class Notificator_Linkback
{
    protected $config;

    public function __construct($config)
    {
        $this->config = $config;
    }

    /**
     * Send linkback on "create" events to remote repositories
     */
    public function send($event, Repository $repo)
    {
        if ($this->config === false) {
            return;
        }

        if ($event != 'create') {
            return;
        }

        $origin = $repo->getConnectionInfo()->getOrigin();
        if ($origin === null) {
            return;
        }
        $originWebUrl = $origin->getWebUrl(true);
        if ($originWebUrl === null) {
            return;
        }


        $this->pbc = new \PEAR2\Services\Linkback\Client();
        $req = $this->pbc->getRequest();
        $req->setConfig(
            array(
                'ssl_verify_peer' => false,
                'ssl_verify_host' => false
            )
        );
        $this->pbc->setRequestTemplate($req);
        $req->setHeader('user-agent', 'phorkie');
        try {
            $res = $this->pbc->send(
                $repo->getLink('display', null, true),
                $originWebUrl
            );
        } catch (\Exception $e) {
            //FIXME: log errors
        }
    }
}
?>