From a5dac356e48207a3467ab41a31195bbef54142f9 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Wed, 23 Dec 2015 10:45:42 -0800 Subject: [PATCH] fetch the user's h-card after logging in and update their profile data --- composer.json | 1 + composer.lock | 49 +++++++++++++++++++++++++++++-- controllers/Auth.php | 2 ++ controllers/Controller.php | 14 +++++++-- lib/Telegraph/ProfileFetcher.php | 27 +++++++++++++++++ public/assets/default-user.jpg | Bin 0 -> 4134 bytes views/dashboard.php | 16 ++++++++++ views/layout-loggedin.php | 14 +++++---- 8 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 lib/Telegraph/ProfileFetcher.php create mode 100644 public/assets/default-user.jpg diff --git a/composer.json b/composer.json index 7e5d35a..b6c4dc4 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index e84bf6f..e1b6de1 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": "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", diff --git a/controllers/Auth.php b/controllers/Auth.php index d6e0b85..9081f8b 100644 --- a/controllers/Auth.php +++ b/controllers/Auth.php @@ -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); diff --git a/controllers/Controller.php b/controllers/Controller.php index 4b04161..ba1a005 100644 --- a/controllers/Controller.php +++ b/controllers/Controller.php @@ -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; } diff --git a/lib/Telegraph/ProfileFetcher.php b/lib/Telegraph/ProfileFetcher.php new file mode 100644 index 0000000..d63a1ef --- /dev/null +++ b/lib/Telegraph/ProfileFetcher.php @@ -0,0 +1,27 @@ +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(); + } + } + +} diff --git a/public/assets/default-user.jpg b/public/assets/default-user.jpg new file mode 100644 index 0000000000000000000000000000000000000000..817cd8ffd947c2bcac77746e69e76bce595e28d6 GIT binary patch literal 4134 zcmai03pmtS8$bWKDih-_sh!3q%^G7|re?qu zqCfwnW5c*~ z9?@nkVNEn6S`Z=NO9Keef^eaP5zQpdfisltSv7@7m@|=vF^RUbQ3>9z?gTrLm`|`a zvm|rPsZ;`uW=6HLrqQUT1PgPj1;t$X(a2OQhBb|0v6AqY5S7uyydcJA`}KdtQudg{ zza|wG6=fD>X(kfyq)_Q}`YeWp1zBl9mc$690nuck#OO1EJzv5VheSw2L_)$WVnCoM zQpzMMGyQW4f`~7$f4f%S7`nRtZ&QI_b^+#KCDP6OulfEhu*5Saf=}7Zmxv<8T)xuW zXx2G`VJGGXNJU~#ktqE0D!K=Yq#{YMD1uufDotu$X}Y3)F_TJ_o2Uc`+Q@P*RP zzPzu#w*TlmO9nxNGO|5i9I~6wTQ3#~2y>HWg#1k|Ry6uLOFL^@x`VCV-{vq%-27R=spIBE9jB(IuBL|5)YR72)HIltC0_)>VzD??oSwS6 zo`JT8_BSJ6O#XLcrXFahfIHw064C$&4G5_L&D;R6vdR$%B=oiZ0i=S$BGDKG^sRDk z91kD_5{<&5R8Sb?oCZQ@AW=)HwrGq;z%K0T1IZUPwN%btBU-dP`D1gNHb*~DeChjj z2eT}7bnQI#H2w>5rW@dt!IdZ)zy@4YkrU;>L}f1vgm)v=fDQq<4*)64n1tE|{dixu zqzVPNeJJ~RhrFUy!L}P1W<3$&u)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#Q;+?bsE%!X9xZIr((tMP((r0l84d&w(ardOEm z_fuu0rrx?~uLhsef4{E5i9T62oY8x3^Rm3Nwek!H4$|{0ruVP`nZ4w;qJ*0~ z)))VrS&^01osfW<0^4AQiONS7wG_LresMn$pi7Y+v58%l7EB7o=v;bX$-S(HNuk#o z&x@L)9{V4fUp!l5E|rZxjT&BH_6ar;mqc=GyF?1k%7anmP;|9}#yqv@lD zw;9||;~jpr`Lj=UpnI+@scK(T&U0SsNu7yllHyYDK*Cko3|KY;cCoKNz&wKVL0>Iv zRjwLg6J3t{(+-QxyXN6|I*_KSg^x%-m)iwOXI2Y|&(t`zRoJ=PrB6PI9c zB^?zk=Z_P4uEti@n4z-RO7GA5PW9LPOC9Rww|h z=O3*Gfa4434b(m~T=cLat!eC5;bI@BwHu?Wj{%co52i)Z$}Gh&CoH2fE9;sE>l;{v z4|#ma!|)BYLy4gx@ikD}z0q`^*LjOm)iZ!eHkC=VxGhJYZo0pkSJsDE#7as)!O%{i z3zroH5H7J5 z7niKQ#|sT_b^h(Hcq+Rgs4?8el37PNtUE~+aAq%{8`xO*Fl-dBvR7^nwGx=}bqCgn zkWZyDcJ@`5Nm{rpaf?gZ8%JuBZ;MB`r@OUr!JD>ol8}3OcZZChoqVk0V=6kmskrwx ziC(+u$Nn{IW`J{S&flGJkN*n2 z=X9Pa9N4S)?htaapvcCj;eDu$%Dj*HVg7#_AZ$W2x+YGQRGfPa@B2RpSgYgC89CcN z-i!J9V%4-Db7BUt4X{3u$wHC-Vc7qCF4vxa=y8&6*Do6Kg6134(pqgbG z0R<~BO!a7>I{`+4+_jeFklu}`*M)tV{pJv?R(xMy1PKY$DYze?@CYHaK>2pY?J5Uq zfZ>f)W$l5ZKq+DuB&SSn@BzHS_clrKy?z8)obPzgq% SaMt$HS5POSkFbB{;eP-rG-!VS literal 0 HcmV?d00001 diff --git a/views/dashboard.php b/views/dashboard.php index 653e19c..b6610ec 100644 --- a/views/dashboard.php +++ b/views/dashboard.php @@ -1 +1,17 @@ layout('layout-loggedin', ['title' => $title, 'accounts' => $accounts, 'user' => $user]); ?> + +
+ + + + + + + + + + + + +
DateSource & Target
created_at ?>e($mention['webmention']->source) ?>
e($mention['webmention']->target) ?>
+
diff --git a/views/layout-loggedin.php b/views/layout-loggedin.php index 8e76389..9500ab3 100644 --- a/views/layout-loggedin.php +++ b/views/layout-loggedin.php @@ -9,15 +9,17 @@ Dashboard API