Replaces links to twitter.com an "x.com" to a nitter server #1461

Closed
loma-one wants to merge 3 commits from (deleted):develop into develop
2 changed files with 13 additions and 7 deletions

View file

@ -21,6 +21,8 @@ Excerp from nitters about page.
Changelog
---------
* **Version 2.1**
* Extended by the domain x.com
* **Version 2.0**
* Changes the used hook by the addon, so that attached previews of postings get replaced as well.
This means the admins need to reload the addon

View file

@ -1,8 +1,8 @@
<?php
/*
* Name: nitter
* Description: Replaces links to twitter.com to a nitter server in all displays of postings on a node.
* Version: 2.0
* Description: Replaces links to twitter.com and "x.com" to a nitter server in all displays of postings on a node.
* Version: 2.1
* Author: Tobias Diekershoff <tobias@social.diekershoff.de>
*
* Copyright (c) 2020 Tobias Diekershoff
@ -55,19 +55,23 @@ function nitter_addon_admin(string &$o)
}
/*
* replace "twitter.com" with "nitter.net"
* replace "twitter.com" and "x.com" with "nitter.net"
*/
function nitter_render(array &$b)
{
// this needs to be a system setting
$replaced = false;
$nitter = DI::config()->get('nitter', 'server', 'https://nitter.net');
if (strstr($b['html'], 'https://mobile.twitter.com')) {
$b['html'] = str_replace('https://mobile.twitter.com', $nitter, $b['html']);
if (strstr($b['html'], 'https://mobile.twitter.com/')) {
Review

It seems as if the nitter server url is stored without a trailing /. So replacing the url including a trailing / with the nitter url without a trailing / will not work.

It seems as if the nitter server url is stored without a trailing `/`. So replacing the url including a trailing `/` with the nitter url without a trailing `/` will not work.
$b['html'] = str_replace('https://mobile.twitter.com/', $nitter, $b['html']);
$replaced = true;
}
if (strstr($b['html'], 'https://twitter.com')) {
$b['html'] = str_replace('https://twitter.com', $nitter, $b['html']);
if (strstr($b['html'], 'https://twitter.com/')) {
$b['html'] = str_replace('https://twitter.com/', $nitter, $b['html']);
$replaced = true;
}
if (strstr($b['html'], 'https://x.com/')) {
$b['html'] = str_replace('https://x.com/', $nitter, $b['html']);
$replaced = true;
}
if ($replaced) {