123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- <?php
- if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
- class ThreadedNoticeList extends NoticeList
- {
- protected $userProfile;
- function __construct(Notice $notice, Action $out=null, $profile=-1)
- {
- parent::__construct($notice, $out);
- if (is_int($profile) && $profile == -1) {
- $profile = Profile::current();
- }
- $this->userProfile = $profile;
- }
-
- function show()
- {
- $this->out->elementStart('div', array('id' =>'notices_primary'));
-
- $this->out->element('h2', null, _m('HEADER','Notices'));
- $this->out->elementStart('ol', array('class' => 'notices threaded-notices xoxo'));
- $notices = $this->notice->fetchAll();
- $total = count($notices);
- $notices = array_slice($notices, 0, NOTICES_PER_PAGE);
-
- $allnotices = self::_allNotices($notices);
- self::prefill($allnotices);
-
- $conversations = array();
-
- foreach ($notices as $notice) {
-
-
- if ($notice->repeat_of) {
- $orig = Notice::getKV('id', $notice->repeat_of);
- if ($orig instanceof Notice) {
- $notice = $orig;
- }
- }
- $convo = $notice->conversation;
- if (!empty($conversations[$convo])) {
-
- continue;
- }
- $conversations[$convo] = true;
-
- $root = $notice->conversationRoot($this->userProfile);
- if ($root instanceof Notice) {
- $notice = $root;
- }
- try {
- $item = $this->newListItem($notice);
- $item->show();
- } catch (Exception $e) {
-
- common_log(LOG_ERR, $e->getMessage());
- continue;
- }
- }
- $this->out->elementEnd('ol');
- $this->out->elementEnd('div');
- return $total;
- }
- function _allNotices($notices)
- {
- $convId = array();
- foreach ($notices as $notice) {
- $convId[] = $notice->conversation;
- }
- $convId = array_unique($convId);
- $allMap = Notice::listGet('conversation', $convId);
- $allArray = array();
- foreach ($allMap as $convId => $convNotices) {
- $allArray = array_merge($allArray, $convNotices);
- }
- return $allArray;
- }
-
- function newListItem(Notice $notice)
- {
- return new ThreadedNoticeListItem($notice, $this->out, $this->userProfile);
- }
- }
- class ThreadedNoticeListItem extends NoticeListItem
- {
- protected $userProfile = null;
- function __construct(Notice $notice, Action $out=null, $profile=null)
- {
- parent::__construct($notice, $out);
- $this->userProfile = $profile;
- }
- function initialItems()
- {
- return 3;
- }
-
- function showEnd()
- {
- $max = $this->initialItems();
- if (!$this->repeat) {
- $stream = new ConversationNoticeStream($this->notice->conversation, $this->userProfile);
- $notice = $stream->getNotices(0, $max + 2);
- $notices = array();
- $cnt = 0;
- $moreCutoff = null;
- while ($notice->fetch()) {
- if (Event::handle('StartAddNoticeReply', array($this, $this->notice, $notice))) {
-
- if (!empty($notice->repeat_of)) {
- continue;
- }
- if ($notice->id == $this->notice->id) {
-
- continue;
- }
- $cnt++;
- if ($cnt > $max) {
-
- $moreCutoff = clone($notice);
- break;
- }
- $notices[] = clone($notice);
- Event::handle('EndAddNoticeReply', array($this, $this->notice, $notice));
- }
- }
- if (Event::handle('StartShowThreadedNoticeTail', array($this, $this->notice, &$notices))) {
- $threadActive = count($notices) > 0;
- $this->out->elementStart('ul', 'notices threaded-replies xoxo');
- if (Event::handle('StartShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive))) {
-
-
-
- $item = new ThreadedNoticeListRepeatsItem($this->notice, $this->out);
- $threadActive = $item->show() || $threadActive;
- Event::handle('EndShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive));
- }
- if (count($notices)>0) {
- if ($moreCutoff) {
- $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out, count($notices));
- $item->show();
- }
- foreach (array_reverse($notices) as $notice) {
- if (Event::handle('StartShowThreadedNoticeSub', array($this, $this->notice, $notice))) {
- $item = new ThreadedNoticeListSubItem($notice, $this->notice, $this->out);
- $item->show();
- Event::handle('EndShowThreadedNoticeSub', array($this, $this->notice, $notice));
- }
- }
- }
- if ($threadActive && Profile::current() instanceof Profile) {
-
-
- $item = new ThreadedNoticeListReplyItem($this->notice, $this->out);
- $item->show();
- }
- $this->out->elementEnd('ul');
- Event::handle('EndShowThreadedNoticeTail', array($this, $this->notice, $notices));
- }
- }
- parent::showEnd();
- }
- }
- class ThreadedNoticeListSubItem extends NoticeListItem
- {
- protected $root = null;
- function __construct(Notice $notice, $root, $out)
- {
- $this->root = $root;
- parent::__construct($notice, $out);
- }
- function avatarSize()
- {
- return AVATAR_STREAM_SIZE;
- }
- function showNoticeLocation()
- {
-
- }
- function showNoticeSource()
- {
-
- }
- function getReplyProfiles()
- {
- $all = parent::getReplyProfiles();
- $profiles = array();
- $rootAuthor = $this->root->getProfile();
- foreach ($all as $profile) {
- if ($profile->id != $rootAuthor->id) {
- $profiles[] = $profile;
- }
- }
- return $profiles;
- }
- function showEnd()
- {
- $threadActive = null;
- if (Event::handle('StartShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive))) {
- $item = new ThreadedNoticeListInlineRepeatsItem($this->notice, $this->out);
- $hasRepeats = $item->show();
- Event::handle('EndShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive));
- }
- parent::showEnd();
- }
- }
- class ThreadedNoticeListMoreItem extends NoticeListItem
- {
- protected $cnt;
- function __construct(Notice $notice, Action $out, $cnt)
- {
- parent::__construct($notice, $out);
- $this->cnt = $cnt;
- }
-
- function show()
- {
- $this->showStart();
- $this->showMiniForm();
- $this->showEnd();
- }
-
- function showStart()
- {
- $this->out->elementStart('li', array('class' => 'notice-reply-comments'));
- }
- function showEnd()
- {
- $this->out->elementEnd('li');
- }
- function showMiniForm()
- {
- $id = $this->notice->conversation;
- $url = common_local_url('conversation', array('id' => $id));
- $n = Conversation::noticeCount($id) - 1;
-
-
- $msg = sprintf(_m('Show reply', 'Show all %d replies', $n), $n);
- $this->out->element('a', array('href' => $url), $msg);
- }
- }
- class ThreadedNoticeListReplyItem extends NoticeListItem
- {
-
- function show()
- {
- $this->showStart();
- $this->showMiniForm();
- $this->showEnd();
- }
-
- function showStart()
- {
- $this->out->elementStart('li', array('class' => 'notice-reply-placeholder'));
- }
- function showMiniForm()
- {
- $this->out->element('input', array('class' => 'placeholder',
-
- 'value' => _('Write a reply...')));
- }
- }
- class ThreadedNoticeListRepeatsItem extends NoticeListActorsItem
- {
- function getProfiles()
- {
- $repeats = $this->notice->getRepeats();
- $profiles = array();
- foreach ($repeats as $rep) {
- $profiles[] = $rep->profile_id;
- }
- return $profiles;
- }
- function magicList($items)
- {
- if (count($items) > 4) {
- return parent::magicList(array_slice($items, 0, 3));
- } else {
- return parent::magicList($items);
- }
- }
- function getListMessage($count, $you)
- {
- if ($count == 1 && $you) {
-
-
- return _m('REPEATLIST', 'You repeated this.');
- } else if ($count > 4) {
-
-
-
- return sprintf(_m('%%s and %d other repeated this.',
- '%%s and %d others repeated this.',
- $count - 3),
- $count - 3);
- } else {
-
-
-
- return sprintf(_m('%%s repeated this.',
- '%%s repeated this.',
- $count),
- $count);
- }
- }
- function showStart()
- {
- $this->out->elementStart('li', array('class' => 'notice-data notice-repeats'));
- }
- function showEnd()
- {
- $this->out->elementEnd('li');
- }
- }
- class ThreadedNoticeListInlineRepeatsItem extends ThreadedNoticeListRepeatsItem
- {
- function showStart()
- {
- $this->out->elementStart('div', array('class' => 'notice-repeats'));
- }
- function showEnd()
- {
- $this->out->elementEnd('div');
- }
- }
|