Skip to content
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

Closed
wants to merge 11 commits into from

Conversation

DjidjaleskaSandra
Copy link

@DjidjaleskaSandra DjidjaleskaSandra commented Jun 13, 2024

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

Screenshot 2024-06-13 at 23 05 40

Task

https://app.productive.io/1-infinum/time/me/task/8267996?tour=day-view-layout

@DjidjaleskaSandra DjidjaleskaSandra added the feature request New feature request label Jun 13, 2024
@DjidjaleskaSandra DjidjaleskaSandra self-assigned this Jun 13, 2024
Copy link
Contributor

@goranalkovic-infinum goranalkovic-infinum left a 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": {
Copy link
Contributor

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

Comment on lines 23 to 27
const embedClass = classnames([
selector(componentClass, componentClass),
selector(blockClass, blockClass, selectorClass),
selector(additionalClass, additionalClass),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines 29 to 32
const embedIframeClass = classnames([
selector(componentClass, componentClass, 'iframe'),
selector(blockClass, blockClass, `${selectorClass}-iframe`),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const embedIframeClass = classnames([
selector(componentClass, componentClass, 'iframe'),
selector(blockClass, blockClass, `${selectorClass}-iframe`),
]);
const embedIframeClass = classnames(
selector(componentClass, 'iframe'),
selector(blockClass, `${selectorClass}-iframe`),
);

Comment on lines 34 to 43
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}`;
}
Copy link
Contributor

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.

Comment on lines 45 to 62
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>
}
</>
}
</>
);
Copy link
Contributor

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

Comment on lines 1 to 15
.embed {
position: relative;
width: 100%;
overflow: hidden;
padding-top: 56.25%;

&__iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
}
Copy link
Contributor

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...

Comment on lines 31 to 40
$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"),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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"),
]);

Comment on lines 50 to 75
/**
* 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}";
}
Copy link
Contributor

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); ?>">
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this

@DjidjaleskaSandra
Copy link
Author

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%'

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%'

@goranalkovic-infinum Thank you for the suggestions. The PR is not yet ready for review. I will inform you when it is.

@DjidjaleskaSandra DjidjaleskaSandra marked this pull request as draft June 13, 2024 11:44
@DjidjaleskaSandra DjidjaleskaSandra marked this pull request as ready for review June 13, 2024 21:14

export const EmbedOptions = ({ attributes, setAttributes }) => {
return (
<PanelBody title={__('Embed', 'safer-internet')}>
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong text domain

@iruzevic iruzevic closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants