From b0c4e8fc3d406b6d2dc8b54b1892b39e0bb796bc Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 6 May 2014 21:49:42 +0200 Subject: [PATCH] Enable events for showing Attachment representation --- EVENTS.txt | 12 ++++++++ lib/attachmentlist.php | 63 +++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/EVENTS.txt b/EVENTS.txt index 32bbcdde99..fe36855785 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1445,3 +1445,15 @@ CreateFileImageThumbnailSource: Hook to create image thumbnail source from a Fil - $file: 'File' object to source the image from - &$imgPath: Path to image file which can be used as source for our thumbnail algorithm. - $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. diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 74248313eb..7f356f9527 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -28,9 +28,7 @@ * @link http://status.net/ */ -if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * widget for displaying a list of notice attachments @@ -289,10 +287,29 @@ class Attachment extends AttachmentListItem } function showRepresentation() { - if (empty($this->oembed->type)) { - if (empty($this->attachment->mimetype)) { - $this->showFallback(); - } else { + if (Event::handle('StartShowAttachmentRepresentation', array($this->out, $this->attachment))) { + if (!empty($this->oembed->type)) { + 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)); + } + 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) { case 'image/gif': case 'image/png': @@ -348,32 +365,13 @@ class Attachment extends AttachmentListItem // Fall through to default. default: - $this->showFallback(); + Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment)); } - } - } else { - 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(); + } else { + Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment)); } } + Event::handle('EndShowAttachmentRepresentation', array($this->out, $this->attachment)); } protected function showHtmlFile(File $attachment) @@ -428,9 +426,4 @@ class Attachment extends AttachmentListItem return $scrubbed; } - - function showFallback() - { - // still needed: should show a link? - } } -- 2.39.5