4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
23 $longoptions = array('all', 'suspicious', 'quiet');
25 $helptext = <<<END_OF_HELP
26 update-profile-data.php [options] [http://example.com/profile/url]
28 Rerun profile discovery for the given OStatus remote profile, and save the
29 updated profile data (nickname, fullname, avatar, bio, etc).
30 Doesn't touch feed state.
31 Can be used to clean up after breakages.
34 --all Run for all known OStatus profiles
35 --suspicious Run for OStatus profiles with all-numeric nicknames
36 (fixes 0.9.7 prerelease back-compatibility bug)
40 require_once INSTALLDIR.'/scripts/commandline.inc';
42 function showProfileInfo(Ostatus_profile $oprofile) {
43 if ($oprofile->isGroup()) {
46 $profile = $oprofile->localProfile();
48 foreach (array('nickname', 'fullname', 'bio', 'homepage', 'location') as $field) {
49 print " $field: {$profile->$field}\n";
51 } catch (NoProfileException $e) {
52 print "local profile not found";
58 function fixProfile($uri) {
59 $oprofile = Ostatus_profile::getKV('uri', $uri);
62 print "No OStatus remote profile known for URI $uri\n";
67 showProfileInfo($oprofile);
69 $feedurl = $oprofile->feeduri;
70 $client = new HttpClient();
71 $response = $client->get($feedurl);
72 if ($response->isOk()) {
73 echo "Updating profile from feed: $feedurl\n";
74 $dom = new DOMDocument();
75 if ($dom->loadXML($response->getBody())) {
76 $feed = $dom->documentElement;
77 $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
78 if ($entries->length) {
79 $entry = $entries->item(0);
80 $activity = new Activity($entry, $feed);
81 $oprofile->checkAuthorship($activity);
84 echo " (no entry; skipping)\n";
88 echo " (bad feed; skipping)\n";
92 echo "Failed feed fetch: {$response->getStatus()} for $feedurl\n";
97 showProfileInfo($oprofile);
102 $validate = new Validate();
103 if (have_option('all')) {
104 $oprofile = new Ostatus_profile();
106 echo "Found $oprofile->N profiles:\n\n";
107 while ($oprofile->fetch()) {
109 $ok = fixProfile($oprofile->uri) && $ok;
110 } catch (Exception $e) {
112 echo "Failed on URI=="._ve($oprofile->uri).": {$e->getMessage()}\n";
115 } else if (have_option('suspicious')) {
116 $oprofile = new Ostatus_profile();
117 $oprofile->joinAdd(array('profile_id', 'profile:id'));
118 $oprofile->whereAdd("nickname rlike '^[0-9]$'");
120 echo "Found $oprofile->N matching profiles:\n\n";
121 while ($oprofile->fetch()) {
123 $ok = fixProfile($oprofile->uri) && $ok;
124 } catch (Exception $e) {
126 echo "Failed on URI=="._ve($oprofile->uri).": {$e->getMessage()}\n";
129 } else if (!empty($args[0]) && $validate->uri($args[0])) {
132 $ok = fixProfile($oprofile->uri) && $ok;
133 } catch (Exception $e) {
135 echo "Failed on URI=="._ve($oprofile->uri).": {$e->getMessage()}\n";