From 6eadc6ca6f19ce2b4ee4c434afa91ce6ce76ff7a Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 22 Apr 2017 15:36:25 +0200 Subject: [PATCH] [TwitterBridge] Show quotes and pictures This adds new features to show quotes and pictures in feeds. Quotes will show up on top of a tweet and are separated from the quoting feed by a horizontal line. Pictures that are embedded in the tweet will be captured and attached to the feed using enclosures. By default the picture will also be shown in the feed itself. This can be disabled using the option '&noimg=on' Some codes are now split into separate functions so they can be used for tweets and quotes alike. --- bridges/TwitterBridge.php | 128 ++++++++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 18 deletions(-) diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index 86dce7b1..316094d1 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -11,6 +11,11 @@ class TwitterBridge extends BridgeAbstract { 'name' => 'Hide profile pictures', 'type' => 'checkbox', 'title' => 'Activate to hide profile pictures in content' + ), + 'noimg' => array( + 'name' => 'Hide images in tweets', + 'type' => 'checkbox', + 'title' => 'Activate to hide images in tweets' ) ), 'By keyword or hashtag' => array( @@ -119,23 +124,8 @@ class TwitterBridge extends BridgeAbstract { ) ); - // processing content links - foreach($tweet->find('a') as $link){ - if($link->hasAttribute('data-expanded-url')){ - $link->href = $link->getAttribute('data-expanded-url'); - } - $link->removeAttribute('data-expanded-url'); - $link->removeAttribute('data-query-source'); - $link->removeAttribute('rel'); - $link->removeAttribute('class'); - $link->removeAttribute('target'); - $link->removeAttribute('title'); - } - - // process emojis (reduce size) - foreach($tweet->find('img.Emoji') as $img){ - $img->style .= ' height: 1em;'; - } + $this->processContentLinks($tweet); + $this->processEmojis($tweet); // get tweet text $cleanedTweet = str_replace( @@ -150,7 +140,7 @@ class TwitterBridge extends BridgeAbstract { $picture_html = << {$item['username']} @@ -158,6 +148,22 @@ class TwitterBridge extends BridgeAbstract { EOD; } + // Add embeded image to content + $image_html = ''; + $image = $this->getImageURI($tweet); + if(!$this->getInput('noimg') && !is_null($image)){ + // add enclosures + $item['enclosures'] = array($this->getImageURI($tweet)); + + $image_html = << + + +EOD; + } + // add content $item['content'] = << @@ -166,10 +172,96 @@ EOD;
{$cleanedTweet}
+
+
{$image_html}
+
EOD; + // add quoted tweet + $quotedTweet = $tweet->find('div.QuoteTweet', 0); + if($quotedTweet){ + // get tweet text + $cleanedQuotedTweet = str_replace( + 'href="/', + 'href="' . self::URI, + $quotedTweet->find('div.tweet-text', 0)->innertext + ); + + $this->processContentLinks($quotedTweet); + $this->processEmojis($quotedTweet); + + // Add embeded image to content + $quotedImage_html = ''; + $quotedImage = $this->getQuotedImageURI($tweet); + if(!$this->getInput('noimg') && !is_null($quotedImage)){ + // add enclosures + $item['enclosures'] = array($this->getQuotedImageURI($tweet)); + + $quotedImage_html = << + + +EOD; + } + + $item['content'] = << +
{$cleanedQuotedTweet}
+ +
+
{$quotedImage_html}
+
+
+{$item['content']} +EOD; + } + // put out $this->items[] = $item; } } + + private function processEmojis($tweet){ + // process emojis (reduce size) + foreach($tweet->find('img.Emoji') as $img){ + $img->style .= ' height: 1em;'; + } + } + + private function processContentLinks($tweet){ + // processing content links + foreach($tweet->find('a') as $link){ + if($link->hasAttribute('data-expanded-url')){ + $link->href = $link->getAttribute('data-expanded-url'); + } + $link->removeAttribute('data-expanded-url'); + $link->removeAttribute('data-query-source'); + $link->removeAttribute('rel'); + $link->removeAttribute('class'); + $link->removeAttribute('target'); + $link->removeAttribute('title'); + } + } + + private function getImageURI($tweet){ + // Find media in tweet + $container = $tweet->find('div.AdaptiveMedia-container', 0); + if($container && $container->find('img', 0)){ + return $container->find('img', 0)->src; + } + + return null; + } + + private function getQuotedImageURI($tweet){ + // Find media in tweet + $container = $tweet->find('div.QuoteMedia-container', 0); + if($container && $container->find('img', 0)){ + return $container->find('img', 0)->src; + } + + return null; + } }