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