From 70827f337922c2fc03f39b475c65978c7e6152be Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 7 Oct 2011 14:37:09 -0400 Subject: [PATCH] write all activity files to the feed file --- .../offlinebackupqueuehandler.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/plugins/OfflineBackup/offlinebackupqueuehandler.php b/plugins/OfflineBackup/offlinebackupqueuehandler.php index a8c4c5428a..054c4d403c 100644 --- a/plugins/OfflineBackup/offlinebackupqueuehandler.php +++ b/plugins/OfflineBackup/offlinebackupqueuehandler.php @@ -88,6 +88,10 @@ class OfflineBackupQueueHandler extends QueueHandler $fileName = File::filename($user->getProfile(), "backup", "application/atom+xml"); $fullPath = File::path($fileName); + $this->makeActivityFeed($user, $tmpdir, $fullPath); + + $this->delTree($tmpdir); + return $fileName; } @@ -234,4 +238,67 @@ class OfflineBackupQueueHandler extends QueueHandler } while ($mem->N > GROUPS_PER_PAGE); } + + function makeActivityFeed($user, $tmpdir, $fullPath) + { + $handle = fopen($fullPath, 'c'); + + $this->writeFeedHeader($user, $handle); + + $objects = scandir($tmpdir); + + rsort($objects); + + foreach ($objects as $object) { + $objFull = $tmpdir . '/' . $object; + if (!is_dir($objFull)) { + $entry = file_get_contents($objFull); + fwrite($handle, $entry); + $entry = null; + } + } + + $this->writeFeedFooter($user, $handle); + fclose($handle); + } + + function writeFeedHeader($user, $handle) + { + fwrite($handle, ''); + fwrite($handle, "\n"); + fwrite($handle, ''); + fwrite($handle, "\n"); + + $profile = $user->getProfile(); + + $author = ActivityObject::fromProfile($profile); + + $xs = new XMLStringer(); + $author->outputTo($xs, 'author'); + fwrite($handle, $xs->getString()); + fwrite($handle, "\n"); + } + + function writeFeedFooter($user, $handle) + { + fwrite($handle, ''); + } + + function delTree($dir) + { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (filetype($dir."/".$object) == "dir") { + $this->delTree($dir."/".$object); + } else { + unlink($dir."/".$object); + } + } + } + reset($objects); + rmdir($dir); + } + } } -- 2.39.5