Strip trailing newlines
[tweeper.git] / rss_converter_pump.io.xsl
1 <!--
2   Stylesheet to convert Pump.io activity streams to RSS.
3
4   Copyright (C) 2013-2014  Antonio Ospite <ao2@ao2.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 <!-- To Evan, please reconsider publishing RSS ouput for _public_ contents -->
22 <xsl:stylesheet version="1.0"
23     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
24     xmlns:php="http://php.net/xsl"
25     xsl:extension-element-prefixes="php"
26     exclude-result-prefixes="php">
27
28     <xsl:output method="xml" indent="yes"/>
29
30     <xsl:variable name="domain-name" select="substring-after(//div[@id='profile-block']/@data-profile-id, '@')"/>
31     <xsl:variable name="BaseURL" select="concat('https://', $domain-name)"/>
32
33     <xsl:variable name="user-name" select="substring-after(//div[@id='profile-block']/@data-profile-id, ':')"/>
34
35     <xsl:template match="//div[@id='user-content-activities']//ul[@id='major-stream']/li">
36         <xsl:variable name="item-content" select=".//div[@class='activity-content']"/>
37         <xsl:variable name="item-permalink" select=".//p[@class='muted']/small/a/@href"/>
38         <item>
39             <title>
40                 <xsl:value-of select="concat($user-name, ': ', normalize-space($item-content))"/>
41             </title>
42             <link>
43                 <xsl:value-of select="$item-permalink"/>
44             </link>
45             <guid>
46                 <xsl:value-of select="$item-permalink"/>
47             </guid>
48             <pubDate>
49                 <xsl:value-of select="php:functionString('Tweeper::str_to_gmdate', .//abbr[@class='easydate']/@title)"/>
50             </pubDate>
51             <description>
52                 <xsl:value-of select="concat($user-name, ': ')"/>
53                 <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
54                 <xsl:copy-of select="$item-content/node()"/>
55                 <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
56             </description>
57         </item>
58     </xsl:template>
59
60     <xsl:template match="/">
61         <xsl:variable name="channel-title" select="concat(substring-after($user-name, '@'), ' / ', substring-before($user-name, '@'))"/>
62         <xsl:variable name="channel-link" select="concat('https://', substring-after($user-name, '@'), '/', substring-before($user-name, '@'))"/>
63
64         <rss version="2.0">
65             <xsl:attribute name="xml:base"><xsl:value-of select="$BaseURL" /></xsl:attribute>
66             <channel>
67                 <generator>Tweeper</generator>
68                 <title>
69                     <xsl:value-of select="$channel-title"/>
70                 </title>
71                 <link>
72                     <xsl:value-of select="$channel-link"/>
73                 </link>
74                 <description>
75                     <xsl:value-of select="normalize-space(//h1[@class='media-header'])"/>
76                 </description>
77                 <image>
78                     <title>
79                         <xsl:value-of select="$channel-title"/>
80                     </title>
81                     <link>
82                         <xsl:value-of select="$channel-link"/>
83                     </link>
84                     <url>
85                         <xsl:value-of select="//div[@id='profile-block']/span/img[@class='img-rounded media-object']/@src"/>
86                     </url>
87                 </image>
88                 <xsl:apply-templates select="//div[@id='user-content-activities']//ul[@id='major-stream']/li"/>
89             </channel>
90         </rss>
91     </xsl:template>
92 </xsl:stylesheet>