From 87a3a0589a86ca56593f50c6199ff74e7a63ac85 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 21 May 2021 10:11:11 +0200 Subject: [PATCH 1/2] nitter addon added Treansfering the addon from the separate repository into the projects addon collection. This addon is meant to replace links to Twitter in the body of postings with a nitter [1] instance of the admins choice. It is not meant to change links to contact prociles. In addition to the change, a note about the changed links is placed at the bottom of the posting. 1: https://github.com/zedeus/nitter --- nitter/LICENSE | 7 ++++ nitter/README.md | 27 +++++++++++++++ nitter/lang/C/messages.po | 41 +++++++++++++++++++++++ nitter/lang/de/messages.po | 41 +++++++++++++++++++++++ nitter/lang/de/strings.php | 7 ++++ nitter/nitter.php | 67 ++++++++++++++++++++++++++++++++++++++ nitter/templates/admin.tpl | 5 +++ 7 files changed, 195 insertions(+) create mode 100644 nitter/LICENSE create mode 100644 nitter/README.md create mode 100644 nitter/lang/C/messages.po create mode 100644 nitter/lang/de/messages.po create mode 100644 nitter/lang/de/strings.php create mode 100644 nitter/nitter.php create mode 100644 nitter/templates/admin.tpl diff --git a/nitter/LICENSE b/nitter/LICENSE new file mode 100644 index 00000000..69d75892 --- /dev/null +++ b/nitter/LICENSE @@ -0,0 +1,7 @@ +Copyright 2020 Tobias Diekershoff + +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 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 the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +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. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/nitter/README.md b/nitter/README.md new file mode 100644 index 00000000..8fab6304 --- /dev/null +++ b/nitter/README.md @@ -0,0 +1,27 @@ +nitter Addon for Friendica +========================== + +This addon will replace all occurances of the string _https://twitter.com_ with the server address of a nitter installation in all displayed postings on a Friendica node. + +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 body of the postings are affected. + +Nitter sources can be found on [github.com](https://github.com/zedeus/nitter) it is released unter the AGPLv3 or later. + +Why +--- + +Excerp from nitters about page. + +> It's basically impossible to use Twitter without JavaScript enabled. If you try, you're redirected to the legacy mobile version which is awful both functionally and aesthetically. For privacy-minded folks, preventing JavaScript analytics and potential IP-based tracking is important, but apart from using the legacy mobile version and a VPN, it's impossible. +> +> Using an instance of Nitter (hosted on a VPS for example), you can browse Twitter without JavaScript while retaining your privacy. In addition to respecting your privacy, Nitter is on average around 15 times lighter than Twitter, and in some cases serves pages faster. +> +> In the future a simple account system will be added that lets you follow Twitter users, allowing you to have a clean chronological timeline without needing a Twitter account. + +Changelog +--------- + +* **Version 1.1** + * Initial localization support with DE translation + * Configurable nitter instance address from the admin panel +* **Version 1.0**: Initial Release diff --git a/nitter/lang/C/messages.po b/nitter/lang/C/messages.po new file mode 100644 index 00000000..a9e2428a --- /dev/null +++ b/nitter/lang/C/messages.po @@ -0,0 +1,41 @@ +# ADDON nitter +# Copyright (C) +# This file is distributed under the same license as the Friendica nitter addon package. +# +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-03-08 07:44+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: nitter.php:51 +#, php-format +msgid "" +"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." +msgstr "" + +#: nitter.php:52 +msgid "Nitter server" +msgstr "" + +#: nitter.php:53 +msgid "Save Settings" +msgstr "" + +#: nitter.php:65 +#, php-format +msgid "" +"Links to Twitter in this posting were replaced by links to the Nitter " +"instance at %s" +msgstr "" diff --git a/nitter/lang/de/messages.po b/nitter/lang/de/messages.po new file mode 100644 index 00000000..fb3825f5 --- /dev/null +++ b/nitter/lang/de/messages.po @@ -0,0 +1,41 @@ +# ADDON nitter +# Copyright (C) +# This file is distributed under the same license as the Friendica nitter addon package. +# +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-03-08 07:44+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: nitter.php:51 +#, php-format +msgid "" +"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." +msgstr "Welcher Nitter server soll für die Ersetzungen verwendet werden? Gib die URL mit Servername und Protokoll an. Eine Liste von öffentlichen Nitter servern findest du unter %s." + +#: nitter.php:52 +msgid "Nitter server" +msgstr "Nitter Server" + +#: nitter.php:53 +msgid "Save Settings" +msgstr "Einstellungen Speichern" + +#: nitter.php:65 +#, php-format +msgid "" +"Links to Twitter in this posting were replaced by links to the Nitter " +"instance at %s" +msgstr "In diesem Beitrag wurden Links nach twitter.com durch die Nitter Instanz auf %s ersetzt." diff --git a/nitter/lang/de/strings.php b/nitter/lang/de/strings.php new file mode 100644 index 00000000..33a0ed2e --- /dev/null +++ b/nitter/lang/de/strings.php @@ -0,0 +1,7 @@ +strings["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."] = "Welcher Nitter server soll für die Ersetzungen verwendet werden? Gib die URL mit Servername und Protokoll an. Eine Liste von öffentlichen Nitter servern findest du unter %s."; +$a->strings["Nitter server"] = "Nitter Server"; +$a->strings["Save Settings"] = "Einstellungen Speichern"; +$a->strings["Links to Twitter in this posting were replaced by links to the Nitter instance at %s"] = "In diesem Beitrag wurden Links nach twitter.com durch die Nitter Instanz auf %s ersetzt."; diff --git a/nitter/nitter.php b/nitter/nitter.php new file mode 100644 index 00000000..b6630b7c --- /dev/null +++ b/nitter/nitter.php @@ -0,0 +1,67 @@ + + * + * Copyright (c) 2020 Tobias Diekershoff + * + * 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 + * 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 + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. + * + * 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. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +use Friendica\App; +use Friendica\Core\Addon; +use Friendica\Core\Renderer; +use Friendica\DI; + +function nitter_install() { + Addon::registerHook ('prepare_body', 'addon/nitter/nitter.php', 'nitter_render'); +} + +/* Handle the send data from the admin settings + */ +function nitter_addon_admin_post(App $a) +{ + $nitterserver = trim($_POST['nitterserver']); + DI::config()->set('nitter', 'server', $nitterserver); +} + +/* Hook into the admin settings to let the admin choose a + * nitter server to use for the replacement. + */ +function nitter_addon_admin(App $a, &$o) +{ + $nitterserver = DI::config()->get('nitter', 'server'); + $t = Renderer::getMarkupTemplate("admin.tpl", "addon/nitter/"); + $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"), + '$nitterserver' => ["nitterserver", DI::l10n()->t('Nitter server'), $nitterserver, 'http://example.com'], + '$submit' => DI::l10n()->t('Save Settings'), + ]); +} + +/* + * replace "twitter.com" with "nitter.net" + */ +function nitter_render(&$a, &$o) { + // this needs to be a system setting + $nitter = DI::config()->get('nitter', 'server', 'https://nitter.net'); + if (strstr($o['html'],'https://twitter.com')) { + $o['html'] = str_replace('https://twitter.com', $nitter, $o['html']); + $o['html'] .= '

