Initial commit: Atomaste website

This commit is contained in:
2025-12-10 12:17:30 -05:00
commit 0b9e5d1605
19260 changed files with 5206382 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_addthis_script' );
function cmplz_addthis_script( $tags ) {
$tags[] = array(
'name' => 'addthis',
'category' => 'marketing',
'urls' => array(
'addthis.com',
),
);
return $tags;
}

View File

@@ -0,0 +1,18 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_style_tags', 'cmplz_adobe_fonts' );
function cmplz_adobe_fonts( $tags ) {
$tags[] = array(
'name' => 'adobe-fonts',
'category' => 'marketing',
'urls' => array(
'use.typekit.net',
'p.typekit.net',
),
'enable_placeholder' => '0',
'dependency' => '0',
);
return $tags;
}

View File

@@ -0,0 +1,26 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_calendly_script' );
function cmplz_calendly_script( $tags ) {
$tags[] = array(
'name' => 'calendly',
'category' => 'marketing',
'placeholder' => 'calendly',
'urls' => array(
'assets.calendly.com',
'calendly.com',
),
'enable_placeholder' => '1',
'placeholder_class' => 'calendly-inline-widget',
);
return $tags;
}
/**
* This empty function ensures Complianz recognizes that this integration has a placeholder
* @return void
*
*/
function cmplz_calendly_placeholder(){}

View File

@@ -0,0 +1,47 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_dailymotion_iframetags' );
function cmplz_dailymotion_iframetags( $tags ) {
$tags[] = array(
'name' => 'dailymotion',
'category' => 'marketing',
'placeholder' => 'dailymotion',
'urls' => array(
'dailymotion.com/embed/video/',
),
);
return $tags;
}
function cmplz_dailymotion_placeholder( $new_src, $src ) {
if ( preg_match( '/dailymotion\.com\/(embed\/video)\/([^_]+)[^#]*\?|dailymotion\.com\/(embed\/video|video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?|(dai\.ly\/([^_]+))!/i',
$src, $matches )
) {
if ( isset( $matches[6] ) ) {
$daily_motion_id = $matches[6];
} elseif ( isset( $matches[4] ) ) {
$daily_motion_id = $matches[4];
} else {
$daily_motion_id = $matches[2];
}
$new_src = cmplz_get_transient( "cmplz_dailymotion_image_$daily_motion_id" );
if ( ! $new_src || ! cmplz_file_exists_on_url( $new_src ) ) {
//pass thumbnail_60_url (60px height), thumbnail_120_url (120px height), thumbnail_180_url (180px height), thumbnail_240_url (240px height), thumbnail_360_url (360px height), thumbnail_480_url (480px height), thumbnail_720_url (720px height), thumbnail_1080_url (1080px height), for different sizes
$thumbnail_large_url = 'https://api.dailymotion.com/video/'
. $daily_motion_id
. '?fields=thumbnail_1080_url';
$json_thumbnail = file_get_contents( $thumbnail_large_url );
$arr_dailymotion = json_decode( $json_thumbnail, true );
$new_src = $arr_dailymotion['thumbnail_1080_url'];
$new_src = cmplz_download_to_site( $new_src,
'dailymotion' . $daily_motion_id );
cmplz_set_transient( "cmplz_dailymotion_image_$daily_motion_id", $new_src,
WEEK_IN_SECONDS );
}
}
return $new_src;
}
add_filter( 'cmplz_placeholder_dailymotion', 'cmplz_dailymotion_placeholder', 10, 2 );

View File

@@ -0,0 +1,14 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_disqus_script' );
function cmplz_disqus_script( $tags ) {
$tags[] = array(
'name' => 'disqus',
'category' => 'marketing',
'urls' => array(
'disqus.com',
),
);
return $tags;
}

View File

@@ -0,0 +1,37 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_facebook_script' );
function cmplz_facebook_script( $tags ) {
$tags[] = array(
'name' => 'facebook',
'category' => 'marketing',
'urls' => array(
'connect.facebook.net',
'facebook.com/plugins',
),
'placeholder' => 'facebook',
'enable_placeholder' => '1',
'placeholder_class' => 'fb-page,fb-post',
);
return $tags;
}
/**
* Add some custom css for the placeholder
*/
add_action( 'cmplz_banner_css', 'cmplz_facebook_css' );
function cmplz_facebook_css() {
?>
.cmplz-placeholder-element > blockquote.fb-xfbml-parse-ignore {
margin: 0 20px;
}
<?php
}
/**
* This empty function ensures Complianz recognizes that this integration has a placeholder
* @return void
*
*/
function cmplz_facebook_placeholder(){}

