]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/scripts/update-profile-data.php
Work in progress: update-profile-data.php to update ostatus profile info from the...
[quix0rs-gnu-social.git] / plugins / OStatus / scripts / update-profile-data.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - a distributed open-source microblogging tool
5  * Copyright (C) 2010, StatusNet, Inc.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
22
23 $helptext = <<<END_OF_HELP
24 update-profile-data.php [options] http://example.com/profile/url
25
26 Rerun profile discovery for the given OStatus remote profile, and save the
27 updated profile data (nickname, avatar, bio, etc). Doesn't touch feed state.
28 Can be used to clean up after breakages.
29
30 END_OF_HELP;
31
32 require_once INSTALLDIR.'/scripts/commandline.inc';
33
34 if (empty($args[0]) || !Validate::uri($args[0])) {
35     print "$helptext";
36     exit(1);
37 }
38
39 $uri = $args[0];
40
41
42 $oprofile = Ostatus_profile::staticGet('uri', $uri);
43
44 if (!$oprofile) {
45     print "No OStatus remote profile known for URI $uri\n";
46     exit(1);
47 }
48
49 function showProfileInfo($oprofile) {
50     if ($oprofile->isGroup()) {
51         echo "group\n";
52     } else {
53         $profile = $oprofile->localProfile();
54         foreach (array('nickname', 'bio', 'homepage', 'location') as $field) {
55             print "  $field: {$profile->$field}\n";
56         }
57     }
58     echo "\n";
59 }
60
61 echo "Before:\n";
62 showProfileInfo($oprofile);
63
64 $feedurl = $oprofile->feeduri;
65 $client = new HttpClient();
66 $response = $client->get($feedurl);
67 if ($response->isOk()) {
68     echo "Updating profile from feed: $feedurl\n";
69     $dom = new DOMDocument();
70     if ($dom->loadXML($response->getBody())) {
71         $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
72         if ($entries->length) {
73             $entry = $entries->item(0);
74             $activity = new Activity($entry, $feed);
75             $oprofile->checkAuthorship($activity);
76             echo "  (ok)\n";
77         } else {
78             echo "  (no entry; skipping)\n";
79         }
80     } else {
81         echo "  (bad feed; skipping)\n";
82     }
83 } else {
84     echo "Failed feed fetch: {$response->getStatus()} for $feedurl\n";
85 }
86
87 echo "After:\n";
88 showProfileInfo($oprofile);