Skip to content

Commit

Permalink
Commit Plugin Version 1.8.1
Browse files Browse the repository at this point in the history
Commit complete version 1.8.1 of the affilinet WordPress Plugin to
github
  • Loading branch information
Alwin Viereck committed Jun 5, 2016
1 parent 0d6a935 commit e328acd
Show file tree
Hide file tree
Showing 130 changed files with 44,613 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
20 changes: 20 additions & 0 deletions affilinet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
Plugin Name: Affilinet Performance Ads
Description: Integrate our data driven and automated performance display plugin into your WordPress platform and serve your users targeted ads in real time.
Version: 1.8.1
Author: Affilinet
Author URI: https://www.affili.net/de/publisher/tools/performance-ads
License: GPLv2 or later
*/

// @TODO: does not work with symlink

define("AFFILINET_PLUGIN_DIR", dirname(__FILE__).DIRECTORY_SEPARATOR);

foreach (glob(AFFILINET_PLUGIN_DIR . "classes/*.php") as $filename) {
include $filename;
}

new Affilinet_Plugin();
64 changes: 64 additions & 0 deletions classes/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php


class Affilinet_Api
{

/**
* Login at the api to retrieve a token
*
* Returns false if password mismatch
*
* @return bool|String $credentialToken
*/
public static function logon()
{
try {
$logon_client = new \SoapClient('https://api.affili.net/V2.0/Logon.svc?wsdl');
$params = array(
"Username" => get_option('affilinet_publisher_id'),
"Password" => get_option('affilinet_standard_webservice_password'),
"WebServiceType" => "Publisher"
);
$token = $logon_client->__soapCall("Logon", array($params));

return $token;
} catch (\SoapFault $e) {

Affilinet_Helper::displayAdminError(__('Could not connect to Affilinet API. Please recheck your Webservice Password and Publisher ID', 'affilinet'));

return false;
}
}

public static function getDailyStatistics(\DateTime $start_date, \DateTime $end_date)
{
try {
$daily_statistics_client = new \SoapClient('https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl');
$params = array(
'CredentialToken' => self::logon(),
'GetDailyStatisticsRequestMessage' => array(
'StartDate' => (int) date_format($start_date, 'U'),
'EndDate' => (int) date_format($end_date, 'U'),
'SubId' => '',
'ProgramTypes' => 'All',
'ValuationType' => 'DateOfRegistration',
'ProgramId' => Affilinet_PerformanceAds::getProgramIdByPlatform(get_option('affilinet_platform'))

)
);
$statistics = $daily_statistics_client->__soapCall('GetDailyStatistics', array($params));
if (isset($statistics->DailyStatisticsRecords->DailyStatisticRecords->DailyStatisticsRecord)) {
return $statistics->DailyStatisticsRecords->DailyStatisticRecords->DailyStatisticsRecord;
}

Affilinet_Helper::displayAdminError(__('No data in selected time frame', 'affilinet'));

return null;
} catch (\SoapFault $e) {
Affilinet_Helper::displayAdminError(__('Could not connect to Affilinet API. Please recheck your Webservice Password and Publisher ID', 'affilinet'));

return false;
}
}
}
125 changes: 125 additions & 0 deletions classes/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php


class Affilinet_Helper
{

/**
* Get the currency String for the given platform
* @param Int $platformId
* @return String $currencyCode
*/
public static function getCurrencyForPlatformId($platformId)
{
switch ($platformId) {
case 1: // DE
case 3: // FR
case 4: // NL
case 7: // AT

return '&euro;';
case 2: // UK

return '&pound;';
case 6: // CH

return 'CHF';
default :
return '';
}
}

/**
* Return the platforms' view hostname
* @param Int $platformId
* @return bool|string $hostName
*/
public static function getViewHostnameForPlatform($platformId)
{
switch ($platformId) {
case 1: // de
case 7: // at
case 6: // ch

return 'banners.webmasterplan.com';
case 2: //uk

return 'become.successfultogether.co.uk';
case 3: //fr

return 'banniere.reussissonsensemble.fr';
case 4:
return 'worden.samenresultaat.nl';
default :
return false;
}
}

/**
* Return the platforms' click hostname
* @param Int $platformId
* @return bool|string $hostName
*/
public static function getClickHostnameForPlatform($platformId)
{
switch ($platformId) {
case 1: // DE
case 7: // AT
case 6: // CH

return 'partners.webmasterplan.com';
case 2: // UK

return 'being.successfultogether.co.uk';
case 3: // FR

return 'clic.reussissonsensemble.fr';
case 4: // NL

return 'zijn.samenresultaat.nl';
default :
return false;
}
}

/**
* Get the short locale String
* will return de for locale like de_DE
* @return string
*/
public static function getShortLocale()
{
$locale = get_locale();
$shortLocale = mb_substr($locale, 0, 2);

return $shortLocale;
}

/**
* Helper to display an error message
*/
public static function displayAdminError($message)
{
?>
<div class="error">
<p>
<?php echo $message;?>
</p>
</div>
<?php
}

/**
* Returns current plugin version.
*
* @return string Plugin version
*/
public static function get_plugin_version()
{
if ( ! function_exists( 'get_plugins' ) )
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$plugin_folder = get_plugin_data(AFFILINET_PLUGIN_DIR.DIRECTORY_SEPARATOR.'affilinet.php') ;

return $plugin_folder['Version'];
}
}
161 changes: 161 additions & 0 deletions classes/PerformanceAds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php


