123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872 |
- <?php
- function rdf_help($path, $arg) {
- switch ($path) {
- case 'admin/help#rdf':
- $output = '';
- $output .= '<h3>' . t('About') . '</h3>';
- $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 online handbook entry for <a href="@rdf">RDF module</a>.', array('@rdfa' => 'http://www.w3.org/TR/xhtml-rdfa-primer/', '@rdf' => 'http://drupal.org/documentation/modules/rdf')) . '</p>';
- return $output;
- }
- }
- define('RDF_DEFAULT_BUNDLE', '');
- 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/',
- 'og' => 'http://ogp.me/ns#',
- 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
- '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#',
- );
- }
- function rdf_get_namespaces() {
- $rdf_namespaces = module_invoke_all('rdf_namespaces');
-
-
-
-
- foreach ($rdf_namespaces as $prefix => $uri) {
- if (is_array($uri)) {
- if (count(array_unique($uri)) == 1) {
-
-
- $rdf_namespaces[$prefix] = $uri[0];
- }
- else {
-
-
-
- unset($rdf_namespaces[$prefix]);
- }
- }
- }
- return $rdf_namespaces;
- }
- function rdf_mapping_load($type, $bundle = RDF_DEFAULT_BUNDLE) {
-
- $entity_info = entity_get_info($type);
- if (!empty($entity_info['bundles'][$bundle]['rdf_mapping'])) {
- return $entity_info['bundles'][$bundle]['rdf_mapping'];
- }
-
-
- else {
- return _rdf_get_default_mapping($type);
- }
- }
- function _rdf_get_default_mapping($type) {
- $default_mappings = &drupal_static(__FUNCTION__);
- if (!isset($default_mappings)) {
-
- $modules = module_implements('rdf_mapping');
-
- foreach ($modules as $module) {
- $mappings = module_invoke($module, 'rdf_mapping');
- foreach ($mappings as $mapping) {
- if ($mapping['bundle'] === RDF_DEFAULT_BUNDLE) {
- $default_mappings[$mapping['type']] = $mapping['mapping'];
- }
- }
- }
- }
- return isset($default_mappings[$type]) ? $default_mappings[$type] : array();
- }
- function _rdf_mapping_load($type, $bundle) {
- $mappings = _rdf_mapping_load_multiple($type, array($bundle));
- return $mappings ? reset($mappings) : array();
- }
- function _rdf_mapping_load_multiple($type, array $bundles) {
- $mappings = db_select('rdf_mapping')
- ->fields(NULL, array('bundle', 'mapping'))
- ->condition('type', $type)
- ->condition('bundle', $bundles)
- ->execute()
- ->fetchAllKeyed();
- foreach ($mappings as $bundle => $mapping) {
- $mappings[$bundle] = unserialize($mapping);
- }
- return $mappings;
- }
- function rdf_mapping_save($mapping) {
-
-
-
- $mapping['mapping'] += _rdf_get_default_mapping($mapping['type']);
- $status = db_merge('rdf_mapping')
- ->key(array(
- 'type' => $mapping['type'],
- 'bundle' => $mapping['bundle'],
- ))
- ->fields(array(
- 'mapping' => serialize($mapping['mapping']),
- ))
- ->execute();
- entity_info_cache_clear();
- return $status;
- }
- function rdf_mapping_delete($type, $bundle) {
- $num_rows = db_delete('rdf_mapping')
- ->condition('type', $type)
- ->condition('bundle', $bundle)
- ->execute();
- return (bool) ($num_rows > 0);
- }
- function rdf_rdfa_attributes($mapping, $data = NULL) {
-
- $type = isset($mapping['type']) ? $mapping['type'] : 'property';
- switch ($type) {
-
- case 'rel':
- case 'rev':
- $attributes[$type] = $mapping['predicates'];
- break;
-
-
- case 'property':
- $attributes['property'] = $mapping['predicates'];
-
- if (isset($data) && isset($mapping['callback']) && function_exists($mapping['callback'])) {
- $callback = $mapping['callback'];
- $attributes['content'] = $callback($data);
- }
- if (isset($mapping['datatype'])) {
- $attributes['datatype'] = $mapping['datatype'];
- }
- break;
- }
- return $attributes;
- }
- function rdf_modules_installed($modules) {
- foreach ($modules as $module) {
- $function = $module . '_rdf_mapping';
- if (function_exists($function)) {
- foreach ($function() as $mapping) {
-
- if ($mapping['bundle'] !== RDF_DEFAULT_BUNDLE) {
- rdf_mapping_save($mapping);
- }
- }
- }
- }
- }
- function rdf_modules_uninstalled($modules) {
-
- }
- function rdf_entity_info_alter(&$entity_info) {
-
- foreach ($entity_info as $entity_type => $entity_type_info) {
- if (!empty($entity_type_info['bundles'])) {
- $bundles = array_keys($entity_type_info['bundles']);
- $mappings = _rdf_mapping_load_multiple($entity_type, $bundles);
- foreach ($bundles as $bundle) {
- if (isset($mappings[$bundle])) {
- $entity_info[$entity_type]['bundles'][$bundle]['rdf_mapping'] = $mappings[$bundle];
- }
- else {
-
-
- $entity_info[$entity_type]['bundles'][$bundle]['rdf_mapping'] = _rdf_get_default_mapping($entity_type);
- }
- }
- }
- }
- }
- function rdf_entity_load($entities, $type) {
- foreach ($entities as $entity) {
-
- list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
- $entity->rdf_mapping = rdf_mapping_load($type, $bundle);
- }
- }
- function rdf_comment_load($comments) {
- foreach ($comments as $comment) {
-
-
-
- $comment->rdf_data['date'] = rdf_rdfa_attributes($comment->rdf_mapping['created'], $comment->created);
- $comment->rdf_data['nid_uri'] = url('node/' . $comment->nid);
- if ($comment->pid) {
- $comment->rdf_data['pid_uri'] = url('comment/' . $comment->pid, array('fragment' => 'comment-' . $comment->pid));
- }
- }
- }
- function rdf_theme() {
- return array(
- 'rdf_template_variable_wrapper' => array(
- 'variables' => array('content' => NULL, 'attributes' => array(), 'context' => array(), 'inline' => TRUE),
- ),
- 'rdf_metadata' => array(
- 'variables' => array('metadata' => array()),
- ),
- );
- }
- function rdf_process(&$variables, $hook) {
-
-
-
-
- if (!empty($variables['rdf_template_variable_attributes_array'])) {
- foreach ($variables['rdf_template_variable_attributes_array'] as $variable_name => $attributes) {
- $context = array(
- 'hook' => $hook,
- 'variable_name' => $variable_name,
- 'variables' => $variables,
- );
- $variables[$variable_name] = theme('rdf_template_variable_wrapper', array('content' => $variables[$variable_name], 'attributes' => $attributes, 'context' => $context));
- }
- }
-
-
-
-
- if (!empty($variables['rdf_metadata_attributes_array'])) {
- if (!isset($variables['content']['#prefix'])) {
- $variables['content']['#prefix'] = '';
- }
- $variables['content']['#prefix'] = theme('rdf_metadata', array('metadata' => $variables['rdf_metadata_attributes_array'])) . $variables['content']['#prefix'];
- }
- }
- function rdf_preprocess_node(&$variables) {
-
-
-
-
- $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'];
-
- if (!empty($variables['node']->rdf_mapping['title']['predicates'])) {
- $variables['title_suffix']['rdf_meta_title'] = array(
- '#theme' => 'rdf_metadata',
- '#metadata' => array(
- array(
- 'property' => $variables['node']->rdf_mapping['title']['predicates'],
- 'content' => $variables['node']->title,
- ),
- ),
- );
- }
-
- 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;
- }
- }
-
- 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'];
- }
- }
-
- if (isset($variables['node']->comment_count) &&
- !empty($variables['node']->rdf_mapping['comment_count']['predicates']) &&
- user_access('access comments')) {
-
- $variables['title_suffix']['rdf_meta_comment_count'] = array(
- '#theme' => 'rdf_metadata',
- '#metadata' => array(
- array(
- 'property' => $variables['node']->rdf_mapping['comment_count']['predicates'],
- 'content' => $variables['node']->comment_count,
- 'datatype' => $variables['node']->rdf_mapping['comment_count']['datatype'],
- ),
- ),
- );
- }
- }
- function rdf_preprocess_field(&$variables) {
- $element = $variables['element'];
- $mapping = rdf_mapping_load($element['#entity_type'], $element['#bundle']);
- $field_name = $element['#field_name'];
- if (!empty($mapping) && !empty($mapping[$field_name])) {
- foreach ($element['#items'] as $delta => $item) {
- $variables['item_attributes_array'][$delta] = rdf_rdfa_attributes($mapping[$field_name], $item);
-
-
-
-
-
- if (isset($item['uri'])) {
- if (!empty($element[$delta]['#image_style'])) {
- $variables['item_attributes_array'][$delta]['resource'] = image_style_url($element[$delta]['#image_style'], $item['uri']);
- }
- else {
- $variables['item_attributes_array'][$delta]['resource'] = file_create_url($item['uri']);
- }
- }
- }
- }
- }
- function rdf_preprocess_user_profile(&$variables) {
- $account = $variables['elements']['#account'];
- $uri = entity_uri('user', $account);
-
-
- if (!empty($account->rdf_mapping['rdftype'])) {
- $variables['attributes_array']['typeof'] = $account->rdf_mapping['rdftype'];
- $variables['attributes_array']['about'] = url($uri['path'], $uri['options']);
- }
-
-
- $account_holder_meta = array(
- '#tag' => 'meta',
- '#attributes' => array(
- 'about' => url($uri['path'], array_merge($uri['options'], array('fragment' => 'me'))),
- 'typeof' => array('foaf:Person'),
- 'rel' => array('foaf:account'),
- 'resource' => url($uri['path'], $uri['options']),
- ),
- );
-
- $username_meta = array(
- '#tag' => 'meta',
- '#attributes' => array(
- 'about' => url($uri['path'], $uri['options']),
- 'property' => $account->rdf_mapping['name']['predicates'],
- 'content' => $account->name,
- )
- );
- drupal_add_html_head($account_holder_meta, 'rdf_user_account_holder');
- drupal_add_html_head($username_meta, 'rdf_user_username');
- }
- function rdf_preprocess_username(&$variables) {
-
-
-
-
-
- if (empty($variables['attributes_array']['xml:lang'])) {
- $variables['attributes_array']['xml:lang'] = '';
- }
-
-
-
-
-
-
- $rdf_mapping = rdf_mapping_load('user', 'user');
-
-
-
-
-
-
-
- if ($variables['uid'] > 0) {
- $variables['attributes_array']['about'] = url('user/' . $variables['uid']);
- }
- $attributes = array();
-
-
- if (!empty($rdf_mapping['rdftype'])) {
- $attributes['typeof'] = $rdf_mapping['rdftype'];
- }
-
-
-
- if (!empty($rdf_mapping['name'])) {
- $attributes['property'] = $rdf_mapping['name']['predicates'];
- $attributes['datatype'] = '';
- }
-
- if (!empty($variables['homepage']) && !empty($rdf_mapping['homepage'])) {
- $attributes['rel'] = $rdf_mapping['homepage']['predicates'];
- }
-
-
-
-
-
- $variables['attributes_array'] = array_merge_recursive($variables['attributes_array'], $attributes);
- }
- function rdf_preprocess_comment(&$variables) {
- $comment = $variables['comment'];
- if (!empty($comment->rdf_mapping['rdftype'])) {
-
-
-
-
- $uri = entity_uri('comment', $comment);
- $variables['attributes_array']['about'] = url($uri['path'], $uri['options']);
- $variables['attributes_array']['typeof'] = $comment->rdf_mapping['rdftype'];
- }
-
- if (!empty($comment->rdf_mapping['created'])) {
-
-
- $date_attributes_array = $comment->rdf_data['date'];
- $variables['rdf_template_variable_attributes_array']['created'] = $date_attributes_array;
- $variables['rdf_template_variable_attributes_array']['submitted'] = $date_attributes_array;
- }
-
- if (!empty($comment->rdf_mapping['uid'])) {
- $variables['rdf_template_variable_attributes_array']['author']['rel'] = $comment->rdf_mapping['uid']['predicates'];
- $variables['rdf_template_variable_attributes_array']['submitted']['rel'] = $comment->rdf_mapping['uid']['predicates'];
- }
- if (!empty($comment->rdf_mapping['title'])) {
-
-
-
-
- $variables['title_attributes_array']['property'] = $comment->rdf_mapping['title']['predicates'];
- $variables['title_attributes_array']['datatype'] = '';
- }
-
-
- if (!empty($comment->rdf_mapping['pid'])) {
-
- $parent_node_attributes['rel'] = $comment->rdf_mapping['pid']['predicates'];
-
-
- $parent_node_attributes['resource'] = $comment->rdf_data['nid_uri'];
- $variables['rdf_metadata_attributes_array'][] = $parent_node_attributes;
-
- if ($comment->pid != 0) {
- $parent_comment_attributes['rel'] = $comment->rdf_mapping['pid']['predicates'];
-
-
- $parent_comment_attributes['resource'] = $comment->rdf_data['pid_uri'];
- $variables['rdf_metadata_attributes_array'][] = $parent_comment_attributes;
- }
- }
- }
- function rdf_preprocess_taxonomy_term(&$variables) {
-
- $term = $variables['term'];
- $term_label_meta = array(
- '#tag' => 'meta',
- '#attributes' => array(
- 'about' => url('taxonomy/term/' . $term->tid),
- 'typeof' => $term->rdf_mapping['rdftype'],
- 'property' => $term->rdf_mapping['name']['predicates'],
- 'content' => $term->name,
- ),
- );
- drupal_add_html_head($term_label_meta, 'rdf_term_label');
- }
- function rdf_field_attach_view_alter(&$output, $context) {
-
- foreach (element_children($output) as $field_name) {
- $element = &$output[$field_name];
- if ($element['#field_type'] == 'taxonomy_term_reference' && $element['#formatter'] == 'taxonomy_term_reference_link') {
- foreach ($element['#items'] as $delta => $item) {
-
-
-
- if (isset($item['taxonomy_term'])) {
- $term = $item['taxonomy_term'];
- if (!empty($term->rdf_mapping['rdftype'])) {
- $element[$delta]['#options']['attributes']['typeof'] = $term->rdf_mapping['rdftype'];
- }
- if (!empty($term->rdf_mapping['name']['predicates'])) {
-
-
- $element[$delta]['#options']['attributes']['property'] = $term->rdf_mapping['name']['predicates'];
- $element[$delta]['#options']['attributes']['datatype'] = '';
- }
- }
- }
- }
- }
- }
- function rdf_preprocess_image(&$variables) {
-
-
-
- $variables['attributes']['typeof'] = array('foaf:Image');
- }
- function theme_rdf_template_variable_wrapper($variables) {
- $output = $variables['content'];
- if (!empty($output) && !empty($variables['attributes'])) {
- $attributes = drupal_attributes($variables['attributes']);
- $output = $variables['inline'] ? "<span$attributes>$output</span>" : "<div$attributes>$output</div>";
- }
- return $output;
- }
- function theme_rdf_metadata($variables) {
- $output = '';
- foreach ($variables['metadata'] as $attributes) {
-
-
- $attributes['class'][] = 'rdf-meta';
- $attributes['class'][] = 'element-hidden';
-
-
-
-
- $output .= '<span' . drupal_attributes($attributes) . '></span>';
- }
- return $output;
- }
|