Index: custom_breadcrumbs_paths.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/custom_breadcrumbs/custom_breadcrumbs_paths/Attic/custom_breadcrumbs_paths.module,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 custom_breadcrumbs_paths.module
--- custom_breadcrumbs_paths.module	7 May 2009 02:51:39 -0000	1.1.2.4
+++ custom_breadcrumbs_paths.module	9 May 2009 17:19:54 -0000
@@ -1,10 +1,16 @@
 <?php
-// $Id: custom_breadcrumbs_paths.module,v 1.1.2.4 2009/05/07 02:51:39 mgn Exp $
+// $Id: $
+
+/**
+ * @file
+ * Assign custom breadcrumbs based on the Drupal path.
+ */
+
 require_once(drupal_get_path('module', 'custom_breadcrumbs') .'/custom_breadcrumbs.admin.inc');
 
 /**
  * Implementation of hook_cb_breadcrumb_info().
- *   @return an array with elements 
+ *   @return an array with elements
  *     'table' indicating the db_table to load the breadcrumb from,
  *     'field' a unique field of the database table used to identify the breadcrumb
  *     'type' a string used for indicating the breadcrumb type on the admin list
@@ -37,40 +43,66 @@ function custom_breadcrumbs_paths_menu()
 }
 
 /**
- *  Implementation of hook_nodeapi().
+ * Implementation of hook_nodeapi().
  */
 function custom_breadcrumbs_paths_nodeapi($node, $op, $teaser, $page) {
   if ($op == 'alter' && empty($teaser) && !empty($page)) {
     $curpath = $_REQUEST['q'];
-    // check for breadcrumb for this path
-    $breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_paths', array('specific_path' => $curpath));
+    // Check for breadcrumb for this path.
+    $matchpath = variable_get('custom_breadcrumbs_paths_allow_wildcards', FALSE);
+    $param = ($matchpath) ? array() : array('specific_path' => $curpath);
+    $breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_paths', $param);
     while ($breadcrumb = array_pop($breadcrumbs)) {
-      if (custom_breadcrumbs_is_visible($breadcrumb, $node)) {
-        custom_breadcrumbs_set_breadcrumb($breadcrumb, $node);
-        // Don't check any others once a visible breadcrumb is found.
-        return;
+      $page_match = FALSE;
+      if ($matchpath) {
+        $page_match = _custom_breadcrumbs_paths_page_match($curpath, $breadcrumb->specific_path);
+      }
+      if ((!$matchpath) || ($matchpath && $page_match)) {
+        if (custom_breadcrumbs_is_visible($breadcrumb, $node)) {
+          custom_breadcrumbs_set_breadcrumb($breadcrumb, $node);
+          // Don't check any others once a visible breadcrumb is found.
+          return;
+        }
       }
     }
   }
 }
 
 /**
- *  Implementation of hook_views_pre_view().
+ * Implementation of hook_views_pre_render().
  */
 // TODO: create a common helper function for these hooks to avoid code duplication
 // TODO: pass $this into custom_breadcrumbs_is_visible to allow use of the views object in
 //       determining visibility. Needs some modification of that function to check for the
 //       object type.
-function custom_breadcrumbs_paths_views_pre_view($this, $display_id, $args) {
+function custom_breadcrumbs_paths_views_pre_render(&$view) {
   // Don't really do anything with the view. This is just a pretense to insert a breadcrumb.
   $curpath = $_REQUEST['q'];
-  // Check for breadcrumb at this path.
-  $breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_paths', array('specific_path' => $curpath));
-  while ($breadcrumb = array_pop($breadcrumbs)) {
-    if (custom_breadcrumbs_is_visible($breadcrumb, $this)) {
-      custom_breadcrumbs_set_breadcrumb($breadcrumb);
-      // Don't check any others once a visible breadcrumb is found.
-      return;
+  $curpath = drupal_get_normal_path($curpath);
+  // Check to see if the view path matches the current path.
+  $viewpage = FALSE;
+  foreach ($view->display as $display) {
+    $viewpage = $viewpage || ($display->display_options['path'] == $curpath);
+  }
+  if ($viewpage) {
+    // Check for breadcrumb at this path.
+    $matchpath = variable_get('custom_breadcrumbs_paths_allow_wildcards', FALSE);
+    $param = ($matchpath) ? array() : array('specific_path' => $curpath);
+    $breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_paths', $param);
+    while ($breadcrumb = array_pop($breadcrumbs)) {
+      $page_match = FALSE;
+      if ($matchpath) {
+        $page_match = _custom_breadcrumbs_paths_page_match($curpath, $breadcrumb->specific_path);
+      }
+      if ((!$matchpath) || ($matchpath && $page_match)) {
+        
+        if (custom_breadcrumbs_is_visible($breadcrumb, $view)) {
+          
+          custom_breadcrumbs_set_breadcrumb($breadcrumb);
+          // Don't check any others once a visible breadcrumb is found.
+          return;
+        }
+      }
     }
   }
 }
@@ -86,11 +118,15 @@ function custom_breadcrumbs_paths_form(&
   else {
     drupal_set_title('Add Custom Breadcrumb for Path');
   }
+  $description = t('The drupal path that this custom breadcrumb trail will apply to. ');
+  if (variable_get('custom_breadcrumbs_paths_allow_wildcards', FALSE)) {
+    $description .= t("The '*' character can be used as a wildcard to set a custom breadcrumb for all matching paths. For example, foo/bar/* could be used to match every page with a path beginning with foo/bar.");
+  }
   $form['specific_path'] = array(
     '#type' => 'textfield',
     '#title' => t('Specific Path'),
     '#required' => TRUE,
-    '#description' => t('The drupal path that this custom breadcrumb trail will apply to.'),
+    '#description' => $description,
     '#default_value' => $bid ?  $breadcrumb->specific_path : NULL,
     '#weight' => -10,
   );
@@ -99,15 +135,32 @@ function custom_breadcrumbs_paths_form(&
   $form['#table'] = 'custom_breadcrumbs_paths';
   $form['#submit'][] = 'custom_breadcrumbs_form_submit';
   $form['#validate'][] = 'custom_breadcrumbs_form_validate';
-  
   return $form;
 }
 
-function custom_breadcrumbs_paths_form_validate($form, &$form_state) {
-  // Make sure specific path does not already have a custom breadcrumb.
-  $specific_path = trim($form_state['values']['specific_path']);
-  $breadcrumb = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_paths', array('specific_path' => $specific_path));
-  if ($breadcrumb) {
-    form_set_error('specific_path', t('This path already has a custom breadcrumb. You can edit it from the custom breadcrumbs list.'));
+/**
+ * Implementation of hook_form_alter().
+ *
+ * @return NONE
+ */
+function custom_breadcrumbs_paths_form_alter(&$form, $form_state, $form_id) {
+  if ($form_id == 'custom_breadcrumbs_admin_settings') {
+    $form['adv_settings']['custom_breadcrumbs_paths_allow_wildcards'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Use wildcard pattern matching in paths'),
+      '#default_value' => variable_get('custom_breadcrumbs_paths_allow_wildcards', FALSE),
+      '#description' => t("When checked, the '*' character can be used as a wildcard to set a custom breadcrumb for all matching paths. For example, foo/bar/* could be used to match every page with a path beginning with foo/bar."),
+      '#weight' => -20,
+    );
+  }
+}
+
+function _custom_breadcrumbs_paths_page_match($curpath, $breadcrumb_path) {
+  $path = drupal_get_path_alias($curpath);
+  // Compare with the internal and path alias (if any).
+  $page_match = drupal_match_path($path, $breadcrumb_path);
+  if ($path != $curpath) {
+    $page_match = $page_match || drupal_match_path($curpath, $breadcrumb_path);
   }
+  return $page_match;
 }
