Exemplo n.º 1
0
 public static function get_link($movieId)
 {
     $link = self::find_by_id($movieId);
     $exists = $link ? true : false;
     if ($link && days_from_now($link->timestamp) < LINK_UPDATE_DAYS) {
         // good
     } else {
         $exists = $link ? true : false;
         $movie = Movie::find_by_id($movieId);
         $link = new YouTube();
         $link->id = $movieId;
         $link->timestamp = gen_timestamp();
         $title = urlencode($movie->title);
         $endpoint = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q={$title}&type=video&videoCategoryId=30&key=AIzaSyBOaDIBNUCfbthPQ0XSZScnqI8jyxJ9G5Q";
         $m = self::getData($endpoint);
         foreach ($m->items as $mov) {
             $desc = $mov->snippet->description;
             if (levenshtein($title, $mov->snippet->title) < 2) {
                 foreach ($castArr as $actor) {
                     if (strpos($desc, $actor) !== false) {
                         $link->videoId = $mov->id->videoId;
                         break 2;
                         // break out of both foreach loops
                     }
                 }
             }
         }
         if ($exists) {
             $link->update();
         } else {
             $link->create();
         }
     }
     return $link;
 }
Exemplo n.º 2
0
 public static function get_link($movieId, $googleplay_id = "")
 {
     $link = self::find_by_id($movieId);
     if ($link && days_from_now($link->timestamp) < LINK_UPDATE_DAYS) {
         // good
     } else {
         if ($link) {
             $googleplay_id = $googleplay_id ? $googleplay_id : $link->googleplay_id;
             if (!empty($googleplay_id)) {
                 $html = file_get_contents("https://play.google.com/store/movies/details?id={$id}");
                 if (strpos($html, "<title>Not Found</title>") === false) {
                     // verified
                     $link->timestamp = gen_timestamp();
                     $link->update();
                     return $link;
                 }
             }
         }
         // no current link in db; generate one
         $link = new GooglePlay();
         $link->id = $movieId;
         $link->timestamp = gen_timestamp();
         $link->create();
     }
     return $link;
 }
function smarty_function_recurse_messages($params, &$smarty)
{
    if (is_array($params['array']) && count($params['array']) > 0) {
        $markup = '';
        if ($params['array'][0]['depth'] == '') {
            $markup .= "\n<ul class=tree>";
        } else {
            $markup .= "\n<ul>";
        }
        foreach ($params['array'] as $element) {
            $indent = '';
            for ($i = 0; $i < $element['depth']; ++$i) {
                $indent .= "    ";
            }
            $markup .= "\n<li>" . $indent;
            $markup .= $element['message'] . ' -  <font size=1>' . $element['screen_name'] . ' ' . days_from_now($element['timestamp']) . '</font>';
            if ($element['from_id'] != $_SESSION['id'] && $_SESSION['id'] != '' && !$element['read_only']) {
                $markup .= ' <font size=1><a href="message.php?msg=' . $element['id'] . '">respond to this user</a></font>';
            }
            if ($_SESSION['admin_type'] > '1') {
                $markup .= ' <font size=1><a href="message_list.php?manage=' . $element['id'] . '">manage</a></font>';
            }
            /*$markup .= '<h1>' . $element['timestamp'] . '</h1>';
              $markup .= '<p>' . $element['message'] . '</p>';*/
            if (isset($element['messages'])) {
                $markup .= smarty_function_recurse_messages(array('array' => $element['messages']), $smarty);
            }
            $markup .= "\n</li>";
        }
        $markup .= "\n</ul>";
        return $markup;
    } else {
        return 'not array';
    }
}
Exemplo n.º 4
0
 public static function get_link($movieId)
 {
     $link = self::find_by_id($movieId);
     $exists = $link ? true : false;
     if ($link && days_from_now($link->timestamp) < LINK_UPDATE_DAYS) {
         // good
     } else {
         $exists = $link ? true : false;
         $movie = Movie::find_by_id($movieId);
         $link = new Netflix();
         $link->id = $movieId;
         $link->timestamp = gen_timestamp();
         $years_from_search = array();
         $links_from_search = array();
         $titles_from_search = array();
         $html = file_get_contents("http://instantwatcher.com/titles?q=" . urlencode($movie->title));
         $matches = strallpos($html, "<span class=\"releaseYear\">");
         $link_matches = strallpos($html, "location.href");
         $title_matches = strallpos($html, "class=\"title-list-item-link");
         if (sizeof($matches) == sizeof($link_matches)) {
             for ($i = 0; $i < sizeof($matches); $i++) {
                 $years_from_search[] = substr($html, $matches[$i] + 26, 4);
                 $links_from_search[] = str_replace('Player?movieid=', 'Movie/', strstr(substr($html, $link_matches[$i] + 17), "'", true));
                 $titles_from_search[] = substr(strstr(strstr(substr($html, $title_matches[$i]), ">"), "</a>", true), 1);
                 if ($years_from_search[$i] == $movie->year && levenshtein($titles_from_search[$i], $movie->title) < 2) {
                     $link->link = $links_from_search[$i];
                     break;
                 }
             }
         }
         if ($exists) {
             $link->update();
         } else {
             $link->create();
         }
     }
     return $link;
 }
Exemplo n.º 5
0
 public static function get_link($movieId)
 {
     $link = self::find_by_id($movieId);
     $exists = $link ? true : false;
     if ($link && days_from_now($link->timestamp) < LINK_UPDATE_DAYS) {
         // good
     } else {
         $exists = $link ? true : false;
         $movie = Movie::find_by_id($movieId);
         $link = new Amazon();
         $link->id = $movieId;
         $link->timestamp = gen_timestamp();
         require_once LIB_PATH . DS . "amazon_api_class.php";
         $runtime = $movie->runtime;
         $title = preg_replace('/[^a-z0-9]+/i', ' ', $movie->title);
         $obj = new AmazonProductAPI();
         try {
             $result = $obj->searchProducts($title, AmazonProductAPI::VIDEO, "TITLE");
         } catch (Exception $e) {
             echo $e->getMessage();
         }
         $cast = Actor::list_of_names($movie->id);
         foreach ($result->Items->Item as $k) {
             if ($k->ItemAttributes->Binding == 'Amazon Instant Video') {
                 if (abs($k->ItemAttributes->RunningTime - $runtime) < 5 && strpos($cast, (string) $k->ItemAttributes->Actor) !== false || abs($k->ItemAttributes->RunningTime - $runtime) < 5 && levenshtein($title, (string) $k->ItemAttributes->Title) <= 3) {
                     $link->link = $k->DetailPageURL;
                     $link->asin = $k->ASIN;
                     break;
                 }
             }
         }
         if (strlen($link->link) > 0) {
             $html = file_get_contents($link->link);
             if (!strpos($html, 'movie is currently unavailable') && strlen($html) > 20) {
                 $html = substr($html, strpos($html, '<ul class="button-list">'), 2000);
                 $matches = array();
                 $rent = "";
                 $buy = "";
                 preg_match_all("/Rent SD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $rent .= substr($matches[0][0], 8);
                 }
                 preg_match_all("/Rent HD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $rent .= "|" . substr($matches[0][0], 8);
                 }
                 preg_match_all("/Buy SD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $buy .= substr($matches[0][0], 7);
                 }
                 preg_match_all("/Buy HD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $buy .= "|" . substr($matches[0][0], 7);
                 }
                 $link->rent = $rent;
                 $link->buy = $buy;
             }
         }
         if ($exists) {
             $link->update();
         } else {
             $link->create();
         }
     }
     return $link;
 }