Return a DOMElement instead of a string in Tweeper::generateEnclosure()
[tweeper.git] / rss_converter_instagram.com.xsl
index 0e1de8d..f12ecbb 100644 (file)
@@ -24,7 +24,7 @@
     xsl:extension-element-prefixes="php"
     exclude-result-prefixes="php">
 
-    <xsl:param name="generateEnclosure"/>
+    <xsl:param name="generate-enclosure"/>
 
     <xsl:output method="xml" indent="yes"/>
 
         <xsl:text>https://instagram.com</xsl:text>
     </xsl:variable>
 
-    <xsl:template match="images">
-        <xsl:value-of disable-output-escaping="yes" select="php:function('Tweeper::generate_enclosure', string(./standard_resolution/url))"/>
+    <xsl:template match="display_src">
+        <xsl:copy-of select="php:function('Tweeper::generateEnclosure', string(text()))"/>
     </xsl:template>
 
-    <xsl:variable name="screen-name" select="//ProfilePage/XML_Serializer_Tag/user/full_name"/>
-    <xsl:variable name="user-name" select="//ProfilePage/XML_Serializer_Tag/user/username"/>
+    <xsl:variable name="user-name" select="//ProfilePage/user/username"/>
 
-    <xsl:template match="//media/nodes/XML_Serializer_Tag">
+    <!-- Some users do not specify the full name -->
+    <xsl:variable name="full-name" select="//ProfilePage/user/full_name"/>
+    <xsl:variable name="screen-name">
+        <xsl:choose>
+            <xsl:when test="$full-name != ''">
+                <xsl:value-of select="$full-name"/>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:value-of select="$user-name"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:variable>
+
+    <xsl:template match="//media/nodes">
         <xsl:variable name="item-content-image" select="./display_src"/>
         <xsl:variable name="item-content-caption" select="./caption"/>
         <xsl:variable name="item-permalink" select="concat($BaseURL, '/p/', ./code, '/')"/>
         <item>
             <title>
                 <xsl:variable name="title-length" select="140"/>
+                <xsl:variable name="item-content-title" select="normalize-space(concat($user-name, ': ', $item-content-caption))"/>
                 <!-- ellipsize, inspired from http://stackoverflow.com/questions/13622338 -->
                 <xsl:choose>
-                    <xsl:when test="string-length($item-content-caption) > $title-length">
+                    <xsl:when test="string-length($item-content-title) > $title-length">
                         <xsl:variable name="truncated-length" select="$title-length - 3"/>
-                        <xsl:value-of select="normalize-space(substring($item-content-caption, 1, $truncated-length))"/>
+                        <xsl:value-of select="substring($item-content-title, 1, $truncated-length)"/>
                         <xsl:text>...</xsl:text>
                     </xsl:when>
                     <xsl:otherwise>
-                        <xsl:value-of select="normalize-space($item-content-caption)"/>
+                        <xsl:value-of select="$item-content-title"/>
                     </xsl:otherwise>
                 </xsl:choose>
             </title>
             </guid>
             <pubDate>
                 <xsl:variable name="timestamp" select="./date"/>
-                <xsl:value-of select="php:functionString('Tweeper::epoch_to_gmdate', number($timestamp))"/>
+                <xsl:value-of select="php:functionString('Tweeper::epochToRssDate', number($timestamp))"/>
             </pubDate>
             <description>
                 <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
-                <p><xsl:value-of select="$item-content-caption"/></p><br />
+                <p>
+                    <xsl:if test="./is_video/text() = 1">
+                        (Video) 
+                    </xsl:if>
+                    <xsl:value-of select="$item-content-caption"/>
+                </p><br />
                 <a href="{$item-permalink}"><img src="{$item-content-image}" /></a>
                 <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
             </description>
-            <xsl:if test="$generateEnclosure = 1">
-                <xsl:apply-templates select="./images"/>
+            <xsl:if test="$generate-enclosure = 1">
+                <xsl:apply-templates select="./display_src"/>
             </xsl:if>
         </item>
     </xsl:template>
                     <xsl:value-of select="$channel-link"/>
                 </link>
                 <description>
-                    <xsl:value-of select="//user/biography"/>
+                    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
+                    <xsl:value-of select="normalize-space(concat($screen-name, '. ', //user/biography))"/>
+                    <xsl:variable name="external-url" select="//user/external_url"/>
+                    <xsl:if test="$external-url != ''">
+                        <xsl:text> </xsl:text><a href="{$external-url}"><xsl:value-of select="$external-url"/></a>
+                    </xsl:if>
+                    <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
                 </description>
                 <image>
                     <title>
                         <xsl:value-of select="//user/profile_pic_url"/>
                     </url>
                 </image>
-                <xsl:apply-templates select="//media/nodes/XML_Serializer_Tag"/>
+                <xsl:apply-templates select="//media/nodes"/>
             </channel>
         </rss>
     </xsl:template>