functions.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $name = explode('/', $folder);
  13. if(is_dir($folder)) {
  14. preg_match_all("/S[0-9]+/", $name[sizeof($name) - 1], $output);
  15. if(sizeof($output[0]) > 0) {
  16. return "posters/" . $name[3] . "_" . ltrim(str_replace('S', '', $name[sizeof($name) - 1]), "0") . ".jpg";
  17. }
  18. return "posters/" . $name[3] . ".jpg";
  19. } else {
  20. // ([a-zA-Z.]*).(S[0-9]*E[0-9]*).([a-zA-Z0-9.-]*) : $1-$2-$3
  21. // ([a-zA-Z ]*) - (S([0-9]+)E([0-9]+)) - ([a-zA-Z ]*) : $1-$2-$5
  22. // ([a-zA-Z]*) - ([0-9]*x[0-9]*) - ([a-zA-Z0-9]*) : $1-$2-$3
  23. // old regex: ([a-zA-Z.*]+)-S([0-9]+)E([0-9]+)-([a-zA-Z0-9.-]+).([a-zA-Z*]+)
  24. // ([a-zA-Z.*]+)-[S|s]([0-9]+)[E|e]([0-9]+)-([a-zA-Z0-9.-]+)\.([a-zA-Z0-9*]+)
  25. // ([a-zA-Z0-9.*]+)-[S|s]([0-9]+)[E|e]([0-9]+)-([a-zA-Z0-9.-]+)\.([a-zA-Z0-9\(\).*\w\,]+)
  26. preg_match_all("/([a-zA-Z0-9.*]+)-[S|s]([0-9]+)[E|e]([0-9]+)-([a-zA-Z0-9äöüÄÖÜß\-\.\,\w]+)\.([a-zA-Z0-9\(\).*\w\,]+)/", $folder, $output);
  27. if(sizeof($output[0]) > 0) {
  28. if((string) $output[3][0] != "0") {
  29. $output[3][0] = ltrim((string) $output[3][0], "0");
  30. }
  31. if((string) $output[2][0] != "0") {
  32. $output[2][0] = ltrim((string) $output[2][0], "0");
  33. }
  34. return "posters/" . $name[3] . "_" . $output[2][0] . "_" . $output[3][0] . ".jpg";
  35. } else {
  36. $movieName = explode('/', $folder);
  37. $movieName = explode('.', $movieName[3]);
  38. unset($movieName[sizeof($movieName) - 1]);
  39. unset($movieName[sizeof($movieName) - 1]);
  40. $movieName = implode(' ', $movieName);
  41. $movieName = str_replace(" Directors Cut", "", $movieName);
  42. return "posters/" . $movieName . ".jpg";
  43. }
  44. }
  45. }
  46. function curl_download($Url){
  47. // is cURL installed yet?
  48. if (!function_exists('curl_init')){
  49. die('Sorry cURL is not installed!');
  50. }
  51. // OK cool - then let's create a new cURL resource handle
  52. $ch = curl_init();
  53. // Now set some options (most are optional)
  54. // Set URL to download
  55. curl_setopt($ch, CURLOPT_URL, $Url);
  56. // Set a referer
  57. //curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
  58. // User agent
  59. 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");
  60. // Include header in result? (0 = yes, 1 = no)
  61. curl_setopt($ch, CURLOPT_HEADER, 0);
  62. // Should cURL return or print out the data? (true = return, false = print)
  63. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  64. // Timeout in seconds
  65. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  66. // Download the given URL, and return output
  67. $output = curl_exec($ch);
  68. // Close the cURL resource, and free system resources
  69. curl_close($ch);
  70. return $output;
  71. }
  72. ?>