Merge branch 'fix-markdown-in-previews' into 'develop'

Properly handle markdown choices inside titles, if no text as fallback, use the…

Closes #326

See merge request framasoft/framadate!323
This commit is contained in:
Thomas Citharel 2018-05-25 19:35:20 +02:00
commit f656c790d0
3 changed files with 28 additions and 12 deletions

View File

@ -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) {

View File

@ -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",

View File

@ -82,19 +82,19 @@
<ul class="list-unstyled choice">
<li class="yes">
<input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2" {if $choice=='2'}checked {/if}/>
<label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {$slots[$id]->title|html}">
<label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {markdown_to_text markdown=$slots[$id]->title id=$id|html}">
<i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
</label>
</li>
<li class="ifneedbe">
<input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1" {if $choice=='1'}checked {/if}/>
<label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slots[$id]->title|html}">
<label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {markdown_to_text markdown=$slots[$id]->title id=$id|html}">
(<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
</label>
</li>
<li class="no">
<input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value="0" {if $choice=='0'}checked {/if}/>
<label class="btn btn-default btn-xs" for="n-choice-{$id}" title="{__('Poll results', 'Vote no for')|html} {$slots[$id]->title|html}">
<label class="btn btn-default btn-xs" for="n-choice-{$id}" title="{__('Poll results', 'Vote no for')|html} {markdown_to_text markdown=$slots[$id]->title id=$id|html}">
<i class="glyphicon glyphicon-ban-circle"></i><span class="sr-only">{__('Generic', 'No')}</span>
</label>
</li>
@ -204,7 +204,7 @@
<input type="radio" id="y-choice-{$id}" name="choices[{$id}]" value="2"
{(!isset($selectedNewVotes[$id]) || ("2" !== $selectedNewVotes[$id])) ? "" : " checked"}
/>
<label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {$slot->title|html}">
<label class="btn btn-default btn-xs" for="y-choice-{$id}" title="{__('Poll results', 'Vote yes for')|html} {markdown_to_text markdown=$slot->title id=$id|html}">
<i class="glyphicon glyphicon-ok"></i><span class="sr-only">{__('Generic', 'Yes')}</span>
</label>
</li>
@ -212,7 +212,7 @@
<input type="radio" id="i-choice-{$id}" name="choices[{$id}]" value="1"
{(!isset($selectedNewVotes[$id]) || ("1" !== $selectedNewVotes[$id])) ? "" : " checked"}
/>
<label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {$slot->title|html}">
<label class="btn btn-default btn-xs" for="i-choice-{$id}" title="{__('Poll results', 'Vote ifneedbe for')|html} {markdown_to_text markdown=$slot->title id=$id|html}">
(<i class="glyphicon glyphicon-ok"></i>)<span class="sr-only">{__('Generic', 'Ifneedbe')}</span>
</label>
</li>
@ -221,7 +221,7 @@
<input type="radio" id="n-choice-{$id}" name="choices[{$id}]" value="0"
{(!isset($selectedNewVotes[$id]) || ("0" !== $selectedNewVotes[$id])) ? "" : " checked"}
/>
<label class="btn btn-default btn-xs {(!isset($selectedNewVotes[$id]) || ("0" !== $selectedNewVotes[$id])) ? "startunchecked" : ""}" for="n-choice-{$id}" title="{__('Poll results', 'Vote no for')|html} {$slot->title|html}">
<label class="btn btn-default btn-xs {(!isset($selectedNewVotes[$id]) || ("0" !== $selectedNewVotes[$id])) ? "startunchecked" : ""}" for="n-choice-{$id}" title="{__('Poll results', 'Vote no for')|html} {markdown_to_text markdown=$slot->title id=$id|html}">
<i class="glyphicon glyphicon-ban-circle"></i><span class="sr-only">{__('Generic', 'No')}</span>
</label>
</li>
@ -361,9 +361,9 @@
{$i = 0}
<ul class="list-unstyled">
{foreach $slots as $slot}
{foreach $slots as $i => $slot}
{if $best_choices['y'][$i] == $max}
<li><strong>{$slot->title|markdown:true}</strong></li>
<li><strong>{markdown_to_text markdown=$slot->title id=$i}</strong></li>
{/if}
{$i = $i+1}
{/foreach}