debian/changelog: release package version 1.4.0-1
[tweeper.git] / src / rss_converter_pump.io.xsl
1 <!--
2   Stylesheet to convert Pump.io activity streams to RSS.
3
4   Copyright (C) 2013-2018  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     exclude-result-prefixes="php">
26
27     <xsl:param name="generate-enclosure"/>
28     <xsl:param name="show-usernames"/>
29
30     <xsl:output method="xml" indent="yes"/>
31
32     <xsl:variable name="domain-name" select="substring-after(//div[@id='profile-block']/@data-profile-id, '@')"/>
33     <xsl:variable name="BaseURL" select="concat('https://', $domain-name)"/>
34
35     <xsl:variable name="user-name" select="substring-after(//div[@id='profile-block']/@data-profile-id, ':')"/>
36
37     <xsl:template match="//div[@id='user-content-activities']//ul[@id='major-stream']/li">
38         <xsl:variable name="item-content" select=".//div[@class='activity-content']"/>
39         <xsl:variable name="item-permalink" select=".//p[@class='muted']/small/a/@href"/>
40         <item>
41             <title>
42                 <xsl:if test="$show-usernames = 1">
43                     <xsl:value-of select="concat($user-name, ': ')"/>
44                 </xsl:if>
45                 <xsl:value-of select="normalize-space($item-content)"/>
46             </title>
47             <link>
48                 <xsl:value-of select="$item-permalink"/>
49             </link>
50             <guid>
51                 <xsl:value-of select="$item-permalink"/>
52             </guid>
53             <pubDate>
54                 <xsl:value-of select="php:functionString('Tweeper\Tweeper::strToRssDate', .//abbr[@class='easydate']/@title)"/>
55             </pubDate>
56             <description>
57                 <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
58                 <xsl:if test="$show-usernames = 1">
59                     <xsl:value-of select="concat($user-name, ': ')"/>
60                 </xsl:if>
61                 <xsl:copy-of select="$item-content/node()"/>
62                 <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
63             </description>
64             <xsl:if test="$generate-enclosure = 1">
65                 <xsl:variable name="image-thumb-link" select=".//img[contains(@class, 'object-image')]/@src"/>
66                 <xsl:if test="$image-thumb-link">
67                     <xsl:variable name="image-link" select="php:functionString('str_replace', '_thumb', '', $image-thumb-link)"/>
68                     <xsl:copy-of select="php:functionString('Tweeper\Tweeper::generateEnclosure', $image-link)"/>
69                 </xsl:if>
70             </xsl:if>
71         </item>
72     </xsl:template>
73
74     <xsl:template match="/">
75         <xsl:variable name="channel-title" select="concat(substring-after($user-name, '@'), ' / ', substring-before($user-name, '@'))"/>
76         <xsl:variable name="channel-link" select="concat('https://', substring-after($user-name, '@'), '/', substring-before($user-name, '@'))"/>
77
78         <rss version="2.0">
79             <xsl:attribute name="xml:base"><xsl:value-of select="$BaseURL" /></xsl:attribute>
80             <channel>
81                 <generator>Tweeper</generator>
82                 <title>
83                     <xsl:value-of select="$channel-title"/>
84                 </title>
85                 <link>
86                     <xsl:value-of select="$channel-link"/>
87                 </link>
88                 <description>
89                     <xsl:value-of select="normalize-space(//h1[@class='media-header'])"/>
90                 </description>
91                 <image>
92                     <title>
93                         <xsl:value-of select="$channel-title"/>
94                     </title>
95                     <link>
96                         <xsl:value-of select="$channel-link"/>
97                     </link>
98                     <url>
99                         <xsl:value-of select="//div[@id='profile-block']/span/img[contains(@class, 'img-rounded media-object')]/@src"/>
100                     </url>
101                 </image>
102                 <xsl:apply-templates select="//div[@id='user-content-activities']//ul[@id='major-stream']/li"/>
103             </channel>
104         </rss>
105     </xsl:template>
106 </xsl:stylesheet>