You are here

function nodewords_preprocess_page in Nodewords: D6 Meta Tags 6.2

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

Implements hook_preprocess_page().

File

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

Code

function nodewords_preprocess_page(&$variables) {

  // Do not output meta tags on administration pages.
  if (arg(0) == 'admin') {
    return;
  }
  $output_tags = array();
  $head_tags = variable_get('nodewords_head', array());
  $options = nodewords_detect_type_id();
  if ($options['type'] != NODEWORDS_TYPE_NONE && $options['type'] != NODEWORDS_TYPE_OFFLINE) {
    $options['output'] = 'head';
    if ($options['type'] == NODEWORDS_TYPE_PAGER) {
      nodewords_load_all_includes('nodewords.tags.inc');
      foreach (nodewords_get_possible_tags() as $name => $info) {
        if (empty($head_tags[$name])) {
          continue;
        }
        $bool = !empty($info['context']['allowed']) && in_array(NODEWORDS_TYPE_PAGER, $info['context']['allowed']) && function_exists($function = $info['callback'] . '_prepare');
        if ($bool) {
          $options['parameters'] = !empty($info['callback arguments']) ? $info['callback arguments'] : array();
          $function($output_tags, array(), $options);
        }
      }
    }
    else {

      // Load the values from the database
      if ($options['type'] != NODEWORDS_TYPE_NODE || node_access('view', node_load($options['id']))) {
        $tags = nodewords_load_tags($options);
      }
      else {
        $tags = array();
      }
      nodewords_load_all_includes('nodewords.tags.inc');

      // Prepare the tags.
      foreach (nodewords_get_possible_tags() as $name => $info) {
        if (empty($head_tags[$name])) {
          continue;
        }
        if (function_exists($function = $info['callback'] . '_prepare')) {
          $options['parameters'] = !empty($info['callback arguments']) ? $info['callback arguments'] : array();
          $function($output_tags, _nodewords_tag_value($name, isset($tags[$name]) ? $tags[$name] : array(), $options + array(
            'admin' => FALSE,
          )), $options);
        }
      }
    }
    nodewords_load_all_includes('nodewords.hooks.inc');
    drupal_alter('nodewords_tags', $output_tags, $options);
    $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();
  }
}