diff --git a/fp-plugins/bbcode/plugin.bbcode.php b/fp-plugins/bbcode/plugin.bbcode.php index 839b2341..85d727c3 100644 --- a/fp-plugins/bbcode/plugin.bbcode.php +++ b/fp-plugins/bbcode/plugin.bbcode.php @@ -193,6 +193,50 @@ function plugin_bbcode_normalize_dimension($value) { return (int) $value; } +/** + * Escapes a value for use inside an HTML attribute. + * + * @param mixed $value + * @return string + */ +function plugin_bbcode_escape_html_attribute($value) { + return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); +} + +/** + * Normalizes a [video] width/height attribute to a positive integer string. + * + * @param mixed $value + * @param string $fallback + * @return string + */ +function plugin_bbcode_video_dimension($value, $fallback) { + $dimension = plugin_bbcode_normalize_dimension($value); + return $dimension > 0 ? (string) $dimension : $fallback; +} + +/** + * Returns a safe CSS class suffix for [video] float positioning. + * + * @param mixed $value + * @return string + */ +function plugin_bbcode_video_float_class($value) { + if (!is_scalar($value)) { + return 'nofloat'; + } + + $value = strtolower(trim((string) $value)); + $allowed = array( + 'left' => true, + 'right' => true, + 'center' => true, + 'nofloat' => true + ); + + return isset($allowed [$value]) ? $value : 'nofloat'; +} + /** * Build an inline style override for explicit image dimensions if responsive theme CSS * would otherwise override the requested height. @@ -584,9 +628,9 @@ function do_bbcode_video($action, $attr, $content, $params, $node_object) { } // Check the [video] element's attributes width, height and float - $width = isset($attr ['width']) ? $attr ['width'] : '560'; - $height = isset($attr ['height']) ? $attr ['height'] : '315'; - $floatClass = isset($attr ['float']) ? $attr ['float'] : 'nofloat'; + $width = isset($attr ['width']) ? plugin_bbcode_video_dimension($attr ['width'], '560') : '560'; + $height = isset($attr ['height']) ? plugin_bbcode_video_dimension($attr ['height'], '315') : '315'; + $floatClass = isset($attr ['float']) ? plugin_bbcode_video_float_class($attr ['float']) : 'nofloat'; $query = array(); if (array_key_exists('query', $vurl)) { @@ -607,7 +651,7 @@ function do_bbcode_video($action, $attr, $content, $params, $node_object) { case 'youtube': $output = '
' . // '