1;(function($){ 2 3 // CFP cookies prefix 4 var cname = 'advads_procfp'; 5 var cname_vc = 'advanced_ads_ad_clicks'; // visitor conditions 6 7 // CFP cookies parameter ( domain/path ) 8 var PATH = null; 9 var DOMAIN = null; 10 11 /** 12 * wrapper for JSON.parse 13 */ 14 function jsonDecode( str ) { 15 try { 16 var res = JSON.parse( str ); 17 return res; 18 } catch( Ex ) { 19 return null; 20 } 21 } 22 23 // Max ad click conditions/ passive Cache busting. 24 25 $( document ).on( 'advads-passive-cb-conditions', function( e, cbs ) { 26 cbs.conditions['ad_clicks'] = 'check_ad_clicks'; 27 cbs['check_ad_clicks'] = function ( options, ad ) { 28 if ( advads.cookie_exists( cname_vc + '_' + ad.id ) ) { 29 var C_vc = advads.get_cookie( cname_vc + '_' + ad.id ); 30 C_vc = jsonDecode( C_vc ); 31 } 32 33 if ( C_vc ) { 34 var now = parseInt( new Date().getTime() / 1000 ); 35 for ( var i in C_vc ) { 36 37 if ( '_' + options.expiration == i ) { 38 39 // if still valid counter and click limit reached 40 if ( C_vc[i]['ttl'] >= now && C_vc[i]['count'] >= parseInt( options.limit ) ) { 41 return false; 42 } 43 44 } 45 46 } 47 } 48 49 return true; 50 }; 51 }); 52 53 var cfpTracker = function() { 54 this.$elements = {}; 55 this.currentIFrame = false; 56 this.focusLost = false; 57 this.init(); 58 } 59 60 cfpTracker.prototype = { 61 62 constructor: cfpTracker, 63 64 init: function() { 65 var that = this; 66 67 // increment counter on click on link 68 $( document ).on( 'click', 'a[data-cfpa]', function(){ 69 that.onClick( parseInt( $( this ).attr( 'data-cfpa' ) ) ); 70 } ); 71 72 // increment counter on blur only if an iframe has recently bern hovered 73 $( window ).on( 'blur', function() { 74 if ( false !== that.currentIFrame ) { 75 that.onClick( that.currentIFrame ); 76 that.currentIFrame = false; 77 that.focusLost = true; 78 } 79 } ); 80 81 // 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) 82 $( document ).on( 'mouseenter', 'div[data-cfpa]', function(){ 83 var id = parseInt( $( this ).attr( 'data-cfpa' ) ); 84 that.addElement( id ); 85 } ); 86 }, 87 88 addElement: function( $el ) { 89 if ( false === $el instanceof jQuery ) { 90 $el = $( '[data-cfpa="' + $el + '"]' ); 91 } 92 93 var hasIframe = $el.find( 'iframe' ).length ? true : false; 94 if ( !hasIframe ) { 95 if ( !$el.find( 'a' ).length ) { 96 // no an anchor and no iframe -- likely and ad that is not yet loaded (adsense or other ad network) 97 return; 98 } 99 } 100 101 var adID = parseInt( $el.attr( 'data-cfpa' ) ); 102 103 this.$elements[adID] = $el; 104 105 // remove attribute from the wrapper 106 $el.removeAttr( 'data-cfpa' ); 107 108 // And then move it to the first anchor or iframe found 109 if ( hasIframe ) { 110 $el.find( 'iframe' ).first().attr({ 111 'data-cfpa': adID, 112 }) 113 if ( $el.attr( 'data-cfph' ) ) { 114 $el.find( 'iframe' ).first().attr({ 115 'data-cfph': $el.attr( 'data-cfph' ), 116 }) 117 } 118 } else { 119 $el.find( 'a' ).not( '.advads-edit-button' ).first().attr({ 120 'data-cfpa': adID, 121 }) 122 if ( $el.attr( 'data-cfph' ) ) { 123 $el.find( 'a' ).not( '.advads-edit-button' ).first().attr({ 124 'data-cfph': $el.attr( 'data-cfph' ), 125 }) 126 } 127 } 128 // remove Hours attribute from the wrapper 129 $el.removeAttr( 'data-cfph' ); 130 131 // update TTL field for all outdated counter (visitor conditions) 132 if ( advads.cookie_exists( cname_vc + '_' + adID ) ) { 133 134 var C_vc = advads.get_cookie( cname_vc + '_' + adID ); 135 C_vc = jsonDecode( C_vc ); 136 137 if ( C_vc ) { 138 var now = parseInt( new Date().getTime() / 1000 ), cookie_modified = false; 139 for ( var i in C_vc ) { 140 if ( !C_vc.hasOwnProperty( i ) ) continue; 141 if ( 'exp' == i ) continue; 142 if ( C_vc[i]['ttl'] < now ) { 143 var period = parseFloat( i.substr( 1 ) ); 144 var newTTL = C_vc[i]['ttl']; 145 while ( newTTL < now ) { 146 newTTL += period * 60 * 60; 147 } 148 C_vc[i]['ttl'] = newTTL; 149 C_vc[i]['count'] = 0; 150 cookie_modified = true; 151 } 152 } 153 if ( cookie_modified ) { 154 var expTime = new Date( C_vc['exp'] ); 155 advads.set_cookie_sec( cname_vc + '_' + adID, JSON.stringify( C_vc, 'false', false ), parseInt( expTime.getTime() / 1000 ), PATH, DOMAIN ); 156 } 157 } 158 159 } 160 }, 161 162 onClick: function( ID ){ 163 var C = false, C_vc = false;
164 165 if ( $( '[data-cfpa="' + ID + '"]' ).attr( 'data-cfph' ) ) { 166 // if there are some visitor conditions, use the vc cookie 167 168 if ( advads.cookie_exists( cname_vc + '_' + ID ) ) { 169 C_vc = advads.get_cookie( cname_vc + '_' + ID ); 170 C_vc = jsonDecode( C_vc ); 171 } 172 173 if ( C_vc ) { 174 // Cookie already exists, increment each counter (keep expiration time) 175 for ( var h in C_vc ) { 176 if ( !C_vc.hasOwnProperty( h ) ) continue; 177 if ( 'exp' == h ) continue; 178 var count = parseInt( C_vc[h]['count'] ); 179 C_vc[h]['count'] = count + 1; 180 } 181 var now = new Date(); 182 var expiry = new Date( C_vc.exp ); 183 var expirySecs = parseInt( ( expiry.getTime() - now.getTime() ) / 1000 ); 184 advads.set_cookie_sec( cname_vc + '_' + ID, JSON.stringify( C_vc, 'false', false ), expirySecs, PATH, DOMAIN ); 185 } else { 186 // create a new cookie 187 var H = $( '[data-cfpa="' + ID + '"]' ).attr( 'data-cfph' ).split( '_' ); 188 var cval = {}, maxHValue = 0; 189 190 var d = new Date(); 191 var now = new Date(); 192 193 for ( var h in H ) { 194 if ( parseFloat( H[h] ) > maxHValue ) { 195 maxHValue = parseFloat( H[h] ); 196 } 197 cval['_' + H[h]] = { 198 count: 1, 199 ttl: parseInt( ( ( now.getTime() / 1000 ) + ( parseFloat( H[h] ) * 3600 ) ) ), 200 }; 201 } 202 203 // use the longest hour value for the expiry time 204 d.setTime( d.getTime() + ( maxHValue * 60 * 60 * 1000 ) ); 205 var expires = "expires="+ d.toUTCString(); 206 var expirySecs = parseInt( ( d.getTime() - now.getTime() ) / 1000 ); 207 208 cval['exp'] = expires; 209 advads.set_cookie_sec( cname_vc + '_' + ID, JSON.stringify( cval, 'false', false ), expirySecs, PATH, DOMAIN ); 210 } 211 212 } else { 213 // use the module wide CFP cookie 214 215 if ( advads.cookie_exists( cname + '_' + ID ) ) { 216 C = advads.get_cookie( cname + '_' + ID ); 217 C = jsonDecode( C ); 218 } 219 if ( C ) { 220 // Cookie already exists, increment the counter (keep expiration time) 221 222 var count = parseInt( C.count ); 223 C.count = count +1; 224 var now = new Date(); 225 var expiry = new Date( C.exp ); 226 var expirySecs = ( expiry.getTime() - now.getTime() ) / 1000; 227 advads.set_cookie_sec( cname + '_' + ID, JSON.stringify( C, 'false', false ), expirySecs, PATH, DOMAIN ); 228 if ( advadsCfpClickLimit <= C.count && 'undefined' != typeof advadsCfpBan ) { 229 // CFP module enabled - ban this visitor 230 var d = new Date(); 231 d.setTime( d.getTime() + ( advadsCfpBan*24*60*60*1000 ) ); 232 var ban = ( d.getTime() - now.getTime() ) / 1000; 233 advads.set_cookie_sec( 'advads_pro_cfp_ban', 1, ban, PATH, DOMAIN ); 234 } 235 } else { 236 // create a new cookie 237 238 var d = new Date(); 239 var now = new Date(); 240 d.setTime( d.getTime() + ( advadsCfpExpHours*60*60*1000 ) ); 241 var expires = "expires="+ d.toUTCString(); 242 var expirySecs = ( d.getTime() - now.getTime() ) / 1000; 243 advads.set_cookie_sec( cname + '_' + ID, '{"count":1,"exp":"' + expires + '"}', expirySecs, PATH, DOMAIN ); 244 } 245 } 246 247 }, 248 } 249 250 // IFRAME click tracking 251 $( document ).on( 'mouseenter', 'iframe[data-cfpa]', function(){ 252 var ID = parseInt( $( this ).attr( 'data-cfpa' ) ); 253 advadsProCfp.currentIFrame = ID; 254 } ).on( 'mouseleave', '[data-cfpa]', function(){ 255 advadsProCfp.currentIFrame = false; 256 if ( advadsProCfp.focusLost ) { 257 advadsProCfp.focusLost = false; 258 $( window ).focus(); 259 } 260 } ); 261 262 $( function(){ 263 264 /** 265 * Max ad click ( visitor conditions ) 266 */ 267 window.advadsProCfp = new cfpTracker(); 268 269 // construct all elements already present in the queue 270 for( var i in advadsCfpQueue ) { 271 if ( advadsCfpQueue.hasOwnProperty( i ) ) { 272 advadsProCfp.addElement( advadsCfpQueue[i] ); 273 } 274 } 275 276 advadsCfpQueue = []; 277 278 /** 279 * Click fraud protection module. 280 */ 281 if ( 'undefined' == typeof window.advadsCfpPath ) return; 282 283 // get the path/domain parameter to use in cookies 284 if ( '' != advadsCfpPath ) { 285 PATH = advadsCfpPath; 286 } 287 288 if ( '' != advadsCfpDomain ) { 289 DOMAIN = advadsCfpDomain; 290 } 291 292 293 } ); 294 295})(window.jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.