From 9e5c71e701a5f1a6647a2dadcf7d68746c9b968e Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 7 Jan 2016 12:58:14 +0100 Subject: [PATCH] Fixed group representation in Directory plugin, also some ->raw calls --- classes/Profile.php | 12 ++++++++ classes/User_group.php | 13 +------- plugins/Directory/lib/sortablegrouplist.php | 30 +++++++------------ .../lib/sortablesubscriptionlist.php | 24 ++++----------- 4 files changed, 30 insertions(+), 49 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index 554215a973..8e12dfc6ee 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -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); diff --git a/classes/User_group.php b/classes/User_group.php index b95ab228f6..497e301dad 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -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() diff --git a/plugins/Directory/lib/sortablegrouplist.php b/plugins/Directory/lib/sortablegrouplist.php index ab00068f6d..94ee054df3 100644 --- a/plugins/Directory/lib/sortablegrouplist.php +++ b/plugins/Directory/lib/sortablegrouplist.php @@ -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) - .''; - } - + 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'); } diff --git a/plugins/Directory/lib/sortablesubscriptionlist.php b/plugins/Directory/lib/sortablesubscriptionlist.php index 719834bc91..ec8874b2e5 100644 --- a/plugins/Directory/lib/sortablesubscriptionlist.php +++ b/plugins/Directory/lib/sortablesubscriptionlist.php @@ -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) - .''; - } - + if ($this->profile->getDescription()) { $this->out->elementStart('p', 'note'); - $this->out->raw($bio); + $this->out->text($this->profile->getDescription()); $this->out->elementEnd('p'); } }