Bug 533547 - Confusing navigation for packages download

Change-Id: I292b4b5d71f944058db1437250fe065e7a884914
Signed-off-by: Christopher Guindon <chris.guindon@eclipse-foundation.org>
diff --git a/promo/impression.class.php b/promo/impression.class.php
index 0720133..48d12f5 100644
--- a/promo/impression.class.php
+++ b/promo/impression.class.php
@@ -1,14 +1,16 @@
 <?php
-/*******************************************************************************
- * Copyright (c) 2010-2014 Eclipse Foundation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+/**
+ * Copyright (c) 2018 Eclipse Foundation.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
  *
  * Contributors:
- *    Nathan Gervais (Eclipse Foundation) - Initial API + Implementation
- *******************************************************************************/
+ *   Christopher Guindon (Eclipse Foundation) - Initial implementation
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
 
-// Moving this file to eclipse.org-common.
+// Moving this file to eclipse.org-common
 require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/ads/campaignImpression.class.php");
diff --git a/promo/promos.php b/promo/promos.php
index 4c2c4ed..80c9b47 100644
--- a/promo/promos.php
+++ b/promo/promos.php
@@ -1,263 +1,41 @@
 <?php
+/**
+ * Copyright (c) 2018 Eclipse Foundation.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * Contributors:
+ * Christopher Guindon (Eclipse Foundation) - Initial implementation
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
 
-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) {
-  $mimg = new MemberImage();
-  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 . '" ';
-    return '<div class="eclipsefnd-ad ad-strategic ad-strategic-frontpage"><a href="/membership/showMember.php?member_id=' . $array['memberID'] . '" rel="nofollow" style="background-image: url(\'/membership/scripts/get_image.php?size=small&id=' . $array['memberID'] .'\')">' . $array['memberName'] . '</a></div>';
-  }
-
-  return "";
-}
-
-function buildStrategicAd($array) {
-  if (empty($array) || empty($array['url']) || empty($array['imageurl']) || empty($array['memberName'])) {
-    return "";
-  }
-  $impression = new CampaignImpression($array['url'], $_SERVER['REQUEST_URI'], @gethostbyaddr($_SERVER['REMOTE_ADDR']));
-  $impression->recordImpression();
-  return'<div class="eclipsefnd-ad ad-strategic ad-strategic-default"><a href="/go/' . $array['url'] . '" rel="nofollow" style="background-image: url(\''.$array['imageurl'].'\')">'.$array['memberName'].'</a></div>';
-}
-
-// 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 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;
-}
+// Moving this file to eclipse.org-common.
+require_once ($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/ads/promotions.class.php");
 
 /**
- * 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
+ * @deprecated
+ * @return unknown
  */
 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-Eclipse-Banner-Ad-1.png',
-    'memberName' => 'YATTA',
-    'type' => 'paid',
-    'weight' => 10
-  );
-
-  $retVal[] = array(
-    'url' => 'PAID_CLOUDBEES',
-    'imageurl' => '/membership/promo/images/cloudbees-200x200.jpg',
-    'memberName' => 'Itemis',
-    'type' => 'strat_ad',
-    'weight' => 10
-  );
-
-  /**
-   * Other Ads (70%)
-   * */
-
-  // Strategic Members
-  $retVal[] = array(
-    'memberID' => 655,
-    'memberName' => 'CA',
-    'type' => 'strategic',
-    'weight' => 10
-  );
-
-  // Strategic Member Ads
-  $retVal[] = array(
-    'url' => 'PROMO_ORACLE',
-    'imageurl' => '/membership/promo/images/oepe_ad_200x200.jpg',
-    'memberName' => 'Oracle',
-    'type' => 'strat_ad',
-    'weight' => 10
-  );
-
-  $retVal[] = array(
-    'url' => 'IBM_JAZZ',
-    'imageurl' => '/membership/promo/images/ibm200x200-ibm_cloud.jpg',
-    'memberName' => 'IBM',
-    'type' => 'strat_ad',
-    'weight' => 10
-  );
-  $retVal[] = array(
-    'url' => 'PROMO_SAP',
-    'imageurl' => '/membership/promo/images/sap200x200.jpg',
-    'memberName' => 'SAP',
-    'type' => 'strat_ad',
-    'weight' => 10
-  );
-
-  $retVal[] = array(
-    'url' => 'PROMO_OBEO',
-    'imageurl' => '/membership/promo/images/Sirius_ad_200.png',
-    'memberName' => 'Obeo',
-    'type' => 'strat_ad',
-    'weight' => 7.5
-  );
-
-  $retVal[] = array(
-    'url' => 'PROMO_CEA',
-    'imageurl' => '/membership/promo/images/PapyrusCEA.gif',
-    'memberName' => 'CEA',
-    'type' => 'strat_ad',
-    'weight' => 7.5
-  );
-
-  $retVal[] = array(
-    'url' => 'PROMO_PAYARA',
-    'imageurl' => '/membership/promo/images/payara.png',
-    'memberName' => 'PAYARA',
-    'type' => 'strat_ad',
-    'weight' => 7.5
-  );
-
-  $retVal[] = array(
-    'url' => 'PROMO_TOMITRIBE',
-    'imageurl' => '/membership/promo/images/Tomitribe-TCPP-banner-200x200.jpg',
-    'memberName' => 'TOMITRIBE',
-    'type' => 'strat_ad',
-    'weight' => 7.5
-  );
-
-  $foundation_promos = getFoundationPromos();
-  $retVal = array_merge($retVal, $foundation_promos);
-
-  return $retVal;
+  return Promotions::allPromos();
 }
 
 /**
- * Get Eclipse Foundation Promo
- *
- * @return array
+ * @deprecated
+ * @return unknown
  */
-function getFoundationPromos() {
-
-  $retVal = array();
-
-  return $retVal;
-}
-
 function chooseRandomPromo($adNo = NULL, $frontPage = NULL) {
-
-  $promos = allPromos();
-
-  if ($adNo != NULL) {
-    $selectedAd = $promos[$adNo];
-  } else {
-    $selectedAd = array_rand_weighted($promos);
-  }
-
-  switch ($selectedAd['type']) {
-    case 'paid':
-    // THERE IS NO BREAK HERE ON PURPOSE WE WANT STRAT_AD CASE CODE TO RUN
-    case 'strat_ad':
-      return buildStrategicAd($selectedAd);
-      break;
-    case 'strategic':
-      if ($frontPage != NULL)
-        return buildStrategicFrontPage($selectedAd);
-      else
-        return buildStrategic($selectedAd);
-      break;
-    case 'donate_ad':
-      return buildDonateAd($selectedAd);
-      break;
-  }
+  return Promotions::chooseRandomPromo();
 }
 
-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;
-}
-
+/**
+ * @deprecated
+ * @return unknown
+ */
 function chooseDownloadAd($adNo = NULL) {
-  $promos = strategicAds();
-
-  if ($adNo != NULL) {
-    $selectedAd = $promos[$adNo];
-  } else {
-    $selectedAd = array_rand_weighted($promos);
-  }
-
-  return buildDownloadAd($selectedAd);
+  return Promotions::chooseRandomPromo();
 }