Browse Source

parse home page h-card for the user's name and profile photo

pull/10/head
Aaron Parecki 9 years ago
parent
commit
bce43daf28
4 changed files with 69 additions and 8 deletions
  1. +46
    -5
      composer.lock
  2. +16
    -0
      controllers/auth.php
  3. +2
    -0
      lib/config.template.php
  4. +5
    -3
      views/layout.php

+ 46
- 5
composer.lock View File

@ -5,6 +5,46 @@
],
"hash": "da493f8238b017e74269bc3cdeba5e92",
"packages": [
{
"name": "barnabywalters/mf-cleaner",
"version": "v0.1.3",
"source": {
"type": "git",
"url": "https://github.com/barnabywalters/php-mf-cleaner.git",
"reference": "4ecbfc5a2893a5140b07afafb0bb00619e853809"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barnabywalters/php-mf-cleaner/zipball/4ecbfc5a2893a5140b07afafb0bb00619e853809",
"reference": "4ecbfc5a2893a5140b07afafb0bb00619e853809",
"shasum": ""
},
"require-dev": {
"php": ">=5.3",
"phpunit/phpunit": "*"
},
"suggest": {
"mf2/mf2": "To parse microformats2 structures from (X)HTML"
},
"type": "library",
"autoload": {
"files": [
"src/BarnabyWalters/Mf2/Functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barnaby Walters",
"email": "barnaby@waterpigs.co.uk"
}
],
"description": "Cleans up microformats2 array structures",
"time": "2014-05-16 15:25:47"
},
{
"name": "firebase/php-jwt",
"version": "dev-master",
@ -51,19 +91,20 @@
},
{
"name": "indieauth/client",
"version": "0.1.4",
"version": "0.1.7",
"source": {
"type": "git",
"url": "https://github.com/indieweb/indieauth-client-php.git",
"reference": "ecb74843c5c01ca49f118480d068087b5477e4f9"
"reference": "dec4f2f77ddaab11b00537db0a5fe52cc0bc3296"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/indieweb/indieauth-client-php/zipball/ecb74843c5c01ca49f118480d068087b5477e4f9",
"reference": "ecb74843c5c01ca49f118480d068087b5477e4f9",
"url": "https://api.github.com/repos/indieweb/indieauth-client-php/zipball/dec4f2f77ddaab11b00537db0a5fe52cc0bc3296",
"reference": "dec4f2f77ddaab11b00537db0a5fe52cc0bc3296",
"shasum": ""
},
"require": {
"barnabywalters/mf-cleaner": "0.*",
"indieweb/link-rel-parser": "0.1.1",
"mf2/mf2": "0.2.*",
"php": ">5.3.0"
@ -85,7 +126,7 @@
}
],
"description": "IndieAuth Client Library",
"time": "2014-08-15 18:03:06"
"time": "2014-10-06 06:25:22"
},
{
"name": "indieweb/date-formatter",

+ 16
- 0
controllers/auth.php View File

@ -61,6 +61,18 @@ function hostname($url) {
return parse_url($url, PHP_URL_HOST);
}
function add_hcard_info($user, $hCard) {
if($user && $hCard) {
// Update the user's h-card info if present
if(array_key_exists('name', $hCard)) {
$user->name = $hCard['name'];
}
if(array_key_exists('photo', $hCard)) {
$user->photo_url = $hCard['photo'];
}
}
}
$app->get('/', function($format='html') use($app) {
$res = $app->response();
@ -95,6 +107,7 @@ $app->get('/auth/start', function() use($app) {
$authorizationEndpoint = IndieAuth\Client::discoverAuthorizationEndpoint($me);
$tokenEndpoint = IndieAuth\Client::discoverTokenEndpoint($me);
$micropubEndpoint = IndieAuth\Client::discoverMicropubEndpoint($me);
$hCard = IndieAuth\Client::getHCard($me);
// Generate a "state" parameter for the request
$state = IndieAuth\Client::generateStateParameter();
@ -111,8 +124,10 @@ $app->get('/auth/start', function() use($app) {
// the debugging screens and redirect immediately to the auth endpoint.
// This will still generate a new access token when they finish logging in.
$user = ORM::for_table('users')->where('url', hostname($me))->find_one();
if($user && $user->access_token && !array_key_exists('restart', $params)) {
add_hcard_info($user, $hCard);
$user->micropub_endpoint = $micropubEndpoint;
$user->authorization_endpoint = $authorizationEndpoint;
$user->token_endpoint = $tokenEndpoint;
@ -125,6 +140,7 @@ $app->get('/auth/start', function() use($app) {
if(!$user)
$user = ORM::for_table('users')->create();
add_hcard_info($user, $hCard);
$user->url = hostname($me);
$user->date_created = date('Y-m-d H:i:s');
$user->micropub_endpoint = $micropubEndpoint;

+ 2
- 0
lib/config.template.php View File

@ -10,5 +10,7 @@ class Config {
public static $dbPassword = '';
public static $jwtSecret = 'xxx';
public static $mf2Debug = false;
}

+ 5
- 3
views/layout.php View File

@ -52,9 +52,11 @@
<?= $html=$this->fetch($this->page . '.php') ?>
</div>
<div class="narrow">
<pre><?= json_encode(Mf2\parse($html), JSON_PRETTY_PRINT) ?></pre>
</div>
<?php if(Config::$mf2Debug): ?>
<div class="narrow">
<pre><?= json_encode(Mf2\parse($html), JSON_PRETTY_PRINT) ?></pre>
</div>
<?php endif; ?>
<div class="footer">
<div class="nav">

Loading…
Cancel
Save