]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Enable events for showing Attachment representation
authorMikael Nordfeldth <mmn@hethane.se>
Tue, 6 May 2014 19:49:42 +0000 (21:49 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Tue, 6 May 2014 19:49:42 +0000 (21:49 +0200)
EVENTS.txt
lib/attachmentlist.php

index 32bbcdde999f6f26e1cbae2eaca91f4dff2979b1..fe36855785caf9dc47a4d6bbfa67409b060f46e4 100644 (file)
@@ -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.
index 74248313ebadd095235170cc26b54915323ab9da..7f356f9527f24193ea41016aa2952442267a7ee0 100644 (file)
@@ -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?
-    }
 }