OPPG-413: Enable caching, fill default tag list for HTML validation
parent
35e2623e1b
commit
d2e3558927
|
@ -1169,12 +1169,27 @@ class H5PContentValidator {
|
||||||
*/
|
*/
|
||||||
public function validateText(&$text, $semantics) {
|
public function validateText(&$text, $semantics) {
|
||||||
if ($semantics->widget && $semantics->widget == 'html') {
|
if ($semantics->widget && $semantics->widget == 'html') {
|
||||||
// FIXME: Implicit tags added in javascript are NOT vissible in
|
// Build allowed tag list, based in $semantics->tags and known defaults.
|
||||||
// $semantics->tags (such as mathml etc). Need to include defaults.
|
// These four are always allowed.
|
||||||
$allowedtags = '<div>';
|
$tags = array('div', 'span', 'p', 'br');
|
||||||
if ($semantics->tags) {
|
if (isset($semantics->tags)) {
|
||||||
$allowedtags = implode('', array_map(array($this, 'bracketTags'), $semantics->tags));
|
$tags = array_merge($tags, $semantics->tags);
|
||||||
|
// Add related tags for table etc.
|
||||||
|
if (in_array('table', $semantics->tags)) {
|
||||||
|
$tags = array_merge($tags, array('tr', 'td', 'th', 'colgroup', 'thead', 'tbody', 'tfoot'));
|
||||||
}
|
}
|
||||||
|
if (in_array('b', $semantics->tags)) {
|
||||||
|
$tags[] = 'strong';
|
||||||
|
}
|
||||||
|
if (in_array('i', $semantics->tags)) {
|
||||||
|
$tags[] = 'em';
|
||||||
|
}
|
||||||
|
if (in_array('ul', $semantics->tags) || in_array('ol', $semantics->tags)) {
|
||||||
|
$tags[] = 'li';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$allowedtags = implode('', array_map(array($this, 'bracketTags'), $tags));
|
||||||
|
|
||||||
// Strip invalid HTML tags.
|
// Strip invalid HTML tags.
|
||||||
$text = strip_tags($text, $allowedtags);
|
$text = strip_tags($text, $allowedtags);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue