Browse Source

Whitespace

widget
Lee Willis 6 years ago
parent
commit
30bc2000e3
  1. 2
      github-api.php
  2. 23
      github-embed.php

2
github-api.php

@ -1,7 +1,5 @@
<?php <?php
// 0 - none. // 0 - none.
define( 'GEDEBUG_NONE', 0 ); define( 'GEDEBUG_NONE', 0 );

23
github-embed.php

@ -36,13 +36,13 @@ Author URI: http://www.leewillis.co.uk/
* class to retrieve the information from the GitHub API. * class to retrieve the information from the GitHub API.
* @uses class github_api * @uses class github_api
*/ */
class github_embed { class github_embed {
private $api; private $api;
/** /**
* Constructor. Registers hooks and filters * Constructor. Registers hooks and filters
*
* @param class $api An instance of the github_api classs * @param class $api An instance of the github_api classs
*/ */
public function __construct( $api ) { public function __construct( $api ) {
@ -92,7 +92,9 @@ class github_embed {
* Register the oEmbed provider, and point it at a local endpoint since github * Register the oEmbed provider, and point it at a local endpoint since github
* doesn't directly support oEmbed yet. Our local endpoint will use the github * doesn't directly support oEmbed yet. Our local endpoint will use the github
* API to fulfil the request. * API to fulfil the request.
*
* @param array $providers The current list of providers * @param array $providers The current list of providers
*
* @return array The list, with our new provider added * @return array The list, with our new provider added
*/ */
public function register_oembed_handler() { public function register_oembed_handler() {
@ -113,6 +115,7 @@ class github_embed {
$key = md5( time() . rand( 0, 65535 ) ); $key = md5( time() . rand( 0, 65535 ) );
add_option( 'github_oembed_key', $key, '', 'yes' ); add_option( 'github_oembed_key', $key, '', 'yes' );
} }
return $key; return $key;
} }
@ -188,11 +191,13 @@ class github_embed {
if ( ! locate_template( 'wp-github-oembed/' . $template, true ) ) { if ( ! locate_template( 'wp-github-oembed/' . $template, true ) ) {
require_once 'templates/' . $template; require_once 'templates/' . $template;
} }
return ob_get_clean(); return ob_get_clean();
} }
/** /**
* Retrieve a list of contributors for a project * Retrieve a list of contributors for a project
*
* @param string $owner The owner of the repository * @param string $owner The owner of the repository
* @param string $repository The repository name * @param string $repository The repository name
*/ */
@ -210,7 +215,7 @@ class github_embed {
$response->version = '1.0'; $response->version = '1.0';
$response->title = $data['repo']->description; $response->title = $data['repo']->description;
$response->html = $this->process_template( $response->html = $this->process_template(
'repository_contributors.php', $data); 'repository_contributors.php', $data );
header( 'Content-Type: application/json' ); header( 'Content-Type: application/json' );
echo json_encode( $response ); echo json_encode( $response );
@ -234,7 +239,7 @@ class github_embed {
$response->version = '1.0'; $response->version = '1.0';
$response->title = $data['repo']->description; $response->title = $data['repo']->description;
$response->html = $this->process_template( $response->html = $this->process_template(
'repository_milestone_summary.php', $data); 'repository_milestone_summary.php', $data );
header( 'Content-Type: application/json' ); header( 'Content-Type: application/json' );
echo json_encode( $response ); echo json_encode( $response );
@ -246,10 +251,10 @@ class github_embed {
* Retrieve the information from github for a repo, and * Retrieve the information from github for a repo, and
* output it as an oembed response * output it as an oembed response
*/ */
private function oembed_github_repo ( $owner, $repository ) { private function oembed_github_repo( $owner, $repository ) {
$data = [ $data = [
$owner, 'owner_slug' => $owner,
$repository, 'repo_slug' => $repository,
]; ];
$data['repo'] = $this->api->get_repo( $owner, $repository ); $data['repo'] = $this->api->get_repo( $owner, $repository );
$data['commits'] = $this->api->get_repo_commits( $owner, $repository ); $data['commits'] = $this->api->get_repo_commits( $owner, $repository );
@ -262,7 +267,7 @@ class github_embed {
$response->version = '1.0'; $response->version = '1.0';
$response->title = $data['repo']->description; $response->title = $data['repo']->description;
$response->html = $this->process_template( $response->html = $this->process_template(
'repository.php', $data); 'repository.php', $data );
header( 'Content-Type: application/json' ); header( 'Content-Type: application/json' );
@ -274,7 +279,7 @@ class github_embed {
* Retrieve the information from github for an author, and output * Retrieve the information from github for an author, and output
* it as an oembed response * it as an oembed response
*/ */
private function oembed_github_author ( $owner ) { private function oembed_github_author( $owner ) {
$data = []; $data = [];
$data["owner"] = $owner; $data["owner"] = $owner;
$data["owner_info"] = $this->api->get_user( $owner ); $data["owner_info"] = $this->api->get_user( $owner );
@ -288,7 +293,7 @@ class github_embed {
$response->version = '1.0'; $response->version = '1.0';
$response->title = $data['owner_info']->name; $response->title = $data['owner_info']->name;
$response->html = $this->process_template( $response->html = $this->process_template(
'author.php', $data); 'author.php', $data );
header( 'Content-Type: application/json' ); header( 'Content-Type: application/json' );
echo json_encode( $response ); echo json_encode( $response );

Loading…
Cancel
Save