You are here

function nodewords_preprocess_page in Nodewords: D6 Meta Tags 6

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

Implements hook_preprocess_page().

1 call to nodewords_preprocess_page()
nodewords_preprocess_maintenance_page in ./nodewords.module
Implements hook_preprocess_maintenance_page().

File

./nodewords.module, line 555
Implement an API that other modules can use to implement meta tags.

Code

function nodewords_preprocess_page(&$variables) {

  // Do not do anything when running in install or update mode.
  if (defined('MAINTENANCE_MODE')) {
    return;
  }
  $options = _nodewords_detect_type_and_id();
  $output_tags = array();
  $options += array(
    'default' => nodewords_load_tags(),
    'output' => 'head',
  );
  if ($options['type'] == NODEWORDS_TYPE_PAGER) {
    foreach (nodewords_get_possible_tags() as $name => $info) {
      $bool = !empty($info['context']['allowed']) && in_array(NODEWORDS_TYPE_PAGER, $info['context']['allowed']) && function_exists($function = $info['callback'] . '_prepare');
      if ($bool) {
        $function($output_tags, array(), $options);
      }
    }
  }
  else {

    // User profiles meta tags are not enabled.
    if ($options['type'] == NODEWORDS_TYPE_USER && !variable_get('nodewords_enable_user_metatags', TRUE)) {
      return;
    }
    elseif ($options['type'] == NODEWORDS_TYPE_NODE && !node_access('view', node_load($options['id']))) {
      $tags = array();
    }
    else {
      $tags = nodewords_load_tags($options['type'], $options['id']);
    }

    // Prepare the tags.
    foreach (nodewords_get_possible_tags() as $name => $info) {
      if (function_exists($function = $info['callback'] . '_prepare')) {
        $function($output_tags, isset($tags[$name]) ? $tags[$name] : array(), $options);
      }
    }
  }
  drupal_alter('nodewords_tags', $output_tags, $options);

  // Title tag has its own page preprocess variable and must be handled
  // separately.
  if (isset($output_tags['page_title'])) {
    if (!empty($output_tags['page_title'])) {
      drupal_set_title($output_tags['page_title']);
      $variables['head_title'] = strip_tags(drupal_get_title());
    }
    unset($output_tags['page_title']);
  }
  $output = _nodewords_output_tags($output_tags);
  drupal_alter('nodewords_tags_output', $output, $options);

  // Output the tags to the header.
  drupal_set_html_head($output);
  $variables['head'] = drupal_get_html_head();
}