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.
Completed
Push — master ( fc808e...eee123 )
by Christian
10s
created

podlove.php (6 issues)

1
<?php
2
/**
3
 * @author    Podlove <[email protected]>
4
 * @copyright Copyright (c) 2014-2018, Podlove
5
 * @license   https://github.com/podlove/podlove-subscribe-button-wp-plugin/blob/master/LICENSE MIT
6
 * @package   Podlove\PodloveSubscribeButton
7
 * @version   1.4.0-beta
8
 */
9
10
/**
11
 * Plugin Name: Podlove Subscribe Button
12
 * Plugin URI:  https://wordpress.org/plugins/podlove-subscribe-button/
13
 * Description: Brings the Podlove Subscribe Button to your WordPress installation.
14
 * Version:     1.4.0-beta
15
 * Author:      Podlove
16
 * Author URI:  https://podlove.org/
17
 * License:     MIT
18
 * License URI: license.txt
19
 * Text Domain: podlove-subscribe-button
20
 */
21
22
$correct_php_version = version_compare( phpversion(), "5.3", ">=" );
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 5.3 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...
23
24
if ( ! $correct_php_version ) {
25
	printf( __( 'Podlove Subscribe Button Plugin requires %s or higher.<br>', 'podlove-subscribe-button' ), '<code>PHP 5.3</code>' );
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...
A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
Loading history...
26
	echo '<br />';
27
	printf( __( 'You are running %s', 'podlove-subscribe-button' ), '<code>PHP ' . phpversion() . '</code>' );
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...
A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
Loading history...
All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'phpversion'.
Loading history...
28
	exit;
29
}
30
31
// Constants
32
require( 'constants.php' );
33
require( 'settings/buttons.php' );
34
// Models
35
require( 'model/base.php' );
36
require( 'model/button.php' );
37
require( 'model/network_button.php' );
38
// Table
39
require( 'settings/buttons_list_table.php' );
40
// Media Types
41
require( 'media_types.php' );
42
// Widget
43
require( 'widget.php' );
44
// Version control
45
require( 'version.php' );
46
// Helper functions
47
require( 'helper.php' );
48
49
register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) );
50
51
PodloveSubscribeButton::run();
52
53
/**
54
 * Class PodloveSubscribeButton
55
 */
56
class PodloveSubscribeButton {
57
58
	/**
59
	 * @var string current plugin version
60
	 */
61
	public static $version = '1.4.0-beta';
62
63
	public static function run() {
64
		add_action( 'plugins_loaded', array( __CLASS__, 'load_translations' ) );
65
		add_action( 'init', array( __CLASS__, 'register_shortcode' ) );
66
		add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
67
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) );
68
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
69
		add_action( 'widgets_init', array( __CLASS__, 'widgets' ) );
70
		self::menu();
71
72
	}
73
74
	public static function widgets() {
75
		register_widget( '\PodloveSubscribeButton\Widget' );
76
77
	}
78
79
	public static function menu() {
80
		add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu' ) );
81
82
		if ( is_network_admin() ) {
83
			add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu' ) );
84
		}
85
86
	}
87
88
	public static function enqueue_assets( $hook ) {
89
90
		$pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' );
91
92
		if ( ! in_array( $hook, $pages ) ) {
93
			return;
94
		}
95
96
		// CSS Stylesheet
97
		wp_register_style( 'podlove-subscribe-button', plugin_dir_url( __FILE__ ) . 'style.css', false, self::$version );
98
		wp_enqueue_style( 'podlove-subscribe-button' );
99
100
		// Admin JS
101
		wp_enqueue_style( 'wp-color-picker' );
102
		wp_register_script( 'podlove-subscribe-button-admin-tools', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery', 'wp-color-picker' ), self::$version );
103
		$js_translations = array(
104
			'media_library' => __( 'Media Library', 'podlove-subscribe-button' ),
105
			'use_for'       => __( 'Use for Podcast Cover Art', 'podlove-subscribe-button' ),
106
		);
107
		wp_localize_script( 'podlove-subscribe-button-admin-tools', 'i18n', $js_translations );
108
		wp_enqueue_script( 'podlove-subscribe-button-admin-tools' );
109
110
	}
111
112
	public static function admin_menu() {
113
		add_options_page(
114
			__( 'Podlove Subscribe Button Options', 'podlove-subscribe-button' ),
115
			__( 'Podlove Subscribe Button', 'podlove-subscribe-button' ),
116
			'manage_options',
117
			'podlove-subscribe-button',
118
			array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
119
		);
120
121
	}
122
123
	public static function admin_network_menu() {
124
		add_submenu_page(
125
			'settings.php',
126
			__( 'Podlove Subscribe Button Options', 'podlove-subscribe-button' ),
127
			__( 'Podlove Subscribe Button', 'podlove-subscribe-button' ),
128
			'manage_options',
129
			'podlove-subscribe-button',
130
			array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
131
		);
132
133
	}
134
135
	public static function load_translations() {
136
		load_plugin_textdomain( 'podlove-subscribe-button' );
137
138
	}
139
140
	public static function register_settings() {
141
		$settings = array(
142
			'size',
143
			'autowidth',
144
			'style',
145
			'format',
146
			'color',
147
		);
148
149
		foreach ( $settings as $setting ) {
150
			register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting );
151
		}
152
153
	}
