Index: front_page.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/front/front_page.module,v
retrieving revision 1.75.2.6
diff -u -r1.75.2.6 front_page.module
--- front_page.module	29 Apr 2008 08:34:08 -0000	1.75.2.6
+++ front_page.module	30 Jan 2010 17:16:47 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: front_page.module,v 1.75.2.6 2008/04/29 08:34:08 augustin Exp $
+// $Id: front_page.module,v 1.75.2.7 2010/01/30 08:34:08 DublinDrupaller Exp $
 /**
  *
  * This module allows the site admin to set advanced front page settings.
@@ -19,11 +19,15 @@
 function front_page_help($section) {
   switch ($section) {
     case 'admin/settings/front':
-      $roles = user_roles();
+      $roles = _front_page_get_roles();
       $special_note = '';
       if (count($roles) >= 3) {
-        krsort($roles);
-        $special_note = '<fieldset>'. t('<legend>front page by role usage</legend><p><strong>Note:</strong>When using the front pages by role option, please note that if a user has multiple roles the first role match will determine which front page they see. Here is the order that the roles will be checked (from left to right).</p>') .'<p>';
+        $special_note = '<fieldset>'. t('<legend>front page by role usage</legend><p><strong>Note:</strong>When using the front pages by role option, please note that if a user has multiple roles the first role match will determine which front page they see. Here is the order that the roles will be checked (from left to right).');
+        if (_front_page_is_roleweight_module_available()) {
+            // we can use the roleweight module to change the order of priority
+            $special_note .= '<strong>  Using role order specified by your roleweight settings.</strong>';
+        }
+        $special_note .= '</p><p>';
         foreach ($roles as $role_id => $role_name) {
           $special_note .= "<strong>$role_id</strong> $role_name |  ";
         }
@@ -59,6 +63,31 @@
 }
 
 /**
+ * Get the roles.  If the roleweight module is installed then we respect the ordering presented there
+ *
+ * @return Roles array indexed with role ID.
+ */
+function _front_page_get_roles() {
+    if (!_front_page_is_roleweight_module_available()) {
+        $roles = user_roles ();
+        krsort($roles);
+        return $roles;
+    } else {
+        $roles = roleweight_get_roles();
+        $result = array();
+        foreach ( $roles as $role ) {
+             $result[ $role['rid'] ] = $role['name'];
+        }
+        $result = array_reverse ($result, true);
+        return $result;
+    }
+}
+
+function _front_page_is_roleweight_module_available () {
+     return function_exists('roleweight_get_roles');
+}
+
+/**
  * This function sets up the admin/build/front_page settings page.
  *
  */
@@ -74,7 +103,7 @@
   );
 
   // build the form for roles
-  $roles = user_roles();
+  $roles = _front_page_get_roles();
   foreach (element_children($roles) as $role) {
     $rolename = $roles[$role];
 
@@ -258,6 +287,7 @@
  * Function to handle the display of the front page.
  */
 function front_page() {
+
   // Set a default value for landing zone if no front_page variables are filled.
   // If the module is turned on but empty in certain areas then a redirection loop will occur.
   // Defaulting to 'node' prevents this.
@@ -286,7 +316,7 @@
   }
 
   //this checks to see if you are overriding HOME links on the site
-  if (variable_get('front_page_breadcrumb', 0)) {
+   if (variable_get('front_page_breadcrumb', 0) && isset($_SERVER['HTTP_REFERER'])) {
     // This checks to see if the referer is an internal HOME link or not.
     $newhome =  variable_get('front_page_breadcrumb_redirect', 'node');
     $ref = $_SERVER['HTTP_REFERER'];
@@ -303,6 +333,7 @@
 
   // if the user is not logged in load up the page for anonymous users
   if (!$user->uid) {
+
     $output = variable_get('front_1_text', 'drupal');
 
     // If PHP code execution is allowed then use eval.
@@ -326,10 +357,8 @@
     }
   }
 
-
   $roles = ""; //make sure the roles variable is clear
-  $roles = user_roles(); //load up the user roles for the site
-  krsort($roles); //reverse the order of role types so it checks the highest or more recent role type first.
+  $roles = _front_page_get_roles(); //load up the user roles for the site
   $siteroles = count($roles);
 
   /* this is where the front page by role stuff happens  */
@@ -413,5 +442,4 @@
       }
     }
   }
-}
-
+}
\ No newline at end of file

