'; $str .= ''; $str .= ''; $str .= ''; $str .= 'URL'; $str .= '' . $encoded_url . ''; $str .= ''; $str .= ''; file_put_contents($path, $str); } # Find the *.webloc file, if in, in the provided folder function findWebloc($path) { $retval = false; $dir = opendir($path); if ($dir === FALSE) { die('Unable to opendir(): ' . htmlspecialchars($path) . "\n"); } while (false !== ($name = readdir($dir))) { # Skip junk if (isJunk($name)) { continue; } # We only care about *.webloc files if (!preg_match('/\.webloc$/', $name)) { continue; } # The file must be readable to be useful $file = $path . '/' . $name; if (is_readable($file)) { $retval = $file; last; } } closedir($dir); return $retval; } # Read and parse the provided *.webloc file function readWebloc($file) { global $TVDB_URL; $retval = array( 'tvdb-id' => false, 'tvdb-lid' => false, 'url' => false, ); # Read and parse the file # Accept both the resource-fork and data-fork (i.e. plist) verisons of the file $str = trim(file_get_contents($file)); if (preg_match('/(?:\?|\&(?:amp;)?)id=(\d+)/', $str, $matches)) { $retval['tvdb-id'] = $matches[1]; } if (preg_match('/(?:\?|\&(?:amp;)?)lid=(\d+)/', $str, $matches)) { $retval['tvdb-lid'] = $matches[1]; } # Construct a URL if ($retval['tvdb-id'] !== false) { $retval['url'] = $TVDB_URL . '&id=' . $retval['tvdb-id']; if ($retval['tvdb-lid'] !== false) { $retval['url'] .= '&lid=' . $retval['tvdb-lid']; } } return $retval; } ?>