From 3b413222a5d286e8fa5db37c32fad693ab7423ee Mon Sep 17 00:00:00 2001 From: abemillett <31320481+abemillett@users.noreply.github.com> Date: Tue, 3 Jul 2018 16:31:32 -0400 Subject: [PATCH] updated module to handle URL fields If the field that is passed contains no spaces, ie is a URL field or similar, do not check for
tag when replacing video url's. --- TextformatterVideoEmbed.module | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/TextformatterVideoEmbed.module b/TextformatterVideoEmbed.module index 6e30bbe..5cd1cba 100644 --- a/TextformatterVideoEmbed.module +++ b/TextformatterVideoEmbed.module @@ -159,8 +159,12 @@ class TextformatterVideoEmbed extends Textformatter implements ConfigurableModul && strpos($str, '://www.youtube.com/v/') === false && strpos($str, '://youtu.be/') === false) return; - // 1: full URL 2:video id 3: query string (optional) - $regex = '#
\s*(https?://(?:www\.)?youtu(?:.be|be.com)+/(?:watch/?\?v=|v/)?([^\s&<\'"]+))(&[-_,.=&;a-zA-Z0-9]*)?.*?
#'; + // Does the given string contain ONLY a URL? Else, search for a URL contained in a+ $regexBase = '(https?://(?:www\.)?youtu(?:.be|be.com)+/(?:watch/?\?v=|v/)?([^\s&<\'"]+))(&[-_,.=&;a-zA-Z0-9]*)?'; + $regex = (strpos($str, ' ') === false) + ? '#'.$regexBase.'#' + : '#
\s*'.$regexBase.'.*?
#'; + if(!preg_match_all($regex, $str, $matches)) return; foreach($matches[0] as $key => $line) { @@ -196,7 +200,13 @@ class TextformatterVideoEmbed extends Textformatter implements ConfigurableModul if(strpos($str, '://vimeo.com/') === false) return; - if(!preg_match_all('#\s*(https?://vimeo.com/(\d+)).*?
#', $str, $matches)) return; + // Does the given string contain ONLY a URL? Else, search for a URL contained in a+ $regexBase = '(https?://vimeo.com/(\d+))'; + $regex = (strpos($str, ' ') === false) + ? '#'.$regexBase.'#' + : '#
\s*'.$regexBase.'.*?
#'; + + if(!preg_match_all($regex, $str, $matches)) return; foreach($matches[0] as $key => $line) {