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 ( a6186c...4efb95 )
by Chris
9s
created

PPP_Dashboard_Shares   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 141
rs 10
wmc 16
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 12 2
C widget() 0 76 8
A config() 0 11 2
A get_count() 0 7 4
1
<?php
2
/**
3
 * Add a widget to the dashboard.
4
 *
5
 * @since  2.2.3
6
 */
7
class PPP_Dashboard_Shares {
8
9
	/**
10
	 * The ID of this widget.
11
	 */
12
	const wid = 'ppp_dashboard_shares';
13
14
	/**
15
	 * Hook to wp_dashboard_setup to add the widget.
16
	 *
17
	 * @since  2.2.3
18
	 */
19
	public static function init() {
20
		if ( ! current_user_can( 'manage_options' ) ) {
21
			return;
22
		}
23
24
		wp_add_dashboard_widget(
25
			self::wid,
26
			__( 'Upcoming Shares', 'ppp-tweets' ),
27
			array( 'PPP_Dashboard_Shares', 'widget' ),
28
			array( 'PPP_Dashboard_Shares', 'config' )
29
		);
30
	}
31
32
	/**
33
	 * Load the widget code
34
	 *
35
	 * @since  2.2.3
36
	 */
37
	public static function widget() {
38
		$number = self::get_count();
39
		$shares = ppp_get_shceduled_crons();
40
41
		if ( ! empty( $shares ) ) {
42
			$limited_shares = array_slice( $shares, 0, $number, true );
43
			?>
44
			<div id="future-tweets" class="activity-block">
45
				<h4><?php _e( 'Post-Related shares', 'ppp-tweets' ); ?></h4>
46
				<ul>
47
				<?php
48
				foreach ( $limited_shares as $key => $share ) {
49
					$ppp_data = $share;
50
					$timestamp = $ppp_data['timestamp'];
51
52
					$name_parts = explode( '_', $ppp_data['args'][1] );
53
					$service    = isset( $name_parts[3] ) ? $name_parts[3] : 'tw';
54
					$builder    = 'ppp_' . $service . '_build_share_message';
55
56
					$post_id    = $ppp_data['args'][0];
57
					$date       = $timestamp + ( get_option( 'gmt_offset' ) * 3600 );
58
					$content    = '';
59
					if ( function_exists( $builder ) ) {
60
						$content    = $builder( $ppp_data['args'][0], $ppp_data['args'][1], false );
61
					}
62
63
					$regex   = "@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@";
64
					$content = preg_replace( $regex, '', $content );
65
					?>
66
					<li>
67
						<span class="meta"><i class="dashicons icon-ppp-<?php echo $service; ?>"></i>&nbsp;<?php echo date_i18n( 'M jS, ' . get_option( 'time_format' ), $date ); ?></span>
68
						<a href="<?php echo admin_url( 'post.php?post=' . $post_id . '&action=edit' ); ?>"><?php echo $content; ?></a>
69
					</li>
70
				<?php } ?>
71
				</ul>
72
				<p>
73
					<a class="button-primary" href="<?php echo admin_url( 'admin.php?page=ppp-schedule-info' ); ?>"><?php _e( 'View Full Schedule', 'ppp-txt' ); ?></a>
74
				</p>
75
			</div>
76
			<?php
77
		} else {
78
			$args = array(
79
				'numberposts' => 1,
80
				'orderby'     => 'post_date',
81
				'order'       => 'DESC',
82
				'post_type'   => ppp_allowed_post_types(),
83
				'post_status' => array( 'draft', 'publish', 'future' ),
84
			);
85
86
			$recent_posts   = wp_get_recent_posts( $args, ARRAY_A );
87
			$recent_post    = $recent_posts[0];
88
			$post_type      = get_post_type_object( $recent_post['post_type'] );
89
			$post_type_name = $post_type->labels->singular_name;
90
			$edit_url       = admin_url( 'post.php?post=' . $recent_post['ID'] . '&action=edit' );
91
92
			switch( $recent_post['post_status'] ) {
93
				case 'draft':
94
					$relative_time = __( '<a href="%s">Configure them</a> for your draft ' . $post_type_name, 'ppp-txt' );
95
					break;
96
				case 'future':
97
					$relative_time = __( '<a href="%s">Schedule one</a> for your upcoming ' . $post_type_name, 'ppp-txt' );
98
					break;
99
				case 'publish':
100
				default:
101
					$relative_time = __( '<a href="%s">Schedule one</a> for your most recent ' . $post_type_name, 'ppp-txt' );
102
					break;
103
104
			}
105
			?><span><em>
106
				<?php _e( 'No scheduled shares at this time.', 'ppp-txt' ); ?>
107
				<?php printf( $relative_time, $edit_url ); ?>
108
			</em></span><?php
109
		}
110
111
		do_action( 'ppp_dashboard_shares' );
112
	}
113
114
	/**
115
	 * Load widget config code.
116
	 *
117
	 * This is what will display when an admin clicks
118
	 *
119
	 * @since  2.2.3
120
	 */
121
	public static function config() {
122
		if ( ! empty( $_POST['number_of_tweets'] ) ) {
123
			update_option( 'ppp_dashboard_twitter_count', absint( $_POST['number_of_tweets'] ) );
124
		}
125
126
		$number = self::get_count();
127
		?>
128
		<p><input type="number" size="3" min="1" max="99" step="1" value="<?php echo $number; ?>" id="ppp-number-of-tweets" name="number_of_tweets" />&nbsp;<label for="ppp-number-of-tweets"><?php _e( 'Number of Tweets to Show.', 'ppp-txt' ); ?></label></p>
129
	<?php
130
131
	}
132
133
	/**
134
	 * Gets the count of tweets to show
135
	 *
136
	 * @since  2.2.3
137
	 * @return int The Number of tweets to show
138
	 */
139
	private static function get_count() {
140
		$stored_count = get_option( 'ppp_dashboard_shares_count' );
141
142
		$stored_count = empty( $stored_count ) || ! is_numeric( $stored_count ) ? 5 : absint( $stored_count );
143
144
		return ! empty( $stored_count ) ? $stored_count : 5;
145
	}
146
147
}
148
add_action('wp_dashboard_setup', array('PPP_Dashboard_Shares','init') );
149