Move content filter HTML in a template

This commit is contained in:
Hypolite Petovan 2018-04-22 18:02:00 -04:00
parent 4cfb12e9d9
commit 48122733b8
2 changed files with 29 additions and 21 deletions

View file

@ -1411,27 +1411,13 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
function apply_content_filter($html, array $reasons) function apply_content_filter($html, array $reasons)
{ {
if (count($reasons)) { if (count($reasons)) {
$rnd = random_string(8); $tpl = get_markup_template('wall/content_filter.tpl');
$html = replace_macros($tpl, [
if (count($reasons) > 1) { '$reasons' => $reasons,
$content_filter_html = '<ul class="content-filter-reasons">'; '$rnd' => random_string(8),
foreach ($reasons as $reason) { '$openclose' => L10n::t('Click to open/close'),
$content_filter_html .= '<li>' . htmlspecialchars($reason) . '</li>' . PHP_EOL; '$html' => $html
} ]);
$content_filter_html .= '</ul>
<p><button type="button" id="content-filter-wrap-' . $rnd . '" class="btn btn-default btn-small content-filter-button" onclick="openClose(\'content-filter-' . $rnd . '\');"><i class="glyphicon glyphicon-eye-open"></i> ' .
L10n::t('Click to open/close') .
'</button></p>';
} elseif (count($reasons) == 1) {
$reason = array_pop($reasons);
$content_filter_html .= '<p>' . htmlspecialchars($reason) . ' <button type="button" id="content-filter-wrap-' . $rnd . '" class="btn btn-default btn-xs content-filter-button" onclick="openClose(\'content-filter-' . $rnd . '\');"><i class="glyphicon glyphicon-eye-open"></i> ' .
L10n::t('Click to open/close') .
'</button></p>';
}
$content_filter_html .= '<div id="content-filter-' . $rnd . '" class="content-filter-content" style="display: none;">';
$html = $content_filter_html . $html . '</div>';
} }
return $html; return $html;

View file

@ -0,0 +1,22 @@
{{if count($reasons) > 1}}
<ul class="content-filter-reasons">
{{foreach $reasons as $reason}}
<li>{{$reason|escape:html}}</li>
{{/foreach}}
</ul>
<p>
<button type="button" id="content-filter-wrap-{{$rnd}}" class="btn btn-default btn-small content-filter-button" onclick="openClose('content-filter-{{$rnd}}');">
<i class="glyphicon glyphicon-eye-open"></i> {{$openclose}}
</button>
</p>
{{else}}
<p>
{{$reasons.0|escape:html}}
<button type="button" id="content-filter-wrap-{{$rnd}}" class="btn btn-default btn-xs content-filter-button" onclick="openClose('content-filter-{{$rnd}}');">
<i class="glyphicon glyphicon-eye-open"></i> {{$openclose}}
</button>
</p>
{{/if}}
<div id="content-filter-{{$rnd}}" class="content-filter-content" style="display: none;">
{{$html}}
</div>