From 3a72c70b7e560023ecb7439be680942e4d0e6350 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 17 Mar 2010 12:34:35 -0700 Subject: [PATCH 1/5] When too-long messages come in via OStatus, mark the attachment link up as a "more" link in the HTML output, marked with class="attachment more" so JS code can fold it out smartly. Text output will still include the raw link. --- plugins/OStatus/classes/Ostatus_profile.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 73f5d23229..7b18fed9c8 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -547,9 +547,19 @@ 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. + $rendered = common_render_text($shortSummary) . + ' ' . + '' . + // TRANS: expansion link for too-long remote messages + htmlspecialchars(_m('(more)')) . + ''; } } From f797a10256969c0e3bf214967e5eafe8df886149 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 17 Mar 2010 13:58:25 -0700 Subject: [PATCH 2/5] Display scrubbed HTML attachments inline on attachment view page. --- lib/attachmentlist.php | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index dc6709d678..22ae8ba07a 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -330,6 +330,13 @@ class Attachment extends AttachmentListItem $this->out->element('param', array('name' => 'autoStart', 'value' => 1)); $this->out->elementEnd('object'); break; + + case 'text/html': + if ($this->attachment->filename) { + // Locally-uploaded HTML. Scrub and display inline. + $this->showHtmlFile($this->attachment); + } + break; } } } else { @@ -356,5 +363,60 @@ class Attachment extends AttachmentListItem } } } + + protected function showHtmlFile(File $attachment) + { + $body = $this->scrubHtmlFile($attachment); + if ($body) { + $this->out->elementStart('div', array('class' => 'inline-attachment')); + $this->out->raw($body); + $this->out->elementEnd('div'); + } + } + + /** + * @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