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
Showing only changes of commit 1e13884a12 - Show all commits

nitter/nitter.php aktualisiert

loma-one 2024-01-23 08:15:24 +01:00

View file

@ -1,7 +1,7 @@
<?php
/*
* Name: nitter
* Description: Replaces links to twitter.com an "x.com" to a nitter server in all displays of postings on a node.
* 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>
*
@ -55,23 +55,23 @@ function nitter_addon_admin(string &$o)
}
/*
* replace "twitter.com" an "x.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/')) {

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']);
if (strstr($b['html'], 'https://x.com/')) {
$b['html'] = str_replace('https://x.com/', $nitter, $b['html']);
$replaced = true;
}
if ($replaced) {