View File

@@ -0,0 +1,44 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
/**
* Do not activate if any of these plugins is active, or if the user has not explicitly chosen to block
*/
if ( !defined('CMPLZ_SELF_HOSTED_PLUGIN_ACTIVE') && cmplz_get_option('self_host_google_fonts') === 'block' ) {
add_filter( 'cmplz_known_script_tags', 'cmplz_google_fonts_script' );
add_filter( 'cmplz_known_style_tags', 'cmplz_google_fonts_style' );
}
function cmplz_google_fonts_script( $tags ) {
$tags[] = array(
'name' => 'google-fonts',
'category' => 'marketing',
'urls' => array(
'fonts.googleapis.com',
'ajax.googleapis.com/ajax/libs/webfont',
'fonts.gstatic.com',
),
'enable_placeholder' => '0',
'enable_dependency' => '1',
'dependency' => [
//'wait-for-this-script' => 'script-that-should-wait'
'fonts.googleapis.com' => 'WebFont.load',
'fonts.googleapis.' => 'WebFontConfig',
],
);
return $tags;
}
function cmplz_google_fonts_style( $tags ) {
$tags[] = array(
'name' => 'google-fonts',
'category' => 'marketing',
'urls' => array(
'fonts.googleapis.com',
'fonts.gstatic.com',
),
'enable_placeholder' => '0',
'enable_dependency' => '0',
);
return $tags;
}

View File

@@ -0,0 +1,54 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_googlemaps_script' );
function cmplz_googlemaps_script( $tags ) {
$tags[] = array(
'name' => 'google-maps',
'placeholder' => 'google-maps',
'category' => 'marketing',
'urls' => array(
'new google.maps.',
'maps.google.com',
'google.com/maps',
'apis.google.com',
'maps.google.de',
),
);
return $tags;
}
add_filter( 'cmplz_image_tags', 'cmplz_googlemaps_imagetags' );
function cmplz_googlemaps_imagetags( $tags ) {
$tags[] = 'maps.googleapis.com/maps/api/staticmap';
return $tags;
}
/**
* Declare a placeholder
* @param string $new_src
* @param string $src
*
* @return mixed|string
*/
function cmplz_google_maps_placeholder( $new_src, $src ) {
$key_pattern = '/maps\.googleapis\.com\/maps\/api\/staticmap/i';
if ( preg_match( $key_pattern, $src, $matches ) ) {
$id = str_replace(array('http://', 'https://','maps.googleapis.com/maps/api/staticmap'), '', $src);
//to prevent issues with the url as ID, we create a separate ID, and look it up by the url of this image
$new_src = cmplz_get_transient('cmplz_googlemaps_image_' . sanitize_title( $id ) );
if ( ! $new_src || ! cmplz_file_exists_on_url( $new_src ) ) {
$guid = time();
$new_src = cmplz_download_to_site( html_entity_decode( $src ), sanitize_title( 'cmplz_googlemaps_image_'.$guid ), false );
cmplz_set_transient( 'cmplz_googlemaps_image_' . sanitize_title( $id ) , $new_src, MONTH_IN_SECONDS );
}
}
return $new_src;
}
add_filter( 'cmplz_placeholder_google-maps', 'cmplz_google_maps_placeholder', 10, 2 );

View File

