swisnl / avg-safe-iframes
Fix iframe elements in order to comply to AVG
1.0.0
2018-05-28 13:44 UTC
Requires
- php: >=7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.11
- phpunit/phpunit: >=5.4.3
This package is auto-updated.
Last update: 2024-11-29 04:25:17 UTC
README
This package will look for <iframe>
-elements in a HTML-snippet, and "fix" it in order to play nicely with our cookiebar.
Install
composer require swisnl/avg-safe-iframes
What it does
- Replace the src-attribute with data-src (so the iframe won't load right away)
- Adds a class to the element (
cookie-settings-*
), so the cookiebar knows if it complies with the users preferences. The default class is for tracking-cookies.
How to use it
Via the class:
$avgSafeIframe = new \Swis\AvgSafeIframes\AvgSafeIframes();
$text = '<div><iframe class="foo-bar" src="http:///www.example.com"></iframe></div>';
return $avgSafeIframe->fix($text);
// <div><iframe class="foo-bar cookie-settings-tracking" data-src="http:///www.example.com"></iframe></div>
Via the helper (in a blade-template, for example):
{!! safeAvgIframes($text) !!}
In both scenario's, you could provide a second parameter to add a different class. Please use one of the AvgSafeIframes::MODE*_
constants:
MODE_TRACKING
MODE_STATS
MODE_STATS_AND_TRACKING
Todo
- Add a (Laravel) middleware so you won't have to manually use the helper