From 289d7b344c01d57e04df52408f8d06fd7d24adf9 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 26 Dec 2019 08:14:04 +0000 Subject: [PATCH 1/2] New Addon Markdown --- markdown/README | 5 ++++ markdown/markdown.php | 53 +++++++++++++++++++++++++++++++++ markdown/templates/settings.tpl | 15 ++++++++++ 3 files changed, 73 insertions(+) create mode 100644 markdown/README create mode 100644 markdown/markdown.php create mode 100644 markdown/templates/settings.tpl diff --git a/markdown/README b/markdown/README new file mode 100644 index 000000000..da3cd53de --- /dev/null +++ b/markdown/README @@ -0,0 +1,5 @@ +Markdown +======== + +The Markdown addon parses user input for new items and comments via the Markdown parser. +This enables users to use the Markdown syntax additionally to the BBCode syntax. diff --git a/markdown/markdown.php b/markdown/markdown.php new file mode 100644 index 000000000..a5358d0e3 --- /dev/null +++ b/markdown/markdown.php @@ -0,0 +1,53 @@ + + */ +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; + +function markdown_install() { + Hook::register('post_local_start', __FILE__, 'markdown_post_local_start'); + Hook::register('addon_settings', __FILE__, 'markdown_addon_settings'); + Hook::register('addon_settings_post', __FILE__, 'markdown_addon_settings_post'); +} + +function markdown_addon_settings(App $a, &$s) +{ + if (!local_user()) { + return; + } + + $enabled = intval(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'), + ]); +} + +function markdown_addon_settings_post(App $a, &$b) +{ + if (!local_user() || empty($_POST['markdown-submit'])) { + return; + } + + 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')) { + return; + } + + $request['body'] = Markdown::toBBCode($request['body']); +} diff --git a/markdown/templates/settings.tpl b/markdown/templates/settings.tpl new file mode 100644 index 000000000..3d0135150 --- /dev/null +++ b/markdown/templates/settings.tpl @@ -0,0 +1,15 @@ + +

{{$title}}

+
+ From 95f0065759b10182a108690d8c33ff226ad36da3 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 26 Dec 2019 10:05:27 +0000 Subject: [PATCH 2/2] Added messages --- markdown/lang/C/messages.po | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 markdown/lang/C/messages.po diff --git a/markdown/lang/C/messages.po b/markdown/lang/C/messages.po new file mode 100644 index 000000000..b2ce51ed4 --- /dev/null +++ b/markdown/lang/C/messages.po @@ -0,0 +1,35 @@ +# ADDON markdown +# Copyright (C) +# This file is distributed under the same license as the Friendica markdown addon package. +# +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-12-26 10:04+0000\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" + +#: markdown.php:32 +msgid "Markdown" +msgstr "" + +#: markdown.php:33 +msgid "Enable Markdown parsing" +msgstr "" + +#: markdown.php:33 +msgid "" +"If enabled, self created items will additionally be parsed via Markdown." +msgstr "" + +#: markdown.php:34 +msgid "Save Settings" +msgstr ""