diff --git a/shurly.module b/shurly.module index 7d76d4b..6aed980 100644 --- a/shurly.module +++ b/shurly.module @@ -1025,3 +1025,41 @@ function _shurly_language_stub() { } return $language; } + +/** + * Implements hook_filter_info(). + */ +function shurly_filter_info() { + $filters = array(); + $filters['shurly'] = array( + 'title' => t("Shorten all outgoing URL's"), + 'description' => t("Shorten all outgoing URL's."), + 'process callback' => '_shurly_filter_process', + 'tips callback' => '_shurly_filter_tips', + ); + + return $filters; +} + +/** + * Process callback for shurly filter. + */ +function _shurly_filter_process($text, $filter) { + // Find all a tags containing a full URL. + preg_match_all('/]*href="(http[^"]*)"[^>]*>/i', $text, $links); + if (!empty($links)) { + $links = $links[1]; + foreach ($links as $key => $link) { + $short_url = shurly_shorten($link); + $text = str_replace('"' . $link . '"', '"' . $short_url['shortUrl'] . '"', $text); + } + } + return $text; +} + +/** + * Implements callback_filter_tips(). + */ +function _shurly_filter_tips($filter, $format, $long = FALSE) { + return t('All links starting with http or https will be replaced.'); +}