@@ -0,0 +1,63 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_recaptcha_script' );
function cmplz_recaptcha_script( $tags ) {
if (defined('WPCF7_VERSION') && version_compare(WPCF7_VERSION, 5.4, '>=')) return $tags;
if (cmplz_get_option('block_recaptcha_service') === 'yes'){
$tags[] = array(
'name' => 'google-recaptcha',
'placeholder' => 'google-recaptcha',
'category' => 'marketing',
'urls' => array(
'google.com/recaptcha',
'grecaptcha',
'recaptcha.js',
'recaptcha/api',
'apis.google.com/js/platform.js',
),
'enable_placeholder' => '1',
'placeholder_class' => 'recaptcha-invisible,g-recaptcha',
);
}
return $tags;
}
/**
* Add some custom css for the placeholder
*/
add_action( 'cmplz_banner_css', 'cmplz_recaptcha_css' );
function cmplz_recaptcha_css() {
if (defined('WPCF7_VERSION') && version_compare(WPCF7_VERSION, 5.4, '>=')) return;
?>
.cmplz-blocked-content-container.recaptcha-invisible,
.cmplz-blocked-content-container.g-recaptcha {
max-width: initial !important;
height: 80px !important;
margin-bottom: 20px;
}
@media only screen and (max-width: 400px) {
.cmplz-blocked-content-container.recaptcha-invisible,
.cmplz-blocked-content-container.g-recaptcha {
height: 100px !important
}
}
.cmplz-blocked-content-container.recaptcha-invisible .cmplz-blocked-content-notice,
.cmplz-blocked-content-container.g-recaptcha .cmplz-blocked-content-notice {
max-width: initial;
padding: 7px;
}
<?php
}
/**
* This empty function ensures Complianz recognizes that this integration has a placeholder
* @return void
*
*/
function cmplz_google_recaptcha_placeholder(){}

View File

@@ -0,0 +1,20 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_hotjar_script' );
function cmplz_hotjar_script( $tags ) {
/**
* hotjar should get blocked if
* - not privacy friendly or
* - privacy friendly AND Germany (eu_consent_regions = yes)
*/
if ( cmplz_get_option( 'eu_consent_regions' ) === 'yes'
|| cmplz_get_option( 'hotjar_privacyfriendly' ) !== 'yes'
) {
$tags[] = 'static.hotjar.com';
}
return $tags;
}

View File

@@ -0,0 +1,60 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_hs_tracking_script' );
function cmplz_hs_tracking_script( $tags ) {
$tags[] = 'track.hubspot.com';
$tags[] = 'js.hs-analytics.net';
return $tags;
}
/**
* Sync the Complianz banner with the hubspot banner by clicking on the apropriate buttonn when consent is given.
*/
function cmplz_hubspot_clicker() {
if ( cmplz_get_option('block_hubspot_service') === 'yes' ) {
ob_start();
?>
<script>
document.addEventListener("cmplz_enable_category", cmplzHubspotScriptHandler);
document.addEventListener("cmplz_status_change_service", cmplzHubspotScriptHandler);
document.addEventListener("cmplz_status_change", cmplzHubspotScriptHandler);
function cmplzHubspotScriptHandler(consentData) {
let hubspotAcceptBtn = document.getElementById("hs-eu-confirmation-button");
let hubspotDeclinetBtn = document.getElementById("hs-eu-decline-button");
if ( consentData.detail.category === 'marketing' ) {
if ( hubspotAcceptBtn != null ) {
hubspotAcceptBtn.click();
}
} else {
if ( hubspotDeclinetBtn != null && !consentData.detail.categories.includes("marketing") ) {
hubspotDeclinetBtn.click();
}
}
// if ( hubspotAcceptBtn ) {
// hubspotAcceptBtn.parentNode.removeChild(hubspotAcceptBtn);
// }
}
</script>
<?php
$script = ob_get_clean();
$script = str_replace(array('<script>', '</script>'), '', $script);
wp_add_inline_script( 'cmplz-cookiebanner', $script);
}
}
add_action( 'wp_enqueue_scripts', 'cmplz_hubspot_clicker', PHP_INT_MAX);
/**
* Add custom hubspot css
*/
function cmplz_hubspot_css() {
if ( cmplz_get_option('block_hubspot_service') === 'yes' ){ ?>
<style>
div#hs-eu-cookie-confirmation {display: none;}
</style>
<?php
}
}
add_action( 'wp_footer', 'cmplz_hubspot_css' );

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,45 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_instagram_script' );
function cmplz_instagram_script( $tags ) {
$tags[] = array(
'name' => 'instagram',
'placeholder' => 'instagram',
'category' => 'marketing',
'urls' => array(
'instawidget.net/js/instawidget.js',
'instagram.com',
),
'enable_placeholder' => '1',
'placeholder_class' => 'instagram-media',
);
return $tags;
}
add_filter( 'cmplz_post_scribe_tags', 'cmplz_instagram_asynclist' );
function cmplz_instagram_asynclist( $tags ) {
$tags[] = 'instawidget.net/js/instawidget.js';
return $tags;
}
/**
* Add some custom css for the placeholder
*/
add_action( 'cmplz_banner_css', 'cmplz_instagram_css' );
function cmplz_instagram_css() {
?>
.instagram-media.cmplz-placeholder-element > div {
max-width: 100%;
}
<?php
}
/**
* This empty function ensures Complianz recognizes that this integration has a placeholder
* @return void
*
*/
function cmplz_instagram_placeholder(){}

