You are here

function sharerich_tokens in Sharerich 7.3

Same name and namespace in other branches
  1. 8 sharerich.tokens.inc \sharerich_tokens()
  2. 7 includes/sharerich.tokens.inc \sharerich_tokens()
  3. 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(decode_entities($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(decode_entities($value));
          break;
      }
      $replacements[$original] = $value;
    }
    return $replacements;
  }
}