function _tweet_get_url in Tweet 6
Same name and namespace in other branches
- 5.2 tweet.module \_tweet_get_url()
Gets an abbreviated URL using either CURL or PHP from the appropriate service. Times out after three (3) seconds.
Parameters
$original: The URL of the page for which to retrieve the abbreviated URL
$service: The service to use to abbreviate the URL. Available services include hex.io, idek.net, is.gd, lin.cr, ri.ms, th8.us, and TinyURL.
Return value
An abbreviated URL.
See also
1 call to _tweet_get_url()
- _tweet_make_url in ./
tweet.module - Retrieves and beautifies the abbreviated URL.
File
- ./
tweet.module, line 226 - Builds links to post pages to twitter.
Code
function _tweet_get_url($original, $service = '') {
if (!$service) {
$service = variable_get('tweet_service', 'is.gd');
}
if ($service == 'hex.io') {
$url = 'http://hex.io/api-create.php?url=' . $original;
}
else {
if ($service == 'idek.net') {
$url = 'http://idek.net/c.php?idek-api=true&idek-ref=drupal_tweet_module&idek-url=' . $original;
}
else {
if ($service == 'is.gd') {
$url = 'http://is.gd/api.php?longurl=' . $original;
}
else {
if ($service == 'lin.cr') {
$url = 'http://lin.cr/?mode=api&full=1&l=' . $original;
}
else {
if ($service == 'ri.ms') {
$url = 'http://ri.ms/api-create.php?url=' . $original;
}
else {
if ($service == 'th8.us') {
$url = 'http://th8.us/api.php?url=' . $original;
}
else {
if ($service == 'TinyURL') {
$url = 'http://tinyurl.com/api-create.php?url=' . $original;
}
else {
return $original;
}
}
}
}
}
}
}
if (variable_get('tweet_method', 'curl') == 'php') {
$context = stream_context_create(array(
'http' => array(
'timeout' => 3,
),
));
$contents = file_get_contents($url, 0, $context);
}
else {
if (variable_get('tweet_method', 'curl') == 'curl') {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($c, CURLOPT_URL, $url);
$contents = curl_exec($c);
curl_close($c);
}
else {
$contents = $url;
}
}
if ($contents && drupal_substr($contents, 0, 7) == 'http://') {
return $contents;
}
watchdog('tweet', '%method failed to return an abbreviated URL from %service.', array(
'%method' => drupal_strtoupper(variable_get('tweet_method', 'curl')),
'%service' => variable_get('tweet_service', 'is.gd'),
), WATCHDOG_NOTICE, $url);
return FALSE;
}