Compare commits

...

8 commits

Author SHA1 Message Date
Dr. Tobias Quathamer d3ba63c559 Increment version 2024-03-13 22:57:16 +01:00
Dr. Tobias Quathamer 6d941dd0a8 Update message catalog 2024-03-13 22:56:58 +01:00
Dr. Tobias Quathamer a2b3691916 Remove now unnecessary variable 2024-03-13 22:56:06 +01:00
Dr. Tobias Quathamer 499167ec50 Reformat code, no content changes 2024-03-13 22:56:06 +01:00
Dr. Tobias Quathamer 4a98e20fb7 Enable individual replacement preferences 2024-03-13 22:41:15 +01:00
Dr. Tobias Quathamer 1a9dc5b2ad Update README 2024-03-13 17:09:19 +01:00
Dr. Tobias Quathamer ebfaeab289 Add proxigram for instagram redirection.
Based on an idea and patch from loma-one. Thanks!
2024-03-13 17:07:10 +01:00
Dr. Tobias Quathamer 94c59c4c4c Simplify providing a default empty array 2024-03-13 15:39:21 +01:00
4 changed files with 112 additions and 37 deletions

View file

@ -4,7 +4,8 @@ This addon will replace all occurrences of specified URLs with the address of
alternative servers in all displayed postings on a Friendica node.
You can use this to switch from Twitter (or X) to a nitter instance, from
YouTube to an invidious instance, or from some news sites to 12ft.io.
YouTube to an invidious instance, from Instagram to a proxigram instance,
or from some news sites to 12ft.io.
Note: If you are using the twitter connector on your server, the links to the
contacts profile pages will not be replaced by this addon. Only links in the

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-05 00:06+0100\n"
"POT-Creation-Date: 2024-03-13 22:56+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,34 +17,56 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: url_replace.php:54
#: url_replace.php:64
msgid "Replace links to X."
msgstr ""
#: url_replace.php:69
msgid "Nitter server"
msgstr ""
#: url_replace.php:56
#: url_replace.php:71
msgid "Specify the URL with protocol. The default is https://nitter.net."
msgstr ""
#: url_replace.php:62
#: url_replace.php:77
msgid "Replace links to YouTube."
msgstr ""
#: url_replace.php:82
msgid "Invidious server"
msgstr ""
#: url_replace.php:64
#: url_replace.php:84
msgid "Specify the URL with protocol. The default is https://yewtu.be."
msgstr ""
#: url_replace.php:70
#: url_replace.php:90
msgid "Replace links to Instagram."
msgstr ""
#: url_replace.php:95
msgid "Proxigram server"
msgstr ""
#: url_replace.php:97
msgid ""
"Specify the URL with protocol. The default is https://proxigram.lunar.icu."
msgstr ""
#: url_replace.php:103
msgid "Sites which are accessed through 12ft.io"
msgstr ""
#: url_replace.php:72
#: url_replace.php:105
msgid "Specify the URLs with protocol, one per line."
msgstr ""
#: url_replace.php:76
#: url_replace.php:109
msgid "Save settings"
msgstr ""
#: url_replace.php:125
msgid "(URL replace addon enabled for X, YouTube and some news sites.)"
#: url_replace.php:175
msgid ""
"(URL replace addon enabled for X, YouTube, Instagram and some news sites.)"
msgstr ""

View file

@ -1,5 +1,9 @@
{{include file="field_checkbox.tpl" field=$nitter_server_enabled}}
{{include file="field_input.tpl" field=$nitter_server}}
{{include file="field_checkbox.tpl" field=$invidious_server_enabled}}
{{include file="field_input.tpl" field=$invidious_server}}
{{include file="field_checkbox.tpl" field=$proxigram_server_enabled}}
{{include file="field_input.tpl" field=$proxigram_server}}
{{include file="field_textarea.tpl" field=$twelvefeet_sites}}
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>

View file

