| 1 |
<?php |
<?php |
| 2 |
// $Id: taxonomy_menu.module,v 1.19.2.2.2.39 2009/10/18 01:13:00 indytechcook Exp $ |
// $Id: taxonomy_menu.module,v 1.19.2.2.2.40 2009/10/31 18:39:33 indytechcook Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 16 |
function taxonomy_menu_init() { |
function taxonomy_menu_init() { |
| 17 |
//include the database layer |
//include the database layer |
| 18 |
require_once(drupal_get_path('module', 'taxonomy_menu') .'/taxonomy_menu.database.inc'); |
require_once(drupal_get_path('module', 'taxonomy_menu') .'/taxonomy_menu.database.inc'); |
| 19 |
|
|
| 20 |
//include the batch functions |
//include the batch functions |
| 21 |
require_once(drupal_get_path('module', 'taxonomy_menu') .'/taxonomy_menu.batch.inc'); |
require_once(drupal_get_path('module', 'taxonomy_menu') .'/taxonomy_menu.batch.inc'); |
| 22 |
} |
} |
| 318 |
*/ |
*/ |
| 319 |
function taxonomy_menu_nodeapi(&$node, $op, $a3, $a4) { |
function taxonomy_menu_nodeapi(&$node, $op, $a3, $a4) { |
| 320 |
static $terms_old; |
static $terms_old; |
| 321 |
|
static $status; |
| 322 |
// We only need to check for updates if |
|
| 323 |
// 'hide empty terms' or 'show number of nodes' |
if ($op == 'presave' || $op == 'update' || $op == 'insert' || $op == 'delete') { |
| 324 |
// is selected |
// Get the vocabs assoicated to this node |
| 325 |
if (variable_get('taxonomy_menu_display_num', FALSE) |
if (!$status) { |
| 326 |
|| variable_get('taxonomy_menu_hide_empty_terms', FALSE)) { |
$vids = _taxonomy_menu_get_vid_by_tid($node->taxonomy); |
| 327 |
|
// Check to see if the any of the vocabs have display num |
| 328 |
//if display numbers is on, update the menu item with the new name |
// or empty terms enabled |
| 329 |
if ($op == 'update' || $op == 'insert') { |
foreach ($vids as $vid) { |
| 330 |
//we use this direct table pull to avoid the cache and because |
if (variable_get('taxonomy_menu_display_num_'. $vid, FALSE) |
| 331 |
//free tags are not formated in a matter where extrating the |
|| variable_get('taxonomy_menu_hide_empty_terms_'. $vid, FALSE)) { |
| 332 |
//tid's is easy |
$status = 2; |
| 333 |
$terms_new = _taxonomy_menu_get_node_terms($node->nid); |
} |
| 334 |
|
else { |
| 335 |
//merge current terms and previous terms to update both menu items. |
$status = 1; |
| 336 |
$terms = array_unique(array_merge((array)$terms_new, (array)$terms_old)); |
} |
| 337 |
_taxonomy_menu_nodeadpi_helper($op, $terms); |
} |
| 338 |
} |
} |
| 339 |
elseif ($op == 'presave') { |
|
| 340 |
//get the terms from the database before the changes are made. |
if ($status == 2) { |
| 341 |
//these will be used to update the menu item's name if needed |
switch ($op) { |
| 342 |
//we go directly to the db to bypass any caches |
case 'insert': |
| 343 |
$terms_old = _taxonomy_menu_get_node_terms($node->nid); |
case 'update': |
| 344 |
} |
//we use this direct table pull to avoid the cache and because |
| 345 |
elseif ($op == 'delete') { |
//free tags are not formated in a matter where extrating the |
| 346 |
//since the delete operation is run after the data is deleted |
//tid's is easy |
| 347 |
//pull the terms from the node object |
$terms_new = _taxonomy_menu_get_node_terms($node->nid); |
| 348 |
$terms = array_keys($node->taxonomy); |
|
| 349 |
_taxonomy_menu_nodeadpi_helper($op, $terms); |
//merge current terms and previous terms to update both menu items. |
| 350 |
|
$terms = array_unique(array_merge((array)$terms_new, (array)$terms_old)); |
| 351 |
|
_taxonomy_menu_nodeadpi_helper($op, $terms); |
| 352 |
|
break; |
| 353 |
|
|
| 354 |
|
case 'presave': |
| 355 |
|
//get the terms from the database before the changes are made. |
| 356 |
|
//these will be used to update the menu item's name if needed |
| 357 |
|
//we go directly to the db to bypass any caches |
| 358 |
|
$terms_old = _taxonomy_menu_get_node_terms($node->nid); |
| 359 |
|
break; |
| 360 |
|
|
| 361 |
|
case 'delete': |
| 362 |
|
//since the delete operation is run after the data is deleted |
| 363 |
|
//pull the terms from the node object |
| 364 |
|
$terms = array_keys($node->taxonomy); |
| 365 |
|
_taxonomy_menu_nodeadpi_helper($op, $terms); |
| 366 |
|
break; |
| 367 |
|
} |
| 368 |
} |
} |
| 369 |
} |
} |
| 370 |
} |
} |
| 371 |
|
|
| 372 |
/** |
/** |
| 373 |
* Helper function to |
* Helper function to |
| 374 |
* @param $tids |
* @param $tids |
| 375 |
* @return unknown_type |
* @return unknown_type |
| 376 |
*/ |
*/ |
| 502 |
'expanded' => variable_get('taxonomy_menu_expanded_'. $item['vid'], TRUE), |
'expanded' => variable_get('taxonomy_menu_expanded_'. $item['vid'], TRUE), |
| 503 |
'link_path' => $path, |
'link_path' => $path, |
| 504 |
); |
); |
| 505 |
|
|
| 506 |
//Add setup the query paramater in the URL correctly |
//Add setup the query paramater in the URL correctly |
| 507 |
if (strpos($path, '?') !== FALSE) { |
if (strpos($path, '?') !== FALSE) { |
| 508 |
$split = explode('?', $path); |
$split = explode('?', $path); |
| 509 |
if (strpos($split[1], '?') !== FALSE) { |
if (strpos($split[1], '?') !== FALSE) { |
| 510 |
// the query split didn't work, too many question marks |
// the query split didn't work, too many question marks |
| 511 |
// error? |
// error? |
| 614 |
else { |
else { |
| 615 |
$path = taxonomy_term_path(taxonomy_get_term($tid)); |
$path = taxonomy_term_path(taxonomy_get_term($tid)); |
| 616 |
if (variable_get('taxonomy_menu_display_descendants_'. $vid, FALSE)) { |
if (variable_get('taxonomy_menu_display_descendants_'. $vid, FALSE)) { |
| 617 |
//Use 'all' at the end of the path |
//Use 'all' at the end of the path |
| 618 |
if (variable_get('taxonomy_menu_end_all_'. $vid, TRUE)) { |
if (variable_get('taxonomy_menu_end_all_'. $vid, TRUE)) { |
| 619 |
$path .= '/all'; |
$path .= '/all'; |
| 620 |
} |
} |
| 907 |
|
|
| 908 |
$options['display_descendants'] = array( |
$options['display_descendants'] = array( |
| 909 |
'#title' => t('Display descendants'), |
'#title' => t('Display descendants'), |
| 910 |
'#description' => t('TODO'), |
'#description' => t('Changes the default path to taxonomy/term/tid+tid+tid for all terms thave have child terms.'), |
| 911 |
'default' => FALSE, |
'default' => FALSE, |
| 912 |
); |
); |
| 913 |
|
|
| 914 |
$options['end_all'] = array( |
$options['end_all'] = array( |
| 915 |
'#title' => t("Use 'all' at the end of URL"), |
'#title' => t("Use 'all' at the end of URL"), |
| 916 |
'default' => TRUE, |
'default' => TRUE, |
| 968 |
} |
} |
| 969 |
} |
} |
| 970 |
} |
} |
|
|
|