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
Pull Request — master (#175)
by Chris
04:24
created

admin-pages.php ➔ ppp_admin_page()   F

Complexity

Conditions 13
Paths 480

Size

Total Lines 100
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 13
eloc 64
c 3
b 0
f 0
nc 480
nop 0
dl 0
loc 100
rs 3.2936

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
// Exit if accessed directly
4
if ( ! defined( 'ABSPATH' ) ) {
5
	exit;
6
}
7
8
/**
9
 * Display the General settings tab
10
 * @return void
11
 */
12
function ppp_admin_page() {
13
	global $ppp_options;
14
	$license    = get_option( '_ppp_license_key' );
15
	$status     = get_option( '_ppp_license_key_status' );
16
17
	?>
18
	<div class="wrap">
19
		<div id="icon-options-general" class="icon32"></div><h1><?php _e( 'Post Promoter Pro', 'ppp-txt' ); ?></h1>
20
		<form method="post" action="options.php">
21
			<?php wp_nonce_field( 'ppp-options' ); ?>
22
			<table class="form-table">
23
24
				<tr valign="top">
25
					<th scope="row" valign="top">
26
						<?php _e( 'License Key', 'ppp-txt' ); ?><br /><span style="font-size: x-small;"><?php _e( 'Enter your license key', 'ppp-txt' ); ?></span>
27
					</th>
28
					<td>
29
						<input id="ppp_license_key" name="_ppp_license_key" type="text" class="regular-text" value="<?php esc_attr_e( $license ); ?>" /><?php if( $status !== false && $status == 'valid' ) { ?>
30
						<span style="color:green;">&nbsp;<?php _e( 'active', 'ppp-txt' ); ?></span><?php } ?>
31
					</td>
32
				</tr>
33
34
				<?php if( false !== $license ) { ?>
35
					<tr valign="top">
36
						<th scope="row" valign="top">
37
							<?php _e( 'Activate License', 'ppp-txt' ); ?>
38
						</th>
39
						<td>
40
							<?php if( $status !== false && $status == 'valid' ) { ?>
41
								<?php wp_nonce_field( 'ppp_deactivate_nonce', 'ppp_deactivate_nonce' ); ?>
42
								<input type="submit" class="button-secondary" name="ppp_license_deactivate" value="<?php _e( 'Deactivate License', 'ppp-txt' ); ?>"/>
43
							<?php } else {
44
								wp_nonce_field( 'ppp_activate_nonce', 'ppp_activate_nonce' ); ?>
45
								<input type="submit" class="button-secondary" name="ppp_license_activate" value="<?php _e( 'Activate License', 'ppp-txt' ); ?>"/>
46
							<?php } ?>
47
						</td>
48
					</tr>
49
				<?php } ?>
50
51
				<tr valign="top">
52
					<th scope="row"><?php _e( 'Default Share Text', 'ppp-txt' ); ?><br />
53
						<span style="font-size: x-small;"><a href="#" onclick="jQuery('#ppp-text-helper').toggle(); return false;"><?php _e( 'Default Text Tips', 'ppp-txt' ); ?></a></span>
54
					</th>
55
					<td>
56
						<?php $default_text = isset( $ppp_options['default_text'] ) ? $ppp_options['default_text'] : ''; ?>
57
						<input type="text" class="regular-text" name="ppp_options[default_text]" value="<?php echo $default_text; ?>" placeholder="Post Title will be used if empty" size="50" />
58
						<p id="ppp-text-helper" style="display: none">
59
							<small>
60
							<?php _e( 'The typical length of a link shortened on Twitter is 23 characters, so keep that in mind when writing your default text.', 'ppp-txt' ); ?>
61
							<br />
62
							<?php _e( 'Status updates over 140 charcters will fail to post.', 'ppp-txt' ); ?>
63
							<br />
64
							<?php _e( 'Possible Replacements:', 'ppp-txt' ); ?>
65
							<br />
66
							<?php foreach( ppp_get_text_tokens() as $token ): ?>
67
								<code>{<?php echo $token['token']; ?>}</code> - <?php echo $token['description']; ?><br />
68
							<?php endforeach; ?>
69
							</small>
70
						</p>
71
					</td>
72
				</tr>
73
74
				<tr valign="top">
75
					<th scope="row"><?php _e( 'Post Types', 'ppp-txt' ); ?><br /><span style="font-size: x-small;"><?php _e( 'What post types do you want to schedule for?', 'ppp-txt' ); ?></span></th>
76
					<td>
77
						<?php $post_types = ppp_supported_post_types(); ?>
78
						<?php foreach ( $post_types as $post_type => $type_data ): ?>
79
							<?php $value = ( isset( $ppp_options['post_types'] ) && isset( $ppp_options['post_types'][$post_type] ) ) ? true : false; ?>
80
							<input type="checkbox" name="ppp_options[post_types][<?php echo $post_type; ?>]" value="1" id="<?php echo $post_type; ?>" <?php checked( true, $value, true ); ?> />&nbsp;
81
							<label for="<?php echo $post_type; ?>"><?php echo $type_data->labels->name; ?></label></br />
82
						<?php endforeach; ?>
83
					</td>
84
				</tr>
85
86
				<tr valign="top">
87
					<th scope="row"><?php _e( 'Advanced', 'ppp-txt' ); ?><br /><span style="font-size: x-small;"><?php _e( 'Tools for troubleshooting and advanced usage', 'ppp-txt' ); ?></span></th>
88
					<td>
89
						<p>
90
						<?php $debug_enabled = isset( $ppp_options['enable_debug'] ) ? true : false; ?>
91
						<input type="checkbox" name="ppp_options[enable_debug]" <?php checked( true, $debug_enabled, true ); ?> value="1" /> <?php _e( 'Enable Debug', 'ppp-txt' ); ?>
92
						</p>
93
						<p>
94
						<?php $delete_on_uninstall = isset( $ppp_options['delete_on_uninstall'] ) ? true : false; ?>
95
						<input type="checkbox" name="ppp_options[delete_on_uninstall]" <?php checked( true, $delete_on_uninstall, true ); ?> value="1" /> <?php _e( 'Delete All Data On Uninstall', 'ppp-txt' ); ?>
96
						</p>
97
					</td>
98
				</tr>
99
100
				<?php do_action( 'ppp_general_settings_after' ); ?>
101
102
				<input type="hidden" name="action" value="update" />
103
				<?php $page_options = apply_filters( 'ppp_settings_page_options', array( 'ppp_options', '_ppp_license_key' ) ); ?>
104
				<input type="hidden" name="page_options" value="<?php echo implode( ',', $page_options ); ?>" />
105
				<?php settings_fields( 'ppp-options' ); ?>
106
			</table>
107
			<input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'ppp-txt' ) ?>" />
108
		</form>
109
	</div>
110
	<?php
111
}
112
113
114
/**
115
* Display the Social tab
116
* @return void
117
*/
118
function ppp_display_social() {
119
	do_action( 'ppp_social_settings_pre_form' );
120
121
	$ppp_share_settings = get_option( 'ppp_share_settings' );
122
	?>
123
	<div class="wrap">
124
		<div id="icon-options-general" class="icon32"></div><h1><?php _e( 'Post Promoter Pro - Social Settings', 'ppp-txt' ); ?></h1>
125
		<form method="post" action="options.php">
126
			<?php wp_nonce_field( 'ppp-share-settings' ); ?>
127
			<h3><?php _e( 'Social Media Accounts', 'ppp-txt' ); ?></h3>
128
			<?php
129
			require_once PPP_PATH . 'includes/admin/class-accounts-table.php';
130
131
			$accounts_table = new PPP_Accounts_Table();
132
			$accounts_table->prepare_items();
133
134
			$accounts_table->display();
135
			?>
136
			<table class="form-table">
137
				<?php $analytics_option = isset( $ppp_share_settings['analytics'] ) ? $ppp_share_settings['analytics'] : 0; ?>
138
				<tr valign="top">
139
					<th scope="row" valign="top">
140
						<?php _e( 'Analytics', 'ppp-txt' ); ?></span>
141
					</th>
142
					<td id="ppp-analytics-options">
143
						<p>
144
							<input id="ppp_no_tracking"
145
							       name="ppp_share_settings[analytics]"
146
							       type="radio"
147
							       value="none"
148
							       <?php checked( 'none', $analytics_option, true ); ?>
149
							/>&nbsp;<label for="ppp_no_tracking"><?php _e( 'None', 'ppp-txt' ); ?></label>
150
						</p>
151
						<br />
152
						<p>
153
							<input id="ppp_unique_links"
154
							       name="ppp_share_settings[analytics]"
155
							       type="radio"
156
							       value="unique_links"
157
							       <?php checked( 'unique_links', $analytics_option, true ); ?>
158
							/>&nbsp;<label for="ppp_unique_links"><?php _e( 'Simple Tracking', 'ppp-txt' ); ?></label><br />
159
							<small><?php _e( 'Appends a query string to shared links for analytics.', 'ppp-txt' ); ?></small>
160
						</p>
161
						<br />
162
						<p>
163
							<input id="ppp_ga_tags"
164
							       name="ppp_share_settings[analytics]"
165
							       type="radio"
166
							       value="google_analytics"
167
							       <?php checked( 'google_analytics', $analytics_option, true ); ?>
168
							/>&nbsp;<label for="ppp_ga_tags"><?php _e( 'Google Analytics Tags', 'ppp-txt' ); ?></label><br />
169
							<small><?php _e( 'Results can be seen in the Acquisition Menu under "Campaigns"', 'ppp-txt' ); ?></small>
170
						</p>
171
						<?php do_action( 'ppp-settings-analytics-radio' ); ?>
172
						<p id="ppp-link-example">
173
						<hr />
174
						<small><?php _e( 'Here is an example of what your link will look like', 'ppp-txt' ); ?>: <br />
175
							<?php $post = wp_get_recent_posts( array( 'numberposts' => 1 ) ); ?>
176
							<?php if( count( $post ) > 0 ): ?>
177
								<code><?php echo ppp_generate_link( $post[0]['ID'], 'sharedate_1_' . $post[0]['ID'], false ); ?></code></small>
178
							<?php else: ?>
179
								<em><?php _e( 'No posts available to generate link from.', 'ppp-txt' ); ?></em>
180
							<?php endif; ?>
181
						</p>
182
					</td>
183
				</tr>
184
185
				<?php
186
				$tw_sop = ! empty( $ppp_share_settings['twitter']['share_on_publish'] ) ? true : false;
187
				$fb_sop = ! empty( $ppp_share_settings['facebook']['share_on_publish'] ) ? true : false;
188
				$li_sop = ! empty( $ppp_share_settings['linkedin']['share_on_publish'] ) ? true : false;
189
				?>
190
				<tr valign="top">
191
					<th scope="row" valign="top">
192
						<?php _e( 'Share on Publish Defaults', 'ppp-txt' ); ?></span><br />
193
						<small><em><?php _e( 'Enabled sharing on publish by default', 'ppp-txt' ); ?></em></small>
194
					</th>
195
					<td id="ppp-share-on-publish-wrapper">
196
						<?php if ( ppp_twitter_enabled() ) : ?>
197
						<p>
198
							<input type="checkbox" id="twitter-share-on-publish" value="1" <?php checked( true, $tw_sop, true ); ?> name="ppp_share_settings[twitter][share_on_publish]" />
199
							<label for="twitter-share-on-publish"><?php _e( 'Twitter', 'ppp-txt' ); ?></label>
200
						</p>
201
						<?php endif; ?>
202
203
						<?php if ( ppp_facebook_enabled() ) : ?>
204
						<p>
205
							<input type="checkbox" id="facebook-share-on-publish" value="1" <?php checked( true, $fb_sop, true ); ?> name="ppp_share_settings[facebook][share_on_publish]" />
206
							<label for="facebook-share-on-publish"><?php _e( 'Facebook', 'ppp-txt' ); ?></label>
207
						</p>
208
						<?php endif; ?>
209
210
						<?php if ( ppp_linkedin_enabled() ) : ?>
211
						<p>
212
							<input type="checkbox" id="linkedin-share-on-publish" value="1" <?php checked( true, $li_sop, true ); ?> name="ppp_share_settings[linkedin][share_on_publish]" />
213
							<label for="linkedin-share-on-publish"><?php _e( 'LinkedIn', 'ppp-txt' ); ?></label>
214
						</p>
215
						<?php endif; ?>
216
					</td>
217
				</tr>
218
219
				<?php $twitter_cards_enabled = ppp_tw_cards_enabled(); ?>
220
				<tr valign="top">
221
					<th scope="row" valign="top">
222
						<?php _e( 'Twitter Settings', 'ppp-txt' ); ?></span>
223
					</th>
224
					<td id="ppp-twitter-cards-wrapper">
225
						<p>
226
							<input id="ppp-twitter-cards"
227
							       name="ppp_share_settings[twitter][cards_enabled]"
228
							       type="checkbox"
229
							       value="1"
230
							       <?php checked( true, $twitter_cards_enabled, true ); ?>
231
							/>&nbsp;<label for="ppp-twitter-cards"><?php _e( 'Enable Twitter Cards', 'ppp-txt' ); ?></label>
232
						</p>
233
					</td>
234
				</tr>
235
236
				<?php
237
				$shortener = isset( $ppp_share_settings['shortener'] ) ? $ppp_share_settings['shortener'] : false;
238
				?>
239
				<tr valign="top">
240
					<th scope="row" valign="top">
241
						<?php _e( 'URL Shortener', 'ppp-txt' ); ?></span>
242
					</th>
243
					<td id="ppp-shortener-options">
244
						<p>
245
							<select name="ppp_share_settings[shortener]">
246
								<option value="-1"><?php _e( 'Select a Service', 'ppp-txt' ); ?></option>
247
								<?php do_action( 'ppp_url_shorteners', $shortener ); ?>
248
							</select>
249
						</p>
250
						<?php if ( $shortener ) : ?>
251
							<?php do_action( 'ppp_shortener_settings-' . $shortener ); ?>
252
						<?php endif; ?>
253
					</td>
254
				</tr>
255
256
				<?php settings_fields( 'ppp-share-settings' ); ?>
257
258
				<input type="hidden" name="action" value="update" />
259
				<input type="hidden" name="page_options" value="ppp_share_settings,ppp_social_settings" />
260
261
262
			</table>
263
264
			<input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'ppp-txt' ) ?>" />
