From 90e6eab68e6d6d020b0c227727d6733678a6e106 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 14 Apr 2011 16:57:50 -0400 Subject: [PATCH] show user's lists in sidebar --- classes/Profile.php | 34 +++++++++++++++++++ classes/Profile_list.php | 11 +++++++ lib/profileaction.php | 71 ++++++++++++++++++++++++++-------------- 3 files changed, 92 insertions(+), 24 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index 6c7c182345..b44ad77dd2 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -1323,4 +1323,38 @@ class Profile extends Memcached_DataObject } return $profile; } + + function getLists($offset, $limit) + { + $ids = array(); + + $keypart = sprintf('profile:lists:%d', $this->id); + + $idstr = self::cacheGet($keypart); + + if ($idstr !== false) { + $ids = explode(',', $idstr); + } else { + $list = new Profile_list(); + $list->selectAdd(); + $list->selectAdd('id'); + $list->tagger = $this->id; + + if ($list->find()) { + while ($list->fetch()) { + $ids[] = $list->id; + } + } + + self::cacheSet($keypart, implode(',', $ids)); + } + + $lists = array(); + + foreach ($ids as $id) { + $lists[] = Profile_list::staticGet('id', $id); + } + + return new ArrayWrapper($lists); + } } diff --git a/classes/Profile_list.php b/classes/Profile_list.php index 7de1d15730..17c2ffd4f4 100644 --- a/classes/Profile_list.php +++ b/classes/Profile_list.php @@ -326,6 +326,8 @@ class Profile_list extends Memcached_DataObject Profile_tag::cleanup($this); Profile_tag_subscription::cleanup($this); + self::blow('profile:lists:%d', $this->tagger); + return parent::delete(); } @@ -910,4 +912,13 @@ class Profile_list extends Memcached_DataObject return new ArrayWrapper($wrapped); } } + + function insert() + { + $result = parent::insert(); + if ($result) { + self::blow('profile:lists:%d', $this->tagger); + } + return $result; + } } diff --git a/lib/profileaction.php b/lib/profileaction.php index 59682d5505..4f2a403e28 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -97,8 +97,7 @@ class ProfileAction extends OwnerDesignAction $this->showSubscriptions(); $this->showSubscribers(); $this->showGroups(); - $this->showListsFor(); - $this->showListSubscriptions(); + $this->showLists(); $this->showStatistics(); } @@ -180,28 +179,6 @@ class ProfileAction extends OwnerDesignAction $this->elementEnd('div'); } - function showListsFor() - { - if (Event::handle('StartShowListsForSection', array($this))) { - - $section = new PeopletagsForUserSection($this, $this->profile); - $section->show(); - - Event::handle('EndShowListsForSection', array($this)); - } - } - - function showListSubscriptions() - { - if (Event::handle('StartShowListSubscriptionsSection', array($this))) { - - $section = new PeopletagSubscriptionsSection($this, $this->profile); - $section->show(); - - Event::handle('EndShowListSubscriptionsSection', array($this)); - } - } - function showStatistics() { $notice_count = $this->profile->noticeCount(); @@ -305,6 +282,52 @@ class ProfileAction extends OwnerDesignAction } $this->elementEnd('div'); } + + function showLists() + { + $lists = $this->profile->getLists(); + + if ($lists->N > 0) { + $this->elementStart('div', array('id' => 'entity_lists', + 'class' => 'section')); + + if (Event::handle('StartShowListsMiniList', array($this))) { + + $this->elementStart('h2'); + // TRANS: H2 text for user list membership statistics. + $this->statsSectionLink('userlists', _('Lists')); + $this->text(' '); + $this->text($lists->N); + $this->elementEnd('h2'); + + $this->elementStart('ul'); + + $cur = common_current_user(); + + while ($lists->fetch()) { + if (!$lists->private || + ($lists->private && !empty($cur) && $cur->id == $profile->id)) { + if (!empty($lists->mainpage)) { + $url = $lists->mainpage; + } else { + $url = common_local_url('showprofiletag', + array('tagger' => $this->profile->nickname, + 'tag' => $lists->tag)); + } + $this->elementStart('li'); + $this->element('a', array('href' => $url), + $lists->tag); + $this->elementEnd('li'); + } + } + + $this->elementEnd('ul'); + + Event::handle('EndShowListsMiniList', array($this)); + } + $this->elementEnd('div'); + } + } } class SubscribersMiniList extends ProfileMiniList -- 2.39.5