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; }
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
Popularity: unranked [?]





































