diff options
Diffstat (limited to 'lib/feedimporter.php')
-rw-r--r-- | lib/feedimporter.php | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/lib/feedimporter.php b/lib/feedimporter.php index e2c9df72f..0b94eeb9b 100644 --- a/lib/feedimporter.php +++ b/lib/feedimporter.php @@ -84,12 +84,12 @@ class FeedImporter extends QueueHandler if (empty($user)) { if ($trusted) { $user = $this->userFromAuthor($author); + } else { + throw new ClientException(_("Can't import without a user.")); } } - $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); - - $activities = $this->entriesToActivities($entries, $feed); + $activities = $this->getActivities($feed); $qm = QueueManager::get(); @@ -108,6 +108,36 @@ class FeedImporter extends QueueHandler } } + function getActivities($feed) + { + $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); + + $activities = array(); + + for ($i = 0; $i < $entries->length; $i++) { + $activities[] = new Activity($entries->item($i)); + } + + usort($activities, array("FeedImporter", "activitySort")); + + return $activities; + } + + /** + * Sort activities oldest-first + */ + + static function activitySort($a, $b) + { + if ($a->time == $b->time) { + return 0; + } else if ($a->time < $b->time) { + return -1; + } else { + return 1; + } + } + function userFromAuthor($author) { $user = User::staticGet('uri', $author->id); |