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.
|
||||
|
||||
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,
|
||||
or from some news sites to 12ft.io.
|
||||
YouTube to an invidious 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
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \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"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -17,56 +17,34 @@ msgstr ""
|
|||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: url_replace.php:64
|
||||
msgid "Replace links to X."
|
||||
msgstr ""
|
||||
|
||||
#: url_replace.php:69
|
||||
#: url_replace.php:54
|
||||
msgid "Nitter server"
|
||||
msgstr ""
|
||||
|
||||
#: url_replace.php:71
|
||||
#: url_replace.php:56
|
||||
msgid "Specify the URL with protocol. The default is https://nitter.net."
|
||||
msgstr ""
|
||||
|
||||
#: url_replace.php:77
|
||||
msgid "Replace links to YouTube."
|
||||
msgstr ""
|
||||
|
||||
#: url_replace.php:82
|
||||
#: url_replace.php:62
|
||||
msgid "Invidious server"
|
||||
msgstr ""
|
||||
|
||||
#: url_replace.php:84
|
||||
#: url_replace.php:64
|
||||
msgid "Specify the URL with protocol. The default is https://yewtu.be."
|
||||
msgstr ""
|
||||
|
||||
#: 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
|
||||
#: url_replace.php:70
|
||||
msgid "Sites which are accessed through 12ft.io"
|
||||
msgstr ""
|
||||
|
||||
#: url_replace.php:105
|
||||
#: url_replace.php:72
|
||||
msgid "Specify the URLs with protocol, one per line."
|
||||
msgstr ""
|
||||
|
||||
#: url_replace.php:109
|
||||
#: url_replace.php:76
|
||||
msgid "Save settings"
|
||||
msgstr ""
|
||||
|
||||
#: url_replace.php:175
|
||||
msgid ""
|
||||
"(URL replace addon enabled for X, YouTube, Instagram and some news sites.)"
|
||||
#: url_replace.php:125
|
||||
msgid "(URL replace addon enabled for X, YouTube and some news sites.)"
|
||||
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_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>
|
||||
|
|
|
@ -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.1
|
||||
* Version: 1.0
|
||||
* Author: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
|
||||
* Maintainer: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
|
||||
*/
|
||||
|
@ -21,12 +21,8 @@ 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
|
||||
|
@ -45,25 +41,16 @@ function url_replace_addon_admin_post()
|
|||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$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');
|
||||
$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') ?? []);
|
||||
$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'),
|
||||
|
@ -72,11 +59,6 @@ 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'),
|
||||
|
@ -85,19 +67,6 @@ 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'),
|
||||
|
@ -115,63 +84,46 @@ function url_replace_addon_admin(string &$o)
|
|||
*/
|
||||
function url_replace_render(array &$b)
|
||||
{
|
||||
$replacements = [];
|
||||
$replaced = false;
|
||||
|
||||
$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';
|
||||
}
|
||||
$invidious_server_enabled = DI::config()->get('url_replace', 'invidious_server_enabled', true);
|
||||
if ($invidious_server_enabled) {
|
||||
$replacements = array_merge($replacements, [
|
||||
|
||||
// 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,
|
||||
]);
|
||||
}
|
||||
|
||||
$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 (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