Exemple #1
0
/**
 * Loads the required module based on the action specified and run the
 * action.
 *
 * @param array $params API Request parameters
 *
 * @return bool Returns true if the action specified is valid and was
 *              successfully run.
 */
function loadModule($params)
{
    $valid_actions = array('downloadScreenshot' => 'WebClient', 'getClosestImage' => 'WebClient', 'getDataSources' => 'WebClient', 'getJP2Header' => 'WebClient', 'getNewsFeed' => 'WebClient', 'getStatus' => 'WebClient', 'getSciDataScript' => 'WebClient', 'getTile' => 'WebClient', 'getUsageStatistics' => 'WebClient', 'getDataCoverageTimeline' => 'WebClient', 'getDataCoverage' => 'WebClient', 'updateDataCoverage' => 'WebClient', 'shortenURL' => 'WebClient', 'takeScreenshot' => 'WebClient', 'getJP2Image' => 'JHelioviewer', 'getJPX' => 'JHelioviewer', 'getJPXClosestToMidPoint' => 'JHelioviewer', 'launchJHelioviewer' => 'JHelioviewer', 'downloadMovie' => 'Movies', 'getMovieStatus' => 'Movies', 'playMovie' => 'Movies', 'queueMovie' => 'Movies', 'reQueueMovie' => 'Movies', 'uploadMovieToYouTube' => 'Movies', 'checkYouTubeAuth' => 'Movies', 'getYouTubeAuth' => 'Movies', 'getUserVideos' => 'Movies', 'getObservationDateVideos' => 'Movies', 'getEventFRMs' => 'SolarEvents', 'getEvent' => 'SolarEvents', 'getFRMs' => 'SolarEvents', 'getDefaultEventTypes' => 'SolarEvents', 'getEvents' => 'SolarEvents', 'importEvents' => 'SolarEvents', 'getEventsByEventLayers' => 'SolarEvents', 'getEventGlossary' => 'SolarEvents');
    include_once HV_ROOT_DIR . '/../src/Validation/InputValidator.php';
    try {
        if (!array_key_exists('action', $params) || !array_key_exists($params['action'], $valid_actions)) {
            $url = HV_WEB_ROOT_URL . '/docs/';
            throw new Exception('Invalid action specified.<br />Consult the <a href="' . $url . '">' . 'API Documentation</a> for a list of valid actions.', 26);
        } else {
            // Execute action
            $moduleName = $valid_actions[$params['action']];
            $className = 'Module_' . $moduleName;
            include_once HV_ROOT_DIR . '/../src/Module/' . $moduleName . '.php';
            $module = new $className($params);
            $module->execute();
            // Update usage stats
            $actions_to_keep_stats_for = array('getClosestImage', 'takeScreenshot', 'getJPX', 'uploadMovieToYouTube');
            // Note that in addition to the above, buildMovie requests and
            // addition to getTile when the tile was already in the cache.
            if (HV_ENABLE_STATISTICS_COLLECTION && in_array($params['action'], $actions_to_keep_stats_for)) {
                include_once HV_ROOT_DIR . '/../src/Database/Statistics.php';
                $statistics = new Database_Statistics();
                $statistics->log($params['action']);
            }
        }
    } catch (Exception $e) {
        printHTMLErrorMsg($e->getMessage());
    }
    return true;
}
 /**
  * Build the movie frames and movie
  */
 public function build()
 {
     $this->_dbSetup();
     date_default_timezone_set('UTC');
     if ($this->status == 2) {
         return;
     }
     $this->_db->markMovieAsProcessing($this->id, 'mp4');
     try {
         $this->directory = $this->_buildDir();
         // If the movie frames have not been built create them
         if (!@file_exists($this->directory . 'frames')) {
             require_once HV_ROOT_DIR . '/../src/Image/Composite/HelioviewerMovieFrame.php';
             $t1 = date('Y-m-d H:i:s');
             // Get timestamps for frames in the key movie layer
             $this->_getTimeStamps();
             // Set the actual start and end dates, frame-rate,
             // movie length, numFrames and dimensions
             $this->_setMovieProperties();
             // Build movie frames
             $this->_buildMovieFrames($this->watermark);
             $t2 = date('Y-m-d H:i:s');
             // Update status and log time to build frames
             $this->_db->finishedBuildingMovieFrames($this->id, $t1, $t2);
         } else {
             $this->filename = $this->_buildFilename();
         }
     } catch (Exception $e) {
         $this->_abort('Error encountered during movie frame compilation: ' . $e->getMessage());
     }
     $t3 = time();
     // Compile movie
     try {
         $this->_encodeMovie();
     } catch (Exception $e) {
         $t4 = time();
         $this->_abort('Error encountered during video encoding. ' . 'This may be caused by an FFmpeg configuration issue, ' . 'or by insufficient permissions in the cache.', $t4 - $t3);
     }
     // Log buildMovie in statistics table
     if (HV_ENABLE_STATISTICS_COLLECTION) {
         include_once HV_ROOT_DIR . '/../src/Database/Statistics.php';
         $statistics = new Database_Statistics();
         $statistics->log('buildMovie');
     }
     $this->_cleanUp();
 }
 /**
  * Retrieves the latest usage statistics from the database
  */
 public function updateDataCoverage()
 {
     include_once HV_ROOT_DIR . '/../src/Database/Statistics.php';
     $statistics = new Database_Statistics();
     if (array_key_exists('period', $this->_options)) {
         $period = $this->_options['period'];
     } else {
         $period = null;
     }
     $this->_printJSON($statistics->updateDataCoverage($period));
 }