From 8ef9d75bbc9fd1fd322872a95882fca2c792279c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 17 Mar 2011 13:07:17 -0700 Subject: [PATCH 1/4] Work in progress: faves in the threaded reply area --- lib/threadednoticelist.php | 63 +++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index 919c912831..1328ff74dc 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -183,6 +183,8 @@ class ThreadedNoticeListItem extends NoticeListItem if ($notices) { $this->out->elementStart('ul', 'notices threaded-replies xoxo'); + $item = new ThreadedNoticeListFavesItem($notice, $this->out); + $hasFaves = $item->show(); if ($moreCutoff) { $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out); $item->show(); @@ -316,4 +318,63 @@ 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() + { + return $this->showFaves(); + } + + function showFaves() + { + $this->out->text('(QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ)'); + return 0; + // @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('%s', + htmlspecialchars($profile->profileurl), + htmlspecialchars($profile->getBestName()), + htmlspecialchars($profile->nickname)); + } + } + + if ($links) { + $count = count($links); + $msg = _m('%1$s has favored this notice', '%1$s have favored this notice', $count); + $out = sprintf($msg, implode(', ', $links)); + + $this->out->elementStart('li', array('class' => 'notice-faves')); + $this->out->raw($out); + $this->out->elementEnd('li'); + return $count; + } else { + return 0; + } + } +} From 6c236ab0ff4309c883d7856324f409e043f7db56 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 17 Mar 2011 13:25:20 -0700 Subject: [PATCH 2/4] work in progress --- lib/threadednoticelist.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index 1328ff74dc..6fb059491a 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -183,7 +183,7 @@ class ThreadedNoticeListItem extends NoticeListItem if ($notices) { $this->out->elementStart('ul', 'notices threaded-replies xoxo'); - $item = new ThreadedNoticeListFavesItem($notice, $this->out); + $item = new ThreadedNoticeListFavesItem($this->notice, $this->out); $hasFaves = $item->show(); if ($moreCutoff) { $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out); @@ -196,7 +196,7 @@ class ThreadedNoticeListItem extends NoticeListItem // @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'); @@ -327,13 +327,6 @@ class ThreadedNoticeListFavesItem extends NoticeListItem { function show() { - return $this->showFaves(); - } - - function showFaves() - { - $this->out->text('(QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ)'); - return 0; // @fixme caching & scalability! $fave = new Fave(); $fave->notice_id = $this->notice->id; @@ -366,7 +359,13 @@ class ThreadedNoticeListFavesItem extends NoticeListItem if ($links) { $count = count($links); - $msg = _m('%1$s has favored this notice', '%1$s have favored this notice', $count); + 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, implode(', ', $links)); $this->out->elementStart('li', array('class' => 'notice-faves')); From 58d39153c616be71a7b7af1bab2038e1471f0f37 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 17 Mar 2011 13:51:55 -0700 Subject: [PATCH 3/4] Favored lists in progress: 'foo, bar and baz' --- lib/threadednoticelist.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index 6fb059491a..28e6aa5aa8 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -361,12 +361,12 @@ class ThreadedNoticeListFavesItem extends NoticeListItem $count = count($links); if ($count == 1 && $you) { // darn first person being different from third person! - $msg = _m('FAVELIST', 'You have favored this notice'); + $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); + // 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, implode(', ', $links)); + $out = sprintf($msg, $this->magicList($links)); $this->out->elementStart('li', array('class' => 'notice-faves')); $this->out->raw($out); @@ -376,4 +376,18 @@ class ThreadedNoticeListFavesItem extends NoticeListItem return 0; } } + + 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)); + } + } } From ed6d5c6e7a86d4e548a46f456f0314f1fbbe1c61 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 17 Mar 2011 14:19:03 -0700 Subject: [PATCH 4/4] Initial inline listing of favoriters --- lib/threadednoticelist.php | 44 ++++++++++++++++++++++++++++++++------ theme/neo/css/display.css | 3 ++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index 28e6aa5aa8..87e2a7e39a 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -181,10 +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'); - $item = new ThreadedNoticeListFavesItem($this->notice, $this->out); - $hasFaves = $item->show(); if ($moreCutoff) { $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out); $item->show(); @@ -193,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($this->notice, $this->out); $item->show(); } - $this->out->elementEnd('ul'); } + $this->out->elementEnd('ul'); } parent::showEnd(); @@ -229,6 +231,13 @@ class ThreadedNoticeListSubItem extends NoticeListItem { // } + + function showEnd() + { + $item = new ThreadedNoticeListInlineFavesItem($this->notice, $this->out); + $hasFaves = $item->show(); + parent::showEnd(); + } } /** @@ -368,15 +377,25 @@ class ThreadedNoticeListFavesItem extends NoticeListItem } $out = sprintf($msg, $this->magicList($links)); - $this->out->elementStart('li', array('class' => 'notice-faves')); + $this->showStart(); $this->out->raw($out); - $this->out->elementEnd('li'); + $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) { @@ -391,3 +410,16 @@ class ThreadedNoticeListFavesItem extends NoticeListItem } } } + +class ThreadedNoticeListInlineFavesItem extends ThreadedNoticeListFavesItem +{ + function showStart() + { + $this->out->elementStart('div', array('class' => 'entry-content notice-faves')); + } + + function showEnd() + { + $this->out->elementEnd('div'); + } +} diff --git a/theme/neo/css/display.css b/theme/neo/css/display.css index 643a1f29dd..ee3c13624f 100644 --- a/theme/neo/css/display.css +++ b/theme/neo/css/display.css @@ -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;