-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task #771 - Embed video block added #830
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very happy with this, looks like it was just copied over without any adaptation to the rest of the current FE libs components.
Please resolve all the comments, and:
- use components from FE libs so the UI/UX matches the rest of components
- fix all textdomains, they can't be
safer-internet
, should be'%g_textdomain%'
} | ||
}, | ||
"variables": { | ||
"embedAlign": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The align option is not needed
const embedClass = classnames([ | ||
selector(componentClass, componentClass), | ||
selector(blockClass, blockClass, selectorClass), | ||
selector(additionalClass, additionalClass), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const embedClass = classnames([ | |
selector(componentClass, componentClass), | |
selector(blockClass, blockClass, selectorClass), | |
selector(additionalClass, additionalClass), | |
]); | |
const embedClass = classnames( | |
componentClass, | |
bem(blockClass, selectorClass), | |
additionalClass | |
); |
Import classnames
and bem
from Frontend libs
const embedIframeClass = classnames([ | ||
selector(componentClass, componentClass, 'iframe'), | ||
selector(blockClass, blockClass, `${selectorClass}-iframe`), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const embedIframeClass = classnames([ | |
selector(componentClass, componentClass, 'iframe'), | |
selector(blockClass, blockClass, `${selectorClass}-iframe`), | |
]); | |
const embedIframeClass = classnames( | |
selector(componentClass, 'iframe'), | |
selector(blockClass, `${selectorClass}-iframe`), | |
); |
if (embedUrl.includes('https://www.youtube.com/watch?v=')) { | ||
embedUrl = embedUrl.replace('watch?v=', 'embed/'); | ||
} | ||
|
||
if (embedUrl.includes('https://vimeo.com')) { | ||
const matches = [...embedUrl.matchAll(/https:\/\/vimeo\.com\/(\d+)/g)]; | ||
|
||
const videoId = matches[0][1] ?? ''; | ||
embedUrl = `https://player.vimeo.com/video/${videoId}`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed so any embed link can work, not only YouTube and Vimeo.
return ( | ||
<> | ||
{embedUse && | ||
<> | ||
{(embedUrl === '') ? | ||
<Placeholder icon={video} label={__('Please add embed using sidebar options!', 'safer-internet')} /> : | ||
<div className={embedClass}> | ||
<iframe | ||
title={'video'} | ||
className={embedIframeClass} | ||
src={embedUrl} | ||
/> | ||
</div> | ||
} | ||
</> | ||
} | ||
</> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is pretty messy, please clean it up
.embed { | ||
position: relative; | ||
width: 100%; | ||
overflow: hidden; | ||
padding-top: 56.25%; | ||
|
||
&__iframe { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
border: 0; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rework this so it doesn't use the old aspect ratio hack, we've had aspect-ratio
in all browsers for 3 years now...
$embedClass = Helpers::classnames([ | ||
Helpers::selector($componentClass, $componentClass), | ||
Helpers::selector($blockClass, $blockClass, $selectorClass), | ||
Helpers::selector($additionalClass, $additionalClass), | ||
]); | ||
|
||
$embedIframeClass = Helpers::classnames([ | ||
Helpers::selector($componentClass, $componentClass, "iframe"), | ||
Helpers::selector($blockClass, $blockClass, "{$selectorClass}-iframe"), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$embedClass = Helpers::classnames([ | |
Helpers::selector($componentClass, $componentClass), | |
Helpers::selector($blockClass, $blockClass, $selectorClass), | |
Helpers::selector($additionalClass, $additionalClass), | |
]); | |
$embedIframeClass = Helpers::classnames([ | |
Helpers::selector($componentClass, $componentClass, "iframe"), | |
Helpers::selector($blockClass, $blockClass, "{$selectorClass}-iframe"), | |
]); | |
$embedClass = Helpers::classnames([ | |
$componentClass, | |
Helpers::selector($blockClass, $blockClass, $selectorClass), | |
$additionalClass, | |
]); | |
$embedIframeClass = Helpers::classnames([ | |
Helpers::selector($componentClass, $componentClass, "iframe"), | |
Helpers::selector($blockClass, $blockClass, "{$selectorClass}-iframe"), | |
]); |
/** | ||
* YouTube provider | ||
* | ||
* The link | ||
* https://www.youtube.com/watch?v=dQw4w9WgXcQ | ||
* will be transformed to | ||
* https://www.youtube.com/embed/dQw4w9WgXcQ . | ||
*/ | ||
if (strpos($embedUrl, 'https://www.youtube.com/watch?v=') !== false) { | ||
$embedUrl = str_replace('watch?v=', 'embed/', $embedUrl); | ||
} | ||
|
||
/** | ||
* Vimeo provider | ||
* | ||
* The link | ||
* https://vimeo.com/642263700 | ||
* will be transformed to | ||
* https://player.vimeo.com/video/642263700 . | ||
*/ | ||
if (strpos($embedUrl, 'https://vimeo.com') !== false) { | ||
preg_match_all('/https:\/\/vimeo\.com\/(\d+)/', $embedUrl, $matches); | ||
|
||
$videoId = $matches[1][0] ?? ''; | ||
$embedUrl = "https://player.vimeo.com/video/{$videoId}"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace this so it can work with any site.
Note
For videos, WordPress does have a built-in function for this, but it's very bad for performance. Find a solution to store its output if you're planning to use it.
However, we should probably not support only videos.
|
||
?> | ||
|
||
<div class="<?php echo esc_attr($embedClass); ?>"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need a wrapping div
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The div is used for video position
const embedAlign = checkAttr('embedAlign', attributes, manifest); | ||
|
||
return ( | ||
<MatrixAlignControl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this
@goranalkovic-infinum Thank you for the suggestions. The PR is not yet ready for review. I will inform you when it is. |
|
||
export const EmbedOptions = ({ attributes, setAttributes }) => { | ||
return ( | ||
<PanelBody title={__('Embed', 'safer-internet')}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong text domain
} | ||
|
||
/** Add style to WP core embed block **/ | ||
.wp-block-embed__wrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this used for?
/** | ||
* Template for the Embed Block view. | ||
* | ||
* @package SaferInternet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong text domain
Description
Use the Embed Video Block to seamlessly embed videos. Paste the video’s embed URL (e.g., https://www.youtube.com/embed/dQwsxXcQ), and the block will display the video directly on your site.
Screenshots / Videos
Task
https://app.productive.io/1-infinum/time/me/task/8267996?tour=day-view-layout