You are here

function uc_recurring_tokens in UC Recurring Payments and Subscriptions 7.2

Implements hook_tokens().

File

./uc_recurring.tokens.inc, line 68
Token related functions for the Ubercart recurring payments module.

Code

function uc_recurring_tokens($type, $tokens, $data = array(), $options = array()) {
  $language_code = NULL;
  if (isset($options['language'])) {
    $language_code = $options['language']->language;
  }
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'uc_recurring_fee' && !empty($data['uc_recurring_fee'])) {
    $fee = $data['uc_recurring_fee'];
    $path = 'user/' . $fee->uid . '/recurring-fees';
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'recurring-fee-id':
          $replacements[$original] = $fee->rfid;
          break;
        case 'next-charge':
          $replacements[$original] = format_date($fee->next_charge);
          break;
        case 'fee-amount':
          $replacements[$original] = uc_currency_format($fee->fee_amount);
          break;
        case 'fee-title':
          $replacements[$original] = $sanitize ? check_plain($fee->fee_title) : $fee->fee_title;
          break;
        case 'charged-intervals':
          $replacements[$original] = $fee->charged_intervals;
          break;
        case 'remaining-intervals':
          $replacements[$original] = $fee->remaining_intervals < 0 ? t('Until cancelled') : $fee->remaining_intervals;
          break;
        case 'renewal-attempts':
          $replacements[$original] = $fee->attempts;
          break;
        case 'link':
          $replacements[$original] = l($fee->rfid, $path, array(
            'absolute' => TRUE,
          ));
          break;
        case 'url':
          $replacements[$original] = url($path, array(
            'absolute' => TRUE,
          ));
          break;
      }
    }

    // Handles chaining for tokens that have 'type' defined in hook_token_info()
    if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
      $replacements += token_generate('url', $url_tokens, array(
        'path' => $path,
      ), $options);
    }
    if ($next_charge_tokens = token_find_with_prefix($tokens, 'next-charge')) {
      $replacements += token_generate('date', $next_charge_tokens, array(
        'date' => $fee->next_charge,
      ), $options);
    }
  }
  return $replacements;
}