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
Pull Request — master (#27)
by Christian
02:18
created

podlove.php (31 issues)

1
<?php
2
/**
3
 * Plugin Name: Podlove Subscribe Button
4
 * Plugin URI:  http://wordpress.org/extend/plugins/podlove-subscribe-button/
5
 * Description: Brings the Podlove Subscribe Button to your WordPress installation.
6
 * Version:     1.3.4
7
 * Author:      Podlove
8
 * Author URI:  http://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
add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu') );
0 ignored issues
show
Missing space before array closer.
Loading history...
43
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...
44
	add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu') );
0 ignored issues
show
Missing space before array closer.
Loading history...
45
46
add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) );
47
register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) );
48
49
// Register Settings
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
50
add_action( 'admin_init', function () {
51
	$settings = array('size', 'autowidth', 'style', 'format', 'color');
0 ignored issues
show
Missing space after array opener.
Loading history...
Missing space before array closer.
Loading history...
52
53
	foreach ($settings as $setting) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
54
		register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting );
55
	}
56
} );
57
58
add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) );
59
60
add_action( 'plugins_loaded', function () {
61
	load_plugin_textdomain( 'podlove-subscribe-button', false, dirname(plugin_basename( __FILE__)) . '/languages/');
62
} );
63
64
PodloveSubscribeButton::run();
65
66
67
class PodloveSubscribeButton {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for class PodloveSubscribeButton
Loading history...
68
69
	public static function run() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function run()
Loading history...
70
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
71
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
72
73
	public static function enqueue_assets( $hook ) {
74
75
		$pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' );
76
77
		if ( ! in_array( $hook, $pages )  ) {
78
			return;
79
		}
80
81
		// CSS Stylesheet
82
		wp_register_style( 'podlove-subscribe-button', plugin_dir_url( __FILE__ ) . 'style.css', false, '1.3.3' );
83
		wp_enqueue_style( 'podlove-subscribe-button' );
84
85
		// Spectrum JS
86
		wp_enqueue_style( 'podlove-subscribe-button-spectrum', plugin_dir_url( __FILE__ ) . 'js/spectrum/spectrum.css', array(), '1.8.0' );
87
		wp_enqueue_script( 'podlove-subscribe-button-spectrum', plugin_dir_url( __FILE__ ) . 'js/spectrum/spectrum.js', array( 'jquery' ), '1.8.0' );
88
89
		// Admin JS
90
		wp_register_script( 'podlove-subscribe-button-admin-tools', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ), '1.3.3' );
91
		$js_translations = array(
92
			'select_color'  => __( 'Select Color', 'podlove-subscribe-button' ),
93
			'cancel'        => __( 'Cancel', 'podlove-subscribe-button' ),
94
			'media_library' => __( 'Media Library', 'podlove-subscribe-button' ),
95
			'use_for'       => __( 'Use for Podcast Cover Art', 'podlove-subscribe-button' ),
96
		);
97
		wp_localize_script( 'podlove-subscribe-button-admin-tools', 'i18n', $js_translations );
98
		wp_enqueue_script( 'podlove-subscribe-button-admin-tools' );
99
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
100
101
	public static function admin_menu() {
102
		add_options_page(
103
				'Podlove Subscribe Button Options',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
104
				'Podlove Subscribe Button',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
105
				'manage_options',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
106
				'podlove-subscribe-button',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
107
				array( 'PodloveSubscribeButton\Settings\Buttons', 'page')
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
Missing space before array closer.
Loading history...
108
			);
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 12.
Loading history...
109
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
110
111
	public static function admin_network_menu() {
112
		add_submenu_page(
113
				'settings.php',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
114
				'Podlove Subscribe Button Options',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
115
				'Podlove Subscribe Button',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
116
				'manage_options',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
117
				'podlove-subscribe-button',
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
118
				array( 'PodloveSubscribeButton\Settings\Buttons', 'page')
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
Missing space before array closer.
Loading history...
119
			);
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 12.
Loading history...
120
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
121
122
	public static function build_models() {
123
		// Build Databases
124
		\PodloveSubscribeButton\Model\Button::build();
125
		if ( is_multisite() )
126
			\PodloveSubscribeButton\Model\NetworkButton::build();
127
128
		// Set Button "default" values
129
		$default_values = array(
130
				'size' => 'big',
131
				'autowidth' => 'on',
132
				'color' => '#599677',
133
				'style' => 'filled',
134
				'format' => 'rectangle'
135
			);
136
137
		foreach ($default_values as $option => $default_value) {
138
			if ( ! get_option('podlove_subscribe_button_default_' . $option ) ) {
139
				update_option('podlove_subscribe_button_default_' . $option, $default_value);
140
			}
141
		}
142
	}
143
144
	public static function shortcode( $args ) {
145
		if ( ! $args || ! isset($args['button']) ) {
146
			return __('You need to create a Button first and provide its ID.', 'podlove-subscribe-button');
147
		} else {
148
			$buttonid = $args['button'];
149
		}
150
151
		// Fetch the (network)button by it's name
152
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) )
153
			return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] );
154
155
		// Get button styling and options
156
		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback($args, 'width') );
157
		$size = self::get_attribute( 'size', self::get_array_value_with_fallback($args, 'size') );
158
		$style = self::get_attribute( 'style', self::get_array_value_with_fallback($args, 'style') );
159
		$format = self::get_attribute( 'format', self::get_array_value_with_fallback($args, 'format') );
160
		$color = self::get_attribute( 'color', self::get_array_value_with_fallback($args, 'color') );
161
162
		if ( isset($args['language']) ) {
163
			$language = $args['language'];
164
		} else {
165
			$language = 'en';
166
		}
167
168
		if ( isset($args['color']) ) {
169
			$color = $args['color'];
170
		} else {
171
			$color = get_option('podlove_subscribe_button_default_color', '#599677');
172
		}
173
174
		if ( isset($args['hide']) && $args['hide'] == 'true' ) {
175
			$hide = true;
176
		} else {
177
			$hide = false;
178
		}
179
180
		// Render button
181
		return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid, $language);
182
	}
183
184
	public static function get_array_value_with_fallback($args, $key) {
185
		if ( isset($args[$key]) )
186
			return $args[$key];
187
188
		return false;
189
	}
190
191
	/**
192
	 * @param  string $attribute
193
	 * @param  string $attribute_value
194
	 * @return string
195
	 */
196
	private static function get_attribute($attribute=null, $attribute_value=null) {
197
		if ( isset($attribute_value) && ctype_alnum($attribute_value) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
198
			return $attribute_value;
199
		} else {
200
			return get_option('podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[$attribute]);
201
		}
202
	}
203
204
	/**
205
	 * Interprets the provided width attribute and return either auto- or a specific width
206
	 * @param  string $width_attribute
207
	 * @return string
208
	 */
209
	private static function interpret_width_attribute( $width_attribute = null ) {
210
		if ( $width_attribute == 'auto' )
211
			return 'on';
212
		if ( $width_attribute && $width_attribute !== 'auto' )
213
			return 'off';
214
215
		return get_option('podlove_subscribe_button_default_autowidth', 'on');
0 ignored issues
show
Expected 1 spaces after opening bracket; 0 found
Loading history...
Expected 1 spaces before closing bracket; 0 found
Loading history...
216
	}
217
}