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.

33 lines
971 B

  1. <?php
  2. namespace Telegraph;
  3. use ORM, Exception, Mf2;
  4. class ProfileFetcher {
  5. public static function fetch($id) {
  6. initdb();
  7. // Fetch the user's home page and look for profile information there
  8. $user = ORM::for_table('users')->where_id_is($id)->find_one();
  9. echo "Looking for representative h-card for ".$user->url."\n";
  10. $client = new HTTP();
  11. $data = $client->get($user->url);
  12. $parsed = Mf2\parse($data['body'], $user->url);
  13. $representative = Mf2\HCard\representative($parsed, $user->url);
  14. if($representative) {
  15. echo "Found it!\n";
  16. print_r($representative);
  17. if(array_key_exists('name', $representative['properties'])) {
  18. $user->name = $representative['properties']['name'][0];
  19. }
  20. if(array_key_exists('photo', $representative['properties'])) {
  21. $user->photo = $representative['properties']['photo'][0];
  22. }
  23. $user->save();
  24. } else {
  25. echo "Couldn't find one\n";
  26. }
  27. }
  28. }