265
266
		</form>
267
	</div>
268
	<?php
269
}
270
271
/**
272
* Display the List Table tab
273
* @return void
274
*/
275
function ppp_display_schedule() {
276
	?>
277
	<style type="text/css">
278
		.wp-list-table .column-day { width: 5%; }
279
		.wp-list-table .column-date { width: 20%; }
280
		.wp-list-table .column-post_title { width: 25%; }
281
		.wp-list-table .column-content { width: 50%; }
282
	</style>
283
	<?php
284
	require_once PPP_PATH . 'includes/admin/class-schedule-table.php';
285
	$schedule_table = new PPP_Schedule_Table();
286
	$schedule_table->prepare_items();
287
	?>
288
	<div class="wrap">
289
		<div id="icon-options-general" class="icon32"></div><h1><?php _e( 'Post Promoter Pro - Scheduled Shares', 'ppp-txt' ); ?></h1>
290
		<?php $schedule_table->display() ?>
291
	</div>
292
	<?php if ( ppp_is_shortener_enabled() ): ?>
293
	<p>
294
		<small><?php _e( 'NOTICE: Schedule view does not show shortened links, they will be shortened at the time of sharing', 'ppp-txt' ); ?></small>
295
	</p>
296
	<?php endif; ?>
297
	<?php
298
}
299
300
/**
301
 * Display the System Info Tab
302
 * @return void
303
 */
