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 (#25)
by Christian
02:19
created

podlove.php (1 issue)

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');
19
	echo __("You are running PHP ", 'podlove-subscribe-button') . phpversion();
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
		// Admin JS
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
85
		wp_enqueue_style( 'wp-color-picker' );
86
		wp_register_script( 'podlove-subscribe-button-admin-tools', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery', 'wp-color-picker' ), '1.3.3' );
87
		$js_translations = array(
88
			'media_library' => __( 'Media Library', 'podlove-subscribe-button' ),
89
			'use_for'       => __( 'Use for Podcast Cover Art', 'podlove-subscribe-button' ),
90
		);
91
		wp_localize_script( 'podlove-subscribe-button-admin-tools', 'i18n', $js_translations );
92
		wp_enqueue_script( 'podlove-subscribe-button-admin-tools' );
93
	}
94
95
	public static function admin_menu() {
96
		add_options_page(
97
				'Podlove Subscribe Button Options',
98
				'Podlove Subscribe Button',
99
				'manage_options',
100
				'podlove-subscribe-button',
101
				array( 'PodloveSubscribeButton\Settings\Buttons', 'page')
102
			);
103
	}
104
105
	public static function admin_network_menu() {
106
		add_submenu_page(
107
				'settings.php',
108
				'Podlove Subscribe Button Options',
109
				'Podlove Subscribe Button',
110
				'manage_options',
111
				'podlove-subscribe-button',
112
				array( 'PodloveSubscribeButton\Settings\Buttons', 'page')
113
			);
114
	}
115
116
	public static function build_models() {
117
		// Build Databases
118
		\PodloveSubscribeButton\Model\Button::build();
119
		if ( is_multisite() )
120
			\PodloveSubscribeButton\Model\NetworkButton::build();
121
122
		// Set Button "default" values
123
		$default_values = array(
124
				'size' => 'big',
125
				'autowidth' => 'on',
126
				'color' => '#599677',
127
				'style' => 'filled',
128
				'format' => 'rectangle'
129
			);
130
131
		foreach ($default_values as $option => $default_value) {
132
			if ( ! get_option('podlove_subscribe_button_default_' . $option ) ) {
133
				update_option('podlove_subscribe_button_default_' . $option, $default_value);
134
			}
135
		}
136
	}
137
138
	public static function shortcode( $args ) {
139
		if ( ! $args || ! isset($args['button']) ) {
140
			return __('You need to create a Button first and provide its ID.', 'podlove-subscribe-button');
141
		} else {
142
			$buttonid = $args['button'];
143
		}
144
145
		// Fetch the (network)button by it's name
146
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) )
147
			return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] );
148
149
		// Get button styling and options
150
		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback($args, 'width') );
151
		$size = self::get_attribute( 'size', self::get_array_value_with_fallback($args, 'size') );
152
		$style = self::get_attribute( 'style', self::get_array_value_with_fallback($args, 'style') );
153
		$format = self::get_attribute( 'format', self::get_array_value_with_fallback($args, 'format') );
154
		$color = self::get_attribute( 'color', self::get_array_value_with_fallback($args, 'color') );
155
156
		if ( isset($args['language']) ) {
157
			$language = $args['language'];
158
		} else {
159
			$language = 'en';
160
		}
161
162
		if ( isset($args['color']) ) {
163
			$color = $args['color'];
164
		} else {
165
			$color = get_option('podlove_subscribe_button_default_color', '#599677');
166
		}
167
168
		if ( isset($args['hide']) && $args['hide'] == 'true' ) {
169
			$hide = true;
170
		} else {
171
			$hide = false;
172
		}
173
174
		// Render button
175
		return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid, $language);
176
	}
177
178
	public static function get_array_value_with_fallback($args, $key) {
179
		if ( isset($args[$key]) )
180
			return $args[$key];
181
182
		return false;
183
	}
184
185
	/**
186
	 * @param  string $attribute
187
	 * @param  string $attribute_value
188
	 * @return string
189
	 */
190
	private static function get_attribute($attribute=null, $attribute_value=null) {
191
		if ( isset($attribute_value) && ctype_alnum($attribute_value) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
192
			return $attribute_value;
193
		} else {
194
			return get_option('podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[$attribute]);
195
		}
196
	}
197
198
	/**
199
	 * Interprets the provided width attribute and return either auto- or a specific width
200
	 * @param  string $width_attribute
201
	 * @return string
202
	 */
203
	private static function interpret_width_attribute( $width_attribute = null ) {
204
		if ( $width_attribute == 'auto' )
205
			return 'on';
206
		if ( $width_attribute && $width_attribute !== 'auto' )
207
			return 'off';
208
209
		return get_option('podlove_subscribe_button_default_autowidth', 'on');
210
	}
211
}