You are here

function mappy_token_to_html in Mappy 7

Replace token [mappy:google ... ] to html analogue <mappy:google ...>.

2 calls to mappy_token_to_html()
mappy_tokens in ./mappy.module
Implements hook_tokens().
_mappy_filter_prepare in ./mappy.module
Prepare text to filtering.

File

./mappy.module, line 150
Module file for mappy.

Code

function mappy_token_to_html($token) {
  $pattern = "/\\[mappy(\\:(.+))?( .+)?\\]/isU";
  preg_match_all($pattern, $token, $matches);
  $service = $matches[2][0];

  // This is the real magic of Hogwarts. I spent totaly about 5-6 hours
  // to make this pattern work.
  preg_match_all("/(\\s)+(\\w+):(((\\s)*(\\w+))|(\\'(?:\\.|[^\\'\\\\])*\\'))/i", str_replace("&#39;", "'", $token), $parameters);

  // And write parameters to an array.
  $att = array();
  foreach ($parameters['0'] as $key => $name) {

    // Additional, we remove quotes.
    $att[$parameters['2'][$key]] = str_replace("'", "", $parameters['3'][$key]);
  }

  // Now we generate HTML Mappy tag.
  // Generate attributes.
  $attributes = "";
  foreach ($att as $key => $value) {
    $attributes .= " {$key}=\"{$value}\"";
  }

  // And add all to tag.
  // Without '<mappy:' because drupal remove colons from tag.
  $tag = "<{$service}{$attributes}></{$service}>";
  return $tag;
}