Skip to content

Commit e328acd

Browse files
author
Alwin Viereck
committed
Commit Plugin Version 1.8.1
Commit complete version 1.8.1 of the affilinet WordPress Plugin to github
1 parent 0d6a935 commit e328acd

File tree

130 files changed

+44613
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+44613
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

affilinet.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
Plugin Name: Affilinet Performance Ads
5+
Description: Integrate our data driven and automated performance display plugin into your WordPress platform and serve your users targeted ads in real time.
6+
Version: 1.8.1
7+
Author: Affilinet
8+
Author URI: https://www.affili.net/de/publisher/tools/performance-ads
9+
License: GPLv2 or later
10+
*/
11+
12+
// @TODO: does not work with symlink
13+
14+
define("AFFILINET_PLUGIN_DIR", dirname(__FILE__).DIRECTORY_SEPARATOR);
15+
16+
foreach (glob(AFFILINET_PLUGIN_DIR . "classes/*.php") as $filename) {
17+
include $filename;
18+
}
19+
20+
new Affilinet_Plugin();

classes/Api.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
4+
class Affilinet_Api
5+
{
6+
7+
/**
8+
* Login at the api to retrieve a token
9+
*
10+
* Returns false if password mismatch
11+
*
12+
* @return bool|String $credentialToken
13+
*/
14+
public static function logon()
15+
{
16+
try {
17+
$logon_client = new \SoapClient('https://api.affili.net/V2.0/Logon.svc?wsdl');
18+
$params = array(
19+
"Username" => get_option('affilinet_publisher_id'),
20+
"Password" => get_option('affilinet_standard_webservice_password'),
21+
"WebServiceType" => "Publisher"
22+
);
23+
$token = $logon_client->__soapCall("Logon", array($params));
24+
25+
return $token;
26+
} catch (\SoapFault $e) {
27+
28+
Affilinet_Helper::displayAdminError(__('Could not connect to Affilinet API. Please recheck your Webservice Password and Publisher ID', 'affilinet'));
29+
30+
return false;
31+
}
32+
}
33+
34+
public static function getDailyStatistics(\DateTime $start_date, \DateTime $end_date)
35+
{
36+
try {
37+
$daily_statistics_client = new \SoapClient('https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl');
38+
$params = array(
39+
'CredentialToken' => self::logon(),
40+
'GetDailyStatisticsRequestMessage' => array(
41+
'StartDate' => (int) date_format($start_date, 'U'),
42+
'EndDate' => (int) date_format($end_date, 'U'),
43+
'SubId' => '',
44+
'ProgramTypes' => 'All',
45+
'ValuationType' => 'DateOfRegistration',
46+
'ProgramId' => Affilinet_PerformanceAds::getProgramIdByPlatform(get_option('affilinet_platform'))
47+
48+
)
49+
);
50+
$statistics = $daily_statistics_client->__soapCall('GetDailyStatistics', array($params));
51+
if (isset($statistics->DailyStatisticsRecords->DailyStatisticRecords->DailyStatisticsRecord)) {
52+
return $statistics->DailyStatisticsRecords->DailyStatisticRecords->DailyStatisticsRecord;
53+
}
54+
55+
Affilinet_Helper::displayAdminError(__('No data in selected time frame', 'affilinet'));
56+
57+
return null;
58+
} catch (\SoapFault $e) {
59+
Affilinet_Helper::displayAdminError(__('Could not connect to Affilinet API. Please recheck your Webservice Password and Publisher ID', 'affilinet'));
60+
61+
return false;
62+
}
63+
}
64+
}

