get text attachments directly instead of via the api

This commit is contained in:
Hannes Mannerheim 2015-09-21 00:58:11 +02:00
parent d35368039c
commit dcd4f55c69
2 changed files with 30 additions and 24 deletions

View File

@ -453,9 +453,9 @@ class QvitterPlugin extends Plugin {
$twitter_status['repeated_id'] = $repeated->id;
}
// thumb urls
// more metadata about attachments
// find all thumbs
// get all attachments first, and put all the extra meta data in an array
$attachments = $notice->attachments();
$attachment_url_to_id = array();
if (!empty($attachments)) {
@ -463,6 +463,11 @@ class QvitterPlugin extends Plugin {
if(is_object($attachment)) {
try {
$enclosure_o = $attachment->getEnclosure();
// add id to all attachments
$attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
// add data about thumbnails
$thumb = $attachment->getThumbnail();
$large_thumb = $attachment->getThumbnail(1000,3000,false);
if(method_exists('File_thumbnail','url')) {
@ -472,7 +477,6 @@ class QvitterPlugin extends Plugin {
$thumb_url = $thumb->getUrl();
$large_thumb_url = $large_thumb->getUrl();
}
$attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
$attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url;
$attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url;
$attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width;
@ -489,6 +493,7 @@ class QvitterPlugin extends Plugin {
}
}
// this applies to older versions of gnu social, i think
} catch (ServerException $e) {
$thumb = File_thumbnail::getKV('file_id', $attachment->id);
if ($thumb instanceof File_thumbnail) {
@ -515,18 +520,11 @@ class QvitterPlugin extends Plugin {
}
}
// add thumbs to $twitter_status
// add the extra meta data to $twitter_status
if (!empty($twitter_status['attachments'])) {
foreach ($twitter_status['attachments'] as &$attachment) {
if (!empty($attachment_url_to_id[$attachment['url']])) {
$attachment['id'] = $attachment_url_to_id[$attachment['url']]['id'];
$attachment['width'] = $attachment_url_to_id[$attachment['url']]['width'];
$attachment['height'] = $attachment_url_to_id[$attachment['url']]['height'];
$attachment['thumb_url'] = $attachment_url_to_id[$attachment['url']]['thumb_url'];
$attachment['large_thumb_url'] = $attachment_url_to_id[$attachment['url']]['large_thumb_url'];
if(isset($attachment_url_to_id[$attachment['url']]['animated'])) {
$attachment['animated'] = $attachment_url_to_id[$attachment['url']]['animated'];
}
$attachment = array_merge($attachment,$attachment_url_to_id[$attachment['url']]);
}
}
}

View File

@ -812,8 +812,7 @@ function expand_queet(q,doScrolling) {
q.prev().addClass('next-expanded');
// if shortened queet, get full text
if(q.children('.queet').find('span.attachment.more').length>0) {
var attachmentId = q.children('.queet').find('span.attachment.more').attr('data-attachment-id');
if(q.children('.queet').find('span.attachment.more').length>0 && q.data('attachments') != 'undefined') {
// get full html for queet, first try localstorage cache
var cacheData = localStorageObjectCache_GET('fullQueetHtml',qid);
@ -822,13 +821,22 @@ function expand_queet(q,doScrolling) {
q.children('.queet').outerHTML(detectRTL(q.children('.queet').outerHTML()));
}
else {
getFromAPI("attachment/" + attachmentId + ".json",function(data){
var attachmentId = q.children('.queet').find('span.attachment.more').attr('data-attachment-id');
// the url to the text/html attachment is in an array in an attribute
$.each(q.data('attachments'), function(k,attachment) {
if(attachment.id == attachmentId) {
$.get(attachment.url,function(data){
if(data) {
localStorageObjectCache_STORE('fullQueetHtml',qid,data);
q.children('.queet').find('.queet-text').html($.trim(data));
q.children('.queet').outerHTML(detectRTL(q.children('.queet').outerHTML()));
}
});
return false;
}
});
}
}
@ -1723,7 +1731,7 @@ function buildQueetHtml(obj, idInStream, extraClassesThisRun, requeeted_by, isCo
var attachmentNum = 0;
if(typeof obj.attachments != "undefined") {
$.each(obj.attachments, function(){
if(this.id != null) { // if there's an id we assume this is a image or video
if(typeof this.thumb_url != 'undefined' && this.thumb_url !== null) { // if there's a thumb_url we assume this is a image or video
var bigThumbW = 1000;
var bigThumbH = 3000;
if(bigThumbW > window.siteMaxThumbnailSize) {
@ -1754,11 +1762,11 @@ function buildQueetHtml(obj, idInStream, extraClassesThisRun, requeeted_by, isCo
// animated gifs always get default small non-animated thumbnail
if(this.animated === true && typeof this.thumb_url != 'undefined') {
if(this.animated === true) {
var img_url = this.thumb_url;
}
// if no dimensions are set, go with default thumb
else if(this.width === null && this.height === null && typeof this.thumb_url != 'undefined') {
else if(this.width === null && this.height === null) {
var img_url = this.thumb_url;
}
// large images get large thumbnail