Browse Source

fetch the user's h-card after logging in and update their profile data

pull/3/head
Aaron Parecki 9 years ago
parent
commit
a5dac356e4
8 changed files with 113 additions and 10 deletions
  1. +1
    -0
      composer.json
  2. +47
    -2
      composer.lock
  3. +2
    -0
      controllers/Auth.php
  4. +12
    -2
      controllers/Controller.php
  5. +27
    -0
      lib/Telegraph/ProfileFetcher.php
  6. BIN
      public/assets/default-user.jpg
  7. +16
    -0
      views/dashboard.php
  8. +8
    -6
      views/layout-loggedin.php

+ 1
- 0
composer.json View File

@ -3,6 +3,7 @@
"php": ">=5.5",
"mf2/mf2": "0.2.*",
"indieweb/mention-client": "1.*",
"indieweb/representative-h-card": "0.1.*",
"indieauth/client": "0.1.*",
"firebase/php-jwt": "~3.0",
"league/route": "~1.2",

+ 47
- 2
composer.lock View File

@ -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": "b33b0001cd49507ca593b5ac7a1c7f62",
"content-hash": "d16bb0e3e3c4ada5c5eb9cb1eb603d15",
"hash": "f093ab92ae4ced25546dcff30639c5d9",
"content-hash": "61bdf94447ac95a334eb26e591a7b4e3",
"packages": [
{
"name": "barnabywalters/mf-cleaner",
@ -217,6 +217,51 @@
"homepage": "https://github.com/indieweb/mention-client-php",
"time": "2015-12-22 23:40:11"
},
{
"name": "indieweb/representative-h-card",
"version": "0.1.2",
"source": {
"type": "git",
"url": "https://github.com/indieweb/representative-h-card-php.git",
"reference": "b70b01bd0dd7f2a940602137335dbf46ab6e2e38"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/indieweb/representative-h-card-php/zipball/b70b01bd0dd7f2a940602137335dbf46ab6e2e38",
"reference": "b70b01bd0dd7f2a940602137335dbf46ab6e2e38",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"require-dev": {
"mf2/mf2": "0.2.*",
"phpunit/phpunit": "*"
},
"type": "library",
"autoload": {
"files": [
"src/mf2/representative-h-card.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Aaron Parecki",
"homepage": "http://aaronparecki.com"
}
],
"keywords": [
"h-card",
"indieweb",
"mf2",
"microformats"
],
"time": "2015-12-23 18:11:19"
},
{
"name": "j4mie/idiorm",
"version": "v1.5.1",

+ 2
- 0
controllers/Auth.php View File

@ -140,6 +140,8 @@ class Auth {
$user->save();
}
q()->queue('Telegraph\ProfileFetcher', 'fetch', [$user->id]);
session_start();
$_SESSION['user_id'] = $user->id;
$response->setStatusCode(302);

+ 12
- 2
controllers/Controller.php View File

@ -42,12 +42,22 @@ class Controller {
}
}
$site = ORM::for_table('sites')->where_id_is($role->site_id);
$site = ORM::for_table('sites')->where_id_is($role->site_id)->find_one();
$webmentions = [];
foreach(ORM::for_table('webmentions')->where('site_id', $site->id)->find_many() as $m) {
$webmentions[] = [
'webmention' => $m,
'statuses' => ORM::for_table('webmention_status')->where('webmention_id', $m->id)->order_by_desc('created_at')->find_many()
];
}
$response->setContent(view('dashboard', [
'title' => 'Telegraph Dashboard',
'user' => $this->_user(),
'accounts' => $this->_accounts()
'accounts' => $this->_accounts(),
'site' => $site,
'webmentions' => $webmentions
]));
return $response;
}

+ 27
- 0
lib/Telegraph/ProfileFetcher.php View File

@ -0,0 +1,27 @@
<?php
namespace Telegraph;
use ORM, Exception, Mf2;
class ProfileFetcher {
public static function fetch($id) {
// Fetch the user's home page and look for profile information there
$user = ORM::for_table('users')->where_id_is($id)->find_one();
echo "Looking for representative h-card for ".$user->url."\n";
$data = HTTP::get($user->url);
$parsed = Mf2\parse($data['body']);
$representative = Mf2\HCard\representative($parsed, $user->url);
if($representative) {
echo "Found it!\n";
print_r($representative);
if(array_key_exists('name', $representative['properties'])) {
$user->name = $representative['properties']['name'][0];
}
if(array_key_exists('photo', $representative['properties'])) {
$user->photo = $representative['properties']['photo'][0];
}
$user->save();
}
}
}

BIN
public/assets/default-user.jpg View File

Before After
Width: 200  |  Height: 200  |  Size: 4.0 KiB

+ 16
- 0
views/dashboard.php View File

@ -1 +1,17 @@
<?php $this->layout('layout-loggedin', ['title' => $title, 'accounts' => $accounts, 'user' => $user]); ?>
<div class="ui main text container">
<table class="ui striped table fixed single line">
<thead>
<th>Date</th>
<th>Source &amp; Target</th>
</thead>
<?php foreach($webmentions as $mention): ?>
<tr>
<td><?= $mention['webmention']->created_at ?></td>
<td><?= $this->e($mention['webmention']->source) ?><br><?= $this->e($mention['webmention']->target) ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>

+ 8
- 6
views/layout-loggedin.php View File

@ -9,15 +9,17 @@
<a href="/dashboard" class="item">Dashboard</a>
<a href="/api" class="item">API</a>
<div class="ui right simple dropdown item">
Sites <i class="dropdown icon"></i>
<img class="ui mini circular image" src="<?= $user->photo ?: '/assets/default-user.jpg' ?>"> <i class="dropdown icon"></i>
<div class="menu">
<div class="header"><?= display_url($user->url) ?></div>
<?php foreach($accounts as $account): ?>
<div class="header">Websites</div>
<? foreach($accounts as $account): ?>
<a class="item" href="/dashboard?account=<?= $account->id ?>"><?= $this->e($account->name) ?></a>
<?php endforeach; ?>
<? endforeach; ?>
<div class="divider"></div>
<a class="item" href="/new-site">New Site</a>
<a class="item" href="/logout">Log Out</a>
<a class="item" href="/new-site"><i class="plus icon"></i> New Site</a>
<a class="item" href="/profile"><i class="user icon"></i> Profile</a>
<div class="divider"></div>
<a class="item" href="/logout"><i class="sign out icon"></i> Log Out</a>
</div>
</div>
</div>

Loading…
Cancel
Save