| @@ -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.4 | |
| 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,21 +208,25 @@ | ||
| 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 | |
| 219 | + $details = $this->api->get_user ($contributor->login); | |
| 255 | 220 | $response->html .= '<li class="github-repo-contributor">'; |
| 256 | 221 | $response->html .= '<img class="github-repo-contributor-avatar" src="'; |
| 257 | - $response->html .= esc_url(add_query_arg(array('s'=>$gravatar_size), $contributor->author->avatar_url)); | |
| 258 | - $response->html .= '" alt="Picture of '.esc_attr($contributor->author->login).'">'; | |
| 222 | + $response->html .= esc_url(add_query_arg(array('s'=>$gravatar_size), $contributor->avatar_url)); | |
| 223 | + $response->html .= '" alt="Picture of '.esc_attr($contributor->login).'">'; | |
| 224 | + if ( ! empty ( $details->name ) ) { | |
| 225 | + $response->html .= '<span class="github-repo-contributor-name">'.esc_html($details->name)."</span><br>"; | |
| 226 | + } | |
| 259 | 227 | $response->html .= '<span class="github-repo-contributor-login">'; |
| 260 | - $response->html .= '<a href="https://github.com/'.esc_attr($contributor->author->login).'">'.esc_attr($contributor->author->login).'</a></span>'; | |
| 228 | + $response->html .= '<a href="https://github.com/'.esc_attr($contributor->login).'">'.esc_attr($contributor->login).'</a></span>'; | |
| 261 | 229 | } |
| 262 | 230 | |
| 263 | 231 | $response->html .= '</ul>'; |
| 264 | 232 | $response->html .= '<div style="clear: both;"></div>'; |
| @@ -290,23 +258,23 @@ | ||
| 290 | 258 | |
| 291 | 259 | // @TODO This should all be templated |
| 292 | 260 | $response->html = '<div class="github-embed github-embed-milestone-summary">'; |
| 293 | 261 | $response->html .= '<p><a href="'.esc_attr($repo->html_url).'" target="_blank"><strong>'.esc_html($repo->description)."</strong></a><br/>"; |
| 294 | - | |
| 262 | + | |
| 295 | 263 | $response->html .= '<span class="github-heading">Milestone: </span>'; |
| 296 | 264 | $response->html .= '<span class="github-milestone-title">'.esc_html($summary->title)."</span><br>"; |
| 297 | - | |
| 265 | + | |
| 298 | 266 | $response->html .= '<span class="github-heading">Issues: </span>'; |
| 299 | 267 | $response->html .= '<span class="github-milestone-issues">'; |
| 300 | - $response->html .= esc_html ( number_format_i18n ( $summary->open_issues ) )." open, "; | |
| 301 | - $response->html .= esc_html ( number_format_i18n ( $summary->closed_issues ) )." closed.</span><br>"; | |
| 302 | - | |
| 268 | + $response->html .= esc_html($summary->open_issues)." open, "; | |
| 269 | + $response->html .= esc_html($summary->closed_issues)." closed.</span><br>"; | |
| 270 | + | |
| 303 | 271 | if ( ! empty ( $summary->due_on ) ) { |
| 304 | 272 | $response->html .= '<span class="github-heading">Due: </span>'; |
| 305 | 273 | $due_date = date_format ( date_create ( $summary->due_on ), 'jS F Y' ); |
| 306 | 274 | $response->html .= '<span class="github-milestone-due-date">'.esc_html($due_date).'</span><br>'; |
| 307 | 275 | } |
| 308 | - | |
| 276 | + | |
| 309 | 277 | $response->html .= '<p class="github-milestone-description">'.nl2br(esc_html($summary->description))."</p><br>"; |
| 310 | 278 | $response->html .= '</div>'; |
| 311 | 279 | |
| 312 | 280 | header ( 'Content-Type: application/json' ); |
| @@ -312,9 +280,9 @@ | ||
| 312 | 280 | header ( 'Content-Type: application/json' ); |
| 313 | 281 | echo json_encode ( $response ); |
| 314 | 282 | die(); |
| 315 | 283 | |
| 316 | - } | |
| 284 | + } | |
| 317 | 285 | |
| 318 | 286 | |
| 319 | 287 | |
| 320 | 288 | /** |
| @@ -336,10 +304,10 @@ | ||
| 336 | 304 | // @TODO This should all be templated |
| 337 | 305 | $response->html = '<div class="github-embed github-embed-repository">'; |
| 338 | 306 | $response->html .= '<p><a href="'.esc_attr($repo->html_url).'" target="_blank"><strong>'.esc_html($repo->description)."</strong></a><br/>"; |
| 339 | 307 | $response->html .= '<a href="'.esc_attr($repo->html_url).'" target="_blank">'.esc_html($repo->html_url)."</a><br/>"; |
| 340 | - $response->html .= esc_html ( number_format_i18n ( $repo->forks_count ) )." forks.<br/>"; | |
| 341 | - $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/>"; | |
| 342 | 310 | |
| 343 | 311 | if ( count ( $commits ) ) { |
| 344 | 312 | |
| 345 | 313 | $cnt = 0; |
| @@ -354,9 +322,9 @@ | ||
| 354 | 322 | $response->html .= '<li class="github_commit">'; |
| 355 | 323 | $response->html .= '<a href="https://github.com/'.$owner.'/'.$repository.'/commit/'.esc_attr($commit->sha).'" target="_blank">'.esc_html($commit->commit->message)."</a>, "; |
| 356 | 324 | $response->html .= esc_html($commit->commit->committer->name); |
| 357 | 325 | $response->html .= '</li>'; |
| 358 | - | |
| 326 | + | |
| 359 | 327 | $cnt++; |
| 360 | 328 | |
| 361 | 329 | } |
| 362 | 330 | |
| @@ -391,10 +359,10 @@ | ||
| 391 | 359 | |
| 392 | 360 | // @TODO This should all be templated |
| 393 | 361 | $response->html = '<div class="github-embed github-embed-user">'; |
| 394 | 362 | $response->html .= '<p><a href="https://github.com/'.esc_attr($owner).'" target="_blank"><strong>'.esc_html($owner)."</strong></a><br/>"; |
| 395 | - $response->html .= esc_html ( number_format_i18n ( $owner_info->public_repos ) ).' repositories, '; | |
| 396 | - $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>'; | |
| 397 | 365 | $response->html .= '</div>'; |
| 398 | 366 | |
| 399 | 367 | header ( 'Content-Type: application/json' ); |
| 400 | 368 | echo json_encode ( $response ); |