X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=nitter%2Fnitter.php;h=440f199f3840a781bacb5e2f7288203c46198f9d;hb=239003fa6c983b84bdbb58780f1ecc6c3791ef6b;hp=e8f3bcdb0a1532d6a209a6bebd240926e3e0f90e;hpb=63d6c3f40f86f681d17f228f36bc744c6e9ac0a6;p=friendica-addons.git diff --git a/nitter/nitter.php b/nitter/nitter.php index e8f3bcdb..440f199f 100644 --- a/nitter/nitter.php +++ b/nitter/nitter.php @@ -2,7 +2,7 @@ /* * Name: nitter * Description: Replaces links to twitter.com to a nitter server in all displays of postings on a node. - * Version: 1.1 + * Version: 2.0 * Author: Tobias Diekershoff * * Copyright (c) 2020 Tobias Diekershoff @@ -24,33 +24,32 @@ */ use Friendica\App; -use Friendica\Core\Addon; +use Friendica\Core\Hook; use Friendica\Core\Renderer; use Friendica\DI; function nitter_install() { - Addon::registerHook ('prepare_body', 'addon/nitter/nitter.php', 'nitter_render'); + Hook::register('prepare_body_final', 'addon/nitter/nitter.php', 'nitter_render'); } /* Handle the send data from the admin settings */ function nitter_addon_admin_post(App $a) { - $nitterserver = rtrim(trim($_POST['nitterserver']),'/'); - DI::config()->set('nitter', 'server', $nitterserver); + DI::config()->set('nitter', 'server', rtrim(trim($_POST['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) +function nitter_addon_admin(App $a, string &$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'], + '$nitterserver' => ['nitterserver', DI::l10n()->t('Nitter server'), $nitterserver, 'https://example.com'], '$submit' => DI::l10n()->t('Save Settings'), ]); } @@ -58,20 +57,20 @@ function nitter_addon_admin(App $a, &$o) /* * replace "twitter.com" with "nitter.net" */ -function nitter_render(&$a, &$o) +function nitter_render(App $a, array &$b) { // this needs to be a system setting $replaced = false; $nitter = DI::config()->get('nitter', 'server', 'https://nitter.net'); - if (strstr($o['html'], 'https://mobile.twitter.com')) { - $o['html'] = str_replace('https://mobile.twitter.com', $nitter, $o['html']); - $replace = true; + if (strstr($b['html'], 'https://mobile.twitter.com')) { + $b['html'] = str_replace('https://mobile.twitter.com', $nitter, $b['html']); + $replaced = true; } - if (strstr($o['html'], 'https://twitter.com')) { - $o['html'] = str_replace('https://twitter.com', $nitter, $o['html']); - $replace = true; + if (strstr($b['html'], 'https://twitter.com')) { + $b['html'] = str_replace('https://twitter.com', $nitter, $b['html']); + $replaced = true; } - if ($replace) { - $o['html'] .= '

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

'; + if ($replaced) { + $b['html'] .= '

' . DI::l10n()->t('(Nitter addon enabled: Twitter links via %s)', $nitter) . '

'; } }