rdf.module 22.9 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Enables semantically enriched output for Drupal sites in the form of RDFa.
6
7
 */

8
use Drupal\Component\Utility\NestedArray;
9
10
use Drupal\Core\Template\Attribute;

11
/**
12
 * Implements hook_help().
13
14
15
16
17
18
 */
function rdf_help($path, $arg) {
  switch ($path) {
    case 'admin/help#rdf':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
19
      $output .= '<p>' . t('The RDF module enriches your content with metadata to let other applications (e.g., search engines, aggregators, and so on) better understand its relationships and attributes. This semantically enriched, machine-readable output for Drupal sites uses the <a href="!rdfa">RDFa specification</a>, which allows RDF data to be embedded in HTML markup. Other modules can define mappings of their data to RDF terms, and the RDF module makes this RDF data available to the theme. The core Drupal modules define RDF mappings for their data model, and the core Drupal themes output this RDF metadata information along with the human-readable visual information. For more information, see the <a href="!rdf">online documentation for the RDF module</a>.', array('!rdfa' => 'http://www.w3.org/TR/xhtml-rdfa-primer/', '!rdf' => 'https://drupal.org/documentation/modules/rdf')) . '</p>';
20
21
22
23
      return $output;
  }
}

24
/**
25
 * @defgroup rdf RDF Mapping API
26
 * @{
27
 * Functions to describe entities and bundles in RDF.
28
 *
29
30
31
32
 * The RDF module introduces RDF and RDFa to Drupal. RDF is a W3C standard to
 * describe structured data. RDF can be serialized as RDFa in XHTML attributes
 * to augment visual data with machine-readable hints.
 * @see http://www.w3.org/RDF/
33
34
 * @see http://www.w3.org/TR/xhtml-rdfa-primer/
 *
35
36
37
38
 * Modules can provide mappings of their bundles' data and metadata to RDF
 * classes and properties. This module takes care of injecting these mappings
 * into variables available to theme functions and templates. All Drupal core
 * themes are coded to be RDFa compatible.
39
40
41
 */
/**
 * Returns the RDF mapping object associated to a bundle.
42
 *
43
44
45
46
47
48
49
50
 * The function reads the rdf_mapping object from the current configuration,
 * or returns a ready-to-use empty one if no configuration entry exists yet for
 * this bundle. This streamlines the manipulation of mapping objects by always
 * returning a consistent object that reflects the current state of the
 * configuration.
 *
 * Example usage:
 * -Map the 'article' bundle to 'sioc:Post' and the 'title' field to 'dc:title'.
51
 * @code
52
53
54
55
56
57
58
59
 * rdf_get_mapping('node', 'article')
 *   ->setBundleMapping(array(
 *     'types' => array('sioc:Post'),
 *   ))
 *   ->setFieldMapping('title', array(
 *     'properties' => array('dc:title')
 *   ))
 *   ->save();
60
61
 * @endcode
 *
62
63
64
65
66
 * @param string $entity_type
 *   The entity type.
 * @param string $bundle
 *   The bundle.
 *
67
 * @return \Drupal\rdf\Entity\RdfMapping
68
 *   The RdfMapping object.
69
 */
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function rdf_get_mapping($entity_type, $bundle) {
  // Try loading the mapping from configuration.
  $mapping = entity_load('rdf_mapping', $entity_type . '.' . $bundle);

  // If not found, create a fresh mapping object.
  if (!$mapping) {
    $mapping = entity_create('rdf_mapping', array(
      'targetEntityType' => $entity_type,
      'bundle' => $bundle,
    ));
  }

  return $mapping;
}
84

85
86
87
88
89
90
91
92
/**
 * Implements hook_rdf_namespaces().
 */
function rdf_rdf_namespaces() {
  return array(
    'content'  => 'http://purl.org/rss/1.0/modules/content/',
    'dc'       => 'http://purl.org/dc/terms/',
    'foaf'     => 'http://xmlns.com/foaf/0.1/',
93
    'og'       => 'http://ogp.me/ns#',
94
    'rdfs'     => 'http://www.w3.org/2000/01/rdf-schema#',
95
    'schema'   => 'http://schema.org/',
96
97
98
99
100
101
102
    'sioc'     => 'http://rdfs.org/sioc/ns#',
    'sioct'    => 'http://rdfs.org/sioc/types#',
    'skos'     => 'http://www.w3.org/2004/02/skos/core#',
    'xsd'      => 'http://www.w3.org/2001/XMLSchema#',
  );
}

