Skip to content
Browse files

Update v0.0.2

v0.0.2
fixed issue #2 (Object created in class php file)
added functions latestMovie, nowPlayingMovies (thank's to steffmeister)
  • Loading branch information...
1 parent dbc4189 commit 21130537122f68b61aaada1639f0fa236275b784 @pixelead0 committed Nov 7, 2012
Showing with 231 additions and 209 deletions.
  1. +231 −209 tmdb_v3.php
View
440 tmdb_v3.php
@@ -6,10 +6,10 @@
*
* @pakage TMDB_V3_API_PHP
* @author adangq <adangq@gmail.com>
-* @copyright 2012 adangq
+* @copyright 2012 pixelead0
* @date 2012-02-12
-* @link http://www.github.com/adangq
-* @version 0.0.1
+* @link http://www.github.com/pixelead
+* @version 0.0.2
* @license BSD http://www.opensource.org/licenses/bsd-license.php
*
*
@@ -21,273 +21,295 @@
* @author Jonas De Smet - Glamorous
* @link {https://github.com/glamorous/TMDb-PHP-API}
*
-*
-*
* Function List
-* 1.
-* 2.
-
-//configuration http://api.themoviedb.org/3/configuration
-// Imagenes http://cf2.imgobject.com/t/p/original/IMAGEN.jpg
-
-//Buscar Pelicula http://api.themoviedb.org/3/search/movie
-// Buscar Persona http://api.themoviedb.org/3/search/person
+* public function __construct($apikey,$lang='en')
+* public function setLang($lang="en")
+* public function getLang()
+* public function setImageURL($config)
+* public function getImageURL($size="original")
+* public function movieTitles($idMovie)
+* public function movieTrans($idMovie)
+* public function movieTrailer($idMovie,$source="")
+* public function movieDetail($idMovie)
+* public function moviePoster($idMovie)
+* public function movieCast($idMovie)
+* public function movieInfo($idMovie,$option="",$print=false)
+* public function searchMovie($movieTitle)
+* public function getConfig()
+* public function latestMovie()
+* public function nowPlayingMovies($page=1)
+*
+* private function _call($action,$text,$lang="")
+* private function setApikey($apikey)
+* private function getApikey()
-//Movie Info http://api.themoviedb.org/3/movie/11
-//Casts http://api.themoviedb.org/3/movie/11/casts
-//Imagenes http://api.themoviedb.org/3/movie/11/images
-//Trailers http://api.themoviedb.org/3/movie/11/trailers
-//translations http://api.themoviedb.org/3/movie/11/translations
-//Titulos Alternativos http://api.themoviedb.org/3/movie/11/alternative_titles
+URL LIST:
+configuration http://api.themoviedb.org/3/configuration
+Imagenes http://cf2.imgobject.com/t/p/original/IMAGEN.jpg
+Buscar Pelicula http://api.themoviedb.org/3/search/movie
+Buscar Persona http://api.themoviedb.org/3/search/person
+Movie Info http://api.themoviedb.org/3/movie/11
+Casts http://api.themoviedb.org/3/movie/11/casts
+Imagenes http://api.themoviedb.org/3/movie/11/images
+Trailers http://api.themoviedb.org/3/movie/11/trailers
+translations http://api.themoviedb.org/3/movie/11/translations
+Titulos Alternativos http://api.themoviedb.org/3/movie/11/alternative_titles
-//Collection Info http://api.themoviedb.org/3/collection/11
+//Collection Info http://api.themoviedb.org/3/collection/11
//Person images http://api.themoviedb.org/3/person/287/images
+*
+** v0.0.2:
+* fixed issue #2 (Object created in class php file)
+* added functions latestMovie, nowPlayingMovies (thank's to steffmeister)
+*
+
*/
###########################
-$apikey="YOUR APIKEY";
-$tmdb_V3 = new TMDBv3($apikey);
-
-
class TMDBv3{
- /**#@+
- * Constants
- */
- /**
- * url of TMDB api
- */
+ #<CONSTANTS>
+ #@var string url of API TMDB
const _API_URL_ = "http://api.themoviedb.org/3/";
+
+ #@var string Version of this class
+ const VERSION = '0.0.2';
+
+ #@var string API KEY
+ private $_apikey;
+
+ #@var string Default language
+ private $_lang;
+
+ #@var string url of TMDB images
+ private $_imgUrl;
+ #</CONSTANTS>
+###############################################################################################################
/**
- * Version of Class
- */
- const VERSION = '0.0.1';
- /**
- * @link http://www.example.com Example link
- * @see myclass()
- * @uses testing, anotherconstant
- * @var array
+ * Construct Class
+ * @param string apikey
+ * @param string language default is english
*/
- /**
- * The API-key
- *
- * @var string
+ public function __construct($apikey,$lang='en') {
+ //Assign Api Key
+ $this->setApikey($apikey);
+
+ //Setting Language
+ $this->setLang($lang);
+
+ //Get Configuration
+ $conf = $this->getConfig();
+ if (empty($conf)){echo "Unable to read configuration, verify that the API key is valid";exit;}
+
+ //set Images URL contain in config
+ $this->setImageURL($conf);
+ }//end of __construct
+
+ /** Setter for the API-key
+ * @param string $apikey
+ * @return void
*/
- private $_apikey;
+ private function setApikey($apikey) {
+ $this->_apikey = (string) $apikey;
+ }//end of setApikey
+
+ /** Getter for the API-key
+ * no input
+ ** @return string
+ */
+ private function getApikey() {
+ return $this->_apikey;
+ }//end of getApikey
+
+ /** Setter for the default language
+ * @param string $lang
+ * @return void
+ **/
+ public function setLang($lang="en") {
+ $this->_lang = $lang;
+ }//end of setLang
+
+ /** Getter for the default language
+ * no input
+ * @return string
+ **/
+ public function getLang() {
+ return $this->_lang;
+ }//end of getLang
+
/**
- * The default language
- *
- * @var string
+ * Set URL of images
+ * @param $config Configurarion of API
+ * @return array
+ */
+ public function setImageURL($config) {
+ $this->_imgUrl = (string) $config['images']["base_url"];
+ } //end of setImageURL
+
+ /** Getter for the URL images
+ * no input
+ * @return string
*/
- private $_lang;
+ public function getImageURL($size="original") {
+ return $this->_imgUrl . $size;
+ }//end of getImageURL
+
/**
- * url of TMDB images
+ * movie Alternative Titles
+ * http://api.themoviedb.org/3/movie/$id/alternative_titles
+ * @param array titles
*/
- private $_imgUrl;
-###############################################################################################################
- function __construct($apikey) {
- //Assign Api Key
- $this->setApikey($apikey);
- //Setting Language
- $this->setLang();
-
- //Get Configuration
- $conf = $this->getConfig();
- if (empty($conf)){echo "Imposible leer configuracion, verifique que la llave de la API sea valida";exit;}
- //set Images URL contain in config
- $this->setImageURL($conf);
- }
+ public function movieTitles($idMovie) {
+ $titleTmp = $this->movieInfo($idMovie,"alternative_titles",false);
+ foreach ($titleTmp['titles'] as $titleArr){
+ $title[]=$titleArr['title']." - ".$titleArr['iso_3166_1'];
+ }
+ return $title;
+ }//end of movieTitles
/**
- * Movie Info
- * http://api.themoviedb.org/3/movie/$id
- * @param array movieInfo
+ * movie translations
+ * http://api.themoviedb.org/3/movie/$id/translations
+ * @param array translationsInfo
*/
- public function movieTitles($idMovie)
- {
- $titleTmp = $this->movieInfo($idMovie,"alternative_titles",false);
- foreach ($titleTmp['titles'] as $titleArr){
- $title[]=$titleArr['title']." - ".$titleArr['iso_3166_1'];
- }
- return $title;
- }
+ public function movieTrans($idMovie)
+ {
+ $transTmp = $this->movieInfo($idMovie,"translations",false);
+
+ foreach ($transTmp['translations'] as $transArr){
+ $trans[]=$transArr['english_name']." - ".$transArr['iso_639_1'];
+ }
+ return $trans;
+ }//end of movieTrans
/**
- * Movie Info
- * http://api.themoviedb.org/3/movie/$id
- * @param array movieInfo
+ * movie Trailer
+ * http://api.themoviedb.org/3/movie/$id/trailers
+ * @param array trailerInfo
*/
- public function movieTrans($idMovie)
- {
- $transTmp = $this->movieInfo($idMovie,"translations",false);
+ public function movieTrailer($idMovie) {
+ $trailer = $this->movieInfo($idMovie,"trailers",false);
+ return $trailer;
+ } //movieTrailer
- foreach ($transTmp['translations'] as $transArr){
- $trans[]=$transArr['english_name']." - ".$transArr['iso_639_1'];
- }
- return $trans;
- }
/**
- * Movie Info
+ * movie Detail
* http://api.themoviedb.org/3/movie/$id
- * @param array movieInfo
+ * @param array movieDetail
*/
- public function movieTrailer($idMovie)
- {
- $trailer = $this->movieInfo($idMovie,"trailers",false);
- // $trailer =$trailer['posters'];
- return $trailer;
- }
- public function movieDetail($idMovie)
- {
- return $this->movieInfo($idMovie,"",false);
- }
+ public function movieDetail($idMovie)
+ {
+ return $this->movieInfo($idMovie,"",false);
+ }//end of movieDetail
/**
- * Movie Info
- * http://api.themoviedb.org/3/movie/$id
- * @param array movieInfo
+ * movie Poster
+ * http://api.themoviedb.org/3/movie/$id/images
+ * @param array moviePoster
*/
- public function moviePoster($idMovie)
- {
- $posters = $this->movieInfo($idMovie,"images",false);
- $posters =$posters['posters'];
- return $posters;
- }
+ public function moviePoster($idMovie)
+ {
+ $posters = $this->movieInfo($idMovie,"images",false);
+ $posters =$posters['posters'];
+ return $posters;
+ }//end of
/**
- * Movie Info
- * http://api.themoviedb.org/3/movie/$id
- * @param array movieInfo
+ * movie Casting
+ * http://api.themoviedb.org/3/movie/$id/casts
+ * @param array movieCast
*/
- public function movieCast($idMovie)
- {
- $castingTmp = $this->movieInfo($idMovie,"casts",false);
- foreach ($castingTmp['cast'] as $castArr){
- $casting[]=$castArr['name']." - ".$castArr['character'];
- }
- return $casting;
- }
+ public function movieCast($idMovie)
+ {
+ $castingTmp = $this->movieInfo($idMovie,"casts",false);
+ foreach ($castingTmp['cast'] as $castArr){
+ $casting[]=$castArr['name']." - ".$castArr['character'];
+ }
+ return $casting;
+ }//end of movieCast
/**
* Movie Info
* http://api.themoviedb.org/3/movie/$id
* @param array movieInfo
*/
- public function movieInfo($idMovie,$option="",$print=false){
- $option = (empty($option))?"":"/" . $option;
- $params = "movie/" . $idMovie . $option;
- $movie= $this->_call($params,"");
- return $movie;
- }
+ public function movieInfo($idMovie,$option="",$print=false){
+ $option = (empty($option))?"":"/" . $option;
+ $params = "movie/" . $idMovie . $option;
+ $movie= $this->_call($params,"");
+ return $movie;
+ }//end of movieInfo
/**
* Search Movie
* http://api.themoviedb.org/3/search/movie?api_keyf&language&query=future
* @param string $peopleName
*/
- public function searchMovie($movieTitle,$lang="en"){
- $movieTitle="query=".urlencode($movieTitle);
- return $this->_call("search/movie",$movieTitle,$lang);
- }
+ public function searchMovie($movieTitle){
+ $movieTitle="query=".urlencode($movieTitle);
+ return $this->_call("search/movie",$movieTitle,$this->_lang);
+ }//end of searchMovie
+
/**
* Get Confuguration of API
- * configuration http://api.themoviedb.org/3/configuration?apikey
- * @param
+ * configuration
+ * http://api.themoviedb.org/3/configuration?apikey
* @return array
*/
- public function getConfig() {
- return $this->_call("configuration","");
- }
+ public function getConfig() {
+ return $this->_call("configuration","");
+ }//end of getConfig
/**
- * Makes the call to the API
- *
- * @param string $action API specific function name for in the URL
- * @param string $text Unencoded paramter for in the URL
- * @return string
- */
- private function _call($action,$text,$lang=""){
- // # http://api.themoviedb.org/3/movie/11?api_key=XXX
- $lang=(empty($lang))?$this->getLang():$lang;
- $url= TMDBv3::_API_URL_.$action."?api_key=".$this->getApikey()."&language=".$lang."&".$text;
- // echo "<pre>$url</pre>";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_FAILONERROR, 1);
-
- $results = curl_exec($ch);
- $headers = curl_getinfo($ch);
-
- $error_number = curl_errno($ch);
- $error_message = curl_error($ch);
-
- curl_close($ch);
- // header('Content-Type: text/html; charset=iso-8859-1');
- // echo"<pre>";print_r(($results));echo"</pre>";
- $results = json_decode(($results),true);
- return (array) $results;
- }
-
+ * Latest Movie
+ * http://api.themoviedb.org/3/latest/movie?api_key
+ * @return array
+ */
+ public function latestMovie() {
+ return $this->_call('latest/movie','');
+ }
/**
- * Setter for the API-key
- *
- * @param string $apikey
- * @return void
- */
- private function setApikey($apikey)
- {
- $this->_apikey = (string) $apikey;
+ * Now Playing Movies
+ * http://api.themoviedb.org/3/movie/now-playing?api_key&language&page
+ * @param integer $page
+ */
+ public function nowPlayingMovies($page=1) {
+ return $this->_call('movie/now-playing', 'page='.$page);
}
/**
- * Getter for the API-key
- *e
+ * Makes the call to the API
+ *
+ * @param string $action API specific function name for in the URL
+ * @param string $text Unencoded paramter for in the URL
* @return string
*/
- private function getApikey() {
- return $this->_apikey;
- }
+ private function _call($action,$text,$lang=""){
+ // # http://api.themoviedb.org/3/movie/11?api_key=XXX
+ $lang=(empty($lang))?$this->getLang():$lang;
+ $url= TMDBv3::_API_URL_.$action."?api_key=".$this->getApikey()."&language=".$lang."&".$text;
+ echo "<pre>$url</pre>";
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_FAILONERROR, 1);
- /*
- * Setter for the default language
- *
- * @param string $lang
- * @return void
- */
- public function setLang($lang="es") {
- $this->_lang = $lang;
- }
+ $results = curl_exec($ch);
+ $headers = curl_getinfo($ch);
- /**
- * Getter for the default language
- *
- * @return string
- */
- public function getLang() {
- return $this->_lang;
- }
+ $error_number = curl_errno($ch);
+ $error_message = curl_error($ch);
- /**
- * Set URL of images
- * @param $config Configurarion of API
- * @return array
- */
- public function setImageURL($config) {
- $this->_imgUrl = (string) $config['images']["base_url"];
- }
+ curl_close($ch);
+ // header('Content-Type: text/html; charset=iso-8859-1');
+ echo"<pre>";print_r(($results));echo"</pre>";
+ $results = json_decode(($results),true);
+ return (array) $results;
+ }//end of _call
- /**
- * Getter for the URL images
- *
- * @return string
- */
- public function getImageURL() {
- return $this->_imgUrl . "original";
- }
-}
-?>
+} //end of class
+?>

0 comments on commit 2113053

Please sign in to comment.
Something went wrong with that request. Please try again.