functions.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. function pa($debug, $var = false) {
  3. echo "<pre>";
  4. if($var) {
  5. var_dump($debug);
  6. } else {
  7. print_r($debug);
  8. }
  9. echo "</pre>";
  10. }
  11. function getImageByName($folder) {
  12. return "/posters/" . $folder . ".jpg";
  13. error_log($folder);
  14. $imdbID = trim(preg_replace('/\s+/', ' ', file_get_contents($folder . '/imdbid')));
  15. error_log($imdbID);
  16. $result = json_decode(curl_download("http://www.omdbapi.com/?i=" . $imdbID));
  17. error_log($result->{"Poster"});
  18. return $result->{"Poster"};
  19. }
  20. function curl_download($Url){
  21. // is cURL installed yet?
  22. if (!function_exists('curl_init')){
  23. die('Sorry cURL is not installed!');
  24. }
  25. // OK cool - then let's create a new cURL resource handle
  26. $ch = curl_init();
  27. // Now set some options (most are optional)
  28. // Set URL to download
  29. curl_setopt($ch, CURLOPT_URL, $Url);
  30. // Set a referer
  31. //curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
  32. // User agent
  33. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
  34. // Include header in result? (0 = yes, 1 = no)
  35. curl_setopt($ch, CURLOPT_HEADER, 0);
  36. // Should cURL return or print out the data? (true = return, false = print)
  37. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  38. // Timeout in seconds
  39. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  40. // Download the given URL, and return output
  41. $output = curl_exec($ch);
  42. // Close the cURL resource, and free system resources
  43. curl_close($ch);
  44. return $output;
  45. }
  46. ?>