You are here

function _nodewords_output_tags in Nodewords: D6 Meta Tags 6.3

Same name and namespace in other branches
  1. 6 nodewords.module \_nodewords_output_tags()
  2. 6.2 nodewords.module \_nodewords_output_tags()

Render the meta tag values as HTML.

Parameters

$tags: An array of tags.

$output_type: The type of output, 'head' (default), or 'update index'.

Return value

A string containing the HTML output for the META tag.

1 call to _nodewords_output_tags()
nodewords_preprocess_page in ./nodewords.module
Implements hook_preprocess_page().

File

./nodewords.module, line 1012
Implement an version that other modules can use to add meta tags.

Code

function _nodewords_output_tags(array $tags) {
  $output = array();
  $tags_info = nodewords_get_possible_tags();
  $weights = array();
  foreach ($tags as $name => $content) {
    if (empty($content)) {
      continue;
    }
    $parts = explode(':', $name);
    $template = '';
    if (!isset($parts[1])) {
      $parts[1] = $parts[0];
    }
    if (!is_array($content)) {
      $content = array(
        $content,
      );
    }
    foreach ($content as $value) {
      $bool = isset($tags_info[$parts[0]]['templates']['head'][$parts[1]]) && ($meta_name = check_plain(decode_entities(strip_tags($parts[1])))) && ($meta_content = trim(check_plain(decode_entities(strip_tags(preg_replace('/(\\s)\\s+/', '$1', $value))))));
      if ($bool) {
        $replace = array(
          '%name' => $meta_name,
          '%content' => $meta_content,
          '%attributes' => empty($tags_info[$parts[0]]['attributes'][$parts[1]]) ? '' : drupal_attributes($tags_info[$parts[0]]['attributes'][$parts[1]]),
        );
        $template = $tags_info[$parts[0]]['templates']['head'][$parts[1]];
        $weight = isset($tags_info[$parts[0]]['weight'][$parts[1]]) ? $tags_info[$parts[0]]['weight'][$parts[1]] : 0;
        switch ($template) {
          case NODEWORDS_META:
            $template = '<meta name="%name" content="%content"%attributes />';
            break;
          case NODEWORDS_HTTP_EQUIV:
            $template = '<meta http-equiv="%name" content="%content"%attributes />';
            break;
          case NODEWORDS_LINK_REL:
            $template = '<link rel="%name" href="%content"%attributes />';
            break;
          case NODEWORDS_LINK_REV:
            $template = '<link rev="%name" href="%content"%attributes />';
            break;
          default:
            if (!is_string($template)) {
              $template = '';
            }
            break;
        }
      }
      if (!empty($template)) {
        $output[] = strtr($template, $replace);
        $weights[] = $weight;
      }
    }
  }
  if (count($output)) {
    array_multisort($weights, $output);
    return implode("\n", $output);
  }
  else {
    return '';
  }
}