You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
867 B

<?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();
}
}
}