Updated 'more' anchor for attachments to do an XHR GET

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.
This commit is contained in:
Brion Vibber 2010-03-25 14:15:54 -07:00
parent 7fc8b6af4a
commit c11064a539
6 changed files with 140 additions and 54 deletions

View File

@ -399,6 +399,17 @@ var SN = { // StatusNet
return;
}
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());
});
return false;
});
}
else {
$.fn.jOverlay.options = {
method : 'GET',
data : '',
@ -452,6 +463,7 @@ var SN = { // StatusNet
}
);
}
}
},
NoticeDataAttach: function() {

View 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

View 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>';
}
}

View 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;

View 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 {

View 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 {