Exemplo n.º 1
1
 public static function api($row_obj, $include_episodes = TRUE)
 {
     if ($row_obj instanceof self) {
         $row = $row_obj->toArray();
         $row['stations'] = array();
         if ($row_obj->stations) {
             foreach ($row_obj->stations as $station) {
                 $row['stations'][] = Station::api($station);
             }
         }
         $row['episodes'] = array();
         if ($include_episodes && $row_obj->episodes) {
             foreach ($row_obj->episodes as $episode) {
                 $row['episodes'][] = $episode;
             }
         }
     } else {
         $row = $row_obj;
         if (isset($row['stations'])) {
             $stations_raw = array();
             foreach ($row['stations'] as $station) {
                 $stations_raw[] = Station::api($station);
             }
             $row['stations'] = $stations_raw;
         } else {
             $row['stations'] = array();
         }
         if (!isset($row['episodes'])) {
             $row['episodes'] = array();
         }
     }
     $api_row = array('id' => (int) $row['id'], 'name' => $row['name'], 'country' => $row['country'], 'description' => $row['description'], 'image_url' => \PVL\Url::upload(self::getArtistImage($row['image_url'])), 'banner_url' => \PVL\Url::upload($row['banner_url']), 'stations' => (array) $row['stations'], 'is_adult' => (bool) $row['is_adult']);
     if ($include_episodes) {
         $api_row['episodes'] = array();
         $i = 1;
         foreach ((array) $row['episodes'] as $ep) {
             if (is_int($include_episodes) && $i > $include_episodes) {
                 break;
             }
             $api_row['episodes'][] = PodcastEpisode::api($ep);
             $i++;
         }
     }
     $social_types = array_keys(self::getSocialTypes());
     foreach ($social_types as $type_key) {
         $api_row[$type_key] = $row[$type_key];
     }
     return $api_row;
 }
Exemplo n.º 2
0
 public function latestAction()
 {
     try {
         $latest_shows = Podcast::fetchLatest();
         $return = array();
         foreach ((array) $latest_shows as $show_info) {
             $return_row = Podcast::api($show_info['record'], FALSE);
             foreach ((array) $show_info['episodes'] as $ep_row) {
                 $return_row['episodes'][] = PodcastEpisode::api($ep_row);
             }
             $return[] = $return_row;
         }
         return $this->returnSuccess($return);
     } catch (\Exception $e) {
         return $this->returnError($e->getMessage());
     }
 }
Exemplo n.º 3
0
 /**
  * Send notifications for new podcast episodes.
  *
  * @param \Phalcon\DiInterface $di
  * @throws \DF\Exception
  */
 public static function _runPodcastEpisodes(\Phalcon\DiInterface $di, $force = false)
 {
     $em = $di->get('em');
     $start_threshold = time() - 86400 * 7;
     $end_threshold = time();
     $podcast_episodes = $em->createQuery('SELECT pe, p
         FROM Entity\\PodcastEpisode pe JOIN pe.podcast p
         WHERE pe.timestamp BETWEEN :start AND :end
         AND pe.is_notified = 0
         AND pe.is_active = 1
         AND p.is_approved = 1
         ORDER BY pe.timestamp DESC')->setParameter('start', $start_threshold)->setParameter('end', $end_threshold)->setMaxResults(1)->execute();
     if ($podcast_episodes) {
         $episode = $podcast_episodes[0];
         $podcast = $episode->podcast;
         $podcast_name = $podcast->name;
         if ($podcast->is_adult) {
             $podcast_name = '[18+] ' . $podcast_name;
         }
         $title = \DF\Utilities::truncateText($episode->title, 110 - strlen($podcast_name) - 6);
         $tweet = $podcast_name . ': "' . $title . '"';
         PvlNode::push('podcast.new_episode', array('episode' => PodcastEpisode::api($episode), 'podcast' => Podcast::api($podcast, false)));
         $image_url = NULL;
         if ($podcast->banner_url) {
             $image_url = \PVL\Service\AmazonS3::path($podcast->banner_url);
         }
         // Special handling of podcast YT videos.
         if (stristr($episode->web_url, 'youtube.com') !== false) {
             $image_url = NULL;
         }
         self::notify($tweet, $episode->getLocalUrl('twitter'), $image_url);
         // Set all episodes of the same podcast to be notified, to prevent spam.
         $em->createQuery('UPDATE Entity\\PodcastEpisode pe SET pe.is_notified=1 WHERE pe.podcast_id = :podcast_id')->setParameter('podcast_id', $podcast->id)->execute();
     }
 }