]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Updated 'more' anchor for attachments to do an XHR GET
authorBrion Vibber <brion@pobox.com>
Thu, 25 Mar 2010 21:15:54 +0000 (14:15 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 25 Mar 2010 21:15:54 +0000 (14:15 -0700)
Conflicts:

lib/attachmentlist.php
plugins/OStatus/classes/Ostatus_profile.php

Merge tried to delete things that it seems it shouldn't, very confusing order. Hope rest of the cherry-picking isn't a problem.

js/util.js
lib/attachmentlist.php
plugins/OStatus/classes/Ostatus_profile.php
theme/base/css/display.css
theme/default/css/display.css
theme/identica/css/display.css

index f82ca992c6559d82941feb8e79bea95639790466..79fd40debac308343a840e9c6c08c9785fe2554d 100644 (file)
@@ -399,58 +399,70 @@ var SN = { // StatusNet
                 return;
             }
 
-            $.fn.jOverlay.options = {
-                method : 'GET',
-                data : '',
-                url : '',
-                color : '#000',
-                opacity : '0.6',
-                zIndex : 9999,
-                center : false,
-                imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
-                bgClickToClose : true,
-                success : function() {
-                    $('#jOverlayContent').append('<button class="close">&#215;</button>');
-                    $('#jOverlayContent button').click($.closeOverlay);
-                },
-                timeout : 0,
-                autoHide : true,
-                css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
-            };
-
-            notice.find('a.attachment').click(function() {
-                var attachId = ($(this).attr('id').substring('attachment'.length + 1));
-                if (attachId) {
-                    $().jOverlay({url: $('address .url')[0].href+'attachment/' + attachId + '/ajax'});
-                    return false;
-                }
-            });
+            var attachment_more = notice.find('.attachment.more');
+            if (attachment_more.length > 0) {
+                attachment_more.click(function() {
+                    $.get($(this).attr('href')+'/ajax', null, function(data) {
+                        notice.find('.entry-title .entry-content').html($(data).find('#attachment_view .entry-content').html());
+                    });
 
-            if ($('#shownotice').length == 0) {
-                var t;
-                notice.find('a.thumbnail').hover(
-                    function() {
-                        var anchor = $(this);
-                        $('a.thumbnail').children('img').hide();
-                        anchor.closest(".entry-title").addClass('ov');
-
-                        if (anchor.children('img').length === 0) {
-                            t = setTimeout(function() {
-                                $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
-                                    anchor.append(data);
-                                });
-                            }, 500);
-                        }
-                        else {
-                            anchor.children('img').show();
-                        }
+                    return false;
+                });
+            }
+            else {
+                $.fn.jOverlay.options = {
+                    method : 'GET',
+                    data : '',
+                    url : '',
+                    color : '#000',
+                    opacity : '0.6',
+                    zIndex : 9999,
+                    center : false,
+                    imgLoading : $('address .url')[0].href+'theme/base/images/illustrations/illu_progress_loading-01.gif',
+                    bgClickToClose : true,
+                    success : function() {
+                        $('#jOverlayContent').append('<button class="close">&#215;</button>');
+                        $('#jOverlayContent button').click($.closeOverlay);
                     },
-                    function() {
-                        clearTimeout(t);
-                        $('a.thumbnail').children('img').hide();
-                        $(this).closest('.entry-title').removeClass('ov');
+                    timeout : 0,
+                    autoHide : true,
+                    css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
+                };
+
+                notice.find('a.attachment').click(function() {
+                    var attachId = ($(this).attr('id').substring('attachment'.length + 1));
+                    if (attachId) {
+                        $().jOverlay({url: $('address .url')[0].href+'attachment/' + attachId + '/ajax'});
+                        return false;
                     }
-                );
+                });
+
+                if ($('#shownotice').length == 0) {
+                    var t;
+                    notice.find('a.thumbnail').hover(
+                        function() {
+                            var anchor = $(this);
+                            $('a.thumbnail').children('img').hide();
+                            anchor.closest(".entry-title").addClass('ov');
+
+                            if (anchor.children('img').length === 0) {
+                                t = setTimeout(function() {
+                                    $.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
+                                        anchor.append(data);
+                                    });
+                                }, 500);
+                            }
+                            else {
+                                anchor.children('img').show();
+                            }
+                        },
+                        function() {
+                            clearTimeout(t);
+                            $('a.thumbnail').children('img').hide();
+                            $(this).closest('.entry-title').removeClass('ov');
+                        }
+                    );
+                }
             }
         },
 
