]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
/main/all will give a network-wide public stream
authorMikael Nordfeldth <mmn@hethane.se>
Wed, 28 Jan 2015 19:25:39 +0000 (20:25 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Wed, 28 Jan 2015 19:25:39 +0000 (20:25 +0100)
Qvitter had implemented this as a "PublicAndExternal" stream, but
I figured we might as well put it into the GNU social core.

actions/networkpublic.php [new file with mode: 0644]
actions/public.php
classes/Notice.php
lib/networkpublicnoticestream.php [new file with mode: 0644]
lib/publicnoticestream.php
lib/router.php
lib/threadingnetworkpublicnoticestream.php [new file with mode: 0644]
lib/threadingpublicnoticestream.php [new file with mode: 0644]

diff --git a/actions/networkpublic.php b/actions/networkpublic.php
new file mode 100644 (file)
index 0000000..4bba2f7
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class NetworkpublicAction extends PublicAction
+{
+    protected function streamPrepare()
+    {
+        if (!$this->scoped instanceof Profile && common_config('public', 'localonly')) {
+            $this->serverError(_('Network wide public feed is not permitted without authorization'), 403);
+        }
+        if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
+            $this->stream = new NetworkPublicNoticeStream($this->scoped);
+        } else {
+            $this->stream = new ThreadingNetworkPublicNoticeStream($this->scoped);
+        }
+    }
+
+    function title()
+    {
+        if ($this->page > 1) {
+            // TRANS: Title for all public timeline pages but the first.
+            // TRANS: %d is the page number.
+            return sprintf(_('Network public timeline, page %d'), $this->page);
+        } else {
+            // TRANS: Title for the first public timeline page.
+            return _('Network public timeline');
+        }
+    }
+
+    function extraHead()
+    {
+        // the PublicAction has some XRDS stuff that might be unique to the non-network public feed
+        // FIXME: Solve this with a call that doesn't rely on parent:: and is unique for each class.
+        ManagedAction::extraHead();
+    }
+
+    function showSections()
+    {
+        // Show invite button, as long as site isn't closed, and
+        // we have a logged in user.
+        if (common_config('invite', 'enabled') && !common_config('site', 'closed') && common_logged_in()) {
+            if (!common_config('site', 'private')) {
+                $ibs = new InviteButtonSection(
+                    $this,
+                    // TRANS: Button text for inviting more users to the StatusNet instance.
+                    // TRANS: Less business/enterprise-oriented language for public sites.
+                    _m('BUTTON', 'Send invite')
+                );
+            } else {
+                $ibs = new InviteButtonSection($this);
+            }
+            $ibs->show();
+        }
+
+        // Network public tag cloud?
+    }
+
+    /**
+     * FIXME: Network public feed! Get a template from PublicAction
+     */
+    function getFeeds()
+    {
+        return array();
+    }
+}
index 52bab072aec60ea5172f0e432e3a9829b3218383..4f91b77e1ec44334f81383ad065da0314d38546b 100644 (file)
@@ -45,7 +45,7 @@ define('MAX_PUBLIC_PAGE', 100);
  * @see      PublicrssAction
  * @see      PublicxrdsAction
  */
-class PublicAction extends Action
+class PublicAction extends ManagedAction
 {
     /**
      * page of the stream we're on; default = 1
@@ -61,16 +61,8 @@ class PublicAction extends Action
         return true;
     }
 
-    /**
-     * Read and validate arguments
-     *
-     * @param array $args URL parameters
-     *
-     * @return boolean success value
-     */
-    protected function prepare(array $args=array())
+    protected function doPreparation()
     {
-        parent::prepare($args);
         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
 
         if ($this->page > MAX_PUBLIC_PAGE) {
@@ -108,22 +100,6 @@ class PublicAction extends Action
         }
     }
 
-    /**
-     * handle request
-     *
-     * Show the public stream, using recipe method showPage()
-     *
-     * @param array $args arguments, mostly unused
-     *
-     * @return void
-     */
-    protected function handle()
-    {
-        parent::handle();
-
-        $this->showPage();
-    }
-
     /**
      * Title of the page
      *
@@ -219,9 +195,7 @@ class PublicAction extends Action
      */
     function showContent()
     {
-        $user = common_current_user();
-
-        if (!empty($user) && $user->streamModeOnly()) {
+        if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
             $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
         } else {
             $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped);
@@ -234,7 +208,7 @@ class PublicAction extends Action
         }
 
         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
-                          $this->page, 'public');
+                          $this->page, $this->action);
     }
 
     function showSections()
@@ -285,11 +259,3 @@ class PublicAction extends Action
         $this->elementEnd('div');
     }
 }
-
-class ThreadingPublicNoticeStream extends ThreadingNoticeStream
-{
-    function __construct($profile)
-    {
-        parent::__construct(new PublicNoticeStream($profile));
-    }
-}
index 641b1295525106fccb7290d31c11ed6bdf047805..6760eb7278a9c6527317e94c13f96b6440a33df8 100644 (file)
@@ -997,6 +997,7 @@ class Notice extends Managed_DataObject
 
         if ($this->isPublic()) {
             $this->blowStream('public');
+            $this->blowStream('networkpublic');
         }
 
         self::blow('notice:list-ids:conversation:%s', $this->conversation);
