root / branches / 1.1 / demo / multifeeds.php @ 960

1
<?php
2
/********************************************************************
3
MULTIFEEDS TEST PAGE
4
5
Nothing too exciting here.  Just a sample page that demos integrated 
6
Multifeeds support as well as cached favicons and perhaps a few other 
7
things.
8
9
Lots of this code is commented to help explain some of the new stuff.  
10
Code was tested in PHP 5.2.2, but *should* also work with earlier 
11
versions of PHP, as supported by SimplePie (PHP 4.1).
12
13
********************************************************************/
14
15
// Include the SimplePie library, and the one that handles internationalized domain names.
16
require_once('../simplepie.inc');
17
require_once('../idn/idna_convert.class.php');
18
19
// Initialize some feeds for use.
20
$feed = new SimplePie();
21
$feed->set_feed_url(array(
22
        'http://rss.news.yahoo.com/rss/topstories',
23
        'http://news.google.com/?output=atom',
24
        'http://rss.cnn.com/rss/cnn_topstories.rss'
25
));
26
27
// When we set these, we need to make sure that the handler_image.php file is also trying to read from the same cache directory that we are.
28
$feed->set_favicon_handler('./handler_image.php');
29
$feed->set_image_handler('./handler_image.php');
30
31
// Initialize the feed.
32
$feed->init();
33
34
// Make sure the page is being served with the UTF-8 headers.
35
$feed->handle_content_type();
36
37
// Begin the (X)HTML page.
38
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
39
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
40
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">        
41
<head>
42
        <title>Multifeeds Test page</title>
43
        <link rel="stylesheet" href="../demo/for_the_demo/simplepie.css" type="text/css" media="screen" title="SimplePie Styles" charset="utf-8" />
44
        <style type="text/css">
45
        div#site {
46
                width:600px;
47
        }
48
        span.footnote {
49
                white-space:nowrap;
50
        }
51
        h1 {
52
                line-height:1.4em;
53
        }
54
        h4 {
55
                padding-left:20px;
56
                background-color:transparent;
57
                background-repeat:no-repeat;
58
                background-position:0 1px;
59
        }
60
        .clearBoth {
61
                clear:both;
62
        }
63
        </style>
64
</head>
65
<body>
66
<div id="site">
67
68
        <?php if ($feed->error): ?>
69
                <p><?=$feed->error()?></p>
70
        <?php endif ?>
71
72
        <div class="chunk">
73
                <h1>Quick-n-Dirty Multifeeds Demo</a></h1>
74
        </div>
75
76
        <?php
77
        // Let's loop through each item in the feed.
78
        foreach($feed->get_items() as $item):
79
80
        // Let's give ourselves a reference to the parent $feed object for this particular item.
81
        $feed = $item->get_feed();
82
        ?>
83
84
                <div class="chunk">
85
                        <h4 style="background-image:url(<?php echo $feed->get_favicon(); ?>);"><a href="<?php echo $item->get_permalink(); ?>"><?php echo html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8'); ?></a></h4>
86
87
                        <!-- get_content() prefers full content over summaries -->
88
                        <?php echo $item->get_content(); ?>
89
90
                        <?php if ($enclosure = $item->get_enclosure()): ?>
91
                                <div>
92
                                <?php echo $enclosure->native_embed(array(
93
                                        // New 'mediaplayer' attribute shows off Flash-based MP3 and FLV playback.
94
                                        'mediaplayer' => '../demo/for_the_demo/mediaplayer.swf'
95
                                )); ?>
96
                                </div>
97
                        <?php endif; ?>
98
99
                        <p class="footnote">Source: <a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a> | <?php echo $item->get_date('j M Y | g:i a'); ?></p>
100
                </div>
101
102
        <?php endforeach ?>
103
104
        <p class="footnote">This is a test of the emergency broadcast system.  This is only a test&hellip; beeeeeeeeeeeeeeeeeeeeeeeeeep!</p>
105
106
</div>
107
</body>
108
</html>