3 * Laconica, the distributed open-source microblogging tool
5 * widget for displaying a list of notice attachments
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.
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.
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/>.
24 * @author Evan Prodromou <evan@controlyourself.ca>
25 * @author Sarven Capadisli <csarven@controlyourself.ca>
26 * @copyright 2008 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!defined('LACONICA')) {
36 * widget for displaying a list of notice attachments
38 * There are a number of actions that display a list of notices, in
39 * reverse chronological order. This widget abstracts out most of the
40 * code for UI for notice lists. It's overridden to hide some
41 * data for e.g. the profile page.
45 * @author Evan Prodromou <evan@controlyourself.ca>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://laconi.ca/
50 * @see ProfileNoticeList
53 class AttachmentList extends Widget
55 /** the current stream of notices being displayed. */
62 * @param Notice $notice stream of notices from DB_DataObject
65 function __construct($notice, $out=null)
67 parent::__construct($out);
68 $this->notice = $notice;
72 * show the list of notices
74 * "Uses up" the stream by looping through it. So, probably can't
75 * be called twice on the same list.
77 * @return int count of notices listed.
82 $this->out->elementStart('dl', array('id' =>'attachment'));
83 $this->out->element('dt', null, _('Attachments'));
84 $this->out->elementStart('dd');
85 $this->out->elementStart('ul', array('class' => 'attachments'));
88 $att = $atts->getAttachments($this->notice->id);
89 foreach ($att as $n=>$attachment) {
90 $item = $this->newListItem($attachment);
94 $this->out->elementEnd('dd');
95 $this->out->elementEnd('ul');
96 $this->out->elementEnd('dl');
102 * returns a new list item for the current notice
104 * Recipe (factory?) method; overridden by sub-classes to give
105 * a different list item class.
107 * @param Notice $notice the current notice
109 * @return NoticeListItem a list item for displaying the notice
112 function newListItem($attachment)
114 return new AttachmentListItem($attachment, $this->out);
119 * widget for displaying a single notice
121 * This widget has the core smarts for showing a single notice: what to display,
122 * where, and under which circumstances. Its key method is show(); this is a recipe
123 * that calls all the other show*() methods to build up a single notice. The
124 * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
125 * author info (since that's implicit by the data in the page).
129 * @author Evan Prodromou <evan@controlyourself.ca>
130 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
131 * @link http://laconi.ca/
133 * @see ProfileNoticeListItem
136 class AttachmentListItem extends Widget
138 /** The attachment this item will show. */
140 var $attachment = null;
147 * Also initializes the profile attribute.
149 * @param Notice $notice The notice we'll display
152 function __construct($attachment, $out=null)
154 parent::__construct($out);
155 $this->attachment = $attachment;
156 $this->oembed = File_oembed::staticGet('file_id', $this->attachment->id);
160 if (empty($this->attachment->title)) {
161 if (empty($this->oembed->title)) {
162 $title = $this->attachment->url;
164 $title = $this->oembed->title;
167 $title = $this->attachment->title;
173 function linkTitle() {
174 return $this->title();
178 * recipe function for displaying a single notice.
180 * This uses all the other methods to correctly display a notice. Override
181 * it or one of the others to fine-tune the output.
189 $this->showNoticeAttachment();
193 function linkAttr() {
194 return array('class' => 'attachment', 'href' => $this->attachment->url, 'id' => 'attachment-' . $this->attachment->id);
197 function showLink() {
198 $this->out->elementStart('a', $this->linkAttr());
199 $this->out->element('span', null, $this->linkTitle());
200 $this->showRepresentation();
201 $this->out->elementEnd('a');
204 function showNoticeAttachment()
209 function showRepresentation() {
210 $thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id);
211 if (!empty($thumbnail)) {
212 $this->out->element('img', array('alt' => 'nothing to say', 'src' => $thumbnail->url, 'width' => $thumbnail->width, 'height' => $thumbnail->height));
217 * start a single notice.
225 // TODO: add notice_type class e.g., notice_video, notice_image
226 $this->out->elementStart('li');
232 * Close the last elements in the notice list item
239 $this->out->elementEnd('li');
243 class Attachment extends AttachmentListItem
246 $this->showNoticeAttachment();
249 function linkAttr() {
250 return array('class' => 'external', 'href' => $this->attachment->url);
253 function linkTitle() {
254 return $this->attachment->url;
257 function showRepresentation() {
258 if (empty($this->oembed->type)) {
259 if (empty($this->attachment->mimetype)) {
260 $this->out->element('pre', null, 'oh well... not sure how to handle the following: ' . print_r($this->attachment, true));
262 switch ($this->attachment->mimetype) {
267 $this->out->element('img', array('src' => $this->attachment->url, 'alt' => 'alt'));
272 switch ($this->oembed->type) {
276 if (!empty($this->oembed->html)) {
277 $this->out->raw($this->oembed->html);
282 $this->out->element('img', array('src' => $this->oembed->url, 'width' => $this->oembed->width, 'height' => $this->oembed->height, 'alt' => 'alt'));
286 $this->out->element('pre', null, 'oh well... not sure how to handle the following oembed: ' . print_r($this->oembed, true));