mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-09 16:38:50 +00:00
[TwitterBridge] Filter out any promoted tweet (#3652)
* Filter out any advertise tweet * Make some filter work, fix bug that may happen with tweet id list. * clear phpcs warning, ignore line length warning
This commit is contained in:
parent
52b90e0873
commit
dbe37cc302
@ -217,7 +217,7 @@ EOD
|
|||||||
private function getFullText($id)
|
private function getFullText($id)
|
||||||
{
|
{
|
||||||
$url = sprintf(
|
$url = sprintf(
|
||||||
'https://cdn.syndication.twimg.com/tweet-result?id=%s&lang=en',
|
'https://cdn.syndication.twimg.com/tweet-result?id=%s&lang=en&token=449yf2pc4g',
|
||||||
$id
|
$id
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -306,55 +306,67 @@ EOD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array of Tweet IDs
|
|
||||||
$tweetIds = [];
|
|
||||||
// Filter out unwanted tweets
|
|
||||||
foreach ($data->tweets as $tweet) {
|
|
||||||
if (isset($tweet->rest_id)) {
|
|
||||||
$tweetIds[] = $tweet->rest_id;
|
|
||||||
$tweet = $tweet->legacy;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$tweet) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Filter out retweets to remove possible duplicates of original tweet
|
|
||||||
switch ($this->queriedContext) {
|
|
||||||
case 'By keyword or hashtag':
|
|
||||||
if ((isset($tweet->retweeted_status) || isset($tweet->retweeted_status_result)) && substr($tweet->full_text, 0, 4) === 'RT @') {
|
|
||||||
continue 2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$tweets[] = $tweet;
|
|
||||||
}
|
|
||||||
|
|
||||||
$hidePictures = $this->getInput('nopic');
|
$hidePictures = $this->getInput('nopic');
|
||||||
|
|
||||||
$hidePinned = $this->getInput('nopinned');
|
$hidePinned = $this->getInput('nopinned');
|
||||||
if ($hidePinned) {
|
if ($hidePinned) {
|
||||||
$pinnedTweetId = null;
|
$pinnedTweetId = null;
|
||||||
if ($user && $user->pinned_tweet_ids_str) {
|
if ($data->user_info && $data->user_info->legacy->pinned_tweet_ids_str) {
|
||||||
$pinnedTweetId = $user->pinned_tweet_ids_str;
|
$pinnedTweetId = $data->user_info->legacy->pinned_tweet_ids_str[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Array of Tweet IDs
|
||||||
|
$tweetIds = [];
|
||||||
|
// Filter out unwanted tweets
|
||||||
|
foreach ($data->tweets as $tweet) {
|
||||||
|
if (!$tweet) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($tweet->legacy)) {
|
||||||
|
$legacy_info = $tweet->legacy;
|
||||||
|
} else {
|
||||||
|
$legacy_info = $tweet;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter out retweets to remove possible duplicates of original tweet
|
||||||
|
switch ($this->queriedContext) {
|
||||||
|
case 'By keyword or hashtag':
|
||||||
|
// phpcs:ignore
|
||||||
|
if ((isset($legacy_info->retweeted_status) || isset($legacy_info->retweeted_status_result)) && substr($legacy_info->full_text, 0, 4) === 'RT @') {
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip own Retweets...
|
||||||
|
if (isset($legacy_info->retweeted_status) && $legacy_info->retweeted_status->user->id_str === $tweet->user->id_str) {
|
||||||
|
continue;
|
||||||
|
// phpcs:ignore
|
||||||
|
} elseif (isset($legacy_info->retweeted_status_result) && $tweet->retweeted_status_result->result->legacy->user_id_str === $legacy_info->user_id_str) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tweetId = (isset($legacy_info->id_str) ? $legacy_info->id_str : $tweet->rest_id);
|
||||||
|
// Skip pinned tweet
|
||||||
|
if ($hidePinned && ($tweetId === $pinnedTweetId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($tweet->rest_id)) {
|
||||||
|
$tweetIds[] = $tweetId;
|
||||||
|
}
|
||||||
|
$rtweet = $legacy_info;
|
||||||
|
$tweets[] = $rtweet;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->queriedContext === 'By username') {
|
if ($this->queriedContext === 'By username') {
|
||||||
$this->feedIconUrl = $data->user_info->legacy->profile_image_url_https ?? null;
|
$this->feedIconUrl = $data->user_info->legacy->profile_image_url_https ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($tweets as $tweet) {
|
foreach ($tweets as $tweet) {
|
||||||
// Skip own Retweets...
|
|
||||||
if (isset($tweet->retweeted_status) && $tweet->retweeted_status->user->id_str === $tweet->user->id_str) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip pinned tweet
|
|
||||||
if ($hidePinned && $tweet->id_str === $pinnedTweetId) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$item = [];
|
$item = [];
|
||||||
|
|
||||||
$realtweet = $tweet;
|
$realtweet = $tweet;
|
||||||
|
@ -146,9 +146,14 @@ class TwitterClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($timeline->data->user)) {
|
if (isset($timeline->data->user)) {
|
||||||
if (!isset($entry->content->itemContent->tweet_results->result->legacy)) {
|
if (!isset($entry->content->itemContent->tweet_results->result)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($entry->content->itemContent->promotedMetadata)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$tweets[] = $entry->content->itemContent->tweet_results->result;
|
$tweets[] = $entry->content->itemContent->tweet_results->result;
|
||||||
|
|
||||||
$userIds[] = $entry->content->itemContent->tweet_results->result->core->user_results->result;
|
$userIds[] = $entry->content->itemContent->tweet_results->result->core->user_results->result;
|
||||||
@ -156,6 +161,12 @@ class TwitterClient
|
|||||||
if (!isset($entry->content->content->tweetResult->result->legacy)) {
|
if (!isset($entry->content->content->tweetResult->result->legacy)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter out any advertise tweet
|
||||||
|
if (isset($entry->content->content->tweetPromotedMetadata)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$tweets[] = $entry->content->content->tweetResult->result;
|
$tweets[] = $entry->content->content->tweetResult->result;
|
||||||
|
|
||||||
$userIds[] = $entry->content->content->tweetResult->result->core->user_result->result;
|
$userIds[] = $entry->content->content->tweetResult->result->core->user_result->result;
|
||||||
|
Loading…
Reference in New Issue
Block a user