- $prep_arr = ['item' => $item, 'html' => $s];
- Addon::callHooks('prepare_body_final', $prep_arr);
+ $hook_data = ['item' => $item, 'html' => $s];
+ Addon::callHooks('prepare_body_final', $hook_data);
+
+ return $hook_data['html'];
+}
+
+/**
+ * Given a HTML text and a set of filtering reasons, adds a content hiding header with the provided reasons
+ *
+ * Reasons are expected to have been translated already.
+ *
+ * @param string $html
+ * @param array $reasons
+ * @return string
+ */
+function apply_content_filter($html, array $reasons)
+{
+ if (count($reasons)) {
+ $rnd = random_string(8);
+ $content_filter_html = '<ul class="content-filter-reasons">';
+ foreach ($reasons as $reason) {
+ $content_filter_html .= '<li>' . htmlspecialchars($reason) . '</li>' . PHP_EOL;
+ }
+ $content_filter_html .= '</ul>
+ <p><span id="content-filter-wrap-' . $rnd . '" class="fakelink content-filter-button" onclick=openClose(\'content-filter-' . $rnd . '\'); >' .
+ L10n::t('Click to open/close') .
+ '</span></p>
+ <div id="content-filter-' . $rnd . '" class="content-filter-content" style="display: none;">';
+
+ $html = $content_filter_html . $html . '</div>';
+ }