예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 public function isYouTubeVideoExist($videoID)
 {
     include_once HV_ROOT_DIR . '/../src/Net/Proxy.php';
     $theURL = "http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v={$videoID}&format=json";
     $proxy = new Net_Proxy($theURL);
     $data = json_decode($proxy->query(array(), true), true);
     if (isset($data['type'])) {
         return $data;
     } else {
         return false;
     }
 }
예제 #3
0
 /**
  * Uses bit.ly to generate a shortened URL
  *
  * Requests are sent via back-end for security per the bit.ly docs
  * recommendation.
  */
 public function shortenURL()
 {
     include_once HV_ROOT_DIR . '/../src/Net/Proxy.php';
     $proxy = new Net_Proxy('http://api.bitly.com/v3/shorten?');
     $allowed = false;
     if (stripos($this->_params['queryString'], HV_BITLY_ALLOWED_DOMAIN) !== false) {
         $allowed = true;
     }
     if ($allowed) {
         $longURL = urldecode($this->_params['queryString']);
         $params = array('longUrl' => $longURL, 'login' => HV_BITLY_USER, 'apiKey' => HV_BITLY_API_KEY);
         $this->_printJSON($proxy->query($params, true));
     } else {
         $this->_printJSON(json_encode(array("status_code" => 200, "status_txt" => "OK", "data" => array("long_url" => $this->_params['queryString'], "url" => $this->_params['queryString']))));
     }
 }