Mais conteúdo relacionado
Semelhante a RSS Like A Ninja (20)
Mais de Jason Austin (12)
RSS Like A Ninja
- 1. How to RSS like a ninja
Jason Austin - @jason_austin
- 2. On the agenda...
• What is RSS?
• Why should I use it?
• Creating RSS feeds
• Consuming RSS
• Tracking RSS performance
- 4. Why use RSS?
• Keep users up-to-date with fresh content
• Write once, use many
• Replace older subscription models
- 5. Use RSS for...
• ...blog posts!
• ...news articles
• ...forum and article comments
- 6. DO NOT use RSS for...
• ...a calendar feed
• ...a replacement for XML-based API’s
• ...static content
- 7. Types of RSS Feeds
• RSS 2.0
• RSS 1.0
• Atom
• ...lots more
- 8. RSS 2.0
• RSS 2.0 = Really Simple Syndication
• Most Popular
• Simplest
- 9. <?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Ninja Academy</title>
<link>http://ninjaacademy.com/</link>
<description>The source for Ninjas</description>
<item>
<title>Throwing Stars</title>
<link>http://ninjaacademy.com/stars</link>
<description>How to throw stars</description>
</item>
<item>
<title>Tips for Sneakery</title>
<link>http://ninjaacademy.com/sneakery</link>
<description>Be Sneaky My Friend</description>
</item>
</channel>
- 10. RSS 1.0
• RSS 1.0 = RDF Site Summary
• RDF = Resource Description Framework
• way of structuring metadata
• Consumption instructions are built in
- 11. <?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel rdf:about="http://ninjaacademy.com/news.rss">
<title>Ninja Academy</title>
<link>http://ninjaacademy.com/</link>
<description>The Source For Ninjas</description>
<items>
<rdf:Seq>
<rdf:li resource="http://ninjaacademy.com/stars/"/>
<rdf:li resource="http://ninjaacademy.com/sneakery/"/>
</rdf:Seq>
</items>
</channel>
<item rdf:about="http://ninjaacademy.com/stars/">
<title>Throwing Stars</title>
<link>http://ninjaacademy.com/stars/</link>
<description>How to Throw Stars</description>
<dc:date>2002-09-01</dc:date>
</item>
<item rdf:about="http://ninjaacademy.com/sneakery/">
<title>Tips for Sneakery</title>
<link>http://ninjaacademy.com/sneakery/</link>
<dc:date>2002-09-02</dc:date>
</item>
</rdf:RDF>
- 12. Atom Feeds
• 2 types of Atom Specs
• Atom Syndication Format
• Atom Publishing Protocol
- 15. Atom as a feed
• Intended to replace RSS
• Meant to clarify feed specs
• Not as widely adopted
- 16. <?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Ninja Academy</title>
<link href="http://ninjaacademy.com/"/>
<updated>2003-12-13T18:30:02Z</updated>
<author>
<name></name>
</author>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
<entry>
<title>Throwing Stars</title>
<link href="http://ninjaacademy.com/stars/"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>How to throw stars.</summary>
</entry>
<entry>
<title>Tips for Sneakery</title>
<link href="http://ninjaacademy.com/sneakery/"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Be Sneaky My Friend</summary>
</entry>
</feed>
- 17. Choosing a Format
• Personal Choice
• Most syndicators can read all formats
• Don’t invent your own
- 18. Creating a feed
• Drupal, Wordpress, Joomla, etc.
• Create your own
• Lots of OSS libraries in every language
• Pretty easy to implement
- 19. <?php
$ncsu = new Tweets_Ncsu();
$timeline = $ncsu->getTimeline();
$feed = array();
$feed['title'] = ‘NC State Tweets’;
$feed['link'] = ‘http://twitter.ncsu.edu/feed.php';
$feed['charset'] = 'UTF-8';
$feed['author'] = ‘NC State University’;
$feed[‘entries’] = array();
foreach ($timeline as $t) {
$feed[‘entries’][] = array(
'title' => 'Tweet by @' . $t['user-screen_name'],
'link' => 'http://www.twitter.com/' . $t['user-screen_name'],
'description' => $t['text'],
'lastUpdate' => strtotime($t['created_at']),
);
}
// importing a rss feed from an array
$rssFeed = Zend_Feed::importArray($fa, 'rss');
// send http headers and dump the feed
$rssFeed->send();
- 20. Validate your feed
• w3c’s Feed Validator
http://validator.w3.org/feed/
• Validates RSS 2.0 and Atom formats
- 22. Finding feeds in code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<title>Jason Austin's Blog</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="wp-content/themes/lightword/original.css"
type="text/css" />
<link rel="shortcut icon" href="http://www.jasonawesome.com/favicon.ico" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0"
href="http://www.jasonawesome.com/feed/" />
<link rel="alternate" type="text/xml" title="RSS .92" href="http://
www.jasonawesome.com/feed/rss/" />
<link rel="alternate" type="application/atom+xml" title="Atom 1.0"
href="http://www.jasonawesome.com/feed/atom/" />
</head>
- 25. <?php
$feed = new Zend_Feed_Rss(‘http://twitter.ncsu.edu/feed.php’);
foreach ($feed as $f) {
echo ‘<a href="’ . $f->link . ‘">’ . $f->title . ‘</a><br />’;
echo ‘<p>’ . $f->description . ‘</p>’;
}