DABR Twitter Web Client Mini Blog Yo Mama Jokes Sports Bookmarklets About Us

November 24, 2009

More DABR Goodness: Unshortening Short URLs



 

I’m loving DABR – makes me want to find a way to load XAMPP on my phone. Anyways I’ve made a few more tweaks to my codebase recently. Inspired by this Terrence Eden post…:Expanding URLs in Dabr / Twitter – Terence Eden’s Blog

I hate shortened URLs with a passion. It makes it hard to see what a link is and whether I’ve visited it before. If they fail – like tr.im threatened to do – you lose your links with no way to see where they once went.

So, hurrah for LongURLPlease – a service which takes those horrid little links and turns them in to full sized URLs.

…I went about implementing this longurl scheme and having the long URL show in the tweet. But to make it so that it the tweet isn’t dominated by a 600 character URL (and reduce some of the benefit of short URLs) I figured I could try to make it only display the domain name of each link while still keeping the actual link in the HTML – much like they do at slashdot. Easy peasy, I thought. Just uncomment the LONGURL_KEY in config.php and move the gwt code from the twitter_parse_links_callback function to the theme_external_link function in common/twitter.php. Right?

function twitter_parse_links_callback($matches) {
  $url = $matches[1];
  if (substr($url, 0, strlen(BASE_URL)) == BASE_URL) return "<a href='$url'>$url</a>";
  return theme('external_link', $url);
}

function theme_external_link($url, $content = null) {
     //Long URL functionality.  Also uncomment function long_url($shortURL)
     if (!$content)
     {
          $longurl = long_url($url);
          $domain = parse_url($longurl,PHP_URL_HOST);
          if (setting_fetch('gwt') == 'on') {
               $encoded = urlencode($longurl);
               $longurl = "http://google.com/gwt/n?u=$encoded";
          }
          return "<a href='$longurl' target='_blank'>[".$domain."]</a>";
     }
     else
     {
          return "<a href='$url' target='_blank'>$content</a>";
     }
}

Well, not so much. Because of some of the mechanisms in identifying links and adding the appropriate HTML, I broke the image-service thumbnail code and had to think through how this was going to work out. It ended up with me changing the twitter_photo_replace and my twitlonger_replace functions to only return the addendums (if any) and not the entire tweet text

function twitter_photo_replace($text) {

.
.
.

  if (!empty($images)) 
     return implode(' ', $images).'<br />';
}  

function twitlonger_replace($text) {
  $tmp = strip_tags($text);

  if (preg_match('#http://tl.gd/([dw]+)#', $tmp, $matches)) {
.
.
.
     $returntext = "<p style="padding:5px;margin:5px;border:thin dashed;">$longtweet</p>";//$text";
    return theme('external_link', $matches[0], $returntext);
  } else {
     return "";
  }
}

then I changed how the twitter_parse_tags function called them and appended the data. Also important is to make it use the original unaltered tweet ($input) as a source rather than the modified one with the links ($out).

function twitter_parse_tags($input) {
.
.
.

  if (!in_array(setting_fetch('browser'), array('text', 'worksafe'))) {
    $twitlonger = twitlonger_replace($input);
    $out = twitter_photo_replace($twitlonger.$input).$twitlonger.$out;
  }
  return $out;
}

Dabr Decoding Short URLs

The results, though, are great . Nice and clean. As mentioned on other pages, the overhead may be a bit much for more than your personal web server, but I love the change. One byproduct as well is that now any posts with images in Twitlonger that don’t get into the original tweet will have their photo thumbnail displayed too. 5% scenario – yes, but still icing :)

Bookmark and Share Blog This Facebook Twiit Google Yahoo! Buzz Ping StumbleUpon Fark Propellor Netvouz Newsvine reddit Simpy Blinklist Blogmarks Mr Wong Startaid Segnalo Wists Boxed Up

Popularity: unranked [?]

November 15, 2009

Improved Sharing and Twitter Bookmarklet



 

Since my last forays with Mini-blogging (or microblogging) and bookmarkletting, lots of things have changed. Specifically for this purpose, the url-shortening service urlTea was yanked. It forced me to switch to tinyurl and then to tr.im – which also almost went down. Along with increasingly sharing more links on sites other than Twitter, I combined some of my other bookmarklets into an all-in-one server-driven bookmarklet bonanza.

This new server side script will facilitate sharing links via Twitter, Facebook, email, BB Code forums, blogs/Myspace. Since the Twitter explosion this year – many more cool url shortening services have opened and offered API’s like is.gd and u.nu. Twitter now uses bit.ly/j.mp but since it needed a login, I didn’t bother. There is no more JSON, just straight API calls.

This new code still solves the problem of allowing you to provide context for your tweet or other form of sharing – and also integrates flexibility amongst using shortened URLs or not, and which shortening service to use. It can be used as a stand-alone script, or as a bookmarklet. The bookmarklet still captures the link, title, and any selected text on the page you want to share. It can be set to automatically forward to Twitter, or to stay on the helper popup. In the case of the latter, there is still a button that allows you to forward the link, title, and any selected text to Twitter where you handle editing and the character count.

