Merge pull request '[url_replace] Add support for empty config value' (#1478) from MrPetovan/friendica-addons:bug/13968-url_replace-fatal into 2024.03-rc

Reviewed-on: friendica/friendica-addons#1478
This commit is contained in:
Tobias Diekershoff 2024-03-07 19:52:53 +01:00
commit c9923e47de

View file

@ -6,6 +6,7 @@
* Author: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy> * Author: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
* Maintainer: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy> * Maintainer: Dr. Tobias Quathamer <https://social.anoxinon.de/@toddy>
*/ */
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
@ -46,7 +47,8 @@ function url_replace_addon_admin(string &$o)
{ {
$nitter_server = DI::config()->get('url_replace', 'nitter_server'); $nitter_server = DI::config()->get('url_replace', 'nitter_server');
$invidious_server = DI::config()->get('url_replace', 'invidious_server'); $invidious_server = DI::config()->get('url_replace', 'invidious_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/');
$o = Renderer::replaceMacros($t, [ $o = Renderer::replaceMacros($t, [
'$nitter_server' => [ '$nitter_server' => [
@ -112,10 +114,7 @@ function url_replace_render(array &$b)
} }
} }
$twelvefeet_sites = DI::config()->get('url_replace', 'twelvefeet_sites'); $twelvefeet_sites = DI::config()->get('url_replace', 'twelvefeet_sites') ?? [] ?: [];
if (empty($twelvefeet_sites)) {
$twelvefeet_sites = [];
}
foreach ($twelvefeet_sites as $twelvefeet_site) { foreach ($twelvefeet_sites as $twelvefeet_site) {
if (strpos($b['html'], $twelvefeet_site) !== false) { if (strpos($b['html'], $twelvefeet_site) !== false) {
$b['html'] = str_replace($twelvefeet_site, 'https://12ft.io/' . $twelvefeet_site, $b['html']); $b['html'] = str_replace($twelvefeet_site, 'https://12ft.io/' . $twelvefeet_site, $b['html']);