@ -2,7 +2,7 @@
/**
* Name: URL Replace
* Description: Replaces occurrences of specified URLs with the address of alternative servers in all displays of postings on a node.
* Version: 1.0
* Version: 1.1
* Author: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
* Maintainer: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
*/
@ -21,18 +21,22 @@ function url_replace_install()
*/
function url_replace_addon_admin_post()
{
DI::config()->set('url_replace', 'nitter_server_enabled', !empty($_POST['nitter_server_enabled']));
DI::config()->set('url_replace', 'nitter_server', rtrim(trim($_POST['nitter_server']), '/'));
DI::config()->set('url_replace', 'invidious_server_enabled', !empty($_POST['invidious_server_enabled']));
DI::config()->set('url_replace', 'invidious_server', rtrim(trim($_POST['invidious_server']), '/'));
DI::config()->set('url_replace', 'proxigram_server_enabled', !empty($_POST['proxigram_server_enabled']));
DI::config()->set('url_replace', 'proxigram_server', rtrim(trim($_POST['proxigram_server']), '/'));
// Convert twelvefeet_sites into an array before setting the new value
$twelvefeet_sites = explode(PHP_EOL, $_POST['twelvefeet_sites']);
// Normalize URLs by using lower case, removing a trailing slash and whitespace
$twelvefeet_sites = array_map(fn($value): string => rtrim(trim(strtolower($value)), '/'), $twelvefeet_sites);
$twelvefeet_sites = array_map(fn ($value): string => rtrim(trim(strtolower($value)), '/'), $twelvefeet_sites);
// Do not store empty lines or duplicates
$twelvefeet_sites = array_filter($twelvefeet_sites, fn($value): bool => !empty($value));
$twelvefeet_sites = array_filter($twelvefeet_sites, fn ($value): bool => !empty($value));
$twelvefeet_sites = array_unique($twelvefeet_sites);
// Ensure a protocol and default to HTTPS
$twelvefeet_sites = array_map(
fn($value): string => substr($value, 0, 4) !== 'http' ? 'https://' . $value : $value,
fn ($value): string => substr($value, 0, 4) !== 'http' ? 'https://' . $value : $value,
$twelvefeet_sites
);
asort($twelvefeet_sites);
@ -41,16 +45,25 @@ function url_replace_addon_admin_post()
/**
* Hook into admin settings to enable choosing a different server
* for twitter, youtube, and news sites.
* for twitter, youtube, instagram, and news sites.
*/
function url_replace_addon_admin(string &$o)
{
$nitter_server_enabled = DI::config()->get('url_replace', 'nitter_server_enabled', true);
$nitter_server = DI::config()->get('url_replace', 'nitter_server');
$invidious_server_enabled = DI::config()->get('url_replace', 'invidious_server_enabled', true);
$invidious_server = DI::config()->get('url_replace', 'invidious_server');
$twelvefeet_sites = implode(PHP_EOL, DI::config()->get('url_replace', 'twelvefeet_sites') ?? [] ?: []);
$proxigram_server_enabled = DI::config()->get('url_replace', 'proxigram_server_enabled', true);
$proxigram_server = DI::config()->get('url_replace', 'proxigram_server');
$twelvefeet_sites = implode(PHP_EOL, DI::config()->get('url_replace', 'twelvefeet_sites') ?? []);
$t = Renderer::getMarkupTemplate('admin.tpl', 'addon/url_replace/');
$o = Renderer::replaceMacros($t, [
'$nitter_server_enabled' => [
'nitter_server_enabled',
DI::l10n()->t('Replace links to X.'),
$nitter_server_enabled,
],
'$nitter_server' => [
'nitter_server',
DI::l10n()->t('Nitter server'),
@ -59,6 +72,11 @@ function url_replace_addon_admin(string &$o)
null,
'placeholder="https://nitter.net"',
],
'$invidious_server_enabled' => [
'invidious_server_enabled',
DI::l10n()->t('Replace links to YouTube.'),
$invidious_server_enabled,
],
'$invidious_server' => [
'invidious_server',
DI::l10n()->t('Invidious server'),
@ -67,6 +85,19 @@ function url_replace_addon_admin(string &$o)
null,
'placeholder="https://yewtu.be"',
],
'$proxigram_server_enabled' => [
'proxigram_server_enabled',
DI::l10n()->t('Replace links to Instagram.'),
$proxigram_server_enabled,
],
'$proxigram_server' => [
'proxigram_server',
DI::l10n()->t('Proxigram server'),
$proxigram_server,
DI::l10n()->t('Specify the URL with protocol. The default is https://proxigram.lunar.icu.'),
null,
'placeholder="https://proxigram.lunar.icu"',
],
'$twelvefeet_sites' => [
'twelvefeet_sites',
DI::l10n()->t('Sites which are accessed through 12ft.io'),
@ -84,46 +115,63 @@ function url_replace_addon_admin(string &$o)
*/
function url_replace_render(array &$b)
{
$replaced = false;
$replacements = [];
$nitter_server = DI::config()->get('url_replace', 'nitter_server');
if (empty($nitter_server)) {
$nitter_server = 'https://nitter.net';
}
$nitter_server_enabled = DI::config()->get('url_replace', 'nitter_server_enabled', true);
if ($nitter_server_enabled) {
$replacements = array_merge($replacements, [
'https://mobile.twitter.com' => $nitter_server,
'https://twitter.com' => $nitter_server,
'https://mobile.x.com' => $nitter_server,
'https://x.com' => $nitter_server,
]);
}
$invidious_server = DI::config()->get('url_replace', 'invidious_server');
if (empty($invidious_server)) {
$invidious_server = 'https://yewtu.be';
}
// Handle some of twitter and youtube
$replacements = [
'https://mobile.twitter.com' => $nitter_server,
'https://twitter.com' => $nitter_server,
'https://mobile.x.com' => $nitter_server,
'https://x.com' => $nitter_server,
$invidious_server_enabled = DI::config()->get('url_replace', 'invidious_server_enabled', true);
if ($invidious_server_enabled) {
$replacements = array_merge($replacements, [
'https://www.youtube.com' => $invidious_server,
'https://youtube.com' => $invidious_server,
'https://m.youtube.com' => $invidious_server,
'https://youtu.be' => $invidious_server,
];
]);
}
$proxigram_server = DI::config()->get('url_replace', 'proxigram_server');
if (empty($proxigram_server)) {
$proxigram_server = 'https://proxigram.lunar.icu';
}
$proxigram_server_enabled = DI::config()->get('url_replace', 'proxigram_server_enabled', true);
if ($proxigram_server_enabled) {
$replacements = array_merge($replacements, [
'https://www.instagram.com' => $proxigram_server,
'https://instagram.com' => $proxigram_server,
'https://ig.me' => $proxigram_server,
]);
}
foreach ($replacements as $server => $replacement) {
if (strpos($b['html'], $server) !== false) {
$b['html'] = str_replace($server, $replacement, $b['html']);
$replaced = true;
}
}
$twelvefeet_sites = DI::config()->get('url_replace', 'twelvefeet_sites') ?? [] ?: [];
$twelvefeet_sites = DI::config()->get('url_replace', 'twelvefeet_sites') ?? [];
foreach ($twelvefeet_sites as $twelvefeet_site) {
if (strpos($b['html'], $twelvefeet_site) !== false) {
$b['html'] = str_replace($twelvefeet_site, 'https://12ft.io/' . $twelvefeet_site, $b['html']);
$replaced = true;
}
}
if ($replaced) {
$b['html'] .= '<hr><p><small>' . DI::l10n()->t('(URL replace addon enabled for X, YouTube and some news sites.)') . '</small></p>';
if (count($replacements) > 0) {
$b['html'] .= '<hr><p><small>' . DI::l10n()->t('(URL replace addon enabled for X, YouTube, Instagram and some news sites.)') . '</small></p>';
}
}