function post() { parse_str(trim(file_get_contents("php://input")), $vars); // Check that both source and target are non-empty if (!empty($vars['source']) && !empty($vars['target']) && $vars['source'] != $vars['target']) { $source = urldecode($vars['source']); $target = urldecode($vars['target']); // Get the page handler for target if ($page = \Idno\Core\site()->getPageHandler($target)) { // Check that source exists, parse it for mf2 content, // and ensure that it genuinely mentions this page if ($source_content = \Idno\Core\Webmention::getPageContent($source)) { if (substr_count($source_content['content'], $target) || $source_content['response'] == 410) { $source_mf2 = \Idno\Core\Webmention::parseContent($source_content['content']); // Set source and target information as input variables $page->setPermalink(); if ($page->webmentionContent($source, $target, $source_content, $source_mf2)) { $this->setResponse(202); // Webmention received a-ok. exit; } else { $error = 'target_not_supported'; $error_text = 'This is not webmentionable.'; } } else { $error = 'no_link_found'; $error_text = 'The source URI does not contain a link to the target URI.'; error_log('No link from ' . $source . ' to ' . $target); } } else { $error = 'source_not_found'; $error_text = 'The source content could not be obtained.'; error_log('No content from ' . $source); } } else { $error = 'target_not_found'; $error_text = 'The target page does not exist.'; } } $this->setResponse(400); // Webmention failed. echo json_encode(['error' => $error, 'error_text' => $error_text]); }
function getContent() { if (!\Idno\Core\site()->session()->isLoggedIn()) { $this->setResponse(401); $this->forward('/session/login'); } $url = $this->getInput('share_url'); $title = $this->getInput('share_title'); $share_type = 'note'; if ($content = \Idno\Core\Webmention::getPageContent($url)) { if ($mf2 = \Idno\Core\Webmention::parseContent($content['content'])) { if (substr_count($content['content'], 'h-entry') == 1) { $share_type = 'reply'; if (substr_count($content['content'], 'h-event') == 1) { $share_type = 'rsvp'; } } } } $content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($share_type); if (!empty($content_type)) { if ($page = \Idno\Core\site()->getPageHandler('/' . $content_type->camelCase($content_type->getEntityClassName()) . '/edit')) { if ($share_type == 'note' && !substr_count($url, 'twitter.com')) { $page->setInput('body', $title . ' ' . $url); } else { $page->setInput('url', $url); if (substr_count($url, 'twitter.com')) { preg_match("|https?://(www\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $url, $matches); if (!empty($matches[3])) { $page->setInput('body', '@' . $matches[3] . ' '); } } } $page->setInput('hidenav', true); $page->get(); } } else { $t = \Idno\Core\site()->template(); $body = $t->__(['share_type' => $share_type, 'content_type' => $content_type])->draw('firefox/share'); $t->__(['title' => 'Share', 'body' => $body, 'hidenav' => true])->drawPage(); } }