forked from friendica/friendica-addons
Compare commits
No commits in common. "d3ba63c559b71dfc4eecd0f1e068ad37d8e933cb" and "d11efc108cb5059dd6b12bfa6e8f468defb9db2a" have entirely different histories.
d3ba63c559
...
d11efc108c
|
@ -4,8 +4,7 @@ This addon will replace all occurrences of specified URLs with the address of
|
||||||
alternative servers in all displayed postings on a Friendica node.
|
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
|
You can use this to switch from Twitter (or X) to a nitter instance, from
|
||||||
YouTube to an invidious instance, from Instagram to a proxigram instance,
|
YouTube to an invidious instance, or from some news sites to 12ft.io.
|
||||||
or from some news sites to 12ft.io.
|
|
||||||
|
|
||||||
Note: If you are using the twitter connector on your server, the links to the
|
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
|
contacts profile pages will not be replaced by this addon. Only links in the
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: \n"
|
"Project-Id-Version: \n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2024-03-13 22:56+0100\n"
|
"POT-Creation-Date: 2024-01-05 00:06+0100\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -17,56 +17,34 @@ msgstr ""
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
#: url_replace.php:64
|
#: url_replace.php:54
|
||||||
msgid "Replace links to X."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: url_replace.php:69
|
|
||||||
msgid "Nitter server"
|
msgid "Nitter server"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: url_replace.php:71
|
#: url_replace.php:56
|
||||||
msgid "Specify the URL with protocol. The default is https://nitter.net."
|
msgid "Specify the URL with protocol. The default is https://nitter.net."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: url_replace.php:77
|
#: url_replace.php:62
|
||||||
msgid "Replace links to YouTube."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: url_replace.php:82
|
|
||||||
msgid "Invidious server"
|
msgid "Invidious server"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: url_replace.php:84
|
#: url_replace.php:64
|
||||||
msgid "Specify the URL with protocol. The default is https://yewtu.be."
|
msgid "Specify the URL with protocol. The default is https://yewtu.be."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: url_replace.php:90
|
#: url_replace.php:70
|
||||||
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"
|
msgid "Sites which are accessed through 12ft.io"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: url_replace.php:105
|
#: url_replace.php:72
|
||||||
msgid "Specify the URLs with protocol, one per line."
|
msgid "Specify the URLs with protocol, one per line."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: url_replace.php:109
|
#: url_replace.php:76
|
||||||
msgid "Save settings"
|
msgid "Save settings"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: url_replace.php:175
|
#: url_replace.php:125
|
||||||
msgid ""
|
msgid "(URL replace addon enabled for X, YouTube and some news sites.)"
|
||||||
"(URL replace addon enabled for X, YouTube, Instagram and some news sites.)"
|
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
{{include file="field_checkbox.tpl" field=$nitter_server_enabled}}
|
|
||||||
{{include file="field_input.tpl" field=$nitter_server}}
|
{{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_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}}
|
{{include file="field_textarea.tpl" field=$twelvefeet_sites}}
|
||||||
|
|
||||||
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>
|
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}" /></div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* Name: URL Replace
|
* Name: URL Replace
|
||||||
* Description: Replaces occurrences of specified URLs with the address of alternative servers in all displays of postings on a node.
|
* Description: Replaces occurrences of specified URLs with the address of alternative servers in all displays of postings on a node.
|
||||||
* Version: 1.1
|
* Version: 1.0
|
||||||
* Author: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
|
* Author: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
|
||||||
* Maintainer: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
|
* Maintainer: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
|
||||||
*/
|
*/
|
||||||
|
@ -21,22 +21,18 @@ function url_replace_install()
|
||||||
*/
|
*/
|
||||||
function url_replace_addon_admin_post()
|
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', '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', '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
|
// Convert twelvefeet_sites into an array before setting the new value
|
||||||
$twelvefeet_sites = explode(PHP_EOL, $_POST['twelvefeet_sites']);
|
$twelvefeet_sites = explode(PHP_EOL, $_POST['twelvefeet_sites']);
|
||||||
// Normalize URLs by using lower case, removing a trailing slash and whitespace
|
// 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
|
// 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);
|
$twelvefeet_sites = array_unique($twelvefeet_sites);
|
||||||
// Ensure a protocol and default to HTTPS
|
// Ensure a protocol and default to HTTPS
|
||||||
$twelvefeet_sites = array_map(
|
$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
|
$twelvefeet_sites
|
||||||
);
|
);
|
||||||
asort($twelvefeet_sites);
|
asort($twelvefeet_sites);
|
||||||
|
@ -45,25 +41,16 @@ function url_replace_addon_admin_post()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook into admin settings to enable choosing a different server
|
* Hook into admin settings to enable choosing a different server
|
||||||
* for twitter, youtube, instagram, and news sites.
|
* for twitter, youtube, and news sites.
|
||||||
*/
|
*/
|
||||||
function url_replace_addon_admin(string &$o)
|
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');
|
||||||
$nitter_server = DI::config()->get('url_replace', 'nitter_server');
|
$invidious_server = DI::config()->get('url_replace', 'invidious_server');
|
||||||
$invidious_server_enabled = DI::config()->get('url_replace', 'invidious_server_enabled', true);
|
$twelvefeet_sites = implode(PHP_EOL, DI::config()->get('url_replace', 'twelvefeet_sites') ?? [] ?: []);
|
||||||
$invidious_server = DI::config()->get('url_replace', 'invidious_server');
|
|
||||||
$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/');
|
$t = Renderer::getMarkupTemplate('admin.tpl', 'addon/url_replace/');
|
||||||
$o = Renderer::replaceMacros($t, [
|
$o = Renderer::replaceMacros($t, [
|
||||||
'$nitter_server_enabled' => [
|
|
||||||
'nitter_server_enabled',
|
|
||||||
DI::l10n()->t('Replace links to X.'),
|
|
||||||
$nitter_server_enabled,
|
|
||||||
],
|
|
||||||
'$nitter_server' => [
|
'$nitter_server' => [
|
||||||
'nitter_server',
|
'nitter_server',
|
||||||
DI::l10n()->t('Nitter server'),
|
DI::l10n()->t('Nitter server'),
|
||||||
|
@ -72,11 +59,6 @@ function url_replace_addon_admin(string &$o)
|
||||||
null,
|
null,
|
||||||
'placeholder="https://nitter.net"',
|
'placeholder="https://nitter.net"',
|
||||||
],
|
],
|
||||||
'$invidious_server_enabled' => [
|
|
||||||
'invidious_server_enabled',
|
|
||||||
DI::l10n()->t('Replace links to YouTube.'),
|
|
||||||
$invidious_server_enabled,
|
|
||||||
],
|
|
||||||
'$invidious_server' => [
|
'$invidious_server' => [
|
||||||
'invidious_server',
|
'invidious_server',
|
||||||
DI::l10n()->t('Invidious server'),
|
DI::l10n()->t('Invidious server'),
|
||||||
|
@ -85,19 +67,6 @@ function url_replace_addon_admin(string &$o)
|
||||||
null,
|
null,
|
||||||
'placeholder="https://yewtu.be"',
|
'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' => [
|
||||||
'twelvefeet_sites',
|
'twelvefeet_sites',
|
||||||
DI::l10n()->t('Sites which are accessed through 12ft.io'),
|
DI::l10n()->t('Sites which are accessed through 12ft.io'),
|
||||||
|
@ -115,63 +84,46 @@ function url_replace_addon_admin(string &$o)
|
||||||
*/
|
*/
|
||||||
function url_replace_render(array &$b)
|
function url_replace_render(array &$b)
|
||||||
{
|
{
|
||||||
$replacements = [];
|
$replaced = false;
|
||||||
|
|
||||||
$nitter_server = DI::config()->get('url_replace', 'nitter_server');
|
$nitter_server = DI::config()->get('url_replace', 'nitter_server');
|
||||||
if (empty($nitter_server)) {
|
if (empty($nitter_server)) {
|
||||||
$nitter_server = 'https://nitter.net';
|
$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');
|
$invidious_server = DI::config()->get('url_replace', 'invidious_server');
|
||||||
if (empty($invidious_server)) {
|
if (empty($invidious_server)) {
|
||||||
$invidious_server = 'https://yewtu.be';
|
$invidious_server = 'https://yewtu.be';
|
||||||
}
|
}
|
||||||
$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,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
'https://www.youtube.com' => $invidious_server,
|
||||||
|
'https://youtube.com' => $invidious_server,
|
||||||
|
'https://m.youtube.com' => $invidious_server,
|
||||||
|
'https://youtu.be' => $invidious_server,
|
||||||
|
];
|
||||||
foreach ($replacements as $server => $replacement) {
|
foreach ($replacements as $server => $replacement) {
|
||||||
if (strpos($b['html'], $server) !== false) {
|
if (strpos($b['html'], $server) !== false) {
|
||||||
$b['html'] = str_replace($server, $replacement, $b['html']);
|
$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) {
|
foreach ($twelvefeet_sites as $twelvefeet_site) {
|
||||||
if (strpos($b['html'], $twelvefeet_site) !== false) {
|
if (strpos($b['html'], $twelvefeet_site) !== false) {
|
||||||
$b['html'] = str_replace($twelvefeet_site, 'https://12ft.io/' . $twelvefeet_site, $b['html']);
|
$b['html'] = str_replace($twelvefeet_site, 'https://12ft.io/' . $twelvefeet_site, $b['html']);
|
||||||
|
$replaced = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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>';
|
if ($replaced) {
|
||||||
|
$b['html'] .= '<hr><p><small>' . DI::l10n()->t('(URL replace addon enabled for X, YouTube and some news sites.)') . '</small></p>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue