]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User_group.php
do our own repeating so we can pass in a uri
[quix0rs-gnu-social.git] / classes / User_group.php
index 6a06583e0b51291e3b8934ac19b51d5be2b40cbd..0b83cfd47dfe2ee93a97c8ab53d2d3fb5ea94dfe 100644 (file)
@@ -91,7 +91,7 @@ class User_group extends Memcached_DataObject
         return Notice::getStreamByIds($ids);
     }
 
-    function _streamDirect($offset, $limit, $since_id, $max_id, $since)
+    function _streamDirect($offset, $limit, $since_id, $max_id)
     {
         $inbox = new Group_inbox();
 
@@ -108,10 +108,6 @@ class User_group extends Memcached_DataObject
             $inbox->whereAdd('notice_id <= ' . $max_id);
         }
 
-        if (!is_null($since)) {
-            $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
-        }
-
         $inbox->orderBy('notice_id DESC');
 
         if (!is_null($offset)) {
@@ -158,6 +154,21 @@ class User_group extends Memcached_DataObject
         return $members;
     }
 
+    function getMemberCount()
+    {
+        // XXX: WORM cache this
+
+        $members = $this->getMembers();
+        $member_count = 0;
+
+        /** $member->count() doesn't work. */
+        while ($members->fetch()) {
+            $member_count++;
+        }
+
+        return $member_count;
+    }
+
     function getAdmins($offset=0, $limit=null)
     {
         $qry =
@@ -283,12 +294,26 @@ class User_group extends Memcached_DataObject
         return true;
     }
 
-    static function getForNickname($nickname)
+    static function getForNickname($nickname, $profile=null)
     {
         $nickname = common_canonical_nickname($nickname);
-        $group = User_group::staticGet('nickname', $nickname);
+
+        // Are there any matching remote groups this profile's in?
+        if ($profile) {
+            $group = $profile->getGroups();
+            while ($group->fetch()) {
+                if ($group->nickname == $nickname) {
+                    // @fixme is this the best way?
+                    return clone($group);
+                }
+            }
+        }
+
+        // If not, check local groups.
+
+        $group = Local_group::staticGet('nickname', $nickname);
         if (!empty($group)) {
-            return $group;
+            return User_group::staticGet('id', $group->group_id);
         }
         $alias = Group_alias::staticGet('alias', $nickname);
         if (!empty($alias)) {
@@ -361,16 +386,15 @@ class User_group extends Memcached_DataObject
 
         if ($source) {
             $xs->elementStart('source');
+            $xs->element('id', null, $this->permalink());
             $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name'));
             $xs->element('link', array('href' => $this->permalink()));
-        }
-
-        if ($source) {
+            $xs->element('updated', null, $this->modified);
             $xs->elementEnd('source');
         }
 
         $xs->element('title', null, $this->nickname);
-        $xs->element('summary', null, $this->description);
+        $xs->element('summary', null, common_xml_safe_str($this->description));
 
         $xs->element('link', array('rel' => 'alternate',
                                    'href' => $this->permalink()));
@@ -380,7 +404,11 @@ class User_group extends Memcached_DataObject
         $xs->element('published', null, common_date_w3dtf($this->created));
         $xs->element('updated', null, common_date_w3dtf($this->modified));
 
-        $xs->element('content', array('type' => 'html'), $this->description);
+        $xs->element(
+            'content',
+            array('type' => 'html'),
+            common_xml_safe_str($this->description)
+        );
 
         $xs->elementEnd('entry');
 
@@ -446,6 +474,11 @@ class User_group extends Memcached_DataObject
 
         $group->query('BEGIN');
 
+        if (empty($uri)) {
+            // fill in later...
+            $uri = null;
+        }
+
         $group->nickname    = $nickname;
         $group->fullname    = $fullname;
         $group->homepage    = $homepage;
@@ -459,6 +492,7 @@ class User_group extends Memcached_DataObject
 
         if (!$result) {
             common_log_db_error($group, 'INSERT', __FILE__);
+            // TRANS: Server exception thrown when creating a group failed.
             throw new ServerException(_('Could not create group.'));
         }
 
@@ -468,6 +502,7 @@ class User_group extends Memcached_DataObject
             $result = $group->update($orig);
             if (!$result) {
                 common_log_db_error($group, 'UPDATE', __FILE__);
+                // TRANS: Server exception thrown when updating a group URI failed.
                 throw new ServerException(_('Could not set group URI.'));
             }
         }
@@ -475,6 +510,7 @@ class User_group extends Memcached_DataObject
         $result = $group->setAliases($aliases);
 
         if (!$result) {
+            // TRANS: Server exception thrown when creating group aliases failed.
             throw new ServerException(_('Could not create aliases.'));
         }
 
@@ -489,6 +525,7 @@ class User_group extends Memcached_DataObject
 
         if (!$result) {
             common_log_db_error($member, 'INSERT', __FILE__);
+            // TRANS: Server exception thrown when setting group membership failed.
             throw new ServerException(_('Could not set group membership.'));
         }
 
@@ -503,6 +540,7 @@ class User_group extends Memcached_DataObject
 
             if (!$result) {
                 common_log_db_error($local_group, 'INSERT', __FILE__);
+                // TRANS: Server exception thrown when saving local group information failed.
                 throw new ServerException(_('Could not save local group info.'));
             }
         }