classes/Helper.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
4+
class Affilinet_Helper
5+
{
6+
7+
/**
8+
* Get the currency String for the given platform
9+
* @param Int $platformId
10+
* @return String $currencyCode
11+
*/
12+
public static function getCurrencyForPlatformId($platformId)
13+
{
14+
switch ($platformId) {
15+
case 1: // DE
16+
case 3: // FR
17+
case 4: // NL
18+
case 7: // AT
19+
20+
return '&euro;';
21+
case 2: // UK
22+
23+
return '&pound;';
24+
case 6: // CH
25+
26+
return 'CHF';
27+
default :
28+
return '';
29+
}
30+
}
31+
32+
/**
33+
* Return the platforms' view hostname
34+
* @param Int $platformId
35+
* @return bool|string $hostName
36+
*/
37+
public static function getViewHostnameForPlatform($platformId)
38+
{
39+
switch ($platformId) {
40+
case 1: // de
41+
case 7: // at
42+
case 6: // ch
43+
44+
return 'banners.webmasterplan.com';
45+
case 2: //uk
46+
47+
return 'become.successfultogether.co.uk';
48+
case 3: //fr
49+
50+
return 'banniere.reussissonsensemble.fr';
51+
case 4:
52+
return 'worden.samenresultaat.nl';
53+
default :
54+
return false;
55+
}
56+
}
57+
58+
/**
59+
* Return the platforms' click hostname
60+
* @param Int $platformId
61+
* @return bool|string $hostName
62+
*/
63+
public static function getClickHostnameForPlatform($platformId)
64+
{
65+
switch ($platformId) {
66+
case 1: // DE
67+
case 7: // AT
68+
case 6: // CH
69+
70+
return 'partners.webmasterplan.com';
71+
case 2: // UK
72+
73+
return 'being.successfultogether.co.uk';
74+
case 3: // FR
75+
76+
return 'clic.reussissonsensemble.fr';
77+
case 4: // NL
78+
79+
return 'zijn.samenresultaat.nl';
80+
default :
81+
return false;
82+
}
83+
}
84+
85+
/**
86+
* Get the short locale String
87+
* will return de for locale like de_DE
88+
* @return string
89+
*/
90+
public static function getShortLocale()
91+
{
92+
$locale = get_locale();
93+
$shortLocale = mb_substr($locale, 0, 2);
94+
95+
return $shortLocale;
96+
}
97+
98+
/**
99+
* Helper to display an error message
100+
*/
101+
public static function displayAdminError($message)
102+
{
103+
?>
104+
<div class="error">
105+
<p>
106+
<?php echo $message;?>
107+
</p>
108+
</div>
109+
<?php
110+
}
111+
112+
/**
113+
* Returns current plugin version.
114+
*
115+
* @return string Plugin version
116+
*/
117+
public static function get_plugin_version()
118+
{
119+
if ( ! function_exists( 'get_plugins' ) )
120+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
121+
$plugin_folder = get_plugin_data(AFFILINET_PLUGIN_DIR.DIRECTORY_SEPARATOR.'affilinet.php') ;
122+
123+
return $plugin_folder['Version'];
124+
}
125+
}

