You are here

function _gotwo_filter in Go - url redirects 5

Same name and namespace in other branches
  1. 6 gotwo.module \_gotwo_filter()

This function will strip the <go> link into it's parts, save the link with the title to the database and returns a HTML based link for the replacement in the content.

Parameters

$link: A raw <go> link to be processed.

Return value

The HTML representation of a <go> link.

1 string reference to '_gotwo_filter'
gotwo_filter in ./gotwo.module
Implementation of hook_filter

File

./gotwo.module, line 197
Module that provides easy to use redirection links. A redirection link would be like: http://examples.org/go/a_label http://examples.org/go/123546 http://examples.org/go/or/like/this

Code

function _gotwo_filter($link) {

  // Split all link tag attributes into key and value pairs.
  preg_match_all('/\\s?+([^=]*)=["\']([^"\']*)["\']/i', $link[1], $matches);
  $go_attributes = array_combine($matches[1], $matches[2]);

  // Drop empty attributes and sort by name.
  $go_attributes = array_filter($go_attributes);
  ksort($go_attributes);

  // Verify if the url exists in the {gotwo} table. If the url is missing,
  // add the url with link title to the {gotwo} table.
  if (!empty($go_attributes['href'])) {
    $go_attributes['href'] = gotwo_get_url($go_attributes['href'], isset($go_attributes['title']) ? $go_attributes['title'] : NULL);
  }

  // Do not return a link if the go link doesn't haven attributes.
  return empty($go_attributes) ? $link[2] : '<a ' . drupal_attributes($go_attributes) . '>' . $link[2] . '</a>';
}