]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'faves' into 1.0.x
authorBrion Vibber <brion@pobox.com>
Thu, 17 Mar 2011 21:48:14 +0000 (14:48 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 17 Mar 2011 21:48:14 +0000 (14:48 -0700)
lib/threadednoticelist.php
theme/neo/css/display.css

index 919c9128311ed6be4df361132944c101d2e4826b..87e2a7e39a48dbf5127015663f754cc8a3c41790 100644 (file)
@@ -181,8 +181,10 @@ class ThreadedNoticeListItem extends NoticeListItem
                 $notices[] = clone($notice); // *grumble* inefficient as hell
             }
 
+            $this->out->elementStart('ul', 'notices threaded-replies xoxo');
+            $item = new ThreadedNoticeListFavesItem($this->notice, $this->out);
+            $hasFaves = $item->show();
             if ($notices) {
-                $this->out->elementStart('ul', 'notices threaded-replies xoxo');
                 if ($moreCutoff) {
                     $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out);
                     $item->show();
@@ -191,14 +193,16 @@ class ThreadedNoticeListItem extends NoticeListItem
                     $item = new ThreadedNoticeListSubItem($notice, $this->out);
                     $item->show();
                 }
+            }
+            if ($notices || $hasFaves) {
                 // @fixme do a proper can-post check that's consistent
                 // with the JS side
                 if (common_current_user()) {
-                    $item = new ThreadedNoticeListReplyItem($notice, $this->out);
+                    $item = new ThreadedNoticeListReplyItem($this->notice, $this->out);
                     $item->show();
                 }
-                $this->out->elementEnd('ul');
             }
+            $this->out->elementEnd('ul');
         }
 
         parent::showEnd();
@@ -227,6 +231,13 @@ class ThreadedNoticeListSubItem extends NoticeListItem
     {
         //
     }
+
+    function showEnd()
+    {
+        $item = new ThreadedNoticeListInlineFavesItem($this->notice, $this->out);
+        $hasFaves = $item->show();
+        parent::showEnd();
+    }
 }
 
 /**
@@ -316,4 +327,99 @@ class ThreadedNoticeListReplyItem extends NoticeListItem
         $this->out->element('input', array('class' => 'placeholder',
                                            'value' => _('Write a reply...')));
     }
-}
\ No newline at end of file
+}
+
+/**
+ * Placeholder for showing faves...
+ */
+class ThreadedNoticeListFavesItem extends NoticeListItem
+{
+    function show()
+    {
+        // @fixme caching & scalability!
+        $fave = new Fave();
+        $fave->notice_id = $this->notice->id;
+        $fave->find();
+
+        $cur = common_current_user();
+        $profiles = array();
+        $you = false;
+        while ($fave->fetch()) {
+            if ($cur && $cur->id == $fave->user_id) {
+                $you = true;
+            } else {
+                $profiles[] = $fave->user_id;
+            }
+        }
+
+        $links = array();
+        if ($you) {
+            $links[] = _m('FAVELIST', 'You');
+        }
+        foreach ($profiles as $id) {
+            $profile = Profile::staticGet('id', $id);
+            if ($profile) {
+                $links[] = sprintf('<a href="%s" title="%s">%s</a>',
+                                   htmlspecialchars($profile->profileurl),
+                                   htmlspecialchars($profile->getBestName()),
+                                   htmlspecialchars($profile->nickname));
+            }
+        }
+
+        if ($links) {
+            $count = count($links);
+            if ($count == 1 && $you) {
+                // darn first person being different from third person!
+                $msg = _m('FAVELIST', 'You have favored this notice.');
+            } else {
+                // if 'you' is the first item, 
+                $msg = _m('FAVELIST', '%1$s has favored this notice.', '%1$s have favored this notice.', $count);
+            }
+            $out = sprintf($msg, $this->magicList($links));
+
+            $this->showStart();
+            $this->out->raw($out);
+            $this->showEnd();
+            return $count;
+        } else {
+            return 0;
+        }
+    }
+
+    function showStart()
+    {
+        $this->out->elementStart('li', array('class' => 'notice-data notice-faves'));
+    }
+
+    function showEnd()
+    {
+        $this->out->elementEnd('li');
+    }
+
+    function magicList($items)
+    {
+        if (count($items) == 0) {
+            return '';
+        } else if (count($items) == 1) {
+            return $items[0];
+        } else {
+            $first = array_slice($items, 0, -1);
+            $last = array_slice($items, -1, 1);
+            // TRANS For building a list such as "You, bob, mary and 5 others have favored this notice".
+            return sprintf(_m('FAVELIST', '%1$s and %2$s'), implode(', ', $first), implode(', ', $last));
+        }
+    }
+}
+
+class ThreadedNoticeListInlineFavesItem extends ThreadedNoticeListFavesItem
+{
+    function showStart()
+    {
+        $this->out->elementStart('div', array('class' => 'entry-content notice-faves'));
+    }
+
+    function showEnd()
+    {
+        $this->out->elementEnd('div');
+    }
+}
index 643a1f29dd780733990a6cd56ede841f04111ccd..ee3c13624f82fa0400afba527cde4e42d94c819e 100644 (file)
@@ -577,7 +577,8 @@ div.entry-content a.response:after {
     font-size: 1em;
 }
 
-#content .notice .threaded-replies .notice {
+#content .notice .threaded-replies .notice,
+#content .notice .threaded-replies .notice-data {
     width: 440px;
     min-height: 1px;
     padding-bottom: 14px;