]> Tony Duckles's Git Repositories (git.nynim.org) - delicious-utils.git/blob - delicious-xml2rss/delicious-xml2rss.php
Initial commit
[delicious-utils.git] / delicious-xml2rss / delicious-xml2rss.php
1 <?php
2 /*
3 Name: delicious-xml2rss.php
4 Description: Given a Delicious "posts/all"-style XML text, output an
5 RSS-style XML feed.
6 Author: Tony Duckles <tony@nynim.org>
7
8 Usage:
9 1) Create the "userinfo.inc.php" file, with your Delicious username and
10 full-name, e.g.:
11 <?php
12 define('DELICIOUS_USERNAME', 'username');
13 ?>
14 2) Run this script and redirect the output as needed:
15 $ php delicious-xml2rss.php < delicious-posts.xml > delicious-rss.xml
16 */
17
18 // Load the (private) "auth_info.inc.php" file
19 require('userinfo.inc.php');
20 if (!defined('DELICIOUS_USERNAME'))
21 define('DELICIOUS_USERNAME', 'username');
22
23 // Print the initial '<?xml ... >' line using PHP code, so that the trailing
24 // "?"+">" doesn't confuse PHP and/or editor syntax-highlighting.
25 print '<?xml version="1.0" encoding="UTF-8"?>'."\n";
26 ?>
27 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://web.resource.org/cc/">
28 <channel>
29 <title>Delicious/<? print DELICIOUS_USERNAME; ?></title>
30 <link>http://delicious.com/<? print DELICIOUS_USERNAME; ?></link>
31 <description>bookmarks posted by <? print DELICIOUS_USERNAME; ?></description>
32 <atom:link rel="self" type="application/rss+xml" href="http://feeds.delicious.com/v2/rss/<? print DELICIOUS_USERNAME; ?>?count=15"/>
33 <cc:license rdf:resource="http://creativecommons.org/licenses/by/2.5/"/>
34 <?php
35 $lines = file('php://stdin');
36 foreach ($lines as $line_num => $line) {
37 if ($line_num > 1) {
38 $pattern = '/<post href="(.*)" hash="(.*)" description="(.*)" tag="(.*)" time="(.*)" extended="(.*)" meta="(.*)"/';
39 if (preg_match($pattern, $line, $matches) > 0) {
40 echo ' <item>'."\n";
41 echo ' <title>'.$matches[3].'</title>'."\n";
42 echo ' <pubDate>'.date('r', strtotime(str_replace('T', ' ',$matches[5]))).'</pubDate>'."\n";
43 echo ' <guid isPermaLink="false">http://delicious.com/url/'.$matches[2].'#'.DELICIOUS_USERNAME.'</guid>'."\n";
44 echo ' <link>'.$matches[1].'</link>'."\n";
45 echo ' <dc:creator><![CDATA['.DELICIOUS_USERNAME.']]></dc:creator>'."\n";
46 echo ' <comments>http://delicious.com/url/'.$matches[2].'</comments>'."\n";
47 echo ' <wfw:commentRss>http://feeds.delicious.com/v2/rss/url/'.$matches[2].'</wfw:commentRss>'."\n";
48 echo ' <source url="http://feeds.delicious.com/v2/rss/'.DELICIOUS_USERNAME.'">'.DELICIOUS_USERNAME.'\'s bookmarks</source>'."\n";
49 $tags = explode(' ', $matches[4]);
50 foreach ($tags as $tag) {
51 echo ' <category domain="http://delicious.com/'.DELICIOUS_USERNAME.'/">'.$tag.'</category>'."\n";
52 }
53 echo ' </item>'."\n";
54 }
55 }
56 }
57 ?>
58 </channel>
59 </rss>