Projet

Général

Profil

Révision b4adf10d

Ajouté par Assos Assos il y a plus de 9 ans

Udpate to 7.33

Voir les différences:

drupal7/modules/rdf/rdf.module
190 190
 *   An RDF mapping structure or an empty array if no record was found.
191 191
 */
192 192
function _rdf_mapping_load($type, $bundle) {
193
  $mapping = db_select('rdf_mapping')
194
    ->fields(NULL, array('mapping'))
193
  $mappings = _rdf_mapping_load_multiple($type, array($bundle));
194
  return $mappings ? reset($mappings) : array();
195
}
196

  
197
/**
198
 * Helper function to retrieve a set of RDF mappings from the database.
199
 *
200
 * @param $type
201
 *   The entity type of the mappings.
202
 * @param $bundles
203
 *   The bundles the mappings refer to.
204
 *
205
 * @return
206
 *   An array of RDF mapping structures, or an empty array.
207
 */
208
function _rdf_mapping_load_multiple($type, array $bundles) {
209
  $mappings = db_select('rdf_mapping')
210
    ->fields(NULL, array('bundle', 'mapping'))
195 211
    ->condition('type', $type)
196
    ->condition('bundle', $bundle)
212
    ->condition('bundle', $bundles)
197 213
    ->execute()
198
    ->fetchField();
214
    ->fetchAllKeyed();
199 215

  
200
  if (!$mapping) {
201
    return array();
216
  foreach ($mappings as $bundle => $mapping) {
217
    $mappings[$bundle] = unserialize($mapping);
202 218
  }
203
  return unserialize($mapping);
219
  return $mappings;
204 220
}
205 221

  
206 222
/**
......
368 384
function rdf_entity_info_alter(&$entity_info) {
369 385
  // Loop through each entity type and its bundles.
370 386
  foreach ($entity_info as $entity_type => $entity_type_info) {
371
    if (isset($entity_type_info['bundles'])) {
372
      foreach ($entity_type_info['bundles'] as $bundle => $bundle_info) {
373
        if ($mapping = _rdf_mapping_load($entity_type, $bundle)) {
374
          $entity_info[$entity_type]['bundles'][$bundle]['rdf_mapping'] = $mapping;
387
    if (!empty($entity_type_info['bundles'])) {
388
      $bundles = array_keys($entity_type_info['bundles']);
389
      $mappings = _rdf_mapping_load_multiple($entity_type, $bundles);
390

  
391
      foreach ($bundles as $bundle) {
392
        if (isset($mappings[$bundle])) {
393
          $entity_info[$entity_type]['bundles'][$bundle]['rdf_mapping'] = $mappings[$bundle];
375 394
        }
376 395
        else {
377 396
          // If no mapping was found in the database, assign the default RDF
......
471 490
  $variables['attributes_array']['about'] = empty($variables['node_url']) ? NULL: $variables['node_url'];
472 491
  $variables['attributes_array']['typeof'] = empty($variables['node']->rdf_mapping['rdftype']) ? NULL : $variables['node']->rdf_mapping['rdftype'];
473 492

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

  
481
  // In full node mode, the title is not displayed by node.tpl.php so it is
482
  // added in the <head> tag of the HTML page.
483
  if ($variables['page']) {
484
    $element = array(
485
      '#tag' => 'meta',
486
      '#attributes' => array(
487
        'content' => $variables['node']->title,
488
        'about' => $variables['node_url'],
493
  // Adds RDFa markup about the title of the node to the title_suffix.
494
  if (!empty($variables['node']->rdf_mapping['title']['predicates'])) {
495
    $variables['title_suffix']['rdf_meta_title'] = array(
496
      '#theme' => 'rdf_metadata',
497
      '#metadata' => array(
498
        array(
499
          'property' => $variables['node']->rdf_mapping['title']['predicates'],
500
          'content' => $variables['node']->title,
501
        ),
489 502
      ),
490 503
    );
491
    if (!empty($variables['node']->rdf_mapping['title']['predicates'])) {
492
      $element['#attributes']['property'] = $variables['node']->rdf_mapping['title']['predicates'];
493
    }
494
    drupal_add_html_head($element, 'rdf_node_title');
495 504
  }
496 505

  
497 506
  // Adds RDFa markup for the date.
......
511 520
  }
512 521

  
513 522
  // Adds RDFa markup annotating the number of comments a node has.
514
  if (isset($variables['node']->comment_count) && !empty($variables['node']->rdf_mapping['comment_count']['predicates'])) {
515
    // Annotates the 'x comments' link in teaser view.
516
    if (isset($variables['content']['links']['comment']['#links']['comment-comments'])) {
517
      $comment_count_attributes['property'] = $variables['node']->rdf_mapping['comment_count']['predicates'];
518
      $comment_count_attributes['content'] = $variables['node']->comment_count;
519
      $comment_count_attributes['datatype'] = $variables['node']->rdf_mapping['comment_count']['datatype'];
520
      // According to RDFa parsing rule number 4, a new subject URI is created
521
      // from the href attribute if no rel/rev attribute is present. To get the
522
      // original node URL from the about attribute of the parent container we
523
      // set an empty rel attribute which triggers rule number 5. See
524
      // http://www.w3.org/TR/rdfa-syntax/#sec_5.5.
525
      $comment_count_attributes['rel'] = '';
526
      $variables['content']['links']['comment']['#links']['comment-comments']['attributes'] += $comment_count_attributes;
527
    }
528
    // In full node view, the number of comments is not displayed by
529
    // node.tpl.php so it is expressed in RDFa in the <head> tag of the HTML
530
    // page.
531
    if ($variables['page'] && user_access('access comments')) {
532
      $element = array(
533
        '#tag' => 'meta',
534
        '#attributes' => array(
535
          'about' => $variables['node_url'],
523
  if (isset($variables['node']->comment_count) &&
524
      !empty($variables['node']->rdf_mapping['comment_count']['predicates']) &&
525
      user_access('access comments')) {
526
    // Adds RDFa markup for the comment count near the node title as metadata.
527
    $variables['title_suffix']['rdf_meta_comment_count'] = array(
528
      '#theme' => 'rdf_metadata',
529
      '#metadata' => array(
530
        array(
536 531
          'property' => $variables['node']->rdf_mapping['comment_count']['predicates'],
537 532
          'content' => $variables['node']->comment_count,
538 533
          'datatype' => $variables['node']->rdf_mapping['comment_count']['datatype'],
539 534
        ),
540
      );
541
      drupal_add_html_head($element, 'rdf_node_comment_count');
542
    }
535
      ),
536
    );
543 537
  }
544 538
}
545 539

  
......
865 859
  $output = '';
866 860
  foreach ($variables['metadata'] as $attributes) {
867 861
    // Add a class so that developers viewing the HTML source can see why there
868
    // are empty <span> tags in the document. The class can also be used to set
869
    // a CSS display:none rule in a theme where empty spans affect display.
862
    // are empty <span> tags in the document.
870 863
    $attributes['class'][] = 'rdf-meta';
864
    $attributes['class'][] = 'element-hidden';
871 865
    // The XHTML+RDFa doctype allows either <span></span> or <span /> syntax to
872 866
    // be used, but for maximum browser compatibility, W3C recommends the
873 867
    // former when serving pages using the text/html media type, see

Formats disponibles : Unified diff