X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2FUser_group.php;h=0b83cfd47dfe2ee93a97c8ab53d2d3fb5ea94dfe;hb=f7d69c38af60fbc984743d20340bd0fd02fd6d77;hp=64fe024b34de06deeb19495aa4c429bb7f7f1502;hpb=097e3f89b630b7a28f27c96f5e9a036df3ed7710;p=quix0rs-gnu-social.git diff --git a/classes/User_group.php b/classes/User_group.php index 64fe024b34..0b83cfd47d 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -154,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 = @@ -279,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)) { @@ -357,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())); @@ -376,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'); @@ -442,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; @@ -455,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.')); } @@ -464,13 +502,15 @@ class User_group extends Memcached_DataObject $result = $group->update($orig); if (!$result) { common_log_db_error($group, 'UPDATE', __FILE__); - throw new ServerException(_('Could not set group uri.')); + // TRANS: Server exception thrown when updating a group URI failed. + throw new ServerException(_('Could not set group URI.')); } } $result = $group->setAliases($aliases); if (!$result) { + // TRANS: Server exception thrown when creating group aliases failed. throw new ServerException(_('Could not create aliases.')); } @@ -485,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.')); } @@ -499,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.')); } }