rss_converter_twitter.com.xsl: fix getting the profile picture
[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:param name="generateEnclosure"/>
27
28     <xsl:output method="xml" indent="yes"/>
29
30     <xsl:variable name="twitterBaseURL">
31         <xsl:text>https://twitter.com</xsl:text>
32     </xsl:variable>
33
34     <xsl:template match="a[@data-expanded-url]">
35         <xsl:value-of disable-output-escaping="yes" select="php:function('Tweeper::generate_enclosure', string(./@data-expanded-url))"/>
36     </xsl:template>
37
38     <xsl:variable name="screen-name" select="//div[@class='user-actions btn-group not-following ']/@data-screen-name"/>
39
40     <xsl:template match="//*[@data-item-type='tweet']">
41         <xsl:variable name="user-name" select=".//div[contains(@class, 'js-stream-tweet')]/@data-screen-name"/>
42         <xsl:variable name="tweet-text" select=".//p[contains(@class, 'js-tweet-text')]"/>
43         <item>
44             <title>
45                 <xsl:value-of select="concat($user-name, ': ', $tweet-text)"/>
46             </title>
47             <link>
48                 <xsl:value-of select="concat($twitterBaseURL, .//a[contains(@class, 'js-permalink')]/@href)"/>
49             </link>
50             <pubDate>
51                 <xsl:variable name="timestamp" select=".//span[contains(@class, 'js-short-timestamp')]/@data-time"/>
52                 <xsl:value-of select="php:functionString('Tweeper::epoch_to_gmdate', number($timestamp))"/>
53             </pubDate>
54             <description>
55                 <xsl:value-of select="concat($user-name, ': ')"/>
56                 <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
57                 <xsl:copy-of select="$tweet-text/node()"/>
58                 <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
59             </description>
60             <xsl:if test="$generateEnclosure = 1">
61                 <xsl:apply-templates select="$tweet-text//a[@data-expanded-url]"/>
62             </xsl:if>
63         </item>
64     </xsl:template>
65
66     <xsl:template match="/">
67
68         <rss version="2.0">
69             <xsl:attribute name="xml:base"><xsl:value-of select="$twitterBaseURL" /></xsl:attribute>
70             <channel>
71                 <generator>Tweeper</generator>
72                 <title>
73                     <xsl:text>Twitter / </xsl:text><xsl:value-of select="$screen-name"/>
74                 </title>
75                 <link>
76                     <xsl:value-of select="//link[@rel='canonical']/@href"/>
77                 </link>
78                 <description>
79                     <xsl:value-of select="//meta[@name='description']/@content"/>
80                 </description>
81                 <image>
82                     <url>
83                         <xsl:value-of select="//a[contains(@class, 'profile-picture media-thumbnail')]/@href"/>
84                     </url>
85                 </image>
86                 <xsl:apply-templates select="//*[@data-item-type='tweet']"/>
87             </channel>
88         </rss>
89     </xsl:template>
90 </xsl:stylesheet>