]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
trac31 added longurl title to anchors when applicable. Also removed * url prefix...
authormillette <millette@controlyourself.ca>
Thu, 13 Nov 2008 18:28:34 +0000 (13:28 -0500)
committermillette <millette@controlyourself.ca>
Thu, 13 Nov 2008 18:28:34 +0000 (13:28 -0500)
darcs-hash:20081113182834-099f7-f55adc95eb8fb46f8cee1c176653c88f65e27ab6.gz

actions/othersettings.php
lib/util.php

index 497500509fc50fb4a1d856d96c3d8f33c89358e3..18de9c189fb5c2c7d33e795ece4318220215603f 100644 (file)
@@ -51,7 +51,7 @@ class OthersettingsAction extends SettingsAction {
                        'metamark.net' => 'metamark.net'
                );
                
-               common_dropdown('urlshorteningservice', _('Service'), $services, _('Shortening service to use when notices exceed the 140 character limit. Precede a URL with a * to prevent shortening of that URL.'), FALSE, $user->urlshorteningservice);
+               common_dropdown('urlshorteningservice', _('Service'), $services, _('Shortening service to use when notices exceed the 140 character limit.'), FALSE, $user->urlshorteningservice);
                
                common_submit('save', _('Save'));
                
index ee1a149a7d660df970f0ed94d1762cb9401bc18f..bdc7983148bf045d43c1484153f5c30ab3b43d02 100644 (file)
@@ -744,14 +744,28 @@ function common_render_uri_thingy($matches) {
                        $trailer = $final . $trailer;
                }
        }
-       return '<a href="' . $uri . '" class="extlink">' . $uri . '</a>' . $trailer;
+       if ($longurl = common_longurl($uri)) {
+               $longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8');
+               $title = " title=$longurl";
+       }
+       else $title = '';
+       
+       return '<a href="' . $uri . '"' . $title . ' class="extlink">' . $uri . '</a>' . $trailer;
+}
+
+function common_longurl($uri)  {
+       $uri_e = urlencode($uri);
+       $longurl = unserialize(file_get_contents("http://api.longurl.org/v1/expand?format=php&url=$uri_e"));
+       if (empty($longurl['long_url']) || $uri === $longurl['long_url']) return false;
+       return $longurl['long_url'];
 }
 
 function common_shorten_links($text) {
        $r = htmlspecialchars($text);
     // \s = not a horizontal whitespace character (since PHP 5.2.4)
-       $r = preg_replace('@[^*]https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $r);
-//     $r = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $r);
+       // RYM this should prevent * preceded URLs from being processed but it its a char
+//     $r = preg_replace('@[^*](https?://[^)\]>\s]+)@e', "common_shorten_link('\\1')", $r);
+       $r = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $r);
        return $r;
 }