103
/**
104
105
106
107
 * Retrieves RDF namespaces.
 *
 * Invokes hook_rdf_namespaces() and collects RDF namespaces from modules that
 * implement it.
108
109
 */
function rdf_get_namespaces() {
110
111
  $namespaces = array();
  // In order to resolve duplicate namespaces by using the earliest defined
112
  // namespace, do not use \Drupal::moduleHandler()->invokeAll().
113
  foreach (\Drupal::moduleHandler()->getImplementations('rdf_namespaces') as $module) {
114
115
116
    $function = $module . '_rdf_namespaces';
    if (function_exists($function)) {
      $namespaces = NestedArray::mergeDeep($function(), $namespaces);
117
118
    }
  }
119
  return $namespaces;
120
121
}

122
123
124
125
126
127
128
129
130
/**
 * @} End of "defgroup rdf".
 */

/**
 * @addtogroup rdf
 * @{
 */

131
/**
132
133
 * Builds an array of RDFa attributes for a given mapping.
 *
134
135
136
137
 * This array will typically be passed through Drupal\Core\Template\Attribute
 * to create the attributes variables that are available to template files.
 * These include $attributes, $title_attributes, $content_attributes and the
 * field-specific $item_attributes variables.
138
 *
139
140
141
 * @param array $mapping
 *   An array containing a mandatory 'properties' key and optional 'datatype',
 *   'datatype_callback' and 'type' keys. For example:
142
143
 *   @code
 *     array(
144
145
146
147
148
149
150
 *       'properties' => array('schema:interactionCount'),
 *       'datatype' => 'xsd:integer',
 *       'datatype_callback' => array(
 *         'callable' => 'Drupal\rdf\SchemaOrgDataConverter::interactionCount',
 *         'arguments' => array(
 *           'interaction_type' => 'UserComments'
 *         ),
151
152
153
 *       ),
 *     );
 *   @endcode
154
 * @param mixed $data
155
156
 *   (optional) A value that needs to be converted by the provided callback
 *   function.
157
 *
158
 * @return array
159
 *   RDFa attributes suitable for Drupal\Core\Template\Attribute.
160
161
 */
function rdf_rdfa_attributes($mapping, $data = NULL) {
162
163
  $attributes = array();

164
  // The type of mapping defaults to 'property'.
165
  $type = isset($mapping['mapping_type']) ? $mapping['mapping_type'] : 'property';
166
167
168
169
170

  switch ($type) {
    // The mapping expresses the relationship between two resources.
    case 'rel':
    case 'rev':
171
      $attributes[$type] = $mapping['properties'];
172
173
174
175
176
      break;

    // The mapping expresses the relationship between a resource and some
    // literal text.
    case 'property':
177
178
179
180
      if (!empty($mapping['properties'])) {
        $attributes['property'] = $mapping['properties'];
        // Convert $data to a specific format as per the callback function.
        if (isset($data) && !empty($mapping['datatype_callback'])) {
181
182
183
          $callback = $mapping['datatype_callback']['callable'];
          $arguments = isset($mapping['datatype_callback']['arguments']) ? $mapping['datatype_callback']['arguments'] : NULL;
          $attributes['content'] = call_user_func($callback, $data, $arguments);
184
185
186
187
188
        }
        if (isset($mapping['datatype'])) {
          $attributes['datatype'] = $mapping['datatype'];
        }
        break;
189
190
191
192
193
194
195
      }
  }

  return $attributes;
}

/**
196
 * @} End of "addtogroup rdf".
197
198
 */

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/**
 * Implements hook_entity_prepare_view().
 */
function rdf_entity_prepare_view($entity_type, array $entities, array $displays) {
  // Iterate over the RDF mappings for each entity and prepare the RDFa
  // attributes to be added inside field formatters.
  foreach ($entities as $entity) {
    $mapping = rdf_get_mapping($entity_type, $entity->bundle());
    // Only prepare the RDFa attributes for the fields which are configured to
    // be displayed.
    foreach ($displays[$entity->bundle()]->getComponents() as $name => $options) {
      $field_mapping = $mapping->getPreparedFieldMapping($name);
      if ($field_mapping['properties']) {
        foreach ($entity->get($name) as $item) {
          $item->_attributes += rdf_rdfa_attributes($field_mapping, $item->getValue());
        }
      }
    }
  }
}