classes/PerformanceAds.php

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
3+
4+
class Affilinet_PerformanceAds
5+
{
6+
7+
/**
8+
* Get the ProgramID for a Platform Id
9+
*
10+
* Returns false if the platform id is invalid
11+
*
12+
* @param int $platformId
13+
*
14+
* @return bool|int $programId
15+
*/
16+
public static function getProgramIdByPlatform($platformId)
17+
{
18+
switch ($platformId) {
19+
case 1: // DE
20+
21+
return 9192;
22+
case 2: // UK
23+
24+
return 12752;
25+
case 3: // FR
26+
27+
return 12751;
28+
case 4: // NL
29+
30+
return 13397;
31+
case 6: // CH
32+
33+
return 12252;
34+
case 7: // AT
35+
36+
return 12376;
37+
38+
default :
39+
return false;
40+
}
41+
}
42+
43+
/**
44+
* Return the AdCode for the given size
45+
* $size must be one of '728x90','300x250','250x250', '468x60', '160x600', '120x600'
46+
* @param $size
47+
* @return string|void
48+
*/
49+
public static function getAdCode($size)
50+
{
51+
$publisherId = get_option('affilinet_publisher_id');
52+
$platformId = get_option('affilinet_platform');
53+
54+
if ($publisherId === false || $publisherId === '') {
55+
return __('No publisher ID given', 'affilinet');
56+
}
57+
if ($platformId === false || $platformId === '') {
58+
return __('No platform chosen', 'affilinet');
59+
}
60+
61+
/**
62+
* Disable Netherlands
63+
*/
64+
if ($platformId == 4) {
65+
return '';
66+
}
67+
68+
$programId = Affilinet_PerformanceAds::getProgramIdByPlatform($platformId);
69+
$viewUrl = Affilinet_Helper::getViewHostnameForPlatform($platformId);
70+
$clickUrl = Affilinet_Helper::getClickHostnameForPlatform($platformId);
71+
$pluginVersion = Affilinet_Helper::get_plugin_version();
72+
$wpVersion = get_bloginfo('version');
73+
$subId = 'Wordpress'.$wpVersion.'-Plugin'.$pluginVersion;
74+
$hnb = self::getHnbForPlatform($platformId, $size);
75+
76+
if ($hnb === false) {
77+
return __('Invalid ad size given. Choose one of "728x90","300x250","250x250","468x60","160x600","120x600"', 'affilinet');
78+
}
79+
80+
$html = '<script language="javascript" type="text/javascript" src="' .
81+
'http://' . $viewUrl . '/view.asp?ref=' . $publisherId . '&site=' . $programId . '&type=html&hnb=' . $hnb . '&js=1&subid='.$subId.
82+
'"></script><noscript><a href="' .
83+
'http://' . $clickUrl . '/click.asp?ref=' . $publisherId . '&site=' . $programId . '&type=b1&bnb=1&subid='.$subId.
84+
'" target="_blank"><img src="' .
85+
'http://' . $viewUrl . '/view.asp?ref=' . $publisherId . '&site=' . $programId . '&b=1&subid='.$subId.
86+
'" border="0"/></a><br /></noscript>';
87+
88+
return $html;
89+
}
90+
91+
/**
92+
* Get the HNB paramter for performance Ads
93+
* @param $platformId
94+
* @param $size
95+
* @return bool
96+
*/
97+
public static function getHnbForPlatform($platformId, $size)
98+
{
99+
$hnb = array(
100+
// DE
101+
1 => array(
102+
'728x90' => 1,
103+
'300x250' => 4,
104+
'250x250' => 6,
105+
'468x60' => 5,
106+
'160x600' => 3,
107+
'120x600' => 2
108+
),
109+
// AT
110+
7 => array(
111+
'728x90' => 1,
112+
'300x250' => 2,
113+
'250x250' => 6,
114+
'468x60' => 3,
115+
'160x600' => 4,
116+
'120x600' => 5,
117+
),
118+
// CH
119+
6 => array(
120+
'728x90' => 1,
121+
'300x250' => 2,
122+
'250x250' => 6,
123+
'468x60' => 4,
124+
'160x600' => 3,
125+
'120x600' => 5,
126+
),
127+
// UK
128+
2 => array(
129+
'728x90' => 2,
130+
'300x250' => 3,
131+
'250x250' => 6,
132+
'468x60' => 1,
133+
'160x600' => 4,
134+
'120x600' => 5
135+
),
136+
// FR
137+
3 => array(
138+
'728x90' => 2,
139+
'300x250' => 3,
140+
'250x250' => 6,
141+
'468x60' => 1,
142+
'160x600' => 4,
143+
'120x600' => 5
144+
),
145+
4 => array(
146+
'728x90' => 2,
147+
'300x250' => 3,
148+
'250x250' => 6,
149+
'468x60' => 1,
150+
'160x600' => 4,
151+
'120x600' => 5
152+
)
153+
);
154+
if (isset($hnb[$platformId]) && isset($hnb[$platformId][$size])) {
155+
return $hnb[$platformId][$size];
156+
} else {
157+
return false;
158+
}
159+
160+
}
161+
}

0 commit comments

Comments
 (0)