We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Tweet This

Development and Programming

Eric Barnes's avatar
Eric Barnes
487 posts
16 years ago
Eric Barnes's avatar Eric Barnes

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

       
LHAuctioneers's avatar
LHAuctioneers
33 posts
16 years ago
LHAuctioneers's avatar LHAuctioneers

very cool - i dig it.

nice and simple

       
leadsuccess's avatar
leadsuccess
408 posts
16 years ago
leadsuccess's avatar leadsuccess

Very cool! Want to suggest a feature add, how about how many times it’s been twittered.

       
Eric Barnes's avatar
Eric Barnes
487 posts
16 years ago
Eric Barnes's avatar Eric Barnes

Very good idea. I would have to do some research on that. I guess that could be done using their api. Although not 100% sure.

       
medic119's avatar
medic119
52 posts
16 years ago
medic119's avatar medic119

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.

       
Eric Barnes's avatar
Eric Barnes
487 posts
16 years ago
Eric Barnes's avatar Eric Barnes
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.

       
medic119's avatar
medic119
52 posts
16 years ago
medic119's avatar medic119

Perfect! Thank you.

       
OrganizedFellow's avatar
OrganizedFellow
435 posts
16 years ago
OrganizedFellow's avatar OrganizedFellow

By default it uses is.gd Can you add bit.ly?

       
chrispiciullo's avatar
chrispiciullo
69 posts
16 years ago
chrispiciullo's avatar chrispiciullo

bit.ly, to my knowledge, requires the use of an api key + username/password authentication. Not sure one would be willing to post that up in a plugin.

       
Jason Morehead's avatar
Jason Morehead
454 posts
16 years ago
Jason Morehead's avatar Jason Morehead

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.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
15 years ago
Ryan M.'s avatar Ryan M.

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?

       
Eric Barnes's avatar
Eric Barnes
487 posts
15 years ago
Eric Barnes's avatar Eric Barnes

@mdesign - My guess is you may need to use htmlentities on the title before the link is generated.

$title = $TMPL->fetch_param('title');
$title = $this->dot($title, 70, '...');
$title = htmlentities($title);
       
Ryan M.'s avatar
Ryan M.
1,511 posts
15 years ago
Ryan M.'s avatar Ryan M.

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.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
15 years ago
Ryan M.'s avatar Ryan M.

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.

       
Eric Barnes's avatar
Eric Barnes
487 posts
15 years ago
Eric Barnes's avatar Eric Barnes

That is great news! Glad you got it sorted out. 😊

       
1 2 3 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.