220
221
222
223
224
/**
 * Implements hook_comment_load().
 */
function rdf_comment_load($comments) {
  foreach ($comments as $comment) {
225
226
227
    // Pages with many comments can show poor performance. This information
    // isn't needed until rdf_preprocess_comment() is called, but set it here
    // to optimize performance for websites that implement an entity cache.
228
229
230
    $created_mapping = rdf_get_mapping('comment', $comment->bundle())
      ->getPreparedFieldMapping('created');
    $comment->rdf_data['date'] = rdf_rdfa_attributes($created_mapping, $comment->created->value);
231
232
233
    $entity = entity_load($comment->entity_type->value, $comment->entity_id->value);
    $uri = $entity->uri();
    $comment->rdf_data['entity_uri'] = url($uri['path']);
234
    if ($comment->pid->target_id) {
235
      $comment->rdf_data['pid_uri'] = url('comment/' . $comment->pid->target_id);
236
237
238
239
    }
  }
}

240
241
242
243
244
245
/**
 * Implements hook_theme().
 */
function rdf_theme() {
  return array(
    'rdf_metadata' => array(
246
      'variables' => array('metadata' => array()),
247
248
249
250
    ),
  );
}

251
/**
252
 * Implements hook_preprocess_HOOK() for HTML document templates.
253
254
255
256
 */
function rdf_preprocess_html(&$variables) {
  // Adds RDF namespace prefix bindings in the form of an RDFa 1.1 prefix
  // attribute inside the html element.
257
258
259
  if (!isset($variables['html_attributes']['prefix'])) {
    $variables['html_attributes']['prefix'] = array();
  }
260
  foreach(rdf_get_namespaces() as $prefix => $uri) {
261
    $variables['html_attributes']['prefix'][] = $prefix . ': ' . $uri . "\n";
262
263
264
  }
}

265
/**
266
 * Implements hook_preprocess_HOOK() for node templates.
267
268
 */
function rdf_preprocess_node(&$variables) {
269
  // Adds RDFa markup to the node container. The about attribute specifies the
270
271
272
  // 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.)
273
274
275
  $bundle = $variables['node']->bundle();
  $mapping = rdf_get_mapping('node', $bundle);
  $bundle_mapping = $mapping->getPreparedBundleMapping('node', $bundle);
276
  $variables['attributes']['about'] = empty($variables['node_url']) ? NULL: $variables['node_url'];
277
  $variables['attributes']['typeof'] = empty($bundle_mapping['types']) ? NULL : $bundle_mapping['types'];
278

279
280
281
  // Adds RDFa markup for the node title as metadata because wrapping the title
  // with markup is not reliable and the title output is different depdending on
  // the view mode (e.g. full vs. teaser).
282
  $title_mapping = $mapping->getPreparedFieldMapping('title');
283
284
  if ($title_mapping) {
    $title_attributes['property'] = empty($title_mapping['properties']) ? NULL : $title_mapping['properties'];
285
    $title_attributes['content'] = $variables['node']->label();
286
287
288
    $variables['title_suffix']['rdf_meta_title'] = array(
      '#theme' => 'rdf_metadata',
      '#metadata' => array($title_attributes),
289
    );
290
291
  }

292
293
294
295
296
297
298
  // Adds RDFa markup for the relation between the node and its author.
  $author_mapping = $mapping->getPreparedFieldMapping('uid');
  if (!empty($author_mapping['properties']) && $variables['submitted']) {
    $author_attributes = array('rel' => $author_mapping['properties']);
    $variables['submitted'] = '<span ' . new Attribute($author_attributes) . '>' . $variables['submitted'] . '</span>';
  }

299
  // Adds RDFa markup for the date.
300
  $created_mapping = $mapping->getPreparedFieldMapping('created');
301
  if (!empty($created_mapping) && $variables['submitted']) {
302
    $date_attributes = rdf_rdfa_attributes($created_mapping, $variables['node']->getCreatedTime());
303
304
305
306
307
    $rdf_metadata = array(
      '#theme' => 'rdf_metadata',
      '#metadata' => array($date_attributes),
    );
    $variables['submitted'] .= drupal_render($rdf_metadata);
308
  }
309
310

  // Adds RDFa markup annotating the number of comments a node has.
311
312
  if (\Drupal::moduleHandler()->moduleExists('comment') && \Drupal::currentUser()->hasPermission('access comments')) {
    $comment_count_mapping = $mapping->getPreparedFieldMapping('comment_count');
313
314
315
316
317
318
319
    if (!empty($comment_count_mapping['properties'])) {
      $fields = array_keys(\Drupal::service('comment.manager')->getFields('node'));
      $definitions = array_keys($variables['node']->getPropertyDefinitions());
      $valid_fields = array_intersect($fields, $definitions);
      $count = 0;
      foreach ($valid_fields as $field_name) {
        $count += $variables['node']->get($field_name)->comment_count;
320
321
322
323
324
        // Adds RDFa markup for the comment count near the node title as metadata
        $comment_count_attributes = rdf_rdfa_attributes($comment_count_mapping, $variables['node']->get($field_name)->comment_count);
        $variables['title_suffix']['rdf_meta_comment_count'] = array(
          '#theme' => 'rdf_metadata',
          '#metadata' => array($comment_count_attributes),
325
326
        );
      }
327
328
    }
  }
329
330
331
}

