Skip to content

Commit 7f3cb70

Browse files
author
sgotre
committed
Version 1.0 submitted to WP Repo
1 parent 414dd00 commit 7f3cb70

29 files changed

Lines changed: 1508 additions & 1 deletion

tags/1.0/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== affilinet Performance Ads ===
2+
Contributors: affilinet, teraone
3+
Tags: Affiliate, affilinet, advertising, banner, widgets
4+
Requires at least: 3.0.1
5+
Tested up to: 4.9
6+
Stable tag: 1.0
7+
License: GPLv2 or later
8+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
9+
10+
The plugin allows you simple integration of affilinet Product Widgets into your WordPress posts and sidebar.
11+
12+
== Description ==
13+
14+
The plugin allows you simple integration of affilinet Product Widgets into your WordPress posts and sidebar.
15+
16+
17+
== Installation ==
18+
19+
20+
= Required settings =
21+
22+
23+
== Changelog ==
24+
25+
26+
= 1.0 =
27+
* Release Date: Feb 19, 2017
28+
* Initial release
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 Product Widgets
5+
Plugin URI: https://www.affili.net/de/publisher/tools/influencer-web-extension
6+
Description: The plugin allows you simple integration of affilinet Product Widgets into your WordPress posts and sidebar.
7+
Version: 1.0
8+
Author: affilinet
9+
Author URI: https://www.affili.net/
10+
License: GPLv2 or later
11+
*/
12+
13+
define("AFFILINET_PRODUCT_WIDGETS_PLUGIN_DIR", dirname(__FILE__) . DIRECTORY_SEPARATOR);
14+
define("AFFILINET_PRODUCT_WIDGETS_PLUGIN_FILE", plugin_basename( __FILE__) );
15+
16+
foreach (glob( AFFILINET_PRODUCT_WIDGETS_PLUGIN_DIR . "classes/*.php") as $filename) {
17+
include $filename;
18+
}
19+
20+
new AffilinetWidgetsPlugin();
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
4+
class AffilinetWidgetsApi
5+
{
6+
7+
const API_ENDPOINT = 'https://productwidget.com/api/v1.0/widgets';
8+
9+
/**
10+
* Login at the a token
11+
*
12+
* Returns false if password mismatch
13+
*
14+
* @param null $username
15+
* @param null $password
16+
*
17+
* @return bool|String $credentialToken
18+
*/
19+
public static function logon($username = null, $password = null)
20+
{
21+
22+
try {
23+
if ($password === null) {
24+
$password = get_option('affilinet_product_widgets_publisher_webservice_password');
25+
}
26+
if ($username === null) {
27+
$username = get_option('affilinet_product_widgets_publisher_id');
28+
}
29+
$logon_client = new \SoapClient('https://api.affili.net/V2.0/Logon.svc?wsdl');
30+
$params = array(
31+
"Username" => $username,
32+
"Password" => $password,
33+
"WebServiceType" => "Publisher"
34+
);
35+
$token = $logon_client->__soapCall("Logon", array($params));
36+
37+
if ($token !== false) {
38+
update_option('affilinet_product_widgets_webservice_login_is_correct', 'true', true);
39+
}
40+
41+
return $token;
42+
} catch (\SoapFault $e) {
43+
update_option('affilinet_product_widgets_webservice_login_is_correct', 'false', true);
44+
$errorMessage = __('errors.couldNotConnect', 'affilinet-product-widgets');
45+
AffilinetWidgetsHelper::displayHugeAdminMessage($errorMessage, 'error', 'fa-exclamation-triangle');
46+
47+
return false;
48+
}
49+
}
50+
51+
/**
52+
* @return array
53+
*/
54+
public static function getMyWidgets()
55+
{
56+
$errorMessage = __('errors.couldNotConnect', 'affilinet-product-widgets');
57+
58+
try {
59+
$token = self::logon();
60+
$publisherId = get_option('affilinet_product_widgets_publisher_id');
61+
if ( $token === false ) {
62+
// error already displayed
63+
return [];
64+
}
65+
66+
67+
$url = self::API_ENDPOINT . "?credentialToken=" . $token . "&publisherId=" . $publisherId;
68+
$response = wp_remote_get($url);
69+
if ( is_array( $response ) ) {
70+
return json_decode( $response['body'], true); // use the content
71+
} else {
72+
AffilinetWidgetsHelper::displayHugeAdminMessage($errorMessage, 'error', 'fa-exclamation-triangle');
73+
return [];
74+
}
75+
76+
}
77+
catch (\SoapFault $e) {
78+
$errorMessage = $e->getMessage();
79+
AffilinetWidgetsHelper::displayHugeAdminMessage($errorMessage, 'error', 'fa-exclamation-triangle');
80+
return [];
81+
}
82+
}
83+
84+
85+
86+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
4+
class AffilinetWidgetsHelper
5+
{
6+
/**
7+
* Helper to display an error message
8+
*
9+
* @param $message
10+
* @param string $type
11+
* @param bool $icon
12+
*/
13+
public static function displayHugeAdminMessage($message, $type = 'error', $icon = false)
14+
{
15+
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
16+
add_action( 'admin_notices', function() use ($message , $type, $icon ){
17+
18+
?>
19+
<div class="notice-<?php echo $type?> notice" style="min-height:75px;">
20+
21+
<?php
22+
if ($icon !== false) {
23+
switch ($type) {
24+
case'error' : $color = 'rgb(230, 73, 64)';break;
25+
case'warning' : $color = 'rgb(255, 197, 2)';break;
26+
case'success' : $color = 'rgb(84, 190, 100)';break;
27+
case'info' :
28+
default:
29+
$color = 'rgb(23, 175, 218)';
30+
}
31+
?>
32+
<div style="width: 50px;padding: 10px 20px;display: inline-block;">
33+
<i class="fa <?php echo $icon; ?>" style="font-size: 40px; color: <?php echo $color;?>; position:absolute; margin-top:10px;"></i>
34+
</div>
35+
<?php
36+
}
37+
?>
38+
39+
40+
<p style="display: inline-block;position: absolute; margin-top: 18px;">
41+
<strong>affilinet Product Widgets</strong> <br>
42+
<?php echo $message;?>
43+
</p>
44+
<div class="clearfix"></div>
45+
</div>
46+
<?php
47+
48+
});
49+
50+
}
51+
52+
53+
/**
54+
* Returns current plugin version.
55+
*
56+
* @return string Plugin version
57+
*/
58+
public static function get_plugin_version()
59+
{
60+
if ( ! function_exists( 'get_plugins' ) )
61+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
62+
$plugin_folder = get_plugin_data( AFFILINET_PRODUCT_WIDGETS_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'affilinet.php') ;
63+
64+
return $plugin_folder['Version'];
65+
}
66+
}

0 commit comments

Comments
 (0)