aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/Notificator/Linkback.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2013-11-22 21:32:06 +0100
committerChristian Weiske <cweiske@cweiske.de>2013-11-22 21:32:06 +0100
commitf47ddf0758f120dfb26f03fb36be5cd897a10f23 (patch)
tree9b64102a66eff570eee85c382688a2f1d423beb4 /src/phorkie/Notificator/Linkback.php
parent934246267dc4089dc0952bbe8412f32fd7346739 (diff)
downloadphorkie-f47ddf0758f120dfb26f03fb36be5cd897a10f23.tar.gz
phorkie-f47ddf0758f120dfb26f03fb36be5cd897a10f23.zip
first work on remote fork notifications with linkback (webmention/pingback)
Diffstat (limited to 'src/phorkie/Notificator/Linkback.php')
-rw-r--r--src/phorkie/Notificator/Linkback.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/phorkie/Notificator/Linkback.php b/src/phorkie/Notificator/Linkback.php
new file mode 100644
index 0000000..4c1abfb
--- /dev/null
+++ b/src/phorkie/Notificator/Linkback.php
@@ -0,0 +1,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
+ }
+ }
+}
+?>