@@ -1041,6 +1042,7 @@ class Notice extends Managed_DataObject
 
         if ($this->isPublic()) {
             self::blow('public;last');
+            self::blow('networkpublic;last');
         }
 
         self::blow('fave:by_notice', $this->id);
@@ -2636,12 +2638,8 @@ class Notice extends Managed_DataObject
 
     function isPublic()
     {
-        if (common_config('public', 'localonly')) {
-            return ($this->is_local == Notice::LOCAL_PUBLIC);
-        } else {
-            return (($this->is_local != Notice::LOCAL_NONPUBLIC) &&
-                    ($this->is_local != Notice::GATEWAY));
-        }
+        return (($this->is_local != Notice::LOCAL_NONPUBLIC) &&
+                ($this->is_local != Notice::GATEWAY));
     }
 
     /**
diff --git a/lib/networkpublicnoticestream.php b/lib/networkpublicnoticestream.php
new file mode 100644 (file)
index 0000000..3320b7c
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+
+if (!defined('GNUSOCIAL')) { exit(1); } 
+
+class NetworkPublicNoticeStream extends ScopingNoticeStream
+{
+    function __construct(Profile $scoped=null)
+    {
+        parent::__construct(new CachingNoticeStream(new RawNetworkPublicNoticeStream(),
+                                                    'networkpublic'),
+                            $scoped);
+    }
+}
+
+/**
+ * Raw public stream
+ *
+ * @category  Stream
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2011 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+class RawNetworkPublicNoticeStream extends NoticeStream
+{
+    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    {
+        $notice = new Notice();
+
+        $notice->selectAdd(); // clears it
+        $notice->selectAdd('id');
+
+        $notice->orderBy('created DESC, id DESC');
+
+        if (!is_null($offset)) {
+            $notice->limit($offset, $limit);
+        }
+
+        $notice->whereAdd('is_local ='. Notice::REMOTE);
+        // -1 == blacklisted, -2 == gateway (i.e. Twitter)
+        $notice->whereAdd('is_local !='. Notice::LOCAL_NONPUBLIC);
+        $notice->whereAdd('is_local !='. Notice::GATEWAY);
+
+        Notice::addWhereSinceId($notice, $since_id);
+        Notice::addWhereMaxId($notice, $max_id);
+
+        if (!empty($this->selectVerbs)) {
+            $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
+        }
+
+        $ids = array();
+
+        if ($notice->find()) {
+            while ($notice->fetch()) {
+                $ids[] = $notice->id;
+            }
+        }
+
+        $notice->free();
+        $notice = NULL;
+
+        return $ids;
+    }
+}
index 34f7b4a1defb69d558bd6949118496cff3aa147f..757c2164c08fc69af8e00bb9a24418d4b13899ec 100644 (file)
@@ -81,13 +81,8 @@ class RawPublicNoticeStream extends NoticeStream
             $notice->limit($offset, $limit);
         }
 
-        if (common_config('public', 'localonly')) {
-            $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
-        } else {
-            // -1 == blacklisted, -2 == gateway (i.e. Twitter)
-            $notice->whereAdd('is_local !='. Notice::LOCAL_NONPUBLIC);
-            $notice->whereAdd('is_local !='. Notice::GATEWAY);
-        }
+        // This feed always gives only local activities.
+        $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
 
         Notice::addWhereSinceId($notice, $since_id);
         Notice::addWhereMaxId($notice, $max_id);
index a3be38ebbdf3804c7f1db26e549ade8a22ded8be..bcdeee80c7907a769ed3acf0fcce24614090ccbc 100644 (file)
@@ -949,8 +949,12 @@ class Router
                 }
             } else {
                 $m->connect('main/public', array('action' => 'public'));
-                $m->connect('', array('action' => 'public'));
                 $m->connect('main/all', array('action' => 'networkpublic'));
+                if (common_config('site', 'localonly')) {
+                    $m->connect('', array('action' => 'public'));
+                } else {
+                    $m->connect('', array('action' => 'networkpublic'));
+                }
                 $m->connect('rss', array('action' => 'publicrss'));
                 $m->connect('featuredrss', array('action' => 'featuredrss'));
                 $m->connect('featured/', array('action' => 'featured'));
diff --git a/lib/threadingnetworkpublicnoticestream.php b/lib/threadingnetworkpublicnoticestream.php
new file mode 100644 (file)
index 0000000..f733c43
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class ThreadingNetworkPublicNoticeStream extends ThreadingNoticeStream
+{
+    public function __construct(Profile $scoped=null)
+    {
+        parent::__construct(new NetworkPublicNoticeStream($scoped));
+    }
+}
diff --git a/lib/threadingpublicnoticestream.php b/lib/threadingpublicnoticestream.php
new file mode 100644 (file)
index 0000000..a16b7a6
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class ThreadingPublicNoticeStream extends ThreadingNoticeStream
+{
+    function __construct($scoped)
+    {
+        parent::__construct(new PublicNoticeStream($scoped));
+    }
+}