function handle($data) { list($user, $xml, $trusted) = $data; try { $doc = DOMDocument::loadXML($xml); $feed = $doc->documentElement; if ($feed->namespaceURI != Activity::ATOM || $feed->localName != 'feed') { // TRANS: Client exception thrown when an imported feed is not an Atom feed. throw new ClientException(_("Not an Atom feed.")); } $author = ActivityUtils::getFeedAuthor($feed); if (empty($author)) { // TRANS: Client exception thrown when an imported feed does not have an author. throw new ClientException(_("No author in the feed.")); } if (empty($user)) { if ($trusted) { $user = $this->userFromAuthor($author); } else { // TRANS: Client exception thrown when an imported feed does not have an author that // TRANS: can be associated with a user. throw new ClientException(_("Cannot import without a user.")); } } $activities = $this->getActivities($feed); $qm = QueueManager::get(); foreach ($activities as $activity) { $qm->enqueue(array($user, $author, $activity, $trusted), 'actimp'); } } catch (ClientException $ce) { common_log(LOG_WARNING, $ce->getMessage()); return true; } catch (ServerException $se) { common_log(LOG_ERR, $ce->getMessage()); return false; } catch (Exception $e) { common_log(LOG_ERR, $ce->getMessage()); return false; } }
/** * Look up and, if necessary, create an Ostatus_profile for the remote * profile with the given RSS feed - actually loaded from the feed. * This should never return null -- you will either get an object or * an exception will be thrown. * * @param DOMElement $feedEl root element of a loaded RSS feed * @param array $hints additional discovery information passed from higher levels * @todo FIXME: Should this be marked public? * @return Ostatus_profile * @throws Exception */ public static function ensureRssChannel(DOMElement $feedEl, array $hints) { // Special-case for Posterous. They have some nice metadata in their // posterous:author elements. We should use them instead of the channel. $items = $feedEl->getElementsByTagName('item'); if ($items->length > 0) { $item = $items->item(0); $authorEl = ActivityUtils::child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS); if (!empty($authorEl)) { $obj = ActivityObject::fromPosterousAuthor($authorEl); // Posterous has multiple authors per feed, and multiple feeds // per author. We check if this is the "main" feed for this author. if (array_key_exists('profileurl', $hints) && !empty($obj->poco) && common_url_to_nickname($hints['profileurl']) == $obj->poco->preferredUsername) { return self::ensureActivityObjectProfile($obj, $hints); } } } $obj = ActivityUtils::getFeedAuthor($feedEl); // @todo FIXME: We should check whether this feed has elements // with different <author> or <dc:creator> elements, and... I dunno. // Do something about that. if (empty($obj)) { $obj = ActivityObject::fromRssChannel($feedEl); } return self::ensureActivityObjectProfile($obj, $hints); }
/** * Look up and, if necessary, create an Ostatus_profile for the remote * profile with the given Atom feed - actually loaded from the feed. * This should never return null -- you will either get an object or * an exception will be thrown. * * @param DOMElement $feedEl root element of a loaded Atom feed * @param array $hints additional discovery information passed from higher levels * @todo FIXME: Should this be marked public? * @return Ostatus_profile * @throws Exception */ public static function ensureAtomFeed($feedEl, $hints) { $author = ActivityUtils::getFeedAuthor($feedEl); if (empty($author)) { // XXX: make some educated guesses here // TRANS: Feed sub exception. throw new FeedSubException(_m('Cannot find enough profile ' . 'information to make a feed.')); } return self::ensureActivityObjectProfile($author, $hints); }