当前位置: 首页>>代码示例>>PHP>>正文


PHP Webmention::findRepresentativeHEntry方法代码示例

本文整理汇总了PHP中Idno\Core\Webmention::findRepresentativeHEntry方法的典型用法代码示例。如果您正苦于以下问题:PHP Webmention::findRepresentativeHEntry方法的具体用法?PHP Webmention::findRepresentativeHEntry怎么用?PHP Webmention::findRepresentativeHEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Idno\Core\Webmention的用法示例。


在下文中一共展示了Webmention::findRepresentativeHEntry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: webmentionContent

 /**
  * A webmention to our profile page means someone mentioned us.
  */
 function webmentionContent($source, $target, $source_response, $source_mf2)
 {
     Idno::site()->logging()->info("received user mention from {$source} to {$target}");
     if (empty($this->arguments)) {
         Idno::site()->logging()->debug("could not process user mention, no pagehandler arguments");
         return false;
     }
     $user = User::getByHandle($this->arguments[0]);
     if (empty($user)) {
         Idno::site()->logging()->debug('could not process user mention, no user for handle ' . $this->arguments[0]);
         return false;
     }
     Idno::site()->logging()->debug("found target user {$user->getHandle()}");
     // if this is anything other than a normal mention (e.g. a delete), accept the wm, but do nothing
     if ($source_response['response'] !== 200) {
         return true;
     }
     $title = Webmention::getTitleFromContent($source_response['content'], $source);
     $mention = ['permalink' => $source, 'title' => $title];
     // look for the first and only h-entry or h-event on the page
     $entry = Webmention::findRepresentativeHEntry($source_mf2, $source, ['h-entry', 'h-event']);
     $card = Webmention::findAuthorHCard($source_mf2, $source, $entry);
     // try to get some more specific details of the mention from mf2 content
     if ($entry) {
         if (!empty($entry['properties']['url'])) {
             $mention['permalink'] = $entry['properties']['url'][0];
         }
         if (!empty($entry['properties']['content'])) {
             $content = $entry['properties']['content'][0];
             $mention['content'] = Idno::site()->template()->sanitize_html(is_array($content) ? $content['html'] : $content);
         }
     }
     $sender_url = false;
     if ($card) {
         if (!empty($card['properties']['url'])) {
             $sender_url = $card['properties']['url'][0];
             $mention['owner_url'] = $card['properties']['url'][0];
         }
         if (!empty($card['properties']['name'])) {
             $mention['owner_name'] = $card['properties']['name'][0];
         }
     }
     $message = 'You were mentioned';
     if (isset($mention['owner_name'])) {
         $message .= ' by ' . $mention['owner_name'];
     }
     $message .= ' on ' . parse_url($mention['permalink'], PHP_URL_HOST);
     $notif = new Notification();
     if ($notif->setNotificationKey(['mention', $user->getUUID(), $source, $target])) {
         $notif->setOwner($user);
         $notif->setMessage($message);
         $notif->setMessageTemplate('content/notification/mention');
         $notif->setActor($sender_url);
         $notif->setVerb('mention');
         $notif->setObject($mention);
         $notif->setTarget($user);
         $notif->save();
         $user->notify($notif);
     } else {
         \Idno\Core\Idno::site()->logging()->debug("ignoring duplicate notification", ['source' => $source, 'target' => $target, 'user' => $user->getHandle()]);
     }
     return true;
 }
开发者ID:smartboyathome,项目名称:Known,代码行数:66,代码来源:View.php

示例2: addWebmentions

 /**
  * Add webmentions as annotations based on Microformats 2 data
  *
  * @param string $source The source URL
  * @param string $target The target URL (i.e., the page on this site that was pinged)
  * @param array $source_response The Webservice response from fetching the source page
  * @param array $source_mf2 Parsed Microformats 2 content from $source
  * @return bool Success
  */
 function addWebmentions($source, $target, $source_response, $source_mf2)
 {
     if ($source_response['response'] == 410) {
         $this->removeAnnotation($source);
         $this->save();
         return true;
     }
     $return = false;
     if (!empty($source_mf2) && !empty($source_mf2['items']) && is_array($source_mf2['items'])) {
         // At this point, we don't know who owns the page or what the content is.
         // First, we'll initialize some variables that we're interested in filling.
         $mentions = array('owner' => array(), 'mentions' => array());
         // Content owner and usable webmention items
         // Get the page title from the source content
         $title = Webmention::getTitleFromContent($source_response['content'], $source);
         // primary h-entry on the page
         $primary = Webmention::findRepresentativeHEntry($source_mf2, $source, ['h-entry']);
         $author = Webmention::findAuthorHCard($source_mf2, $source, $primary);
         // Convert the h-entry to one or more mentions
         if ($primary) {
             $mentions = $this->addWebmentionItem($primary, $author, $mentions, $source, $target, $title);
         }
         if (!empty($mentions['mentions']) && !empty($mentions['owner'])) {
             $return = true;
             if (empty($mentions['owner']['photo'])) {
                 $mentions['owner']['photo'] = '';
             }
             if (empty($mentions['owner']['url'])) {
                 $mentions['owner']['url'] = $source;
             }
             if (empty($mentions['owner']['name'])) {
                 $mentions['owner']['name'] = 'Web user';
             }
             if (empty($mentions['title'])) {
                 $mentions['title'] = '';
             }
             $this->removeAnnotation($source);
             foreach ($mentions['mentions'] as $mention) {
                 if (!empty($mention['url'])) {
                     $permalink = $mention['url'][0];
                     //implode('', $mention['url']);
                 } else {
                     $permalink = $source;
                 }
                 // Special exemption for bridgy
                 if (strpos($source, 'https://brid-gy.appspot.com/') !== false && in_array($mention['type'], array('like', 'share', 'rsvp'))) {
                     $permalink = \Idno\Core\Idno::site()->template()->getURLWithVar('known_from', $source, implode('', $mention['url']));
                 }
                 if (!$this->addAnnotation($mention['type'], $mentions['owner']['name'], $mentions['owner']['url'], $mentions['owner']['photo'], $mention['content'], $permalink, $mention['created'], $mention['title'])) {
                     $return = false;
                 }
             }
             $this->save();
             if ($return && $this->isReply()) {
                 if ($reply_urls = $this->getReplyToURLs()) {
                     foreach ($reply_urls as $reply_url) {
                         Webmention::sendWebmentionPayload($this->getDisplayURL(), $reply_url);
                     }
                 }
             }
         }
     }
     return $return;
 }
开发者ID:kreativmind,项目名称:Known,代码行数:73,代码来源:Entity.php


注:本文中的Idno\Core\Webmention::findRepresentativeHEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。