]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '1.0.x' into limitdist2
authorEvan Prodromou <evan@status.net>
Sat, 26 Mar 2011 19:37:05 +0000 (15:37 -0400)
committerEvan Prodromou <evan@status.net>
Sat, 26 Mar 2011 19:37:05 +0000 (15:37 -0400)
17 files changed:
classes/Notice.php
classes/Profile.php
classes/statusnet.ini
db/core.php
lib/conversationnoticestream.php
lib/favenoticestream.php
lib/filenoticestream.php
lib/filteringnoticestream.php [new file with mode: 0644]
lib/groupnoticestream.php
lib/profilenoticestream.php
lib/publicnoticestream.php
lib/repeatedbymenoticestream.php
lib/repeatsofmenoticestream.php
lib/replynoticestream.php
lib/scopingnoticestream.php [new file with mode: 0644]
lib/taggedprofilenoticestream.php
lib/tagnoticestream.php

index 114119bfc9f7027f23d56b9877a58b94a4e48f7b..83507f3bc0f63c1ed916d3ed08760999f567c5a4 100644 (file)
@@ -73,6 +73,7 @@ class Notice extends Memcached_DataObject
     public $location_ns;                     // int(4)
     public $repeat_of;                       // int(4)
     public $object_type;                     // varchar(255)
+    public $scope;                           // int(4)
 
     /* Static get */
     function staticGet($k,$v=NULL)
@@ -89,6 +90,11 @@ class Notice extends Memcached_DataObject
     const LOCAL_NONPUBLIC = -1;
     const GATEWAY         = -2;
 
+    const SITE_SCOPE      = 1;
+    const ADDRESSEE_SCOPE = 2;
+    const GROUP_SCOPE     = 4;
+    const FOLLOWER_SCOPE  = 8;
+
     function getProfile()
     {
         $profile = Profile::staticGet('id', $this->profile_id);
@@ -2011,4 +2017,84 @@ class Notice extends Memcached_DataObject
                     ($this->is_local != Notice::GATEWAY));
         }
     }
