/**
  * 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 getSharedVideosByTime($num, $skip, $date)
 {
     include_once HV_ROOT_DIR . '/../src/Helper/DateTimeConversions.php';
     include_once HV_ROOT_DIR . '/../src/Net/Proxy.php';
     // Load data directly from the database
     $this->_dbConnect();
     $date = isoDateToMySQL($date);
     $sql = sprintf('SELECT youtube.id, youtube.movieId, youtube.youtubeId, youtube.timestamp, youtube.title, youtube.description, ' . 'youtube.keywords, youtube.thumbnail, youtube.shared, youtube.checked, 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 ' . '("%s" BETWEEN movies.startDate AND movies.endDate) ' . 'ORDER BY movies.startDate 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();
     $timestamp = time();
     while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
         if (strtotime($row['checked']) < time() - 30 * 24 * 60 * 60 || empty($row['thumbnail'])) {
             //Check if Video is still exist/shared on YouTube
             $videoID = $row['youtubeId'];
             $theURL = "http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v={$videoID}&format=json";
             $proxy = new Net_Proxy($theURL);
             $response = $proxy->query(array(), true);
             if ($response == 'Not Found' || $response == 'Unauthorized') {
                 $this->_dbConnection->query('UPDATE youtube SET shared = 0 WHERE id = ' . $row['id'] . '');
             } else {
                 $data = json_decode($response, true);
                 $row['thumbnail'] = $data['thumbnail_url'];
                 $this->_dbConnection->query('UPDATE youtube SET thumbnail = "' . $data['thumbnail_url'] . '", checked=NOW() WHERE id = ' . $row['id'] . '');
                 array_push($videos, $row);
             }
         } else {
             array_push($videos, $row);
         }
     }
     return $videos;
 }
Example #2
0
 /**
  * Return an array of data from a given data source within the specified
  * time range.
  *
  * @param datetime $start    Query start time
  * @param datetime $end      Query end time
  * @param int      $sourceId The data source identifier in the database
  *
  * @return array Array containing matched rows from the `data` table
  */
 public function getDataRange($start, $end, $sourceId)
 {
     include_once HV_ROOT_DIR . '/../src/Helper/DateTimeConversions.php';
     $this->_dbConnect();
     $data = array();
     $startDate = isoDateToMySQL($start);
     $endDate = isoDateToMySQL($end);
     $sql = sprintf("SELECT * " . "FROM data " . "WHERE " . "sourceId = %d AND " . "date BETWEEN '%s' AND '%s' " . "ORDER BY date ASC;", (int) $sourceId, $this->_dbConnection->link->real_escape_string($startDate), $this->_dbConnection->link->real_escape_string($endDate));
     try {
         $result = $this->_dbConnection->query($sql);
     } catch (Exception $e) {
         return false;
     }
     $result_array = array();
     while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
         array_push($data, $row);
     }
     return $data;
 }
 /**
  * Check the request start and end dates. If either are outside of the
  * range of available data, they are adjusted to fall within the available
  * data range. If the request range falls completely outside of the range
  * of available data, no movie is generated.
  *
  * @param object $imgIndex An instance of ImgIndex
  *
  * @return void
  */
 private function _checkRequestDates($imgIndex)
 {
     // TODO  08/02/2010:  Make note when dates use differ significantly
     //                    from request date.  Perhaps instead of returning
     //                    a "message" parameter, just return the items of
     //                    interest: startTime, endTime, overmax, etc.
     $startImage = $imgIndex->getClosestDataAfterDate($this->_startTime, $this->_sourceId);
     $endImage = $imgIndex->getClosestDataBeforeDate($this->_endTime, $this->_sourceId);
     $this->_startTime = isoDateToMySQL($startImage['date']);
     $this->_endTime = isoDateToMySQL($endImage['date']);
 }