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.
83 $att = $atts->getAttachments($this->notice->id);
84 if (empty($att)) return 0;
85 $this->out->elementStart('dl', array('id' =>'attachments',
86 'class' => 'entry-content'));
87 $this->out->element('dt', null, _('Attachments'));
88 $this->out->elementStart('dd');
89 $this->out->elementStart('ol', array('class' => 'attachments'));
91 foreach ($att as $n=>$attachment) {
92 $item = $this->newListItem($attachment);
96 $this->out->elementEnd('dd');
97 $this->out->elementEnd('ol');
98 $this->out->elementEnd('dl');
104 * returns a new list item for the current notice
106 * Recipe (factory?) method; overridden by sub-classes to give
107 * a different list item class.
109 * @param Notice $notice the current notice
111 * @return NoticeListItem a list item for displaying the notice
114 function newListItem($attachment)
116 return new AttachmentListItem($attachment, $this->out);
121 * widget for displaying a single notice
123 * This widget has the core smarts for showing a single notice: what to display,
124 * where, and under which circumstances. Its key method is show(); this is a recipe
125 * that calls all the other show*() methods to build up a single notice. The
126 * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
127 * author info (since that's implicit by the data in the page).
131 * @author Evan Prodromou <evan@controlyourself.ca>
132 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
133 * @link http://laconi.ca/
135 * @see ProfileNoticeListItem
138 class AttachmentListItem extends Widget
140 /** The attachment this item will show. */
142 var $attachment = null;
149 * Also initializes the profile attribute.
151 * @param Notice $notice The notice we'll display
154 function __construct($attachment, $out=null)
156 parent::__construct($out);
157 $this->attachment = $attachment;
158 $this->oembed = File_oembed::staticGet('file_id', $this->attachment->id);
162 if (empty($this->attachment->title)) {
163 if (empty($this->oembed->title)) {
164 $title = $this->attachment->url;
166 $title = $this->oembed->title;
169 $title = $this->attachment->title;
175 function linkTitle() {
176 return $this->title();
180 * recipe function for displaying a single notice.
182 * This uses all the other methods to correctly display a notice. Override
183 * it or one of the others to fine-tune the output.
191 $this->showNoticeAttachment();
195 function linkAttr() {
196 return array('class' => 'attachment', 'href' => $this->attachment->url, 'id' => 'attachment-' . $this->attachment->id);
199 function showLink() {
200 $this->out->elementStart('a', $this->linkAttr());
201 $this->out->element('span', null, $this->linkTitle());
202 $this->showRepresentation();
203 $this->out->elementEnd('a');
206 function showNoticeAttachment()
211 function showRepresentation() {
212 $thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id);
213 if (!empty($thumbnail)) {
214 $this->out->element('img', array('alt' => '', 'src' => $thumbnail->url, 'width' => $thumbnail->width, 'height' => $thumbnail->height));
219 * start a single notice.
227 // TODO: add notice_type class e.g., notice_video, notice_image
228 $this->out->elementStart('li');
234 * Close the last elements in the notice list item
241 $this->out->elementEnd('li');
245 class Attachment extends AttachmentListItem
247 function showLink() {
248 $this->out->elementStart('div', array('id' => 'attachment_view',
249 'class' => 'hentry'));
250 $this->out->elementStart('div', 'entry-title');
251 $this->out->elementStart('a', $this->linkAttr());
252 $this->out->element('span', null, $this->linkTitle());
253 $this->out->elementEnd('a');
254 $this->out->elementEnd('div');
256 $this->out->elementStart('div', 'entry-content');
257 $this->showRepresentation();
258 $this->out->elementEnd('div');
260 if (!empty($this->oembed->author_name) || !empty($this->oembed->provider)) {
261 $this->out->elementStart('div', array('id' => 'oembed_info',
262 'class' => 'entry-content'));
263 if (!empty($this->oembed->author_name)) {
264 $this->out->elementStart('dl', 'vcard author');
265 $this->out->element('dt', null, _('Author'));
266 $this->out->elementStart('dd', 'fn');
267 if (empty($this->oembed->author_url)) {
268 $this->out->text($this->oembed->author_name);
270 $this->out->element('a', array('href' => $this->oembed->author_url,
271 'class' => 'url'), $this->oembed->author_name);
273 $this->out->elementEnd('dd');
274 $this->out->elementEnd('dl');
276 if (!empty($this->oembed->provider)) {
277 $this->out->elementStart('dl', 'vcard');
278 $this->out->element('dt', null, _('Provider'));
279 $this->out->elementStart('dd', 'fn');
280 if (empty($this->oembed->provider_url)) {
281 $this->out->text($this->oembed->provider);
283 $this->out->element('a', array('href' => $this->oembed->provider_url,
284 'class' => 'url'), $this->oembed->provider);
286 $this->out->elementEnd('dd');
287 $this->out->elementEnd('dl');
289 $this->out->elementEnd('div');
291 $this->out->elementEnd('div');
295 $this->showNoticeAttachment();
298 function linkAttr() {
299 return array('class' => 'external', 'href' => $this->attachment->url);
302 function linkTitle() {
303 return $this->attachment->url;
306 function showRepresentation() {
307 if (empty($this->oembed->type)) {
308 if (empty($this->attachment->mimetype)) {
309 $this->out->element('pre', null, 'oh well... not sure how to handle the following: ' . print_r($this->attachment, true));
311 switch ($this->attachment->mimetype) {
316 $this->out->element('img', array('src' => $this->attachment->url, 'alt' => 'alt'));
319 case 'application/ogg':
320 case 'audio/x-speex':
324 case 'video/quicktime':
325 $arr = array('type' => $this->attachment->mimetype,
326 'data' => $this->attachment->url,
330 $this->out->elementStart('object', $arr);
331 $this->out->element('param', array('name' => 'src', 'value' => $this->attachment->url));
332 $this->out->element('param', array('name' => 'autoStart', 'value' => 1));
333 $this->out->elementEnd('object');
338 switch ($this->oembed->type) {
342 if (!empty($this->oembed->html)) {
343 require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
346 'elements'=>'*+object+embed');
347 $this->out->raw(htmLawed($this->oembed->html,$config));
348 //$this->out->raw($this->oembed->html);
353 $this->out->element('img', array('src' => $this->oembed->url, 'width' => $this->oembed->width, 'height' => $this->oembed->height, 'alt' => 'alt'));
357 $this->out->element('pre', null, 'oh well... not sure how to handle the following oembed: ' . print_r($this->oembed, true));