From 55fccd8917384034a7e5bdf10636a51b24ed48af Mon Sep 17 00:00:00 2001
From: GoZ <goz@226961.no-reply.drupal.org>
Date: Mon, 7 Nov 2011 17:53:41 +0100
Subject: [PATCH] Issue #1334400: Add microdata to breadcrumb

---
 menu_breadcrumb.install |    1 +
 menu_breadcrumb.module  |  102 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 100 insertions(+), 3 deletions(-)

diff --git a/menu_breadcrumb.install b/menu_breadcrumb.install
index a5e8ab4..f2037ab 100644
--- a/menu_breadcrumb.install
+++ b/menu_breadcrumb.install
@@ -16,6 +16,7 @@ function menu_breadcrumb_uninstall() {
   variable_del('menu_breadcrumb_menus');
   variable_del('menu_breadcrumb_pattern_matches');
   variable_del('menu_breadcrumb_pattern_matches_rebuild');
+  variable_del('menu_breadcrumb_get_breadcrumb_microdata');
 }
 
 /**
diff --git a/menu_breadcrumb.module b/menu_breadcrumb.module
index fe2fb64..bf6ae4f 100644
--- a/menu_breadcrumb.module
+++ b/menu_breadcrumb.module
@@ -335,14 +335,29 @@ function menu_breadcrumb_init() {
   }
 
   // Generate the breadcrumbs using the active menu.
-  $breadcrumb = drupal_get_breadcrumb();
+  $breadcrumb = menu_breadcrumb_get_breadcrumb();
 
   if (variable_get('menu_breadcrumb_append_node_title', 0) == 1) {
     if (variable_get('menu_breadcrumb_append_node_url', 0) == 1) {
-      $breadcrumb[] = $is_front ? l(t('Home'), '<front>') : l(drupal_get_title(), $_GET['q'], array('html' => TRUE,));
+    	if(variable_get('menu_breadcrumb_get_breadcrumb_microdata', 0)){ // Microdata
+    		$title = theme('menu_breadcrumb_microdata_title', $is_front ? t('Home') : drupal_get_title());
+		    $options = array('html'=>TRUE,
+					'attributes' => array(
+						'itemprop' => 'url',
+				));
+				$crumb = l($title, $is_front ? $_GET['q'] : '<front>', array_merge($options));
+		    $breadcrumb[] = theme('menu_breadcrumb_microdata_itemscope', $crumb);
+    	}else{ // Standard
+	      $breadcrumb[] = $is_front ? l(t('Home'), '<front>') : l(drupal_get_title(), $_GET['q'], array('html' => TRUE,));
+	    }
     }
     else {
-      $breadcrumb[] = $is_front ? t('Home') : drupal_get_title();
+    	if(variable_get('menu_breadcrumb_get_breadcrumb_microdata', 0)){ // Microdata
+    		$title = theme('menu_breadcrumb_microdata_title', $is_front ? t('Home') : drupal_get_title());
+				$breadcrumb[] = theme('menu_breadcrumb_microdata_itemscope', $title);    		
+    	}else{ // Standard
+	      $breadcrumb[] = $is_front ? t('Home') : drupal_get_title();
+	    }
     }
   }
 
@@ -387,6 +402,13 @@ function menu_breadcrumb_admin_settings_form() {
     '#description' => t('Choose whether or not the breadcrumb should be hidden if the breadcrumb only contains a link to the front page (<em>Home</em>.).'),
     '#default_value' => variable_get('menu_breadcrumb_hide_on_single_item', 0),
   );
+  
+  $form['menu_breadcrumb_get_breadcrumb_microdata'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use microdata in breadcrumb display.'),
+    '#description' => t('By default, Drupal 6 not use microdata. If this is checked, breadcrumb will use http://www.google.com/support/webmasters/bin/answer.py?&answer=185417 microdata definition'),
+    '#default_value' => variable_get('menu_breadcrumb_get_breadcrumb_microdata', 0),
+  );
 
   $form['include_exclude'] = array(
     '#type' => 'fieldset',
@@ -551,6 +573,12 @@ function menu_breadcrumb_theme() {
     'menu_breadcrumb_menus_table' => array(
       'arguments' => array('element' => NULL),
     ),
+    'menu_breadcrumb_microdata_itemscope' => array(
+    	'arguments' => array('content' => NULL)
+    ),
+    'menu_breadcrumb_microdata_title' => array(
+    	'arguments' => array('content' => NULL)
+    ),
   );
 }
 
@@ -620,3 +648,71 @@ function menu_breadcrumb_html_id($id) {
   return $id;
 }
 
+function menu_breadcrumb_get_breadcrumb(){
+	if(variable_get('menu_breadcrumb_get_breadcrumb_microdata', 0)){
+		$breadcrumb = drupal_set_breadcrumb();
+
+	  if (is_null($breadcrumb)) {
+	    $breadcrumb = menu_breadcrumb_get_active_breadcrumb();
+	  }
+	
+	  return $breadcrumb;
+	}else{
+		return drupal_get_breadcrumb();
+	}
+}
+
+function menu_breadcrumb_get_active_breadcrumb(){
+	$breadcrumb = array();
+
+  // No breadcrumb for the front page.
+  if (drupal_is_front_page()) {
+    return $breadcrumb;
+  }
+
+  $item = menu_get_item();
+  if ($item && $item['access']) {
+    $active_trail = menu_get_active_trail();
+
+    foreach ($active_trail as $parent) {
+    	
+
+			$options = array();
+
+      $title = theme('menu_breadcrumb_microdata_title', $parent['title']);
+
+	    $options = array('html'=>TRUE,
+				'attributes' => array(
+					'itemprop' => 'url',
+			));
+
+			$crumb = l($title, $parent['href'], array_merge($options, $parent['localized_options']));
+	
+	    $breadcrumb[] = theme('menu_breadcrumb_microdata_itemscope', $crumb);
+
+    }
+    $end = end($active_trail);
+
+    // Don't show a link to the current page in the breadcrumb trail.
+    if ($item['href'] == $end['href'] || ($item['type'] == MENU_DEFAULT_LOCAL_TASK && $end['href'] != '<front>')) {
+      array_pop($breadcrumb);
+    }
+  }
+  return $breadcrumb;
+}
+
+
+
+/**
+ * Return container tag for microdata
+ */
+function theme_menu_breadcrumb_microdata_itemscope($value){
+  return '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb" class="itemscope">'.$value.'</div>';
+}
+
+/**
+ * Return container title tag for microdata
+ */
+function theme_menu_breadcrumb_microdata_title($value){
+  return '<span itemprop="title">'.$value.'</span>';
+}
-- 
1.7.3.3

