X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=markdown%2Fmarkdown.php;h=f02bc2a017f208b878e08bd72be7b8ae1c7def76;hb=17b7362b1734f633f411d3bb2aead8754fc017b8;hp=9bebf64f188074fa867f5251ad190c47a7c0d9db;hpb=2f3e727570d9b4168a3eb307a3f26e3f645fb38e;p=friendica-addons.git diff --git a/markdown/markdown.php b/markdown/markdown.php index 9bebf64f..f02bc2a0 100644 --- a/markdown/markdown.php +++ b/markdown/markdown.php @@ -7,11 +7,9 @@ */ use Friendica\App; use Friendica\Core\Hook; -use Friendica\Core\Logger; use Friendica\Content\Text\Markdown; use Friendica\Core\Renderer; -use Friendica\Core\PConfig; -use Friendica\Core\L10n; +use Friendica\DI; function markdown_install() { Hook::register('post_local_start', __FILE__, 'markdown_post_local_start'); @@ -25,13 +23,13 @@ function markdown_addon_settings(App $a, &$s) return; } - $enabled = intval(PConfig::get(local_user(), 'markdown', 'enabled')); + $enabled = intval(DI::pConfig()->get(local_user(), 'markdown', 'enabled')); $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/markdown/'); $s .= Renderer::replaceMacros($t, [ - '$title' => L10n::t('Markdown'), - '$enabled' => ['enabled', L10n::t('Enable Markdown parsing'), $enabled, L10n::t('If enabled, self created items will additionally be parsed via Markdown.')], - '$submit' => L10n::t('Save Settings'), + '$title' => DI::l10n()->t('Markdown'), + '$enabled' => ['enabled', DI::l10n()->t('Enable Markdown parsing'), $enabled, DI::l10n()->t('If enabled, self created items will additionally be parsed via Markdown.')], + '$submit' => DI::l10n()->t('Save Settings'), ]); } @@ -41,33 +39,34 @@ function markdown_addon_settings_post(App $a, &$b) return; } - PConfig::set(local_user(), 'markdown', 'enabled', intval($_POST['enabled'])); + DI::pConfig()->set(local_user(), 'markdown', 'enabled', intval($_POST['enabled'])); } function markdown_post_local_start(App $a, &$request) { - if (empty($request['body']) || !PConfig::get(local_user(), 'markdown', 'enabled')) { + if (empty($request['body']) || !DI::pConfig()->get(local_user(), 'markdown', 'enabled')) { return; } // Elements that shouldn't be parsed - $elements = ['code', 'noparse', 'nobb', 'pre']; + $elements = ['code', 'noparse', 'nobb', 'pre', 'share', 'url', 'img', 'bookmark', + 'audio', 'video', 'youtube', 'vimeo', 'attachment', 'iframe', 'map', 'mail']; foreach ($elements as $element) { - $request['body'] = preg_replace_callback("/\[" . $element . "\](.*?)\[\/" . $element . "\]/ism", - function ($match) use ($element) { - return '[base64' . $element . ']' . base64_encode($match[1]) . '[/base64' . $element . ']'; - }, - $request['body'] - ); + $request['body'] = preg_replace_callback("/\[" . $element . "(.*?)\](.*?)\[\/" . $element . "\]/ism", + function ($match) use ($element) { + return '[' . $element . '-b64' . base64_encode($match[1]) . ']' . base64_encode($match[2]) . '[/b64-' . $element . ']'; + }, + $request['body'] + ); } $request['body'] = Markdown::toBBCode($request['body']); - foreach ($elements as $element) { - $request['body'] = preg_replace_callback("/\[base64" . $element . "\](.*?)\[\/base64" . $element . "\]/ism", - function ($match) use ($element) { - return '[' . $element . ']' . base64_decode($match[1]) . '[/' . $element . ']'; - }, - $request['body'] - ); + foreach (array_reverse($elements) as $element) { + $request['body'] = preg_replace_callback("/\[" . $element . "-b64(.*?)\](.*?)\[\/b64-" . $element . "\]/ism", + function ($match) use ($element) { + return '[' . $element . base64_decode($match[1]) . ']' . base64_decode($match[2]) . '[/' . $element . ']'; + }, + $request['body'] + ); } }