? me.menu_item_link.big.patch
? me.menu_item_link.small.patch
Index: me.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/me/me.module,v
retrieving revision 1.5.2.7.2.8
diff -u -r1.5.2.7.2.8 me.module
--- me.module	1 Jul 2009 22:59:11 -0000	1.5.2.7.2.8
+++ me.module	22 Nov 2010 22:33:26 -0000
@@ -31,10 +31,14 @@
 
 /**
  * Implementation of hook_theme_registry_alter().
+ *
+ * There is a different registry version for each theme,
+ * and this function will be called for each of them.
  */
 function me_theme_registry_alter(&$theme_registry) {
   if (isset($theme_registry['menu_item_link']['function'])) {
-    variable_set('me_theme_menu_item_link', $theme_registry['menu_item_link']['function']);
+    // remember the original function
+    $theme_registry['menu_item_link']['me_original_function'] = $theme_registry['menu_item_link']['function'];
     $theme_registry['menu_item_link']['function'] = 'me_theme_menu_item_link';
   }
 }
@@ -50,27 +54,50 @@
  * Implementation of theme_menu_item_link().
  */
 function me_theme_menu_item_link($link) {
-  _me_check_path($link);
+  static $_functions = array();
+
+  $theme = $GLOBALS['theme'];
 
-  // Check if we got a valid function from the registry rebuild.
-  $function = me_variable_get('me_theme_menu_item_link');
-  if (empty($function) || !function_exists($function)) {
-    // If not, then go through the available themes to get the correct function to use.
-    if (isset($GLOBALS['custom_theme']) && function_exists($GLOBALS['custom_theme'] .'_menu_item_link')) {
-      $function = $GLOBALS['custom_theme'] .'_menu_item_link';
+  if (!isset($_functions[$theme])) {
+    $registry = theme_get_registry();
+    if (function_exists($candidate = $registry['menu_item_link']['me_original_function'])) {
+      $function = $candidate;
+    }
+    else if (isset($GLOBALS['theme_info'])) {
+      $themes = $GLOBALS['base_theme_info'];
+      $themes[] = $GLOBALS['theme_info'];
+      foreach (array_reverse($themes) as $theme_info) {
+        $candidate = $theme_info->name .'_menu_item_link';
+        if (function_exists($candidate)) {
+          $function = $candidate;
+          break;
+        }
+      }
     }
-    elseif (isset($GLOBALS['theme_key']) && function_exists($GLOBALS['theme_key'] .'_menu_item_link')) {
-      $function = $GLOBALS['theme_key'] .'_menu_item_link';
+    if (isset($function)) {
+      // do nothing
     }
-    elseif (isset($GLOBALS['theme_engine']) && function_exists($GLOBALS['theme_engine'] .'_menu_item_link')) {
-      $function = $GLOBALS['theme_engine'] .'_menu_item_link';
+    elseif (isset($GLOBALS['theme_key']) && function_exists($candidate = $GLOBALS['theme_key'] .'_menu_item_link')) {
+      $function = $candidate;
     }
-    else {
+    elseif (isset($GLOBALS['theme_engine']) && function_exists($candidate = $GLOBALS['theme_engine'] .'_menu_item_link')) {
+      $function = $candidate;
+    }
+    elseif (function_exists('theme_menu_item_link')) {
       $function = 'theme_menu_item_link';
     }
+    $_functions[$theme] = $function;
   }
 
-  return $function($link);
+  if (isset($_functions[$theme]) && $_functions[$theme] !== __FUNCTION__) {
+    _me_check_path($link);
+    $function = $_functions[$theme];
+    return $function($link);
+  }
+  else {
+    // This should never happen.
+    return __FUNCTION__;
+  }
 }
 
 /**
