Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 142 lines (119 sloc) 3.419 kB
e2ca446 moved simplexml call into template files for consistency
erik authored
1 <?php
2
3 /**
4 * This is a template for rendering a standard RSS 2.0 feed.
5 */
6
adff8f8 now preprocessing data
erik authored
7 $feedUrl = 'http://rss.news.yahoo.com/rss/world';
f109d95 we now specify template file in app url, as noted in index.php remova…
erik authored
8
1698137 reduced curl code and clarified comment
erik authored
9 //fetch rss xml using curl, which is more commonly available than simplexml_load_file
10 $ch = curl_init($feedUrl);
dd8f66b now fetching rss xml using curl, which is mor commonly available than…
erik authored
11 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
12 $xmlString = curl_exec($ch);
13 curl_close($ch);
14
2478fe3 now utf-8 encoding xml string before passing it into simplxml_load_st…
erik authored
15 //ensure string is utf-8 encoded for simplexml_load_string()
16 $utf8String = utf8_encode($xmlString);
17
f109d95 we now specify template file in app url, as noted in index.php remova…
erik authored
18 //parse xml
2478fe3 now utf-8 encoding xml string before passing it into simplxml_load_st…
erik authored
19 $feed = simplexml_load_string($utf8String);
f109d95 we now specify template file in app url, as noted in index.php remova…
erik authored
20
21 //format data & set default values to keep template uncluttered
22 $data = array(
23 'header' => array(
24 'title' => $feed->channel->title,
25 'link' => $feed->channel->link
26 ),
27 'body' => array()
adff8f8 now preprocessing data
erik authored
28 );
f109d95 we now specify template file in app url, as noted in index.php remova…
erik authored
29
30 //define list items
31 foreach($feed->channel->item as $item){
32
33 //extract image info, if defined
34 $image = null;
35
36 if(isset($item->children('http://search.yahoo.com/mrss/')->content)){
37 $image = array(
38 'url' => $item->children('http://search.yahoo.com/mrss/')->content->attributes()->url
39 );
40 }
41
42 //package item data
43 $data['body'][] = array(
44 'image' => $image,
45 'category' => array(
c998049 removed reference to category domain, which is undefined in sample rs…
erik authored
46 'text' => $item->category
f109d95 we now specify template file in app url, as noted in index.php remova…
erik authored
47 ),
48 'title' => $item->title,
49 'link' => $item->link,
50 'description' => $item->description,
51 'pubDate' => $item->pubDate,
52 );
53 }
e2ca446 moved simplexml call into template files for consistency
erik authored
54 ?>
f609dd8 defined templates for standard rss and the 'basic' y\! front doors te…
erik authored
55
56 <style>
57 /* wrap app to limit style bleeding from parent */
58 .wrapper {
59
60 /* define app-global settings */
61 font-family: arial;
62 font-size: 12pt;
63 }
64 .wrapper a {
65
66 /* we don't ever want links underlined */
67 text-decoration: none;
68 }
69 .wrapper .header .logo {
70 background-color: #ccc;
71 padding: 10px;
72 }
73 .wrapper .header .logo .title {
74 color: #fff;
75 font-size: 150%;
76 font-weight: bold;
77 }
78 .wrapper .body {
79
80 /* remove whitespace above list */
81 margin-top: 0px;
82
83 /* add whitespace around list */
84 padding: 10px;
85 }
86 .wrapper .body li {
87 margin-bottom: 10px;
88
89 /* remove li bullet points*/
90 list-style: none;
91
92 /* display separator under each item */
93 border-bottom: 1px solid #ccc;
94
95 /* add whitespace above bottom separator */
96 padding-bottom: 10px;
97 }
98 .wrapper .body li .category {
99 font-weight: bold;
100 margin-bottom: 10px;
101 }
102 .wrapper .body li .title {
103 font-weight: bold;
104 margin-bottom: 10px;
105
106 /* title is an a-tag. display block so we can add a margin to it */
107 display: block;
108 }
109 .wrapper .body li .description {
110 margin-bottom: 10px;
111 color: #ccc;
112 }
1a21137 added whitespace to right of embedded image and removed template hand…
erik authored
113 .wrapper .body li .description img {
114 margin-right: 10px;
115 }
f609dd8 defined templates for standard rss and the 'basic' y\! front doors te…
erik authored
116 .wrapper .body li .pubDate {
117 color: #ccc;
118 float: right;
119 }
120 </style>
121
122 <div class="wrapper">
123 <div class="header">
124 <div class="logo">
adff8f8 now preprocessing data
erik authored
125 <a href="<?= $data['header']['link'] ?>" class="title"><?= $data['header']['title'] ?></a>
f609dd8 defined templates for standard rss and the 'basic' y\! front doors te…
erik authored
126 </div>
127 </div>
128 <ul class="body">
adff8f8 now preprocessing data
erik authored
129 <? foreach($data['body'] as $item): ?>
1a21137 added whitespace to right of embedded image and removed template hand…
erik authored
130 <li>
adff8f8 now preprocessing data
erik authored
131 <a href="<?= $item['link'] ?>" class="title"><?= $item['title'] ?></a>
1a21137 added whitespace to right of embedded image and removed template hand…
erik authored
132
133 <!-- use image embedded in description instead of the media:content -->
adff8f8 now preprocessing data
erik authored
134 <div class="description"><?= $item['description'] ?></div>
1a21137 added whitespace to right of embedded image and removed template hand…
erik authored
135
adff8f8 now preprocessing data
erik authored
136 <div class="pubDate"><?= $item['pubDate'] ?></div>
f609dd8 defined templates for standard rss and the 'basic' y\! front doors te…
erik authored
137 <div style="clear:both"></div>
138 </li>
adff8f8 now preprocessing data
erik authored
139 <? endforeach ?>
f609dd8 defined templates for standard rss and the 'basic' y\! front doors te…
erik authored
140 </ul>
adff8f8 now preprocessing data
erik authored
141 </div>
Something went wrong with that request. Please try again.