From 8f00d77403980577c59aedd4c350685ffda80667 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Fri, 16 Nov 2018 11:50:12 +0100 Subject: [PATCH 1/1] Add option to enable or disable showing multimedia content in RSS items Tweeper by default shows multimedia contents like Twitter and Instagram images in items descriptions. However sometimes just having multimedia contents in the element may be enough, so make it optional to also have the content in the item description. Keep the current default behavior for backwards compatibility. --- src/Tweeper.php | 8 +++++++- src/rss_converter_dilbert.com.xsl | 5 ++++- src/rss_converter_instagram.com.xsl | 5 ++++- src/rss_converter_twitter.com.xsl | 23 ++++++++++++++--------- tweeper.1.asciidoc | 4 ++++ tweeper.php | 24 ++++++++++++++++++++---- 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/Tweeper.php b/src/Tweeper.php index b75409b..8fda9b1 100644 --- a/src/Tweeper.php +++ b/src/Tweeper.php @@ -49,10 +49,15 @@ class Tweeper { * Enables showing the username in front of the content for multi-user * sites (enabled by default). Only some stylesheets supports this * functionality (twitter, instagram, pump.io). + * @param bool $show_multimedia + * Enables showing multimedia content (images, videos) directly in the + * item description (enabled by default). Only some stylesheets supports + * this functionality (twitter, instagram, dilbert). */ - public function __construct($generate_enclosure = FALSE, $show_usernames = TRUE) { + public function __construct($generate_enclosure = FALSE, $show_usernames = TRUE, $show_multimedia = TRUE) { $this->generate_enclosure = $generate_enclosure; $this->show_usernames = $show_usernames; + $this->show_multimedia = $show_multimedia; } /** @@ -362,6 +367,7 @@ class Tweeper { $xsltProcessor->registerPHPFunctions(); $xsltProcessor->setParameter('', 'generate-enclosure', $this->generate_enclosure); $xsltProcessor->setParameter('', 'show-usernames', $this->show_usernames); + $xsltProcessor->setParameter('', 'show-multimedia', $this->show_multimedia); $xsltProcessor->importStylesheet($xslDoc); return $xsltProcessor; diff --git a/src/rss_converter_dilbert.com.xsl b/src/rss_converter_dilbert.com.xsl index 99d2b27..fd30d35 100644 --- a/src/rss_converter_dilbert.com.xsl +++ b/src/rss_converter_dilbert.com.xsl @@ -37,6 +37,7 @@ exclude-result-prefixes="php"> + @@ -72,7 +73,9 @@ <![CDATA[ - {$picture-title} + + {$picture-title} + ]]> diff --git a/src/rss_converter_instagram.com.xsl b/src/rss_converter_instagram.com.xsl index 01bd3d1..855ce0b 100644 --- a/src/rss_converter_instagram.com.xsl +++ b/src/rss_converter_instagram.com.xsl @@ -25,6 +25,7 @@ + @@ -106,7 +107,9 @@


- + + + ]]> diff --git a/src/rss_converter_twitter.com.xsl b/src/rss_converter_twitter.com.xsl index b59a97b..1c20e70 100644 --- a/src/rss_converter_twitter.com.xsl +++ b/src/rss_converter_twitter.com.xsl @@ -25,6 +25,7 @@ + @@ -72,15 +73,17 @@ too instead of the t.co redirections. --> - - - - + + + + + + + - - - - + + + @@ -173,7 +176,9 @@ white-space: pre-wrap; - + + + ]]> diff --git a/tweeper.1.asciidoc b/tweeper.1.asciidoc index 8519d3a..37e885a 100644 --- a/tweeper.1.asciidoc +++ b/tweeper.1.asciidoc @@ -45,6 +45,10 @@ OPTIONS *-e*:: show links to supported media files in the RSS element +*-m <0|1>*:: + enable or disable showing multimedia content (e.g. Twitter or Instagram + pictures) directly inside the item description. Default is 1 (enable). + *-u <0|1>*:: enable or disable showing usernames in front of the item for hosts which supports it (Twitter.com/Instagram.com). Default is 1 (enable). diff --git a/tweeper.php b/tweeper.php index 84712f6..2d5017e 100644 --- a/tweeper.php +++ b/tweeper.php @@ -38,10 +38,10 @@ function is_cli() { */ function usage($argv) { if (is_cli()) { - $usage = "{$argv[0]} [-e|-u <0|1>|-h|--help] \n"; + $usage = "{$argv[0]} [-e|-m <0|1>|-u <0|1>|-h|--help] \n"; } else { - $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=&generate_enclosure=<0|1>&show_usernames=<0|1>"); + $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=&generate_enclosure=<0|1>&show_usernames=<0|1>&show_multimedia=<0|1>"); } return "usage: $usage"; @@ -54,19 +54,30 @@ function parse_options_cli($argv, $argc) { $options = array( 'generate_enclosure' => FALSE, 'show_usernames' => TRUE, + 'show_multimedia' => TRUE, ); if ($argc < 2) { return $options; } - $cli_options = getopt("eu:h", array("help")); + $cli_options = getopt("em:u:h", array("help")); foreach ($cli_options as $opt => $val) { switch ($opt) { case 'e': $options['generate_enclosure'] = TRUE; break; + case 'm': + $ret = filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + if (NULL === $ret) { + fwrite(STDERR, "Invalid argument for the -m option.\n"); + fwrite(STDERR, usage($argv)); + exit(1); + } + $options['show_multimedia'] = $val; + break; + case 'u': $ret = filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); if (NULL === $ret) { @@ -102,6 +113,7 @@ function parse_options_query_string() { $options = array( 'generate_enclosure' => FALSE, 'show_usernames' => TRUE, + 'show_multimedia' => TRUE, ); if (isset($_GET['src_url'])) { @@ -112,6 +124,10 @@ function parse_options_query_string() { $options['generate_enclosure'] = $_GET['generate_enclosure'] == 1; } + if (isset($_GET['show_multimedia'])) { + $options['show_multimedia'] = $_GET['show_multimedia'] != 0; + } + if (isset($_GET['show_usernames'])) { $options['show_usernames'] = $_GET['show_usernames'] != 0; } @@ -133,7 +149,7 @@ if (!isset($options['src_url'])) { exit(1); } -$tweeper = new Tweeper($options['generate_enclosure'], $options['show_usernames']); +$tweeper = new Tweeper($options['generate_enclosure'], $options['show_usernames'], $options['show_multimedia']); $output = $tweeper->tweep($options['src_url']); if (is_null($output)) { exit(1); -- 2.1.4