Enable events for showing Attachment representation

This commit is contained in:
Mikael Nordfeldth 2014-05-06 21:49:42 +02:00
parent 074b2b621c
commit b0c4e8fc3d
2 changed files with 40 additions and 35 deletions

View File

@ -1445,3 +1445,15 @@ CreateFileImageThumbnailSource: Hook to create image thumbnail source from a Fil
- $file: 'File' object to source the image from - $file: 'File' object to source the image from
- &$imgPath: Path to image file which can be used as source for our thumbnail algorithm. - &$imgPath: Path to image file which can be used as source for our thumbnail algorithm.
- $media: MIME media type ('image', 'video', 'audio' etc.) - $media: MIME media type ('image', 'video', 'audio' etc.)
StartShowAttachmentRepresentation: Attachment representation, full file (or in rare cases thumbnails/previews).
- $out: HTMLOutputter class to use for outputting HTML.
- $file: 'File' object which we're going to show representation for.
EndShowAttachmentRepresentation: Executed after Attachment representation, despite perhaps being unsupported media.
- $out: HTMLOutputter class to use for outputting HTML.
- $file: 'File' object which we're going to show representation for.
ShowUnsupportedAttachmentRepresentation: Attachment representation, full file (or in rare cases thumbnails/previews).
- $out: HTMLOutputter class to use for outputting HTML.
- $file: 'File' object which we're going to show representation for.

View File

@ -28,9 +28,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* widget for displaying a list of notice attachments * widget for displaying a list of notice attachments
@ -289,10 +287,29 @@ class Attachment extends AttachmentListItem
} }
function showRepresentation() { function showRepresentation() {
if (empty($this->oembed->type)) { if (Event::handle('StartShowAttachmentRepresentation', array($this->out, $this->attachment))) {
if (empty($this->attachment->mimetype)) { if (!empty($this->oembed->type)) {
$this->showFallback(); switch ($this->oembed->type) {
} else { case 'rich':
case 'video':
case 'link':
if (!empty($this->oembed->html)) {
require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
$config = array(
'safe'=>1,
'elements'=>'*+object+embed');
$this->out->raw(htmLawed($this->oembed->html,$config));
}
break;
case 'photo':
$this->out->element('img', array('src' => $this->oembed->url, 'width' => $this->oembed->width, 'height' => $this->oembed->height, 'alt' => 'alt'));
break;
default:
Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment));
}
} elseif (!empty($this->attachment->mimetype)) {
switch ($this->attachment->mimetype) { switch ($this->attachment->mimetype) {
case 'image/gif': case 'image/gif':
case 'image/png': case 'image/png':
@ -348,32 +365,13 @@ class Attachment extends AttachmentListItem
// Fall through to default. // Fall through to default.
default: default:
$this->showFallback(); Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment));
} }
} } else {
} else { Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment));
switch ($this->oembed->type) {
case 'rich':
case 'video':
case 'link':
if (!empty($this->oembed->html)) {
require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
$config = array(
'safe'=>1,
'elements'=>'*+object+embed');
$this->out->raw(htmLawed($this->oembed->html,$config));
//$this->out->raw($this->oembed->html);
}
break;
case 'photo':
$this->out->element('img', array('src' => $this->oembed->url, 'width' => $this->oembed->width, 'height' => $this->oembed->height, 'alt' => 'alt'));
break;
default:
$this->showFallback();
} }
} }
Event::handle('EndShowAttachmentRepresentation', array($this->out, $this->attachment));
} }
protected function showHtmlFile(File $attachment) protected function showHtmlFile(File $attachment)
@ -428,9 +426,4 @@ class Attachment extends AttachmentListItem
return $scrubbed; return $scrubbed;
} }
function showFallback()
{
// still needed: should show a link?
}
} }