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

Bugfix/59 ckeditor video embed #12675

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- HTML Purifier now allows `oembed` tags. ([ckeditor#59](https://github.com/craftcms/ckeditor/issues/59))
- Added `craft\htmlpurifier\VideoEmbedUrlDef`.
- Fixed a bug where entries that aren’t propagated to the primary site weren’t showing revision notes. ([#12641](https://github.com/craftcms/cms/issues/12641))
- Fixed a bug where HTML tags weren’t getting stripped from auto-generated Handle and URI Format setting values.
- Fixed a JavaScript error that could occur if an object with `null `values was passed to `Craft.compare()`.
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/HtmlPurifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace craft\helpers;

use craft\htmlpurifier\VideoEmbedUrlDef;
use HTMLPurifier_Config;

/**
Expand Down Expand Up @@ -71,6 +72,9 @@ public static function configure($config)

// https://github.com/ezyang/htmlpurifier/issues/152#issuecomment-414192516
$def->addAttribute('a', 'download', 'URI');

$def->addElement('oembed', 'Block', 'Inline', 'Common');
$def->addAttribute('oembed', 'url', new VideoEmbedUrlDef());
}
}
}
31 changes: 31 additions & 0 deletions src/htmlpurifier/VideoEmbedUrlDef.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\htmlpurifier;

use HTMLPurifier_AttrDef_URI;

/**
* Class VideoEmbedUrlDef
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 3.7.66
*/
class VideoEmbedUrlDef extends HTMLPurifier_AttrDef_URI
{
public function validate($uri, $config, $context)
{
$regexp = $config->get('URI.SafeIframeRegexp');
if ($regexp !== null) {
if (!preg_match($regexp, $uri)) {
return false;
}
}

return parent::validate($uri, $config, $context);
}
}