diff --git a/lib/useractivitystream.php b/lib/useractivitystream.php index bd26d38ee0..82f0be0504 100644 --- a/lib/useractivitystream.php +++ b/lib/useractivitystream.php @@ -99,12 +99,10 @@ class UserActivityStream extends AtomUserNoticeFeed * Interleave the pre-sorted subs/groups/faves with the user's * notices, all in reverse chron order. */ - function renderEntries() + function renderEntries($format=Feed::ATOM, $handle=null) { $end = time() + 1; - $i = 0; foreach ($this->objs as $obj) { - $i++; try { $act = $obj->asActivity(); } catch (Exception $e) { @@ -122,7 +120,11 @@ class UserActivityStream extends AtomUserNoticeFeed foreach ($notices as $noticeAct) { try { $nact = $noticeAct->asActivity(); - $nact->outputTo($this, false, false); + if ($format == Feed::ATOM) { + $nact->outputTo($this, false, false); + } else { + fwrite($handle, json_encode($nact->asArray())); + } } catch (Exception $e) { common_log(LOG_ERR, $e->getMessage()); continue; @@ -138,8 +140,16 @@ class UserActivityStream extends AtomUserNoticeFeed $notices = null; unset($notices); - // Only show the author sub-element if it's different from default user - $act->outputTo($this, false, ($act->actor->id != $this->user->uri)); + 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->uri)); + } else { + fwrite($handle, json_encode($act->asArray())); + } + } catch (Exception $e) { + common_log(LOG_ERR, $e->getMessage()); + } $act = null; unset($act); @@ -154,7 +164,11 @@ class UserActivityStream extends AtomUserNoticeFeed foreach ($notices as $noticeAct) { try { $nact = $noticeAct->asActivity(); - $nact->outputTo($this, false, false); + if ($format == Feed::ATOM) { + $nact->outputTo($this, false, false); + } else { + fwrite($handle, json_encode($nact->asArray())); + } } catch (Exception $e) { common_log(LOG_ERR, $e->getMessage()); continue; @@ -284,4 +298,12 @@ class UserActivityStream extends AtomUserNoticeFeed return $groups; } + + function writeJSON($handle) + { + require_once INSTALLDIR.'/lib/activitystreamjsondocument.php'; + fwrite($handle, '{"items": ['); + $this->renderEntries(Feed::JSON, $handle); + fwrite($handle, ']'); + } } diff --git a/scripts/backupuser.php b/scripts/backupuser.php index ee2951fc8f..d183dba2b9 100644 --- a/scripts/backupuser.php +++ b/scripts/backupuser.php @@ -19,8 +19,8 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -$shortoptions = 'i:n:f:'; -$longoptions = array('id=', 'nickname=', 'file='); +$shortoptions = 'i:n:f:j'; +$longoptions = array('id=', 'nickname=', 'file=', 'json'); $helptext = <<getString(); + if (have_option('j', 'json')) { + $actstr->writeJSON(STDOUT); + } else { + print $actstr->getString(); + } } catch (Exception $e) { print $e->getMessage()."\n"; exit(1);