]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/threadednoticelistitem.php
Split threaded notice list classes into own files.
[quix0rs-gnu-social.git] / lib / threadednoticelistitem.php
1 <?php
2
3 if (!defined('GNUSOCIAL')) { exit(1); }
4
5 /**
6  * widget for displaying a single notice
7  *
8  * This widget has the core smarts for showing a single notice: what to display,
9  * where, and under which circumstances. Its key method is show(); this is a recipe
10  * that calls all the other show*() methods to build up a single notice. The
11  * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
12  * author info (since that's implicit by the data in the page).
13  *
14  * @category UI
15  * @package  StatusNet
16  * @author   Evan Prodromou <evan@status.net>
17  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
18  * @link     http://status.net/
19  * @see      NoticeList
20  * @see      ProfileNoticeListItem
21  */
22 class ThreadedNoticeListItem extends NoticeListItem
23 {
24     protected $userProfile = null;
25
26     function __construct(Notice $notice, Action $out=null, $profile=null)
27     {
28         parent::__construct($notice, $out);
29         $this->userProfile = $profile;
30     }
31
32     function initialItems()
33     {
34         return 3;
35     }
36
37     /**
38      * finish the notice
39      *
40      * Close the last elements in the notice list item
41      *
42      * @return void
43      */
44     function showEnd()
45     {
46         $max = $this->initialItems();
47         if (!$this->repeat instanceof Notice) {
48             $stream = new ConversationNoticeStream($this->notice->conversation, $this->userProfile);
49             $notice = $stream->getNotices(0, $max + 2);
50             $notices = array();
51             $cnt = 0;
52             $moreCutoff = null;
53             while ($notice->fetch()) {
54                 if (Event::handle('StartAddNoticeReply', array($this, $this->notice, $notice))) {
55                     // Don't list repeats as separate notices in a conversation
56                     if (!empty($notice->repeat_of)) {
57                         continue;
58                     }
59
60                     if ($notice->id == $this->notice->id) {
61                         // Skip!
62                         continue;
63                     }
64                     $cnt++;
65                     if ($cnt > $max) {
66                         // boo-yah
67                         $moreCutoff = clone($notice);
68                         break;
69                     }
70                     $notices[] = clone($notice); // *grumble* inefficient as hell
71                     Event::handle('EndAddNoticeReply', array($this, $this->notice, $notice));
72                 }
73             }
74
75             if (Event::handle('StartShowThreadedNoticeTail', array($this, $this->notice, &$notices))) {
76                 $threadActive = count($notices) > 0; // has this thread had any activity?
77
78                 $this->out->elementStart('ul', 'notices threaded-replies xoxo');
79
80                 if (Event::handle('StartShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive))) {
81                     // Repeats and Faves/Likes are handled in plugins.
82                     Event::handle('EndShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive));
83                 }
84
85                 if (count($notices)>0) {
86                     if ($moreCutoff) {
87                         $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out, count($notices));
88                         $item->show();
89                     }
90                     foreach (array_reverse($notices) as $notice) {
91                         if (Event::handle('StartShowThreadedNoticeSub', array($this, $this->notice, $notice))) {
92                             $item = new ThreadedNoticeListSubItem($notice, $this->notice, $this->out);
93                             $item->show();
94                             Event::handle('EndShowThreadedNoticeSub', array($this, $this->notice, $notice));
95                         }
96                     }
97                 }
98
99                 Event::handle('EndShowThreadedNoticeTail', array($this, $this->notice, $notices));
100                 $this->out->elementEnd('ul');
101             }
102         }
103
104         parent::showEnd();
105     }
106 }