+ $haveOne = false;
+
+ $end = time() + 1;
+ foreach ($this->objs as $obj) {
+ try {
+ $act = $obj->asActivity();
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
+ }
+
+ $start = $act->time;
+
+ if ($this->outputMode == self::OUTPUT_RAW && $start != $end) {
+ // In raw mode, we haven't pre-fetched notices.
+ // Grab the chunks of notices between other activities.
+ try {
+ $notices = $this->getNoticesBetween($start, $end);
+ foreach ($notices as $noticeAct) {
+ try {
+ $nact = $noticeAct->asActivity($this->user->getProfile());
+ if ($format == Feed::ATOM) {
+ $nact->outputTo($this, false, false);
+ } else {
+ if ($haveOne) {
+ fwrite($handle, ",");
+ }
+ fwrite($handle, json_encode($nact->asArray()));
+ $haveOne = true;
+ }
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
+ }
+ $nact = null;
+ unset($nact);
+ }
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ }
+ }
+
+ $notices = null;
+ unset($notices);
+
+ try {
+ if ($format == Feed::ATOM) {
+ // Only show the author sub-element if it's different from default user
+ $act->outputTo($this, false, ($act->actor->id != $this->user->getUri()));
+ } else {
+ if ($haveOne) {
+ fwrite($handle, ",");
+ }
+ fwrite($handle, json_encode($act->asArray()));
+ $haveOne = true;
+ }
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ }
+
+ $act = null;
+ unset($act);
+
+ $end = $start;
+ }
+
+ if ($this->outputMode == self::OUTPUT_RAW) {
+ // Grab anything after the last pre-sorted activity.
+ try {
+ if (!empty($this->after)) {
+ $notices = $this->getNoticesBetween($this->after, $end);
+ } else {
+ $notices = $this->getNoticesBetween(0, $end);
+ }
+ foreach ($notices as $noticeAct) {
+ try {
+ $nact = $noticeAct->asActivity($this->user->getProfile());
+ if ($format == Feed::ATOM) {
+ $nact->outputTo($this, false, false);
+ } else {
+ if ($haveOne) {
+ fwrite($handle, ",");
+ }
+ fwrite($handle, json_encode($nact->asArray()));
+ $haveOne = true;
+ }
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
+ }
+ }
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ }
+ }
+
+ if (empty($this->after) || strtotime($this->user->created) > $this->after) {
+ // We always add the registration activity at the end, even if
+ // they have older activities (from restored backups) in their stream.
+
+ try {
+ $ract = $this->user->registrationActivity();
+ if ($format == Feed::ATOM) {
+ $ract->outputTo($this, false, false);
+ } else {
+ if ($haveOne) {
+ fwrite($handle, ",");
+ }
+ fwrite($handle, json_encode($ract->asArray()));
+ $haveOne = true;
+ }
+ } catch (Exception $e) {
+ common_log(LOG_ERR, $e->getMessage());
+ continue;
+ }