Skip to content

Commit d09dedf

Browse files
author
sgotre
committed
fix #11, fix #10, fix #9, fix #8
1 parent 73697ac commit d09dedf

7 files changed

Lines changed: 160 additions & 151 deletions

trunk/affilinet-product-widgets.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
Plugin Name: affilinet Product Widgets
55
Plugin URI: https://www.affili.net/de/publisher/tools/influencer-web-extension
66
Description: A brief description of the Plugin.
7-
Version: 0.91
7+
Version: 0.92
88
Author: affilinet
99
Author URI: https://www.affili.net/
1010
License: GPLv2 or later
1111
*/
1212

1313
define("AFFILINET_PRODUCT_WIDGETS_PLUGIN_DIR", dirname(__FILE__) . DIRECTORY_SEPARATOR);
14+
define("AFFILINET_PRODUCT_WIDGETS_PLUGIN_FILE", plugin_basename( __FILE__) );
1415

1516
foreach (glob( AFFILINET_PRODUCT_WIDGETS_PLUGIN_DIR . "classes/*.php") as $filename) {
1617
include $filename;
Lines changed: 150 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,121 @@
11
<?php
22

3-
class AffilinetWidgetsPlugin
4-
{
3+
class AffilinetWidgetsPlugin {
54

6-
public function __construct()
7-
{
8-
add_action('admin_init', array($this, 'admin_init'));
9-
add_action('admin_menu', array($this, 'admin_menu'));
10-
add_action('widgets_init', array($this, 'register_widget'));
5+
public function __construct() {
116

12-
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
137

14-
add_action('plugins_loaded', array($this, 'load_textdomain'));
8+
add_action( 'admin_init', array( $this, 'admin_init' ) );
9+
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
10+
add_action( 'widgets_init', array( $this, 'register_widget' ) );
1511

16-
add_shortcode('affilinet_widget', array($this, 'affilinet_product_widgets_shortcode'));
12+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
1713

18-
add_action( 'admin_notices', array( $this, 'admin_notice' ));
14+
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
1915

16+
add_shortcode( 'affilinet_widget', array( $this, 'affilinet_product_widgets_shortcode' ) );
2017

21-
}
18+
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
19+
20+
21+
add_filter( 'plugin_action_links_' .plugin_basename(AFFILINET_PRODUCT_WIDGETS_PLUGIN_FILE ), array( $this, 'plugin_add_settings_link' ) );
22+
23+
24+
25+
26+
}
2227

2328

2429
/**
2530
* Register Settings for admin area
2631
*/
27-
public function admin_init()
28-
{
29-
register_setting('affilinet-product-widgets-settings-group', 'affilinet_product_widgets_publisher_id');
30-
register_setting('affilinet-product-widgets-settings-group', 'affilinet_product_widgets_publisher_webservice_password');
32+
public function admin_init() {
33+
register_setting( 'affilinet-product-widgets-settings-group', 'affilinet_product_widgets_publisher_id' );
34+
register_setting( 'affilinet-product-widgets-settings-group', 'affilinet_product_widgets_publisher_webservice_password' );
3135
// this value will change with every update and can be used to hook the password change
32-
register_setting('affilinet-product-widgets-settings-group', 'affilinet_product_widgets_last_credential_change', array('sanitize_callback'=> array($this, 'validate_credentials')));
36+
register_setting( 'affilinet-product-widgets-settings-group', 'affilinet_product_widgets_last_credential_change', array(
37+
'sanitize_callback' => array(
38+
$this,
39+
'validate_credentials'
40+
)
41+
) );
3342
}
3443

3544

36-
37-
function validate_credentials($timestamp)
38-
{
39-
// clear the cache to get the new values
40-
wp_cache_delete ( 'alloptions', 'options' );
45+
function validate_credentials( $timestamp ) {
46+
// clear the cache to get the new values
47+
wp_cache_delete( 'alloptions', 'options' );
4148

4249
// check credentials
43-
if (AffilinetWidgetsApi::logon() === false) {
44-
add_settings_error('affilinet_product_widgets_publisher_webservice_password', '1', __('Invalid Webservice Password or Publisher ID ', 'affilinet-product-widgets') );
45-
update_option('affilinet_product_widgets_webservice_login_is_correct', 'false', true);
46-
wp_cache_delete ( 'alloptions', 'options' );
47-
return $timestamp;
48-
}
49-
return $timestamp;
50+
if ( AffilinetWidgetsApi::logon() === false ) {
51+
add_settings_error( 'affilinet_product_widgets_publisher_webservice_password', '1', __( 'Invalid Webservice Password or Publisher ID ', 'affilinet-product-widgets' ) );
52+
update_option( 'affilinet_product_widgets_webservice_login_is_correct', 'false', true );
53+
wp_cache_delete( 'alloptions', 'options' );
54+
55+
return $timestamp;
56+
}
57+
58+
return $timestamp;
5059
}
5160

5261
function admin_notice() {
5362

54-
if (get_option('affilinet_product_widgets_webservice_login_is_correct', 'false') === 'false') {
55-
?>
63+
if ( get_option( 'affilinet_product_widgets_webservice_login_is_correct', 'false' ) === 'false' ) {
64+
?>
5665
<div class="notice notice-warning is-dismissible">
57-
<p><?php _e('<strong>affilinet Widgets:</strong><br> Please make sure you have entered the correct Publisher ID and Publisher Webservice password.', 'affilinet-product-widgets' ); ?>
58-
<a class="button" href="<?php echo admin_url( 'options-general.php?page=affilinet-product-widgets-settings' ) ;?>"><?php _e('Check your settings.', 'affilinet-product-widgets');?></a>
66+
<p><?php _e( '<strong>affilinet Widgets:</strong><br> Please make sure you have entered the correct Publisher ID and Publisher Webservice password.', 'affilinet-product-widgets' ); ?>
67+
<a class="button"
68+
href="<?php echo admin_url( 'options-general.php?page=affilinet-product-widgets-settings' ); ?>"><?php _e( 'Check your settings.', 'affilinet-product-widgets' ); ?></a>
5969

6070
</p>
6171
</div>
62-
<?php
63-
}
64-
}
65-
66-
67-
68-
/**
69-
* Create the admin Menu
70-
*/
71-
public function admin_menu()
72-
{
73-
// options menu
74-
add_options_page('affilinet Widgets Settings', 'affilinet Widgets', 'manage_options', 'affilinet-product-widgets-settings', 'AffilinetWidgetsView::settings');
75-
}
76-
77-
/**
78-
* Register the widget
79-
*/
80-
public function register_widget()
81-
{
82-
register_widget('AffilinetWidgetsWidget');
83-
}
84-
85-
/**
86-
* Load Admin scripts
87-
* @param $hook string
88-
*/
89-
public function admin_enqueue_scripts($hook)
90-
{
91-
// on post page add the editor button for affilinet plugin
92-
if ($hook === 'post.php' || $hook == 'post-new.php') {
93-
add_action('admin_head', array($this, 'register_tiny_mce_buttons'));
94-
add_action( "admin_head-$hook",array($this, 'add_tiny_mce_variables') );
95-
}
96-
97-
// on settings page integrate font awesome
98-
99-
if ($hook == 'settings_page_affilinet-product-widgets-settings') {
100-
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
101-
}
102-
103-
}
72+
<?php
73+
}
74+
}
75+
76+
77+
/**
78+
* Create the admin Menu
79+
*/
80+
public function admin_menu() {
81+
// options menu
82+
add_options_page( 'affilinet Widgets Settings', 'affilinet Widgets', 'manage_options', 'affilinet-product-widgets-settings', 'AffilinetWidgetsView::settings' );
83+
}
84+
85+
/**
86+
* Register the widget
87+
*/
88+
public function register_widget() {
89+
register_widget( 'AffilinetWidgetsWidget' );
90+
}
91+
92+
93+
/**
94+
* Load Admin scripts
95+
*
96+
* @param $hook string
97+
*/
98+
public function admin_enqueue_scripts( $hook ) {
99+
// on post page add the editor button for affilinet plugin
100+
if ( $hook === 'post.php' || $hook == 'post-new.php' ) {
101+
add_action( 'admin_head', array( $this, 'register_tiny_mce_buttons' ) );
102+
add_action( "admin_head-$hook", array( $this, 'add_tiny_mce_variables' ) );
103+
}
104+
105+
// on settings page integrate font awesome
106+
107+
if ( $hook == 'settings_page_affilinet-product-widgets-settings' ) {
108+
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' );
109+
}
110+
111+
}
112+
113+
public function plugin_add_settings_link( $links ) {
114+
115+
$settings_link = '<a href="' . admin_url( 'options-general.php?page=affilinet-product-widgets-settings' ) . '">' . __( 'Settings' ) . '</a>';
116+
array_push( $links, $settings_link );
117+
return $links;
118+
}
104119

105120

106121
/**
@@ -110,83 +125,77 @@ public function admin_enqueue_scripts($hook)
110125
*
111126
* @return string
112127
*/
113-
public function affilinet_product_widgets_shortcode($params = array())
114-
{
115-
// default $widget_id parameter
116-
/**
117-
* @var String $size
118-
*/
119-
extract(shortcode_atts(array(
120-
'id' => 'notset',
121-
), $params));
122-
123-
return AffilinetWidgetsWidget::getAdCode($params['id']);
124-
}
125-
126-
/**
127-
* TRANSLATION
128-
*/
129-
public function load_textdomain()
130-
{
131-
load_plugin_textdomain( 'affilinet-product-widgets', false, dirname(dirname( plugin_basename( __FILE__ ) )) . '/languages' );
132-
}
133-
134-
/**
135-
* TinyMCE Editor Button
136-
*/
137-
public function register_tiny_mce_buttons()
138-
{
139-
// check user permissions
140-
if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
141-
return;
142-
}
143-
// check if WYSIWYG is enabled
144-
if (get_user_option('rich_editing') == 'true') {
145-
add_filter('mce_external_plugins', array($this, 'add_buttons'));
146-
add_filter('mce_buttons', array($this, 'register_buttons'));
147-
}
148-
}
149-
150-
/**
151-
* Load TinyMCE Variables
152-
*/
153-
public function add_tiny_mce_variables()
154-
{
155-
$img = plugin_dir_url( plugin_basename( dirname(__FILE__ )) ). 'images/';
156-
$widgets = AffilinetWidgetsApi::getMyWidgets();
157-
$widgetsForTinyMce = [];
158-
foreach ($widgets as $widget) {
159-
$widgetsForTinyMce[] = [
160-
'value' => $widget['id'],
161-
'id' => $widget['id'],
162-
'text' => $widget['widgetName'],
163-
];
164-
}
165-
?>
128+
public function affilinet_product_widgets_shortcode( $params = array() ) {
129+
// default $widget_id parameter
130+
/**
131+
* @var String $size
132+
*/
133+
extract( shortcode_atts( array(
134+
'id' => 'notset',
135+
), $params ) );
136+
137+
return AffilinetWidgetsWidget::getAdCode( $params['id'] );
138+
}
139+
140+
/**
141+
* TRANSLATION
142+
*/
143+
public function load_textdomain() {
144+
load_plugin_textdomain( 'affilinet-product-widgets', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages' );
145+
}
146+
147+
/**
148+
* TinyMCE Editor Button
149+
*/
150+
public function register_tiny_mce_buttons() {
151+
// check user permissions
152+
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
153+
return;
154+
}
155+
// check if WYSIWYG is enabled
156+
if ( get_user_option( 'rich_editing' ) == 'true' ) {
157+
add_filter( 'mce_external_plugins', array( $this, 'add_buttons' ) );
158+
add_filter( 'mce_buttons', array( $this, 'register_buttons' ) );
159+
}
160+
}
161+
162+
/**
163+
* Load TinyMCE Variables
164+
*/
165+
public function add_tiny_mce_variables() {
166+
$img = plugin_dir_url( plugin_basename( dirname( __FILE__ ) ) ) . 'images/';
167+
$widgets = AffilinetWidgetsApi::getMyWidgets();
168+
$widgetsForTinyMce = [];
169+
foreach ( $widgets as $widget ) {
170+
$widgetsForTinyMce[] = [
171+
'value' => $widget['id'],
172+
'id' => $widget['id'],
173+
'text' => $widget['widgetName'],
174+
];
175+
}
176+
?>
166177
<!-- TinyMCE Shortcode Plugin -->
167178
<script type='text/javascript'>
168179
var affilinet_product_widgets_mce_variables = {
169180
'image_path': '<?php echo $img; ?>',
170181
'choose_widget': 'Choose widget',
171-
'widgets' : <?php echo json_encode($widgetsForTinyMce, JSON_PRETTY_PRINT); ?>,
182+
'widgets': <?php echo json_encode( $widgetsForTinyMce, JSON_PRETTY_PRINT ); ?>,
172183
};
173184
</script>
174185
<!-- TinyMCE Shortcode Plugin -->
175-
<?php
176-
}
186+
<?php
187+
}
177188

178-
public function add_buttons($plugin_array)
179-
{
180-
$plugin_array['affilinet_product_widgets_mce_button'] = plugin_dir_url( plugin_basename( dirname(__FILE__) ) ). 'js/affilinet_product_widgets_mce_button.js';
189+
public function add_buttons( $plugin_array ) {
190+
$plugin_array['affilinet_product_widgets_mce_button'] = plugin_dir_url( plugin_basename( dirname( __FILE__ ) ) ) . 'js/affilinet_product_widgets_mce_button.js';
181191

182-
return $plugin_array;
183-
}
192+
return $plugin_array;
193+
}
184194

185-
public function register_buttons($buttons)
186-
{
187-
array_push($buttons, 'affilinet_product_widgets_mce_button');
195+
public function register_buttons( $buttons ) {
196+
array_push( $buttons, 'affilinet_product_widgets_mce_button' );
188197

189-
return $buttons;
190-
}
198+
return $buttons;
199+
}
191200

192201
}

trunk/classes/AffilinetWidgetsWidget.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,13 @@ public function widget($args, $instance)
8989

9090
public function getAdCode($widgetId)
9191
{
92-
return '<div id="affilinet-product-widget-'
93-
. $widgetId
94-
. '" class="affilinet-product-widget" data-affilinet-product-widget-id="'
95-
. $widgetId
96-
.'">'
97-
. '<link rel="stylesheet" type="text/css" href="https://productwidget.com/style-1.0.0.css">'
98-
. '<script type="text/javascript">!function(d){var e,i = \'affilinet-product-widget-script\';'
99-
. 'if(!d.getElementById(i)){e = d.createElement(\'script\');e.id = i;e.src = \'https://productwidget.com/affilinet-product-widget-1.0.0-min.js\''
100-
.';d.body.appendChild(e);}if (typeof window.__affilinetWidget===\'object\')if (d.readyState===\'complete\'){window.__affilinetWidget.init();}}(document);</script></div>';
92+
return '<div id="affilinet-product-widget-'
93+
. $widgetId
94+
. '" class="affilinet-product-widget" data-affilinet-widget-id="'
95+
. $widgetId
96+
. '"><link rel="stylesheet" type="text/css" href="https://productwidget.com/style-1.0.0.css">'
97+
. '<script type="text/javascript">!function(d){var e,i = \'affilinet-product-widget-script\';'
98+
. 'if(!d.getElementById(i)){e = d.createElement(\'script\');e.id = i;e.src = \'https://productwidget.com/affilinet-product-widget-1.0.0-min.js\''
99+
.';d.body.appendChild(e);}if (typeof window.__affilinetWidget===\'object\')if (d.readyState===\'complete\'){window.__affilinetWidget.init();}}(document);</script></div>';
101100
}
102101
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)