Created
January 15, 2013 20:54
-
-
Save jsicot/4541962 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//this script use the TMDb PHP API class from glamorous https://github.com/glamorous/TMDb-PHP-API | |
function getInitials($name){ | |
$words=explode(" ",$name); | |
$inits=''; | |
foreach($words as $word){ | |
$inits.=strtoupper(substr($word,0,1)); | |
$inits.=' '; | |
} | |
return $inits; | |
} | |
function setMovie($a) { | |
$b['id'] = $a['id']; | |
$b['original_title'] = $a['original_title']; | |
$b['release_date'] = $a['release_date']; | |
$b['poster_path'] = $a['poster_path']; | |
$b['title'] = $a['title']; | |
return $b; | |
} | |
include('TMDb.php'); | |
$tmdb = new TMDb('YOUR_API_KEY', 'fr', TRUE); | |
$sortie = Array(); | |
//$_GET['director'] ="Carl Dreyer"; | |
//$_GET['movie'] = "Du skal aere din hustru" ; | |
$initials = ''; | |
$director = ''; | |
$title = ''; | |
$title2 = ''; | |
if (isset($_GET['director-fn']) && !empty($_GET['director-fn'])){ | |
$initials = getInitials($_GET['director-fn']); | |
} | |
if (isset($_GET['director-sn']) && !empty($_GET['director-sn'])){ | |
$directorBis = $initials." ".$_GET['director-sn'] ; | |
$director = $_GET['director-fn']." ".$_GET['director-sn'] ; | |
} | |
if (isset($_GET['movie1']) && !empty($_GET['movie1'])) { | |
$title = $_GET['movie1'] ; | |
} | |
if (isset($_GET['movie2']) && !empty($_GET['movie2'])){ | |
$title2 = $_GET['movie2']; | |
} | |
$adult ="false"; | |
$year=""; | |
$lang="fr"; | |
$real= $tmdb->searchPerson($director, $page = 1, $adult, $year, $lang ); | |
if (sizeof($real['results']) == 0) { | |
$real= $tmdb->searchPerson($directorBis, $page = 1, $adult, $year, $lang ); | |
} | |
if (sizeof($real['results']) > 0) { | |
$real = $real['results'][0]['id']; | |
$PersonCredits = $tmdb->getPersonCredits($real, $lang); | |
$movies = $PersonCredits['crew']; | |
$movie = Array(); | |
$count = 0; | |
foreach($movies as $aMovie) { | |
$count ++; | |
similar_text($title, $aMovie['title'], $percent); | |
if ($percent > 80) { | |
$movie = setMovie($aMovie); | |
break; | |
else { | |
similar_text($title, $aMovie['original_title'], $percentOri); | |
if ($percentOri > 80) { | |
$movie = setMovie($aMovie); | |
break; | |
} else { | |
similar_text($title2, $aMovie['title'], $percent2); | |
if ($percent2 > 80) { | |
$movie = setMovie($aMovie); | |
break; | |
} | |
else { | |
similar_text($title2, $aMovie['original_title'], $percentOri2); | |
if ($percentOri2 > 80) { | |
$movie = setMovie($aMovie); | |
break; | |
} | |
} | |
} | |
} | |
} | |
array_push($sortie,$movie); | |
} | |
header('Content-Type: text/javascript; charset=utf8'); | |
header('Access-Control-Allow-Methods: GET, POST'); | |
$json= '('.json_encode($sortie).');'; //must wrap in parens and end with semicolon | |
print_r($_GET['callback'].$json); //callback is prepended for json-p | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment