]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/showgroup.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / actions / showgroup.php
index eb12389029a096dd0373ae7ed523ddc517092d62..9a12bafaf62aba1b4ff763738f1125c558f8cf19 100644 (file)
@@ -122,9 +122,9 @@ class ShowgroupAction extends GroupDesignAction
             return false;
         }
 
-        $this->group = User_group::staticGet('nickname', $nickname);
+        $local = Local_group::staticGet('nickname', $nickname);
 
-        if (!$this->group) {
+        if (!$local) {
             $alias = Group_alias::staticGet('alias', $nickname);
             if ($alias) {
                 $args = array('id' => $alias->group_id);
@@ -134,11 +134,19 @@ class ShowgroupAction extends GroupDesignAction
                 common_redirect(common_local_url('groupbyid', $args), 301);
                 return false;
             } else {
+                common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
         }
 
+        $this->group = User_group::staticGet('id', $local->group_id);
+
+        if (!$this->group) {
+            $this->clientError(_('No such group.'), 404);
+            return false;
+        }
+
         common_set_returnto($this->selfUrl());
 
         return true;
@@ -213,7 +221,8 @@ class ShowgroupAction extends GroupDesignAction
 
     function showGroupProfile()
     {
-        $this->elementStart('div', 'entity_profile vcard author');
+        $this->elementStart('div', array('id' => 'i',
+                                         'class' => 'entity_profile vcard author'));
 
         $this->element('h2', null, _('Group profile'));
 
@@ -293,19 +302,26 @@ class ShowgroupAction extends GroupDesignAction
         $this->element('h2', null, _('Group actions'));
         $this->elementStart('ul');
         $this->elementStart('li', 'entity_subscribe');
-        $cur = common_current_user();
-        if ($cur) {
-            if ($cur->isMember($this->group)) {
-                $lf = new LeaveForm($this, $this->group);
-                $lf->show();
-            } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
-                $jf = new JoinForm($this, $this->group);
-                $jf->show();
+        if (Event::handle('StartGroupSubscribe', array($this, $this->group))) {
+            $cur = common_current_user();
+            if ($cur) {
+                if ($cur->isMember($this->group)) {
+                    $lf = new LeaveForm($this, $this->group);
+                    $lf->show();
+                } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
+                    $jf = new JoinForm($this, $this->group);
+                    $jf->show();
+                }
             }
+            Event::handle('EndGroupSubscribe', array($this, $this->group));
         }
-
         $this->elementEnd('li');
-
+        if ($cur->hasRight(Right::DELETEGROUP)) {
+            $this->elementStart('li', 'entity_delete');
+            $df = new DeleteGroupForm($this, $this->group);
+            $df->show();
+            $this->elementEnd('li');
+        }
         $this->elementEnd('ul');
         $this->elementEnd('div');
     }
@@ -378,18 +394,23 @@ class ShowgroupAction extends GroupDesignAction
         $this->elementStart('div', array('id' => 'entity_members',
                                          'class' => 'section'));
 
-        $this->element('h2', null, _('Members'));
+        if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
 
-        $pml = new ProfileMiniList($member, $this);
-        $cnt = $pml->show();
-        if ($cnt == 0) {
-             $this->element('p', null, _('(None)'));
-        }
+            $this->element('h2', null, _('Members'));
+
+            $gmml = new GroupMembersMiniList($member, $this);
+            $cnt = $gmml->show();
+            if ($cnt == 0) {
+                $this->element('p', null, _('(None)'));
+            }
+
+            if ($cnt > MEMBERS_PER_SECTION) {
+                $this->element('a', array('href' => common_local_url('groupmembers',
+                                                                     array('nickname' => $this->group->nickname))),
+                               _('All members'));
+            }
 
-        if ($cnt > MEMBERS_PER_SECTION) {
-            $this->element('a', array('href' => common_local_url('groupmembers',
-                                                                 array('nickname' => $this->group->nickname))),
-                           _('All members'));
+            Event::handle('EndShowGroupMembersMiniList', array($this));
         }
 
         $this->elementEnd('div');
@@ -415,14 +436,6 @@ class ShowgroupAction extends GroupDesignAction
 
     function showStatistics()
     {
-        // XXX: WORM cache this
-        $members = $this->group->getMembers();
-        $members_count = 0;
-        /** $member->count() doesn't work. */
-        while ($members->fetch()) {
-            $members_count++;
-        }
-
         $this->elementStart('div', array('id' => 'entity_statistics',
                                          'class' => 'section'));
 
@@ -436,7 +449,7 @@ class ShowgroupAction extends GroupDesignAction
 
         $this->elementStart('dl', 'entity_members');
         $this->element('dt', null, _('Members'));
-        $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
+        $this->element('dd', null, $this->group->getMemberCount());
         $this->elementEnd('dl');
 
         $this->elementEnd('div');
@@ -492,3 +505,26 @@ class GroupAdminSection extends ProfileSection
         return null;
     }
 }
+
+class GroupMembersMiniList extends ProfileMiniList
+{
+    function newListItem($profile)
+    {
+        return new GroupMembersMiniListItem($profile, $this->action);
+    }
+}
+
+class GroupMembersMiniListItem extends ProfileMiniListItem
+{
+    function linkAttributes()
+    {
+        $aAttrs = parent::linkAttributes();
+
+        if (common_config('nofollow', 'members')) {
+            $aAttrs['rel'] .= ' nofollow';
+        }
+
+        return $aAttrs;
+    }
+}
+