Skip to main content
Topic: Twitter embed (Read 2828 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Twitter embed

Reply #30
Code: [Select]
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.

Code: [Select]
$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:

Code: [Select]
(http[s]?://(\.?mobile\.)?twitter.com/\w+/status/\d+(\?.*)?)

Edit: Or more concretely as part of the whole, like this:
Code: [Select]
$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:
Code: [Select]
\?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. :)

 

Re: Twitter embed

Reply #31
Code: [Select]
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.
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).

You should probably replace that greedy .* with something slightly safer, for example:
Code: [Select]
\?ref_src=[\w%]+
However, I don't know enough about that ref_src thing to tell.
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:
Code: [Select]
$message = preg_replace_callback('~<a href="(http[s]?://(\.?mobile\.)?twitter.com/\w+/status/\d+(\?ref_src=.*)?)" (.*?)>\1</a>~',
Bugs creator.
Features destroyer.
Template killer.

Re: Twitter embed

Reply #32
Cool. I'll do some testing later and see how it goes.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Twitter embed

Reply #33
Code: [Select]
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.
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).

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.
Code: [Select]
$ 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.

Re: Twitter embed

Reply #34
Ohh... I didn't notice the dot, no it is most likely a typo. The correct address is mobile.twitter.com
Bugs creator.
Features destroyer.
Template killer.

Re: Twitter embed

Reply #35
But why would I think a little URL-encoded ^ was invalid? lol :P

Re: Twitter embed

Reply #36
I have no idea. xD
Bugs creator.
Features destroyer.
Template killer.

Re: Twitter embed

Reply #37
Ohh... I didn't notice the dot, no it is most likely a typo. The correct address is mobile.twitter.com
Yup, typo on my part. Sorry about that.

Haven't got around to testing the proposed code yet. Will try to remember.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Twitter embed

Reply #38
In that case you can simplify the regex to something like this:
Code: [Select]
$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.

Re: Twitter embed

Reply #39
Is the addon updated? I get "Modification parse error" for ./themes/default/scripts/nofollow.twitter_embed.bbcode.js


Re: Twitter embed

Reply #41
@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?


Re: Twitter embed

Reply #43
Twitter supports OEmbed, by the way ...

Re: Twitter embed

Reply #44
I tried pasting the link as well as the embed tweet code. It doesn't work