Author: Nick Sagona, III (nick@popphp.org)
Inheritance: extends AbstractFormat
Beispiel #1
0
 /**
  * Method to parse Youtube Atom feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         if ($items[$key]['content'] == '') {
             $items[$key]['content'] = $item['title'];
         }
         $id = substr($item['link'], strpos($item['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;
 }
Beispiel #2
0
 /**
  * Method to parse Facebook Atom feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     // If graph.facebook.com hasn't been parsed yet.
     if (!isset($this->feed['username'])) {
         $objItems = $this->obj->entry;
         $username = null;
         foreach ($objItems as $itm) {
             if (strpos($itm->link->attributes()->href, '/posts/') !== false) {
                 $username = substr($itm->link->attributes()->href, strpos($itm->link->attributes()->href, 'http://www.facebook.com/') + 24);
                 $username = substr($username, 0, strpos($username, '/'));
             }
         }
         if (null !== $username) {
             $json = json_decode(file_get_contents('http://graph.facebook.com/' . $username), true);
             foreach ($json as $key => $value) {
                 $this->feed[$key] = $value;
             }
         } else {
             if (isset($this->options['name'])) {
                 $this->feed['username'] = $this->options['name'];
             }
         }
     }
     if (strpos($this->feed['url'], $this->feed['username']) === false) {
         $this->feed['url'] .= $this->feed['username'];
     }
     if (null === $this->feed['author']) {
         $this->feed['author'] = isset($this->obj->entry[0]->author->name) ? (string) $this->obj->entry[0]->author->name : $this->feed['username'];
     }
     if (null === $this->feed['date']) {
         $this->feed['date'] = (string) $this->obj->updated;
     }
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         $items[$key]['title'] = str_replace(array('<![CDATA[', ']]>'), array(null, null), $item['title']);
         $items[$key]['content'] = str_replace(array('<![CDATA[', ']]>'), array(null, null), $item['content']);
     }
     $this->feed['items'] = $items;
 }
Beispiel #3
0
 /**
  * Method to parse Flickr Atom feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     if (null === $this->feed['author']) {
         $this->feed['author'] = str_replace('Uploads from ', '', $this->feed['title']);
     }
     if (null === $this->feed['date']) {
         $this->feed['date'] = date('D, d M Y H:i:s O');
     }
     if (null === $this->feed['generator']) {
         $this->feed['generator'] = 'Flickr';
     }
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         $image = substr($item['content'], strpos($item['content'], '<img src="') + 10);
         $image = substr($image, 0, strpos($image, '"'));
         $items[$key]['image_thumb'] = str_replace('_m', '_s', $image);
         $items[$key]['image_medium'] = $image;
         $items[$key]['image_large'] = str_replace('_m', '', $image);
         $items[$key]['image_orig'] = str_replace('_m', '_b', $image);
     }
     $this->feed['items'] = $items;
 }