304
function ppp_display_sysinfo() {
305
	global $wpdb, $ppp_options;
306
	?>
307
	<div class="wrap">
308
		<div id="icon-options-general" class="icon32"></div><h1><?php _e( 'Post Promoter Pro - System Info', 'ppp-txt' ); ?></h1>
309
		<textarea style="font-family: Menlo, Monaco, monospace; white-space: pre" onclick="this.focus();this.select()" readonly cols="150" rows="35">
310
	SITE_URL:                 <?php echo site_url() . "\n"; ?>
311
	HOME_URL:                 <?php echo home_url() . "\n"; ?>
312
313
	PPP Version:             <?php echo PPP_VERSION . "\n"; ?>
314
	WordPress Version:        <?php echo get_bloginfo( 'version' ) . "\n"; ?>
315
316
	PPP SETTINGS:
317
	<?php
318
	foreach ( $ppp_options as $name => $value ) {
319
	if ( $value == false ) {
320
		$value = 'false';
321
	}
322
323
	if ( $value == '1' ) {
324
		$value = 'true';
325
	}
326
327
	echo $name . ': ' . maybe_serialize( $value ) . "\n\t";
328
	}
329
	?>
330
331
	ACTIVE PLUGINS:
332
	<?php
333
	$plugins = get_plugins();
334
	$active_plugins = get_option( 'active_plugins', array() );
335
336
	foreach ( $plugins as $plugin_path => $plugin ) {
337
		// If the plugin isn't active, don't show it.
338
		if ( ! in_array( $plugin_path, $active_plugins ) ) {
339
			continue;
340
		}
341
342
		echo $plugin['Name']; ?>: <?php echo $plugin['Version'] ."\n\t";
343
344
	}
345
	?>
346
347
	CURRENT THEME:
348
	<?php
349
	if ( get_bloginfo( 'version' ) < '3.4' ) {
350
		$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
351
		echo $theme_data['Name'] . ': ' . $theme_data['Version'];
352
	} else {
353
		$theme_data = wp_get_theme();
354
		echo $theme_data->Name . ': ' . $theme_data->Version;
355
	}
356
	?>
357
358
359
	Multi-site:               <?php echo is_multisite() ? 'Yes' . "\n" : 'No' . "\n" ?>
360
361
	ADVANCED INFO:
362
	PHP Version:              <?php echo PHP_VERSION . "\n"; ?>
363
	MySQL Version:            <?php echo $wpdb->db_version() . "\n"; ?>
364
	Web Server Info:          <?php echo $_SERVER['SERVER_SOFTWARE'] . "\n"; ?>
365
366
	PHP Memory Limit:         <?php echo ini_get( 'memory_limit' ) . "\n"; ?>
367
	PHP Post Max Size:        <?php echo ini_get( 'post_max_size' ) . "\n"; ?>
368
	PHP Time Limit:           <?php echo ini_get( 'max_execution_time' ) . "\n"; ?>
369
370
	WP_DEBUG:                 <?php echo defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
371
	SCRIPT_DEBUG:             <?php echo defined( 'SCRIPT_DEBUG' ) ? SCRIPT_DEBUG ? 'Enabled' . "\n" : 'Disabled' . "\n" : 'Not set' . "\n" ?>
372
373
	WP Table Prefix:          <?php echo "Length: ". strlen( $wpdb->prefix ); echo " Status:"; if ( strlen( $wpdb->prefix )>16 ) {echo " ERROR: Too Long";} else {echo " Acceptable";} echo "\n"; ?>
374
375
	Show On Front:            <?php echo get_option( 'show_on_front' ) . "\n" ?>
376
	Page On Front:            <?php $id = get_option( 'page_on_front' ); echo get_the_title( $id ) . ' #' . $id . "\n" ?>
377
	Page For Posts:           <?php $id = get_option( 'page_on_front' ); echo get_the_title( $id ) . ' #' . $id . "\n" ?>
378
379
	Session:                  <?php echo isset( $_SESSION ) ? 'Enabled' : 'Disabled'; ?><?php echo "\n"; ?>
380
	Session Name:             <?php echo esc_html( ini_get( 'session.name' ) ); ?><?php echo "\n"; ?>
381
	Cookie Path:              <?php echo esc_html( ini_get( 'session.cookie_path' ) ); ?><?php echo "\n"; ?>
382
	Save Path:                <?php echo esc_html( ini_get( 'session.save_path' ) ); ?><?php echo "\n"; ?>
383
	Use Cookies:              <?php echo ini_get( 'session.use_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
384
	Use Only Cookies:         <?php echo ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off'; ?><?php echo "\n"; ?>
385
386
	UPLOAD_MAX_FILESIZE:      <?php if ( function_exists( 'phpversion' ) ) echo ini_get( 'upload_max_filesize' ); ?><?php echo "\n"; ?>
387
	POST_MAX_SIZE:            <?php if ( function_exists( 'phpversion' ) ) echo ini_get( 'post_max_size' ); ?><?php echo "\n"; ?>
388
	WordPress Memory Limit:   <?php echo WP_MEMORY_LIMIT; ?><?php echo "\n"; ?>
389
	DISPLAY ERRORS:           <?php echo ( ini_get( 'display_errors' ) ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A'; ?><?php echo "\n"; ?>
390
	FSOCKOPEN:                <?php echo ( function_exists( 'fsockopen' ) ) ? __( 'Your server supports fsockopen.', 'ppp-txt' ) : __( 'Your server does not support fsockopen.', 'ppp-txt' ); ?><?php echo "\n"; ?>
391
		</textarea>
392
	</div>
393
	<?php
394
}
395