'.DI::l10n()->t('Links to Twitter in this posting were replaced by links to the Nitter instance at %s', $nitter).'

'; + } +} diff --git a/nitter/templates/admin.tpl b/nitter/templates/admin.tpl new file mode 100644 index 00000000..b7f02421 --- /dev/null +++ b/nitter/templates/admin.tpl @@ -0,0 +1,5 @@ +

{{$settingdescription}}

+ +{{include file="field_input.tpl" field=$nitterserver}} + +
From c2d502d2443ae1f003a4c9aefb7e9bfaecd97f48 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 21 May 2021 14:06:47 +0200 Subject: [PATCH 2/2] some CS --- nitter/nitter.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/nitter/nitter.php b/nitter/nitter.php index b6630b7c..ea8e24be 100644 --- a/nitter/nitter.php +++ b/nitter/nitter.php @@ -28,16 +28,17 @@ use Friendica\Core\Addon; use Friendica\Core\Renderer; use Friendica\DI; -function nitter_install() { - Addon::registerHook ('prepare_body', 'addon/nitter/nitter.php', 'nitter_render'); +function nitter_install() +{ + Addon::registerHook ('prepare_body', 'addon/nitter/nitter.php', 'nitter_render'); } /* Handle the send data from the admin settings */ function nitter_addon_admin_post(App $a) { - $nitterserver = trim($_POST['nitterserver']); - DI::config()->set('nitter', 'server', $nitterserver); + $nitterserver = trim($_POST['nitterserver']); + DI::config()->set('nitter', 'server', $nitterserver); } /* Hook into the admin settings to let the admin choose a @@ -45,23 +46,24 @@ function nitter_addon_admin_post(App $a) */ function nitter_addon_admin(App $a, &$o) { - $nitterserver = DI::config()->get('nitter', 'server'); - $t = Renderer::getMarkupTemplate("admin.tpl", "addon/nitter/"); - $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"), - '$nitterserver' => ["nitterserver", DI::l10n()->t('Nitter server'), $nitterserver, 'http://example.com'], - '$submit' => DI::l10n()->t('Save Settings'), - ]); + $nitterserver = DI::config()->get('nitter', 'server'); + $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/nitter/'); + $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'), + '$nitterserver' => ['nitterserver', DI::l10n()->t('Nitter server'), $nitterserver, 'http://example.com'], + '$submit' => DI::l10n()->t('Save Settings'), + ]); } /* * replace "twitter.com" with "nitter.net" */ -function nitter_render(&$a, &$o) { - // this needs to be a system setting - $nitter = DI::config()->get('nitter', 'server', 'https://nitter.net'); - if (strstr($o['html'],'https://twitter.com')) { - $o['html'] = str_replace('https://twitter.com', $nitter, $o['html']); - $o['html'] .= '

'.DI::l10n()->t('Links to Twitter in this posting were replaced by links to the Nitter instance at %s', $nitter).'

'; - } +function nitter_render(&$a, &$o) +{ + // this needs to be a system setting + $nitter = DI::config()->get('nitter', 'server', 'https://nitter.net'); + if (strstr($o['html'], 'https://twitter.com')) { + $o['html'] = str_replace('https://twitter.com', $nitter, $o['html']); + $o['html'] .= '

' . DI::l10n()->t('Links to Twitter in this posting were replaced by links to the Nitter instance at %s', $nitter) . '

'; + } }