/**
332
 * Implements hook_preprocess_HOOK() for user templates.
333
 */
334
335
function rdf_preprocess_user(&$variables) {
  $account = $variables['elements']['#user'];
336
  $uri = $account->uri();
337
338
  $mapping = rdf_get_mapping('user', 'user');
  $bundle_mapping = $mapping->getPreparedBundleMapping();
339
340

  // Adds RDFa markup to the user profile page. Fields displayed in this page
341
  // will automatically describe the user.
342
343
  if (!empty($bundle_mapping['types'])) {
    $variables['attributes']['typeof'] = $bundle_mapping['types'];
344
    $variables['attributes']['about'] = url($uri['path'], $uri['options']);
345
  }
346
347
348
  // If we are on the user account page, add the relationship between the
  // sioc:UserAccount and the foaf:Person who holds the account.
  if (current_path() == $uri['path']) {
349
350
    // Adds the markup for username as language neutral literal, see
    // rdf_preprocess_username().
351
352
353
354
355
356
357
    $name_mapping = $mapping->getPreparedFieldMapping('name');
    if (!empty($name_mapping['properties'])) {
      $username_meta = array(
        '#tag' => 'meta',
        '#attributes' => array(
          'about' => url($uri['path'], $uri['options']),
          'property' => $name_mapping['properties'],
358
          'content' => $account->getUsername(),
359
360
361
362
363
          'lang' => '',
        ),
      );
      drupal_add_html_head($username_meta, 'rdf_user_username');
    }
364
  }
365
366
367
}

/**
368
 * Implements hook_preprocess_HOOK() for theme_username().
369
370
 */
function rdf_preprocess_username(&$variables) {
371
  $attributes = array();
372
  // Because lang is set on the HTML element that wraps the page, the
373
374
375
376
  // username inherits this language attribute. However, since the username
  // might not be transliterated to the same language that the content is in,
  // we do not want it to inherit the language attribute, so we set the
  // attribute to an empty string.
377
  if (empty($variables['attributes']['lang'])) {
378
    $attributes['lang'] = '';
379
380
  }

381
  // The profile URI is used to identify the user account. The about attribute
382
  // is used to set the URI as the default subject of the properties embedded
383
384
385
386
  // as RDFa in the child elements. Even if the user profile is not accessible
  // to the current user, we use its URI in order to identify the user in RDF.
  // We do not use this attribute for the anonymous user because we do not have
  // a user profile URI for it (only a homepage which cannot be used as user
387
  // profile in RDF.)
388
  if ($variables['uid'] > 0) {
389
    $attributes['about'] = url('user/' . $variables['uid']);
390
  }
391

392
393
394
395
396
  // Add RDF type of user.
  $mapping = rdf_get_mapping('user', 'user');
  $bundle_mapping = $mapping->getPreparedBundleMapping();
  if (!empty($bundle_mapping['types'])) {
    $attributes['typeof'] = $bundle_mapping['types'];
397
  }
398
399
400
  // Annotate the username in RDFa. A property attribute is used with an empty
  // datatype attribute to ensure the username is parsed as a plain literal
  // in RDFa 1.0 and 1.1.
401
402
403
  $name_mapping = $mapping->getPreparedFieldMapping('name');
  if (!empty($name_mapping)) {
    $attributes['property'] = $name_mapping['properties'];
404
    $attributes['datatype'] = '';
405
406
  }
  // Add the homepage RDFa markup if present.
407
408
409
  $homepage_mapping = $mapping->getPreparedFieldMapping('homepage');
  if (!empty($variables['homepage']) && !empty($homepage_mapping)) {
    $attributes['rel'] = $homepage_mapping['properties'];
410
  }
411
  // The remaining attributes can have multiple values listed, with whitespace
412
413
  // separating the values in the RDFa attributes
  // (see http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes).
414
  // Therefore, merge rather than override so as not to clobber values set by
415
416
417
418
419
420
421
422
  // earlier preprocess functions. These attributes will be placed in the a
  // element if a link is rendered, or on a span element otherwise.
  if (isset($variables['link_path'])) {
    $variables['link_options']['attributes'] = array_merge_recursive($variables['link_options']['attributes'], $attributes);
  }
  else {
    $variables['attributes'] = array_merge_recursive($variables['attributes'], $attributes);
  }
423
424
425
}

