My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
WPF CODE EXAMPLE created on Sunday, March 21, 2010 permalink
How to consume text from any Google Document, RSS feed, or Twitter feed in your Silverlight application
If you try to read data via WebClient into a Silverlight application, you will get a security error unless the site from which you are reading text has a clientaccesspolicy.xml file which allows you to read the text. This seriously limits the kinds of data Silverlight application can access on the web: no public RSS feeds, no Twitter feeds, etc. So I wrote this proxy script and put it up on my PHP site, and now can get text into Silverlight from any site on the Internet via this proxy by passing the url I want to access as a parameter like this: http://www.mysite.com/getwebdata.php?url=http://docs.google.com/Doc?id=dc7gj86r_1sdc4trnd2. This allows you to create Silverlight applications whose content can be controlled by non-technical administrators simply tweeting or updating a Google Docs document, etc.
<?php
$url = filter_input(INPUT_GET, 'url',FILTER_SANITIZE_STRING);

$validUrls[] = "http://docs.google.com";
$validUrls[] = "http://twitter.com/statuses/user_timeline";

if(beginsWithOneOfThese($url, $validUrls)) {
    $user_agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie");
    curl_setopt($ch, CURLOPT_URL, $url );
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    echo curl_exec($ch);
} else
    echo "invalid url";

function beginsWithOneOfThese($main, $prefixes) {
    foreach($prefixes as $prefix) {
    if(beginsWith($main, $prefix))
        return true;
    }
    return false;
}

function beginsWith($main, $prefix) {
    return strpos($main, $prefix) === 0;
}
?>
need markup?