blob: ef2d1ccaf3b4adba33a5fd76f685fbdd66c1479d [file] [log] [blame]
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/membership/membershipImage.class.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/membership/promo/impression.class.php");
function buildStrategic($array) {
$retVal = "";
$mimg = new MemberImage();
$mimg->setdebug(1);
$strategicPreamble = '<div class="sideitem"><h6>Featured Member</h6><div style="text-align:center;">';
$strategicPostamble = '</div></div>';
list($width, $height) = $mimg->getsmall_image($array['memberID']);
//check for errors ( -1 in both means something bad happened getting the image details)
if ($width >= 1 && $height >= 1) {
$heightText = 'height="' . $height . '" ';
$retVal = $strategicPreamble . '<a href="/membership/showMember.php?member_id=' . $array['memberID'] . '" rel="nofollow">' . '<img width="120" ' . $heightText . ' src="/membership/scripts/get_image.php?size=small&id=' . $array['memberID'] . '"' . ' style="padding:5px;" alt="' . $array['memberName'] . '" title="' . $array['memberName'] . '"></a>' . $strategicPostamble . "
";
}
return $retVal;
}
function buildStrategicFrontPage($array) {
$retVal = "";
$mimg = new MemberImage();
$strategicPreamble = '<div><div style="text-align:center;">';
$strategicPostamble = '</div></div>';
list($width, $height) = $mimg->getsmall_image($array['memberID']);
//check for errors ( -1 in both means something bad happened getting the image details)
if ($width >= 1 && $height >= 1) {
$heightText = 'height="' . $height . '" ';
$retVal = $strategicPreamble . '<a href="/membership/showMember.php?member_id=' . $array['memberID'] . '" rel="nofollow">' . '<img width="120" ' . $heightText . ' src="/membership/scripts/get_image.php?size=small&id=' . $array['memberID'] . '"' . ' style="padding:5px;" alt="' . $array['memberName'] . '" title="' . $array['memberName'] . '"></a>' . $strategicPostamble . "
";
}
return $retVal;
}
function buildStrategicAd($array) {
$strat_ad_preamble = '<div style="text-align:center;padding-bottom:20px;">';
$strat_ad_postamble = '</div>';
$retVal = $strat_ad_preamble . '<a href="/go/' . $array['url'] . '" rel="nofollow"><img width="200" height="200" src="' . $array['imageurl'] . '" alt="' . $array['memberName'] . '" title="' . $array['memberName'] . '"/></a>' . $strat_ad_postamble;
return $retVal;
}
// Strategic Member Ads for Download Page only
function buildDownloadAd($array) {
ob_start(); ?>
<div style="text-align:center;">
<a href="/go/<?php print $array['url'];?>" rel="nofollow">
<img width="200" height="200" src="<?php print $array['imageurl'];?>" alt="<?php print $array['memberName'];?>" title="<?php print $array['memberName'];?>"/></a>
</div>
<?php
$impression = new CampaignImpression($array['url'], 'Download Page', @gethostbyaddr($_SERVER['REMOTE_ADDR']));
$impression->recordImpression();
return ob_get_clean();
}
function buildGoogleAd() {
$ad_preamble = '<div style="width:200px;" align="center">';
$ad_postamble = '<br><img width="200" height="1" src="/membership/promo/images/200spacer.gif"></div>';
$retVal = $ad_preamble . '<script type="text/javascript"><!--
google_ad_client = "pub-6797025590085056";
/* 200x200, created 2/22/08 */
google_ad_slot = "2659366666";
google_ad_width = 200;
google_ad_height = 200;
//-->
</script>
<script type="text/javascript"
src="//pagead2.googlesyndication.com/pagead/show_ads.js">
</script>' . $ad_postamble;
return $retVal;
}
function buildDonateAd() {
$ad_preamble = '<div width="200" align="center">';
$ad_postamble = '<br><img src="/membership/promo/images/200spacer.gif"></div>';
$retVal = $ad_preamble . '<a href="http://eclipse.org/donate/"><img src="/donate/images/donate.jpg" rel="nofollow"></a>' . $ad_postamble;
return $retVal;
}
function buildDownloadHtmlAd($array) {
// Get the urls that have been specified in the html ad
// from the allPromos() function
if (empty($array['url'])) {
return "";
}
ob_start();
?>
<div class="ad-eclipsecon-schedule">
<h3 class="header-short-underline">Upcoming Events</h3>
<a href="/go/<?php print $array['url']; ?>">
<img src="/membership/promo/images/eclipsecon-ad-europe2017-400x400.png" alt="Eclipsecon Europe 2017">
</a>
</div>
<?php
$impression = new CampaignImpression($array['url'], 'Download Page', @gethostbyaddr($_SERVER['REMOTE_ADDR']));
$impression->recordImpression();
return ob_get_clean();
}
/**
* Eclipse Advertisements
*
* 1. Paid ads should split 40% of the total impressions
* 2. EclipseCon should take 10% of the total impressions
* 3. Members ads should split the remaning 50%.
*
* @return array $retVal
*/
function allPromos() {
$retVal = array();
/**
* IMPORTANT:
* Total weight should result to 100
* */
/**
* PAID ads (30%)
* */
$retVal[] = array(
'url' => 'PAID_FROGLOGIC',
'imageurl' => '/membership/promo/images/froglogic.gif',
'memberName' => 'FrogLogic',
'type' => 'paid',
'weight' => 10
);
$retVal[] = array(
'url' => 'PAID_YATTA',
'imageurl' => '/membership/promo/images/yatta-profiles-set02-200x200.png',
'memberName' => 'YATTA',
'type' => 'paid',
'weight' => 10
);
$retVal[] = array(
'url' => 'PAID_XDEV',
'imageurl' => '/membership/promo/images/xdev-2017-10-29.png',
'memberName' => 'XDEV',
'type' => 'paid',
'weight' => 10,
);
$retVal[] = array(
'url' => 'PAID_CLOUDBEES',
'imageurl' => '/membership/promo/images/cloudbees-200x200.jpg',
'memberName' => 'Itemis',
'type' => 'strat_ad',
'weight' => 12
);
/**
* Other Ads (70%)
* */
// Strategic Members
$retVal[] = array(
'memberID' => 655,
'memberName' => 'CA',
'type' => 'strategic',
'weight' => 6.25
);
// Strategic Member Ads
$retVal[] = array(
'url' => 'PROMO_ORACLE',
'imageurl' => '/membership/promo/images/oepe_ad_200x200.jpg',
'memberName' => 'Oracle',
'type' => 'strat_ad',
'weight' => 6.25
);
$retVal[] = array(
'url' => 'IBM_JAZZ',
'imageurl' => '/membership/promo/images/ibm200x200-eclipse_orion.png',
'memberName' => 'IBM',
'type' => 'strat_ad',
'weight' => 6.25
);
$retVal[] = array(
'url' => 'PROMO_SAP',
'imageurl' => '/membership/promo/images/sap200x200.jpg',
'memberName' => 'SAP',
'type' => 'strat_ad',
'weight' => 6.25
);
$retVal[] = array(
'url' => 'PROMO_ITEMIS',
'imageurl' => '/membership/promo/images/xtext_200x200.gif',
'memberName' => 'Itemis',
'type' => 'strat_ad',
'weight' => 6.5
);
$retVal[] = array(
'url' => 'PROMO_OBEO',
'imageurl' => '/membership/promo/images/Sirius_ad_200.png',
'memberName' => 'Obeo',
'type' => 'strat_ad',
'weight' => 7.75
);
// Internal ads
$current_time = time();
$ec_weight = 9.75;
// F4G2018 ad
if ($current_time >= strtotime("2018/02/26") && $current_time < strtotime("2018/03/08")) {
$retVal[] = array(
'memberName' => "Eclipsecon",
'type' => 'strat_ad',
'weight' => $ec_weight,
'imageurl' => "/membership/promo/images/F4G_200x200_square_register_early_red.png",
'url' => "PROMO_F4G2018",
);
}
if ($current_time >= strtotime("2018/03/15") && $current_time < strtotime("2018/04/05")) {
$retVal[] = array(
'memberName' => "Eclipsecon",
'type' => 'strat_ad',
'weight' => $ec_weight,
'imageurl' => "/membership/promo/images/F4G_200x200_square_register_now.png",
'url' => "PROMO_F4G2018",
);
}
if ($current_time >= strtotime("2018/04/30") && $current_time < strtotime("2018/05/07")) {
$retVal[] = array(
'memberName' => "Eclipsecon",
'type' => 'strat_ad',
'weight' => $ec_weight,
'imageurl' => "/membership/promo/images/F4G_200x200_square_2_weeks_red.png",
'url' => "PROMO_F4G2018",
);
}
if ($current_time >= strtotime("2018/05/07") && $current_time < strtotime("2018/05/11")) {
$retVal[] = array(
'memberName' => "Eclipsecon",
'type' => 'strat_ad',
'weight' => $ec_weight,
'imageurl' => "/membership/promo/images/F4G_200x200_square_1_week_red.png",
'url' => "PROMO_F4G2018",
);
}
// ECF2018 ad
if ($current_time >= strtotime("2018/04/16") && $current_time < strtotime("2018/04/30")) {
$retVal[] = array(
'memberName' => "Eclipsecon",
'type' => 'strat_ad',
'weight' => $ec_weight,
'imageurl' => "/membership/promo/images/ECF_register-2018-Early-200.png",
'url' => "PROMO_ECF2018",
);
}
if ($current_time >= strtotime("2018/05/14") && $current_time < strtotime("2018/05/30")) {
$retVal[] = array(
'memberName' => "Eclipsecon",
'type' => 'strat_ad',
'weight' => $ec_weight,
'imageurl' => "/membership/promo/images/ECF_register-2018-Now-200.png",
'url' => "PROMO_ECF2018",
);
}
if ($current_time >= strtotime("2018/05/30") && $current_time < strtotime("2018/06/06")) {
$retVal[] = array(
'memberName' => "Eclipsecon",
'type' => 'strat_ad',
'weight' => $ec_weight,
'imageurl' => "/membership/promo/images/ECF_register-2018-Two-Weeks-200.png",
'url' => "PROMO_ECF2018",
);
}
if ($current_time >= strtotime("2018/06/06") && $current_time < strtotime("2018/06/13")) {
$retVal[] = array(
'memberName' => "Eclipsecon",
'type' => 'strat_ad',
'weight' => $ec_weight,
'imageurl' => "/membership/promo/images/ECF_register-2018-One-Week-200.png",
'url' => "PROMO_ECF2018",
);
}
$retVal[] = array(
'memberName' => "Jakarta",
'type' => 'strat_ad',
'weight' => 9,
'imageurl' => "/membership/promo/images/TakeJakartaeeSurvey_ad.png",
'url' => "PROMO_JAKARTA",
);
return $retVal;
}
function chooseRandomPromo($adNo = NULL, $frontPage = NULL) {
$promos = allPromos();
if ($adNo != null) {
$selectedAd = $promos[$adNo];
} else {
$selectedAd = array_rand_weighted($promos);
}
// If the selected Ad is in HTML
if (!empty($selectedAd['format']) && $selectedAd['format'] == "html") {
return buildDownloadHtmlAd($selectedAd);
}
switch ($selectedAd['type']) {
case 'paid':
// THERE IS NO BREAK HERE ON PURPOSE WE WANT STRAT_AD CASE CODE TO RUN
case 'strat_ad':
$impression = new CampaignImpression($selectedAd['url'], $_SERVER['REQUEST_URI'], @gethostbyaddr($_SERVER['REMOTE_ADDR']));
$impression->recordImpression();
return buildStrategicAd($selectedAd);
break;
case 'strategic':
if ($frontPage != NULL)
return buildStrategicFrontPage($selectedAd);
else
return buildStrategic($selectedAd);
break;
case 'google_ad':
return buildGoogleAd($selectedAd);
break;
case 'donate_ad':
return buildDonateAd($selectedAd);
break;
}
}
function array_rand_weighted($values) {
$totalWeight = 0;
foreach ($values as $rr) {
$totalWeight += $rr['weight'];
}
$r = mt_rand(1, $totalWeight);
foreach ($values as $item) {
if ($r <= $item['weight'])
return $item;
$r -= $item['weight'];
}
}
function strategicAds() {
$promos = allPromos();
$retVal = array();
foreach ($promos as $promo) {
if ($promo['type'] == 'strat_ad' || $promo['type'] == 'paid') {
$retVal[] = $promo;
}
}
return $retVal;
}
function chooseDownloadAd($adNo = NULL) {
$promos = strategicAds();
if ($adNo != null) {
$selectedAd = $promos[$adNo];
} else {
$selectedAd = array_rand_weighted($promos);
}
// If the selected Ad is in HTML
if (!empty($selectedAd['format']) && $selectedAd['format'] == "html") {
return buildDownloadHtmlAd($selectedAd);
}
return buildDownloadAd($selectedAd);
}