/**
426
 * Implements hook_preprocess_HOOK() for comment templates.
427
428
429
 */
function rdf_preprocess_comment(&$variables) {
  $comment = $variables['comment'];
430
431
432
433
  $mapping = rdf_get_mapping('comment', $comment->bundle());
  $bundle_mapping = $mapping->getPreparedBundleMapping();

  if (!empty($bundle_mapping['types'])) {
434
    // Adds RDFa markup to the comment container. The about attribute specifies
435
    // the URI of the resource described within the HTML element, while the
436
437
    // typeof attribute indicates its RDF type (e.g., sioc:Post, foaf:Document,
    // and so on.)
438
    $uri = $comment->uri();
439
    $variables['attributes']['about'] = url($uri['path'], $uri['options']);
440
    $variables['attributes']['typeof'] = $bundle_mapping['types'];
441
442
  }

443
444
445
446
  // Adds RDFa markup for the relation between the comment and its author.
  $author_mapping = $mapping->getPreparedFieldMapping('uid');
  if (!empty($author_mapping)) {
    $author_attributes = array('rel' => $author_mapping['properties']);
447
448
449
    // Wraps the author variable and the submitted variable which are both
    // available in comment.html.twig.
    $variables['author'] = '<span ' . new Attribute($author_attributes) . '>' . $variables['author'] . '</span>';
450
451
    $variables['submitted'] = '<span ' . new Attribute($author_attributes) . '>' . $variables['submitted'] . '</span>';
  }
452
  // Adds RDFa markup for the date of the comment.
453
454
  $created_mapping = $mapping->getPreparedFieldMapping('created');
  if (!empty($created_mapping)) {
455
456
    // The comment date is precomputed as part of the rdf_data so that it can be
    // cached as part of the entity.
457
    $date_attributes = $comment->rdf_data['date'];
458
459
460
461
462
463
464
465
466
467

    $rdf_metadata = array(
      '#theme' => 'rdf_metadata',
      '#metadata' => array($date_attributes),
    );
    $created_metadata_markup = drupal_render($rdf_metadata);
    // Appends the markup to the created variable and the submitted variable
    // which are both available in comment.html.twig.
    $variables['created'] .= $created_metadata_markup;
    $variables['submitted'] .= $created_metadata_markup;
468
  }
469
  $title_mapping = $mapping->getPreparedFieldMapping('subject');
470
  if (!empty($title_mapping)) {
471
472
473
474
    // Adds RDFa markup to the subject of the comment. Because the RDFa markup
    // is added to an <h3> 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.
475
    $variables['title_attributes']['property'] = $title_mapping['properties'];
476
    $variables['title_attributes']['datatype'] = '';
477
478
479
480
  }

  // Annotates the parent relationship between the current comment and the node
  // it belongs to. If available, the parent comment is also annotated.
481
482
  // @todo When comments are turned into fields, this should be changed.
  // Currently there is no mapping relating a comment to its node.
483
484
  $pid_mapping = $mapping->getPreparedFieldMapping('pid');
  if (!empty($pid_mapping)) {
485
486
487
488
489
490
    // Adds the relation to the parent entity.
    $parent_entity_attributes['rel'] = $pid_mapping['properties'];
    // The parent entity URI is precomputed as part of the rdf_data so that it
    // can be cached as part of the entity.
    $parent_entity_attributes['resource'] = $comment->rdf_data['entity_uri'];
    $variables['rdf_metadata_attributes'][] = $parent_entity_attributes;
491

492
    // Adds the relation to parent comment, if it exists.
493
    if ($comment->pid->target_id != 0) {
494
      $parent_comment_attributes['rel'] = $pid_mapping['properties'];
495
496
      // The parent comment URI is precomputed as part of the rdf_data so that
      // it can be cached as part of the entity.
497
      $parent_comment_attributes['resource'] = $comment->rdf_data['pid_uri'];
498
      $variables['rdf_metadata_attributes'][] = $parent_comment_attributes;
499
500
    }
  }
501
502
503
504
505
  // Adds RDF metadata markup above comment body.
  if (!empty($variables['rdf_metadata_attributes'])) {
    if (!isset($variables['content']['comment_body']['#prefix'])) {
      $variables['content']['comment_body']['#prefix'] = '';
    }
506
507
508
509
510
    $rdf_metadata = array(
      '#theme' => 'rdf_metadata',
      '#metadata' => $variables['rdf_metadata_attributes'],
    );
    $variables['content']['comment_body']['#prefix'] = drupal_render($rdf_metadata) . $variables['content']['comment_body']['#prefix'];
511
  }
512
513
}

