Compare commits

...

3 commits

Author SHA1 Message Date
Hypolite Petovan 5478552040 [nitter] Drop support for the addon
- Please use the URL replace addon instead
2024-03-19 12:56:08 -04:00
Hypolite Petovan a601a6b4a2 [invidious] Drop support for the addon
- Please use the URL replace addon instead
2024-03-19 12:56:08 -04:00
Hypolite Petovan c491c04111 [url_replace] Simplify config setting conditions
- Add default values for config values in url_replace_addon_admin()
- Capitalize brand names
2024-03-19 12:56:08 -04:00
3 changed files with 28 additions and 25 deletions

View file

@ -5,7 +5,8 @@
* Version: 0.3 * Version: 0.3
* Author: Matthias Ebers <https://loma.ml/profile/feb> * Author: Matthias Ebers <https://loma.ml/profile/feb>
* Author: Michael Vogel <https://pirati.ca/profile/heluecht> * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
* * Status: Unsupported
* Note: Please use the URL Replace addon instead
*/ */
use Friendica\Core\Hook; use Friendica\Core\Hook;
@ -91,7 +92,7 @@ function invidious_render(array &$b)
$original = $b['html']; $original = $b['html'];
$server = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'invidious', 'server', DI::config()->get('invidious', 'server', INVIDIOUS_DEFAULT)); $server = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'invidious', 'server', DI::config()->get('invidious', 'server', INVIDIOUS_DEFAULT));
$b['html'] = preg_replace("/https?:\/\/www.youtube.com\/watch\?v\=(.*?)/ism", $server . '/watch?v=$1', $b['html']); $b['html'] = preg_replace("/https?:\/\/www.youtube.com\/watch\?v\=(.*?)/ism", $server . '/watch?v=$1', $b['html']);
$b['html'] = preg_replace("/https?:\/\/www.youtube.com\/embed\/(.*?)/ism", $server . '/embed/$1', $b['html']); $b['html'] = preg_replace("/https?:\/\/www.youtube.com\/embed\/(.*?)/ism", $server . '/embed/$1', $b['html']);
$b['html'] = preg_replace("/https?:\/\/www.youtube.com\/shorts\/(.*?)/ism", $server . '/shorts/$1', $b['html']); $b['html'] = preg_replace("/https?:\/\/www.youtube.com\/shorts\/(.*?)/ism", $server . '/shorts/$1', $b['html']);

View file

@ -4,18 +4,20 @@
* Description: Replaces links to twitter.com to a nitter server in all displays of postings on a node. * Description: Replaces links to twitter.com to a nitter server in all displays of postings on a node.
* Version: 2.0 * Version: 2.0
* Author: Tobias Diekershoff <tobias@social.diekershoff.de> * Author: Tobias Diekershoff <tobias@social.diekershoff.de>
* Status: Unsupported
* Note: Please use the URL Replace addon instead
* *
* Copyright (c) 2020 Tobias Diekershoff * Copyright (c) 2020 Tobias Diekershoff
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including * associated documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial * The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software. * portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
@ -49,7 +51,7 @@ function nitter_addon_admin(string &$o)
$t = Renderer::getMarkupTemplate('admin.tpl', 'addon/nitter/'); $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/nitter/');
$o = Renderer::replaceMacros($t, [ $o = Renderer::replaceMacros($t, [
'$settingdescription' => DI::l10n()->t('Which nitter server shall be used for the replacements in the post bodies? Use the URL with servername and protocol. See %s for a list of available public Nitter servers.', 'https://github.com/zedeus/nitter/wiki/Instances'), '$settingdescription' => DI::l10n()->t('Which nitter server shall be used for the replacements in the post bodies? Use the URL with servername and protocol. See %s for a list of available public Nitter servers.', 'https://github.com/zedeus/nitter/wiki/Instances'),
'$nitterserver' => ['nitterserver', DI::l10n()->t('Nitter server'), $nitterserver, 'https://example.com'], '$nitterserver' => ['nitterserver', DI::l10n()->t('Nitter server'), $nitterserver, 'https://example.com'],
'$submit' => DI::l10n()->t('Save Settings'), '$submit' => DI::l10n()->t('Save Settings'),
]); ]);
} }

View file

@ -26,25 +26,25 @@ 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_enabled', !empty($_POST['nitter_server_enabled']));
$server = rtrim(trim($_POST['nitter_server']), '/'); $nitter_server = rtrim(trim($_POST['nitter_server']), '/');
if (empty($server)) { if ($nitter_server) {
DI::config()->delete('url_replace', 'nitter_server'); DI::config()->set('url_replace', 'nitter_server', $nitter_server);
} else { } else {
DI::config()->set('url_replace', 'nitter_server', $server); DI::config()->delete('url_replace', 'nitter_server');
} }
DI::config()->set('url_replace', 'invidious_server_enabled', !empty($_POST['invidious_server_enabled'])); DI::config()->set('url_replace', 'invidious_server_enabled', !empty($_POST['invidious_server_enabled']));
$server = rtrim(trim($_POST['invidious_server']), '/'); $invidious_server = rtrim(trim($_POST['invidious_server']), '/');
if (empty($server)) { if ($invidious_server) {
DI::config()->delete('url_replace', 'invidious_server'); DI::config()->set('url_replace', 'invidious_server', $invidious_server);
} else { } else {
DI::config()->set('url_replace', 'invidious_server', $server); DI::config()->delete('url_replace', 'invidious_server');
} }
DI::config()->set('url_replace', 'proxigram_server_enabled', !empty($_POST['proxigram_server_enabled'])); DI::config()->set('url_replace', 'proxigram_server_enabled', !empty($_POST['proxigram_server_enabled']));
$server = rtrim(trim($_POST['proxigram_server']), '/'); $proxigram_server = rtrim(trim($_POST['proxigram_server']), '/');
if (empty($server)) { if ($proxigram_server) {
DI::config()->delete('url_replace', 'proxigram_server'); DI::config()->set('url_replace', 'proxigram_server', $proxigram_server);
} else { } else {
DI::config()->set('url_replace', 'proxigram_server', $server); DI::config()->delete('url_replace', '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']);
@ -64,16 +64,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, Instagram, 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_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_enabled = DI::config()->get('url_replace', 'invidious_server_enabled', true); $invidious_server_enabled = DI::config()->get('url_replace', 'invidious_server_enabled') ?? true;
$invidious_server = DI::config()->get('url_replace', 'invidious_server'); $invidious_server = DI::config()->get('url_replace', 'invidious_server') ?? '';
$proxigram_server_enabled = DI::config()->get('url_replace', 'proxigram_server_enabled', true); $proxigram_server_enabled = DI::config()->get('url_replace', 'proxigram_server_enabled') ?? true;
$proxigram_server = DI::config()->get('url_replace', 'proxigram_server'); $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/'); $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/url_replace/');