You are here

function HashtagsLinksConverter::replace in Hashtags 7

File

./hashtags.module, line 1142

Class

HashtagsLinksConverter

Code

function replace($matches) {
  if (isset($this->hashtags_tids)) {
    $hashtags_tids = $this->hashtags_tids;
  }
  $first_delimeter = isset($matches[1]) ? $matches[1] : '';
  $hashtag_name = isset($matches[3]) ? $matches[3] : '';
  $hashtag_tid = isset($hashtags_tids[strtolower($hashtag_name)]) ? $hashtags_tids[strtolower($hashtag_name)] : '';
  $hashtag_name = '#' . $hashtag_name;

  // hashtag is not exists - show without link
  if (empty($hashtag_tid)) {
    return $first_delimeter . $hashtag_name;
  }

  // Fatal error: [] operator not supported for strings in /includes/common.inc on line 2442
  // Issue comes up when we try to bind attribute to link which has path parameter of the current page............
  if ($_GET['q'] == 'taxonomy/term/' . $hashtag_tid) {
    $hashtag_link = l($hashtag_name, 'taxonomy/term/' . $hashtag_tid);
  }
  else {
    $hashtag_link = l($hashtag_name, 'taxonomy/term/' . $hashtag_tid, array(
      'attributes' => array(
        'class' => 'hashtag',
      ),
    ));
  }
  return $first_delimeter . $hashtag_link;
}