class Affilinet_PerformanceAds
{

/**
* Get the ProgramID for a Platform Id
*
* Returns false if the platform id is invalid
*
* @param int $platformId
*
* @return bool|int $programId
*/
public static function getProgramIdByPlatform($platformId)
{
switch ($platformId) {
case 1: // DE

return 9192;
case 2: // UK

return 12752;
case 3: // FR

return 12751;
case 4: // NL

return 13397;
case 6: // CH

return 12252;
case 7: // AT

return 12376;

default :
return false;
}
}

/**
* Return the AdCode for the given size
* $size must be one of '728x90','300x250','250x250', '468x60', '160x600', '120x600'
* @param $size
* @return string|void
*/
public static function getAdCode($size)
{
$publisherId = get_option('affilinet_publisher_id');
$platformId = get_option('affilinet_platform');

if ($publisherId === false || $publisherId === '') {
return __('No publisher ID given', 'affilinet');
}
if ($platformId === false || $platformId === '') {
return __('No platform chosen', 'affilinet');
}

/**
* Disable Netherlands
*/
if ($platformId == 4) {
return '';
}

$programId = Affilinet_PerformanceAds::getProgramIdByPlatform($platformId);
$viewUrl = Affilinet_Helper::getViewHostnameForPlatform($platformId);
$clickUrl = Affilinet_Helper::getClickHostnameForPlatform($platformId);
$pluginVersion = Affilinet_Helper::get_plugin_version();
$wpVersion = get_bloginfo('version');
$subId = 'Wordpress'.$wpVersion.'-Plugin'.$pluginVersion;
$hnb = self::getHnbForPlatform($platformId, $size);

if ($hnb === false) {
return __('Invalid ad size given. Choose one of "728x90","300x250","250x250","468x60","160x600","120x600"', 'affilinet');
}

$html = '<script language="javascript" type="text/javascript" src="' .
'http://' . $viewUrl . '/view.asp?ref=' . $publisherId . '&site=' . $programId . '&type=html&hnb=' . $hnb . '&js=1&subid='.$subId.
'"></script><noscript><a href="' .
'http://' . $clickUrl . '/click.asp?ref=' . $publisherId . '&site=' . $programId . '&type=b1&bnb=1&subid='.$subId.
'" target="_blank"><img src="' .
'http://' . $viewUrl . '/view.asp?ref=' . $publisherId . '&site=' . $programId . '&b=1&subid='.$subId.
'" border="0"/></a><br /></noscript>';

return $html;
}

/**
* Get the HNB paramter for performance Ads
* @param $platformId
* @param $size
* @return bool
*/
public static function getHnbForPlatform($platformId, $size)
{
$hnb = array(
// DE
1 => array(
'728x90' => 1,
'300x250' => 4,
'250x250' => 6,
'468x60' => 5,
'160x600' => 3,
'120x600' => 2
),
// AT
7 => array(
'728x90' => 1,
'300x250' => 2,
'250x250' => 6,
'468x60' => 3,
'160x600' => 4,
'120x600' => 5,
),
// CH
6 => array(
'728x90' => 1,
'300x250' => 2,
'250x250' => 6,
'468x60' => 4,
'160x600' => 3,
'120x600' => 5,
),
// UK
2 => array(
'728x90' => 2,
'300x250' => 3,
'250x250' => 6,
'468x60' => 1,
'160x600' => 4,
'120x600' => 5
),
// FR
3 => array(
'728x90' => 2,
'300x250' => 3,
'250x250' => 6,
'468x60' => 1,
'160x600' => 4,
'120x600' => 5
),
4 => array(
'728x90' => 2,
'300x250' => 3,
'250x250' => 6,
'468x60' => 1,
'160x600' => 4,
'120x600' => 5
)
);
if (isset($hnb[$platformId]) && isset($hnb[$platformId][$size])) {
return $hnb[$platformId][$size];
} else {
return false;
}

}
}
Loading

0 comments on commit e328acd

Please sign in to comment.