You are here

function service_links_short_url in Service links 7.2

Same name and namespace in other branches
  1. 6.2 service_links.module \service_links_short_url()

Create short links using predefined settings.

1 call to service_links_short_url()
_service_links_get_tags in ./service_links.module
Fill an array with tags and the content to substitute.

File

./service_links.module, line 419
Adds social network links to the content.

Code

function service_links_short_url($url, $nid = NULL) {
  switch (variable_get('service_links_short_links_type', SERVICE_LINKS_SHORT_URL_TYPE_NODE)) {
    case SERVICE_LINKS_SHORT_URL_TYPE_NODE:
      if (empty($nid)) {
        return $url;
      }
      else {

        // With alias = true doesn't change the path.
        return url("node/{$nid}", array(
          'absolute' => TRUE,
          'alias' => TRUE,
        ));
      }
    case SERVICE_LINKS_SHORT_URL_TYPE_SERVICE:
      if (module_exists('shorten')) {
        $turl = shorten_url($url);
      }
      else {
        $turl = drupal_http_request('http://tinyurl.com/api-create.php?url=' . urlencode($url));
        $turl = isset($turl->data) && $turl->code == 200 ? $turl->data : $url;
      }
      return $turl;
    case SERVICE_LINKS_SHORT_URL_TYPE_REDIRECT_DOMAIN:
      $burl = variable_get('service_links_domain_redirect', NULL);
      return url($url, array(
        'absolute' => TRUE,
        'base_url' => $burl,
      ));
    case SERVICE_LINKS_SHORT_URL_TYPE_REDIRECT_ALL:
      $burl = variable_get('service_links_domain_redirect', NULL);
      if (empty($nid)) {
        return url($url, array(
          'absolute' => TRUE,
          'base_url' => $burl,
        ));
      }
      else {
        return url("node/{$nid}", array(
          'absolute' => TRUE,
          'alias' => TRUE,
          'base_url' => $burl,
        ));
      }
  }
}