function pathauto_token_values in Pathauto 5.2
Same name and namespace in other branches
- 6.2 pathauto.module \pathauto_token_values()
- 6 pathauto.module \pathauto_token_values()
Implementation of hook_token_values() for Pathauto specific tokens.
File
- ./
pathauto.module, line 121 - Main file for the Pathauto module, which automatically generates aliases for content.
Code
function pathauto_token_values($type, $object = NULL) {
if (module_exists('taxonomy')) {
if ($type == 'taxonomy' || $type == 'node' || $type == 'all') {
_pathauto_include();
switch ($type) {
case 'node':
// We're on a node and it's a book and it has a parent? Get the book path alias
if (module_exists('book')) {
if ($object->type == 'book' && $object->parent) {
$values['bookpathalias-raw'] = drupal_get_path_alias('node/' . $object->parent);
$values['bookpathalias'] = check_plain($values['bookpathalias-raw']);
}
else {
$values['bookpathalias'] = '';
$values['bookpathalias-raw'] = '';
}
}
// Get taxonomy related data.
$vid = db_result(db_query_range("SELECT t.vid 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.nid = %d ORDER BY v.weight, t.weight, t.name", $object->nid, 0, 1));
$category = db_fetch_object(db_query_range("SELECT t.tid, t.name FROM {term_data} t INNER JOIN {term_node} r ON r.tid = t.tid WHERE t.vid = %d AND r.nid = %d ORDER BY weight", $vid, $object->nid, 0, 1));
$category->vid = $vid;
// In the realm of nodes these are terms, in the realm of Taxonomy, cats
$label = 'term';
case 'taxonomy':
default:
if (!isset($category)) {
$category = $object;
}
if (!isset($label)) {
$label = 'cat';
}
if (isset($category->tid)) {
$separator = variable_get('pathauto_separator', '-');
$parents = taxonomy_get_parents_all($category->tid);
array_shift($parents);
$catpath = '';
$catpath_raw = '';
foreach ($parents as $parent) {
// Replace any / characters in individual terms which might create confusing URLs
$catpath = pathauto_cleanstring(check_plain(preg_replace('/\\//', '', $parent->name))) . '/' . $catpath;
$catpath_raw = pathauto_cleanstring(preg_replace('/\\//', '', $parent->name)) . '/' . $catpath_raw;
}
$values[$label . 'path'] = $catpath . '/' . check_plain($category->name);
$values[$label . 'path-raw'] = $catpath_raw . '/' . $category->name;
// We only do this for taxonomy because token already provides the [term] value but has problem with [cat] TODO: fix that?
if ($type == 'taxonomy') {
$values[$label] = check_plain($category->name);
$values[$label . '-raw'] = $category->name;
}
$values[$label . 'alias-raw'] = drupal_get_path_alias('taxonomy/term/' . $category->tid);
$values[$label . 'alias'] = check_plain($values[$label . 'alias-raw']);
}
else {
// Provide some defaults if they aren't set.
$values[$label . 'path'] = '';
$values[$label . 'path-raw'] = '';
$values[$label . 'alias'] = '';
$values[$label . 'alias-raw'] = '';
}
}
return $values;
}
}
}