function postContent() { $this->gatekeeper(); $user = Idno::site()->session()->currentUser(); $url = $this->getInput('url'); if ($micropub_endpoint = IndieAuthClient::discoverMicropubEndpoint($url)) { $auth_endpoint = IndieAuthClient::discoverAuthorizationEndpoint($url); $client_id = Idno::site()->config()->getDisplayURL(); $redirect_uri = Idno::site()->config()->getDisplayURL() . 'account/indiesyndicate/cb'; $auth_url = IndieAuthClient::buildAuthorizationURL($auth_endpoint, $url, $redirect_uri, $client_id, 'TODO123', 'post'); $this->forward($auth_url); } else { $mention_client = new MentionClient(); if ($webmention_endpoint = $mention_client->discoverWebmentionEndpoint($url)) { $name = $this->parseTitle($url); $user->indiesyndicate[$url] = ['name' => $name ? $name : $url, 'method' => 'webmention']; $user->save(); Idno::site()->session()->addMessage('Added webmention target ' . $me); } else { Idno::site()->session()->addMessage('Endpoint does not appear to support Micropub or Webmention: ' . $me); } $this->forward(Idno::site()->config()->getDisplayURL() . 'account/indiesyndicate'); } }
private function doWebmention($syndacct, $object) { $details = $this->getAccountDetails($syndacct); if (!$details || !isset($details['method']) || $details['method'] !== 'webmention') { return false; } // temporarily set the syndication link to the syndication url $object->setPosseLink('indiesyndicate', $syndacct); $object->save(); // send a webmention! $client = new MentionClient(); $resp = $client->sendWebmention($object->getSyndicationURL(), $syndacct); // bit of a hack to remove the temporary url array_pop($object->posse['indiesyndicate']); // support for 2xx Created and 3xx Redirect if ($resp['code'] >= 200 && $resp['code'] < 400) { $msg = "Successfully webmention {$syndacct}."; if (isset($resp['headers']['Location'])) { $syndurl = $resp['headers']['Location']; $object->setPosseLink('indiesyndicate', $syndurl, $details['name'], $syndurl, $syndacct, ['icon' => $details['icon']]); $msg .= " Returned URL {$syndurl}."; } Idno::site()->session()->addMessage($msg); Idno::site()->logging()->info($msg); } else { $msg = "Sending webmention to {$syndacct} failed."; Idno::site()->session()->addErrorMessage($msg); Idno::site()->logging()->error($msg, ['response' => $resp]); } $object->save(); return true; }