514
/**
515
 * Implements hook_preprocess_HOOK() for taxonomy term templates.
516
517
518
 */
function rdf_preprocess_taxonomy_term(&$variables) {
  $term = $variables['term'];
519
520
521
522
  $mapping = rdf_get_mapping('taxonomy_term', $term->bundle());
  $bundle_mapping = $mapping->getPreparedBundleMapping();
  $name_field_mapping = $mapping->getPreparedFieldMapping('name');
  // Adds the RDF type of the term and the term name in a <meta> tag.
523
  $term_label_meta = array(
524
525
526
527
528
529
530
531
    '#tag' => 'meta',
    '#attributes' => array(
      'about' => url('taxonomy/term/' . $term->id()),
      'typeof' => $bundle_mapping['types'],
      'property' => $name_field_mapping['properties'],
      'content' => $term->label(),
    ),
  );
532
533
534
  drupal_add_html_head($term_label_meta, 'rdf_term_label');
}

535
/**
536
 * Implements hook_preprocess_HOOK() for theme_image().
537
538
 */
function rdf_preprocess_image(&$variables) {
539
540
541
  // Adds the RDF type for image.  We cannot use the usual entity-based mapping
  // to get 'foaf:Image' because image does not have its own entity type or
  // bundle.
542
543
544
  $variables['attributes']['typeof'] = array('foaf:Image');
}

545
/**
546
 * Returns HTML for a series of empty spans for exporting RDF metadata in RDFa.
547
 *
548
549
550
 * Sometimes it is useful to export data which is not semantically present in
 * the HTML output. For example, a hierarchy of comments is visible for a human
 * but not for machines because this hiearchy is not present in the DOM tree.
551
552
 * We can express it in RDFa via empty <span> tags. These aren't visible and
 * give machines extra information about the content and its structure.
553
 *
554
555
556
557
558
 * @param $variables
 *   An associative array containing:
 *   - metadata: An array of attribute arrays. Each item in the array
 *     corresponds to its own set of attributes, and therefore, needs its own
 *     element.
559
 *
560
561
 * @see rdf_process()
 * @ingroup themeable
562
 * @ingroup rdf
563
 */
564
565
566
function theme_rdf_metadata($variables) {
  $output = '';
  foreach ($variables['metadata'] as $attributes) {
567
568
569
    // Add a class so that developers viewing the HTML source can see why there
    // are empty <span> tags in the document. The class can also be used to set
    // a CSS display:none rule in a theme where empty spans affect display.
570
    $attributes['class'][] = 'rdf-meta';
571
572
573
574
    // The XHTML+RDFa doctype allows either <span></span> or <span /> syntax to
    // be used, but for maximum browser compatibility, W3C recommends the
    // former when serving pages using the text/html media type, see
    // http://www.w3.org/TR/xhtml1/#C_3.
575
    $output .= '<span' . new Attribute($attributes) . '></span>';
576
577
  }
  return $output;
578
}