示例#1
0
 public function editAction()
 {
     $form = new \DF\Form($this->current_module_config->forms->rotator);
     if ($this->hasParam('id')) {
         $id = (int) $this->getParam('id');
         $record = Record::find($id);
         $form->setDefaults($record->toArray(FALSE, TRUE));
     }
     if ($_POST && $form->isValid($_POST)) {
         $data = $form->getValues();
         if (!$record instanceof Record) {
             $record = new Record();
         }
         $files = $form->processFiles('rotators');
         foreach ($files as $file_field => $file_paths) {
             if (!empty($file_paths)) {
                 $data[$file_field] = $file_paths[1];
             }
         }
         if ($data['image_url']) {
             \DF\Image::resizeImage($data['image_url'], $data['image_url'], 336, 280);
         }
         $record->fromArray($data);
         $record->save();
         $this->alert('Changes saved.', 'green');
         return $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
     }
     $this->renderForm($form, 'edit', 'Edit Record');
 }
示例#2
0
 /**
  * Process a new file for uploading, and crop it to fit specified dimensions.
  *
  * @param $field_name
  * @param $new_value
  * @param $width
  * @param $height
  * @return bool
  * @throws \DF\Exception
  */
 protected function _processAndCropImage($field_name, $new_value, $width, $height)
 {
     if (!$new_value) {
         return false;
     }
     $local_path = DF_INCLUDE_TEMP . DIRECTORY_SEPARATOR . $new_value;
     \DF\Image::resizeImage($local_path, $local_path, $width, $height, true);
     return $this->_processFile($field_name, $new_value);
 }
示例#3
0
 public static function checkPendingFolder()
 {
     $pending_log = array();
     set_time_limit(600);
     $music_files = self::globDirectory(self::CHECK_DIR . '/*.mp3');
     $id3 = new \getID3();
     $id3->option_md5_data = true;
     $id3->option_md5_data_source = true;
     $id3->encoding = 'UTF-8';
     $existing_songs = ArchiveSong::getExistingSongHashes();
     foreach ($music_files as $file_path) {
         set_time_limit(30);
         $file_info = $id3->analyze($file_path);
         $file_name = basename($file_path);
         if (isset($file_info['error'])) {
             $pending_log['failures'][$file_name] = 'Error processing file: ' . $file_info['error'];
             continue;
         }
         $song_info = array('length' => $file_info['playtime_string'], 'bitrate' => round($file_info['audio']['bitrate'] / 1000) . 'kbps', 'title' => $file_info['tags']['id3v2']['title'][0], 'artist' => $file_info['tags']['id3v2']['artist'][0], 'album' => $file_info['tags']['id3v2']['album'][0], 'year' => $file_info['tags']['id3v2']['year'][0], 'genre' => $file_info['tags']['id3v2']['genre'][0]);
         $song_hash = ArchiveSong::getSongHash($song_info);
         if (in_array($song_hash, $existing_songs)) {
             $pending_log['failures'][$file_name] = 'Duplicate song already exists.';
             continue;
         }
         $photo_data = $file_info['comments']['picture'][0]['data'];
         $image_path = $thumb_path = NULL;
         if ($photo_data) {
             $image_path = $file_path . '.jpg';
             $thumb_path = $file_path . '.thumb.jpg';
             try {
                 @file_put_contents($image_path, $photo_data);
                 @file_put_contents($thumb_path, $photo_data);
                 \DF\Image::resizeImage($image_path, $thumb_path, 150, 150);
                 @unlink($image_path);
             } catch (\Exception $e) {
                 @unlink($image_path);
                 @unlink($thumb_path);
                 $image_path = $thumb_path = NULL;
             }
         }
         $song_info['file_path'] = $file_path;
         $song_info['art_path'] = $thumb_path;
         $song = new \Entity\ArchiveSong();
         $song->fromArray($song_info);
         $song->fixPaths(false);
         $song->save();
         $existing_songs[] = $song_hash;
         $pending_log['successes'][$file_name] = 'Imported successfully.';
     }
     set_time_limit(900);
     self::clearDirectory(self::CHECK_DIR, FALSE);
     self::cleanUpMainDirectories();
     return $pending_log;
 }
示例#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');
 }
示例#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;
 }