154
155
	public static function register_shortcode() {
156
		add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) );
157
158
	}
159
160
	public static function build_models() {
161
		// Build Databases
162
		\PodloveSubscribeButton\Model\Button::build();
163
164
		if ( is_multisite() ) {
165
			\PodloveSubscribeButton\Model\NetworkButton::build();
166
		}
167
168
		// Set Button "default" values
169
		$default_values = array(
170
			'size'      => 'big',
171
			'autowidth' => 'on',
172
			'color'     => '#599677',
173
			'style'     => 'filled',
174
			'format'    => 'rectangle'
175
		);
176
177
		foreach ( $default_values as $option => $default_value ) {
178
			if ( ! get_option( 'podlove_subscribe_button_default_' . $option ) ) {
179
				update_option( 'podlove_subscribe_button_default_' . $option, $default_value );
180
			}
181
		}
182
183
	}
184
185
	/**
186
	 * Add the shortcode
187
	 *
188
	 * @param $args
189
	 *
190
	 * @return string|void
191
	 */
192
	public static function shortcode( $args ) {
193
		if ( ! $args || ! isset( $args[ 'button' ] ) ) {
194
			return __( 'You need to create a Button first and provide its ID.', 'podlove-subscribe-button' );
195
		} else {
196
			$buttonid = $args[ 'button' ];
197
		}
198
199
		// Fetch the (network)button by it's name
200
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $args[ 'button' ] ) )
201
			return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args[ 'button' ] );
202
203
		// Get button styling and options
204
		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback( $args, 'width' ) );
205
		$size      = self::get_attribute( 'size', self::get_array_value_with_fallback( $args, 'size' ) );
206
		$style     = self::get_attribute( 'style', self::get_array_value_with_fallback( $args, 'style' ) );
207
		$format    = self::get_attribute( 'format', self::get_array_value_with_fallback( $args, 'format' ) );
208
		$color     = self::get_attribute( 'color', self::get_array_value_with_fallback( $args, 'color' ) );
209
210
		if ( isset( $args[ 'language' ] ) ) {
211
			$language = $args[ 'language' ];
212
		} else {
213
			$language = 'en';
214
		}
215
216
		if ( isset( $args[ 'color' ] ) ) {
217
			$color = $args[ 'color' ];
218
		} else {
219
			$color = get_option( 'podlove_subscribe_button_default_color', '#599677' );
220
		}
221
222
		if ( isset( $args[ 'hide' ] ) && $args[ 'hide' ] == 'true' ) {
223
			$hide = true;
224
		} else {
225
			$hide = false;
226
		}
227
228
		// Render button
229
		return $button->render( $size, $autowidth, $style, $format, $color, $hide, $buttonid, $language );
230
231
	}
232
233
	public static function get_array_value_with_fallback( $args, $key ) {
234
		if ( isset( $args[ $key ] ) ) {
235
			return $args[ $key ];
236
		}
237
238
		return false;
239
240
	}
241
242
	/**
243
	 * @param  string $attribute
244
	 * @param  string $attribute_value
245
	 * @return string
246
	 */
247
	private static function get_attribute( $attribute = null, $attribute_value = null ) {
248
		if ( isset( $attribute_value ) && ctype_alnum( $attribute_value ) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
249
			return $attribute_value;
250
		} else {
251
			return get_option( 'podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[ $attribute ] );
252
		}
253
254
	}
255
256
	/**
257
	 * Interprets the provided width attribute and return either auto- or a specific width
258
	 *
259
	 * @param  string $width_attribute
260
	 * @return string
261
	 */
262
	private static function interpret_width_attribute( $width_attribute = null ) {
263
		if ( $width_attribute == 'auto' ) {
264
			return 'on';
265
		}
266
267
		if ( $width_attribute && $width_attribute !== 'auto' ) {
268
			return 'off';
269
		}
270
271
		return get_option( 'podlove_subscribe_button_default_autowidth', 'on' );
272
273
	}
274
275
} // END class
276