View File

@@ -0,0 +1,18 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_linkedin_script' );
function cmplz_linkedin_script( $tags ) {
$tags[] = array(
'name' => 'linkedin',
'placeholder' => 'linkedin',
'category' => 'marketing',
'urls' => array(
'platform.linkedin.com/in.js',
'linkedin.com/embed/feed/update',
),
'enable_placeholder' => '1',
'placeholder_class' => 'share-update-card',
);
return $tags;
}

View File

@@ -0,0 +1,17 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_livechat_script' );
function cmplz_livechat_script( $tags ) {
$tags[] = array(
'name' => 'livechat',
'placeholder' => 'livechat',
'category' => 'marketing',
'urls' => array(
'cdn.livechatinc.com/tracking.js',
),
);
return $tags;
}

View File

@@ -0,0 +1,56 @@
<?php
defined('ABSPATH') or die("you do not have access to this page!");
add_filter('cmplz_known_script_tags', 'cmplz_microsoftads_script');
function cmplz_microsoftads_script($tags)
{
$tags[] = 'bat.bing.com';
return $tags;
}
add_filter('cmplz_known_script_tags', 'cmplz_microsoftads_iframetags');
function cmplz_microsoftads_iframetags($tags)
{
$tags[] = 'bing.com';
return $tags;
}
function cmplz_microsoftads_uet_consent()
{
$thirdparty_services = cmplz_get_option('thirdparty_services_on_site');
$is_microsoft_ads_enabled = in_array('microsoftads', $thirdparty_services);
if ($is_microsoft_ads_enabled) {
$script = "
window.uetq = window.uetq || [];
window.uetq.push('consent', 'default', {
'ad_storage': 'denied'
});
document.addEventListener('cmplz_fire_categories', function(e) {
var consentedCategories = e.detail.categories;
let marketing = 'denied';
if (cmplz_in_array('marketing', consentedCategories)) {
marketing = 'granted';
}
window.uetq.push('consent', 'update', {
'ad_storage': marketing
});
});
document.addEventListener('cmplz_revoke', function(e) {
window.uetq.push('consent', 'update', {
'ad_storage': 'denied'
});
});
";
wp_add_inline_script('cmplz-cookiebanner', $script);
}
};
add_action('wp_enqueue_scripts', 'cmplz_microsoftads_uet_consent', PHP_INT_MAX);

View File

@@ -0,0 +1,21 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_openstreetmaps_iframetags' );
function cmplz_openstreetmaps_iframetags( $tags ) {
$tags[] = array(
'name' => 'openstreetmaps',
'placeholder' => 'openstreetmaps',
'category' => 'marketing',
'urls' => array(
'openstreetmap.org',
),
);
return $tags;
}
/**
* function to let complianz detect this integration as having placeholders.
*/
function cmplz_openstreetmaps_placeholder() {}

View File

@@ -0,0 +1,15 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_pinterest_script' );
function cmplz_pinterest_script( $tags ) {
$tags[] = array(
'name' => 'pinterest',
'category' => 'marketing',
'urls' => array(
'assets.pinterest.com',
'pinmarklet.js',
),
);
return $tags;
}

View File

@@ -0,0 +1,10 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_sharethis_script' );
function cmplz_sharethis_script( $tags ) {
$tags[] = 'sharethis.com';
return $tags;
}

View File

@@ -0,0 +1,22 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_soundcloud_iframetags' );
function cmplz_soundcloud_iframetags( $tags ) {
$tags[] = array(
'name' => 'soundcloud',
'placeholder' => 'soundcloud',
'category' => 'marketing',
'urls' => array(
'soundcloud.com/player',
),
);
return $tags;
}
/**
* function to let complianz detect this integration as having placeholders.
*/
function cmplz_soundcloud_placeholder() {}

View File

