Merge pull request #1159 from tobiasd/20210818-nitter

nitter: mobile links and config enhancements
This commit is contained in:
Hypolite Petovan 2021-08-19 04:34:52 -04:00 committed by GitHub
commit 083c13b031
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,7 +37,7 @@ function nitter_install()
*/ */
function nitter_addon_admin_post(App $a) function nitter_addon_admin_post(App $a)
{ {
$nitterserver = trim($_POST['nitterserver']); $nitterserver = rtrim(trim($_POST['nitterserver']),'/');
DI::config()->set('nitter', 'server', $nitterserver); DI::config()->set('nitter', 'server', $nitterserver);
} }
@ -61,9 +61,17 @@ function nitter_addon_admin(App $a, &$o)
function nitter_render(&$a, &$o) function nitter_render(&$a, &$o)
{ {
// this needs to be a system setting // this needs to be a system setting
$replaced = false;
$nitter = DI::config()->get('nitter', 'server', 'https://nitter.net'); $nitter = DI::config()->get('nitter', 'server', 'https://nitter.net');
if (strstr($o['html'], 'https://mobile.twitter.com')) {
$o['html'] = str_replace('https://mobile.twitter.com', $nitter, $o['html']);
$replace = true;
}
if (strstr($o['html'], 'https://twitter.com')) { if (strstr($o['html'], 'https://twitter.com')) {
$o['html'] = str_replace('https://twitter.com', $nitter, $o['html']); $o['html'] = str_replace('https://twitter.com', $nitter, $o['html']);
$replace = true;
}
if ($replace) {
$o['html'] .= '<hr><p>' . DI::l10n()->t('Links to Twitter in this posting were replaced by links to the Nitter instance at %s', $nitter) . '</p>'; $o['html'] .= '<hr><p>' . DI::l10n()->t('Links to Twitter in this posting were replaced by links to the Nitter instance at %s', $nitter) . '</p>';
} }
} }