Commit aa97de3e authored by Christoph Zysik's avatar Christoph Zysik

classify ptc

parent 7fc8a34d
......@@ -38,6 +38,7 @@ $vms->ptc->setCurrentRunningAd( $art, $kampdaten->id, $tan );
<body>
<script>
var notified = false;
var VmsPtc = new zPtc();
var campaign_data = <?php echo json_encode(array('earnings' => $kampdaten->verdienst, 'wait_time' => $kampdaten->aufendhalt, 'ad_type' => $kampdaten->werbeart, 'tan' => $kampdaten->tan)); ?>;
function notify()
......
......@@ -13,11 +13,31 @@ head ('Klickbanner');
</script>
<script>
var VmsPtc = new zPtc();
$( document )
.ready(
function()
{
window.addEventListener("message",
function(event)
{
if ( pageconfig['domain'] != event.origin )
{
return;
}
var art = event.data['art'],
tan = event.data['tan'],
action = event.data['action'];
if( 'adcheck' == action )
{
VmsPtc.setAdWindowOpened( art, tan, true );
}
}
);
function displayAds(data, status)
{
var useData = jQuery.parseJSON( data );
......@@ -28,9 +48,9 @@ $( document )
}
}
$( "#loadAds_btn").on('click', function(e) { loadAds( 'forcedbanner', 'getNewPtcData', displayAds ) } );
$( "#loadAds_btn").on('click', function(e) { VmsPtc.loadAds( 'forcedbanner', 'getNewPtcData', displayAds ) } );
loadAds( 'forcedbanner', 'getNewPtcData', displayAds );
VmsPtc.loadAds( 'forcedbanner', 'getNewPtcData', displayAds );
/*
* gets executed on click on ad
......@@ -52,7 +72,7 @@ $( document )
)
{
$(elem).remove();
openAdWindow( art, tan, sec, use_frame );
VmsPtc.openAdWindow( art, tan, sec, use_frame );
}
}
);
......
// requires var VmsPtc = new zPtc();
notify();
function use_frame_cll( secstatus, data )
......@@ -21,14 +23,14 @@ function use_frame_cll( secstatus, data )
}
}
startAdCountdown( campaign_data['ad_type'], campaign_data['tan'], campaign_data['wait_time'], use_frame_cll );
VmsPtc.startAdCountdown( campaign_data['ad_type'], campaign_data['tan'], campaign_data['wait_time'], use_frame_cll );
Visibility.change(
function (e, state)
{
if( 'hidden' == state )
{
invalidateAd( campaign_data['ad_type'], campaign_data['tan'] );
VmsPtc.invalidateAd( campaign_data['ad_type'], campaign_data['tan'] );
}
}
......
class zPtc {
var adFenster = new Array();
window.addEventListener("message", function(event)
{
if ( pageconfig['domain'] != event.origin )
{
return;
}
var art = event.data['art'],
tan = event.data['tan'],
action = event.data['action'];
if( 'adcheck' == action )
{
adFenster[art][tan]['opened'] = true;
constructor()
{
this.adFenster = new Array();
}
}
}
);
setAdWindowOpened( art, tan, ostatus )
{
this.adFenster[art][tan]['opened'] = true;
}
function checkAdOk( art, tan, use_frame )
checkAdOk( art, tan, use_frame )
{
if( 0 !== use_frame || (false == adFenster[art][tan]['checked'] && false == adFenster[art][tan]['window'].closed) )
if( 0 !== use_frame || (false == this.adFenster[art][tan]['checked'] && false == this.adFenster[art][tan]['window'].closed) )
{
var pdata = window.btoa(art) + '-' + window.btoa(tan)
if( 0 == use_frame )
adFenster[art][tan]['checked'] = true;
this.adFenster[art][tan]['checked'] = true;
$.post( "ext/ap/ads.php",
{
......@@ -47,10 +38,10 @@
/*
* if u do something wrong, sorry no matter which ad was active, invalidate
*/
function invalidateAd( art, tan )
invalidateAd( art, tan )
{
if( undefined !== adFenster[art] )
adFenster[art][tan]['checked'] = true;
if( undefined !== this.adFenster[art] )
this.adFenster[art][tan]['checked'] = true;
var pdata = window.btoa(art) + '-' + window.btoa(tan)
$.post( "ext/ap/ads.php",
......@@ -61,43 +52,41 @@
{
try
{
if( undefined != adFenster[art][tan]['checked'] )
if( undefined != this.adFenster[art][tan]['checked'] )
window.open(pageconfig['domain']+'/adcheck.php?data='+pdata, art+'-'+tan, "height=120,width=200");
}
catch(e) { } // wurscht
}
);
}
async function startAdCountdown( art, tan, sec, use_frame )
async startAdCountdown( art, tan, sec, use_frame )
{
var sec_done = -1;
let timer = setInterval( () =>
{
if( 0 == use_frame )
{
if( true == adFenster[art][tan]['checked'] )
if( true == this.adFenster[art][tan]['checked'] )
{
clearInterval(timer);
} else {
if( document.hasFocus() )
{
invalidateAd( art, tan );
this.invalidateAd( art, tan );
clearInterval(timer);
}
try
{
if ( adFenster[art][tan]['window'].closed )
if ( this.adFenster[art][tan]['window'].closed )
{
invalidateAd( art, tan );
this.invalidateAd( art, tan );
clearInterval(timer);
}
}
catch (e)
{
invalidateAd( art, tan );
this.invalidateAd( art, tan );
clearInterval(timer);
}
}
......@@ -106,7 +95,7 @@
{
if( sec_done >= sec )
{
checkAdOk( art, tan, use_frame );
this.checkAdOk( art, tan, use_frame );
clearInterval(timer);
}
sec_done++;
......@@ -118,7 +107,7 @@
if( 0 == use_frame )
{
await sleep(sec * 1000);
checkAdOk( art, tan, 0 );
this.checkAdOk( art, tan, 0 );
}
}
......@@ -126,32 +115,32 @@
/*
* communicates with ad window, placing detection of actual click
*/
function openAdWindow( art, tan, sec, use_frame )
openAdWindow( art, tan, sec, use_frame )
{
if ( 'undefined' == typeof adFenster[art] || (! adFenster[art] instanceof Array ) )
if ( 'undefined' == typeof this.adFenster[art] || (! this.adFenster[art] instanceof Array ) )
{
adFenster[art] = new Array();
this.adFenster[art] = new Array();
}
if ( 'undefined' == typeof adFenster[art][tan] || (! adFenster[art][tan] instanceof Array ) )
if ( 'undefined' == typeof this.adFenster[art][tan] || (! this.adFenster[art][tan] instanceof Array ) )
{
adFenster[art][tan] = new Array();
this.adFenster[art][tan] = new Array();
}
if( ( 'undefined' == adFenster[art][tan]['window'] || null == adFenster[art][tan]['window'] ) || adFenster[art][tan]['window'].closed )
if( ( 'undefined' == typeof this.adFenster[art][tan]['window'] || null == this.adFenster[art][tan]['window'] ) || this.adFenster[art][tan]['window'].closed )
{
var data = window.btoa(art) + '-' + window.btoa(tan);
adFenster[art][tan]['window'] = window.open( pageconfig['domain'] + '/adclick.php?data='+data, "_blank" );
this.adFenster[art][tan]['window'] = window.open( pageconfig['domain'] + '/adclick.php?data='+data, "_blank" );
adFenster[art][tan]['window'].focus();
adFenster[art][tan]['opened'] = false;
adFenster[art][tan]['checked']= false;
this.adFenster[art][tan]['window'].focus();
this.adFenster[art][tan]['opened'] = false;
this.adFenster[art][tan]['checked']= false;
if( 0 == use_frame )
{
adFenster[art][tan]['window'].onbeforeunload = function()
this.adFenster[art][tan]['window'].onbeforeunload = function()
{
startAdCountdown( art, tan, sec, use_frame );
this.startAdCountdown( art, tan, sec, use_frame );
}
}
}
......@@ -161,7 +150,7 @@
/*
* gets executed first, loads available ads and prepares the bootstrap <ul>-list for display
*/
function loadAds( ad_type, ad_cat, fn)
loadAds( ad_type, ad_cat, fn)
{
$.post( "ext/ap/ads.php",
{
......@@ -171,3 +160,4 @@
fn
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment