* @see NoticeListItem
* @see ProfileNoticeList
*/
-
class AttachmentList extends Widget
{
/** the current stream of notices being displayed. */
*
* @param Notice $notice stream of notices from DB_DataObject
*/
-
function __construct($notice, $out=null)
{
parent::__construct($out);
*
* @return int count of notices listed.
*/
-
function show()
{
$atts = new File;
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'));
*
* @return NoticeListItem a list item for displaying the notice
*/
-
function newListItem($attachment)
{
return new AttachmentListItem($attachment, $this->out);
* @see NoticeList
* @see ProfileNoticeListItem
*/
-
class AttachmentListItem extends Widget
{
/** The attachment this item will show. */
*
* @param Notice $notice The notice we'll display
*/
-
function __construct($attachment, $out=null)
{
parent::__construct($out);
*
* @return void
*/
-
function show()
{
- $this->showStart();
- $this->showNoticeAttachment();
- $this->showEnd();
+ if ($this->attachment->isEnclosure()) {
+ $this->showStart();
+ $this->showNoticeAttachment();
+ $this->showEnd();
+ }
}
function linkAttr() {
}
function showRepresentation() {
+ $thumb = $this->getThumbInfo();
+ if ($thumb) {
+ $thumb = $this->sizeThumb($thumb);
+ $this->out->element('img', array('alt' => '', 'src' => $thumb->url, 'width' => $thumb->width, 'height' => $thumb->height));
+ }
+ }
+
+ /**
+ * Pull a thumbnail image reference for the given file.
+ * In order we check:
+ * 1) file_thumbnail table (thumbnails found via oEmbed)
+ * 2) image URL from direct dereference or oEmbed 'photo' type URL
+ * 3) ???
+ *
+ * @return mixed object with (url, width, height) properties, or false
+ */
+ function getThumbInfo()
+ {
$thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id);
- if (!empty($thumbnail)) {
- $this->out->element('img', array('alt' => '', 'src' => $thumbnail->url, 'width' => $thumbnail->width, 'height' => $thumbnail->height));
+ if ($thumbnail) {
+ return $thumbnail;
+ }
+ $enc = $this->attachment->getEnclosure();
+ if ($enc) {
+ switch ($enc->mimetype) {
+ case 'image/gif':
+ case 'image/png':
+ case 'image/jpg':
+ case 'image/jpeg':
+ $thumb = (object)array();
+ $thumb->url = $enc->url;
+ $thumb->width = 100;
+ $thumb->height = 75; // @fixme
+ return $thumb;
+ }
+ }
+ return false;
+ }
+
+ function sizeThumb($thumbnail) {
+ $maxWidth = 100;
+ $maxHeight = 75;
+ if ($thumbnail->width > $maxWidth) {
+ $thumb = clone($thumbnail);
+ $thumb->width = $maxWidth;
+ $thumb->height = intval($thumbnail->height * $maxWidth / $thumbnail->width);
+ return $thumb;
+ } else {
+ return $thumbnail;
}
}
*
* @return void
*/
-
function showStart()
{
// XXX: RDFa
*
* @return void
*/
-
function showEnd()
{
$this->out->elementEnd('li');
}
}
+/**
+ * used for one-off attachment action
+ */
class Attachment extends AttachmentListItem
{
function showLink() {
$this->out->elementEnd('div');
if (!empty($this->oembed->author_name) || !empty($this->oembed->provider)) {
- $this->out->elementStart('div', array('id' => 'oembed_info',
+ $this->out->elementStart('div', array('id' => 'oembed_info',
'class' => 'entry-content'));
if (!empty($this->oembed->author_name)) {
$this->out->elementStart('dl', 'vcard author');
+ // TRANS: DT element label in attachment list item.
$this->out->element('dt', null, _('Author'));
$this->out->elementStart('dd', 'fn');
if (empty($this->oembed->author_url)) {
}
if (!empty($this->oembed->provider)) {
$this->out->elementStart('dl', 'vcard');
+ // TRANS: DT element label in attachment list item.
$this->out->element('dt', null, _('Provider'));
$this->out->elementStart('dd', 'fn');
if (empty($this->oembed->provider_url)) {
function showRepresentation() {
if (empty($this->oembed->type)) {
if (empty($this->attachment->mimetype)) {
- $this->out->element('pre', null, 'oh well... not sure how to handle the following: ' . print_r($this->attachment, true));
+ $this->showFallback();
} else {
switch ($this->attachment->mimetype) {
case 'image/gif':
if ($this->attachment->filename) {
// Locally-uploaded HTML. Scrub and display inline.
$this->showHtmlFile($this->attachment);
+ break;
}
- break;
+ // Fall through to default.
+
+ default:
+ $this->showFallback();
}
}
} else {
break;
default:
- $this->out->element('pre', null, 'oh well... not sure how to handle the following oembed: ' . print_r($this->oembed, true));
+ $this->showFallback();
}
}
}
return $scrubbed;
}
}
-