[49072ea] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * @file |
---|
| 5 | * Builds placeholder replacement tokens for pathauto. |
---|
| 6 | * |
---|
| 7 | * @ingroup pathauto |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | /** |
---|
| 11 | * Implements hook_token_list(). |
---|
| 12 | */ |
---|
| 13 | function _pathauto_token_list($type = 'all') { |
---|
| 14 | $tokens = array(); |
---|
| 15 | |
---|
| 16 | if (module_exists('taxonomy')) { |
---|
| 17 | if ($type == 'taxonomy' || $type == 'all') { |
---|
| 18 | $tokens['taxonomy']['catpath'] = t('As [cat], but including its supercategories separated by /.'); |
---|
| 19 | $tokens['taxonomy']['catpath-raw'] = t('As [cat-raw], but including its supercategories separated by /.'); |
---|
| 20 | $tokens['taxonomy']['catalias'] = t('The URL alias of the taxonomy term.'); |
---|
| 21 | $tokens['taxonomy']['catalias-raw'] = t('The URL alias of the taxonomy term.'); |
---|
| 22 | } |
---|
| 23 | if ($type == 'node' || $type == 'all') { |
---|
| 24 | $tokens['node']['termpath'] = t('As [term], but including its supercategories separated by /.'); |
---|
| 25 | $tokens['node']['termpath-raw'] = t('As [term-raw], but including its supercategories separated by /.'); |
---|
| 26 | $tokens['node']['termalias'] = t('The URL alias of the taxonomy term.'); |
---|
| 27 | $tokens['node']['termalias-raw'] = t('The URL alias of the taxonomy term.'); |
---|
| 28 | } |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | if (module_exists('book')) { |
---|
| 32 | if ($type == 'node' || $type == 'all') { |
---|
| 33 | $tokens['node']['bookpathalias'] = t('The URL alias of the parent book of the node.'); |
---|
| 34 | $tokens['node']['bookpathalias-raw'] = t('The URL alias of the parent book of the node.'); |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | return $tokens; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Implements hook_token_values(). |
---|
| 43 | */ |
---|
| 44 | function _pathauto_token_values($type, $object = NULL, $options = array(), $label = NULL) { |
---|
| 45 | $values = array(); |
---|
| 46 | |
---|
| 47 | if ($type == 'node' && !empty($object)) { |
---|
| 48 | // Token [bookpathalias]. |
---|
| 49 | if (module_exists('book')) { |
---|
| 50 | $values['bookpathalias'] = ''; |
---|
| 51 | $values['bookpathalias-raw'] = ''; |
---|
| 52 | if (!empty($object->book['plid']) && $parent = book_link_load($object->book['plid'])) { |
---|
| 53 | $values['bookpathalias-raw'] = drupal_get_path_alias($parent['href']); |
---|
| 54 | $values['bookpathalias'] = check_plain($values['bookpathalias-raw']); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | // Tokens [termpath], [termpath-raw], and [termalias]. |
---|
| 59 | if (module_exists('taxonomy')) { |
---|
| 60 | // Get the lowest-weighted term from the lowest-weighted vocabulary. |
---|
| 61 | // This query is copied from @taxonomy_node_get_terms() |
---|
| 62 | $term = db_fetch_object(db_query_range('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.vid = %d ORDER BY v.weight, t.weight, t.name', $object->vid, 0, 1)); |
---|
| 63 | if ($term) { |
---|
| 64 | $values = array_merge($values, _pathauto_token_values('taxonomy', $term, $options, 'term')); |
---|
| 65 | } |
---|
| 66 | else { |
---|
| 67 | $values['termpath'] = ''; |
---|
| 68 | $values['termpath-raw'] = ''; |
---|
| 69 | $values['termalias'] = ''; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | if ($type == 'taxonomy' && !empty($object)) { |
---|
| 75 | // In the realm of nodes these are 'terms', in the realm of taxonomy, 'cats'. |
---|
| 76 | if (!isset($label)) { |
---|
| 77 | $label = 'cat'; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | $values[$label . 'path'] = ''; |
---|
| 81 | $values[$label . 'path-raw'] = ''; |
---|
| 82 | $values[$label . 'alias'] = ''; |
---|
| 83 | $values[$label . 'alias-raw'] = ''; |
---|
| 84 | |
---|
| 85 | // Tokens [catpath] and [catpath-raw]. |
---|
| 86 | if (isset($object->tid)) { |
---|
| 87 | $parents = taxonomy_get_parents_all($object->tid); |
---|
| 88 | $catpath = $catpath_raw = array(); |
---|
| 89 | foreach ($parents as $parent) { |
---|
| 90 | array_unshift($catpath, check_plain($parent->name)); |
---|
| 91 | array_unshift($catpath_raw, $parent->name); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | $values[$label . 'path'] = !empty($options['pathauto']) ? $catpath : implode('/', $catpath); |
---|
| 95 | $values[$label . 'path-raw'] = !empty($options['pathauto']) ? $catpath_raw : implode('/', $catpath_raw); |
---|
| 96 | |
---|
| 97 | // Token [catalias-raw] and [catalias]. |
---|
| 98 | $values[$label . 'alias-raw'] = drupal_get_path_alias(taxonomy_term_path($object)); |
---|
| 99 | $values[$label . 'alias'] = check_plain($values[$label . 'alias-raw']); |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | return $values; |
---|
| 104 | } |
---|