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 ( 3b4963...d53694 )
by Christian
02:09
created

podlove.php (9 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
	_e("Podlove Subscribe Button Plugin requires <strong>PHP 5.3</strong> or higher.<br>", 'podlove-subscribe-button');
0 ignored issues
show
All output should be run through an escaping function (like esc_html_e() or esc_attr_e()), found '_e'.
Loading history...
Expected 1 spaces after opening bracket; 0 found
Loading history...
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style Comprehensibility introduced by
The string literal Podlove Subscribe Button.../strong> or higher.<br> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
19
	echo __("You are running PHP ", 'podlove-subscribe-button') . phpversion();
0 ignored issues
show
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '__'.
Loading history...
Expected 1 spaces after opening bracket; 0 found
Loading history...
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style Comprehensibility introduced by
The string literal You are running PHP does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'phpversion'.
Loading history...
20
	exit;
21
}
22
23
// Constants
24
require('constants.php');
25
require('settings/buttons.php');
26
// Models
27
require('model/base.php');
28
require('model/button.php');
29
require('model/network_button.php');
30
// Table
31
require('settings/buttons_list_table.php');
32
// Media Types
33
require('media_types.php');
34
// Widget
35
require('widget.php');
36
// Version control
37
require('version.php');
38
// Helper functions
39
require('helper.php');
40
41
add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu') );
42
if ( is_multisite() )
43
	add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu') );
44
45
add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) );
46
register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) );
47
48
// Register Settings
49
add_action( 'admin_init', function () {
50
	$settings = array('size', 'autowidth', 'style', 'format', 'color');
51
52
	foreach ($settings as $setting) {
53
		register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting );
54
	}
55
} );
56
57
add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) );
58
59
add_action( 'plugins_loaded', function () {
60
	load_plugin_textdomain( 'podlove-subscribe-button', false, dirname(plugin_basename( __FILE__)) . '/languages/');
61
} );
62
63
PodloveSubscribeButton::run();
64
65
66
class PodloveSubscribeButton {
67
68
	public static function run() {
69
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
70
	}
71
72
	public static function enqueue_assets( $hook ) {
73
74
		$pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' );
75
76
		if ( ! in_array( $hook, $pages )  ) {
77
			return;
78
		}
79
80
		// CSS Stylesheet
81
		wp_register_style( 'podlove-subscribe-button', plugin_dir_url( __FILE__ ) . 'style.css', false, '1.3.3' );
82
		wp_enqueue_style( 'podlove-subscribe-button' );
83
84
		// Spectrum JS
85
		wp_enqueue_style( 'podlove-subscribe-button-spectrum', plugin_dir_url( __FILE__ ) . 'js/spectrum/spectrum.css', array(), '1.8.0' );
86
		wp_enqueue_script( 'podlove-subscribe-button-spectrum', plugin_dir_url( __FILE__ ) . 'js/spectrum/spectrum.js', array( 'jquery' ), '1.8.0' );
87
88
		// Admin JS
89
		wp_register_script( 'podlove-subscribe-button-admin-tools', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ), '1.3.3' );
90
		$js_translations = array(
91
			'select_color'  => __( 'Select Color', 'podlove-subscribe-button' ),
92
			'cancel'        => __( 'Cancel', 'podlove-subscribe-button' ),
93
			'media_library' => __( 'Media Library', 'podlove-subscribe-button' ),
94
			'use_for'       => __( 'Use for Podcast Cover Art', 'podlove-subscribe-button' ),
95
		);
96
		wp_localize_script( 'podlove-subscribe-button-admin-tools', 'i18n', $js_translations );
97
		wp_enqueue_script( 'podlove-subscribe-button-admin-tools' );
98
	}
99
100
	public static function admin_menu() {
101
		add_options_page(
102
				'Podlove Subscribe Button Options',
103
				'Podlove Subscribe Button',
104
				'manage_options',
105
				'podlove-subscribe-button',
106
				array( 'PodloveSubscribeButton\Settings\Buttons', 'page')
107
			);
108
	}
109
110
	public static function admin_network_menu() {
111
		add_submenu_page(
112
				'settings.php',
113
				'Podlove Subscribe Button Options',
114
				'Podlove Subscribe Button',
115
				'manage_options',
116
				'podlove-subscribe-button',
117
				array( 'PodloveSubscribeButton\Settings\Buttons', 'page')
118
			);
119
	}
120
121
	public static function build_models() {
122
		// Build Databases
123
		\PodloveSubscribeButton\Model\Button::build();
124
		if ( is_multisite() )
125
			\PodloveSubscribeButton\Model\NetworkButton::build();
126
127
		// Set Button "default" values
128
		$default_values = array(
129
				'size' => 'big',
130
				'autowidth' => 'on',
131
				'color' => '#599677',
132
				'style' => 'filled',
133
				'format' => 'rectangle'
134
			);
135
136
		foreach ($default_values as $option => $default_value) {
137
			if ( ! get_option('podlove_subscribe_button_default_' . $option ) ) {
138
				update_option('podlove_subscribe_button_default_' . $option, $default_value);
139
			}
140
		}
141
	}
142
143
	public static function shortcode( $args ) {
144
		if ( ! $args || ! isset($args['button']) ) {
145
			return __('You need to create a Button first and provide its ID.', 'podlove-subscribe-button');
146
		} else {
147
			$buttonid = $args['button'];
148
		}
149
150
		// Fetch the (network)button by it's name
151
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) )
152
			return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] );
153
154
		// Get button styling and options
155
		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback($args, 'width') );
156
		$size = self::get_attribute( 'size', self::get_array_value_with_fallback($args, 'size') );
157
		$style = self::get_attribute( 'style', self::get_array_value_with_fallback($args, 'style') );
158
		$format = self::get_attribute( 'format', self::get_array_value_with_fallback($args, 'format') );
159
		$color = self::get_attribute( 'color', self::get_array_value_with_fallback($args, 'color') );
160
161
		if ( isset($args['language']) ) {
162
			$language = $args['language'];
163
		} else {
164
			$language = 'en';
165
		}
166
167
		if ( isset($args['color']) ) {
168
			$color = $args['color'];
169
		} else {
170
			$color = get_option('podlove_subscribe_button_default_color', '#599677');
171
		}
172
173
		if ( isset($args['hide']) && $args['hide'] == 'true' ) {
174
			$hide = true;
175
		} else {
176
			$hide = false;
177
		}
178
179
		// Render button
180
		return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid, $language);
181
	}
182
183
	public static function get_array_value_with_fallback($args, $key) {
184
		if ( isset($args[$key]) )
185
			return $args[$key];
186
187
		return false;
188
	}
189
190
	/**
191
	 * @param  string $attribute
192
	 * @param  string $attribute_value
193
	 * @return string
194
	 */
195
	private static function get_attribute($attribute=null, $attribute_value=null) {
196
		if ( isset($attribute_value) && ctype_alnum($attribute_value) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
197
			return $attribute_value;
198
		} else {
199
			return get_option('podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[$attribute]);
200
		}
201
	}
202
203
	/**
204
	 * Interprets the provided width attribute and return either auto- or a specific width
205
	 * @param  string $width_attribute
206
	 * @return string
207
	 */
208
	private static function interpret_width_attribute( $width_attribute = null ) {
209
		if ( $width_attribute == 'auto' )
210
			return 'on';
211
		if ( $width_attribute && $width_attribute !== 'auto' )
212
			return 'off';
213
214
		return get_option('podlove_subscribe_button_default_autowidth', 'on');
215
	}
216
}