You are here

function _drupagram_filter_text in Drupagram 7

This helper function converts Instagram-style @usernames and #hashtags into actual links.

3 calls to _drupagram_filter_text()
drupagram_views_handler_field_xss::render in ./drupagram_views_field_handlers.inc
Render the field.
_drupagram_filter_hashtag in ./drupagram.module
Callback for drupagram #hashtag converter
_drupagram_filter_username in ./drupagram.module
Callback for drupagram @username converter

File

./drupagram.module, line 255
Provides API integration with the Instagram microblogging service.

Code

function _drupagram_filter_text($text, $prefix, $destination) {
  $matches = array(
    '/\\>' . $prefix . '([a-z0-9_]+)/i',
    '/^' . $prefix . '([a-z0-9_]+)/i',
    '/(\\s+)' . $prefix . '([a-z0-9_]+)/i',
  );
  $replacements = array(
    '><a href="' . $destination . '/${1}">' . $prefix . '${1}</a>',
    '<a href="' . $destination . '/${1}">' . $prefix . '${1}</a>',
    '${1}<a href="' . $destination . '/${2}">' . $prefix . '${2}</a>',
  );
  return preg_replace($matches, $replacements, $text);
}