]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
show user's lists in sidebar
authorEvan Prodromou <evan@status.net>
Thu, 14 Apr 2011 20:57:50 +0000 (16:57 -0400)
committerEvan Prodromou <evan@status.net>
Thu, 14 Apr 2011 20:57:50 +0000 (16:57 -0400)
classes/Profile.php
classes/Profile_list.php
lib/profileaction.php

index 6c7c18234525f4ab6c5a8794f99161f960c77382..b44ad77dd204a898661ef6996359250776e43246 100644 (file)
@@ -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);
+    }
 }
index 7de1d15730d054f84b04cf70763b3e6bb0417c7c..17c2ffd4f470c78dcadddb9327d43f0f6ad642c7 100644 (file)
@@ -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;
+    }
 }
index 59682d5505e76bf84d967f5cdf2a7c1cec88ce28..4f2a403e28c54750ec72784f7baf59fa327365ba 100644 (file)
@@ -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