Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
280 lines (227 sloc) 13.6 KB
// Start counting time for the page load
$starttime = explode(' ', microtime());
$starttime = $starttime[1] + $starttime[0];
// Include SimplePie
// Located in the parent directory
// Create a new instance of the SimplePie object
$feed = new SimplePie();
if (isset($_GET['js']))
// Make sure that page is getting passed a URL
if (isset($_GET['feed']) && $_GET['feed'] !== '')
// Strip slashes if magic quotes is enabled (which automatically escapes certain characters)
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
$_GET['feed'] = stripslashes($_GET['feed']);
// Use the URL that was passed to the page in SimplePie
// Allow us to change the input encoding from the URL string if we want to. (optional)
if (!empty($_GET['input']))
// Allow us to choose to not re-order the items by date. (optional)
if (!empty($_GET['orderbydate']) && $_GET['orderbydate'] == 'false')
// Trigger force-feed
if (!empty($_GET['force']) && $_GET['force'] == 'true')
// Initialize the whole SimplePie object. Read the feed, process it, parse it, cache it, and
// all that other good stuff. The feed's information will not be available to SimplePie before
// this is called.
$success = $feed->init();
// We'll make sure that the right content type and character encoding gets set automatically.
// This function will grab the proper character encoding, as well as set the content type to text/html.
// When we end our PHP block, we want to make sure our DOCTYPE is on the top line to make
// sure that the browser snaps into Standards Mode.
?><!DOCTYPE html>
<html lang="en-US">
<title>SimplePie: Demo</title>
<link rel="stylesheet" href="./for_the_demo/sIFR-screen.css" type="text/css" media="screen">
<link rel="stylesheet" href="./for_the_demo/sIFR-print.css" type="text/css" media="print">
<link rel="stylesheet" href="./for_the_demo/simplepie.css" type="text/css" media="screen, projector" />
<script type="text/javascript" src="./for_the_demo/sifr.js"></script>
<script type="text/javascript" src="./for_the_demo/sifr-config.js"></script>
<script type="text/javascript" src="./for_the_demo/sleight.js"></script>
<script type="text/javascript" src="?js"></script>
<body id="bodydemo">
<div id="header">
<div id="headerInner">
<div id="logoContainer">
<div id="logoContainerInner">
<div align="center"><a href=""><img src="./for_the_demo/logo_simplepie_demo.png" alt="SimplePie Demo: PHP-based RSS and Atom feed handling" title="SimplePie Demo: PHP-based RSS and Atom feed handling" border="0" /></a></div>
<div class="clearLeft"></div>
<div id="menu">
<!-- I know, I know, I know... tables for layout, I know. If a web standards evangelist (like me) has to resort
to using tables for something, it's because no other possible solution could be found. This issue? No way to
do centered floats purely with CSS. The table box model allows for a dynamic width while centered, while the
CSS box model for DIVs doesn't allow for it. :( -->
<table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td>
<ul><li id="demo"><a href="./">SimplePie Demo</a></li><li><a href="">FAQ/Troubleshooting</a></li><li><a href="">Support Forums</a></li><li><a href="">API Reference</a></li><li><a href="">Weblog</a></li><li><a href="../test/test.php">Unit Tests</a></li></ul>
<div class="clearLeft"></div>
<div id="site">
<div id="content">
<div class="chunk">
<form action="" method="get" name="sp_form" id="sp_form">
<div id="sp_input">
<!-- If a feed has already been passed through the form, then make sure that the URL remains in the form field. -->
<p><input type="text" name="feed" value="<?php if ($feed->subscribe_url()) echo $feed->subscribe_url(); ?>" class="text" id="feed_input" />&nbsp;<input type="submit" value="Read" class="button" /></p>
// Check to see if there are more than zero errors (i.e. if there are any errors at all)
if ($feed->error())
// If so, start a <div> element with a classname so we can style it.
echo '<div class="sp_errors">' . "\r\n";
// ... and display it.
echo '<p>' . htmlspecialchars($feed->error()) . "</p>\r\n";
// Close the <div> element we opened.
echo '</div>' . "\r\n";
<!-- Here are some sample feeds. -->
<p class="sample_feeds"><strong>Or try one of the following:</strong>
<a href="?feed=http://www.詹姆斯.com/atomtests/iri/everything.atom" title="Test: International Domain Name support">詹姆斯.com</a>,
<a href="?feed=" title="Humor from the people who make [adult swim] cartoons.">adult swim</a>,
<a href="?feed=" title="Ripping, Burning, DRM, and the Dark Side of Consumer Electronics Media">Afterdawn</a>,
<a href="?feed=" title="AJAX and Scripting News">Ajaxian</a>,
<a href="?feed=;image=true" title="Test: Bypass Image Hotlink Blocking">Andy Budd</a>,
<a href="?feed=" title="Test: Embedded Enclosures">Ask a Ninja</a>,
<a href="?feed=" title="Test: Atom 1.0 Support"></a>,
<a href="?feed=" title="World News">BBC News</a>,
<a href="?feed=" title="Test: Windows-1256 Encoding">BBC Arabic</a>,
<a href="?feed=" title="Test: GB2312 Encoding">BBC China</a>,
<a href="?feed=" title="Test: Windows-1251 Encoding">BBC Russia</a>,
<a href="?feed=" title="Developer of NetNewsWire">Brent Simmons</a>,
<a href="?feed=" title="Test: Embedded Enclosures">Channel Frederator</a>,
<a href="?feed=" title="World News">CNN</a>,
<a href="?feed=" title="Tech news. Better than Slashdot.">Digg</a>,
<a href="?feed=" title="Tech and industry videocast.">Diggnation</a>,
<a href="?feed=" title="Flickr Photos">Flickr</a>,
<a href="?feed=" title="World News">Google News</a>,
<a href="?feed=;num=20&amp;output=rss" title="Test: Media RSS Support">Google Video</a>,
<a href="?feed=" title="Test: Tag Stripping">Harvard Law</a>,
<a href="?feed=" title="Test: Window-1255 Encoding">Hebrew Language</a>,
<a href="?feed=" title="Test: Ad Stripping">InfoWorld</a>,
<a href="?feed=;orderbydate=false" title="Test: Tag Stripping">iTunes</a>,
<a href="?feed=" title="Test: EUC-JP Encoding">Japanese Language</a>,
<a href="?feed=;input=EUC-KR" title="Test: EUC-KR Encoding">Korean Language</a>,
<a href="?feed=" title="Weblog for the developer of Scriptaculous"></a>,
<a href="?feed=" title="Apple's QuickTime movie trailer site">Movie Trailers</a>,
<a href="?feed=" title="Tech and Science News">Newspond</a>,
<a href="?feed=" title="Developer of TopStyle and FeedDemon">Nick Bradbury</a>,
<a href="?feed=" title="Usability comics and commentary">OK/Cancel</a>,
<a href="?feed=" title="News about every OS ever">OS News</a>,
<a href="?feed=" title="Test: Atom 1.0 Support">Phil Ringnalda</a>,
<a href="?feed=" title="Test: Improved enclosure type sniffing">Photoshop Videocast</a>,
<a href="?feed=" title="Top links from around the web">reddit</a>,
<a href="?feed=" title="Test: ISO-8859-1 Encoding">Romanian Language</a>,
<a href="?feed=" title="Test: KOI8-R Encoding">Russian Language</a>,
<a href="?feed=" title="SimplePie developer alumnus">Ryan Parman</a>,
<a href="?feed=" title="Test: BIG5 Encoding">Traditional Chinese Language</a>,
<a href="?feed=" title="Technorati watch for SimplePie">Technorati</a>,
<a href="?feed=" title="Test: Atom 1.0 Support">Tim Bray</a>,
<a href="?feed=" title="Apple News">TUAW</a>,
<a href="?feed=;image=true" title="Test: Bypass Image Hotlink Blocking">TVgasm</a>,
<a href="?feed=" title="Interesting tech randomness">UNEASYsilence</a>,
<a href="?feed=" title="Test: Embedded Enclosures">Web 2.0 Show</a>,
<a href="?feed=" title="Test: Tag Stripping">Windows Vista Blog</a>,
<a href="?feed=" title="Test: LightHTTPd and GZipping">XKCD</a>,
<a href="?feed=" title="World News">Yahoo! News</a>,
<a href="?feed=" title="Funny user-submitted videos">You Tube</a>,
<a href="?feed=" title="The father of the web standards movement">Zeldman</a></p>
<div id="sp_results">
<!-- As long as the feed has data to work with... -->
<?php if ($success): ?>
<div class="chunk focus" align="center">
<!-- If the feed has a link back to the site that publishes it (which 99% of them do), link the feed's title to it. -->
<h3 class="header">
$link = $feed->get_link();
$title = $feed->get_title();
if ($link)
$title = "<a href='$link' title='$title'>$title</a>";
echo $title;
<!-- If the feed has a description, display it. -->
<?php echo $feed->get_description(); ?>
<!-- Let's begin looping through each individual news item in the feed. -->
<?php foreach($feed->get_items() as $item): ?>
<div class="chunk">
<!-- If the item has a permalink back to the original post (which 99% of them do), link the item's title to it. -->
<h4><?php if ($item->get_permalink()) echo '<a href="' . $item->get_permalink() . '">'; echo $item->get_title(); if ($item->get_permalink()) echo '</a>'; ?>&nbsp;<span class="footnote"><?php echo $item->get_date('j M Y, g:i a'); ?></span></h4>
<!-- Display the item's primary content. -->
<?php echo $item->get_content(); ?>
// Check for enclosures. If an item has any, set the first one to the $enclosure variable.
if ($enclosure = $item->get_enclosure(0))
// Use the embed() method to embed the enclosure into the page inline.
echo '<div align="center">';
echo '<p>' . $enclosure->embed(array(
'audio' => './for_the_demo/place_audio.png',
'video' => './for_the_demo/place_video.png',
'mediaplayer' => './for_the_demo/mediaplayer.swf',
'altclass' => 'download'
)) . '</p>';
if ($enclosure->get_link() && $enclosure->get_type())
echo '<p class="footnote" align="center">(' . $enclosure->get_type();
if ($enclosure->get_size())
echo '; ' . $enclosure->get_size() . ' MB';
echo ')</p>';
if ($enclosure->get_thumbnail())
echo '<div><img src="' . $enclosure->get_thumbnail() . '" alt="" /></div>';
echo '</div>';
<!-- Stop looping through each item once we've gone through all of them. -->
<?php endforeach; ?>
<!-- From here on, we're no longer using data from the feed. -->
<?php endif; ?>
<!-- Display how fast the page was rendered. -->
<p class="footnote">Page processed in <?php $mtime = explode(' ', microtime()); echo round($mtime[0] + $mtime[1] - $starttime, 3); ?> seconds.</p>
<!-- Display the version of SimplePie being loaded. -->
<p class="footnote">Powered by <a href="<?php echo SIMPLEPIE_URL; ?>"><?php echo SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . ', Build ' . SIMPLEPIE_BUILD; ?></a>. Run the <a href="../compatibility_test/sp_compatibility_test.php">SimplePie Compatibility Test</a>. SimplePie is &copy; 2004&ndash;<?php echo date('Y'); ?>, Ryan Parman and Geoffrey Sneddon, and licensed under the <a href="">BSD License</a>.</p>
Jump to Line
Something went wrong with that request. Please try again.