Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #26 from abahlo/master

Add GitHub Plugin
  • Loading branch information...
commit 7e91f41fbe1bbf474b61a6f3db7c8ad2ca0a29d3 2 parents a47cc6a + 6c6a41e
@bastianallgeier authored
View
39 plugins/github/README.md
@@ -0,0 +1,39 @@
+GitHub Plugin for Kirby
+=======================
+
+With that plugin you can implement a users GitHub information or list your repos easily in Kirby.
+
+Usage example for repos:
+========================
+```php
+<?php
+$github = new github('abahlo', 10);
+
+foreach($github->repos() as $repo):
+?>
+ <li>
+ <h1><a href="<?php echo $repo->url ?>"><?php echo $repo->name ?></a></h1>
+ <p><?php echo $repo->description ?></p>
+ </li>
+<?php endforeach ?>
+```
+
+Attributes for repo()
+=====================
+- `$repo->name` the name of the repository
+- `$repo->description` the description
+- `$repo->url` the url to the repository
+- `$repo->last_update` the timestamp to the last update
+- `$repo->forkcount` the number of forks
+- `$repo->watchers` the number of watchers
+
+Attributes for user()
+=====================
+- `$user->username` the GitHub username
+- `$user->name` the real name
+- `$user->email` the email, if given
+- `$user->followers` the count of followers
+- `$user->following` the count of following
+- `$user->url` the GitHub-url
+- `$user->gravatar_id` the gravatar-id
+- `$user->repos_url` the url to the repos
View
5 plugins/github/changelog.md
@@ -0,0 +1,5 @@
+# Changelog
+
+## v1.0
+
+* Initial release
View
81 plugins/github/github.php
@@ -0,0 +1,81 @@
+<?php
+/*
+ * With that plugin you can implement your GitHub information or list your repos easily in Kirby.
+ * Copyright (c) 2012 by Arne Bahlo
+ *
+ */
+class github {
+ // Constructor
+ function __construct($username = null, $count = 0) {
+ if(is_null($username)) return false;
+ $this->username = $username;
+ $this->count = $count;
+ }
+
+ // Get repos and sort them
+ public function repos($sorted = false) {
+ if($this->count <= 0) return false;
+ $url = 'https://api.github.com/users/' . $this->username . '/repos';
+ $data = $this->get_data($url);
+
+ $this->repos = array();
+
+ foreach ($data as $key => $obj) {
+ if($key >= $this->count) break;
+
+ $this->repos[$key] = new stdClass;
+
+ $this->repos[$key]->name = $obj->name;
+ $this->repos[$key]->description = $obj->description;
+ $this->repos[$key]->url = $obj->html_url;
+ $this->repos[$key]->last_update = strtotime($obj->updated_at);
+ $this->repos[$key]->forkount = $obj->forks_count;
+ $this->repos[$key]->watchers = $obj->watchers_count;
+ }
+
+ if($sorted) {
+ function cmp($a, $b) {
+ if ($b->last_update == $a->last_update) return 0;
+ return ($b->last_update < $a->last_update) ? -1 : 1;
+ }
+ usort($this->repos, 'cmp');
+ }
+
+ return $this->repos;
+ }
+
+ // Get user
+ public function user() {
+ $url = 'https://api.github.com/users/' . $this->username;
+ $data = $this->get_data($url);
+
+ $this->user = new stdClass;
+
+ $this->user->username = $data->login;
+ $this->user->name = $data->name;
+ $this->user->email = $data->email;
+ $this->user->followers = $data->followers;
+ $this->user->following = $data->following;
+ $this->user->url = 'https://github.com/' . $data->login;
+ $this->user->gravatar_id = $data->gravatar_id;
+ $this->user->repos_url = $data->repos_url;
+
+ return $this->user;
+ }
+
+ // Fetch data
+ protected function get_data($url) {
+ if($url == '') return false;
+ $handler = curl_init();
+
+ curl_setopt($handler, CURLOPT_URL, $url);
+ curl_setopt($handler, CURLOPT_RETURNTRANSFER, 1);
+
+ $data = curl_exec($handler);
+ curl_close($handler);
+
+ return json_decode($data);
+ }
+}
+
+?>
View
9 plugins/github/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "github",
+ "readable": "GitHub",
+ "version": "1.0",
+ "stable": true,
+ "description": "Fetch GitHub user or repo",
+ "author": "Arne Bahlo",
+ "url": "http://arne.me"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.