function _nodewords_output_tags in Nodewords: D6 Meta Tags 6
Same name and namespace in other branches
- 6.3 nodewords.module \_nodewords_output_tags()
- 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.
2 calls to _nodewords_output_tags()
- nodewords_nodeapi in ./
nodewords.module - Implements hook_nodeapi().
- nodewords_preprocess_page in ./
nodewords.module - Implements hook_preprocess_page().
File
- ./
nodewords.module, line 1429 - Implement an API that other modules can use to implement meta tags.
Code
function _nodewords_output_tags($tags, $output_type = 'head') {
$output = array();
$tags_info = nodewords_get_possible_tags();
$weights = array();
foreach ($tags as $name => $content) {
if ($content === '') {
continue;
}
// Check if it's a property meta tag (which may contain an XML namespace).
$is_property = $output_type == 'head' && isset($tags_info[$name]['templates']['head'][$name]) && $tags_info[$name]['templates']['head'][$name] == NODEWORDS_META_PROPERTY;
$parts = $is_property ? array(
$name,
$name,
) : explode(':', $name);
// Ensure that the previous assigned output template was cleared.
$template = NULL;
if (!isset($parts[1])) {
$parts[1] = $parts[0];
}
if ($output_type == 'update index') {
$bool = isset($tags_info[$parts[0]]['templates']['search index'][$parts[1]]);
if ($bool) {
// The '%content' element will be added later.
$replace = array(
'%attributes' => empty($tags_info[$parts[0]]['attributes'][$parts[1]]) ? '' : drupal_attributes($tags_info[$parts[0]]['attributes'][$parts[1]]),
);
$template = $tags_info[$parts[0]]['templates']['search index'][$parts[1]];
$weight = isset($tags_info[$parts[0]]['weight'][$parts[1]]) ? $tags_info[$parts[0]]['weight'][$parts[1]] : 0;
}
}
else {
$bool = isset($tags_info[$parts[0]]['templates']['head'][$parts[1]]) && ($meta_name = check_plain(decode_entities(strip_tags($parts[1]))));
if ($bool) {
// The '%content' element will be added later.
$replace = array(
'%name' => $meta_name,
'%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;
if (!is_string($template)) {
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;
// This requires theme customizations in order for the output to
// remain valid XHTML, see the OpenGraph section of the README.txt
// for further details.
case NODEWORDS_META_PROPERTY:
$template = '<meta property="%name" content="%content"%attributes />';
break;
default:
$template = '';
break;
}
}
}
}
if (!empty($template)) {
// Allow the meta tags to have multiple values.
if (!empty($tags_info[$name]['multiple'])) {
$content = explode("\n", $content);
}
// Simplify the output handling.
if (!is_array($content)) {
$content = array(
$content,
);
}
// Now add the content element(s) to the replacement array.
foreach ($content as $content_item) {
$replace['%content'] = str_replace(''', "'", trim(check_plain(decode_entities(strip_tags($content_item)))));
$output[] = strtr($template, $replace);
$weights[] = $weight;
}
}
}
if (count($output)) {
array_multisort($weights, $output);
return implode("\n", $output);
}
else {
return '';
}
}