View source
<?php
module_load_include('inc', 'microdata', 'includes/microdata.form_alter');
define('MICRODATA_DEFAULT_BUNDLE', '');
function microdata_help($path, $arg) {
switch ($path) {
case 'admin/help#microdata':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t("The Microdata module makes it easy to share content between sites and with services like Google's Recipe View.", array(
'@recipe' => 'http://www.google.com/landing/recipes/',
)) . '</p>';
$output .= '<h3>' . t('Microdata concepts') . '</h3>';
$output .= '<p>' . t('Microdata is a small set of attributes for HTML that can be used to add more information about the content. These attributes\' values often use a predefined set of terms. These groups of terms are called vocabularies and can be defined on the Web. For example, <a href="http://schema.org">schema.org</a> defines a vocabulary that will be used by search engines to present better search results.') . '</p>';
$output .= '<h4>itemtype</h4>';
$output .= '<h4>itemprop</h4>';
$output .= '<p>' . t("Short names (such as 'location') can be used for properties defined by the content type's itemtype. Full URLs (such as 'http://schema.org/location') should be used for properties that are defined by other vocabularies.") . '</p>';
return $output;
}
}
function microdata_hook_info() {
$hooks['microdata_suggestions'] = array(
'group' => 'microdata',
);
return $hooks;
}
function microdata_menu() {
$config_base = array(
'access arguments' => array(
'administer microdata',
),
'file' => 'microdata.admin.inc',
);
$autocomplete_base = array(
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'microdata.pages.inc',
);
$items['admin/config/services/microdata'] = array(
'title' => 'Microdata settings',
'description' => 'Configure how site content gets published in Microdata.',
'page callback' => 'microdata_mapping_overview',
) + $config_base;
$items['admin/config/services/microdata/mappings'] = array(
'title' => 'Mappings',
'description' => 'Configure microdata mappings for bundles.',
'page callback' => 'microdata_mapping_overview',
'type' => MENU_DEFAULT_LOCAL_TASK,
) + $config_base;
$items['admin/config/services/microdata/vocabularies'] = array(
'title' => 'Vocabularies',
'description' => 'Configure vocabularies to use in autocomplete dropdown.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'microdata_vocabulary_settings',
),
'type' => MENU_LOCAL_TASK,
) + $config_base;
$items['admin/config/services/microdata/mappings/manage/%/%/%ctools_js'] = array(
'title' => 'Edit microdata mapping',
'description' => 'Configure the microdata mapping for a bundle and its fields.',
'page callback' => 'microdata_ajax_bundle_mapping',
'page arguments' => array(
6,
7,
8,
),
) + $config_base;
$items['microdata_autocomplete/itemtype'] = array(
'title' => 'Itemtype autocomplete',
'description' => 'Vocabulary autocomplete for itemtypes.',
'page callback' => 'microdata_autocomplete_itemtype',
) + $autocomplete_base;
$items['microdata_autocomplete/itemprop/%'] = array(
'title' => 'Itemprop autocomplete',
'description' => 'Vocabulary autocomplete for itemprops.',
'page callback' => 'microdata_autocomplete_itemprop',
'page arguments' => array(
2,
3,
),
) + $autocomplete_base;
return $items;
}
function microdata_microdata_vocabulary_info() {
return array(
'schema_org' => array(
'label' => 'Schema.org',
'description' => t("Google, Bing, and Yahoo! supported terms for Rich Snippets, documented at !link.", array(
'!link' => l('Schema.org', 'http://schema.org'),
)),
'import_url' => 'http://schema.rdfs.org/all.json',
),
'google_schema_org_extensions' => array(
'label' => 'Google Schema.org Extensions',
'description' => t("Google's custom extensions to Schema.org, such as SoftwareApplication. These are not well documented.", array(
'!link' => l('http://schema.org', 'Schema.org'),
)),
'import_url' => 'http://lin-clark.com/api/vocbaulary/google-schemaorg',
),
);
}
function microdata_permission() {
return array(
'administer microdata' => array(
'title' => t('Administer microdata'),
'description' => t('Configure and setup microdata module.'),
),
);
}
function microdata_theme() {
return array(
'microdata_item_meta_tags' => array(
'variables' => array(
'items' => array(),
),
),
'microdata_mapping_admin' => array(
'variables' => array(
'bundle' => array(),
'itemtype' => array(),
'field_mappings' => array(),
'edit_path' => '',
),
),
'microdata_mapping_admin_overview_row' => array(
'variables' => array(
'field' => array(),
'field_name' => '',
),
),
);
}
function microdata_theme_registry_alter(&$theme_registry) {
$rdf_preprocess_hooks = array(
'node',
'field',
'user_profile',
'username',
'comment',
'taxonomy_term',
'image',
);
foreach ($rdf_preprocess_hooks as $hook) {
if (isset($theme_registry[$hook]) && isset($theme_registry[$hook]['preprocess functions'])) {
$key = array_search('rdf_preprocess_' . $hook, $theme_registry[$hook]['preprocess functions']);
if (!empty($key)) {
unset($theme_registry[$hook]['preprocess functions'][$key]);
}
}
}
}
function microdata_field_info_alter(&$info) {
$info['image']['microdata'] = TRUE;
$info['list_integer']['microdata'] = TRUE;
$info['list_float']['microdata'] = TRUE;
$info['list_text']['microdata'] = TRUE;
$info['list_boolean']['microdata'] = TRUE;
$info['number_integer']['microdata'] = TRUE;
$info['number_decimal']['microdata'] = TRUE;
$info['number_float']['microdata'] = TRUE;
$info['taxonomy_term_reference']['microdata'] = TRUE;
$info['text']['microdata'] = TRUE;
$info['text_long']['microdata'] = TRUE;
$info['text_with_summary']['microdata'] = TRUE;
}
function microdata_entity_info_alter(&$entity_info) {
foreach ($entity_info as $entity_type => $entity_type_info) {
if (isset($entity_type_info['bundles'])) {
foreach ($entity_type_info['bundles'] as $bundle => $bundle_info) {
$entity_info[$entity_type]['bundles'][$bundle]['microdata_mapping'] = _microdata_load_mapping($entity_type, $bundle);
}
}
}
drupal_static_reset('microdata_get_mapping');
foreach (language_list() as $language) {
cache_clear_all('microdata_get_mapping:' . $language->language, 'cache');
}
}
function microdata_entity_property_info_alter(&$info) {
$field_info_fields = field_info_fields();
$field_types = field_info_field_types();
foreach ($info as $entity_type => &$entity_info) {
if (isset($entity_info['bundles'])) {
foreach ($entity_info['bundles'] as $bundle_name => &$bundle_info) {
if (!empty($bundle_info['properties'])) {
foreach ($bundle_info['properties'] as $field_name => &$field_info) {
if (!empty($field_info_fields[$field_name]['type'])) {
$field_type = $field_info_fields[$field_name]['type'];
if (!empty($field_types[$field_type]['microdata'])) {
$field_info['microdata'] = TRUE;
}
}
if ($field_info['type'] == 'text_formatted') {
$field_info['property info']['value']['microdata'] = TRUE;
if (isset($field_info['property info']['summary'])) {
$field_info['property info']['summary']['microdata'] = TRUE;
}
}
}
}
}
}
}
}
function microdata_entity_load($entities, $type) {
foreach ($entities as $entity) {
list($id, $vid, $bundle_type) = entity_extract_ids($type, $entity);
$microdata_mapping = microdata_get_mapping($type, $bundle_type);
$entity->microdata = microdata_mapping_to_attributes($microdata_mapping, $type, $entity);
}
}
function microdata_field_attach_view_alter(&$output, $context) {
foreach (element_children($output) as $field_name) {
$element =& $output[$field_name];
if (!field_info_field($field_name)) {
continue;
}
if (!isset($element['#object']->microdata)) {
continue;
}
$subject_entity = $element['#object'];
$subject_entity_type = $element['#entity_type'];
$subject_bundle_type = $element['#bundle'];
$subject_entity_is_item = isset($subject_entity->microdata['#attributes']['itemid']);
$subject_itemrefs = array();
$entity_properties = entity_get_property_info($subject_entity_type);
$bundle_properties = $entity_properties['bundles'][$subject_bundle_type]['properties'];
if (!isset($bundle_properties[$field_name]) || !isset($subject_entity->microdata[$field_name])) {
continue;
}
$field_microdata = $subject_entity->microdata[$field_name];
if (empty($field_microdata['#attributes']['itemprop'])) {
continue;
}
$type = _microdata_get_field_type($bundle_properties[$field_name]['type']);
if (microdata_get_value_type($type) == 'item_reference') {
$object_entity_type = $type;
$wrapper = entity_metadata_wrapper($subject_entity_type, $subject_entity);
$object_entities = $wrapper->{$field_name}
->value();
if (isset($object_entities)) {
if (is_object($object_entities)) {
$object_entities = array(
$object_entities,
);
}
foreach ($object_entities as $delta => $object_entity) {
if (!empty($object_entity->microdata['#attributes']['itemid'])) {
$field_id = microdata_get_itemref_id();
$element[$delta]['#microdata_field_id'] = $field_id;
$object_attributes = $object_entity->microdata['#attributes'];
if ($subject_entity_is_item) {
$object_id = microdata_get_itemref_id();
$object_attributes['id'][] = $object_id;
$subject_itemrefs[] = $object_id;
}
if (isset($field_microdata['#attributes']['itemprop'])) {
$object_attributes['itemprop'] = $field_microdata['#attributes']['itemprop'];
}
$object_attributes['itemref'][] = $field_id;
list($entity_id, , ) = entity_extract_ids($object_entity_type, $object_entity);
microdata_item($object_entity_type, $entity_id, $object_attributes);
}
elseif ($subject_entity_is_item) {
$field_id = microdata_get_itemref_id();
$element[$delta]['#microdata_field_id'] = $field_id;
$subject_itemrefs[] = $field_id;
}
if ($element['#field_type'] == 'taxonomy_term_reference') {
if (!empty($object_entity->microdata['title']['#attributes'])) {
$element[$delta]['#attributes'] = $object_entity->microdata['url']['#attributes'];
$text_attributes = drupal_attributes($object_entity->microdata['title']['#attributes']);
$element[$delta]['#prefix'] = "<span {$text_attributes}>";
$element[$delta]['#suffix'] = '</span>';
}
}
}
}
}
elseif ($subject_entity_is_item) {
$field_id = microdata_get_itemref_id();
$element['#microdata_field_id'] = $field_id;
$subject_itemrefs[] = $field_id;
}
if ($subject_entity_is_item) {
$attributes = $subject_entity->microdata['#attributes'];
$attributes['itemref'] = $subject_itemrefs;
list($entity_id, , ) = entity_extract_ids($subject_entity_type, $subject_entity);
microdata_item($subject_entity_type, $entity_id, $attributes);
}
}
}
function microdata_preprocess_field(&$variables) {
if (isset($variables['element']['#object']->in_preview)) {
return;
}
$element = $variables['element'];
$field_name = $element['#field_name'];
$mapping = microdata_get_mapping($element['#entity_type'], $element['#bundle']);
if (!isset($mapping[$field_name]) || empty($mapping[$field_name]['#value_type']) || !isset($element['#formatter']) || empty($element['#object']->microdata)) {
return;
}
$field_mapping = $mapping[$field_name];
$microdata = $element['#object']->microdata;
if (isset($element['#microdata_field_id'])) {
$variables['content_attributes_array']['id'] = $element['#microdata_field_id'];
}
foreach ($variables['items'] as $delta => &$item) {
if (isset($field_mapping['#value_type'])) {
$is_datetime = $field_mapping['#value_type'] === 'datetime' ? TRUE : FALSE;
$is_url = $field_mapping['#value_type'] === 'url' ? TRUE : FALSE;
$is_item_reference = $field_mapping['#value_type'] === 'item_reference' ? microdata_is_item($element['#entity_type'], $element['#object'], $field_name, $delta) : FALSE;
$place_microdata_wrapper = !($is_datetime || $is_url || $is_item_reference);
}
else {
$place_microdata_wrapper = TRUE;
}
if ($place_microdata_wrapper) {
$attributes = isset($variables['item_attributes_array'][$delta]) ? $variables['item_attributes_array'][$delta] : array();
if (isset($microdata[$field_name]['#attributes'])) {
$variables['item_attributes_array'][$delta] = array_merge($attributes, $microdata[$field_name]['#attributes']);
}
else {
$variables['item_attributes_array'][$delta] = $attributes;
}
}
if (isset($item['#microdata_field_id'])) {
$variables['item_attributes_array'][$delta]['id'] = $item['#microdata_field_id'];
}
switch ($element['#formatter']) {
case 'image':
$item['#item']['attributes']['itemprop'] = $field_mapping['#itemprop'];
break;
case 'text_default':
if ($field_mapping['#value_type'] != 'text') {
$attributes = isset($variables['item_attributes_array'][$delta]) ? $variables['item_attributes_array'][$delta] : array();
$variables['item_attributes_array'][$delta] = array_merge($attributes, $microdata[$field_name]['value']['#attributes']);
}
break;
case 'text_trimmed':
case 'text_summary_or_trimmed':
$attributes = isset($variables['item_attributes_array'][$delta]) ? $variables['item_attributes_array'][$delta] : array();
if (is_array($microdata[$field_name]['#attributes']) && isset($microdata[$field_name]['summary']['#attributes'])) {
$variables['item_attributes_array'][$delta] = array_merge($attributes, $microdata[$field_name]['summary']['#attributes']);
}
break;
}
}
}
function microdata_process_page(&$variables) {
_microdata_process_page($variables);
}
function microdata_process_panels_everywhere_page(&$variables) {
_microdata_process_page($variables);
}
function _microdata_process_page(&$variables) {
$page =& $variables['page'];
$items = microdata_item();
$titles = array();
$schema_urls = array();
foreach ($items as $entity_type => &$ids) {
foreach ($ids as $id => &$attributes) {
$entity = entity_load_single($entity_type, $id);
if (!empty($entity->microdata['title']) && !empty($entity->microdata['title']['#attributes'])) {
$title = isset($entity->title) ? $entity->title : $entity->name;
$field_id = microdata_get_itemref_id();
$entity->microdata['title']['#attributes']['content'] = $title;
$entity->microdata['title']['#attributes']['id'] = $field_id;
$titles[$entity_type][] = array(
'#attributes' => $entity->microdata['title']['#attributes'],
);
$attributes['#attributes']['itemref'][] = $field_id;
}
if (!empty($entity->microdata['microdata_schema_url'])) {
$field_id = microdata_get_itemref_id();
$entity->microdata['microdata_schema_url']['#attributes']['id'] = $field_id;
$schema_urls[$entity_type][] = array(
'#attributes' => $entity->microdata['microdata_schema_url']['#attributes'],
);
$attributes['#attributes']['itemref'][] = $field_id;
}
}
}
$page['content']['microdata_items']['items'] = array(
'#type' => 'markup',
'#markup' => theme('microdata_item_meta_tags', array(
'items' => $items,
'html_tag' => 'span',
)),
);
$page['content']['microdata_items']['titles'] = array(
'#type' => 'markup',
'#markup' => theme('microdata_item_meta_tags', array(
'items' => $titles,
'html_tag' => 'meta',
)),
);
$page['content']['microdata_items']['schema_urls'] = array(
'#type' => 'markup',
'#markup' => theme('microdata_item_meta_tags', array(
'items' => $schema_urls,
'html_tag' => 'link',
)),
);
}
function theme_microdata_item_meta_tags($variables) {
$output = '';
$item_array = $variables['items'];
$tag = $variables['html_tag'];
$void_elements = array(
'area',
'base',
'br',
'col',
'command',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'meta',
'param',
'source',
'track',
'wbr',
);
foreach ($item_array as $entity_type => $items) {
foreach ($items as $id => $item) {
switch ($tag) {
case 'meta':
case 'link':
$element = array(
'#tag' => $tag,
'#attributes' => $item['#attributes'],
);
drupal_add_html_head($element, 'microdata:' . $tag . ':' . $entity_type . ':' . $id);
break;
default:
$output .= "<{$tag}" . drupal_attributes($item['#attributes']) . " >";
if (!in_array($tag, $void_elements)) {
$output .= "</{$tag}>";
}
}
}
}
return $output;
}
function microdata_get_mapping($entity_type, $bundle_type) {
global $language;
$mappings =& drupal_static(__FUNCTION__);
$langcode = $language->language;
if (!isset($mappings[$entity_type][$bundle_type])) {
if ($cache = cache_get("microdata_get_mapping:{$langcode}")) {
$mappings = $cache->data;
}
if (!isset($mappings[$entity_type][$bundle_type])) {
$entity_info = entity_get_info($entity_type);
$mappings[$entity_type][$bundle_type] = array();
if (!empty($entity_info['bundles'][$bundle_type]['microdata_mapping'])) {
$mappings[$entity_type][$bundle_type] = $entity_info['bundles'][$bundle_type]['microdata_mapping'];
}
_microdata_prepare_mapping($mappings[$entity_type][$bundle_type], $entity_type, $bundle_type);
cache_set("microdata_get_mapping:{$langcode}", $mappings);
}
}
return $mappings[$entity_type][$bundle_type];
}
function microdata_save_mapping($entity_type, $bundle, $mapping) {
$status = db_merge('microdata_mapping')
->key(array(
'type' => $entity_type,
'bundle' => $bundle,
))
->fields(array(
'mapping' => serialize($mapping),
))
->execute();
if (module_exists('rdf')) {
}
entity_info_cache_clear();
return $status;
}
function microdata_item($item_type = NULL, $item_id = NULL, $input_attributes = array()) {
static $microdata_item;
if (empty($microdata_item)) {
$microdata_item = array();
}
if (empty($item_type)) {
foreach ($microdata_item as $entity_type => &$items) {
foreach ($items as &$item) {
foreach ($item as &$attributes) {
foreach ($attributes as &$attribute) {
if (is_array($attribute)) {
$attribute = array_unique($attribute);
}
}
}
}
}
return $microdata_item;
}
if (!isset($microdata_item[$item_type][$item_id]['#attributes'])) {
$microdata_item[$item_type][$item_id]['#attributes'] = array();
}
$attributes =& $microdata_item[$item_type][$item_id]['#attributes'];
$attributes = array_merge_recursive($attributes, $input_attributes);
}
function microdata_get_itemref_id() {
static $itemref_id_incrementer;
if (!isset($itemref_id_incrementer)) {
$itemref_id_incrementer = 0;
}
$itemref_id_incrementer++;
return 'md' . $itemref_id_incrementer;
}
function microdata_get_vocabulary_info() {
$vocabularies = array();
foreach (module_implements('microdata_vocabulary_info') as $module) {
$vocabularies = array_merge($vocabularies, call_user_func($module . '_microdata_vocabulary_info'));
}
return $vocabularies;
}
function microdata_get_enabled_vocabularies() {
return variable_get('microdata_enabled_vocabularies');
}
function microdata_enabled($info) {
if (!empty($info['microdata'])) {
return TRUE;
}
return FALSE;
}
function microdata_get_value_type($type = 'no_type') {
$microdata_value_types =& drupal_static(__FUNCTION__);
$type = _microdata_get_field_type($type);
if (!isset($microdata_value_types)) {
$microdata_value_types = array(
'text' => 'text',
'integer' => 'text',
'decimal' => 'text',
'uri' => 'url',
'field_item_image' => 'url',
'date' => 'datetime',
'field_item_textsummary' => 'text',
'text_formatted' => 'text',
);
foreach (array_keys(entity_get_info()) as $entity_type) {
$microdata_value_types[$entity_type] = 'item_reference';
}
drupal_alter('microdata_value_types', $microdata_value_types);
}
$type = isset($microdata_value_types[$type]) ? $microdata_value_types[$type] : NULL;
return $type;
}
function microdata_mapping_to_attributes($mapping, $entity_type = NULL, $entity = NULL) {
if (is_string($mapping)) {
return $mapping;
}
if (isset($mapping['#is_item'])) {
if ($mapping['#is_item'] === TRUE) {
$mapping['#value_type'] = 'item';
}
else {
$mapping['#value_type'] = 'struct';
}
}
$return['#attributes'] = array();
if (!empty($mapping['#itemprop'])) {
$return['#attributes']['itemprop'] = $mapping['#itemprop'];
}
if (isset($mapping['#value_type']) && $mapping['#value_type'] === 'item') {
$return['#attributes']['itemscope'] = '';
if (!empty($mapping['#itemtype'])) {
$return['#attributes']['itemtype'] = $mapping['#itemtype'];
}
if (isset($mapping['#itemid_token'])) {
switch ($entity_type) {
case 'taxonomy_term':
$group = 'term';
break;
case 'taxonomy_vocabulary':
$group = 'vocabulary';
break;
default:
$group = $entity_type;
}
$return['#attributes']['itemid'] = token_replace($mapping['#itemid_token'], array(
$group => $entity,
));
}
}
foreach (array_keys($mapping) as $property) {
if ($property[0] != '#') {
$return[$property] = microdata_mapping_to_attributes($mapping[$property]);
}
}
if (isset($mapping['#use_schema_url'])) {
$return['microdata_schema_url'] = _microdata_get_schema_url($entity_type, $entity);
}
return $return;
}
function _microdata_load_mapping($entity_type, $bundle_type, $field = NULL) {
$mapping = db_select('microdata_mapping')
->fields(NULL, array(
'mapping',
))
->condition('type', $entity_type)
->condition('bundle', $bundle_type)
->execute()
->fetchField();
if ($mapping) {
$mapping = unserialize($mapping);
}
if (!is_array($mapping)) {
$mapping = array();
}
return $mapping;
}
function _microdata_prepare_mapping(&$mapping, $entity_type, $bundle_type) {
$property_info = entity_get_property_info($entity_type);
if (isset($property_info['bundles']) && isset($property_info['bundles'][$bundle_type])) {
$bundle_properties = $property_info['bundles'][$bundle_type]['properties'];
}
$fields = field_info_fields();
_microdata_mapping_add_defaults($mapping, $entity_type, $bundle_type, $fields);
foreach ($mapping as $field_name => &$field_mapping) {
if ($field_name[0] === '#' || !isset($bundle_properties[$field_name])) {
continue;
}
$field_info = $bundle_properties[$field_name];
if (microdata_enabled($field_info)) {
$field_mapping['#value_type'] = microdata_get_value_type($bundle_properties[$field_name]['type']);
}
$properties = _microdata_get_field_properties($entity_type, $bundle_type, $field_name);
foreach ($field_mapping as $subfield_name => &$subfield_mapping) {
if (isset($properties[$subfield_name])) {
$subfield_mapping['#value_type'] = microdata_get_value_type($properties[$subfield_name]['type']);
}
}
}
$mapping['#value_type'] = 'item';
}
function _microdata_get_field_properties($entity_type, $bundle_type, $field_name) {
$property_info = entity_get_property_info($entity_type);
if (isset($property_info['bundles'][$bundle_type]['properties'][$field_name]['property info'])) {
$properties = $property_info['bundles'][$bundle_type]['properties'][$field_name]['property info'];
foreach ($properties as $key => $property) {
if (!microdata_enabled($property)) {
unset($properties[$key]);
}
}
return $properties;
}
return array();
}
function _microdata_get_field_type($type) {
return preg_match('/(?<=list\\<).*(?=\\>)/', $type, $matches) ? $matches[0] : $type;
}
function _microdata_mapping_add_defaults(&$mapping, $entity_type, $bundle_type, $fields) {
$defaults = array(
'#itemprop' => array(),
'#itemtype' => array(),
);
foreach ($fields as $field_name => $field) {
if (!isset($field['bundles'][$entity_type]) || !in_array($bundle_type, $field['bundles'][$entity_type])) {
continue;
}
if (!isset($mapping[$field_name])) {
$mapping[$field_name] = array();
}
$mapping[$field_name] = array_merge($defaults, $mapping[$field_name]);
$subfields = _microdata_get_field_properties($entity_type, $bundle_type, $field_name);
foreach ($subfields as $subfield_name => &$subfield) {
if (!isset($mapping[$field_name][$subfield_name])) {
$mapping[$field_name][$subfield_name] = array();
}
$subfield_mapping =& $mapping[$field_name][$subfield_name];
$subfield_mapping = array_merge($defaults, $subfield_mapping);
}
}
}
function _microdata_get_schema_url($entity_type, $entity) {
$entity_uri = entity_uri($entity_type, $entity);
if (!isset($entity_uri['options']) || !is_array($entity_uri['options'])) {
$entity_uri['options'] = array();
}
return array(
'#attributes' => array(
'href' => url($entity_uri['path'], $entity_uri['options']),
'itemprop' => 'url',
),
);
}
function microdata_is_item($entity_type, $entity, $field_name, $delta) {
$wrapper = entity_metadata_wrapper($entity_type, $entity);
$value = $wrapper->{$field_name}
->value();
if (!is_object($value)) {
if (is_array($value)) {
if (isset($value[$delta]) && is_object($value[$delta])) {
$value = $value[$delta];
}
}
else {
return FALSE;
}
}
return isset($value->microdata['#attributes']['itemscope']);
}