You are here

function _shortener_url_behavior in Shorten URLs 6

Same name and namespace in other branches
  1. 7.2 shortener/shortener.module \_shortener_url_behavior()
  2. 7 shortener/shortener.module \_shortener_url_behavior()

Determines the link caption based on the filter behavior setting.

2 calls to _shortener_url_behavior()
_shortener_filter_url in shortener/shortener.module
Replaces URLs with the shortened version.
_shortener_url_parse_partial_links in shortener/shortener.module
Processes matches on partial URLs and returns the "fixed" version.
1 string reference to '_shortener_url_behavior'
_shortener_filter_url in shortener/shortener.module
Replaces URLs with the shortened version.

File

shortener/shortener.module, line 86
Provides an input filter that replaces URLs with a shortened version.

Code

function _shortener_url_behavior($match, $partial = FALSE, $behavior = NULL, $max_length = NULL) {
  static $_behavior;
  if ($behavior !== NULL) {
    $_behavior = $behavior;
  }
  static $_max_length;
  if ($max_length !== NULL) {
    $_max_length = $max_length;
  }
  if (!empty($match)) {
    $match[2] = decode_entities($match[2]);
    $caption = '';
    $href = $match[2];
    $title = check_url($match[2]);
    if ($_behavior == 'short' || $_behavior == 'strict') {
      $caption = shorten_url($match[2]);
      $href = $caption;
    }
    else {
      $caption = check_plain(_filter_url_trim($match[2]));
      if ($partial) {
        $href = 'http://' . check_url($match[2]);
      }
      $title = shorten_url($match[2]);
    }
    return $match[1] . '<a href="' . $href . '" title="' . $title . '" class="shortener-length-' . $_max_length . ' shortener-link shortener-' . $_behavior . '">' . $caption . '</a>' . $match[$partial ? 3 : 5];
  }
  return '';
}