+
+    /**
+     * Check that the given profile is allowed to read, respond to, or otherwise
+     * act on this notice.
+     * 
+     * The $scope member is a bitmask of scopes, representing a logical AND of the
+     * scope requirement. So, 0x03 (Notice::ADDRESSEE_SCOPE | Notice::SITE_SCOPE) means
+     * "only visible to people who are mentioned in the notice AND are users on this site."
+     * Users on the site who are not mentioned in the notice will not be able to see the
+     * notice.
+     *
+     * @param Profile $profile The profile to check
+     *
+     * @return boolean whether the profile is in the notice's scope
+     */
+
+    function inScope($profile)
+    {
+        // If there's any scope, and there's no logged-in user,
+        // not allowed.
+
+        if ($this->scope > 0 && empty($profile)) {
+            return false;
+        }
+
+        // Only for users on this site
+
+        if ($this->scope & Notice::SITE_SCOPE) {
+            $user = $profile->getUser();
+            if (empty($user)) {
+                return false;
+            }
+        }
+
+        // Only for users mentioned in the notice
+
+        if ($this->scope & Notice::ADDRESSEE_SCOPE) {
+
+            // XXX: just query for the single reply
+
+            $replies = $this->getReplies();
+
+            if (!in_array($profile->id, $replies)) {
+                return false;
+            }
+        }
+
+        // Only for members of the given group
+
+        if ($this->scope & Notice::GROUP_SCOPE) {
+
+            // XXX: just query for the single membership
+
+            $groups = $this->getGroups();
+
+            $foundOne = false;
+
+            foreach ($groups as $group) {
+                if ($profile->isMember($group)) {
+                    $foundOne = true;
+                    break;
+                }
+            }
+
+            if (!$foundOne) {
+                return false;
+            }
+        }
+
+        // Only for followers of the author
+
+        if ($this->scope & Notice::FOLLOWER_SCOPE) {
+            $author = $this->getProfile();
+            if (!Subscription::exists($profile, $author)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
 }
index b582451350f94551e74b30a8df31ffa21dcfe941..b6b05f6a4fb89ff0d19f6910325b6a03c842d8ea 100644 (file)
@@ -1090,4 +1090,44 @@ class Profile extends Memcached_DataObject
 
         return $profile;
     }
+
+    function canRead(Notice $notice)
+    {
+        if ($notice->scope & Notice::SITE_SCOPE) {
+            $user = $this->getUser();
+            if (empty($user)) {
+                return false;
+            }
+        }
+
+        if ($notice->scope & Notice::ADDRESSEE_SCOPE) {
+            $replies = $notice->getReplies();
+
+            if (!in_array($this->id, $replies)) {
+                $groups = $notice->getGroups();
+
+                $foundOne = false;
+
+                foreach ($groups as $group) {
+                    if ($this->isMember($group)) {
+                        $foundOne = true;
+                        break;
+                    }
+                }
+
+                if (!$foundOne) {
+                    return false;
+                }
+            }
+        }
+
+        if ($notice->scope & Notice::FOLLOWER_SCOPE) {
+            $author = $notice->getProfile();
+            if (!Subscription::exists($this, $author)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
 }
index f648fb3fbf183a30951ea091efd18155bc9d76dc..12c59daae0324a6a1085ca56440e56110c53c5f9 100644 (file)
@@ -337,6 +337,7 @@ location_id = 1
 location_ns = 1
 repeat_of = 1
 object_type = 2
+scope = 1
 
 [notice__keys]
 id = N
index 928186d94d9a69d96b1119b062499519a73bb4f8..3e439e5010e6d0dc24181d81f7b8bfe3283596bd 100644 (file)
@@ -202,6 +202,9 @@ $schema['notice'] = array(
         'location_ns' => array('type' => 'int', 'description' => 'namespace for location'),
         'repeat_of' => array('type' => 'int', 'description' => 'notice this is a repeat of'),
         'object_type' => array('type' => 'varchar', 'length' => 255, 'description' => 'URI representing activity streams object type', 'default' => 'http://activitystrea.ms/schema/1.0/note'),
+        'scope' => array('type' => 'int',
+                         'default' => '1',
+                         'description' => 'bit map for distribution scope; 0 = everywhere; 1 = this server only; 2 = addressees; 4 = followers'),
     ),
     'primary key' => array('id'),
     'unique keys' => array(
index dbba6cd6f0f225a97aeb7a9e888690e4f9497715..addf8768ceb57e0db3b84be1ca96d7947480c784 100644 (file)
@@ -1,14 +1,70 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Notice stream for a conversation
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Cache
+ * @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 ConversationNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Notice stream for a conversation
+ *
+ * @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 ConversationNoticeStream extends ScopingNoticeStream
 {
     function __construct($id)
     {
-        parent::__construct(new RawConversationNoticeStream($id),
-                            'notice:conversation_ids:'.$id);
+        parent::__construct(new CachingNoticeStream(new RawConversationNoticeStream($id),
+                                                    'notice:conversation_ids:'.$id));
     }
 }
 
+/**
+ * Notice stream for a conversation
+ *
+ * @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 RawConversationNoticeStream extends NoticeStream
 {
     protected $id;
index 5aaad5ce5b51f3c9a452342a5c42e1684b7e68c0..987805cf9d970246f9cd8192474f811fb28ac44d 100644 (file)
@@ -1,6 +1,51 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Notice stream for favorites
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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/
+ */
+
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
 
-class FaveNoticeStream extends CachingNoticeStream
+/**
+ * Notice stream for favorites
+ *
+ * @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 FaveNoticeStream extends ScopingNoticeStream
 {
     function __construct($user_id, $own)
     {
@@ -10,10 +55,21 @@ class FaveNoticeStream extends CachingNoticeStream
         } else {
             $key = 'fave:ids_by_user:'.$user_id;
         }
-        parent::__construct($stream, $key);
+        parent::__construct(new CachingNoticeStream($stream, $key));
     }
 }
 
+/**
+ * Raw notice stream for favorites
+ *
+ * @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 RawFaveNoticeStream extends NoticeStream
 {
     protected $user_id;
index fddc5d33ce930cb72af4d7a7c431ae95273a8536..8c01893634d55fe030a3a6dced098c73ca8b6d1e 100644 (file)
@@ -1,22 +1,67 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Stream of notices that reference an URL
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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 FileNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+class FileNoticeStream extends ScopingNoticeStream
 {
     function __construct($file)
     {
-        parent::__construct(new RawFileNoticeStream($file),
-                            'file:notice-ids:'.$this->url);
+        parent::__construct(new CachingNoticeStream(new RawFileNoticeStream($file),
+                                                    'file:notice-ids:'.$this->url));
     }
 }
 
+/**
+ * Raw stream for a file
+ *
+ * @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 RawFileNoticeStream extends NoticeStream
 {
     protected $file = null;
 
     function __construct($file)
     {
-        $this->file = $file;
         parent::__construct();
+        $this->file = $file;
     }
 
     /**
diff --git a/lib/filteringnoticestream.php b/lib/filteringnoticestream.php
new file mode 100644 (file)
index 0000000..a3bdc08
--- /dev/null
@@ -0,0 +1,115 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * A notice stream that filters its upstream content
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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/
+ */
+
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * A class for presenting a filtered notice stream based on an upstream 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/
+ */
+
+abstract class FilteringNoticeStream extends NoticeStream
+{
+    protected $upstream;
+
+    function __construct($upstream)
+    {
+        $this->upstream = $upstream;
+    }
+
+    abstract function filter($notice);
+
+    function getNotices($offset, $limit, $sinceId, $maxId)
+    {
+        // "offset" is virtual; we have to get a lot
+        $total = $offset + $limit;
+
+        $filtered = array();
+
+        $startAt = 0;
+        $askFor  = $total;
+
+        // Keep going till we have $total notices in $notices array,
+        // or we get nothing from upstream.
+
+        $results = null;
+
+        do {
+
+            $raw = $this->upstream->getNotices($startAt, $askFor, $sinceId, $maxId);
+
+            $results = $raw->N;
+
+            if ($results == 0) {
+                break;
+            }
+
+            while ($raw->fetch()) {
+                if ($this->filter($raw)) {
+                    $filtered[] = clone($raw);
+                    if (count($filtered >= $total)) {
+                        break;
+                    }
+                }
+            }
+
+            // XXX: make these smarter; factor hit rate into $askFor
+
+            $startAt += $askFor;
+            $askFor   = max($total - count($filtered), NOTICES_PER_PAGE);
+
+        } while (count($filtered) < $total && $results !== 0);
+
+        return new ArrayWrapper(array_slice($filtered, $offset, $limit));
+    }
+
+    function getNoticeIds($offset, $limit, $sinceId, $maxId)
+    {
+        $notices = $this->getNotices($offset, $limit, $sinceId, $maxId);
+
+        $ids = array();
+
+        while ($notices->fetch()) {
+            $ids[] = $notice->id;
+        }
+
+        return $ids;
+    }
+}
index 4b4fb0022954f3b758e373069219dff9e4b9718b..22d94d0482fcc7f1ee54884dfc692473f41ec3e0 100644 (file)
@@ -1,14 +1,68 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Stream of notices for a group
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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 GroupNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Stream of notices for a group
+ *
+ * @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 GroupNoticeStream extends ScopingNoticeStream
 {
     function __construct($group)
     {
-        parent::__construct(new RawGroupNoticeStream($group),
-                            'user_group:notice_ids:' . $group->id);
+        parent::__construct(new CachingNoticeStream(new RawGroupNoticeStream($group),
+                                                    'user_group:notice_ids:' . $group->id));
     }
 }
 
+/**
+ * Stream of notices for a group
+ *
+ * @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 RawGroupNoticeStream extends NoticeStream
 {
     protected $group;
index f62b787b04d5109b8653c47266ac598d6d3b3d1d..7ea653f8c8c2a1bcc31bfabc6ad033c5f643c2d0 100644 (file)
@@ -45,12 +45,12 @@ if (!defined('STATUSNET')) {
  * @link      http://status.net/
  */
 
-class ProfileNoticeStream extends CachingNoticeStream
+class ProfileNoticeStream extends ScopingNoticeStream
 {
     function __construct($profile)
     {
-        parent::__construct(new RawProfileNoticeStream($profile),
-                            'profile:notice_ids:' . $profile->id);
+        parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile),
+                                                    'profile:notice_ids:' . $profile->id));
     }
 }
 
index 6a861ca26e68109921ca1acd4042a0c2602df88b..5c8d313d46591dd3650d80a6bd78352a9aceca48 100644 (file)
@@ -1,13 +1,70 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Public stream
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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 PublicNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * 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 PublicNoticeStream extends ScopingNoticeStream
 {
     function __construct()
     {
-        parent::__construct(new RawPublicNoticeStream(), 'public');
+        parent::__construct(new CachingNoticeStream(new RawPublicNoticeStream(),
+                                                    'public'));
     }
 }
 
+/**
+ * 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 RawPublicNoticeStream extends NoticeStream
 {
     function getNoticeIds($offset, $limit, $since_id, $max_id)
index 2c4c00ebf9f056fdab9a43103167cf156deb2f90..98c1583d6a596481a252a9ef7d1ad14b32358296 100644 (file)
@@ -1,14 +1,70 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Stream of notices repeated by me
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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 RepeatedByMeNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Stream of notices repeated by me
+ *
+ * @category  General
+ * @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 RepeatedByMeNoticeStream extends ScopingNoticeStream
 {
     function __construct($user)
     {
-        parent::__construct(new RawRepeatedByMeNoticeStream($user),
-                            'user:repeated_by_me:'.$user->id);
+        parent::__construct(new CachingNoticeStream(new RawRepeatedByMeNoticeStream($user),
+                                                    'user:repeated_by_me:'.$user->id));
     }
 }
 
+/**
+ * Raw stream of notices repeated by me
+ *
+ * @category  General
+ * @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 RawRepeatedByMeNoticeStream extends NoticeStream
 {
     protected $user;
index 1441908e5aeb6e41b2ac9fe038217fa89c082987..f51fc9e4472d49b1d041f01cbeae762e60875497 100644 (file)
@@ -1,14 +1,69 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Stream of notices that are repeats of mine
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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 RepeatsOfMeNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Stream of notices that are repeats of mine
+ *
+ * @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 RepeatsOfMeNoticeStream extends ScopingNoticeStream
 {
     function __construct($user)
     {
-        parent::__construct(new RawRepeatsOfMeNoticeStream($user),
-                            'user:repeats_of_me:'.$user->id);
+        parent::__construct(new CachingNoticeStream(new RawRepeatsOfMeNoticeStream($user),
+                                                    'user:repeats_of_me:'.$user->id));
     }
 }
 
+/**
+ * Raw stream of notices that are repeats of mine
+ *
+ * @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 RawRepeatsOfMeNoticeStream extends NoticeStream
 {
     protected $user;
index d0ae5fc4a7309b44746237543187263bef8d4876..9de8d4efaf9c49ca62b17e48e819537c2f7b4dba 100644 (file)
@@ -1,14 +1,70 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Stream of mentions of me
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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 ReplyNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Stream of mentions of me
+ *
+ * @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 ReplyNoticeStream extends ScopingNoticeStream
 {
     function __construct($userId)
     {
-        parent::__construct(new RawReplyNoticeStream($userId),
-                            'reply:stream:' . $userId);
+        parent::__construct(new CachingNoticeStream(new RawReplyNoticeStream($userId),
+                                                    'reply:stream:' . $userId));
     }
 }
 
+/**
+ * Raw stream of mentions of me
+ *
+ * @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 RawReplyNoticeStream extends NoticeStream
 {
     protected $userId;
diff --git a/lib/scopingnoticestream.php b/lib/scopingnoticestream.php
new file mode 100644 (file)
index 0000000..a7ecbcd
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Filtering notice stream that recognizes notice scope
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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/
+ */
+
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Class comment
+ *
+ * @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 ScopingNoticeStream extends FilteringNoticeStream
+{
+    protected $profile;
+
+    function __construct($upstream, $profile = null)
+    {
+        parent::__construct($upstream);
+
+        if (empty($profile)) {
+            $user = common_current_user();
+            if (!empty($user)) {
+                $profile = $user->getProfile();
+            }
+        }
+        $this->profile = $profile;
+    }
+
+    /**
+     * Only return notices where the profile is in scope
+     *
+     * @param Notice $notice The notice to check
+     *
+     * @return boolean whether to include the notice
+     */
+
+    function filter($notice)
+    {
+        return $notice->inScope($this->profile);
+    }
+    
+}
index 291d3d6eb0de1d511f5ad3cb01b6bcdc27777bd8..83c304ed8ffedce35d2797e9f2b53014b56b35f1 100644 (file)
@@ -1,14 +1,70 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Stream of notices by a profile with a given tag
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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 TaggedProfileNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Stream of notices with a given profile and tag
+ *
+ * @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 TaggedProfileNoticeStream extends ScopingNoticeStream
 {
     function __construct($profile, $tag)
     {
-        parent::__construct(new RawTaggedProfileNoticeStream($profile, $tag),
-                            'profile:notice_ids_tagged:'.$profile->id.':'.Cache::keyize($tag));
+        parent::__construct(new CachingNoticeStream(new RawTaggedProfileNoticeStream($profile, $tag),
+                                                    'profile:notice_ids_tagged:'.$profile->id.':'.Cache::keyize($tag)));
     }
 }
 
+/**
+ * Raw stream of notices with a given profile and tag
+ *
+ * @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 RawTaggedProfileNoticeStream extends NoticeStream
 {
     protected $profile;
index 0e287744dd0215b4c8bf6ec5b418266987dafaa8..1dcf9f14bb9b4f12e951daad8462783bfafc7f7b 100644 (file)
@@ -1,14 +1,70 @@
 <?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Stream of notices with a given tag
+ * 
+ * PHP version 5
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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 TagNoticeStream extends CachingNoticeStream
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Stream of notices with a given tag
+ *
+ * @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 TagNoticeStream extends ScopingNoticeStream
 {
     function __construct($tag)
     {
-        parent::__construct(new RawTagNoticeStream($tag),
-                            'notice_tag:notice_ids:' . Cache::keyize($tag));
+        parent::__construct(new CachingNoticeStream(new RawTagNoticeStream($tag),
+                                                    'notice_tag:notice_ids:' . Cache::keyize($tag)));
     }
 }
 
+/**
+ * Raw stream of notices with a given tag
+ *
+ * @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 RawTagNoticeStream extends NoticeStream
 {
     protected $tag;