You are here

function theme_google_appliance_add_meta_tags in Google Search Appliance 6.2

Add meta tags to HTML header. Using a themeable function as a rough way of enabling customisation, but this could be made cleaner.

See also invocation of hook_google_appliance_meta_tags(). Implementations can add new tags, and over-ride default tags (including setting content to NULL to delete them).

1 theme call to theme_google_appliance_add_meta_tags()
google_appliance_init in ./google_appliance.module
Implementation of hook_init().

File

./google_appliance.module, line 1188
Google Search Appliance (GSA) / Google Mini integration

Code

function theme_google_appliance_add_meta_tags($node) {

  // create list of tags to add
  $meta_data = array();

  // Adding taxonomy tags
  $vocabs = taxonomy_get_vocabularies();
  if (module_exists('nat') && $node->nat) {

    // Node Auto Term integration
    $node->taxonomy = array_merge($node->nat, $node->taxonomy);
  }
  if (!empty($node->taxonomy) && is_array($node->taxonomy)) {
    foreach ($node->taxonomy as $term) {
      $tagname = 'category-' . strtolower($vocabs[$term->vid]->name);
      $meta_data[] = array(
        $tagname,
        $term->name,
      );
    }
  }

  // Adding sort date IMPORTANT: for sorting, mini must be configured to use this tag
  $meta_data[] = array(
    'modified',
    date('Y-m-d h:i:s', $node->changed),
  );
  $meta_data[] = array(
    'created',
    date('Y-m-d h:i:s', $node->created),
  );

  // Normally this doesn't matter, but if you want to
  // allow the GSA to access unpublished pages and later
  // filter on this, you will need it.
  $meta_data[] = array(
    'status',
    $node->status,
  );

  // i18n configuration
  if ($node->language) {
    $meta_data[] = array(
      'content-language',
      $node->language,
    );
  }

  // node type
  $meta_data[] = array(
    'type',
    $node->type,
  );

  // Author
  $node->uid = empty($node->uid) ? 0 : $node->uid;
  $user = user_load(array(
    'uid' => 0,
  ));
  $meta_data[] = array(
    'author',
    empty($user->name) ? 'anonymous' : $user->name,
  );

  // Invoke hook_google_appliance_meta_tags(&$meta_data, $node = NULL);
  $meta_data = array_merge($meta_data, module_invoke_all('google_appliance_meta_tags', $node));

  // Apply meta tags to page header
  foreach ($meta_data as $data) {
    list($name, $content) = $data;
    $content = strip_tags($content);
    if ($content !== NULL) {
      drupal_set_html_head(t('<meta name="@name" content="!content" />', array(
        '@name' => google_appliance_sgml_id_name($name),
        //see HTML4, 7.4.4 Meta data
        '!content' => htmlentities($content, ENT_QUOTES),
      )));
    }
  }
}