本文整理汇总了PHP中Idno\Core\Webservice::head方法的典型用法代码示例。如果您正苦于以下问题:PHP Webservice::head方法的具体用法?PHP Webservice::head怎么用?PHP Webservice::head使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Idno\Core\Webservice
的用法示例。
在下文中一共展示了Webservice::head方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
}
示例2: 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';
// 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 (preg_match('/text\\/(html|plain)+/', $headers['Content-Type'])) {
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();
}
}