functions.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. if(is_dir($folder)) {
  13. $name = explode('/', $folder);
  14. return "posters/" . $name[3] . ".jpg";
  15. } else {
  16. $movieName = explode('/', $folder);
  17. $movieName = explode('.', $movieName[3]);
  18. unset($movieName[sizeof($movieName) - 1]);
  19. unset($movieName[sizeof($movieName) - 1]);
  20. $movieName = implode(' ', $movieName);
  21. $movieName = str_replace(" Directors Cut", "", $movieName);
  22. return "posters/" . $movieName . ".jpg";
  23. }
  24. error_log($folder);
  25. $imdbID = trim(preg_replace('/\s+/', ' ', file_get_contents($folder . '/imdbid')));
  26. error_log($imdbID);
  27. $result = json_decode(curl_download("http://www.omdbapi.com/?i=" . $imdbID));
  28. error_log($result->{"Poster"});
  29. return $result->{"Poster"};
  30. }
  31. function curl_download($Url){
  32. // is cURL installed yet?
  33. if (!function_exists('curl_init')){
  34. die('Sorry cURL is not installed!');
  35. }
  36. // OK cool - then let's create a new cURL resource handle
  37. $ch = curl_init();
  38. // Now set some options (most are optional)
  39. // Set URL to download
  40. curl_setopt($ch, CURLOPT_URL, $Url);
  41. // Set a referer
  42. //curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
  43. // User agent
  44. 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");
  45. // Include header in result? (0 = yes, 1 = no)
  46. curl_setopt($ch, CURLOPT_HEADER, 0);
  47. // Should cURL return or print out the data? (true = return, false = print)
  48. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  49. // Timeout in seconds
  50. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  51. // Download the given URL, and return output
  52. $output = curl_exec($ch);
  53. // Close the cURL resource, and free system resources
  54. curl_close($ch);
  55. return $output;
  56. }
  57. ?>