Jump to content

Module: TextformatterTwitterReplace


Joss
 Share

Recommended Posts

if someone can check I have done this right, I would be obliged as I ain't no module developer!

This is a very simple text formatter that looks for @ and # and adds the appropriate links to twitter.
 
So, @profile will become http://www.twitter.com/profile and #searchterm will become http://twitter.com/search?q=searchterm
 
It uses preg_replace as a quick and dirty solution rather than the Twitter API - so no apps need to be created and so on.

https://github.com/jsanglier/TextformaterTwitterReplace

Obviously, if you use @something and #something regularly and DONT want them linked, then this is useless for you. But quite nice for blogging purposes :)

Unsolicited thanks to Netcarver because I nicked one of his modules to work out how to do it  :P

Joss

  • Like 9
Link to comment
Share on other sites

Great stuff, Joss :-)

I think that your expressions could be a little more specific to the type being checked for. For example, usernames are only allowed numbers, letters, and underscores. So that expression can be changed to: /[a-z0-9_]/i (note that I've removed the caps and added the case-insensitive flag on the end there). As for hashtags, those are a lot more complex. I don't think I'd be able to explain what on earth this is (I'm no regex junkie). Guess /(#\w+)/ would also suffice.

Link to comment
Share on other sites

Nothing special about your module, but I think twitter only uses https. You can avoid a redirect, if you replace the http://. And – maybe its just me :-) – you could add a config where users can choose whether links will open in a new window or not.

Ahh … one more: adding a css class will make it possible to address those links.

However, thanks for that module. I'll use it in an upcoming website :-)

Link to comment
Share on other sites

Changed to https (serves me right for copying and pasting!)

There are probably a few config options that could be added. 

Adding a class is a nice one if someone wants to open in a popup of some sort and wants to target it with jquery, for instance.

I might have another poke at it next week

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...