@@ -0,0 +1,22 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_spotify_iframetags' );
function cmplz_spotify_iframetags( $tags ) {
$tags[] = array(
'name' => 'spotify',
'placeholder' => 'spotify',
'category' => 'marketing',
'urls' => array(
'open.spotify.com/embed',
),
);
return $tags;
}
/**
* function to let complianz detect this integration as having placeholders.
*/
function cmplz_spotify_placeholder() {}

View File

@@ -0,0 +1,35 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_tiktok_script' );
function cmplz_tiktok_script( $tags ) {
$tags[] = array(
'name' => 'tiktok',
'placeholder' => 'tiktok',
'category' => 'marketing',
'urls' => array(
'tiktok.com',
),
'enable_placeholder' => '1',
'placeholder_class' => 'tiktok-embed',
);
return $tags;
}
/**
* Add some custom css for the placeholder
*/
add_action( 'cmplz_banner_css', 'cmplz_tiktok_css' );
function cmplz_tiktok_css() {
?>
.tiktok-embed.cmplz-placeholder-element > div { max-width: 100%;}
<?php
}
/**
* This empty function ensures Complianz recognizes that this integration has a placeholder
* @return void
*
*/
function cmplz_tiktok_placeholder(){}

View File

@@ -0,0 +1,32 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_twitch_script' );
function cmplz_twitch_script( $tags ) {
$tags[] = array(
'name' => 'twitch',
'placeholder' => 'twitch',
'category' => 'marketing',
'urls' => array(
'player.twitch.tv',
'twitch.tv',
'new Twitch.Embed',
),
'enable_placeholder' => '1',
'placeholder_class' => 'twitch-embed',
'enable_dependency' => '1',
'dependency' => [
//'wait-for-this-script' => 'script-that-should-wait'
'twitch.tv' => 'new Twitch.Embed',
],
);
return $tags;
}
/**
* This empty function ensures Complianz recognizes that this integration has a placeholder
* @return void
*
*/
function cmplz_twitch_placeholder() {}

View File

@@ -0,0 +1,51 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_twitter_script' );
function cmplz_twitter_script( $tags ) {
$tags[] = array(
'name' => 'twitter',
'placeholder' => 'twitter',
'category' => 'marketing',
'urls' => array(
'platform.twitter.com',
'twitter-widgets.js',
),
'enable_placeholder' => '1',
'placeholder_class' => 'twitter-tweet,twitter-timeline',
);
return $tags;
}
/**
* Add some custom css for the placeholder
*/
add_action( 'cmplz_banner_css', 'cmplz_twitter_css' );
function cmplz_twitter_css() {
?>
.twitter-tweet.cmplz-blocked-content-container {padding: 10px 40px;}
<?php
}
function cmplz_add_twitter_js() {
ob_start();
$script = "
let cmplzBlockedContent = document.querySelector('.cmplz-blocked-content-notice');
if ( cmplzBlockedContent) {
cmplzBlockedContent.addEventListener('click', function(event) {
event.stopPropagation();
});
}
";
ob_get_clean();
wp_add_inline_script( 'cmplz-cookiebanner', $script);
}
add_action( 'wp_enqueue_scripts', 'cmplz_add_twitter_js', PHP_INT_MAX);
/**
* This empty function ensures Complianz recognizes that this integration has a placeholder
* @return void
*
*/
function cmplz_twitter_placeholder(){}

View File

@@ -0,0 +1,16 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_videopress_script' );
function cmplz_videopress_script( $tags ) {
$tags[] = array(
'name' => 'videopress',
'placeholder' => 'videopress',
'category' => 'marketing',
'urls' => array(
'videopress.com/videopress-iframe',
'videopress.com/embed',
),
);
return $tags;
}

View File

