From f8d8584cf8c48b0b58424db4b6842334f30b9c0f Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 28 Nov 2023 12:18:51 +0530 Subject: [PATCH 1/3] fixed issue with video shortcode on front end --- js/qsm-quiz.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index 080ed0a5f..81a14cb1e 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1485,29 +1485,30 @@ jQuery(function () { }); function qsm_check_shortcode(message = null) { - // Check if message contains a video shortcode - let videoRegex = /\[video(?:(?:\ssrc="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,3}\s*\]/g; + let videoRegex = /\[video(?:(?:\ssrc="([^"]+)")|(?:\smp4="([^"]+)")|(?:\sm4v="([^"]+)")|(?:\swebm="([^"]+)")|(?:\sogv="([^"]+)")|(?:\swmv="([^"]+)")|(?:\sflv="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,3}\s*\](.*?)\[\/video\]/g; let videoMatch = message.match(videoRegex); - + if (videoMatch) { - let videoHTML = message.replace(videoRegex, function(match, src, width, height) { - return ''; + let videoHTML = message.replace(videoRegex, function(match, src, mp4, m4v, webm, ogv, wmv, flv, width, height, content) { + const videoSource = src || mp4 || m4v || webm || ogv || wmv || flv || ''; + const videoTag = ''; + return '
' + videoTag + '
'; }); - return '
' + videoHTML + '
'; + return videoHTML; } // Check if message contains an image shortcode let imageRegex = /\[img(?:(?:\ssrc="([^"]+)")|(?:\salt="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,4}\s*\]/g; let imageMatch = message.match(imageRegex); - + if (imageMatch) { let imageHTML = message.replace(imageRegex, function(match, src, alt, width, height) { return '' + (alt || '') + ''; }); return '
' + imageHTML + '
'; } - + return message; } From ebf0f073a2dc0181476264fc4b04896f83982ee3 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 28 Nov 2023 12:28:20 +0530 Subject: [PATCH 2/3] fixed issue with video shortcode on front end --- js/qsm-quiz.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index 81a14cb1e..e140da5db 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1485,19 +1485,30 @@ jQuery(function () { }); function qsm_check_shortcode(message = null) { - // Check if message contains a video shortcode - let videoRegex = /\[video(?:(?:\ssrc="([^"]+)")|(?:\smp4="([^"]+)")|(?:\sm4v="([^"]+)")|(?:\swebm="([^"]+)")|(?:\sogv="([^"]+)")|(?:\swmv="([^"]+)")|(?:\sflv="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,3}\s*\](.*?)\[\/video\]/g; - let videoMatch = message.match(videoRegex); - + const videoAttributesRegex = /(?:\ssrc="([^"]+)")|(?:\smp4="([^"]+)")|(?:\sm4v="([^"]+)")|(?:\swebm="([^"]+)")|(?:\sogv="([^"]+)")|(?:\swmv="([^"]+)")|(?:\sflv="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")/g; + const videoContentRegex = /\[video(?:(?:\s(?:src|mp4|m4v|webm|ogv|wmv|flv|width|height)="[^"]*")*)\](.*?)\[\/video\]/g; + + let videoMatch = message.match(videoContentRegex); + if (videoMatch) { - let videoHTML = message.replace(videoRegex, function(match, src, mp4, m4v, webm, ogv, wmv, flv, width, height, content) { - const videoSource = src || mp4 || m4v || webm || ogv || wmv || flv || ''; - const videoTag = ''; - return '
' + videoTag + '
'; + let videoHTML = message.replace(videoContentRegex, function(match, content) { + let attributesMatch; + let src = ''; + let width = ''; + let height = ''; + + while ((attributesMatch = videoAttributesRegex.exec(match)) !== null) { + src = src || attributesMatch[1] || attributesMatch[2] || attributesMatch[3] || attributesMatch[4] || attributesMatch[5] || attributesMatch[6] || attributesMatch[7] || ''; + width = width || attributesMatch[8] || ''; + height = height || attributesMatch[9] || ''; + } + + const videoTag = ``; + return `
${videoTag}
`; }); return videoHTML; } - + // Check if message contains an image shortcode let imageRegex = /\[img(?:(?:\ssrc="([^"]+)")|(?:\salt="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,4}\s*\]/g; let imageMatch = message.match(imageRegex); From 5b084a4d3464c43b407a5619f00f02784d4d990a Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 28 Nov 2023 12:34:58 +0530 Subject: [PATCH 3/3] fixed issue with video shortcode on front end --- js/qsm-quiz.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index e140da5db..28becd64c 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1485,23 +1485,37 @@ jQuery(function () { }); function qsm_check_shortcode(message = null) { - const videoAttributesRegex = /(?:\ssrc="([^"]+)")|(?:\smp4="([^"]+)")|(?:\sm4v="([^"]+)")|(?:\swebm="([^"]+)")|(?:\sogv="([^"]+)")|(?:\swmv="([^"]+)")|(?:\sflv="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")/g; - const videoContentRegex = /\[video(?:(?:\s(?:src|mp4|m4v|webm|ogv|wmv|flv|width|height)="[^"]*")*)\](.*?)\[\/video\]/g; - + const videoAttributePatterns = [ + /\ssrc="([^"]+)"/, + /\smp4="([^"]+)"/, + /\sm4v="([^"]+)"/, + /\swebm="([^"]+)"/, + /\sogv="([^"]+)"/, + /\swmv="([^"]+)"/, + /\sflv="([^"]+)"/, + /\swidth="(\d+)"/, + /\sheight="(\d+)"/ + ]; + + const videoContentRegex = /\[video(?:\s(?:src|mp4|m4v|webm|ogv|wmv|flv|width|height)="[^"]*")*\](.*?)\[\/video\]/g; let videoMatch = message.match(videoContentRegex); if (videoMatch) { let videoHTML = message.replace(videoContentRegex, function(match, content) { - let attributesMatch; let src = ''; let width = ''; let height = ''; - while ((attributesMatch = videoAttributesRegex.exec(match)) !== null) { - src = src || attributesMatch[1] || attributesMatch[2] || attributesMatch[3] || attributesMatch[4] || attributesMatch[5] || attributesMatch[6] || attributesMatch[7] || ''; - width = width || attributesMatch[8] || ''; - height = height || attributesMatch[9] || ''; - } + videoAttributePatterns.forEach(pattern => { + if (!src) { + const attrMatch = match.match(pattern); + if (attrMatch) { + src = attrMatch[1] || ''; + if (pattern.toString().includes('width')) width = attrMatch[1] || ''; + if (pattern.toString().includes('height')) height = attrMatch[1] || ''; + } + } + }); const videoTag = ``; return `
${videoTag}
`;