Projet

Général

Profil

Paste
Télécharger (13,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / libraries / simplepie / demo / index.php @ 41cc1b08

1
<?php
2
// Start counting time for the page load
3
$starttime = explode(' ', microtime());
4
$starttime = $starttime[1] + $starttime[0];
5

    
6
// Include SimplePie
7
// Located in the parent directory
8
include_once('../autoloader.php');
9
include_once('../idn/idna_convert.class.php');
10

    
11
// Create a new instance of the SimplePie object
12
$feed = new SimplePie();
13

    
14
//$feed->force_fsockopen(true);
15

    
16
if (isset($_GET['js']))
17
{
18
        SimplePie_Misc::output_javascript();
19
        die();
20
}
21

    
22
// Make sure that page is getting passed a URL
23
if (isset($_GET['feed']) && $_GET['feed'] !== '')
24
{
25
        // Strip slashes if magic quotes is enabled (which automatically escapes certain characters)
26
        if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
27
        {
28
                $_GET['feed'] = stripslashes($_GET['feed']);
29
        }
30

    
31
        // Use the URL that was passed to the page in SimplePie
32
        $feed->set_feed_url($_GET['feed']);
33
}
34

    
35
// Allow us to change the input encoding from the URL string if we want to. (optional)
36
if (!empty($_GET['input']))
37
{
38
        $feed->set_input_encoding($_GET['input']);
39
}
40

    
41
// Allow us to choose to not re-order the items by date. (optional)
42
if (!empty($_GET['orderbydate']) && $_GET['orderbydate'] == 'false')
43
{
44
        $feed->enable_order_by_date(false);
45
}
46

    
47
// Trigger force-feed
48
if (!empty($_GET['force']) && $_GET['force'] == 'true')
49
{
50
        $feed->force_feed(true);
51
}
52

    
53
// Initialize the whole SimplePie object.  Read the feed, process it, parse it, cache it, and
54
// all that other good stuff.  The feed's information will not be available to SimplePie before
55
// this is called.
56
$success = $feed->init();
57

    
58
// We'll make sure that the right content type and character encoding gets set automatically.
59
// This function will grab the proper character encoding, as well as set the content type to text/html.
60
$feed->handle_content_type();
61

    
62
// When we end our PHP block, we want to make sure our DOCTYPE is on the top line to make
63
// sure that the browser snaps into Standards Mode.
64
?><!DOCTYPE html>
65

    
66
<html lang="en-US">
67
<head>
68
<title>SimplePie: Demo</title>
69

    
70
<link rel="stylesheet" href="./for_the_demo/sIFR-screen.css" type="text/css" media="screen">
71
<link rel="stylesheet" href="./for_the_demo/sIFR-print.css" type="text/css" media="print">
72
<link rel="stylesheet" href="./for_the_demo/simplepie.css" type="text/css" media="screen, projector" />
73

    
74
<script type="text/javascript" src="./for_the_demo/sifr.js"></script>
75
<script type="text/javascript" src="./for_the_demo/sifr-config.js"></script>
76
<script type="text/javascript" src="./for_the_demo/sleight.js"></script>
77
<script type="text/javascript" src="?js"></script>
78

    
79
</head>
80

    
81
<body id="bodydemo">
82

    
83
<div id="header">
84
        <div id="headerInner">
85
                <div id="logoContainer">
86
                        <div id="logoContainerInner">
87
                                <div align="center"><a href="http://simplepie.org"><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>
88
                                <div class="clearLeft"></div>
89
                        </div>
90

    
91
                </div>
92
                <div id="menu">
93
                <!-- I know, I know, I know... tables for layout, I know.  If a web standards evangelist (like me) has to resort
94
                to using tables for something, it's because no other possible solution could be found.  This issue?  No way to
95
                do centered floats purely with CSS. The table box model allows for a dynamic width while centered, while the
96
                CSS box model for DIVs doesn't allow for it. :( -->
97
                <table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td>
98
<ul><li id="demo"><a href="./">SimplePie Demo</a></li><li><a href="http://simplepie.org/wiki/faq/start">FAQ/Troubleshooting</a></li><li><a href="http://simplepie.org/support/">Support Forums</a></li><li><a href="http://simplepie.org/wiki/reference/start">API Reference</a></li><li><a href="http://simplepie.org/blog/">Weblog</a></li><li><a href="../test/test.php">Unit Tests</a></li></ul>
99

    
100
                        <div class="clearLeft"></div>
101
                </td></tr></tbody></table>
102
                </div>
103
        </div>
104
</div>
105

    
106
<div id="site">
107

    
108
        <div id="content">
109

    
110
                <div class="chunk">
111
                        <form action="" method="get" name="sp_form" id="sp_form">
112
                                <div id="sp_input">
113

    
114

    
115
                                        <!-- If a feed has already been passed through the form, then make sure that the URL remains in the form field. -->
116
                                        <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>
117

    
118

    
119
                                </div>
120
                        </form>
121

    
122

    
123
                        <?php
124
                        // Check to see if there are more than zero errors (i.e. if there are any errors at all)
125
                        if ($feed->error())
126
                        {
127
                                // If so, start a <div> element with a classname so we can style it.
128
                                echo '<div class="sp_errors">' . "\r\n";
129

    
130
                                        // ... and display it.
131
                                        echo '<p>' . htmlspecialchars($feed->error()) . "</p>\r\n";
132

    
133
                                // Close the <div> element we opened.
134
                                echo '</div>' . "\r\n";
135
                        }
136
                        ?>
137

    
138
                        <!-- Here are some sample feeds. -->
139
                        <p class="sample_feeds"><strong>Or try one of the following:</strong>
140
                        <a href="?feed=http://www.詹姆斯.com/atomtests/iri/everything.atom" title="Test: International Domain Name support">詹姆斯.com</a>,
141
                        <a href="?feed=http://www.adultswim.com/williams/podcast/tools/xml/video_rss.xml" title="Humor from the people who make [adult swim] cartoons.">adult swim</a>,
142
                        <a href="?feed=http://afterdawn.com/news/afterdawn_rss.xml" title="Ripping, Burning, DRM, and the Dark Side of Consumer Electronics Media">Afterdawn</a>,
143
                        <a href="?feed=http://feeds.feedburner.com/ajaxian" title="AJAX and Scripting News">Ajaxian</a>,
144
                        <a href="?feed=http://www.andybudd.com/index.rdf&amp;image=true" title="Test: Bypass Image Hotlink Blocking">Andy Budd</a>,
145
                        <a href="?feed=http://feeds.feedburner.com/AskANinja" title="Test: Embedded Enclosures">Ask a Ninja</a>,
146
                        <a href="?feed=http://www.atomenabled.org/atom.xml" title="Test: Atom 1.0 Support">AtomEnabled.org</a>,
147
                        <a href="?feed=http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml" title="World News">BBC News</a>,
148
                        <a href="?feed=http://newsrss.bbc.co.uk/rss/arabic/news/rss.xml" title="Test: Windows-1256 Encoding">BBC Arabic</a>,
149
                        <a href="?feed=http://newsrss.bbc.co.uk/rss/chinese/simp/news/rss.xml" title="Test: GB2312 Encoding">BBC China</a>,
150
                        <a href="?feed=http://newsrss.bbc.co.uk/rss/russian/news/rss.xml" title="Test: Windows-1251 Encoding">BBC Russia</a>,
151
                        <a href="?feed=http://inessential.com/xml/rss.xml" title="Developer of NetNewsWire">Brent Simmons</a>,
152
                        <a href="?feed=http://www.channelfrederator.com/rss" title="Test: Embedded Enclosures">Channel Frederator</a>,
153
                        <a href="?feed=http://rss.cnn.com/rss/cnn_topstories.rss" title="World News">CNN</a>,
154
                        <a href="?feed=http://digg.com/rss/index.xml" title="Tech news. Better than Slashdot.">Digg</a>,
155
                        <a href="?feed=http://revision3.com/diggnation/feed/quicktime-large" title="Tech and industry videocast.">Diggnation</a>,
156
                        <a href="?feed=http://www.flickr.com/services/feeds/photos_public.gne?format=rss2" title="Flickr Photos">Flickr</a>,
157
                        <a href="?feed=http://news.google.com/?output=rss" title="World News">Google News</a>,
158
                        <a href="?feed=http://video.google.com/videofeed?type=top100new&amp;num=20&amp;output=rss" title="Test: Media RSS Support">Google Video</a>,
159
                        <a href="?feed=http://blogs.law.harvard.edu/home/feed/rdf/" title="Test: Tag Stripping">Harvard Law</a>,
160
                        <a href="?feed=http://hagada.org.il/hagada/html/backend.php" title="Test: Window-1255 Encoding">Hebrew Language</a>,
161
                        <a href="?feed=http://www.infoworld.com/rss/news.xml" title="Test: Ad Stripping">InfoWorld</a>,
162
                        <a href="?feed=http://phobos.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/limit=10/rss.xml&amp;orderbydate=false" title="Test: Tag Stripping">iTunes</a>,
163
                        <a href="?feed=http://blog.japan.cnet.com/lessig/index.rdf" title="Test: EUC-JP Encoding">Japanese Language</a>,
164
                        <a href="?feed=http://nurapt.kaist.ac.kr/~jamaica/htmls/blog/rss.php&amp;input=EUC-KR" title="Test: EUC-KR Encoding">Korean Language</a>,
165
                        <a href="?feed=http://mir.aculo.us/xml/rss/feed.xml" title="Weblog for the developer of Scriptaculous">mir.aculo.us</a>,
166
                        <a href="?feed=http://images.apple.com/trailers/rss/newtrailers.rss" title="Apple's QuickTime movie trailer site">Movie Trailers</a>,
167
                        <a href="?feed=http://www.newspond.com/rss/main.xml" title="Tech and Science News">Newspond</a>,
168
                        <a href="?feed=http://nick.typepad.com/blog/index.rss" title="Developer of TopStyle and FeedDemon">Nick Bradbury</a>,
169
                        <a href="?feed=http://feeds.feedburner.com/ok-cancel" title="Usability comics and commentary">OK/Cancel</a>,
170
                        <a href="?feed=http://osnews.com/files/recent.rdf" title="News about every OS ever">OS News</a>,
171
                        <a href="?feed=http://weblog.philringnalda.com/feed/" title="Test: Atom 1.0 Support">Phil Ringnalda</a>,
172
                        <a href="?feed=http://kabili.libsyn.com/rss" title="Test: Improved enclosure type sniffing">Photoshop Videocast</a>,
173
                        <a href="?feed=http://www.reddit.com/" title="Top links from around the web">reddit</a>,
174
                        <a href="?feed=http://www.pariurisportive.com/blog/xmlsrv/rss2.php?blog=2" title="Test: ISO-8859-1 Encoding">Romanian Language</a>,
175
                        <a href="?feed=http://www.erased.info/rss2.php" title="Test: KOI8-R Encoding">Russian Language</a>,
176
                        <a href="?feed=http://ryanparman.com/" title="SimplePie developer alumnus">Ryan Parman</a>,
177
                        <a href="?feed=http://www.upsaid.com/isis/index.rdf" title="Test: BIG5 Encoding">Traditional Chinese Language</a>,
178
                        <a href="?feed=http://technorati.com/watchlists/rss.html?wid=29290" title="Technorati watch for SimplePie">Technorati</a>,
179
                        <a href="?feed=http://www.tbray.org/ongoing/ongoing.atom" title="Test: Atom 1.0 Support">Tim Bray</a>,
180
                        <a href="?feed=http://tuaw.com/rss.xml" title="Apple News">TUAW</a>,
181
                        <a href="?feed=http://www.tvgasm.com/atom.xml&amp;image=true" title="Test: Bypass Image Hotlink Blocking">TVgasm</a>,
182
                        <a href="?feed=http://uneasysilence.com/feed/" title="Interesting tech randomness">UNEASYsilence</a>,
183
                        <a href="?feed=http://feeds.feedburner.com/web20Show" title="Test: Embedded Enclosures">Web 2.0 Show</a>,
184
                        <a href="?feed=http://windowsvistablog.com/blogs/MainFeed.aspx" title="Test: Tag Stripping">Windows Vista Blog</a>,
185
                        <a href="?feed=http://xkcd.com/rss.xml" title="Test: LightHTTPd and GZipping">XKCD</a>,
186
                        <a href="?feed=http://rss.news.yahoo.com/rss/topstories" title="World News">Yahoo! News</a>,
187
                        <a href="?feed=http://gdata.youtube.com/feeds/api/standardfeeds/top_favorites" title="Funny user-submitted videos">You Tube</a>,
188
                        <a href="?feed=http://zeldman.com/rss/" title="The father of the web standards movement">Zeldman</a></p>
189

    
190
                </div>
191

    
192
                <div id="sp_results">
193

    
194
                        <!-- As long as the feed has data to work with... -->
195
                        <?php if ($success): ?>
196
                                <div class="chunk focus" align="center">
197

    
198
                                        <!-- 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. -->
199
                                        <h3 class="header"><?php if ($feed->get_link()) echo '<a href="' . $feed->get_link() . '">'; echo $feed->get_title(); if ($feed->get_link()) echo '</a>'; ?></h3>
200

    
201
                                        <!-- If the feed has a description, display it. -->
202
                                        <?php echo $feed->get_description(); ?>
203

    
204
                                </div>
205

    
206
                                <!-- Let's begin looping through each individual news item in the feed. -->
207
                                <?php foreach($feed->get_items() as $item): ?>
208
                                        <div class="chunk">
209

    
210
                                                <!-- If the item has a permalink back to the original post (which 99% of them do), link the item's title to it. -->
211
                                                <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>
212

    
213
                                                <!-- Display the item's primary content. -->
214
                                                <?php echo $item->get_content(); ?>
215

    
216
                                                <?php
217
                                                // Check for enclosures.  If an item has any, set the first one to the $enclosure variable.
218
                                                if ($enclosure = $item->get_enclosure(0))
219
                                                {
220
                                                        // Use the embed() method to embed the enclosure into the page inline.
221
                                                        echo '<div align="center">';
222
                                                        echo '<p>' . $enclosure->embed(array(
223
                                                                'audio' => './for_the_demo/place_audio.png',
224
                                                                'video' => './for_the_demo/place_video.png',
225
                                                                'mediaplayer' => './for_the_demo/mediaplayer.swf',
226
                                                                'altclass' => 'download'
227
                                                        )) . '</p>';
228

    
229
                                                        if ($enclosure->get_link() && $enclosure->get_type())
230
                                                        {
231
                                                                echo '<p class="footnote" align="center">(' . $enclosure->get_type();
232
                                                                if ($enclosure->get_size())
233
                                                                {
234
                                                                        echo '; ' . $enclosure->get_size() . ' MB';
235
                                                                }
236
                                                                echo ')</p>';
237
                                                        }
238
                                                        if ($enclosure->get_thumbnail())
239
                                                        {
240
                                                                echo '<div><img src="' . $enclosure->get_thumbnail() . '" alt="" /></div>';
241
                                                        }
242
                                                        echo '</div>';
243
                                                }
244
                                                ?>
245

    
246
                                        </div>
247

    
248
                                <!-- Stop looping through each item once we've gone through all of them. -->
249
                                <?php endforeach; ?>
250

    
251
                        <!-- From here on, we're no longer using data from the feed. -->
252
                        <?php endif; ?>
253

    
254
                </div>
255

    
256
                <div>
257
                        <!-- Display how fast the page was rendered. -->
258
                        <p class="footnote">Page processed in <?php $mtime = explode(' ', microtime()); echo round($mtime[0] + $mtime[1] - $starttime, 3); ?> seconds.</p>
259

    
260
                        <!-- Display the version of SimplePie being loaded. -->
261
                        <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="http://www.opensource.org/licenses/bsd-license.php">BSD License</a>.</p>
262
                </div>
263

    
264
        </div>
265

    
266
</div>
267

    
268
</body>
269
</html>