function testAddSyndicatedReplyTargets() { // test u-syndication $doc = <<<EOD <div class="h-entry"> <span class="p-name e-content">This is a post</span> <a class="u-url" href="http://foo.bar/post">permalink</a> <a class="u-syndication" href="https://twitter.com/foobar/12345">on Twitter</a> <a class="u-syndication" href="https://www.facebook.com/foobar/posts/12345">on Facebook</a> </div> EOD; $result = Webmention::addSyndicatedReplyTargets('http://foo.bar/post', [], ['response' => 200, 'content' => $doc]); $this->assertEquals(['https://twitter.com/foobar/12345', 'https://www.facebook.com/foobar/posts/12345'], $result); // test rel-syndication $doc = <<<EOD <head> <link rel="syndication" href="https://twitter.com/foobar/12345" /> <link rel="syndication" href="https://www.facebook.com/foobar/posts/12345" /> </head> <body> <div class="h-entry"> <span class="p-name e-content">This is a post</span> <a class="u-url" href="http://foo.bar/post">permalink</a> </div> </body> EOD; $result = Webmention::addSyndicatedReplyTargets('http://foo.bar/post', [], ['response' => 200, 'content' => $doc]); $this->assertEquals(['https://twitter.com/foobar/12345', 'https://www.facebook.com/foobar/posts/12345'], $result); }
function saveDataFromInput() { $page = Idno::site()->currentPage(); if (empty($this->_id)) { $new = true; } else { $new = false; } $this->likeof = $page->getInput('like-of'); if ($this->likeof) { foreach ((array) $this->likeof as $likeofurl) { $this->syndicatedto = Webmention::addSyndicatedReplyTargets($likeofurl, $this->syndicatedto); } } $this->description = $page->getInput('description'); if (empty($this->description)) { $result = \IdnoPlugins\Reactions\Pages\Fetch::fetch($this->likeof); if (!empty($result['description'])) { $this->description = $result['description']; } } $this->setAccess($page->getInput('access')); Idno::site()->logging()->log("saving like. new: {$new}"); if ($this->publish($new)) { Idno::site()->logging()->log("sending webmentions from {$this->getURL()} to {$this->likeof}"); Webmention::sendWebmentionPayload($this->getURL(), $this->likeof); } return true; }
function saveDataFromInput() { $page = Idno::site()->currentPage(); if (empty($this->_id)) { $new = true; } else { $new = false; } $this->repostof = $page->getInput('repost-of'); if ($this->repostof) { foreach ((array) $this->repostof as $repostofurl) { $this->syndicatedto = Webmention::addSyndicatedReplyTargets($repostofurl, $this->syndicatedto); } } $this->description = $page->getInput('description'); $this->body = $page->getInput('body'); if (empty($this->description) && empty($this->body)) { $result = \IdnoPlugins\Reactions\Pages\Fetch::fetch($this->repostof); if (isset($result['description'])) { $this->description = $result['description']; } if (isset($result['content'])) { $this->body = $result['content']; } } $this->setAccess($page->getInput('access')); if ($this->publish($new)) { Webmention::sendWebmentionPayload($this->getURL(), $this->repostof); } return true; }
/** * Saves changes to this object based on user input * @return true|false */ function saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } $body = \Idno\Core\site()->currentPage()->getInput('body'); $inreplyto = \Idno\Core\site()->currentPage()->getInput('inreplyto'); $tags = \Idno\Core\site()->currentPage()->getInput('tags'); if ($time = \Idno\Core\site()->currentPage()->getInput('created')) { if ($time = strtotime($time)) { $this->created = $time; } } if (!empty($body)) { $this->body = $body; $this->inreplyto = $inreplyto; $this->tags = $tags; if (!empty($inreplyto)) { if (is_array($inreplyto)) { foreach ($inreplyto as $inreplytourl) { $this->syndicatedto = \Idno\Core\Webmention::addSyndicatedReplyTargets($inreplytourl, $this->syndicatedto); } } else { $this->syndicatedto = \Idno\Core\Webmention::addSyndicatedReplyTargets($inreplyto); } } $this->setAccess('PUBLIC'); if ($this->save()) { if ($new) { $this->addToFeed(); } // Add it to the Activity Streams feed \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription())); return true; } } else { \Idno\Core\site()->session()->addMessage('You can\'t save an empty status update.'); } return false; }
/** * Saves changes to this object based on user input * @return true|false */ function saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } $body = \Idno\Core\Idno::site()->currentPage()->getInput('body'); $inreplyto = \Idno\Core\Idno::site()->currentPage()->getInput('inreplyto'); $tags = \Idno\Core\Idno::site()->currentPage()->getInput('tags'); $access = \Idno\Core\Idno::site()->currentPage()->getInput('access'); if ($time = \Idno\Core\Idno::site()->currentPage()->getInput('created')) { if ($time = strtotime($time)) { $this->created = $time; } } if (!empty($body)) { $this->body = $body; $this->inreplyto = $inreplyto; $this->tags = $tags; // TODO fetch syndicated reply targets asynchronously (or maybe on-demand, when syndicating?) if (!empty($inreplyto)) { if (is_array($inreplyto)) { foreach ($inreplyto as $inreplytourl) { $this->syndicatedto = \Idno\Core\Webmention::addSyndicatedReplyTargets($inreplytourl, $this->syndicatedto); } } else { $this->syndicatedto = \Idno\Core\Webmention::addSyndicatedReplyTargets($inreplyto); } } $this->setAccess($access); if ($this->publish($new)) { if ($this->getAccess() == 'PUBLIC') { \Idno\Core\Idno::site()->queue()->enqueue('default', 'webmention/sendall', ['source' => $this->getURL(), 'text' => \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription())]); } return true; } } else { \Idno\Core\Idno::site()->session()->addErrorMessage('You can\'t save an empty status update.'); } return false; }
function getContent() { $this->gatekeeper(); $url = $this->getInput('share_url', $this->getInput('url')); $title = $this->getInput('share_title', $this->getInput('title')); $type = $this->getInput('share_type'); $syndicatedto = []; // remove cruft added by mobile apps if (preg_match('~\\b(?:f|ht)tps?://[^\\s]+\\b~i', $url, $matches)) { $url = $matches[0]; } $event = new \Idno\Core\Event(); $event->setResponse($url); \Idno\Core\Idno::site()->events()->dispatch('url/shorten', $event); $short_url = $event->response(); if (!$type || !\Idno\Common\ContentType::getRegisteredForIndieWebPostType($type)) { $share_type = 'note'; // Probe to see if this is something we can MF2 parse, before we do $headers = []; if ($head = \Idno\Core\Webservice::head($url)) { $headers = http_parse_headers($head['header']); } // Only MF2 Parse supported types if (isset($headers['Content-Type']) && preg_match('/text\\/(html|plain)+/', $headers['Content-Type'])) { if ($response = \Idno\Core\Webservice::get($url)) { if ($mf2 = \Idno\Core\Webmention::parseContent($response['content'])) { if (!empty($mf2['items'])) { foreach ($mf2['items'] as $item) { if (!empty($item['type'])) { if (in_array('h-entry', $item['type'])) { $share_type = 'reply'; } if (in_array('h-event', $item['type'])) { $share_type = 'rsvp'; } } } } } $syndicatedto = \Idno\Core\Webmention::addSyndicatedReplyTargets($url, $syndicatedto, $response); } } } else { $share_type = $type; } $content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($share_type); $hide_nav = false; if ($this->getInput('via') == 'ff_social') { $hide_nav = true; } if (!empty($content_type)) { if ($page = \Idno\Core\Idno::site()->getPageHandler($content_type->getEditURL())) { if ($share_type == 'note') { $page->setInput('body', $title . ' ' . $short_url); } else { $page->setInput('short-url', $short_url); $page->setInput('url', $url); $page->setInput('syndicatedto', $syndicatedto); // prefill the @-name of the person we're replying to $atusers = []; foreach (array_merge((array) $url, (array) $syndicatedto) as $tweeturl) { if (strstr($tweeturl, 'twitter.com') !== false) { if (preg_match("|https?://([a-z]+\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $tweeturl, $matches) && !empty($matches[3])) { $atusers[] = '@' . $matches[3]; } if (preg_match_all("|@([^\\s^\\)]+)|", $title, $matches)) { $atusers = array_merge($atusers, $matches[0]); } } } if ($atusers) { // See if one of your registered twitter handles is present, if so remove it. $user = \Idno\Core\Idno::site()->session()->currentUser(); if (!empty($user->twitter) && is_array($user->twitter)) { $me = []; foreach ($user->twitter as $k => $v) { $me[] = '@' . $k; } $atusers = array_diff($atusers, $me); } } if ($atusers) { $atusers = array_unique($atusers); $page->setInput('body', implode(' ', $atusers) . ' '); } } $page->setInput('hidenav', $hide_nav); $page->setInput('sharing', true); $page->setInput('share_type', $share_type); $page->get(); } } else { $t = \Idno\Core\Idno::site()->template(); $body = $t->__(array('share_type' => $share_type, 'content_type' => $content_type, 'sharing' => true))->draw('entity/share'); $t->__(array('title' => 'Share', 'body' => $body, 'hidenav' => $hide_nav))->drawPage(); } }