<?php include 'TMDb.php'; // Default English language $tmdb = new TMDb('API-key'); // Set-up the class with your own language $tmdb_nl = new TMDb('API-key', 'nl'); // If you want to load the TMDb-config (default FALSE) $tmdb_load_config = new TMDb('API-key', 'en', TRUE); // After initialize the class // First request a token from API $token = $tmdb->getAuthToken(); // Request valid session for that particular user from API $session = $tmdb->getAuthSession(); //Retrieve config with initialisation of the class $tmdb = new TMDb('API-key', 'en', TRUE); //Retrieve (cached) config when the class is already initialised $config = $tmdb->getConfig(); //Retrieve config when the class is already initialised from TMDb (always new request) $config = $tmdb->getConfiguration(); //Filepath retrieved from a method (Backdrop image) $filepath = '/eJhymb0SiOd39L3BDe7aO7iQhQx.jpg'; //Get image URL for the backdrop image in its original size $image_url = $tmdb->getImageUrl($filepath, TMDb::IMAGE_BACKDROP, 'original');
/** * List all movies matching submitted title using the API's search * method. * * If no result were returned, display a notification. More than one * results means the search is not accurate, display first results in * case one of them matches the search and add a notification to try a * more specific search. If only on movie showed up, it should be the * one, call the API using the movie ID. * * If more than one result, all movies listed will link to a new AJAX * call to load the movie by ID. * * @since 1.0 * * @param string $title Query to search after in the TMDb database * @param string $lang Lang to use in the query * @param int $post_id Related Post ID */ public static function _get_movie_by_title($title, $lang, $post_id = null) { $tmdb = new TMDb(); $config = $tmdb->getConfig(); $title = preg_replace('/[^\\p{L}\\p{N}\\s]/u', '', trim($title)); $data = $tmdb->searchMovie($title, 1, FALSE, NULL, $lang); if (is_wp_error($data)) { return $data; } $_result = 'empty'; $_message = __('Sorry, your search returned no result. Try a more specific query?', 'wpmovielibrary'); $_movies = array(); $_post_id = $post_id; if (isset($data['status_code'])) { return new WP_Error(esc_attr($data['status_code']), esc_attr($data['status_message']), array('_id' => $post_id)); } else { if (!isset($data['total_results'])) { $_result = 'empty'; $_message = __('Sorry, your search returned no result. Try a more specific query?', 'wpmovielibrary'); $_post_id = $post_id; } else { if (1 == $data['total_results']) { $_result = 'movie'; $_message = null; $_movie = self::get_movie_by_id($data['results'][0]['id'], $lang, $post_id); if (is_wp_error($_movie)) { return $_movie; } $_movies[] = $_movie; $_post_id = $post_id; } else { if ($data['total_results'] > 1) { $_result = 'movies'; $_message = __('Your request showed multiple results. Select your movie in the list or try another search:', 'wpmovielibrary'); $_movies = array(); $_post_id = $post_id; foreach ($data['results'] as $movie) { if (!is_null($movie['poster_path'])) { $movie['poster_path'] = self::get_image_url($movie['poster_path'], 'poster', 'small'); } else { $movie['poster_path'] = str_replace('{size}', '-medium', WPMOLY_DEFAULT_POSTER_URL); } $_movies[] = array('id' => $movie['id'], 'poster' => $movie['poster_path'], 'title' => $movie['title'], 'year' => apply_filters('wpmoly_format_movie_date', $movie['release_date'], 'Y'), 'json' => json_encode($movie), '_id' => $post_id); } } } } } $movies = array('result' => $_result, 'message' => $_message, 'movies' => $_movies, 'post_id' => $_post_id); return $movies; }