]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Removing excessive "inline" attachment listings
authorMikael Nordfeldth <mmn@hethane.se>
Tue, 5 Aug 2014 09:30:45 +0000 (11:30 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Tue, 5 Aug 2014 09:30:45 +0000 (11:30 +0200)
classes/File.php
lib/attachmentlist.php
lib/attachmentlistitem.php
lib/inlineattachmentlist.php

index 029ff487a48e4fe561411f7e4a8dfa04f3c460dc..210e758419570c8044bba27429f0ca5ecdb1dde8 100644 (file)
@@ -541,4 +541,11 @@ class File extends Managed_DataObject
         // And finally remove the entry from the database
         return parent::delete($useWhere);
     }
+
+    public function getTitle()
+    {
+        $title = $this->title ?: $this->filename;
+
+        return $title ?: null;
+    }
 }
index 6609cb40daecc66c64492d02bcbf7338b3772d4d..d6cfda6f95961b4f3bd74be7a1a52d384df947bc 100644 (file)
@@ -74,18 +74,28 @@ class AttachmentList extends Widget
      */
     function show()
     {
-       $att = $this->notice->attachments();
-        if (empty($att)) return 0;
+       $attachments = $this->notice->attachments();
+        $representable = false;
+        foreach ($attachments as $key=>$att) {
+            // Only show attachments representable with a title
+            if ($att->getTitle() === null) {
+                unset($attachments[$key]);
+            }
+        }
+        if (!count($attachments)) {
+            return 0;
+        }
+
         $this->showListStart();
 
-        foreach ($att as $n=>$attachment) {
-            $item = $this->newListItem($attachment);
+        foreach ($attachments as $att) {
+            $item = $this->newListItem($att);
             $item->show();
         }
 
         $this->showListEnd();
 
-        return count($att);
+        return count($attachments);
     }
 
     function showListStart()
index 025ffa9fd6a7cefb019ad178d7bfac476308a69b..3764c827cb2f7ea459f4db9ceb99601177274531 100644 (file)
@@ -63,7 +63,7 @@ class AttachmentListItem extends Widget
     }
 
     function title() {
-        return $this->attachment->title ?: $this->attachment->filename;
+        return $this->attachment->getTitle();
     }
 
     function linkTitle() {
index b68701fb31266f570ead2a3d69603d8cba9baf32..d760400487605ddc92f42fccac005e61b3d9b0b4 100644 (file)
@@ -35,12 +35,8 @@ class InlineAttachmentList extends AttachmentList
 {
     function showListStart()
     {
-        $this->out->elementStart('div', array('class' => 'attachments'));
-    }
-
-    function showListEnd()
-    {
-        $this->out->elementEnd('div');
+        $this->out->element('h2', null, _('Attachments'));
+        parent::showListStart();
     }
 
     /**
@@ -72,7 +68,7 @@ class InlineAttachmentListItem extends AttachmentListItem
     {
         // XXX: RDFa
         // TODO: add notice_type class e.g., notice_video, notice_image
-        $this->out->elementStart('span', array('class' => 'inline-attachment'));
+        $this->out->elementStart('li', array('class' => 'inline-attachment'));
     }
 
     /**
@@ -84,6 +80,6 @@ class InlineAttachmentListItem extends AttachmentListItem
      */
     function showEnd()
     {
-        $this->out->elementEnd('span');
+        $this->out->elementEnd('li');
     }
 }