webloc.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?
  2. function writeWebloc($url, $path) {
  3. die_if_not_authenticated();
  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. clearCache();
  15. }
  16. # Find the *.webloc file, if in, in the provided folder
  17. function findWebloc($path) {
  18. $retval = false;
  19. $dir = opendir($path);
  20. if ($dir === FALSE) {
  21. die('Unable to opendir(): ' . htmlspecialchars($path) . "\n");
  22. }
  23. while (false !== ($name = readdir($dir))) {
  24. # Skip junk
  25. if (isJunk($name)) {
  26. continue;
  27. }
  28. # We only care about *.webloc files
  29. if (!preg_match('/\.webloc$/', $name)) {
  30. continue;
  31. }
  32. # The file must be readable to be useful
  33. $file = $path . '/' . $name;
  34. if (is_readable($file)) {
  35. $retval = $file;
  36. last;
  37. }
  38. }
  39. closedir($dir);
  40. return $retval;
  41. }
  42. # Read and parse the provided *.webloc file
  43. function readWebloc($file) {
  44. $str = trim(file_get_contents($file));
  45. return parseTVDBURL($str);
  46. }
  47. ?>