저자: Nick Sagona, III (nick@popphp.org)
상속: extends AbstractFormat
예제 #1
0
 /**
  * Method to parse a Flickr RSS 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';
     }
     $namespaces = $this->obj->getDocNamespaces(true);
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         $entry = $this->obj->item[0];
         $dc = $entry->children($namespaces['dc']);
         $image = substr($item['content'], strpos($item['content'], '<img src="') + 10);
         $image = substr($image, 0, strpos($image, '"'));
         $items[$key]['published'] = (string) $dc->{'date.Taken'};
         $items[$key]['time'] = self::calculateTime($items[$key]['published']);
         $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;
 }
예제 #2
0
파일: Vimeo.php 프로젝트: nicksagona/PopPHP
 /**
  * Method to parse a Vimeo RSS feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     if (null === $this->feed['author']) {
         $this->feed['author'] = str_replace('Vimeo / ', null, $this->feed['title']);
     }
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         $id = substr($item['link'], strrpos($item['link'], '/') + 1);
         $items[$key]['id'] = $id;
         $vimeo = \Pop\Http\Response::parse('http://vimeo.com/api/v2/video/' . $id . '.php');
         if (!$vimeo->isError()) {
             $info = unserialize($vimeo->getBody());
             if (isset($info[0]) && is_array($info[0])) {
                 $items[$key]['views'] = isset($info[0]['stats_number_of_plays']) ? $info[0]['stats_number_of_plays'] : null;
                 $items[$key]['likes'] = isset($info[0]['stats_number_of_likes']) ? $info[0]['stats_number_of_likes'] : null;
                 $items[$key]['duration'] = $info[0]['duration'];
                 $items[$key]['image_thumb'] = $info[0]['thumbnail_small'];
                 $items[$key]['image_medium'] = $info[0]['thumbnail_medium'];
                 $items[$key]['image_large'] = $info[0]['thumbnail_large'];
                 foreach ($info[0] as $k => $v) {
                     if ($v != '') {
                         $items[$key][$k] = $v;
                     }
                 }
             }
         }
     }
     $this->feed['items'] = $items;
 }
예제 #3
0
 /**
  * Method to parse a Youtube RSS feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         $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;
 }
예제 #4
0
 /**
  * Method to parse a Facebook RSS 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->channel->item;
         $username = null;
         foreach ($objItems as $itm) {
             if (strpos($itm->link, '/posts/') !== false) {
                 $username = substr($itm->link, strpos($itm->link, '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->channel->item[0]->author) ? (string) $this->obj->channel->item[0]->author : $this->feed['username'];
     }
     if (null === $this->feed['date']) {
         $this->feed['date'] = (string) $this->obj->channel->lastBuildDate;
     }
     $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;
 }