PluginProbe
Github Embed / 1.2
Github Embed v1.2
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 +19 -55 1.31.2 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.3
7 +Version: 1.2
8 8 Author: Lee Willis
9 9 Author URI: http://www.leewillis.co.uk/
10 10 */
11 11
@@ -32,9 +32,9 @@
32 32 */
33 33
34 34 /**
35 35 * This class handles being the oEmbed provider in terms of registering the URLs that
36 - * we can embed, and handling the actual oEmbed calls. It relies on the github_api
36 + * we can embed, and handling the actual oEmbed calls. It relies on the github_api
37 37 * class to retrieve the information from the GitHub API.
38 38 * @uses class github_api
39 39 */
40 40 class github_embed {
@@ -55,11 +55,9 @@
55 55
56 56 add_action ( 'init', array ( $this, 'register_oembed_handler' ) );
57 57 add_action ( 'init', array ( $this, 'maybe_handle_oembed' ) );
58 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 -
59 +
62 60 // @TODO i18n
63 61
64 62 }
65 63
@@ -64,42 +62,8 @@
64 62 }
65 63
66 64
67 65
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 -
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 -
79 - }
80 -
81 -
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() {
89 -
90 - global $wpdb, $table_prefix;
91 -
92 - $sql = "DELETE
93 - FROM {$table_prefix}postmeta
94 - WHERE meta_key LIKE '_oembed_%'";
95 -
96 - $results = $wpdb->get_results ( $sql );
97 -
98 - }
99 -
100 -
101 -
102 66 /**
103 67 * Enqueue the frontend CSS
104 68 * @return void
105 69 */
@@ -106,9 +70,9 @@
106 70 function enqueue_styles() {
107 71
108 72 wp_register_style ( 'github-embed', plugins_url(basename(dirname(__FILE__)).'/css/github-embed.css' ) );
109 73 wp_enqueue_style ( 'github-embed' );
110 -
74 +
111 75 }
112 76
113 77
114 78
@@ -137,9 +101,9 @@
137 101 */
138 102 private function get_key() {
139 103
140 104 $key = get_option ( 'github_oembed_key' );
141 -
105 +
142 106 if ( ! $key ) {
143 107 $key = md5 ( time() . rand ( 0,65535 ) );
144 108 add_option ( 'github_oembed_key', $key, '', 'yes' );
145 109 }
@@ -244,13 +208,13 @@
244 208
245 209 // @TODO This should all be templated
246 210 $response->html = '<div class="github-embed github-embed-repo-contributors">';
247 211 $response->html .= '<p><a href="'.esc_attr($repo->html_url).'" target="_blank"><strong>'.esc_html($repo->description)."</strong></a><br/>";
248 -
212 +
249 213 $response->html .= '<span class="github-heading">Contributors: </span>';
250 214
251 215 $response->html .= '<ul class="github-repo-contributors">';
252 -
216 +
253 217 foreach ( $contributors as $contributor ) {
254 218
255 219 $details = $this->api->get_user ($contributor->login);
256 220 $response->html .= '<li class="github-repo-contributor">';
@@ -294,23 +258,23 @@
294 258
295 259 // @TODO This should all be templated
296 260 $response->html = '<div class="github-embed github-embed-milestone-summary">';
297 261 $response->html .= '<p><a href="'.esc_attr($repo->html_url).'" target="_blank"><strong>'.esc_html($repo->description)."</strong></a><br/>";
298 -
262 +
299 263 $response->html .= '<span class="github-heading">Milestone: </span>';
300 264 $response->html .= '<span class="github-milestone-title">'.esc_html($summary->title)."</span><br>";
301 -
265 +
302 266 $response->html .= '<span class="github-heading">Issues: </span>';
303 267 $response->html .= '<span class="github-milestone-issues">';
304 - $response->html .= esc_html ( number_format_i18n ( $summary->open_issues ) )." open, ";
305 - $response->html .= esc_html ( number_format_i18n ( $summary->closed_issues ) )." closed.</span><br>";
306 -
268 + $response->html .= esc_html($summary->open_issues)." open, ";
269 + $response->html .= esc_html($summary->closed_issues)." closed.</span><br>";
270 +
307 271 if ( ! empty ( $summary->due_on ) ) {
308 272 $response->html .= '<span class="github-heading">Due: </span>';
309 273 $due_date = date_format ( date_create ( $summary->due_on ), 'jS F Y' );
310 274 $response->html .= '<span class="github-milestone-due-date">'.esc_html($due_date).'</span><br>';
311 275 }
312 -
276 +
313 277 $response->html .= '<p class="github-milestone-description">'.nl2br(esc_html($summary->description))."</p><br>";
314 278 $response->html .= '</div>';
315 279
316 280 header ( 'Content-Type: application/json' );
@@ -316,9 +280,9 @@
316 280 header ( 'Content-Type: application/json' );
317 281 echo json_encode ( $response );
318 282 die();
319 283
320 - }
284 + }
321 285
322 286
323 287
324 288 /**
@@ -340,10 +304,10 @@
340 304 // @TODO This should all be templated
341 305 $response->html = '<div class="github-embed github-embed-repository">';
342 306 $response->html .= '<p><a href="'.esc_attr($repo->html_url).'" target="_blank"><strong>'.esc_html($repo->description)."</strong></a><br/>";
343 307 $response->html .= '<a href="'.esc_attr($repo->html_url).'" target="_blank">'.esc_html($repo->html_url)."</a><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/>";
308 + $response->html .= esc_html($repo->forks_count)." forks.<br/>";
309 + $response->html .= esc_html($repo->open_issues_count)." open issues.<br/>";
346 310
347 311 if ( count ( $commits ) ) {
348 312
349 313 $cnt = 0;
@@ -358,9 +322,9 @@
358 322 $response->html .= '<li class="github_commit">';
359 323 $response->html .= '<a href="https://github.com/'.$owner.'/'.$repository.'/commit/'.esc_attr($commit->sha).'" target="_blank">'.esc_html($commit->commit->message)."</a>, ";
360 324 $response->html .= esc_html($commit->commit->committer->name);
361 325 $response->html .= '</li>';
362 -
326 +
363 327 $cnt++;
364 328
365 329 }
366 330
@@ -395,10 +359,10 @@
395 359
396 360 // @TODO This should all be templated
397 361 $response->html = '<div class="github-embed github-embed-user">';
398 362 $response->html .= '<p><a href="https://github.com/'.esc_attr($owner).'" target="_blank"><strong>'.esc_html($owner)."</strong></a><br/>";
399 - $response->html .= esc_html ( number_format_i18n ( $owner_info->public_repos ) ).' repositories, ';
400 - $response->html .= esc_html ( number_format_i18n ( $owner_info->followers ) ).' followers.</p>';
363 + $response->html .= esc_html($owner_info->public_repos).' repositories, ';
364 + $response->html .= esc_html($owner_info->followers).' followers.</p>';
401 365 $response->html .= '</div>';
402 366
403 367 header ( 'Content-Type: application/json' );
404 368 echo json_encode ( $response );