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.

admin-pages.php ➔ ppp_display_social()   F
last analyzed

Complexity

Conditions 14
Paths 544

Size

Total Lines 145

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
nc 544
nop 0
dl 0
loc 145
rs 2.1866
c 0
b 0
f 0

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