X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FOStatus%2Fclasses%2FOstatus_profile.php;h=c4d857f22cdb57a4baac1825519d7b48ac246fd9;hb=dc424ab63a91bf4c29198452d54543b8737b65ac;hp=b43a2b5f11fde33c05d8524808dd0e4def553117;hpb=eb0495d10719f2be86f8f97e82aaa1b8bf923c7d;p=quix0rs-gnu-social.git diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index b43a2b5f11..c4d857f22c 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -331,6 +331,7 @@ class Ostatus_profile extends Memcached_DataObject * an acceptable response from the remote site. * * @param mixed $entry XML string, Notice, or Activity + * @param Profile $actor * @return boolean success */ public function notifyActivity($entry, $actor) @@ -457,7 +458,8 @@ class Ostatus_profile extends Memcached_DataObject { $activity = new Activity($entry, $feed); - if (Event::handle('StartHandleFeedEntry', array($activity))) { + if (Event::handle('StartHandleFeedEntryWithProfile', array($activity, $this)) && + Event::handle('StartHandleFeedEntry', array($activity))) { // @todo process all activity objects switch ($activity->objects[0]->type) { @@ -479,6 +481,7 @@ class Ostatus_profile extends Memcached_DataObject } Event::handle('EndHandleFeedEntry', array($activity)); + Event::handle('EndHandleFeedEntryWithProfile', array($activity, $this)); } } @@ -491,36 +494,10 @@ class Ostatus_profile extends Memcached_DataObject */ public function processPost($activity, $method) { - if ($this->isGroup()) { - // A group feed will contain posts from multiple authors. - // @fixme validate these profiles in some way! - $oprofile = self::ensureActorProfile($activity); - if ($oprofile->isGroup()) { - // Groups can't post notices in StatusNet. - common_log(LOG_WARNING, "OStatus: skipping post with group listed as author: $oprofile->uri in feed from $this->uri"); - return false; - } - } else { - $actor = $activity->actor; - - if (empty($actor)) { - // OK here! assume the default - } else if ($actor->id == $this->uri || $actor->link == $this->uri) { - $this->updateFromActivityObject($actor); - } else if ($actor->id) { - // We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner. - // This isn't what we expect from mainline OStatus person feeds! - // Group feeds go down another path, with different validation... - // Most likely this is a plain ol' blog feed of some kind which - // doesn't match our expectations. We'll take the entry, but ignore - // the info. - common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}"); - } else { - // Plain without ActivityStreams actor info. - // We'll just ignore this info for now and save the update under the feed's identity. - } + $oprofile = $this->checkAuthorship($activity); - $oprofile = $this; + if (empty($oprofile)) { + return false; } // It's not always an ActivityObject::NOTE, but... let's just say it is. @@ -935,54 +912,19 @@ class Ostatus_profile extends Memcached_DataObject * @return Ostatus_profile * @throws Exception */ + public static function ensureAtomFeed($feedEl, $hints) { - // Try to get a profile from the feed activity:subject - - $subject = ActivityUtils::child($feedEl, Activity::SUBJECT, Activity::SPEC); - - if (!empty($subject)) { - $subjObject = new ActivityObject($subject); - return self::ensureActivityObjectProfile($subjObject, $hints); - } + $author = ActivityUtils::getFeedAuthor($feedEl); - // Otherwise, try the feed author - - $author = ActivityUtils::child($feedEl, Activity::AUTHOR, Activity::ATOM); - - if (!empty($author)) { - $authorObject = new ActivityObject($author); - return self::ensureActivityObjectProfile($authorObject, $hints); + if (empty($author)) { + // XXX: make some educated guesses here + // TRANS: Feed sub exception. + throw new FeedSubException(_m('Can\'t find enough profile '. + 'information to make a feed.')); } - // Sheesh. Not a very nice feed! Let's try fingerpoken in the - // entries. - - $entries = $feedEl->getElementsByTagNameNS(Activity::ATOM, 'entry'); - - if (!empty($entries) && $entries->length > 0) { - - $entry = $entries->item(0); - - $actor = ActivityUtils::child($entry, Activity::ACTOR, Activity::SPEC); - - if (!empty($actor)) { - $actorObject = new ActivityObject($actor); - return self::ensureActivityObjectProfile($actorObject, $hints); - - } - - $author = ActivityUtils::child($entry, Activity::AUTHOR, Activity::ATOM); - - if (!empty($author)) { - $authorObject = new ActivityObject($author); - return self::ensureActivityObjectProfile($authorObject, $hints); - } - } - - // XXX: make some educated guesses here - // TRANS: Feed sub exception. - throw new FeedSubException(_m('Can\'t find enough profile information to make a feed.')); + return self::ensureActivityObjectProfile($author, $hints); } /** @@ -1170,7 +1112,8 @@ class Ostatus_profile extends Memcached_DataObject return $url; } } - return common_path('plugins/OStatus/images/96px-Feed-icon.svg.png'); + + return Plugin::staticPath('OStatus', 'images/96px-Feed-icon.svg.png'); } /** @@ -1411,7 +1354,17 @@ class Ostatus_profile extends Memcached_DataObject { $orig = clone($profile); - $profile->nickname = self::getActivityObjectNickname($object, $hints); + // Existing nickname is better than nothing. + + if (!array_key_exists('nickname', $hints)) { + $hints['nickname'] = $profile->nickname; + } + + $nickname = self::getActivityObjectNickname($object, $hints); + + if (!empty($nickname)) { + $profile->nickname = $nickname; + } if (!empty($object->title)) { $profile->fullname = $object->title; @@ -1427,9 +1380,23 @@ class Ostatus_profile extends Memcached_DataObject $profile->profileurl = $object->id; } - $profile->bio = self::getActivityObjectBio($object, $hints); - $profile->location = self::getActivityObjectLocation($object, $hints); - $profile->homepage = self::getActivityObjectHomepage($object, $hints); + $bio = self::getActivityObjectBio($object, $hints); + + if (!empty($bio)) { + $profile->bio = $bio; + } + + $location = self::getActivityObjectLocation($object, $hints); + + if (!empty($location)) { + $profile->location = $location; + } + + $homepage = self::getActivityObjectHomepage($object, $hints); + + if (!empty($homepage)) { + $profile->homepage = $homepage; + } if (!empty($object->geopoint)) { $location = ActivityContext::locationFromPoint($object->geopoint); @@ -1552,8 +1519,11 @@ class Ostatus_profile extends Memcached_DataObject } // Try the profile url (like foo.example.com or example.com/user/foo) - - $profileUrl = ($object->link) ? $object->link : $hints['profileurl']; + if (!empty($object->link)) { + $profileUrl = $object->link; + } else if (!empty($hints['profileurl'])) { + $profileUrl = $hints['profileurl']; + } if (!empty($profileUrl)) { $nickname = self::nicknameFromURI($profileUrl); @@ -1584,9 +1554,11 @@ class Ostatus_profile extends Memcached_DataObject protected static function nicknameFromURI($uri) { - preg_match('/(\w+):/', $uri, $matches); - - $protocol = $matches[1]; + if (preg_match('/(\w+):/', $uri, $matches)) { + $protocol = $matches[1]; + } else { + return null; + } switch ($protocol) { case 'acct': @@ -1832,12 +1804,55 @@ class Ostatus_profile extends Memcached_DataObject case 'mailto': $rest = $match[2]; $oprofile = Ostatus_profile::ensureWebfinger($rest); + break; default: - common_log("Unrecognized URI protocol for profile: $protocol ($uri)"); + throw new ServerException("Unrecognized URI protocol for profile: $protocol ($uri)"); break; } + } else { + throw new ServerException("No URI protocol for profile: ($uri)"); + } + } + + return $oprofile; + } + + function checkAuthorship($activity) + { + if ($this->isGroup()) { + // A group feed will contain posts from multiple authors. + // @fixme validate these profiles in some way! + $oprofile = self::ensureActorProfile($activity); + if ($oprofile->isGroup()) { + // Groups can't post notices in StatusNet. + common_log(LOG_WARNING, + "OStatus: skipping post with group listed as author: ". + "$oprofile->uri in feed from $this->uri"); + return false; } + } else { + $actor = $activity->actor; + + if (empty($actor)) { + // OK here! assume the default + } else if ($actor->id == $this->uri || $actor->link == $this->uri) { + $this->updateFromActivityObject($actor); + } else if ($actor->id) { + // We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner. + // This isn't what we expect from mainline OStatus person feeds! + // Group feeds go down another path, with different validation... + // Most likely this is a plain ol' blog feed of some kind which + // doesn't match our expectations. We'll take the entry, but ignore + // the info. + common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}"); + } else { + // Plain without ActivityStreams actor info. + // We'll just ignore this info for now and save the update under the feed's identity. + } + + $oprofile = $this; } + return $oprofile; } }