Ejemplo n.º 1
0
 /**
  * Process RSS feed and return results.
  *
  * @param $feed_url
  * @param null $cache_name
  * @param int $cache_expires
  * @return array|mixed
  */
 public static function getNewsFeed($feed_url, $cache_name = NULL, $cache_expires = 900)
 {
     if (!is_null($cache_name)) {
         $feed_cache = Cache::get('feed_' . $cache_name);
     } else {
         $feed_cache = null;
     }
     if ($feed_cache) {
         return $feed_cache;
     }
     // Catch the occasional error when the RSS feed is malformed or the HTTP request times out.
     try {
         $news_feed = Reader::import($feed_url);
     } catch (\Exception $e) {
         $news_feed = NULL;
     }
     if (!is_null($news_feed)) {
         $latest_news = array();
         $article_num = 0;
         foreach ($news_feed as $item) {
             $article_num++;
             $news_item = array('num' => $article_num, 'title' => $item->getTitle(), 'timestamp' => $item->getDateModified()->getTimestamp(), 'description' => trim($item->getDescription()), 'link' => $item->getLink(), 'categories' => $item->getCategories()->getValues());
             $latest_news[] = $news_item;
         }
         $latest_news = array_slice($latest_news, 0, 10);
         if (!is_null($cache_name)) {
             Cache::set($latest_news, 'feed_' . $cache_name, array('feeds', $cache_name), $cache_expires);
         }
         return $latest_news;
     }
 }
Ejemplo n.º 2
0
 /**
  * Static Functions
  */
 public static function fetch($only_approved = true)
 {
     $cache_name = 'pvlive_affiliates_' . ($only_approved ? 'approved' : 'all');
     $records = \DF\Cache::get($cache_name);
     if (!$records) {
         $records = self::fetchArray();
         if ($only_approved) {
             $records = array_filter($records, function ($record) {
                 return $record['is_approved'];
             });
         }
         // Add affiliate tracking info.
         foreach ($records as &$record) {
             $record['web_url'] = \PVL\AnalyticsManager::addTracking($record['web_url'], array('source' => 'pvliveaffiliate'));
         }
         \DF\Cache::set($records, $cache_name, array(), 60);
     }
     shuffle($records);
     return $records;
 }
Ejemplo n.º 3
0
 public function indexAction()
 {
     if ($this->hasParam('id')) {
         $id = (int) $this->getParam('id');
         $record = $this->em->createQuery('SELECT p, s, pe FROM Entity\\Podcast p LEFT JOIN p.stations s LEFT JOIN p.episodes pe WHERE p.is_approved = 1 AND p.id = :id')->setParameter('id', $id)->execute();
         if ($record[0] instanceof Podcast) {
             $return = Podcast::api($record[0], TRUE);
             return $this->returnSuccess($return);
         } else {
             return $this->returnError('Show not found!');
         }
     } else {
         $return = \DF\Cache::get('api_shows');
         if (!$return) {
             $records = $this->em->createQuery('SELECT p, s, pe FROM Entity\\Podcast p LEFT JOIN p.stations s LEFT JOIN p.episodes pe WHERE p.is_approved = 1 ORDER BY p.name ASC')->getArrayResult();
             $return = array();
             foreach ($records as $record) {
                 $return[] = Podcast::api($record, 10);
             }
             \DF\Cache::set($return, 'api_shows', array(), 60);
         }
         return $this->returnSuccess($return);
     }
 }
Ejemplo n.º 4
0
 public function feedAction()
 {
     $this->doNotRender();
     if ($this->hasParam('id')) {
         $id = (int) $this->getParam('id');
         $record = Podcast::find($id);
         if (!$record instanceof Podcast) {
             throw new \DF\Exception\DisplayOnly('Show record not found!');
         }
         $feed_title = $record->name;
         $feed_desc = $record->description ? $record->description : 'A Ponyville Live! Show.';
         $cache_name = 'podcasts_' . $id . '_feed';
         $q = $this->em->createQuery('SELECT pe, p FROM Entity\\PodcastEpisode pe JOIN pe.podcast p WHERE p.is_approved = 1 AND p.id = :id ORDER BY pe.timestamp DESC')->setParameter('id', $id);
     } else {
         $feed_title = 'Ponyville Live! Shows';
         $feed_desc = 'The partner shows of the Ponyville Live! network, including commentary, interviews, episode reviews, convention coverage, and more.';
         $cache_name = 'podcasts_all_feed';
         $q = $this->em->createQuery('SELECT pe, p FROM Entity\\PodcastEpisode pe JOIN pe.podcast p WHERE p.is_approved = 1 AND pe.timestamp >= :threshold ORDER BY pe.timestamp DESC')->setParameter('threshold', strtotime('-3 months'));
     }
     $rss = \DF\Cache::get($cache_name);
     if (!$rss) {
         $records = $q->getArrayResult();
         // Initial RSS feed setup.
         $feed = new \Zend\Feed\Writer\Feed();
         $feed->setTitle($feed_title);
         $feed->setLink('http://ponyvillelive.com/');
         $feed->setDescription($feed_desc);
         $feed->addAuthor(array('name' => 'Ponyville Live!', 'email' => '*****@*****.**', 'uri' => 'http://ponyvillelive.com'));
         $feed->setDateModified(time());
         foreach ((array) $records as $episode) {
             try {
                 $podcast = $episode['podcast'];
                 $title = $episode['title'];
                 // Check for podcast name preceding episode name.
                 if (substr($title, 0, strlen($podcast['name'])) == $podcast['name']) {
                     $title = substr($title, strlen($podcast['name']));
                 }
                 $title = trim($title, " :-\t\n\r\v");
                 $title = $podcast['name'] . ' - ' . $title;
                 // Create record.
                 $entry = $feed->createEntry();
                 $entry->setTitle($title);
                 $entry->setLink($episode['web_url']);
                 $entry->addAuthor(array('name' => $podcast['name'], 'uri' => $podcast['web_url']));
                 $entry->setDateModified($episode['timestamp']);
                 $entry->setDateCreated($episode['timestamp']);
                 if ($podcast['description']) {
                     $entry->setDescription($podcast['description']);
                 }
                 if ($episode['body']) {
                     $entry->setContent($episode['body']);
                 }
                 $feed->addEntry($entry);
             } catch (\Exception $e) {
             }
         }
         // Export feed.
         $rss = $feed->export('rss');
         \DF\Cache::set($rss, $cache_name, array(), 60 * 15);
     }
     header("Content-Type: application/rss+xml");
     echo $rss;
 }