You are here

function _shortener_filter_url in Shorten URLs 6

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

Replaces URLs with the shortened version.

Unlike the core URL filter, this only matches HTTP and HTTPS addresses, because those are the only ones accepted by most URL shortening services.

1 call to _shortener_filter_url()
shortener_filter in shortener/shortener.module
Implementation of hook_filter().

File

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

Code

function _shortener_filter_url($text, $format) {

  // Pass length to regexp callback.
  _filter_url_trim(NULL, variable_get('shortener_url_length_' . $format, 72));

  // Pass behavior to regexp callback.
  _shortener_url_behavior(NULL, FALSE, variable_get('shortener_url_behavior_' . $format, 'short'), variable_get('shortener_url_length_' . $format, 72));
  $text = ' ' . $text . ' ';

  // Match absolute URLs.
  $text = preg_replace_callback("`(<p>|<li>|<br\\s*/?>|[ \n\r\t\\(])((http://|https://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?!]*?)(?=(</p>|</li>|<br\\s*/?>|[ \n\r\t\\)]))`i", '_shortener_url_behavior', $text);

  // Match www domains/addresses.
  $text = preg_replace_callback("`(<p>|<li>|[ \n\r\t\\(])(www\\.[a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+~#\\&=/;-])([.,?!]*?)(?=(</p>|</li>|<br\\s*/?>|[ \n\r\t\\)]))`i", '_shortener_url_parse_partial_links', $text);
  $text = substr($text, 1, -1);
  return $text;
}