The beauty of this approach is – if you don’t want to share on Twitter, or also want to share on other sites, you can get the code needed to post on MySpace or Facebook or by email or on sites that use BBCode. Here is the bookmarklet. As usual – drag it to your Bookmarks or Links bar, or simply bookmark it.

Twiit or Auto-Twiit

As always, the bookmarklet is a simple link that contains javascript. You click it whenever you’re on a web page that you want to share. Again, I offer no appologies or warranties. Take it and make it yours if you like it. Or just use the bookmarklet here and let me know how it works.

The PHP:

Bookmark and Share Blog This Facebook Twiit Google Yahoo! Buzz Ping StumbleUpon Fark Propellor Netvouz Newsvine reddit Simpy Blinklist Blogmarks Mr Wong Startaid Segnalo Wists Boxed Up

Popularity: unranked [?]

November 19, 2007

Mini Blog for 2007-11-19



 

Powered by Twitter Tools.

Bookmark and Share Blog This Facebook Twiit Google Yahoo! Buzz Ping StumbleUpon Fark Propellor Netvouz Newsvine reddit Simpy Blinklist Blogmarks Mr Wong Startaid Segnalo Wists Boxed Up

Popularity: 1% [?]

November 6, 2007

Microblogging With urlTea – My Twitter Bookmarklet



 

UPDATE: Improved Sharing and Twitter Bookmarklet | myopiclunacy.com


As you know I’m trying the whole Mini-Blog thing now as a way of microblogging my thoughts – mostly on links to pages/stories I come across. Using a Twitter account and a plug-in called Twitter Tools from Alex King, I can show my Mini Blog on the left side, and then all the mini-blog entries/tweets for the day (using GMT time, unfortunately) get posted into a daily blog entry the next day. It’s a real cool tool.

Using Twitter for microblogging has become popular especially because Twitter will take any link it finds in your tweet and HTMLize it. One problem that I came across, though, was the cumbersome way of getting links and context into the tweet – a lot of copying and pasting going on. Because of the 140 character limit, Twitter has some kind of feature where it uses TinyUrl to shorten the urls posted into the status, but I couldn’t find a bookmarklet that would include the page title and a selection of text. Reason being, probably, this isn’t a highly requested feature. So I tried writing my own.

I did it in a somewhat cumbersome way, by using a bookmarklet to get the page URL, title, and selected text and call a PHP form that uses JSON to connect to the urlTea url shortening service. It then autoposts the form to the Twitter status window ready to be updated. All of this in a pop-up window and, of course, assuming you’re already signed into Twitter. I let Twitter handle the character count and any additional editing – especially when the page title and selected text become too long. The page title, the urlTea shortened link, and any selected text are copied in that order separated by a space.

TwitIt or TwrimIt

The bookmarklet is a simple link that contains javascript. You drag it to your link toolbar (or just bookmark it from the right-click menu) and click it whenever you want to microblog. (If you’re new to bookmarklets – they’re an awesome timesaver. Check out the other bookmarklets I use.) I’m sure this smacks of hackery and is rife with style infractions. I offer no appologies or warranties. Take it and make it yours if you like it. Or just use the bookmarklet here and let me know how it works.

Update (11/14/07): So after looking over a few pages, and the inexplicable problems I had with the JSON api, I’ve updated the script to use the regular API. Which I can switch to use TinyUrl if I need to. I suppose I could then have it use the twitter API but I want the intermediate editing step.

Update (1/17/09): Fixed issues with slashes and escaped code. Also added an option for using tr.im URL shortening service – which is shorter than tinyurl. Works much better. If you want to use tr.im, choose the TwrimIt bookmarklet. All this is pending an API key from the good folks at tr.im. BTW – urlTea is now defunct in case you were wondering!

The PHP page is real simple and portable:

<?php

$url = $_GET["url"];
$r1 = array(’”‘);
$r2 = array(”“”);
$title = str_replace($r1,$r2,stripslashes(htmlspecialchars(urldecode($_GET["title"]))));
$text = str_replace($r1,$r2,stripslashes(htmlspecialchars(urldecode($_GET["text"]))));
$urlt = file_get_contents(”http://tr.im/api/trim_simple?url=” . $url);
$urlt = file_get_contents(”http://tinyurl.com/api-create.php?url=” . $url);
// $urlt = file_get_contents(”http://tr.im/api/trim_simple?url=” . $url);
$status = “$title $urlt $text”
?>

<html>
<head>
<title>myopiclunacy.com’s Twitter TinuURl/tr.im submitter</title>
</head>
<body>
<form name=twit id=twit method=”get” action=”http://twitter.com/home”>
<input type=”hidden” name=”status” value=”<?php echo $status; ?>”>
</form>
<script type=”text/javascript”>
document.forms[0].submit();
</script>
</body>

If you’re looking for something for the Blackberry – check out this article from Tao of Mac.

Bookmark and Share Blog This Facebook Twiit Google Yahoo! Buzz Ping StumbleUpon Fark Propellor Netvouz Newsvine reddit Simpy Blinklist Blogmarks Mr Wong Startaid Segnalo Wists Boxed Up

Popularity: 4% [?]

Powered by WordPress

Blog Information