function rdf_preprocess_node

7.x rdf.module rdf_preprocess_node(&$variables)

Implements MODULE_preprocess_HOOK().

File

drupal-7.x/modules/rdf/rdf.module, line 466
Enables semantically enriched output for Drupal sites in the form of RDFa.

Code

function rdf_preprocess_node(&$variables) {
  // Adds RDFa markup to the node container. The about attribute specifies the
  // URI of the resource described within the HTML element, while the @typeof
  // attribute indicates its RDF type (e.g., foaf:Document, sioc:Person, and so
  // on.)
  $variables['attributes_array']['about'] = empty($variables['node_url']) ? NULL : $variables['node_url'];
  $variables['attributes_array']['typeof'] = empty($variables['node']->rdf_mapping['rdftype']) ? NULL : $variables['node']->rdf_mapping['rdftype'];

  // Adds RDFa markup to the title of the node. Because the RDFa markup is
  // added to the <h2> tag which might contain HTML code, we specify an empty
  // datatype to ensure the value of the title read by the RDFa parsers is a
  // literal.
  $variables['title_attributes_array']['property'] = empty($variables['node']->rdf_mapping['title']['predicates']) ? NULL : $variables['node']->rdf_mapping['title']['predicates'];
  $variables['title_attributes_array']['datatype'] = '';

  // In full node mode, the title is not displayed by node.tpl.php so it is
  // added in the <head> tag of the HTML page.
  if ($variables['page']) {
    $element = array(
      '#tag' => 'meta',
      '#attributes' => array(
        'content' => $variables['node']->title,
        'about' => $variables['node_url'],
      ),
    );
    if (!empty($variables['node']->rdf_mapping['title']['predicates'])) {
      $element['#attributes']['property'] = $variables['node']->rdf_mapping['title']['predicates'];
    }
    drupal_add_html_head($element, 'rdf_node_title');
  }

  // Adds RDFa markup for the date.
  if (!empty($variables['rdf_mapping']['created'])) {
    $date_attributes_array = rdf_rdfa_attributes($variables['rdf_mapping']['created'], $variables['created']);
    $variables['rdf_template_variable_attributes_array']['date'] = $date_attributes_array;
    if ($variables['submitted']) {
      $variables['rdf_template_variable_attributes_array']['submitted'] = $date_attributes_array;
    }
  }
  // Adds RDFa markup for the relation between the node and its author.
  if (!empty($variables['rdf_mapping']['uid'])) {
    $variables['rdf_template_variable_attributes_array']['name']['rel'] = $variables['rdf_mapping']['uid']['predicates'];
    if ($variables['submitted']) {
      $variables['rdf_template_variable_attributes_array']['submitted']['rel'] = $variables['rdf_mapping']['uid']['predicates'];
    }
  }

  // Adds RDFa markup annotating the number of comments a node has.
  if (isset($variables['node']->comment_count) && !empty($variables['node']->rdf_mapping['comment_count']['predicates'])) {
    // Annotates the 'x comments' link in teaser view.
    if (isset($variables['content']['links']['comment']['#links']['comment-comments'])) {
      $comment_count_attributes['property'] = $variables['node']->rdf_mapping['comment_count']['predicates'];
      $comment_count_attributes['content'] = $variables['node']->comment_count;
      $comment_count_attributes['datatype'] = $variables['node']->rdf_mapping['comment_count']['datatype'];
      // According to RDFa parsing rule number 4, a new subject URI is created
      // from the href attribute if no rel/rev attribute is present. To get the
      // original node URL from the about attribute of the parent container we
      // set an empty rel attribute which triggers rule number 5. See
      // http://www.w3.org/TR/rdfa-syntax/#sec_5.5.
      $comment_count_attributes['rel'] = '';
      $variables['content']['links']['comment']['#links']['comment-comments']['attributes'] += $comment_count_attributes;
    }
    // In full node view, the number of comments is not displayed by
    // node.tpl.php so it is expressed in RDFa in the <head> tag of the HTML
    // page.
    if ($variables['page'] && user_access('access comments')) {
      $element = array(
        '#tag' => 'meta',
        '#attributes' => array(
          'about' => $variables['node_url'],
          'property' => $variables['node']->rdf_mapping['comment_count']['predicates'],
          'content' => $variables['node']->comment_count,
          'datatype' => $variables['node']->rdf_mapping['comment_count']['datatype'],
        ),
      );
      drupal_add_html_head($element, 'rdf_node_comment_count');
    }
  }
}