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 ( eee123...78b81a )
by Christian
11s
created

inc/Settings/Buttons.php (2 issues)

Severity
1
<?php
0 ignored issues
show
Filenames should be all lowercase with hyphens as word separators. Expected buttons.php, but found Buttons.php.
Loading history...
Class file names should be based on the class name with "class-" prepended. Expected class-buttons.php, but found Buttons.php.
Loading history...
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
 */
8
9
namespace PodloveSubscribeButton\Settings;
10
11
class Buttons {
12
13
	public static function page() {
14
15
		$action = null !== filter_input( INPUT_GET, 'action' ) ? filter_input( INPUT_GET, 'action' ) : null;
16
		$is_network = is_network_admin();
17
18
		if ( $action == 'confirm_delete' && null !== filter_input( INPUT_GET, 'button' ) ) {
19
			$button = ( $is_network === true ? \PodloveSubscribeButton\Model\NetworkButton::find_by_id( (int) filter_input( INPUT_GET, 'button' ) ) : \PodloveSubscribeButton\Model\Button::find_by_id( (int) filter_input( INPUT_GET, 'button' ) ) );
20
			?>
21
			<div class="updated">
22
				<p>
23
					<strong>
24
						<?php printf( __( 'You selected to delete the button "%s". Please confirm this action.', 'podlove-subscribe-button' ), $button->title ) ?>
25
					</strong>
26
				</p>
27
				<p>
28
					<?php echo self::get_action_link( $button, __( 'Delete button permanently', 'podlove-subscribe-button' ), 'delete', 'button' ) ?>
29
					<?php echo self::get_action_link( $button, __( "Don't change anything", 'podlove-subscribe-button' ), 'keep', 'button-primary' ) ?>
30
				</p>
31
			</div>
32
			<?php
33
		}
34
		?>
35
		<div class="wrap">
36
			<h1><?php echo __( 'Podlove Subscribe Button', 'podlove-subscribe-button' ); ?> <a href="?page=<?php echo filter_input( INPUT_GET, 'page' ); ?>&amp;action=new&amp;network=<?php echo $is_network; ?>" class="add-new-h2"><?php _e( 'Add New', 'podlove-subscribe-button' ); ?></a></h1>
37
			<?php
38
39
			switch ( $action ) {
40
				case 'new':   self::new_template(); break;
41
				case 'edit':  self::edit_template(); break;
42
				case 'index': self::view_template(); break;
43
				default:      self::view_template(); break;
44
			}
45
			?>
46
		</div>
47
		<?php
48
	}
49
50
	/**
51
	 * Process form: save/update a format
52
	 */
53
	public static function save() {
54
		if ( null == filter_input( INPUT_GET, 'button' ) )
55
			return;
56
57
		$post = filter_input_array( INPUT_POST );
58
59
		$button = ( filter_input( INPUT_GET, 'network' ) === '1' ? \PodloveSubscribeButton\Model\NetworkButton::find_by_id( filter_input( INPUT_GET, 'button' ) ) : \PodloveSubscribeButton\Model\Button::find_by_id( filter_input( INPUT_GET, 'button' ) ) );
60
		$button->update_attributes( $post[ 'podlove_button' ] );
61
62
		if ( isset( $post[ 'submit_and_stay' ] ) ) {
63
			self::redirect( 'edit', $button->id, array( 'network' => filter_input( INPUT_GET, 'network' ) ), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
64
		} else {
65
			self::redirect( 'index', $button->id, array(), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
66
		}
67
	}
68
	/**
69
	 * Process form: create a format
70
	 */
71
	public static function create() {
72
		global $wpdb;
73
74
		$post = filter_input_array( INPUT_POST );
75
76
		$button = ( filter_input( INPUT_GET, 'network' ) === '1' ? new \PodloveSubscribeButton\Model\NetworkButton : new \PodloveSubscribeButton\Model\Button );
77
		$button->update_attributes( $post[ 'podlove_button' ] );
78
79
		if ( isset( $post[ 'submit_and_stay' ] ) ) {
80
			self::redirect( 'edit', $button->id, array( 'network' => filter_input( INPUT_GET, 'network' ) ), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
81
		} else {
82
			self::redirect( 'index', $button->id, array(), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
83
		}
84
	}
85
86
	/**
87
	 * Process form: delete a format
88
	 */
89
	public static function delete() {
90
		if ( null == filter_input( INPUT_GET, 'button' ) )
91
			return;
92
93
		$button = ( filter_input( INPUT_GET, 'network' ) === '1' ? \PodloveSubscribeButton\Model\NetworkButton::find_by_id( filter_input( INPUT_GET, 'button' ) ) : \PodloveSubscribeButton\Model\Button::find_by_id( filter_input( INPUT_GET, 'button' ) ) );
94
		$button->delete();
95
96
		self::redirect( 'index', null, array(), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
97
	}
98
99
	/**
100
	 * Helper method: redirect to a certain page.
101
	 */
102
	public static function redirect( $action, $button_id = null, $params = array(), $network = false ) {
103
		$page    = ( $network ? '/network/settings' : 'options-general' ) . '.php?page=' . filter_input( INPUT_GET, 'page' );
104
		$show    = ( $button_id ) ? '&button=' . $button_id : '';
105
		$action  = '&action=' . $action;
106
107
		array_walk( $params, function( &$value, $key ) { $value = "&$key=$value"; } );
108
109
		wp_redirect( admin_url( $page . $show . $action . implode( '', $params ) ) );
110
	}
111
112
	public static function process_form() {
113
		if ( null === filter_input( INPUT_GET, 'button' ) )
114
			return;
115
116
		$action = ( null !== filter_input( INPUT_GET, 'action' ) ? filter_input( INPUT_GET, 'action' ) : null );
117
118
		if ( $action === 'save' ) {
119
			self::save();
120
		} elseif ( $action === 'create' ) {
121
			self::create();
122
		} elseif ( $action === 'delete' ) {
123
			self::delete();
124
		}
125
	}
126
127
	public static function new_template() {
128
		if ( filter_input( INPUT_GET, 'network' ) == '1' ) {
129
			$button = new \PodloveSubscribeButton\Model\NetworkButton;
130
		} else {
131
			$button = new \PodloveSubscribeButton\Model\Button;
132
		}
133
134
		echo '<h2>' . __( 'New Subscribe button', 'podlove-subscribe-button' ) . '</h2>' .
135
				__( 'Please fill in your Podcast metadata to create a Podlove Subscription button', 'podlove-subscribe-button' );
136
		self::form_template( $button, 'create' );
137
	}
138
139
	public static function edit_template() {
140
		if ( filter_input( INPUT_GET, 'network' ) == '1' ) {
141
			$button = \PodloveSubscribeButton\Model\NetworkButton::find_by_id( filter_input( INPUT_GET, 'button' ) );
142
		} else {
143
			$button = \PodloveSubscribeButton\Model\Button::find_by_id( filter_input( INPUT_GET, 'button' ) );
144
		}
145
146
		echo '<h2>' . sprintf( __( 'Edit Subscribe button: %s', 'podlove-subscribe-button' ), $button->title ) . '</h2>';
147
		self::form_template( $button, 'save' );
148
	}
149
150
	public static function view_template() {
151
		$is_network = is_network_admin();
152
		?>
153
		<p><?php _e( 'This plugin allows easy inclusion of the Podlove Subscribe Button. Put it in your sidebar with a simple widget or include the button in pages and/or posts with a simple shortcode.', 'podlove-subscribe-button' ); ?></p>
154
		<p><?php _e( 'Start by adding a button for each of your podcasts here. You can then add the button to your sidebar by adding the <a href="widgets.php">Podlove Subscribe Button widget</a>.', 'podlove-subscribe-button' ); ?></p>
155
		<p><?php _e( 'If you want to display the button inside a page or article, you can also use the <code>[podlove-subscribe-button]</code> shortcode anywhere.', 'podlove-subscribe-button' ); ?></p>
156
		<?php
157
		$table = new \PodloveSubscribeButton\Button_List_Table;
158
		$table->prepare_items();
159
		$table->display();
160
161
		// Get the global button settings (with fallback to default values)
162
		$settings = \PodloveSubscribeButton\Model\Button::get_global_setting_with_fallback();
163
164
		if ( ! $is_network ) :
165
		?>
166
		<h3><?php _e( 'Default Settings', 'podlove-subscribe-button' ); ?></h3>
167
		<form method="post" action="options.php">
168
			<?php settings_fields( 'podlove-subscribe-button' ); ?>
169
			<?php do_settings_sections( 'podlove-subscribe-button' ); ?>
170
			<table class="form-table">
171
				<tr valign="top">
172
				<th scope="row"><label for="podlove_subscribe_button_default_size"><?php _e( 'Size', 'podlove-subscribe-button' ); ?></label></th>
173
				<td>
174
					<select name="podlove_subscribe_button_default_size" id="podlove_subscribe_button_default_size">
175
						<?php foreach ( \PodloveSubscribeButton\Model\Button::$size as $value => $description ) : ?>
176
							<option value="<?php echo $value; ?>" <?php echo ( $settings[ 'size' ] == $value ? "selected" : '' ); ?>><?php echo $description; ?></option>
177
						<?php endforeach; ?>
178
					</select>
179
				</td>
180
				</tr>
181
				<tr valign="top">
182
				<th scope="row"><label for="podlove_subscribe_button_default_autowidth"><?php _e( 'Autowidth', 'podlove-subscribe-button' ); ?></label></th>
183
				<td>
184
					<input type="checkbox" name="podlove_subscribe_button_default_autowidth" id="podlove_subscribe_button_default_autowidth" <?php echo ( $settings[ 'autowidth' ] == 'on' ? 'checked' : '' ) ?> />
185
				</td>
186
				</tr>
187
				<tr valign="top">
188
				<th scope="row"><label for="podlove_subscribe_button_default_color"><?php _e( 'Color', 'podlove-subscribe-button' ); ?></label></th>
189
				<td>
190
					<input id="podlove_subscribe_button_default_color" name="podlove_subscribe_button_default_color" class="podlove_subscribe_button_color" value="<?php echo $settings[ 'color' ] ?>" />
191
				</td>
192
				</tr>
193
				<tr valign="top">
194
				<th scope="row"><label for="podlove_subscribe_button_default_style"><?php _e( 'Style', 'podlove-subscribe-button' ); ?></label></th>
195
				<td>
196
					<select name="podlove_subscribe_button_default_style" id="podlove_subscribe_button_default_style">
197
						<?php foreach ( \PodloveSubscribeButton\Model\Button::$style as $value => $description ) : ?>
198
							<option value="<?php echo $value; ?>" <?php echo ( $settings[ 'style' ] == $value ? "selected" : '' ); ?>><?php echo $description; ?></option>
199
						<?php endforeach; ?>
200
					</select>
201
				</td>
202
				</tr>
203
				<tr valign="top">
204
				<th scope="row"><label for="podlove_subscribe_button_default_format"><?php _e( 'Format', 'podlove-subscribe-button' ); ?></label></th>
205
				<td>
206
					<select name="podlove_subscribe_button_default_format" id="podlove_subscribe_button_default_format">
207
						<?php foreach ( \PodloveSubscribeButton\Model\Button::$format as $value => $description ) : ?>
208
							<option value="<?php echo $value; ?>" <?php echo ( $settings[ 'format' ] == $value ? "selected" : '' ); ?>><?php echo $description; ?></option>
209
						<?php endforeach; ?>
210
					</select>
211
				</td>
212
				</tr>
213
			</table>
214
			<?php submit_button(); ?>
215
		</form>
216
		<?php
217
		endif;
218
	}
219
220
	private static function form_template( $button, $action ) {
221
		// Enqueue Scripts for Media Manager
222
		wp_enqueue_media();
223
		// Adjust if is_network
224
		$is_network = is_network_admin();
225
		?>
226
		<form method="post" action="<?php echo ( $is_network === true ? '/wp-admin/network/settings' : 'options-general' ) ?>.php?page=podlove-subscribe-button&button=<?php echo $button->id; ?>&action=<?php echo $action; ?>&network=<?php echo $is_network; ?>">
227
			<input type="hidden" value="<?php echo $button->id; ?>" name="podlove_button[id]" />
228
			<table class="form-table" border="0" cellspacing="0">
229
					<tbody>
230
					<tr>
231
						<th scope="row">
232
							<label for="podlove_button_name"><?php _e( 'Button ID', 'podlove-subscribe-button' ); ?></label>
233
						</th>
234
						<td>
235
							<input type="text" class="regular-text" id="podlove_button_name" name="podlove_button[name]" value="<?php echo $button->name; ?>" />
236
                            <p class="description"><?php _e( 'The ID will be used as in internal identifier for shortcodes.', 'podlove-subscribe-button' ); ?></p>
237
                        </td>
238
					</tr>
239
					<tr>
240
						<th scope="row">
241
							<label for="podlove_button_title"><?php _e( 'Podcast Title', 'podlove-subscribe-button' ); ?></label>
242
						</th>
243
						<td>
244
							<input type="text" class="regular-text" id="podlove_button_title" name="podlove_button[title]" value="<?php echo $button->title; ?>" />
245
						</td>
246
					</tr>
247
					<tr>
248
						<th scope="row">
249
							<label for="podlove_button_subtitle"><?php _e( 'Podcast Subtitle', 'podlove-subscribe-button' ); ?></label>
250
						</th>
251
						<td>
252
							<input type="text" class="regular-text" id="podlove_button_subtitle" name="podlove_button[subtitle]" value="<?php echo $button->subtitle; ?>" />
253
						</td>
254
					</tr>
255
					<tr>
256
						<th scope="row">
257
							<label for="podlove_button_description"><?php _e( 'Podcast Description', 'podlove-subscribe-button' ); ?></label>
258
						</th>
259
						<td>
260
							<textarea class="autogrow" cols="40" rows="3" id="podlove_button_description" name="podlove_button[description]"><?php echo $button->description; ?></textarea>
261
						</td>
262
					</tr>
263
					<tr>
264
						<th scope="row">
265
							<label for="podlove-button-cover"><?php _e( 'Podcast Image URL', 'podlove-subscribe-button' ); ?></label>
266
						</th>
267
						<td>
268
							<input type="text" class="regular-text" id="podlove-button-cover" name="podlove_button[cover]" value="<?php echo $button->cover; ?>" />
269
							<a id="Podlove_cover_image_select" class="button" href="#">Select</a>
270
							<br /><img src="<?php echo $button->cover; ?>" alt="" style="width: 200px" />
271
							<script type="text/javascript">
272
								(function($) {
273
									$("#podlove-button-cover").on( 'change', function() {
274
										url = $(this).val();
275
										$(this).parent().find("img").attr("src", url);
276
									} );
277
								})(jQuery);
278
							</script>
279
						</td>
280
					</tr>
281
					<tr>
282
						<th scope="row">
283
							<label for="feeds_table"><?php _e( 'Podcast Feeds', 'podlove-subscribe-button' ); ?></label>
284
						</th>
285
						<td>
286
							<table id="feeds_table" class="podlove_alternating" border="0" cellspacing="0">
287
								<thead>
288
									<tr>
289
										<th><?php _e( 'URL', 'podlove-subscribe-button' ); ?></th>
290
										<th><?php _e( 'iTunes feed ID', 'podlove-subscribe-button' ); ?></th>
291
										<th><?php _e( 'Media format', 'podlove-subscribe-button' ); ?></th>
292
										<th><?php _e( 'Actions', 'podlove-subscribe-button' ); ?></th>
293
									</tr>
294
								</thead>
295
								<tbody id="feeds_table_body">
296
								</tbody>
297
							</table>
298
							<input type="button" class="button add_feed" value="+" />
299
							<p><span class="description"><?php _e( 'Provide all Feeds with their corresponding Media File Type. The Subscribe Button will then automatically provide the most suitable feed to the subscriber with respect to their Podcast Client.', 'podlove-subscribe-button' ); ?></span></p>
300
						</td>
301
					</tr>
302
					</tbody>
303
				</table>
304
				<input name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'podlove-subscribe-button' ); ?>" type="submit" />
305
				<input type="submit" name="submit_and_stay" id="submit_and_stay" class="button" value="<?php _e( 'Save Changes and Continue Editing', 'podlove-subscribe-button' ); ?>"  />
306
307
				<script type="text/template" id="feed_line_template">
308
					<tr>
309
						<td>
310
							<input type="text" class="regular-text" name="podlove_button[feeds][{{id}}][url]" value="{{url}}" />
311
						</td>
312
						<td>
313
						<input type="text" class="regular-text" name="podlove_button[feeds][{{id}}][itunesfeedid]" value="{{itunesfeedid}}" />
314
						</td>
315
						<td>
316
							<select class="regular-text podlove-media-format" name="podlove_button[feeds][{{id}}][format]">
317
								<?php
318
									foreach ( \PodloveSubscribeButton\MediaTypes::$audio as $id => $audio ) {
319
										echo "<option value='" . $id . "'>" . $audio[ 'title' ] . "</option>\n";
320
									}
321
								?>
322
							</select>
323
						</td>
324
						<td><i class="clickable podlove-icon-remove"></i></td>
325
					</tr>
326
				</script>
327
				<script type="text/javascript">
328
					var feeds = <?php echo json_encode( $button->feeds ); ?>;
329
				</script>
330
		</form>
331
		<?php
332
	}
333
334
	public static function get_action_link( $button, $title, $action = 'edit', $type = 'link' ) {
335
		return sprintf(
336
			'<a href="?page=%s&action=%s&button=%s&network=' . is_network_admin() . '"%s>' . $title . '</a>',
337
			filter_input( INPUT_GET, 'page' ),
338
			$action,
339
			$button->id,
340
			$type == 'button' ? ' class="button"' : ''
341
		);
342
	}
343
344
} // END class
345