/[drupal]/contributions/modules/taxonomy_breadcrumb/taxonomy_breadcrumb.module
ViewVC logotype

Contents of /contributions/modules/taxonomy_breadcrumb/taxonomy_breadcrumb.module

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


Revision 1.10 - (show annotations) (download) (as text)
Thu Mar 12 18:51:39 2009 UTC (8 months, 2 weeks ago) by mgn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +4 -1 lines
File MIME type: text/x-php
#359319: by stevenghines, radj and MGN: new feature provides option to append
node title at end of breadcrumb trail.
#395082 by kndr and MGN: correctly set weight of taxonomy_breadcrumb module to be greater than the taxonomy module.
1 <?php
2 // $Id: taxonomy_breadcrumb.module,v 1.7 2009/01/12 02:19:26 mgn Exp $.
3
4 /**
5 * @file
6 * The taxonomy_breadcrumb module generates taxonomy based breadcrumbs on node
7 * pages and taxonomy/term pages. The breadcrumb trail takes on the form:
8 * [HOME] >> [VOCABULARY] >> TERM >> [TERM] ...
9 *
10 * - The HOME breadcrumb (if present) links to the homepage. The text
11 * displayed for HOME is administrator configurable. If the HOME
12 * breadcrumb is not defined by the administrator, it will not appear
13 * in the breadcrumb trail.
14 * - The VOCABULARY breadcrumb (if present) will link to an administrator
15 * defined page. If the VOCABULARY does not have an administrator
16 * defined page, it will not appear in the breadcrumb trail.
17 * - Each TERM breadcrumb will link to either
18 * (1) taxonomy/term/tid by default, or
19 * (2) an administrator defined page if one is defined for the term.
20 * - These administrator defined "breadcrumb links" for VOCABULARIES and TERMS
21 * are controlled from the add/edit vocabulary and add/edit term
22 * administrator pages.
23 *
24 * Examples:
25 * home >> term >> term
26 * mysite >> term >> term
27 * home >> vocabulary >> term >> term
28 * vocabulary >> term >> term
29 *
30 * Issues:
31 * - use of db_rewrite_sql?
32 * - This module is not expected to be compatible with other modules that call
33 * drupal_set_breadcrumb, such as taxonomy_context.
34 * - With multi-parent terms, all parent terms seem to show up, look into
35 * taxonomy_get_parents_all.
36 */
37
38 // default value for Advanced Settings, Node Types
39 define('TAXONOMY_BREADCRUMB_NODE_TYPES_DEFAULT', 'book');
40
41 /**
42 * Implementation of hook_menu().
43 */
44 function taxonomy_breadcrumb_menu() {
45 $items['admin/settings/taxonomy-breadcrumb'] = array(
46 'title' => 'Taxonomy Breadcrumb',
47 'description' => 'Configure how taxonomy based breadcrumbs are displayed.',
48 'file' => 'taxonomy_breadcrumb.admin.inc',
49 'page callback' => 'drupal_get_form',
50 'page arguments' => array('taxonomy_breadcrumb_admin_settings'),
51 'access callback' => 'user_access',
52 'access arguments' => array('administer site configuration'),
53 'type' => MENU_NORMAL_ITEM, // optional
54 );
55
56 // Similiar to core menu item in taxonomy_menu, except callback is different
57 $items['taxonomy/term/%'] = array(
58 'title' => 'Taxonomy term',
59 'file' => 'taxonomy_breadcrumb.inc',
60 'page callback' => '_taxonomy_breadcrumb_term_page',
61 'page arguments' => array(2),
62 'access callback' => 'user_access',
63 'access arguments' => array('access content'),
64 'type' => MENU_CALLBACK,
65 );
66
67 return $items;
68 }
69
70 /**
71 * Implementation of hook_nodeapi().
72 */
73 function taxonomy_breadcrumb_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
74 // If we are on a page view (not just a teaser), set the breadcrumb
75 // $a4 contains TRUE if we are on a page view
76 if ($op == 'view' && $a4 && !drupal_is_front_page()) {
77 // Include the .inc file with all helper functions
78 include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc';
79
80 // See if the node type of the current node is part of the node types listed on the advanced settings page.
81 $array_of_types = array_filter((array)variable_get('taxonomy_breadcrumb_node_types', TAXONOMY_BREADCRUMB_NODE_TYPES_DEFAULT));
82 $in_list = in_array($node->type, $array_of_types);
83
84 // if the node type IS IN the node types list and the list IS inclusive OR
85 // if the node type IS NOT IN the node types list and the list IS NOT inclusive (e.g. exclusive)
86 // THEN modify the breadcrumb trail.
87 if ($in_list == variable_get('taxonomy_breadcrumb_include_nodes', FALSE) ) {
88
89 // Extract lightest term from lightest vocabulary assosciated with node.
90 $term = _taxonomy_breadcrumb_node_get_lightest_term($node->nid);
91 $breadcrumb = _taxonomy_breadcrumb_generate_breadcrumb($term->tid);
92 if (variable_get('taxonomy_breadcrumb_include_node_title', FALSE)) {
93 $breadcrumb[] = $node->title;
94 }
95 drupal_set_breadcrumb($breadcrumb);
96 }
97 }
98 }
99
100 /**
101 * Implementation of hook_help().
102 */
103 function taxonomy_breadcrumb_help($path, $arg) {
104 switch ($path) {
105 case 'admin/help#taxonomy_breadcrumb':
106 return t('<p>See %link.</p>', array('%link' => l('admin/settings/taxonomy-breadcrumb', 'admin/settings/taxonomy-breadcrumb')));
107 case 'admin/settings/taxonomy-breadcrumb':
108 return t('The taxonomy_breadcrumb module generates taxonomy based breadcrumbs on node pages and taxonomy/term pages. The breadcrumb trail takes on the form:
109 <ul>[HOME] >> [VOCABULARY] >> TERM >> [TERM] ...</ul>
110 <ul>
111 <li>The text displayed for HOME is configurable below. The <em>HOME </em>breadcrumb (if present) links to the homepage. The text displayed for HOME is administrator configurable. If the HOME breadcrumb is not defined by the administrator, it will not appear in the breadcrumb trail.</li>
112 <li>The <em>VOCABULARY </em>breadcrumb (if present) will link to an administrator defined page. If the VOCABULARY does not have an administrator defined page, it will not appear in the breadcrumb trail. This can be configured on the add/edit vocabulary pages within !tax_link (taxonomy).</li>
113 <li>Each <em>TERM </em>breadcrumb will link to either (1) taxonomy/term/tid by default, or (2) an administrator defined page if one is defined for the term. This can be configured on the add/edit term pages within !tax_link (taxonomy).</li>
114 </ul>
115 <br />
116 <p>Examples:
117 <ul>
118 <li>home >> term >> term</li>
119 <li>mysite >> term >> term</li>
120 <li>home >> vocabulary >> term >> term</li>
121 <li>vocabulary >> term >> term</li>
122 </ul>', array('!tax_link' => l('administer >> categories', 'admin/content/taxonomy')));
123 }
124 }
125
126 /**
127 * Implementation of hook_form_alter().
128 *
129 * This must be used over hook_taxonomy to
130 * add the Breadcrumb Path fields to the vocabulary and term forms. The
131 * hook_taxonomy function does not provide a way to obtain the vid or tid
132 * of the vocabulary or term.
133 */
134 function taxonomy_breadcrumb_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
135 // Include the .inc file with all helper functions
136 include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.admin.inc';
137 include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc';
138
139 $form['taxonomy_breadcrumb_path'] = array(
140 '#type' => 'textfield',
141 '#title' => t('Breadcrumb path (taxonomy_breadcrumb)'),
142 '#default_value' => _taxonomy_breadcrumb_get_vocabulary_path($form['vid']['#value']),
143 '#maxlength' => 128,
144 '#description' => t('Specify the path this vocabulary links to as a breadcrumb. If blank, the breadcrumb will not appear. Use a relative path and don\'t add a trailing slash. For example: node/42 or my/path/alias.'),
145 '#weight' => 0,
146 );
147 }
148
149 /**
150 * Implementation of hook_form_alter().
151 *
152 * This must be used over hook_taxonomy to
153 * add the Breadcrumb Path fields to the vocabulary and term forms. The
154 * hook_taxonomy function does not provide a way to obtain the vid or tid
155 * of the vocabulary or term.
156 */
157 function taxonomy_breadcrumb_form_taxonomy_form_term_alter(&$form, &$form_state) {
158 // Include the .inc file with all helper functions
159 include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc';
160
161 $form['taxonomy_breadcrumb_path'] = array(
162 '#type' => 'textfield',
163 '#title' => t('Breadcrumb path (taxonomy_breadcrumb)'),
164 '#default_value' => _taxonomy_breadcrumb_get_term_path($form['tid']['#value']),
165 '#maxlength' => 128,
166 '#description' => t('Specify the path this term links to as a breadcrumb. If blank, the breadcrumb links to the default taxonomy page. Use a relative path and don\'t add a trailing slash. For example: node/42 or my/path/alias.'),
167 '#weight' => 0,
168 );
169 }
170
171 /**
172 * Implementation of hook_taxonomy(). This implementation checks to see if a
173 * vocabulary or term is being updated and makes the necessary changes in
174 * the taxonomy_breadcrumb database tables.
175 */
176 function taxonomy_breadcrumb_taxonomy($op, $type, $object = NULL) {
177
178 // if (after a vocabulary or term is updated)
179 // called by module_invoke_all('taxonomy', 'update', 'term', $edit); in taxonomy.module
180 if ( $op == 'update' && ($type == 'vocabulary' || $type == 'term') ) {
181 // Include the .inc file with all helper functions
182 include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc';
183
184 // Set variables to used in SQL query to reflect if vocabulary or term is
185 // being updated.
186
187 if ($type == 'vocabulary') {
188 $table = '{taxonomy_breadcrumb_vocabulary}';
189 $key_type = 'vid';
190 $old_path = _taxonomy_breadcrumb_get_vocabulary_path($object['vid']);
191 }
192 elseif ($type == 'term') {
193 $table = '{taxonomy_breadcrumb_term}';
194 $key_type = 'tid';
195 $old_path = _taxonomy_breadcrumb_get_term_path($object['tid']);
196 }
197 $key = isset($object[$key_type]) ? $object[$key_type] : NULL;
198 $new_path = isset($object['taxonomy_breadcrumb_path']) ? $object['taxonomy_breadcrumb_path'] : NULL;
199
200 if (!is_null($new_path)) { // Only modify database when the object has the 'taxonomy_breadcrumb_path' field
201
202 // Delete record from taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term
203 if (drupal_strlen($new_path) == 0 && $old_path !== NULL) {
204 db_query("DELETE FROM $table WHERE $key_type = %d", $key);
205 }
206
207 // Update existing record in taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term
208 elseif (drupal_strlen($new_path) != 0 && $old_path != NULL) {
209 db_query("UPDATE $table SET path = '%s' WHERE $key_type = %d", $new_path, $key );
210 }
211
212 // Create new record in taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term
213 elseif (drupal_strlen($new_path) != 0 && $old_path == NULL) {
214 db_query("INSERT INTO $table ($key_type, path) VALUES (%d, '%s')", $key, $new_path);
215 }
216 }
217 }
218 }

  ViewVC Help
Powered by ViewVC 1.1.2