Tweeper shows usernames by default in items created from multi-user
sites like Twitter or Instagram.
This is because the main use case is to aggregate multiple feeds in the
same viewer, and in this scenario having some info about where the
messages is coming from can be useful.
However sometimes tweeper can be used to track one single feed and in
this case having always the same username repeated over and over is
unnecessary.
Make showing the username optional, but keep the current behavior as
default.
NOTE: for Twitter keep always showing the username in case of retweets
($screen-name != $user-name).
private static $userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Firefox/60.0";
/**
private static $userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Firefox/60.0";
/**
- * Constructor sets up {@link $generate_enclosure}.
+ * Create a new Tweeper object controlling optional settings.
+ *
+ * @param bool $generate_enclosure
+ * Enables the creation of <enclosure/> elements (disabled by default).
+ * @param bool $show_usernames
+ * 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).
- public function __construct($generate_enclosure = FALSE) {
+ public function __construct($generate_enclosure = FALSE, $show_usernames = TRUE) {
$this->generate_enclosure = $generate_enclosure;
$this->generate_enclosure = $generate_enclosure;
+ $this->show_usernames = $show_usernames;
$xsltProcessor = new XSLTProcessor();
$xsltProcessor->registerPHPFunctions();
$xsltProcessor->setParameter('', 'generate-enclosure', $this->generate_enclosure);
$xsltProcessor = new XSLTProcessor();
$xsltProcessor->registerPHPFunctions();
$xsltProcessor->setParameter('', 'generate-enclosure', $this->generate_enclosure);
+ $xsltProcessor->setParameter('', 'show-usernames', $this->show_usernames);
$xsltProcessor->importStylesheet($xslDoc);
return $xsltProcessor;
$xsltProcessor->importStylesheet($xslDoc);
return $xsltProcessor;
exclude-result-prefixes="php">
<xsl:param name="generate-enclosure"/>
exclude-result-prefixes="php">
<xsl:param name="generate-enclosure"/>
+ <xsl:param name="show-usernames"/>
<xsl:output method="xml" indent="yes"/>
<xsl:output method="xml" indent="yes"/>
<item>
<title>
<xsl:variable name="title-length" select="140"/>
<item>
<title>
<xsl:variable name="title-length" select="140"/>
- <xsl:variable name="item-content-title" select="normalize-space(concat($screen-name, ': ', $item-content-caption))"/>
+ <xsl:variable name="item-content-title">
+ <xsl:if test="$show-usernames = 1">
+ <xsl:value-of select="concat($screen-name, ': ')"/>
+ </xsl:if>
+ <xsl:value-of select="normalize-space($item-content-caption)"/>
+ </xsl:variable>
<!-- ellipsize, inspired from http://stackoverflow.com/questions/13622338 -->
<xsl:choose>
<xsl:when test="string-length($item-content-title) > $title-length">
<!-- ellipsize, inspired from http://stackoverflow.com/questions/13622338 -->
<xsl:choose>
<xsl:when test="string-length($item-content-title) > $title-length">
exclude-result-prefixes="php">
<xsl:param name="generate-enclosure"/>
exclude-result-prefixes="php">
<xsl:param name="generate-enclosure"/>
+ <xsl:param name="show-usernames"/>
<xsl:output method="xml" indent="yes"/>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="item-permalink" select=".//p[@class='muted']/small/a/@href"/>
<item>
<title>
<xsl:variable name="item-permalink" select=".//p[@class='muted']/small/a/@href"/>
<item>
<title>
- <xsl:value-of select="concat($user-name, ': ', normalize-space($item-content))"/>
+ <xsl:if test="$show-usernames = 1">
+ <xsl:value-of select="concat($user-name, ': ')"/>
+ </xsl:if>
+ <xsl:value-of select="normalize-space($item-content)"/>
</title>
<link>
<xsl:value-of select="$item-permalink"/>
</title>
<link>
<xsl:value-of select="$item-permalink"/>
<xsl:value-of select="php:functionString('Tweeper\Tweeper::strToRssDate', .//abbr[@class='easydate']/@title)"/>
</pubDate>
<description>
<xsl:value-of select="php:functionString('Tweeper\Tweeper::strToRssDate', .//abbr[@class='easydate']/@title)"/>
</pubDate>
<description>
- <xsl:value-of select="concat($user-name, ': ')"/>
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
+ <xsl:if test="$show-usernames = 1">
+ <xsl:value-of select="concat($user-name, ': ')"/>
+ </xsl:if>
<xsl:copy-of select="$item-content/node()"/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</description>
<xsl:copy-of select="$item-content/node()"/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</description>
exclude-result-prefixes="php">
<xsl:param name="generate-enclosure"/>
exclude-result-prefixes="php">
<xsl:param name="generate-enclosure"/>
+ <xsl:param name="show-usernames"/>
<xsl:output method="xml" indent="yes"/>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="item-has-gif" select="$item-media//*[contains(@class, 'PlayableMedia--gif')]"/>
<item>
<title>
<xsl:variable name="item-has-gif" select="$item-media//*[contains(@class, 'PlayableMedia--gif')]"/>
<item>
<title>
- <xsl:value-of select="concat($user-name, ': ')"/>
+ <xsl:if test="($show-usernames = 1) or ($screen-name != $user-name)">
+ <xsl:value-of select="concat($user-name, ': ')"/>
+ </xsl:if>
<xsl:if test="$item-has-video">
<xsl:text>(Video) </xsl:text>
</xsl:if>
<xsl:if test="$item-has-video">
<xsl:text>(Video) </xsl:text>
</xsl:if>
</pubDate>
<description>
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
</pubDate>
<description>
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
- <xsl:value-of select="concat($user-name, ':')"/>
- <xsl:element name="br"/>
+ <xsl:if test="($show-usernames = 1) or ($screen-name != $user-name)">
+ <xsl:value-of select="concat($user-name, ':')"/>
+ <xsl:element name="br"/>
+ </xsl:if>
<xsl:if test="$item-has-video">
<xsl:text> (Video)</xsl:text>
<xsl:element name="br"/>
<xsl:if test="$item-has-video">
<xsl:text> (Video)</xsl:text>
<xsl:element name="br"/>
*-e*::
show links to supported media files in the RSS <enclosure/> element
*-e*::
show links to supported media files in the RSS <enclosure/> element
+*-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).
+
*-h, --help*::
show the help message
*-h, --help*::
show the help message
*/
function usage($argv) {
if (is_cli()) {
*/
function usage($argv) {
if (is_cli()) {
- $usage = "{$argv[0]} [-e|-h|--help] <src_url>\n";
+ $usage = "{$argv[0]} [-e|-u <0|1>|-h|--help] <src_url>\n";
- $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=<src_url>&generate_enclosure=<0|1>");
+ $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=<src_url>&generate_enclosure=<0|1>&show_usernames=<0|1>");
}
return "usage: $usage";
}
return "usage: $usage";
function parse_options_cli($argv, $argc) {
$options = array(
'generate_enclosure' => FALSE,
function parse_options_cli($argv, $argc) {
$options = array(
'generate_enclosure' => FALSE,
+ 'show_usernames' => TRUE,
);
if ($argc < 2) {
return $options;
}
);
if ($argc < 2) {
return $options;
}
- $cli_options = getopt("eh", array("help"));
+ $cli_options = getopt("eu:h", array("help"));
foreach ($cli_options as $opt => $val) {
switch ($opt) {
case 'e':
$options['generate_enclosure'] = TRUE;
break;
foreach ($cli_options as $opt => $val) {
switch ($opt) {
case 'e':
$options['generate_enclosure'] = TRUE;
break;
+ case 'u':
+ $ret = filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
+ if (NULL === $ret) {
+ fwrite(STDERR, "Invalid argument for the -u option.\n");
+ fwrite(STDERR, usage($argv));
+ exit(1);
+ }
+ $options['show_usernames'] = $val;
+ break;
+
case 'h':
case 'help':
echo usage($argv);
case 'h':
case 'help':
echo usage($argv);
- $options['src_url'] = $argv[count($cli_options) + 1];
+ // For now assume that the URL is the lest argument, in the future we could
+ // switch to PHP >= 7.1 and use the $optind argument of getopt().
+ $options['src_url'] = array_pop($argv);
function parse_options_query_string() {
$options = array(
'generate_enclosure' => FALSE,
function parse_options_query_string() {
$options = array(
'generate_enclosure' => FALSE,
+ 'show_usernames' => TRUE,
);
if (isset($_GET['src_url'])) {
);
if (isset($_GET['src_url'])) {
$options['generate_enclosure'] = $_GET['generate_enclosure'] == 1;
}
$options['generate_enclosure'] = $_GET['generate_enclosure'] == 1;
}
+ if (isset($_GET['show_usernames'])) {
+ $options['show_usernames'] = $_GET['show_usernames'] != 0;
+ }
+
-$tweeper = new Tweeper($options['generate_enclosure']);
+$tweeper = new Tweeper($options['generate_enclosure'], $options['show_usernames']);
$output = $tweeper->tweep($options['src_url']);
if (is_null($output)) {
exit(1);
$output = $tweeper->tweep($options['src_url']);
if (is_null($output)) {
exit(1);