From 530b9de71851e5a23b63d322a6454d96e7aeb2ca Mon Sep 17 00:00:00 2001 From: Corne Oppelaar Date: Sun, 19 Jun 2016 19:48:25 +0200 Subject: [PATCH 1/2] show contributors and add GitHub and Stash service --- composer.json | 3 +- composer.lock | 110 +++++++++++++++++++++++++++++++++++++++- config/app.yml | 9 ++-- public/css/main.css | 19 +++++-- public/css/main.css.map | 2 +- public/css/main.scss | 22 ++++++-- public/index.php | 2 +- public/js/home.js | 17 +++++++ public/js/zerooo.js | 81 +++++++++++++++++++++++++++++ src/Core.php | 1 - src/Handler/Home.php | 23 ++++++++- src/Service/GitHub.php | 85 +++++++++++++++++++++++++++++++ src/Service/Stash.php | 15 ++++++ views/home.html.twig | 16 +++++- 14 files changed, 385 insertions(+), 20 deletions(-) create mode 100644 public/js/home.js create mode 100644 public/js/zerooo.js create mode 100644 src/Service/GitHub.php create mode 100644 src/Service/Stash.php diff --git a/composer.json b/composer.json index 05dded1..0b8f86d 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "hassankhan/config": "0.10.0", "monolog/monolog": "1.18.1", "aura/session": "2.0.1", - "guzzlehttp/guzzle": "^6.2" + "guzzlehttp/guzzle": "^6.2", + "tedivm/stash": "^0.14.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index d72b704..df8bd21 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "95b6dc2302dd6086dbc2b7248a1f5768", - "content-hash": "61847eefe53610226629206b81b6f8b5", + "hash": "7f7a5098d89b4841741255592bee1890", + "content-hash": "045408fd26a025036d65a2e00bb8a369", "packages": [ { "name": "aura/session", @@ -558,6 +558,52 @@ ], "time": "2015-06-27 11:58:48" }, + { + "name": "psr/cache", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "9e66031f41fbbdda45ee11e93c45d480ccba3eb3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/9e66031f41fbbdda45ee11e93c45d480ccba3eb3", + "reference": "9e66031f41fbbdda45ee11e93c45d480ccba3eb3", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "time": "2015-12-11 02:52:07" + }, { "name": "psr/http-message", "version": "1.0", @@ -1167,6 +1213,66 @@ "homepage": "https://symfony.com", "time": "2016-03-04 07:54:35" }, + { + "name": "tedivm/stash", + "version": "v0.14.1", + "source": { + "type": "git", + "url": "https://github.com/tedious/Stash.git", + "reference": "bcb739b08b22571e35589ebe5403af9b89a33394" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tedious/Stash/zipball/bcb739b08b22571e35589ebe5403af9b89a33394", + "reference": "bcb739b08b22571e35589ebe5403af9b89a33394", + "shasum": "" + }, + "require": { + "php": "^5.4|^7.0", + "psr/cache": "~1.0" + }, + "provide": { + "psr/cache-implementation": "1.0.0" + }, + "require-dev": { + "fabpot/php-cs-fixer": "^1.9", + "phpunit/phpunit": "4.8.*", + "satooshi/php-coveralls": "1.0.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Stash\\": "src/Stash/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Robert Hafner", + "email": "tedivm@tedivm.com" + }, + { + "name": "Josh Hall-Bachner", + "email": "charlequin@gmail.com" + } + ], + "description": "The place to keep your cache.", + "homepage": "http://github.com/tedious/Stash", + "keywords": [ + "apc", + "cache", + "caching", + "memcached", + "psr-6", + "psr6", + "redis", + "sessions" + ], + "time": "2016-02-10 22:23:16" + }, { "name": "twig/twig", "version": "v1.24.0", diff --git a/config/app.yml b/config/app.yml index 59fe567..47490a7 100644 --- a/config/app.yml +++ b/config/app.yml @@ -3,9 +3,10 @@ core: level: debug debug: true container: - name: "Glim" - author: "Corné Oppelaar " + name: "Zer.ooo" + author: "EaterOfCode" sessionName: '0sess' + github-repo: 'EaterOfCode/zer.ooo' services: slim: Eater\Glim\Service\Slim user: Eater\Glim\Service\User @@ -13,4 +14,6 @@ core: twig: Eater\Glim\Service\Twig twig-vars: Eater\Glim\Service\TwigVars ca: Eater\Glim\Service\CA - server: Eater\Glim\Service\Server \ No newline at end of file + server: Eater\Glim\Service\Server + stash: Eater\Glim\Service\Stash + github: Eater\Glim\Service\GitHub \ No newline at end of file diff --git a/public/css/main.css b/public/css/main.css index e0fc744..2613ca2 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -151,18 +151,27 @@ body { display: flex; flex-direction: column; justify-content: center; - align-items: center; - height: 20vh; } + align-items: center; } .footer-page a { color: black; } -.footer-page h1 { +.footer-page-title, .footer-page h1, .footer-page h2 { font-family: 'Inconsolata'; - font-size: 1.5em; color: #E08E79; letter-spacing: 3pt; - font-weight: lighter; } + font-weight: lighter; + text-transform: lowercase; } + +.footer-page h1 { + font-size: 1.5em; } + +.footer-page h2 { + font-size: 1.2em; + font-weight: bold; } + +.footer-page h2 a { + margin-right: -3pt; } .login-page { background: linear-gradient(#070a15, #252b46); diff --git a/public/css/main.css.map b/public/css/main.css.map index 8b471c6..7818bb2 100644 --- a/public/css/main.css.map +++ b/public/css/main.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": "AAAQ,0BAAe;AACf,yBAAc;AAGd,uBAAY;AAGZ,6IAAqI;AACrI,6GAAqG;ACR7G,SAAS;EACP,eAAe,EAAE,IAAI;EACrB,MAAM,EAAE,CAAC;EACT,OAAO,EAAE,CAAC;EACV,QAAQ,EAAE,MAAM;;AAElB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ACzB,OAAO,EAAE,IAAI;EACb,cAAc,EAAE,MAAM;EACtB,eAAe,EAAE,MAAM;EACvB,WAAW,EAAE,MAAM;;AAGrB,cAAe;EACb,KAAK,EAAE,KAAK;;AAKd,oDAAmB;EACjB,WAAW,EAAE,aAAa;EAC1B,KAAK,EAAE,OAAO;EACd,cAAc,EAAE,GAAG;EACnB,WAAW,EAAE,OAAO;EACpB,cAAc,EAAE,SAAS;;AAG3B,eAAgB;EAEd,SAAS,EAAE,KAAK;;AAGlB,eAAgB;EAEd,SAAS,EAAE,KAAK;EAChB,WAAW,EAAE,IAAI;;AAGnB,iBAAkB;EAChB,YAAY,EAAE,IAAI;;AAIpB,WAAY;EACV,UAAU,EAAE,iCAAiC;EAAE,qBAAqB;EACpE,OAAO,EAAE,IAAI;EACb,eAAe,EAAE,MAAM;EAAE,sBAAsB;EAC/C,WAAW,EAAE,MAAM;EAAE,oBAAoB;EACzC,cAAc,EAAE,MAAM;EACtB,OAAO,EAAE,IAAI;;AAGf,gBAAiB;EACf,WAAW,EAAE,mBAAmB;EAChC,SAAS,EAAE,GAAG;EACd,WAAW,EAAE,KAAK;EAClB,cAAc,EAAE,SAAS;EACzB,KAAK,EAAE,OAAO;EA3Id,WAAW,EAFC,uOAAmD;;AAgJjE,gBAAiB;EACf,gBAAgB,EAAE,IAAI;EACtB,OAAO,EAAE,KAAK;EACd,UAAU,EAAE,UAAU;EACtB,aAAa,EAAE,GAAG;EAClB,UAAU,EAAE,CAAC;EACb,aAAa,EAAE,iBAAiB;EAChC,YAAY,EAAE,iBAAiB;EAC/B,WAAW,EAAE,CAAC;;AAGhB,WAAY;EACV,UAAU,EAAE,iCAAiC;EAAE,qBAAqB;EACpE,OAAO,EAAE,IAAI;EACb,cAAc,EAAE,MAAM;EACtB,eAAe,EAAE,MAAM;EACvB,WAAW,EAAE,MAAM", "sources": ["main.scss","navigation.sass","forms.sass"], "names": [], "file": "main.css" diff --git a/public/css/main.scss b/public/css/main.scss index 9e28d8f..f99bb8b 100644 --- a/public/css/main.scss +++ b/public/css/main.scss @@ -109,19 +109,35 @@ body { flex-direction: column; justify-content: center; align-items: center; - height: 20vh; } .footer-page a { color: black } -.footer-page h1 { + + +.footer-page-title { font-family: 'Inconsolata'; - font-size: 1.5em; color: #E08E79; letter-spacing: 3pt; font-weight: lighter; + text-transform: lowercase; +} + +.footer-page h1 { + @extend .footer-page-title; + font-size: 1.5em; +} + +.footer-page h2 { + @extend .footer-page-title; + font-size: 1.2em; + font-weight: bold; +} + +.footer-page h2 a { + margin-right: -3pt; } // login page diff --git a/public/index.php b/public/index.php index 628e66e..64c5a22 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,6 @@ ' + contributor.login + ''; + })); + + Zerooo.select('#contributors').innerHTML = html; + Zerooo.select('#contributors-container').style.display = 'block'; + }); +}); \ No newline at end of file diff --git a/public/js/zerooo.js b/public/js/zerooo.js new file mode 100644 index 0000000..f57c5e2 --- /dev/null +++ b/public/js/zerooo.js @@ -0,0 +1,81 @@ +Zerooo = {}; + +Zerooo.getJSON = function (url, callback) { + var x = new XMLHttpRequest(); + var callbackSent = false; + + x.open("GET", url, true); + x.onerror = function (message, source, lineno, colno, error) { + if (!callbackSent) { + sendCallback(error); + } + }; + + x.onreadystatechange = function () { + if (x.readyState != 4) return; + + if (x.status !== 200) { + sendCallback(new Error(url + " responded with status code " + x.status)); + return; + } + + var data = x.responseText; + var json = null; + + try { + json = JSON.parse(data); + } catch (e) { + sendCallback(e) + } + + sendCallback(null, json); + }; + x.send(); + + function sendCallback(err, data) + { + if (!callbackSent) { + callbackSent = true; + callback(err, data || null); + } + } +}; + +Zerooo.whenReady = function (callback) { + if (document.readyState == "complete") { + setTimeout(callback, 0); + return; + } + + document.onreadystatechange = function () { + if (document.readyState == "complete") { + callback(); + } + } +}; + +Zerooo.select = function (sel) { + return document.querySelector(sel); +}; + +Zerooo.selectAll = function (sel) { + return document.querySelectorAll(sel); +}; + +Zerooo.joinHumanReadable = function (arr) { + if (arr.length === 0) { + return ""; + } + + if (arr.length === 1) { + return arr.shift(); + } + + var str = arr.shift(); + + while (arr.length > 1) { + str += ', ' + arr.shift(); + } + + return str + " and " + arr.shift(); +}; \ No newline at end of file diff --git a/src/Core.php b/src/Core.php index 179ecf7..4eb17ef 100644 --- a/src/Core.php +++ b/src/Core.php @@ -362,5 +362,4 @@ class Core implements ContainerInterface { $this->getSlim()->run(); } - } \ No newline at end of file diff --git a/src/Handler/Home.php b/src/Handler/Home.php index 46f8c2a..d9e532a 100644 --- a/src/Handler/Home.php +++ b/src/Handler/Home.php @@ -2,10 +2,31 @@ namespace Eater\Glim\Handler; +use Eater\Glim\Service\GitHub; + class Home extends Session { function handle() { - return $this->render("home.html.twig"); + /** @var GitHub $github */ + $github = $this->get('github'); + + /** @var string $repo */ + $repo = $this->get('github-repo'); + + /** @var string $author */ + $author = $this->get('author'); + + $info = $github->getRepoInfo(); + + if ($info !== false) { + $author = $info['owner']['login']; + } + + return $this->render("home.html.twig", [ + 'author' => $author, + 'contributors' => $github->getContributors(), + 'githubRepo' => $repo + ]); } } \ No newline at end of file diff --git a/src/Service/GitHub.php b/src/Service/GitHub.php new file mode 100644 index 0000000..ad13822 --- /dev/null +++ b/src/Service/GitHub.php @@ -0,0 +1,85 @@ +get('stash'); + + $contributors = $pool->getItem('github/contributors'); + + if ($contributors->isMiss()) { + $contributorsData = []; + + try { + $contributorsJson = @$this->fetch('/repos/' . $this->get('github-repo') . '/contributors'); + $contributorsNewData = json_decode($contributorsJson, true); + if ($contributorsNewData !== null) { + $contributorsData = $contributorsNewData; + } + } catch (\Exception $e) { + } + + $info = $this->getRepoInfo(); + + if ($info !== false) { + + $ownerId = $info['owner']['id']; + + $contributorsNewData = []; + + foreach ($contributorsData as $contributor) { + if ($contributor['id'] !== $ownerId) { + $contributorsNewData[] = $contributor; + } + } + + $contributorsData = $contributorsNewData; + } + + $contributors->expiresAfter(3600); + $contributors->set($contributorsData); + $contributors->save(); + } + + return $contributors->get(); + } + + public function getRepoInfo() { + /** @var Pool $pool */ + $pool = $this->get('stash'); + + $info = $pool->getItem('github/info'); + + if ($info->isMiss()) { + $infoData = false; + + try { + $infoJson = @$this->fetch('/repos/' . $this->get('github-repo')); + $infoNewData = json_decode($infoJson, true); + if ($infoNewData !== null) { + $infoData = $infoNewData; + } + } catch (\Exception $e) { + } + + $info->expiresAfter(3600); + $info->set($infoData); + $info->save(); + } + + return $info->get(); + } + + private function fetch($path) + { + $options = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT'])); + $context = stream_context_create($options); + return file_get_contents('https://api.github.com' . $path, false, $context); + } +} \ No newline at end of file diff --git a/src/Service/Stash.php b/src/Service/Stash.php new file mode 100644 index 0000000..2bc2aba --- /dev/null +++ b/src/Service/Stash.php @@ -0,0 +1,15 @@ + + +{% endblock %} {% block content %}
@@ -36,7 +40,15 @@
{% endblock %} From b712668bf3b6696c8d1aef4028f564fed832e7be Mon Sep 17 00:00:00 2001 From: Corne Oppelaar Date: Sun, 19 Jun 2016 19:51:43 +0200 Subject: [PATCH 2/2] remove zerooo.js and home.js since fetching contributors in now done in php --- public/js/home.js | 17 ---------- public/js/zerooo.js | 81 -------------------------------------------- views/home.html.twig | 4 --- 3 files changed, 102 deletions(-) delete mode 100644 public/js/home.js delete mode 100644 public/js/zerooo.js diff --git a/public/js/home.js b/public/js/home.js deleted file mode 100644 index ce9b437..0000000 --- a/public/js/home.js +++ /dev/null @@ -1,17 +0,0 @@ -Zerooo.whenReady(function() { - Zerooo.getJSON('https://api.github.com/repos/EaterOfCode/zer.ooo/contributors', function (err, data) { - if (err) return; - - var contributors = data.filter(function (data) { - // It's me! - return data.id !== 1922630; - }); - - var html = Zerooo.joinHumanReadable(contributors.map(function (contributor) { - return '' + contributor.login + ''; - })); - - Zerooo.select('#contributors').innerHTML = html; - Zerooo.select('#contributors-container').style.display = 'block'; - }); -}); \ No newline at end of file diff --git a/public/js/zerooo.js b/public/js/zerooo.js deleted file mode 100644 index f57c5e2..0000000 --- a/public/js/zerooo.js +++ /dev/null @@ -1,81 +0,0 @@ -Zerooo = {}; - -Zerooo.getJSON = function (url, callback) { - var x = new XMLHttpRequest(); - var callbackSent = false; - - x.open("GET", url, true); - x.onerror = function (message, source, lineno, colno, error) { - if (!callbackSent) { - sendCallback(error); - } - }; - - x.onreadystatechange = function () { - if (x.readyState != 4) return; - - if (x.status !== 200) { - sendCallback(new Error(url + " responded with status code " + x.status)); - return; - } - - var data = x.responseText; - var json = null; - - try { - json = JSON.parse(data); - } catch (e) { - sendCallback(e) - } - - sendCallback(null, json); - }; - x.send(); - - function sendCallback(err, data) - { - if (!callbackSent) { - callbackSent = true; - callback(err, data || null); - } - } -}; - -Zerooo.whenReady = function (callback) { - if (document.readyState == "complete") { - setTimeout(callback, 0); - return; - } - - document.onreadystatechange = function () { - if (document.readyState == "complete") { - callback(); - } - } -}; - -Zerooo.select = function (sel) { - return document.querySelector(sel); -}; - -Zerooo.selectAll = function (sel) { - return document.querySelectorAll(sel); -}; - -Zerooo.joinHumanReadable = function (arr) { - if (arr.length === 0) { - return ""; - } - - if (arr.length === 1) { - return arr.shift(); - } - - var str = arr.shift(); - - while (arr.length > 1) { - str += ', ' + arr.shift(); - } - - return str + " and " + arr.shift(); -}; \ No newline at end of file diff --git a/views/home.html.twig b/views/home.html.twig index 4b1de1a..c4790a4 100644 --- a/views/home.html.twig +++ b/views/home.html.twig @@ -1,8 +1,4 @@ {% extends "base.html.twig" %} -{% block head %} - - -{% endblock %} {% block content %}