예제 #1
0
 public function parsePost(DOMElement $el)
 {
     $authorPhoto = $this->query('.//*' . Mf2\xpcs('fbStreamPermalinkHeader') . '//*' . Mf2\xpcs('profilePic'))->item(0)->getAttribute('src');
     $authorLink = $this->query('.//*' . Mf2\xpcs('permalinkHeaderInfo') . '/a')->item(0);
     $authorUrl = $this->resolveUrl($authorLink->getAttribute('href'));
     $authorName = trim($authorLink->textContent);
     $postLink = $this->query('.//*' . Mf2\xpcs('permalinkHeaderContentText') . '//*' . Mf2\xpcs('uiStreamSource') . '/a')->item(0);
     // TODO: resolve once php-mf2 is updated making ->resolveUrl() public
     $postUrl = $this->resolveUrl($postLink->getAttribute('href'));
     $postPublished = fbTimeToIso8601($this->query('./abbr', $postLink)->item(0)->getAttribute('title'));
     $contentEl = $this->query('.//*' . Mf2\xpcs('userContentWrapper') . '//*' . Mf2\xpcs('userContent'))->item(0);
     foreach ($this->query('.//a[starts-with(@onmouseover, "LinkshimAsyncLink")]') as $linkEl) {
         $linkEl->setAttribute('href', $linkEl->textContent);
         $linkEl->removeAttribute('onclick');
         $linkEl->removeAttribute('onmouseover');
         $linkEl->removeAttribute('target');
     }
     $contentPlaintext = $contentEl->textContent;
     $contentHtml = '';
     foreach ($contentEl->childNodes as $node) {
         $contentHtml .= $node->C14N();
     }
     $post = array('type' => array('h-entry'), 'properties' => array('author' => array('type' => array('h-card'), 'properties' => array('photo' => array($authorPhoto), 'name' => array($authorName), 'url' => array($authorUrl))), 'url' => array($postUrl), 'published' => array($postPublished), 'content' => array(array('value' => $contentPlaintext, 'html' => $contentHtml))));
     return $post;
 }
예제 #2
0
 /**
  * Parse
  * 
  * @return array
  */
 public function parse($convertClassic = true, DOMElement $context = NULL)
 {
     $items = array();
     foreach ($this->query('//*' . Mf2\xpcs('profile-card')) as $node) {
         $items[] = $this->parseProfile($node);
     }
     $permalinkTweets = $this->query('//*' . Mf2\xpcs('tweet', 'permalink-tweet'));
     if ($permalinkTweets->length > 0) {
         foreach ($permalinkTweets as $node) {
             $items[] = $this->parseTweet($node);
             // In some cases there are multiple “permalink” tweets — only grab the first.
             break;
         }
     } else {
         foreach ($this->query('//*' . Mf2\xpcs('stream-items') . '//*' . Mf2\xpcs('tweet')) as $node) {
             $items[] = $this->parseTweet($node, false);
         }
     }
     return array('items' => array_values(array_filter($items)));
 }