webloc.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?
  2. require 'config.php';
  3. function writeWebloc($url, $path) {
  4. $encoded_url = htmlspecialchars($url, ENT_XML1, 'UTF-8');
  5. $str = '<?xml version="1.0" encoding="UTF-8"?>';
  6. $str .= '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">';
  7. $str .= '<plist version="1.0">';
  8. $str .= '<dict>';
  9. $str .= '<key>URL</key>';
  10. $str .= '<string>' . $encoded_url . '</string>';
  11. $str .= '</dict>';
  12. $str .= '</plist>';
  13. file_put_contents($path, $str);
  14. }
  15. # Find the *.webloc file, if in, in the provided folder
  16. function findWebloc($path) {
  17. $retval = false;
  18. $dir = opendir($path);
  19. if ($dir === FALSE) {
  20. die('Unable to opendir(): ' . htmlspecialchars($path) . "\n");
  21. }
  22. while (false !== ($name = readdir($dir))) {
  23. # Skip junk
  24. if (isJunk($name)) {
  25. continue;
  26. }
  27. # We only care about *.webloc files
  28. if (!preg_match('/\.webloc$/', $name)) {
  29. continue;
  30. }
  31. # The file must be readable to be useful
  32. $file = $path . '/' . $name;
  33. if (is_readable($file)) {
  34. $retval = $file;
  35. last;
  36. }
  37. }
  38. closedir($dir);
  39. return $retval;
  40. }
  41. # Read and parse the provided *.webloc file
  42. function readWebloc($file) {
  43. $str = trim(file_get_contents($file));
  44. return parseTVDBURL($str);
  45. }
  46. ?>