Skip to content

Conversation

martinyde
Copy link
Contributor

@martinyde martinyde commented Oct 8, 2025

Includes

  • Base functionality with a new itk_video field type
  • Support for Videotool and Vimeo
  • Support for CookieInformation.com
  • Config page.
Skærmbillede 2025-10-09 kl  08 32 33 Skærmbillede 2025-10-09 kl  08 32 51 Skærmbillede 2025-10-09 kl  08 33 12

@martinyde martinyde requested a review from rimi-itk October 9, 2025 07:42
Copy link
Contributor

@rimi-itk rimi-itk left a comment

Choose a reason for hiding this comment

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

I think this works, but some parts are hard to understand. Some comments added and questions asked.

$requiredCookies = $supportedProviders[$providerKey]['requiredCookies'];

if (!empty($requiredCookies) && isset($videoArray['iframe'])) {
$videoArray['iframe'] = str_replace(' src="', ' src="" data-category-consent="' . $requiredCookies . '" data-consent-src="', $videoArray['iframe']);
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably works, but it makes a lot of assumptions on the structure of the iframe HTML.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does assume there is a ' src="' attribute. What would be a better approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

Using string replacements to manipulate HTML/XML is never the best solution. If the oEmbed provider suddenly returns something that not a iframe element or starts returning something that contains more than one src attribute, the replacement will not work as expected.

The best way to do the manipulations would be to use https://www.php.net/manual/en/class.dom-htmldocument.php to load the HTML and then use DOM operations to add/change/remove attributes. This would also make it easy to check that we actually have an iframe element and report an error (like “Unhandled oEmbed code”, say) if not.

Using HTMLDocument will require a little more work (programming), but makes the solution much more clear, e.g. something along the lines of

function consentifyOEmmed(string $content, array $requiredCookies) {
    $dom = \Dom\HTMLDocument::createFromString('<!DOCTYPE html><html><body>'.$content.'</body></html');
    $element = $dom->body->firstElementChild;

    if ('IFRAME' === $element->nodeName && $element->hasAttribute('src')) {
        $src = $element->getAttribute('src');
        $element->setAttribute('src', '');
        $element->setAttribute('data-consent-src', $src);
        $element->setAttribute('data-category-consent', implode(' ', $requiredCookies));
    } else {
        die(sprintf("Unhandled oEmbed code: %s\n", $content));
    }

    return $dom->saveHtml($element);
}

martinyde and others added 7 commits October 20, 2025 08:30
Co-authored-by: Mikkel Ricky <rimi@aarhus.dk>
Co-authored-by: Mikkel Ricky <rimi@aarhus.dk>
Co-authored-by: Mikkel Ricky <rimi@aarhus.dk>
Co-authored-by: Mikkel Ricky <rimi@aarhus.dk>
Co-authored-by: Mikkel Ricky <rimi@aarhus.dk>
Co-authored-by: Mikkel Ricky <rimi@aarhus.dk>
@martinyde martinyde requested a review from rimi-itk October 20, 2025 08:24
$requiredCookies = $supportedProviders[$providerKey]['requiredCookies'];

if (!empty($requiredCookies) && isset($videoArray['iframe'])) {
$videoArray['iframe'] = str_replace(' src="', ' src="" data-category-consent="' . $requiredCookies . '" data-consent-src="', $videoArray['iframe']);
Copy link
Contributor

Choose a reason for hiding this comment

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

Using string replacements to manipulate HTML/XML is never the best solution. If the oEmbed provider suddenly returns something that not a iframe element or starts returning something that contains more than one src attribute, the replacement will not work as expected.

The best way to do the manipulations would be to use https://www.php.net/manual/en/class.dom-htmldocument.php to load the HTML and then use DOM operations to add/change/remove attributes. This would also make it easy to check that we actually have an iframe element and report an error (like “Unhandled oEmbed code”, say) if not.

Using HTMLDocument will require a little more work (programming), but makes the solution much more clear, e.g. something along the lines of

function consentifyOEmmed(string $content, array $requiredCookies) {
    $dom = \Dom\HTMLDocument::createFromString('<!DOCTYPE html><html><body>'.$content.'</body></html');
    $element = $dom->body->firstElementChild;

    if ('IFRAME' === $element->nodeName && $element->hasAttribute('src')) {
        $src = $element->getAttribute('src');
        $element->setAttribute('src', '');
        $element->setAttribute('data-consent-src', $src);
        $element->setAttribute('data-category-consent', implode(' ', $requiredCookies));
    } else {
        die(sprintf("Unhandled oEmbed code: %s\n", $content));
    }

    return $dom->saveHtml($element);
}

@martinyde martinyde merged commit 7a84d33 into develop Oct 20, 2025
8 checks passed
@martinyde martinyde deleted the release/first_version branch October 20, 2025 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants