GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 0392a4...4f7518 )
by Christian
02:13
created

podlove.php (25 issues)

1
<?php
2
/**
3
 * Plugin Name: Podlove Subscribe Button
4
 * Plugin URI:  https://wordpress.org/plugins/podlove-subscribe-button/
5
 * Description: Brings the Podlove Subscribe Button to your WordPress installation.
6
 * Version:     1.4.0-beta
7
 * Author:      Podlove
8
 * Author URI:  https://podlove.org/
9
 * License:     MIT
10
 * License URI: license.txt
11
 * Text Domain: podlove-subscribe-button
12
 * Domain Path: /languages
13
 */
14
15
$correct_php_version = version_compare( phpversion(), "5.3", ">=" );
16
17
if ( ! $correct_php_version ) {
18
	printf( __( 'Podlove Subscribe Button Plugin requires %s or higher.<br>', 'podlove-subscribe-button' ), '<code>PHP 5.3</code>' );
19
	echo '<br />';
20
	printf( __( 'You are running %s', 'podlove-subscribe-button' ), '<code>PHP ' . phpversion() . '</code>' );
21
	exit;
22
}
23
24
// Constants
25
require( 'constants.php' );
26
require( 'settings/buttons.php' );
27
// Models
28
require( 'model/base.php' );
29
require( 'model/button.php' );
30
require( 'model/network_button.php' );
31
// Table
32
require( 'settings/buttons_list_table.php' );
33
// Media Types
34
require( 'media_types.php' );
35
// Widget
36
require( 'widget.php' );
37
// Version control
38
require( 'version.php' );
39
// Helper functions
40
require( 'helper.php' );
41
42
register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) );
43
44
PodloveSubscribeButton::run();
45
46
/**
47
 * Class PodloveSubscribeButton
48
 */
49
class PodloveSubscribeButton {
50
51
	/**
52
	 * @var string current plugin version
53
	 */
54
	public static $version = '1.4.0-beta';
55
56
	public static function run() {
57
		add_action( 'plugins_loaded', array( __CLASS__, 'load_translations' ) );
58
		add_action( 'init', array( __CLASS__, 'register_shortcode' ) );
59
		add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
60
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) );
61
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
62
		add_action( 'widgets_init', array( __CLASS__, 'widgets' ) );
63
		self::menu();
64
65
	}
66
67
	public static function widgets() {
68
		register_widget( '\PodloveSubscribeButton\Widget' );
69
70
	}
71
72
	public static function menu() {
73
		add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu' ) );
74
75
		if ( is_network_admin() ) {
76
			add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu' ) );
77
		}
78
79
	}
80
81
	public static function enqueue_assets( $hook ) {
82
83
		$pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' );
84
85
		if ( ! in_array( $hook, $pages ) ) {
86
			return;
87
		}
88
89
		// CSS Stylesheet
90
		wp_register_style( 'podlove-subscribe-button', plugin_dir_url( __FILE__ ) . 'style.css', false, self::$version );
91
		wp_enqueue_style( 'podlove-subscribe-button' );
92
93
		// Spectrum JS
94
		wp_enqueue_style( 'podlove-subscribe-button-spectrum', plugin_dir_url( __FILE__ ) . 'js/spectrum/spectrum.css', array(), '1.8.0' );
95
		wp_enqueue_script( 'podlove-subscribe-button-spectrum', plugin_dir_url( __FILE__ ) . 'js/spectrum/spectrum.js', array( 'jquery' ), '1.8.0' );
96
97
		// Admin JS
98
		wp_register_script( 'podlove-subscribe-button-admin-tools', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ), self::$version );
99
		$js_translations = array(
100
			'select_color'  => __( 'Select Color', 'podlove-subscribe-button' ),
101
			'cancel'        => __( 'Cancel', 'podlove-subscribe-button' ),
102
			'media_library' => __( 'Media Library', 'podlove-subscribe-button' ),
103
			'use_for'       => __( 'Use for Podcast Cover Art', 'podlove-subscribe-button' ),
104
		);
105
		wp_localize_script( 'podlove-subscribe-button-admin-tools', 'i18n', $js_translations );
106
		wp_enqueue_script( 'podlove-subscribe-button-admin-tools' );
107
108
	}
109
110
	public static function admin_menu() {
111
		add_options_page(
112
			'Podlove Subscribe Button Options',
113
			'Podlove Subscribe Button',
114
			'manage_options',
115
			'podlove-subscribe-button',
116
			array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
117
		);
118
119
	}
120
121
	public static function admin_network_menu() {
122
		add_submenu_page(
123
			'settings.php',
124
			'Podlove Subscribe Button Options',
125
			'Podlove Subscribe Button',
126
			'manage_options',
127
			'podlove-subscribe-button',
128
			array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
129
		);
130
131
	}
132
133
	public static function load_translations() {
134
		load_plugin_textdomain( 'podlove-subscribe-button', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
135
136
	}
137
138
	public static function register_settings() {
139
		$settings = array(
140
			'size',
141
			'autowidth',
142
			'style',
143
			'format',
144
			'color',
145
		);
146
147
		foreach ( $settings as $setting ) {
148
			register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting );
149
		}
150
151
	}
152
153
	public static function register_shortcode() {
154
		add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) );
155
156
	}
157
158
	public static function build_models() {
159
		// Build Databases
160
		\PodloveSubscribeButton\Model\Button::build();
161
		if ( is_multisite() )
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
162
			\PodloveSubscribeButton\Model\NetworkButton::build();
163
164
		// Set Button "default" values
165
		$default_values = array(
166
				'size' => 'big',
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
Array double arrow not aligned correctly; expected 6 space(s) between "'size'" and double arrow, but found 1.
Loading history...
167
				'autowidth' => 'on',
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
168
				'color' => '#599677',
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
Array double arrow not aligned correctly; expected 5 space(s) between "'color'" and double arrow, but found 1.
Loading history...
169
				'style' => 'filled',
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
Array double arrow not aligned correctly; expected 5 space(s) between "'style'" and double arrow, but found 1.
Loading history...
170
				'format' => 'rectangle'
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
Array double arrow not aligned correctly; expected 4 space(s) between "'format'" and double arrow, but found 1.
Loading history...
171
			);
0 ignored issues
show
Array closer not aligned correctly; expected 8 space(s) but found 12
Loading history...
172
173
		foreach ( $default_values as $option => $default_value ) {
174
			if ( ! get_option( 'podlove_subscribe_button_default_' . $option ) ) {
175
				update_option( 'podlove_subscribe_button_default_' . $option, $default_value );
176
			}
177
		}
178
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
179
180
	public static function shortcode( $args ) {
181
		if ( ! $args || ! isset( $args[ 'button' ] ) ) {
182
			return __( 'You need to create a Button first and provide its ID.', 'podlove-subscribe-button' );
183
		} else {
184
			$buttonid = $args[ 'button' ];
185
		}
186
187
		// Fetch the (network)button by it's name
188
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $args[ 'button' ] ) )
189
			return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args[ 'button' ] );
190
191
		// Get button styling and options
192
		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback( $args, 'width' ) );
193
		$size = self::get_attribute( 'size', self::get_array_value_with_fallback( $args, 'size' ) );
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
194
		$style = self::get_attribute( 'style', self::get_array_value_with_fallback( $args, 'style' ) );
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
195
		$format = self::get_attribute( 'format', self::get_array_value_with_fallback( $args, 'format' ) );
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
196
		$color = self::get_attribute( 'color', self::get_array_value_with_fallback( $args, 'color' ) );
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
197
198
		if ( isset( $args[ 'language' ] ) ) {
199
			$language = $args[ 'language' ];
200
		} else {
201
			$language = 'en';
202
		}
203
204
		if ( isset( $args[ 'color' ] ) ) {
205
			$color = $args[ 'color' ];
206
		} else {
207
			$color = get_option( 'podlove_subscribe_button_default_color', '#599677' );
208
		}
209
210
		if ( isset( $args[ 'hide' ] ) && $args[ 'hide' ] == 'true' ) {
211
			$hide = true;
212
		} else {
213
			$hide = false;
214
		}
215
216
		// Render button
217
		return $button->render( $size, $autowidth, $style, $format, $color, $hide, $buttonid, $language );
218
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
219
220
	public static function get_array_value_with_fallback( $args, $key ) {
221
		if ( isset( $args[ $key ] ) )
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
222
			return $args[ $key ];
223
224
		return false;
225
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
226
227
	/**
228
	 * @param  string $attribute
229
	 * @param  string $attribute_value
230
	 * @return string
231
	 */
232
	private static function get_attribute( $attribute = null, $attribute_value = null ) {
233
		if ( isset( $attribute_value ) && ctype_alnum( $attribute_value ) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
234
			return $attribute_value;
235
		} else {
236
			return get_option( 'podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[ $attribute ] );
237
		}
238
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
239
240
	/**
241
	 * Interprets the provided width attribute and return either auto- or a specific width
242
	 * @param  string $width_attribute
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
243
	 * @return string
244
	 */
245
	private static function interpret_width_attribute( $width_attribute = null ) {
246
		if ( $width_attribute == 'auto' )
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
247
			return 'on';
248
		if ( $width_attribute && $width_attribute !== 'auto' )
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
249
			return 'off';
250
251
		return get_option( 'podlove_subscribe_button_default_autowidth', 'on' );
252
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
253
}
254