/[drupal]/contributions/modules/category/contrib/category_breadcrumb/category_breadcrumb.module
ViewVC logotype

Diff of /contributions/modules/category/contrib/category_breadcrumb/category_breadcrumb.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Sun Aug 5 19:09:16 2007 UTC revision 1.2, Wed Aug 5 04:52:54 2009 UTC
# Line 3  Line 3 
3    
4  /**  /**
5   * @file   * @file
6   * Create sensible breadcrumb-navigation on node-pages, based on Categories   * Create breadcrumb-navigation on node-pages, based on Categories
7   */   */
8    
9    
10  /*  /*
11  * Implementation of hook_menu (for admin settings only)  * Implementation of hook_menu (for admin settings only)
12  */  */
13  function category_breadcrumb_menu($may_cache) {  function category_breadcrumb_menu() {
14    $items[] = array(    $items['admin/content/category/category_breadcrumb'] = array(
15      'path' => 'admin/settings/category_breadcrumb',      'title' => 'Breadcrumbs',
16      'title' => t('Category Breadcrumb'),      'page callback' => 'drupal_get_form',
17      'description' => t('Configure breadcrumb-navigation for category-assigned nodes.'),      'page arguments' => array('category_breadcrumb_admin_settings'),
18      'callback' => 'drupal_get_form',      'access arguments' => array('administer site configuration'),
19      'callback arguments' => array('category_breadcrumb_admin_settings'),      'type' => MENU_LOCAL_TASK,
20      'access' => user_access('administer site configuration'),      'file' => 'category_breadcrumb.admin.inc',
     'type' => MENU_NORMAL_ITEM,  
21    );    );
22    return $items;    return $items;
23  }  }
24    
25    
26  /**  /**
27   * The admin settings form   * Implementation of hook_help().
28   */   */
29  function category_breadcrumb_admin_settings() {  function category_breadcrumb_help($path, $arg) {
30      switch ($path) {
31    $form['category_breadcrumb_amount'] = array(      case 'admin/content/category/category_breadcrumb':
32      '#type' => 'radios',        $output = t("The category_breadcrumb module adds breadcrumb navigation to your category and container pages, as well as categorized contents (i.e. node pages), so that it reflects your site's hiearchy of categories rather than menu links. The settings below may be used to change the behavior of category-based breadcrumbs.");
33      '#title' => t('For category-assigned nodes'),        return $output;
34      '#default_value' => variable_get('category_breadcrumb_amount', 1),    }
     '#options' => array(  
       '0' => t("Do nothing (use system's breadcrumb)"),  
       '1' => t('Show just one breadcrumb (default)'),  
       '2' => t('Show multiple breadcrumbs'),  
       ),  
     '#description' => t("One breadcrumb is exactly like system breadcrumbs, but if there are more categories assigned to the node, it shows only just one of the possible paths, confusing the user if he came from another. Multiple breadcrumbs shows the paths for all assigned categories, but may be incompatible with some themes.")  
   );  
   
   $form['category_breadcrumb_catpages'] = array(  
     '#type' => 'radios',  
     '#title' => t('For category and container pages'),  
     '#default_value' => variable_get('category_breadcrumb_catpages', 1),  
     '#options' => array(  
       '0' => t("Do nothing (use system's menu-based breadcrumb)"),  
       '1' => t('Show breadcrumb (default)'),  
       ),  
     '#description' => t("While enabled, this feature replaces any existing (menu-based) breadcrumbs on category- and container-pages.")  
   );  
   
   $form['category_breadcrumb_exclude'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Do not create breadcrumbs for'),  
     '#default_value' => variable_get('category_breadcrumb_exclude', 'forum,blog'),  
     '#size' => 60,  
     '#maxlength' => 200,  
     '#description' => t("Enter comma-separated list of node-types to exclude from breadcrumb processing. 'forum' and 'blog' are recommended to avoid common problems. (More node types may be easily observed in HTML source of your pages as class names near top of the content.)")  
   );  
   
   $form['category_breadcrumb_title'] = array(  
     '#type' => 'radios',  
     '#title' => t('Add actual node-title to the breadcrumb'),  
     '#default_value' => variable_get('category_breadcrumb_title', 0),  
     '#options' => array(  
       '0' => t('No title, show just path (default)'),  
       '1' => t('Title as plain text'),  
       '2' => t('Title as link'),  
       ),  
     '#description' => t("Drupal defines the breadcrumb with no title in it, so usually it's up to theme to add the currently viewed page's title (or not), and this option should be disabled. But however, while using the Multiple breadcrumbs option, it might be better to enable the title here - and remove from your theme in turn - to have the title on each of the multiple breadcrumbs. You can add title even if no breadcrumb chosen above (i.e. adding to the system's breadcrumb), but this doesn't work for any pages other than nodes.")  
   );  
   
   return system_settings_form($form);  
35  }  }
36    
37    
# Line 88  function category_breadcrumb_nodeapi(&$n Line 46  function category_breadcrumb_nodeapi(&$n
46      // Viewing a node as page, not front: Check for existing breadcrumbs & excluded node-types      // Viewing a node as page, not front: Check for existing breadcrumbs & excluded node-types
47      if (!drupal_set_breadcrumb() && !in_array($node->type, explode(',', variable_get('category_breadcrumb_exclude', 'forum,blog')))) {      if (!drupal_set_breadcrumb() && !in_array($node->type, explode(',', variable_get('category_breadcrumb_exclude', 'forum,blog')))) {
48    
49        // Handle category/container pages        // Handle node types with category/container behavior
50        if ($node->type == 'category_cat' or $node->type == 'category_cont') {        if (!empty($node->category) && !empty($node->category['behavior'])) {
51          if (variable_get('category_breadcrumb_catpages', 1)) {          if (variable_get('category_breadcrumb_catpages', 1)) {
52            $crumbs[] = _category_breadcrumb_build($node, $add_title);            $crumbs[] = _category_breadcrumb_build($node, $add_title);
53          }          }
54        }        }
55        // All other node-types: One breadcrumb per category assigned        // All other node-types are content: One breadcrumb per category assigned
56        else {        else {
57          $amount = variable_get('category_breadcrumb_amount', 1);          $amount = variable_get('category_breadcrumb_amount', 1);
58          if ($node->category && $amount) {          if ($node->categories && $amount) {
59            foreach ($node->category as $category) {            foreach ($node->categories as $category) {
60              $crumbs[] = _category_breadcrumb_build($node, $add_title, $category);              $crumbs[] = _category_breadcrumb_build($node, $add_title, $category);
61              if ($amount < 2)              if ($amount < 2)
62                break;  // If no multiple breadcrumbs, stop after the first                break;  // If no multiple breadcrumbs, stop after the first
# Line 115  function category_breadcrumb_nodeapi(&$n Line 73  function category_breadcrumb_nodeapi(&$n
73  // all occurences of the separator, then allow Drupal to re-unite it with any separator wanted.  // all occurences of the separator, then allow Drupal to re-unite it with any separator wanted.
74    
75        // Multiple breadcrumbs as item-list, otherwise no change        // Multiple breadcrumbs as item-list, otherwise no change
76        $output = (count($crumbs) > 1) ? '<ul><li>'.implode('</li><li>', $crumbs).'</li></ul>' : $crumbs[0];        $output = (count($crumbs) > 1) ? '<ul><li>'. implode('</li><li>', $crumbs) .'</li></ul>' : $crumbs[0];
77        drupal_set_breadcrumb(explode('»', $output));        drupal_set_breadcrumb(explode('»', $output));
78      }      }
79      // Even if no breadcrumb created, we may still want to append node-title for theming consistency      // Even if no breadcrumb created, we may still want to append node-title for theming consistency
# Line 151  function _category_breadcrumb_build($nod Line 109  function _category_breadcrumb_build($nod
109    }    }
110    
111    // Add further parents, until no more left    // Add further parents, until no more left
112    while ($parents = category_get_parents($cid, 'cid', FALSE)) {    do {
113      $cid = $parents[0]->cid;      $parents = category_get_parents($cid, 'cid', FALSE);
114      if(!$parents[0]->hidden_cont) {      $parent = reset($parents);
115        $crumb[] = l($parents[0]->title, 'node/'.$cid);      $cid = $parent->cid;
116        $hidden = 0;
117    
118        if ($cid && !$parent->cnid) {
119          // This is a container. Since category_get_parents() doesn't fetch
120          // hidden_cont data in 6.x version, we need to check manually.
121          $data = db_fetch_object(db_query('SELECT hidden_cont FROM {category_cont} WHERE cid = %d', $cid));
122          $hidden = $data->hidden_cont;
123      }      }
124    }  
125        if ($cid && !$hidden) {
126          $crumb[] = l($parent->title, 'node/'.$cid);
127        }
128      } while ($cid);
129    
130    // Add 'Home' and join into string    // Add 'Home' and join into string
131    $crumb[] = l(t('Home'), variable_get('site_frontpage', 'node'));    $crumb[] = l(t('Home'), variable_get('site_frontpage', 'node'));

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2