From 92f699337f907f4da31c932e72a68d3b19680fed Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 25 May 2018 19:24:54 +0200 Subject: [PATCH 1/2] Properly handle markdown choices inside titles, if no text as fallback, use the number of the choice column Also, unrelated, but finally disabled smarty caching on php's build-in server Signed-off-by: Thomas Citharel --- app/inc/smarty.php | 17 ++++++++++++++++- locale/en.json | 1 + tpl/part/vote_table_classic.tpl | 18 +++++++++--------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/inc/smarty.php b/app/inc/smarty.php index f67e7e7..338ba2f 100644 --- a/app/inc/smarty.php +++ b/app/inc/smarty.php @@ -45,7 +45,7 @@ if (defined('FAVICON')) { } // Dev Mode -if (isset($_SERVER['FRAMADATE_DEVMODE']) && $_SERVER['FRAMADATE_DEVMODE']) { +if (isset($_SERVER['FRAMADATE_DEVMODE']) && $_SERVER['FRAMADATE_DEVMODE'] || php_sapi_name() === 'cli-server') { $smarty->force_compile = true; $smarty->compile_check = true; } else { @@ -80,6 +80,21 @@ function smarty_modifier_html($html) { return Utils::htmlEscape($html); } +/** + * markdown_to_text + * Retrieves a markdown string and tries to make a plain text value + * + * @param array $options + * @return string + */ +function smarty_function_markdown_to_text($options, Smarty_Internal_Template $template) +{ + $locale = \o80\i18n\I18N::instance()->getLoadedLang(); + $text = strip_tags(Parsedown::instance()->text($options['markdown'])); + $number_letters = (new NumberFormatter($locale, NumberFormatter::ORDINAL))->format($options['id'] + 1); + return $text !== '' ? $text : __f('Poll results', '%s option', $number_letters); +} + function smarty_modifier_datepicker_path($lang) { $i = 0; while (!is_file(path_for_datepicker_locale($lang)) && $i < 3) { diff --git a/locale/en.json b/locale/en.json index 14f93d1..8a0093d 100644 --- a/locale/en.json +++ b/locale/en.json @@ -290,6 +290,7 @@ "You have to provide a password to access the poll.": "You have to provide a password to access the poll." }, "Poll results": { + "%s option": "%s option", "Addition": "Total", "Anyone will be able to access your email address after your vote": "Anyone will be able to see your email address after you voted", "Best choice": "Best choice", diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index 6ce6b38..3ccc43f 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -82,19 +82,19 @@