basic support for video alt-text

This commit is contained in:
Mike Macgirvin 2024-06-24 20:36:54 +10:00
parent 485935ffe6
commit b73e9f7c35
2 changed files with 29 additions and 2 deletions

View file

@ -168,7 +168,28 @@ function videowithopts($match)
$poster = 'poster="' . (($zrl) ? zid($matches[1]) : $matches[1]) . '"';
}
return '<video ' . $poster . ' controls="controls" preload="none" src="' . str_replace(' ', '%20', $link) . '" style="width:100%; max-width:100%;"><a href="' . str_replace(' ', '%20', $link) . '">' . $link . '</a></video>';
$x = preg_match("/title='(.*?)'/ism", $attributes, $matches);
if ($x) {
$title = $matches[1];
}
$x = preg_match("/title=\&quot\;(.*?)\&quot\;/ism", $attributes, $matches);
if ($x) {
$title = $matches[1];
}
// This regex permits backslash-quote escapes inside the alt text.
$x = preg_match('/title="([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"/ism', $attributes, $matches);
if ($x) {
$title = $matches[1];
}
$title = (($title)
? 'title="' . htmlspecialchars(str_replace('\\"', '"', $title), ENT_QUOTES, 'UTF-8', false) . '"'
: '');
return '<video ' . $poster . $title . ' controls="controls" preload="none" src="' . str_replace(' ', '%20', $link) . '" style="width:100%; max-width:100%;"><a href="' . str_replace(' ', '%20', $link) . '">' . $link . '</a></video>';
}
// [noparse][i]italic[/i][/noparse] turns into

View file

@ -4730,7 +4730,13 @@ class Activity
}
if (array_key_exists('type', $a) && stripos($a['type'], 'video') !== false) {
if (self::media_not_in_body($a['href'], $item['body'])) {
$item['body'] .= "\n\n" . '[video]' . $a['href'] . '[/video]';
if (isset($a['name']) && $a['name']) {
$alt = htmlspecialchars($a['name'], ENT_QUOTES, 'UTF-8', false);
$alt = str_replace(['[', ']'], ['&#xFF3B;', '&#xFF3D;'], $alt);
$item['body'] .= "\n\n" . '[video title="' . $alt . '"]' . $a['href'] . '[/img]';
} else {
$item['body'] .= "\n\n" . '[video]' . $a['href'] . '[/video]';
}
}
}
if (array_key_exists('type', $a) && stripos($a['type'], 'audio') !== false) {