parse() public method

Method to parse a JSON feed object
public parse ( ) : void
return void
示例#1
0
 /**
  * Method to parse Facebook JSON feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     $rss = new \Pop\Feed\Format\Rss\Facebook(array('url' => 'http://www.facebook.com/feeds/page.php?id=' . $this->id . '&format=rss20'), $this->limit);
     $this->feed->username = substr($this->feed->url, strpos($this->feed->url, '.com/') + 5);
     $this->feed->title = (string) $rss->obj()->channel->title;
     $this->feed->date = (string) $rss->obj()->channel->lastBuildDate;
     $this->feed->generator = (string) $rss->obj()->channel->generator;
     $this->feed->author = substr($this->feed->title, 0, strpos($this->feed->title, "'s"));
     $i = 0;
     foreach ($rss->obj()->channel->item as $item) {
         if (isset($this->feed->items[$i])) {
             $title = trim((string) $item->title);
             if ($title == '') {
                 $title = (string) $item->link;
             }
             $this->feed->items[$i]->title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
             $this->feed->items[$i]->content = html_entity_decode((string) $item->description, ENT_QUOTES, 'UTF-8');
             $this->feed->items[$i]->link = (string) $item->link;
             $this->feed->items[$i]->published = (string) $item->pubDate;
             $this->feed->items[$i]->time = self::calculateTime((string) $item->pubDate);
         }
         $i++;
     }
 }
示例#2
0
 /**
  * Method to parse Youtube JSON feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     $this->feed['title'] = $this->feed['title']['$t'];
     $this->feed['url'] = $this->feed['url'][0]['href'];
     $this->feed['description'] = $this->feed['title'];
     $this->feed['date'] = $this->feed['date']['$t'];
     $this->feed['generator'] = $this->feed['generator']['$t'];
     $this->feed['author'] = $this->feed['author'][0]['name']['$t'];
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         if (isset($this->obj['feed']['entry'][$key]['content']['$t'])) {
             $content = html_entity_decode($this->obj['feed']['entry'][$key]['content']['$t'], ENT_QUOTES, 'UTF-8');
         } else {
             $content = $this->obj['feed']['entry'][$key]['title']['$t'];
         }
         $items[$key]['title'] = $this->obj['feed']['entry'][$key]['title']['$t'];
         $items[$key]['content'] = $content;
         $items[$key]['link'] = $items[$key]['link'][0]['href'];
         $items[$key]['published'] = $this->obj['feed']['entry'][$key]['published']['$t'];
         $items[$key]['time'] = self::calculateTime($this->obj['feed']['entry'][$key]['published']['$t']);
         $id = substr($items[$key]['link'], strpos($items[$key]['link'], 'v=') + 2);
         if (strpos($id, '&') !== false) {
             $id = substr($id, 0, strpos($id, '&'));
         }
         $items[$key]['id'] = $id;
         $youtube = \Pop\Http\Response::parse('http://gdata.youtube.com/feeds/api/videos/' . $id . '?v=2&alt=json');
         if (!$youtube->isError()) {
             $info = json_decode($youtube->getBody(), true);
             $items[$key]['views'] = $info['entry']['yt$statistics']['viewCount'];
             $items[$key]['likes'] = $info['entry']['yt$rating']['numLikes'];
             $items[$key]['duration'] = $info['entry']['media$group']['yt$duration']['seconds'];
             $items[$key]['image_thumb'] = 'http://i.ytimg.com/vi/' . $id . '/default.jpg';
             $items[$key]['image_medium'] = 'http://i.ytimg.com/vi/' . $id . '/mqdefault.jpg';
             $items[$key]['image_large'] = 'http://i.ytimg.com/vi/' . $id . '/hqdefault.jpg';
             foreach ($info as $k => $v) {
                 if ($v != '') {
                     $items[$key][$k] = $v;
                 }
             }
         }
     }
     $this->feed['items'] = $items;
 }