Skip to content
Browse files

added github plugin

  • Loading branch information...
1 parent a47cc6a commit 901bbd89b84e1322d35cc8fa431230c7824a9009 @bahlo bahlo committed Dec 17, 2012
Showing with 134 additions and 0 deletions.
  1. +39 −0 plugins/github/README.md
  2. +5 −0 plugins/github/changelog.md
  3. +81 −0 plugins/github/github.php
  4. +9 −0 plugins/github/package.json
View
39 plugins/github/README.md
@@ -0,0 +1,39 @@
+GitHub Plugin for Kirby
+=======================
+
+With that plugin you can implement your 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"
+}

0 comments on commit 901bbd8

Please sign in to comment.
Something went wrong with that request. Please try again.