Merge tag 'v0.5' into debian
authorAntonio Ospite <ao2@ao2.it>
Fri, 13 May 2016 16:19:01 +0000 (18:19 +0200)
committerAntonio Ospite <ao2@ao2.it>
Fri, 13 May 2016 16:19:01 +0000 (18:19 +0200)
Release v0.5

INSTALL
NEWS
rss_converter_instagram.com.xsl
rss_converter_twitter.com.xsl
tweeper.php

diff --git a/INSTALL b/INSTALL
index d575bb1..bb71797 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -2,5 +2,6 @@ The recommended way to install tweeper globally is to install all its files
 under /usr/share/php/tweeper and then make a symlink to the wrapper script
 "tweeper" under /usr/bin
 
-Tweeper depends on php-xml-serializer which is used to convert json to xml for
-some sites that provide the timeline data in json rather than in usable html.
+Tweeper depends on php-symfony-serializer which is used to convert json to xml
+for some sites which provide the timeline data in json rather than in usable
+html.
diff --git a/NEWS b/NEWS
index d50eb50..0a4af4a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+News for v0.5:
+==============
+
+  * Use the Symfony Serializer component instead of the PEAR XML_Serializer
+  * Make the Twitter stylesheet stricter to avoid empty timeline entries
+
 News for v0.4:
 ==============
 
index 5f1bb7f..aaab2e8 100644 (file)
         <xsl:value-of disable-output-escaping="yes" select="php:function('Tweeper::generate_enclosure', string(text()))"/>
     </xsl:template>
 
-    <xsl:variable name="user-name" select="//ProfilePage/XML_Serializer_Tag/user/username"/>
+    <xsl:variable name="user-name" select="//ProfilePage/user/username"/>
 
     <!-- Some users do not specify the full name -->
-    <xsl:variable name="full-name" select="//ProfilePage/XML_Serializer_Tag/user/full_name"/>
+    <xsl:variable name="full-name" select="//ProfilePage/user/full_name"/>
     <xsl:variable name="screen-name">
         <xsl:choose>
             <xsl:when test="$full-name != ''">
@@ -51,7 +51,7 @@
         </xsl:choose>
     </xsl:variable>
 
-    <xsl:template match="//media/nodes/XML_Serializer_Tag">
+    <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, '/')"/>
                         <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>
index 9185a54..15507f0 100644 (file)
@@ -38,7 +38,7 @@
 
     <xsl:variable name="screen-name" select="//div[@class='user-actions btn-group not-following ']/@data-screen-name"/>
 
-    <xsl:template match="//li[@data-item-type='tweet']">
+    <xsl:template match="//li[@data-item-id and @data-item-type='tweet']">
         <xsl:variable name="user-name" select=".//div[contains(@class, 'js-stream-tweet')]/@data-screen-name"/>
         <xsl:variable name="item-content" select=".//p[contains(@class, 'js-tweet-text')]"/>
         <xsl:variable name="item-permalink" select="concat($BaseURL, .//div[@data-permalink-path]/@data-permalink-path)"/>
     </xsl:template>
 
     <xsl:template match="/">
-        <xsl:variable name="channel-title" select="concat('Twitter / ', $screen-name)"/>
+        <xsl:variable name="channel-title">
+            <xsl:choose>
+                <xsl:when test="$screen-name != ''">
+                    <xsl:value-of select="concat('Twitter / ', $screen-name)"/>
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="concat('Twitter / ', normalize-space(//h1[1]))"/>
+                </xsl:otherwise>
+            </xsl:choose>
+        </xsl:variable>
         <xsl:variable name="channel-link" select="//link[@rel='canonical']/@href"/>
 
         <rss version="2.0">
                         <xsl:value-of select="//a[contains(@class, 'profile-picture media-thumbnail')]/@href"/>
                     </url>
                 </image>
-                <xsl:apply-templates select="//li[@data-item-type='tweet']"/>
+                <xsl:apply-templates select="//ol[@id='stream-items-id']/li[@data-item-id and @data-item-type='tweet']"/>
             </channel>
         </rss>
     </xsl:template>
index a9fce9b..bed6350 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-require_once 'XML/Serializer.php';
+require_once 'Symfony/Component/Serializer/autoload.php';
+
+use Symfony\Component\Serializer\Serializer;
+use Symfony\Component\Serializer\Encoder\XmlEncoder;
+use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
 
 date_default_timezone_set('UTC');
 
@@ -186,27 +190,31 @@ class Tweeper {
       return NULL;
     }
 
-    $data = json_decode($matches[1]);
+    // Apparenty the ObjectNormalizer used afterwards is not able to handle
+    // the stdClass object created by json_decode() with the default setting
+    // $assoc = false; so use $assoc = true 
+    $data = json_decode($matches[1], $assoc = true);
     if (!$data) {
       return NULL;
     }
 
+    $encoder = new XmlEncoder();
+    $normalizer = new ObjectNormalizer();
+    $serializer = new Serializer(array($normalizer), array($encoder));
+
     $serializer_options = array (
-      'addDecl' => TRUE,
-      'encoding' => "UTF-8",
-      'indent' => '  ',
-      'rootName' => $rootName,
+      'xml_encoding' => "UTF-8",
+      'xml_format_output' => TRUE,
+      'xml_root_node_name' => $rootName,
     );
 
-    $serializer = new XML_Serializer($serializer_options);
-
-    $status = $serializer->serialize($data);
-    if (PEAR::isError($status)) {
-      trigger_error($status->getMessage(), E_USER_ERROR);
+    $xml_data = $serializer->serialize($data, 'xml', $serializer_options);
+    if (!$xml_data) {
+      trigger_error("Cannot serialize data", E_USER_ERROR);
       return NULL;
     }
 
-    return $serializer->getSerializedData();
+    return $xml_data;
   }
 
   private function get_xml_instagram_com($html) {