rdf_preprocess_username

Versions
7
rdf_preprocess_username(&$variables)

Implements MODULE_preprocess_HOOK().

Code

modules/rdf/rdf.module, line 455

<?php
function rdf_preprocess_username(&$variables) {
  // $variables['account'] is a pseudo account object, and as such, does not
  // contain the rdf mappings for the user; in the case of nodes and comments,
  // it contains the mappings for the node or comment object instead. Therefore,
  // the real account object for the user is needed. The real account object is
  // needed for this function only; it should not replace $variables['account'].
  if ($account = user_load($variables['uid'])) {
    // An RDF resource for the user is created with the 'about' attribute and
    // the profile URI is used to identify this resource. Even if the user
    // profile is not accessible, we generate its URI regardless in order to
    // be able 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 profile in RDF).
    if ($account->uid > 0) {
      $variables['attributes_array']['about'] = url('user/' . $account->uid);
    }

    // The remaining attributes are defined by RDFa as lists
    // (http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes). Therefore, merge
    // rather than override, so as not to clobber values set by earlier
    // preprocess functions.
    $attributes = array();

    // The 'typeof' attribute specifies the RDF type(s) of this resource. They
    // are defined in the 'rdftype' property of the user object RDF mapping.
    if (!empty($account->rdf_mapping['rdftype'])) {
      $attributes['typeof'] = $account->rdf_mapping['rdftype'];
    }

    // Annotate the user name in RDFa. The attribute 'property' is used here
    // because the user name is a literal.
    if (!empty($account->rdf_mapping['name'])) {
      $attributes['property'] = $account->rdf_mapping['name']['predicates'];
    }

    // Add the homepage RDFa markup if present.
    if (!empty($variables['homepage']) && !empty($account->rdf_mapping['homepage'])) {
      $attributes['rel'] = $account->rdf_mapping['homepage']['predicates'];
    }

    $variables['attributes_array'] = array_merge_recursive($variables['attributes_array'], $attributes);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.