/**
  * Prepares the parameters passed in from the api call and makes a
  * movie from them.
  *
  * @return {String} a url to the movie, or the movie will display.
  */
 public function __construct($publicId, $format = 'mp4')
 {
     $this->_db = false;
     $this->_cachedir = 'api/HelioviewerMovie';
     $this->_filename = urlencode($publicId . '.cache');
     $this->_filepath = $this->_cachedir . '/' . $this->_filename;
     if (HV_DISABLE_CACHE !== true) {
         $cache = new Helper_Serialize($this->_cachedir, $this->_filename, 60);
         $info = $cache->readCache($verifyAge = true);
         if ($info !== false) {
             $this->_cached = true;
         }
     }
     if ($this->_cached !== true) {
         $info = $this->_loadFromDB($publicId, $format);
         $info['regionOfInterest'] = $info['roi'];
         if (HV_DISABLE_CACHE !== true) {
             if ($cache->writeCache($info)) {
                 $this->_cached = true;
             }
         }
     }
     $this->publicId = $publicId;
     $this->format = $format;
     $this->reqStartDate = $info['reqStartDate'];
     $this->reqEndDate = $info['reqEndDate'];
     $this->startDate = $info['startDate'];
     $this->endDate = $info['endDate'];
     $this->timestamp = $info['timestamp'];
     $this->modified = isset($info['modified']) ? $info['modified'] : null;
     $this->imageScale = (double) $info['imageScale'];
     $this->frameRate = (double) $info['frameRate'];
     $this->movieLength = (double) $info['movieLength'];
     $this->id = (int) alphaID($publicId, true, 5, HV_MOVIE_ID_PASS);
     $this->status = (int) $info['status'];
     $this->numFrames = (int) $info['numFrames'];
     $this->width = (int) $info['width'];
     $this->height = (int) $info['height'];
     $this->watermark = (bool) $info['watermark'];
     $this->eventsLabels = (bool) $info['eventsLabels'];
     $this->scale = (bool) $info['scale'];
     $this->scaleType = $info['scaleType'];
     $this->scaleX = (double) $info['scaleX'];
     $this->scaleY = (double) $info['scaleY'];
     $this->maxFrames = min((int) $info['maxFrames'], HV_MAX_MOVIE_FRAMES);
     // Data Layers
     $this->_layers = new Helper_HelioviewerLayers($info['dataSourceString']);
     $this->_events = new Helper_HelioviewerEvents($info['eventSourceString']);
     // Regon of interest
     $this->_roi = Helper_RegionOfInterest::parsePolygonString($info['roi'], $info['imageScale']);
 }
 /**
  * Get a list of movies recently shared on YouTube from a cache file
  * or from a live database query.
  *
  * @param int  $num    Number of movies to return
  * @param str  $since  ISO date
  * @param bool $force  Force reading from database instead of cache
  *
  * @return arr Array containing movieId, youtubeId, timestamp for each
  *             of the matched movies or boolean false.
  */
 public function getSharedVideos($num, $skip, $since, $force = false)
 {
     include_once HV_ROOT_DIR . '/../src/Helper/DateTimeConversions.php';
     $cached = false;
     if (HV_DISABLE_CACHE !== true || $force === false) {
         include_once HV_ROOT_DIR . '/../src/Helper/Serialize.php';
         $cachedir = 'api/MovieDatabse/getSharedvideos';
         $filename = urlencode($since . '_' . $num . '.cache');
         $filepath = $cachedir . '/' . $filename;
         $cache = new Helper_Serialize($cachedir, $filename, 90);
         // Read cache (and invalidate if older than
         // Helper_Serialize::_maxAgeSec)
         $videos = $cache->readCache(true);
         if ($videos !== false) {
             $cached = true;
         }
     }
     // Load data directly from the database
     if ($cached !== true || $force === true) {
         $this->_dbConnect();
         $date = isoDateToMySQL($since);
         $sql = sprintf('SELECT youtube.movieId, youtube.youtubeId, youtube.timestamp, youtube.title, youtube.description, ' . 'youtube.keywords, youtube.shared, movies.imageScale, movies.dataSourceString, movies.eventSourceString, ' . 'movies.movieLength, movies.width, movies.height, movies.startDate, movies.endDate ' . 'FROM youtube ' . 'LEFT JOIN movies ' . 'ON movies.id = youtube.movieId ' . 'WHERE ' . 'youtube.shared>0 AND ' . 'youtube.youtubeId IS NOT NULL AND ' . 'youtube.timestamp > "%s" ' . 'ORDER BY youtube.timestamp DESC ' . 'LIMIT %d,%d;', mysqli_real_escape_string($this->_dbConnection->link, $date), (int) $skip, (int) $num);
         try {
             $result = $this->_dbConnection->query($sql);
         } catch (Exception $e) {
             return false;
         }
         $videos = array();
         while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
             array_push($videos, $row);
         }
         if (HV_DISABLE_CACHE !== true) {
             if ($cache->writeCache($videos)) {
                 $cached = true;
             }
         }
     }
     return $videos;
 }