This commit is contained in:
Hannes Mannerheim 2016-01-20 17:39:34 +01:00
parent 830ef883e0
commit bcb88e5239
6 changed files with 171 additions and 31 deletions

View File

@ -513,6 +513,22 @@ class QvitterPlugin extends Plugin {
try {
$enclosure_o = $attachment->getEnclosure();
// Oembed
if(array_key_exists('Oembed', StatusNet::getActivePlugins())) {
$oembed = File_oembed::getKV('file_id',$attachment->id);
if($oembed instanceof File_oembed) {
$attachment_url_to_id[$enclosure_o->url]['oembed'] = array(
'provider'=> $oembed->provider,
'provider_url'=> $oembed->provider_url,
'oembedHTML'=> $oembed->html,
'title'=> $oembed->title,
'author_url'=> $oembed->author_url
);
} else {
$attachment_url_to_id[$enclosure_o->url]['oembed'] = false;
}
}
// add id to all attachments
$attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id;
@ -536,8 +552,7 @@ class QvitterPlugin extends Plugin {
$image = ImageFile::fromFileObject($attachment);
if($image->animated == 1) {
$attachment_url_to_id[$enclosure_o->url]['animated'] = true;
}
else {
} else {
$attachment_url_to_id[$enclosure_o->url]['animated'] = false;
}
}

View File

@ -87,6 +87,12 @@ class QvitterAction extends ApiAction
$attachmentroot = common_path('attachment/', StatusNet::isHTTPS());
$instanceurl = common_path('', StatusNet::isHTTPS());
// user's browser's language setting
$user_browser_language = 'en'; // use english if we can't find the browser language
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$user_browser_language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
common_set_returnto(''); // forget this
@ -196,8 +202,8 @@ class QvitterAction extends ApiAction
for the JavaScript code in this page.
*/
window.usersLanguageCode = <?php print json_encode(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)) ?>;
window.usersLanguageNameInEnglish = <?php print json_encode(Locale::getDisplayLanguage(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), 'en')) ?>;
window.usersLanguageCode = <?php print json_encode($user_browser_language) ?>;
window.usersLanguageNameInEnglish = <?php print json_encode(Locale::getDisplayLanguage($user_browser_language, 'en')) ?>;
window.englishLanguageData = <?php print file_get_contents($qvitterpath.'/locale/en.json'); ?>;
window.defaultAvatarStreamSize = <?php print json_encode(Avatar::defaultImage(AVATAR_STREAM_SIZE)) ?>;
window.defaultAvatarProfileSize = <?php print json_encode(Avatar::defaultImage(AVATAR_PROFILE_SIZE)) ?>;
@ -664,7 +670,8 @@ class QvitterAction extends ApiAction
#popup-faq #faq-container p.indent,
.post-to-group,
.quoted-notice:hover,
.stream-item:hover:not(.expanded) .quoted-notice: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*/;
}
span.inline-reply-caret .caret-inner {

View File

@ -1942,7 +1942,7 @@ background-repeat: no-repeat;
body.rtl .queet.rtl .expanded-content {
direction:rtl;
}
.stream-item.expanded div:first-child {
.stream-item.expanded > div:first-child {
border-top-left-radius:6px;
border-top-right-radius:6px;
}
@ -2028,11 +2028,13 @@ body.rtl .queet.rtl .expanded-content {
display:block;
}
.quoted-notices {
.quoted-notices,
.oembed-data {
width:100%;
position:relative;
}
.quoted-notice {
.quoted-notice,
.oembed-item {
width:100%;
border: 1px solid #eee;
border-radius: 4px;
@ -2045,10 +2047,14 @@ body.rtl .queet.rtl .expanded-content {
color:#292f33 !important;
overflow: hidden;
}
.oembed-item {
padding:0;
}
.quoted-notice:hover {
text-decoration: none !important;
}
.stream-item:hover:not(.expanded) .quoted-notice {
.stream-item:hover:not(.expanded) .quoted-notice ,
.stream-item:hover:not(.expanded) .oembed-item {
border: 1px solid #ddd;
}
@ -2064,7 +2070,8 @@ body.rtl .queet.rtl .expanded-content {
float: left;
}
.quoted-notice-img-container {
.quoted-notice-img-container,
.oembed-img-container {
height: 102px;
width: 102px;
display: inline-block;
@ -2074,6 +2081,12 @@ body.rtl .queet.rtl .expanded-content {
background-repeat:no-repeat;
background-position: center;
}
.oembed-img-container {
height: 125px;
width: 125px;
margin:0 10px 0 0;
float: left;
}
.quoted-notice-attachments-num-1 .quoted-notice-img-container {
height: 100%;
@ -2081,7 +2094,8 @@ body.rtl .queet.rtl .expanded-content {
margin:0;
}
.quoted-notice-img {
.quoted-notice-img,
.oembed-img {
height: 100%;
opacity: 0;
width: 100%;
@ -2107,6 +2121,47 @@ body.rtl .queet.rtl .expanded-content {
word-wrap: break-word;
}
.oembed-item-header {
padding:10px 10px 0 0;
line-height: 18.5px;
margin-bottom:2px;
font-weight:bold;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.oembed-item-body {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
max-height:55px;
overflow: hidden;
text-overflow: ellipsis;
}
.oembed-item-body,
.oembed-item-footer {
padding:0 10px 0 0;
line-height: 18.3px;
margin-top:4.5px;
}
.oembed-item-footer {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color:#999;
padding-bottom: 9px;
}
.oembed-item-provider-url {
font-style:italic;
}
.oembed-item-provider-url:not(:empty)::before {
content:' · ';
}
.oembed-item-header,
.oembed-item-body,
.oembed-item-footer {
margin-left:10px;
}
.queet .queet-thumbs {
-webkit-transition: max-height 0s linear;

View File

@ -1155,7 +1155,7 @@ function expand_queet(q,doScrolling) {
}
catch(e) {
var attachmentsParsed = false;
console.log('could not parse attachment data when expanding the notice');
console.log('could not parse attachment data when expanding the notice: ' + e);
}
if(attachmentsParsed !== false) {
$.each(attachmentsParsed, function() {
@ -2119,9 +2119,11 @@ function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversat
· · · · · · · · · · · · · */
function buildAttachmentHTML(attachments){
var attachment_html = '';
var attachmentHTML = '';
var oembedHTML = '';
var quotedNotices = [];
var attachmentNum = 0;
var oembedNum = 0;
var urlsToHide = [];
if(typeof attachments != "undefined") {
$.each(attachments, function(){
@ -2153,7 +2155,7 @@ function buildAttachmentHTML(attachments){
}
}
var quotedNoticeHTML = '<a href="' + window.siteInstanceURL + 'notice/' + this.quoted_notice.id + '" class="quoted-notice" data-notice-url=' + this.url + '>\
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>\
@ -2166,6 +2168,57 @@ function buildAttachmentHTML(attachments){
quotedNotices.push({url: this.url, html: quotedNoticeHTML});
}
// if we have oembed data
else if(typeof this.oembed != 'undefined'
&& this.oembed !== false
&& this.oembed.title !== null) {
var oembedImage = '';
// not if stripped from html it's the same as the title (wordpress does this..)
if(typeof this.thumb_url != 'undefined' && this.thumb_url !== null) {
oembedImage = '<div class="oembed-img-container" style="background-image:url(\'' + this.thumb_url + '\')"><img class="oembed-img" src="' + this.thumb_url + '" /></div>';
}
var oembedBody = '';
try {
var oembedStrippedHTML = $.trim($('<div>' + this.oembed.oembedHTML + '</div>').text().replace('<!--//-->',''));
}
catch(e) {
var oembedStrippedHTML = '';
}
// not if stripped from html it's the same as the title (wordpress does this..)
if(this.oembed.oembedHTML !== null
&& oembedStrippedHTML.length > 0
&& oembedStrippedHTML != $.trim(this.oembed.title)) {
if(oembedStrippedHTML.length > 160) {
oembedStrippedHTML = oembedStrippedHTML.substring(0,250) + '…';
}
oembedBody = oembedStrippedHTML;
}
if(this.oembed.provider === null) {
var oembedProvider = this.url;
var oembedProviderURL = '';
}
else {
var oembedProvider = this.oembed.provider;
var oembedProviderURL = removeProtocolFromUrl(this.oembed.provider_url);
}
oembedHTML += '<a href="' + this.url + '" class="oembed-item">\
' + oembedImage + '\
<div class="oembed-item-header">\
<span class="oembed-item-title">' + this.oembed.title + '</span>\
</div>\
<div class="oembed-item-body">' + oembedBody + '</div>\
<div class="oembed-item-footer">\
<span class="oembed-item-provider">' + this.oembed.provider + '</span>\
<span class="oembed-item-provider-url">' + oembedProviderURL + '</span>\
</div>\
</a>';
oembedNum++;
}
// if there's a local thumb_url we assume this is a image or video
else if(typeof this.thumb_url != 'undefined'
&& this.thumb_url !== null
@ -2225,20 +2278,19 @@ function buildAttachmentHTML(attachments){
var img_url = this.thumb_url;
}
attachment_html = attachment_html + '<a style="background-image:url(\'' + img_url + '\')" class="thumb-container' + noCoverClass + playButtonClass + youTubeClass + animatedGifClass + '" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + img_url + '"/ data-width="' + this.width + '" data-height="' + this.height + '" data-full-image-url="' + this.url + '" data-thumb-url="' + img_url + '"></a>';
attachmentHTML += '<a style="background-image:url(\'' + img_url + '\')" class="thumb-container' + noCoverClass + playButtonClass + youTubeClass + animatedGifClass + '" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + img_url + '"/ data-width="' + this.width + '" data-height="' + this.height + '" data-full-image-url="' + this.url + '" data-thumb-url="' + img_url + '"></a>';
urlsToHide.push(window.siteInstanceURL + 'attachment/' + this.id); // hide this attachment url from the queet text
// urlsToHide.push(this.url);
attachmentNum++;
}
else if (this.mimetype == 'image/svg+xml') {
attachment_html = attachment_html + '<a style="background-image:url(\'' + this.url + '\')" class="thumb-container" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + this.url + '"/></a>';
attachmentHTML += '<a style="background-image:url(\'' + this.url + '\')" class="thumb-container" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + this.url + '"/></a>';
urlsToHide.push(window.siteInstanceURL + 'attachment/' + this.id); // hide this attachment url from the queet text
// urlsToHide.push(this.url);
attachmentNum++;
}
});
}
return { html: '<div class="queet-thumbs thumb-num-' + attachmentNum + '">' + attachment_html + '</div>',
return { html: '<div class="oembed-data oembed-num-' + oembedNum + '">' + oembedHTML + '</div><div class="queet-thumbs thumb-num-' + attachmentNum + '">' + attachmentHTML + '</div>',
urlsToHide: urlsToHide,
quotedNotices: quotedNotices };
quotedNotices: quotedNotices
};
}

View File

@ -676,6 +676,12 @@ function guessInstanceUrlWithoutProtocolFromProfileUrlAndNickname(profileUrl, ni
· · · · · · · · · */
function removeProtocolFromUrl(url) {
if(typeof url == 'undefined'
|| url === null
|| url === false
|| url == '') {
return '';
}
if(url.indexOf('://') == -1) {
return url;
}
@ -878,7 +884,7 @@ function searchForUpdatedNoticeData(obj) {
streamItemFoundInFeed.attr('data-attachments',JSON.stringify(obj.attachments));
var attachmentsHTMLBuild = buildAttachmentHTML(obj.attachments);
queetFoundInFeed.find('.queet-thumbs').remove();
queetFoundInFeed.find('.quoted-notices').remove();
queetFoundInFeed.find('.oembed-data').remove();
// 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) {
@ -936,6 +942,7 @@ function slideUpAndRemoveStreamItem(streamItem,callback) {
$(this).css('height',$(this).height() + 'px');
$(this).animate({height:'0px'},500,'linear',function(){
$(this).addClass('deleted always-hidden');
rememberStreamStateInLocalStorage();
if(typeof callback == 'function') {
callback();
}
@ -1165,7 +1172,10 @@ function iterateRecursiveReplaceHtmlSpecialChars(obj) {
if (typeof obj[property] == "object") {
iterateRecursiveReplaceHtmlSpecialChars(obj[property]);
}
else if(typeof obj[property] == 'string' && property != 'statusnet_html' && property != 'source') {
else if(typeof obj[property] == 'string'
&& property != 'statusnet_html'
&& property != 'oembedHTML' // this is hopefully purified by gnusocial
&& property != 'source') {
obj[property] = replaceHtmlSpecialChars(obj[property]);
}
}

View File

@ -1820,7 +1820,9 @@ $('body').on('click','#new-queets-bar',function(){
· · · · · · · · · · · · · */
$('body').on('click','.queet',function (event) {
if(!$(event.target).is('\
if(typeof $(this).attr('href') == 'undefined'
&& $(event.target).closest('a').length == 0
&& !$(event.target).is('\
a,\
video,\
.cm-mention,\
@ -2545,7 +2547,6 @@ $('body').on('click', '.queet-toolbar button',function () {
if(parentQueetBox.length == 0
|| parentQueetBox.children('.syntax-middle').css('display') == 'none') {
if(insertedTempQueet.parent().hasClass('expanded') || insertedTempQueet.parent().hasClass('conversation')) {
console.log(parentQueetBox.attr('data-replies-text'));
if(parentQueetBox.children('.queet-box').attr('data-replies-text') == '') {
insertedTempQueet.parent().find('.inline-reply-queetbox').remove();
newInsertedQueet.children('.queet').append(replyFormHtml(newInsertedQueet,newInsertedQueet.attr('data-quitter-id')));
@ -3196,7 +3197,7 @@ $('body').keyup(function (e) {
// reply to queet on 'r'
else if(e.which == 82) {
if(selectedQueet.hasClass('expanded')) {
selectedQueet.children('.queet').find('.queet-box-syntax').click();
selectedQueet.find('.queet-box-syntax').click();
}
else {
selectedQueet.children('.queet').find('.icon.sm-reply').click();