You are here

function _slack_process_message in Slack 7

Replaces links with slack friendly tags. Strips all other html.

Parameters

string $message: The message sent to the channel.

Return value

string Message with replaced links.

1 call to _slack_process_message()
_slack_send_message in includes/slack.api.inc
Send message to the Slack with more options.

File

includes/slack.api.inc, line 114
Slack integration module API functions.

Code

function _slack_process_message($message) {
  $regexp = "<a\\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\\/a>";
  if (preg_match_all("/{$regexp}/siU", $message, $matches, PREG_SET_ORDER)) {
    $i = 1;
    foreach ($matches as $match) {
      $new_link = "<{$match[2]} | {$match[3]}>";
      $links['link-' . $i] = $new_link;
      $message = str_replace($match[0], 'link-' . $i, $message);
      $i++;
      $message = strip_tags($message);
      foreach ($links as $id => $link) {
        $message = str_replace($id, $link, $message);
      }
    }
  }
  return $message;
}