]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
function for checking scope rules for Profile
authorEvan Prodromou <evan@status.net>
Thu, 17 Mar 2011 02:55:14 +0000 (22:55 -0400)
committerEvan Prodromou <evan@status.net>
Tue, 22 Mar 2011 15:56:28 +0000 (11:56 -0400)
classes/Profile.php

index 95662269515af60c546e1ba28df0ebb0d7cce910..fe097753d9d78f9a39442f036fd61d0638bcbaad 100644 (file)
@@ -1156,4 +1156,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;
+    }
 }