5a57c8f683e495c3381f31fa6cdd2087a3268c6e
[tweeper.git] / rss_converter_twitter.com.xsl
1 <!--
2   Stylesheet to convert Twitter user timelines to RSS.
3
4   Copyright (C) 2013  Antonio Ospite <ospite@studenti.unina.it>
5
6   This file is part of tweeper.
7
8   This program is free software: you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation, either version 3 of the License, or
11   (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 -->
21 <xsl:stylesheet version="1.0"
22     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23     xmlns:php="http://php.net/xsl"
24     xsl:extension-element-prefixes="php">
25
26     <xsl:output method="xml" indent="yes"/>
27
28     <xsl:variable name="twitterBaseURL">
29         <xsl:text>https://twitter.com</xsl:text>
30     </xsl:variable>
31
32     <xsl:variable name="screen-name" select="//div[@class='profile-card-inner']/@data-screen-name"/>
33
34     <xsl:template match="//div[@id='timeline']//ol[@id='stream-items-id']//li[@data-item-type='tweet']">
35         <xsl:variable name="tweet-text" select=".//p[@class='js-tweet-text tweet-text']"/>
36         <item>
37             <title>
38                 <xsl:value-of select="concat($screen-name, ': ', $tweet-text)"/>
39             </title>
40             <link>
41                 <xsl:value-of select="concat($twitterBaseURL, .//a[@class='details with-icn js-details']/@href)"/>
42             </link>
43             <pubDate>
44                 <xsl:value-of select="php:functionString('epoch_to_gmdate', .//small[@class='time']//span/@data-time)"/>
45             </pubDate>
46             <description>
47                 <xsl:value-of select="concat($screen-name, ': ')"/>
48                 <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
49                 <xsl:copy-of select="$tweet-text/node()"/>
50                 <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
51             </description>
52         </item>
53     </xsl:template>
54
55     <xsl:template match="/">
56
57         <rss version="2.0">
58             <channel>
59                 <generator>Tweeper</generator>
60                 <title>
61                     <xsl:text>Twitter / </xsl:text><xsl:value-of select="$screen-name"/>
62                 </title>
63                 <link>
64                     <xsl:value-of select="//link[@rel='canonical']/@href"/>
65                 </link>
66                 <description>
67                     <xsl:value-of select="//meta[@name='description']/@content"/>
68                 </description>
69                 <image>
70                     <url>
71                         <xsl:value-of select="//a[@class='profile-picture media-thumbnail']/@href"/>
72                     </url>
73                 </image>
74                 <xsl:apply-templates select="//div[@id='timeline']//ol[@id='stream-items-id']//li[@data-item-type='tweet']"/>
75             </channel>
76         </rss>
77     </xsl:template>
78 </xsl:stylesheet>