I am proud to release my first Expression Engine plugin. This one is named Tweet This which will allow you to add a “Tweet This” link in your blog entries. This will enable visitors to tweet the entry. By default it will use the is.gd url shortening service to make the link short and also trim the title to less than 70 characters.
Example Usage
{exp:tweet_this title="{title}" url="{title_permalink=blog/entry}"}
PARAMETERS
title=”{title}” - The title of the entry.
url=”{title_permalink=blog/entry}” - The url or permalink to the entry.
no_short_url=”TRUE” - Do you not want to use the is.gd url shortening server?
link_title=”Tweet This!” - This is the link title. Could be text or image.
Requirements - Curl - json_decode for bit.ly
Help & Support I make absolutely no guarantee I can offer support but if you need help post here or leave a comment on my site: http://ericlbarnes.com/blog/develop/ee-tweet-this/
UPDATE mdesign has put up a repo on GitHub that is extensively updated: Short’n Tweet There are comments in the plugin about the bit.ly stuff. If anyone wants to fork it, optimize and improve it…have at it! http://github.com/mdesign/shortn-tweet.ee_addon
UPDATE December 06, 2009 Now forked to work with EE 2.0: http://github.com/ericbarnes/shortn-tweet.ee_addon
I like this, quick and simple. One thing I would like if possible is a parameter to replace “Tweet This” with a user defined variable. i.e. I use a small image for my twitter link not text so a parameter to allow me to use that would be helpful.
I just uploaded a new version that will support this.
Also the original had a class assigned to the link so in theory you could use it to add an image and hide the text through css.
I’m trying to get this to work on a site, but I keep getting an error saying the entered URL is incorrect. Unfortunately, due to the more static nature of the site, I can’t just use “title_permalink” tag. Instead, I’m trying to rebuild the URL based on URL segment variables. However, even when I hardcode a URL, like so, I still get an error:
{exp:tweet_this title="" url="http://www.google.com/" link_title="Share on Twitter"}
Is there something I’m missing?
FWIW, I’m leaving the title parameter blank on purpose. However, even when I have something in there, I still get an error.
I modified this to be more flexible with the output. You can still use it the original way, but if you close the tag with “{/exp:tweet_this}” you get a few variables. I can now do this:
{exp:tweet_this title="{title}" url="{url_title_path=weblog/item}"}
<a href="http://{twt:twitter_url}Reading:">Tweet This Thang (link)</a>
title url: {twt:title_url}
title: {twt:title}
twitter url: {twt:twitter_url}
twitter full url: {twt:twitter_full_url}
{/exp:tweet_this}
and get output like:
Tweet This Thang (link) title url: h ttp://is.gd/x1x2we title: This is my awesome title twitter url: h ttp://twitter.com/home?status= twitter full url: h ttp://twitter.com/home?status=Reading: ‘This is my awesome title’ - h ttp://is.gd/x1x2we (via @me)
The only problem I’m running into is when the title contains quotes. In one case I had a left single quote and a right single quote and when I linked to Twitter, Twitter came back with an “Invalid Unicode value in parameter status” message. So there probably needs to be a way to properly encode or escape any quotes in a supplied title. Anyone have ideas about the best way to do that?
Thanks. I’ve tried almost everything I can think of here, but Twitter is still throwing a fit. Say my title is Movies: Meatballs ‘swedish style’ (where the single quotes are actually curly quotes). If I use htmlentities, the rendered output looks like:
h ttp://twitter.com/home?status=Movies: Meatballs ‘Swedish Style’ - h ttp://is.gd/x1x2we (via @me)
If I click that link to go to Twitter, the tweet cuts off right before that first quote:
Movies: Meatballs
I’ve tried variations with htmlspecialchars, htmlentities, html_entity_decode, str_replace, $REGX->ascii_to_entities, $REGX->_html_entity_decode, and so on. I just can’t seem to get the title back out with quotes in a link that Twitter will understand.
I think I finally got this to work with quotes and a couple other trouble characters. On this site we have the setting to convert high ASCII characters to entities set to ‘yes’. I added a new function in the plugin to replace some entities:
$title = $TMPL->fetch_param('title');
$title = $this->dot($title, 70, '...');
$title = $this->_convert_chars($title);
function _convert_chars($string) {
$search = array("‘", "’", "“", "”","–","—");
$replace = array("'", "'", '"', '"','-','--');
return str_replace($search, $replace, $string);
}
I’m getting all single quotes, double quotes, emdash and endash with this, which should cover most of the things that Twitter is chucking a wobbly about. Seems to be working OK on a number of test entries.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.