]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
write all activity files to the feed file
authorEvan Prodromou <evan@status.net>
Fri, 7 Oct 2011 18:37:09 +0000 (14:37 -0400)
committerEvan Prodromou <evan@status.net>
Fri, 7 Oct 2011 18:37:09 +0000 (14:37 -0400)
plugins/OfflineBackup/offlinebackupqueuehandler.php

index a8c4c5428a85442983df496f5ef3d6fbdf88fd08..054c4d403c322648f767802a6cb238cd2ee042df 100644 (file)
@@ -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, '<?xml version="1.0" encoding="UTF-8"?>');
+        fwrite($handle, "\n");
+        fwrite($handle, '<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">');
+        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, '</feed>');
+    }
+
+    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);
+        }
+    }
 }