function google_authorship_tokens in Google Authorship 7
Same name and namespace in other branches
- 7.2 google_authorship.tokens.inc \google_authorship_tokens()
Implements hook_tokens().
File
- ./
google_authorship.tokens.inc, line 28 - Custom tokens for Google Authorship.
Code
function google_authorship_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$sanitize = !empty($options['sanitize']);
// Node tokens.
if ($type == 'node' && !empty($data['node'])) {
$node = $data['node'];
foreach ($tokens as $name => $original) {
if ($original == '[node:google_authorship_id]' || $original == '[node:google_authorship_url]') {
$account = user_load($node->uid);
$fields = field_get_items('user', $account, 'field_google_plus_id');
if (!empty($fields)) {
$field = reset($fields);
if (!empty($field['safe_value']) && is_numeric($field['safe_value'])) {
// The ID will be needed for either token.
$replacements[$original] = $field['safe_value'];
// If the URL is requested, put it together.
if ($original == '[node:google_authorship_url]') {
$replacements[$original] = GOOGLE_AUTHORSHIP_PREFIX . $replacements[$original];
}
}
}
}
}
}
return $replacements;
}