PluginProbe
Github Embed / 1.3
Github Embed v1.3
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.0.1 2.0.2 2.1.0 2.2.0 2.2.1
← All changes | github-embed.php +43 -46 1.51.3 View file →
@@ -3,9 +3,9 @@
3 3 /*
4 4 Plugin Name: Github Embed
5 5 Plugin URI: http://www.leewillis.co.uk/wordpress-plugins
6 6 Description: Paste the URL to a Github project into your posts or pages, and have the project information pulled in and displayed automatically
7 -Version: 1.5
7 +Version: 1.3
8 8 Author: Lee Willis
9 9 Author URI: http://www.leewillis.co.uk/
10 10 */
11 11
@@ -52,13 +52,13 @@
52 52 public function __construct ( $api ) {
53 53
54 54 $this->api = $api;
55 55
56 - add_action( 'init', array ( $this, 'register_oembed_handler' ) );
57 - add_action( 'init', array( $this, 'maybe_handle_oembed' ) );
58 - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
59 - add_action( 'admin_init', array( $this, 'schedule_expiry' ) );
60 - add_action( 'github_embed_cron', array( $this, 'cron' ) );
56 + add_action ( 'init', array ( $this, 'register_oembed_handler' ) );
57 + add_action ( 'init', array ( $this, 'maybe_handle_oembed' ) );
58 + add_action ( 'wp_enqueue_scripts', array ( $this, 'enqueue_styles' ) );
59 + add_action ( 'admin_init', array ( $this, 'schedule_expiry' ) );
60 + add_action ( 'github_embed_cron', array ( $this, 'cron' ) );
61 61
62 62 // @TODO i18n
63 63
64 64 }
@@ -64,39 +64,39 @@
64 64 }
65 65
66 66
67 67
68 - /**
69 - * Make sure we have a scheduled event set to clear down the oEmbed cache until
70 - * WordPress supports cache_age in oEmbed responses.
71 - */
72 - function schedule_expiry() {
68 + /**
69 + * Make sure we have a scheduled event set to clear down the oEmbed cache until
70 + * WordPress supports cache_age in oEmbed responses.
71 + */
72 + function schedule_expiry() {
73 73
74 - if( ! wp_next_scheduled( 'github_embed_cron' ) ) {
75 - $frequency = apply_filters ( 'github_embed_cache_frequency', 'daily' );
76 - wp_schedule_event( time(), $frequency, 'github_embed_cron' );
77 - }
74 + if( ! wp_next_scheduled( 'github_embed_cron' ) ) {
75 + $frequency = apply_filters ( 'github_embed_cache_frequency', 'daily' );
76 + wp_schedule_event( time(), $frequency, 'github_embed_cron' );
77 + }
78 78
79 - }
79 + }
80 80
81 81
82 82
83 - /**
84 - * Expire old oEmbeds.
85 - * Note: This is a bit sledgehammer-to-crack-a-nut hence why I'm only running it
86 - * daily. Ideally WP should honour cache_age in oEmbed responses properly
87 - */
88 - function cron() {
83 + /**
84 + * Expire old oEmbeds.
85 + * Note: This is a bit sledgehammer-to-crack-a-nut hence why I'm only running it
86 + * daily. Ideally WP should honour cache_age in oEmbed responses properly
87 + */
88 + function cron() {
89 89
90 - global $wpdb, $table_prefix;
90 + global $wpdb, $table_prefix;
91 91
92 - $sql = "DELETE
93 - FROM {$table_prefix}postmeta
94 - WHERE meta_key LIKE '_oembed_%'";
92 + $sql = "DELETE
93 + FROM {$table_prefix}postmeta
94 + WHERE meta_key LIKE '_oembed_%'";
95 95
96 - $results = $wpdb->get_results ( $sql );
96 + $results = $wpdb->get_results ( $sql );
97 97
98 - }
98 + }
99 99
100 100
101 101
102 102 /**
@@ -105,9 +105,9 @@
105 105 */
106 106 function enqueue_styles() {
107 107
108 108 wp_register_style ( 'github-embed', plugins_url(basename(dirname(__FILE__)).'/css/github-embed.css' ) );
109 - wp_enqueue_style ( 'github-embed' );
109 + wp_enqueue_style ( 'github-embed' );
110 110
111 111 }
112 112
113 113
@@ -120,12 +120,12 @@
120 120 * @return array The list, with our new provider added
121 121 */
122 122 public function register_oembed_handler() {
123 123
124 - $oembed_url = home_url();
124 + $oembed_url = home_url ();
125 125 $key = $this->get_key();
126 - $oembed_url = add_query_arg( array( 'github_oembed' => $key ), $oembed_url );
127 - wp_oembed_add_provider( '#https?://github.com/.*#i', $oembed_url, true );
126 + $oembed_url = add_query_arg ( array ( 'github_oembed' => $key ), $oembed_url);
127 + wp_oembed_add_provider ( '#https?://github.com/.*#i', $oembed_url, true );
128 128
129 129 }
130 130
131 131
@@ -171,9 +171,9 @@
171 171 public function handle_oembed() {
172 172
173 173 // Check this request is valid
174 174 if ( $_GET['github_oembed'] != $this->get_key() ) {
175 - header ( 'HTTP/1.0 403 Forbidden' );
175 + header ( 'HTTP/1.0 403 Forbidden' );
176 176 die ( 'Sad Octocat is sad.' );
177 177 }
178 178
179 179 // Check we have the required information
@@ -206,13 +206,8 @@
206 206 if ( $milestone ) {
207 207 $this->oembed_github_repo_milestone_summary ( $matches[1], $matches[2], $milestone );
208 208 }
209 209
210 - // New style milestone URL, e.g. https://github.com/example/example/milestone/1
211 - } elseif ( preg_match ( '#https?://github.com/([^/]*)/([^/]*)/milestone/([0-9]*)$#i', $url, $matches ) ) {
212 -
213 - $this->oembed_github_repo_milestone_summary( $matches[1], $matches[2], $matches[3] );
214 -
215 210 // Repository
216 211 } elseif ( preg_match ( '#https?://github.com/([^/]*)/([^/]*)/?$#i', $url, $matches ) && ! empty ( $matches[2] ) ) {
217 212
218 213 $this->oembed_github_repo ( $matches[1], $matches[2] );
@@ -256,14 +251,18 @@
256 251 $response->html .= '<ul class="github-repo-contributors">';
257 252
258 253 foreach ( $contributors as $contributor ) {
259 254
255 + $details = $this->api->get_user ($contributor->login);
260 256 $response->html .= '<li class="github-repo-contributor">';
261 257 $response->html .= '<img class="github-repo-contributor-avatar" src="';
262 - $response->html .= esc_url(add_query_arg(array('s'=>$gravatar_size), $contributor->author->avatar_url));
263 - $response->html .= '" alt="Picture of '.esc_attr($contributor->author->login).'">';
258 + $response->html .= esc_url(add_query_arg(array('s'=>$gravatar_size), $contributor->avatar_url));
259 + $response->html .= '" alt="Picture of '.esc_attr($contributor->login).'">';
260 + if ( ! empty ( $details->name ) ) {
261 + $response->html .= '<span class="github-repo-contributor-name">'.esc_html($details->name)."</span><br>";
262 + }
264 263 $response->html .= '<span class="github-repo-contributor-login">';
265 - $response->html .= '<a href="https://github.com/'.esc_attr($contributor->author->login).'">'.esc_attr($contributor->author->login).'</a></span>';
264 + $response->html .= '<a href="https://github.com/'.esc_attr($contributor->login).'">'.esc_attr($contributor->login).'</a></span>';
266 265 }
267 266
268 267 $response->html .= '</ul>';
269 268 $response->html .= '<div style="clear: both;"></div>';
@@ -313,9 +312,8 @@
313 312
314 313 $response->html .= '<p class="github-milestone-description">'.nl2br(esc_html($summary->description))."</p><br>";
315 314 $response->html .= '</div>';
316 315
317 - error_log( basename( __FILE__ ) . ': (' . __LINE__ . ') : response is ' . print_r( $response, 1 ) );
318 316 header ( 'Content-Type: application/json' );
319 317 echo json_encode ( $response );
320 318 die();
321 319
@@ -342,11 +340,10 @@
342 340 // @TODO This should all be templated
343 341 $response->html = '<div class="github-embed github-embed-repository">';
344 342 $response->html .= '<p><a href="'.esc_attr($repo->html_url).'" target="_blank"><strong>'.esc_html($repo->description)."</strong></a><br/>";
345 343 $response->html .= '<a href="'.esc_attr($repo->html_url).'" target="_blank">'.esc_html($repo->html_url)."</a><br/>";
346 - $response->html .= '<a href="'.esc_attr($repo->html_url . '/network') . '" target="_blank">'.esc_html ( number_format_i18n ( $repo->forks_count ) ) . "</a> forks.<br/>";
347 - $response->html .= '<a href="'.esc_attr($repo->html_url . '/stargazers') . '" target="_blank">'.esc_html ( number_format_i18n ( $repo->stargazers_count ) ) . "</a> stars.<br/>";
348 - $response->html .= '<a href="'.esc_attr($repo->html_url . '/issues') . '" target="_blank">'.esc_html ( number_format_i18n ( $repo->open_issues_count ) ) . "</a> open issues.<br/>";
344 + $response->html .= esc_html ( number_format_i18n ( $repo->forks_count ) )." forks.<br/>";
345 + $response->html .= esc_html ( number_format_i18n ( $repo->open_issues_count ) )." open issues.<br/>";
349 346
350 347 if ( count ( $commits ) ) {
351 348
352 349 $cnt = 0;
@@ -413,5 +410,5 @@
413 410
414 411 require_once ( 'github-api.php' );
415 412
416 413 $github_api = new github_api();
417 -$github_embed = new github_embed ( $github_api );
414 +$github_embed = new github_embed ( $github_api );