index b503bfb45e02f8575c3060b80385801974a830e9..c6261dea5986ccfe5bfa38e28d98ccc9b0ada3ab 100644 (file)
@@ -359,6 +359,59 @@ class Attachment extends AttachmentListItem
         }
     }
 
+    protected function showHtmlFile(File $attachment)
+    {
+        $body = $this->scrubHtmlFile($attachment);
+        if ($body) {
+            $this->out->raw($body);
+        }
+    }
+
+    /**
+     * @return mixed false on failure, HTML fragment string on success
+     */
+    protected function scrubHtmlFile(File $attachment)
+    {
+        $path = File::path($attachment->filename);
+        if (!file_exists($path) || !is_readable($path)) {
+            common_log(LOG_ERR, "Missing local HTML attachment $path");
+            return false;
+        }
+        $raw = file_get_contents($path);
+
+        // Normalize...
+        $dom = new DOMDocument();
+        if(!$dom->loadHTML($raw)) {
+            common_log(LOG_ERR, "Bad HTML in local HTML attachment $path");
+            return false;
+        }
+
+        // Remove <script>s or htmlawed will dump their contents into output!
+        // Note: removing child nodes while iterating seems to mess things up,
+        // hence the double loop.
+        $scripts = array();
+        foreach ($dom->getElementsByTagName('script') as $script) {
+            $scripts[] = $script;
+        }
+        foreach ($scripts as $script) {
+            common_log(LOG_DEBUG, $script->textContent);
+            $script->parentNode->removeChild($script);
+        }
+
+        // Trim out everything outside the body...
+        $body = $dom->saveHTML();
+        $body = preg_replace('/^.*<body[^>]*>/is', '', $body);
+        $body = preg_replace('/<\/body[^>]*>.*$/is', '', $body);
+
+        require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
+        $config = array('safe' => 1,
+                        'deny_attribute' => 'id,style,on*',
+                        'comment' => 1); // remove comments
+        $scrubbed = htmLawed($body, $config);
+
+        return $scrubbed;
+    }
+
     function showFallback()
     {
         // If we don't know how to display an attachment inline, we probably
index c7e3b05096863b8028c540ff51945697b0ff6e5d..51a426dc465a79e27d69dfa36877f53a4bc9435c 100644 (file)
@@ -555,9 +555,21 @@ class Ostatus_profile extends Memcached_DataObject
                 $shortSummary = substr($shortSummary,
                                        0,
                                        Notice::maxContent() - (mb_strlen($url) + 2));
-                $shortSummary .= '… ' . $url;
-                $content = $shortSummary;
-                $rendered = common_render_text($content);
+                $shortSummary .= '…';
+                $content = $shortSummary . ' ' . $url;
+
+                // We mark up the attachment link specially for the HTML output
+                // so we can fold-out the full version inline.
+                $attachUrl = common_local_url('attachment',
+                                              array('attachment' => $attachment->id));
+                $rendered = common_render_text($shortSummary) .
+                            ' ' .
+                            '<a href="' .
+                            htmlspecialchars($attachUrl) .
+                            '" class="attachment more">' .
+                            // TRANS: expansion link for too-long remote messages
+                            htmlspecialchars(_m('more')) .
+                            '</a>';
             }
         }
 
index a2e4cdf2afe3347aba21d549be3ceb5e2c94b701..9044021f5f5544da29b79fa75c886f7473e75fc3 100644 (file)
@@ -1284,9 +1284,16 @@ height:16px;
 position:relative;
 padding-left:16px;
 }
-#attachments .attachment {
+#attachments .attachment,
+.notice .attachment.more {
 padding-left:0;
 }
+.notice .attachment.more:before {
+content:'( ';
+}
+.notice .attachment.more:after {
+content:' )';
+}
 .notice .attachment img {
 position:absolute;
 top:18px;
index d92a53965b223ac16d272dd378cf89b112262d41..c08a03061d6b8f6244219ae27479d89a1907b458 100644 (file)
@@ -410,7 +410,8 @@ background-position: 0 -1714px;
 .notice .attachment {
 background-position:0 -394px;
 }
-#attachments .attachment {
+#attachments .attachment,
+.notice .attachment.more {
 background:none;
 }
 .notice-options .notice_reply {
index 59cb3c38a0afedbe82bbd5f3913efa935e46fc69..62a9e25d8199fbbd5c138b713382efb5509398d1 100644 (file)
@@ -409,7 +409,8 @@ background-position: 0 -1714px;
 .notice .attachment {
 background-position:0 -394px;
 }
-#attachments .attachment {
+#attachments .attachment,
+.notice .attachment.more {
 background:none;
 }
 .notice-options .notice_reply {