Esempio n. 1
0
 /**
  * Retrieves user-submitted videos from YouTube and returns the
  * result as a JSON array.
  */
 public function getObservationDateVideos()
 {
     include_once HV_ROOT_DIR . '/../src/Database/MovieDatabase.php';
     include_once HV_ROOT_DIR . '/../src/Movie/HelioviewerMovie.php';
     include_once HV_ROOT_DIR . '/../lib/alphaID/alphaID.php';
     include_once HV_ROOT_DIR . '/../src/Helper/HelioviewerLayers.php';
     $movies = new Database_MovieDatabase();
     // Default options
     $defaults = array('num' => 10, 'skip' => 0, 'date' => getUTCDateString());
     $opts = array_replace($defaults, $this->_options);
     // Get a list of recent videos
     $videos = array();
     foreach ($movies->getSharedVideosByTime($opts['num'], $opts['skip'], $opts['date']) as $video) {
         $youtubeId = $video['youtubeId'];
         $movieId = (int) $video['movieId'];
         // Convert id
         $publicId = alphaID($movieId, false, 5, HV_MOVIE_ID_PASS);
         // Load movie
         $movie = new Movie_HelioviewerMovie($publicId);
         $layers = new Helper_HelioviewerLayers($video['dataSourceString']);
         $layersArray = $layers->toArray();
         $name = '';
         if (count($layersArray) > 0) {
             foreach ($layersArray as $layer) {
                 $name .= $layer['name'] . ', ';
             }
         }
         $name = substr($name, 0, -2);
         array_push($videos, array('id' => $publicId, 'url' => 'http://www.youtube.com/watch?v=' . $youtubeId, 'thumbnails' => array('small' => $video['thumbnail'], 'medium' => $video['thumbnail']), 'published' => $video['timestamp'], 'title' => $name . ' (' . $video['startDate'] . ' - ' . $video['endDate'] . ' UTC)', 'description' => $video['description'], 'keywords' => $video['keywords'], 'imageScale' => $video['imageScale'], 'dataSourceString' => $video['dataSourceString'], 'eventSourceString' => $video['eventSourceString'], 'movieLength' => $video['movieLength'], 'width' => $video['width'], 'height' => $video['height'], 'startDate' => $video['startDate'], 'endDate' => $video['endDate']));
     }
     $this->_printJSON(json_encode($videos));
 }
Esempio n. 2
0
 /**
  * Re-generate a screenshot using the metadata stored in the
  * `screenshots` database table.
  *
  * @return
  */
 public function reTakeScreenshot($screenshotId)
 {
     include_once HV_ROOT_DIR . '/../src/Database/ImgIndex.php';
     include_once HV_ROOT_DIR . '/../src/Image/Composite/HelioviewerScreenshot.php';
     include_once HV_ROOT_DIR . '/../src/Helper/HelioviewerLayers.php';
     include_once HV_ROOT_DIR . '/../src/Helper/HelioviewerEvents.php';
     include_once HV_ROOT_DIR . '/../src/Helper/RegionOfInterest.php';
     // Default options
     $defaults = array('force' => false, 'display' => false);
     $options = array_replace($defaults, $this->_params);
     $screenshotId = intval($screenshotId);
     if ($screenshotId <= 0) {
         throw new Exception('Value of screenshot "id" parameter is invalid.', 25);
     }
     $imgIndex = new Database_ImgIndex();
     $metaData = $imgIndex->getScreenshotMetadata($screenshotId);
     $options['timestamp'] = $metaData['timestamp'];
     $options['observationDate'] = $metaData['observationDate'];
     $roiArr = explode(',', str_replace(array('POLYGON((', '))'), '', $metaData['roi']));
     $roi = array();
     foreach ($roiArr as $index => $coordStr) {
         $coordArr = explode(' ', $coordStr);
         if ($index === 0) {
             $x1 = $coordArr[0];
             $y1 = $coordArr[1];
             $x2 = $coordArr[0];
             $y2 = $coordArr[1];
         } else {
             if ($coordArr[0] <= $x1 && $coordArr[1] <= $y1) {
                 $x1 = $coordArr[0];
                 $y1 = $coordArr[1];
             } else {
                 if ($coordArr[0] >= $x2 && $coordArr[1] >= $y2) {
                     $x2 = $coordArr[0];
                     $y2 = $coordArr[1];
                 }
             }
         }
     }
     $roi = new Helper_RegionOfInterest($x1, $y1, $x2, $y2, $metaData['imageScale']);
     // Data Layers
     $layers = new Helper_HelioviewerLayers($metaData['dataSourceString']);
     // Limit screenshot to five layers
     if ($layers->length() < 1 || $layers->length() > 5) {
         throw new Exception('Invalid layer choices! You must specify 1-5 comma-separated ' . 'layer names.', 22);
     }
     // Event Layers
     $events = new Helper_HelioviewerEvents($metaData['eventSourceString']);
     // Create the screenshot
     $screenshot = new Image_Composite_HelioviewerScreenshot($layers, $events, (bool) $metaData['eventsLabels'], (bool) $metaData['scale'], $metaData['scaleType'], $metaData['scaleX'], $metaData['scaleY'], $metaData['observationDate'], $roi, $options);
 }