<?php 
// deaktiviert wegen Serverlast
header("HTTP/1.1 404 Not Found");
die("disabled");

// YouTube Favorites RSS with video enclosures made by Walter Rafelsberger (http://www.rafelsberger.at) using Dapper & PHP
// This script is free. However, it would be nice if you let me know where you use it.

// For this to work you need:
// The Dapper API
require_once(dirname(__FILE__).'/dapp/Dapp.php');
// - "Favorites YouTube Videos 2" from Dapper (http://www.dapper.net/dapp-howto-use.php?dappName=FavoriteYouTubeVideos2)
$dapp = "FavoriteYouTubeVideos3";
// - Set a default username (may be overriden with "?user=..." in the URL
$username= "walterra";
// - If you're hosting this yourself please adapt the webmaster info
$webmaster = "walter@rafelsberger.at (Walter Rafelsberger)";

if (isset($_GET["user"])) {
    // check user for possible exploits
            $user = trim(stripslashes(strip_tags($_GET["user"])));
    $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload)/i";
    if (preg_match($exploits, $user)) die();
    $username = $user;
}

date_default_timezone_set('UTC');
header('Content-type: application/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <link>http://www.youtube.com/profile_favorites?user=<?php echo $username; ?></link>
	<atom:link href="http://www.metaportaldermedienpolemik.net/youtube_favorites.php?user=<?php echo $username; ?>" rel="self" type="application/rss+xml" />       
	<title><?php echo $username; ?>'s Favorite YouTube Videos</title>
        <description><?php echo $username; ?>'s Favorite YouTube Videos</description>
        <webMaster><?php echo $webmaster; ?></webMaster>
<?php

// The Dapp constructor throws Exceptions - so we should catch it
try {
  // $dappO = new Dapp($dapp, null, array($username));
  // $dapp_url = "http://www.dapper.net/RunDapp?dappName=FavoriteYouTubeVideos3&v=1&v_username=".$username;
  $dapp_url = "http://gdata.youtube.com/feeds/api/users/".$username."/favorites";
  //$xml = new SimpleXMLElement($dappO->getXML());
  $xml = simplexml_load_file($dapp_url);
  var_dump($xml);
  die();
  
  foreach ($xml->entry as $movie) {
        $video = explode("?v=", $movie->link[0]["href"]);
		$video = str_replace("&feature=youtube_gdata", "", $video[1]);
        // $length = explode(":", $movie->Length);
        // $length = ($length[0] * 60 + $length[1]) * 32768;
		$v = simplexml_load_file("http://gdata.youtube.com/feeds/api/videos/".$video);
		var_dump($v);
		die();
        
        echo "<item>\n<title>".$movie->title."</title>\n";
        echo "<link><![CDATA[".$movie->link[0]["href"]."]]></link>\n";
        echo "<guid><![CDATA[".$movie->link[0]["href"]."]]></guid>\n";
        echo "<description>&lt;a href=\"http://www.youtube.com/v/".$video."\"&gt;".$movie->title."&lt;/a&gt;</description>\n";
        echo "<enclosure url=\"http://youtube.com/v/".$video.".swf\" type=\"application/x-shockwave-flash\" />\n";
        echo "</item>\n";
  }
}
catch (Exception $e) {
  echo 'Exception: '.get_class($e)."\nMessage: ".$e->getMessage()."\n";
}

?>
</channel>
</rss>