You are here

function cf_theme_generate_headers in Common Functionality 7

Same name and namespace in other branches
  1. 7.2 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

Why: 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 doing 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.

array $function_history: (optional) An array of function names, ie: array('0' => 'my_function_name').

Return value

string A string of html data.

File

modules/cf_theme/cf_theme.module, line 365

Code

function cf_theme_generate_headers(array $cf, array $function_history = array()) {
  $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';
  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));
    }
  }
  */
  return $output;
}