Fixed group representation in Directory plugin, also some ->raw calls
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 7 Jan 2016 11:58:14 +0000 (12:58 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 7 Jan 2016 11:58:14 +0000 (12:58 +0100)
classes/Profile.php
classes/User_group.php
plugins/Directory/lib/sortablegrouplist.php
plugins/Directory/lib/sortablesubscriptionlist.php

index 554215a973f48b7adf320e7e1eb9dbd18fde1d55..8e12dfc6ee5cbad32427996db1e0dc37fc6186d6 100644 (file)
@@ -1422,6 +1422,18 @@ class Profile extends Managed_DataObject
      */
     public function getUrl()
     {
+        $url = null;
+        if ($this->isGroup()) {
+            // FIXME: Get rid of this event, it fills no real purpose, data should be in Profile->profileurl (replaces User_group->mainpage)
+            if (Event::handle('StartUserGroupHomeUrl', array($this->getGroup(), &$url))) {
+                $url = $this->isLocal()
+                        ? common_local_url('showgroup', array('nickname' => $this->getNickname()))
+                        : $this->profileurl;
+            }
+            Event::handle('EndUserGroupHomeUrl', array($this->getGroup(), $url));
+        } else {
+            $url = $this->profileurl;
+        }
         if (empty($this->profileurl) ||
                 !filter_var($this->profileurl, FILTER_VALIDATE_URL)) {
             throw new InvalidUrlException($this->profileurl);
index b95ab228f6f5ecc00f51ffc21933aefa3a216f46..497e301dade37c33b8de48f00978c692ae825ec9 100644 (file)
@@ -115,18 +115,7 @@ class User_group extends Managed_DataObject
 
     function homeUrl()
     {
-        $url = null;
-        if (Event::handle('StartUserGroupHomeUrl', array($this, &$url))) {
-            // normally stored in mainpage, but older ones may be null
-            if (!empty($this->mainpage)) {
-                $url = $this->mainpage;
-            } elseif ($this->isLocal()) {
-                $url = common_local_url('showgroup',
-                                        array('nickname' => $this->nickname));
-            }
-        }
-        Event::handle('EndUserGroupHomeUrl', array($this, &$url));
-        return $url;
+        $this->getProfile()->getUrl();
     }
 
     function getUri()
index ab00068f6d20a5f438794e1986dc3d07a98db8b8..94ee054df3a076a914fddea0fb54c62ff3665d54 100644 (file)
@@ -105,7 +105,7 @@ class SortableGroupList extends SortableSubscriptionList
         $this->out->elementStart('tbody');
     }
 
-    function newListItem($profile)
+    function newListItem(Profile $profile)
     {
         return new SortableGroupListItem($profile, $this->owner, $this->action);
     }
@@ -115,28 +115,20 @@ class SortableGroupListItem extends SortableSubscriptionListItem
 {
     function showHomepage()
     {
-        if (!empty($this->profile->homepage)) {
+        if ($this->profile->getHomepage()) {
             $this->out->text(' ');
             $aAttrs = $this->homepageAttributes();
             $this->out->elementStart('a', $aAttrs);
-            $this->out->raw($this->highlight($this->profile->homepage));
+            $this->out->text($this->profile->getHomepage());
             $this->out->elementEnd('a');
         }
     }
 
     function showDescription()
     {
-        if (!empty($this->profile->description)) {
-            $cutoff      = 140; // XXX Should this be configurable?
-            $description = htmlspecialchars($this->profile->description);
-
-            if (mb_strlen($description) > $cutoff) {
-                $description = mb_substr($description, 0, $cutoff - 1)
-                    .'<a href="' . $this->profile->homeUrl() .'">…</a>';
-            }
-
+        if ($this->profile->getDescription()) {
             $this->out->elementStart('p', 'note');
-            $this->out->raw($description);
+            $this->out->text($this->profile->getDescription());
             $this->out->elementEnd('p');
         }
 
@@ -181,8 +173,8 @@ class SortableGroupListItem extends SortableSubscriptionListItem
     {
         $this->startProfile();
 
-        $this->showAvatar($this->profile->getProfile());
-        $this->out->element('a', array('href'  => $this->profile->homeUrl(),
+        $this->showAvatar($this->profile);
+        $this->out->element('a', array('href'  => $this->profile->getUrl(),
                                             'class' => 'p-org p-nickname',
                                             'rel'   => 'contact group'),
                                  $this->profile->getNickname());
@@ -231,7 +223,7 @@ class SortableGroupListItem extends SortableSubscriptionListItem
             $this->out->elementStart('li', 'entity_subscribe');
             // XXX: special-case for user looking at own
             // subscriptions page
-            if ($user->isMember($this->profile)) {
+            if ($user->isMember($this->profile->getGroup())) {
                 $lf = new LeaveForm($this->out, $this->profile);
                 $lf->show();
             } else if (!Group_block::isBlocked($this->profile, $user->getProfile())) {
@@ -246,7 +238,7 @@ class SortableGroupListItem extends SortableSubscriptionListItem
     function showMemberCount()
     {
         $this->out->elementStart('td', 'entry_member_count');
-        $this->out->raw($this->profile->getMemberCount());
+        $this->out->text($this->profile->getGroup()->getMemberCount());
         $this->out->elementEnd('td');
     }
 
@@ -254,7 +246,7 @@ class SortableGroupListItem extends SortableSubscriptionListItem
     {
         $this->out->elementStart('td', 'entry_created');
         // @todo FIXME: Should we provide i18n for timestamps in core?
-        $this->out->raw(date('j M Y', strtotime($this->profile->created)));
+        $this->out->text(date('j M Y', strtotime($this->profile->created)));
         $this->out->elementEnd('td');
     }
 
@@ -262,7 +254,7 @@ class SortableGroupListItem extends SortableSubscriptionListItem
     {
         $this->out->elementStart('td', 'entry_admins');
         // @todo
-        $this->out->raw('gargargar');
+        $this->out->text('gargargar');
         $this->out->elementEnd('td');
     }
 
index 719834bc917d3aa9c5e17a74c0e63e9470646725..ec8874b2e539c586915e6638c1b79b2e540e0d90 100644 (file)
@@ -114,7 +114,7 @@ class SortableSubscriptionList extends SubscriptionList
         $this->out->elementEnd('table');
     }
 
-    function newListItem($profile)
+    function newListItem(Profile $profile)
     {
         return new SortableSubscriptionListItem($profile, $this->owner, $this->action);
     }
@@ -197,41 +197,29 @@ class SortableSubscriptionListItem extends SubscriptionListItem
     function showSubscriberCount()
     {
         $this->out->elementStart('td', 'entry_subscriber_count');
-        $this->out->raw($this->profile->subscriberCount());
+        $this->out->text($this->profile->subscriberCount());
         $this->out->elementEnd('td');
     }
 
     function showCreatedDate()
     {
         $this->out->elementStart('td', 'entry_created');
-        $this->out->raw(date('j M Y', strtotime($this->profile->created)));
+        $this->out->text(date('j M Y', strtotime($this->profile->created)));
         $this->out->elementEnd('td');
     }
 
     function showNoticeCount()
     {
         $this->out->elementStart('td', 'entry_notice_count');
-        $this->out->raw($this->profile->noticeCount());
+        $this->out->text($this->profile->noticeCount());
         $this->out->elementEnd('td');
     }
 
-    /**
-     * Overrided to truncate the bio if it's real long, because it
-     * looks better that way in the SortableSubscriptionList's table
-     */
     function showBio()
     {
-        if (!empty($this->profile->bio)) {
-            $cutoff = 140; // XXX Should this be configurable?
-            $bio    = htmlspecialchars($this->profile->bio);
-
-            if (mb_strlen($bio) > $cutoff) {
-                $bio = mb_substr($bio, 0, $cutoff - 1)
-                    .'<a href="' . $this->profile->profileurl .'">…</a>';
-            }
-
+        if ($this->profile->getDescription()) {
             $this->out->elementStart('p', 'note');
-            $this->out->raw($bio);
+            $this->out->text($this->profile->getDescription());
             $this->out->elementEnd('p');
         }
     }