Do we have a Twitter embed plugin ?
Shouldn't be crazy hard to port this over: http://custom.simplemachines.org/mods/index.php?mod=3837
I think I wrote something a while ago, but I couldn't find anything around... maybe it was just a déjà vu... OMG The Matrix is changing!! :P
Hmm... at some point I'll try that as a test of the hooks in my BBC parser. You couldn't do the automatic Tweet link to embedded tweet without code edits in the current version but you can do the tag version pretty easily with a single simple hook.
Found this. Want to use ?
https://twitframe.com/
I was looking for a twitter-embed add-on today and it looks like none exists. Has anyone gone the bbcode route on their forums? Have some tips on how to implement?
I had a moment of madness and put together something fancy. :P
The php code could be just:
$message = preg_replace_callback('~<a href="(http[s]?://twitter.com/\w+/status/\d+)" (.*?)>\1</a>~',
function($matches) {
$matches[2] = str_replace('class="', 'class="twitter_embed ', $matches[2]);
return '<a href="' . $matches[1] . '" ' . $matches[2] . '>' . $matches[1] . '</a>';
},
$message
);
static $load_js = true;
if ($load_is === true)
{
loadJavascriptFile('twitter_embed.jquery.js');
addInlineJavascript('
$(document).ready(function() {
$(".twitter_embed").lazyload();
});');
$load_js = false;
}
put in a function and attached to the integrate_post_parsebbc hook.
Then there is a bit of javascript that is a modified version of https://github.com/tuupola/jquery_lazyload (and is attached here).
The two will work together to embed the twitter post only when scrolling the message appears in the viewport.
Hey!! Put this in addons will ya... :P
Too lazy and too many other things to do. :P
I'm too new to modifying ElkArte to make much sense of this, I'm afraid.
"put in a function"? How do you do this? Put it in an existing php file of functions? And how do you attach to the hook? jquery_lazyload doesn't exist currently in my installation, so I assume it's just an upload.
goddamnit I'm going to have to learn fudge nuggets, aren't I?
If nobody else will pack it before, I can have a look at it... let's say before the end of next week.
Candidate for default ;D
Nice but nicer if we can also do vice versa tweet post from elkarte to tweeter. Will be great if can the same with FB as well. And instagram etc... :D :D :D
You mean auto sharing on social media ?
Hello! Wondering if you've had any time to think about this.
In the last few days I barely had time to look at the bug reports. xD
Next week. ;)
I feel like such a pest!
Not tested at all.
I have not even idea if it installs. O:-)
Thank you! I'll install it on a test system tonight and let you know how it goes!
Sorry for the delay in feedback.
The package throws a "Modification parse error" in the preinstall check. Is the package complete?
Some more detail: the parse error is nothing to do with existing files. It's related to the extraction of /themes/default/scripts/nofollow.twitter_embed.bbcode.js from the package.
The problem is that there is no such file in the package, which makes it a bit difficult to extract the thing. The only js file in the package is twitter_embed.jquery.js, and when I looked at the code in that file it turned out to be a jQuery plug-in for lazy loading images.
/*!
* Lazy Load - jQuery plugin for lazy loading images
*
* Copyright (c) 2007-2015 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* http://www.appelsiini.net/projects/lazyload
*
* Version: 1.9.7
*
*/
Methinks the package has a minor bug or two. :D
Yes, I used the lazyloading plugin in order to fetch twitter only when it's needed (i.e. when the potential embed enters the visible screen).
Sooo... yes, I guess I didn't pay much attention to the renaming, you can unzip, rename "nofollow.twitter_embed.bbcode.js" to "twitter_embed.bbcode.js", zip again and upload. :)
Since
@emanuele is being lazy :P I repacked it with the js name correction.
There were also a couple of other little things that I updated, without which you may have gotten a white screen after you installed it.
Bonzer. I'll give it a whirl and see what else it kills. :D
Edit: Seems to be fine. Tweets work. No errors in log. Throw the deranged on the add-ons site.
Cheers.
Thank you!!!
If it was just a couple I consider myself pretty lucky! xD
Ok, next question: can we haz hard working load? As is not lazy? :D
Coz although I understand the idea of lazy load, and although it's a good one as far as it goes, in practice the jumpy flashing tweets are not exactly the thing to soothe savage beasts. So if they weren't all lazy they would be easier to get along with, and I don't think the number of them per page is likely to be a serious issue.
So AFAICT simply killing this in TwitterEmbedder.integrate.php should do the trick, yes?
protected static $load_js = true;
if (self::$load_js === true)
{
loadJavascriptFile('twitter_embed.jquery.js', array('defer' => true));
addInlineJavascript('
$(document).ready(function() {
$(".twitter_embed").lazyload();
});', true);
self::$load_js = false;
}
Ok so that doesn't work. However this gets rid of most of the annoying behaviour.
if (self::$load_js === true)
{
loadJavascriptFile('twitter_embed.jquery.js', array('defer' => true));
addInlineJavascript('
$(document).ready(function() {
$(".twitter_embed").lazyload({
threshold : 800
});
});', true);
self::$load_js = false;
}
It's not that I did them thinking about loading time or some performances issues, just because I had the plugin handy and it seemed easy to make it work that way. :P
Hey Ema, there has been a little bit of grumbling about the add-on. Yes, I know, it's amazing. Who would have thought that users would grumble about results of someone's coding? Ungrateful mongrels, the lot of them.
Anyway, the first catch is the ?ref_src=twsrc%5Etfw suffix that is added when tweets are linked via social media. Copying the complete url, including suffix, breaks embedding. So as an example this is fine:
https://twitter.com/Shareblue/status/842491578191110146
But this breaks the add-on:
https://twitter.com/Shareblue/status/842491578191110146?ref_src=twsrc%5Etfw
We have told the grumblers that all they have to do is remove the suffix, but apparently this is a gross infringement of their sacred human rights and there should be a law against it. It's the first step on the road to fascism and will undoubtedly result in kittens having sex with warthogs.
The other catch is if someone is browsing on a phone. In that case Twitter will send them to this:
https://mobile.twitter.com/Shareblue/status/842491578191110146
or this:
https://.mobile.twitter.com/Shareblue/status/842491578191110146?ref_src=twsrc%5Etfw
Both of those will break the add-on.
So, how hard would it be to tweak the PHP so that it can handle both the mobile prefix (if it exists) and/or the bafflecrud suffix (if that exists) as well as the basic url that it can deal with now?
https://.mobile.twitter.com/Shareblue/status/842491578191110146?ref_src=twsrc%5Etfw
Is that even a valid URL? But yes, that'd be very easy to do. See line 19 in 0.0.2.
$message = preg_replace_callback('~<a href="(http[s]?://twitter.com/\w+/status/\d+)" (.*?)>\1</a>~',
I can't be bothered to look up the specific PHP regex syntax atm, but the basic idea would be something like this:
(http[s]?://(\.?mobile\.)?twitter.com/\w+/status/\d+(\?.*)?)
Edit: Or more concretely as part of the whole, like this:
$message = preg_replace_callback('~<a href="(http[s]?://(\.?mobile\.)?twitter.com/\w+/status/\d+(\?.*)?)" (.*?)>\1</a>~',
You should probably replace that greedy .* with something slightly safer, for example:
\?ref_src=[\w%]+
However, I don't know enough about that ref_src thing to tell.
Also you would need to make those groups non-matching with (?:blabla) or whichever syntax applies, or otherwise name your actually relevant groups. Sorry, that quick drive-by is all I have time for. :)
Yes, it is, nothing particularly wrong with it.
BTW, Twitter is famous for find any kind of funky url, I still remember the fuss for the autolinking when they were using the # as part of the URL and not as the identifier of the beginning of the fragment (that is valid according to the URL specifications).
Judging by what I can seen on the internet, I think the first is fine. You can at maximum add the ref_src, bit the . is probably a must:
$message = preg_replace_callback('~<a href="(http[s]?://(\.?mobile\.)?twitter.com/\w+/status/\d+(\?ref_src=.*)?)" (.*?)>\1</a>~',
Cool. I'll do some testing later and see how it goes.
Something
is wrong with it though. Are you sure you can actually have an empty subdomain? In any case, .mobile.twitter.com doesn't resolve in any browser or tool I've tried, so in the unlikely case it does make sense either they haven't set it up correctly or none of the tools consider a technical loophole in the rules a sensible interpretation.
$ ping .mobile.twitter.com
ping: .mobile.twitter.com: Name or service not known
$ ping mobile.twitter.com
PING mobile.twitter.com (199.16.156.107) 56(84) bytes of data.
Edit: https://tools.ietf.org/html/rfc1123#page-13
It says that the first character of a host name can be "either a letter or a digit". Not a nothing. Admittedly I only briefly checked the RFCs that may have superseded this document that's almost as old as I am. I couldn't find anything that seemed relevant, but methinks the only sensible overrides would be widening the definition of "letter" (e.g., to all or at least a great many UTF-8 characters) and allowing longer domain names.
Ohh... I didn't notice the dot, no it is most likely a typo. The correct address is mobile.twitter.com
But why would I think a little URL-encoded ^ was invalid? lol :P
I have no idea. xD
Yup, typo on my part. Sorry about that.
Haven't got around to testing the proposed code yet. Will try to remember.
In that case you can simplify the regex to something like this:
$message = preg_replace_callback('~<a href="(http[s]?://(mobile\.)?twitter.com/\w+/status/\d+(\?.*)?)" (.*?)>\1</a>~',
I think you can make named groups using (?P<name>stuff to match) if necessary.
Is the addon updated? I get "Modification parse error" for ./themes/default/scripts/nofollow.twitter_embed.bbcode.js
Hi
@Jason which one did you use?
Did you try the one from Spuds https://www.elkarte.net/community/index.php?topic=2937.msg31153#msg31153 ?
@emanuele I used the file which was given by you, now tried Spuds. It installed without any issues.. But once again a noob question. How to embed twitter link. Should i use the Embed Tweet link or Twitter post link?
I'm not expert of twitter either, I think that if you just put the url of a twit it should just work... I think.
Something like this:
https://twitter.com/ElkArteForum/status/974425972354224128
Twitter supports OEmbed, by the way ...
I tried pasting the link as well as the embed tweet code. It doesn't work
What a pain... why did the hook name changed? xD
Same considerations done with my first package: I have no idea if it installs properly.
@forumsearch0r2 it's just a javascript library that uses OEmbed. The php trick is just to add the correct class to the tag.
I wouldn't use JavaScript for that. It would have to be fetched on every page call.
Yeah, but then it's a problem of the client (and twitter). :P
Sorry emanuele, still the same thing. It displays as link
Can I see an example?
A live one was my idea, can't get much out of a picture. :P
Have I mentioned that mine works?
Where is it? So I can get rid of another addon to "support"? 8)
BTW there were a couple of other issues. O:-)
@emanuele sorry again it failed.. and
@forumsearch0r2 let me try this addon itself..
The plugin does not work