本文整理汇总了PHP中Idno\Core\Webmention::parseContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Webmention::parseContent方法的具体用法?PHP Webmention::parseContent怎么用?PHP Webmention::parseContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Idno\Core\Webmention
的用法示例。
在下文中一共展示了Webmention::parseContent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
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]);
}
示例2: getContent
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();
}
}
示例3: getActionTypeFromHTML
/**
* Given content, returns the type of action you can respond with
* @param $content
* @return string
*/
static function getActionTypeFromHTML($content)
{
$share_type = 'comment';
if ($mf2 = \Idno\Core\Webmention::parseContent($content['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';
}
}
}
}
}
return $share_type;
}
示例4: post
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 = $vars['source'];
$target = $vars['target'];
// Remove anchors from target URL, but save them to '#' input so we can still reference them later
if (strpos($target, '#')) {
list($target, $fragment) = explode('#', $target, 2);
if (!empty($fragment)) {
$this->setInput('#', $fragment);
}
}
// Get the page handler for target
if ($page = \Idno\Core\Idno::site()->getPageHandler($target)) {
// First of all, make sure the target page isn't the source page. Let's not webmention ourselves!
$webmention_ok = true;
if (\Idno\Common\Entity::isLocalUUID($source)) {
if ($source_page = \Idno\Core\Idno::site()->getPageHandler($source)) {
if ($source_page == $page) {
$webmention_ok = false;
}
}
}
// Check that source exists, parse it for mf2 content,
// and ensure that it genuinely mentions this page
if ($webmention_ok) {
if ($source_content = \Idno\Core\Webservice::get($source)) {
if (substr_count($source_content['content'], $target) || $source_content['response'] == 410) {
$source_mf2 = \Idno\Core\Webmention::parseContent($source_content['content'], $source);
// 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.';
\Idno\Core\Idno::site()->logging->warning('No link from ' . $source . ' to ' . $target);
}
} else {
$error = 'source_not_found';
$error_text = 'The source content for ' . $source . ' could not be obtained.';
\Idno\Core\Idno::site()->logging->warning('No content from ' . $source);
}
} else {
$error = 'target_not_supported';
$error_text = 'A page can\'t webmention itself.';
}
} else {
$error = 'target_not_found';
$error_text = 'The target page ' . $target . ' does not exist.';
\Idno\Core\Idno::site()->logging()->error('Could not find handler for ' . $target);
}
}
$this->setResponse(400);
// Webmention failed.
if (empty($error)) {
$error = 'unknown_error';
$error_text = 'Not all the required webmention variables were set.';
}
echo json_encode(array('error' => $error, 'error_text' => $error_text));
}
示例5: getContent
function getContent()
{
$this->gatekeeper();
$url = $this->getInput('share_url');
$title = $this->getInput('share_title');
$type = $this->getInput('share_type');
// Provide a hook to a URL shortener (TODO: Tidy this up when #237 is merged)
$event = new \Idno\Core\Event();
$event->setResponse($url);
\Idno\Core\site()->events()->dispatch('url/shorten', $event);
$url = $event->response();
if (!in_array($type, ['note', 'reply', 'rsvp', 'like'])) {
$share_type = 'note';
if ($content = \Idno\Core\Webservice::get($url)) {
if ($mf2 = \Idno\Core\Webmention::parseContent($content['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';
}
}
}
}
}
}
} 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\site()->getPageHandler('/' . $content_type->camelCase($content_type->getEntityClassName()) . '/edit')) {
if ($share_type == 'note') {
$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', $hide_nav);
$page->setInput('sharing', true);
$page->setInput('share_type', $share_type);
$page->get();
}
} else {
$t = \Idno\Core\site()->template();
$body = $t->__(['share_type' => $share_type, 'content_type' => $content_type, 'sharing' => true])->draw('entity/share');
$t->__(['title' => 'Share', 'body' => $body, 'hidenav' => $hide_nav])->drawPage();
}
}
示例6: getContent
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();
}
}
示例7: getContent
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');
$event = new \Idno\Core\Event();
$event->setResponse($url);
\Idno\Core\site()->events()->dispatch('url/shorten', $event);
$short_url = $event->response();
if (!in_array($type, array('note', 'reply', 'rsvp', 'like', 'bookmark'))) {
$share_type = 'note';
if ($content = \Idno\Core\Webservice::get($url)) {
if ($mf2 = \Idno\Core\Webmention::parseContent($content['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';
}
}
}
}
}
}
} 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\site()->getPageHandler('/' . $content_type->camelCase($content_type->getEntityClassName()) . '/edit')) {
if ($share_type == 'note') {
$page->setInput('body', $title . ' ' . $short_url);
} else {
$page->setInput('short-url', $short_url);
$page->setInput('url', $url);
if (substr_count($url, 'twitter.com')) {
$atusers = [];
preg_match("|https?://([a-z]+\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $url, $matches);
if (!empty($matches[3])) {
$atusers[] = '@' . $matches[3];
// $page->setInput('body', '@' . $matches[3] . ' ');
}
if (preg_match_all("|@([^\\s^\\)]+)|", $title, $matches)) {
$atusers = array_merge($atusers, $matches[0]);
}
// See if one of your registered twitter handles is present, if so remove it.
$user = \Idno\Core\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);
}
$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\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();
}
}