Exemple #1
0
 /**
  * Process a file for uploading and delete any existing file that it replaces.
  * Returns true if file value changed, false if not.
  *
  * @param $field_name
  * @param $new_value
  * @return bool
  */
 protected function _processFile($field_name, $new_value)
 {
     if ($new_value) {
         if ($this->{$field_name} && $this->{$field_name} != $new_value) {
             \PVL\Service\AmazonS3::delete($this->{$field_name});
         }
         $local_path = DF_INCLUDE_TEMP . DIRECTORY_SEPARATOR . $new_value;
         \PVL\Service\AmazonS3::upload($local_path, $new_value);
         $this->{$field_name} = $new_value;
         return true;
     }
     return false;
 }
Exemple #2
0
 public function uploadSong($local_path)
 {
     if (!$this->title) {
         $this->title = 'No Title';
     }
     if (!$this->artist) {
         $this->artist = 'Various Artists';
     }
     // Create a new path based on the song metadata.
     $song_path_base = $this->artist . ' - ' . $this->title;
     $song_path_base = preg_replace('/[^\\w\\s-]+/', '', $song_path_base);
     $song_path_base = preg_replace('/\\s\\s+/', ' ', $song_path_base);
     $new_path = 'song_uploads/' . $song_path_base . '.' . \DF\File::getFileExtension($local_path);
     // Upload to remote service.
     \PVL\Service\AmazonS3::upload($local_path, $new_path);
     $this->song_url = $new_path;
     return \PVL\Service\AmazonS3::url($new_path);
 }
Exemple #3
0
 public function importAction()
 {
     ini_set('memory_limit', '250M');
     // Tables to export from local DB.
     $tables = array('settings', 'block', 'action', 'role', 'role_has_action', 'artist_type', 'artist', 'artist_has_type', 'affiliates', 'rotators', 'songs', 'station', 'station_streams', 'podcast', 'podcast_on_station', 'podcast_sources', 'podcast_episodes', 'convention', 'convention_archives');
     // Compose mysqldump command.
     $db_config = $this->config->db->toArray();
     $destination_path = realpath(DF_INCLUDE_TEMP) . DIRECTORY_SEPARATOR . 'pvl_import.sql';
     $command_flags = array('-h ' . $db_config['host'], '-u ' . $db_config['user'], '-p' . $db_config['password'], '--no-create-info', '--skip-extended-insert', '--complete-insert', '--single-transaction', '--quick', $db_config['dbname'], implode(' ', $tables));
     $command = 'mysqldump ' . implode(' ', $command_flags) . ' > ' . $destination_path;
     // Execute mysqldump.
     $dump_output = exec($command);
     // Stream file out to screen.
     if (file_exists($destination_path)) {
         $s3_path = 'db_dumps/pvlive_import.sql';
         \PVL\Service\AmazonS3::upload($destination_path, $s3_path);
         return $this->returnSuccess(array('path' => $s3_path, 'dump' => $dump_output));
     } else {
         return $this->returnError('MySQL Dump was not successful.');
     }
 }
Exemple #4
0
 public static function getEpisodeRotatorUrl($episode, $podcast = NULL, $source = NULL)
 {
     if ($episode instanceof self) {
         if ($podcast === null) {
             $podcast = $episode->podcast;
         }
         if ($source === null) {
             $source = $episode->source;
         }
     }
     if ($episode['banner_url'] && !$podcast['is_adult'] && !$podcast['always_use_banner_url']) {
         $image_path_base = 'podcast_episodes/' . $episode['guid'] . '.jpg';
         $image_path = AmazonS3::path($image_path_base);
         // Crop remote banner URL if the local version doesn't already exist.
         if (file_exists($image_path)) {
             return AmazonS3::url($image_path_base);
         } else {
             $temp_path_ext = \DF\File::getFileExtension($episode['banner_url']);
             $temp_path = DF_INCLUDE_TEMP . DIRECTORY_SEPARATOR . '/podcast_episodes/podcast_episode_' . $episode['id'] . '_temp.' . $temp_path_ext;
             @mkdir(dirname($temp_path));
             @copy($episode['banner_url'], $temp_path);
             if (file_exists($temp_path)) {
                 try {
                     Image::resizeImage($temp_path, $temp_path, 600, 300, TRUE);
                     AmazonS3::upload($temp_path, $image_path_base);
                     return AmazonS3::url($image_path_base);
                 } catch (\Exception $e) {
                 }
             }
         }
     }
     if ($podcast !== null && !empty($podcast['banner_url'])) {
         // Reference the podcast's existing banner URL.
         return AmazonS3::url($podcast['banner_url']);
     }
     if ($source !== null) {
         return Url::content('images/podcast_' . $source['type'] . '_banner.png');
     }
     return Url::content('images/podcast_default.png');
 }
Exemple #5
0
 public static function _runTumblrNews(\Phalcon\DiInterface $di)
 {
     $news_items = array();
     $config = $di->get('config');
     // Pull featured images.
     $timestamp_threshold = strtotime('-6 weeks');
     $api_params = array('api_key' => $config->apis->tumblr->key, 'limit' => 10);
     $api_url = 'http://api.tumblr.com/v2/blog/news.ponyvillelive.com/posts/photo?' . http_build_query($api_params);
     $results_raw = @file_get_contents($api_url);
     if ($results_raw) {
         $results = json_decode($results_raw, true);
         $posts = $results['response']['posts'];
         foreach ((array) $posts as $post) {
             if ($post['timestamp'] < $timestamp_threshold) {
                 continue;
             }
             $image = null;
             $post_style = 'vertical';
             $image_is_valid = false;
             foreach ((array) $post['photos'] as $photo) {
                 $image = $photo['original_size'];
                 if ($image['width'] == 600 && $image['height'] == 300) {
                     $image_is_valid = true;
                     $post_style = 'vertical';
                     break;
                 } elseif ($image['width'] == 1150 && $image['height'] == 200) {
                     $image_is_valid = true;
                     $post_style = 'horizontal';
                     break;
                 }
             }
             if (!$image_is_valid) {
                 continue;
             }
             // Copy the image to the local static directory (for SSL and other caching support).
             $image_url = $image['url'];
             $image_url_basename = basename($image_url);
             $local_path_base = 'rotators/' . $image_url_basename;
             $local_url = $local_path_base;
             $local_path = DF_INCLUDE_TEMP . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $local_path_base);
             $s3_path = Service\AmazonS3::path($local_url);
             if (!file_exists($s3_path)) {
                 @mkdir(dirname($local_path));
                 @copy($image_url, $local_path);
                 // Optimize image for fast display.
                 Image::resizeImage($local_path, $local_path, $image['width'], $image['height']);
                 Service\AmazonS3::upload($local_path, $local_path_base);
             }
             $tags = array_map('strtolower', (array) $post['tags']);
             if (in_array('archive', $tags)) {
                 continue;
             }
             $description = strip_tags($post['caption']);
             if (strpos($description, ':') === FALSE) {
                 break;
             }
             list($title, $description) = explode(':', $description, 2);
             $description = Utilities::truncateText($description, self::DESCRIPTION_LENGTH);
             $news_items[] = array('id' => 'tumblr_' . $post['id'], 'title' => trim($title), 'source' => 'tumblr', 'body' => trim($description), 'image_url' => \PVL\Url::upload($local_url), 'web_url' => $post['post_url'], 'layout' => $post_style, 'tags' => (array) $post['tags'], 'sort_timestamp' => $post['timestamp'], 'display_timestamp' => $post['timestamp']);
         }
     }
     return $news_items;
 }