]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/attachmentlist.php
Merge branch '1.0.x' into shortcontrol10x
[quix0rs-gnu-social.git] / lib / attachmentlist.php
index 13dafd13e4818e2102f366efa9e0c73e7adf54d4..59cab9532c6b7373f0e2a210e0cf8ae3772149df 100644 (file)
@@ -84,6 +84,7 @@ class AttachmentList extends Widget
         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'));
@@ -260,6 +261,7 @@ class Attachment extends AttachmentListItem
                                                   '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)) {
@@ -273,6 +275,7 @@ class Attachment extends AttachmentListItem
             }
             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)) {
@@ -304,7 +307,7 @@ class Attachment extends AttachmentListItem
     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':
@@ -335,8 +338,12 @@ class Attachment extends AttachmentListItem
                     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 {
@@ -359,7 +366,7 @@ class Attachment extends AttachmentListItem
                 break;
 
             default:
-                $this->out->element('pre', null, 'oh well... not sure how to handle the following oembed: ' . print_r($this->oembed, true));
+                $this->showFallback();
             }
         }
     }
@@ -416,5 +423,19 @@ class Attachment extends AttachmentListItem
 
         return $scrubbed;
     }
+
+    function showFallback()
+    {
+        // If we don't know how to display an attachment inline, we probably
+        // shouldn't have gotten to this point.
+        //
+        // But, here we are... displaying details on a file or remote URL
+        // either on the main view or in an ajax-loaded lightbox. As a lesser
+        // of several evils, we'll try redirecting to the actual target via
+        // client-side JS.
+
+        common_log(LOG_ERR, "Empty or unknown type for file id {$this->attachment->id}; falling back to client-side redirect.");
+        $this->out->raw('<script>window.location = ' . json_encode($this->attachment->url) . ';</script>');
+    }
 }