From ef4f6c6fb10b121fa79a0d8b6ccd7930fec48591 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Sat, 27 Jul 2013 13:24:44 +0200 Subject: [PATCH 1/1] Make stylesheet file name parametric The host is encoded in the file name, this is in order to support more sites with no changes to the code, all that is needed is just new stylesheets with the host in their filename following the scheme will: rss_converter_HOST.xsl Where HOST has the meaning of the "host" field in the return value of the PHP parse_url() function. --- rss_converter_twitter.com.xsl | 79 +++++++++++++++++++++++++++++++++++++++++++ tweeper.php | 9 ++--- twitter_user_timeline2rss.xsl | 79 ------------------------------------------- 3 files changed, 81 insertions(+), 86 deletions(-) create mode 100644 rss_converter_twitter.com.xsl delete mode 100644 twitter_user_timeline2rss.xsl diff --git a/rss_converter_twitter.com.xsl b/rss_converter_twitter.com.xsl new file mode 100644 index 0000000..6d72ceb --- /dev/null +++ b/rss_converter_twitter.com.xsl @@ -0,0 +1,79 @@ + + + + + + + https://twitter.com + + + + + + + + + <xsl:value-of select="concat($screen-name, ': ')"/> + <xsl:value-of select="$tweet-text"/> + + + + + + + + + + <![CDATA[ + + ]]> + + + + + + + + + Tweeper + + <xsl:text>Twitter / </xsl:text><xsl:value-of select="$screen-name"/> + + + + + + + + + + + + + + + + + diff --git a/tweeper.php b/tweeper.php index a275a64..4050100 100755 --- a/tweeper.php +++ b/tweeper.php @@ -95,14 +95,9 @@ $url = parse_url($src_url); if (FALSE === $url || empty($url["host"])) die("Invalid url\n"); -$stylesheets = array( - "twitter.com" => "twitter_user_timeline2rss.xsl", -); - -if (FALSE === array_key_exists($url["host"], $stylesheets)) +$stylesheet = "rss_converter_" . $url["host"] . ".xsl"; +if (FALSE === file_exists($stylesheet)) die("Unsupported host\n"); -$stylesheet = $stylesheets[$url["host"]]; - $tweeper = new Tweeper($stylesheet); echo $tweeper->tweep($src_url); diff --git a/twitter_user_timeline2rss.xsl b/twitter_user_timeline2rss.xsl deleted file mode 100644 index 6d72ceb..0000000 --- a/twitter_user_timeline2rss.xsl +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - https://twitter.com - - - - - - - - - <xsl:value-of select="concat($screen-name, ': ')"/> - <xsl:value-of select="$tweet-text"/> - - - - - - - - - - <![CDATA[ - - ]]> - - - - - - - - - Tweeper - - <xsl:text>Twitter / </xsl:text><xsl:value-of select="$screen-name"/> - - - - - - - - - - - - - - - - - -- 2.1.4