]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/threadednoticelist.php
visual tweaks for convo view
[quix0rs-gnu-social.git] / lib / threadednoticelist.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * widget for displaying a list of notices
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  UI
23  * @package   StatusNet
24  * @author    Brion Vibber <brion@status.net>
25  * @copyright 2011 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * widget for displaying a list of notices
36  *
37  * There are a number of actions that display a list of notices, in
38  * reverse chronological order. This widget abstracts out most of the
39  * code for UI for notice lists. It's overridden to hide some
40  * data for e.g. the profile page.
41  *
42  * @category UI
43  * @package  StatusNet
44  * @author   Evan Prodromou <evan@status.net>
45  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46  * @link     http://status.net/
47  * @see      Notice
48  * @see      NoticeListItem
49  * @see      ProfileNoticeList
50  */
51
52 class ThreadedNoticeList extends NoticeList
53 {
54     /**
55      * show the list of notices
56      *
57      * "Uses up" the stream by looping through it. So, probably can't
58      * be called twice on the same list.
59      *
60      * @return int count of notices listed.
61      */
62
63     function show()
64     {
65         $this->out->elementStart('div', array('id' =>'notices_primary'));
66         $this->out->element('h2', null, _('Notices'));
67         $this->out->elementStart('ol', array('class' => 'notices xoxo'));
68
69         $cnt = 0;
70         $conversations = array();
71         while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
72             $convo = $this->notice->conversation;
73             if (!empty($conversations[$convo])) {
74                 // Seen this convo already -- skip!
75                 continue;
76             }
77             $conversations[$convo] = true;
78
79             // Get the convo's root notice
80             // @fixme stream goes in wrong direction, this needs sane caching
81             //$notice = Notice::conversationStream($convo, 0, 1);
82             //$notice->fetch();
83             $notice = new Notice();
84             $notice->conversation = $this->notice->conversation;
85             $notice->orderBy('CREATED');
86             $notice->limit(1);
87             $notice->find(true);
88
89             $cnt++;
90
91             if ($cnt > NOTICES_PER_PAGE) {
92                 break;
93             }
94
95             try {
96                 $item = $this->newListItem($notice);
97                 $item->show();
98             } catch (Exception $e) {
99                 // we log exceptions and continue
100                 common_log(LOG_ERR, $e->getMessage());
101                 continue;
102             }
103         }
104
105         $this->out->elementEnd('ol');
106         $this->out->elementEnd('div');
107
108         return $cnt;
109     }
110
111     /**
112      * returns a new list item for the current notice
113      *
114      * Recipe (factory?) method; overridden by sub-classes to give
115      * a different list item class.
116      *
117      * @param Notice $notice the current notice
118      *
119      * @return NoticeListItem a list item for displaying the notice
120      */
121
122     function newListItem($notice)
123     {
124         return new ThreadedNoticeListItem($notice, $this->out);
125     }
126 }
127
128 /**
129  * widget for displaying a single notice
130  *
131  * This widget has the core smarts for showing a single notice: what to display,
132  * where, and under which circumstances. Its key method is show(); this is a recipe
133  * that calls all the other show*() methods to build up a single notice. The
134  * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
135  * author info (since that's implicit by the data in the page).
136  *
137  * @category UI
138  * @package  StatusNet
139  * @author   Evan Prodromou <evan@status.net>
140  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
141  * @link     http://status.net/
142  * @see      NoticeList
143  * @see      ProfileNoticeListItem
144  */
145
146 class ThreadedNoticeListItem extends NoticeListItem
147 {
148     /**
149      * finish the notice
150      *
151      * Close the last elements in the notice list item
152      *
153      * @return void
154      */
155
156     function showEnd()
157     {
158         $notice = Notice::conversationStream($this->notice->conversation);
159         $notices = array();
160         while ($notice->fetch()) {
161             if ($notice->id == $this->notice->id) {
162                 // Skip!
163                 continue;
164             }
165             $notices[] = clone($notice); // *grumble* inefficient as hell
166         }
167
168         if ($notices) {
169             $this->out->elementStart('ul', 'notices threaded-notices xoxo');
170             foreach (array_reverse($notices) as $notice) {
171                 $item = new ThreadedNoticeListSubItem($notice, $this->out);
172                 $item->show();
173             }
174             $this->out->elementEnd('ul');
175         }
176
177         parent::showEnd();
178     }
179 }
180
181 class ThreadedNoticeListSubItem extends NoticeListItem
182 {
183
184     function avatarSize()
185     {
186         return AVATAR_STREAM_SIZE; // @fixme would like something in between
187     }
188
189     function showNoticeLocation()
190     {
191         //
192     }
193
194     function showNoticeSource()
195     {
196         //
197     }
198 }