]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/noticestreamaction.php
Faster NodeInfo stats
[quix0rs-gnu-social.git] / lib / noticestreamaction.php
index e064b2801d207659519d37b8e504e96f660b63ac..e668a27daf23830788c4a7d4e2c0f8e3a5eb1a78 100644 (file)
@@ -2,8 +2,50 @@
 
 if (!defined('GNUSOCIAL')) { exit(1); }
 
-interface NoticestreamAction
+abstract class NoticestreamAction extends ProfileAction
 {
+    protected $notice = null;   // holds the stream result
+
+    protected function prepare(array $args=array()) {
+        parent::prepare($args);
+
+        // In case we need more info than ProfileAction->doPreparation() gives us
+        $this->doStreamPreparation();
+
+        // fetch the actual stream stuff
+        try {
+            $stream = $this->getStream();
+            $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+        } catch (PrivateStreamException $e) {
+            $this->notice = new Notice();
+            $this->notice->whereAdd('FALSE');
+        }
+
+        if ($this->page > 1 && $this->notice->N == 0) {
+            // TRANS: Client error when page not found (404).
+            $this->clientError(_('No such page.'), 404);
+        }
+
+        return true;
+    }
+
+    protected function doStreamPreparation()
+    {
+        // pass by default
+    }
+
+    public function extraHeaders()
+    {
+        parent::extraHeaders();
+        foreach ($this->getFeeds() as $feed) {
+            header('Link: <'.htmlspecialchars($feed->getUrl()).'>;' .
+                        ' rel="'.htmlspecialchars($feed->rel()).'";' .
+                        ' type="'.htmlspecialchars($feed->mimeType()).'"',
+                    false    // don't overwrite previous headers of this sort
+                    );
+        }
+    }
+
     // this fetches the NoticeStream
-    public function getStream();
+    abstract public function getStream();
 }