split out InlineAttachmentList from AttachmentList

This commit is contained in:
Brion Vibber 2010-11-09 10:45:19 -08:00
parent 504529e8cd
commit f25accc43e
5 changed files with 134 additions and 14 deletions

View File

@ -331,6 +331,15 @@ class SingleNoticeItem extends DoFollowListItem
$this->showEnd();
}
/**
* For our zoomed-in special case we'll use a fuller list
* for the attachment info.
*/
function showNoticeAttachments() {
$al = new AttachmentList($this->notice, $this->out);
$al->show();
}
/**
* show the avatar of the notice's author
*

View File

@ -79,23 +79,33 @@ class AttachmentList extends Widget
$atts = new File;
$att = $atts->getAttachments($this->notice->id);
if (empty($att)) return 0;
$this->out->elementStart('dl', array('id' =>'attachments',
'class' => 'entry-content'));
// TRANS: DT element label in attachment list.
$this->out->element('dt', null, _('Attachments'));
$this->out->elementStart('dd');
$this->out->elementStart('ol', array('class' => 'attachments'));
$this->showListStart();
foreach ($att as $n=>$attachment) {
$item = $this->newListItem($attachment);
$item->show();
}
$this->showListEnd();
return count($att);
}
function showListStart()
{
$this->out->elementStart('dl', array('id' =>'attachments',
'class' => 'entry-content'));
// TRANS: DT element label in attachment list.
$this->out->element('dt', null, _('Attachments'));
$this->out->elementStart('dd');
$this->out->elementStart('ol', array('class' => 'attachments'));
}
function showListEnd()
{
$this->out->elementEnd('dd');
$this->out->elementEnd('ol');
$this->out->elementEnd('dl');
return count($att);
}
/**
@ -181,11 +191,9 @@ class AttachmentListItem extends Widget
*/
function show()
{
if ($this->attachment->isEnclosure()) {
$this->showStart();
$this->showNoticeAttachment();
$this->showEnd();
}
$this->showStart();
$this->showNoticeAttachment();
$this->showEnd();
}
function linkAttr() {

View File

@ -0,0 +1,97 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* widget for displaying notice attachments thumbnails
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category UI
* @package StatusNet
* @author Brion Vibber <brion@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
exit(1);
}
class InlineAttachmentList extends AttachmentList
{
function showListStart()
{
$this->out->elementStart('div', array('class' => 'entry-content thumbnails'));
}
function showListEnd()
{
$this->out->elementEnd('div');
}
/**
* returns a new list item for the current attachment
*
* @param File $notice the current attachment
*
* @return ListItem a list item for displaying the attachment
*/
function newListItem($attachment)
{
return new InlineAttachmentListItem($attachment, $this->out);
}
}
class InlineAttachmentListItem extends AttachmentListItem
{
function show()
{
if ($this->attachment->isEnclosure()) {
parent::show();
}
}
function showLink() {
$this->out->elementStart('a', $this->linkAttr());
$this->showRepresentation();
$this->out->elementEnd('a');
}
/**
* start a single notice.
*
* @return void
*/
function showStart()
{
// XXX: RDFa
// TODO: add notice_type class e.g., notice_video, notice_image
$this->out->elementStart('span', array('class' => 'inline-attachment'));
}
/**
* finish the notice
*
* Close the last elements in the notice list item
*
* @return void
*/
function showEnd()
{
$this->out->elementEnd('span');
}
}

View File

@ -385,7 +385,7 @@ class NoticeListItem extends Widget
}
function showNoticeAttachments() {
$al = new AttachmentList($this->notice, $this->out);
$al = new InlineAttachmentList($this->notice, $this->out);
$al->show();
}

View File

@ -1728,6 +1728,12 @@ width:auto;
min-width:0;
}
.inline-attachment img {
/* Why on earth is this changed to block at the top? */
display: inline;
border: solid 1px #aaa;
padding: 1px;
}
}/*end of @media screen, projection, tv*/