Closed (fixed)
Project:
Twitter
Version:
6.x-5.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
8 Dec 2011 at 22:29 UTC
Updated:
23 May 2016 at 22:01 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
steinmb commented+1 from me. Patches are welcome :)
Comment #2
sillygwailoFirst attempt. Needs:
Comment #3
sillygwailoComment #4
decipheredIf it helps, I wrote a Custom Formatter for Embedded Tweets: http://customformatters.com/formatters/14/embeddedtweets
Comment #5
dddave commentedAs far as I can see there is no other module that allows the embedding of tweets into normal content (i.e. not using blocks). To allow that we have to whitelist script-tags and this is a security issue on sites with many editors. Imho this would be a killer addition to Drupal itself and this module in particular.
Comment #6
balleyne commentedI've attached a patch that creates a new input filter, utilizing the pre-existing statuses_oembed() function already contained inside twitter.lib.php to perform the API call. (The only downside is that requires an authenticated Twitter account... whereas the Twitter API doesn't actually seem to require authentication for this particular API call.)
I've also copied code from the URL filter in filter.module to treat Twitter URLs like that filter does, i.e. don't convert URLs contained inside tag attributes (like the href attribute in a link tag).
I've made the patch to 7.x-5.x, because I need this functionality for a site currently using 7.x-5.x, but I'd be happy to apply it to 7.x-6.x if needed or preferred.
Lastly, this filter should probably appear after any "limited allowed HTML tags" type filter, since it injects a script tag from the Twitter API, but as the patch stands it doesn't currently warn Drupal site builders who might not consider that. Similarly, it won't warn a user if there are no authenticated accounts available, it just won't perform the substitution.
(Please forgive my boldness in changing the issue settings, or any mistakes I've made in generating the patch -- I'm rather new to submitting patches.)
Hope that helps...
Comment #7
dddave commentedWohooo!
I am very much looking forward to testing this one out tonight. And I especially don't mind the version change as I am using v5 exclusively at the moment. ;)
Comment #8
dddave commentedWorks like a charm. Congrats, you upped the usability of this module massively. THANKS A MILLION!
Comment #9
dddave commentedSomewhere between the core update and the new dev of this module this stopped working correctly.
Comment #10
dddave commentedOk, this was caused by the Do Not Track Me FF extension. Still works like a charm!
Comment #11
dddave commentedHas this anybody working with https://drupal.org/project/wysiwyg_ckeditor or wysiwyg+ckeditor 4.x?I've no idea how but during my testruns the "turn urls into links" filter went behind this one. Of course this cannot work when that happens. So I happily report that this works like a charm when used with wysiwyg_ckeditor.
I really wonder what people are doing on their site's when they want to embed tweets into content bodies. Seems like a very common approach in todays blogging culture yet hardly anyone seems to be testing this awesome patch. :(
Comment #12
tim_djworks perfect!
However it does not cache the return of oembed which is advisable because otherwise it will connect to twitter every request
Comment #13
gaxze commentedNot having a great deal of success here - especially when pasting URL's for tweets with media.I've realised it's actually an issue with caching and twitter returning a 429 error: https://dev.twitter.com/docs/error-codes-responses
Comment #14
gaxze commentedI've had a go at working on a patch to cache the requests as mentioned in #12
Comment #15
gaxze commentedIt appears my patching skills are useless - this is meant to be a patch addition to #12
Code below:
Comment #16
dddave commentedJust to be clear and so I can test this (I suck at coding but can test patches):
Latest 5x dev, patched and then your code where?
Comment #17
gaxze commentedThe website i've applied this to is using the version: 7.x-5.8
I've basically applied the patch from #6 and then made the following changes to twitter.inc
From:
To:
Comment #18
dddave commentedI applied this change to the current dev (patched) and it seems to be fine. Code makes sense to me but that really doesn't mean anything.
Comment #19
damienmckennaTriggering the testbot.
Comment #20
damienmckennaTriggering the testbot.
Comment #21
happysnowmantech commentedI've attached another patch that combines the changes from #6 and #17 into a single patch that can be applied cleanly (I applied it to version 7.x-5.8). I had previously tried the patch from #14 but it did not apply cleanly.
Comment #22
dddave commentedPatch works as advertised even when applied to the latest 7.x-5.x-dev (minor offset aside).
Comment #23
dddave commentedI am hesitant to RTBC this although I have the patch in production for a while now because my code skills are really nothing to trust. A second opinion would be nice. I would really like to see this patch go in. Glad to see the tests pass.
Comment #24
Sergey Filimonov commentedLooks like there is an error, you can find it if you use several twitts in one text area.
In this code:
You need to change this line
to this:
Otherwise only last twitt will be shown.
Comment #25
jenlamptonThanks for the patches! :)
Thus far it looks like we're unable to render images, videos, and link previews. Is that still yet to be done? I'd be happy to add that.
Also, it looks like the current implementation works only when the "Limit allowed HTML tags" filter is disabled, Is anyone else running into that problem?
Comment #26
jenlamptonOkay, here's an updated patch with some minor code style formatting updates, and new options for embedded media, alignment, and conversation threading.
To answer my own question about about filters, I just needed to move the "Embed tweet" filter below the "Limit allowed HTML tags" filter and everything works great :)
Comment #27
damienmckennaThanks everyone for working on this!
@jenlampton: Would you mind adding a note to the README.txt about the text filter, along with a mention about positioning it in relation to other filters? Some tests might be useful, but they're not required.
Comment #28
damienmckennaComment #29
dddave commentedPlaying around with the (cleanly applying) patch and I am seeing this:
TwitterException: Not Found in Twitter->request() (Zeile 156 von MYSITE/drupal/sites/all/modules/twitter/twitter.lib.php).edit: Saw this in logs first, tried a new post with an embedded tweet which went fine. Went on to edit the post and pasted the embed code of a tweet (not the link to it) and the test site sunk.
Comment #30
dddave commentedReferrer and message from the log.
Comment #31
dddave commentedHad no time to dig deeper but it seems this is indeed coming from this patch alone. Current unpatched .dev seems to work fine. Additionally I noticed that said error also was thrown on cron runs.
Comment #32
damienmckennaThis isn't working for me if a link to a tweet is the first text in the field. I'm testing it in the Full HTML text format, the Embed Tweet filter is first in the list, so the list looks like the following:
and
)
I added

dpm($chunks);right after the preg_split() and it shows the following items:I'm not discounting there being something wrong with my setup, e.g. I'm a little confused as to why the link has already been converted to a link.
Comment #33
damienmckennaOk, never mind, it seems like I needed to re-save the text formats in order for it to work properly.
Comment #34
damienmckennaRerolled, for 7.x-5.x.
Comment #35
damienmckennaBTW the updated patch in #34 includes a note in the filter that says "Should be sorted after the "Limit allowed HTML tags", if used."
Comment #36
damienmckennaFor 7.x-6.x.
Comment #38
damienmckennaFor 6.x-5.x.
Comment #41
damienmckennaCommitted. Thanks everyone!
Comment #43
nickonom commentedCurrently, we need to allow the
<script>tag to use this input filter and that is really not desirable for security reasons. Isn't possible to inject the required script, for example in header section of any page where the filter is used, without allowing the<script>tag?Comment #44
adamps commented@nickonom Please could you open a new issue for your new request "input filter without need for script tag"?
This issue was fixed 10 months ago, and it confuses people like me finding the thread from Google if the status doesn't match that.
You can of course link your new issue from here to help other people who might have a similar idea.
Comment #45
adamps commented@nickonom Also note the description of "Embed Tweets" filter:
If you get the order right I don't think you need to allow script.