handle twitter oembed in same way as quotes
This commit is contained in:
parent
51b25f4a2b
commit
3b39b3fc43
|
@ -520,14 +520,23 @@ class QvitterPlugin extends Plugin {
|
|||
$oembed = File_oembed::getKV('file_id',$attachment->id);
|
||||
if($oembed instanceof File_oembed) {
|
||||
$oembed_html = str_replace('<!--//-->','',$oembed->html); // trash left of wordpress' javascript after htmLawed removed the tags
|
||||
if($oembed->provider == 'Twitter' && strstr($oembed_html, '<div>—')) {
|
||||
$oembed_html = substr($oembed_html,0,strpos($oembed_html, '<div>—')); // remove user data from twitter oembed html (we have it in )
|
||||
$twitter_username = substr($oembed->html,strpos($oembed->html, '<div>—')+12);
|
||||
$twitter_username = substr($twitter_username, strpos($twitter_username,'(@')+1);
|
||||
$twitter_username = substr($twitter_username, 0,strpos($twitter_username,')'));
|
||||
$oembed->title = $twitter_username;
|
||||
}
|
||||
$oembed_html = str_replace('…','...',$oembed_html); // ellipsis is sometimes stored as html in db, for some reason
|
||||
$oembed_html = strip_tags(html_entity_decode($oembed_html)); // sometimes we have html charachters that we want to decode and then strip
|
||||
$oembed_title = strip_tags(html_entity_decode($oembed->title));
|
||||
$oembed_title = strip_tags(html_entity_decode($oembed->title));
|
||||
$attachment_url_to_id[$enclosure_o->url]['oembed'] = array(
|
||||
'type'=> $oembed->type,
|
||||
'provider'=> $oembed->provider,
|
||||
'provider_url'=> $oembed->provider_url,
|
||||
'oembedHTML'=> $oembed_html,
|
||||
'title'=> $oembed_title,
|
||||
'author_name'=> $oembed->author_name,
|
||||
'author_url'=> $oembed->author_url
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -685,6 +685,7 @@ class QvitterAction extends ApiAction
|
|||
#popup-faq #faq-container p.indent,
|
||||
.post-to-group,
|
||||
.quoted-notice:hover,
|
||||
.oembed-item:hover,
|
||||
.stream-item:hover:not(.expanded) .quoted-notice:hover,
|
||||
.stream-item:hover:not(.expanded) .oembed-item:hover {
|
||||
border-color:/*LIGHTERBORDERCOLORSTART*/rgb(155,206,224)/*LIGHTERBORDERCOLOREND*/;
|
||||
|
|
|
@ -2050,7 +2050,8 @@ body.rtl .queet.rtl .expanded-content {
|
|||
.oembed-item {
|
||||
padding:0;
|
||||
}
|
||||
.quoted-notice:hover {
|
||||
.quoted-notice:hover,
|
||||
.oembed-item:hover {
|
||||
text-decoration: none !important;
|
||||
}
|
||||
.stream-item:hover:not(.expanded) .quoted-notice ,
|
||||
|
@ -2130,6 +2131,11 @@ body.rtl .queet.rtl .expanded-content {
|
|||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.oembed-twitter-username {
|
||||
font-size:13px;
|
||||
color:#999;
|
||||
font-weight:normal;
|
||||
}
|
||||
.oembed-item-body {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
|
|
|
@ -2028,37 +2028,10 @@ function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversat
|
|||
}
|
||||
});
|
||||
});
|
||||
// try to find a place in the queet-text for the quoted notices
|
||||
var quotedNoticesNotFoundInQueetTextHTML = '';
|
||||
var quoteURLfoundInQueetText = false;
|
||||
$.each(attachmentBuild.quotedNotices,function(k,qoutedNotice){
|
||||
if(typeof qoutedNotice.url != 'undefined') {
|
||||
quoteURLfoundInQueetText = false;
|
||||
$.each(statusnetHTML.find('a').not('.quoted-notice'), function(){
|
||||
if(removeProtocolFromUrl($(this).attr('href')) == removeProtocolFromUrl(qoutedNotice.url) && $(this).css('display') != 'none') {
|
||||
quoteURLfoundInQueetText = true;
|
||||
$(this).css('display','none');
|
||||
$(this).after(qoutedNotice.html);
|
||||
// remove unnecessary line breaks, i.e. remove br between two quoted notices
|
||||
if($(this).prev().is('br')) {
|
||||
$(this).prev().remove();
|
||||
}
|
||||
return false; // break
|
||||
}
|
||||
});
|
||||
if(quoteURLfoundInQueetText === false) {
|
||||
console.log('not found: ' + qoutedNotice.html);
|
||||
quotedNoticesNotFoundInQueetTextHTML += qoutedNotice.html;
|
||||
}
|
||||
}
|
||||
});
|
||||
// find a place in the queet-text for the quoted notices
|
||||
statusnetHTML = placeQuotedNoticesInQueetText(attachmentBuild.quotedNotices, statusnetHTML);
|
||||
statusnetHTML = statusnetHTML.html();
|
||||
|
||||
// quoted notices that we didn't find in the queet text is placed below the text
|
||||
if(quotedNoticesNotFoundInQueetTextHTML.length > 0) {
|
||||
attachmentBuild.html = '<div class="quoted-notices">' + quotedNoticesNotFoundInQueetTextHTML + '</div>' + attachmentBuild.html;
|
||||
}
|
||||
|
||||
// external
|
||||
var ostatusHtml = '';
|
||||
if(obj.is_local === false) {
|
||||
|
@ -2108,6 +2081,43 @@ function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversat
|
|||
}
|
||||
|
||||
|
||||
/* ·
|
||||
·
|
||||
· Place quoted notices in the queet text
|
||||
·
|
||||
· @param quotedNotices: object returned by buildAttachmentHTML()
|
||||
· @param queetText: jQuery object for queet text
|
||||
·
|
||||
· · · · · · · · · */
|
||||
|
||||
function placeQuotedNoticesInQueetText(quotedNotices,queetText) {
|
||||
$.each(quotedNotices,function(k,qoutedNotice){
|
||||
if(typeof qoutedNotice.url != 'undefined') {
|
||||
var quoteLinkFound = queetText.find('a[href*="' + removeProtocolFromUrl(qoutedNotice.url) + '"]');
|
||||
// if we can't found it in a href, we might find it in data-quote-url attribute!
|
||||
if(quoteLinkFound.length==0) {
|
||||
quoteLinkFound = queetText.find('a[data-quote-url*="' + removeProtocolFromUrl(qoutedNotice.url) + '"]');
|
||||
}
|
||||
if(quoteLinkFound.length>0) {
|
||||
quoteLinkFound.each(function(){
|
||||
$(this).addClass(qoutedNotice.class);
|
||||
$(this).attr('href',qoutedNotice.href);
|
||||
$(this).attr('data-quote-url',qoutedNotice.url);
|
||||
$(this).html(qoutedNotice.html);
|
||||
// remove unnecessary line breaks, i.e. remove br between two quoted notices
|
||||
if($(this).prev().is('br')) {
|
||||
$(this).prev().remove();
|
||||
}
|
||||
if(!$(this).next().is('br')) {
|
||||
$(this).after('<br>');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return queetText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ·
|
||||
|
@ -2155,24 +2165,50 @@ function buildAttachmentHTML(attachments){
|
|||
}
|
||||
}
|
||||
|
||||
var quotedNoticeHTML = '<a href="' + window.siteInstanceURL + 'notice/' + this.quoted_notice.id + '" class="quoted-notice" data-notice-url="' + this.url + '">\
|
||||
' + quotedAttachmentsHTMLbefore + '\
|
||||
<div class="quoted-notice-header">\
|
||||
<span class="quoted-notice-author-fullname">' + this.quoted_notice.fullname + '</span>\
|
||||
<span class="quoted-notice-author-nickname">' + this.quoted_notice.nickname + '</span>\
|
||||
</div>\
|
||||
<div class="quoted-notice-body">' + $.trim(quotedContent) + '</div>\
|
||||
' + quotedAttachmentsHTMLafter + '\
|
||||
</a>';
|
||||
var quotedNoticeHTML = quotedAttachmentsHTMLbefore + '\
|
||||
<div class="quoted-notice-header">\
|
||||
<span class="quoted-notice-author-fullname">' + this.quoted_notice.fullname + '</span>\
|
||||
<span class="quoted-notice-author-nickname">' + this.quoted_notice.nickname + '</span>\
|
||||
</div>\
|
||||
<div class="quoted-notice-body">' + $.trim(quotedContent) + '</div>\
|
||||
' + quotedAttachmentsHTMLafter;
|
||||
|
||||
quotedNotices.push({url: this.url, html: quotedNoticeHTML});
|
||||
quotedNotices.push({
|
||||
url: this.url,
|
||||
html: quotedNoticeHTML,
|
||||
href: window.siteInstanceURL + 'notice/' + this.quoted_notice.id,
|
||||
class:'quoted-notice'
|
||||
});
|
||||
}
|
||||
|
||||
// if we have oembed data (but not for youtube, we handle that later)
|
||||
// if we have Twitter oembed data, we add is as quotes
|
||||
else if(typeof this.oembed != 'undefined'
|
||||
&& this.oembed !== false
|
||||
&& this.oembed.provider == 'Twitter') {
|
||||
|
||||
var twitterHTML = '<div class="oembed-item-header">\
|
||||
<span class="oembed-item-title">\
|
||||
' + this.oembed.author_name + '\
|
||||
<span class="oembed-twitter-username">' + this.oembed.title + '</span>\
|
||||
</span>\
|
||||
</div>\
|
||||
<div class="oembed-item-body">' + this.oembed.oembedHTML + '</div>\
|
||||
<div class="oembed-item-footer">\
|
||||
<span class="oembed-item-provider">' + this.oembed.provider + '</span>\
|
||||
</div>';
|
||||
quotedNotices.push({
|
||||
url: this.url,
|
||||
html: twitterHTML,
|
||||
href: this.url,
|
||||
class:'oembed-item'
|
||||
});
|
||||
}
|
||||
// if we have other oembed data (but not for photos and youtube, we handle those later)
|
||||
else if(typeof this.oembed != 'undefined'
|
||||
&& this.oembed !== false
|
||||
&& this.oembed.title !== null
|
||||
&& this.oembed.provider != 'YouTube') {
|
||||
&& this.oembed.provider != 'YouTube'
|
||||
&& this.oembed.type != 'photo') {
|
||||
|
||||
var oembedImage = '';
|
||||
// not if stripped from html it's the same as the title (wordpress does this..)
|
||||
|
|
|
@ -885,6 +885,7 @@ function searchForUpdatedNoticeData(obj) {
|
|||
var attachmentsHTMLBuild = buildAttachmentHTML(obj.attachments);
|
||||
queetFoundInFeed.find('.queet-thumbs').remove();
|
||||
queetFoundInFeed.find('.oembed-data').remove();
|
||||
placeQuotedNoticesInQueetText(attachmentsHTMLBuild.quotedNotices,queetFoundInFeed.find('.queet-text'));
|
||||
// we might want to hide urls (rendered as attachments) in the queet text
|
||||
$.each(queetFoundInFeed.find('.queet-text').find('a'),function(){
|
||||
if(attachmentsHTMLBuild.urlsToHide.indexOf($(this).text()) > -1) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user