4 * Description: Replaces links to youtube.com to an invidious instance in all displays of postings on a node.
6 * Author: Matthias Ebers <@feb@loma.ml>
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
15 function invidious_install()
17 Hook::register('prepare_body_final', 'addon/invidious/invidious.php', 'invidious_render');
20 /* Handle the send data from the admin settings
22 function invidious_addon_admin_post()
24 DI::config()->set('invidious', 'server', rtrim(trim($_POST['invidiousserver']), '/'));
27 /* Hook into the admin settings to let the admin choose an
28 * invidious server to use for the replacement.
30 function invidious_addon_admin(string &$o)
32 $invidiousserver = DI::config()->get('invidious', 'server');
33 $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/invidious/');
34 $o = Renderer::replaceMacros($t, [
35 '$settingdescription' => DI::l10n()->t('Which Invidious 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 Invidious servers.', 'https://redirect.invidious.io'),
36 '$invidiousserver' => ['invidiousserver', DI::l10n()->t('Invidious server'), $invidiousserver, 'https://example.com'],
37 '$submit' => DI::l10n()->t('Save Settings'),
42 * replace "youtube.com" with the chosen Invidious instance
44 function invidious_render(array &$b)
46 // this needs to be a system setting
48 $invidious = DI::config()->get('invidious', 'server', 'https://invidio.us');
49 if (strstr($b['html'], 'https://www.youtube.com')) {
50 $b['html'] = str_replace('https://www.youtube.com', $invidious, $b['html']);
53 if (strstr($b['html'], 'https://youtube.com')) {
54 $b['html'] = str_replace('https://youtube.com', $invidious, $b['html']);
58 $b['html'] .= '<hr><p><small>' . DI::l10n()->t('(Invidious addon enabled: YouTube links via %s)', $invidious) . '</small></p>';