Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,262 @@
/**
PLACEMENT TESTS PAGE
*/
/* stylelint-disable */
.advads-placement-tests-table {
min-width: 80%;
background: #fff;
border: 1px solid #c3c4c7;
border-collapse: collapse;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}
.advads-placement-tests-table tbody tr {
border-top: 1px solid #f1f1f1;
}
.advads-placement-tests-table th,
.advads-placement-tests-table td {
margin: 0;
padding: 10px;
text-align: left;
vertical-align: top;
}
.advads-placement-tests-table tbody tr td:first-child {
width: 70px;
}
.advads-placement-tests-table tbody tr td:nth-child(2) {
width: 225px;
}
.advads-placement-tests-table tbody tr td:last-child {
width: 70px;
}
.advads-placements-table-test-column {
width: 150px;
}
.advads-placements-table-options
.advads-option-placement-custom-position
fieldset {
margin-left: 2em;
margin-bottom: 1em;
}
.advads-placements-table-options
.advads-option-placement-custom-position
fieldset
legend {
margin-left: -2em;
font-weight: bold;
}
/**
PLACEMENT VISITOR AND DISPLAY CONDITIONS
*/
.advads-placements-table .advads-conditions-table tbody tr td {
width: auto;
}
/**
AD GROUPD PAGE
*/
.advads-option-group-pro-grid-size > div {
line-height: 28px;
}
/**
AD EDIT PAGE
*/
#advads-pro-weekdays {
margin-top: 5px;
font-size: 12px;
}
#advads-pro-weekdays option {
padding-bottom: 1px;
}
#advads-custom-code-wrap {
float: none;
overflow: auto;
}
#advads-custom-code-textarea {
width: 100%;
height: 10em;
}
#modal-category-hierarchy .preloader {
text-align: center;
}
#modal-category-hierarchy .preloader img {
width: 28px;
height: 28px;
}
#modal-category-hierarchy .level-header {
display: inline-block;
margin: 0.5em 0.5em 0 0;
}
#modal-category-hierarchy .level-header .dashicons {
color: #7a7a79;
cursor: pointer;
}
#modal-category-hierarchy .level-header .dashicons.not-parent {
visibility: hidden;
cursor: default;
}
#modal-category-hierarchy .category-level .category-level {
margin-left: 2em;
padding-left: 1.5em;
border-left: 1px dashed #9b9b9b;
}
.rtl #modal-category-hierarchy .category-level .category-level {
margin-right: 2em;
margin-left: 0;
padding-right: 1.5em;
padding-left: 0;
border-right: 1px dashed #9b9b9b;
border-left: none;
}
#modal-category-hierarchy .category-level .category-level.folded {
height: 0;
overflow: hidden;
}
#modal-category-hierarchy .advads-category.advads-button[data-status="active"] {
border-color: #0074a2 !important;
background: #2ea2cc !important;
color: #fff !important;
box-shadow: none;
border-width: 1px;
}
#modal-category-hierarchy .advads-category.advads-button[data-status="mixed"] {
background: #fff;
}
#modal-category-hierarchy .advads-category.advads-button span:after {
content: "";
border: none;
width: 0;
}
#modal-category-hierarchy .advads-category.advads-button span:before {
font-family: "dashicons";
padding: 0;
width: 28px;
display: inline-block;
border-right: 1px solid #ccc;
margin-right: 1em;
height: 28px;
line-height: 30px;
text-align: center;
color: #ccc;
margin-left: -1em;
}
.rtl #modal-category-hierarchy .advads-category.advads-button span:before {
border-left: 1px solid #ccc;
border-right: none;
margin-left: 1em;
margin-right: 0;
}
#modal-category-hierarchy .advads-category.advads-button span:before {
content: "\f159";
}
#modal-category-hierarchy .advads-category.advads-button:hover span:before,
#modal-category-hierarchy
.advads-category.advads-button[data-status="mixed"]:hover
span:before {
content: "\f12a";
}
#modal-category-hierarchy
.advads-category.advads-button[data-status="active"]
span:before {
content: "\f12a";
color: white;
border-color: #0074a2;
}
#modal-category-hierarchy
.advads-category.advads-button[data-status="mixed"]
span:before {
content: "\f14f";
color: #2ea2cc;
border-color: #0074a2;
}
#modal-category-hierarchy
.advads-category.advads-button[data-status="active"]:hover
span:before {
content: "\f159";
}
/**
MODULE ACTIVATION
*/
.advads-sub-settings {
display: none;
}
input.advads-has-sub-settings:checked ~ .advads-sub-settings {
display: block;
}
#advads-settings-hide-by-post-type {
-webkit-columns: 200px 5;
-moz-columns: 200px 5;
columns: 200px 5;
column-gap: 10px;
}
#advads-settings-hide-by-post-type label {
display: block;
}
.advads-color-green {
color: green;
}
.advads-color-red {
color: red;
}
.advads-settings-margin {
margin: 1.33em 0;
}
.d-block {
display: block;
}
.advads-eadblocker-radio-button {
margin-bottom: 5px;
margin-right: 1.5em;
}
.width-100 {
width: 100%;
}
.advads-eab-overlay-notice {
display: none;
}
.advads-settings-checkbox-inline {
-webkit-columns: 200px 5;
-moz-columns: 200px 5;
columns: 200px 5;
column-gap: 10px;
}
.advads-settings-checkbox-inline label {
display: block;
margin-bottom: 9px;
}

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@@ -0,0 +1,88 @@
/**
* Advanced ads cache-busting admin bar.
*/
var advanced_ads_pro_admin_bar;
if ( ! advanced_ads_pro_admin_bar ) {
advanced_ads_pro_admin_bar = {
offset: 0,
adminBar: null,
bufferedAds: [],
/**
* Observe ads inserted using Cache Busting
*
* @param {object} event Cache Busting event.
*/
observe: function ( event ) {
var that = advanced_ads_pro_admin_bar;
if ( event.event === 'hasAd' && event.ad && event.ad.title && event.ad.cb_type !== 'off' ) {
if ( ! that.adminBar ) {
// No admin-bar yet: buffer.
that.bufferedAds.push( event.ad );
} else {
// Flush buffer if not empty.
if ( that.bufferedAds.length > 0 ) {
that.flush();
}
// Inject current ad.
that.inject( event.ad );
}
}
},
/**
* Flush earlier collected items.
*/
flush: function() {
var that = advanced_ads_pro_admin_bar, i = 0;
for (i = that.bufferedAds.length - 1; i >= 0; i-- ) {
that.inject( that.bufferedAds[i] );
}
that.bufferedAds = [];
},
/**
* Inject an ad.
*
* @param {object} ad An ad to inject.
*/
inject: function ( ad ) {
var that = advanced_ads_pro_admin_bar;
if ( that.offset === 0 ) {
// Remove 'No Ads found' `<li>`.
jQuery( '#wp-admin-bar-advads_no_ads_found' ).remove();
}
const count = ad.count ?? 1;
const countString = 1 === count ? '' : `(${count}) `;
const internalId = ad.id ? `${ad.type}_${ad.id}` : `${ad.type}_${ad.title}`;
const previousOccurrence = that.adminBar.find( `[data-aditem="${internalId}"]` );
if ( previousOccurrence.length ) {
const countSpan = previousOccurrence.find( '.occurence-count' );
countSpan.attr( 'data-count', parseInt( countSpan.attr( 'data-count' ), 10 ) + 1 ).text( `(${countSpan.data( 'count' )}) ` );
} else {
that.adminBar.append( '<li id="wp-admin-bar-advads_current_ad_' + that.offset + '"><div class="ab-item ab-empty-item" data-aditem="' + `${internalId}` + '">' +
`<span class="occurence-count" data-count="${count}">` + countString + '</span>' + ad.title + ' (' + ad.type + ')</div></li>' );
}
that.offset += 1;
}
};
}
if ( typeof advanced_ads_pro !== 'undefined' ) {
advanced_ads_pro.observers.add( advanced_ads_pro_admin_bar.observe );
}
( window.advanced_ads_ready || jQuery( document ).ready ).call( null, function() {
advanced_ads_pro_admin_bar.adminBar = jQuery( '#wp-admin-bar-advads_current_ads-default' );
advanced_ads_pro_admin_bar.flush();
if ( window.advads_admin_bar_items ) {
// Append items that do not use cache-busting.
window.advads_admin_bar_items.forEach( advanced_ads_pro_admin_bar.inject )
}
} );

View File

