Last active
          September 3, 2024 15:01 
        
      - 
      
- 
        Save annelyse/52da76027098b9d72cb0e9bae5dab907 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | addEventListener("DOMContentLoaded", (event) => { | |
| console.log(window._axcb); | |
| (_axcb = window._axcb || []).push(function(sdk) { | |
| sdk.on('cookies:complete', function(choices) { | |
| document | |
| .querySelectorAll('[data-hide-on-vendor-consent]') | |
| .forEach(el => { | |
| const vendor = el.getAttribute('data-hide-on-vendor-consent'); | |
| el.style.display = choices[vendor] ? 'none' : 'inherit'; | |
| }); | |
| document | |
| .querySelectorAll('[data-requires-vendor-consent]') | |
| .forEach(el => { | |
| const vendor = el.getAttribute('data-requires-vendor-consent'); | |
| if (choices[vendor]) { | |
| iframe = el.querySelector("iframe"); | |
| iframe.setAttribute('src', iframe.getAttribute('data-src')); | |
| el.removeAttribute('data-requires-vendor-consent'); | |
| el.setAttribute('data-vendor-consent-accepted', ''); | |
| } | |
| }); | |
| }); | |
| }); | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // videos blocked by cookie consent | |
| [data-requires-vendor-consent] { | |
| .cookie_alert { | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| background-color: rgba(0, 0, 0, 0.05); | |
| border: 1px solid #ccc; | |
| padding: 40px; | |
| border-radius: 4px; | |
| min-height: 300px; | |
| flex-direction: column; | |
| position: absolute; | |
| z-index: 2; | |
| /* Assurez-vous que la hauteur minimale soit définie */ | |
| } | |
| } | |
| [data-vendor-consent-accepted] { | |
| .cookie_alert { | |
| display: none; | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //BLOCK gutemberg EMBED VIDEO, rendu RGPD Friendly avec tarte au citron | |
| add_filter('render_block', 'wrap_my_image_block', 10, 2); | |
| function wrap_my_image_block($block_content, $block) | |
| { | |
| if (!is_admin()) { | |
| if ('core/embed' == $block['blockName']) { | |
| if ($block["attrs"]['providerNameSlug'] == 'youtube' || $block["attrs"]['providerNameSlug'] == 'vimeo') { | |
| $type_player = ''; | |
| $videoId = ''; | |
| $data_src = ''; | |
| if (isset($block["attrs"]['url'])) { | |
| if ($block["attrs"]['providerNameSlug'] == 'youtube') { | |
| $type_player = 'youtube_player'; | |
| $url = $block["attrs"]['url']; | |
| parse_str(parse_url($url, PHP_URL_QUERY), $my_array_of_vars); | |
| $videoId = $my_array_of_vars['v']; | |
| $data_src = 'https://www.youtube.com/embed/' . $videoId ; | |
| } elseif ($block["attrs"]['providerNameSlug'] == 'vimeo') { | |
| $type_player = 'vimeo_player'; | |
| $url = $block["attrs"]['url']; | |
| $videoId = getVimeoVideoIdFromUrl($url); | |
| $data_src = 'https://player.vimeo.com/video/' . $videoId; | |
| } | |
| } | |
| $className = ''; | |
| if (empty($block["attrs"]['className'])) { | |
| $className = 'wp-embed-aspect-16-9 wp-has-aspect-ratio'; | |
| } else { | |
| $className = $block["attrs"]['className']; | |
| } | |
| // gestion de la légende | |
| $html = $block['innerHTML']; | |
| preg_match_all('/<figcaption>(.*?)<\/figcaption>/s', $html, $match); | |
| $legende = ''; | |
| if (!empty($match[0])) { | |
| $legende = $match[0][0]; | |
| } | |
| $typeVideo = $block["attrs"]['providerNameSlug']; | |
| $return = '<div data-requires-vendor-consent="' . $typeVideo . '" class="' . $className . '" ><div data-hide-on-vendor-consent="' . $typeVideo . '" class="cookie_alert"><p>Cette vidéo a été bloqué.</p> <p>Pour pouvoir lire la video, veuillez accepter les cookies ' . $typeVideo . '</p><button class="btn btn-primary-light" onclick="window.axeptioSDK.requestConsent(\'youtube\')">Accepter les cookies</button></div><div class="wp-block-embed__wrapper"><iframe class="' . $type_player . '" data-src="' . $data_src . '" videoID="' . $videoId . '" width="100%" height="auto" theme="dark" rel="1" controls="1" showinfo="1" autoplay="0" mute="mute" loop="0" loading="1"></iframe></div>' . $legende . '</div>'; | |
| return $return; | |
| } else { | |
| return $block_content; | |
| } | |
| } | |
| } | |
| return $block_content; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment