| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_breadcrumb.module,v 1.7 2009/01/12 02:19:26 mgn Exp $. |
// $Id: $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 43 |
*/ |
*/ |
| 44 |
function taxonomy_breadcrumb_menu() { |
function taxonomy_breadcrumb_menu() { |
| 45 |
$items['admin/settings/taxonomy-breadcrumb'] = array( |
$items['admin/settings/taxonomy-breadcrumb'] = array( |
| 46 |
'title' => 'Taxonomy Breadcrumb', |
'title' => 'Taxonomy Breadcrumb', |
| 47 |
'description' => 'Configure how taxonomy based breadcrumbs are displayed.', |
'description' => 'Configure how taxonomy based breadcrumbs are displayed.', |
| 48 |
'file' => 'taxonomy_breadcrumb.admin.inc', |
'file' => 'taxonomy_breadcrumb.admin.inc', |
| 49 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 50 |
'page arguments' => array('taxonomy_breadcrumb_admin_settings'), |
'page arguments' => array('taxonomy_breadcrumb_admin_settings'), |
| 51 |
'access callback' => 'user_access', |
'access callback' => 'user_access', |
| 52 |
'access arguments' => array('administer site configuration'), |
'access arguments' => array('administer site configuration'), |
| 53 |
'type' => MENU_NORMAL_ITEM, // optional |
'type' => MENU_NORMAL_ITEM, |
|
); |
|
|
|
|
|
// Similiar to core menu item in taxonomy_menu, except callback is different |
|
|
$items['taxonomy/term/%'] = array( |
|
|
'title' => 'Taxonomy term', |
|
|
'file' => 'taxonomy_breadcrumb.inc', |
|
|
'page callback' => '_taxonomy_breadcrumb_term_page', |
|
|
'page arguments' => array(2), |
|
|
'access callback' => 'user_access', |
|
|
'access arguments' => array('access content'), |
|
|
'type' => MENU_CALLBACK, |
|
| 54 |
); |
); |
| 55 |
|
|
| 56 |
return $items; |
return $items; |
| 60 |
* Implementation of hook_nodeapi(). |
* Implementation of hook_nodeapi(). |
| 61 |
*/ |
*/ |
| 62 |
function taxonomy_breadcrumb_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
function taxonomy_breadcrumb_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
| 63 |
// If we are on a page view (not just a teaser), set the breadcrumb |
// If we are on a page view (not just a teaser), set the breadcrumb. |
| 64 |
// $a4 contains TRUE if we are on a page view |
// $a4 contains TRUE if we are on a page view |
| 65 |
if ($op == 'view' && $a4 && !drupal_is_front_page()) { |
if ($op == 'view' && $a4 && !drupal_is_front_page()) { |
| 66 |
// Include the .inc file with all helper functions |
// Include the .inc file with all helper functions |
| 87 |
} |
} |
| 88 |
|
|
| 89 |
/** |
/** |
| 90 |
|
* Implementation of hook_menu_alter(). |
| 91 |
|
*/ |
| 92 |
|
function taxonomy_breadcrumb_menu_alter(&$callbacks) { |
| 93 |
|
// Defined by taxonomy, but might be modified by another module. |
| 94 |
|
$existing_callback = $callbacks['taxonomy/term/%']; |
| 95 |
|
variable_set('taxonomy_breadcrumb_override_callback', $existing_callback); |
| 96 |
|
$callbacks['taxonomy/term/%']['page callback'] = '_taxonomy_breadcrumb_term_page'; |
| 97 |
|
$callbacks['taxonomy/term/%']['file'] = 'taxonomy_breadcrumb.inc'; |
| 98 |
|
$callbacks['taxonomy/term/%']['file path'] = drupal_get_path('module', 'taxonomy_breadcrumb'); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
/** |
| 102 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 103 |
*/ |
*/ |
| 104 |
function taxonomy_breadcrumb_help($path, $arg) { |
function taxonomy_breadcrumb_help($path, $arg) { |
| 133 |
* of the vocabulary or term. |
* of the vocabulary or term. |
| 134 |
*/ |
*/ |
| 135 |
function taxonomy_breadcrumb_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) { |
function taxonomy_breadcrumb_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) { |
| 136 |
// Include the .inc file with all helper functions |
// Include the .inc file with all helper functions. |
| 137 |
include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.admin.inc'; |
include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.admin.inc'; |
| 138 |
include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc'; |
include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc'; |
| 139 |
|
|
| 140 |
$form['taxonomy_breadcrumb_path'] = array( |
$form['taxonomy_breadcrumb_path'] = array( |
| 141 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 142 |
'#title' => t('Breadcrumb path (taxonomy_breadcrumb)'), |
'#title' => t('Breadcrumb path (taxonomy_breadcrumb)'), |
| 143 |
'#default_value' => _taxonomy_breadcrumb_get_vocabulary_path($form['vid']['#value']), |
'#default_value' => _taxonomy_breadcrumb_get_vocabulary_path($form['vid']['#value']), |
| 144 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 145 |
'#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.'), |
'#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.'), |
| 146 |
'#weight' => 0, |
'#weight' => 0, |
| 147 |
); |
); |
| 148 |
} |
} |
| 149 |
|
|
| 150 |
/** |
/** |
| 151 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 156 |
* of the vocabulary or term. |
* of the vocabulary or term. |
| 157 |
*/ |
*/ |
| 158 |
function taxonomy_breadcrumb_form_taxonomy_form_term_alter(&$form, &$form_state) { |
function taxonomy_breadcrumb_form_taxonomy_form_term_alter(&$form, &$form_state) { |
| 159 |
// Include the .inc file with all helper functions |
// Include the .inc file with all helper functions. |
| 160 |
include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc'; |
include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc'; |
| 161 |
|
|
| 162 |
$form['taxonomy_breadcrumb_path'] = array( |
$form['taxonomy_breadcrumb_path'] = array( |
| 163 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 164 |
'#title' => t('Breadcrumb path (taxonomy_breadcrumb)'), |
'#title' => t('Breadcrumb path (taxonomy_breadcrumb)'), |
| 165 |
'#default_value' => _taxonomy_breadcrumb_get_term_path($form['tid']['#value']), |
'#default_value' => _taxonomy_breadcrumb_get_term_path($form['tid']['#value']), |
| 166 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 167 |
'#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.'), |
'#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.'), |
| 168 |
'#weight' => 0, |
'#weight' => 0, |
| 169 |
); |
); |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
/** |
/** |
| 173 |
* Implementation of hook_taxonomy(). This implementation checks to see if a |
* Implementation of hook_taxonomy(). This implementation checks to see if a |
| 176 |
*/ |
*/ |
| 177 |
function taxonomy_breadcrumb_taxonomy($op, $type, $object = NULL) { |
function taxonomy_breadcrumb_taxonomy($op, $type, $object = NULL) { |
| 178 |
|
|
| 179 |
// if (after a vocabulary or term is updated) |
// If (after a vocabulary or term is updated) |
| 180 |
// called by module_invoke_all('taxonomy', 'update', 'term', $edit); in taxonomy.module |
// called by module_invoke_all('taxonomy', 'update', 'term', $edit) in taxonomy.module. |
| 181 |
if ( $op == 'update' && ($type == 'vocabulary' || $type == 'term') ) { |
if ( $op == 'update' && ($type == 'vocabulary' || $type == 'term') ) { |
| 182 |
// Include the .inc file with all helper functions |
// Include the .inc file with all helper functions. |
| 183 |
include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc'; |
include_once drupal_get_path('module', 'taxonomy_breadcrumb') .'/taxonomy_breadcrumb.inc'; |
| 184 |
|
|
| 185 |
// Set variables to used in SQL query to reflect if vocabulary or term is |
// Set variables to used in SQL query to reflect if vocabulary or term is being updated. |
|
// being updated. |
|
| 186 |
|
|
| 187 |
if ($type == 'vocabulary') { |
if ($type == 'vocabulary') { |
| 188 |
$table = '{taxonomy_breadcrumb_vocabulary}'; |
$table = '{taxonomy_breadcrumb_vocabulary}'; |
| 199 |
|
|
| 200 |
if (!is_null($new_path)) { // Only modify database when the object has the 'taxonomy_breadcrumb_path' field |
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 |
// Delete the record from taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term. |
| 203 |
if (drupal_strlen($new_path) == 0 && $old_path !== NULL) { |
if (drupal_strlen($new_path) == 0 && $old_path !== NULL) { |
| 204 |
db_query("DELETE FROM $table WHERE $key_type = %d", $key); |
db_query("DELETE FROM $table WHERE $key_type = %d", $key); |
| 205 |
} |
} |
| 206 |
|
|
| 207 |
// Update existing record in taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term |
// Update the existing record in taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term. |
| 208 |
elseif (drupal_strlen($new_path) != 0 && $old_path != NULL) { |
elseif (drupal_strlen($new_path) != 0 && $old_path != NULL) { |
| 209 |
db_query("UPDATE $table SET path = '%s' WHERE $key_type = %d", $new_path, $key ); |
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 |
// Create a new record in taxonomy_breadcrumb_vocabulary or taxonomy_breadcrumb_term. |
| 213 |
elseif (drupal_strlen($new_path) != 0 && $old_path == NULL) { |
elseif (drupal_strlen($new_path) != 0 && $old_path == NULL) { |
| 214 |
db_query("INSERT INTO $table ($key_type, path) VALUES (%d, '%s')", $key, $new_path); |
db_query("INSERT INTO $table ($key_type, path) VALUES (%d, '%s')", $key, $new_path); |
| 215 |
} |
} |