function sharerich_tokens in Sharerich 7
Same name and namespace in other branches
- 8 sharerich.tokens.inc \sharerich_tokens()
- 7.3 includes/sharerich.tokens.inc \sharerich_tokens()
- 7.2 includes/sharerich.tokens.inc \sharerich_tokens()
Implements hook_tokens().
File
- includes/
sharerich.tokens.inc, line 42 - Tokens for Sharerich.
Code
function sharerich_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'sharerich') {
foreach ($tokens as $name => $original) {
$value = '';
switch ($name) {
case 'fb_app_id':
$value = check_plain(variable_get('sharerich_facebook_app_id'));
break;
case 'fb_site_url':
$value = check_plain(variable_get('sharerich_facebook_site_url'));
break;
case 'youtube_username':
$value = check_plain(variable_get('sharerich_youtube_username'));
break;
case 'github_username':
$value = check_plain(variable_get('sharerich_github_username'));
break;
case 'url':
if (isset($data['node']) && !empty($data['node'])) {
$value = token_replace('[node:url]', $data, $options);
}
else {
$value = token_replace('[current-page:url]');
}
$value = rawurlencode($value);
break;
case 'title':
if (isset($data['node']) && !empty($data['node'])) {
$value = token_replace('[node:title]', $data, $options);
}
else {
$value = token_replace('[current-page:title]');
}
$value = rawurlencode($value);
break;
case 'summary':
if (isset($data['node']) && !empty($data['node'])) {
$value = token_replace('[node:summary]', $data, $options);
}
else {
$value = token_replace('[site:name]');
}
$value = rawurlencode($value);
break;
}
$replacements[$original] = $value;
}
return $replacements;
}
}