BackType Tweetcount 1.2 with su.pr Short URL Support
The new BackType Tweetcount just launched last night. With a little work, it’ll support your very own custom shortened URL in the re-tweet. We like su.pr. Thanks to a bit of help from Michael of BackType, we’re able to figure out this mod overnight.
The previous version of BackType worked well but it always re-tweet your posts through awe.sm. That’s great and all, but what about the rest of us who have our own click tracking or even our own custom shorteners.
So to make it better, last night we added a new option for developers to add a function into the code that will allow them to build their own custom functions and generate their own custom links. It’s really just a meta tag, “bttc_short_url” that gets generated the first time the post is viewed. Here’s the best part. Since the short url is generated the FIRST time everything is viewed. Just by browsing your pages, and olf non-syndicated links are automatically added into su.pr. If you use another shortening service, it’ll do the same for that too.
After grabbing the latest BackType Tweetcount, load up your favorite editing tool and add this function to the very bottom of the code:
As a quick note there. The commented out //$SU_newurl is for those that host their own url shortcodes on their domain using the su.pr htaccess modification.
Go to Line 180, insert this code:
Then go to Line 161, search for this code:
Directly below the code, paste the following:
And that's it. Edit the first bttc_supr function into basically whatever you want, and the short URL will automatically generated the first time the posts are viewed. It'll let you re-tweet with your own custom links, and even add old content that you haven't added to your shortening admin pages for you. This is a pretty raw version of doing this. BackType will be launching an updated version soon with these modifications to make it easier for users that don't want to edit as much code.
The previous version of BackType worked well but it always re-tweet your posts through awe.sm. That’s great and all, but what about the rest of us who have our own click tracking or even our own custom shorteners.
So to make it better, last night we added a new option for developers to add a function into the code that will allow them to build their own custom functions and generate their own custom links. It’s really just a meta tag, “bttc_short_url” that gets generated the first time the post is viewed. Here’s the best part. Since the short url is generated the FIRST time everything is viewed. Just by browsing your pages, and olf non-syndicated links are automatically added into su.pr. If you use another shortening service, it’ll do the same for that too.
After grabbing the latest BackType Tweetcount, load up your favorite editing tool and add this function to the very bottom of the code:
| PHP | | copy code | | ? |
| 01 | |
| 02 | function bttc_supr($url) {
|
| 03 | $SU_username = "username"; |
| 04 | $SU_api = "api_key"; |
| 05 | $SU_url = "http://su.pr/api"; |
| 06 | $SU_vars = "?url=$url&login=$SU_username&apiKey=$SU_api"; |
| 07 | |
| 08 | $curl_handle = curl_init(); |
| 09 | curl_setopt($curl_handle, CURLOPT_URL, $SU_url . $SU_vars); |
| 10 | curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); |
| 11 | curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); |
| 12 | curl_setopt($curl_handle, CURLOPT_HTTPGET, 1); |
| 13 | $buffer = curl_exec($curl_handle); |
| 14 | curl_close($curl_handle); |
| 15 | //$SU_newURL = str_replace("su.pr/", "", $buffer);
|
| 16 | $SU_newURL = $buffer; |
| 17 | |
| 18 | return $SU_newURL; |
| 19 | } |
| 20 |
As a quick note there. The commented out //$SU_newurl is for those that host their own url shortcodes on their domain using the su.pr htaccess modification.
Go to Line 180, insert this code:
| PHP | | copy code | | ? |
| 1 | |
| 2 | if (get_post_meta($post->ID, 'bttc_short_url', true) != '') {
|
| 3 | $button .= 'tweetcount_short_url=\'' . wp_specialchars(get_post_meta($post->ID, 'bttc_short_url', true), '1') . '\';'; |
| 4 | } |
| 5 |
Then go to Line 161, search for this code:
| PHP | | copy code | | ? |
| 1 | |
| 2 | if ($meta == '') {
|
| 3 | add_post_meta($post->ID, 'bttc_cache', time() . ':' . $cnt); |
| 4 | } else {
|
| 5 | update_post_meta($post->ID, 'bttc_cache', time() . ':' . $cnt); |
| 6 | } |
| 7 |
Directly below the code, paste the following:
| PHP | | copy code | | ? |
| 1 | |
| 2 | if (get_post_meta($post->ID, 'bttc_short_url', true) == '') {
|
| 3 | $short_url = bttc_supr($url); |
| 4 | if ($short_url) {
|
| 5 | add_post_meta($post->ID, 'bttc_short_url', $short_url); |
| 6 | } |
| 7 | } |
| 8 |
And that's it. Edit the first bttc_supr function into basically whatever you want, and the short URL will automatically generated the first time the posts are viewed. It'll let you re-tweet with your own custom links, and even add old content that you haven't added to your shortening admin pages for you. This is a pretty raw version of doing this. BackType will be launching an updated version soon with these modifications to make it easier for users that don't want to edit as much code.
Tags: API, backtype, cURL, Marketing, PHP, social marketing, Tweaks, twitter, web design, web development



















































July 14th, 2009 at 7:41 AM Hi Alex,
It was great helping you get the plugin to support su.pr. Just a quick note, we haven’t deployed a new version of the plugin that supports additional URL shorteners, though server side we are accepting the parameter. We’ll have something up soon, but if anyone else is modifying the source they will have to also add a few lines that check the post meta for ‘bttc_short_url’ and if it is set, add it as the ‘tweetcount_short_url’ in the js output of the button.
July 14th, 2009 at 9:08 AM Thanks for the note. I added an extra step into there to include the check for the short url.
November 12th, 2009 at 9:54 AM this is wonderful tutorial .. i read it 3 times and get a fantastic results and sure i put a
copy of this lesson on my site here