You are here

protected function Html2Text::buildlinkList in Swift Mailer 7

Helper function called by preg_replace() on link replacement.

Maintains an internal list of links to be displayed at the end of the text, with numeric indices to the original point in the text they appeared. Also makes an effort at identifying and handling absolute and relative links.

Parameters

string $link URL of the link:

string $display Part of the text to associate number with:

null $linkOverride:

Return value

string

1 call to Html2Text::buildlinkList()
Html2Text::pregCallback in includes/classes/Html2Text.inc
Callback function for preg_replace_callback use.

File

includes/classes/Html2Text.inc, line 389

Class

Html2Text

Code

protected function buildlinkList($link, $display, $linkOverride = null) {
  $linkMethod = $linkOverride ? $linkOverride : $this->options['do_links'];
  if ($linkMethod == 'none') {
    return $display;
  }

  // Ignored link types
  if (preg_match('!^(javascript:|mailto:|#)!i', $link)) {
    return $display;
  }
  if (preg_match('!^([a-z][a-z0-9.+-]+:)!i', $link)) {
    $url = $link;
  }
  else {
    $url = $this->baseurl;
    if (substr($link, 0, 1) != '/') {
      $url .= '/';
    }
    $url .= $link;
  }
  if ($linkMethod == 'table') {
    if (($index = array_search($url, $this->linkList)) === false) {
      $index = count($this->linkList);
      $this->linkList[] = $url;
    }
    return $display . ' [' . ($index + 1) . ']';
  }
  elseif ($linkMethod == 'nextline') {
    return $display . "\n[" . $url . ']';
  }
  else {

    // link_method defaults to inline
    return $display . ' [' . $url . ']';
  }
}