only expand URLs we shortened ourselves + only shorten if notice > 140 chars
darcs-hash:20081128200004-099f7-085c833e3e34b2a13b5b3ec3b1316e7948ff196f.gz
This commit is contained in:
parent
aa29ebf9f4
commit
4fca9960cd
@ -522,7 +522,7 @@ class ProfilesettingsAction extends SettingsAction {
|
|||||||
// delete user (id)
|
// delete user (id)
|
||||||
// delete user_openid (user_id)
|
// delete user_openid (user_id)
|
||||||
// delete profile (id)
|
// delete profile (id)
|
||||||
//
|
// delete tags tables (to verify)
|
||||||
// delete all the users notices
|
// delete all the users notices
|
||||||
|
|
||||||
$this->show_form(_('Your account has been deleted.'), true);
|
$this->show_form(_('Your account has been deleted.'), true);
|
||||||
|
32
lib/util.php
32
lib/util.php
@ -822,7 +822,13 @@ function common_render_uri_thingy($matches) {
|
|||||||
return '<a href="' . $uri . '"' . $title . ' class="extlink">' . $uri . '</a>' . $trailer;
|
return '<a href="' . $uri . '"' . $title . ' class="extlink">' . $uri . '</a>' . $trailer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function common_longurl($uri) {
|
function common_longurl($short_url) {
|
||||||
|
$long_url = common_shorten_link($short_url, true);
|
||||||
|
if ($long_url === $short_url) return false;
|
||||||
|
return $long_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
function common_longurl2($uri) {
|
||||||
$uri_e = urlencode($uri);
|
$uri_e = urlencode($uri);
|
||||||
$longurl = unserialize(file_get_contents("http://api.longurl.org/v1/expand?format=php&url=$uri_e"));
|
$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;
|
if (empty($longurl['long_url']) || $uri === $longurl['long_url']) return false;
|
||||||
@ -830,6 +836,7 @@ function common_longurl($uri) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function common_shorten_links($text) {
|
function common_shorten_links($text) {
|
||||||
|
if (mb_strlen($text) <= 140) return $text;
|
||||||
// \s = not a horizontal whitespace character (since PHP 5.2.4)
|
// \s = not a horizontal whitespace character (since PHP 5.2.4)
|
||||||
// RYM this should prevent * preceded URLs from being processed but it its a char
|
// 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('\\1')", $r);
|
||||||
@ -837,7 +844,7 @@ function common_shorten_links($text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function common_shorten_link($long_url) {
|
function common_shorten_link($long_url) {
|
||||||
|
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
|
|
||||||
$curlh = curl_init();
|
$curlh = curl_init();
|
||||||
@ -848,38 +855,38 @@ function common_shorten_link($long_url) {
|
|||||||
switch($user->urlshorteningservice) {
|
switch($user->urlshorteningservice) {
|
||||||
case 'ur1.ca':
|
case 'ur1.ca':
|
||||||
$short_url_service = new LilUrl;
|
$short_url_service = new LilUrl;
|
||||||
$short_url = $short_url_service->shorten($long_url);
|
$short_url = $short_url_service->shorten($url);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '2tu.us':
|
case '2tu.us':
|
||||||
$short_url_service = new TightUrl;
|
$short_url_service = new TightUrl;
|
||||||
$short_url = $short_url_service->shorten($long_url);
|
$short_url = $short_url_service->shorten($url);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ptiturl.com':
|
case 'ptiturl.com':
|
||||||
$short_url_service = new PtitUrl;
|
$short_url_service = new PtitUrl;
|
||||||
$short_url = $short_url_service->shorten($long_url);
|
$short_url = $short_url_service->shorten($url);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'bit.ly':
|
case 'bit.ly':
|
||||||
curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($long_url));
|
curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($url));
|
||||||
$short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl;
|
$short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'is.gd':
|
case 'is.gd':
|
||||||
curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($long_url));
|
curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($url));
|
||||||
$short_url = curl_exec($curlh);
|
$short_url = curl_exec($curlh);
|
||||||
break;
|
break;
|
||||||
case 'snipr.com':
|
case 'snipr.com':
|
||||||
curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($long_url));
|
curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($url));
|
||||||
$short_url = curl_exec($curlh);
|
$short_url = curl_exec($curlh);
|
||||||
break;
|
break;
|
||||||
case 'metamark.net':
|
case 'metamark.net':
|
||||||
curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($long_url));
|
curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($url));
|
||||||
$short_url = curl_exec($curlh);
|
$short_url = curl_exec($curlh);
|
||||||
break;
|
break;
|
||||||
case 'tinyurl.com':
|
case 'tinyurl.com':
|
||||||
curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($long_url));
|
curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($url));
|
||||||
$short_url = curl_exec($curlh);
|
$short_url = curl_exec($curlh);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -889,9 +896,10 @@ function common_shorten_link($long_url) {
|
|||||||
curl_close($curlh);
|
curl_close($curlh);
|
||||||
|
|
||||||
if ($short_url) {
|
if ($short_url) {
|
||||||
return $short_url;
|
$url_cache[(string)$short_url] = $url;
|
||||||
|
return (string)$short_url;
|
||||||
}
|
}
|
||||||
return $long_url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function common_xml_safe_str($str) {
|
function common_xml_safe_str($str) {
|
||||||
|
Loading…
Reference in New Issue
Block a user