@@ -0,0 +1,46 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_vimeo_iframetags' );
function cmplz_vimeo_iframetags( $tags ) {
$tags[] = array(
'name' => 'vimeo',
'placeholder' => 'vimeo',
'category' => 'statistics',
'urls' => array(
'vimeo.com',
'i.vimeocdn.com',
),
);
return $tags;
}
add_filter( 'cmplz_whitelisted_script_tags', 'cmplz_vimeo_whitelist' );
function cmplz_vimeo_whitelist( $tags ) {
$tags[] = 'dnt=1';
$tags[] = 'dnt=true';
return $tags;
}
function cmplz_vimeo_placeholder( $placeholder_src, $src ) {
//get id, used only for storing in transient
$vimeo_pattern
= '/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|video\/|)(\d+)(?:[a-zA-Z0-9_\-]+)?/i';
if ( preg_match( $vimeo_pattern, $src, $matches ) ) {
$vimeo_id = $matches[1];
$new_src = cmplz_get_transient( "cmplz_vimeo_image_$vimeo_id" );
if ( ! $new_src || ! cmplz_file_exists_on_url( $new_src ) ) {
$data = json_decode( file_get_contents( 'http://vimeo.com/api/oembed.json?url=' . $src ) );
if (!empty($data) ) {
$placeholder_src = $data->thumbnail_url;
$placeholder_src = cmplz_download_to_site( $placeholder_src, 'vimeo' . $vimeo_id );
cmplz_set_transient( "cmplz_vimeo_image_$vimeo_id", $placeholder_src, WEEK_IN_SECONDS );
}
} else {
$placeholder_src = $new_src;
}
}
return $placeholder_src;
}
add_filter( 'cmplz_placeholder_vimeo', 'cmplz_vimeo_placeholder', 10, 2 );

View File

@@ -0,0 +1,92 @@
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_youtube_script' );
function cmplz_youtube_script( $tags ) {
$tags[] = array(
'name' => 'youtube',
'placeholder' => 'youtube',
'category' => 'marketing',
'urls' => array(
'www.youtube.com/iframe_api',
'youtube.com',
'youtube-nocookie.com',
'youtu.be',
),
);
return $tags;
}
/**
* Get the first video id from a video series
*
* @param string $src
*
* @return string
*/
function cmplz_youtube_get_video_id_from_series($src){
$output = wp_remote_get($src);
$youtube_id = false;
if (isset($output['body'])) {
$body = $output['body'];
$body = stripcslashes($body);
$series_pattern = '/VIDEO_ID\': "([^#\&\?].*?)"/i';
if ( preg_match( $series_pattern, $body, $matches ) ) {
$youtube_id = $matches[1];
}
}
return $youtube_id;
}
/**
* Get screenshot from youtube as placeholder
* @param $new_src
* @param $src
*
* @return mixed|string
*/
function cmplz_youtube_placeholder( $new_src, $src ) {
$youtube_pattern = '/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/videoseries\?list=RD|embed\/|watch\?v=)([^#\&\?]*).*/i';
if ( preg_match( $youtube_pattern, $src, $matches ) ) {
$youtube_id = $matches[1];
//check if it's a video series. If so, we get the first video
if ( $youtube_id === 'videoseries' ) {
//get the videoseries id
$series_pattern = '/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/videoseries\?list=RD|embed\/|watch\?v=)[^#\&\?]*\?list=(.*)/i';
//if we find the unique id, we save it in the cache
if ( preg_match( $series_pattern, $src, $matches ) ) {
$series_id = $matches[1];
$youtube_id = cmplz_get_transient("cmplz_youtube_videoseries_video_id_$series_id");
if (!$youtube_id){
//we do a get on the url to retrieve the first video
$youtube_id = cmplz_youtube_get_video_id_from_series($src);
cmplz_set_transient( "cmplz_youtube_videoseries_video_id_$series_id", $youtube_id, WEEK_IN_SECONDS );
}
} else{
$youtube_id = cmplz_youtube_get_video_id_from_series($src);
}
}
/**
* The highest resolution of youtube thumbnail is the maxres, but it does not
* always exist. In that case, we take the hq thumb
* To lower the number of file exists checks, we cache the result.
*
* */
$new_src = cmplz_get_transient( "cmplz_youtube_image_$youtube_id" );
if ( ! $new_src || ! cmplz_file_exists_on_url( $new_src ) ) {
$new_src = "https://img.youtube.com/vi/$youtube_id/maxresdefault.jpg";
if ( ! cmplz_remote_file_exists( $new_src ) ) {
$new_src = "https://img.youtube.com/vi/$youtube_id/hqdefault.jpg";
}
$new_src = cmplz_download_to_site( $new_src, 'youtube' . $youtube_id );
cmplz_set_transient( "cmplz_youtube_image_$youtube_id", $new_src, WEEK_IN_SECONDS );
}
}
return $new_src;
}
add_filter( 'cmplz_placeholder_youtube', 'cmplz_youtube_placeholder', 10, 2 );