function cf_theme_generate_headers in Common Functionality 7.2
Same name and namespace in other branches
- 7 modules/cf_theme/cf_theme.module \cf_theme_generate_headers()
Properly generates html headers based on the contents of the $cf parameter.
This will auto-add all appropriate css headers through the appropriate drupal css calls.
The following meta are ignored because drupal core already handles them:
- Content-Type
- Generator
Justification: Theme *.tpl.php files should not ever have to call generate or perform isset()/empty() checks to prevent errors from happening. All of this work should be done in the template.php. There is not a standard way of doin this such that other modules and themes can hook into. This also allows custom modules to alter themes without having to hack or alter any existing theme that supports these functions.
Parameters
array $cf: An array of header elements to process.
Return value
string A string of html data.
Related topics
File
- modules/
cf_theme/ cf_theme.module, line 573 - Common Functionality - Theme module.
Code
function cf_theme_generate_headers(array $cf) {
$output = '';
// handle meta tags
if (!empty($cf['meta']['charset'])) {
$output .= '<meta charset="' . filter_xss($cf['meta']['charset'], array()) . '">' . "\n";
}
$supported_meta = array();
$supported_meta[] = 'abstract';
$supported_meta[] = 'author';
$supported_meta[] = 'classification';
$supported_meta[] = 'copyright';
$supported_meta[] = 'description';
$supported_meta[] = 'distribution';
$supported_meta[] = 'doc-class';
$supported_meta[] = 'doc-rights';
$supported_meta[] = 'doc-type';
$supported_meta[] = 'DownloadOptions';
$supported_meta[] = 'expires';
$supported_meta[] = 'generator';
$supported_meta[] = 'googlebot';
$supported_meta[] = 'keywords';
$supported_meta[] = 'MSSmartTagsPreventParsing';
$supported_meta[] = 'name';
$supported_meta[] = 'owner';
$supported_meta[] = 'progid';
$supported_meta[] = 'rating';
$supported_meta[] = 'refresh';
$supported_meta[] = 'reply-to';
$supported_meta[] = 'resource-type';
$supported_meta[] = 'revisit-after';
$supported_meta[] = 'robots';
$supported_meta[] = 'Template';
$supported_meta[] = 'google-site-verification';
foreach ($supported_meta as $tag) {
if (!empty($cf['meta']['name'][$tag])) {
$output .= '<meta name="' . $tag . '" content="' . filter_xss($cf['meta']['name'][$tag], array()) . '">' . "\n";
}
}
$supported_http_equiv = array();
$supported_http_equiv[] = 'cache-control';
$supported_http_equiv[] = 'content-language';
$supported_http_equiv[] = 'content-type';
$supported_http_equiv[] = 'date';
$supported_http_equiv[] = 'expires';
$supported_http_equiv[] = 'last-modified';
$supported_http_equiv[] = 'location';
$supported_http_equiv[] = 'refresh';
$supported_http_equiv[] = 'set-cookie';
$supported_http_equiv[] = 'window-target';
$supported_http_equiv[] = 'X-UA-Compatible';
// for specifying minimum Internet Explorer version
foreach ($supported_http_equiv as $tag) {
if (!empty($cf['meta']['http-equiv'][$tag])) {
$output .= '<meta http-equiv="' . $tag . '" content="' . filter_xss($cf['meta']['http-equiv'][$tag], array()) . '">' . "\n";
}
}
// handle css (Currently not working)
/*
foreach ($cf['css'] as $key => &$css) {
if (!empty($css['data'])) {
drupal_add_css($css['data'], (!empty($css['options']) ? $css['options'] : NULL));
}
}
*/
// handle custom links
$supported_link_media = array();
$supported_link_media[] = 'screen';
$supported_link_media[] = 'tty';
$supported_link_media[] = 'tv';
$supported_link_media[] = 'projection';
$supported_link_media[] = 'handheld';
$supported_link_media[] = 'print';
$supported_link_media[] = 'braille';
$supported_link_media[] = 'aural';
$supported_link_media[] = 'all';
$supported_link_rel = array();
$supported_link_rel[] = 'alternate';
$supported_link_rel[] = 'appendix';
$supported_link_rel[] = 'bookmark';
$supported_link_rel[] = 'canonical';
$supported_link_rel[] = 'chapter';
$supported_link_rel[] = 'contents';
$supported_link_rel[] = 'copyright';
$supported_link_rel[] = 'glossary';
$supported_link_rel[] = 'help';
$supported_link_rel[] = 'home';
$supported_link_rel[] = 'index';
$supported_link_rel[] = 'next';
$supported_link_rel[] = 'prev';
$supported_link_rel[] = 'section';
$supported_link_rel[] = 'shortlink';
$supported_link_rel[] = 'start';
$supported_link_rel[] = 'stylesheet';
$supported_link_rel[] = 'subsection';
$supported_link_rel[] = 'shortcut icon';
$supported_link_rel[] = 'apple-touch-icon';
$supported_link_rel[] = 'apple-touch-icon-precomposed';
foreach ($cf['link'] as $key => &$link) {
if (empty($link['href'])) {
continue;
}
$output .= '<link';
foreach (array(
'charset',
'href',
'hreflang',
'media',
'rel',
'target',
'type',
'title',
) as $type) {
if ($type == 'rel') {
if (empty($link['rel'])) {
if (!empty($link['rev']) && in_array($link['rev'], $supported_link_rel)) {
$output .= ' rev="' . $link['rev'] . '"';
}
}
else {
if (in_array($link['rel'], $supported_link_rel)) {
$output .= ' rel="' . $link['rel'] . '"';
}
}
}
else {
if ($type == 'media') {
if (!empty($link['media']) && in_array($link['media'], $supported_link_media)) {
$output .= ' media="' . $link['media'] . '"';
}
}
else {
if (!empty($link[$type])) {
$output .= ' ' . $type . '="' . filter_xss($link[$type], array()) . '"';
}
}
}
}
$output .= '>' . "\n";
}
return $output;
}