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 ( dc0f35...efd704 )
by Christian
15s
created

inc/Settings/Buttons.php (17 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
 */
8
9
namespace PodloveSubscribeButton\Settings;
10
11
use PodloveSubscribeButton\Helpers;
12
13
class Buttons {
14
15
	public static function page() {
16
17
		$action = null !== filter_input( INPUT_GET, 'action' ) ? filter_input( INPUT_GET, 'action' ) : null;
18
		$is_network = is_network_admin();
19
20
		if ( $action == 'confirm_delete' && null !== filter_input( INPUT_GET, 'button' ) ) {
21
			$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' ) ) );
22
			?>
23
			<div class="updated">
24
				<p>
25
					<strong>
26
						<?php printf( __( 'You selected to delete the button "%s". Please confirm this action.', 'podlove-subscribe-button' ), $button->title ) ?>
27
					</strong>
28
				</p>
29
				<p>
30
					<?php echo self::get_action_link( $button, __( 'Delete button permanently', 'podlove-subscribe-button' ), 'delete', 'button' ) ?>
31
					<?php echo self::get_action_link( $button, __( "Don't change anything", 'podlove-subscribe-button' ), 'keep', 'button-primary' ) ?>
32
				</p>
33
			</div>
34
			<?php
35
		}
36
		?>
37
		<div class="wrap">
38
			<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>
39
            <div id="poststuff">
40
                <div id="post-body" class="columns-2">
41
                    <div id="post-body-content">
42
	                    <?php
43
	                    switch ( $action ) {
44
		                    case 'new':   self::new_template(); break;
45
		                    case 'edit':  self::edit_template(); break;
46
		                    case 'index': self::view_template(); break;
47
		                    default:      self::view_template(); break;
48
	                    }
49
	                    ?>
50
                    </div>
51
                    <div id="postbox-container-1" class="postbox-container">
52
                        <?php self::sidebar(); ?>
53
                    </div>
54
                </div>
55
            </div>
56
		</div><!-- .wrap -->
57
		<?php
58
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
59
60
	/**
61
	 * Render the sidebar HTML
62
	 */
63
	public static function sidebar() { ?>
64
        <div id="submitdiv" class="postbox">
65
            <h2 class="ui-sortable-handle"><span>Podlove Subscribe Button <code><?php echo \PodloveSubscribeButton::$version; ?></code></span></h2>
66
            <div class="inside">
67
                <div id="minor-publishing" style="padding:0 10px;">
68
                    <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>
69
                    <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>
70
                    <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>
71
                </div>
72
                <div id="major-publishing-actions">
73
                    <ul>
74
                        <li>
75
                            <a href="https://subscribe-button.podlove.org/" target="_blank">Podlove Subscribe Button</a>
76
                        </li>
77
                        <li>
78
                            <a href="https://podlove.org" target="_blank">Podlove Initiative</a>
79
                        </li>
80
                        <li>
81
                            <a href="https://community.podlove.org/" target="_blank">Podlove Community</a>
82
                        </li>
83
                        <li>
84
                            <a href="https://docs.podlove.org" target="_blank">Documentation &amp; Guides</a>
85
                        </li>
86
                        <li>
87
                            <a href="https://podlove.org/donations/" target="_blank">Donate</a>
88
                        </li>
89
                    </ul>
90
                </div>
91
            </div>
92
        </div>
93
        <?php
94
95
    }
96
97
	/**
98
	 * Process form: save/update a format
99
	 */
100
	public static function save() {
101
		if ( null == filter_input( INPUT_GET, 'button' ) )
102
			return;
103
104
		$post = filter_input_array( INPUT_POST );
105
106
		$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' ) ) );
107
		$button->update_attributes( $post[ 'podlove_button' ] );
108
109
		if ( isset( $post[ 'submit_and_stay' ] ) ) {
110
			self::redirect( 'edit', $button->id, array( 'network' => filter_input( INPUT_GET, 'network' ) ), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
111
		} else {
112
			self::redirect( 'index', $button->id, array(), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
113
		}
114
	}
115
	/**
116
	 * Process form: create a format
117
	 */
118
	public static function create() {
119
		global $wpdb;
120
121
		$post = filter_input_array( INPUT_POST );
122
123
		$button = ( filter_input( INPUT_GET, 'network' ) === '1' ? new \PodloveSubscribeButton\Model\NetworkButton : new \PodloveSubscribeButton\Model\Button );
124
		$button->update_attributes( $post[ 'podlove_button' ] );
125
126
		if ( isset( $post[ 'submit_and_stay' ] ) ) {
127
			self::redirect( 'edit', $button->id, array( 'network' => filter_input( INPUT_GET, 'network' ) ), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
128
		} else {
129
			self::redirect( 'index', $button->id, array(), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
130
		}
131
	}
132
133
	/**
134
	 * Process form: delete a format
135
	 */
136
	public static function delete() {
137
		if ( null == filter_input( INPUT_GET, 'button' ) )
138
			return;
139
140
		$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' ) ) );
141
		$button->delete();
142
143
		self::redirect( 'index', null, array(), ( filter_input( INPUT_GET, 'network' ) === '1' ? true : false ) );
144
	}
145
146
	/**
147
	 * Helper method: redirect to a certain page.
148
	 */
149
	public static function redirect( $action, $button_id = null, $params = array(), $network = false ) {
150
		$page    = ( $network ? '/network/settings' : 'options-general' ) . '.php?page=' . filter_input( INPUT_GET, 'page' );
151
		$show    = ( $button_id ) ? '&button=' . $button_id : '';
152
		$action  = '&action=' . $action;
153
154
		array_walk( $params, function( &$value, $key ) { $value = "&$key=$value"; } );
155
156
		wp_redirect( admin_url( $page . $show . $action . implode( '', $params ) ) );
157
	}
158
159
	public static function process_form() {
160
		if ( null === filter_input( INPUT_GET, 'button' ) )
161
			return;
162
163
		$action = ( null !== filter_input( INPUT_GET, 'action' ) ? filter_input( INPUT_GET, 'action' ) : null );
164
165
		if ( $action === 'save' ) {
166
			self::save();
167
		} elseif ( $action === 'create' ) {
168
			self::create();
169
		} elseif ( $action === 'delete' ) {
170
			self::delete();
171
		}
172
	}
173
174
	public static function new_template() {
175
		if ( filter_input( INPUT_GET, 'network' ) == '1' ) {
176
			$button = new \PodloveSubscribeButton\Model\NetworkButton;
177
		} else {
178
			$button = new \PodloveSubscribeButton\Model\Button;
179
		}
180
181
		echo '<h2>' . __( 'New Subscribe button', 'podlove-subscribe-button' ) . '</h2>' .
182
				__( 'Please fill in your Podcast metadata to create a Podlove Subscription button', 'podlove-subscribe-button' );
183
		self::form_template( $button, 'create' );
184
	}
185
186
	public static function edit_template() {
187
		if ( filter_input( INPUT_GET, 'network' ) == '1' ) {
188
			$button = \PodloveSubscribeButton\Model\NetworkButton::find_by_id( filter_input( INPUT_GET, 'button' ) );
189
		} else {
190
			$button = \PodloveSubscribeButton\Model\Button::find_by_id( filter_input( INPUT_GET, 'button' ) );
191
		}
192
193
		echo '<h2>' . sprintf( __( 'Edit Subscribe button: %s', 'podlove-subscribe-button' ), $button->title ) . '</h2>';
194
		self::form_template( $button, 'save' );
195
	}
196
197
	public static function view_template() {
198
199
		$is_network = is_network_admin();
200
		$table = new \PodloveSubscribeButton\Button_List_Table;
201
		$table->prepare_items();
202
		$table->display();
203
204
		if ( $is_network ) {
205
		    // https://vedovini.net/2015/10/using-the-wordpress-settings-api-with-network-admin-pages/
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
206
			?>
207
            <form method="post" action="edit.php?action=podlove_psb_update_network_options">
208
				<?php
209
				settings_fields( 'podlove-psb' );
210
				do_settings_sections( 'podlove-psb' );
211
				submit_button();
212
				?>
213
            </form>
214
			<?php
215
		} else {
216
			?>
217
            <form method="post" action="options.php">
218
				<?php
219
				settings_fields( 'podlove-psb' );
220
				do_settings_sections( 'podlove-psb' );
221
				submit_button();
222
				?>
223
            </form>
224
		<?php }
0 ignored issues
show
Opening PHP tag must be on a line by itself
Loading history...
225
	}
226
227
	private static function form_template( $button, $action ) {
228
		// Enqueue Scripts for Media Manager
229
		wp_enqueue_media();
230
		// Adjust if is_network
231
		$is_network = is_network_admin();
232
		?>
233
		<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; ?>">
234
			<input type="hidden" value="<?php echo $button->id; ?>" name="podlove_button[id]" />
235
			<table class="form-table" border="0" cellspacing="0">
236
					<tbody>
237
					<tr>
238
						<th scope="row">
239
							<label for="podlove_button_name"><?php _e( 'Button ID', 'podlove-subscribe-button' ); ?></label>
240
						</th>
241
						<td>
242
							<input type="text" class="regular-text" id="podlove_button_name" name="podlove_button[name]" value="<?php echo $button->name; ?>" />
243
                            <p class="description"><?php _e( 'The ID will be used as in internal identifier for shortcodes.', 'podlove-subscribe-button' ); ?></p>
244
                        </td>
245
					</tr>
246
					<tr>
247
						<th scope="row">
248
							<label for="podlove_button_title"><?php _e( 'Podcast Title', 'podlove-subscribe-button' ); ?></label>
249
						</th>
250
						<td>
251
							<input type="text" class="regular-text" id="podlove_button_title" name="podlove_button[title]" value="<?php echo $button->title; ?>" />
252
						</td>
253
					</tr>
254
					<tr>
255
						<th scope="row">
256
							<label for="podlove_button_subtitle"><?php _e( 'Podcast Subtitle', 'podlove-subscribe-button' ); ?></label>
257
						</th>
258
						<td>
259
							<input type="text" class="regular-text" id="podlove_button_subtitle" name="podlove_button[subtitle]" value="<?php echo $button->subtitle; ?>" />
260
						</td>
261
					</tr>
262
					<tr>
263
						<th scope="row">
264
							<label for="podlove_button_description"><?php _e( 'Podcast Description', 'podlove-subscribe-button' ); ?></label>
265
						</th>
266
						<td>
267
							<textarea class="autogrow" cols="40" rows="3" id="podlove_button_description" name="podlove_button[description]"><?php echo $button->description; ?></textarea>
268
						</td>
269
					</tr>
270
					<tr>
271
						<th scope="row">
272
							<label for="podlove-button-cover"><?php _e( 'Podcast Image URL', 'podlove-subscribe-button' ); ?></label>
273
						</th>
274
						<td>
275
							<input type="text" class="regular-text" id="podlove-button-cover" name="podlove_button[cover]" value="<?php echo $button->cover; ?>" />
276
							<a id="Podlove_cover_image_select" class="button" href="#">Select</a>
277
							<br /><img src="<?php echo $button->cover; ?>" alt="" style="width: 200px" />
278
							<script type="text/javascript">
279
								(function($) {
280
									$("#podlove-button-cover").on( 'change', function() {
281
										url = $(this).val();
282
										$(this).parent().find("img").attr("src", url);
283
									} );
284
								})(jQuery);
285
							</script>
286
						</td>
287
					</tr>
288
					<tr>
289
						<th scope="row">
290
							<label for="feeds_table"><?php _e( 'Podcast Feeds', 'podlove-subscribe-button' ); ?></label>
291
						</th>
292
						<td>
293
							<table id="feeds_table" class="podlove_alternating widefat striped">
294
								<thead>
295
									<tr>
296
										<th scope="col" id="url" class="manage-column column-primary"><?php _e( 'URL', 'podlove-subscribe-button' ); ?></th>
297
										<th scope="col" id="itunes_id" class="manage-column"><?php _e( 'iTunes feed ID', 'podlove-subscribe-button' ); ?></th>
298
										<th scope="col" id="format" class="manage-column"><?php _e( 'Media format', 'podlove-subscribe-button' ); ?></th>
299
										<th scope="col" id="action" class="manage-column"><?php _e( 'Actions', 'podlove-subscribe-button' ); ?></th>
300
									</tr>
301
								</thead>
302
								<tbody id="feeds_table_body">
303
								</tbody>
304
							</table>
305
							<input type="button" class="button add_feed" value="+" />
306
							<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>
307
						</td>
308
					</tr>
309
					</tbody>
310
				</table>
311
				<input name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'podlove-subscribe-button' ); ?>" type="submit" />
312
				<input type="submit" name="submit_and_stay" id="submit_and_stay" class="button" value="<?php _e( 'Save Changes and Continue Editing', 'podlove-subscribe-button' ); ?>"  />
313
314
				<script type="text/template" id="feed_line_template">
315
					<tr>
316
						<td>
317
							<input type="text" class="regular-text" name="podlove_button[feeds][{{id}}][url]" value="{{url}}" />
318
						</td>
319
						<td>
320
						<input type="text" class="regular-text" name="podlove_button[feeds][{{id}}][itunesfeedid]" value="{{itunesfeedid}}" />
321
						</td>
322
						<td>
323
							<select class="regular-text podlove-media-format" name="podlove_button[feeds][{{id}}][format]">
324
								<?php
325
									foreach ( \PodloveSubscribeButton\Defaults::media_types() as $id => $audio ) {
326
										echo "<option value='" . $id . "'>" . $audio[ 'title' ] . "</option>\n";
327
									}
328
								?>
329
							</select>
330
						</td>
331
						<td><span class="dashicons dashicons-trash clickable podlove-icon-remove"></span></td>
332
					</tr>
333
				</script>
334
				<script type="text/javascript">
335
					var feeds = <?php echo json_encode( $button->feeds ); ?>;
336
				</script>
337
		</form>
338
		<?php
339
	}
340
341
	public static function get_action_link( $button, $title, $action = 'edit', $type = 'link' ) {
342
		return sprintf(
343
			'<a href="?page=%s&action=%s&button=%s&network=' . is_network_admin() . '"%s>' . $title . '</a>',
344
			filter_input( INPUT_GET, 'page' ),
345
			$action,
346
			$button->id,
347
			$type == 'button' ? ' class="button"' : ''
348
		);
349
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
350
351
	public static function podlove_psb_update_network_options() {
0 ignored issues
show
Method name "Buttons::podlove_psb_update_network_options" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function podlove_psb_update_network_options()
Loading history...
352
353
		//Verify Post Referring Page
0 ignored issues
show
No space found before comment text; expected "// Verify Post Referring Page" but found "//Verify Post Referring Page"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
354
		check_admin_referer( 'podlove-psb-options' );
355
		update_site_option( 'podlove_psb_defaults', $_POST['podlove_psb_defaults'] );
0 ignored issues
show
Detected usage of a non-validated input variable: $_POST
Loading history...
Missing wp_unslash() before sanitization.
Loading history...
Detected usage of a non-sanitized input variable: $_POST
Loading history...
356
357
		//Redirect to Network Settings Page
0 ignored issues
show
No space found before comment text; expected "// Redirect to Network Settings Page" but found "//Redirect to Network Settings Page"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
358
		wp_redirect( add_query_arg( array( 'page' => 'podlove-subscribe-button', 'updated' => 'true' ), network_admin_url( 'settings.php' ) ) );
0 ignored issues
show
wp_redirect() found. Using wp_safe_redirect(), along with the allowed_redirect_hosts filter if needed, can help avoid any chances of malicious redirects within code. It is also important to remember to call exit() after a redirect so that no other unwanted code is executed.
Loading history...
When a multi-item array uses associative keys, each value should start on a new line.
Loading history...
359
360
		exit;
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
361
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
362
363
} // END class
364