@@ -0,0 +1,550 @@
;(function($){
// CFP cookies prefix
var cname = 'advads_procfp';
var cname_vc = 'advanced_ads_ad_clicks'; // visitor conditions
// CFP cookies parameter ( domain/path )
var PATH = null;
var DOMAIN = null;
/**
* wrapper for JSON.parse
*/
function jsonDecode( str ) {
try {
var res = JSON.parse( str );
return res;
} catch( Ex ) {
return null;
}
}
// Max ad click conditions/ passive Cache busting.
$( document ).on( 'advads-passive-cb-conditions', function( e, cbs ) {
cbs.conditions['ad_clicks'] = 'check_ad_clicks';
cbs['check_ad_clicks'] = function ( options, ad ) {
if ( advads.cookie_exists( cname_vc + '_' + ad.id ) ) {
var C_vc = advads.get_cookie( cname_vc + '_' + ad.id );
C_vc = jsonDecode( C_vc );
}
if ( C_vc ) {
var now = parseInt( new Date().getTime() / 1000 );
for ( var i in C_vc ) {
if ( '_' + options.expiration == i ) {
// if still valid counter and click limit reached
if ( C_vc[i]['ttl'] >= now && C_vc[i]['count'] >= parseInt( options.limit ) ) {
return false;
}
}
}
}
return true;
};
});
var cfpTracker = function() {
this.$elements = {};
this.currentIFrame = false;
this.focusLost = false;
this.wrappers = [
'.google-auto-placed'
];
this.attributes = {
'data-anchor-status': 'displayed',
'data-vignette-loaded': 'true'
};
this.lastClick = 0;
this.init();
}
cfpTracker.prototype = {
constructor: cfpTracker,
init: function () {
const that = this;
let touchmoved;
// increment counter on click on link
$( document ).on( 'click', 'a[data-cfpa]', function () {
that.onClick( parseInt( $( this ).attr( 'data-cfpa' ) ) );
} );
// Increment counter on blur only if an iframe has recently been hovered.
$( window ).on( 'blur', function ( e ) {
// Use timeout of 0 ms as a workaround to make sure that the active element has changed correctly.
setTimeout( function () {
if ( ! that.currentIFrame ) {
// Loop parent nodes from the target to the delegation node to recognise iframe clicks.
for ( let target = document.activeElement; target && target !== this && target !== document; target = target.parentNode ) {
that.currentIFrame = that.checkWrappers( target );
if ( that.currentIFrame ) {
break;
}
}
}
if ( that.currentIFrame ) {
that.onClick( that.currentIFrame );
that.focusLost = true;
top.focus();
}
}, 0 );
} );
// mouse passes over an ad that has not yet been initialized (adsense and other distant ads - OR just an ad that contains no link nor iframes)
$( document ).on( 'mouseenter', 'div[data-cfpa]', function () {
var id = parseInt( $( this ).attr( 'data-cfpa' ) );
that.addElement( id );
} );
// Detect swipe and click on mobile devices.
document.addEventListener( 'touchmove', function () {
touchmoved = true;
}, false );
document.addEventListener( 'touchstart', function () {
touchmoved = false;
}, false );
// Detect desktop and mobile clicks.
['click', 'touchend'].forEach(
function ( event ) {
document.addEventListener( event, function ( e ) {
// Prevent swipes and simultaneous clicks on wrapper and element as well as fast clicks in a row
if ( touchmoved || ( that.getTimestamp() - that.lastClick ) < 1 ) {
return;
}
let adId = null;
// Loop parent nodes from the target to the delegation node.
for ( let target = e.target; target && target !== this && target !== document; target = target.parentNode ) {
// Loop all predefined wrappers to detect clicks on Google Auto Ads iframes.
adId = that.checkWrappers( target );
if ( adId ) {
that.onClick( adId );
break;
}
// Check if clicked element is a cfp wrapper.
if ( target.hasAttribute( 'data-cfpa' ) && target.hasAttribute( 'data-cfptl' ) ) {
adId = parseInt( target.getAttribute( 'data-cfpa' ), 10 );
that.onClick( adId );
break;
}
}
} );
}
);
},
/**
* Create current timestamp
*
* @return {number}
*/
getTimestamp: function () {
return Math.floor( Date.now() / 1000 );
},
/**
* Check if target element is a predefined wrapper or has Google Auto Ads attributes.
*
* @param target
* @returns {string|null}
*/
checkWrappers: function ( target ) {
for ( let i = 0, wrappersLength = this.wrappers.length, selector = null; i < wrappersLength; i ++ ) {
selector = this.wrappers[i];
if ( target.matches && target.matches( selector ) ) {
return ( selector === '.google-auto-placed' ) ? 'google-auto-placed' : null;
}
}
for ( const [key, value] of Object.entries( this.attributes ) ) {
if ( target.hasAttribute( key ) && target.getAttribute( key ) === value ) {
return 'google-auto-placed';
}
}
return null;
},
addElement: function( $el ) {
if ( false === $el instanceof jQuery ) {
// Select the first ad since there may be multiple copies of the same ad on the page.
$el = $( 'div[data-cfpa="' + $el + '"]' ).first();
}
var hasIframe = $el.find( 'iframe' ).length ? true : false;
if ( !hasIframe ) {
if ( !$el.find( 'a' ).length ) {
// no an anchor and no iframe -- likely and ad that is not yet loaded (adsense or other ad network)
return;
}
}
var adID = parseInt( $el.attr( 'data-cfpa' ) );
this.$elements[adID] = $el;
// remove attribute from the wrapper
$el.removeAttr( 'data-cfpa' );
// And then move it to the first anchor or iframe found
if ( hasIframe ) {
$el.find( 'iframe' ).first().attr({
'data-cfpa': adID,
})
if ( $el.attr( 'data-cfph' ) ) {
$el.find( 'iframe' ).first().attr({
'data-cfph': $el.attr( 'data-cfph' ),
})
}
} else {
$el.find( 'a' ).not( '.advads-edit-button' ).first().attr({
'data-cfpa': adID,
})
if ( $el.attr( 'data-cfph' ) ) {
$el.find( 'a' ).not( '.advads-edit-button' ).first().attr({
'data-cfph': $el.attr( 'data-cfph' ),
})
}
}
// remove Hours attribute from the wrapper
$el.removeAttr( 'data-cfph' );
// update TTL field for all outdated counter (visitor conditions)
if ( advads.cookie_exists( cname_vc + '_' + adID ) ) {
var C_vc = advads.get_cookie( cname_vc + '_' + adID );
C_vc = jsonDecode( C_vc );
if ( C_vc ) {
var now = parseInt( new Date().getTime() / 1000 ), cookie_modified = false;
for ( var i in C_vc ) {
if ( !C_vc.hasOwnProperty( i ) ) continue;
if ( 'exp' == i ) continue;
if ( C_vc[i]['ttl'] < now ) {
var period = parseFloat( i.substr( 1 ) );
var newTTL = C_vc[i]['ttl'];
while ( newTTL < now ) {
newTTL += period * 60 * 60;
}
C_vc[i]['ttl'] = newTTL;
C_vc[i]['count'] = 0;
cookie_modified = true;
}
}
if ( cookie_modified ) {
var expTime = new Date( C_vc['exp'] );
advads.set_cookie_sec( cname_vc + '_' + adID, JSON.stringify( C_vc, 'false', false ), parseInt( expTime.getTime() / 1000 ), PATH, DOMAIN );
}
}
}
},
/**
* Ban the visitor
*/
_banVisitor: function() {
var now = new Date();
var d = new Date();
d.setTime( d.getTime() + ( advadsCfpInfo.cfpBan * 24 * 60 * 60 * 1000 ) );
var ban = ( d.getTime() - now.getTime() ) / 1000;
advads.set_cookie_sec( 'advads_pro_cfp_ban', 1, ban, PATH, DOMAIN );
// Select ad wrappers and delete them.
document.querySelectorAll( '[data-cfpw]:not([data-cfp-exclude])' ).forEach( function( el ) {
el.remove();
} );
this.removeEmptyWrappers();
// Select Google AdSense Auto Ads and delete them.
this.wrappers.forEach( function ( wrapper ) {
jQuery( wrapper ).remove();
} );
for ( const [key, value] of Object.entries( this.attributes ) ) {
jQuery( '[' + key + '="' + value + '"]' ).remove();
}
},
/**
* Remove top-level wrappers that do not contain ads.
*/
removeEmptyWrappers: function() {
// Select top-level wrappers that are not ads.
document.querySelectorAll( '[data-cfptl]:not([data-cfpw])' ).forEach( function( el ) {
// If there are no nested ads, remove the top-level wrapper.
if ( ! el.querySelectorAll( '[data-cfpw]' ).length ) {
el.remove();
};
} );
},
/**
* Click handler.
*
* @param {string} ID Ad id.
*/
onClick: function( ID ){
var that = this,
// Module wide cookie
cookieVisitor = false,
// Visitor condition cookie.
cookieVisitorCondition = false;
this.lastClick = this.getTimestamp();
if ( 'google-auto-placed' !== ID && $( '[data-cfpa="' + ID + '"]' ).attr( 'data-cfph' ) ) {
// if there are some visitor conditions, use the vc cookie
if ( advads.cookie_exists( cname_vc + '_' + ID ) ) {
cookieVisitorCondition = jsonDecode( advads.get_cookie( cname_vc + '_' + ID ) );
}
const clickLimits = jsonDecode( $( '[data-cfpa="' + ID + '"]' ).attr( 'data-cfph' ) );
if ( cookieVisitorCondition ) {
// Cookie already exists, increment each counter (keep expiration time)
const nowInSeconds = parseInt( new Date().getTime() / 1000, 10 );
const adWrapper = document.querySelectorAll( '[data-cfpw="' + ID + '"]' );
for ( var h in cookieVisitorCondition ) {
if ( ! cookieVisitorCondition.hasOwnProperty( h ) ) {
continue;
}
if ( h === 'exp') {
// Ignore the key that contains expiration date.
continue;
}
cookieVisitorCondition[h]['count'] = parseInt( cookieVisitorCondition[h]['count'], 10 ) + 1;
if ( cookieVisitorCondition[h]['ttl'] >= nowInSeconds && cookieVisitorCondition[h]['count'] >= parseInt( clickLimits[h], 10 ) ) {
adWrapper.forEach( function( node ) {
node.remove();
} );
// If the ad was wrapper with a top-level wrapper, try to remove it.
that.removeEmptyWrappers();
}
}
var now = new Date();
var expiry = new Date( cookieVisitorCondition.exp );
var expirySecs = parseInt( ( expiry.getTime() - now.getTime() ) / 1000 );
advads.set_cookie_sec( cname_vc + '_' + ID, JSON.stringify( cookieVisitorCondition, 'false', false ), expirySecs, PATH, DOMAIN );
} else {
// create a new cookie
var cval = {}, maxHValue = 0;
var d = new Date();
var now = new Date();
for ( var h in clickLimits ) {
h = h.substring( 1 );
if ( parseFloat( h ) > maxHValue ) {
maxHValue = parseFloat( h );
}
cval['_' + h] = {
count: 1,
ttl: parseInt( ( ( now.getTime() / 1000 ) + ( parseFloat( h ) * 3600 ) ), 10 ),
};
}
// use the longest hour value for the expiry time
d.setTime( d.getTime() + ( maxHValue * 60 * 60 * 1000 ) );
var expires = "expires="+ d.toUTCString();
var expirySecs = parseInt( ( d.getTime() - now.getTime() ) / 1000 );
cval['exp'] = expires;
advads.set_cookie_sec( cname_vc + '_' + ID, JSON.stringify( cval, 'false', false ), expirySecs, PATH, DOMAIN );
if ( 1 === clickLimits[Object.keys( clickLimits )[0]] ) {
document.querySelectorAll( '[data-cfpw="' + ID + '"]' ).forEach( function ( node ) {
node.remove();
} );
this.removeEmptyWrappers();
}
}
}
if ( '1' !== advadsCfpInfo.cfpEnabled ) {
return;
}
// use the module wide CFP cookie
if ( advads.cookie_exists( cname + '_' + ID ) ) {
cookieVisitor = jsonDecode( advads.get_cookie( cname + '_' + ID ) );
}
if ( cookieVisitor ) {
// Cookie already exists, increment the counter (keep expiration time)
cookieVisitor.count = parseInt( cookieVisitor.count, 10 ) + 1;
var now = new Date();
var expiry = new Date( cookieVisitor.exp );
var expirySecs = ( expiry.getTime() - now.getTime() ) / 1000;
advads.set_cookie_sec( cname + '_' + ID, JSON.stringify( cookieVisitor, 'false', false ), expirySecs, PATH, DOMAIN );
if ( parseInt( advadsCfpInfo.cfpClickLimit,10 ) <= cookieVisitor.count ) {
// CFP module enabled - ban this visitor
that._banVisitor();
}
} else {
// create a new cookie
var d = new Date();
var now = new Date();
d.setTime( d.getTime() + ( parseInt( advadsCfpInfo.cfpExpHours, 10 ) * 60 * 60 * 1000 ) );
var expires = "expires="+ d.toUTCString();
var expirySecs = ( d.getTime() - now.getTime() ) / 1000;
advads.set_cookie_sec( cname + '_' + ID, '{"count":1,"exp":"' + expires + '"}', expirySecs, PATH, DOMAIN );
if ( parseInt( advadsCfpInfo.cfpClickLimit, 10 ) === 1 ) {
// CFP module enabled - ban this visitor
that._banVisitor();
}
}
},
}
$( function(){
/**
* Max ad click ( visitor conditions )
*/
window.advadsProCfp = new cfpTracker();
// IFRAME click tracking
$( document ).on( 'mouseenter', 'iframe[data-cfpa]', function(e){
var ID = parseInt( $( this ).attr( 'data-cfpa' ) );
advadsProCfp.currentIFrame = ID;
} ).on( 'mouseenter', '.google-auto-placed', function(e){
// Use the same ID for all Google AdSense Auto Ads.
advadsProCfp.currentIFrame = 'google-auto-placed';
} ).on( 'mouseleave mouseout', '[data-cfpa], .google-auto-placed', function(){
advadsProCfp.currentIFrame = false;
if ( advadsProCfp.focusLost ) {
advadsProCfp.focusLost = false;
$( window ).trigger( 'focus' );
}
} );
// construct all elements already present in the queue
for( var i in advadsCfpQueue ) {
if ( advadsCfpQueue.hasOwnProperty( i ) ) {
advadsProCfp.addElement( advadsCfpQueue[i] );
}
}
advadsCfpQueue = [];
/**
* Click fraud protection module.
*/
if ( 'undefined' == typeof window.advadsCfpInfo.cfpPath ) return;
// get the path/domain parameter to use in cookies
if ( '' != advadsCfpInfo.cfpPath ) {
PATH = advadsCfpInfo.cfpPath;
}
if ( '' != advadsCfpInfo.cfpDomain ) {
DOMAIN = advadsCfpInfo.cfpDomain;
}
} );
})(window.jQuery);
/**
* Reload on resize.
*/
var advanced_ads_resizetimeout = 1000; // time to wait until resized window width is saved, in millisec
var advanced_ads_cookieexpires = 30; // days until the cookie expires
var advanced_ads_browser_width = advanced_ads_get_browser_width();
// Save browserWidth in a cookie if not set or not equal to current saved width.
if ( window.advads !== undefined ) {
var cookieValue = advads.get_cookie( 'advanced_ads_visitor' );
var info = cookieValue ? JSON.parse( cookieValue ) : {};
if ( ! info.browser_width || info.browser_width !== advanced_ads_browser_width ) {
advanced_ads_save_width( advanced_ads_browser_width );
}
}
// Save new browser width, when window resizes.
if ( window.addEventListener ) { // most non-IE browsers and IE9
window.addEventListener( 'resize', advanced_ads_resize_window, false );
} else if ( window.attachEvent ) { // Internet Explorer 5 or above
window.attachEvent( 'onresize', advanced_ads_resize_window );
}
function advanced_ads_resize_window() {
advads_resize_delay( function () {
var previous_width = advanced_ads_browser_width;
advanced_ads_browser_width = advanced_ads_get_browser_width();
if ( previous_width === advanced_ads_browser_width ) {
// Return if the viewport has not actually changed
// Scroll events were triggering this on iOS due to the position of the address bar.
return;
}
advanced_ads_save_width( advanced_ads_browser_width );
var advanced_ads_responsive = window.advanced_ads_responsive || {};
if ( window.jQuery && parseInt( advanced_ads_responsive.reload_on_resize, 10 ) ) {
jQuery( document ).triggerHandler( 'advanced-ads-resize-window' );
}
}, advanced_ads_resizetimeout );
}
// Save width in cookie.
function advanced_ads_save_width( width ) {
if ( window.advads === undefined ) {
return;
}
var cookieValue = advads.get_cookie( 'advanced_ads_visitor' );
var info = cookieValue ? JSON.parse( cookieValue ) : {};
info.browser_width = width;
advads.set_cookie( 'advanced_ads_visitor', JSON.stringify( info ), advanced_ads_cookieexpires, advanced_ads_cookies.cookie_path, advanced_ads_cookies.cookie_domain );
}
// Create a listener calling only once after resize.
// http://stackoverflow.com/questions/2854407/javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed
var advads_resize_delay = ( function () {
var timer = 0;
return function ( callback, ms ) {
clearTimeout( timer );
timer = setTimeout( callback, ms );
};
} )();
/**
* Get the width of the browser.
*/
function advanced_ads_get_browser_width() {
if ( window.jQuery ) {
return jQuery( window ).width();
} else {
var browserWidth = 0;
if ( typeof ( window.innerWidth ) == 'number' ) {
// Non-IE
browserWidth = window.innerWidth;
} else if ( document.documentElement && document.documentElement.clientWidth ) {
// IE 6+ in 'standards compliant mode'
browserWidth = document.documentElement.clientWidth;
} else if ( document.body && document.body.clientWidth ) {
// IE 4 compatible
browserWidth = document.body.clientWidth;
}
return browserWidth;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,41 @@
/**
* If there is no cache-busting script add this to decrypt TCF privacy encrypted ads.
*/
if ( ! advanced_ads_pro ) {
var advanced_ads_pro = {
observers: jQuery.Callbacks()
};
}
document.addEventListener( 'advanced_ads_privacy', function ( event ) {
if (
event.detail.previousState !== 'unknown'
&& ! ( event.detail.previousState === 'rejected' && event.detail.state === 'accepted' )
) {
return;
}
if ( event.detail.state === 'accepted' || event.detail.state === 'not_needed' ) {
var encodedAd = 'script[type="text/plain"][data-tcf="waiting-for-consent"]';
var decoded_ads = {},
decode_ad = function ( node ) {
if ( typeof node.dataset.noTrack === 'undefined' || node.dataset.noTrack !== 'impressions' ) {
if ( ! decoded_ads.hasOwnProperty( node.dataset.bid ) ) {
decoded_ads[node.dataset.bid] = [];
}
decoded_ads[node.dataset.bid].push( parseInt( node.dataset.id, 10 ) );
}
advads.privacy.decode_ad( node );
};
// Find all scripts and decode them.
document.querySelectorAll( encodedAd ).forEach( function ( node ) {
decode_ad( node );
} );
if ( Object.keys( decoded_ads ).length ) {
advanced_ads_pro.observers.fire( {event: 'advanced_ads_decode_inserted_ads', ad_ids: decoded_ads} );
}
}
} );

View File

@@ -0,0 +1 @@
if(!advanced_ads_pro)var advanced_ads_pro={observers:jQuery.Callbacks()};document.addEventListener("advanced_ads_privacy",(function(e){if(("unknown"===e.detail.previousState||"rejected"===e.detail.previousState&&"accepted"===e.detail.state)&&("accepted"===e.detail.state||"not_needed"===e.detail.state)){var a={};document.querySelectorAll('script[type="text/plain"][data-tcf="waiting-for-consent"]').forEach((function(e){!function(e){void 0!==e.dataset.noTrack&&"impressions"===e.dataset.noTrack||(a.hasOwnProperty(e.dataset.bid)||(a[e.dataset.bid]=[]),a[e.dataset.bid].push(parseInt(e.dataset.id,10))),advads.privacy.decode_ad(e)}(e)})),Object.keys(a).length&&advanced_ads_pro.observers.fire({event:"advanced_ads_decode_inserted_ads",ad_ids:a})}}));

View File

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

View File

@@ -0,0 +1,259 @@
export default () => {
'use strict';
const fallbacks = {},
ajaxResponses = {};
let Observer = null,
observedAds = 0;
/**
* Extract AdSense fallback item data from the AdSense ad wrapper
*
* @param {Node} node the ad or group wrapper.
* @return {{}} fallback item data
*/
const extractFallBackData = (node) => {
const result = {};
node.classList.forEach((className) => {
if (className.startsWith('gas_fallback-')) {
const exploded = className.split('-');
result.ad = exploded[1];
result.fallback = exploded[2];
}
});
return result;
};
/**
* Bind the mutation observer to an AdSense ad tag
*
* @param {Node} ins the <ins/> tag of the AdSense ad which hold the "data-ad-status" attribute.
*/
const observeAd = (ins) => {
if (null === Observer) {
Observer = new window.MutationObserver((records) => {
for (const record of records) {
if (
'unfilled' !==
record.target.getAttribute('data-ad-status')
) {
return;
}
document.dispatchEvent(
new CustomEvent('advanced_ads_pro_adsense_unfilled', {
detail: { ad: record.target },
})
);
}
});
}
// Only observe the `data-ad-status` attribute, and only one the <ins/> tag.
Observer.observe(ins, { attributeFilter: ['data-ad-status'] });
observedAds++;
};
/**
* Inject the fallback ad or group using passive CB
*
* @param {Object} fallBackData fallback item data extracted from the AdSense ad wrapper.
* @param {Object} placement CB placement data (can be in passive or AJAX format).
*/
const passiveInject = (fallBackData, placement) => {
const fallBackItem = fallBackData.fallback.split('_');
// The fallback item is an ad.
if ('ad' === fallBackItem[0]) {
const adInfo = getAdInfo(placement, fallBackItem[1]);
if (!adInfo) {
return;
}
const passiveAd = new window.Advads_passive_cb_Ad(
adInfo,
fallBackData.cbId
);
// Remove the current AdSense ad wrapper then inject the fallback ad's output.
fallBackData.wrapper.remove();
passiveAd.output({
track: true,
inject: true,
do_has_ad: true,
});
}
// The fallback item is a group.
if ('group' === fallBackItem[0]) {
placement.id = parseInt(fallBackItem[1], 10);
placement.type = 'group';
placement.group_info = placement.adsense_fallback_group_info;
const passiveGroup = new window.Advads_passive_cb_Group(
placement,
fallBackData.cbId
);
// Remove the current AdSense ad wrapper then inject the fallback group's output.
fallBackData.wrapper.remove();
passiveGroup.output();
}
};
/**
* Inject (using passive CB) the fallback into the AdSense ad's CB wrapper.
*
* Check into the passive placements list first as this is the most common case.
* Then check into the AJAX CB placement afterward.
* If no matching placement is found do not inject. The feature works only with CB placements.
*
* @param {Object} fallbackData fallback ad/group data for the current AdSense ad.
*/
const injectFallback = (fallbackData) => {
const placement =
getPassivePlacement(fallbackData.cbId) ||
getAjaxPlacement(fallbackData.cbId);
if (placement) {
passiveInject(fallbackData, placement);
adHealthEntry(placement);
}
};
/**
* Add an ad health entry about the unfilled AdSense slot.
*
* @param {Object} placement data about the placement containing the failed AdSense ad.
*/
const adHealthEntry = (placement) => {
if (
!advancedAds.adHealthNotice.enabled ||
!document.getElementById('wpadminbar')
) {
return;
}
const allFine = document.getElementById(
'wp-admin-bar-advanced_ads_ad_health_fine'
);
allFine?.remove();
const adHealth = document
.getElementById('wp-admin-bar-advanced_ads_ad_health')
.querySelector('ul');
const li = document.createElement('li');
li.role = 'group';
li.id = 'wp-admin-bar-advanced_ads_gads_fallback';
const div = document.createElement('div');
div.className = 'ab-item ab-empty-item';
div.role = 'menuitem';
div.textContent = window.advancedAds.adHealthNotice.pattern.replace(
'[ad_title]',
placement.ads[
parseInt(placement.placement_info.item.split('_')[1], 10)
].title
);
adHealth.appendChild(li);
li.appendChild(div);
};
/**
* Get data about a potential passive CB placement given the CB wrapper ID (HTML id attribute).
*
* @param {string} cbId CB wrapper ID (a.k.a. elementid or elementId).
* @return {Object|boolean} false if no matching placement found.
*/
const getPassivePlacement = (cbId) => {
return (
Object.values(window.advads_passive_placements).find(
(placement) => placement.elementid.indexOf(cbId) === 0
) || false
);
};
/**
* Get data about a potential AJAX CB placement given the CB wrapper ID (HTML id attribute).
*
* @param {string} cbId CB wrapper ID (a.k.a. elementid or elementId).
* @return {Object|boolean} false if no matching placement found.
*/
const getAjaxPlacement = (cbId) => {
return 'undefined' !== typeof ajaxResponses[cbId]
? ajaxResponses[cbId]
: false;
};
/**
* Get ad data for passive CB injection of the fallback — iterate (call it repeatedly) through all ads for a group
*
* @param {Object} placement placement data.
* @param {string} adId the ad ID.
* @return {Object|boolean} false if no matching ad found.
*/
const getAdInfo = (placement, adId) => {
return placement.ads[adId] || false;
};
/**
* Process fallback when Google signals an unfilled spot
*/
document.addEventListener('advanced_ads_pro_adsense_unfilled', (ev) => {
observedAds--;
if (0 === observedAds) {
// Cleanup when all observed ads are unfilled.
Observer.disconnect();
}
const fallbackData = extractFallBackData(
ev.detail.ad.closest('[class^="gas_fallback-"]')
);
if (!fallbacks[fallbackData.ad]) {
return;
}
injectFallback(fallbacks[fallbackData.ad]);
});
/**
* Collect AJAX CB placements data
*/
document.body.addEventListener('advads_ajax_cb_response', ({ detail }) => {
detail.response.forEach((placement) => {
ajaxResponses[placement.elementId] = placement;
});
});
// Initialization
window.advanced_ads_ready(() => {
if (!window.advanced_ads_pro) {
return;
}
/**
* Observe any newly injected AdSense Ad (injected via CB)
*/
window.advanced_ads_pro.postscribeObservers.add((event) => {
if ('postscribe_done' !== event.event) {
return;
}
if (-1 === event.ad.indexOf('gas_fallback-')) {
return;
}
const cbWrapper = event.ref[0],
itemWrapper = cbWrapper.querySelector(
'[class^="gas_fallback-"]'
);
const fallbackData = extractFallBackData(itemWrapper);
fallbacks[fallbackData.ad] = {
fallback: fallbackData.fallback,
wrapper: itemWrapper,
cbId: cbWrapper.id,
};
observeAd(itemWrapper.querySelector('ins'));
});
});
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,202 @@
/* eslint-disable */
/*
* Group refresh
*/
import jQuery from 'jquery';
import { PassivePlacement } from './passive-placement';
export const GroupRefresh = {
/**
* Wrapper ids of groups with refresh enabled.
*/
element_ids: {},
/**
* Equivalent passive cb data for groups using ajax refresh
*/
passiveRefresh: {},
/**
* Collect placement group and ad data on the very first impression of an ajax refresh group
*
* @param {Object} data all the data needed for a passive placement creation.
*/
collectPassiveRefreshData: (data) => {
GroupRefresh.passiveRefresh[data.cb_id] = data;
},
/**
* Empty a CB wrapper then create a passive placement using the same wrapper
*
* @param {string} cbid id of the CB wrapper.
*/
switchToPassive: (cbid) => {
const data = GroupRefresh.passiveRefresh[cbid];
setTimeout(
() => {
jQuery(`.${data.cb_id}`).empty();
GroupRefresh.launchRefresh(data);
},
parseInt(data.default_interval, 10)
);
},
/**
* Create and output a passive placement with a refreshed group
*
* @param {Object} data data needed for a passive placement creation.
*/
launchRefresh: (data) => {
new PassivePlacement(
{
id: data.placement_info.id,
type: data.type,
ads: data.ads,
placement_info: data.placement_info,
group_info: data.group_info,
group_wrap: data.group_wrap,
},
data.cb_id
).output();
},
/**
* Requests group with AJAX. Uses single request, if possible.
*
* @param {obj} query
* @param {int} interval
*/
add_query: (function advanced_ads_group_refresh_add_query(query, interval) {
var queries = [];
return function (query, interval) {
var elementid = query.elementid;
var call_at = new Date().getTime() + interval;
queries[call_at] = queries[call_at] || [];
queries[call_at].push(query);
setTimeout(function () {
var now = new Date().getTime();
var requests = [];
for (const call_time in queries) {
if (!queries.hasOwnProperty(call_time)) {
continue;
}
if (now > call_time - 1000) {
// Gather multiple requests into one request.
var queries_for_time = queries[call_time];
var queries_length = queries_for_time.length;
for (var i = 0; i < queries_length; i++) {
requests.push(queries_for_time[i]);
}
delete queries[call_time];
}
}
advanced_ads_pro.process_ajax_ads(requests);
}, interval);
};
})(),
/**
* Find a first floated div.
*
* @param {jQuery} $el Element id.
* @return string/false
*/
find_float: function ($el) {
var r = false;
$el.find('div').each(function (i, el) {
if (this.style.float === 'left' || this.style.float === 'right') {
r = this.style.float;
return false;
}
});
return r;
},
/**
* Prepare the wrapper for inserting new ad.
*
* @param {jQuery} $el Wrapper id.
* @param {string|bool} float The float setting of the ad.
* @param {bool} is_first_time True for the first ad injection.
*/
prepare_wrapper: function ($el, float, is_first_time) {
if (!is_first_time) {
this.maybe_increase_sizes($el);
$el.empty();
}
this.set_float($el, float);
},
/**
* Increase the width and height of the wrapper to fit an ad.
* The width and height can only be increased, not decreased to minimize content jumping.
*
* @param {jQuery} $el Element id.
*/
maybe_increase_sizes: function ($el) {
var float = $el.css('float');
if (['left', 'right'].indexOf(float) === -1) {
float = false;
}
var sizes = {};
if (float) {
// Check if we need to increase the width.
var prev_w = parseInt($el.css('min-width'), 10) || 0;
// Get measured width.
var now_w = $el.prop('scrollWidth') || 0;
if (now_w > prev_w) {
sizes['min-width'] = now_w;
}
}
// Check if we need to increase the height.
var prev_h = parseInt($el.css('min-height'), 10) || 0;
// Get measured height.
var now_h = $el.prop('scrollHeight') || 0;
if (now_h > prev_h) {
sizes['min-height'] = now_h;
}
if (sizes['min-height'] || sizes['min-width']) {
$el.css(sizes);
}
},
/**
* Get the 'float' attribute from the ad or the placement (nested floated divs) and assign it to '$el'.
*
* @param {jQuery} $el Wrapper id.
* @param {string|bool} float The float setting of the ad.
*/
set_float: function ($el, float) {
if (['left', 'right'].indexOf(float) === -1) {
float = false;
}
var prev_float = $el.data('prev_float') || false;
if (float !== prev_float) {
$el.data('prev_float', float);
if (float) {
// Allow to measure the size of the '$el' that contains floated divs using 'scrollWidth/Height'
// Allow texts to be floated around the '$el' that has 'min-height' set.
$el.css({ 'min-width': '', 'min-height': '', float: float });
} else {
$el.css({ 'min-width': '', 'min-height': '', float: '' });
}
}
},
};
export const GroupRefreshCompat = () => {
window.advanced_ads_group_refresh = GroupRefresh;
};

View File

@@ -0,0 +1,358 @@
/* eslint-disable */
import jQuery from 'jquery';
export class PassiveAd {
/**
* Constructor
*
* @param {Object} ad_info object which contains info about the ad.
* @param {string} elementid id of wrapper div.
*/
constructor(ad_info, elementid) {
if (
typeof ad_info !== 'object' ||
!advads_pro_utils.isset(ad_info.id) ||
!advads_pro_utils.isset(ad_info.title) ||
!advads_pro_utils.isset(ad_info.content)
) {
throw new SyntaxError('Can not create Advads_passive_cb_Ad obj');
}
this.id = ad_info.id;
this.title = ad_info.title;
this.content = ad_info.content ? ad_info.content : '';
this.type = ad_info.type;
this.expiry_date = parseInt(ad_info.expiry_date) || 0;
this.visitors = ad_info.visitors;
this.once_per_page = ad_info.once_per_page;
this.elementid = elementid ? elementid : null;
this.day_indexes = ad_info.day_indexes ? ad_info.day_indexes : null;
this.debugmode = ad_info.debugmode;
this.tracking_enabled =
ad_info.tracking_enabled === undefined ||
ad_info.tracking_enabled === true;
this.blog_id = ad_info.blog_id ? ad_info.blog_id : '';
this.privacy = ad_info.privacy ? ad_info.privacy : {};
this.position = ad_info.position ? ad_info.position : '';
// Let modules and add-ons add info to an ad.
document.dispatchEvent(
new CustomEvent('advanced-ads-passive-cb-ad-info', {
detail: {
ad: this,
adInfo: ad_info,
},
})
);
}
/**
* Returns the ad output
*
* @param {Object} options output options
* track - track if true, do not track if false
* inject - inject the ad if true, return the ad content if false
* do_has_ad - true if we need to call the hasAd function
*
* @return {string} the ad output if inject is `false`.
*/
output(options) {
options = options || {};
if (this.debugmode) {
var is_displayed = this.can_display({ ignore_debugmode: true })
? 'displayed'
: 'hidden';
var debug_message = jQuery(this.content)
.find('.advads-passive-cb-debug')
.data(is_displayed);
// inject debug info
this.content = this.content.replace(
'##advanced_ads_passive_cb_debug##',
debug_message
);
}
if (options.do_has_ad) {
advanced_ads_pro.hasAd(this.id, 'ad', this.title, 'passive');
}
if (options.track && this.tracking_enabled) {
if (!advanced_ads_pro.passive_ads[this.blog_id]) {
advanced_ads_pro.passive_ads[this.blog_id] = [];
}
advanced_ads_pro.passive_ads[this.blog_id].push(this.id);
}
advads_pro_utils.log(
'output passive ad',
this.id,
this.elementid,
this.content
);
if (!options.inject) {
return this.content;
}
advanced_ads_pro.inject(this.elementid, this.content);
}
/**
* Check if the ad can be displayed in frontend due to its own conditions
*
* @param {Object} check_options possibility to bypass the check when in debug mode.
* @returns {boolean} whether the ad can be displayed.
*/
can_display(check_options) {
check_options = check_options || {};
if (this.debugmode && !check_options.ignore_debugmode) {
return true;
}
if ('' === this.content.trim()) {
advads_pro_utils.log(
'passive ad id',
this.id,
'cannot be displayed: empty content'
);
return false;
}
if (!this.can_display_by_visitor()) {
advads_pro_utils.log(
'passive ad id',
this.id,
'cannot be displayed: by_visitor'
);
return false;
}
if (!this.can_display_by_expiry_date()) {
advads_pro_utils.log(
'passive ad id',
this.id,
'cannot be displayed: by_expiry_date'
);
return false;
}
if (!this.can_display_by_timeout()) {
advads_pro_utils.log(
'passive ad id',
this.id,
'cannot be displayed: by_timeout'
);
return false;
}
if (!this.can_display_by_display_limit()) {
advads_pro_utils.log(
'passive ad id',
this.id,
'cannot be displayed: by_display_limit'
);
return false;
}
if (!this.can_display_by_weekday()) {
advads_pro_utils.log(
'passive ad id',
this.id,
'cannot be displayed: by_weekday'
);
return false;
}
if (!this.can_display_by_cfp()) {
advads_pro_utils.log(
'passive ad id',
this.id,
'cannot be displayed: by_cfp'
);
return false;
}
if (!this.can_display_by_consent()) {
advads_pro_utils.log(
'passive ad id',
this.id,
'cannot be displayed: by_consent'
);
return false;
}
const canDisplay = { display: true };
// Let modules and add-ons do a `canDisplay` check.
document.dispatchEvent(
new CustomEvent('advanced-ads-passive-cb-can-display', {
detail: {
canDisplay,
checkOptions: check_options,
adInfo: this,
},
})
);
return canDisplay.display;
}
/**
* Check visitor conditions
*
* @return {boolean} true if the ad can be displayed in frontend based on visitor settings, false otherwise
*/
can_display_by_visitor() {
if (!Array.isArray(this.visitors) || this.visitors.length === 0) {
return true;
}
window.Advads_passive_cb_Conditions.init();
var pos = 0,
last_result = false,
_condition;
for (var i = 0; i < this.visitors.length; ++i) {
_condition = this.visitors[pos];
// ignore OR if last result was true
if (last_result && _condition.connector === 'or') {
pos++;
continue;
}
last_result = window.Advads_passive_cb_Conditions.frontend_check(
_condition,
this
);
if (!last_result) {
// return false only, if the next condition doesnt have an OR operator
pos++;
if (
!this.visitors[pos] ||
this.visitors[pos].connector !== 'or'
) {
return false;
}
} else {
pos++;
}
}
return true;
}
/**
* Check expiry date
*
* @return {boolean} true if not expired yet
*/
can_display_by_expiry_date() {
if (this.expiry_date <= 0) {
return true;
}
// check against current time (universal time)
return this.expiry_date > ~~(new Date().getTime() / 1000);
}
/**
* Check if ad can be displayed today
*
* @return {boolean} true if ad can be displayed
*/
can_display_by_weekday() {
if (!this.day_indexes) {
return true;
}
var date = new Date(),
offsetMinutes =
window.advanced_ads_pro_ajax_object.wp_timezone_offset / 60,
offsetHours =
offsetMinutes / 60 >= 0
? Math.floor(offsetMinutes / 60)
: Math.ceil(offsetMinutes / 60);
offsetMinutes = date.getUTCMinutes() + (offsetMinutes % 60);
if (offsetMinutes > 60) {
offsetHours++;
offsetMinutes %= 60;
}
date.setHours(date.getUTCHours() + offsetHours);
date.setMinutes(offsetMinutes);
return jQuery.inArray(date.getDay(), this.day_indexes) >= 0;
}
/**
* Check close and timeout feature implemented by Advads Layer
*
* @return {boolean} true if ad can be displayed in frontend based on expiry date, false otherwise
*/
can_display_by_timeout() {
//check if ad was closed with a cookie before (Advads layer plugin)
return !advads_pro_utils.isset(advads.get_cookie('timeout_' + this.id));
}
/**
* Check if the ad can be displayed based on display limit
*
* @return {boolean} true if limit is not reached, false otherwise
*/
can_display_by_display_limit() {
if (this.once_per_page) {
var adsLen = advanced_ads_pro.ads.length;
for (var i = 0; i < adsLen; i++) {
if (
advanced_ads_pro.ads[i].type === 'ad' &&
parseInt(advanced_ads_pro.ads[i].id, 10) === this.id
) {
return false;
}
}
}
return true;
}
/**
* Check if the user is banned (Click Fraud Protection module).
*
* @return {boolean} false if banned
*/
can_display_by_cfp() {
// Check if the global setting is ignored.
for (const visitor of this.visitors) {
if (
visitor['type'] === 'ad_clicks' &&
visitor['exclude-from-global']
) {
return true;
}
}
// Check if the user is banned
return !advads.get_cookie('advads_pro_cfp_ban');
}
/**
* Check if ad can be displayed based on user's consent.
*
* @return {boolean} true if allowed
*/
can_display_by_consent() {
// If consent is not needed for the ad.
if (
!advads.privacy ||
this.privacy.ignore ||
(this.type === 'adsense' &&
advads.privacy.is_adsense_npa_enabled()) ||
((this.type === 'image' || this.type === 'dummy') &&
!this.privacy.needs_consent)
) {
return true;
}
var state = advads.privacy.get_state();
return state === 'accepted' || state === 'not_needed';
}
}
export const PassiveAdCompat = () => {
window.Advads_passive_cb_Ad = PassiveAd;
};

View File

@@ -0,0 +1,504 @@
/* eslint-disable */
import jQuery from 'jquery';
export class PassiveGroup {
/**
* Constructor
*
* @param {object} item object which contains info about the group.
* @param {string} elementid cache busting wrapper id.
*/
constructor(item, elementid) {
if (
!advads_pro_utils.isset(item.group_info.id) ||
!advads_pro_utils.isset(item.group_info.type) ||
!advads_pro_utils.isset(item.group_info.weights) ||
!advads_pro_utils.isset(item.group_info.ordered_ad_ids) ||
!advads_pro_utils.isset(item.group_info.ad_count) ||
!advads_pro_utils.isset(item.ads)
) {
throw new SyntaxError('Can not create Advads_passive_cb_Group obj');
}
this.id = item.group_info.id;
this.name = item.group_info.name ? item.group_info.name : this.id;
this.type = item.group_info.type;
this.weights = item.group_info.weights;
this.ordered_ad_ids = item.group_info.ordered_ad_ids;
this.ad_count = item.group_info.ad_count;
this.elementid = elementid ? elementid : null;
this.slider_options = advads_pro_utils.isset(
item.group_info.slider_options
)
? item.group_info.slider_options
: false;
this.refresh_enabled = advads_pro_utils.isset(
item.group_info.refresh_enabled
);
if (advads_pro_utils.isset(item.group_info.refresh_interval_for_ads)) {
this.refresh_interval = item.group_info.refresh_interval_for_ads;
} else if (advads_pro_utils.isset(item.group_info.refresh_interval)) {
// Deprecated.
this.refresh_interval = item.group_info.refresh_interval;
} else {
this.refresh_interval = 2000;
}
this.placement =
item instanceof Advads_passive_cb_Placement ? item : false;
this.random = item.group_info.random;
this.ads = item.ads;
this.group_wrap = item.group_wrap;
this.is_empty = true;
}
/**
* Inject group output inside the cache busting wrapper
*/
output() {
var ad_for_adblocker =
this.placement && this.placement.get_ad_for_adblocker();
advanced_ads_pro.hasAd(this.id, 'group', this.name, 'passive');
if (!ad_for_adblocker && this.refresh_enabled) {
this.output_refresh();
return;
}
var ordered_ad_ids,
ads_displayed = 0,
output_buffer = [];
const group_for_ab =
this.placement && this.placement.get_group_for_adblocker();
if (group_for_ab) {
this.ads = group_for_ab.ads;
}
switch (this.type) {
case 'ordered':
case 'slider':
ordered_ad_ids = this.shuffle_ordered_ads(
this.ordered_ad_ids,
this.weights
);
break;
case 'grid':
ordered_ad_ids = this.random
? this.shuffle_ads()
: this.shuffle_ordered_ads(
this.ordered_ad_ids,
this.weights
);
break;
default:
ordered_ad_ids = this.shuffle_ads();
}
if (!Array.isArray(ordered_ad_ids) || !jQuery.isPlainObject(this.ads)) {
return;
}
for (var i = 0; i < ordered_ad_ids.length; i++) {
if (!this.ads.hasOwnProperty(ordered_ad_ids[i])) {
continue;
}
var ad_info = this.ads[ordered_ad_ids[i]];
if (typeof ad_info === 'object') {
var ad = new Advads_passive_cb_Ad(ad_info, this.elementid);
if (ad.can_display()) {
if (ad_for_adblocker) {
ad = ad_for_adblocker;
}
const canTrack =
!advads.privacy ||
'unknown' !== advads.privacy.get_state();
if (
(this.type === 'slider' && this.slider_options) ||
this.group_wrap
) {
output_buffer.push(
ad.output({
track: canTrack,
inject: false,
do_has_ad: true,
})
);
} else {
ad.output({
track: canTrack,
inject: true,
do_has_ad: true,
});
}
ads_displayed++;
this.is_empty = false;
}
}
// break the loop when maximum ads are reached
if (ads_displayed === this.ad_count) {
break;
}
// show only first ad when an ad blocker is found.
if (!this.is_empty && ad_for_adblocker) {
break;
}
}
if (output_buffer.length) {
if (this.type === 'slider' && this.slider_options) {
output_buffer = this.output_slider(output_buffer);
}
advanced_ads_pro.inject(
this.elementid,
this.add_group_wrap(output_buffer, ads_displayed)
);
}
}
/**
* Output for group that has a refresh set up
*/
output_refresh() {
var ordered_ad_ids = this.ordered_ad_ids,
output_buffer = [],
self = this,
index = 0,
ad_id,
prev_ad_id = false,
tracked_ads = [],
ads_displayed = 0,
interval = this.refresh_interval;
var $el = jQuery('.' + self.elementid);
$el = advanced_ads_pro._inject_before(this.elementid, $el);
if (!Array.isArray(ordered_ad_ids) || !jQuery.isPlainObject(this.ads)) {
return;
}
/**
* Track the ad.
*
* @param {Object} ad Advads_passive_cb_Ad
*/
function track_ad(ad) {
if (jQuery.inArray(ad.id, tracked_ads) < 0 && ad.tracking_enabled) {
var data = {};
data[ad.blog_id] = [ad.id];
advanced_ads_pro.observers.fire({
event: 'inject_passive_ads',
ad_ids: data,
});
}
}
function pick_ids() {
switch (self.type) {
case 'ordered':
var prev_index = ordered_ad_ids.indexOf(prev_ad_id);
if (prev_index !== -1) {
var new_ids = ordered_ad_ids
.slice(prev_index + 1)
.concat(ordered_ad_ids.slice(0, prev_index));
} else {
var new_ids = ordered_ad_ids;
}
break;
default:
var new_ids = self.shuffle_ads();
var prev_index = new_ids.indexOf(prev_ad_id);
if (prev_index !== -1) {
new_ids.splice(prev_index, 1);
}
}
return new_ids;
}
function get_ad_interval(ad_id) {
if (typeof self.refresh_interval !== 'object') {
return parseInt(self.refresh_interval, 10) || 2000;
}
return parseInt(self.refresh_interval[ad_id], 10) || 2000;
}
/**
* Get the 'float' property from the ad or the placement.
*
* @param {Object} ad Advads_passive_cb_Ad
* @return string
*/
function get_position(ad) {
var position = '';
if (
advads_pro_utils.isset_nested(
self.placement,
'placement_info',
'options',
'placement_position'
)
) {
position =
self.placement.placement_info.options.placement_position;
}
if (['left', 'right'].indexOf(position) === -1) {
position = ad.position;
}
return position;
}
(function tick() {
var new_ids = pick_ids();
var idsLen = new_ids.length;
for (var i = 0; i < idsLen; i++) {
var ad_id = new_ids[i];
var ad_info = self.ads[ad_id];
if (typeof ad_info === 'object') {
var ad = new Advads_passive_cb_Ad(ad_info, self.elementid);
if (ad.can_display()) {
// The first ad will be tracked like all other passive ads.
if (ads_displayed === 0) {
output_buffer = [
ad.output({
track: true,
inject: false,
do_has_ad: true,
}),
];
advanced_ads_group_refresh.prepare_wrapper(
$el,
get_position(ad),
true
);
} else {
var do_has_ad =
jQuery.inArray(ad_id, tracked_ads) < 0;
output_buffer = [
ad.output({
track: false,
inject: false,
do_has_ad: do_has_ad,
}),
];
track_ad(ad);
advanced_ads_group_refresh.prepare_wrapper(
$el,
get_position(ad),
false
);
}
tracked_ads.push(ad.id);
advanced_ads_pro.inject(
self.elementid,
self.add_group_wrap(output_buffer, 1)
);
self.is_empty = false;
ads_displayed++;
setTimeout(function () {
if (
!self.placement ||
self.placement.can_display()
) {
tick();
}
}, get_ad_interval(ad_id));
prev_ad_id = ad.id;
break;
}
}
}
})();
}
/**
* Get markup to inject around each ad and around entire set of ads (if needed)
*
* @param {Array} output_buffer output buffer.
* @param {number} ads_displayed amount of ad to show for the group.
* @returns {string} output with wrapper (if any)
*/
add_group_wrap(output_buffer, ads_displayed) {
if (!output_buffer.length) {
return '';
}
var before = '',
after = '';
if (this.group_wrap) {
for (var i = 0; i < this.group_wrap.length; i++) {
var wrap = this.group_wrap[i];
wrap.min_ads = wrap.min_ads || 1;
if (typeof wrap !== 'object' || wrap.min_ads > ads_displayed) {
continue;
}
if (wrap.before) {
before = wrap.before + before;
}
if (wrap.after) {
after = after + wrap.after;
}
if (typeof wrap.each === 'string') {
for (var j = 0; j < output_buffer.length; j++) {
output_buffer[j] = wrap.each.replace(
'%s',
output_buffer[j]
);
}
} else if (typeof wrap.each === 'object') {
var each_obj = wrap.each;
for (var j = 0; j < output_buffer.length; j++) {
for (var format_index in each_obj) {
var ad_wrapped = false;
if (
each_obj.hasOwnProperty(format_index) &&
format_index !== 'all' &&
(1 + j) % parseInt(format_index, 10) === 0
) {
output_buffer[j] = each_obj[
format_index
].replace('%s', output_buffer[j]);
ad_wrapped = true;
break;
}
}
if (!ad_wrapped && each_obj.all) {
// applied here since JavaScript does not guarantee object key order
output_buffer[j] = each_obj.all.replace(
'%s',
output_buffer[j]
);
}
}
}
}
}
return before + output_buffer.join('') + after;
}
/**
* Output slider markup around slides
*
* @param output_buffer output buffer
* @deprecated since AAS_VERSION > 1.3.1
* @returns {*[]}
*/
output_slider(output_buffer) {
var output_html, ads_output;
if (
output_buffer.length > 1 &&
typeof jQuery.fn.unslider === 'function'
) {
ads_output = output_buffer.join('</li><li>');
output_buffer = [];
output_buffer.push(
'<div id="' +
this.slider_options.slider_id +
'" class="' +
this.slider_options.init_class +
' ' +
this.slider_options.prefix +
'slider"><ul><li>'
);
output_buffer.push(ads_output);
output_buffer.push('</li></ul></div>');
/* custom css file was added with version 1.1 of Advads Slider. Deactivate the following lines if there are issues with your layout
output_buffer.push( "<style>.advads-slider { position: relative; width: 100% !important; overflow: hidden; } " );
output_buffer.push( ".advads-slider ul, .advads-slider li { list-style: none; margin: 0 !important; padding: 0 !important; } " );
output_buffer.push( ".advads-slider ul li { width: 100%; float: left; }</style>" );
*/
output_buffer.push(
'<scr' +
"ipt>jQuery(function() { jQuery('." +
this.slider_options.init_class +
"').unslider({ " +
this.slider_options.settings +
' }); });</scr' +
'ipt>'
);
}
return output_buffer;
}
/**
* Shuffle ads that have the same weights.
*
* @param {Array} ordered_ad_ids Ad ids.
* @param {Object} weights ad_id: weight pairs.
* @return {Array} ordered_ad_ids Ad ids.
*/
shuffle_ordered_ads(ordered_ad_ids, weights) {
// Get weights of ordered ad ids.
const weight_array = [];
for (var i = 0; i < ordered_ad_ids.length; i++) {
var weight = weights[ordered_ad_ids[i]];
if (!weight) {
return ordered_ad_ids;
}
weight_array.push(weight);
}
var count = weight_array.length;
var pos = 0;
for (var i = 1; i <= count; i++) {
if (i == count || weight_array[i] !== weight_array[i - 1]) {
var slice_len = i - pos;
if (slice_len !== 1) {
var shuffled = advads_pro_utils.shuffle_array(
ordered_ad_ids.slice(pos, pos + slice_len)
);
// Replace the unshuffled chunk of array with the shuffled one.
var arg = [pos, slice_len].concat(shuffled);
Array.prototype.splice.apply(ordered_ad_ids, arg);
}
pos = i;
}
}
return ordered_ad_ids;
}
/**
* shuffle ads based on ad weight
*
* @return {Array} shuffled array with ad ids
*/
shuffle_ads() {
const shuffled_ads = [],
ad_weights = jQuery.extend({}, this.weights);
let random_ad_id = advads_pro_utils.get_random_el_by_weight(ad_weights);
// while non-zero weights are set select random next
while (null !== random_ad_id) {
// remove chosen ad from weights array
delete ad_weights[random_ad_id];
// put random ad into shuffled array
shuffled_ads.push(parseInt(random_ad_id, 10));
random_ad_id = advads_pro_utils.get_random_el_by_weight(ad_weights);
}
return shuffled_ads;
}
}
export const PassiveGroupCompat = () => {
window.Advads_passive_cb_Group = PassiveGroup;
};

View File

@@ -0,0 +1,310 @@
/* eslint-disable */
import jQuery from 'jquery';
export class PassivePlacement {
/**
* Constructor
*
* @param {Object} placement
* @param {string} element_id
*/
constructor(placement, element_id) {
if (
typeof placement !== 'object' ||
!placement.hasOwnProperty('id') ||
!placement.hasOwnProperty('type') ||
!placement.hasOwnProperty('ads') ||
!placement.hasOwnProperty('placement_info') ||
typeof placement.ads !== 'object'
) {
throw new SyntaxError(
'Can not create Advads_passive_cb_Placement obj'
);
}
this.id = placement.id;
this.ajax_query = placement.ajax_query;
this.type = placement.type;
this.element_id = element_id;
this.ads = placement.ads;
this.ads_for_ab = placement.ads_for_ab;
this.groups_for_ab = placement.groups_for_ab;
this.placement_info = placement.placement_info;
this.placement_id = advads_pro_utils.isset_nested(
this.placement_info,
'id'
)
? parseInt(this.placement_info.id, 10)
: null;
this.group_info = placement.group_info;
this.group_wrap = placement.group_wrap;
this.server_info_duration =
parseInt(placement.server_info_duration, 10) || 0;
// Conditions that can be checked by passive cache-busting only if cookies exist.
// If not, ajax cache-busting will be used.
this.server_conditions = placement.server_conditions;
if (placement.inject_before) {
advanced_ads_pro.inject_before.push({
elementId: this.element_id,
data: placement.inject_before,
});
}
}
/**
* Check if the placement can be displayed in frontend due to its own conditions
*
* @return {boolean} true if the placement can be displayed in frontend, false otherwise
*/
can_display() {
if (
advads_pro_utils.isset_nested(this.placement_info, 'test_id') &&
jQuery.inArray(
this.placement_info.slug,
advanced_ads_pro.get_random_placements()
) < 0
) {
// do not deliver placement, that belongs to a test, and was not randomly selected by weight
return false;
}
//check if placement was closed with a cookie before (Advads layer plugin)
if (
advads_pro_utils.isset_nested(
this.placement_info,
'layer_placement',
'close',
'enabled'
) &&
this.placement_info.layer_placement.close.enabled
) {
if (
advads_pro_utils.isset_nested(
this.placement_info,
'layer_placement',
'close',
'timeout_enabled'
) &&
this.placement_info.layer_placement.close.timeout_enabled &&
advads_pro_utils.isset(
advads.get_cookie(
'timeout_placement_' + this.placement_info.slug
)
)
) {
return false;
}
}
//check if placement was closed with a cookie before (Sticky Ads plugin)
if (
advads_pro_utils.isset_nested(
this.placement_info,
'close',
'enabled'
) &&
this.placement_info.close.enabled
) {
if (
advads_pro_utils.isset_nested(
this.placement_info,
'close',
'timeout_enabled'
) &&
this.placement_info.close.timeout_enabled &&
advads_pro_utils.isset(
advads.get_cookie(
'timeout_placement_' + this.placement_info.slug
)
)
) {
return false;
}
}
// dont show `Custom Position` placement ad if selector doesnt exist
if (
advads_pro_utils.isset_nested(this.placement_info, 'options') &&
typeof this.placement_info.options === 'object'
) {
var params = this.placement_info.options;
// do not show `Custom Position` placement ad if selector doesn't exist
if (!advads_pro_utils.selector_exists(params)) {
return false;
}
}
return true;
}
/**
* Check if passive cache-busting can be used, i.e. all needed cookies exist.
*
* @return {boolean} true if passive method can be used for this placement
*/
can_use_passive_cb() {
if (!this.ajax_query) {
return true;
}
var stored_info = window.Advads_passive_cb_Conditions.get_stored_info();
var now = ~~(new Date().getTime() / 1000);
for (var hash in this.server_conditions) {
if (!this.server_conditions.hasOwnProperty(hash)) {
continue;
}
var condition = this.server_conditions[hash];
var stored_type = stored_info[condition.type];
if ('object' !== typeof stored_type) {
return false;
}
var stored_condition = stored_type[hash];
if ('object' !== typeof stored_condition) {
return false;
}
if (
(parseInt(stored_condition.time, 10) || 0) +
this.server_info_duration <
now
) {
return false;
}
}
return true;
}
/**
* Fill the placement with the final output
*/
output() {
let is_empty = true;
const group_for_ab = this.get_group_for_adblocker();
if (this.can_display()) {
switch (this.type) {
case 'ad':
if (!this.can_display()) {
break;
}
let ad = new Advads_passive_cb_Ad(
this.ads[this.id],
this.element_id
); // only one ad, pass it as argument
if (!ad.can_display()) {
break;
}
const ad_for_adblocker = this.get_ad_for_adblocker();
if (group_for_ab) {
this.swap_group_info(group_for_ab);
const group = new Advads_passive_cb_Group(
this,
this.element_id
);
group.output();
is_empty = group.is_empty;
break;
} else if (
ad_for_adblocker &&
ad_for_adblocker.can_display()
) {
ad = ad_for_adblocker;
}
ad.output({
track:
!advads.privacy ||
'unknown' !== advads.privacy.get_state(),
inject: true,
do_has_ad: true,
});
is_empty = false;
break;
case 'group':
if (typeof this.group_info === 'object') {
if (group_for_ab) {
this.swap_group_info(group_for_ab);
}
const group = new Advads_passive_cb_Group(
this,
this.element_id
);
group.output();
is_empty = group.is_empty;
}
break;
}
}
advanced_ads_pro.dispatchWrapperCBEvent(
this.element_id,
is_empty,
'passive',
{
emptyCbOption: Boolean(this.placement_info.cache_busting_empty),
}
);
advanced_ads_pro.observers.fire({
event: 'inject_placement',
id: this.placement_id,
is_empty: is_empty,
cb_type: 'passive',
});
advanced_ads_pro.hasAd(
this.placement_id,
'placement',
this.placement_info.title,
'passive'
);
}
/**
* Swap placement item to group type (if not group yet) and use an alternate group info data
*
* @param {Array} group data about the alternative group to use
*/
swap_group_info(group) {
this.id = group.id;
this.type = 'group';
this.group_info = group;
}
/**
* Get passive ad object from the ad blocker item of the placement
*
* @return {Object|boolean} Advads_passive_cb_Ad or false if no ad for ad blocker is set up.
*/
get_ad_for_adblocker() {
return advanced_ads_pro.adblocker_active && this.ads_for_ab
? new Advads_passive_cb_Ad(
this.ads_for_ab[Object.keys(this.ads_for_ab)[0]],
this.element_id
)
: false;
}
/**
* Get group info from the ad blocker item of the placement
*
* @return {Array|boolean} Group info or false if no group is set up as ad blocker item.
*/
get_group_for_adblocker() {
return advanced_ads_pro.adblocker_active && this.groups_for_ab
? this.groups_for_ab
: false;
}
}
export const PassivePlacementCompat = () => {
window.Advads_passive_cb_Placement = PassivePlacement;
};

View File

@@ -0,0 +1,261 @@
/* eslint-disable */
import jQuery from 'jquery';
export const Utils = {
debug:
window.location &&
window.location.hash &&
window.location.hash.indexOf('#debug=true') !== -1,
// Loop over each item in an array-like value.
each: function (arr, fn, _this) {
var i,
len = (arr && arr.length) || 0;
for (i = 0; i < len; i++) {
fn.call(_this, arr[i], i);
}
},
// Loop over each key/value pair in a hash.
each_key: function (obj, fn, _this) {
if ('object' === typeof obj) {
var key;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
fn.call(_this, key, obj[key]);
}
}
}
},
/**
* Log messages to the browser console.
*/
log: function () {
if (this.debug && this.isset(window.console)) {
var args = Array.prototype.slice.call(arguments);
args.unshift('Advanced Ads CB:');
window.console.log.apply(window.console, args);
}
},
/**
* Log cache-busting arrays (AJAX and passive cb).
*/
print_debug_arrays: function () {
if (advanced_ads_pro.iterations === 0) {
// Available when passive cb is enabled for all ads/groups which are not delivered through a placement.
this.log('passive_ads\n', window.advads_passive_ads);
this.log('passive_groups\n', window.advads_passive_groups);
this.log('passive_placements\n', window.advads_passive_placements);
this.log('ajax_queries\n', window.advads_ajax_queries);
this.log(
window.Advads_passive_cb_Conditions.VISITOR_INFO_COOKIE_NAME +
'\n',
window.Advads_passive_cb_Conditions.get_stored_info()
);
}
},
isset: function (str) {
return typeof str !== 'undefined';
},
/**
* Check if nested object key exists
*
* @param {obj}
* @params {str} level1, .. levelN
* @return {bool} true on success false on failure
*/
isset_nested: function (obj) {
var argsLen = arguments.length;
for (var i = 1; i < argsLen; i++) {
if (!obj || !obj.hasOwnProperty(arguments[i])) {
return false;
}
obj = obj[arguments[i]];
}
return true;
},
is_numeric: function (n) {
return !isNaN(parseFloat(n)) && isFinite(n);
},
// generate a random number between min and max (inclide min and max)
get_random_number: function (min, max) {
var rand = min - 0.5 + Math.random() * (max - min + 1);
return Math.round(rand);
},
/**
* Get random element by weight
*
* @param {object} weights e.g. {'A' => 2, 'B' => 3, 'C' => 5}
* @param {string} skip to skip, e.g. 'A'
* @source applied with fix for order http://stackoverflow.com/a/11872928/904614
*/
get_random_el_by_weight: function (weights, skip) {
var max = 0,
rand;
skip = typeof skip !== 'undefined' ? skip : false;
if (typeof weights === 'object') {
for (var el in weights) {
if (el !== skip && weights.hasOwnProperty(el)) {
max += parseInt(weights[el]) || 0;
}
}
if (max < 1) {
return null;
}
rand = advads_pro_utils.get_random_number(1, max);
for (var el in weights) {
if (el !== skip && weights.hasOwnProperty(el)) {
rand -= weights[el];
if (rand <= 0) {
return el;
}
}
}
}
},
/**
* A 'polyfill' of the native 'bind' function.
*
* @param {function} func
* @param {obj} context
*/
bind: function (func, context) {
return function () {
return func.apply(context, arguments);
};
},
/**
* Shuffle array (knuthfisheryates).
* http://stackoverflow.com/a/2450976/1037948
*
* @param {array} arr
* @return {array} arr
*/
shuffle_array: function (arr) {
var temp,
j,
i = arr.length;
if (!i) {
return arr;
}
while (--i) {
j = ~~(Math.random() * (i + 1));
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
return arr;
},
/**
* Check if the selector of the Custom position placement exists.
*
* @param {array} params Placement options.
* @return bool
*/
selector_exists: function (params) {
var cp_target =
!params.inject_by || params.inject_by === 'pro_custom_element'
? 'pro_custom_element'
: 'container_id';
var el = params[cp_target];
if (!el) {
// Not Custom Position placement.
return true;
}
var $el = jQuery(el);
if (!$el.length) {
advads_pro_utils.log('selector does not exist', el);
return false;
}
if (
!advanced_ads_pro_ajax_object.moveintohidden &&
!$el.filter(':visible').length
) {
advads_pro_utils.log('selector is hidden', el);
return false;
}
return true;
},
/**
* Converts the number in degrees to the radians.
*/
deg2rad: function (deg) {
return (deg * Math.PI) / 180;
},
/**
* Computes the distance between the coordinates and returns the result.
*/
calculate_distance: function (lat1, lon1, lat2, lon2, unit) {
unit = unit || 'km';
lat1 = this.deg2rad(lat1);
lon1 = this.deg2rad(lon1);
lat2 = this.deg2rad(lat2);
lon2 = this.deg2rad(lon2);
const dLon = lon2 - lon1;
a =
Math.pow(Math.cos(lat2) * Math.sin(dLon), 2) +
Math.pow(
Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon),
2
);
b =
Math.sin(lat1) * Math.sin(lat2) +
Math.cos(lat1) * Math.cos(lat2) * Math.cos(dLon);
const rad = Math.atan2(Math.sqrt(a), b);
if (unit === 'mi') {
return rad * 3958.755865744;
} else {
return rad * 6371.0;
}
},
/**
* Extract cookie data from a stringified cookie.
*
* @param {string} cookie {
* A stringified cookie.
*
* @type {string} data Cookie data.
* @type {string} expire Expiration time.
* }
* @return {mixed} The data field on success, original stringified cookie on error.
*/
extract_cookie_data(cookie) {
try {
var cookie_obj = JSON.parse(cookie);
} catch (e) {
return cookie;
}
if (typeof cookie_obj !== 'object') {
return cookie;
}
return cookie_obj.data;
},
};
export const UtilsCompat = () => {
window.advads_pro_utils = Utils;
};

View File

@@ -0,0 +1,221 @@
import jQuery from 'jquery';
import { PassiveAdCompat } from './cache-busting/passive-ad';
import { PassivePlacementCompat } from './cache-busting/passive-placement';
import { CacheBusting, CacheBustingCompat } from './cache-busting/cacheBusting';
import { PassiveConditionsCompat } from './cache-busting/passive-conditions';
import { PassiveGroupCompat } from './cache-busting/passive-group';
import { Utils, UtilsCompat } from './cache-busting/utils';
import { GroupRefreshCompat } from './cache-busting/group-refresh';
import Adsense from './adsense/adsense';
CacheBustingCompat();
PassiveConditionsCompat();
PassivePlacementCompat();
PassiveAdCompat();
PassiveGroupCompat();
UtilsCompat();
GroupRefreshCompat();
jQuery(() => {
Adsense();
});
/* eslint-disable */
if (
typeof advads !== 'undefined' &&
typeof advads.privacy.dispatch_event !== 'undefined'
) {
// check for changes in privacy settings.
document.addEventListener('advanced_ads_privacy', function (event) {
if (
event.detail.previousState !== 'unknown' &&
!(
event.detail.previousState === 'rejected' &&
event.detail.state === 'accepted'
)
) {
Utils.log(
'no action! transition from ' +
event.detail.previousState +
' to ' +
event.detail.state
);
return;
}
Utils.log(
'reload ads! transition from ' +
event.detail.previousState +
' to ' +
event.detail.state
);
if (
event.detail.state === 'accepted' ||
event.detail.state === 'not_needed'
) {
var encodedAd =
'script[type="text/plain"][data-tcf="waiting-for-consent"]';
// Find all scripts and decode them.
document.querySelectorAll(encodedAd).forEach(function (node) {
// Add the decoded ad ids to passive_ads, so they can be tracked.
if (
!CacheBusting.passive_ads.hasOwnProperty(node.dataset.bid)
) {
CacheBusting.passive_ads[node.dataset.bid] = [];
}
CacheBusting.passive_ads[node.dataset.bid].push(
parseInt(node.dataset.id, 10)
);
advads.privacy.decode_ad(node);
});
// Observe all child node changes on body; check for dynamically added encoded ads.
new MutationObserver(function (mutations) {
var decoded_ads = {},
decode_ad = function (node) {
if (
typeof node.dataset.noTrack === 'undefined' ||
node.dataset.noTrack !== 'impressions'
) {
if (!decoded_ads.hasOwnProperty(node.dataset.bid)) {
decoded_ads[node.dataset.bid] = [];
}
decoded_ads[node.dataset.bid].push(
parseInt(node.dataset.id, 10)
);
}
advads.privacy.decode_ad(node);
};
mutations.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
// The injected node is the ad itself.
if (
typeof node.tagName !== 'undefined' &&
typeof node.dataset !== 'undefined' &&
node.tagName.toLowerCase() === 'script' &&
node.dataset.tcf === 'waiting-for-consent'
) {
decode_ad(node);
return;
}
// The injected node might hold encoded ads, e.g. in infinite scroll.
if (
typeof node.dataset === 'undefined' ||
node.dataset.tcf !== 'waiting-for-consent'
) {
document
.querySelectorAll(encodedAd)
.forEach(decode_ad);
}
});
});
if (Object.keys(decoded_ads).length) {
CacheBusting.observers.fire({
event: 'advanced_ads_decode_inserted_ads',
ad_ids: decoded_ads,
});
}
}).observe(document, {
subtree: true,
childList: true,
});
}
// Wait for advanced_ads_pro to return to idle state.
if (CacheBusting.busy) {
// Only hook this once to prevent infinite loops.
document.addEventListener(
'advanced_ads_pro.idle',
CacheBusting.process_passive_cb,
{ once: true }
);
return;
}
CacheBusting.process_passive_cb();
});
} else {
// Fallback for older versions of base plugin.
(window.advanced_ads_ready || jQuery(document).ready).call(
null,
function () {
CacheBusting.process_passive_cb();
}
);
}
/* eslint-enable */
// Reload ads when screen resizes.
jQuery(document).on('advanced-ads-resize-window', function () {
const handleResize = function () {
// Remove ajax and passive ads.
let cbCount = CacheBusting.ads.length;
while (cbCount--) {
if ('off' !== CacheBusting.ads.cb_method) {
CacheBusting.ads.splice(cbCount, 1);
}
}
CacheBusting.process_passive_cb();
};
// Wait for advanced_ads_pro to return to idle state.
if (CacheBusting.busy) {
// Only hook this once to prevent infinite loops.
document.addEventListener('advanced_ads_pro.idle', handleResize, {
once: true,
});
return;
}
handleResize();
});
/**
* Removes placement placeholder if cache busting could not fill it.
*/
document.addEventListener('advads_pro_cache_busting_done', (ev) => {
if (!ev.detail.isEmpty || !ev.detail.extra.emptyCbOption) {
return;
}
let wrapper = document.getElementById(ev.detail.elementId);
if (!wrapper) {
return;
}
// If the placement is the only thing in the widget (e.g. not within a column block).
if (wrapper.parentNode && wrapper.parentNode.classList.contains('widget')) {
wrapper = wrapper.parentNode;
}
wrapper.remove();
});
/**
* Update ad health ad count on ad injection.
*/
const updateAdHealthCount = () => {
const adHealth = document.getElementById(
'wp-admin-bar-advanced_ads_ad_health_highlight_ads'
);
if (!adHealth) {
return;
}
adHealth.querySelector('.highlighted_ads_count').innerText =
document.querySelectorAll(
`.${window.advancedAds.frontendPrefix}highlight-wrapper`
).length;
};
CacheBusting.observers.add((event) => {
if (
-1 === ['inject_passive_ads', 'inject_ajax_ads'].indexOf(event.event) ||
(Array.isArray(event.ad_ids) && !event.ad_ids.length)
) {
return;
}
updateAdHealthCount();
});

View File

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