From: Evan Prodromou Date: Fri, 7 Oct 2011 18:37:09 +0000 (-0400) Subject: write all activity files to the feed file X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=70827f337922c2fc03f39b475c65978c7e6152be;p=quix0rs-gnu-social.git write all activity files to the feed file --- 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); + } + } }